Commits

Akira TAGOH committed 86186c3

Add sub-pixel rendering support and hintstyle support

  • Participants
  • Parent commits fd2f4e1

Comments (0)

Files changed (5)

File libeasyfc-gobject/gengir.sh

 s/\(const[ \t].*\)${__cl}/\1${__Cl}/g
 s/\([ \t].*\)_${__cl}/\1_${__Cl}/g
 s/\([\t(].*\)${__cl}/\1${__Cl}/g
-s/^\([ \t].*\)${__cl}/\1${__Cl}/g" > $__tmpsed
+s/^\([ \t].*\)${__cl}/\1${__Cl}/g
+s/^\(}[ \t].*\)${__cl}/\1${__Cl}/g" > $__tmpsed
     sed -f $__tmpsed $__in > $__out
     rm $__tmpsed
 }

File libeasyfc/ezfc-config.c

 	const gchar *family = ezfc_font_get_family(font);
 	gint masks, n = 0;
 
+	masks = ezfc_font_get_boolean_masks(font);
+	if (masks == 0)
+		return TRUE;
 	match = xmlNewNode(NULL,
 			   (const xmlChar *)"match");
 	xmlNewProp(match,
 	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;
+		static const gchar *hintstyles[] = {
+			NULL,
+			"hintnone",
+			"hintslight",
+			"hintmedium",
+			"hintfull",
+			NULL
+		};
 
 		if (i == 0 || i >= EZFC_FONT_MASK_END)
 			goto bail;
 				       (const xmlChar *)"embeddedbitmap");
 			    f = ezfc_font_get_embedded_bitmap(font);
 			    break;
+		    case EZFC_FONT_MASK_HINTSTYLE:
+			    xmlNewProp(edit,
+				       (const xmlChar *)"name",
+				       (const xmlChar *)"hintstyle");
+			    xmlNewProp(edit,
+				       (const xmlChar *)"mode",
+				       (const xmlChar *)"assign");
+			    xmlNewChild(edit, NULL,
+					(const xmlChar *)"const",
+					(const xmlChar *)hintstyles[ezfc_font_get_hintstyle(font)]);
+			    goto bail;
 		    default:
 			    g_return_val_if_reached(FALSE);
 		}
 
 	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));

File libeasyfc/ezfc-font-private.h

 G_BEGIN_DECLS
 
 typedef struct _ezfc_font_private_t {
-	ezfc_mem_t  parent;
-	FcPattern  *pattern;
-	gboolean    check_font_existence;
-	gint        masks;
-	gboolean    hinting;
-	gboolean    autohinting;
-	gboolean    antialiasing;
-	gboolean    embedded_bitmap;
+	ezfc_mem_t             parent;
+	FcPattern             *pattern;
+	gboolean               check_font_existence;
+	gint                   masks;
+	gint                   rgba;
+	ezfc_font_hintstyle_t  hintstyle;
+	gboolean               hinting;
+	gboolean               autohinting;
+	gboolean               antialiasing;
+	gboolean               embedded_bitmap;
 } ezfc_font_private_t;
 
 typedef enum _ezfc_font_mask_t {
 	EZFC_FONT_MASK_AUTOHINT        = 1 << 1,
 	EZFC_FONT_MASK_ANTIALIAS       = 1 << 2,
 	EZFC_FONT_MASK_EMBEDDED_BITMAP = 1 << 3,
+	EZFC_FONT_MASK_HINTSTYLE       = 1 << 4,
 	EZFC_FONT_MASK_END
 } ezfc_font_mask_t;
 

