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

Miklos Vajna vmiklos at kemper.freedesktop.org
Wed Apr 25 02:58:15 PDT 2012


 sw/qa/extras/rtftok/data/fdo48193.rtf          |   10 +++
 sw/qa/extras/rtftok/rtftok.cxx                 |    8 ++
 writerfilter/source/rtftok/rtfdocumentimpl.cxx |   80 +++++++++----------------
 writerfilter/source/rtftok/rtfdocumentimpl.hxx |   11 +++
 4 files changed, 60 insertions(+), 49 deletions(-)

New commits:
commit f1fdcdea5436e927dde9b4dd242c4f90c2a75e9d
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Wed Apr 25 11:28:49 2012 +0200

    avoid code duplication by introducing RTFDocumentImpl::singleChar

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index ed89aa2..ba4db68 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -833,6 +833,24 @@ bool RTFFrame::inFrame()
         || nY > 0;
 }
 
+void RTFDocumentImpl::singleChar(sal_uInt8 nValue)
+{
+    sal_uInt8 sValue[] = { nValue };
+    if (!m_pCurrentBuffer)
+    {
+        Mapper().startCharacterGroup();
+        Mapper().text(sValue, 1);
+        Mapper().endCharacterGroup();
+    }
+    else
+    {
+        m_pCurrentBuffer->push_back(make_pair(BUFFER_STARTRUN, RTFValue::Pointer_t()));
+        RTFValue::Pointer_t pValue(new RTFValue(*sValue));
+        m_pCurrentBuffer->push_back(make_pair(BUFFER_TEXT, pValue));
+        m_pCurrentBuffer->push_back(make_pair(BUFFER_ENDRUN, RTFValue::Pointer_t()));
+    }
+}
+
 void RTFDocumentImpl::text(OUString& rString)
 {
     bool bRet = true;
@@ -1075,22 +1093,7 @@ int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword)
                 if (aBuf.toString().equals("EQ"))
                     m_bEq = true;
                 else
-                {
-                    sal_uInt8 sFieldStart[] = { 0x13 };
-                    if (!m_pCurrentBuffer)
-                    {
-                        Mapper().startCharacterGroup();
-                        Mapper().text(sFieldStart, 1);
-                        Mapper().endCharacterGroup();
-                    }
-                    else
-                    {
-                        m_pCurrentBuffer->push_back(make_pair(BUFFER_STARTRUN, RTFValue::Pointer_t()));
-                        RTFValue::Pointer_t pValue(new RTFValue(*sFieldStart));
-                        m_pCurrentBuffer->push_back(make_pair(BUFFER_TEXT, pValue));
-                        m_pCurrentBuffer->push_back(make_pair(BUFFER_ENDRUN, RTFValue::Pointer_t()));
-                    }
-                }
+                    singleChar(0x13);
                 m_aStates.top().nDestinationState = DESTINATION_FIELDINSTRUCTION;
             }
             break;
@@ -3025,42 +3028,12 @@ int RTFDocumentImpl::popState()
             m_aFormfieldSprms->clear();
         }
         if (!m_bEq)
