From 79e4f436e7fc4634ed285d548cad48069c6390eb Mon Sep 17 00:00:00 2001 From: justvanrossum Date: Wed, 17 Feb 2021 10:21:58 +0100 Subject: [PATCH] Apply rounding correctly when calculating glyph extents for CFF and CFF2; adjust expected test results --- src/hb-ot-cff1-table.cc | 4 ++-- src/hb-ot-cff2-table.cc | 4 ++-- test/api/test-ot-extents-cff.c | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/hb-ot-cff1-table.cc b/src/hb-ot-cff1-table.cc index 66b9c8c90..3298fa35a 100644 --- a/src/hb-ot-cff1-table.cc +++ b/src/hb-ot-cff1-table.cc @@ -426,7 +426,7 @@ bool OT::cff1::accelerator_t::get_extents (hb_font_t *font, hb_codepoint_t glyph else { extents->x_bearing = font->em_scalef_x (bounds.min.x.to_real ()); - extents->width = font->em_scalef_x (bounds.max.x.to_real () - bounds.min.x.to_real ()); + extents->width = font->em_scalef_x (bounds.max.x.to_real ()) - extents->x_bearing; } if (bounds.min.y >= bounds.max.y) { @@ -436,7 +436,7 @@ bool OT::cff1::accelerator_t::get_extents (hb_font_t *font, hb_codepoint_t glyph else { extents->y_bearing = font->em_scalef_y (bounds.max.y.to_real ()); - extents->height = font->em_scalef_y (bounds.min.y.to_real () - bounds.max.y.to_real ()); + extents->height = font->em_scalef_y (bounds.min.y.to_real ()) - extents->y_bearing; } return true; diff --git a/src/hb-ot-cff2-table.cc b/src/hb-ot-cff2-table.cc index ac0feeee2..879b7cdb2 100644 --- a/src/hb-ot-cff2-table.cc +++ b/src/hb-ot-cff2-table.cc @@ -127,7 +127,7 @@ bool OT::cff2::accelerator_t::get_extents (hb_font_t *font, else { extents->x_bearing = font->em_scalef_x (param.min_x.to_real ()); - extents->width = font->em_scalef_x (param.max_x.to_real () - param.min_x.to_real ()); + extents->width = font->em_scalef_x (param.max_x.to_real ()) - extents->x_bearing; } if (param.min_y >= param.max_y) { @@ -137,7 +137,7 @@ bool OT::cff2::accelerator_t::get_extents (hb_font_t *font, else { extents->y_bearing = font->em_scalef_y (param.max_y.to_real ()); - extents->height = font->em_scalef_y (param.min_y.to_real () - param.max_y.to_real ()); + extents->height = font->em_scalef_y (param.min_y.to_real ()) - extents->y_bearing; } return true; diff --git a/test/api/test-ot-extents-cff.c b/test/api/test-ot-extents-cff.c index 7109e302e..e6aeb0d6e 100644 --- a/test/api/test-ot-extents-cff.c +++ b/test/api/test-ot-extents-cff.c @@ -170,7 +170,7 @@ test_extents_cff2_vsindex (void) g_assert_cmpint (extents.x_bearing, ==, 12); g_assert_cmpint (extents.y_bearing, ==, 655); - g_assert_cmpint (extents.width, ==, 652); + g_assert_cmpint (extents.width, ==, 651); g_assert_cmpint (extents.height, ==, -655); result = hb_font_get_glyph_extents (font, 2, &extents); @@ -178,7 +178,7 @@ test_extents_cff2_vsindex (void) g_assert_cmpint (extents.x_bearing, ==, 8); g_assert_cmpint (extents.y_bearing, ==, 669); - g_assert_cmpint (extents.width, ==, 649); + g_assert_cmpint (extents.width, ==, 648); g_assert_cmpint (extents.height, ==, -669); hb_font_destroy (font); @@ -201,7 +201,7 @@ test_extents_cff2_vsindex_named_instance (void) g_assert_cmpint (extents.x_bearing, ==, 13); g_assert_cmpint (extents.y_bearing, ==, 652); - g_assert_cmpint (extents.width, ==, 653); + g_assert_cmpint (extents.width, ==, 652); g_assert_cmpint (extents.height, ==, -652); result = hb_font_get_glyph_extents (font, 2, &extents);