summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2023-12-05 21:43:16 -0500
committerMiklos Vajna <vmiklos@collabora.com>2023-12-11 16:14:50 +0100
commit5f888fa920c99cce91dfd18244a5c3869807b970 (patch)
tree04cee270ce73de06079fb4df862807c95d45873f
parent7d5c403f3759b14fe3be206f4c29494799eac2b4 (diff)
tdf#108505 rtfexport: avoid mis-inheriting field char settings
The field result fully defines its own character properties, so it should not inherit any "parent" properties from the field. My test file didn't show any problems with DOCX or DOC, and reading through the code I didn't notice anything that looked wrong. Both are very different from RTF syntax, and it didn't look like they did anything "special" for this situation, so nothing to copy from... This whole area of field properties looks very hacky, but it seems pretty clear that OutputTextNode loops through OutAttr's run properties for each of start/sep/end for fields. OutAttr picks up all of the direct formatting, so nothing should be "missing", and therefore a \plain character reset should be appropriate. The good news is that MS Word 2010 imported both the bad and the good export just like we do. make CppunitTest_sw_rtfexport6 \ CPPUNIT_TEST_NAME=testTdf108505_fieldCharFormat2 Change-Id: I713c071dfcd40117bfff03d152718eb5d847327e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160375 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r--sw/qa/extras/rtfexport/rtfexport6.cxx12
-rw-r--r--sw/source/filter/ww8/rtfattributeoutput.cxx8
-rw-r--r--sw/source/filter/ww8/wrtw8nds.cxx7
3 files changed, 18 insertions, 9 deletions
diff --git a/sw/qa/extras/rtfexport/rtfexport6.cxx b/sw/qa/extras/rtfexport/rtfexport6.cxx
index 275d2593d2df..ff331caa7307 100644
--- a/sw/qa/extras/rtfexport/rtfexport6.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport6.cxx
@@ -178,21 +178,19 @@ DECLARE_RTFEXPORT_TEST(testTdf108505_fieldCharFormat, "tdf108505_fieldCharFormat
DECLARE_RTFEXPORT_TEST(testTdf108505_fieldCharFormat2, "tdf108505_fieldCharFormat2.rtf")
{
- // not exported properly. Currently xyz exports as run 6, red, italic.
- if (isExported())
- return;
-
uno::Reference<text::XTextTable> xTable(getParagraphOrTable(1), uno::UNO_QUERY);
uno::Reference<text::XTextRange> xCell(xTable->getCellByName("C1"), uno::UNO_QUERY);
uno::Reference<text::XTextRange> xPara = getParagraphOfText(1, xCell->getText());
- // Preemptive test: nothing found wrong/fixed by the accompanying patch
+ const sal_Int32 nRun = isExported() ? 6 : 5;
+ const Color aColor = isExported() ? COL_BLACK : COL_AUTO;
+
// Character formatting should only be defined by the \fldrslt, and not by prior formatting.
// Prior formatting is italic, red, 20pt.
- uno::Reference<text::XTextRange> xRun = getRun(xPara, 5, u"xyz"_ustr);
+ uno::Reference<text::XTextRange> xRun = getRun(xPara, nRun, u"xyz"_ustr);
CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD, getProperty<float>(xRun, "CharWeight"));
CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE, getProperty<awt::FontSlant>(xRun, "CharPosture"));
- CPPUNIT_ASSERT_EQUAL(COL_AUTO, getProperty<Color>(xRun, "CharColor"));
+ CPPUNIT_ASSERT_EQUAL(aColor, getProperty<Color>(xRun, "CharColor"));
}
/** Make sure that the document variable "Unused", which is not referenced in the document,
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx
index 1ca7c61fba4d..2d68556e8a23 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -1858,7 +1858,13 @@ void RtfAttributeOutput::WriteField_Impl(const SwField* const pField, ww::eField
msfilter::rtfutil::OutString(rFieldCmd, m_rExport.GetCurrentEncoding()));
if (nMode & FieldFlags::CmdEnd)
{
- m_aRunText->append("}}{" OOO_STRING_SVTOOLS_RTF_FLDRSLT " {");
+ m_aRunText->append("}}{" OOO_STRING_SVTOOLS_RTF_FLDRSLT);
+ // The fldrslt contains its own full copy of character formatting,
+ // but if the result is empty (nMode & FieldFlags::End) or field export is condensed
+ // in any way (multiple flags) then avoid spamming an unnecessary plain character reset.
+ if (nMode == FieldFlags::CmdEnd)
+ m_aRunText->append(OOO_STRING_SVTOOLS_RTF_PLAIN);
+ m_aRunText->append(" {");
}
if (nMode & FieldFlags::Close)
{
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx
index 5b1d62b4b12b..74e53d2fec0b 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -2517,7 +2517,12 @@ void MSWordExportBase::OutputTextNode( SwTextNode& rNode )
// DateFieldmark / ODF_FORMDATE is not a field...
if (pFieldmark->GetFieldname() != ODF_FORMDATE)
{
- OutputField( nullptr, lcl_getFieldId( pFieldmark ), OUString(), FieldFlags::CmdEnd );
+ FieldFlags nFlags = FieldFlags::CmdEnd;
+ // send hint that fldrslt is empty, to avoid spamming RTF CharProp reset.
+ // ::End does nothing when sending rFieldCmd=OUString(), so safe to do.
+ if (pFieldmark->GetContent().isEmpty())
+ nFlags |= FieldFlags::End;
+ OutputField(nullptr, lcl_getFieldId(pFieldmark), OUString(), nFlags);
if (pFieldmark->GetFieldname() == ODF_UNHANDLED)
{