diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2024-04-24 13:05:13 +0500 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2024-04-29 10:02:51 +0500 |
commit | 1dea0177e554a9d4f93b19e3604e5476c111183f (patch) | |
tree | 840f79bfb9f554712dff526618090118f262db91 | |
parent | bf51233e9f83148c7399718c6d6ca7f09eabdd21 (diff) |
Reapply "tdf#160436: fix glyph bounds calculation for vertical glyphs"
This reverts commit 9599b7d969cfe534c17d2249fd8f718dbb39867a.
-rw-r--r-- | vcl/qa/cppunit/logicalfontinstance.cxx | 25 | ||||
-rw-r--r-- | vcl/source/font/LogicalFontInstance.cxx | 11 |
2 files changed, 32 insertions, 4 deletions
diff --git a/vcl/qa/cppunit/logicalfontinstance.cxx b/vcl/qa/cppunit/logicalfontinstance.cxx index 1eaf0ebd28db..77de9b9b4e3f 100644 --- a/vcl/qa/cppunit/logicalfontinstance.cxx +++ b/vcl/qa/cppunit/logicalfontinstance.cxx @@ -46,6 +46,7 @@ void VclLogicalFontInstanceTest::testglyphboundrect() basegfx::B2DRectangle aBoundRect; const auto LATIN_SMALL_LETTER_B = 0x0062; + const auto SECTION_SIGN = 0x00A7; // UTR#50: Vertical_Orientation (vo) property value U pFontInstance->GetGlyphBoundRect(pFontInstance->GetGlyphIndex(LATIN_SMALL_LETTER_B), aBoundRect, false); @@ -54,6 +55,14 @@ void VclLogicalFontInstanceTest::testglyphboundrect() CPPUNIT_ASSERT_DOUBLES_EQUAL(49.5, aBoundRect.getWidth(), 0.05); CPPUNIT_ASSERT_DOUBLES_EQUAL(80.8, aBoundRect.getHeight(), 0.05); + // tdf#160436: test vertically oriented glyphs + pFontInstance->GetGlyphBoundRect(pFontInstance->GetGlyphIndex(SECTION_SIGN), aBoundRect, true); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(-79.7, aBoundRect.getMinX(), 0.05); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-55.0, aBoundRect.getMinY(), 0.05); + CPPUNIT_ASSERT_DOUBLES_EQUAL(88.9, aBoundRect.getWidth(), 0.05); + CPPUNIT_ASSERT_DOUBLES_EQUAL(48.8, aBoundRect.getHeight(), 0.05); + font.SetOrientation(900_deg10); device->SetFont(font); @@ -67,6 +76,14 @@ void VclLogicalFontInstanceTest::testglyphboundrect() CPPUNIT_ASSERT_DOUBLES_EQUAL(80.8, aBoundRect.getWidth(), 0.05); CPPUNIT_ASSERT_DOUBLES_EQUAL(49.5, aBoundRect.getHeight(), 0.05); + // tdf#160436: test vertically oriented glyphs + pFontInstance->GetGlyphBoundRect(pFontInstance->GetGlyphIndex(SECTION_SIGN), aBoundRect, true); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(-55.0, aBoundRect.getMinX(), 0.05); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-9.2, aBoundRect.getMinY(), 0.05); + CPPUNIT_ASSERT_DOUBLES_EQUAL(48.8, aBoundRect.getWidth(), 0.05); + CPPUNIT_ASSERT_DOUBLES_EQUAL(88.9, aBoundRect.getHeight(), 0.05); + font.SetOrientation(450_deg10); device->SetFont(font); @@ -79,6 +96,14 @@ void VclLogicalFontInstanceTest::testglyphboundrect() CPPUNIT_ASSERT_DOUBLES_EQUAL(-96.4, aBoundRect.getMinY(), 0.05); CPPUNIT_ASSERT_DOUBLES_EQUAL(92.1, aBoundRect.getWidth(), 0.05); CPPUNIT_ASSERT_DOUBLES_EQUAL(92.1, aBoundRect.getHeight(), 0.05); + + // tdf#160436: test vertically oriented glyphs + pFontInstance->GetGlyphBoundRect(pFontInstance->GetGlyphIndex(SECTION_SIGN), aBoundRect, true); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(-95.3, aBoundRect.getMinX(), 0.05); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-45.4, aBoundRect.getMinY(), 0.05); + CPPUNIT_ASSERT_DOUBLES_EQUAL(97.4, aBoundRect.getWidth(), 0.05); + CPPUNIT_ASSERT_DOUBLES_EQUAL(97.4, aBoundRect.getHeight(), 0.05); } CPPUNIT_TEST_SUITE_REGISTRATION(VclLogicalFontInstanceTest); diff --git a/vcl/source/font/LogicalFontInstance.cxx b/vcl/source/font/LogicalFontInstance.cxx index 6524422397f0..9d893b85aa70 100644 --- a/vcl/source/font/LogicalFontInstance.cxx +++ b/vcl/source/font/LogicalFontInstance.cxx @@ -171,8 +171,8 @@ void LogicalFontInstance::IgnoreFallbackForUnicode(sal_UCS4 cChar, FontWeight eW bool LogicalFontInstance::GetGlyphBoundRect(sal_GlyphId nID, basegfx::B2DRectangle& rRect, bool bVertical) const { - // TODO/FIXME: bVertical handling here is highly suspicious. When it's true, it may - // return different rectangle, depending on if this glyph was cached already or not. + // TODO: find out if it's possible for the same glyph in the same font to be used both + // normally and vertically; if yes, then these two variants must be cached separately if (mpFontCache && mpFontCache->GetCachedGlyphBoundRect(this, nID, rRect)) return true; @@ -191,10 +191,13 @@ bool LogicalFontInstance::GetGlyphBoundRect(sal_GlyphId nID, basegfx::B2DRectang double fMaxY = -(aExtents.y_bearing + aExtents.height) * nYScale; rRect = basegfx::B2DRectangle(fMinX, fMinY, fMaxX, fMaxY); - if (mnOrientation && !bVertical) + auto orientation = mnOrientation; + if (bVertical) + orientation += 900_deg10; + if (orientation) { // Apply font rotation. - rRect.transform(basegfx::utils::createRotateB2DHomMatrix(-toRadians(mnOrientation))); + rRect.transform(basegfx::utils::createRotateB2DHomMatrix(-toRadians(orientation))); } if (mpFontCache) |