Akira TAGOH avatar Akira TAGOH committed fd2f4e1

Added boolean value modification

Comments (0)

Files changed (7)

libeasyfc-gobject/gengir.sh

 _tmpgen=`mktemp gengir.XXXXXXXX`
 capitalize "$srcdir/$target" $_tmpgen $_cl
 
-sed -i -e 's,^\(#include[ \t]<\)liblangtag\(/lt-.*\)\(\.h>\),\1liblangtag-gobject\2.gir\3,' $_tmpgen
+sed -i -e 's,^\(#include[ \t]<\)libeasyfc\(/ezfc-.*\)\(\.h>\),\1libeasyfc-gobject\2.gir\3,' $_tmpgen
 
 while [ 1 ]; do
     if [ "x$type" == "xh" ]; then

libeasyfc/ezfc-config.c

 #include <libxml/xpath.h>
 #include <libeasyfc/ezfc-error.h>
 #include <libeasyfc/ezfc-font.h>
+#include "ezfc-font-private.h"
 #include <libeasyfc/ezfc-utils.h>
 #include "ezfc-mem.h"
 #include <libeasyfc/ezfc-config.h>
 struct _ezfc_config_t {
 	ezfc_mem_t  parent;
 	GHashTable *aliases;
+	GHashTable *fonts;
 	gchar      *name;
 	gint        priority;
 	gboolean    loaded;
 }
 
 static gboolean
+_ezfc_config_real_to_font_xml(xmlNodePtr   root,
+			      ezfc_font_t *font,
+			      gboolean    *no_elements)
+{
+	xmlNodePtr match, test, edit;
+	const gchar *family = ezfc_font_get_family(font);
+	gint masks, n = 0;
+
+	match = xmlNewNode(NULL,
+			   (const xmlChar *)"match");
+	xmlNewProp(match,
+		   (const xmlChar *)"target",
+		   (const xmlChar *)"font");
+	test = xmlNewChild(match, NULL,
+			   (const xmlChar *)"test",
+			   NULL);
+	xmlNewProp(test,
+		   (const xmlChar *)"name",
+		   (const xmlChar *)"family");
+	xmlNewChild(test, NULL,
+		    (const xmlChar *)"string",
+		    (const xmlChar *)family);
+	masks = ezfc_font_get_boolean_masks(font);
+	while (masks != 0) {
+		gint i = (masks & 1) << n;
+		gboolean f;
+
+		if (i == 0 || i >= EZFC_FONT_MASK_END)
+			goto bail;
+		edit = xmlNewChild(match, NULL,
+				   (const xmlChar *)"edit",
+				   NULL);
+		switch (i) {
+		    case EZFC_FONT_MASK_HINTING:
+			    xmlNewProp(edit,
+				       (const xmlChar *)"name",
+				       (const xmlChar *)"hinting");
+			    f = ezfc_font_get_hinting(font);
+			    break;
+		    case EZFC_FONT_MASK_AUTOHINT:
+			    xmlNewProp(edit,
+				       (const xmlChar *)"name",
+				       (const xmlChar *)"autohint");
+			    f = ezfc_font_get_autohinting(font);
+			    break;
+		    case EZFC_FONT_MASK_ANTIALIAS:
+			    xmlNewProp(edit,
+				       (const xmlChar *)"name",
+				       (const xmlChar *)"antialias");
+			    f = ezfc_font_get_antialiasing(font);
+			    break;
+		    case EZFC_FONT_MASK_EMBEDDED_BITMAP:
+			    xmlNewProp(edit,
+				       (const xmlChar *)"name",
+				       (const xmlChar *)"embeddedbitmap");
+			    f = ezfc_font_get_embedded_bitmap(font);
+			    break;
+		    default:
+			    g_return_val_if_reached(FALSE);
+		}
+		xmlNewProp(edit,
+			   (const xmlChar *)"mode",
+			   (const xmlChar *)"assign");
+		xmlNewChild(edit, NULL,
+			    (const xmlChar *)"bool",
+			    (const xmlChar *)(f ? "true" : "false"));
+	  bail:
+		masks >>= 1;
+		n++;
+	}
+	xmlAddChild(root, match);
+	*no_elements = FALSE;
+
+	return TRUE;
+}
+
+static gboolean
 _ezfc_config_to_xml(ezfc_config_t  *config,
 		    xmlChar       **output,
 		    int            *size)
 	if (val)
 		if (!_ezfc_config_real_to_xml(root, NULL, val, &no_elements))
 			return FALSE;
+	g_hash_table_iter_init(&iter, config->fonts);
+	while (g_hash_table_iter_next(&iter, &key, &val)) {
+		ezfc_font_t *font = val;
+
+		if (!_ezfc_config_real_to_font_xml(root, font, &no_elements))
+			return FALSE;
+	}
 
 	xmlDocDumpFormatMemory(doc, output, size, 1);
 
 							g_str_equal,
 							g_free,
 							(GDestroyNotify)ezfc_container_unref);
+		retval->fonts = g_hash_table_new_full(g_str_hash,
+						      g_str_equal,
+						      g_free,
+						      (GDestroyNotify)ezfc_font_unref);
 		retval->name = NULL;
 		retval->priority = 0;
 		retval->loaded = FALSE;
 }
 
 /**
+ * ezfc_config_add_font:
+ * @config: a #ezfc_config_t.
+ * @font: a #ezfc_font_t.
+ *
+ * Add a #font font to generate non-language-specific, non-alias-specific
+ * rules.
+ *
+ * Returns: %TRUE if it's successfully completed, otherwise %FALSE.
+ */
+gboolean
+ezfc_config_add_font(ezfc_config_t *config,
+		     ezfc_font_t   *font)
+{
+	const gchar *family;
+
+	g_return_val_if_fail (config != NULL, FALSE);
+	g_return_val_if_fail (font != NULL, FALSE);
+	g_return_val_if_fail (ezfc_font_get_boolean_masks(font) != 0, FALSE);
+
+	family = ezfc_font_get_family(font);
+	g_hash_table_replace(config->fonts, g_strdup(family), ezfc_font_ref(font));
+
+	return TRUE;
+}
+
+/**
+ * ezfc_config_remove_font:
+ * @config: a #ezfc_config_t.
+ * @family: a family name to be removed.
+ *
+ * Remove a #ezfc_font_t instance corresponding to @family.
+ *
+ * Returns: %TRUE if it's successfully removed, otherwise %FALSE.
+ */
+gboolean
+ezfc_config_remove_font(ezfc_config_t *config,
+			const gchar   *family)
+{
+	g_return_val_if_fail (config != NULL, FALSE);
+	g_return_val_if_fail (family != NULL, FALSE);
+
+	return g_hash_table_remove(config->fonts, family);
+}
+
+/**
+ * ezfc_config_remove_fonts:
+ * @config: a #ezfc_config_t.
+ *
+ * Remove all of fonts from @config, which added by ezfc_config_add_font().
+ *
+ * Returns: %TRUE if it's successfully removed, otherwise %FALSE.
+ */
+gboolean
+ezfc_config_remove_fonts(ezfc_config_t *config)
+{
+	g_return_val_if_fail (config != NULL, FALSE);
+
+	g_hash_table_remove_all(config->fonts);
+
+	return TRUE;
+}
+
+/**
  * ezfc_config_get_language_list:
  * @config: a #ezfc_config_t.
  *
 }
 
 /**
+ * ezfc_config_get_fonts:
+ * @config: a #ezfc_config_t.
+ *
+ * Obtains the list of #ezfc_font_t in @config.
+ *
+ * Returns: (element-type ezfc_font_t) (transfer container): a #GList contains #ezfc_font_t or %NULL.
+ */
+GList *
+ezfc_config_get_fonts(ezfc_config_t *config)
+{
+	g_return_val_if_fail (config != NULL, NULL);
+
+	return g_hash_table_get_values(config->fonts);
+}
+
+/**
  * ezfc_config_load:
  * @config: a #ezfc_config_t.
  * @error: (allow-none): a #GError.

libeasyfc/ezfc-config.h

 #define __EZFC_CONFIG_H__
 
 #include <libeasyfc/ezfc-alias.h>
+#include <libeasyfc/ezfc-font.h>
 
 G_BEGIN_DECLS
 
                                              const gchar    *alias_name);
 gboolean       ezfc_config_remove_aliases   (ezfc_config_t  *config,
                                              const gchar    *language);
+gboolean       ezfc_config_add_font         (ezfc_config_t  *config,
+                                             ezfc_font_t    *font);
+gboolean       ezfc_config_remove_font      (ezfc_config_t  *config,
+                                             const gchar    *family);
+gboolean       ezfc_config_remove_fonts     (ezfc_config_t  *config);
 GList         *ezfc_config_get_language_list(ezfc_config_t  *config);
 const GList   *ezfc_config_get_aliases      (ezfc_config_t  *config,
                                              const gchar    *language);
+GList         *ezfc_config_get_fonts        (ezfc_config_t  *config);
 gboolean       ezfc_config_load             (ezfc_config_t  *config,
                                              GError        **error);
 gboolean       ezfc_config_save             (ezfc_config_t  *config,

libeasyfc/ezfc-font-private.h

 	ezfc_mem_t  parent;
 	FcPattern  *pattern;
 	gboolean    check_font_existence;
+	gint        masks;
+	gboolean    hinting;
+	gboolean    autohinting;
+	gboolean    antialiasing;
+	gboolean    embedded_bitmap;
 } ezfc_font_private_t;
 
+typedef enum _ezfc_font_mask_t {
+	EZFC_FONT_MASK_HINTING         = 1 << 0,
+	EZFC_FONT_MASK_AUTOHINT        = 1 << 1,
+	EZFC_FONT_MASK_ANTIALIAS       = 1 << 2,
+	EZFC_FONT_MASK_EMBEDDED_BITMAP = 1 << 3,
+	EZFC_FONT_MASK_END
+} ezfc_font_mask_t;
 
-void ezfc_font_init(ezfc_font_t *font);
+void ezfc_font_init             (ezfc_font_t *font);
+gint ezfc_font_get_boolean_masks(ezfc_font_t *font);
 
 G_END_DECLS
 

libeasyfc/ezfc-font.c

 
 	priv->check_font_existence = (flag == TRUE);
 }
+
+/**
+ * ezfc_font_set_hinting:
+ * @font: a #ezfc_font_t.
+ * @flag: a boolean value.
+ *
+ * Set a flag whether the font use the own hints for rendering
+ */
+void
+ezfc_font_set_hinting(ezfc_font_t *font,
+		      gboolean     flag)
+{
+	ezfc_font_private_t *priv = (ezfc_font_private_t *)font;
+
+	g_return_if_fail (font != NULL);
+
+	priv->masks |= EZFC_FONT_MASK_HINTING;
+	priv->hinting = (flag == TRUE);
+}
+
+/**
+ * ezfc_font_get_hinting:
+ * @font: a #ezfc_font_t.
+ *
+ * Obtain a boolean value about the hinting usage in @font.
+ *
+ * Returns: %TRUE if the hinting is enabled. otherwise %FALSE.
+ */
+gboolean
+ezfc_font_get_hinting(ezfc_font_t *font)
+{
+	ezfc_font_private_t *priv = (ezfc_font_private_t *)font;
+
+	g_return_val_if_fail (font != NULL, FALSE);
+
+	return priv->hinting;
+}
+
+/**
+ * ezfc_font_set_autohinting:
+ * @font: a #ezfc_font_t.
+ * @flag: a boolean value.
+ *
+ * Set a flag whether the font use the auto-hinting for rendering
+ */
+void
+ezfc_font_set_autohinting(ezfc_font_t *font,
+			  gboolean     flag)
+{
+	ezfc_font_private_t *priv = (ezfc_font_private_t *)font;
+
+	g_return_if_fail (font != NULL);
+
+	priv->masks |= EZFC_FONT_MASK_AUTOHINT;
+	priv->autohinting = (flag == TRUE);
+}
+
+/**
+ * ezfc_font_get_autohinting:
+ * @font: a #ezfc_font_t.
+ *
+ * Obtain a boolean value about the auto-hinting usage in @font.
+ *
+ * Returns: %TRUE if the auto-hinting is enabled. otherwise %FALSE.
+ */
+gboolean
+ezfc_font_get_autohinting(ezfc_font_t *font)
+{
+	ezfc_font_private_t *priv = (ezfc_font_private_t *)font;
+
+	g_return_val_if_fail (font != NULL, FALSE);
+
+	return priv->autohinting;
+}
+
+/**
+ * ezfc_font_set_antialiasing:
+ * @font: a #ezfc_font_t.
+ * @flag: a boolean value.
+ *
+ * Set a flag whether the font use the antialiasing.
+ */
+void
+ezfc_font_set_antialiasing(ezfc_font_t *font,
+			   gboolean     flag)
+{
+	ezfc_font_private_t *priv = (ezfc_font_private_t *)font;
+
+	g_return_if_fail (font != NULL);
+
+	priv->masks |= EZFC_FONT_MASK_ANTIALIAS;
+	priv->antialiasing = (flag == TRUE);
+	if (flag && ezfc_font_get_embedded_bitmap(font))
+		ezfc_font_set_embedded_bitmap(font, FALSE);
+}
+
+/**
+ * ezfc_font_get_antialiasing:
+ * @font: a #ezfc_font_t.
+ *
+ * Obtain a boolean value about the anti-aliasing usage in @font.
+ *
+ * Returns: %TRUE if the antialiasing is enabled. otherwise %FALSE.
+ */
+gboolean
+ezfc_font_get_antialiasing(ezfc_font_t *font)
+{
+	ezfc_font_private_t *priv = (ezfc_font_private_t *)font;
+
+	g_return_val_if_fail (font != NULL, FALSE);
+
+	return priv->antialiasing;
+}
+
+/**
+ * ezfc_font_set_embedded_bitmap:
+ * @font: a #ezfc_font_t.
+ * @flag: a boolean value.
+ *
+ * Set a flag whether the font use the embedded bitmap.
+ * Note that Enabling the embedded bitmap causes disabling the antialias.
+ */
+void
+ezfc_font_set_embedded_bitmap(ezfc_font_t *font,
+			      gboolean     flag)
+{
+	ezfc_font_private_t *priv = (ezfc_font_private_t *)font;
+
+	g_return_if_fail (font != NULL);
+
+	priv->masks |= EZFC_FONT_MASK_EMBEDDED_BITMAP;
+	priv->embedded_bitmap = (flag == TRUE);
+	/* This implies changing the antialias too */
+	if (flag)
+		ezfc_font_set_antialiasing(font, FALSE);
+}
+
+/**
+ * ezfc_font_get_embedded_bitmap:
+ * @font: a #ezfc_font_t.
+ *
+ * Obtain a boolean value about the embedded bitmap usage in @font.
+ *
+ * Returns: %TRUE if the embedded bitmap is enabled, otherwise %FALSE.
+ */
+gboolean
+ezfc_font_get_embedded_bitmap(ezfc_font_t *font)
+{
+	ezfc_font_private_t *priv = (ezfc_font_private_t *)font;
+
+	g_return_val_if_fail (font != NULL, FALSE);
+
+	return priv->embedded_bitmap;
+}
+
+/**
+ * ezfc_font_get_boolean_masks:
+ * @font: a #ezfc_font_t.
+ *
+ * Obtain masks that any boolean values are set to @font.
+ * This is set when ezfc_font_set_hinting(), ezfc_font_set_autohinting()
+ * and ezfc_font_set_antialiasing() is called.
+ *
+ * Returns: an integer value
+ */
+gint
+ezfc_font_get_boolean_masks(ezfc_font_t *font)
+{
+	ezfc_font_private_t *priv = (ezfc_font_private_t *)font;
+
+	g_return_val_if_fail (font != NULL, 0);
+
+	return priv->masks;
+}

