[pango/userfont: 13/15] examples: Adapt




commit 8449be793b96cc11bc13be64c68393fb0aafeda5
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Jan 28 01:04:28 2022 -0500

    examples: Adapt

 examples/cairoshape.c | 57 ++++++++++++++++++++++-----------------------------
 examples/userfont.c   | 51 ++++++++++++++++++++++-----------------------
 2 files changed, 48 insertions(+), 60 deletions(-)
---
diff --git a/examples/cairoshape.c b/examples/cairoshape.c
index 4aec3b0f..50fd0366 100644
--- a/examples/cairoshape.c
+++ b/examples/cairoshape.c
@@ -188,28 +188,14 @@ glyph_cb (PangoUserFace  *face,
 }
 
 static gboolean
-advance_cb (PangoUserFace  *face,
-            int             size,
-            hb_codepoint_t  glyph,
-            hb_position_t  *h_advance,
-            hb_position_t  *v_advance,
-            gpointer        user_data)
-{
-  if (glyph == 0x2022)
-    {
-      *h_advance = size;
-      *v_advance = size;
-    }
-
-  return FALSE;
-}
-
-static gboolean
-extents_cb (PangoUserFace      *face,
-            int                 size,
-            hb_codepoint_t      glyph,
-            hb_glyph_extents_t *extents,
-            gpointer            user_data)
+glyph_info_cb (PangoUserFace      *face,
+               int                 size,
+               hb_codepoint_t      glyph,
+               hb_glyph_extents_t *extents,
+               hb_position_t      *h_advance,
+               hb_position_t      *v_advance,
+               gboolean           *is_color,
+               gpointer            user_data)
 {
   if (glyph == 0x2022)
     {
@@ -217,22 +203,29 @@ extents_cb (PangoUserFace      *face,
       extents->y_bearing = - size;
       extents->width = size;
       extents->height = size;
-      return TRUE;
+
+      *h_advance = size;
+      *v_advance = size;
+
+      *is_color = FALSE;
     }
 
-  return TRUE;
+  return FALSE;
 }
 
 static gboolean
-font_extents_cb (PangoUserFace     *face,
-                 int                size,
-                 hb_font_extents_t *extents,
-                 gpointer           user_data)
+font_info_cb (PangoUserFace     *face,
+              int                size,
+              hb_font_extents_t *extents,
+              gboolean          *has_color,
+              gpointer           user_data)
 {
   extents->ascender = size;
   extents->descender = 0;
   extents->line_gap = 0;
 
+  *has_color = FALSE;
+
   return TRUE;
 }
 
@@ -240,6 +233,7 @@ static gboolean
 render_cb (PangoUserFace  *face,
            int             size,
            hb_codepoint_t  glyph,
+           gboolean        use_color,
            gpointer        user_data,
            const char     *backend_id,
            gpointer        backend_data)
@@ -270,11 +264,8 @@ setup_fontmap (PangoHbFontMap *fontmap)
 
   desc = pango_font_description_from_string ("Bullets");
   pango_font_description_unset_fields (desc, 
PANGO_FONT_MASK_VARIANT|PANGO_FONT_MASK_SIZE|PANGO_FONT_MASK_GRAVITY);
-#if 0
-  face = pango_hb_face_new_from_file ("/usr/share/fonts/adobe-source-code-pro/SourceCodePro-Black.otf",
-                                      0, -1, "Black", desc);
-#endif
-  face = pango_user_face_new (font_extents_cb, glyph_cb, advance_cb, extents_cb, render_cb, NULL, NULL, 
"Black", desc);
+
+  face = pango_user_face_new (font_info_cb, glyph_cb, glyph_info_cb, render_cb, NULL, NULL, "Black", desc);
   pango_hb_font_map_add_face (fontmap, PANGO_FONT_FACE (face));
   pango_font_description_free (desc);
 }
diff --git a/examples/userfont.c b/examples/userfont.c
index 9da8b16f..d90688bd 100644
--- a/examples/userfont.c
+++ b/examples/userfont.c
@@ -115,44 +115,41 @@ glyph_cb (PangoUserFace    *face,
 }
 
 static gboolean
-advance_cb (PangoUserFace    *face,
-            int             size,
-            hb_codepoint_t  glyph,
-            hb_position_t  *h_advance,
-            hb_position_t  *v_advance,
-            gpointer        user_data)
+glyph_info_cb (PangoUserFace      *face,
+               int                 size,
+               hb_codepoint_t      glyph,
+               hb_glyph_extents_t *extents,
+               hb_position_t      *h_advance,
+               hb_position_t      *v_advance,
+               gboolean           *is_color,
+               gpointer            user_data)
 {
   test_scaled_font_glyph_t *glyphs = user_data;
 
+  extents->x_bearing = 0;
+  extents->y_bearing = - 0.75 * size;
+  extents->width = glyphs[glyph].width / 4.0 * size;
+  extents->height = size;
+
   *h_advance = *v_advance = glyphs[glyph].width / 4.0 * size;
 
+  *is_color = FALSE;
+
   return TRUE;
 }
 
 static gboolean
-font_extents_cb (PangoUserFace     *face,
-                 int                size,
-                 hb_font_extents_t *extents,
-                 gpointer           user_data)
+font_info_cb (PangoUserFace     *face,
+              int                size,
+              hb_font_extents_t *extents,
+              gboolean          *has_color_glyphs,
+              gpointer           user_data)
 {
   extents->ascender = 0.75 * size;
   extents->descender = 0.25 * size;
   extents->line_gap = 0;
 
-  return TRUE;
-}
-
-static gboolean
-glyph_extents_cb (PangoUserFace      *face,
-                  int                 size,
-                  hb_codepoint_t      glyph,
-                  hb_glyph_extents_t *extents,
-                  gpointer            user_data)
-{
-  extents->x_bearing = 0;
-  extents->y_bearing = - 0.75 * size;
-  extents->width = glyphs[glyph].width / 4.0 * size;
-  extents->height = size;
+  has_color_glyphs = FALSE;
 
   return TRUE;
 }
@@ -161,6 +158,7 @@ static gboolean
 render_cb (PangoUserFace  *face,
            int             size,
            hb_codepoint_t  glyph,
+           gboolean        use_color,
            gpointer        user_data,
            const char     *backend_id,
            gpointer        backend_data)
@@ -212,10 +210,9 @@ setup_fontmap (PangoHbFontMap *fontmap)
 
   desc = pango_font_description_new ();
   pango_font_description_set_family (desc, "Userfont");
-  face = pango_user_face_new (font_extents_cb,
+  face = pango_user_face_new (font_info_cb,
                               glyph_cb,
-                              advance_cb,
-                              glyph_extents_cb,
+                              glyph_info_cb,
                               render_cb,
                               (gpointer) glyphs, NULL,
                               "Black", desc);


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