File libeasyfc/ezfc-font.c

 }
 
 /**
+ * ezfc_font_set_hintstyle:
+ * @font: a #ezfc_font_t.
+ * @hintstyle: a #ezfc_font_hintstyle_t.
+ *
+ * Set a hintstyle for @font.
+ */
+void
+ezfc_font_set_hintstyle(ezfc_font_t           *font,
+			ezfc_font_hintstyle_t  hintstyle)
+{
+	ezfc_font_private_t *priv = (ezfc_font_private_t *)font;
+
+	g_return_if_fail (font != NULL);
+	g_return_if_fail (hintstyle > EZFC_FONT_HINTSTYLE_UNKNOWN && hintstyle < EZFC_FONT_HINTSTYLE_END);
+
+	priv->masks |= EZFC_FONT_MASK_HINTSTYLE;
+	priv->hintstyle = hintstyle;
+}
+
+/**
+ * ezfc_font_get_hintstyle:
+ * @font: a #ezfc_font_t.
+ *
+ * Obtain the hintstyle in @font.
+ *
+ * Returns: a #ezfc_font_hintstyle_t.
+ */
+ezfc_font_hintstyle_t
+ezfc_font_get_hintstyle(ezfc_font_t *font)
+{
+	ezfc_font_private_t *priv = (ezfc_font_private_t *)font;
+
+	g_return_val_if_fail (font != NULL, EZFC_FONT_HINTSTYLE_UNKNOWN);
+
+	return priv->hintstyle;
+}
+
+/**
  * ezfc_font_set_antialiasing:
  * @font: a #ezfc_font_t.
  * @flag: a boolean value.
 }
 
 /**
+ * ezfc_font_set_rgba:
+ * @font: a #ezfc_font_t.
+ * @val: an integer value corresponding to FC_RGBA_*.
+ *
+ * Set @val as the sub-pixel ordering
+ */
+void
+ezfc_font_set_rgba(ezfc_font_t *font,
+		   gint         val)
+{
+	ezfc_font_private_t *priv = (ezfc_font_private_t *)font;
+
+	g_return_if_fail (font != NULL);
+
+	priv->rgba = val;
+}
+
+/**
+ * ezfc_font_get_rgba:
+ * @font: a #ezfc_font_t.
+ *
+ * Obtains current sub-pixel ordering in @font.
+ *
+ * Returns: the sub-pixel ordering value in the integer.
+ */
+gint
+ezfc_font_get_rgba(ezfc_font_t *font)
+{
+	ezfc_font_private_t *priv = (ezfc_font_private_t *)font;
+
+	g_return_val_if_fail (font != NULL, FC_RGBA_UNKNOWN);
+
+	return priv->rgba;
+}
+
+/**
  * ezfc_font_get_boolean_masks:
  * @font: a #ezfc_font_t.
  *
 
 	return priv->masks;
 }
+
+/**
+ * ezfc_font_set_subpixel_rendering:
+ * @font: a #ezfc_font_t.
+ * @mode: a #ezfc_font_subpixel_render_t.
+ *
+ * This is just convenient to change the several configuration for subpixel
+ * rendering.
+ *
+ */
+gboolean
+ezfc_font_set_subpixel_rendering(ezfc_font_t                 *font,
+				 ezfc_font_subpixel_render_t  mode)
+{
+	g_return_val_if_fail (font != NULL, FALSE);
+	g_return_val_if_fail (mode < EZFC_FONT_ANTIALIAS_END, FALSE);
+
+	switch (mode) {
+	    case EZFC_FONT_ANTIALIAS_NONE:
+		    ezfc_font_set_antialiasing(font, FALSE);
+		    ezfc_font_set_rgba(font, FC_RGBA_NONE);
+		    break;
+	    case EZFC_FONT_ANTIALIAS_GRAY:
+		    ezfc_font_set_antialiasing(font, TRUE);
+		    ezfc_font_set_rgba(font, FC_RGBA_NONE);
+		    break;
+	    case EZFC_FONT_ANTIALIAS_RGB:
+		    ezfc_font_set_antialiasing(font, TRUE);
+		    ezfc_font_set_rgba(font, FC_RGBA_RGB);
+		    break;
+	    case EZFC_FONT_ANTIALIAS_BGR:
+		    ezfc_font_set_antialiasing(font, TRUE);
+		    ezfc_font_set_rgba(font, FC_RGBA_BGR);
+		    break;
+	    case EZFC_FONT_ANTIALIAS_VRGB:
+		    ezfc_font_set_antialiasing(font, TRUE);
+		    ezfc_font_set_rgba(font, FC_RGBA_VRGB);
+		    break;
+	    case EZFC_FONT_ANTIALIAS_VBGR:
+		    ezfc_font_set_antialiasing(font, TRUE);
+		    ezfc_font_set_rgba(font, FC_RGBA_VBGR);
+		    break;
+	    default:
+		    g_return_val_if_reached (FALSE);
+	}
+
+	return TRUE;
+}
+
+/**
+ * ezfc_font_get_subpixel_rendering:
+ * @font: a #ezfc_font_t.
+ *
+ * Obtain current status about the sub-pixel rendering in @font.
+ *
+ * Returns: current mode in the sub-pixel rendering.
+ */
+ezfc_font_subpixel_render_t
+ezfc_font_get_subpixel_rendering(ezfc_font_t *font)
+{
+	gboolean antialias;
+	gint rgba;
+	ezfc_font_subpixel_render_t retval;
+
+	g_return_val_if_fail (font != NULL, EZFC_FONT_ANTIALIAS_UNKNOWN);
+
+	antialias = ezfc_font_get_antialiasing(font);
+	rgba = ezfc_font_get_rgba(font);
+
+	if (antialias) {
+		switch (rgba) {
+		    case FC_RGBA_NONE:
+			    retval = EZFC_FONT_ANTIALIAS_GRAY;
+			    break;
+		    case FC_RGBA_RGB:
+			    retval = EZFC_FONT_ANTIALIAS_RGB;
+			    break;
+		    case FC_RGBA_BGR:
+			    retval = EZFC_FONT_ANTIALIAS_BGR;
+			    break;
+		    case FC_RGBA_VRGB:
+			    retval = EZFC_FONT_ANTIALIAS_VRGB;
+			    break;
+		    case FC_RGBA_VBGR:
+			    retval = EZFC_FONT_ANTIALIAS_VBGR;
+			    break;
+		    default:
+			    retval = EZFC_FONT_ANTIALIAS_UNKNOWN;
+			    break;
+		}
+	} else {
+		/* no matter what rgba is, if antialias is false,
+		 * it should be None.
+		 */
+		retval = EZFC_FONT_ANTIALIAS_NONE;
+	}
+
+	return retval;
+}

