drawinglayer/source/processor2d/vclprocessor2d.cxx | 5 + sw/qa/core/text/data/tdf161990-subscripts.fodt | 44 +++++++++++++++ sw/qa/core/text/text.cxx | 58 +++++++++++++++++++++ 3 files changed, 105 insertions(+), 2 deletions(-)
New commits: commit ccc3996cfcbebe14e9d5f3511906cfc64ddf3452 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Sat Jul 13 22:54:05 2024 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Sat Jul 13 23:17:11 2024 +0200 tdf#161990: take MapMode's origin point into account Regression from commit cc3663bbaed4f65d64154e5f9abb51a5f622f710 (tdf#160702: improve text positioning, 2024-04-20). Change-Id: I03f461d7f03c3e67ccdb8c4376720feb69903d6b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170432 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/drawinglayer/source/processor2d/vclprocessor2d.cxx b/drawinglayer/source/processor2d/vclprocessor2d.cxx index b21348cf6635..f7fd3fda7606 100644 --- a/drawinglayer/source/processor2d/vclprocessor2d.cxx +++ b/drawinglayer/source/processor2d/vclprocessor2d.cxx @@ -434,13 +434,14 @@ void VclProcessor2D::RenderTextSimpleOrDecoratedPortionPrimitive2D( MapMode aMapMode = mpOutputDevice->GetMapMode(); aMapMode.SetScaleX(aMapMode.GetScaleX() * nFontScalingFixX); aMapMode.SetScaleY(aMapMode.GetScaleY() * nFontScalingFixY); + Point origin = aMapMode.GetOrigin(); mpOutputDevice->Push(vcl::PushFlags::MAPMODE); mpOutputDevice->SetRelativeMapMode(aMapMode); bChangeMapMode = true; - aPointX /= nFontScalingFixX; - aPointY /= nFontScalingFixY; + aPointX = (aPointX + origin.X()) / nFontScalingFixX - origin.X(); + aPointY = (aPointY + origin.Y()) / nFontScalingFixY - origin.Y(); } } diff --git a/sw/qa/core/text/data/tdf161990-subscripts.fodt b/sw/qa/core/text/data/tdf161990-subscripts.fodt new file mode 100644 index 000000000000..c9f172aa6d56 --- /dev/null +++ b/sw/qa/core/text/data/tdf161990-subscripts.fodt @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:font-face-decls> + <style:font-face style:name="Liberation Sans" svg:font-family="'Liberation Sans'" style:font-family-generic="swiss" style:font-pitch="variable"/> + </office:font-face-decls> + <office:styles> + <style:default-style style:family="graphic"> + <style:graphic-properties draw:start-line-spacing-horizontal="2.83mm" draw:start-line-spacing-vertical="2.83mm" draw:end-line-spacing-horizontal="2.83mm" draw:end-line-spacing-vertical="2.83mm" style:writing-mode="lr-tb" style:flow-with-text="false"/> + <style:paragraph-properties style:text-autospace="ideograph-alpha" style:line-break="strict" style:font-independent-line-spacing="false"/> + <style:text-properties style:use-window-font-color="true" style:font-name="Liberation Sans" fo:font-size="12pt" style:letter-kerning="true"/> + </style:default-style> + </office:styles> + <office:automatic-styles> + <style:style style:name="T1" style:family="text"> + <style:text-properties style:text-position="-33% 58%" fo:font-size="11pt"/> + </style:style> + <style:style style:name="gr1" style:family="graphic"> + <style:graphic-properties draw:stroke="none" draw:fill="none" draw:textarea-horizontal-align="left" draw:auto-grow-height="true" draw:auto-grow-width="true" fo:min-height="5mm" fo:min-width="4mm" fo:padding-top="0" fo:padding-bottom="0" fo:padding-left="0" fo:padding-right="0" fo:wrap-option="wrap" draw:shadow="hidden" style:run-through="foreground" style:vertical-pos="top" style:vertical-rel="page-content" style:horizontal-pos="left" style:horizontal-rel="page-content"/> + </style:style> + <style:page-layout style:name="pm1"> + <style:page-layout-properties fo:page-width="210mm" fo:page-height="297mm" style:print-orientation="portrait" fo:margin-top="20mm" fo:margin-bottom="20mm" fo:margin-left="20mm" fo:margin-right="20mm" style:writing-mode="lr-tb"/> + </style:page-layout> + <style:style style:name="dp1" style:family="drawing-page"/> + </office:automatic-styles> + <office:master-styles> + <style:master-page style:name="Standard" style:page-layout-name="pm1" draw:style-name="dp1"/> + </office:master-styles> + <office:body> + <office:text> + <draw:frame text:anchor-type="page" text:anchor-page-number="1" draw:name="Shape_p1" draw:style-name="gr1" svg:width="9.16mm" svg:height="8.4mm" svg:x="0" svg:y="0"> + <draw:text-box> + <text:p>P<text:span text:style-name="T1">1</text:span></text:p> + </draw:text-box> + </draw:frame> + <draw:frame text:anchor-type="page" text:anchor-page-number="6" draw:name="Shape_p6" draw:style-name="gr1" svg:width="9.16mm" svg:height="8.4mm" svg:x="0" svg:y="0"> + <draw:text-box> + <text:p>P<text:span text:style-name="T1">1</text:span></text:p> + </draw:text-box> + </draw:frame> + <text:p/> + </office:text> + </office:body> +</office:document> \ No newline at end of file diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx index 933fb30f696f..2ca30c713f03 100644 --- a/sw/qa/core/text/text.cxx +++ b/sw/qa/core/text/text.cxx @@ -1700,6 +1700,64 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testTdf112594) u"\u202F\u1824"_ustr); } +CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testTdf161990) +{ + auto pPDFium = vcl::pdf::PDFiumLibrary::get(); + if (!pPDFium) + return; + + // Given a file with two frames, each having a subscript run, on pages 1 and 6: + createSwDoc("tdf161990-subscripts.fodt"); + + // When exporting to PDF: + save(u"writer_pdf_Export"_ustr); + auto pPdfDocument = parsePDFExport(); + + // Check that both subscripts are positioned correctly relative to the non-subscript runs + double expectedOffset = 0; + + // Page 1 + { + auto pPage = pPdfDocument->openPage(0); + auto pTextPage = pPage->getTextPage(); + + CPPUNIT_ASSERT_EQUAL(2, pPage->getObjectCount()); + + auto pObject = pPage->getObject(0); + CPPUNIT_ASSERT_EQUAL(u"P"_ustr, pObject->getText(pTextPage)); + auto textPPos = pObject->getBounds(); + pObject = pPage->getObject(1); + CPPUNIT_ASSERT_EQUAL(u"1"_ustr, pObject->getText(pTextPage)); + auto text1Pos = pObject->getBounds(); + expectedOffset = textPPos.getMaxY() - text1Pos.getMaxY(); + // Without the fix, this would fail with + // - Expected: 7.49 + // - Actual : 7.54150390625 + // But if it fails in some configurations because of different page units, then this + // check is not as important as that this value is the same as on the 6th page below. + CPPUNIT_ASSERT_DOUBLES_EQUAL(7.49, expectedOffset, 0.01); + } + + // Page 6 + { + auto pPage = pPdfDocument->openPage(5); + auto pTextPage = pPage->getTextPage(); + + CPPUNIT_ASSERT_EQUAL(2, pPage->getObjectCount()); + + auto pObject = pPage->getObject(0); + CPPUNIT_ASSERT_EQUAL(u"P"_ustr, pObject->getText(pTextPage)); + auto textPPos = pObject->getBounds(); + pObject = pPage->getObject(1); + CPPUNIT_ASSERT_EQUAL(u"1"_ustr, pObject->getText(pTextPage)); + auto text1Pos = pObject->getBounds(); + // Without the fix, this would fail with + // - Expected: 7.4925537109375 + // - Actual : 20.9005126953125 + CPPUNIT_ASSERT_DOUBLES_EQUAL(expectedOffset, textPPos.getMaxY() - text1Pos.getMaxY(), 0.01); + } +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */