1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: implrenderer.hxx,v $
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>
39 #include <cppcanvas/renderer.hxx>
40 #include <cppcanvas/canvas.hxx>
42 #include <canvasgraphichelper.hxx>
57 class MetaCommentAction
;
70 struct ActionFactoryParameters
;
74 // state stack of OutputDevice, to correctly handle
76 typedef ::std::vector
< OutDevState
> VectorOfOutDevStates
;
96 eDx
= eDy
= eM12
= eM21
= 0.0f
;
99 void Set (float m11
, float m12
, float dx
, float m21
, float m22
, float dy
)
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
;
141 static float GetSwapFloat( SvStream
& rSt
)
144 sal_Int8
* pPtr
= (sal_Int8
*)&fTmp
;
145 rSt
>> pPtr
[3] >> pPtr
[2] >> pPtr
[1] >> pPtr
[0]; // Little Endian <-> Big Endian switch
150 friend SvStream
& operator>>( SvStream
& rIn
, XForm
& rXForm
)
152 if ( sizeof( float ) != 4 )
154 DBG_ERROR( "EnhWMFReader::sizeof( float ) != 4" );
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
);
167 rIn
>> rXForm
.eM11
>> rXForm
.eM12
>> rXForm
.eM21
>> rXForm
.eM22
168 >> rXForm
.eDx
>> rXForm
.eDy
;
175 class ImplRenderer
: public virtual Renderer
, protected CanvasGraphicHelper
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.
198 MtfAction( const ActionSharedPtr
& rAction
,
199 sal_Int32 nOrigIndex
) :
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
;
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
);
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
,
231 void updateClipping( const ::Rectangle
& rClipRect
,
232 const ActionFactoryParameters
& rParms
,
235 ::com::sun::star::uno::Reference
<
236 ::com::sun::star::rendering::XCanvasFont
> createFont( double& o_rFontRotation
,
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
,
264 const sal_Int32
* pCharWidths
,
265 const ActionFactoryParameters
& rParms
,
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
;
280 XForm aBaseTransform
;
281 XForm aWorldTransform
;
282 EMFPObject
* aObjects
[256];
288 ::PolyPolygon aClippingPolygon
;
289 /* EMF+ emf header info */
290 sal_Int32 nFrameLeft
;
292 sal_Int32 nFrameRight
;
293 sal_Int32 nFrameBottom
;
298 /* multipart object data */
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
) :
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 */