summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2015-12-09 08:46:27 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-12-10 09:35:15 +0100
commitd71417b49e8f8685897f5a74f03c81008c73c04e (patch)
treea22fe31fca3bb199d26e7e1b0de7391184be9797
parente4c13fa32f793fee6d99c0c479fd65ab9dd09b66 (diff)
tdf#94377 RTF export: support comment formatting
The core of this change is that RtfAttributeOutput::PostitField() now uses WriteOutliner() to handle comment text, instead of trying to output the plain text as-is. To have working roundtrip of the comment text, a few more changes are needed: 1) When emptying the Styles buffer, also empty the StylesEnd one. 2) Annotations don't want a trailing \par, so don't write one for the last paragraph. 3) Inform the MSWord_SdrAttrIter about where the editeng content will end up, and make WriteOutliner() accessible outside RtfSdrExport. Change-Id: I9cbcf4ce5dc3a099d310c6f321ea8e52f8644f9b (cherry picked from commit 7060525a64ef1048b387f0a6a9f842d78b52fb9a)
-rw-r--r--sw/qa/extras/rtfexport/data/tdf94377.rtf15
-rw-r--r--sw/qa/extras/rtfexport/rtfexport.cxx14
-rw-r--r--sw/source/filter/ww8/rtfattributeoutput.cxx8
-rw-r--r--sw/source/filter/ww8/rtfattributeoutput.hxx1
-rw-r--r--sw/source/filter/ww8/rtfsdrexport.cxx22
-rw-r--r--sw/source/filter/ww8/rtfsdrexport.hxx6
6 files changed, 56 insertions, 10 deletions
diff --git a/sw/qa/extras/rtfexport/data/tdf94377.rtf b/sw/qa/extras/rtfexport/data/tdf94377.rtf
new file mode 100644
index 000000000000..775ed2c0dde6
--- /dev/null
+++ b/sw/qa/extras/rtfexport/data/tdf94377.rtf
@@ -0,0 +1,15 @@
+{\rtf1
+\pard\plain
+a
+{
+{\*\atnid }
+{\*\atnauthor Unknown Author}
+\chatn
+{\*\annotation
+{\fs20 Asdf10}
+\par
+{\fs24 asdf12}
+}
+}
+b \par
+}
diff --git a/sw/qa/extras/rtfexport/rtfexport.cxx b/sw/qa/extras/rtfexport/rtfexport.cxx
index 136860806a49..58dadbc7dddd 100644
--- a/sw/qa/extras/rtfexport/rtfexport.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport.cxx
@@ -952,6 +952,20 @@ DECLARE_RTFEXPORT_TEST(testTdf94043, "tdf94043.rtf")
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), getProperty<sal_Int32>(xTextColumns, "SeparatorLineWidth"));
}
+DECLARE_RTFEXPORT_TEST(testTdf94377, "tdf94377.rtf")
+{
+ uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
+ uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
+ uno::Reference<beans::XPropertySet> xPropertySet(xFields->nextElement(), uno::UNO_QUERY);
+ auto xText = getProperty< uno::Reference<text::XText> >(xPropertySet, "TextRange");
+ // This failed, as:
+ // 1) multiple paragraphs were not exported, so the text was "Asdf10asdf12".
+ // 2) direct formatting of runs were not exported, so this was 12 (the document default).
+ CPPUNIT_ASSERT_EQUAL(10.f, getProperty<float>(getRun(getParagraphOfText(1, xText, "Asdf10"), 1), "CharHeight"));
+ CPPUNIT_ASSERT_EQUAL(12.f, getProperty<float>(getRun(getParagraphOfText(2, xText, "asdf12"), 1), "CharHeight"));
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx
index ab9ad06b857b..9e1c583e5c16 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -424,6 +424,11 @@ OStringBuffer& RtfAttributeOutput::RunText()
return m_aRunText.getLastBuffer();
}
+OStringBuffer& RtfAttributeOutput::StylesEnd()
+{
+ return m_aStylesEnd;
+}
+
void RtfAttributeOutput::RawText(const OUString& rText, rtl_TextEncoding eCharSet)
{
m_aRunText->append(msfilter::rtfutil::OutString(rText, eCharSet));
@@ -3466,7 +3471,8 @@ void RtfAttributeOutput::PostitField(const SwField* pField)
m_aRunText->append("{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_ATNDATE " ");
m_aRunText->append((sal_Int32)sw::ms::DateTime2DTTM(rPField.GetDateTime()));
m_aRunText->append('}');
- m_aRunText->append(OUStringToOString(OUString(rPField.GetText()), m_rExport.eCurrentEncoding));
+ if (const OutlinerParaObject* pObject = rPField.GetTextObject())
+ m_rExport.SdrExporter().WriteOutliner(*pObject, TXT_ATN);
m_aRunText->append('}');
}
diff --git a/sw/source/filter/ww8/rtfattributeoutput.hxx b/sw/source/filter/ww8/rtfattributeoutput.hxx
index e13fcd6c2ec8..77e2303611d8 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.hxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.hxx
@@ -82,6 +82,7 @@ public:
{
return m_aStyles;
}
+ OStringBuffer& StylesEnd();
/// Output text (without markup).
virtual void RawText(const OUString& rText, rtl_TextEncoding eCharSet) override;
diff --git a/sw/source/filter/ww8/rtfsdrexport.cxx b/sw/source/filter/ww8/rtfsdrexport.cxx
index 8f3f97f8eead..c9d386a34a03 100644
--- a/sw/source/filter/ww8/rtfsdrexport.cxx
+++ b/sw/source/filter/ww8/rtfsdrexport.cxx
@@ -554,23 +554,25 @@ sal_Int32 RtfSdrExport::StartShape()
if (pParaObj)
{
// this is reached only in case some text is attached to the shape
- WriteOutliner(*pParaObj);
+ WriteOutliner(*pParaObj, TXT_HFTXTBOX);
}
}
return m_nShapeType;
}
-void RtfSdrExport::WriteOutliner(const OutlinerParaObject& rParaObj)
+void RtfSdrExport::WriteOutliner(const OutlinerParaObject& rParaObj, TextTypes eType)
{
SAL_INFO("sw.rtf", OSL_THIS_FUNC << " start");
const EditTextObject& rEditObj = rParaObj.GetTextObject();
- MSWord_SdrAttrIter aAttrIter(m_rExport, rEditObj, TXT_HFTXTBOX);
+ MSWord_SdrAttrIter aAttrIter(m_rExport, rEditObj, eType);
sal_Int32 nPara = rEditObj.GetParagraphCount();
- m_rAttrOutput.RunText().append('{').append(OOO_STRING_SVTOOLS_RTF_SHPTXT).append(' ');
+ bool bShape = eType == TXT_HFTXTBOX;
+ if (bShape)
+ m_rAttrOutput.RunText().append('{').append(OOO_STRING_SVTOOLS_RTF_SHPTXT).append(' ');
for (sal_Int32 n = 0; n < nPara; ++n)
{
if (n)
@@ -584,6 +586,7 @@ void RtfSdrExport::WriteOutliner(const OutlinerParaObject& rParaObj)
aAttrIter.OutParaAttr(false);
m_rAttrOutput.RunText().append(m_rAttrOutput.Styles().makeStringAndClear());
+ m_rAttrOutput.RunText().append(m_rAttrOutput.StylesEnd().makeStringAndClear());
do
{
@@ -591,7 +594,10 @@ void RtfSdrExport::WriteOutliner(const OutlinerParaObject& rParaObj)
rtl_TextEncoding eNextChrSet = aAttrIter.GetNextCharSet();
aAttrIter.OutAttr(nAktPos);
- m_rAttrOutput.RunText().append('{').append(m_rAttrOutput.Styles().makeStringAndClear()).append(SAL_NEWLINE_STRING);
+ m_rAttrOutput.RunText().append('{');
+ m_rAttrOutput.RunText().append(m_rAttrOutput.Styles().makeStringAndClear());
+ m_rAttrOutput.RunText().append(m_rAttrOutput.StylesEnd().makeStringAndClear());
+ m_rAttrOutput.RunText().append(SAL_NEWLINE_STRING);
bool bTextAtr = aAttrIter.IsTextAttr(nAktPos);
if (!bTextAtr)
{
@@ -606,9 +612,11 @@ void RtfSdrExport::WriteOutliner(const OutlinerParaObject& rParaObj)
aAttrIter.NextPos();
}
while (nAktPos < nEnd);
- m_rAttrOutput.RunText().append(OOO_STRING_SVTOOLS_RTF_PAR);
+ if (bShape || n + 1 < nPara)
+ m_rAttrOutput.RunText().append(OOO_STRING_SVTOOLS_RTF_PAR);
}
- m_rAttrOutput.RunText().append('}');
+ if (bShape)
+ m_rAttrOutput.RunText().append('}');
SAL_INFO("sw.rtf", OSL_THIS_FUNC << " end");
}
diff --git a/sw/source/filter/ww8/rtfsdrexport.hxx b/sw/source/filter/ww8/rtfsdrexport.hxx
index ab0b24d32696..926ff7464ae6 100644
--- a/sw/source/filter/ww8/rtfsdrexport.hxx
+++ b/sw/source/filter/ww8/rtfsdrexport.hxx
@@ -27,6 +27,8 @@
#include <map>
#include <set>
+#include <wrtww8.hxx>
+
class RtfExport;
class RtfAttributeOutput;
class SwFrameFormat;
@@ -68,6 +70,8 @@ public:
/// Is this a standalone TextFrame, or used as a TextBox of a shape?
bool isTextBox(const SwFrameFormat& rFrameFormat);
+ /// Write editeng text, e.g. shape or comment.
+ void WriteOutliner(const OutlinerParaObject& rParaObj, TextTypes eType);
protected:
/// Start the shape for which we just collected the information.
@@ -101,8 +105,6 @@ private:
/// Add position and size to the OStringBuffer.
void AddRectangleDimensions(OStringBuffer& rBuffer, const Rectangle& rRectangle);
- void WriteOutliner(const OutlinerParaObject& rParaObj);
-
/// Exports the pib property of the shape
void impl_writeGraphic();
};