[pango/serialization-improvements: 10/19] Add a way to get the font matrix
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/serialization-improvements: 10/19] Add a way to get the font matrix
- Date: Thu, 25 Nov 2021 00:58:54 +0000 (UTC)
commit c4fe95cc313bab3eac480425f822a0eeebf9b686
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Nov 24 12:19:42 2021 -0500
Add a way to get the font matrix
Add some private api for the serializer to get
the font matrix. This is needed to let the serializer
write a unique fingerprint for the font.
pango/fonts.c | 17 +++++++++++++++++
pango/pango-font-private.h | 5 +++++
pango/pangofc-font.c | 22 ++++++++++++++++++++++
3 files changed, 44 insertions(+)
---
diff --git a/pango/fonts.c b/pango/fonts.c
index 9d3c1bf3..d94feaf8 100644
--- a/pango/fonts.c
+++ b/pango/fonts.c
@@ -1751,6 +1751,13 @@ pango_font_default_get_face (PangoFont *font)
return PANGO_FONT_MAP_GET_CLASS (map)->get_face (map,font);
}
+static void
+pango_font_default_get_matrix (PangoFont *font,
+ PangoMatrix *matrix)
+{
+ *matrix = (PangoMatrix) PANGO_MATRIX_INIT;
+}
+
static void
pango_font_class_init (PangoFontClass *class G_GNUC_UNUSED)
{
@@ -1766,6 +1773,7 @@ pango_font_class_init (PangoFontClass *class G_GNUC_UNUSED)
pclass->get_scale_factors = pango_font_default_get_scale_factors;
pclass->has_char = pango_font_default_has_char;
pclass->get_face = pango_font_default_get_face;
+ pclass->get_matrix = pango_font_default_get_matrix;
}
static void
@@ -2717,6 +2725,15 @@ pango_font_get_languages (PangoFont *font)
return pclass->get_languages (font);
}
+void
+pango_font_get_matrix (PangoFont *font,
+ PangoMatrix *matrix)
+{
+ PangoFontClassPrivate *pclass = PANGO_FONT_GET_CLASS_PRIVATE (font);
+
+ pclass->get_matrix (font, matrix);
+}
+
gboolean
pango_font_is_hinted (PangoFont *font)
{
diff --git a/pango/pango-font-private.h b/pango/pango-font-private.h
index 93ce27aa..1e38371d 100644
--- a/pango/pango-font-private.h
+++ b/pango/pango-font-private.h
@@ -45,12 +45,17 @@ typedef struct {
gboolean (* has_char) (PangoFont *font,
gunichar wc);
PangoFontFace * (* get_face) (PangoFont *font);
+ void (* get_matrix) (PangoFont *font,
+ PangoMatrix *matrix);
} PangoFontClassPrivate;
gboolean pango_font_is_hinted (PangoFont *font);
void pango_font_get_scale_factors (PangoFont *font,
double *x_scale,
double *y_scale);
+void pango_font_get_matrix (PangoFont *font,
+ PangoMatrix *matrix);
+
G_END_DECLS
diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c
index 74503b91..5635e0be 100644
--- a/pango/pangofc-font.c
+++ b/pango/pangofc-font.c
@@ -75,6 +75,8 @@ static gboolean _pango_fc_font_is_hinted (PangoFont *fon
static void _pango_fc_font_get_scale_factors (PangoFont *font,
double *x_scale,
double *y_scale);
+static void pango_fc_font_get_matrix (PangoFont *font,
+ PangoMatrix *matrix);
#define PANGO_FC_FONT_LOCK_FACE(font) (PANGO_FC_FONT_GET_CLASS (font)->lock_face (font))
#define PANGO_FC_FONT_UNLOCK_FACE(font) (PANGO_FC_FONT_GET_CLASS (font)->unlock_face (font))
@@ -109,6 +111,7 @@ pango_fc_font_class_init (PangoFcFontClass *class)
pclass->get_languages = _pango_fc_font_get_languages;
pclass->is_hinted = _pango_fc_font_is_hinted;
pclass->get_scale_factors = _pango_fc_font_get_scale_factors;
+ pclass->get_matrix = pango_fc_font_get_matrix;
/**
* PangoFcFont:pattern:
@@ -1110,3 +1113,22 @@ _pango_fc_font_get_scale_factors (PangoFont *font,
pango_matrix_get_font_scale_factors (&fcfont->matrix, x_scale, y_scale);
}
+
+static void
+pango_fc_font_get_matrix (PangoFont *font,
+ PangoMatrix *matrix)
+{
+ PangoFcFont *fcfont = PANGO_FC_FONT (font);
+ FcMatrix fc_matrix, *fc_matrix_val;
+
+ FcMatrixInit (&fc_matrix);
+ for (int i = 0; FcPatternGetMatrix (fcfont->font_pattern, FC_MATRIX, i, &fc_matrix_val) == FcResultMatch;
i++)
+ FcMatrixMultiply (&fc_matrix, &fc_matrix, fc_matrix_val);
+
+ matrix->xx = fc_matrix.xx;
+ matrix->xy = - fc_matrix.xy;
+ matrix->yx = - fc_matrix.yx;
+ matrix->yy = fc_matrix.yy;
+ matrix->x0 = 0.;
+ matrix->y0 = 0.;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]