[pango/userfont: 10/15] userface: Tweaks



commit 000c8cc07a35aef435d14a4bd2dbe0a722a19026
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Jan 28 00:31:36 2022 -0500

    userface: Tweaks

 pango/pango-userface.h  |  21 +++++-----
 pango/pango-userfont.c  |   9 +++--
 pango/pangocairo-font.c | 101 ++++++++++++++++++++++++++++--------------------
 3 files changed, 77 insertions(+), 54 deletions(-)
---
diff --git a/pango/pango-userface.h b/pango/pango-userface.h
index cbf9f0a4..e5036291 100644
--- a/pango/pango-userface.h
+++ b/pango/pango-userface.h
@@ -32,31 +32,34 @@ typedef struct _PangoUserFont PangoUserFont;
 PANGO_AVAILABLE_IN_1_52
 G_DECLARE_FINAL_TYPE (PangoUserFace, pango_user_face, PANGO, USER_FACE, PangoFontFace)
 
-typedef void          (* PangoUserFaceGetFontExtentsFunc)  (PangoUserFace       *face,
+typedef gboolean      (* PangoUserFaceGetFontExtentsFunc)  (PangoUserFace     *face,
                                                             int                size,
                                                             hb_font_extents_t *extents,
                                                             gpointer           user_data);
 
-typedef gboolean      (* PangoUserFaceGetNominalGlyphFunc) (PangoUserFace    *face,
+typedef gboolean      (* PangoUserFaceGetNominalGlyphFunc) (PangoUserFace  *face,
                                                             hb_codepoint_t  unicode,
                                                             hb_codepoint_t *glyph,
                                                             gpointer        user_data);
 
-typedef hb_position_t (* PangoUserFaceGetGlyphAdvanceFunc) (PangoUserFace    *face,
+typedef gboolean      (* PangoUserFaceGetGlyphAdvanceFunc) (PangoUserFace  *face,
                                                             int             size,
                                                             hb_codepoint_t  glyph,
+                                                            hb_position_t  *h_advance,
+                                                            hb_position_t  *v_advance,
                                                             gpointer        user_data);
 
-typedef gboolean      (* PangoUserFaceGetGlyphExtentsFunc) (PangoUserFace        *face,
+typedef gboolean      (* PangoUserFaceGetGlyphExtentsFunc) (PangoUserFace      *face,
                                                             int                 size,
                                                             hb_codepoint_t      glyph,
                                                             hb_glyph_extents_t *extents,
                                                             gpointer            user_data);
 
-typedef void          (* PangoUserFaceRenderGlyphFunc)     (PangoUserFace    *face,
+typedef gboolean      (* PangoUserFaceRenderGlyphFunc)     (PangoUserFace  *face,
                                                             int             size,
                                                             hb_codepoint_t  glyph,
                                                             gpointer        user_data,
+                                                            const char     *backend_id,
                                                             gpointer        backend_data);
 
 PANGO_AVAILABLE_IN_1_52
@@ -65,9 +68,9 @@ PangoUserFace *   pango_user_face_new          (PangoUserFaceGetFontExtentsFunc
                                                 PangoUserFaceGetGlyphAdvanceFunc   advance_func,
                                                 PangoUserFaceGetGlyphExtentsFunc   glyph_extents_func,
                                                 PangoUserFaceRenderGlyphFunc       render_glyph,
-                                                gpointer                         user_data,
-                                                GDestroyNotify                   destroy,
-                                                const char                      *name,
-                                                const PangoFontDescription      *description);
+                                                gpointer                           user_data,
+                                                GDestroyNotify                     destroy,
+                                                const char                        *name,
+                                                const PangoFontDescription        *description);
 
 G_END_DECLS
diff --git a/pango/pango-userfont.c b/pango/pango-userfont.c
index 6a46d5e2..36920bdc 100644
--- a/pango/pango-userfont.c
+++ b/pango/pango-userfont.c
@@ -274,8 +274,11 @@ glyph_h_advance_func (hb_font_t *font, void *font_data,
 {
   PangoUserFont *self = font_data;
   int size = self->size * self->dpi / 72.;
+  hb_position_t h_advance, v_advance;
 
-  return self->face->advance_func (self->face, size, glyph, self->face->user_data);
+  self->face->advance_func (self->face, size, glyph, &h_advance, &v_advance, self->face->user_data);
+
+  return h_advance;
 }
 
 static hb_bool_t
@@ -298,9 +301,7 @@ font_extents_func (hb_font_t *font, void *font_data,
   PangoUserFont *self = font_data;
   int size = self->size * self->dpi / 72.;
 
-  self->face->font_extents_func (self->face, size, extents, self->face->user_data);
-
-  return TRUE;
+  return self->face->font_extents_func (self->face, size, extents, self->face->user_data);
 }
 
 static hb_font_t *
diff --git a/pango/pangocairo-font.c b/pango/pangocairo-font.c
index 4e256640..7534cb4c 100644
--- a/pango/pangocairo-font.c
+++ b/pango/pangocairo-font.c
@@ -30,6 +30,8 @@
 #include "pango-impl-utils.h"
 #include "pango-hbfont-private.h"
 #include "pango-hbface-private.h"
+#include "pango-userfont-private.h"
+#include "pango-userface-private.h"
 #include "pangocairo-fc.h"
 
 #pragma GCC diagnostic push
@@ -82,40 +84,54 @@ render_func (cairo_scaled_font_t  *scaled_font,
              cairo_text_extents_t *extents)
 {
   cairo_font_face_t *font_face;
-  PangoHbFont *font;
-  PangoUserFontFuncs *user_font;
+  PangoUserFont *font;
   hb_glyph_extents_t glyph_extents;
-  hb_position_t scaled_advance;
+  hb_position_t h_advance;
+  hb_position_t v_advance;
 
   font_face = cairo_scaled_font_get_font_face (scaled_font);
   font = cairo_font_face_get_user_data (font_face, &cairo_user_data);
 
-  user_font = font->face->user_font;
-  user_font->render_func (font->face, font->size,
-                          (hb_codepoint_t)glyph,
-                          user_font->user_data,
-                          cr);
+  font->face->render_func (font->face, font->size,
+                           (hb_codepoint_t)glyph,
+                           font->face->user_data,
+                           "cairo",
+                           cr);
 
-  scaled_advance = user_font->advance_func (font->face, 1024,
-                                            (hb_codepoint_t)glyph,
-                                            user_font->user_data);
+  font->face->advance_func (font->face, 1024,
+                            (hb_codepoint_t)glyph,
+                            &h_advance,
+                            &v_advance,
+                            font->face->user_data);
 
-  user_font->glyph_extents_func (font->face, 1024,
-                                 (hb_codepoint_t)glyph,
-                                 &glyph_extents,
-                                 user_font->user_data);
+  font->face->glyph_extents_func (font->face, 1024,
+                                  (hb_codepoint_t)glyph,
+                                  &glyph_extents,
+                                  font->face->user_data);
 
   extents->x_bearing = glyph_extents.x_bearing / (double) 1024;
   extents->y_bearing = glyph_extents.y_bearing / (double) 1024;
   extents->width = glyph_extents.width / (double) 1024;
   extents->height = glyph_extents.height / (double) 1024;
 
-  extents->x_advance = scaled_advance / (double) 1024;
-  extents->y_advance = 0.;
+  extents->x_advance = h_advance / (double) 1024;
+  extents->y_advance = v_advance / (double) 1024;
 
   return CAIRO_STATUS_SUCCESS;
 }
 
+static cairo_font_face_t *
+create_font_face_for_user_font (PangoUserFont *font)
+{
+  cairo_font_face_t *cairo_face;
+
+  cairo_face = cairo_user_font_face_create ();
+  cairo_font_face_set_user_data (cairo_face, &cairo_user_data, font, NULL);
+  cairo_user_font_face_set_render_glyph_func (cairo_face, render_func);
+
+  return cairo_face;
+}
+
 static cairo_font_face_t *
 create_font_face_for_hb_font (PangoHbFont *font)
 {
@@ -130,14 +146,6 @@ create_font_face_for_hb_font (PangoHbFont *font)
   static const cairo_user_data_key_t key;
   FT_Error error;
 
-  if (font->face->user_font)
-    {
-      cairo_face = cairo_user_font_face_create ();
-      cairo_font_face_set_user_data (cairo_face, &cairo_user_data, font, NULL);
-      cairo_user_font_face_set_render_glyph_func (cairo_face, render_func);
-      return cairo_face;
-    }
-
   if (g_once_init_enter (&ft_library))
     {
       FT_Library library;
@@ -195,8 +203,10 @@ _pango_cairo_font_private_get_scaled_font (PangoCairoFontPrivate *cf_priv)
 
   if (PANGO_IS_CAIRO_FONT (cf_priv->cfont))
     font_face = (* PANGO_CAIRO_FONT_GET_IFACE (cf_priv->cfont)->create_font_face) (cf_priv->cfont);
-  else
+  else if (PANGO_IS_HB_FONT (cf_priv->cfont))
     font_face = create_font_face_for_hb_font (PANGO_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));
 
   if (G_UNLIKELY (font_face == NULL))
     goto done;
@@ -739,26 +749,35 @@ _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)
     {
-      PangoHbFont *hbfont = PANGO_HB_FONT (font);
+      CommonFont *cf = (CommonFont *)font;
       cairo_font_options_t *font_options;
       cairo_matrix_t font_matrix;
+      double x_scale, y_scale;
       int size;
 
-      if (hbfont->face->matrix)
-        cairo_matrix_init (&font_matrix,
-                           hbfont->face->matrix->xx,
-                           - hbfont->face->matrix->yx,
-                           - hbfont->face->matrix->xy,
-                           hbfont->face->matrix->yy,
-                           0., 0.);
-      else
-        cairo_matrix_init (&font_matrix, 1., 0., 0., 1., 0., 0.);
+      cairo_matrix_init (&font_matrix, 1., 0., 0., 1., 0., 0.);
+      x_scale = y_scale = 1;
+
+      if (PANGO_IS_HB_FONT (font))
+        {
+          PangoHbFont *hbfont = PANGO_HB_FONT (font);
+          if (hbfont->face->matrix)
+            cairo_matrix_init (&font_matrix,
+                               hbfont->face->matrix->xx,
+                               - hbfont->face->matrix->yx,
+                               - hbfont->face->matrix->xy,
+                               hbfont->face->matrix->yy,
+                               0., 0.);
+
+          x_scale = hbfont->face->x_scale;
+          y_scale = hbfont->face->y_scale;
+        }
 
-      size = hbfont->size * hbfont->dpi / 72.;
+      size = cf->size * cf->dpi / 72.;
 
       cairo_matrix_scale (&font_matrix,
-                          hbfont->face->x_scale * size / (double)PANGO_SCALE,
-                          hbfont->face->y_scale * size / (double)PANGO_SCALE);
+                          x_scale * size / (double)PANGO_SCALE,
+                          y_scale * size / (double)PANGO_SCALE);
 
       font_options = cairo_font_options_create ();
       cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
@@ -767,9 +786,9 @@ _pango_font_get_cairo_font_private (PangoFont *font)
       cf_priv = g_new0 (PangoCairoFontPrivate, 1);
       _pango_cairo_font_private_initialize (cf_priv,
                                             (PangoCairoFont *)font,
-                                            hbfont->gravity,
+                                            cf->gravity,
                                             font_options,
-                                            &hbfont->matrix,
+                                            &cf->matrix,
                                             &font_matrix);
 
       cairo_font_options_destroy (font_options);


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