[pango/pango2: 80/84] Clean up the PangoFont hierarchy




commit 0bd9bb67ea0c811c3a0529ad8717e74a44d7330e
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Jun 11 14:26:03 2022 -0400

    Clean up the PangoFont hierarchy
    
    Move shared data up, add private setters.

 pango/pango-font-private.h     |  45 ++++++++++++-
 pango/pango-font.c             |  27 ++++----
 pango/pango-hbfont-private.h   |  19 ------
 pango/pango-hbfont.c           | 143 ++++++++++++++++++-----------------------
 pango/pango-userfont-private.h |   9 ---
 pango/pango-userfont.c         | 130 +++++++++++++++----------------------
 pango/pangocairo-font.c        |  66 ++++++++++---------
 pango/shape.c                  |  13 ++--
 8 files changed, 210 insertions(+), 242 deletions(-)
---
diff --git a/pango/pango-font-private.h b/pango/pango-font-private.h
index 82389f0ea..85928b233 100644
--- a/pango/pango-font-private.h
+++ b/pango/pango-font-private.h
@@ -33,7 +33,15 @@ struct _PangoFont
 {
   GObject parent_instance;
 
+  PangoFontFace *face;
+
   hb_font_t *hb_font;
+
+  int size; /* point size, scaled by PANGO_SCALE */
+  float dpi;
+  PangoGravity gravity;
+  PangoMatrix matrix;
+
 #ifdef HAVE_CAIRO
   cairo_font_options_t *options;
 #endif
@@ -51,7 +59,6 @@ struct _PangoFontClass
                                                 PangoRectangle *logical_rect);
   PangoFontMetrics *     (* get_metrics)        (PangoFont      *font,
                                                 PangoLanguage  *language);
-  PangoFontDescription * (* describe_absolute)  (PangoFont      *font);
   void                   (* get_features)       (PangoFont      *font,
                                                  hb_feature_t   *features,
                                                  guint           len,
@@ -64,7 +71,6 @@ struct _PangoFontClass
                                                  double         *y_scale);
   gboolean               (* has_char)           (PangoFont      *font,
                                                  gunichar        wc);
-  PangoFontFace *        (* get_face)           (PangoFont      *font);
   void                   (* get_matrix)         (PangoFont      *font,
                                                  PangoMatrix    *matrix);
   int                    (* get_absolute_size)  (PangoFont      *font);
@@ -73,6 +79,41 @@ struct _PangoFontClass
 #define PANGO_FONT_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), PANGO_TYPE_FONT, PangoFontClass))
 #define PANGO_FONT_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), PANGO_TYPE_FONT, PangoFontClass))
 
+static inline void
+pango_font_set_face (PangoFont     *font,
+                     PangoFontFace *face)
+{
+  font->face = g_object_ref (face);
+}
+
+static inline void
+pango_font_set_size (PangoFont *font,
+                     int        size)
+{
+  font->size = size;
+}
+
+static inline void
+pango_font_set_dpi (PangoFont *font,
+                    float      dpi)
+{
+  font->dpi = dpi;
+}
+
+static inline void
+pango_font_set_gravity (PangoFont    *font,
+                        PangoGravity  gravity)
+{
+  font->gravity = gravity;
+}
+
+static inline void
+pango_font_set_matrix (PangoFont         *font,
+                       const PangoMatrix *matrix)
+{
+  font->matrix = *matrix;
+}
+
 gboolean pango_font_is_hinted         (PangoFont *font);
 void     pango_font_get_scale_factors (PangoFont *font,
                                        double    *x_scale,
diff --git a/pango/pango-font.c b/pango/pango-font.c
index 698763ca3..96f24b097 100644
--- a/pango/pango-font.c
+++ b/pango/pango-font.c
@@ -46,6 +46,7 @@ pango_font_finalize (GObject *object)
 {
   PangoFont *font = PANGO_FONT (object);
 
+  g_object_unref (font->face);
   hb_font_destroy (font->hb_font);
 
   G_OBJECT_CLASS (pango_font_parent_class)->finalize (object);
@@ -54,7 +55,7 @@ pango_font_finalize (GObject *object)
 static PangoLanguage **
 pango_font_default_get_languages (PangoFont *font)
 {
-  return pango_font_face_get_languages (pango_font_get_face (font));
+  return pango_font_face_get_languages (font->face);
 }
 
 static gboolean
@@ -78,12 +79,6 @@ pango_font_default_has_char (PangoFont *font,
   return FALSE;
 }
 
-static PangoFontFace *
-pango_font_default_get_face (PangoFont *font)
-{
-  return NULL;
-}
-
 static void
 pango_font_default_get_matrix (PangoFont   *font,
                                PangoMatrix *matrix)
@@ -115,14 +110,15 @@ pango_font_class_init (PangoFontClass *class G_GNUC_UNUSED)
   class->is_hinted = pango_font_default_is_hinted;
   class->get_scale_factors = pango_font_default_get_scale_factors;
   class->has_char = pango_font_default_has_char;
-  class->get_face = pango_font_default_get_face;
   class->get_matrix = pango_font_default_get_matrix;
   class->get_absolute_size = pango_font_default_get_absolute_size;
 }
 
 static void
-pango_font_init (PangoFont *font G_GNUC_UNUSED)
+pango_font_init (PangoFont *font)
 {
+  font->gravity = PANGO_GRAVITY_AUTO;
+  font->matrix = (PangoMatrix) PANGO_MATRIX_INIT;
 }
 
 /**
@@ -158,15 +154,14 @@ pango_font_describe (PangoFont *font)
 PangoFontDescription *
 pango_font_describe_with_absolute_size (PangoFont *font)
 {
+  PangoFontDescription *desc;
+
   g_return_val_if_fail (font != NULL, NULL);
 
-  if (G_UNLIKELY (!PANGO_FONT_GET_CLASS (font)->describe_absolute))
-    {
-      g_warning ("describe_absolute not implemented for this font class, report this as a bug");
-      return pango_font_describe (font);
-    }
+  desc = pango_font_describe (font);
+  pango_font_description_set_absolute_size (desc, font->size * font->dpi / 72.);
 
-  return PANGO_FONT_GET_CLASS (font)->describe_absolute (font);
+  return desc;
 }
 
 /**
@@ -270,7 +265,7 @@ pango_font_get_metrics (PangoFont     *font,
 PangoFontFace *
 pango_font_get_face (PangoFont *font)
 {
-  return PANGO_FONT_GET_CLASS (font)->get_face (font);
+  return font->face;
 }
 
 /**
diff --git a/pango/pango-hbfont-private.h b/pango/pango-hbfont-private.h
index dbaa55cb7..6fef1a9c1 100644
--- a/pango/pango-hbfont-private.h
+++ b/pango/pango-hbfont-private.h
@@ -40,29 +40,10 @@ struct _HexBoxInfo
   double box_height;
 };
 
-typedef struct _CommonFont CommonFont;
-struct _CommonFont
-{
-  PangoFont parent_instance;
-
-  int size;
-  float dpi;
-  PangoGravity gravity;
-  PangoMatrix matrix;
-};
-
 struct _PangoHbFont
 {
   PangoFont parent_instance;
 
-  int size; /* point size, scaled by PANGO_SCALE */
-  float dpi;
-  PangoGravity gravity;
-  PangoMatrix matrix;
-
-  /* up to here shared with PangoUserFont */
-
-  PangoHbFace *face;
   hb_feature_t *features;
   unsigned int n_features;
   hb_variation_t *variations;
diff --git a/pango/pango-hbfont.c b/pango/pango-hbfont.c
index 78670bc4d..891ed3d90 100644
--- a/pango/pango-hbfont.c
+++ b/pango/pango-hbfont.c
@@ -331,6 +331,7 @@ collect_variations (hb_variation_t        *variations,
 static HexBoxInfo *
 create_hex_box_info (PangoHbFont *self)
 {
+  PangoFont *font = PANGO_FONT (self);
   const char hexdigits[] = "0123456789ABCDEF";
   hb_font_t *hb_font;
   PangoFont *mini_font;
@@ -346,16 +347,16 @@ create_hex_box_info (PangoHbFont *self)
   PangoContext *context;
   PangoFontMap *map;
 
-  if (!PANGO_FONT_FACE (self->face)->family)
+  if (!PANGO_FONT_FACE (font->face)->family)
     return NULL;
 
-  map = PANGO_FONT_FACE (self->face)->family->map;
+  map = PANGO_FONT_FACE (font->face)->family->map;
 
   if (!map)
     return NULL;
 
-  desc = pango_font_describe_with_absolute_size (PANGO_FONT (self));
-  hb_font = pango_font_get_hb_font (PANGO_FONT (self));
+  desc = pango_font_describe_with_absolute_size (font);
+  hb_font = pango_font_get_hb_font (font);
 
   /* Create mini_font description */
 
@@ -370,19 +371,19 @@ create_hex_box_info (PangoHbFont *self)
   pango_font_description_set_family_static (desc, "monospace");
 
   rows = 2;
-  mini_size = self->size / 2.2;
+  mini_size = font->size / 2.2;
 
   if (mini_size < 6.0)
     {
       rows = 1;
-      mini_size = MIN (MAX (self->size - 1, 0), 6.0);
+      mini_size = MIN (MAX (font->size - 1, 0), 6.0);
     }
 
   pango_font_description_set_size (desc, mini_size);
 
   /* Load mini_font */
   context = pango_font_map_create_context (map);
-  pango_context_set_matrix (context, &self->matrix);
+  pango_context_set_matrix (context, &font->matrix);
   pango_context_set_language (context, pango_script_get_sample_language (G_UNICODE_SCRIPT_LATIN));
 
   mini_font = pango_font_map_load_font (map, context, desc);
@@ -429,12 +430,13 @@ get_space_extents (PangoHbFont    *self,
                    PangoRectangle *ink_rect,
                    PangoRectangle *logical_rect)
 {
-  hb_font_t *hb_font = pango_font_get_hb_font (PANGO_FONT (self));
+  PangoFont *font = PANGO_FONT (self);
+  hb_font_t *hb_font = pango_font_get_hb_font (font);
   int width;
   hb_direction_t direction;
   hb_font_extents_t font_extents;
 
-  direction = PANGO_GRAVITY_IS_VERTICAL (self->gravity)
+  direction = PANGO_GRAVITY_IS_VERTICAL (font->gravity)
               ? HB_DIRECTION_TTB
               : HB_DIRECTION_LTR;
 
@@ -442,7 +444,7 @@ get_space_extents (PangoHbFont    *self,
 
   /* See https://docs.microsoft.com/en-us/typography/develop/character-design-standards/whitespace */
 
-  width = self->size / 4;
+  width = font->size / 4;
 
   if (ink_rect)
     {
@@ -527,8 +529,6 @@ G_DEFINE_TYPE (PangoHbFont, pango_hb_font, PANGO_TYPE_FONT)
 static void
 pango_hb_font_init (PangoHbFont *self)
 {
-  self->gravity = PANGO_GRAVITY_AUTO;
-  self->matrix = (PangoMatrix) PANGO_MATRIX_INIT;
 }
 
 static void
@@ -543,7 +543,6 @@ pango_hb_font_finalize (GObject *object)
 {
   PangoHbFont *self = PANGO_HB_FONT (object);
 
-  g_object_unref (self->face);
   g_free (self->variations);
   g_clear_pointer (&self->hex_box_info, hex_box_info_destroy);
 
@@ -554,26 +553,29 @@ static PangoFontDescription *
 pango_hb_font_describe (PangoFont *font)
 {
   PangoHbFont *self = PANGO_HB_FONT (font);
+  PangoHbFace *face = PANGO_HB_FACE (font->face);
   PangoFontDescription *desc;
   PangoVariant variant;
 
-  desc = pango_font_face_describe (PANGO_FONT_FACE (self->face));
-  pango_font_description_set_gravity (desc, self->gravity);
+  desc = pango_font_face_describe (font->face);
+  pango_font_description_set_gravity (desc, font->gravity);
+  pango_font_description_set_size (desc, font->size);
+
   variant = pango_variant_from_features (self->features, self->n_features);
   if (variant != PANGO_VARIANT_NORMAL)
     pango_font_description_set_variant (desc, variant);
-  if (self->n_variations > 0)
+  if (self->n_variations > 0 || face->n_variations > 0)
     {
       hb_variation_t *variations;
       unsigned int n_variations;
       char *str;
 
-      if (self->face->n_variations > 0)
+      if (face->n_variations > 0)
         {
-           variations = g_alloca (sizeof (hb_variation_t) * (self->n_variations + self->face->n_variations));
-           n_variations = merge_variations (self->face->variations, self->face->n_variations,
+           variations = g_alloca (sizeof (hb_variation_t) * (self->n_variations + face->n_variations));
+           n_variations = merge_variations (face->variations, face->n_variations,
                                             self->variations, self->n_variations,
-                                            variations, self->n_variations + self->face->n_variations);
+                                            variations, self->n_variations + face->n_variations);
         }
       else
         {
@@ -585,19 +587,6 @@ pango_hb_font_describe (PangoFont *font)
       pango_font_description_set_variations (desc, str);
       g_free (str);
     }
-  pango_font_description_set_size (desc, self->size);
-
-  return desc;
-}
-
-static PangoFontDescription *
-pango_hb_font_describe_absolute (PangoFont *font)
-{
-  PangoHbFont *self = PANGO_HB_FONT (font);
-  PangoFontDescription *desc;
-
-  desc = pango_hb_font_describe (font);
-  pango_font_description_set_absolute_size (desc, self->size * self->dpi / 72.);
 
   return desc;
 }
@@ -609,12 +598,13 @@ pango_hb_font_get_glyph_extents (PangoFont      *font,
                                  PangoRectangle *logical_rect)
 {
   PangoHbFont *self = PANGO_HB_FONT (font);
+  PangoHbFace *face = PANGO_HB_FACE (font->face);
   hb_font_t *hb_font = pango_font_get_hb_font (font);
   hb_glyph_extents_t extents;
   hb_direction_t direction;
   hb_font_extents_t font_extents;
 
-  direction = PANGO_GRAVITY_IS_VERTICAL (self->gravity)
+  direction = PANGO_GRAVITY_IS_VERTICAL (font->gravity)
               ? HB_DIRECTION_TTB
               : HB_DIRECTION_LTR;
 
@@ -653,17 +643,17 @@ pango_hb_font_get_glyph_extents (PangoFont      *font,
       r.width = extents.width;
       r.height = - extents.height;
 
-      if (self->face->matrix)
+      if (face->matrix)
         {
-          m.xx = self->face->matrix->xx;
-          m.yx = - self->face->matrix->yx;
-          m.xy = - self->face->matrix->xy;
-          m.yy = self->face->matrix->yy;
+          m.xx = face->matrix->xx;
+          m.yx = - face->matrix->yx;
+          m.xy = - face->matrix->xy;
+          m.yy = face->matrix->yy;
         }
 
       pango_matrix_transform_rectangle (&m, &r);
 
-      switch (self->gravity)
+      switch (font->gravity)
         {
         case PANGO_GRAVITY_AUTO:
         case PANGO_GRAVITY_SOUTH:
@@ -694,7 +684,7 @@ pango_hb_font_get_glyph_extents (PangoFont      *font,
           g_assert_not_reached ();
         }
 
-      if (PANGO_GRAVITY_IS_IMPROPER (self->gravity))
+      if (PANGO_GRAVITY_IS_IMPROPER (font->gravity))
         {
           PangoMatrix matrix = (PangoMatrix) PANGO_MATRIX_INIT;
           pango_matrix_scale (&matrix, -1, -1);
@@ -713,7 +703,7 @@ pango_hb_font_get_glyph_extents (PangoFont      *font,
       logical_rect->x = 0;
       logical_rect->height = extents.ascender - extents.descender;
 
-      switch (self->gravity)
+      switch (font->gravity)
         {
         case PANGO_GRAVITY_AUTO:
         case PANGO_GRAVITY_SOUTH:
@@ -736,7 +726,7 @@ pango_hb_font_get_glyph_extents (PangoFont      *font,
           g_assert_not_reached ();
         }
 
-      if (PANGO_GRAVITY_IS_IMPROPER (self->gravity))
+      if (PANGO_GRAVITY_IS_IMPROPER (font->gravity))
         {
           logical_rect->height = - logical_rect->height;
           logical_rect->y = - logical_rect->y;
@@ -801,6 +791,7 @@ static hb_font_t *
 pango_hb_font_create_hb_font (PangoFont *font)
 {
   PangoHbFont *self = PANGO_HB_FONT (font);
+  PangoHbFace *face = PANGO_HB_FACE (font->face);
   hb_font_t *hb_font;
   double x_scale, y_scale;
   unsigned int n_axes;
@@ -808,45 +799,45 @@ pango_hb_font_create_hb_font (PangoFont *font)
   float *coords;
   int size;
 
-  hb_font = hb_font_create (pango_hb_face_get_hb_face (self->face));
+  hb_font = hb_font_create (pango_hb_face_get_hb_face (face));
 
-  size = self->size * self->dpi / 72.f;
-  x_scale = self->face->x_scale;
-  y_scale = self->face->y_scale;
+  size = font->size * font->dpi / 72.f;
+  x_scale = face->x_scale;
+  y_scale = face->y_scale;
 
-  if (PANGO_GRAVITY_IS_IMPROPER (self->gravity))
+  if (PANGO_GRAVITY_IS_IMPROPER (font->gravity))
     {
       x_scale = - x_scale;
       y_scale = - y_scale;
     }
 
   hb_font_set_scale (hb_font, size * x_scale, size * y_scale);
-  hb_font_set_ptem (hb_font, self->size / PANGO_SCALE);
+  hb_font_set_ptem (hb_font, font->size / PANGO_SCALE);
 
 #if HB_VERSION_ATLEAST (3, 3, 0)
-  hb_font_set_synthetic_slant (hb_font, pango_matrix_get_slant_ratio (self->face->matrix));
+  hb_font_set_synthetic_slant (hb_font, pango_matrix_get_slant_ratio (face->matrix));
 #endif
 
-  if (self->face->instance_id >= 0)
-    hb_font_set_var_named_instance (hb_font, self->face->instance_id);
+  if (face->instance_id >= 0)
+    hb_font_set_var_named_instance (hb_font, face->instance_id);
 
-  if (self->n_variations > 0 || self->face->n_variations > 0)
+  if (self->n_variations > 0 || face->n_variations > 0)
     {
-      n_axes = hb_ot_var_get_axis_count (self->face->face);
+      n_axes = hb_ot_var_get_axis_count (face->face);
       axes = g_alloca (sizeof (hb_ot_var_axis_info_t) * n_axes);
       coords = g_alloca (sizeof (float) * n_axes);
 
-      hb_ot_var_get_axis_infos (self->face->face, 0, &n_axes, axes);
+      hb_ot_var_get_axis_infos (face->face, 0, &n_axes, axes);
 
-      if (self->face->instance_id >= 0)
-        hb_ot_var_named_instance_get_design_coords (self->face->face, self->face->instance_id, &n_axes, 
coords);
+      if (face->instance_id >= 0)
+        hb_ot_var_named_instance_get_design_coords (face->face, face->instance_id, &n_axes, coords);
       else
         {
           for (int i = 0; i < n_axes; i++)
             coords[axes[i].axis_index] = axes[i].default_value;
         }
 
-      collect_variations (self->face->variations, self->face->n_variations, n_axes, axes, coords);
+      collect_variations (face->variations, face->n_variations, n_axes, axes, coords);
       collect_variations (self->variations, self->n_variations, n_axes, axes, coords);
 
       hb_font_set_var_coords_design (hb_font, coords, n_axes);
@@ -865,24 +856,16 @@ pango_hb_font_has_char (PangoFont *font,
   return hb_font_get_nominal_glyph (hb_font, wc, &glyph);
 }
 
-static PangoFontFace *
-pango_hb_font_get_face (PangoFont *font)
-{
-  PangoHbFont *self = PANGO_HB_FONT (font);
-
-  return PANGO_FONT_FACE (self->face);
-}
-
 static void
 pango_hb_font_get_matrix (PangoFont   *font,
                           PangoMatrix *matrix)
 {
-  PangoHbFont *self = PANGO_HB_FONT (font);
+  PangoHbFace *face = PANGO_HB_FACE (font->face);
 
-  if (self->face->matrix)
+  if (face->matrix)
     {
-      *matrix = *self->face->matrix;
-      pango_matrix_scale (matrix, self->face->x_scale, self->face->y_scale);
+      *matrix = *face->matrix;
+      pango_matrix_scale (matrix, face->x_scale, face->y_scale);
     }
   else
     *matrix = (PangoMatrix) PANGO_MATRIX_INIT;
@@ -909,14 +892,12 @@ pango_hb_font_class_init (PangoHbFontClass *class)
   object_class->finalize = pango_hb_font_finalize;
 
   font_class->describe = pango_hb_font_describe;
-  font_class->describe_absolute = pango_hb_font_describe_absolute;
   font_class->get_glyph_extents = pango_hb_font_get_glyph_extents;
   font_class->get_metrics = pango_hb_font_get_metrics;
   font_class->create_hb_font = pango_hb_font_create_hb_font;
   font_class->get_features = pango_hb_font_get_features;
-  font_class->has_char = pango_hb_font_has_char;
-  font_class->get_face = pango_hb_font_get_face;
   font_class->get_matrix = pango_hb_font_get_matrix;
+  font_class->has_char = pango_hb_font_has_char;
 }
 
 /* }}} */
@@ -950,21 +931,23 @@ pango_hb_font_new (PangoHbFace       *face,
                    const PangoMatrix *matrix)
 {
   PangoHbFont *self;
+  PangoFont *font;
 
   self = g_object_new (PANGO_TYPE_HB_FONT, NULL);
 
-  self->face = g_object_ref (face);
+  font = PANGO_FONT (self);
+
+  pango_font_set_face (font, PANGO_FONT_FACE (face));
+  pango_font_set_size (font, size);
+  pango_font_set_dpi (font, dpi);
+  pango_font_set_gravity (font, gravity);
+  if (matrix)
+    pango_font_set_matrix (font, matrix);
 
-  self->size = size;
-  self->dpi = dpi;
   self->features = g_memdup2 (features, sizeof (hb_feature_t) * n_features);
   self->n_features = n_features;
   self->variations = g_memdup2 (variations, sizeof (hb_variation_t) * n_variations);
   self->n_variations = n_variations;
-  if (gravity != PANGO_GRAVITY_AUTO)
-    self->gravity = gravity;
-  if (matrix)
-    self->matrix = *matrix;
 
   return self;
 }
diff --git a/pango/pango-userfont-private.h b/pango/pango-userfont-private.h
index a3669a09f..a4e688b19 100644
--- a/pango/pango-userfont-private.h
+++ b/pango/pango-userfont-private.h
@@ -27,13 +27,4 @@
 struct _PangoUserFont
 {
   PangoFont parent_instance;
-
-  int size; /* point size, scaled by PANGO_SCALE */
-  float dpi;
-  PangoGravity gravity;
-  PangoMatrix matrix;
-
-  /* up to here shared with PangoHbFont */
-
-  PangoUserFace *face;
 };
diff --git a/pango/pango-userfont.c b/pango/pango-userfont.c
index cc1ea4d17..8649d7bd1 100644
--- a/pango/pango-userfont.c
+++ b/pango/pango-userfont.c
@@ -47,43 +47,24 @@ struct _PangoUserFontClass
 G_DEFINE_TYPE (PangoUserFont, pango_user_font, PANGO_TYPE_FONT)
 
 static void
-pango_user_font_init (PangoUserFont *self)
+pango_user_font_init (PangoUserFont *self G_GNUC_UNUSED)
 {
-  self->gravity = PANGO_GRAVITY_AUTO;
-  self->matrix = (PangoMatrix) PANGO_MATRIX_INIT;
 }
 
 static void
 pango_user_font_finalize (GObject *object)
 {
-  PangoUserFont *self = PANGO_USER_FONT (object);
-
-  g_object_unref (self->face);
-
   G_OBJECT_CLASS (pango_user_font_parent_class)->finalize (object);
 }
 
 static PangoFontDescription *
 pango_user_font_describe (PangoFont *font)
 {
-  PangoUserFont *self = PANGO_USER_FONT (font);
-  PangoFontDescription *desc;
-
-  desc = pango_font_face_describe (PANGO_FONT_FACE (self->face));
-  pango_font_description_set_gravity (desc, self->gravity);
-  pango_font_description_set_size (desc, self->size);
-
-  return desc;
-}
-
-static PangoFontDescription *
-pango_user_font_describe_absolute (PangoFont *font)
-{
-  PangoUserFont *self = PANGO_USER_FONT (font);
   PangoFontDescription *desc;
 
-  desc = pango_user_font_describe (font);
-  pango_font_description_set_absolute_size (desc, self->size * self->dpi / 72.);
+  desc = pango_font_face_describe (PANGO_FONT_FACE (font->face));
+  pango_font_description_set_gravity (desc, font->gravity);
+  pango_font_description_set_size (desc, font->size);
 
   return desc;
 }
@@ -94,13 +75,12 @@ pango_user_font_get_glyph_extents (PangoFont      *font,
                                    PangoRectangle *ink_rect,
                                    PangoRectangle *logical_rect)
 {
-  PangoUserFont *self = PANGO_USER_FONT (font);
   hb_font_t *hb_font = pango_font_get_hb_font (font);
   hb_glyph_extents_t extents;
   hb_direction_t direction;
   hb_font_extents_t font_extents;
 
-  direction = PANGO_GRAVITY_IS_VERTICAL (self->gravity)
+  direction = PANGO_GRAVITY_IS_VERTICAL (font->gravity)
               ? HB_DIRECTION_TTB
               : HB_DIRECTION_LTR;
 
@@ -132,7 +112,7 @@ pango_user_font_get_glyph_extents (PangoFont      *font,
       r.width = extents.width;
       r.height = - extents.height;
 
-      switch (self->gravity)
+      switch (font->gravity)
         {
         case PANGO_GRAVITY_AUTO:
         case PANGO_GRAVITY_SOUTH:
@@ -163,7 +143,7 @@ pango_user_font_get_glyph_extents (PangoFont      *font,
           g_assert_not_reached ();
         }
 
-      if (PANGO_GRAVITY_IS_IMPROPER (self->gravity))
+      if (PANGO_GRAVITY_IS_IMPROPER (font->gravity))
         {
           PangoMatrix matrix = (PangoMatrix) PANGO_MATRIX_INIT;
           pango_matrix_scale (&matrix, -1, -1);
@@ -184,7 +164,7 @@ pango_user_font_get_glyph_extents (PangoFont      *font,
       logical_rect->width = h_advance;
       logical_rect->height = extents.ascender - extents.descender;
 
-      switch (self->gravity)
+      switch (font->gravity)
         {
         case PANGO_GRAVITY_AUTO:
         case PANGO_GRAVITY_SOUTH:
@@ -207,7 +187,7 @@ pango_user_font_get_glyph_extents (PangoFont      *font,
           g_assert_not_reached ();
         }
 
-      if (PANGO_GRAVITY_IS_IMPROPER (self->gravity))
+      if (PANGO_GRAVITY_IS_IMPROPER (font->gravity))
         {
           logical_rect->height = - logical_rect->height;
           logical_rect->y = - logical_rect->y;
@@ -242,79 +222,82 @@ pango_user_font_get_metrics (PangoFont     *font,
 }
 
 static hb_bool_t
-nominal_glyph_func (hb_font_t *font, void *font_data,
+nominal_glyph_func (hb_font_t *hb_font, void *font_data,
                     hb_codepoint_t unicode,
                     hb_codepoint_t *glyph,
                     void *user_data)
 {
-  PangoUserFont *self = font_data;
+  PangoFont *font = font_data;
+  PangoUserFace *face = PANGO_USER_FACE (font->face);
 
-  return self->face->glyph_func (self->face, unicode, glyph, self->face->user_data);
+  return face->glyph_func (face, unicode, glyph, face->user_data);
 }
 
 static hb_position_t
-glyph_h_advance_func (hb_font_t *font, void *font_data,
+glyph_h_advance_func (hb_font_t *hb_font, void *font_data,
                       hb_codepoint_t glyph,
                       void *user_data)
 {
-  PangoUserFont *self = font_data;
-  int size = self->size * self->dpi / 72.;
+  PangoFont *font = font_data;
+  PangoUserFace *face = PANGO_USER_FACE (font->face);
+  int size = font->size * font->dpi / 72.;
   hb_position_t h_advance, v_advance;
   hb_glyph_extents_t glyph_extents;
   gboolean is_color;
 
-  self->face->glyph_info_func (self->face, size, glyph,
-                               &glyph_extents,
-                               &h_advance, &v_advance,
-                               &is_color,
-                               self->face->user_data);
+  face->glyph_info_func (face, size, glyph,
+                         &glyph_extents,
+                         &h_advance, &v_advance,
+                         &is_color,
+                         face->user_data);
 
   return h_advance;
 }
 
 static hb_bool_t
-glyph_extents_func (hb_font_t *font, void *font_data,
+glyph_extents_func (hb_font_t *hb_font, void *font_data,
                     hb_codepoint_t glyph,
                     hb_glyph_extents_t *extents,
                     void *user_data)
 {
-  PangoUserFont *self = font_data;
-  int size = self->size * self->dpi / 72.;
+  PangoFont *font = font_data;
+  PangoUserFace *face = PANGO_USER_FACE (font->face);
+  int size = font->size * font->dpi / 72.;
   hb_position_t h_advance, v_advance;
   gboolean is_color;
 
-  return self->face->glyph_info_func (self->face, size, glyph,
-                                      extents,
-                                      &h_advance, &v_advance,
-                                      &is_color,
-                                      self->face->user_data);
+  return face->glyph_info_func (face, size, glyph,
+                                extents,
+                                &h_advance, &v_advance,
+                                &is_color,
+                                face->user_data);
 }
 
 static hb_bool_t
-font_extents_func (hb_font_t *font, void *font_data,
+font_extents_func (hb_font_t *hb_font, void *font_data,
                    hb_font_extents_t *extents,
                    void *user_data)
 {
-  PangoUserFont *self = font_data;
-  int size = self->size * self->dpi / 72.;
+  PangoFont *font = font_data;
+  PangoUserFace *face = PANGO_USER_FACE (font->face);
+  int size = font->size * font->dpi / 72.;
 
-  return self->face->font_info_func (self->face, size, extents, self->face->user_data);
+  return face->font_info_func (face, size, extents, face->user_data);
 }
 
 static hb_font_t *
 pango_user_font_create_hb_font (PangoFont *font)
 {
-  PangoUserFont *self = PANGO_USER_FONT (font);
-  hb_font_t *hb_font;
   double x_scale, y_scale;
   int size;
   hb_blob_t *blob;
-  hb_face_t *face;
+  hb_face_t *hb_face;
+  hb_font_t *hb_font;
   hb_font_funcs_t *funcs;
 
   blob = hb_blob_create ("", 0, HB_MEMORY_MODE_READONLY, NULL, NULL);
-  face = hb_face_create (blob, 0);
-  hb_font = hb_font_create (face);
+  hb_face = hb_face_create (blob, 0);
+  hb_font = hb_font_create (hb_face);
 
   funcs = hb_font_funcs_create ();
 
@@ -323,23 +306,23 @@ pango_user_font_create_hb_font (PangoFont *font)
   hb_font_funcs_set_glyph_extents_func (funcs, glyph_extents_func, NULL, NULL);
   hb_font_funcs_set_font_h_extents_func (funcs, font_extents_func, NULL, NULL);
 
-  hb_font_set_funcs (hb_font, funcs, self, NULL);
+  hb_font_set_funcs (hb_font, funcs, font, NULL);
 
   hb_font_funcs_destroy (funcs);
-  hb_face_destroy (face);
+  hb_face_destroy (hb_face);
   hb_blob_destroy (blob);
 
-  size = self->size * self->dpi / 72.f;
+  size = font->size * font->dpi / 72.f;
   x_scale = y_scale = 1;
 
-  if (PANGO_GRAVITY_IS_IMPROPER (self->gravity))
+  if (PANGO_GRAVITY_IS_IMPROPER (font->gravity))
     {
       x_scale = - x_scale;
       y_scale = - y_scale;
     }
 
   hb_font_set_scale (hb_font, size * x_scale, size * y_scale);
-  hb_font_set_ptem (hb_font, self->size / PANGO_SCALE);
+  hb_font_set_ptem (hb_font, font->size / PANGO_SCALE);
 
   return hb_font;
 }
@@ -354,14 +337,6 @@ pango_user_font_has_char (PangoFont *font,
   return hb_font_get_nominal_glyph (user_font, wc, &glyph);
 }
 
-static PangoFontFace *
-pango_user_font_get_face (PangoFont *font)
-{
-  PangoUserFont *self = PANGO_USER_FONT (font);
-
-  return PANGO_FONT_FACE (self->face);
-}
-
 static void
 pango_user_font_class_init (PangoUserFontClass *class)
 {
@@ -371,12 +346,10 @@ pango_user_font_class_init (PangoUserFontClass *class)
   object_class->finalize = pango_user_font_finalize;
 
   font_class->describe = pango_user_font_describe;
-  font_class->describe_absolute = pango_user_font_describe_absolute;
   font_class->get_glyph_extents = pango_user_font_get_glyph_extents;
   font_class->get_metrics = pango_user_font_get_metrics;
   font_class->create_hb_font = pango_user_font_create_hb_font;
   font_class->has_char = pango_user_font_has_char;
-  font_class->get_face = pango_user_font_get_face;
 }
 
 /* }}} */
@@ -402,17 +375,18 @@ pango_user_font_new (PangoUserFace     *face,
                      const PangoMatrix *matrix)
 {
   PangoUserFont *self;
+  PangoFont *font;
 
   self = g_object_new (PANGO_TYPE_USER_FONT, NULL);
 
-  self->face = g_object_ref (face);
+  font = PANGO_FONT (self);
 
-  self->size = size;
-  self->dpi = dpi;
-  if (gravity != PANGO_GRAVITY_AUTO)
-    self->gravity = gravity;
+  pango_font_set_face (font, PANGO_FONT_FACE (face));
+  pango_font_set_size (font, size);
+  pango_font_set_dpi (font, dpi);
+  pango_font_set_gravity (font, gravity);
   if (matrix)
-    self->matrix = *matrix;
+    pango_font_set_matrix (font, matrix);
 
   return self;
 }
diff --git a/pango/pangocairo-font.c b/pango/pangocairo-font.c
index 996ae39c3..5ca9a0474 100644
--- a/pango/pangocairo-font.c
+++ b/pango/pangocairo-font.c
@@ -88,7 +88,8 @@ render_func (cairo_scaled_font_t  *scaled_font,
              cairo_text_extents_t *extents)
 {
   cairo_font_face_t *font_face;
-  PangoUserFont *font;
+  PangoFont *font;
+  PangoUserFace *face;
   hb_glyph_extents_t glyph_extents;
   hb_position_t h_advance;
   hb_position_t v_advance;
@@ -96,6 +97,7 @@ render_func (cairo_scaled_font_t  *scaled_font,
 
   font_face = cairo_scaled_font_get_font_face (scaled_font);
   font = cairo_font_face_get_user_data (font_face, &cairo_user_data);
+  face = PANGO_USER_FACE (font->face);
 
   extents->x_bearing = 0;
   extents->y_bearing = 0;
@@ -104,12 +106,12 @@ render_func (cairo_scaled_font_t  *scaled_font,
   extents->x_advance = 0;
   extents->y_advance = 0;
 
-  if (!font->face->glyph_info_func (font->face, 1024,
-                                    (hb_codepoint_t)glyph,
-                                    &glyph_extents,
-                                    &h_advance, &v_advance,
-                                    &is_color,
-                                    font->face->user_data))
+  if (!face->glyph_info_func (face, 1024,
+                              (hb_codepoint_t)glyph,
+                              &glyph_extents,
+                              &h_advance, &v_advance,
+                              &is_color,
+                              face->user_data))
     {
       return CAIRO_STATUS_USER_FONT_ERROR;
     }
@@ -121,11 +123,11 @@ render_func (cairo_scaled_font_t  *scaled_font,
   extents->x_advance = h_advance / (double) 1024;
   extents->y_advance = v_advance / (double) 1024;
 
-  if (!font->face->render_func (font->face, font->size,
-                                (hb_codepoint_t)glyph,
-                                font->face->user_data,
-                                "cairo",
-                                cr))
+  if (!face->render_func (face, font->size,
+                          (hb_codepoint_t)glyph,
+                          face->user_data,
+                          "cairo",
+                          cr))
     {
       return CAIRO_STATUS_USER_FONT_ERROR;
     }
@@ -134,7 +136,7 @@ render_func (cairo_scaled_font_t  *scaled_font,
 }
 
 static cairo_font_face_t *
-create_font_face_for_user_font (PangoUserFont *font)
+create_font_face_for_user_font (PangoFont *font)
 {
   cairo_font_face_t *cairo_face;
 
@@ -146,8 +148,9 @@ create_font_face_for_user_font (PangoUserFont *font)
 }
 
 static cairo_font_face_t *
-create_font_face_for_hb_font (PangoHbFont *font)
+create_font_face_for_hb_font (PangoFont *font)
 {
+  PangoHbFace *face = PANGO_HB_FACE (font->face);
   hb_blob_t *blob;
   const char *blob_data;
   unsigned int blob_length;
@@ -166,18 +169,18 @@ create_font_face_for_hb_font (PangoHbFont *font)
       g_once_init_leave (&ft_library, library);
     }
 
-  blob = hb_face_reference_blob (hb_font_get_face (pango_font_get_hb_font (PANGO_FONT (font))));
+  hb_font = pango_font_get_hb_font (font);
+  blob = hb_face_reference_blob (hb_font_get_face (hb_font));
   blob_data = hb_blob_get_data (blob, &blob_length);
   hb_blob_destroy (blob);
 
   if ((error = FT_New_Memory_Face (ft_library,
                                    (const FT_Byte *) blob_data,
                                    blob_length,
-                                   hb_face_get_index (font->face->face),
+                                   hb_face_get_index (face->face),
                                    &ft_face)) != 0)
     g_error ("FT_New_Memory_Face failed: %d %s", error, FT_Error_String (error));
 
-  hb_font = pango_font_get_hb_font (PANGO_FONT (font));
   coords = hb_font_get_var_coords_normalized (hb_font, &num_coords);
   if (num_coords > 0)
     {
@@ -190,7 +193,7 @@ create_font_face_for_hb_font (PangoHbFont *font)
     }
 
   cairo_face = cairo_ft_font_face_create_for_ft_face (ft_face, FT_LOAD_NO_HINTING | FT_LOAD_COLOR);
-  if (font->face->embolden)
+  if (face->embolden)
     cairo_ft_font_face_set_synthesize (cairo_face, CAIRO_FT_SYNTHESIZE_BOLD);
   cairo_font_face_set_user_data (cairo_face, &key,
                                  ft_face, (cairo_destroy_func_t) FT_Done_Face);
@@ -215,9 +218,9 @@ _pango_cairo_font_private_get_scaled_font (PangoCairoFontPrivate *cf_priv)
     }
 
   if (PANGO_IS_HB_FONT (cf_priv->cfont))
-    font_face = create_font_face_for_hb_font (PANGO_HB_FONT (cf_priv->cfont));
+    font_face = create_font_face_for_hb_font (cf_priv->cfont);
   else if (PANGO_IS_USER_FONT (cf_priv->cfont))
-    font_face = create_font_face_for_user_font (PANGO_USER_FONT (cf_priv->cfont));
+    font_face = create_font_face_for_user_font (cf_priv->cfont);
 
   if (G_UNLIKELY (font_face == NULL))
     goto done;
@@ -555,7 +558,6 @@ _pango_font_get_cairo_font_private (PangoFont *font)
   cf_priv = g_object_get_data (G_OBJECT (font), "pango-hb-font-cairo_private");
   if (!cf_priv)
     {
-      CommonFont *cf = (CommonFont *)font;
       cairo_font_options_t *font_options;
       cairo_matrix_t font_matrix;
       double x_scale, y_scale;
@@ -566,20 +568,20 @@ _pango_font_get_cairo_font_private (PangoFont *font)
 
       if (PANGO_IS_HB_FONT (font))
         {
-          PangoHbFont *hbfont = PANGO_HB_FONT (font);
-          if (hbfont->face->matrix)
+          PangoHbFace *face = PANGO_HB_FACE (font->face);
+          if (face->matrix)
             cairo_matrix_init (&font_matrix,
-                               hbfont->face->matrix->xx,
-                               - hbfont->face->matrix->yx,
-                               - hbfont->face->matrix->xy,
-                               hbfont->face->matrix->yy,
+                               face->matrix->xx,
+                               - face->matrix->yx,
+                               - face->matrix->xy,
+                               face->matrix->yy,
                                0., 0.);
 
-          x_scale = hbfont->face->x_scale;
-          y_scale = hbfont->face->y_scale;
+          x_scale = face->x_scale;
+          y_scale = face->y_scale;
         }
 
-      size = cf->size * cf->dpi / 72.;
+      size = font->size * font->dpi / 72.;
 
       cairo_matrix_scale (&font_matrix,
                           x_scale * size / (double)PANGO_SCALE,
@@ -598,9 +600,9 @@ _pango_font_get_cairo_font_private (PangoFont *font)
       cf_priv = g_new0 (PangoCairoFontPrivate, 1);
       _pango_cairo_font_private_initialize (cf_priv,
                                             font,
-                                            cf->gravity,
+                                            font->gravity,
                                             font_options,
-                                            &cf->matrix,
+                                            &font->matrix,
                                             &font_matrix);
 
       cairo_font_options_destroy (font_options);
diff --git a/pango/shape.c b/pango/shape.c
index 68edda99e..aed65f45e 100644
--- a/pango/shape.c
+++ b/pango/shape.c
@@ -541,13 +541,14 @@ pango_user_shape (const char          *text,
                   PangoGlyphString    *glyphs,
                   PangoShapeFlags      flags)
 {
-  PangoUserFont *font = PANGO_USER_FONT (analysis->font);
+  PangoFont *font = analysis->font;
+  PangoUserFace *face = PANGO_USER_FACE (font->face);
 
-  font->face->shape_func (font->face, font->size,
-                          text, length,
-                          analysis,
-                          glyphs, flags,
-                          font->face->user_data);
+  face->shape_func (face, font->size,
+                    text, length,
+                    analysis,
+                    glyphs, flags,
+                    face->user_data);
 }
 
 /* }}} */


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