sd/qa/unit/data/odp/tdf161023.fodp | 35 ++++++++++++++++++++++++ sd/qa/unit/import-tests2.cxx | 52 +++++++++++++++++++++++++++++++++++++ xmloff/source/text/txtparai.cxx | 4 ++ 3 files changed, 90 insertions(+), 1 deletion(-)
New commits: commit 2ca93eb5df7ddb8641ff7d884a109261c9700aca Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Sun May 12 22:53:23 2024 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Mon May 13 04:21:20 2024 +0200 tdf#161023: Empty spans may only define paragraph marks in text documents Change-Id: I40607652a0fd8e31c609732daa54bb796e3fffa0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167557 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/sd/qa/unit/data/odp/tdf161023.fodp b/sd/qa/unit/data/odp/tdf161023.fodp new file mode 100644 index 000000000000..bf3a894cec4b --- /dev/null +++ b/sd/qa/unit/data/odp/tdf161023.fodp @@ -0,0 +1,35 @@ +<?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.presentation"> + <office:font-face-decls> + <style:font-face style:name="Liberation Sans" svg:font-family="'Liberation Sans'" style:font-family-generic="roman" style:font-pitch="variable"/> + </office:font-face-decls> + <office:styles> + <style:style style:name="standard" style:family="graphic"> + <style:text-properties style:font-name="Liberation Sans" fo:font-size="18pt"/> + </style:style> + </office:styles> + <office:automatic-styles> + <style:style style:name="T1" style:family="text"> + <style:text-properties fo:font-size="10pt"/> + </style:style> + </office:automatic-styles> + <office:master-styles> + <draw:layer-set> + <draw:layer draw:name="layout"/> + </draw:layer-set> + </office:master-styles> + <office:body> + <office:presentation> + <draw:page draw:name="page1"> + <draw:frame draw:layer="layout" svg:width="4cm" svg:x="4cm" svg:y="4cm"> + <draw:text-box> + <text:p><text:span text:style-name="T1">a</text:span></text:p> + <text:p><text:span text:style-name="T1"/></text:p> + <text:p><text:span text:style-name="T1">c</text:span></text:p> + </draw:text-box> + </draw:frame> + </draw:page> + </office:presentation> + </office:body> +</office:document> \ No newline at end of file diff --git a/sd/qa/unit/import-tests2.cxx b/sd/qa/unit/import-tests2.cxx index 5457224bd642..d5e6c2bf14bb 100644 --- a/sd/qa/unit/import-tests2.cxx +++ b/sd/qa/unit/import-tests2.cxx @@ -2006,6 +2006,58 @@ CPPUNIT_TEST_FIXTURE(SdImportTest2, testMasterSlides) CPPUNIT_ASSERT_EQUAL(sal_Int32(7), xMasterPages->getCount()); } +CPPUNIT_TEST_FIXTURE(SdImportTest2, testTdf161023) +{ + // Given a shape with three paragraphs (18pt), all directly assigned a smaller font (10pt) + createSdImpressDoc("odp/tdf161023.fodp"); + auto shape = getShapeFromPage(0, 0); + + // 1st paragraph, not empty + { + auto paragraph(getParagraphFromShape(0, shape)); + CPPUNIT_ASSERT_EQUAL(u"a"_ustr, paragraph->getString()); + auto run(getRunFromParagraph(0, paragraph)); + CPPUNIT_ASSERT_EQUAL(u"a"_ustr, run->getString()); + uno::Reference<beans::XPropertySet> xPropSet(run, uno::UNO_QUERY_THROW); + double fCharHeight = 0; + xPropSet->getPropertyValue("CharHeight") >>= fCharHeight; + CPPUNIT_ASSERT_EQUAL(10.0, fCharHeight); + // No more runs + CPPUNIT_ASSERT_THROW(getRunFromParagraph(1, paragraph), container::NoSuchElementException); + } + + // Empty 2nd paragraph, consisting of a single span: this span was treated as "paragraph mark" + { + auto paragraph(getParagraphFromShape(1, shape)); + CPPUNIT_ASSERT_EQUAL(u""_ustr, paragraph->getString()); + auto run(getRunFromParagraph(0, paragraph)); + CPPUNIT_ASSERT_EQUAL(u""_ustr, run->getString()); + uno::Reference<beans::XPropertySet> xPropSet(run, uno::UNO_QUERY_THROW); + double fCharHeight = 0; + xPropSet->getPropertyValue("CharHeight") >>= fCharHeight; + // Without the fix, this would fail with + // - Expected: 10 + // - Actual : 18 + CPPUNIT_ASSERT_EQUAL(10.0, fCharHeight); + // No more runs + CPPUNIT_ASSERT_THROW(getRunFromParagraph(1, paragraph), container::NoSuchElementException); + } + + // 3rd paragraph, not empty + { + auto paragraph(getParagraphFromShape(2, shape)); + CPPUNIT_ASSERT_EQUAL(u"c"_ustr, paragraph->getString()); + auto run(getRunFromParagraph(0, paragraph)); + CPPUNIT_ASSERT_EQUAL(u"c"_ustr, run->getString()); + uno::Reference<beans::XPropertySet> xPropSet(run, uno::UNO_QUERY_THROW); + double fCharHeight = 0; + xPropSet->getPropertyValue("CharHeight") >>= fCharHeight; + CPPUNIT_ASSERT_EQUAL(10.0, fCharHeight); + // No more runs + CPPUNIT_ASSERT_THROW(getRunFromParagraph(1, paragraph), container::NoSuchElementException); + } +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/text/txtparai.cxx b/xmloff/source/text/txtparai.cxx index 816bf8769999..cd4cc2b9996c 100644 --- a/xmloff/source/text/txtparai.cxx +++ b/xmloff/source/text/txtparai.cxx @@ -33,6 +33,7 @@ #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/XPropertySetInfo.hpp> #include <com/sun/star/text/ControlCharacter.hpp> +#include <com/sun/star/text/XTextDocument.hpp> #include <com/sun/star/text/XTextRangeCompare.hpp> #include <com/sun/star/drawing/XShapes.hpp> #include <com/sun/star/container/XEnumerationAccess.hpp> @@ -1796,6 +1797,7 @@ void XMLParaContext::endFastElement(sal_Int32 ) uno::Reference<text::XTextRangeCompare> xCompare(xTxtImport->GetText(), uno::UNO_QUERY); if (xCompare.is()) { + bool bTextDocument = GetImport().GetModel().query<XTextDocument>().is(); try { for (const auto& pHint : m_xHints->GetHints()) @@ -1809,7 +1811,7 @@ void XMLParaContext::endFastElement(sal_Int32 ) // created between commits 6249858a8972aef077e0249bd93cfe8f01bce4d6 and // 1a88efa8e02a6d765dab13c7110443bb9e6acecf, where the trailing empty spans // were used to store the marker formatting - if (pHint->GetType() == XMLHintType::XML_HINT_STYLE + if (bTextDocument && pHint->GetType() == XMLHintType::XML_HINT_STYLE && !m_aMarkerStyleName.hasValue() && xCompare->compareRegionStarts(pHint->GetStart(), xEnd) == 0) {