From 1efb1f42e00c4b8915ae3db383597776dd504c36 Mon Sep 17 00:00:00 2001
From: Akira TAGOH <akira@tagoh.org>
Date: Mon, 19 Jan 2015 18:32:47 +0900
Subject: [PATCH] Fix a crash when the config contains a font not installed on
the system
---
libeasyfc/ezfc-config.c | 12 +++++++++++-
libeasyfc/ezfc-config.h | 2 +-
libeasyfc/ezfc-font.c | 20 +++++++++++++++++++-
libeasyfc/ezfc-font.h | 3 ++-
4 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/libeasyfc/ezfc-config.c b/libeasyfc/ezfc-config.c
index 7e88a7c..d8bd045 100644
--- a/libeasyfc/ezfc-config.c
+++ b/libeasyfc/ezfc-config.c
@@ -1,7 +1,7 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* ezfc-config.c
- * Copyright (C) 2011-2013 Akira TAGOH
+ * Copyright (C) 2011-2015 Akira TAGOH
*
* Authors:
* Akira TAGOH <akira@tagoh.org>
@@ -812,10 +812,20 @@ _ezfc_config_from_xml(ezfc_config_t *config,
if (xmlStrcmp(node->name, (const xmlChar *)"test") == 0) {
attr = xmlGetProp(node, (const xmlChar *)"name");
if (xmlStrcmp(attr, (const xmlChar *)FC_FAMILY) == 0) {
+ gboolean b;
+
f = ezfc_font_new();
l = _ezfc_config_parse_string_node(node->children);
/* multiple values is not well supported */
+ /* ezfc_font_add_family may fails if a family doesn't exist in the system
+ * this is just an exception not to check the existence of fonts
+ * so that we can simply ignore that invalid entry until
+ * one installs the missing fonts again.
+ */
+ b = ezfc_font_get_check_existence(f);
+ ezfc_font_check_existence(f, FALSE);
ezfc_font_add_family(f, (const gchar *)l->data, &err);
+ ezfc_font_check_existence(f, b);
g_list_free_full(l, xmlFree);
}
xmlFree(attr);
diff --git a/libeasyfc/ezfc-config.h b/libeasyfc/ezfc-config.h
index d31edd1..a723b07 100644
--- a/libeasyfc/ezfc-config.h
+++ b/libeasyfc/ezfc-config.h
@@ -1,7 +1,7 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* ezfc-config.h
- * Copyright (C) 2011-2012 Akira TAGOH
+ * Copyright (C) 2011-2015 Akira TAGOH
*
* Authors:
* Akira TAGOH <akira@tagoh.org>
diff --git a/libeasyfc/ezfc-font.c b/libeasyfc/ezfc-font.c
index 54dc34a..984663f 100644
--- a/libeasyfc/ezfc-font.c
+++ b/libeasyfc/ezfc-font.c
@@ -1,7 +1,7 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* ezfc-font.c
- * Copyright (C) 2011-2013 Akira TAGOH
+ * Copyright (C) 2011-2015 Akira TAGOH
*
* Authors:
* Akira TAGOH <akira@tagoh.org>
@@ -895,6 +895,24 @@ ezfc_font_check_existence(ezfc_font_t *font,
}
/**
+ * ezfc_font_get_check_existence:
+ * @font: a #ezfc_font_t
+ *
+ * Obtain a flag in @font if it's supposed to check the font existence when invoking
+ *
+ * Returns: %TRUE if it does otherwise %FALSE.
+ */
+gboolean
+ezfc_font_get_check_existence(ezfc_font_t *font)
+{
+ ezfc_font_private_t *priv = (ezfc_font_private_t *)font;
+
+ g_return_val_if_fail (font != NULL, FALSE);
+
+ return priv->check_font_existence;
+}
+
+/**
* ezfc_font_set_hinting:
* @font: a #ezfc_font_t.
* @flag: a boolean value.
diff --git a/libeasyfc/ezfc-font.h b/libeasyfc/ezfc-font.h
index a6f227c..06b25df 100644
--- a/libeasyfc/ezfc-font.h
+++ b/libeasyfc/ezfc-font.h
@@ -1,7 +1,7 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* ezfc-font.h
- * Copyright (C) 2011-2013 Akira TAGOH
+ * Copyright (C) 2011-2015 Akira TAGOH
*
* Authors:
* Akira TAGOH <akira@tagoh.org>
@@ -112,6 +112,7 @@ gboolean ezfc_font_remove_family (ezfc_font_t
GError **error);
void ezfc_font_check_existence (ezfc_font_t *font,
gboolean flag);
+gboolean ezfc_font_get_check_existence (ezfc_font_t *font);
void ezfc_font_set_hinting (ezfc_font_t *font,
gboolean flag);
gboolean ezfc_font_get_hinting (ezfc_font_t *font);
--
2.1.0