[Libreoffice-commits] core.git: Branch 'libreoffice-6-4-0' - sw/qa sw/source

Michael Stahl (via logerrit) logerrit at kemper.freedesktop.org
Fri Jan 17 16:16:18 UTC 2020


 sw/qa/extras/rtfexport/data/mw00_table_of_contents_templates.doc |binary
 sw/qa/extras/rtfexport/rtfexport4.cxx                            |   14 ++++++++++
 sw/source/filter/ww8/ww8atr.cxx                                  |    8 +++++
 3 files changed, 22 insertions(+)

New commits:
commit 6ff3af1d6f59251c0e6d67e3d3d9495a1a182ab5
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Wed Jan 15 16:17:57 2020 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Jan 17 17:15:48 2020 +0100

    tdf#129574 sw: fix RTF export of table of contents
    
    The problem is that the hyperlink that starts at the start of the first
    paragraph of the ToX content is written to RTF before the TOC field
    itself, so the hyperlink contains the entire ToX:
    
    {{\field{\*\fldinst HYPERLINK "#__RefHeading___Toc250984071" }{\fldrslt {\rtlch\langfe1024 \ltrch\lang1024\loch
    {\field{\*\fldinst { TOC \\o "1-3" \\h \\z }}{\fldrslt {1.India\tab 1}}}}
    
    This is because the HYPERLINK is written into m_aRun but the TOC into
    m_aRunText.
    
    Interestingly StartRun() asserts that m_aRunText should be empty, so we
    don't try to change StartURL() to write the HYPERLINK into m_aRunText.
    
    The only function that moves text from m_aRunText to m_aRun is
    EndRun(), so wrap the TOC field in StartRun()/EndRun().
    
    This breaks the export of the ToX to DOCX because a mysterious SDT is
    no longer written around the field but only the field result, so only do
    this for RTF.
    
    Change-Id: I22e45c4a9c9ce6edb2b9114b4a29b2a373ec3284
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86860
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.stahl at cib.de>
    (cherry picked from commit 05d833a26208404e5f2b3d61298a57c9bcc7c1fe)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86872
    Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
    (cherry picked from commit 23ae7824ccd2df8fad6ee42ba66d2bc9a50843ff)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86909
    Tested-by: Xisco Faulí <xiscofauli at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/sw/qa/extras/rtfexport/data/mw00_table_of_contents_templates.doc b/sw/qa/extras/rtfexport/data/mw00_table_of_contents_templates.doc
new file mode 100644
index 000000000000..f0f80543bf4b
Binary files /dev/null and b/sw/qa/extras/rtfexport/data/mw00_table_of_contents_templates.doc differ
diff --git a/sw/qa/extras/rtfexport/rtfexport4.cxx b/sw/qa/extras/rtfexport/rtfexport4.cxx
index 4590b7fa0b4e..92b672c88504 100644
--- a/sw/qa/extras/rtfexport/rtfexport4.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport4.cxx
@@ -10,6 +10,7 @@
 #include <swmodeltestbase.hxx>
 
 #include <com/sun/star/text/WritingMode2.hpp>
+#include <com/sun/star/text/XDocumentIndex.hpp>
 #include <com/sun/star/style/ParagraphAdjust.hpp>
 
 #include <svx/swframetypes.hxx>
@@ -165,6 +166,19 @@ DECLARE_RTFEXPORT_TEST(testParaAdjustDistribute, "para-adjust-distribute.rtf")
                              getProperty<sal_Int16>(getParagraph(2), "ParaLastLineAdjust")));
 }
 
+DECLARE_RTFEXPORT_TEST(testTdf129574, "mw00_table_of_contents_templates.doc")
+{
+    uno::Reference<text::XDocumentIndexesSupplier> xIndexSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> xIndexes(xIndexSupplier->getDocumentIndexes());
+    uno::Reference<text::XDocumentIndex> xTOC(xIndexes->getByIndex(0), uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xTOC.is());
+    uno::Reference<text::XTextRange> xTextRange(xTOC->getAnchor());
+    // table of contents contains 4 paragraphs
+    CPPUNIT_ASSERT_EQUAL(OUString("1.Koffice 1" SAL_NEWLINE_STRING "2.Kword 1" SAL_NEWLINE_STRING
+                                  "3.Kspread 1" SAL_NEWLINE_STRING "4.Kpresenter 1"),
+                         xTextRange->getString());
+}
+
 DECLARE_RTFEXPORT_TEST(testCjklist34, "cjklist34.rtf")
 {
     sal_Int16 numFormat = getNumberingTypeOfParagraph(1);
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index dd9bcf6d02ef..9719ba6ae2ff 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -2498,8 +2498,16 @@ void AttributeOutputBase::StartTOX( const SwSection& rSect )
         if (!sStr.isEmpty())
         {
             GetExport( ).m_bInWriteTOX = true;
+            if (GetExport().GetExportFormat() == MSWordExportBase::ExportFormat::RTF)
+            {   // tdf#129574: required for RTF; doesn't work with DOCX
+                StartRun(nullptr, -42, true);
+            }
             GetExport( ).OutputField( nullptr, eCode, sStr, FieldFlags::Start | FieldFlags::CmdStart |
                 FieldFlags::CmdEnd );
+            if (GetExport().GetExportFormat() == MSWordExportBase::ExportFormat::RTF)
+            {
+                EndRun(nullptr, -42, true);
+            }
         }
     }
 


More information about the Libreoffice-commits mailing list