From d0451dcf96508bf4d75c8147168f974ad3ebf03f Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 26 Jan 2022 08:38:59 +0100 Subject: [PATCH] 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. Change-Id: I20e8094bf431782fe0f5d68e3ec630e1274e30c7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128970 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- desktop/qa/data/3page.odg | Bin 0 -> 11175 bytes desktop/qa/desktop_lib/test_desktop_lib.cxx | 29 ++++++++++++++++++++ desktop/source/lib/init.cxx | 7 ++++- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 desktop/qa/data/3page.odg diff --git a/desktop/qa/data/3page.odg b/desktop/qa/data/3page.odg new file mode 100644 index 0000000000000000000000000000000000000000..1fad913e0493e0c56406fb1a5f9417fb5f3bd8a4 GIT binary patch literal 11175 zcmcI~WmuH!8ZJn8mjZ$yN=Qp7;Ls`EQqmnmHw@h+-3;9^bf(g8~U4e$};Klb#| zDO(tp^1DbL8*R zv$3!+{pYCPl@4g5ZDad?N$vS>@@ZtIZJ-Ba;4`u@)3yZuLm_{cRee(nZ5zFRs+!+r z^+y3MwaxWR{~@*CRjIa)j-ILBV|!ZsOc4L- zNdX9mCR4F(&@iA1wM6#-Hl4sML-iJv9I$ZJv^P-FHIs%8W~@MMGKq^c)sfzxZcAFe zy}dru)F|7C>~Kgat?9L-_mX`t{Ruq{s4>VwH+)vQdXKqM}OjL zUz|OXde+j^7()2*;pNG`v*xH)k5`-?9JVe%t(_5m4a|po!Wiv(CSVX;(q@G#$$vLv zy(Aa8GB5`N+g*Hv&E;{V`27UOo4noI#<;1_+X>Fldx2g z0-+g(|b zZtZQhINa`9Nqbwlj-klmm*$DvrQ&;xFANYs9kKG`kjZ;_N`U73$*G5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&Q_BJPkB)%MbNP3;ps?z;~^Tu^7hp}^!pl{FQknrkSkQk=yTDg zeYr&+9FSDoh%JDhVDcgmpOq>4D|!bFV6n7gHeskD!g(fW|BYsE&{O~;g<>;P!Vv8> zWM%cDX!h{PLEzlZhuNvsw$Yd_PzDxF!i}|!M~JpcF0ETj+jQ)JRnKzS>~>0wCMqYkU!TUh+#M**Q={^X?sO+%)AN;U~g1;IF3B4l%2KQnXaMB z*;|V|ZPPVh&v-AWqywmSgS*oF(f(xP?hn1tP*5VU|J43?kIP0$L3zL%(T_q5X4>XP z`g*{BopKaKNgB5^V)|Tg`iv~fy0Zy(^kfXDnp#KOH|2B^m2 zC~e@%Ir(ZFRMp%*Cypi5I8(EI1uiy;`7>J-XjOSzE@#8Il29Lrmwz&^OZ1 z+6QtUwm{a{c{zJwSmy~(!p&Vi&*+I!c|g+~n)0-~a76p-?oL^GA zKcoCmhW)bUNB4hn^Ec_;pOJo0q`&Oy(fx0vUsAk3qx`*g7#>^Uzft}w&HFRX4{_cv zGx!b8|48-z4EFb;fqw(`OS<=Gl)o2k_BSYhmGb===kHC1{p5eE=;|20wmchq0UfFA?uFMD|Thv8LP91i}+W0;RG N+Q$)E|J9GX{{vd~Cp-WE literal 0 HcmV?d00001 diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 689a406e4a07..76eccc8f4a6d 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -62,6 +62,7 @@ #include #include #include +#include #if USE_TLS_NSS #include @@ -159,6 +160,7 @@ public: void testSearchAllNotificationsCalc(); void testPaintTile(); void testSaveAs(); + void testSaveAsJsonOptions(); void testSaveAsCalc(); void testPasteWriter(); void testPasteWriterJPEG(); @@ -225,6 +227,7 @@ public: CPPUNIT_TEST(testSearchAllNotificationsCalc); CPPUNIT_TEST(testPaintTile); CPPUNIT_TEST(testSaveAs); + CPPUNIT_TEST(testSaveAsJsonOptions); CPPUNIT_TEST(testSaveAsCalc); CPPUNIT_TEST(testPasteWriter); CPPUNIT_TEST(testPasteWriterJPEG); @@ -675,6 +678,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 pPDFium = vcl::pdf::PDFiumLibrary::get(); + std::unique_ptr 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 dfbf503b269f..f9b1d3e0ea96 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -2897,7 +2897,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;