[pango/pango2-windows: 3/6] pango-font.c: Make face_get_blob() a shared function
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/pango2-windows: 3/6] pango-font.c: Make face_get_blob() a shared function
- Date: Thu, 30 Jun 2022 02:50:17 +0000 (UTC)
commit 7733285466668fecfe282b0b7da59e7bd8c79509
Author: Chun-wei Fan <fanchunwei src gnome org>
Date: Tue Jun 28 12:32:39 2022 +0800
pango-font.c: Make face_get_blob() a shared function
...which was in pangocairo-ft-font.c, since we want to use this function for
DirectWrite as well to create the cairo_font_face_t that we want in the Cairo
support.
Rename that function as pango2_font_get_hb_blob(), and move it to pango-font.c,
and place its prototype in pango-font-private.h. Update the calls in
pangocairo-ft-font.c accordingly.
pango2/pango-font-private.h | 26 ++++++-----
pango2/pango-font.c | 103 ++++++++++++++++++++++++++++++++++++++++++++
pango2/pangocairo-ft-font.c | 98 +----------------------------------------
3 files changed, 120 insertions(+), 107 deletions(-)
---
diff --git a/pango2/pango-font-private.h b/pango2/pango-font-private.h
index ca8d3a775..a0ce1a6bd 100644
--- a/pango2/pango-font-private.h
+++ b/pango2/pango-font-private.h
@@ -29,6 +29,8 @@
#include <cairo.h>
#endif
+G_BEGIN_DECLS
+
struct _Pango2Font
{
GObject parent_instance;
@@ -107,18 +109,20 @@ pango2_font_set_ctm (Pango2Font *font,
font->ctm = ctm ? *ctm : matrix_init;
}
-gboolean pango2_font_is_hinted (Pango2Font *font);
-void pango2_font_get_scale_factors (Pango2Font *font,
- double *x_scale,
- double *y_scale);
-void pango2_font_get_transform (Pango2Font *font,
- Pango2Matrix *matrix);
+gboolean pango2_font_is_hinted (Pango2Font *font);
+void pango2_font_get_scale_factors (Pango2Font *font,
+ double *x_scale,
+ double *y_scale);
+void pango2_font_get_transform (Pango2Font *font,
+ Pango2Matrix *matrix);
+
+gboolean pango2_font_description_is_similar (const Pango2FontDescription *a,
+ const Pango2FontDescription *b);
-gboolean pango2_font_description_is_similar (const Pango2FontDescription *a,
- const Pango2FontDescription *b);
+int pango2_font_description_compute_distance (const Pango2FontDescription *a,
+ const Pango2FontDescription *b);
-int pango2_font_description_compute_distance (const Pango2FontDescription *a,
- const Pango2FontDescription *b);
+hb_blob_t *pango2_font_get_hb_blob (Pango2Font *font);
/* We use these values in a few places as a fallback size for an
* unknown glyph, if we have no better information.
@@ -126,3 +130,5 @@ int pango2_font_description_compute_distance (const Pango2FontDescription *
#define PANGO2_UNKNOWN_GLYPH_WIDTH 10
#define PANGO2_UNKNOWN_GLYPH_HEIGHT 14
+
+G_END_DECLS
diff --git a/pango2/pango-font.c b/pango2/pango-font.c
index cdf2fc42c..df8dea5d8 100644
--- a/pango2/pango-font.c
+++ b/pango2/pango-font.c
@@ -246,6 +246,109 @@ pango2_font_get_scale_factors (Pango2Font *font,
PANGO2_FONT_GET_CLASS (font)->get_scale_factors (font, x_scale, y_scale);
}
+/*< private >
+ * pango2_font_get_hb_blob:
+ * @font: a `Pango2Font`
+ *
+ * Get the font data as a blob. Either, the hb_face_t was
+ * created from a blob to begin with, or we receate one using
+ * hb_face_builder_create(). Unfortunately we can't rely on
+ * hb_face_get_table_tags(), so we just have to list all possible
+ * OpenType tables here and try them all.
+ *
+ * This is not ideal from a memory perspective, but cairo does
+ * not have a scaled font implementation that takes individual
+ * tables.
+ */
+hb_blob_t *
+pango2_font_get_hb_blob (Pango2Font *font)
+{
+ hb_font_t *hb_font;
+ hb_face_t *hb_face;
+ hb_blob_t *blob;
+ hb_face_t *builder;
+ static const hb_tag_t ot_tables[] = {
+ HB_TAG ('a','v','a','r'),
+ HB_TAG ('B','A','S','E'),
+ HB_TAG ('C','B','D','T'),
+ HB_TAG ('C','B','L','C'),
+ HB_TAG ('C','F','F',' '),
+ HB_TAG ('C','F','F','2'),
+ HB_TAG ('c','m','a','p'),
+ HB_TAG ('C','O','L','R'),
+ HB_TAG ('C','P','A','L'),
+ HB_TAG ('c','v','a','r'),
+ HB_TAG ('c','v','t',' '),
+ HB_TAG ('D','S','I','G'),
+ HB_TAG ('E','B','D','T'),
+ HB_TAG ('E','B','L','C'),
+ HB_TAG ('E','B','S','C'),
+ HB_TAG ('f','p','g','m'),
+ HB_TAG ('f','v','a','r'),
+ HB_TAG ('g','a','s','p'),
+ HB_TAG ('G','D','E','F'),
+ HB_TAG ('g','l','y','f'),
+ HB_TAG ('G','P','O','S'),
+ HB_TAG ('G','S','U','B'),
+ HB_TAG ('g','v','a','r'),
+ HB_TAG ('h','d','m','x'),
+ HB_TAG ('h','e','a','d'),
+ HB_TAG ('h','h','e','a'),
+ HB_TAG ('h','m','t','x'),
+ HB_TAG ('H','V','A','R'),
+ HB_TAG ('J','S','T','F'),
+ HB_TAG ('k','e','r','n'),
+ HB_TAG ('l','o','c','a'),
+ HB_TAG ('L','T','S','H'),
+ HB_TAG ('M','A','T','H'),
+ HB_TAG ('m','a','x','p'),
+ HB_TAG ('M','E','R','G'),
+ HB_TAG ('m','e','t','a'),
+ HB_TAG ('M','V','A','R'),
+ HB_TAG ('n','a','m','e'),
+ HB_TAG ('O','S','/','2'),
+ HB_TAG ('P','C','L','T'),
+ HB_TAG ('p','o','s','t'),
+ HB_TAG ('p','r','e','p'),
+ HB_TAG ('s','b','i','x'),
+ HB_TAG ('S','T','A','T'),
+ HB_TAG ('S','V','G',' '),
+ HB_TAG ('V','D','M','X'),
+ HB_TAG ('v','h','e','a'),
+ HB_TAG ('v','m','t','x'),
+ HB_TAG ('V','O','R','G'),
+ HB_TAG ('V','V','A','R'),
+ };
+
+ hb_font = pango2_font_get_hb_font (font);
+ hb_face = hb_font_get_face (hb_font);
+ blob = hb_face_reference_blob (hb_face);
+
+ if (blob != hb_blob_get_empty ())
+ return blob;
+
+ builder = hb_face_builder_create ();
+
+ for (unsigned int i = 0; i < G_N_ELEMENTS (ot_tables); i++)
+ {
+ hb_blob_t *table;
+
+ table = hb_face_reference_table (hb_face, ot_tables[i]);
+
+ if (table != hb_blob_get_empty ())
+ {
+ hb_face_builder_add_table (builder, ot_tables[i], table);
+ hb_blob_destroy (table);
+ }
+ }
+
+ blob = hb_face_reference_blob (builder);
+
+ hb_face_destroy (builder);
+
+ return blob;
+}
+
/* }}} */
/* {{{ Public API */
diff --git a/pango2/pangocairo-ft-font.c b/pango2/pangocairo-ft-font.c
index d7770ddbe..f5f6c044e 100644
--- a/pango2/pangocairo-ft-font.c
+++ b/pango2/pangocairo-ft-font.c
@@ -32,101 +32,6 @@
#include <cairo-ft.h>
#include <freetype/ftmm.h>
-/* Get the font data as a blob. Either, the hb_face_t was
- * created from a blob to begin with, or we receate one using
- * hb_face_builder_create(). Unfortunately we can't rely on
- * hb_face_get_table_tags(), so we just have to list all possible
- * OpenType tables here and try them all.
- *
- * This is not ideal from a memory perspective, but cairo does
- * not have a scaled font implementation that takes individual
- * tables.
- */
-static hb_blob_t *
-face_get_blob (hb_face_t *face)
-{
- hb_blob_t *blob;
- hb_face_t *builder;
- static const hb_tag_t ot_tables[] = {
- HB_TAG ('a','v','a','r'),
- HB_TAG ('B','A','S','E'),
- HB_TAG ('C','B','D','T'),
- HB_TAG ('C','B','L','C'),
- HB_TAG ('C','F','F',' '),
- HB_TAG ('C','F','F','2'),
- HB_TAG ('c','m','a','p'),
- HB_TAG ('C','O','L','R'),
- HB_TAG ('C','P','A','L'),
- HB_TAG ('c','v','a','r'),
- HB_TAG ('c','v','t',' '),
- HB_TAG ('D','S','I','G'),
- HB_TAG ('E','B','D','T'),
- HB_TAG ('E','B','L','C'),
- HB_TAG ('E','B','S','C'),
- HB_TAG ('f','p','g','m'),
- HB_TAG ('f','v','a','r'),
- HB_TAG ('g','a','s','p'),
- HB_TAG ('G','D','E','F'),
- HB_TAG ('g','l','y','f'),
- HB_TAG ('G','P','O','S'),
- HB_TAG ('G','S','U','B'),
- HB_TAG ('g','v','a','r'),
- HB_TAG ('h','d','m','x'),
- HB_TAG ('h','e','a','d'),
- HB_TAG ('h','h','e','a'),
- HB_TAG ('h','m','t','x'),
- HB_TAG ('H','V','A','R'),
- HB_TAG ('J','S','T','F'),
- HB_TAG ('k','e','r','n'),
- HB_TAG ('l','o','c','a'),
- HB_TAG ('L','T','S','H'),
- HB_TAG ('M','A','T','H'),
- HB_TAG ('m','a','x','p'),
- HB_TAG ('M','E','R','G'),
- HB_TAG ('m','e','t','a'),
- HB_TAG ('M','V','A','R'),
- HB_TAG ('n','a','m','e'),
- HB_TAG ('O','S','/','2'),
- HB_TAG ('P','C','L','T'),
- HB_TAG ('p','o','s','t'),
- HB_TAG ('p','r','e','p'),
- HB_TAG ('s','b','i','x'),
- HB_TAG ('S','T','A','T'),
- HB_TAG ('S','V','G',' '),
- HB_TAG ('V','D','M','X'),
- HB_TAG ('v','h','e','a'),
- HB_TAG ('v','m','t','x'),
- HB_TAG ('V','O','R','G'),
- HB_TAG ('V','V','A','R'),
- };
-
- blob = hb_face_reference_blob (face);
-
- if (blob != hb_blob_get_empty ())
- return blob;
-
- builder = hb_face_builder_create ();
-
- for (unsigned int i = 0; i < G_N_ELEMENTS (ot_tables); i++)
- {
- hb_blob_t *table;
-
- table = hb_face_reference_table (face, ot_tables[i]);
-
- if (table != hb_blob_get_empty ())
- {
- hb_face_builder_add_table (builder, ot_tables[i], table);
- hb_blob_destroy (table);
- }
- }
-
- blob = hb_face_reference_blob (builder);
-
- hb_face_destroy (builder);
-
- return blob;
-}
-
cairo_font_face_t *
create_cairo_ft_font_face (Pango2Font *font)
{
@@ -154,8 +59,7 @@ create_cairo_ft_font_face (Pango2Font *font)
}
hb_font = pango2_font_get_hb_font (font);
- hbface = hb_font_get_face (hb_font);
- blob = face_get_blob (hbface);
+ blob = pango2_font_get_hb_blob (font);
blob_data = hb_blob_get_data (blob, &blob_length);
if ((error = FT_New_Memory_Face (ft_library,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]