LibreOffice Module filter (master) 1
pdfdecomposer.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 */
9
10#include <vector>
11
17#include <vcl/bitmapex.hxx>
18#include <vcl/pdfread.hxx>
19#include <vcl/svapp.hxx>
20#include <vcl/outdev.hxx>
24
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>
29
30using namespace css;
31
32namespace
33{
35class XPdfDecomposer
36 : public ::cppu::WeakAggImplHelper2<graphic::XPdfDecomposer, lang::XServiceInfo>
37{
38public:
39 explicit XPdfDecomposer(uno::Reference<uno::XComponentContext> const& context);
40 XPdfDecomposer(const XPdfDecomposer&) = delete;
41 XPdfDecomposer& operator=(const XPdfDecomposer&) = delete;
42
43 // XPdfDecomposer
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;
47
48 // XServiceInfo
49 OUString SAL_CALL getImplementationName() override;
50 sal_Bool SAL_CALL supportsService(const OUString&) override;
51 uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
52};
53
54XPdfDecomposer::XPdfDecomposer(uno::Reference<uno::XComponentContext> const&) {}
55
56uno::Sequence<uno::Reference<graphic::XPrimitive2D>> SAL_CALL
57XPdfDecomposer::getDecomposition(const uno::Reference<util::XBinaryDataContainer>& xDataContainer,
58 const uno::Sequence<beans::PropertyValue>& xParameters)
59{
60 sal_Int32 nPageIndex = -1;
61
62 for (const beans::PropertyValue& rProperty : xParameters)
63 {
64 if (rProperty.Name == "PageIndex")
65 {
66 rProperty.Value >>= nPageIndex;
67 break;
68 }
69 }
70
71 if (nPageIndex < 0)
72 nPageIndex = 0;
73
74 BinaryDataContainer aDataContainer = vcl::convertUnoBinaryDataContainer(xDataContainer);
75
76 std::vector<BitmapEx> aBitmaps;
77 int rv = vcl::RenderPDFBitmaps(aDataContainer.getData(), aDataContainer.getSize(), aBitmaps,
78 nPageIndex, 1);
79 if (rv == 0)
80 return {}; // happens if we do not have PDFium
81
82 BitmapEx aReplacement(aBitmaps[0]);
83
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.
87 const Size aMM100(
88 Application::GetDefaultDevice()->PixelToLogic(aBitmapSize, MapMode(MapUnit::Map100thMM)));
90 aMM100.getWidth(), aMM100.getHeight(), 0, 0));
91
92 // create primitive
94 new drawinglayer::primitive2d::BitmapPrimitive2D(aReplacement, aBitmapTransform)
95 }
96 .toSequence();
97}
98
99OUString SAL_CALL XPdfDecomposer::getImplementationName()
100{
101 return "com.sun.star.comp.PDF.PDFDecomposer";
102}
103
104sal_Bool SAL_CALL XPdfDecomposer::supportsService(const OUString& rServiceName)
105{
106 return cppu::supportsService(this, rServiceName);
107}
108
109uno::Sequence<OUString> SAL_CALL XPdfDecomposer::getSupportedServiceNames()
110{
111 return { "com.sun.star.graphic.PdfTools" };
112}
113}
114
115extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
116filter_PdfDecomposer_get_implementation(css::uno::XComponentContext* context,
117 css::uno::Sequence<css::uno::Any> const&)
118{
119 return cppu::acquire(new XPdfDecomposer(context));
120}
121
122/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
static OutputDevice * GetDefaultDevice()
size_t getSize() const
const sal_uInt8 * getData() const
OWeakAggObject & operator=(const OWeakAggObject &rObj) SAL_DELETED_FUNCTION
B2DHomMatrix createScaleTranslateB2DHomMatrix(double fScaleX, double fScaleY, double fTranslateX, double fTranslateY)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
size_t RenderPDFBitmaps(const void *pBuffer, int nSize, std::vector< BitmapEx > &rBitmaps, size_t nFirstPage=0, int nPages=1, const basegfx::B2DTuple *pSizeHint=nullptr)
BinaryDataContainer convertUnoBinaryDataContainer(const css::uno::Reference< css::util::XBinaryDataContainer > &rxBinaryDataContainer)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * filter_PdfDecomposer_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
unsigned char sal_Bool