Bump for 3.6-28
[LibreOffice.git] / cppcanvas / source / inc / implrenderer.hxx
bloba91a818d2ede605ada64114b63b1870269bd1f6e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #ifndef _CPPCANVAS_IMPLRENDERER_HXX
30 #define _CPPCANVAS_IMPLRENDERER_HXX
32 #include <sal/types.h>
34 #include <boost/shared_ptr.hpp>
35 #include <cppcanvas/renderer.hxx>
36 #include <cppcanvas/canvas.hxx>
38 #include <canvasgraphichelper.hxx>
39 #include <action.hxx>
41 #include <vector>
43 class GDIMetaFile;
44 class VirtualDevice;
45 class Gradient;
46 class BitmapEx;
47 class MapMode;
48 class Size;
49 class Rectangle;
50 class Font;
51 class PolyPolygon;
52 class Point;
53 class MetaCommentAction;
55 namespace basegfx {
56 class B2DPolyPolygon;
57 class B2DPolygon;
60 namespace cppcanvas
63 namespace internal
65 struct OutDevState;
66 struct ActionFactoryParameters;
67 struct EMFPObject;
68 struct XForm;
70 // state stack of OutputDevice, to correctly handle
71 // push/pop actions
72 class VectorOfOutDevStates
74 public:
75 OutDevState& getState();
76 const OutDevState& getState() const;
77 void pushState(sal_uInt16 nFlags);
78 void popState();
79 void clearStateStack();
80 private:
81 ::std::vector< OutDevState > m_aStates;
84 // EMF+
85 // TODO: replace?
86 struct XForm
88 float eM11;
89 float eM12;
90 float eM21;
91 float eM22;
92 float eDx;
93 float eDy;
94 XForm()
96 SetIdentity ();
99 void SetIdentity ()
101 eM11 = eM22 = 1.0f;
102 eDx = eDy = eM12 = eM21 = 0.0f;
105 void Set (float m11, float m12, float dx, float m21, float m22, float dy)
107 eM11 = m11;
108 eM12 = m12;
109 eDx = dx;
110 eM21 = m21;
111 eM22 = m22;
112 eDy = dy;
115 void Set (XForm f)
117 eM11 = f.eM11;
118 eM12 = f.eM12;
119 eM21 = f.eM21;
120 eM22 = f.eM22;
121 eDx = f.eDx;
122 eDy = f.eDy;
125 void Multiply (float m11, float m12, float dx, float m21, float m22, float dy)
127 eM11 = eM11*m11 + eM12*m21;
128 eM12 = eM11*m12 + eM12*m22;
129 eM21 = eM21*m11 + eM22*m21;
130 eM22 = eM21*m12 + eM22*m22;
131 eDx *= eDx*m11 + eDy*m21 + dx;
132 eDy *= eDx*m12 + eDy*m22 + dy;
135 void Multiply (XForm f)
137 eM11 = eM11*f.eM11 + eM12*f.eM21;
138 eM12 = eM11*f.eM12 + eM12*f.eM22;
139 eM21 = eM21*f.eM11 + eM22*f.eM21;
140 eM22 = eM21*f.eM12 + eM22*f.eM22;
141 eDx *= eDx*f.eM11 + eDy*f.eM21 + f.eDx;
142 eDy *= eDx*f.eM12 + eDy*f.eM22 + f.eDy;
145 #ifdef OSL_BIGENDIAN
146 // currently unused
147 static float GetSwapFloat( SvStream& rSt )
149 float fTmp;
150 sal_Int8* pPtr = (sal_Int8*)&fTmp;
151 rSt >> pPtr[3] >> pPtr[2] >> pPtr[1] >> pPtr[0]; // Little Endian <-> Big Endian switch
152 return fTmp;
154 #endif
156 friend SvStream& operator>>( SvStream& rIn, XForm& rXForm )
158 if ( sizeof( float ) != 4 )
160 OSL_FAIL( "EnhWMFReader::sizeof( float ) != 4" );
161 rXForm = XForm();
163 else
165 #ifdef OSL_BIGENDIAN
166 rXForm.eM11 = GetSwapFloat( rIn );
167 rXForm.eM12 = GetSwapFloat( rIn );
168 rXForm.eM21 = GetSwapFloat( rIn );
169 rXForm.eM22 = GetSwapFloat( rIn );
170 rXForm.eDx = GetSwapFloat( rIn );
171 rXForm.eDy = GetSwapFloat( rIn );
172 #else
173 rIn >> rXForm.eM11 >> rXForm.eM12 >> rXForm.eM21 >> rXForm.eM22
174 >> rXForm.eDx >> rXForm.eDy;
175 #endif
177 return rIn;
181 class ImplRenderer : public virtual Renderer, protected CanvasGraphicHelper
183 public:
184 ImplRenderer( const CanvasSharedPtr& rCanvas,
185 const GDIMetaFile& rMtf,
186 const Parameters& rParms );
188 virtual ~ImplRenderer();
190 virtual bool draw() const;
191 virtual bool drawSubset( sal_Int32 nStartIndex,
192 sal_Int32 nEndIndex ) const;
193 virtual ::basegfx::B2DRange getSubsetArea( sal_Int32 nStartIndex,
194 sal_Int32 nEndIndex ) const;
197 // element of the Renderer's action vector. Need to be
198 // public, since some functors need it, too.
199 struct MtfAction
201 MtfAction( const ActionSharedPtr& rAction,
202 sal_Int32 nOrigIndex ) :
203 mpAction( rAction ),
204 mnOrigIndex( nOrigIndex )
208 ActionSharedPtr mpAction;
209 sal_Int32 mnOrigIndex;
212 // prefetched and prepared canvas actions
213 // (externally not visible)
214 typedef ::std::vector< MtfAction > ActionVector;
216 /* EMF+ */
217 void ReadRectangle (SvStream& s, float& x, float& y, float &width, float& height, sal_uInt32 flags = 0);
218 void ReadPoint (SvStream& s, float& x, float& y, sal_uInt32 flags);
219 void MapToDevice (double &x, double &y);
220 ::basegfx::B2DPoint Map (double ix, double iy);
221 ::basegfx::B2DSize MapSize (double iwidth, double iheight);
223 private:
224 // default: disabled copy/assignment
225 ImplRenderer(const ImplRenderer&);
226 ImplRenderer& operator=( const ImplRenderer& );
228 void updateClipping( const ::basegfx::B2DPolyPolygon& rClipPoly,
229 const ActionFactoryParameters& rParms,
230 bool bIntersect );
232 void updateClipping( const ::Rectangle& rClipRect,
233 const ActionFactoryParameters& rParms,
234 bool bIntersect );
236 ::com::sun::star::uno::Reference<
237 ::com::sun::star::rendering::XCanvasFont > createFont( double& o_rFontRotation,
238 const ::Font& rFont,
239 const ActionFactoryParameters& rParms ) const;
240 bool createActions( GDIMetaFile& rMtf,
241 const ActionFactoryParameters& rParms,
242 bool bSubsettableActions );
243 bool createFillAndStroke( const ::basegfx::B2DPolyPolygon& rPolyPoly,
244 const ActionFactoryParameters& rParms );
245 bool createFillAndStroke( const ::basegfx::B2DPolygon& rPoly,
246 const ActionFactoryParameters& rParms );
247 void skipContent( GDIMetaFile& rMtf,
248 const char* pCommentString,
249 sal_Int32& io_rCurrActionIndex ) const;
251 bool isActionContained( GDIMetaFile& rMtf,
252 const char* pCommentString,
253 sal_uInt16 nType ) const;
255 void createGradientAction( const ::PolyPolygon& rPoly,
256 const ::Gradient& rGradient,
257 const ActionFactoryParameters& rParms,
258 bool bIsPolygonRectangle,
259 bool bSubsettableActions );
261 void createTextAction( const ::Point& rStartPoint,
262 const String rString,
263 int nIndex,
264 int nLength,
265 const sal_Int32* pCharWidths,
266 const ActionFactoryParameters& rParms,
267 bool bSubsettable );
269 bool getSubsetIndices( sal_Int32& io_rStartIndex,
270 sal_Int32& io_rEndIndex,
271 ActionVector::const_iterator& o_rRangeBegin,
272 ActionVector::const_iterator& o_rRangeEnd ) const;
274 void processObjectRecord(SvMemoryStream& rObjectStream, sal_uInt16 flags, sal_Bool bUseWholeStream = sal_False);
276 /* EMF+ */
277 void processEMFPlus( MetaCommentAction* pAct, const ActionFactoryParameters& rFactoryParms, OutDevState& rState, const CanvasSharedPtr& rCanvas );
278 double setFont( sal_uInt8 objectId, const ActionFactoryParameters& rParms, OutDevState& rState );
279 void EMFPPlusFillPolygon (::basegfx::B2DPolyPolygon& polygon, const ActionFactoryParameters& rParms, OutDevState& rState, const CanvasSharedPtr& rCanvas, bool isColor, sal_uInt32 brushIndexOrColor);
281 ActionVector maActions;
283 /* EMF+ */
284 XForm aBaseTransform;
285 XForm aWorldTransform;
286 EMFPObject* aObjects [256];
287 float fPageScale;
288 sal_Int32 nOriginX;
289 sal_Int32 nOriginY;
290 sal_Int32 nHDPI;
291 sal_Int32 nVDPI;
292 ::PolyPolygon aClippingPolygon;
293 /* EMF+ emf header info */
294 sal_Int32 nFrameLeft;
295 sal_Int32 nFrameTop;
296 sal_Int32 nFrameRight;
297 sal_Int32 nFrameBottom;
298 sal_Int32 nPixX;
299 sal_Int32 nPixY;
300 sal_Int32 nMmX;
301 sal_Int32 nMmY;
302 /* multipart object data */
303 bool mbMultipart;
304 sal_uInt16 mMFlags;
305 SvMemoryStream mMStream;
309 /// Common parameters when creating actions
310 struct ActionFactoryParameters
312 ActionFactoryParameters( VectorOfOutDevStates& rStates,
313 const CanvasSharedPtr& rCanvas,
314 ::VirtualDevice& rVDev,
315 const Renderer::Parameters& rParms,
316 sal_Int32& io_rCurrActionIndex ) :
317 mrStates(rStates),
318 mrCanvas(rCanvas),
319 mrVDev(rVDev),
320 mrParms(rParms),
321 mrCurrActionIndex(io_rCurrActionIndex)
324 VectorOfOutDevStates& mrStates;
325 const CanvasSharedPtr& mrCanvas;
326 ::VirtualDevice& mrVDev;
327 const Renderer::Parameters& mrParms;
328 sal_Int32& mrCurrActionIndex;
333 #endif /* _CPPCANVAS_IMPLRENDERER_HXX */
335 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */