summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-02-10 20:08:11 +0100
committerMiklos Vajna <vmiklos@collabora.com>2022-02-11 08:25:11 +0100
commit00b0ff0687081bd6e88d3c3b0a1352c291fa6bb8 (patch)
treed3e2c1a15745bdeacccb0a00c7f28af214739f39 /svx
parent405a7a09558ad17642808cc3739ab202f86bea0c (diff)
PNG export: allow setting filter data keys from the cmdline
For example, to set a custom pixel size: soffice --convert-to 'png:draw_png_Export:{"PixelHeight":{"type":"long","value":"192"},"PixelWidth":{"type":"long","value":"192"}}' test.odg Change-Id: I628717ba36b6ad1ac03911eec06855c1745ef258 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129801 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'svx')
-rw-r--r--svx/qa/unit/unodraw.cxx36
-rw-r--r--svx/source/unodraw/UnoGraphicExporter.cxx36
2 files changed, 71 insertions, 1 deletions
diff --git a/svx/qa/unit/unodraw.cxx b/svx/qa/unit/unodraw.cxx
index 7e69ba8d4f05..5d2814e2c21a 100644
--- a/svx/qa/unit/unodraw.cxx
+++ b/svx/qa/unit/unodraw.cxx
@@ -19,6 +19,7 @@
#include <com/sun/star/table/XCellRange.hpp>
#include <com/sun/star/text/XTextRange.hpp>
#include <com/sun/star/text/ControlCharacter.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
#include <comphelper/processfactory.hxx>
#include <comphelper/propertysequence.hxx>
@@ -32,6 +33,9 @@
#include <svx/sdr/contact/viewcontact.hxx>
#include <svx/sdr/contact/viewobjectcontact.hxx>
#include <test/xmltesttools.hxx>
+#include <unotools/streamwrap.hxx>
+#include <unotools/mediadescriptor.hxx>
+#include <vcl/filter/PngImageReader.hxx>
#include <sdr/contact/objectcontactofobjlistpainter.hxx>
@@ -208,6 +212,38 @@ CPPUNIT_TEST_FIXTURE(UnodrawTest, testTitleShapeBullets)
// were merged together (e.g. 1 bullet instead of 2 bullets for bulleted paragraphs).
CPPUNIT_ASSERT(xTextE->hasMoreElements());
}
+
+CPPUNIT_TEST_FIXTURE(UnodrawTest, testPngExport)
+{
+ // Given an empty Impress document:
+ mxComponent = loadFromDesktop("private:factory/simpress",
+ "com.sun.star.presentation.PresentationDocument");
+
+ // When exporting that document to PNG with a JSON size:
+ uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY_THROW);
+ SvMemoryStream aStream;
+ uno::Reference<io::XOutputStream> xOut = new utl::OOutputStreamWrapper(aStream);
+ utl::MediaDescriptor aMediaDescriptor;
+ aMediaDescriptor["FilterName"] <<= OUString("impress_png_Export");
+ aMediaDescriptor["FilterOptions"]
+ <<= OUString("{\"PixelHeight\":{\"type\":\"long\",\"value\":\"192\"},"
+ "\"PixelWidth\":{\"type\":\"long\",\"value\":\"192\"}}");
+ aMediaDescriptor["OutputStream"] <<= xOut;
+ xStorable->storeToURL("private:stream", aMediaDescriptor.getAsConstPropertyValueList());
+
+ // Then make sure that the size request is handled:
+ aStream.Seek(STREAM_SEEK_TO_BEGIN);
+ vcl::PngImageReader aPngReader(aStream);
+ BitmapEx aBitmapEx;
+ aPngReader.read(aBitmapEx);
+ Size aSize = aBitmapEx.GetSizePixel();
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 192
+ // - Actual : 595
+ // i.e. it was not possible to influence the size from the cmdline.
+ CPPUNIT_ASSERT_EQUAL(static_cast<tools::Long>(192), aSize.getHeight());
+ CPPUNIT_ASSERT_EQUAL(static_cast<tools::Long>(192), aSize.getWidth());
+}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/unodraw/UnoGraphicExporter.cxx b/svx/source/unodraw/UnoGraphicExporter.cxx
index 7626579502e7..832699357257 100644
--- a/svx/source/unodraw/UnoGraphicExporter.cxx
+++ b/svx/source/unodraw/UnoGraphicExporter.cxx
@@ -64,6 +64,9 @@
#include <svx/xlineit0.hxx>
#include <editeng/flditem.hxx>
#include <svtools/optionsdrawinglayer.hxx>
+#include <comphelper/sequenceashashmap.hxx>
+#include <comphelper/propertysequence.hxx>
+#include <comphelper/sequence.hxx>
#include "UnoGraphicExporter.hxx"
#include <memory>
@@ -402,8 +405,39 @@ VclPtr<VirtualDevice> GraphicExporter::CreatePageVDev( SdrPage* pPage, tools::Lo
return pVDev;
}
-void GraphicExporter::ParseSettings( const Sequence< PropertyValue >& aDescriptor, ExportSettings& rSettings )
+void GraphicExporter::ParseSettings(const Sequence<PropertyValue>& rDescriptor,
+ ExportSettings& rSettings)
{
+ Sequence<PropertyValue> aDescriptor = rDescriptor;
+ if (aDescriptor.hasElements())
+ {
+ comphelper::SequenceAsHashMap aMap(aDescriptor);
+ Sequence<PropertyValue> aFilterData;
+ OUString aFilterOptions;
+ auto it = aMap.find("FilterData");
+ if (it != aMap.end())
+ {
+ it->second >>= aFilterData;
+ }
+ it = aMap.find("FilterOptions");
+ if (it != aMap.end())
+ {
+ it->second >>= aFilterOptions;
+ }
+ if (!aFilterData.hasElements() && !aFilterOptions.isEmpty())
+ {
+ // Allow setting filter data keys from the cmdline.
+ std::vector<PropertyValue> aData
+ = comphelper::JsonToPropertyValues(aFilterOptions.toUtf8());
+ aFilterData = comphelper::containerToSequence(aData);
+ if (aFilterData.hasElements())
+ {
+ aMap["FilterData"] <<= aFilterData;
+ aDescriptor = aMap.getAsConstPropertyValueList();
+ }
+ }
+ }
+
for( const PropertyValue& rValue : aDescriptor )
{
if ( rValue.Name == "FilterName" )