sw/qa/core/text/data/number-portion-format.odt          |binary
 sw/qa/core/text/text.cxx                                |   18 +++++++++++++
 sw/qa/extras/ooxmlexport/data/number-portion-format.odt |binary
 sw/qa/extras/ooxmlexport/ooxmlexport18.cxx              |   20 ++++++++++++++
 sw/source/core/text/txtfld.cxx                          |   22 ++++++++++++++++
 sw/source/filter/ww8/docxattributeoutput.cxx            |    2 -
 sw/source/filter/ww8/wrtw8nds.cxx                       |   15 +++++++++-
 7 files changed, 74 insertions(+), 3 deletions(-)

New commits:
commit 6f4836ae8b72a4f4a5f7a8cb7d32a435a4b96be6
Author:     Miklos Vajna <[email protected]>
AuthorDate: Fri Oct 28 16:39:31 2022 +0200
Commit:     Miklos Vajna <[email protected]>
CommitDate: Tue Jan 3 07:01:35 2023 +0000

    DOCX export, numbering portion format: consider full-para char formats as 
well
    
    The bugdoc had a single paragraph with direct formatting (24pt font
    size), numbering enabled and a bookmark covering half of the paragraph.
    The numbering had default font size in the DOCX export result, not
    inheriting from the paragraph.
    
    In case the bookmark is removed, then the custom font size is not an
    autoformat set on the whole text of the paragraph but rather a format on
    the paragraph level, which does influence the formatting of the
    numbering portion via the paragraph marker formatting, as expected.
    
    Fix the problem in a way similar to what was done in commit
    cb0e1b52d68aa6d5b505f91cb4ce577f7f3b2a8f (sw, numbering portion format:
    consider full-para char formats as well, 2022-10-20), except that was
    for the rendering and this is for the DOCX export.
    
    This also required filtering out grab-bags in
    lcl_writeParagraphMarkerProperties(), otherwise citation SDTs show up in
    the export result at unexpected places, as shown by
    CppunitTest_sw_ooxmlexport14's testTdf129353.
    
    (cherry picked from commit f546f7573158e52359bbeae6194a83a1ff8ac52c)
    
    Conflicts:
            sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
    
    Change-Id: I7bb88e290f2a370d78ecc894f306bcb0a403545f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142103
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144958
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>

diff --git a/sw/qa/extras/ooxmlexport/data/number-portion-format.odt 
b/sw/qa/extras/ooxmlexport/data/number-portion-format.odt
new file mode 100644
index 000000000000..3047153b63af
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/number-portion-format.odt differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
index c0d3e7c6d161..a77e2ec98ca4 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
@@ -115,6 +115,26 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf152200)
     assertXPath(pXmlDoc, "//w:fldChar", 3); // no field characters elsewhere
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testNumberPortionFormatFromODT)
+{
+    // Given a document with a single paragraph, direct formatting asks 24pt 
font size for the
+    // numbering and the text portion:
+    load(DATA_DIRECTORY, "number-portion-format.odt");
+
+    // When saving to DOCX:
+    save("Office Open XML Text", maTempFile);
+    mbExported = true;
+
+    // Then make sure that the paragraph marker's char format has that custom 
font size:
+    xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 1
+    // - Actual  : 0
+    // - XPath '//w:pPr/w:rPr/w:sz' number of nodes is incorrect
+    // i.e. <w:sz> was missing under <w:pPr>'s <w:rPr>.
+    assertXPath(pXmlDoc, "//w:pPr/w:rPr/w:sz", "val", "48");
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index b190bf38e581..0bff96233ce4 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -1407,7 +1407,7 @@ void 
lcl_writeParagraphMarkerProperties(DocxAttributeOutput& rAttributeOutput, c
     bool bFontSizeWritten = false;
     while (nWhichId)
     {
-        if (rParagraphMarkerProperties.GetItemState(nWhichId, true, &pItem) == 
SfxItemState::SET)
+        if (rParagraphMarkerProperties.GetItemState(nWhichId, true, &pItem) == 
SfxItemState::SET && nWhichId != RES_CHRATR_GRABBAG)
         {
             if (isCHRATR(nWhichId) || nWhichId == RES_TXTATR_CHARFMT)
             {
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx 
b/sw/source/filter/ww8/wrtw8nds.cxx
index 89fe95801f85..42036c163eca 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -3211,6 +3211,7 @@ void MSWordExportBase::OutputTextNode( SwTextNode& rNode )
         }
         else if (const SwpHints* pTextAttrs = rNode.GetpSwpHints())
         {
+            bool bFoundAtEnd = false;
             for( size_t i = 0; i < pTextAttrs->Count(); ++i )
             {
                 const SwTextAttr* pHt = pTextAttrs->Get(i);
@@ -3219,13 +3220,23 @@ void MSWordExportBase::OutputTextNode( SwTextNode& 
rNode )
                 // Check if these attributes are for the last character in the 
paragraph
                 // - which means the paragraph marker. If a paragraph has 7 
characters,
                 // then properties on character 8 are for the paragraph marker
-                if( endPos && (startPos == *endPos ) && (*endPos == 
rNode.GetText().getLength()) )
+                if (!endPos)
+                {
+                    continue;
+                }
+                bool bAtEnd = (startPos == *endPos ) && (*endPos == 
rNode.GetText().getLength());
+                if (bAtEnd)
+                {
+                    bFoundAtEnd = true;
+                }
+                bool bWholePara = startPos == 0 && *endPos == 
rNode.GetText().getLength();
+                if (bAtEnd || (!bFoundAtEnd && bWholePara))
                 {
                     SAL_INFO( "sw.ww8", startPos << "startPos == endPos" << 
*endPos);
                     sal_uInt16 nWhich = pHt->GetAttr().Which();
                     SAL_INFO( "sw.ww8", "nWhich" << nWhich);
                     if ((nWhich == RES_TXTATR_AUTOFMT && bCharFormatOnly)
-                        || nWhich == RES_TXTATR_CHARFMT)
+                        || (nWhich == RES_TXTATR_CHARFMT && !bWholePara))
                     {
                         aParagraphMarkerProperties.Put(pHt->GetAttr());
                     }
commit a17cc4ae932ed8bae290e300224cb97c1e8503f2
Author:     Miklos Vajna <[email protected]>
AuthorDate: Thu Oct 20 15:53:16 2022 +0200
Commit:     Miklos Vajna <[email protected]>
CommitDate: Tue Jan 3 07:01:24 2023 +0000

    sw, numbering portion format: consider full-para char formats as well
    
    The bugdoc had a single paragraph with direct formatting (24pt font
    size), numbering enabled and a bookmark covering half of the paragraph.
    The numbering had default font size, not inheriting from the paragraph.
    
    Turns out that in case the bookmark is removed, then the custom font
    size is not an autoformat set on the whole text of the paragraph but
    rather a format on the paragraph level, which does influence the
    formatting of the numbering portion, as expected.
    
    Fix the problem by extending SwTextFormatter::NewNumberPortion(), so it
    looks for char props not only in the item set of the SwTextNode, but
    also in the hints of SwTextNode, if they cover the whole paragraph. This
    fixes the inconsistency that adding a bookmark to the document should
    not change the rendering of the portions.
    
    Interestingly DOCX import already set the font size on the SwTextNode in
    this case, but the ODT import created a char autofmt hint, that covered
    the full paragraph.
    
    (cherry picked from commit cb0e1b52d68aa6d5b505f91cb4ce577f7f3b2a8f)
    
    Conflicts:
            sw/qa/core/text/text.cxx
    
    Change-Id: I09ffabd84511da439bc05a6f8d134615e5dd8599
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142102
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144957
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>

diff --git a/sw/qa/core/text/data/number-portion-format.odt 
b/sw/qa/core/text/data/number-portion-format.odt
new file mode 100644
index 000000000000..3047153b63af
Binary files /dev/null and b/sw/qa/core/text/data/number-portion-format.odt 
differ
diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx
index 95b1113979b1..0bcd850073e9 100644
--- a/sw/qa/core/text/text.cxx
+++ b/sw/qa/core/text/text.cxx
@@ -733,6 +733,24 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, 
testRichContentControlPDF)
     CPPUNIT_ASSERT_EQUAL(1, pPage->getAnnotationCount());
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testNumberPortionFormat)
+{
+    // Given a document with a single paragraph, direct formatting asks 24pt 
font size for the
+    // numbering and the text portion:
+    createSwDoc(DATA_DIRECTORY, "number-portion-format.odt");
+
+    // When laying out that document:
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+
+    // Then make sure that the numbering portion has the correct font size:
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 480
+    // - Actual  : 240
+    // i.e. the numbering portion font size was 12pt, not 24pt (but only when 
the doc had a
+    // bookmark).
+    assertXPath(pXmlDoc, "//Special[@nType='PortionType::Number']", "nHeight", 
"480");
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/text/txtfld.cxx b/sw/source/core/text/txtfld.cxx
index efb8d2926bc4..de789ad9fb45 100644
--- a/sw/source/core/text/txtfld.cxx
+++ b/sw/source/core/text/txtfld.cxx
@@ -752,6 +752,28 @@ SwNumberPortion *SwTextFormatter::NewNumberPortion( 
SwTextFormatInfo &rInf ) con
                     // Build a new numbering font basing on the current 
paragraph font:
                     std::unique_ptr<SwFont> pNumFnt(new SwFont( 
&rInf.GetCharAttr(), pIDSA ));
 
+                    const SwTextNode& rTextNode = 
*rInf.GetTextFrame()->GetTextNodeForParaProps();
+                    if (const SwpHints* pHints = rTextNode.GetpSwpHints())
+                    {
+                        // Also look for a character hint that cover the 
entire current paragraph:
+                        for (size_t i = 0; i < pHints->Count(); ++i)
+                        {
+                            const SwTextAttr* pHint = pHints->Get(i);
+                            if (pHint->Which() == RES_TXTATR_AUTOFMT && 
pHint->GetStart() == 0
+                                && pHint->GetEnd()
+                                && *pHint->GetEnd() == 
rTextNode.GetText().getLength())
+                            {
+                                std::shared_ptr<SfxItemSet> pSet
+                                    = pHint->GetAutoFormat().GetStyleHandle();
+                                if (pSet)
+                                {
+                                    pNumFnt->SetDiffFnt(pSet.get(), pIDSA);
+                                    break;
+                                }
+                            }
+                        }
+                    }
+
                     // #i53199#
                     if ( 
!pIDSA->get(DocumentSettingId::DO_NOT_RESET_PARA_ATTRS_FOR_NUM_FONT) )
                     {

Reply via email to