merge the formfield patch from ooo-build
[ooovba.git] / cppcanvas / source / inc / implrenderer.hxx
blobd18e4ce31e1f97a75fa54064cf6069fb9bf0020d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: implrenderer.hxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _CPPCANVAS_IMPLRENDERER_HXX
32 #define _CPPCANVAS_IMPLRENDERER_HXX
34 #include <sal/types.h>
36 #ifndef BOOST_SHARED_PTR_HPP_INCLUDED
37 #include <boost/shared_ptr.hpp>
38 #endif
39 #include <cppcanvas/renderer.hxx>
40 #include <cppcanvas/canvas.hxx>
42 #include <canvasgraphichelper.hxx>
43 #include <action.hxx>
45 #include <vector>
47 class GDIMetaFile;
48 class VirtualDevice;
49 class Gradient;
50 class BitmapEx;
51 class MapMode;
52 class Size;
53 class Rectangle;
54 class Font;
55 class PolyPolygon;
56 class Point;
57 class MetaCommentAction;
59 namespace basegfx {
60 class B2DPolyPolygon;
61 class B2DPolygon;
64 namespace cppcanvas
67 namespace internal
69 struct OutDevState;
70 struct ActionFactoryParameters;
71 struct EMFPObject;
72 struct XForm;
74 // state stack of OutputDevice, to correctly handle
75 // push/pop actions
76 typedef ::std::vector< OutDevState > VectorOfOutDevStates;
78 // EMF+
79 // TODO: replace?
80 struct XForm
82 float eM11;
83 float eM12;
84 float eM21;
85 float eM22;
86 float eDx;
87 float eDy;
88 XForm()
90 SetIdentity ();
93 void SetIdentity ()
95 eM11 = eM22 = 1.0f;
96 eDx = eDy = eM12 = eM21 = 0.0f;
99 void Set (float m11, float m12, float dx, float m21, float m22, float dy)
101 eM11 = m11;
102 eM12 = m12;
103 eDx = dx;
104 eM21 = m21;
105 eM22 = m22;
106 eDy = dy;
109 void Set (XForm f)
111 eM11 = f.eM11;
112 eM12 = f.eM12;
113 eM21 = f.eM21;
114 eM22 = f.eM22;
115 eDx = f.eDx;
116 eDy = f.eDy;
119 void Multiply (float m11, float m12, float dx, float m21, float m22, float dy)
121 eM11 = eM11*m11 + eM12*m21;
122 eM12 = eM11*m12 + eM12*m22;
123 eM21 = eM21*m11 + eM22*m21;
124 eM22 = eM21*m12 + eM22*m22;
125 eDx *= eDx*m11 + eDy*m21 + dx;
126 eDy *= eDx*m12 + eDy*m22 + dy;
129 void Multiply (XForm f)
131 eM11 = eM11*f.eM11 + eM12*f.eM21;
132 eM12 = eM11*f.eM12 + eM12*f.eM22;
133 eM21 = eM21*f.eM11 + eM22*f.eM21;
134 eM22 = eM21*f.eM12 + eM22*f.eM22;
135 eDx *= eDx*f.eM11 + eDy*f.eM21 + f.eDx;
136 eDy *= eDx*f.eM12 + eDy*f.eM22 + f.eDy;
139 #ifdef OSL_BIGENDIAN
140 // currently unused
141 static float GetSwapFloat( SvStream& rSt )
143 float fTmp;
144 sal_Int8* pPtr = (sal_Int8*)&fTmp;
145 rSt >> pPtr[3] >> pPtr[2] >> pPtr[1] >> pPtr[0]; // Little Endian <-> Big Endian switch
146 return fTmp;
148 #endif
150 friend SvStream& operator>>( SvStream& rIn, XForm& rXForm )
152 if ( sizeof( float ) != 4 )
154 DBG_ERROR( "EnhWMFReader::sizeof( float ) != 4" );
155 rXForm = XForm();
157 else
159 #ifdef OSL_BIGENDIAN
160 rXForm.eM11 = GetSwapFloat( rIn );
161 rXForm.eM12 = GetSwapFloat( rIn );
162 rXForm.eM21 = GetSwapFloat( rIn );
163 rXForm.eM22 = GetSwapFloat( rIn );
164 rXForm.eDx = GetSwapFloat( rIn );
165 rXForm.eDy = GetSwapFloat( rIn );
166 #else
167 rIn >> rXForm.eM11 >> rXForm.eM12 >> rXForm.eM21 >> rXForm.eM22
168 >> rXForm.eDx >> rXForm.eDy;
169 #endif
171 return rIn;
175 class ImplRenderer : public virtual Renderer, protected CanvasGraphicHelper
177 public:
178 ImplRenderer( const CanvasSharedPtr& rCanvas,
179 const GDIMetaFile& rMtf,
180 const Parameters& rParms );
181 ImplRenderer( const CanvasSharedPtr& rCanvas,
182 const BitmapEx& rBmpEx,
183 const Parameters& rParms );
185 virtual ~ImplRenderer();
187 virtual bool draw() const;
188 virtual bool drawSubset( sal_Int32 nStartIndex,
189 sal_Int32 nEndIndex ) const;
190 virtual ::basegfx::B2DRange getSubsetArea( sal_Int32 nStartIndex,
191 sal_Int32 nEndIndex ) const;
194 // element of the Renderer's action vector. Need to be
195 // public, since some functors need it, too.
196 struct MtfAction
198 MtfAction( const ActionSharedPtr& rAction,
199 sal_Int32 nOrigIndex ) :
200 mpAction( rAction ),
201 mnOrigIndex( nOrigIndex )
205 ActionSharedPtr mpAction;
206 sal_Int32 mnOrigIndex;
209 // prefetched and prepared canvas actions
210 // (externally not visible)
211 typedef ::std::vector< MtfAction > ActionVector;
213 /* EMF+ */
214 void ReadRectangle (SvStream& s, float& x, float& y, float &width, float& height, sal_uInt32 flags = 0);
215 void ReadPoint (SvStream& s, float& x, float& y, sal_uInt32 flags = 0);
216 void MapToDevice (double &x, double &y);
217 ::basegfx::B2DPoint Map (::basegfx::B2DPoint& p);
218 ::basegfx::B2DPoint Map (double ix, double iy);
219 ::basegfx::B2DSize MapSize (double iwidth, double iheight);
220 ::basegfx::B2DRange MapRectangle (double ix, double iy, double iwidth, double iheight);
222 private:
223 // default: disabled copy/assignment
224 ImplRenderer(const ImplRenderer&);
225 ImplRenderer& operator=( const ImplRenderer& );
227 void updateClipping( const ::basegfx::B2DPolyPolygon& rClipPoly,
228 const ActionFactoryParameters& rParms,
229 bool bIntersect );
231 void updateClipping( const ::Rectangle& rClipRect,
232 const ActionFactoryParameters& rParms,
233 bool bIntersect );
235 ::com::sun::star::uno::Reference<
236 ::com::sun::star::rendering::XCanvasFont > createFont( double& o_rFontRotation,
237 const ::Font& rFont,
238 const ActionFactoryParameters& rParms ) const;
239 bool createActions( GDIMetaFile& rMtf,
240 const ActionFactoryParameters& rParms,
241 bool bSubsettableActions );
242 bool createFillAndStroke( const ::basegfx::B2DPolyPolygon& rPolyPoly,
243 const ActionFactoryParameters& rParms );
244 bool createFillAndStroke( const ::basegfx::B2DPolygon& rPoly,
245 const ActionFactoryParameters& rParms );
246 void skipContent( GDIMetaFile& rMtf,
247 const char* pCommentString,
248 sal_Int32& io_rCurrActionIndex ) const;
250 bool isActionContained( GDIMetaFile& rMtf,
251 const char* pCommentString,
252 USHORT nType ) const;
254 void createGradientAction( const ::PolyPolygon& rPoly,
255 const ::Gradient& rGradient,
256 const ActionFactoryParameters& rParms,
257 bool bIsPolygonRectangle,
258 bool bSubsettableActions );
260 void createTextAction( const ::Point& rStartPoint,
261 const String rString,
262 int nIndex,
263 int nLength,
264 const sal_Int32* pCharWidths,
265 const ActionFactoryParameters& rParms,
266 bool bSubsettable );
268 bool getSubsetIndices( sal_Int32& io_rStartIndex,
269 sal_Int32& io_rEndIndex,
270 ActionVector::const_iterator& o_rRangeBegin,
271 ActionVector::const_iterator& o_rRangeEnd ) const;
273 void processObjectRecord(SvMemoryStream& rObjectStream, UINT16 flags);
274 void processEMFPlus( MetaCommentAction* pAct, const ActionFactoryParameters& rFactoryParms, OutDevState& rState, const CanvasSharedPtr& rCanvas );
275 void EMFPPlusFillPolygon (::basegfx::B2DPolyPolygon& polygon, const ActionFactoryParameters& rParms, OutDevState& rState, const CanvasSharedPtr& rCanvas, bool isColor, sal_uInt32 brushIndexOrColor);
277 ActionVector maActions;
279 /* EMF+ */
280 XForm aBaseTransform;
281 XForm aWorldTransform;
282 EMFPObject* aObjects [256];
283 float fPageScale;
284 sal_Int32 nOriginX;
285 sal_Int32 nOriginY;
286 sal_Int32 nHDPI;
287 sal_Int32 nVDPI;
288 ::PolyPolygon aClippingPolygon;
289 /* EMF+ emf header info */
290 sal_Int32 nFrameLeft;
291 sal_Int32 nFrameTop;
292 sal_Int32 nFrameRight;
293 sal_Int32 nFrameBottom;
294 sal_Int32 nPixX;
295 sal_Int32 nPixY;
296 sal_Int32 nMmX;
297 sal_Int32 nMmY;
298 /* multipart object data */
299 bool mbMultipart;
300 UINT16 mMFlags;
301 SvMemoryStream mMStream;
305 /// Common parameters when creating actions
306 struct ActionFactoryParameters
308 ActionFactoryParameters( VectorOfOutDevStates& rStates,
309 const CanvasSharedPtr& rCanvas,
310 ::VirtualDevice& rVDev,
311 const Renderer::Parameters& rParms,
312 sal_Int32& io_rCurrActionIndex ) :
313 mrStates(rStates),
314 mrCanvas(rCanvas),
315 mrVDev(rVDev),
316 mrParms(rParms),
317 mrCurrActionIndex(io_rCurrActionIndex)
320 VectorOfOutDevStates& mrStates;
321 const CanvasSharedPtr& mrCanvas;
322 ::VirtualDevice& mrVDev;
323 const Renderer::Parameters& mrParms;
324 sal_Int32& mrCurrActionIndex;
329 #endif /* _CPPCANVAS_IMPLRENDERER_HXX */