summaryrefslogtreecommitdiff
path: root/filter
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2019-10-18 11:19:04 +0200
committerTomaž Vajngerl <quikee@gmail.com>2020-06-06 19:23:54 +0200
commit15834ad4dee944374f4b6298f2d384d185a49815 (patch)
treebb52eb53d8e48fbab826374bb982b18341a373cd /filter
parent3862929efcc5e9275d878bbe64cb034796e4012d (diff)
pdfium: Make Insert -> Image... use VectorGraphicData for PDF.
In principle, the current Svg/Emf/Wmf and PDF handling is trying to achieve the same thing: Keep the original stream untouched, provide a replacement graphics, and a kind of rendering. To hold the data, the Svg/Emf/Wmf and PDF were using different structures though. This commit consolidatates that, and makes the Insert -> Image... (for PDF) actually using the VectorGraphicData to hold the original stream. This breaks loading the PDF as a document via PDFium - I'll fix it in the next commit(s). Change-Id: Iac102f32b757390a03438c165e430283851cc10b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90561 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95618 Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'filter')
-rw-r--r--filter/Library_pdffilter.mk2
-rw-r--r--filter/source/pdf/pdfdecomposer.cxx106
-rw-r--r--filter/source/pdf/pdfdecomposer.hxx22
-rw-r--r--filter/source/pdf/pdffilter.component3
-rw-r--r--filter/source/pdf/pdfuno.cxx7
5 files changed, 140 insertions, 0 deletions
diff --git a/filter/Library_pdffilter.mk b/filter/Library_pdffilter.mk
index 21be2a1cd5ee..306728729895 100644
--- a/filter/Library_pdffilter.mk
+++ b/filter/Library_pdffilter.mk
@@ -48,10 +48,12 @@ $(eval $(call gb_Library_use_libraries,pdffilter,\
cppuhelper \
cppu \
sal \
+ drawinglayer \
))
$(eval $(call gb_Library_add_exception_objects,pdffilter,\
filter/source/pdf/impdialog \
+ filter/source/pdf/pdfdecomposer \
filter/source/pdf/pdfdialog \
filter/source/pdf/pdfexport \
filter/source/pdf/pdffilter \
diff --git a/filter/source/pdf/pdfdecomposer.cxx b/filter/source/pdf/pdfdecomposer.cxx
new file mode 100644
index 000000000000..c926b1b35a9d
--- /dev/null
+++ b/filter/source/pdf/pdfdecomposer.cxx
@@ -0,0 +1,106 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "pdfdecomposer.hxx"
+
+#include <vector>
+
+#include <basegfx/matrix/b2dhommatrixtools.hxx>
+#include <comphelper/processfactory.hxx>
+#include <cppuhelper/implbase2.hxx>
+#include <cppuhelper/supportsservice.hxx>
+#include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
+#include <vcl/bitmapex.hxx>
+#include <vcl/pdfread.hxx>
+#include <vcl/svapp.hxx>
+#include <vcl/outdev.hxx>
+
+#include <com/sun/star/graphic/XPdfDecomposer.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
+
+using namespace css;
+
+namespace
+{
+/// Class to convert the PDF data into a XPrimitive2D (containing only a bitmap).
+class XPdfDecomposer
+ : public ::cppu::WeakAggImplHelper2<graphic::XPdfDecomposer, lang::XServiceInfo>
+{
+public:
+ explicit XPdfDecomposer(uno::Reference<uno::XComponentContext> const& context);
+ XPdfDecomposer(const XPdfDecomposer&) = delete;
+ XPdfDecomposer& operator=(const XPdfDecomposer&) = delete;
+
+ // XPdfDecomposer
+ uno::Sequence<uno::Reference<graphic::XPrimitive2D>>
+ SAL_CALL getDecomposition(const uno::Sequence<sal_Int8>& xPdfData) override;
+
+ // XServiceInfo
+ OUString SAL_CALL getImplementationName() override;
+ sal_Bool SAL_CALL supportsService(const OUString&) override;
+ uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
+};
+
+XPdfDecomposer::XPdfDecomposer(uno::Reference<uno::XComponentContext> const&) {}
+
+uno::Sequence<uno::Reference<graphic::XPrimitive2D>>
+ SAL_CALL XPdfDecomposer::getDecomposition(const uno::Sequence<sal_Int8>& xPdfData)
+{
+ std::vector<Bitmap> aBitmaps;
+ vcl::RenderPDFBitmaps(xPdfData.getConstArray(), xPdfData.getLength(), aBitmaps, 0,
+ 1 /*, fResolutionDPI*/);
+ BitmapEx aReplacement(aBitmaps[0]);
+
+ // short form for scale and translate transformation
+ const Size aDPI(
+ Application::GetDefaultDevice()->LogicToPixel(Size(1, 1), MapMode(MapUnit::MapInch)));
+ const Size aBitmapSize(aReplacement.GetSizePixel());
+ const basegfx::B2DHomMatrix aBitmapTransform(basegfx::utils::createScaleTranslateB2DHomMatrix(
+ aBitmapSize.getWidth() * aDPI.getWidth(), aBitmapSize.getHeight() * aDPI.getHeight(), 0,
+ 0));
+
+ // create primitive
+ uno::Sequence<uno::Reference<graphic::XPrimitive2D>> aSequence(1);
+ aSequence[0] = new drawinglayer::primitive2d::BitmapPrimitive2D(aReplacement, aBitmapTransform);
+
+ return aSequence;
+}
+
+OUString SAL_CALL XPdfDecomposer::getImplementationName()
+{
+ return PDFDecomposer_getImplementationName();
+}
+
+sal_Bool SAL_CALL XPdfDecomposer::supportsService(const OUString& rServiceName)
+{
+ return cppu::supportsService(this, rServiceName);
+}
+
+uno::Sequence<OUString> SAL_CALL XPdfDecomposer::getSupportedServiceNames()
+{
+ return PDFDecomposer_getSupportedServiceNames();
+}
+}
+
+OUString PDFDecomposer_getImplementationName() { return "com.sun.star.comp.PDF.PDFDecomposer"; }
+
+uno::Sequence<OUString> PDFDecomposer_getSupportedServiceNames()
+{
+ return uno::Sequence<OUString>{ "com.sun.star.graphic.PdfTools" };
+}
+
+uno::Reference<uno::XInterface>
+PDFDecomposer_createInstance(const uno::Reference<lang::XMultiServiceFactory>& rSMgr)
+{
+ return static_cast<cppu::OWeakObject*>(
+ new XPdfDecomposer(comphelper::getComponentContext(rSMgr)));
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/filter/source/pdf/pdfdecomposer.hxx b/filter/source/pdf/pdfdecomposer.hxx
new file mode 100644
index 000000000000..7e1bd3954692
--- /dev/null
+++ b/filter/source/pdf/pdfdecomposer.hxx
@@ -0,0 +1,22 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_FILTER_SOURCE_PDF_PDFDECOMPOSER_HXX
+#define INCLUDED_FILTER_SOURCE_PDF_PDFDECOMPOSER_HXX
+
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+
+OUString PDFDecomposer_getImplementationName();
+css::uno::Sequence<OUString> PDFDecomposer_getSupportedServiceNames();
+css::uno::Reference<css::uno::XInterface>
+PDFDecomposer_createInstance(const css::uno::Reference<css::lang::XMultiServiceFactory>& rSMgr);
+
+#endif // INCLUDED_FILTER_SOURCE_PDF_PDFDECOMPOSER_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/filter/source/pdf/pdffilter.component b/filter/source/pdf/pdffilter.component
index 06cee2e4aa27..bc6d8006be24 100644
--- a/filter/source/pdf/pdffilter.component
+++ b/filter/source/pdf/pdffilter.component
@@ -28,4 +28,7 @@
<implementation name="com.sun.star.comp.PDF.PDFExportInteractionHandler">
<service name="com.sun.star.filter.pdfexport.PDFExportInteractionHandler"/>
</implementation>
+ <implementation name="com.sun.star.comp.PDF.PDFDecomposer">
+ <service name="com.sun.star.graphic.PdfTools"/>
+ </implementation>
</component>
diff --git a/filter/source/pdf/pdfuno.cxx b/filter/source/pdf/pdfuno.cxx
index 8dad87097afa..01cbfef7c185 100644
--- a/filter/source/pdf/pdfuno.cxx
+++ b/filter/source/pdf/pdfuno.cxx
@@ -22,6 +22,7 @@
#include <cppuhelper/factory.hxx>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#include "pdfdecomposer.hxx"
#include "pdffilter.hxx"
#include "pdfdialog.hxx"
#include "pdfinteract.hxx"
@@ -63,6 +64,12 @@ extern "C"
PDFInteractionHandler_createInstance, PDFInteractionHandler_getSupportedServiceNames() );
}
+ else if (aImplName == PDFDecomposer_getImplementationName())
+ {
+ xFactory = createSingleFactory(static_cast<XMultiServiceFactory*>(pServiceManager),
+ OUString::createFromAscii(pImplName),
+ PDFDecomposer_createInstance, PDFDecomposer_getSupportedServiceNames());
+ }
if( xFactory.is() )
{