sw/qa/core/text/text.cxx        |   18 ++++++++++--------
 sw/source/core/text/porlay.cxx  |   12 +-----------
 sw/source/core/text/xmldump.cxx |   18 +++++++++++++++++-
 3 files changed, 28 insertions(+), 20 deletions(-)

New commits:
commit 556689c485c2df35abd6a0cdff76329178af17bf
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Thu Mar 3 20:13:48 2022 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Mar 4 08:08:02 2022 +0100

    sw layout xml dump: improve handling of number portions at the start
    
    It's quite tricky to visit each portion exactly once. The "table" of
    portions is an SwParaPortion, a row is an SwLineLayout, which contains
    SwLinePortion instances. But SwLineLayout inherits from SwTextPortion
    (which is a LinePortion), so depending on if e.g. the paragraph starts
    with a numbering portion (not a text portion) or with plain text (is a
    text portion), the first portion in a line is the line layout itself or
    not.
    
    The old behavior was to explicitly dump the first portion of the line as
    an SwLinePortion, but this way e.g. the expand string of leading number
    portions were not visible.
    
    Change this to moving all the loops to SwFrame::dumpAsXml(), and then
    not recursing in para portions / line layouts, this allows reaching e.g.
    SwFieldPortion::dumpAsXml() for leading number portions.
    
    Change-Id: I813fdece0e4d6b7116112e15ec866046862beeeb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130941
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx
index caeb70e4a89d..5741fe656a81 100644
--- a/sw/qa/core/text/text.cxx
+++ b/sw/qa/core/text/text.cxx
@@ -186,15 +186,17 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, 
testChineseAutoFirstLineIndent)
     xmlDocUniquePtr pXmlDoc = parseLayoutDump();
 
     // Get the line width of the first line for the 1st paragraph.
-    sal_Int32 nFirstLineWidth
-        = getXPath(pXmlDoc, 
"//body/txt[1]/SwParaPortion[1]/SwLineLayout[1]/SwLinePortion[1]",
-                   "width")
-              .toInt32();
+    sal_Int32 nFirstLineWidth = getXPath(pXmlDoc,
+                                         
"//body/txt[1]/SwParaPortion/SwLineLayout[1]/"
+                                         
"SwParaPortion/SwLineLayout/SwLinePortion",
+                                         "width")
+                                    .toInt32();
     // Get the line width of the first line for the 2nd paragraph.
-    sal_Int32 nSecondLineWidth
-        = getXPath(pXmlDoc, 
"//body/txt[2]/SwParaPortion[1]/SwLineLayout[1]/SwLinePortion[1]",
-                   "width")
-              .toInt32();
+    sal_Int32 nSecondLineWidth = getXPath(pXmlDoc,
+                                          
"//body/txt[2]/SwParaPortion/SwLineLayout[1]/"
+                                          
"SwParaPortion/SwLineLayout/SwLinePortion",
+                                          "width")
+                                     .toInt32();
 
     // Tdf#129448: the changing of line-height should not affect the auto 
first line indent.
     // As a result, the first line width of the two paragraphs should be the 
same.
diff --git a/sw/source/core/text/porlay.cxx b/sw/source/core/text/porlay.cxx
index 8212fca02f6a..1be31ad972bd 100644
--- a/sw/source/core/text/porlay.cxx
+++ b/sw/source/core/text/porlay.cxx
@@ -751,13 +751,7 @@ void SwLineLayout::dumpAsXml(xmlTextWriterPtr pWriter) 
const
     (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwLineLayout"));
     (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", 
this);
 
-    const SwLinePortion* pFirstPor = GetFirstPortion();
-    pFirstPor->SwLinePortion::dumpAsXml(pWriter);
-    for (const SwLinePortion* pPor = pFirstPor->GetNextPortion(); pPor;
-         pPor = pPor->GetNextPortion())
-    {
-        pPor->dumpAsXml(pWriter);
-    }
+    SwTextPortion::dumpAsXml(pWriter);
 
     (void)xmlTextWriterEndElement(pWriter);
 }
@@ -2550,10 +2544,6 @@ void SwParaPortion::dumpAsXml(xmlTextWriterPtr pWriter) 
const
     (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", 
this);
 
     SwLineLayout::dumpAsXml(pWriter);
-    for (const SwLineLayout* pLine = GetNext(); pLine; pLine = 
pLine->GetNext())
-    {
-        pLine->dumpAsXml(pWriter);
-    }
 
     (void)xmlTextWriterEndElement(pWriter);
 }
diff --git a/sw/source/core/text/xmldump.cxx b/sw/source/core/text/xmldump.cxx
index 1e52e8fdbb68..b7c05e716a5e 100644
--- a/sw/source/core/text/xmldump.cxx
+++ b/sw/source/core/text/xmldump.cxx
@@ -485,7 +485,23 @@ void SwFrame::dumpAsXml( xmlTextWriterPtr writer ) const
             pTextFrame->VisitPortions( pdumper );
             if (const SwParaPortion* pPara = pTextFrame->GetPara())
             {
-                pPara->dumpAsXml(writer);
+                (void)xmlTextWriterStartElement(writer, 
BAD_CAST("SwParaPortion"));
+                (void)xmlTextWriterWriteFormatAttribute(writer, 
BAD_CAST("ptr"), "%p", pPara);
+                const SwLineLayout* pLine = pPara;
+                while (pLine)
+                {
+                    (void)xmlTextWriterStartElement(writer, 
BAD_CAST("SwLineLayout"));
+                    (void)xmlTextWriterWriteFormatAttribute(writer, 
BAD_CAST("ptr"), "%p", pLine);
+                    const SwLinePortion* pPor = pLine->GetFirstPortion();
+                    while (pPor)
+                    {
+                        pPor->dumpAsXml(writer);
+                        pPor = pPor->GetNextPortion();
+                    }
+                    (void)xmlTextWriterEndElement(writer);
+                    pLine = pLine->GetNext();
+                }
+                (void)xmlTextWriterEndElement(writer);
             }
 
         }

Reply via email to