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