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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Aug 28 02:54:52 PDT 2012


 sw/qa/extras/rtfimport/data/fdo52052.rtf       |   23 +++++++++++
 sw/qa/extras/rtfimport/rtfimport.cxx           |    9 ++++
 sw/qa/extras/swmodeltestbase.hxx               |   15 +++++--
 writerfilter/source/rtftok/rtfdocumentimpl.cxx |   51 ++++++++++++++++++++++---
 writerfilter/source/rtftok/rtfdocumentimpl.hxx |    3 +
 5 files changed, 92 insertions(+), 9 deletions(-)

New commits:
commit 1efa576ef88141c4deb5da9818537e053dc6517b
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Tue Aug 28 11:21:50 2012 +0200

    fdo#52052 fix RTF import of page breaks on landscape pages
    
    The problem was that we tried to insert a page break before reaching the
    first section break, where section properties are sent.
    
    Additionally, the continuous section break at the end of the doc caused
    trouble, so ignore it explicitly.
    
    Change-Id: I22bc355994991beeadb41d26b44ce3e2beedbdb2

diff --git a/sw/qa/extras/rtfimport/data/fdo52052.rtf b/sw/qa/extras/rtfimport/data/fdo52052.rtf
new file mode 100644
index 0000000..329762e
--- /dev/null
+++ b/sw/qa/extras/rtfimport/data/fdo52052.rtf
@@ -0,0 +1,23 @@
+{\rtf1\ansi\ansicpg1251\deff0\deflang1033
+{\fonttbl
+{\f0\fswiss\fcharset204 Arial;}
+}
+{\colortbl;\red0\green0\blue0;}
+{\info
+{\title }
+{\author Crystal Reports}
+{\doccomm Powered By Crystal}
+{\company Crystal Decisions}
+}
+\landscape\paperw16836\paperh11904\margl567\margr397\margt567\margb284\gutter0\windowctrl\ftnbj\viewkind1\viewscale100\sectd\linex0\sbknone
+{\pard first
+\par }
+\page\sect 
+{\pard \pvpg\phpg\posx13152\posy612\absw2984\absh-210\fi0 \ltrpar\qr\tx360\tx720\tx1080\tx1440\tx1800\tx2160\tx2520\tx2880
+{\ltrch\f0 \b\i0\ul0\strike0\fs15 \cf1 second}
+\par }
+\page\sect 
+{\pard \pvpg\phpg\posx13152\posy612\absw2984\absh-210\fi0 \ltrpar\qr\tx360\tx720\tx1080\tx1440\tx1800\tx2160\tx2520\tx2880
+{\ltrch\f0 \b\i0\ul0\strike0\fs15 \cf1 third}
+\par }
+\sect }
diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx
index 219acbe..918e7a5 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -106,6 +106,7 @@ public:
     void testFdo48446();
     void testFdo47495();
     void testAllGapsWord();
+    void testFdo52052();
 
     CPPUNIT_TEST_SUITE(Test);
 #if !defined(MACOSX) && !defined(WNT)
@@ -153,6 +154,7 @@ public:
     CPPUNIT_TEST(testFdo48446);
     CPPUNIT_TEST(testFdo47495);
     CPPUNIT_TEST(testAllGapsWord);
+    CPPUNIT_TEST(testFdo52052);
 #endif
     CPPUNIT_TEST_SUITE_END();
 
@@ -915,6 +917,13 @@ void Test::testAllGapsWord()
     borderTest.testTheBorders(mxComponent);
 }
 
