[pango/strdup-avoidance: 2/3] font: Add private api to get the variant




commit 17f2d869f876ea10262ff6841b29fe86463a0d70
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Aug 27 20:51:06 2022 -0400

    font: Add private api to get the variant
    
    Add a private pango_font_get_variant, and implement
    it for PangoFcFont. This will let us avoid many
    pointless font description copies.

 pango/pango-font-private.h | 22 ++++++++++++++++++++++
 pango/pangofc-font.c       |  9 +++++++++
 2 files changed, 31 insertions(+)
---
diff --git a/pango/pango-font-private.h b/pango/pango-font-private.h
index 885e38c17..e95abc7a7 100644
--- a/pango/pango-font-private.h
+++ b/pango/pango-font-private.h
@@ -48,6 +48,7 @@ typedef struct {
   void             (* get_matrix) (PangoFont   *font,
                                    PangoMatrix *matrix);
   int              (* get_absolute_size) (PangoFont *font);
+  PangoVariant     (* get_variant) (PangoFont *font);
 } PangoFontClassPrivate;
 
 gboolean pango_font_is_hinted         (PangoFont *font);
@@ -56,6 +57,7 @@ void     pango_font_get_scale_factors (PangoFont *font,
                                        double    *y_scale);
 void     pango_font_get_matrix        (PangoFont   *font,
                                        PangoMatrix *matrix);
+
 static inline int pango_font_get_absolute_size (PangoFont *font)
 {
   GTypeClass *klass = (GTypeClass *) PANGO_FONT_GET_CLASS (font);
@@ -63,6 +65,26 @@ static inline int pango_font_get_absolute_size (PangoFont *font)
   return priv->get_absolute_size (font);
 }
 
+static inline PangoVariant
+pango_font_get_variant (PangoFont *font)
+{
+  GTypeClass *klass = (GTypeClass *) PANGO_FONT_GET_CLASS (font);
+  PangoFontClassPrivate *priv = g_type_class_get_private (klass, PANGO_TYPE_FONT);
+  if (priv->get_variant)
+    return priv->get_variant (font);
+  else
+    {
+      PangoFontDescription *desc;
+      PangoVariant variant;
+
+      desc = pango_font_describe (font);
+      variant = pango_font_description_get_variant (desc);
+      pango_font_description_free (desc);
+
+      return variant;
+    }
+}
+
 G_END_DECLS
 
 #endif /* __PANGO_FONT_PRIVATE_H__ */
diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c
index 02fb67fc6..053e93cdc 100644
--- a/pango/pangofc-font.c
+++ b/pango/pangofc-font.c
@@ -79,6 +79,7 @@ static void                 _pango_fc_font_get_scale_factors (PangoFont     *fon
 static void                 pango_fc_font_get_matrix      (PangoFont        *font,
                                                            PangoMatrix      *matrix);
 static int                  pango_fc_font_get_absolute_size (PangoFont        *font);
+static PangoVariant         pango_fc_font_get_variant       (PangoFont        *font);
 
 #define PANGO_FC_FONT_LOCK_FACE(font)  (PANGO_FC_FONT_GET_CLASS (font)->lock_face (font))
 #define PANGO_FC_FONT_UNLOCK_FACE(font)        (PANGO_FC_FONT_GET_CLASS (font)->unlock_face (font))
@@ -115,6 +116,7 @@ pango_fc_font_class_init (PangoFcFontClass *class)
   pclass->get_scale_factors = _pango_fc_font_get_scale_factors;
   pclass->get_matrix = pango_fc_font_get_matrix;
   pclass->get_absolute_size = pango_fc_font_get_absolute_size;
+  pclass->get_variant = pango_fc_font_get_variant;
 
   /**
    * PangoFcFont:pattern:
@@ -315,6 +317,13 @@ pango_fc_font_get_absolute_size (PangoFont *font)
   return 0;
 }
 
+static PangoVariant
+pango_fc_font_get_variant (PangoFont *font)
+{
+  PangoFcFont *fcfont = (PangoFcFont *)font;
+  return pango_font_description_get_variant (fcfont->description);
+}
+
 static PangoCoverage *
 pango_fc_font_get_coverage (PangoFont     *font,
                            PangoLanguage *language G_GNUC_UNUSED)


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