[Libreoffice-commits] .: sw/qa writerfilter/source

Miklos Vajna vmiklos at kemper.freedesktop.org
Tue Apr 3 08:56:11 PDT 2012


 sw/qa/extras/rtftok/data/fdo45182.rtf          |   11 +++++++++++
 sw/qa/extras/rtftok/rtftok.cxx                 |   15 +++++++++++++++
 writerfilter/source/rtftok/rtfdocumentimpl.cxx |   17 +++++++++++++++--
 writerfilter/source/rtftok/rtfdocumentimpl.hxx |    2 ++
 4 files changed, 43 insertions(+), 2 deletions(-)

New commits:
commit f4e0cbaa15c2861e87149a62c9c80a9e9b4094b3
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Tue Apr 3 16:49:41 2012 +0200

    fdo#45182 fix RTF import of character encoding in footnotes
    
    There were two problems here:
    
    1) \plain reset the character properties, but did not touch the current encoding
    2) the default properties were not passed to substreams

diff --git a/sw/qa/extras/rtftok/data/fdo45182.rtf b/sw/qa/extras/rtftok/data/fdo45182.rtf
new file mode 100644
index 0000000..b076106
--- /dev/null
+++ b/sw/qa/extras/rtftok/data/fdo45182.rtf
@@ -0,0 +1,11 @@
+{\rtf1\deff0
+{\fonttbl
+{\f0\fcharset238
+Times New Roman;}
+}
+a\chftn 
+{\footnote 
+\ltrpar \pard\plain\'9eivnost\'ed
+\par
+}
+}
diff --git a/sw/qa/extras/rtftok/rtftok.cxx b/sw/qa/extras/rtftok/rtftok.cxx
index 45eabbf..9267967 100644
--- a/sw/qa/extras/rtftok/rtftok.cxx
+++ b/sw/qa/extras/rtftok/rtftok.cxx
@@ -35,6 +35,7 @@
 #include <com/sun/star/text/RelOrientation.hpp>
 #include <com/sun/star/text/SizeType.hpp>
 #include <com/sun/star/text/TextContentAnchorType.hpp>
+#include <com/sun/star/text/XFootnotesSupplier.hpp>
 #include <com/sun/star/text/XPageCursor.hpp>
 #include <com/sun/star/text/XTextDocument.hpp>
 #include <com/sun/star/text/XTextGraphicObjectsSupplier.hpp>
@@ -77,6 +78,7 @@ public:
     void testFdo45394();
     void testFdo48104();
     void testFdo47107();
+    void testFdo45182();
 
     CPPUNIT_TEST_SUITE(RtfModelTest);
 #if !defined(MACOSX) && !defined(WNT)
@@ -97,6 +99,7 @@ public:
     CPPUNIT_TEST(testFdo45394);
     CPPUNIT_TEST(testFdo48104);
     CPPUNIT_TEST(testFdo47107);
+    CPPUNIT_TEST(testFdo45182);
 #endif
     CPPUNIT_TEST_SUITE_END();
 
@@ -500,6 +503,18 @@ void RtfModelTest::testFdo47107()
     xNumberingStyles->getByName("WWNum2");
 }
 
+void RtfModelTest::testFdo45182()
+{
+    load("fdo45182.rtf");
+
+    uno::Reference<text::XFootnotesSupplier> xFootnotesSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> xFootnotes(xFootnotesSupplier->getFootnotes(), uno::UNO_QUERY);
+    uno::Reference<text::XTextRange> xTextRange(xFootnotes->getByIndex(0), uno::UNO_QUERY);
+    // Encoding in the footnote was wrong.
+    OUString aExpected("živností", 10, RTL_TEXTENCODING_UTF8);
+    CPPUNIT_ASSERT_EQUAL(aExpected, xTextRange->getString());
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(RtfModelTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 5ceeaeb..e938f98 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -541,6 +541,14 @@ int RTFDocumentImpl::getFontIndex(int nIndex)
         return m_pSuperstream->getFontIndex(nIndex);
 }
 
+RTFParserState& RTFDocumentImpl::getDefaultState()
+{
+    if (!m_pSuperstream)
+        return m_aDefaultState;
+    else
+        return m_pSuperstream->getDefaultState();
+}
+
 void RTFDocumentImpl::resolve(Stream & rMapper)
 {
     m_pMapperStream = &rMapper;
@@ -1762,8 +1770,13 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
             m_aStates.top().nCurrentEncoding = RTL_TEXTENCODING_MS_1252;
             break;
         case RTF_PLAIN:
-            m_aStates.top().aCharacterSprms = m_aDefaultState.aCharacterSprms;
-            m_aStates.top().aCharacterAttributes = m_aDefaultState.aCharacterAttributes;
+            {
+                m_aStates.top().aCharacterSprms = getDefaultState().aCharacterSprms;
+                RTFValue::Pointer_t pValue = m_aStates.top().aCharacterSprms.find(NS_sprm::LN_CRgFtc0);
+                if (pValue.get())
+                    m_aStates.top().nCurrentEncoding = getEncoding(pValue->getInt());
+                m_aStates.top().aCharacterAttributes = getDefaultState().aCharacterAttributes;
+            }
             break;
         case RTF_PARD:
             m_aStates.top().aParagraphSprms = m_aDefaultState.aParagraphSprms;
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index 1747958..1d72ece 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -372,6 +372,8 @@ namespace writerfilter {
                 int getFontIndex(int nIndex);
                 /// Return the encoding associated with a dmapper font index.
                 rtl_TextEncoding getEncoding(sal_uInt32 nFontIndex);
+                /// Get the default parser state.
+                RTFParserState& getDefaultState();
 
             private:
                 SvStream& Strm();


More information about the Libreoffice-commits mailing list