+void Test::testFdo52052()
+{
+    load("fdo52052.rtf");
+    // Make sure the textframe containing the text "third" appears on the 3rd page.
+    CPPUNIT_ASSERT_EQUAL(OUString("third"), parseDump("/root/page[3]/body/txt/anchored/fly/txt/text()"));
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 8120540..330c34d 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -270,7 +270,8 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& x
     m_bFormField(false),
     m_bIsInFrame(false),
     m_aUnicodeBuffer(),
-    m_aHexBuffer()
+    m_aHexBuffer(),
+    m_bDeferredContSectBreak(false)
 {
     OSL_ASSERT(xInputStream.is());
     m_pInStream.reset(utl::UcbStreamHelper::CreateStream(xInputStream, sal_True));
@@ -1093,6 +1094,7 @@ void RTFDocumentImpl::replayBuffer(RTFBuffer_t& rBuffer)
 int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword)
 {
     checkUnicode();
+    checkDeferredContSectBreak();
     RTFSkipDestination aSkip(*this);
     switch (nKeyword)
     {
@@ -1516,6 +1518,7 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword)
 {
     if (nKeyword != RTF_HEXCHAR)
         checkUnicode();
+    checkDeferredContSectBreak();
     RTFSkipDestination aSkip(*this);
     sal_uInt8 cCh = 0;
 
@@ -1572,7 +1575,17 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword)
             }
             break;
         case RTF_SECT:
-                sectBreak();
+            {
+                RTFValue::Pointer_t pBreak = m_aStates.top().aSectionSprms.find(NS_sprm::LN_SBkc);
+                if (pBreak.get() && !pBreak->getInt())
+                {
+                    // This is a continous section break, don't send it yet.
+                    // It's possible that we'll have nothing after this token, and then we should ignore it.
+                    m_bDeferredContSectBreak = true;
+                }
+                else
+                    sectBreak();
+            }
             break;
         case RTF_NOBREAK:
             {
@@ -1693,10 +1706,21 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword)
             break;
         case RTF_PAGE:
             {
-                sal_uInt8 sBreak[] = { 0xc };
-                Mapper().text(sBreak, 1);
-                if (!m_bNeedPap)
-                    parBreak();
+                // If we're inside a continous section, we should send a section break, not a page one.
+                RTFValue::Pointer_t pBreak = m_aStates.top().aSectionSprms.find(NS_sprm::LN_SBkc);
+                if (pBreak.get() && !pBreak->getInt())
+                {
+                    dispatchFlag(RTF_SBKPAGE);
+                    sectBreak();
+                    dispatchFlag(RTF_SBKNONE);
+                }
+                else
+                {
+                    sal_uInt8 sBreak[] = { 0xc };
+                    Mapper().text(sBreak, 1);
+                    if (!m_bNeedPap)
+                        parBreak();
+                }
             }
             break;
         case RTF_CHPGN:
@@ -1719,6 +1743,7 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword)
 int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
 {
     checkUnicode();
+    checkDeferredContSectBreak();
     RTFSkipDestination aSkip(*this);
     int nParam = -1;
     int nSprm = -1;
@@ -2342,6 +2367,7 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
 int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
 {
     checkUnicode(nKeyword != RTF_U, true);
+    checkDeferredContSectBreak();
     RTFSkipDestination aSkip(*this);
     int nSprm = 0;
     RTFValue::Pointer_t pIntValue(new RTFValue(nParam));
@@ -3081,6 +3107,7 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
 int RTFDocumentImpl::dispatchToggle(RTFKeyword nKeyword, bool bParam, int nParam)
 {
     checkUnicode();
+    checkDeferredContSectBreak();
     RTFSkipDestination aSkip(*this);
     int nSprm = -1;
     RTFValue::Pointer_t pBoolValue(new RTFValue(!bParam || nParam != 0));
@@ -3730,7 +3757,10 @@ int RTFDocumentImpl::popState()
 
     // This is the end of the doc, see if we need to close the last section.
     if (m_nGroup == 1 && !m_bFirstRun)
+    {
+        m_bDeferredContSectBreak = false;
         sectBreak(true);
+    }
 
     m_aStates.pop();
 
@@ -3947,6 +3977,15 @@ void RTFDocumentImpl::checkUnicode(bool bUnicode, bool bHex)
     }
 }
 
+void RTFDocumentImpl::checkDeferredContSectBreak()
+{
+    if (m_bDeferredContSectBreak)
+    {
+        m_bDeferredContSectBreak = false;
+        sectBreak();
+    }
+}
+
 RTFParserState::RTFParserState(RTFDocumentImpl *pDocumentImpl)
     : m_pDocumentImpl(pDocumentImpl),
     nInternalState(INTERNAL_NORMAL),
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index 0759a4c..e3120b7 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -479,6 +479,8 @@ namespace writerfilter {
                 void replayBuffer(RTFBuffer_t& rBuffer);
                 /// If we have some unicode or hex characters to send.
                 void checkUnicode(bool bUnicode = true, bool bHex = true);
+                /// If we have a pending continous section break.
+                void checkDeferredContSectBreak();
 
                 uno::Reference<uno::XComponentContext> const& m_xContext;
                 uno::Reference<io::XInputStream> const& m_xInputStream;
@@ -573,6 +575,7 @@ namespace writerfilter {
                 rtl::OStringBuffer m_aHexBuffer;
                 /// Formula import.
                 oox::formulaimport::XmlStreamBuilder m_aMathBuffer;
+                bool m_bDeferredContSectBreak;
         };
     } // namespace rtftok
 } // namespace writerfilter