File libeasyfc/ezfc-font.h

  */
 typedef struct _ezfc_font_t	ezfc_font_t;
 
+/**
+ * ezfc_font_subpixel_render_t:
+ */
+typedef enum _ezfc_font_subpixel_render_t {
+	EZFC_FONT_ANTIALIAS_UNKNOWN = 0,
+	EZFC_FONT_ANTIALIAS_NONE,
+	EZFC_FONT_ANTIALIAS_GRAY,
+	EZFC_FONT_ANTIALIAS_RGB,
+	EZFC_FONT_ANTIALIAS_BGR,
+	EZFC_FONT_ANTIALIAS_VRGB,
+	EZFC_FONT_ANTIALIAS_VBGR,
+	EZFC_FONT_ANTIALIAS_END
+} ezfc_font_subpixel_render_t;
+
+/**
+ * ezfc_font_hintstyle_t:
+ */
+typedef enum _ezfc_font_hintstyle_t {
+	EZFC_FONT_HINTSTYLE_UNKNOWN = 0,
+	EZFC_FONT_HINTSTYLE_NONE,
+	EZFC_FONT_HINTSTYLE_SLIGHT,
+	EZFC_FONT_HINTSTYLE_MEDIUM,
+	EZFC_FONT_HINTSTYLE_FULL,
+	EZFC_FONT_HINTSTYLE_END
+} ezfc_font_hintstyle_t;
 
-gboolean     ezfc_font_is_alias_font              (const gchar      *alias_name);
-GList       *ezfc_font_get_list                   (const gchar      *language,
-						   const gchar      *alias_name,
-						   gboolean          localized_font_name);
-GList       *ezfc_font_get_pattern_list           (const gchar      *language,
-						   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 gchar *ezfc_font_get_family                 (ezfc_font_t      *font);
-gboolean     ezfc_font_set_family                 (ezfc_font_t      *font,
-						   const gchar      *font_name,
-						   GError          **error);
-void         ezfc_font_check_existence            (ezfc_font_t      *font,
-						   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);
+gboolean                     ezfc_font_is_alias_font              (const gchar                  *alias_name);
+GList                       *ezfc_font_get_list                   (const gchar                  *language,
+                                                                   const gchar                  *alias_name,
+                                                                   gboolean                      localized_font_name);
+GList                       *ezfc_font_get_pattern_list           (const gchar                  *language,
+                                                                   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 gchar                 *ezfc_font_get_family                 (ezfc_font_t                  *font);
+gboolean                     ezfc_font_set_family                 (ezfc_font_t                  *font,
+                                                                   const gchar                  *font_name,
+                                                                   GError                      **error);
+void                         ezfc_font_check_existence            (ezfc_font_t                  *font,
+                                                                   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_hintstyle              (ezfc_font_t                  *font,
+								   ezfc_font_hintstyle_t         hintstyle);
+ezfc_font_hintstyle_t        ezfc_font_get_hintstyle              (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);
+void                         ezfc_font_set_rgba                   (ezfc_font_t                  *font,
+                                                                   gint                          val);
+gint                         ezfc_font_get_rgba                   (ezfc_font_t                  *font);
+gboolean                     ezfc_font_set_subpixel_rendering     (ezfc_font_t                  *font,
+                                                                   ezfc_font_subpixel_render_t   mode);
+ezfc_font_subpixel_render_t  ezfc_font_get_subpixel_rendering     (ezfc_font_t                  *font);
 
 G_END_DECLS