sw/qa/core/text/data/number-portion-format.odt          |binary
 sw/qa/extras/odfimport/data/empty_line_in_text_box.fodt |   31 ++++++++
 sw/qa/extras/odfimport/odfimport.cxx                    |   53 +++++++++++++
 xmloff/source/text/txtparai.cxx                         |   62 ++++------------
 4 files changed, 102 insertions(+), 44 deletions(-)

New commits:
commit 1201d3d6b0457bac30105bf5371c76a4ef69f29a
Author:     Mike Kaganski <[email protected]>
AuthorDate: Mon May 13 15:04:09 2024 +0500
Commit:     Mike Kaganski <[email protected]>
CommitDate: Tue May 14 05:45:20 2024 +0200

    tdf#161054: drop support of last empty span as paragraph mark format
    
    Commits 6249858a8972aef077e0249bd93cfe8f01bce4d6 (sw: ODT import/export
    of DOCX's paragraph marker formatting, 2022-12-19)
    and 209dce614c43f63f63f5b42a746665c0ec1cbfe3 (sw: fix ODT import of
    paragraph marker formatting, 2022-12-20) introduced support for paragraph
    marker formatting in ODF, using an empty trailing span. Later, commit
    1a88efa8e02a6d765dab13c7110443bb9e6acecf (tdf#155238: Reimplement how
    ListAutoFormat is stored to ODF, 2023-05-11) changed how the data was
    stored in ODF. Then, in commit 69ed893087f89d176a5ec4b263ce8d75774be72b
    (tdf#160253: fix list identifier export decision code, 2024-04-24), some
    remnants of the older "trailing empty spans" were removed, but a code
    was added in XMLParaContext::endFastElement, to keep backward compatible
    with documents created in the frame between December 2022 and May 2023.
    
    The said compatibility code brings own problems, requiring new hacks
    like commit 2ca93eb5df7ddb8641ff7d884a109261c9700aca (tdf#161023: Empty
    spans may only define paragraph marks in text documents, 2024-05-13),
    and keeping the code would need more hacks on top, e.g. to fix the case
    in ODT documents.
    
    Instead, let's bite the bullet, and drop the compatibility with this
    initial implementation, because it was only a brief period during which
    the documents could be created, which can be affected by this drop. This
    makes the code simpler.
    
    A testdoc for testNumberPortionFormat was edited to use the new markup
    for the paragraph marks formatting.
    
    Change-Id: I053e72dd1cc2ead83baa6ce7d24c8522b494c8fa
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167583
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>

diff --git a/sw/qa/core/text/data/number-portion-format.odt 
b/sw/qa/core/text/data/number-portion-format.odt
index 19b23ae84420..70b67ee3547e 100644
Binary files a/sw/qa/core/text/data/number-portion-format.odt and 
b/sw/qa/core/text/data/number-portion-format.odt differ
diff --git a/sw/qa/extras/odfimport/data/empty_line_in_text_box.fodt 
b/sw/qa/extras/odfimport/data/empty_line_in_text_box.fodt
new file mode 100644
index 000000000000..4ae36a9c5fac
--- /dev/null
+++ b/sw/qa/extras/odfimport/data/empty_line_in_text_box.fodt
@@ -0,0 +1,31 @@
+<?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="&apos;Liberation Sans&apos;" style:font-family-generic="swiss" 
style:font-pitch="variable"/>
+ </office:font-face-decls>
+ <office:styles>
+  <style:default-style style:family="graphic">
+   <style:text-properties style:font-name="Liberation Sans" 
fo:font-size="18pt"/>
+  </style:default-style>
+ </office:styles>
+ <office:automatic-styles>
+  <style:style style:name="T1" style:family="text">
+   <style:text-properties fo:font-size="10pt"/>
+  </style:style>
+  <style:style style:name="gr1" style:family="graphic">
+   <style:graphic-properties style:vertical-pos="from-top" 
style:vertical-rel="paragraph" style:horizontal-pos="from-left" 
style:horizontal-rel="paragraph"/>
+  </style:style>
+ </office:automatic-styles>
+ <office:body>
+  <office:text>
+   <text:p text:style-name="Standard"><draw:frame text:anchor-type="paragraph" 
draw:name="TextFrame1" draw:style-name="gr1" 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></text:p>
+  </office:text>
+ </office:body>
+</office:document>
\ No newline at end of file
diff --git a/sw/qa/extras/odfimport/odfimport.cxx 
b/sw/qa/extras/odfimport/odfimport.cxx
index 82d73ab5b8dc..a12cd5b53641 100644
--- a/sw/qa/extras/odfimport/odfimport.cxx
+++ b/sw/qa/extras/odfimport/odfimport.cxx
@@ -1563,6 +1563,59 @@ CPPUNIT_TEST_FIXTURE(Test, testBrokenPackage_Tdf159474)
     CPPUNIT_ASSERT_EQUAL(u"Empty document"_ustr, getParagraph(1)->getString());
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testTdf161054)
+{
+    // Similar to testTdf161023 in sd/qa/unit/import-tests2.cxx
+    // Given a shape with three paragraphs (18pt), all directly assigned a 
smaller font (10pt)
+    createSwDoc("empty_line_in_text_box.fodt");
+    auto shapeText = getShape(1).queryThrow<text::XTextRange>()->getText();
+
+    // 1st paragraph, not empty
+    {
+        auto paragraph(getParagraphOfText(1, shapeText));
+        CPPUNIT_ASSERT_EQUAL(u"a"_ustr, paragraph->getString());
+        auto run(getRun(paragraph, 1));
+        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(getRun(paragraph, 2), 
container::NoSuchElementException);
+    }
+
+    // Empty 2nd paragraph, consisting of a single span: this span was treated 
as "paragraph mark"
+    {
+        auto paragraph(getParagraphOfText(2, shapeText));
+        CPPUNIT_ASSERT_EQUAL(u""_ustr, paragraph->getString());
+        auto run(getRun(paragraph, 1));
+        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(getRun(paragraph, 2), 
container::NoSuchElementException);
+    }
+
+    // 3rd paragraph, not empty
+    {
+        auto paragraph(getParagraphOfText(3, shapeText));
+        CPPUNIT_ASSERT_EQUAL(u"c"_ustr, paragraph->getString());
+        auto run(getRun(paragraph, 1));
+        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(getRun(paragraph, 2), 
container::NoSuchElementException);
+    }
+}
+
 } // end of anonymous namespace
 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 cd4cc2b9996c..3b7969256f08 100644
--- a/xmloff/source/text/txtparai.cxx
+++ b/xmloff/source/text/txtparai.cxx
@@ -33,7 +33,6 @@
 #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>
@@ -1790,48 +1789,6 @@ void XMLParaContext::endFastElement(sal_Int32 )
                                                true,
                                                mbOutlineContentVisible);
 
-    bool bEmptyHints = false;
-    XMLHint_Impl* pMarkerStyleHint = nullptr;
-    if (m_xHints)
-    {
-        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())
-                {
-                    if (xCompare->compareRegionStarts(pHint->GetStart(), 
pHint->GetEnd()) == 0)
-                    {
-                        bEmptyHints = true;
-
-                        // Is this the trailing empty span, defining the 
paragraph mark properties?
-                        // Convert it to the marker style, for backward 
compatibility with documents
-                        // created between commits 
6249858a8972aef077e0249bd93cfe8f01bce4d6 and
-                        // 1a88efa8e02a6d765dab13c7110443bb9e6acecf, where the 
trailing empty spans
-                        // were used to store the marker formatting
-                        if (bTextDocument && pHint->GetType() == 
XMLHintType::XML_HINT_STYLE
-                            && !m_aMarkerStyleName.hasValue()
-                            && 
xCompare->compareRegionStarts(pHint->GetStart(), xEnd) == 0)
-                        {
-                            if (auto pStyle = 
GetImport().GetTextImport()->FindAutoCharStyle(
-                                    
static_cast<XMLStyleHint_Impl*>(pHint.get())->GetStyleName()))
-                            {
-                                m_aMarkerStyleName = pStyle->GetAutoName();
-                                pMarkerStyleHint = pHint.get();
-                            }
-                        }
-                    }
-                }
-            }
-            catch (const uno::Exception&)
-            {
-                TOOLS_WARN_EXCEPTION("xmloff.text", "");
-            }
-        }
-    }
-
     if (m_aMarkerStyleName.hasValue())
     {
         if (auto xPropSet = xStart.query<css::beans::XPropertySet>())
@@ -1891,6 +1848,24 @@ void XMLParaContext::endFastElement(sal_Int32 )
 
     if (m_xHints)
     {
+        bool bEmptyHints = false;
+        if (auto xCompare = 
xTxtImport->GetText().query<text::XTextRangeCompare>())
+        {
+            try
+            {
+                for (const auto& pHint : m_xHints->GetHints())
+                {
+                    if (xCompare->compareRegionStarts(pHint->GetStart(), 
pHint->GetEnd()) == 0)
+                    {
+                        bEmptyHints = true;
+                    }
+                }
+            }
+            catch (const uno::Exception&)
+            {
+                TOOLS_WARN_EXCEPTION("xmloff.text", "");
+            }
+        }
         bool bSetNoFormatAttr = false;
         uno::Reference<beans::XPropertySet> xCursorProps(xAttrCursor, 
uno::UNO_QUERY);
         if (bEmptyHints || m_aMarkerStyleName.hasValue())
@@ -1912,7 +1887,6 @@ void XMLParaContext::endFastElement(sal_Int32 )
             switch( pHint->GetType() )
             {
             case XMLHintType::XML_HINT_STYLE:
-                if (pHint != pMarkerStyleHint) // already processed above
                 {
                     const OUString& rStyleName =
                             static_cast<XMLStyleHint_Impl 
*>(pHint)->GetStyleName();

Reply via email to