desktop/CppunitTest_desktop_lib.mk | 1 desktop/qa/data/3page.odg |binary desktop/qa/desktop_lib/test_desktop_lib.cxx | 29 ++++++++++++++++++++++++++++ desktop/source/lib/init.cxx | 7 +++++- 4 files changed, 36 insertions(+), 1 deletion(-)
New commits: commit b5313fd606ddf26d5f57c8502060454070bfd3da Author: Miklos Vajna <[email protected]> AuthorDate: Wed Jan 26 08:38:59 2022 +0100 Commit: Mike Kaganski <[email protected]> CommitDate: Tue Feb 1 09:08:09 2022 +0100 desktop lok, export options: allow passing through a JSON string as-is setFormatSpecificFilterData() sets useful defaults, but the PDF export code has the (sane) behavior of preferring FilterData over FilterOptions, so in case we explicitly got a JSON string in FilterOptions to in fact set FilterData, then leave FilterData empty. (cherry picked from commit d0451dcf96508bf4d75c8147168f974ad3ebf03f) Change-Id: I20e8094bf431782fe0f5d68e3ec630e1274e30c7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129226 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Mike Kaganski <[email protected]> diff --git a/desktop/CppunitTest_desktop_lib.mk b/desktop/CppunitTest_desktop_lib.mk index 68a7ca8f2aed..a5082c002048 100644 --- a/desktop/CppunitTest_desktop_lib.mk +++ b/desktop/CppunitTest_desktop_lib.mk @@ -37,6 +37,7 @@ $(eval $(call gb_CppunitTest_use_libraries,desktop_lib, \ $(eval $(call gb_CppunitTest_use_externals,desktop_lib, \ boost_headers \ cairo \ + pdfium \ )) $(eval $(call gb_CppunitTest_set_include,desktop_lib,\ diff --git a/desktop/qa/data/3page.odg b/desktop/qa/data/3page.odg new file mode 100644 index 000000000000..1fad913e0493 Binary files /dev/null and b/desktop/qa/data/3page.odg differ diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index bee2c2aab765..6cf4d2e79e6c 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -58,6 +58,7 @@ #include <cppunit/TestAssert.h> #include <vcl/BitmapTools.hxx> #include <vcl/pngwrite.hxx> +#include <vcl/filter/PDFiumLibrary.hxx> using namespace com::sun::star; using namespace desktop; @@ -149,6 +150,7 @@ public: void testSearchAllNotificationsCalc(); void testPaintTile(); void testSaveAs(); + void testSaveAsJsonOptions(); void testSaveAsCalc(); void testPasteWriter(); void testPasteWriterJPEG(); @@ -216,6 +218,7 @@ public: CPPUNIT_TEST(testSearchAllNotificationsCalc); CPPUNIT_TEST(testPaintTile); CPPUNIT_TEST(testSaveAs); + CPPUNIT_TEST(testSaveAsJsonOptions); CPPUNIT_TEST(testSaveAsCalc); CPPUNIT_TEST(testPasteWriter); CPPUNIT_TEST(testPasteWriterJPEG); @@ -660,6 +663,32 @@ void DesktopLOKTest::testSaveAs() CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, aTempFile.GetURL().toUtf8().getStr(), "png", nullptr)); } +void DesktopLOKTest::testSaveAsJsonOptions() +{ + // Given a document with 3 pages: + LibLODocument_Impl* pDocument = loadDoc("3page.odg"); + + // When exporting that document to PDF, skipping the first page: + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + OString aOptions("{\"PageRange\":{\"type\":\"string\",\"value\":\"2-\"}}"); + CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, aTempFile.GetURL().toUtf8().getStr(), "pdf", aOptions.getStr())); + + // Then make sure the resulting PDF has 2 pages: + SvFileStream aFile(aTempFile.GetURL(), StreamMode::READ); + SvMemoryStream aMemory; + aMemory.WriteStream(aFile); + std::shared_ptr<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get(); + std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument + = pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize()); + CPPUNIT_ASSERT(pPdfDocument); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 2 + // - Actual : 3 + // i.e. FilterOptions was ignored. + CPPUNIT_ASSERT_EQUAL(2, pPdfDocument->getPageCount()); +} + void DesktopLOKTest::testSaveAsCalc() { LibLODocument_Impl* pDocument = loadDoc("search.ods"); diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 1c2952ab8953..920041060d88 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -2908,7 +2908,12 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha comphelper::SequenceAsHashMap aFilterDataMap; - setFormatSpecificFilterData(sFormat, aFilterDataMap); + // If filter options is JSON string, then make sure aFilterDataMap stays empty, otherwise we + // would ignore the filter options. + if (!aFilterOptions.startsWith("{")) + { + setFormatSpecificFilterData(sFormat, aFilterDataMap); + } if (!watermarkText.isEmpty()) aFilterDataMap["TiledWatermark"] <<= watermarkText;