libeasyfc/ezfc-font.h

 
 gboolean     ezfc_font_is_alias_font              (const gchar      *alias_name);
 GList       *ezfc_font_get_list                   (const gchar      *language,
-                                                   const gchar      *alias_name,
+						   const gchar      *alias_name,
 						   gboolean          localized_font_name);
 GList       *ezfc_font_get_pattern_list           (const gchar      *language,
-                                                   const gchar      *alias_name);
+						   const gchar      *alias_name);
 GList       *ezfc_font_get_alias_name_from_pattern(const FcPattern  *pattern);
 ezfc_font_t *ezfc_font_new                        (void);
 ezfc_font_t *ezfc_font_ref                        (ezfc_font_t      *font);
 void         ezfc_font_unref                      (ezfc_font_t      *font);
 FcPattern   *ezfc_font_get_pattern                (ezfc_font_t      *font);
 gboolean     ezfc_font_set_pattern                (ezfc_font_t      *font,
-                                                   const FcPattern  *pattern,
-                                                   GError          **error);
+						   const FcPattern  *pattern,
+						   GError          **error);
 const gchar *ezfc_font_get_family                 (ezfc_font_t      *font);
 gboolean     ezfc_font_set_family                 (ezfc_font_t      *font,
-                                                   const gchar      *font_name,
-                                                   GError          **error);
+						   const gchar      *font_name,
+						   GError          **error);
 void         ezfc_font_check_existence            (ezfc_font_t      *font,
-                                                   gboolean          flag);
+						   gboolean          flag);
+void         ezfc_font_set_hinting                (ezfc_font_t      *font,
+						   gboolean          flag);
+gboolean     ezfc_font_get_hinting                (ezfc_font_t      *font);
+void         ezfc_font_set_autohinting            (ezfc_font_t      *font,
+						   gboolean          flag);
+gboolean     ezfc_font_get_autohinting            (ezfc_font_t      *font);
+void         ezfc_font_set_antialiasing           (ezfc_font_t      *font,
+						   gboolean          flag);
+gboolean     ezfc_font_get_antialiasing           (ezfc_font_t      *font);
+void         ezfc_font_set_embedded_bitmap        (ezfc_font_t      *font,
+						   gboolean          flag);
+gboolean     ezfc_font_get_embedded_bitmap        (ezfc_font_t      *font);
 
 G_END_DECLS
 

tests/ezfc-tool.py

 config_extra_name = None
 
 def __cmd_add_cb(argv):
-    opts, args = getopt.getopt(argv, 'h', ['help', 'no-load'])
+    opts, args = getopt.getopt(argv, 'a:hl:',
+                               ['alias=', 'help', 'lang=', 'no-load',
+                                'hinting=', 'autohint=', 'antialias=',
+                                'embeddedbitmap='])
     opts.append(('', None)) # just to ensure entering the loop
     loadconf = True
+    alias = None
     lang = None
+    hinting = None
+    autohint = None
+    antialias = None
+    embeddedbitmap = None
     for o, a in opts:
-        if o in ('-h', '--help') or len(args) != 2:
-            print 'Usage: %s add [options] <alias> <family>' % os.path.basename(sys.argv[0])
+        if o in ('-h', '--help') or len(args) != 1:
+            print 'Usage: %s add [options] <family>' % os.path.basename(sys.argv[0])
             print 'Options:'
-            print '  -h or --help        Show this message'
-            print '  -l or --lang=LANG   Set LANG as the language to be added'
-            print '  --no-load           Do not load the configuration file'
+            print '  -a or --alias=ALIAS      Set ALIAS as the alias font for family'
+            print '  -h or --help             Show this message'
+            print '  -l or --lang=LANG        Set LANG as the language to be added'
+            print '  --no-load                Do not load the configuration file'
+            print '  --hinting=<bool>         Set a boolean value for hinting'
+            print '  --autohint=<bool>        Set a boolean value for auto-hinting'
+            print '  --antialias=<bool>       Set a boolean value for antialiasing'
+            print '  --embeddedbitmap=<bool>  Set a boolean value for embeddedbitmap'
             sys.exit()
+        elif o in ('-a', '--alias'):
+            alias = a
         elif o in ('-l', '--lang'):
             lang = a
         elif o == '--no-load':
             loadconf = False
+        elif o == '--hinting':
+            if a.lower() == "true" or a.lower() == "1" or a.lower() == "yes":
+                hinting = True
+            else:
+                hinting = False
+        elif o == '--autohint':
+            if a.lower() == "true" or a.lower() == "1" or a.lower() == "yes":
+                autohint = True
+            else:
+                autohint = False
+        elif o == '--antialias':
+            if a.lower() == "true" or a.lower() == "1" or a.lower() == "yes":
+                antialias = True
+            else:
+                antialias = False
+        elif o == '--embeddedbitmap':
+            if a.lower() == "true" or a.lower() == "1" or a.lower() == "yes":
+                embeddedbitmap = True
+            else:
+                embeddedbitmap = False
+
+    if (hinting != None or autohint != None or antialias != None or embeddedbitmap != None) and alias != None:
+        print "E: --alias can't be used with --hinting, --autohint, --antialias or --embeddedbitmap"
+        sys.exit()
 
     config = Easyfc.Config()
     config.set_priority(config_priority)
                 pass
             else:
                 raise
-    alias = Easyfc.Alias.new(args[0])
-    alias.set_font(args[1])
-    config.add_alias(lang, alias)
+
+    if alias != None:
+        eza = Easyfc.Alias.new(alias)
+        eza.set_font(args[0])
+        config.add_alias(lang, eza)
+        msg = '%s has been added as the alias of %s for %s' % (args[0], alias, lang)
+    else:
+        ezf = Easyfc.Font.new()
+        ezf.set_family(args[0])
+        amsg = []
+        if hinting != None:
+            ezf.set_hinting(hinting)
+            amsg.append('hinting is %s for %s' % ('enabled' if hinting else 'disabled', args[0]))
+        if autohint != None:
+            ezf.set_autohinting(autohint)
+            amsg.append('auto-hinting is %s for %s' % ('enabled' if autohint else 'disabled', args[0]))
+        if antialias != None:
+            ezf.set_antialiasing(antialias)
+            amsg.append('anti-aliasing is %s for %s' % ('enabled' if antialias else 'disabled', args[0]))
+        if embeddedbitmap != None:
+            ezf.set_embedded_bitmap(embeddedbitmap)
+            amsg.append('embedded bitmap is %s for %s' % ('enabled' if embeddedbitmap else 'disabled', args[0]))
+        msg = '\n'.join(amsg)
+        config.add_font(ezf)
+
     config.save()
-    print '%s has been added as the alias of %s for %s' % (args[1], args[0], lang)
+    print msg
 
 def __cmd_remove_cb(argv):
     opts, args = getopt.getopt(argv, 'h', ['help'])
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.