[pango/family-face-api: 56/56] Add pango_font_get_face



commit cd54d6cd189a3b72d262a17fb4bf44fd573f3bc5
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Aug 13 23:15:00 2019 -0400

    Add pango_font_get_face
    
    Since we've run out of slots in PangoFontClass,
    this is implemented with a vfunc in PangoFontMapClass.

 docs/pango-sections.txt       |  1 +
 pango/fonts.c                 | 18 ++++++++++++++++++
 pango/pango-font.h            |  3 +++
 pango/pango-fontmap-private.h |  1 -
 pango/pango-fontmap.c         |  1 -
 pango/pango-fontmap.h         |  6 ++----
 pango/pangocoretext-fontmap.c | 10 ++++++++++
 pango/pangofc-fontmap.c       | 24 ++++++++++++++++++++++++
 pango/pangowin32-fontmap.c    | 11 ++++++++++-
 9 files changed, 68 insertions(+), 7 deletions(-)
---
diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt
index a409f70c..0726f55e 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
diff --git a/pango/fonts.c b/pango/fonts.c
index 6a768058..1ff6ef78 100644
--- a/pango/fonts.c
+++ b/pango/fonts.c
@@ -1880,6 +1880,24 @@ pango_font_get_font_map (PangoFont *font)
     return NULL;
 }
 
+/**
+ * pango_font_get_face:
+ * @font: a #PangoFont
+ *
+ * Gets the #PangoFontFace to which @font belongs.
+ *
+ * Returns: (transfer none): the #PangoFontFace
+ *
+ * Since: 1.44
+ */
+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
diff --git a/pango/pango-font.h b/pango/pango-font.h
index 6e0dfa9a..c42e89d7 100644
--- a/pango/pango-font.h
+++ b/pango/pango-font.h
@@ -647,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_44
+PangoFontFace *       pango_font_get_face          (PangoFont        *font);
+
 PANGO_AVAILABLE_IN_1_44
 gboolean              pango_font_has_char          (PangoFont        *font,
                                                     gunichar          wc);
diff --git a/pango/pango-fontmap-private.h b/pango/pango-fontmap-private.h
index 3452fbca..935fd713 100644
--- a/pango/pango-fontmap-private.h
+++ b/pango/pango-fontmap-private.h
@@ -31,7 +31,6 @@ 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 47096e8b..1fd3712f 100644
--- a/pango/pango-fontmap.c
+++ b/pango/pango-fontmap.c
@@ -390,4 +390,3 @@ pango_font_map_get_family (PangoFontMap *fontmap,
 
   return PANGO_FONT_MAP_GET_CLASS (fontmap)->get_family (fontmap, name);
 }
-
diff --git a/pango/pango-fontmap.h b/pango/pango-fontmap.h
index 6552dff4..7f2f5ac9 100644
--- a/pango/pango-fontmap.h
+++ b/pango/pango-fontmap.h
@@ -117,10 +117,8 @@ struct _PangoFontMapClass
   PangoFontFamily * (*get_family) (PangoFontMap               *fontmap,
                                    const char                 *name);
 
-  /*< private >*/
-
-  /* Padding for future expansion */
-  void (*_pango_reserved1) (void);
+  PangoFontFace *   (*get_face)   (PangoFontMap               *fontmap,
+                                   PangoFont                  *font);
 };
 
 PANGO_AVAILABLE_IN_ALL
diff --git a/pango/pangocoretext-fontmap.c b/pango/pangocoretext-fontmap.c
index b3d9d71c..5a81e388 100644
--- a/pango/pangocoretext-fontmap.c
+++ b/pango/pangocoretext-fontmap.c
@@ -1511,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)
 {
@@ -1525,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 dd066cd3..03d508dd 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -228,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);
@@ -1193,6 +1196,7 @@ pango_fc_font_map_class_init (PangoFcFontMapClass *class)
   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;
 }
 
@@ -1709,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,
diff --git a/pango/pangowin32-fontmap.c b/pango/pangowin32-fontmap.c
index ccdd69bd..905fdee2 100644
--- a/pango/pangowin32-fontmap.c
+++ b/pango/pangowin32-fontmap.c
@@ -764,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++)
@@ -784,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)
 {
@@ -797,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 ();
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]