1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _CPPCANVAS_IMPLRENDERER_HXX 29 #define _CPPCANVAS_IMPLRENDERER_HXX 30 31 #include <sal/types.h> 32 33 #ifndef BOOST_SHARED_PTR_HPP_INCLUDED 34 #include <boost/shared_ptr.hpp> 35 #endif 36 #include <cppcanvas/renderer.hxx> 37 #include <cppcanvas/canvas.hxx> 38 39 #include <canvasgraphichelper.hxx> 40 #include <action.hxx> 41 42 #include <vector> 43 44 class GDIMetaFile; 45 class VirtualDevice; 46 class Gradient; 47 class BitmapEx; 48 class MapMode; 49 class Size; 50 51 namespace basegfx { 52 class B2DPolyPolygon; 53 class B2DPolygon; 54 } 55 56 namespace cppcanvas 57 { 58 59 namespace internal 60 { 61 struct OutDevState; 62 struct ActionFactoryParameters; 63 64 // state stack of OutputDevice, to correctly handle 65 // push/pop actions 66 typedef ::std::vector< OutDevState > VectorOfOutDevStates; 67 68 class ImplRenderer : public virtual Renderer, protected CanvasGraphicHelper 69 { 70 public: 71 ImplRenderer( const CanvasSharedPtr& rCanvas, 72 const GDIMetaFile& rMtf, 73 const Parameters& rParms ); 74 ImplRenderer( const CanvasSharedPtr& rCanvas, 75 const BitmapEx& rBmpEx, 76 const Parameters& rParms ); 77 78 virtual ~ImplRenderer(); 79 80 virtual bool draw() const; 81 virtual bool drawSubset( sal_Int32 nStartIndex, 82 sal_Int32 nEndIndex ) const; 83 virtual ::basegfx::B2DRange getSubsetArea( sal_Int32 nStartIndex, 84 sal_Int32 nEndIndex ) const; 85 86 87 // element of the Renderer's action vector. Need to be 88 // public, since some functors need it, too. 89 struct MtfAction 90 { 91 MtfAction( const ActionSharedPtr& rAction, 92 sal_Int32 nOrigIndex ) : 93 mpAction( rAction ), 94 mnOrigIndex( nOrigIndex ) 95 { 96 } 97 98 ActionSharedPtr mpAction; 99 sal_Int32 mnOrigIndex; 100 }; 101 102 // prefetched and prepared canvas actions 103 // (externally not visible) 104 typedef ::std::vector< MtfAction > ActionVector; 105 106 107 private: 108 // default: disabled copy/assignment 109 ImplRenderer(const ImplRenderer&); 110 ImplRenderer& operator=( const ImplRenderer& ); 111 112 void updateClipping( const ::basegfx::B2DPolyPolygon& rClipPoly, 113 const ActionFactoryParameters& rParms, 114 bool bIntersect ); 115 116 void updateClipping( const ::Rectangle& rClipRect, 117 const ActionFactoryParameters& rParms, 118 bool bIntersect ); 119 120 ::com::sun::star::uno::Reference< 121 ::com::sun::star::rendering::XCanvasFont > createFont( double& o_rFontRotation, 122 const ::Font& rFont, 123 const ActionFactoryParameters& rParms ) const; 124 bool createActions( GDIMetaFile& rMtf, 125 const ActionFactoryParameters& rParms, 126 bool bSubsettableActions ); 127 bool createFillAndStroke( const ::basegfx::B2DPolyPolygon& rPolyPoly, 128 const ActionFactoryParameters& rParms ); 129 bool createFillAndStroke( const ::basegfx::B2DPolygon& rPoly, 130 const ActionFactoryParameters& rParms ); 131 void skipContent( GDIMetaFile& rMtf, 132 const char* pCommentString, 133 sal_Int32& io_rCurrActionIndex ) const; 134 135 bool isActionContained( GDIMetaFile& rMtf, 136 const char* pCommentString, 137 sal_uInt16 nType ) const; 138 139 void createGradientAction( const ::PolyPolygon& rPoly, 140 const ::Gradient& rGradient, 141 const ActionFactoryParameters& rParms, 142 bool bIsPolygonRectangle, 143 bool bSubsettableActions ); 144 145 void createTextAction( const ::Point& rStartPoint, 146 const String rString, 147 int nIndex, 148 int nLength, 149 const sal_Int32* pCharWidths, 150 const ActionFactoryParameters& rParms, 151 bool bSubsettable ); 152 153 bool getSubsetIndices( sal_Int32& io_rStartIndex, 154 sal_Int32& io_rEndIndex, 155 ActionVector::const_iterator& o_rRangeBegin, 156 ActionVector::const_iterator& o_rRangeEnd ) const; 157 158 159 ActionVector maActions; 160 }; 161 162 163 /// Common parameters when creating actions 164 struct ActionFactoryParameters 165 { 166 ActionFactoryParameters( VectorOfOutDevStates& rStates, 167 const CanvasSharedPtr& rCanvas, 168 ::VirtualDevice& rVDev, 169 const Renderer::Parameters& rParms, 170 sal_Int32& io_rCurrActionIndex ) : 171 mrStates(rStates), 172 mrCanvas(rCanvas), 173 mrVDev(rVDev), 174 mrParms(rParms), 175 mrCurrActionIndex(io_rCurrActionIndex) 176 {} 177 178 VectorOfOutDevStates& mrStates; 179 const CanvasSharedPtr& mrCanvas; 180 ::VirtualDevice& mrVDev; 181 const Renderer::Parameters& mrParms; 182 sal_Int32& mrCurrActionIndex; 183 }; 184 } 185 } 186 187 #endif /* _CPPCANVAS_IMPLRENDERER_HXX */ 188