sw/qa/extras/ooxmlexport/data/fontsize-field-separator.docx |binary sw/qa/extras/ooxmlexport/ooxmlexport22.cxx | 11 +++++++++++ sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx | 6 +++++- 3 files changed, 16 insertions(+), 1 deletion(-)
New commits: commit ab1a81b1e3818deac87c21c1d98a546a23dd6ada Author: Jaume Pujantell <[email protected]> AuthorDate: Mon Jun 9 20:13:18 2025 +0200 Commit: Jaume Pujantell <[email protected]> CommitDate: Wed Jun 25 14:15:39 2025 +0200 tdf#166940 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 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> (cherry picked from commit adc483d5f9256b7e10beed29bb63a7c582cab56e) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186453 Tested-by: Jenkins 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 f94fc0ad1f91..a99c549bafc8 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx @@ -381,6 +381,17 @@ CPPUNIT_TEST_FIXTURE(Test, testLineBreakInRef) assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[4]/w:t", u"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/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx index 7fe93aa5522c..d51a1ab78dc8 100644 --- a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx +++ b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx @@ -6460,6 +6460,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 ); } } @@ -9091,7 +9095,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());
