[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-4.1' - 2 commits - sw/qa sw/source writerfilter/source

Miklos Vajna vmiklos at collabora.co.uk
Mon Nov 18 03:15:22 PST 2013


 sw/qa/extras/rtfexport/rtfexport.cxx               |    1 
 sw/qa/extras/rtfimport/data/copypaste-footnote.rtf |    2 -
 sw/qa/extras/rtfimport/data/cp1000018.rtf          |   27 +++++++++++++++++++++
 sw/qa/extras/rtfimport/rtfimport.cxx               |   16 +++++++++++-
 sw/source/filter/ww8/rtfattributeoutput.cxx        |   14 +++++++++-
 sw/source/filter/ww8/rtfexport.cxx                 |    5 +++
 sw/source/filter/ww8/rtfexport.hxx                 |    2 +
 writerfilter/source/dmapper/DomainMapper_Impl.cxx  |    1 
 writerfilter/source/rtftok/rtfdocumentimpl.cxx     |   12 +--------
 9 files changed, 64 insertions(+), 16 deletions(-)

New commits:
commit 698c2829e0692f989cb9d4e6e55454d2d732f4ac
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Nov 18 11:32:57 2013 +0100

    cp#1000018 RTF export: avoid additional paragraph at footnote end
    
    (cherry picked from commit 8299924b750f74f799dc683134788a285b38bd72)
    
    Conflicts:
    	sw/source/filter/ww8/rtfattributeoutput.cxx
    
    Change-Id: I430a7d705208f197050a7d521c9c20b267c33f26

diff --git a/sw/qa/extras/rtfexport/rtfexport.cxx b/sw/qa/extras/rtfexport/rtfexport.cxx
index 196334b..c8aca4a 100644
--- a/sw/qa/extras/rtfexport/rtfexport.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport.cxx
@@ -440,10 +440,11 @@ void Test::testFdo53113()
 void Test::testFdo55939()
 {
     // The problem was that the exported RTF was invalid.
+    // Also, the 'Footnote text.' had an additional newline at its end.
     uno::Reference<text::XTextRange> xParagraph(getParagraph(1));
     getRun(xParagraph, 1, "Main text before footnote.");
     // Why the tab has to be removed here?
-    CPPUNIT_ASSERT_EQUAL(OUString("Footnote text.\n"),
+    CPPUNIT_ASSERT_EQUAL(OUString("Footnote text."),
             getProperty< uno::Reference<text::XTextRange> >(getRun(xParagraph, 2), "Footnote")->getText()->getString().replaceAll("\t", ""));
     getRun(xParagraph, 3, " Text after the footnote."); // However, this leading space is intentional and OK.
 }
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx
index 589f8a9..347c552 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -294,6 +294,12 @@ void RtfAttributeOutput::StartParagraph( ww8::WW8TableNodeInfo::Pointer_t pTextN
 void RtfAttributeOutput::EndParagraph( ww8::WW8TableNodeInfoInner::Pointer_t pTextNodeInfoInner )
 {
     SAL_INFO("sw.rtf", OSL_THIS_FUNC);
+    bool bLastPara = false;
+    if (m_rExport.nTxtTyp == TXT_FTN || m_rExport.nTxtTyp == TXT_EDN)
+    {
+        // We're ending a paragraph that is the last paragraph of a footnote or endnote.
+        bLastPara = m_rExport.m_nCurrentNodeIndex && m_rExport.m_nCurrentNodeIndex == m_rExport.pCurPam->End()->nNode.GetIndex();
+    }
 
     FinishTableRowCell( pTextNodeInfoInner );
 
@@ -306,8 +312,12 @@ void RtfAttributeOutput::EndParagraph( ww8::WW8TableNodeInfoInner::Pointer_t pTe
     else
     {
         aParagraph->append(m_rExport.sNewLine);
-        aParagraph->append(OOO_STRING_SVTOOLS_RTF_PAR);
-        aParagraph->append(' ');
+        // RTF_PAR at the end of the footnote would cause an additional empty paragraph.
+        if (!bLastPara)
+        {
+            aParagraph->append(OOO_STRING_SVTOOLS_RTF_PAR);
+            aParagraph->append(' ');
+        }
     }
     if (m_nColBreakNeeded)
     {
diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx
index c98b780..3f094e3 100644
--- a/sw/source/filter/ww8/rtfexport.cxx
+++ b/sw/source/filter/ww8/rtfexport.cxx
@@ -755,8 +755,10 @@ void RtfExport::OutputLinkedOLE( const OUString& )
 
 void RtfExport::OutputTextNode( const SwTxtNode& rNode )
 {
+    m_nCurrentNodeIndex = rNode.GetIndex();
     if ( !m_bOutOutlineOnly || rNode.IsOutline( ) )
         MSWordExportBase::OutputTextNode( rNode );
+    m_nCurrentNodeIndex = 0;
 }
 
 void RtfExport::AppendSection( const SwPageDesc* pPageDesc, const SwSectionFmt* pFmt, sal_uLong nLnNum )
@@ -779,7 +781,8 @@ RtfExport::RtfExport( RtfExportFilter *pFilter, SwDoc *pDocument, SwPaM *pCurren
               rtl_getTextEncodingFromWindowsCharset(
                   sw::ms::rtl_TextEncodingToWinCharset(DEF_ENCODING))),
       eCurrentEncoding(eDefaultEncoding),
-      bRTFFlySyntax(false)
+      bRTFFlySyntax(false),
+      m_nCurrentNodeIndex(0)
 {
     mbExportModeRTF = true;
     // the attribute output for the document
diff --git a/sw/source/filter/ww8/rtfexport.hxx b/sw/source/filter/ww8/rtfexport.hxx
index f4cbd43..ecc0d33 100644
--- a/sw/source/filter/ww8/rtfexport.hxx
+++ b/sw/source/filter/ww8/rtfexport.hxx
@@ -154,6 +154,8 @@ public:
     rtl_TextEncoding eCurrentEncoding;
     /// This is used by OutputFlyFrame_Impl() to control the written syntax
     bool bRTFFlySyntax;
+    /// Index of the current SwTxtNode, if any.
+    sal_uLong m_nCurrentNodeIndex;
 
     SvStream& Strm();
     SvStream& OutULong( sal_uLong nVal );
commit 7e8f19d93a58e009894e3494272015e752124e11
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Nov 15 15:05:02 2013 +0100

    cp#1000018 RTF import: empty para at the end of footnote text got lost
    
    Updated 3 testcases, in all cases first checked that the new behavior
    matches what Word does.
    
    Also added a new test, to check that empty para at footnote end is now
    kept.
    
    (cherry picked from commit 9389cf78e304a5a99bcf1745b9388e14ac36281a)
    
    Conflicts:
    	sw/qa/extras/rtfimport/rtfimport.cxx
    	writerfilter/source/rtftok/rtfdocumentimpl.cxx
    
    Change-Id: I96b8788feb4d730b5a64ba3a743311a0180ab41f

diff --git a/sw/qa/extras/rtfexport/rtfexport.cxx b/sw/qa/extras/rtfexport/rtfexport.cxx
index 442665f..196334b 100644
--- a/sw/qa/extras/rtfexport/rtfexport.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport.cxx
@@ -443,7 +443,7 @@ void Test::testFdo55939()
     uno::Reference<text::XTextRange> xParagraph(getParagraph(1));
     getRun(xParagraph, 1, "Main text before footnote.");
     // Why the tab has to be removed here?
-    CPPUNIT_ASSERT_EQUAL(OUString("Footnote text."),
+    CPPUNIT_ASSERT_EQUAL(OUString("Footnote text.\n"),
             getProperty< uno::Reference<text::XTextRange> >(getRun(xParagraph, 2), "Footnote")->getText()->getString().replaceAll("\t", ""));
     getRun(xParagraph, 3, " Text after the footnote."); // However, this leading space is intentional and OK.
 }
diff --git a/sw/qa/extras/rtfimport/data/copypaste-footnote.rtf b/sw/qa/extras/rtfimport/data/copypaste-footnote.rtf
index 93e4613..1420878 100644
--- a/sw/qa/extras/rtfimport/data/copypaste-footnote.rtf
+++ b/sw/qa/extras/rtfimport/data/copypaste-footnote.rtf
@@ -1,6 +1,6 @@
 {\rtf1
 aaa
 {\super \chftn
-{\*\footnote \chftn\pard\plain \li339\fi-339 \par}
+{\*\footnote \chftn\pard\plain \li339\fi-339}
 }
 \par }
diff --git a/sw/qa/extras/rtfimport/data/cp1000018.rtf b/sw/qa/extras/rtfimport/data/cp1000018.rtf
new file mode 100644
index 0000000..725d21e
--- /dev/null
+++ b/sw/qa/extras/rtfimport/data/cp1000018.rtf
@@ -0,0 +1,27 @@
+{\rtf1\ansi\deff3\adeflang1025
+{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}{\f1\froman\fprq2\fcharset2 Symbol;}{\f2\fswiss\fprq2\fcharset0 Arial;}{\f3\froman\fprq2\fcharset0 Times New Roman;}{\f4\fswiss\fprq2\fcharset0 Arial;}{\f5\fnil\fprq2\fcharset0 DejaVu Sans;}}
+{\colortbl;\red0\green0\blue0;\red128\green128\blue128;}
+{\stylesheet{\s0\snext0\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\aspalpha\ltrpar\cf0\kerning1\dbch\af5\langfe2052\dbch\af5\afs24\alang1081\loch\f3\fs24\lang1038 Normal;}
+{\*\cs15\snext15 Footnote Characters;}
+{\*\cs16\snext16\super Footnote Anchor;}
+{\*\cs17\snext17\super Endnote Anchor;}
+{\*\cs18\snext18 Endnote Characters;}
+{\s19\sbasedon0\snext20\sb240\sa120\keepn\dbch\af5\dbch\af5\afs28\loch\f4\fs28 Heading;}
+{\s20\sbasedon0\snext20\sb0\sa120 Text Body;}
+{\s21\sbasedon20\snext21\sb0\sa120 List;}
+{\s22\sbasedon0\snext22\sb120\sa120\noline\i\afs24\ai\fs24 Caption;}
+{\s23\sbasedon0\snext23\noline Index;}
+{\s24\sbasedon0\snext24\li339\ri0\lin339\rin0\fi-339\noline\afs20\fs20 Footnote;}
+}{\info{\creatim\yr2010\mo6\dy1\hr16\min51}{\revtim\yr2013\mo11\dy15\hr14\min22}{\printim\yr0\mo0\dy0\hr0\min0}{\comment LibreOfficeDev}{\vern67239936}}\deftab709
+\viewscale100
+{\*\pgdsctbl
+{\pgdsc0\pgdscuse451\pgwsxn11906\pghsxn5499\marglsxn1134\margrsxn1134\margtsxn1134\margbsxn1134\pgdscnxt0 Default Style;}}
+\formshade\paperh5499\paperw11906\margl1134\margr1134\margt1134\margb1134\sectd\sbknone\sectunlocked1\pgndec\pgwsxn11906\pghsxn5499\marglsxn1134\margrsxn1134\margtsxn1134\margbsxn1134\ftnbj\ftnstart1\ftnrstcont\ftnnar\aenddoc\aftnrstcont\aftnstart1\aftnnrlc
+\pgndec\pard\plain \s0\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\aspalpha\ltrpar\cf0\kerning1\dbch\af5\langfe2052\dbch\af5\afs24\alang1081\loch\f3\fs24\lang1038{\rtlch \ltrch\loch
+Hello world!}{{\super \chftn{\*\footnote \chftn\pard\plain \s24\li339\ri0\lin339\rin0\fi-339\noline\afs20\fs20{\rtlch \ltrch\loch\rtlch \ltrch\loch
+\tab Footnote }{\rtlch \ltrch\loch
+first line}{\rtlch \ltrch\loch
+.}
+\par }}
+}
+\par }
\ No newline at end of file
diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx
index 7c27a34..df2afe9 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -163,6 +163,7 @@ public:
     void testFdo69384();
     void testFdo70221();
     void testN823675();
+    void testCp1000018();
 
     CPPUNIT_TEST_SUITE(Test);
 #if !defined(MACOSX) && !defined(WNT)
@@ -309,6 +310,7 @@ void Test::run()
         {"hello.rtf", &Test::testFdo69384},
         {"fdo70221.rtf", &Test::testFdo70221},
         {"n823675.rtf", &Test::testN823675},
+        {"cp1000018.rtf", &Test::testCp1000018},
     };
     header();
     for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
@@ -582,7 +584,7 @@ void Test::testFdo45182()
     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);
+    OUString aExpected("živností\n", 11, RTL_TEXTENCODING_UTF8);
     CPPUNIT_ASSERT_EQUAL(aExpected, xTextRange->getString());
 }
 
@@ -1510,6 +1512,18 @@ void Test::testN823675()
     CPPUNIT_ASSERT_EQUAL(OUString("Symbol"), aFont.Name);
 }
 
+void Test::testCp1000018()
+{
+    // The problem was that the empty paragraph at the end of the footnote got
+    // lost during import.
+    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);
+    // Why the tab has to be removed here?
+    OUString aExpected("Footnote first line.\n");
+    CPPUNIT_ASSERT_EQUAL(aExpected, xTextRange->getString().replaceAll("\t", ""));
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index b3eb0fe..8e053fb 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -1605,7 +1605,6 @@ void DomainMapper_Impl::PushAnnotation()
 
 void DomainMapper_Impl::PopFootOrEndnote()
 {
-    RemoveLastParagraph();
     if (!m_aTextAppendStack.empty())
         m_aTextAppendStack.pop();
 
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 3cb949d..cc34b8a 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -321,14 +321,6 @@ bool RTFDocumentImpl::isSubstream() const
 void RTFDocumentImpl::finishSubstream()
 {
     checkUnicode();
-    // At the end of a footnote stream, we need to emit a run break when importing from Word.
-    // We can't do so unconditionally, as Writer already writes a \par at the end of the footnote.
-    if (m_bNeedCr)
-    {
-        Mapper().startCharacterGroup();
-        runBreak();
-        Mapper().endCharacterGroup();
-    }
 }
 
 void RTFDocumentImpl::setIgnoreFirst(OUString& rIgnoreFirst)
@@ -519,7 +511,7 @@ void RTFDocumentImpl::sectBreak(bool bFinal = false)
     bool bContinuous = pBreak.get() && pBreak->getInt() == 0;
     // If there is no paragraph in this section, then insert a dummy one, as required by Writer,
     // unless this is the end of the doc, we had nothing since the last section break and this is not a continuous one.
-    if (m_bNeedPar && !(bFinal && !m_bNeedSect && !bContinuous))
+    if (m_bNeedPar && !(bFinal && !m_bNeedSect && !bContinuous) && !isSubstream())
         dispatchSymbol(RTF_PAR);
     // It's allowed to not have a non-table paragraph at the end of an RTF doc, add it now if required.
     if (m_bNeedFinalPar && bFinal)
@@ -4432,7 +4424,7 @@ int RTFDocumentImpl::popState()
     // This is the end of the doc, see if we need to close the last section.
     if (m_pTokenizer->getGroup() == 1 && !m_bFirstRun)
     {
-        if (m_bNeedCr)
+        if (m_bNeedCr && !isSubstream())
             dispatchSymbol(RTF_PAR);
         sectBreak(true);
     }


More information about the Libreoffice-commits mailing list