commit ea4b668d4aea664d4d7fb27ff0d3b001581ff779
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Tue Aug 28 11:46:00 2012 +0200

    SwModelTestBase: support extracting node contents from a layout dump
    
    This way tests like "there is a textbox containing foo on the 3rd page"
    are possible.
    
    Also, make sure the XPath expression always matches a single node.
    
    Change-Id: Iac82b389e1910db2257240a3764ec3c7ebaa5a02

diff --git a/sw/qa/extras/swmodeltestbase.hxx b/sw/qa/extras/swmodeltestbase.hxx
index 11669fb..6ebd99c 100644
--- a/sw/qa/extras/swmodeltestbase.hxx
+++ b/sw/qa/extras/swmodeltestbase.hxx
@@ -125,8 +125,12 @@ protected:
         return xStyleFamily;
     }
 
-    /// Extract a value from the layout dump using an XPath expression and an attribute name.
-    rtl::OUString parseDump(rtl::OString aXPath, rtl::OString aAttribute)
+    /**
+     * Extract a value from the layout dump using an XPath expression and an attribute name.
+     *
+     * If the attribute is omitted, the text of the node is returned.
+     */
+    rtl::OUString parseDump(rtl::OString aXPath, rtl::OString aAttribute = OString())
     {
         if (!mpXmlBuffer)
             dumpLayout();
@@ -136,8 +140,13 @@ protected:
         xmlXPathContextPtr pXmlXpathCtx = xmlXPathNewContext(pXmlDoc);
         xmlXPathObjectPtr pXmlXpathObj = xmlXPathEvalExpression(BAD_CAST(aXPath.getStr()), pXmlXpathCtx);
         xmlNodeSetPtr pXmlNodes = pXmlXpathObj->nodesetval;
+        CPPUNIT_ASSERT_EQUAL(1, xmlXPathNodeSetGetLength(pXmlNodes));
         xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
-        rtl::OUString aRet = rtl::OUString::createFromAscii((const char*)xmlGetProp(pXmlNode, BAD_CAST(aAttribute.getStr())));
+        rtl::OUString aRet;
+        if (aAttribute.getLength())
+            aRet = rtl::OUString::createFromAscii((const char*)xmlGetProp(pXmlNode, BAD_CAST(aAttribute.getStr())));
+        else
+            aRet = rtl::OUString::createFromAscii((const char*)XML_GET_CONTENT(pXmlNode));
 
         xmlFreeDoc(pXmlDoc);
 


More information about the Libreoffice-commits mailing list