Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <sal/config.h>
21 :
22 : #include <boost/noncopyable.hpp>
23 : #include <com/sun/star/graphic/XPrimitive2DRenderer.hpp>
24 : #include <com/sun/star/lang/XServiceInfo.hpp>
25 : #include <cppuhelper/implbase2.hxx>
26 : #include <cppuhelper/supportsservice.hxx>
27 : #include <com/sun/star/xml/sax/XParser.hpp>
28 : #include <com/sun/star/xml/sax/InputSource.hpp>
29 : #include <comphelper/processfactory.hxx>
30 : #include <drawinglayer/geometry/viewinformation2d.hxx>
31 : #include <basegfx/numeric/ftools.hxx>
32 : #include <vcl/bitmapex.hxx>
33 : #include <drawinglayer/tools/converters.hxx>
34 : #include <vcl/canvastools.hxx>
35 : #include <com/sun/star/geometry/RealRectangle2D.hpp>
36 : #include <basegfx/matrix/b2dhommatrixtools.hxx>
37 : #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
38 :
39 : #include <xprimitive2drenderer.hxx>
40 :
41 : using namespace ::com::sun::star;
42 :
43 :
44 :
45 : namespace drawinglayer
46 : {
47 : namespace unorenderer
48 : {
49 : class XPrimitive2DRenderer:
50 : public cppu::WeakAggImplHelper2<
51 : css::graphic::XPrimitive2DRenderer, css::lang::XServiceInfo>,
52 : private boost::noncopyable
53 : {
54 : public:
55 : XPrimitive2DRenderer();
56 : virtual ~XPrimitive2DRenderer();
57 :
58 : // XPrimitive2DRenderer
59 : virtual uno::Reference< rendering::XBitmap > SAL_CALL rasterize(
60 : const uno::Sequence< uno::Reference< graphic::XPrimitive2D > >& Primitive2DSequence,
61 : const uno::Sequence< beans::PropertyValue >& aViewInformationSequence,
62 : ::sal_uInt32 DPI_X,
63 : ::sal_uInt32 DPI_Y,
64 : const ::com::sun::star::geometry::RealRectangle2D& Range,
65 : ::sal_uInt32 MaximumQuadraticPixels) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
66 :
67 : // XServiceInfo
68 : virtual OUString SAL_CALL getImplementationName() throw(uno::RuntimeException, std::exception) SAL_OVERRIDE;
69 : virtual sal_Bool SAL_CALL supportsService(const OUString&) throw(uno::RuntimeException, std::exception) SAL_OVERRIDE;
70 : virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(uno::RuntimeException, std::exception) SAL_OVERRIDE;
71 : };
72 : } // end of namespace unorenderer
73 : } // end of namespace drawinglayer
74 :
75 :
76 : // uno functions
77 :
78 : namespace drawinglayer
79 : {
80 : namespace unorenderer
81 : {
82 0 : uno::Sequence< OUString > XPrimitive2DRenderer_getSupportedServiceNames()
83 : {
84 0 : static OUString aServiceName("com.sun.star.graphic.Primitive2DTools" );
85 0 : static uno::Sequence< OUString > aServiceNames( &aServiceName, 1 );
86 :
87 0 : return( aServiceNames );
88 : }
89 :
90 0 : OUString XPrimitive2DRenderer_getImplementationName()
91 : {
92 0 : return OUString( "drawinglayer::unorenderer::XPrimitive2DRenderer" );
93 : }
94 :
95 0 : uno::Reference< uno::XInterface > SAL_CALL XPrimitive2DRenderer_createInstance(const uno::Reference< lang::XMultiServiceFactory >&)
96 : {
97 0 : return static_cast< ::cppu::OWeakObject* >(new XPrimitive2DRenderer);
98 : }
99 : } // end of namespace unorenderer
100 : } // end of namespace drawinglayer
101 :
102 :
103 :
104 : namespace drawinglayer
105 : {
106 : namespace unorenderer
107 : {
108 0 : XPrimitive2DRenderer::XPrimitive2DRenderer()
109 : {
110 0 : }
111 :
112 0 : XPrimitive2DRenderer::~XPrimitive2DRenderer()
113 : {
114 0 : }
115 :
116 0 : uno::Reference< rendering::XBitmap > XPrimitive2DRenderer::rasterize(
117 : const uno::Sequence< uno::Reference< graphic::XPrimitive2D > >& Primitive2DSequence,
118 : const uno::Sequence< beans::PropertyValue >& aViewInformationSequence,
119 : ::sal_uInt32 DPI_X,
120 : ::sal_uInt32 DPI_Y,
121 : const ::com::sun::star::geometry::RealRectangle2D& Range,
122 : ::sal_uInt32 MaximumQuadraticPixels) throw (uno::RuntimeException, std::exception)
123 : {
124 0 : uno::Reference< rendering::XBitmap > XBitmap;
125 :
126 0 : if(Primitive2DSequence.hasElements())
127 : {
128 0 : const basegfx::B2DRange aRange(Range.X1, Range.Y1, Range.X2, Range.Y2);
129 0 : const double fWidth(aRange.getWidth());
130 0 : const double fHeight(aRange.getHeight());
131 :
132 0 : if(basegfx::fTools::more(fWidth, 0.0) && basegfx::fTools::more(fHeight, 0.0))
133 : {
134 0 : if(0 == DPI_X)
135 : {
136 0 : DPI_X = 75;
137 : }
138 :
139 0 : if(0 == DPI_Y)
140 : {
141 0 : DPI_Y = 75;
142 : }
143 :
144 0 : if(0 == MaximumQuadraticPixels)
145 : {
146 0 : MaximumQuadraticPixels = 500000;
147 : }
148 :
149 0 : const geometry::ViewInformation2D aViewInformation2D(aViewInformationSequence);
150 0 : const double fFactor100th_mmToInch(1.0 / (2.54 * 1000.0));
151 0 : const sal_uInt32 nDiscreteWidth(basegfx::fround((fWidth * fFactor100th_mmToInch) * DPI_X));
152 0 : const sal_uInt32 nDiscreteHeight(basegfx::fround((fHeight * fFactor100th_mmToInch) * DPI_Y));
153 :
154 : basegfx::B2DHomMatrix aEmbedding(
155 : basegfx::tools::createTranslateB2DHomMatrix(
156 0 : -aRange.getMinX(),
157 0 : -aRange.getMinY()));
158 :
159 : aEmbedding.scale(
160 : nDiscreteWidth / fWidth,
161 0 : nDiscreteHeight / fHeight);
162 :
163 : const primitive2d::Primitive2DReference xEmbedRef(
164 : new primitive2d::TransformPrimitive2D(
165 : aEmbedding,
166 0 : Primitive2DSequence));
167 0 : const primitive2d::Primitive2DSequence xEmbedSeq(&xEmbedRef, 1);
168 :
169 : BitmapEx aBitmapEx(
170 : tools::convertToBitmapEx(
171 : xEmbedSeq,
172 : aViewInformation2D,
173 : nDiscreteWidth,
174 : nDiscreteHeight,
175 0 : MaximumQuadraticPixels));
176 :
177 0 : if(!aBitmapEx.IsEmpty())
178 : {
179 0 : const uno::Reference< rendering::XGraphicDevice > xGraphicDevice;
180 :
181 0 : aBitmapEx.SetPrefMapMode(MapMode(MAP_100TH_MM));
182 0 : aBitmapEx.SetPrefSize(Size(basegfx::fround(fWidth), basegfx::fround(fHeight)));
183 0 : XBitmap = vcl::unotools::xBitmapFromBitmapEx(xGraphicDevice, aBitmapEx);
184 0 : }
185 : }
186 : }
187 :
188 0 : return XBitmap;
189 : }
190 :
191 0 : OUString SAL_CALL XPrimitive2DRenderer::getImplementationName() throw(uno::RuntimeException, std::exception)
192 : {
193 0 : return(XPrimitive2DRenderer_getImplementationName());
194 : }
195 :
196 0 : sal_Bool SAL_CALL XPrimitive2DRenderer::supportsService(const OUString& rServiceName) throw(uno::RuntimeException, std::exception)
197 : {
198 0 : return cppu::supportsService(this, rServiceName);
199 : }
200 :
201 0 : uno::Sequence< OUString > SAL_CALL XPrimitive2DRenderer::getSupportedServiceNames() throw(uno::RuntimeException, std::exception)
202 : {
203 0 : return XPrimitive2DRenderer_getSupportedServiceNames();
204 : }
205 :
206 : } // end of namespace unorenderer
207 : } // end of namespace drawinglayer
208 :
209 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|