1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <com/sun/star/graphic/XPrimitive2DRenderer.hpp>
23 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <cppuhelper/implbase2.hxx>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <comphelper/sequence.hxx>
28 #include <com/sun/star/xml/sax/XParser.hpp>
29 #include <com/sun/star/xml/sax/InputSource.hpp>
30 #include <comphelper/processfactory.hxx>
31 #include <drawinglayer/geometry/viewinformation2d.hxx>
32 #include <basegfx/numeric/ftools.hxx>
33 #include <vcl/bitmapex.hxx>
34 #include <drawinglayer/tools/converters.hxx>
35 #include <vcl/canvastools.hxx>
36 #include <com/sun/star/geometry/RealRectangle2D.hpp>
37 #include <basegfx/matrix/b2dhommatrixtools.hxx>
38 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
40 #include <xprimitive2drenderer.hxx>
42 using namespace ::com::sun::star
;
45 namespace drawinglayer
49 class XPrimitive2DRenderer
:
50 public cppu::WeakAggImplHelper2
<
51 css::graphic::XPrimitive2DRenderer
, css::lang::XServiceInfo
>
54 XPrimitive2DRenderer();
55 virtual ~XPrimitive2DRenderer();
57 XPrimitive2DRenderer(const XPrimitive2DRenderer
&) = delete;
58 const XPrimitive2DRenderer
& operator=(const XPrimitive2DRenderer
&) = delete;
60 // XPrimitive2DRenderer
61 virtual uno::Reference
< rendering::XBitmap
> SAL_CALL
rasterize(
62 const uno::Sequence
< uno::Reference
< graphic::XPrimitive2D
> >& Primitive2DSequence
,
63 const uno::Sequence
< beans::PropertyValue
>& aViewInformationSequence
,
66 const css::geometry::RealRectangle2D
& Range
,
67 ::sal_uInt32 MaximumQuadraticPixels
) throw (uno::RuntimeException
, std::exception
) override
;
70 virtual OUString SAL_CALL
getImplementationName() throw(uno::RuntimeException
, std::exception
) override
;
71 virtual sal_Bool SAL_CALL
supportsService(const OUString
&) throw(uno::RuntimeException
, std::exception
) override
;
72 virtual uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() throw(uno::RuntimeException
, std::exception
) override
;
74 } // end of namespace unorenderer
75 } // end of namespace drawinglayer
80 namespace drawinglayer
84 uno::Sequence
< OUString
> XPrimitive2DRenderer_getSupportedServiceNames()
86 return uno::Sequence
< OUString
> { "com.sun.star.graphic.Primitive2DTools" };
89 OUString
XPrimitive2DRenderer_getImplementationName()
91 return OUString( "drawinglayer::unorenderer::XPrimitive2DRenderer" );
94 uno::Reference
< uno::XInterface
> SAL_CALL
XPrimitive2DRenderer_createInstance(const uno::Reference
< lang::XMultiServiceFactory
>&)
96 return static_cast< ::cppu::OWeakObject
* >(new XPrimitive2DRenderer
);
98 } // end of namespace unorenderer
99 } // end of namespace drawinglayer
102 namespace drawinglayer
104 namespace unorenderer
106 XPrimitive2DRenderer::XPrimitive2DRenderer()
110 XPrimitive2DRenderer::~XPrimitive2DRenderer()
114 uno::Reference
< rendering::XBitmap
> XPrimitive2DRenderer::rasterize(
115 const uno::Sequence
< uno::Reference
< graphic::XPrimitive2D
> >& aPrimitive2DSequence
,
116 const uno::Sequence
< beans::PropertyValue
>& aViewInformationSequence
,
119 const css::geometry::RealRectangle2D
& Range
,
120 ::sal_uInt32 MaximumQuadraticPixels
) throw (uno::RuntimeException
, std::exception
)
122 uno::Reference
< rendering::XBitmap
> XBitmap
;
124 if(aPrimitive2DSequence
.hasElements())
126 const basegfx::B2DRange
aRange(Range
.X1
, Range
.Y1
, Range
.X2
, Range
.Y2
);
127 const double fWidth(aRange
.getWidth());
128 const double fHeight(aRange
.getHeight());
130 if(basegfx::fTools::more(fWidth
, 0.0) && basegfx::fTools::more(fHeight
, 0.0))
142 if(0 == MaximumQuadraticPixels
)
144 MaximumQuadraticPixels
= 500000;
147 const geometry::ViewInformation2D
aViewInformation2D(aViewInformationSequence
);
148 const double fFactor100th_mmToInch(1.0 / (2.54 * 1000.0));
149 const sal_uInt32
nDiscreteWidth(basegfx::fround((fWidth
* fFactor100th_mmToInch
) * DPI_X
));
150 const sal_uInt32
nDiscreteHeight(basegfx::fround((fHeight
* fFactor100th_mmToInch
) * DPI_Y
));
152 basegfx::B2DHomMatrix
aEmbedding(
153 basegfx::tools::createTranslateB2DHomMatrix(
158 nDiscreteWidth
/ fWidth
,
159 nDiscreteHeight
/ fHeight
);
161 const primitive2d::Primitive2DReference
xEmbedRef(
162 new primitive2d::TransformPrimitive2D(
164 comphelper::sequenceToContainer
<primitive2d::Primitive2DContainer
>(aPrimitive2DSequence
)));
165 const primitive2d::Primitive2DContainer xEmbedSeq
{ xEmbedRef
};
168 tools::convertToBitmapEx(
173 MaximumQuadraticPixels
));
175 if(!aBitmapEx
.IsEmpty())
177 const uno::Reference
< rendering::XGraphicDevice
> xGraphicDevice
;
179 aBitmapEx
.SetPrefMapMode(MapMode(MAP_100TH_MM
));
180 aBitmapEx
.SetPrefSize(Size(basegfx::fround(fWidth
), basegfx::fround(fHeight
)));
181 XBitmap
= vcl::unotools::xBitmapFromBitmapEx(xGraphicDevice
, aBitmapEx
);
189 OUString SAL_CALL
XPrimitive2DRenderer::getImplementationName() throw(uno::RuntimeException
, std::exception
)
191 return(XPrimitive2DRenderer_getImplementationName());
194 sal_Bool SAL_CALL
XPrimitive2DRenderer::supportsService(const OUString
& rServiceName
) throw(uno::RuntimeException
, std::exception
)
196 return cppu::supportsService(this, rServiceName
);
199 uno::Sequence
< OUString
> SAL_CALL
XPrimitive2DRenderer::getSupportedServiceNames() throw(uno::RuntimeException
, std::exception
)
201 return XPrimitive2DRenderer_getSupportedServiceNames();
204 } // end of namespace unorenderer
205 } // end of namespace drawinglayer
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */