[pango/better-space-size: 2/4] Add a private api to get the font size




commit c3866592cdc45877e2fa7e0181d4c83ead059842
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Dec 21 07:49:45 2021 -0500

    Add a private api to get the font size
    
    Add a private vfunc to get the (absolute) size
    of a font. This default implementation just
    pulls it out of the font description, but we
    can do implement this cheaper without copying
    the font description.

 pango/fonts.c              | 14 ++++++++++++++
 pango/pango-font-private.h |  8 +++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)
---
diff --git a/pango/fonts.c b/pango/fonts.c
index 35527e7a..2054dd31 100644
--- a/pango/fonts.c
+++ b/pango/fonts.c
@@ -1761,6 +1761,19 @@ pango_font_default_get_matrix (PangoFont   *font,
   *matrix = (PangoMatrix) PANGO_MATRIX_INIT;
 }
 
+static int
+pango_font_default_get_absolute_size (PangoFont *font)
+{
+  PangoFontDescription *desc;
+  int size;
+
+  desc = pango_font_describe_with_absolute_size (font);
+  size = pango_font_description_get_size (desc);
+  pango_font_description_free (desc);
+
+  return size;
+}
+
 static void
 pango_font_class_init (PangoFontClass *class G_GNUC_UNUSED)
 {
@@ -1777,6 +1790,7 @@ pango_font_class_init (PangoFontClass *class G_GNUC_UNUSED)
   pclass->has_char = pango_font_default_has_char;
   pclass->get_face = pango_font_default_get_face;
   pclass->get_matrix = pango_font_default_get_matrix;
+  pclass->get_absolute_size = pango_font_default_get_absolute_size;
 }
 
 static void
diff --git a/pango/pango-font-private.h b/pango/pango-font-private.h
index 1e38371d..885e38c1 100644
--- a/pango/pango-font-private.h
+++ b/pango/pango-font-private.h
@@ -47,6 +47,7 @@ typedef struct {
   PangoFontFace *  (* get_face) (PangoFont *font);
   void             (* get_matrix) (PangoFont   *font,
                                    PangoMatrix *matrix);
+  int              (* get_absolute_size) (PangoFont *font);
 } PangoFontClassPrivate;
 
 gboolean pango_font_is_hinted         (PangoFont *font);
@@ -55,7 +56,12 @@ 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);
+  PangoFontClassPrivate *priv = g_type_class_get_private (klass, PANGO_TYPE_FONT);
+  return priv->get_absolute_size (font);
+}
 
 G_END_DECLS
 


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