diff options
author | Mark Hung <marklm9@gmail.com> | 2022-05-30 08:18:16 +0800 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-06-07 08:51:58 +0200 |
commit | 7f310b8c2d8d496b38dd62aa6b06e61442e1a2d0 (patch) | |
tree | 29a4074e7009fe0c46b09e34af6d9acea7437d9d /sw/qa | |
parent | 1f127a2b9e1c1daab0972f98fc8708ecb7afa299 (diff) |
tdf#149365 tdf#149214 handle IVS and mix width chars
in Justify::SnapToGrid correctly, and use it in
SwFntObj::GetTextBreak() and SwFntObj::GetModelPositionForViewPoint()
to get correct text positions before any further calculation.
In fntcache.cxx a simple formula was used to calculate the average
width of text grids occupied by ideographs. That's incorrect because 1)
for strings containing Unicode IVS, a ideograph is composed of several
sal_Unicode and the length of the string is not the same as the number
of ideographs contained. 2) The average width doesn't work because
character width varies, like ideograph and half-width kana in the
test case.
Change-Id: I863e8d8e346f555ff184a2f47d615e513b965b34
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135342
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw/qa')
-rw-r--r-- | sw/qa/core/txtnode/justify.cxx | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/sw/qa/core/txtnode/justify.cxx b/sw/qa/core/txtnode/justify.cxx index ec63c2b8c5a4..8f8956f5a736 100644 --- a/sw/qa/core/txtnode/justify.cxx +++ b/sw/qa/core/txtnode/justify.cxx @@ -121,8 +121,37 @@ CPPUNIT_TEST_FIXTURE(SwCoreJustifyTest, testSnapToGrid) 1360, 1040, 1200, 1200, 1200, 1200, 1200, 1200, 1040, 1360, 1200, 1040 }; aActual.InvokeWithKernArray( - [&] { nDelta = Justify::SnapToGrid(aActual.maArray, aText, 0, 12, 400, 14400); }); + [&] { nDelta = Justify::SnapToGrid(aActual.maArray, aText, 0, 12, 400, false); }); CPPUNIT_ASSERT_EQUAL(aExpected, aActual); CPPUNIT_ASSERT_EQUAL(tools::Long(160), nDelta); } + +CPPUNIT_TEST_FIXTURE(SwCoreJustifyTest, testSnapToGridMixWidth) +{ + // Related to: tdf#149365 + tools::Long nDelta = 0; + // "中中中ケコサシスセソカケコ" ( mixing fullwidth ideograph and half-width kana ) + static const OUStringLiteral aText + = u"\u4e2d\u4e2d\u4e2d\uff79\uff7a\uff7b\uff7c\uff7d\uff7e\uff7f\uff76\uff79\uff7a"; + CharWidthArray aActual{ 640, 640, 640, 320, 320, 320, 320, 320, 320, 320, 320, 320, 320 }; + CharWidthArray aExpected{ 800, 800, 760, 400, 400, 400, 400, 400, 400, 400, 400, 400, 360 }; + aActual.InvokeWithKernArray( + [&] { nDelta = Justify::SnapToGrid(aActual.maArray, aText, 0, 13, 400, false); }); + CPPUNIT_ASSERT_EQUAL(aExpected, aActual); + CPPUNIT_ASSERT_EQUAL(tools::Long(80), nDelta); +} + +CPPUNIT_TEST_FIXTURE(SwCoreJustifyTest, testSnapToGridIVS) +{ + // Related to: tdf#149214 + tools::Long nDelta = 0; + static const OUStringLiteral aText = u"\u9053\u9ad8\u4e00\U000E01E2\u5c3a\u5316"; + + CharWidthArray aActual{ 800, 800, 800, 0, 0, 800, 800 }; + CharWidthArray aExpected{ 800, 800, 800, 0, 0, 800, 800 }; + aActual.InvokeWithKernArray( + [&] { nDelta = Justify::SnapToGrid(aActual.maArray, aText, 0, 7, 400, false); }); + CPPUNIT_ASSERT_EQUAL(aExpected, aActual); + CPPUNIT_ASSERT_EQUAL(tools::Long(0), nDelta); +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |