summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-10-28 16:39:31 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-10-28 17:19:19 +0200
commitf546f7573158e52359bbeae6194a83a1ff8ac52c (patch)
tree32f70ba4ca9e48ad305ef797e019a3b1a1b7f7b4
parentab24b70ca0ea80a4655c71762f628e86a76fefa0 (diff)
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. Change-Id: I7bb88e290f2a370d78ecc894f306bcb0a403545f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141995 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
-rw-r--r--sw/qa/extras/ooxmlexport/data/number-portion-format.odtbin0 -> 8987 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport18.cxx20
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx2
-rw-r--r--sw/source/filter/ww8/wrtw8nds.cxx15
4 files changed, 34 insertions, 3 deletions
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
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/number-portion-format.odt
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
index b9932f7c199d..75094f441cd6 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
@@ -117,6 +117,26 @@ DECLARE_OOXMLEXPORT_TEST(testTdf147724, "tdf147724.docx")
CPPUNIT_ASSERT(sFieldResult == "Placeholder -> *HERUNTERLADEN*" || sFieldResult == "Placeholder -> *ABC*");
}
+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 dd6210566bfa..a88049e31c09 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -1369,7 +1369,7 @@ void lcl_writeParagraphMarkerProperties(DocxAttributeOutput& rAttributeOutput, c
bool bFontSizeWritten = false;
while (nWhichId)
{
- if (aIter.GetItemState(true, &pItem) == SfxItemState::SET)
+ if (aIter.GetItemState(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 a9ff9a6b9b56..927ed91bf876 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -3164,6 +3164,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);
@@ -3172,13 +3173,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());
}