[Libreoffice-commits] core.git: Branch 'libreoffice-5-1' - 2 commits - sw/qa sw/source

Miklos Vajna vmiklos at collabora.co.uk
Thu Dec 10 00:35:54 PST 2015


 sw/qa/extras/rtfexport/data/tdf94377.rtf    |   15 +++++++++++++++
 sw/qa/extras/rtfexport/rtfexport.cxx        |   14 ++++++++++++++
 sw/source/filter/ww8/rtfattributeoutput.cxx |    8 +++++++-
 sw/source/filter/ww8/rtfattributeoutput.hxx |    1 +
 sw/source/filter/ww8/rtfsdrexport.cxx       |   21 +++++++++++++++------
 sw/source/filter/ww8/rtfsdrexport.hxx       |    6 ++++--
 6 files changed, 56 insertions(+), 9 deletions(-)

New commits:
commit d71417b49e8f8685897f5a74f03c81008c73c04e
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Dec 9 08:46:27 2015 +0100

    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)

diff --git a/sw/qa/extras/rtfexport/data/tdf94377.rtf b/sw/qa/extras/rtfexport/data/tdf94377.rtf
new file mode 100644
index 0000000..775ed2c
--- /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 1368608..58dadbc 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 ab9ad06..9e1c583 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 e13fcd6..77e2303 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 8f3f97f..c9d386a 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 ab0b24d..926ff74 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();
 };
commit e4c13fa32f793fee6d99c0c479fd65ab9dd09b66
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Dec 8 08:49:03 2015 +0100

    Related: tdf#94377 RTF export: support multiple paragraphs in editeng text
    
    Write a \par at the end of each paragraph instead of writing one at the
    end of the whole text only.
    
    Change-Id: I984b31d4ae3d2e728c993b25bfde761dcad063ae
    (cherry picked from commit c321b6182a31cd2e5d6f74e404797bd4c63e537a)

diff --git a/sw/source/filter/ww8/rtfsdrexport.cxx b/sw/source/filter/ww8/rtfsdrexport.cxx
index cacf2e8..8f3f97f 100644
--- a/sw/source/filter/ww8/rtfsdrexport.cxx
+++ b/sw/source/filter/ww8/rtfsdrexport.cxx
@@ -606,8 +606,9 @@ void RtfSdrExport::WriteOutliner(const OutlinerParaObject& rParaObj)
             aAttrIter.NextPos();
         }
         while (nAktPos < nEnd);
+        m_rAttrOutput.RunText().append(OOO_STRING_SVTOOLS_RTF_PAR);
     }
-    m_rAttrOutput.RunText().append(OOO_STRING_SVTOOLS_RTF_PAR).append('}');
+    m_rAttrOutput.RunText().append('}');
 
     SAL_INFO("sw.rtf", OSL_THIS_FUNC << " end");
 }


More information about the Libreoffice-commits mailing list