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