-        {
-            sal_uInt8 sFieldSep[] = { 0x14 };
-            if (!m_pCurrentBuffer)
-            {
-                Mapper().startCharacterGroup();
-                Mapper().text(sFieldSep, 1);
-                Mapper().endCharacterGroup();
-            }
-            else
-            {
-                m_pCurrentBuffer->push_back(make_pair(BUFFER_STARTRUN, RTFValue::Pointer_t()));
-                RTFValue::Pointer_t pValue(new RTFValue(*sFieldSep));
-                m_pCurrentBuffer->push_back(make_pair(BUFFER_TEXT, pValue));
-                m_pCurrentBuffer->push_back(make_pair(BUFFER_ENDRUN, RTFValue::Pointer_t()));
-            }
-        }
+            singleChar(0x14);
     }
     else if (m_aStates.top().nDestinationState == DESTINATION_FIELDRESULT)
     {
         if (!m_bEq)
-        {
-            sal_uInt8 sFieldEnd[] = { 0x15 };
-            if (!m_pCurrentBuffer)
-            {
-                Mapper().startCharacterGroup();
-                Mapper().text(sFieldEnd, 1);
-                Mapper().endCharacterGroup();
-            }
-            else
-            {
-                m_pCurrentBuffer->push_back(make_pair(BUFFER_STARTRUN, RTFValue::Pointer_t()));
-                RTFValue::Pointer_t pValue(new RTFValue(*sFieldEnd));
-                m_pCurrentBuffer->push_back(make_pair(BUFFER_TEXT, pValue));
-                m_pCurrentBuffer->push_back(make_pair(BUFFER_ENDRUN, RTFValue::Pointer_t()));
-            }
-        }
+            singleChar(0x15);
         else
             m_bEq = false;
     }
