sw/qa/extras/ooxmlexport/data/fontsize-field-separator.docx |binary sw/qa/extras/ooxmlexport/ooxmlexport22.cxx | 11 +++++++++++ writerfilter/source/dmapper/DomainMapper_Impl.cxx | 6 +++++- 3 files changed, 16 insertions(+), 1 deletion(-)
New commits: commit bdab9cca5a67d77e1c9a2eb381a73c1357943ae1 Author: Jaume Pujantell <[email protected]> AuthorDate: Mon Jun 9 20:13:18 2025 +0200 Commit: Jaume Pujantell <[email protected]> CommitDate: Wed Jun 18 09:09:54 2025 +0200 sw: in docx field import use to outer char props For RTF field import, to assign character properties top a field, the properties are assigned to the field mark characters and then added to the content string. For DOCX according to the standard the content can have arbitrary styles, but for now we only support plain strings for some fields. So, for those fields, we want to insert the content with the properties of the surrounding context. This was done by taking the character properties of the end field mark character, like used in RTF import. This works most of the time but fails for documents where those invisible characters have their own properties which shouldn't show up in the visible text. Instead, for DOCX, it makes more sense to take those properties from the first run of the field and apply it to the whole field result. Change-Id: I9287f7ed81c4cc2b5bbf65e7151ee3a8bcbd95d2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186302 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186618 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Jaume Pujantell <[email protected]> diff --git a/sw/qa/extras/ooxmlexport/data/fontsize-field-separator.docx b/sw/qa/extras/ooxmlexport/data/fontsize-field-separator.docx new file mode 100644 index 000000000000..70cae857bc97 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/fontsize-field-separator.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx index a92c72dc57c6..f16c47cd8ea1 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx @@ -152,6 +152,17 @@ CPPUNIT_TEST_FIXTURE(Test, testLineBreakInRef) assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[4]/w:t"_ostr, "Text1"); } +DECLARE_OOXMLEXPORT_TEST(testFieldMarkFormat, "fontsize-field-separator.docx") +{ + uno::Reference<text::XTextRange> xRun(getRun(getParagraph(1), 1)); + + // Without the fix it fails with + // - Expected: 12 + // - Actual : 42 + // i.e. the field content has the properties fo the field marks + CPPUNIT_ASSERT_EQUAL(12.f, getProperty<float>(xRun, u"CharHeight"_ustr)); +} + } // end of anonymous namespace CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index a70b1c18149e..86230bcf288b 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -6139,6 +6139,10 @@ void DomainMapper_Impl::AppendFieldCommand(OUString const & rPartOfCommand) { // Set command line type: normal or deleted pContext->SetCommandType(m_bTextDeleted); + if (pContext->GetCommand().isEmpty()) + { + pContext->getProperties()->InsertProps(GetTopContextOfType(CONTEXT_CHARACTER)); + } pContext->AppendCommand( rPartOfCommand ); } } @@ -8788,7 +8792,7 @@ void DomainMapper_Impl::PopFieldContext() // properties from there. // Also merge in the properties from the field context, // e.g. SdtEndBefore. - if (m_pLastCharacterContext) + if (m_pLastCharacterContext && IsRTFImport()) aMap.InsertProps(m_pLastCharacterContext); aMap.InsertProps(m_aFieldStack.back()->getProperties()); appendTextContent(xToInsert, aMap.GetPropertyValues());
