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>
53 class MetaCommentAction
;
66 struct ActionFactoryParameters
;
70 // state stack of OutputDevice, to correctly handle
72 class VectorOfOutDevStates
75 OutDevState
& getState();
76 const OutDevState
& getState() const;
77 void pushState(sal_uInt16 nFlags
);
79 void clearStateStack();
81 ::std::vector
< OutDevState
> m_aStates
;
102 eDx
= eDy
= eM12
= eM21
= 0.0f
;
105 void Set (float m11
, float m12
, float dx
, float m21
, float m22
, float dy
)
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
;
147 static float GetSwapFloat( SvStream
& rSt
)
150 sal_Int8
* pPtr
= (sal_Int8
*)&fTmp
;
151 rSt
>> pPtr
[3] >> pPtr
[2] >> pPtr
[1] >> pPtr
[0]; // Little Endian <-> Big Endian switch
156 friend SvStream
& operator>>( SvStream
& rIn
, XForm
& rXForm
)
158 if ( sizeof( float ) != 4 )
160 OSL_FAIL( "EnhWMFReader::sizeof( float ) != 4" );
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
);
173 rIn
>> rXForm
.eM11
>> rXForm
.eM12
>> rXForm
.eM21
>> rXForm
.eM22
174 >> rXForm
.eDx
>> rXForm
.eDy
;
181 class ImplRenderer
: public virtual Renderer
, protected CanvasGraphicHelper
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.
201 MtfAction( const ActionSharedPtr
& rAction
,
202 sal_Int32 nOrigIndex
) :
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
;
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
);
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
,
232 void updateClipping( const ::Rectangle
& rClipRect
,
233 const ActionFactoryParameters
& rParms
,
236 ::com::sun::star::uno::Reference
<
237 ::com::sun::star::rendering::XCanvasFont
> createFont( double& o_rFontRotation
,
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
,
265 const sal_Int32
* pCharWidths
,
266 const ActionFactoryParameters
& rParms
,
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
);
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
;
284 XForm aBaseTransform
;
285 XForm aWorldTransform
;
286 EMFPObject
* aObjects
[256];
292 ::PolyPolygon aClippingPolygon
;
293 /* EMF+ emf header info */
294 sal_Int32 nFrameLeft
;
296 sal_Int32 nFrameRight
;
297 sal_Int32 nFrameBottom
;
302 /* multipart object data */
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
) :
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: */