diff options
author | Noah Levitt <nlevitt@columbia.edu> | 2004-02-23 22:39:26 +0000 |
---|---|---|
committer | Noah Levitt <nlevitt@src.gnome.org> | 2004-02-23 22:39:26 +0000 |
commit | e697bf3ac234b070f3ef269142b94bdefb353640 (patch) | |
tree | 2182fc24801330465036bd2c15d8080af1ee4ae5 | |
parent | d234d2a87811f893069d383f45b6365030aa2188 (diff) | |
download | pango-e697bf3ac234b070f3ef269142b94bdefb353640.tar.gz |
New API pango_font_family_is_monospace. (#108728)
2003-02-23 Noah Levitt <nlevitt@columbia.edu>
* pango/pangowin32-fontmap.c:
* pango/pangofc-fontmap.c:
* pango/pango-font.h:
* pango/fonts.c: New API pango_font_family_is_monospace. (#108728)
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | ChangeLog.pre-1-10 | 7 | ||||
-rw-r--r-- | ChangeLog.pre-1-4 | 7 | ||||
-rw-r--r-- | ChangeLog.pre-1-6 | 7 | ||||
-rw-r--r-- | ChangeLog.pre-1-8 | 7 | ||||
-rw-r--r-- | pango/fonts.c | 30 | ||||
-rw-r--r-- | pango/pango-font.h | 3 | ||||
-rw-r--r-- | pango/pangofc-fontmap.c | 48 | ||||
-rw-r--r-- | pango/pangowin32-fontmap.c | 9 |
9 files changed, 116 insertions, 9 deletions
@@ -1,5 +1,12 @@ 2003-02-23 Noah Levitt <nlevitt@columbia.edu> + * pango/pangowin32-fontmap.c: + * pango/pangofc-fontmap.c: + * pango/pango-font.h: + * pango/fonts.c: New API pango_font_family_is_monospace. (#108728) + +2003-02-23 Noah Levitt <nlevitt@columbia.edu> + * pango/fonts.c (pango_font_face_list_sizes): * pango/pangofc-fontmap.c (pango_fc_face_list_sizes): Handle NULL for sizes and n_sizes. diff --git a/ChangeLog.pre-1-10 b/ChangeLog.pre-1-10 index 5b105e00..299881c6 100644 --- a/ChangeLog.pre-1-10 +++ b/ChangeLog.pre-1-10 @@ -1,5 +1,12 @@ 2003-02-23 Noah Levitt <nlevitt@columbia.edu> + * pango/pangowin32-fontmap.c: + * pango/pangofc-fontmap.c: + * pango/pango-font.h: + * pango/fonts.c: New API pango_font_family_is_monospace. (#108728) + +2003-02-23 Noah Levitt <nlevitt@columbia.edu> + * pango/fonts.c (pango_font_face_list_sizes): * pango/pangofc-fontmap.c (pango_fc_face_list_sizes): Handle NULL for sizes and n_sizes. diff --git a/ChangeLog.pre-1-4 b/ChangeLog.pre-1-4 index 5b105e00..299881c6 100644 --- a/ChangeLog.pre-1-4 +++ b/ChangeLog.pre-1-4 @@ -1,5 +1,12 @@ 2003-02-23 Noah Levitt <nlevitt@columbia.edu> + * pango/pangowin32-fontmap.c: + * pango/pangofc-fontmap.c: + * pango/pango-font.h: + * pango/fonts.c: New API pango_font_family_is_monospace. (#108728) + +2003-02-23 Noah Levitt <nlevitt@columbia.edu> + * pango/fonts.c (pango_font_face_list_sizes): * pango/pangofc-fontmap.c (pango_fc_face_list_sizes): Handle NULL for sizes and n_sizes. diff --git a/ChangeLog.pre-1-6 b/ChangeLog.pre-1-6 index 5b105e00..299881c6 100644 --- a/ChangeLog.pre-1-6 +++ b/ChangeLog.pre-1-6 @@ -1,5 +1,12 @@ 2003-02-23 Noah Levitt <nlevitt@columbia.edu> + * pango/pangowin32-fontmap.c: + * pango/pangofc-fontmap.c: + * pango/pango-font.h: + * pango/fonts.c: New API pango_font_family_is_monospace. (#108728) + +2003-02-23 Noah Levitt <nlevitt@columbia.edu> + * pango/fonts.c (pango_font_face_list_sizes): * pango/pangofc-fontmap.c (pango_fc_face_list_sizes): Handle NULL for sizes and n_sizes. diff --git a/ChangeLog.pre-1-8 b/ChangeLog.pre-1-8 index 5b105e00..299881c6 100644 --- a/ChangeLog.pre-1-8 +++ b/ChangeLog.pre-1-8 @@ -1,5 +1,12 @@ 2003-02-23 Noah Levitt <nlevitt@columbia.edu> + * pango/pangowin32-fontmap.c: + * pango/pangofc-fontmap.c: + * pango/pango-font.h: + * pango/fonts.c: New API pango_font_family_is_monospace. (#108728) + +2003-02-23 Noah Levitt <nlevitt@columbia.edu> + * pango/fonts.c (pango_font_face_list_sizes): * pango/pangofc-fontmap.c (pango_fc_face_list_sizes): Handle NULL for sizes and n_sizes. diff --git a/pango/fonts.c b/pango/fonts.c index b6515fca..aaa8c812 100644 --- a/pango/fonts.c +++ b/pango/fonts.c @@ -1361,6 +1361,36 @@ pango_font_family_list_faces (PangoFontFamily *family, PANGO_FONT_FAMILY_GET_CLASS (family)->list_faces (family, faces, n_faces); } +/** + * pango_font_family_is_monospace: + * @family: a #PangoFontFamily + * + * A monospace font is a font designed for text display where the the + * characters form a regular grid. For Western languages this would + * mean that the advance width of all characters are the same, but + * this categorization also includes Asian fonts which include + * double-width characters: characters that occupy two grid cells. + * g_unichar_iswide() returns a result that indicates whether a + * character is typically double-width in a monospace font. + * + * The best way to find out the grid-cell size is to call + * pango_font_metrics_get_approximate_digit_width(), since the results + * of pango_font_metrics_get_approximate_char_width() may be affected + * by double-width characters. + * + * Return value: TRUE if the family is monospace. + **/ +gboolean +pango_font_family_is_monospace (PangoFontFamily *family) +{ + g_return_val_if_fail (PANGO_IS_FONT_FAMILY (family), FALSE); + + if (PANGO_FONT_FAMILY_GET_CLASS (family)->is_monospace) + return PANGO_FONT_FAMILY_GET_CLASS (family)->is_monospace (family); + else + return FALSE; +} + /* * PangoFontFace */ diff --git a/pango/pango-font.h b/pango/pango-font.h index f9cabfb3..56b3b72f 100644 --- a/pango/pango-font.h +++ b/pango/pango-font.h @@ -193,6 +193,7 @@ void pango_font_family_list_faces (PangoFontFamily *family, PangoFontFace ***faces, int *n_faces); G_CONST_RETURN char *pango_font_family_get_name (PangoFontFamily *family); +gboolean pango_font_family_is_monospace (PangoFontFamily *family); #ifdef PANGO_ENABLE_BACKEND @@ -217,11 +218,11 @@ struct _PangoFontFamilyClass PangoFontFace ***faces, int *n_faces); const char * (*get_name) (PangoFontFamily *family); + gboolean (*is_monospace) (PangoFontFamily *family); /*< private >*/ /* Padding for future expansion */ - void (*_pango_reserved1) (void); void (*_pango_reserved2) (void); void (*_pango_reserved3) (void); void (*_pango_reserved4) (void); diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c index 47abfaff..c6011ce0 100644 --- a/pango/pangofc-fontmap.c +++ b/pango/pangofc-fontmap.c @@ -89,6 +89,8 @@ struct _PangoFcFamily PangoFcFace **faces; int n_faces; /* -1 == uninitialized */ + + int spacing; /* FC_SPACING */ }; struct _PangoFcPatternSet @@ -391,11 +393,13 @@ _pango_fc_font_map_remove (PangoFcFontMap *fcfontmap, static PangoFcFamily * create_family (PangoFcFontMap *fcfontmap, - const char *family_name) + const char *family_name, + int spacing) { PangoFcFamily *family = g_object_new (PANGO_FC_TYPE_FAMILY, NULL); family->fontmap = fcfontmap; family->family_name = g_strdup (family_name); + family->spacing = spacing; return family; } @@ -440,34 +444,49 @@ pango_fc_font_map_list_families (PangoFontMap *fontmap, if (priv->n_families < 0) { - FcObjectSet *os = FcObjectSetBuild (FC_FAMILY, NULL); + FcObjectSet *os = FcObjectSetBuild (FC_FAMILY, FC_SPACING, NULL); FcPattern *pat = FcPatternCreate (); - + /* use hash table to avoid duplicate listings if different faces in + * the same family have different spacing values */ + GHashTable *temp_family_hash; + fontset = FcFontList (NULL, pat, os); FcPatternDestroy (pat); FcObjectSetDestroy (os); priv->families = g_new (PangoFcFamily *, fontset->nfont + 3); /* 3 standard aliases */ + temp_family_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); count = 0; for (i = 0; i < fontset->nfont; i++) { FcChar8 *s; FcResult res; + int spacing; res = FcPatternGetString (fontset->fonts[i], FC_FAMILY, 0, (FcChar8 **) &s); g_assert (res == FcResultMatch); + + res = FcPatternGetInteger (fontset->fonts[i], FC_SPACING, 0, &spacing); + g_assert (res == FcResultMatch || res == FcResultNoMatch); + if (res == FcResultNoMatch) + spacing = FC_PROPORTIONAL; - if (!is_alias_family (s)) - priv->families[count++] = create_family (fcfontmap, (gchar *)s); + if (!is_alias_family (s) && !g_hash_table_lookup (temp_family_hash, s)) + { + PangoFcFamily *temp_family = create_family (fcfontmap, (gchar *)s, spacing); + g_hash_table_insert (temp_family_hash, g_strdup (s), s); + priv->families[count++] = temp_family; + } } FcFontSetDestroy (fontset); + g_hash_table_destroy (temp_family_hash); - priv->families[count++] = create_family (fcfontmap, "Sans"); - priv->families[count++] = create_family (fcfontmap, "Serif"); - priv->families[count++] = create_family (fcfontmap, "Monospace"); + priv->families[count++] = create_family (fcfontmap, "Sans", FC_PROPORTIONAL); + priv->families[count++] = create_family (fcfontmap, "Serif", FC_PROPORTIONAL); + priv->families[count++] = create_family (fcfontmap, "Monospace", FC_MONO); priv->n_families = count; } @@ -1232,6 +1251,18 @@ pango_fc_face_list_sizes (PangoFontFace *face, FcObjectSetDestroy (objectset); } +static gboolean +pango_fc_family_is_monospace (PangoFontFamily *family) +{ + PangoFcFamily *fcfamily = PANGO_FC_FAMILY (family); + + return fcfamily->spacing == FC_MONO || +#ifdef FC_DUAL + fcfamily->spacing == FC_DUAL || +#endif + fcfamily->spacing == FC_CHARCELL; +} + static void pango_fc_face_class_init (PangoFontFaceClass *class) { @@ -1358,6 +1389,7 @@ pango_fc_family_class_init (PangoFontFamilyClass *class) { class->list_faces = pango_fc_family_list_faces; class->get_name = pango_fc_family_get_name; + class->is_monospace = pango_fc_family_is_monospace; } static void diff --git a/pango/pangowin32-fontmap.c b/pango/pangowin32-fontmap.c index 44e7b43e..4ecda7e5 100644 --- a/pango/pangowin32-fontmap.c +++ b/pango/pangowin32-fontmap.c @@ -324,11 +324,20 @@ pango_win32_family_get_name (PangoFontFamily *family) return win32family->family_name; } +static gboolean +pango_win32_family_is_monospace (PangoFontFamily *family) +{ + /* FIXME: implement me */ + g_warning ("is_monospace not implemented for win32 backend"); + return FALSE; +} + static void pango_win32_family_class_init (PangoFontFamilyClass *class) { class->list_faces = pango_win32_family_list_faces; class->get_name = pango_win32_family_get_name; + class->is_monospace = pango_win32_family_is_monospace; } GType |