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 adc483d5f9256b7e10beed29bb63a7c582cab56e Author: Jaume Pujantell <[email protected]> AuthorDate: Mon Jun 9 20:13:18 2025 +0200 Commit: Miklos Vajna <[email protected]> CommitDate: Tue Jun 10 13:28:04 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 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[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 ee1bc153baa1..50d16fa1c70c 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx @@ -307,6 +307,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 3992c168ddb1..fc9e14f6a22b 100644 --- a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx +++ b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx @@ -6369,6 +6369,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 ); } } @@ -9000,7 +9004,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());
