[pango/pango2: 20/56] Clean up PangoFontFace hierarchy




commit 50dc17d5962cdf825a7b402ae0441f84e11fe862
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Jun 11 12:43:25 2022 -0400

    Clean up PangoFontFace hierarchy
    
    Move common fields to PangoFontFace, add private
    setters, and add properties.

 pango/pango-font-face-private.h |  30 ++++-
 pango/pango-font-face.c         | 262 +++++++++++++++++++++++++++++++---------
 pango/pango-font-face.h         |   2 +-
 pango/pango-font-family.c       |   2 +-
 pango/pango-fontmap.c           |  21 +++-
 pango/pango-hbface-private.h    |  19 ---
 pango/pango-hbface.c            | 111 +++++++----------
 pango/pango-hbfamily.c          |  30 +++--
 pango/pango-hbfont.c            |   4 +-
 pango/pango-userface-private.h  |   5 -
 pango/pango-userface.c          |  45 ++-----
 tests/test-font.c               |   4 +-
 tests/testhbfont.c              |  10 +-
 utils/pango-list.c              |   4 +-
 14 files changed, 328 insertions(+), 221 deletions(-)
---
diff --git a/pango/pango-font-face-private.h b/pango/pango-font-face-private.h
index f99f20229..7fc0aafb8 100644
--- a/pango/pango-font-face-private.h
+++ b/pango/pango-font-face-private.h
@@ -20,11 +20,17 @@
 #pragma once
 
 #include <pango/pango-font-face.h>
+#include <pango/pango-font-description.h>
 
 
 struct _PangoFontFace
 {
   GObject parent_instance;
+
+  PangoFontFamily *family;
+  PangoFontDescription *description;
+  char *name;
+  char *faceid;
 };
 
 typedef struct _PangoFontFaceClass PangoFontFaceClass;
