diff options
-rw-r--r-- | docs/pango-sections.txt | 4 | ||||
-rw-r--r-- | pango/fonts.c | 87 | ||||
-rw-r--r-- | pango/pango-font.h | 17 | ||||
-rw-r--r-- | pango/pango-fontmap-private.h | 2 | ||||
-rw-r--r-- | pango/pango-fontmap.c | 51 | ||||
-rw-r--r-- | pango/pango-fontmap.h | 11 | ||||
-rw-r--r-- | pango/pangocoretext-fontmap.c | 19 | ||||
-rw-r--r-- | pango/pangofc-fontmap.c | 146 | ||||
-rw-r--r-- | pango/pangowin32-fontmap.c | 26 | ||||
-rw-r--r-- | pango/pangowin32-private.h | 1 |
10 files changed, 327 insertions, 37 deletions
diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt index e4056773..70c4378c 100644 --- a/docs/pango-sections.txt +++ b/docs/pango-sections.txt @@ -251,6 +251,7 @@ PangoFont pango_font_find_shaper pango_font_describe pango_font_describe_with_absolute_size +pango_font_get_face pango_font_get_coverage pango_font_has_char pango_font_get_glyph_extents @@ -264,12 +265,14 @@ pango_font_family_get_name pango_font_family_is_monospace pango_font_family_is_variable pango_font_family_list_faces +pango_font_family_get_face <SUBSECTION> PangoFontFace pango_font_face_get_face_name pango_font_face_list_sizes pango_font_face_describe pango_font_face_is_synthesized +pango_font_face_get_family <SUBSECTION> PangoFontMap PangoFontMapClass @@ -277,6 +280,7 @@ pango_font_map_create_context pango_font_map_load_font pango_font_map_load_fontset pango_font_map_list_families +pango_font_map_get_family pango_font_map_get_serial pango_font_map_changed <SUBSECTION> diff --git a/pango/fonts.c b/pango/fonts.c index 4ffa0378..9e6325b7 100644 --- a/pango/fonts.c +++ b/pango/fonts.c @@ -1881,6 +1881,24 @@ pango_font_get_font_map (PangoFont *font) } /** + * pango_font_get_face: + * @font: a #PangoFont + * + * Gets the #PangoFontFace to which @font belongs. + * + * Returns: (transfer none): the #PangoFontFace + * + * Since: 1.46 + */ +PangoFontFace * +pango_font_get_face (PangoFont *font) +{ + PangoFontMap *map = pango_font_get_font_map (font); + + return PANGO_FONT_MAP_GET_CLASS (map)->get_face (map,font); +} + +/** * pango_font_get_hb_font: (skip) * @font: a #PangoFont * @@ -2160,9 +2178,13 @@ pango_font_metrics_get_strikethrough_thickness (PangoFontMetrics *metrics) G_DEFINE_ABSTRACT_TYPE (PangoFontFamily, pango_font_family, G_TYPE_OBJECT) +static PangoFontFace *pango_font_family_real_get_face (PangoFontFamily *family, + const char *name); + static void pango_font_family_class_init (PangoFontFamilyClass *class G_GNUC_UNUSED) { + class->get_face = pango_font_family_real_get_face; } static void @@ -2212,6 +2234,52 @@ pango_font_family_list_faces (PangoFontFamily *family, PANGO_FONT_FAMILY_GET_CLASS (family)->list_faces (family, faces, n_faces); } +static PangoFontFace * +pango_font_family_real_get_face (PangoFontFamily *family, + const char *name) +{ + PangoFontFace **faces; + int n_faces; + PangoFontFace *face; + int i; + + pango_font_family_list_faces (family, &faces, &n_faces); + + face = NULL; + for (i = 0; i < n_faces; i++) + { + if (strcmp (name, pango_font_face_get_face_name (faces[i])) == 0) + { + face = faces[i]; + break; + } + } + + g_free (faces); + + return face; +} + +/** + * pango_font_family_get_face: + * @family: a #PangoFontFamily + * @name: the name of a face + * + * Gets the #PangoFontFace of @family with the given name. + * + * Returns: (transfer none): the #PangoFontFace + * + * Since: 1.46 + */ +PangoFontFace * +pango_font_family_get_face (PangoFontFamily *family, + const char *name) +{ + g_return_val_if_fail (PANGO_IS_FONT_FAMILY (family), NULL); + + return PANGO_FONT_FAMILY_GET_CLASS (family)->get_face (family, name); +} + /** * pango_font_family_is_monospace: * @family: a #PangoFontFamily @@ -2382,6 +2450,25 @@ pango_font_face_list_sizes (PangoFontFace *face, } /** + * pango_font_face_get_family: + * @face: a #PangoFontFace + * + * Gets the #PangoFontFamily that @face + * belongs to. + * + * Returns: (transfer none): the #PangoFontFamily + * + * Since: 1.46 + */ +PangoFontFamily * +pango_font_face_get_family (PangoFontFace *face) +{ + g_return_val_if_fail (PANGO_IS_FONT_FACE (face), NULL); + + return PANGO_FONT_FACE_GET_CLASS (face)->get_family (face); +} + +/** * pango_font_has_char: * @font: a #PangoFont * @wc: a Unicode character diff --git a/pango/pango-font.h b/pango/pango-font.h index 70c24d20..ba1ea3ae 100644 --- a/pango/pango-font.h +++ b/pango/pango-font.h @@ -428,11 +428,14 @@ struct _PangoFontFamilyClass gboolean (*is_monospace) (PangoFontFamily *family); gboolean (*is_variable) (PangoFontFamily *family); + PangoFontFace * (*get_face) (PangoFontFamily *family, + const char *name); + + /*< private >*/ /* Padding for future expansion */ void (*_pango_reserved2) (void); - void (*_pango_reserved3) (void); }; #endif /* PANGO_DISABLE_DEPRECATED */ @@ -451,6 +454,10 @@ gboolean pango_font_family_is_monospace (PangoFontFamily *family) G_G PANGO_AVAILABLE_IN_1_44 gboolean pango_font_family_is_variable (PangoFontFamily *family) G_GNUC_PURE; +PANGO_AVAILABLE_IN_1_46 +PangoFontFace *pango_font_family_get_face (PangoFontFamily *family, + const char *name); + /* * PangoFontFace @@ -507,6 +514,7 @@ struct _PangoFontFaceClass int **sizes, int *n_sizes); gboolean (*is_synthesized) (PangoFontFace *face); + PangoFontFamily * (*get_family) (PangoFontFace *face); /*< private >*/ @@ -531,6 +539,9 @@ void pango_font_face_list_sizes (PangoFontFace *face, PANGO_AVAILABLE_IN_1_18 gboolean pango_font_face_is_synthesized (PangoFontFace *face) G_GNUC_PURE; +PANGO_AVAILABLE_IN_1_46 +PangoFontFamily * pango_font_face_get_family (PangoFontFace *face); + /* * PangoFont @@ -636,6 +647,9 @@ void pango_font_get_glyph_extents (PangoFont *font, PANGO_AVAILABLE_IN_1_10 PangoFontMap *pango_font_get_font_map (PangoFont *font); +PANGO_AVAILABLE_IN_1_46 +PangoFontFace * pango_font_get_face (PangoFont *font); + PANGO_AVAILABLE_IN_1_44 gboolean pango_font_has_char (PangoFont *font, gunichar wc); @@ -647,7 +661,6 @@ void pango_font_get_features (PangoFont *font, PANGO_AVAILABLE_IN_1_44 hb_font_t * pango_font_get_hb_font (PangoFont *font); - /** * PANGO_GLYPH_EMPTY: * diff --git a/pango/pango-fontmap-private.h b/pango/pango-fontmap-private.h index be06bd8f..935fd713 100644 --- a/pango/pango-fontmap-private.h +++ b/pango/pango-fontmap-private.h @@ -28,11 +28,9 @@ G_BEGIN_DECLS - PANGO_DEPRECATED_IN_1_38 const char *pango_font_map_get_shape_engine_type (PangoFontMap *fontmap); - G_END_DECLS #endif /* __PANGO_FONTMAP_PRIVATE_H__ */ diff --git a/pango/pango-fontmap.c b/pango/pango-fontmap.c index 46054ec1..54ac5d0d 100644 --- a/pango/pango-fontmap.c +++ b/pango/pango-fontmap.c @@ -31,12 +31,16 @@ static PangoFontset *pango_font_map_real_load_fontset (PangoFontMap PangoLanguage *language); +static PangoFontFamily *pango_font_map_real_get_family (PangoFontMap *fontmap, + const char *name); + G_DEFINE_ABSTRACT_TYPE (PangoFontMap, pango_font_map, G_TYPE_OBJECT) static void pango_font_map_class_init (PangoFontMapClass *class) { class->load_fontset = pango_font_map_real_load_fontset; + class->get_family = pango_font_map_real_get_family; } static void @@ -339,3 +343,50 @@ pango_font_map_changed (PangoFontMap *fontmap) if (PANGO_FONT_MAP_GET_CLASS (fontmap)->changed) PANGO_FONT_MAP_GET_CLASS (fontmap)->changed (fontmap); } + +static PangoFontFamily * +pango_font_map_real_get_family (PangoFontMap *fontmap, + const char *name) +{ + PangoFontFamily **families; + int n_families; + PangoFontFamily *family; + int i; + + pango_font_map_list_families (fontmap, &families, &n_families); + + family = NULL; + + for (i = 0; i < n_families; i++) + { + if (strcmp (name, pango_font_family_get_name (families[i])) == 0) + { + family = families[i]; + break; + } + } + + g_free (families); + + return family; +} + +/** + * pango_font_map_get_family: + * @fontmap: a #PangoFontMap + * @name: a family name + * + * Gets a font family by name. + * + * Returns: (transfer none): the #PangoFontFamily + * + * Since: 1.46 + */ +PangoFontFamily * +pango_font_map_get_family (PangoFontMap *fontmap, + const char *name) +{ + g_return_val_if_fail (PANGO_IS_FONT_MAP (fontmap), NULL); + + return PANGO_FONT_MAP_GET_CLASS (fontmap)->get_family (fontmap, name); +} diff --git a/pango/pango-fontmap.h b/pango/pango-fontmap.h index b6206f1d..f30780ee 100644 --- a/pango/pango-fontmap.h +++ b/pango/pango-fontmap.h @@ -114,11 +114,11 @@ struct _PangoFontMapClass guint (*get_serial) (PangoFontMap *fontmap); void (*changed) (PangoFontMap *fontmap); - /*< private >*/ + PangoFontFamily * (*get_family) (PangoFontMap *fontmap, + const char *name); - /* Padding for future expansion */ - void (*_pango_reserved1) (void); - void (*_pango_reserved2) (void); + PangoFontFace * (*get_face) (PangoFontMap *fontmap, + PangoFont *font); }; PANGO_AVAILABLE_IN_ALL @@ -143,6 +143,9 @@ guint pango_font_map_get_serial (PangoFontMap *fontma PANGO_AVAILABLE_IN_1_34 void pango_font_map_changed (PangoFontMap *fontmap); +PANGO_AVAILABLE_IN_1_46 +PangoFontFamily *pango_font_map_get_family (PangoFontMap *fontmap, + const char *name); G_END_DECLS diff --git a/pango/pangocoretext-fontmap.c b/pango/pangocoretext-fontmap.c index 038287a0..5a81e388 100644 --- a/pango/pangocoretext-fontmap.c +++ b/pango/pangocoretext-fontmap.c @@ -559,6 +559,14 @@ pango_core_text_face_is_synthesized (PangoFontFace *face) return cface->synthetic_italic; } +static PangoFontFamily * +pango_core_text_face_get_family (PangoFontFace *face) +{ + PangoCoreTextFace *cface = PANGO_CORE_TEXT_FACE (face); + + return PANGO_FONT_FAMILY (cface->family); +} + static void pango_core_text_face_class_init (PangoCoreTextFaceClass *klass) { @@ -571,6 +579,7 @@ pango_core_text_face_class_init (PangoCoreTextFaceClass *klass) pfclass->get_face_name = pango_core_text_face_get_face_name; pfclass->list_sizes = pango_core_text_face_list_sizes; pfclass->is_synthesized = pango_core_text_face_is_synthesized; + pfclass->get_family = pango_core_text_face_get_family; } /* @@ -1502,6 +1511,15 @@ pango_core_text_font_map_init (PangoCoreTextFontMap *ctfontmap) } } +static PangoFontFace * +pango_core_text_font_map_get_face (PangoFontMap *fontmap, + PangoFont *font) +{ + PangoCoreTextFont *cfont = PANGO_CORE_TEXT_FONT (font); + + return PANGO_FONT_FACE (_pango_core_text_font_get_face (cfont)); +} + static void pango_core_text_font_map_class_init (PangoCoreTextFontMapClass *class) { @@ -1516,6 +1534,7 @@ pango_core_text_font_map_class_init (PangoCoreTextFontMapClass *class) fontmap_class->shape_engine_type = PANGO_RENDER_TYPE_CORE_TEXT; fontmap_class->get_serial = pango_core_text_font_map_get_serial; fontmap_class->changed = pango_core_text_font_map_changed; + fontmap_class->get_face = pango_core_text_font_map_get_face; } /* diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c index 535a6f0e..03d508dd 100644 --- a/pango/pangofc-fontmap.c +++ b/pango/pangofc-fontmap.c @@ -219,6 +219,8 @@ static PangoFontset *pango_fc_font_map_load_fontset (PangoFontMap static void pango_fc_font_map_list_families (PangoFontMap *fontmap, PangoFontFamily ***families, int *n_families); +static PangoFontFamily *pango_fc_font_map_get_family (PangoFontMap *fontmap, + const char *name); static double pango_fc_font_map_get_resolution (PangoFcFontMap *fcfontmap, PangoContext *context); @@ -226,6 +228,9 @@ static PangoFont *pango_fc_font_map_new_font (PangoFcFontMap *fontmap, PangoFcFontsetKey *fontset_key, FcPattern *match); +static PangoFontFace *pango_fc_font_map_get_face (PangoFontMap *fontmap, + PangoFont *font); + static guint pango_fc_font_face_data_hash (PangoFcFontFaceData *key); static gboolean pango_fc_font_face_data_equal (PangoFcFontFaceData *key1, PangoFcFontFaceData *key2); @@ -1190,6 +1195,8 @@ pango_fc_font_map_class_init (PangoFcFontMapClass *class) fontmap_class->load_font = pango_fc_font_map_load_font; fontmap_class->load_fontset = pango_fc_font_map_load_fontset; fontmap_class->list_families = pango_fc_font_map_list_families; + fontmap_class->get_family = pango_fc_font_map_get_family; + fontmap_class->get_face = pango_fc_font_map_get_face; fontmap_class->shape_engine_type = PANGO_RENDER_TYPE_FC; } @@ -1356,26 +1363,13 @@ is_alias_family (const char *family_name) } static void -pango_fc_font_map_list_families (PangoFontMap *fontmap, - PangoFontFamily ***families, - int *n_families) +ensure_families (PangoFcFontMap *fcfontmap) { - PangoFcFontMap *fcfontmap = PANGO_FC_FONT_MAP (fontmap); PangoFcFontMapPrivate *priv = fcfontmap->priv; FcFontSet *fontset; int i; int count; - if (priv->closed) - { - if (families) - *families = NULL; - if (n_families) - *n_families = 0; - - return; - } - if (priv->n_families < 0) { FcObjectSet *os = FcObjectSetBuild (FC_FAMILY, FC_SPACING, FC_STYLE, FC_WEIGHT, FC_WIDTH, FC_SLANT, @@ -1448,6 +1442,27 @@ pango_fc_font_map_list_families (PangoFontMap *fontmap, priv->n_families = count; } +} + +static void +pango_fc_font_map_list_families (PangoFontMap *fontmap, + PangoFontFamily ***families, + int *n_families) +{ + PangoFcFontMap *fcfontmap = PANGO_FC_FONT_MAP (fontmap); + PangoFcFontMapPrivate *priv = fcfontmap->priv; + + if (priv->closed) + { + if (families) + *families = NULL; + if (n_families) + *n_families = 0; + + return; + } + + ensure_families (fcfontmap); if (n_families) *n_families = priv->n_families; @@ -1456,6 +1471,29 @@ pango_fc_font_map_list_families (PangoFontMap *fontmap, *families = g_memdup (priv->families, priv->n_families * sizeof (PangoFontFamily *)); } +static PangoFontFamily * +pango_fc_font_map_get_family (PangoFontMap *fontmap, + const char *name) +{ + PangoFcFontMap *fcfontmap = PANGO_FC_FONT_MAP (fontmap); + PangoFcFontMapPrivate *priv = fcfontmap->priv; + int i; + + if (priv->closed) + return NULL; + + ensure_families (fcfontmap); + + for (i = 0; i < priv->n_families; i++) + { + PangoFontFamily *family = PANGO_FONT_FAMILY (priv->families[i]); + if (strcmp (name, pango_font_family_get_name (family)) == 0) + return family; + } + + return NULL; +} + static double pango_fc_convert_weight_to_fc (PangoWeight pango_weight) { @@ -1675,6 +1713,26 @@ pango_fc_font_map_new_font (PangoFcFontMap *fcfontmap, return (PangoFont *)fcfont; } +static PangoFontFace * +pango_fc_font_map_get_face (PangoFontMap *fontmap, + PangoFont *font) +{ + PangoFcFont *fcfont = PANGO_FC_FONT (font); + FcResult res; + const char *s; + PangoFontFamily *family; + + res = FcPatternGetString (fcfont->font_pattern, FC_FAMILY, 0, (FcChar8 **) &s); + g_assert (res == FcResultMatch); + + family = pango_font_map_get_family (fontmap, s); + + res = FcPatternGetString (fcfont->font_pattern, FC_STYLE, 0, (FcChar8 **)(void*)&s); + g_assert (res == FcResultMatch); + + return pango_font_family_get_face (family, s); +} + static void pango_fc_default_substitute (PangoFcFontMap *fontmap, PangoFcFontsetKey *fontsetkey, @@ -2493,6 +2551,14 @@ pango_fc_face_is_synthesized (PangoFontFace *face) return fcface->fake; } +static PangoFontFamily * +pango_fc_face_get_family (PangoFontFace *face) +{ + PangoFcFace *fcface = PANGO_FC_FACE (face); + + return PANGO_FONT_FAMILY (fcface->family); +} + static void pango_fc_face_finalize (GObject *object) { @@ -2520,6 +2586,7 @@ pango_fc_face_class_init (PangoFcFaceClass *class) class->get_face_name = pango_fc_face_get_face_name; class->list_sizes = pango_fc_face_list_sizes; class->is_synthesized = pango_fc_face_is_synthesized; + class->get_family = pango_fc_face_get_family; } @@ -2549,20 +2616,10 @@ create_face (PangoFcFamily *fcfamily, } static void -pango_fc_family_list_faces (PangoFontFamily *family, - PangoFontFace ***faces, - int *n_faces) +ensure_faces (PangoFcFamily *fcfamily) { - PangoFcFamily *fcfamily = PANGO_FC_FAMILY (family); PangoFcFontMap *fcfontmap = fcfamily->fontmap; - PangoFcFontMapPrivate *priv; - - *faces = NULL; - *n_faces = 0; - if (G_UNLIKELY (!fcfontmap)) - return; - - priv = fcfontmap->priv; + PangoFcFontMapPrivate *priv = fcfontmap->priv; if (fcfamily->n_faces < 0) { @@ -2671,6 +2728,22 @@ pango_fc_family_list_faces (PangoFontFamily *family, fcfamily->faces = faces; } } +} + +static void +pango_fc_family_list_faces (PangoFontFamily *family, + PangoFontFace ***faces, + int *n_faces) +{ + PangoFcFamily *fcfamily = PANGO_FC_FAMILY (family); + + *faces = NULL; + *n_faces = 0; + + if (G_UNLIKELY (!fcfamily->fontmap)) + return; + + ensure_faces (fcfamily); if (n_faces) *n_faces = fcfamily->n_faces; @@ -2679,6 +2752,26 @@ pango_fc_family_list_faces (PangoFontFamily *family, *faces = g_memdup (fcfamily->faces, fcfamily->n_faces * sizeof (PangoFontFace *)); } +static PangoFontFace * +pango_fc_family_get_face (PangoFontFamily *family, + const char *name) +{ + PangoFcFamily *fcfamily = PANGO_FC_FAMILY (family); + int i; + + ensure_faces (fcfamily); + + for (i = 0; i < fcfamily->n_faces; i++) + { + PangoFontFace *face = PANGO_FONT_FACE (fcfamily->faces[i]); + + if (strcmp (name, pango_font_face_get_face_name (face)) == 0) + return face; + } + + return NULL; +} + static const char * pango_fc_family_get_name (PangoFontFamily *family) { @@ -2732,6 +2825,7 @@ pango_fc_family_class_init (PangoFcFamilyClass *class) object_class->finalize = pango_fc_family_finalize; class->list_faces = pango_fc_family_list_faces; + class->get_face = pango_fc_family_get_face; class->get_name = pango_fc_family_get_name; class->is_monospace = pango_fc_family_is_monospace; class->is_variable = pango_fc_family_is_variable; diff --git a/pango/pangowin32-fontmap.c b/pango/pangowin32-fontmap.c index 1c0b70f2..905fdee2 100644 --- a/pango/pangowin32-fontmap.c +++ b/pango/pangowin32-fontmap.c @@ -690,6 +690,8 @@ create_standard_family (PangoWin32FontMap *win32fontmap, new_face->cached_fonts = NULL; + new_face->family = new_family; + new_family->faces = g_slist_append (new_family->faces, new_face); p = p->next; @@ -762,7 +764,6 @@ pango_win32_font_map_fontset_add_fonts (PangoFontMap *fontmap, PangoWin32FontMap *win32fontmap = PANGO_WIN32_FONT_MAP (fontmap); lookup_aliases (win32fontmap->aliases, family, &aliases, &n_aliases); - if (n_aliases) { for (j = 0; j < n_aliases; j++) @@ -782,6 +783,15 @@ pango_win32_font_map_fontset_add_fonts (PangoFontMap *fontmap, } } +static PangoFontFace * +pango_win32_font_map_get_face (PangoFontMap *fontmap, + PangoFont *font) +{ + PangoWin32Font *win32font = PANGO_WIN32_FONT (font); + + return PANGO_FONT_FACE (win32font->win32face); +} + static void _pango_win32_font_map_class_init (PangoWin32FontMapClass *class) { @@ -795,6 +805,7 @@ _pango_win32_font_map_class_init (PangoWin32FontMapClass *class) fontmap_class->load_fontset = pango_win32_font_map_load_fontset; fontmap_class->list_families = pango_win32_font_map_list_families; fontmap_class->shape_engine_type = PANGO_RENDER_TYPE_WIN32; + fontmap_class->get_face = pango_win32_font_map_get_face; pango_win32_get_dc (); } @@ -1633,12 +1644,12 @@ pango_win32_insert_font (PangoWin32FontMap *win32fontmap, win32face->cached_fonts = NULL; - win32family = + win32face->family = win32family = pango_win32_get_font_family (win32fontmap, pango_font_description_get_family (win32face->description)); if ((lfp->lfPitchAndFamily & 0xF0) == FF_MODERN) win32family->is_monospace = TRUE; - + win32family->faces = g_slist_append (win32family->faces, win32face); PING (("name=%s, length(faces)=%d", @@ -1711,6 +1722,14 @@ pango_win32_face_is_synthesized (PangoFontFace *face) return win32face->is_synthetic; } +static PangoFontFamily * +pango_win32_face_get_family (PangoFontFace *face) +{ + PangoWin32Face *win32face = PANGO_WIN32_FACE (face); + + return PANGO_FONT_FAMILY (win32face->family); +} + G_DEFINE_TYPE (PangoWin32Face, pango_win32_face, PANGO_TYPE_FONT_FACE) static void @@ -1743,6 +1762,7 @@ pango_win32_face_class_init (PangoFontFaceClass *class) class->get_face_name = pango_win32_face_get_face_name; class->list_sizes = pango_win32_face_list_sizes; class->is_synthesized = pango_win32_face_is_synthesized; + class->get_family = pango_win32_face_get_family; } static void diff --git a/pango/pangowin32-private.h b/pango/pangowin32-private.h index 9d9a0a73..082470e7 100644 --- a/pango/pangowin32-private.h +++ b/pango/pangowin32-private.h @@ -153,6 +153,7 @@ struct _PangoWin32Face { PangoFontFace parent_instance; + gpointer family; LOGFONTW logfontw; PangoFontDescription *description; PangoCoverage *coverage; |