Kaydet (Commit) 7060525a authored tarafından Miklos Vajna's avatar Miklos Vajna

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
üst 4754afdd
{\rtf1
\pard\plain
a
{
{\*\atnid }
{\*\atnauthor Unknown Author}
\chatn
{\*\annotation
{\fs20 Asdf10}
\par
{\fs24 asdf12}
}
}
b \par
}
......@@ -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: */
......@@ -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('}');
}
......
......@@ -82,6 +82,7 @@ public:
{
return m_aStyles;
}
OStringBuffer& StylesEnd();
/// Output text (without markup).
virtual void RawText(const OUString& rText, rtl_TextEncoding eCharSet) override;
......
......@@ -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");
}
......
......@@ -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();
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment