diff options
author | Matthias Clasen <mclasen@redhat.com> | 2022-01-02 18:49:34 +0000 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2022-01-02 18:49:34 +0000 |
commit | e7147f503495aa88299ca597382c4a4584ea268e (patch) | |
tree | 01af735f9e717c0184e180da59e9c66c8f493f2b | |
parent | fc46f12754e9035c71da2747be55361ddfcf7635 (diff) | |
parent | 1a553ba64c43c13e37d54f1fb20a656ffb2ef067 (diff) | |
download | pango-e7147f503495aa88299ca597382c4a4584ea268e.tar.gz |
Merge branch 'synthetic-slant' into 'main'
Pass synthetic slant to harfbuzz
See merge request GNOME/pango!474
-rw-r--r-- | pango/pango-matrix.c | 34 | ||||
-rw-r--r-- | pango/pango-matrix.h | 2 | ||||
-rw-r--r-- | pango/pangofc-font.c | 12 | ||||
-rw-r--r-- | tests/testmatrix.c | 26 |
4 files changed, 72 insertions, 2 deletions
diff --git a/pango/pango-matrix.c b/pango/pango-matrix.c index a066eb57..3bc0ff16 100644 --- a/pango/pango-matrix.c +++ b/pango/pango-matrix.c @@ -263,6 +263,40 @@ pango_matrix_get_font_scale_factors (const PangoMatrix *matrix, } /** + * pango_matrix_get_slant_ratio: + * @matrix: a `PangoMatrix` + * + * Gets the slant ratio of a matrix. + * + * For a simple shear matrix in the form: + * + * 1 λ + * 0 1 + * + * this is simply λ. + * + * Returns: the slant ratio of @matrix + * + * Since: 1.50 + */ +double +pango_matrix_get_slant_ratio (const PangoMatrix *matrix) +{ + double x0, y0; + double x1, y1; + + x0 = 0; + y0 = 1; + pango_matrix_transform_distance (matrix, &x0, &y0); + + x1 = 1; + y1 = 0; + pango_matrix_transform_distance (matrix, &x1, &y1); + + return (x0 * x1 + y0 * y1) / (x0 * x0 + y0 * y0); +} + +/** * pango_matrix_transform_distance: * @matrix: (nullable): a `PangoMatrix` * @dx: (inout): in/out X component of a distance vector diff --git a/pango/pango-matrix.h b/pango/pango-matrix.h index d4277401..cb53a422 100644 --- a/pango/pango-matrix.h +++ b/pango/pango-matrix.h @@ -121,6 +121,8 @@ double pango_matrix_get_font_scale_factor (const PangoMatrix *matrix) G_GNUC_PUR PANGO_AVAILABLE_IN_1_38 void pango_matrix_get_font_scale_factors (const PangoMatrix *matrix, double *xscale, double *yscale); +PANGO_AVAILABLE_IN_1_50 +double pango_matrix_get_slant_ratio (const PangoMatrix *matrix) G_GNUC_PURE; G_END_DECLS diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c index 03f15efa..9d555a37 100644 --- a/pango/pangofc-font.c +++ b/pango/pangofc-font.c @@ -964,10 +964,12 @@ pango_fc_font_create_hb_font (PangoFont *font) double x_scale, y_scale; double pixel_size; double point_size; + double slant G_GNUC_UNUSED; x_scale_inv = y_scale_inv = 1.0; pixel_size = 1.0; point_size = 1.0; + slant = 0.0; key = _pango_fc_font_get_font_key (fc_font); if (key) @@ -988,11 +990,12 @@ pango_fc_font_create_hb_font (PangoFont *font) FcMatrixMultiply (&fc_matrix, &fc_matrix, fc_matrix_val); font_matrix.xx = fc_matrix.xx; - font_matrix.yx = fc_matrix.yx; + font_matrix.yx = - fc_matrix.yx; font_matrix.xy = fc_matrix.xy; - font_matrix.yy = fc_matrix.yy; + font_matrix.yy = - fc_matrix.yy; pango_matrix_get_font_scale_factors (&font_matrix, &x, &y); + slant = pango_matrix_get_slant_ratio (&font_matrix); x_scale_inv /= x; y_scale_inv /= y; @@ -1003,6 +1006,7 @@ pango_fc_font_create_hb_font (PangoFont *font) x_scale_inv = -x_scale_inv; y_scale_inv = -y_scale_inv; } + get_font_size (key, &pixel_size, &point_size); } @@ -1017,6 +1021,10 @@ pango_fc_font_create_hb_font (PangoFont *font) pixel_size * PANGO_SCALE * y_scale); hb_font_set_ptem (hb_font, point_size); +#if HB_VERSION_ATLEAST (3, 3, 0) + hb_font_set_synthetic_slant (hb_font, slant); +#endif + if (key) { const FcPattern *pattern = pango_fc_font_key_get_pattern (key); diff --git a/tests/testmatrix.c b/tests/testmatrix.c index 607f2b5f..1ba79839 100644 --- a/tests/testmatrix.c +++ b/tests/testmatrix.c @@ -21,6 +21,7 @@ #include <glib.h> #include <pango/pango.h> +#include <math.h> #define matrix_equal(m1, m2) \ (G_APPROX_VALUE ((m1)->xx, (m2)->xx, 0.0001) && \ @@ -185,6 +186,30 @@ test_matrix_transform_pixel_rect (void) g_assert_cmpfloat_with_epsilon (rect.height, 2, 0.1); } +static void +test_matrix_slant_ratio (void) +{ + PangoMatrix m = (PangoMatrix) { 1, 0, 0.2, 1, 0, 0 }; + PangoMatrix m2 = (PangoMatrix) { 1, 0.4, 0, 1, 0, 0 }; + double r; + + r = pango_matrix_get_slant_ratio (&m); + g_assert_cmphex (r, ==, 0.2); + + pango_matrix_rotate (&m, 45); + + r = pango_matrix_get_slant_ratio (&m); + g_assert_cmphex (r, ==, 0.2); + + pango_matrix_scale (&m, 2, 3); + + r = pango_matrix_get_slant_ratio (&m); + g_assert_cmphex (r, ==, 0.2); + + r = pango_matrix_get_slant_ratio (&m2); + g_assert_cmphex (r, ==, 0.4); +} + int main (int argc, char *argv[]) { @@ -199,6 +224,7 @@ main (int argc, char *argv[]) g_test_add_func ("/matrix/transform-distance", test_matrix_transform_distance); g_test_add_func ("/matrix/transform-rect", test_matrix_transform_rect); g_test_add_func ("/matrix/transform-pixel-rect", test_matrix_transform_pixel_rect); + g_test_add_func ("/matrix/slant-ratio", test_matrix_slant_ratio); return g_test_run (); } |