diff options
-rw-r--r-- | sw/source/core/unocore/unoidx.cxx | 10 | ||||
-rw-r--r-- | vcl/qa/cppunit/pdfexport/data/toc-link.fodt | 45 | ||||
-rw-r--r-- | vcl/qa/cppunit/pdfexport/pdfexport.cxx | 47 |
3 files changed, 102 insertions, 0 deletions
diff --git a/sw/source/core/unocore/unoidx.cxx b/sw/source/core/unocore/unoidx.cxx index 5e69d4a85fcf..31c1474f84c7 100644 --- a/sw/source/core/unocore/unoidx.cxx +++ b/sw/source/core/unocore/unoidx.cxx @@ -62,6 +62,7 @@ #include <chpfld.hxx> #include <editsh.hxx> #include <SwStyleNameMapper.hxx> +#include <strings.hrc> #include <comphelper/servicehelper.hxx> #include <comphelper/string.hxx> #include <cppuhelper/implbase.hxx> @@ -2898,6 +2899,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.append(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 99ae3392d68b..033a886f20ec 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx @@ -17,6 +17,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/propertysequence.hxx> @@ -29,6 +31,7 @@ #include <tools/zcodec.hxx> #include <fpdf_edit.h> #include <fpdf_text.h> +#include <fpdf_doc.h> #include <fpdfview.h> #include <vcl/graphicfilter.hxx> @@ -129,6 +132,7 @@ public: void testTdf115262(); void testTdf121962(); void testTdf121615(); + void testTocLink(); CPPUNIT_TEST_SUITE(PdfExportTest); CPPUNIT_TEST(testTdf106059); @@ -164,6 +168,7 @@ public: CPPUNIT_TEST(testTdf115262); CPPUNIT_TEST(testTdf121962); CPPUNIT_TEST(testTdf121615); + CPPUNIT_TEST(testTocLink); CPPUNIT_TEST_SUITE_END(); }; @@ -1737,6 +1742,48 @@ void PdfExportTest::testTdf121615() CPPUNIT_ASSERT_EQUAL( COL_BLACK, aBitmap.GetPixelColor( 199, 299 )); } +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)); +} + CPPUNIT_TEST_SUITE_REGISTRATION(PdfExportTest); } |