From fe1c54b984a92d8b82a3fdb9bc88716f17e81be3 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 31 Oct 2021 00:07:52 -0400 Subject: Make logical glyph extents better For east and west gravity, the logical glyph extents were still misaligned with the ink extents. --- pango/pangocairo-font.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pango/pangocairo-font.c b/pango/pangocairo-font.c index 503f863b..597a320d 100644 --- a/pango/pangocairo-font.c +++ b/pango/pangocairo-font.c @@ -934,12 +934,14 @@ _pango_cairo_font_private_get_glyph_extents (PangoCairoFontPrivate *cf_priv, break; case PANGO_GRAVITY_EAST: logical_rect->width = cf_priv->font_extents.height; + logical_rect->x = - logical_rect->width; break; case PANGO_GRAVITY_NORTH: logical_rect->width = entry->width; break; case PANGO_GRAVITY_WEST: logical_rect->width = - cf_priv->font_extents.height; + logical_rect->x = - logical_rect->width; break; case PANGO_GRAVITY_AUTO: default: -- cgit v1.2.1 From 04a58c3ca28732f54fe3f87aa92f61c3e40b8867 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 31 Oct 2021 11:01:43 -0400 Subject: Add tests for matrix transformations --- tests/testmisc.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/testmisc.c b/tests/testmisc.c index 2e14f11e..75c40b0e 100644 --- a/tests/testmisc.c +++ b/tests/testmisc.c @@ -698,6 +698,44 @@ test_gravity_metrics (void) g_object_unref (context); } +static void +test_transform_rectangle (void) +{ + PangoMatrix matrix = PANGO_MATRIX_INIT; + PangoRectangle rect; + PangoRectangle rect2; + + rect = rect2 = (PangoRectangle) { 10 * PANGO_SCALE, 20 * PANGO_SCALE, 30 * PANGO_SCALE, 40 * PANGO_SCALE }; + pango_matrix_transform_rectangle (&matrix, &rect2); + + g_assert_cmpint (rect2.x, ==, rect.x); + g_assert_cmpint (rect2.y, ==, rect.y); + g_assert_cmpint (rect2.width, ==, rect.width); + g_assert_cmpint (rect2.height, ==, rect.height); + + matrix = (PangoMatrix) PANGO_MATRIX_INIT; + pango_matrix_translate (&matrix, 10, 20); + + pango_matrix_transform_rectangle (&matrix, &rect2); + + g_assert_cmpint (rect2.x, ==, rect.x + 10 * PANGO_SCALE); + g_assert_cmpint (rect2.y, ==, rect.y + 20 * PANGO_SCALE); + g_assert_cmpint (rect2.width, ==, rect.width); + g_assert_cmpint (rect2.height, ==, rect.height); + + rect2 = rect; + + matrix = (PangoMatrix) PANGO_MATRIX_INIT; + pango_matrix_rotate (&matrix, -90); + + pango_matrix_transform_rectangle (&matrix, &rect2); + + g_assert_cmpint (rect2.x, ==, - (rect.y + rect.height)); + g_assert_cmpint (rect2.y, ==, rect.x); + g_assert_cmpint (rect2.width, ==, rect.height); + g_assert_cmpint (rect2.height, ==, rect.width); +} + int main (int argc, char *argv[]) { @@ -730,6 +768,7 @@ main (int argc, char *argv[]) g_test_add_func ("/layout/extents", test_extents); g_test_add_func ("/layout/empty-line-height", test_empty_line_height); g_test_add_func ("/layout/gravity-metrics", test_gravity_metrics); + g_test_add_func ("/matrix/transform-rectangle", test_transform_rectangle); return g_test_run (); } -- cgit v1.2.1