[Libreoffice-commits] core.git: Branch 'distro/vector/vector-5.4' - sw/source vcl/qa

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Fri Apr 26 15:48:58 UTC 2019


 sw/source/core/unocore/unoidx.cxx           |    9 +++
 vcl/qa/cppunit/pdfexport/data/toc-link.fodt |   45 +++++++++++++++++
 vcl/qa/cppunit/pdfexport/pdfexport.cxx      |   71 ++++++++++++++++++++++++++++
 3 files changed, 125 insertions(+)

New commits:
commit 17ce3ed9c394e6190227d3fae8f83e435c448d94
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri Apr 26 15:25:27 2019 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Apr 26 17:27:49 2019 +0200

    sw: sync UNO API default for ToC link start char style with UI
    
    The UI default is in the SwForm ctor, where the content type sets the
    link start char style to STR_POOLCHR_TOXJUMP.
    
    Have the same default in the UNO API in case the import filters don't
    set it explicitly, since that breaks clickable hyperlinks on PDF export.
    
    This also fixes the OSL_ENSURE() failure for missing character formats
    in SwTextINetFormat::GetCharFormat().
    
    Reviewed-on: https://gerrit.libreoffice.org/71366
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins
    (cherry picked from commit 9c3e5875e827c04e6dc029bba1ac179eb2484c29)
    
    Conflicts:
            sw/source/core/unocore/unoidx.cxx
            vcl/qa/cppunit/pdfexport/pdfexport.cxx
    
    Change-Id: Ifff354d56a569614ca7f5a89dd75f41817300078

diff --git a/sw/source/core/unocore/unoidx.cxx b/sw/source/core/unocore/unoidx.cxx
index dbdd6e13d971..864e4ef9a384 100644
--- a/sw/source/core/unocore/unoidx.cxx
+++ b/sw/source/core/unocore/unoidx.cxx
@@ -2911,6 +2911,15 @@ SwXDocumentIndex::TokenAccess_Impl::replaceByIndex(
                 throw lang::IllegalArgumentException();
             }
         }
+
+        if (rTOXBase.GetType() == TOX_CONTENT)
+        {
+            if (aToken.eTokenType == TOKEN_LINK_START && aToken.sCharStyleName.isEmpty())
+            {
+                aToken.sCharStyleName = SwResId(STR_POOLCHR_TOXJUMP);
+            }
+        }
+
         sPattern += aToken.GetString();
     }
     SwForm aForm(rTOXBase.GetTOXForm());
diff --git a/vcl/qa/cppunit/pdfexport/data/toc-link.fodt b/vcl/qa/cppunit/pdfexport/data/toc-link.fodt
new file mode 100644
index 000000000000..ab29e88a47ba
--- /dev/null
+++ b/vcl/qa/cppunit/pdfexport/data/toc-link.fodt
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text">
+  <office:styles>
+    <style:style style:name="Standard" style:family="paragraph" style:class="text"/>
+    <style:style style:name="Heading" style:family="paragraph" style:parent-style-name="Standard" style:next-style-name="Text_20_body" style:class="text"/>
+    <style:style style:name="Heading_20_1" style:display-name="Heading 1" style:family="paragraph" style:parent-style-name="Heading" style:default-outline-level="1" style:class="text">
+      <style:paragraph-properties fo:margin-top="0.423cm" fo:margin-bottom="0.212cm"/>
+    </style:style>
+    <style:style style:name="Contents_20_Heading" style:display-name="Contents Heading" style:family="paragraph" style:parent-style-name="Heading" style:class="index"/>
+    <style:style style:name="Contents_20_1" style:display-name="Contents 1" style:family="paragraph" style:parent-style-name="Index" style:class="index">
+      <style:paragraph-properties fo:margin-left="0cm" fo:margin-right="0cm" fo:text-indent="0cm" style:auto-text-indent="false"/>
+    </style:style>
+    <style:style style:name="Index_20_Link" style:display-name="Index Link" style:family="text"/>
+  </office:styles>
+  <office:automatic-styles>
+    <style:style style:name="Sect1" style:family="section"/>
+    <style:page-layout style:name="pm1">
+      <style:page-layout-properties fo:page-width="21.59cm" fo:page-height="27.94cm" fo:margin-top="2cm" fo:margin-bottom="2cm" fo:margin-left="2cm" fo:margin-right="2cm"/>
+    </style:page-layout>
+  </office:automatic-styles>
+  <office:master-styles>
+    <style:master-page style:name="Standard" style:page-layout-name="pm1"/>
+  </office:master-styles>
+  <office:body>
+    <office:text>
+      <text:table-of-content text:style-name="Sect1" text:protected="true" text:name="Table of Contents">
+        <text:table-of-content-source text:outline-level="10">
+          <text:index-title-template text:style-name="Contents_20_Heading">Table of Contents</text:index-title-template>
+          <text:table-of-content-entry-template text:outline-level="1" text:style-name="Contents_20_1">
+            <text:index-entry-link-start/>
+            <text:index-entry-text/>
+            <text:index-entry-link-end/>
+          </text:table-of-content-entry-template>
+        </text:table-of-content-source>
+        <text:index-body>
+          <text:index-title text:style-name="Sect1" text:name="Table of Contents_Head">
+            <text:p text:style-name="Contents_20_Heading">Table of Contents</text:p>
+          </text:index-title>
+          <text:p text:style-name="Contents_20_1"><text:a xlink:type="simple" xlink:href="#__RefHeading_Toc">Heading 1<text:tab/>1</text:a></text:p>
+        </text:index-body>
+      </text:table-of-content>
+      <text:h text:style-name="Heading_20_1" text:outline-level="1"><text:bookmark-start text:name="__RefHeading_Toc"/>Heading 1<text:bookmark-end text:name="__RefHeading_Toc"/></text:h>
+    </office:text>
+  </office:body>
+</office:document>
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 1b2f03ddc089..d578f3a27207 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -12,6 +12,8 @@
 #include <com/sun/star/frame/Desktop.hpp>
 #include <com/sun/star/frame/XStorable.hpp>
 #include <com/sun/star/view/XPrintable.hpp>