@@ -3465,22 +3438,7 @@ int RTFDocumentImpl::popState()
     else if (aState.nDestinationState == DESTINATION_FIELD)
     {
         if (aState.nFieldStatus == FIELD_INSTRUCTION)
-        {
-            sal_uInt8 sFieldEnd[] = { 0x15 };
-            if (!m_pCurrentBuffer)
-            {
-                Mapper().startCharacterGroup();
-                Mapper().text(sFieldEnd, 1);
-                Mapper().endCharacterGroup();
-            }
-            else
-            {
-                m_pCurrentBuffer->push_back(make_pair(BUFFER_STARTRUN, RTFValue::Pointer_t()));
-                RTFValue::Pointer_t pValue(new RTFValue(*sFieldEnd));
-                m_pCurrentBuffer->push_back(make_pair(BUFFER_TEXT, pValue));
-                m_pCurrentBuffer->push_back(make_pair(BUFFER_ENDRUN, RTFValue::Pointer_t()));
-            }
-        }
+            singleChar(0x15);
     }
     else if (bPopShapeProperties)
     {
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index c905909..d47ab1a 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -397,6 +397,8 @@ namespace writerfilter {
                 void resolveSubstream(sal_uInt32 nPos, Id nId, rtl::OUString& rIgnoreFirst);
 
                 void text(rtl::OUString& rString);
+                // Sends a single character to dmapper, taking care of buffering.
+                void singleChar(sal_uInt8 nValue);
                 void parBreak();
                 void tableBreak();
                 void checkNeedPap();
commit bec0bab00eeed78ccdb7065554dcf9e898f499fa
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Wed Apr 25 11:21:06 2012 +0200

    fdo#48193 fix RTF import of fields without a result

diff --git a/sw/qa/extras/rtftok/data/fdo48193.rtf b/sw/qa/extras/rtftok/data/fdo48193.rtf
new file mode 100644
index 0000000..ca58549
--- /dev/null
+++ b/sw/qa/extras/rtftok/data/fdo48193.rtf
@@ -0,0 +1,10 @@
+{\rtf1
+\pard\plain
+foo
+{\field
+{\*\fldinst 
+{\f8\fs16\f8  PAGE }
+}
+}
+bar
+\par }
diff --git a/sw/qa/extras/rtftok/rtftok.cxx b/sw/qa/extras/rtftok/rtftok.cxx
index 0bb45e4..48e33e2 100644
--- a/sw/qa/extras/rtftok/rtftok.cxx
+++ b/sw/qa/extras/rtftok/rtftok.cxx
@@ -86,6 +86,7 @@ public:
     void testFdo48356();
     void testFdo48023();
     void testFdo48876();
+    void testFdo48193();
 
     CPPUNIT_TEST_SUITE(RtfModelTest);
 #if !defined(MACOSX) && !defined(WNT)
@@ -112,6 +113,7 @@ public:
     CPPUNIT_TEST(testFdo48356);
     CPPUNIT_TEST(testFdo48023);
     CPPUNIT_TEST(testFdo48876);
+    CPPUNIT_TEST(testFdo48193);
 #endif
     CPPUNIT_TEST_SUITE_END();
 
@@ -616,6 +618,12 @@ void RtfModelTest::testFdo48876()
     CPPUNIT_ASSERT_EQUAL(style::LineSpacingMode::MINIMUM, aSpacing.Mode);
 }
 
+void RtfModelTest::testFdo48193()
+{
+    load("fdo48193.rtf");
+    CPPUNIT_ASSERT_EQUAL(7, getLength());
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(RtfModelTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 6bcfdc7..ed89aa2 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -1043,7 +1043,7 @@ int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword)
             m_aStates.top().nDestinationState = DESTINATION_STYLESHEET;
             break;
         case RTF_FIELD:
-            // A field consists of an fldinst and an fldrslt group.
+            m_aStates.top().nDestinationState = DESTINATION_FIELD;
             break;
         case RTF_FLDINST:
             {
@@ -3458,6 +3458,30 @@ int RTFDocumentImpl::popState()
     }
     else if (aState.nDestinationState == DESTINATION_LEVELNUMBERS)
         m_aStates.top().aTableSprms = aState.aTableSprms;
+    else if (aState.nDestinationState == DESTINATION_FIELDINSTRUCTION)
+        m_aStates.top().nFieldStatus = FIELD_INSTRUCTION;
+    else if (aState.nDestinationState == DESTINATION_FIELDRESULT)
+        m_aStates.top().nFieldStatus = FIELD_RESULT;
+    else if (aState.nDestinationState == DESTINATION_FIELD)
+    {
+        if (aState.nFieldStatus == FIELD_INSTRUCTION)
+        {
+            sal_uInt8 sFieldEnd[] = { 0x15 };
+            if (!m_pCurrentBuffer)
+            {
+                Mapper().startCharacterGroup();
+                Mapper().text(sFieldEnd, 1);
+                Mapper().endCharacterGroup();
+            }
+            else
+            {
+                m_pCurrentBuffer->push_back(make_pair(BUFFER_STARTRUN, RTFValue::Pointer_t()));
+                RTFValue::Pointer_t pValue(new RTFValue(*sFieldEnd));
+                m_pCurrentBuffer->push_back(make_pair(BUFFER_TEXT, pValue));
+                m_pCurrentBuffer->push_back(make_pair(BUFFER_ENDRUN, RTFValue::Pointer_t()));
+            }
+        }
+    }
     else if (bPopShapeProperties)
     {
         m_aStates.top().aShape = aShape;
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index 3a1bad4..c905909 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -65,6 +65,7 @@ namespace writerfilter {
             DESTINATION_STYLESHEET,
             DESTINATION_STYLEENTRY,
             DESTINATION_EQINSTRUCTION,
+            DESTINATION_FIELD,
             DESTINATION_FIELDINSTRUCTION,
             DESTINATION_FIELDRESULT,
             DESTINATION_LISTTABLE,
@@ -161,6 +162,13 @@ namespace writerfilter {
             BMPSTYLE_PNG
         };
 
+        enum RTFFieldStatus
+        {
+            FIELD_NONE,
+            FIELD_INSTRUCTION,
+            FIELD_RESULT
+        };
+
         /// A buffer storing dmapper calls.
         typedef std::deque< std::pair<RTFBufferTypes, RTFValue::Pointer_t> > RTFBuffer_t;
 
@@ -244,6 +252,7 @@ namespace writerfilter {
                 RTFDocumentImpl* m_pDocumentImpl;
                 RTFInternalState nInternalState;
                 RTFDesitnationState nDestinationState;
+                RTFFieldStatus nFieldStatus;
                 RTFBorderState nBorderState;
                 // font table, stylesheet table
                 RTFSprms aTableSprms;


More information about the Libreoffice-commits mailing list