@@ -33,12 +39,9 @@ struct _PangoFontFaceClass
 {
   GObjectClass parent_class;
 
-  const char *           (* get_face_name)     (PangoFontFace *face);
-  PangoFontDescription * (* describe)          (PangoFontFace *face);
   gboolean               (* is_synthesized)    (PangoFontFace *face);
   gboolean               (* is_monospace)      (PangoFontFace *face);
   gboolean               (* is_variable)       (PangoFontFace *face);
-  PangoFontFamily *      (* get_family)        (PangoFontFace *face);
   gboolean               (* supports_language) (PangoFontFace *face,
                                                 PangoLanguage *language);
   PangoLanguage **       (* get_languages)     (PangoFontFace *face);
@@ -59,3 +62,24 @@ PangoFont *     pango_font_face_create_font     (PangoFontFace              *fac
                                                  const PangoFontDescription *desc,
                                                  float                       dpi,
                                                  const PangoMatrix          *matrix);
+
+static inline void
+pango_font_face_set_name (PangoFontFace *face,
+                          const char    *name)
+{
+  face->name = g_strdup (name);
+}
+
+static inline void
+pango_font_face_set_description (PangoFontFace              *face,
+                                 const PangoFontDescription *description)
+{
+  face->description = pango_font_description_copy (description);
+}
+
+static inline void
+pango_font_face_set_family (PangoFontFace   *face,
+                            PangoFontFamily *family)
+{
+  face->family = family;
+}
diff --git a/pango/pango-font-face.c b/pango/pango-font-face.c
index f7d307e6f..a7a7514f4 100644
--- a/pango/pango-font-face.c
+++ b/pango/pango-font-face.c
@@ -36,6 +36,20 @@
  * or [method@Pango.FontFace.is_variable].
  */
 
+/* {{{ PangoFontFace implementation */
+
+enum {
+  PROP_NAME = 1,
+  PROP_DESCRIPTION,
+  PROP_FAMILY,
+  PROP_SYNTHESIZED,
+  PROP_MONOSPACE,
+  PROP_VARIABLE,
+  N_PROPERTIES
+};
+
+static GParamSpec *properties[N_PROPERTIES] = { NULL, };
+
 G_DEFINE_ABSTRACT_TYPE (PangoFontFace, pango_font_face, G_TYPE_OBJECT)
 
 static gboolean
@@ -86,8 +100,67 @@ pango_font_face_default_create_font (PangoFontFace              *face,
 }
 
 static void
-pango_font_face_class_init (PangoFontFaceClass *class G_GNUC_UNUSED)
+pango_font_face_finalize (GObject *object)
+{
+  PangoFontFace *face = PANGO_FONT_FACE (object);
+
+  pango_font_description_free (face->description);
+  g_free (face->name);
+
+  G_OBJECT_CLASS (pango_font_face_parent_class)->finalize (object);
+}
+
+static void
+pango_font_face_get_property (GObject    *object,
+                              guint       property_id,
+                              GValue     *value,
+                              GParamSpec *pspec)
 {
+  PangoFontFace *face = PANGO_FONT_FACE (object);
+
+  switch (property_id)
+    {
+    case PROP_NAME:
+      g_value_set_string (value, face->name);
+      break;
+
+    case PROP_DESCRIPTION:
+      if ((pango_font_description_get_set_fields (face->description) & PANGO_FONT_MASK_FACEID) == 0)
+        pango_font_description_set_faceid (face->description,
+                                           pango_font_face_get_faceid (face));
+
+      g_value_set_boxed (value, face->description);
+      break;
+
+    case PROP_FAMILY:
+      g_value_set_object (value, face->family);
+      break;
+
+    case PROP_SYNTHESIZED:
+      g_value_set_boolean (value, pango_font_face_is_synthesized (face));
+      break;
+
+    case PROP_MONOSPACE:
+      g_value_set_boolean (value, pango_font_face_is_monospace (face));
+      break;
+
+    case PROP_VARIABLE:
+      g_value_set_boolean (value, pango_font_face_is_variable (face));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+    }
+}
+
+static void
+pango_font_face_class_init (PangoFontFaceClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+  object_class->finalize = pango_font_face_finalize;
+  object_class->get_property = pango_font_face_get_property;
+
   class->is_monospace = pango_font_face_default_is_monospace;
   class->is_variable = pango_font_face_default_is_variable;
   class->get_languages = pango_font_face_default_get_languages;
@@ -95,6 +168,74 @@ pango_font_face_class_init (PangoFontFaceClass *class G_GNUC_UNUSED)
   class->has_char = pango_font_face_default_has_char;
   class->get_faceid = pango_font_face_default_get_faceid;
   class->create_font = pango_font_face_default_create_font;
+
+  /**
+   * PangoFontFace:name: (attributes org.gtk.Property.get=pango_font_face_get_name)
+   *
+   * A name representing the style of this face.
+   */
+  properties[PROP_NAME] =
+      g_param_spec_string ("name", NULL, NULL, NULL,
+                           G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+  /**
+   * PangoFontFace:description: (attributes org.gtk.Property.get=pango_font_face_describe)
+   *
+   * A font description that matches the face.
+   *
+   * The font description will have the family, style,
+   * variant, weight and stretch of the face, but its size field
+   * will be unset.
+   */
+  properties[PROP_DESCRIPTION] =
+      g_param_spec_boxed ("description", NULL, NULL,
+                          PANGO_TYPE_FONT_DESCRIPTION,
+                          G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+  /**
+   * PangoFontFace:family: (attributes org.gtk.Property.get=pango_font_face_get_family)
+   *
+   * The `PangoFontFamily` that @face belongs to.
+   */
+  properties[PROP_FAMILY] =
+      g_param_spec_object ("family", NULL, NULL,
+                           PANGO_TYPE_FONT_FAMILY,
+                           G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+  /**
+   * PangoFontFace:synthesized: (attributes org.gtk.Property.get=pango_font_face_is_synthesized)
+   *
+   * `TRUE` if the face is synthesized.
+   *
+   * This will be the case if the underlying font rendering engine
+   * creates this face from another face, by shearing, emboldening,
+   * lightening or modifying it in some other way.
+   */
+  properties[PROP_SYNTHESIZED] =
+      g_param_spec_boolean ("synthesized", NULL, NULL, FALSE,
+                            G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+  /**
+   * PangoFontFace:monospace: (attributes org.gtk.Property.get=pango_font_face_is_monospace)
+   *
+   * `TRUE` if the face is designed for text display where the the
+   * characters form a regular grid.
+   */
+  properties[PROP_MONOSPACE] =
+      g_param_spec_boolean ("monospace", NULL, NULL, FALSE,
+                            G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+  /**
+   * PangoFontFace:variable: (attributes org.gtk.Property.get=pango_font_face_is_variable)
+   *
+   * `TRUE` if the face has axes that can be modified
+   * to produce variations.
+   */
+  properties[PROP_VARIABLE] =
+      g_param_spec_boolean ("variable", NULL, NULL, FALSE,
+                            G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_properties (object_class, N_PROPERTIES, properties);
 }
 
 static void
@@ -102,6 +243,60 @@ pango_font_face_init (PangoFontFace *face G_GNUC_UNUSED)
 {
 }
 
+/* }}} */
+/* {{{ Private API */
+
+PangoFont *
+pango_font_face_create_font (PangoFontFace              *face,
+                             const PangoFontDescription *desc,
+                             float                       dpi,
+                             const PangoMatrix          *matrix)
+{
+  g_return_val_if_fail (PANGO_IS_FONT_FACE (face), NULL);
+
+  return PANGO_FONT_FACE_GET_CLASS (face)->create_font (face, desc, dpi, matrix);
+}
+
+/*< private >
+ * pango_font_face_get_faceid:
+ * @self: a `PangoHbFace`
+ *
+ * Returns the faceid of the face.
+ *
+ * The faceid is meant to uniquely identify the face among the
+ * faces of its family. It includes an identifier for the font
+ * file that is used (currently, we use the PostScript name for
+ * this), the face index, the instance ID, as well as synthetic
+ * tweaks such as emboldening and transforms and variations.
+ *
+ * [method@Pango.FontFace.describe] adds the faceid to the font
+ * description that it produces.
+ *
+ * See pango_hb_family_find_face() for the code that takes the
+ * faceid into account when searching for a face. It is careful
+ * to fall back to approximate matching if an exact match for
+ * the faceid isn't found. That should make it safe to preserve
+ * faceids when saving font descriptions in configuration or
+ * other data.
+ *
+ * There are no guarantees about the format of the string that
+ * this function produces, except for that it does not contain
+ * ' ', ',' or '=', so it can be safely embedded in the '@' part
+ * of a serialized font description.
+ *
+ * Returns: (transfer none): the faceid
+ */
+const char *
+pango_font_face_get_faceid (PangoFontFace *face)
+{
+  g_return_val_if_fail (PANGO_IS_FONT_FACE (face), "");
+
+  return PANGO_FONT_FACE_GET_CLASS (face)->get_faceid (face);
+}
+
+/* }}} */
+/* {{{ Public API */
+
 /**
  * pango_font_face_describe:
  * @face: a `PangoFontFace`
@@ -121,7 +316,11 @@ pango_font_face_describe (PangoFontFace *face)
 {
   g_return_val_if_fail (PANGO_IS_FONT_FACE (face), NULL);
 
-  return PANGO_FONT_FACE_GET_CLASS (face)->describe (face);
+  if ((pango_font_description_get_set_fields (face->description) & PANGO_FONT_MASK_FACEID) == 0)
+    pango_font_description_set_faceid (face->description,
+                                       pango_font_face_get_faceid (face));
+
+  return pango_font_description_copy (face->description);
 }
 
 /**
@@ -148,7 +347,7 @@ pango_font_face_is_synthesized (PangoFontFace  *face)
 }
 
 /**
- * pango_font_face_get_face_name:
+ * pango_font_face_get_name:
  * @face: a `PangoFontFace`.
  *
  * Gets a name representing the style of this face.
@@ -157,15 +356,15 @@ pango_font_face_is_synthesized (PangoFontFace  *face)
  * with the same name (e.g. a variable and a non-variable
  * face for the same style).
  *
- * Return value: the face name for the face. This string is
+ * Return value: the name for the face. This string is
  *   owned by the face object and must not be modified or freed.
  */
 const char *
-pango_font_face_get_face_name (PangoFontFace *face)
+pango_font_face_get_name (PangoFontFace *face)
 {
   g_return_val_if_fail (PANGO_IS_FONT_FACE (face), NULL);
 
-  return PANGO_FONT_FACE_GET_CLASS (face)->get_face_name (face);
+  return face->name;
 }
 
 /**
@@ -181,7 +380,7 @@ 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);
+  return face->family;
 }
 
 /**
@@ -293,51 +492,6 @@ pango_font_face_has_char (PangoFontFace *face,
   return PANGO_FONT_FACE_GET_CLASS (face)->has_char (face, wc);
 }
 
-/*< private >
- * pango_font_face_get_faceid:
- * @self: a `PangoHbFace`
- *
- * Returns the faceid of the face.
- *
- * The faceid is meant to uniquely identify the face among the
- * faces of its family. It includes an identifier for the font
- * file that is used (currently, we use the PostScript name for
- * this), the face index, the instance ID, as well as synthetic
- * tweaks such as emboldening and transforms and variations.
- *
- * [method@Pango.FontFace.describe] adds the faceid to the font
- * description that it produces.
- *
- * See pango_hb_family_find_face() for the code that takes the
- * faceid into account when searching for a face. It is careful
- * to fall back to approximate matching if an exact match for
- * the faceid isn't found. That should make it safe to preserve
- * faceids when saving font descriptions in configuration or
- * other data.
- *
- * There are no guarantees about the format of the string that
- * this function produces, except for that it does not contain
- * ' ', ',' or '=', so it can be safely embedded in the '@' part
- * of a serialized font description.
- *
- * Returns: (transfer none): the faceid
- */
-const char *
-pango_font_face_get_faceid (PangoFontFace *face)
-{
-  g_return_val_if_fail (PANGO_IS_FONT_FACE (face), "");
-
-  return PANGO_FONT_FACE_GET_CLASS (face)->get_faceid (face);
-}
-
-PangoFont *
-pango_font_face_create_font (PangoFontFace              *face,
-                             const PangoFontDescription *desc,
-                             float                       dpi,
-                             const PangoMatrix          *matrix)
-{
-  g_return_val_if_fail (PANGO_IS_FONT_FACE (face), NULL);
-
-  return PANGO_FONT_FACE_GET_CLASS (face)->create_font (face, desc, dpi, matrix);
-}
+/* }}} */
 
+/* vim:set foldmethod=marker expandtab: */
diff --git a/pango/pango-font-face.h b/pango/pango-font-face.h
index 09e6b576a..2a5a32c32 100644
--- a/pango/pango-font-face.h
+++ b/pango/pango-font-face.h
@@ -34,7 +34,7 @@ PANGO_DECLARE_INTERNAL_TYPE (PangoFontFace, pango_font_face, PANGO, FONT_FACE, G
 PANGO_AVAILABLE_IN_ALL
 PangoFontDescription *  pango_font_face_describe       (PangoFontFace  *face);
 PANGO_AVAILABLE_IN_ALL
-const char *            pango_font_face_get_face_name  (PangoFontFace  *face) G_GNUC_PURE;
+const char *            pango_font_face_get_name       (PangoFontFace  *face) G_GNUC_PURE;
 PANGO_AVAILABLE_IN_ALL
 gboolean                pango_font_face_is_synthesized (PangoFontFace  *face) G_GNUC_PURE;
 PANGO_AVAILABLE_IN_ALL
diff --git a/pango/pango-font-family.c b/pango/pango-font-family.c
index 70eabaa06..789992d82 100644
--- a/pango/pango-font-family.c
+++ b/pango/pango-font-family.c
@@ -96,7 +96,7 @@ pango_font_family_real_get_face (PangoFontFamily *family,
       PangoFontFace *f = g_list_model_get_item (G_LIST_MODEL (family), i);
       g_object_unref (f);
       if (name == NULL ||
-          strcmp (name, pango_font_face_get_face_name (f)) == 0)
+          strcmp (name, pango_font_face_get_name (f)) == 0)
         {
           face = f;
           break;
diff --git a/pango/pango-fontmap.c b/pango/pango-fontmap.c
index c814e98e4..fbcfd3768 100644
--- a/pango/pango-fontmap.c
+++ b/pango/pango-fontmap.c
@@ -265,7 +265,7 @@ synthesize_bold_and_italic_faces (PangoFontMap *map)
   for (int i = 0; i < map->families->len; i++)
     {
       PangoFontFamily *family = g_ptr_array_index (map->families, i);
-      PangoHbFace *regular_face = NULL;
+      PangoFontFace *regular_face = NULL;
       int regular_dist = G_MAXINT;
       int bold_dist = G_MAXINT;
       gboolean has_italic = FALSE;
@@ -277,7 +277,7 @@ synthesize_bold_and_italic_faces (PangoFontMap *map)
 
       for (int j = 0; j < g_list_model_get_n_items (G_LIST_MODEL (family)); j++)
         {
-          PangoHbFace *face = g_list_model_get_item (G_LIST_MODEL (family), j);
+          PangoFontFace *face = g_list_model_get_item (G_LIST_MODEL (family), j);
           int weight;
           PangoStyle style;
           int dist;
@@ -321,13 +321,22 @@ synthesize_bold_and_italic_faces (PangoFontMap *map)
       if (regular_face)
         {
           if (!has_italic)
-            add_style_variation (PANGO_HB_FAMILY (family), regular_face, PANGO_STYLE_ITALIC, 
PANGO_WEIGHT_NORMAL);
+            add_style_variation (PANGO_HB_FAMILY (family),
+                                 PANGO_HB_FACE (regular_face),
+                                 PANGO_STYLE_ITALIC,
+                                 PANGO_WEIGHT_NORMAL);
 
           if (!has_bold)
-            add_style_variation (PANGO_HB_FAMILY (family), regular_face, PANGO_STYLE_NORMAL, 
PANGO_WEIGHT_BOLD);
+            add_style_variation (PANGO_HB_FAMILY (family),
+                                 PANGO_HB_FACE (regular_face),
+                                 PANGO_STYLE_NORMAL,
+                                 PANGO_WEIGHT_BOLD);
 
           if (!has_bold_italic)
-            add_style_variation (PANGO_HB_FAMILY (family), regular_face, PANGO_STYLE_ITALIC, 
PANGO_WEIGHT_BOLD);
+            add_style_variation (PANGO_HB_FAMILY (family),
+                                 PANGO_HB_FACE (regular_face),
+                                 PANGO_STYLE_ITALIC,
+                                 PANGO_WEIGHT_BOLD);
         }
     }
 }
@@ -779,7 +788,7 @@ pango_font_map_add_face (PangoFontMap  *self,
   g_return_if_fail (PANGO_IS_FONT_MAP (self));
   g_return_if_fail (PANGO_IS_HB_FACE (face) || PANGO_IS_USER_FACE (face));
 
-  description = ((CommonFace *)face)->description;
+  description = face->description;
 
   if (pango_font_description_get_set_fields (description) &
       (PANGO_FONT_MASK_VARIANT | PANGO_FONT_MASK_GRAVITY))
diff --git a/pango/pango-hbface-private.h b/pango/pango-hbface-private.h
index e523cbe1f..b9b918042 100644
--- a/pango/pango-hbface-private.h
+++ b/pango/pango-hbface-private.h
@@ -25,30 +25,11 @@
 #include "pango-language-set-private.h"
 #include <hb.h>
 
-
-typedef struct _CommonFace CommonFace;
-struct _CommonFace {
-  PangoFontFace parent_instance;
-
-  PangoFontDescription *description;
-  char *name;
-  PangoFontFamily *family;
-  char *psname;
-  char *faceid;
-};
-
 struct _PangoHbFace
 {
   PangoFontFace parent_instance;
 
-  PangoFontDescription *description;
-  char *name;
-  PangoFontFamily *family;
-  char *psname;
   char *faceid;
-
-  /* up to here shared with PangoUserFace */
-
   unsigned int index;
   int instance_id;
   char *file;
diff --git a/pango/pango-hbface.c b/pango/pango-hbface.c
index 6330822d4..8cbc8d708 100644
--- a/pango/pango-hbface.c
+++ b/pango/pango-hbface.c
@@ -47,26 +47,28 @@
 
  /* {{{ Utilities */
 
-static char *
+static void
 get_name_from_hb_face (hb_face_t       *face,
                        hb_ot_name_id_t  name_id,
-                       hb_ot_name_id_t  fallback_id)
+                       hb_ot_name_id_t  fallback_id,
+                       char            *buf,
+                       unsigned int     len)
 {
-  char buf[256];
-  unsigned int len;
+  unsigned int size = len;
 
-  len = sizeof (buf);
-  if (hb_ot_name_get_utf8 (face, name_id, HB_LANGUAGE_INVALID, &len, buf) > 0)
-    return g_strdup (buf);
+  if (hb_ot_name_get_utf8 (face, name_id, HB_LANGUAGE_INVALID, &size, buf) > 0)
+    return;
 
   if (fallback_id != HB_OT_NAME_ID_INVALID)
     {
-      len = sizeof (buf);
-      if (hb_ot_name_get_utf8 (face, fallback_id, HB_LANGUAGE_INVALID, &len, buf) > 0)
-        return g_strdup (buf);
+      size = len;
+
+      if (hb_ot_name_get_utf8 (face, fallback_id, HB_LANGUAGE_INVALID, &size, buf) > 0)
+        return;
     }
 
-  return g_strdup ("Unnamed");
+  strncpy (buf, "Unnamed", len);
+  buf[len - 1] = '\0';
 }
 
 static void
@@ -125,13 +127,16 @@ set_name_and_description (PangoHbFace                *self,
                           const char                 *name,
                           const PangoFontDescription *description)
 {
+  PangoFontFace *face = PANGO_FONT_FACE (self);
+
   if (name)
     {
-      self->name = g_strdup (name);
+      pango_font_face_set_name (face, name);
     }
   else
     {
       hb_ot_name_id_t name_id;
+      char face_name[256] = { 0, };
 
       ensure_hb_face (self);
 
@@ -140,39 +145,44 @@ set_name_and_description (PangoHbFace                *self,
       else
         name_id = HB_OT_NAME_ID_TYPOGRAPHIC_SUBFAMILY;
 
-      self->name = get_name_from_hb_face (self->face, name_id, HB_OT_NAME_ID_FONT_SUBFAMILY);
+      get_name_from_hb_face (self->face,
+                             name_id,
+                             HB_OT_NAME_ID_FONT_SUBFAMILY,
+                             face_name, sizeof (face_name));
+
+      pango_font_face_set_name (face, face_name);
     }
 
   if (description)
     {
-      self->description = pango_font_description_copy (description);
+      face->description = pango_font_description_copy (description);
     }
   else
     {
-      char *family;
+      char family[256] = { 0, };
       char *fullname;
 
       ensure_hb_face (self);
 
-      family = get_name_from_hb_face (self->face,
-                                      HB_OT_NAME_ID_TYPOGRAPHIC_FAMILY,
-                                      HB_OT_NAME_ID_FONT_FAMILY);
-      fullname = g_strconcat (family, " ", self->name, NULL);
+      get_name_from_hb_face (self->face,
+                             HB_OT_NAME_ID_TYPOGRAPHIC_FAMILY,
+                             HB_OT_NAME_ID_FONT_FAMILY,
+                             family, sizeof (family));
+      fullname = g_strconcat (family, " ", face->name, NULL);
 
-      self->description = pango_font_description_from_string (fullname);
-      pango_font_description_unset_fields (self->description,
+      face->description = pango_font_description_from_string (fullname);
+      pango_font_description_unset_fields (face->description,
                                            PANGO_FONT_MASK_VARIANT |
                                            PANGO_FONT_MASK_VARIATIONS |
                                            PANGO_FONT_MASK_GRAVITY);
 
       g_free (fullname);
-      g_free (family);
     }
 
   if (self->n_variations > 0)
     {
       char *str = variations_to_string (self->variations, self->n_variations, "=", ",");
-      pango_font_description_set_variations (self->description, str);
+      pango_font_description_set_variations (face->description, str);
       g_free (str);
     }
 }
@@ -212,21 +222,24 @@ hb_face_is_monospace (hb_face_t *face)
   return res;
 }
 
- static void
+static void
 ensure_faceid (PangoHbFace *self)
- {
+{
   double slant;
   char buf0[32], buf1[32], buf2[32];
   char *str = NULL;
-  char *psname;
-   char *p;
+  char psname[256] = { 0, };
+  char *p;
 
   if (self->faceid)
     return;
 
   ensure_hb_face (self);
 
-  psname = get_name_from_hb_face (self->face, HB_OT_NAME_ID_POSTSCRIPT_NAME, HB_OT_NAME_ID_INVALID);
+  get_name_from_hb_face (self->face,
+                         HB_OT_NAME_ID_POSTSCRIPT_NAME,
+                         HB_OT_NAME_ID_INVALID,
+                         psname, sizeof (psname));
 
   /* PostScript name should not contain problematic chars, but just in case,
    * make sure we don't have any ' ', '=' or ',' that would give us parsing
@@ -255,7 +268,6 @@ ensure_faceid (PangoHbFace *self)
                                   self->n_variations > 0 ? ":" : "",
                                   self->n_variations > 0 ? str : "");
   g_free (str);
-  g_free (psname);
 }
 
 static const char *
@@ -312,12 +324,10 @@ pango_hb_face_finalize (GObject *object)
 {
   PangoHbFace *self = PANGO_HB_FACE (object);
 
+  g_free (self->faceid);
   if (self->face)
     hb_face_destroy (self->face);
-  pango_font_description_free (self->description);
-  g_free (self->name);
   g_free (self->file);
-  g_free (self->faceid);
   if (self->languages)
     g_object_unref (self->languages);
   g_free (self->variations);
@@ -327,36 +337,6 @@ pango_hb_face_finalize (GObject *object)
   G_OBJECT_CLASS (pango_hb_face_parent_class)->finalize (object);
 }
 
-static const char *
-pango_hb_face_get_face_name (PangoFontFace *face)
-{
-  PangoHbFace *self = PANGO_HB_FACE (face);
-
-  return self->name;
-}
-
-static PangoFontDescription *
-pango_hb_face_describe (PangoFontFace *face)
-{
-  PangoHbFace *self = PANGO_HB_FACE (face);
-
-  if ((pango_font_description_get_set_fields (self->description) & PANGO_FONT_MASK_FACEID) == 0)
-    {
-      ensure_faceid (self);
-      pango_font_description_set_faceid (self->description, self->faceid);
-    }
-
-  return pango_font_description_copy (self->description);
-}
-
-static PangoFontFamily *
-pango_hb_face_get_family (PangoFontFace *face)
-{
-  PangoHbFace *self = PANGO_HB_FACE (face);
-
-  return self->family;
-}
-
 static gboolean
 pango_hb_face_is_synthesized (PangoFontFace *face)
 {
@@ -467,10 +447,7 @@ pango_hb_face_class_init (PangoHbFaceClass *class)
 
   object_class->finalize = pango_hb_face_finalize;
 
-  face_class->get_face_name = pango_hb_face_get_face_name;
-  face_class->describe = pango_hb_face_describe;
   face_class->is_synthesized = pango_hb_face_is_synthesized;
-  face_class->get_family = pango_hb_face_get_family;
   face_class->is_monospace = pango_hb_face_is_monospace;
   face_class->is_variable = pango_hb_face_is_variable;
   face_class->supports_language = pango_hb_face_supports_language;
@@ -733,7 +710,7 @@ pango_hb_face_new_synthetic (PangoHbFace                *face,
   self->embolden = embolden;
   self->synthetic = self->embolden || (self->matrix != NULL);
 
-  desc = pango_font_description_copy (face->description);
+  desc = pango_font_description_copy (PANGO_FONT_FACE (face)->description);
   pango_font_description_merge (desc, description, TRUE);
 
   if (!name)
@@ -820,7 +797,7 @@ pango_hb_face_new_instance (PangoHbFace                *face,
   self->variations = g_memdup2 (variations, sizeof (hb_variation_t) * n_variations);
   self->n_variations = n_variations;
 
-  desc = pango_font_description_copy (face->description);
+  desc = pango_font_description_copy (PANGO_FONT_FACE (face)->description);
   pango_font_description_merge (desc, description, TRUE);
 
   if (!name)
diff --git a/pango/pango-hbfamily.c b/pango/pango-hbfamily.c
index f059471b7..30f2dbe37 100644
--- a/pango/pango-hbfamily.c
+++ b/pango/pango-hbfamily.c
@@ -72,26 +72,24 @@ static int
 sort_face_func (PangoFontFace *face1,
                 PangoFontFace *face2)
 {
-  CommonFace *cf1 = (CommonFace *)face1;
-  CommonFace *cf2 = (CommonFace *)face2;
   int a, b;
 
-  a = pango_font_description_get_style (cf1->description);
-  b = pango_font_description_get_style (cf2->description);
+  a = pango_font_description_get_style (face1->description);
+  b = pango_font_description_get_style (face2->description);
   if (a != b)
     return a - b;
 
-  a = pango_font_description_get_weight (cf1->description);
-  b = pango_font_description_get_weight (cf2->description);
+  a = pango_font_description_get_weight (face1->description);
+  b = pango_font_description_get_weight (face2->description);
   if (a != b)
     return a - b;
 
-  a = pango_font_description_get_stretch (cf1->description);
-  b = pango_font_description_get_stretch (cf2->description);
+  a = pango_font_description_get_stretch (face1->description);
+  b = pango_font_description_get_stretch (face2->description);
   if (a != b)
     return a - b;
 
-  return strcmp (cf1->name, cf2->name);
+  return strcmp (face1->name, face2->name);
 }
 
 /* return 2 if face is a named instance,
@@ -135,8 +133,8 @@ pango_hb_family_finalize (GObject *object)
 
   for (int i = 0; i < self->faces->len; i++)
     {
-      PangoHbFace *face = g_ptr_array_index (self->faces, i);
-      ((CommonFace *)face)->family = NULL;
+      PangoFontFace *face = g_ptr_array_index (self->faces, i);
+      face->family = NULL;
     }
 
   g_ptr_array_unref (self->faces);
@@ -154,7 +152,7 @@ pango_hb_family_get_face (PangoFontFamily *family,
     {
       PangoFontFace *face = g_ptr_array_index (self->faces, i);
 
-      if (name == NULL || strcmp (name, pango_font_face_get_face_name (face)) == 0)
+      if (name == NULL || strcmp (name, pango_font_face_get_name (face)) == 0)
         return face;
     }
 
@@ -226,7 +224,7 @@ pango_hb_family_add_face (PangoHbFamily *self,
 
   g_ptr_array_insert (self->faces, position, face);
 
-  ((CommonFace *)face)->family = PANGO_FONT_FAMILY (self);
+  pango_font_face_set_family (face, PANGO_FONT_FAMILY (self));
 
   g_list_model_items_changed (G_LIST_MODEL (self), position, 0, 1);
   g_object_notify (G_OBJECT (self), "n-items");
@@ -250,7 +248,7 @@ pango_hb_family_remove_face (PangoHbFamily *self,
   if (!g_ptr_array_find (self->faces, face, &position))
     return;
 
-  ((CommonFace *)face)->family = NULL;
+  pango_font_face_set_family (face, NULL);
 
   g_ptr_array_remove_index (self->faces, position);
 
@@ -311,10 +309,10 @@ pango_hb_family_find_face (PangoHbFamily        *family,
       if (wc && !pango_font_face_has_char (face2, wc))
         continue;
 
-      if (!pango_font_description_is_similar (description, ((CommonFace *)face2)->description))
+      if (!pango_font_description_is_similar (description, face2->description))
         continue;
 
-      distance = pango_font_description_compute_distance (description, ((CommonFace *)face2)->description);
+      distance = pango_font_description_compute_distance (description, face2->description);
 
       variableness = face_get_variableness (PANGO_FONT_FACE (face2));
       if (distance < best_distance ||
diff --git a/pango/pango-hbfont.c b/pango/pango-hbfont.c
index b88fc849b..376b7da4f 100644
--- a/pango/pango-hbfont.c
+++ b/pango/pango-hbfont.c
@@ -346,10 +346,10 @@ create_hex_box_info (PangoHbFont *self)
   PangoContext *context;
   PangoFontMap *map;
 
-  if (!self->face->family)
+  if (!PANGO_FONT_FACE (self->face)->family)
     return NULL;
 
-  map = self->face->family->map;
+  map = PANGO_FONT_FACE (self->face)->family->map;
 
   if (!map)
     return NULL;
diff --git a/pango/pango-userface-private.h b/pango/pango-userface-private.h
index 8e9962933..7ea0bf888 100644
--- a/pango/pango-userface-private.h
+++ b/pango/pango-userface-private.h
@@ -28,13 +28,8 @@ struct _PangoUserFace
 {
   PangoFontFace parent_instance;
 
-  PangoFontDescription *description;
-  char *name;
-  PangoFontFamily *family;
   char *faceid;
 
-  /* up to here shared with PangoHbFace */
-
   PangoUserFaceGetFontInfoFunc font_info_func;
   PangoUserFaceUnicodeToGlyphFunc glyph_func;
   PangoUserFaceGetGlyphInfoFunc glyph_info_func;
diff --git a/pango/pango-userface.c b/pango/pango-userface.c
index 9da6570f1..30f69b1f1 100644
--- a/pango/pango-userface.c
+++ b/pango/pango-userface.c
@@ -48,13 +48,14 @@
 static void
 ensure_faceid (PangoUserFace *self)
 {
+  PangoFontFace *face = PANGO_FONT_FACE (self);
   char *psname;
   char *p;
 
   if (self->faceid)
     return;
 
-  psname = g_strconcat (pango_font_description_get_family (self->description), "_", self->name, NULL);
+  psname = g_strconcat (pango_font_description_get_family (face->description), "_", face->name, NULL);
 
   /* PostScript name should not contain problematic chars, but just in case,
    * make sure we don't have any ' ', '=' or ',' that would give us parsing
@@ -199,8 +200,6 @@ pango_user_face_finalize (GObject *object)
 {
   PangoUserFace *self = PANGO_USER_FACE (object);
 
-  pango_font_description_free (self->description);
-  g_free (self->name);
   g_free (self->faceid);
   if (self->destroy)
     self->destroy (self->user_data);
@@ -208,36 +207,6 @@ pango_user_face_finalize (GObject *object)
   G_OBJECT_CLASS (pango_user_face_parent_class)->finalize (object);
 }
 
-static const char *
-pango_user_face_get_face_name (PangoFontFace *face)
-{
-  PangoUserFace *self = PANGO_USER_FACE (face);
-
-  return self->name;
-}
-
-static PangoFontDescription *
-pango_user_face_describe (PangoFontFace *face)
-{
-  PangoUserFace *self = PANGO_USER_FACE (face);
-
-  if ((pango_font_description_get_set_fields (self->description) & PANGO_FONT_MASK_FACEID) == 0)
-    {
-      ensure_faceid (self);
-      pango_font_description_set_faceid (self->description, self->faceid);
-    }
-
-  return pango_font_description_copy (self->description);
-}
-
-static PangoFontFamily *
-pango_user_face_get_family (PangoFontFace *face)
-{
-  PangoUserFace *self = PANGO_USER_FACE (face);
-
-  return self->family;
-}
-
 static gboolean
 pango_user_face_is_synthesized (PangoFontFace *face)
 {
@@ -295,10 +264,7 @@ pango_user_face_class_init (PangoUserFaceClass *class)
 
   object_class->finalize = pango_user_face_finalize;
 
-  face_class->get_face_name = pango_user_face_get_face_name;
-  face_class->describe = pango_user_face_describe;
   face_class->is_synthesized = pango_user_face_is_synthesized;
-  face_class->get_family = pango_user_face_get_family;
   face_class->is_monospace = pango_user_face_is_monospace;
   face_class->is_variable = pango_user_face_is_variable;
   face_class->has_char = pango_user_face_has_char;
@@ -446,6 +412,7 @@ pango_user_face_new (PangoUserFaceGetFontInfoFunc     font_info_func,
                      const PangoFontDescription      *description)
 {
   PangoUserFace *self;
+  PangoFontFace *face;
 
   self = g_object_new (PANGO_TYPE_USER_FACE, NULL);
 
@@ -460,8 +427,10 @@ pango_user_face_new (PangoUserFaceGetFontInfoFunc     font_info_func,
   if (!name)
     name = style_from_font_description (description);
 
-  self->name = g_strdup (name);
-  self->description = pango_font_description_copy (description);
+  face = PANGO_FONT_FACE (self);
+
+  face->name = g_strdup (name);
+  face->description = pango_font_description_copy (description);
 
   return self;
 }
diff --git a/tests/test-font.c b/tests/test-font.c
index 2aa2d334f..a17133200 100644
--- a/tests/test-font.c
+++ b/tests/test-font.c
@@ -256,8 +256,8 @@ test_enumerate (void)
   for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (family)); i++)
     {
       PangoFontFace *f = g_list_model_get_item (G_LIST_MODEL (family), i);
-      face = pango_font_family_get_face (family, pango_font_face_get_face_name (f));
-      g_assert_cmpstr (pango_font_face_get_face_name (face), ==, pango_font_face_get_face_name (f));
+      face = pango_font_family_get_face (family, pango_font_face_get_name (f));
+      g_assert_cmpstr (pango_font_face_get_name (face), ==, pango_font_face_get_name (f));
       g_object_unref (f);
     }
 
diff --git a/tests/testhbfont.c b/tests/testhbfont.c
index b93294ecb..8ee203199 100644
--- a/tests/testhbfont.c
+++ b/tests/testhbfont.c
@@ -79,7 +79,7 @@ test_hbface_roundtrip (void)
 
   face = pango_hb_face_new_from_file (path, 0, -1, NULL, NULL);
   g_assert_true (PANGO_IS_HB_FACE (face));
-  g_assert_cmpstr (pango_font_face_get_face_name (PANGO_FONT_FACE (face)), ==, "Regular");
+  g_assert_cmpstr (pango_font_face_get_name (PANGO_FONT_FACE (face)), ==, "Regular");
   desc = pango_font_face_describe (PANGO_FONT_FACE (face));
   g_assert_cmpint (pango_font_description_get_set_fields (desc) & NO_FACEID, ==, PANGO_FONT_MASK_FAMILY |
                                                                                  PANGO_FONT_MASK_STYLE |
@@ -97,7 +97,7 @@ test_hbface_roundtrip (void)
   pango_font_description_free (desc);
 
   g_assert_true (PANGO_IS_HB_FACE (face2));
-  g_assert_cmpstr (pango_font_face_get_face_name (PANGO_FONT_FACE (face2)), ==, "Oblique");
+  g_assert_cmpstr (pango_font_face_get_name (PANGO_FONT_FACE (face2)), ==, "Oblique");
   desc = pango_font_face_describe (PANGO_FONT_FACE (face2));
   g_assert_cmpint (pango_font_description_get_set_fields (desc) & NO_FACEID, ==, PANGO_FONT_MASK_FAMILY |
                                                                                  PANGO_FONT_MASK_STYLE |
@@ -116,7 +116,7 @@ test_hbface_roundtrip (void)
   pango_font_description_free (desc);
 
   g_assert_true (PANGO_IS_HB_FACE (face2));
-  g_assert_cmpstr (pango_font_face_get_face_name (PANGO_FONT_FACE (face2)), ==, "Bold");
+  g_assert_cmpstr (pango_font_face_get_name (PANGO_FONT_FACE (face2)), ==, "Bold");
   desc = pango_font_face_describe (PANGO_FONT_FACE (face2));
   g_assert_cmpint (pango_font_description_get_set_fields (desc) & NO_FACEID, ==, PANGO_FONT_MASK_FAMILY |
                                                                                  PANGO_FONT_MASK_STYLE |
@@ -135,7 +135,7 @@ test_hbface_roundtrip (void)
   pango_font_description_free (desc);
 
   g_assert_true (PANGO_IS_HB_FACE (face2));
-  g_assert_cmpstr (pango_font_face_get_face_name (PANGO_FONT_FACE (face2)), ==, "Regular");
+  g_assert_cmpstr (pango_font_face_get_name (PANGO_FONT_FACE (face2)), ==, "Regular");
   desc = pango_font_face_describe (PANGO_FONT_FACE (face2));
   g_assert_cmpint (pango_font_description_get_set_fields (desc) & NO_FACEID, ==, PANGO_FONT_MASK_FAMILY |
                                                                                  PANGO_FONT_MASK_STYLE |
@@ -159,7 +159,7 @@ test_hbface_roundtrip (void)
   pango_font_description_free (desc);
 
   g_assert_true (PANGO_IS_HB_FACE (face2));
-  g_assert_cmpstr (pango_font_face_get_face_name (PANGO_FONT_FACE (face2)), ==, "Fat");
+  g_assert_cmpstr (pango_font_face_get_name (PANGO_FONT_FACE (face2)), ==, "Fat");
   desc = pango_font_face_describe (PANGO_FONT_FACE (face2));
   g_assert_cmpint (pango_font_description_get_set_fields (desc) & NO_FACEID, ==, PANGO_FONT_MASK_FAMILY |
                                                                                  PANGO_FONT_MASK_STYLE |
diff --git a/utils/pango-list.c b/utils/pango-list.c
index 2f0fbc027..e32cdfc5b 100644
--- a/utils/pango-list.c
+++ b/utils/pango-list.c
@@ -162,7 +162,7 @@ main (int    argc,
       for (j = 0; j < g_list_model_get_n_items (G_LIST_MODEL (family)); j++)
        {
           PangoFontFace *face = g_list_model_get_item (G_LIST_MODEL (family), j);
-         const char *face_name = pango_font_face_get_face_name (face);
+         const char *face_name = pango_font_face_get_name (face);
          gboolean is_synth = pango_font_face_is_synthesized (face);
          const char *synth_str = is_synth ? "*" : "";
          const char *variable_str = "";
@@ -173,7 +173,7 @@ main (int    argc,
       for (j = 0; j < g_list_model_get_n_items (G_LIST_MODEL (family)); j++)
         {
           PangoFontFace *face = g_list_model_get_item (G_LIST_MODEL (family), j);
-          const char *face_name = pango_font_face_get_face_name (face);
+          const char *face_name = pango_font_face_get_name (face);
           gboolean is_synth = pango_font_face_is_synthesized (face);
           const char *synth_str = is_synth ? "*" : "";
           gboolean is_variable = pango_font_face_is_variable (face);


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