+#include <com/sun/star/text/XDocumentIndexesSupplier.hpp>
+#include <com/sun/star/util/XRefreshable.hpp>
 
 #include <comphelper/processfactory.hxx>
 #include <comphelper/propertyvalue.hxx>
@@ -25,6 +27,7 @@
 #include <tools/zcodec.hxx>
 #if HAVE_FEATURE_PDFIUM
 #include <fpdf_edit.h>
+#include <fpdf_doc.h>
 #include <fpdfview.h>
 #endif
 
@@ -35,11 +38,35 @@ namespace
 
 const char* const DATA_DIRECTORY = "/vcl/qa/cppunit/pdfexport/data/";
 
+struct CloseDocument {
+    void operator ()(FPDF_DOCUMENT doc) {
+        if (doc != nullptr) {
+            FPDF_CloseDocument(doc);
+        }
+    }
+};
+
+using DocumentHolder =
+    std::unique_ptr<typename std::remove_pointer<FPDF_DOCUMENT>::type, CloseDocument>;
+
+struct ClosePage {
+    void operator ()(FPDF_PAGE page) {
+        if (page != nullptr) {
+            FPDF_ClosePage(page);
+        }
+    }
+};
+
+using PageHolder =
+    std::unique_ptr<typename std::remove_pointer<FPDF_PAGE>::type, ClosePage>;
+
 /// Tests the PDF export filter.
 class PdfExportTest : public test::BootstrapFixture, public unotest::MacrosTest
 {
     uno::Reference<uno::XComponentContext> mxComponentContext;
     uno::Reference<lang::XComponent> mxComponent;
+    utl::TempFile maTempFile;
+    SvMemoryStream maMemory;
 #if HAVE_FEATURE_PDFIUM
     FPDF_PAGE mpPdfPage = nullptr;
     FPDF_DOCUMENT mpPdfDocument = nullptr;
@@ -69,6 +96,7 @@ public:
     void testTdf99680();
     void testTdf99680_2();
 #endif
+    void testTocLink();
 
     CPPUNIT_TEST_SUITE(PdfExportTest);
 #if HAVE_FEATURE_PDFIUM
@@ -86,6 +114,7 @@ public:
     CPPUNIT_TEST(testTdf99680);
     CPPUNIT_TEST(testTdf99680_2);
 #endif
+    CPPUNIT_TEST(testTocLink);
     CPPUNIT_TEST_SUITE_END();
 };
 
@@ -681,6 +710,48 @@ void PdfExportTest::testTdf99680_2()
     }
 }
 
+void PdfExportTest::testTocLink()
+{
+    // Load the Writer document.
+    OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "toc-link.fodt";
+    mxComponent = loadFromDesktop(aURL);
+    CPPUNIT_ASSERT(mxComponent.is());
+
+    // Update the ToC.
+    uno::Reference<text::XDocumentIndexesSupplier> xDocumentIndexesSupplier(mxComponent,
+                                                                            uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xDocumentIndexesSupplier.is());
+
+    uno::Reference<util::XRefreshable> xToc(
+        xDocumentIndexesSupplier->getDocumentIndexes()->getByIndex(0), uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xToc.is());
+
+    xToc->refresh();
+
+    // Save as PDF.
+    uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+    utl::MediaDescriptor aMediaDescriptor;
+    aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
+    xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
+
+    SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ);
+    maMemory.WriteStream(aFile);
+    DocumentHolder pPdfDocument(
+        FPDF_LoadMemDocument(maMemory.GetData(), maMemory.GetSize(), /*password=*/nullptr));
+    CPPUNIT_ASSERT(pPdfDocument.get());
+    CPPUNIT_ASSERT_EQUAL(1, FPDF_GetPageCount(pPdfDocument.get()));
+
+    PageHolder pPdfPage(FPDF_LoadPage(pPdfDocument.get(), /*page_index=*/0));
+    CPPUNIT_ASSERT(pPdfPage.get());
+
+    // Ensure there is a link on the first page (in the ToC).
+    int nStartPos = 0;
+    FPDF_LINK pLinkAnnot = nullptr;
+    // Without the accompanying fix in place, this test would have failed, as FPDFLink_Enumerate()
+    // returned false, as the page contained no links.
+    CPPUNIT_ASSERT(FPDFLink_Enumerate(pPdfPage.get(), &nStartPos, &pLinkAnnot));
+}
+
 #endif
 
 CPPUNIT_TEST_SUITE_REGISTRATION(PdfExportTest);


More information about the Libreoffice-commits mailing list