1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 // MARKER(update_precomp.py): autogen include statement, do not remove 23 #include "precompiled_drawinglayer.hxx" 24 25 #include <com/sun/star/graphic/XPrimitive2DRenderer.hpp> 26 #include <com/sun/star/lang/XServiceInfo.hpp> 27 #include <cppuhelper/implbase2.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> 39 40 ////////////////////////////////////////////////////////////////////////////// 41 42 using namespace ::com::sun::star; 43 44 ////////////////////////////////////////////////////////////////////////////// 45 46 namespace drawinglayer 47 { 48 namespace unorenderer 49 { 50 class XPrimitive2DRenderer : public ::cppu::WeakAggImplHelper2< graphic::XPrimitive2DRenderer, lang::XServiceInfo > 51 { 52 private: 53 XPrimitive2DRenderer(const XPrimitive2DRenderer&); 54 XPrimitive2DRenderer& operator=(const XPrimitive2DRenderer&); 55 56 protected: 57 public: 58 XPrimitive2DRenderer(); 59 virtual ~XPrimitive2DRenderer(); 60 61 // XPrimitive2DRenderer 62 virtual uno::Reference< rendering::XBitmap > SAL_CALL rasterize( 63 const uno::Sequence< uno::Reference< graphic::XPrimitive2D > >& Primitive2DSequence, 64 const uno::Sequence< beans::PropertyValue >& aViewInformationSequence, 65 ::sal_uInt32 DPI_X, 66 ::sal_uInt32 DPI_Y, 67 const ::com::sun::star::geometry::RealRectangle2D& Range, 68 ::sal_uInt32 MaximumQuadraticPixels) throw (uno::RuntimeException); 69 70 // XServiceInfo 71 virtual rtl::OUString SAL_CALL getImplementationName() throw(uno::RuntimeException); 72 virtual ::sal_Bool SAL_CALL supportsService(const rtl::OUString&) throw(uno::RuntimeException); 73 virtual uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames() throw(uno::RuntimeException); 74 }; 75 } // end of namespace unorenderer 76 } // end of namespace drawinglayer 77 78 ////////////////////////////////////////////////////////////////////////////// 79 // uno functions 80 81 namespace drawinglayer 82 { 83 namespace unorenderer 84 { XPrimitive2DRenderer_getSupportedServiceNames()85 uno::Sequence< rtl::OUString > XPrimitive2DRenderer_getSupportedServiceNames() 86 { 87 static rtl::OUString aServiceName(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.graphic.Primitive2DTools" ) ); 88 static uno::Sequence< rtl::OUString > aServiceNames( &aServiceName, 1 ); 89 90 return( aServiceNames ); 91 } 92 XPrimitive2DRenderer_getImplementationName()93 rtl::OUString XPrimitive2DRenderer_getImplementationName() 94 { 95 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "drawinglayer::unorenderer::XPrimitive2DRenderer" ) ); 96 } 97 XPrimitive2DRenderer_createInstance(const uno::Reference<lang::XMultiServiceFactory> &)98 uno::Reference< uno::XInterface > SAL_CALL XPrimitive2DRenderer_createInstance(const uno::Reference< lang::XMultiServiceFactory >&) 99 { 100 return static_cast< ::cppu::OWeakObject* >(new XPrimitive2DRenderer); 101 } 102 } // end of namespace unorenderer 103 } // end of namespace drawinglayer 104 105 ////////////////////////////////////////////////////////////////////////////// 106 107 namespace drawinglayer 108 { 109 namespace unorenderer 110 { XPrimitive2DRenderer()111 XPrimitive2DRenderer::XPrimitive2DRenderer() 112 { 113 } 114 ~XPrimitive2DRenderer()115 XPrimitive2DRenderer::~XPrimitive2DRenderer() 116 { 117 } 118 rasterize(const uno::Sequence<uno::Reference<graphic::XPrimitive2D>> & Primitive2DSequence,const uno::Sequence<beans::PropertyValue> & aViewInformationSequence,::sal_uInt32 DPI_X,::sal_uInt32 DPI_Y,const::com::sun::star::geometry::RealRectangle2D & Range,::sal_uInt32 MaximumQuadraticPixels)119 uno::Reference< rendering::XBitmap > XPrimitive2DRenderer::rasterize( 120 const uno::Sequence< uno::Reference< graphic::XPrimitive2D > >& Primitive2DSequence, 121 const uno::Sequence< beans::PropertyValue >& aViewInformationSequence, 122 ::sal_uInt32 DPI_X, 123 ::sal_uInt32 DPI_Y, 124 const ::com::sun::star::geometry::RealRectangle2D& Range, 125 ::sal_uInt32 MaximumQuadraticPixels) throw (uno::RuntimeException) 126 { 127 uno::Reference< rendering::XBitmap > XBitmap; 128 129 if(Primitive2DSequence.hasElements()) 130 { 131 const basegfx::B2DRange aRange(Range.X1, Range.Y1, Range.X2, Range.Y2); 132 const double fWidth(aRange.getWidth()); 133 const double fHeight(aRange.getHeight()); 134 135 if(basegfx::fTools::more(fWidth, 0.0) && basegfx::fTools::more(fHeight, 0.0)) 136 { 137 if(0 == DPI_X) 138 { 139 DPI_X = 75; 140 } 141 142 if(0 == DPI_Y) 143 { 144 DPI_Y = 75; 145 } 146 147 if(0 == MaximumQuadraticPixels) 148 { 149 MaximumQuadraticPixels = 500000; 150 } 151 152 const geometry::ViewInformation2D aViewInformation2D(aViewInformationSequence); 153 const double fFactor100th_mmToInch(1.0 / (2.54 * 1000.0)); 154 const sal_uInt32 nDiscreteWidth(basegfx::fround((fWidth * fFactor100th_mmToInch) * DPI_X)); 155 const sal_uInt32 nDiscreteHeight(basegfx::fround((fHeight * fFactor100th_mmToInch) * DPI_Y)); 156 157 basegfx::B2DHomMatrix aEmbedding( 158 basegfx::tools::createTranslateB2DHomMatrix( 159 -aRange.getMinX(), 160 -aRange.getMinY())); 161 162 aEmbedding.scale( 163 nDiscreteWidth / fWidth, 164 nDiscreteHeight / fHeight); 165 166 const primitive2d::Primitive2DReference xEmbedRef( 167 new primitive2d::TransformPrimitive2D( 168 aEmbedding, 169 Primitive2DSequence)); 170 const primitive2d::Primitive2DSequence xEmbedSeq(&xEmbedRef, 1); 171 172 BitmapEx aBitmapEx( 173 tools::convertToBitmapEx( 174 xEmbedSeq, 175 aViewInformation2D, 176 nDiscreteWidth, 177 nDiscreteHeight, 178 MaximumQuadraticPixels)); 179 180 if(!aBitmapEx.IsEmpty()) 181 { 182 const uno::Reference< rendering::XGraphicDevice > xGraphicDevice; 183 184 aBitmapEx.SetPrefMapMode(MapMode(MAP_100TH_MM)); 185 aBitmapEx.SetPrefSize(Size(basegfx::fround(fWidth), basegfx::fround(fHeight))); 186 XBitmap = vcl::unotools::xBitmapFromBitmapEx(xGraphicDevice, aBitmapEx); 187 } 188 } 189 } 190 191 return XBitmap; 192 } 193 getImplementationName()194 rtl::OUString SAL_CALL XPrimitive2DRenderer::getImplementationName() throw(uno::RuntimeException) 195 { 196 return(XPrimitive2DRenderer_getImplementationName()); 197 } 198 supportsService(const rtl::OUString & rServiceName)199 sal_Bool SAL_CALL XPrimitive2DRenderer::supportsService(const rtl::OUString& rServiceName) throw(uno::RuntimeException) 200 { 201 const uno::Sequence< rtl::OUString > aServices(XPrimitive2DRenderer_getSupportedServiceNames()); 202 203 for(sal_Int32 nService(0); nService < aServices.getLength(); nService++) 204 { 205 if(rServiceName == aServices[nService]) 206 { 207 return sal_True; 208 } 209 } 210 211 return sal_False; 212 } 213 getSupportedServiceNames()214 uno::Sequence< rtl::OUString > SAL_CALL XPrimitive2DRenderer::getSupportedServiceNames() throw(uno::RuntimeException) 215 { 216 return XPrimitive2DRenderer_getSupportedServiceNames(); 217 } 218 219 } // end of namespace unorenderer 220 } // end of namespace drawinglayer 221 222 ////////////////////////////////////////////////////////////////////////////// 223 // eof 224