1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 #include <basegfx/matrix/b2dhommatrixtools.hxx>
13 #include <cppuhelper/implbase2.hxx>
14 #include <cppuhelper/supportsservice.hxx>
15 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
16 #include <drawinglayer/primitive2d/Primitive2DContainer.hxx>
17 #include <vcl/bitmapex.hxx>
18 #include <vcl/pdfread.hxx>
19 #include <vcl/svapp.hxx>
20 #include <vcl/outdev.hxx>
21 #include <vcl/BinaryDataContainer.hxx>
22 #include <vcl/BinaryDataContainerTools.hxx>
23 #include <toolkit/helper/vclunohelper.hxx>
25 #include <com/sun/star/graphic/XPdfDecomposer.hpp>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <com/sun/star/uno/XComponentContext.hpp>
28 #include <com/sun/star/util/XBinaryDataContainer.hpp>
34 /// Class to convert the PDF data into a XPrimitive2D (containing only a bitmap).
36 : public ::cppu::WeakAggImplHelper2
<graphic::XPdfDecomposer
, lang::XServiceInfo
>
39 explicit XPdfDecomposer(uno::Reference
<uno::XComponentContext
> const& context
);
40 XPdfDecomposer(const XPdfDecomposer
&) = delete;
41 XPdfDecomposer
& operator=(const XPdfDecomposer
&) = delete;
44 uno::Sequence
<uno::Reference
<graphic::XPrimitive2D
>> SAL_CALL
45 getDecomposition(const uno::Reference
<util::XBinaryDataContainer
>& xDataContainer
,
46 const uno::Sequence
<beans::PropertyValue
>& xDecompositionParameters
) override
;
49 OUString SAL_CALL
getImplementationName() override
;
50 sal_Bool SAL_CALL
supportsService(const OUString
&) override
;
51 uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
;
54 XPdfDecomposer::XPdfDecomposer(uno::Reference
<uno::XComponentContext
> const&) {}
56 uno::Sequence
<uno::Reference
<graphic::XPrimitive2D
>> SAL_CALL
57 XPdfDecomposer::getDecomposition(const uno::Reference
<util::XBinaryDataContainer
>& xDataContainer
,
58 const uno::Sequence
<beans::PropertyValue
>& xParameters
)
60 sal_Int32 nPageIndex
= -1;
62 for (const beans::PropertyValue
& rProperty
: xParameters
)
64 if (rProperty
.Name
== "PageIndex")
66 rProperty
.Value
>>= nPageIndex
;
74 BinaryDataContainer aDataContainer
= vcl::convertUnoBinaryDataContainer(xDataContainer
);
76 std::vector
<BitmapEx
> aBitmaps
;
77 int rv
= vcl::RenderPDFBitmaps(aDataContainer
.getData(), aDataContainer
.getSize(), aBitmaps
,
80 return {}; // happens if we do not have PDFium
82 BitmapEx
aReplacement(aBitmaps
[0]);
84 // short form for scale and translate transformation
85 const Size
aBitmapSize(aReplacement
.GetSizePixel());
86 // ImpGraphic::getPrefMapMode() requires mm100 for bitmaps rendered from vector graphic data.
88 Application::GetDefaultDevice()->PixelToLogic(aBitmapSize
, MapMode(MapUnit::Map100thMM
)));
89 const basegfx::B2DHomMatrix
aBitmapTransform(basegfx::utils::createScaleTranslateB2DHomMatrix(
90 aMM100
.getWidth(), aMM100
.getHeight(), 0, 0));
93 return drawinglayer::primitive2d::Primitive2DContainer
{
94 new drawinglayer::primitive2d::BitmapPrimitive2D(aReplacement
, aBitmapTransform
)
99 OUString SAL_CALL
XPdfDecomposer::getImplementationName()
101 return "com.sun.star.comp.PDF.PDFDecomposer";
104 sal_Bool SAL_CALL
XPdfDecomposer::supportsService(const OUString
& rServiceName
)
106 return cppu::supportsService(this, rServiceName
);
109 uno::Sequence
<OUString
> SAL_CALL
XPdfDecomposer::getSupportedServiceNames()
111 return { "com.sun.star.graphic.PdfTools" };
115 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
116 filter_PdfDecomposer_get_implementation(css::uno::XComponentContext
* context
,
117 css::uno::Sequence
<css::uno::Any
> const&)
119 return cppu::acquire(new XPdfDecomposer(context
));
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */