1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef _CPPCANVAS_IMPLRENDERER_HXX
21 #define _CPPCANVAS_IMPLRENDERER_HXX
23 #include <sal/types.h>
25 #include <boost/shared_ptr.hpp>
26 #include <cppcanvas/renderer.hxx>
27 #include <cppcanvas/canvas.hxx>
29 #include <canvasgraphichelper.hxx>
31 #include <outdevstate.hxx>
43 class MetaCommentAction
;
56 struct ActionFactoryParameters
;
61 virtual ~EMFPObject() {}
64 // state stack of OutputDevice, to correctly handle
66 class VectorOfOutDevStates
69 OutDevState
& getState();
70 const OutDevState
& getState() const;
71 void pushState(sal_uInt16 nFlags
);
73 void clearStateStack();
75 ::std::vector
< OutDevState
> m_aStates
;
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 OSL_FAIL( "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
;
177 XForm aWorldTransform
;
178 OutDevState aDevState
;
179 } EmfPlusGraphicState
;
181 typedef ::std::map
<int,EmfPlusGraphicState
> GraphicStateMap
;
183 class ImplRenderer
: public virtual Renderer
, protected CanvasGraphicHelper
186 ImplRenderer( const CanvasSharedPtr
& rCanvas
,
187 const GDIMetaFile
& rMtf
,
188 const Parameters
& rParms
);
190 virtual ~ImplRenderer();
192 virtual bool draw() const;
193 virtual bool drawSubset( sal_Int32 nStartIndex
,
194 sal_Int32 nEndIndex
) const;
195 virtual ::basegfx::B2DRange
getSubsetArea( sal_Int32 nStartIndex
,
196 sal_Int32 nEndIndex
) const;
199 // element of the Renderer's action vector. Need to be
200 // public, since some functors need it, too.
203 MtfAction( const ActionSharedPtr
& rAction
,
204 sal_Int32 nOrigIndex
) :
206 mnOrigIndex( nOrigIndex
)
210 ActionSharedPtr mpAction
;
211 sal_Int32 mnOrigIndex
;
214 // prefetched and prepared canvas actions
215 // (externally not visible)
216 typedef ::std::vector
< MtfAction
> ActionVector
;
219 void ReadRectangle (SvStream
& s
, float& x
, float& y
, float &width
, float& height
, bool bCompressed
= false);
220 void ReadPoint (SvStream
& s
, float& x
, float& y
, sal_uInt32 flags
);
221 void MapToDevice (double &x
, double &y
);
222 ::basegfx::B2DPoint
Map (double ix
, double iy
);
223 ::basegfx::B2DSize
MapSize (double iwidth
, double iheight
);
224 void GraphicStatePush (GraphicStateMap
& map
, sal_Int32 index
, OutDevState
& rState
);
225 void GraphicStatePop (GraphicStateMap
& map
, sal_Int32 index
, OutDevState
& rState
);
228 // default: disabled copy/assignment
229 ImplRenderer(const ImplRenderer
&);
230 ImplRenderer
& operator=( const ImplRenderer
& );
232 void updateClipping( const ::basegfx::B2DPolyPolygon
& rClipPoly
,
233 const ActionFactoryParameters
& rParms
,
236 void updateClipping( const ::Rectangle
& rClipRect
,
237 const ActionFactoryParameters
& rParms
,
240 ::com::sun::star::uno::Reference
<
241 ::com::sun::star::rendering::XCanvasFont
> createFont( double& o_rFontRotation
,
243 const ActionFactoryParameters
& rParms
) const;
244 bool createActions( GDIMetaFile
& rMtf
,
245 const ActionFactoryParameters
& rParms
,
246 bool bSubsettableActions
);
247 bool createFillAndStroke( const ::basegfx::B2DPolyPolygon
& rPolyPoly
,
248 const ActionFactoryParameters
& rParms
);
249 bool createFillAndStroke( const ::basegfx::B2DPolygon
& rPoly
,
250 const ActionFactoryParameters
& rParms
);
251 void skipContent( GDIMetaFile
& rMtf
,
252 const char* pCommentString
,
253 sal_Int32
& io_rCurrActionIndex
) const;
255 bool isActionContained( GDIMetaFile
& rMtf
,
256 const char* pCommentString
,
257 sal_uInt16 nType
) const;
259 void createGradientAction( const ::PolyPolygon
& rPoly
,
260 const ::Gradient
& rGradient
,
261 const ActionFactoryParameters
& rParms
,
262 bool bIsPolygonRectangle
,
263 bool bSubsettableActions
);
265 void createTextAction( const ::Point
& rStartPoint
,
266 const OUString rString
,
269 const sal_Int32
* pCharWidths
,
270 const ActionFactoryParameters
& rParms
,
273 bool getSubsetIndices( sal_Int32
& io_rStartIndex
,
274 sal_Int32
& io_rEndIndex
,
275 ActionVector::const_iterator
& o_rRangeBegin
,
276 ActionVector::const_iterator
& o_rRangeEnd
) const;
278 void processObjectRecord(SvMemoryStream
& rObjectStream
, sal_uInt16 flags
, sal_uInt32 dataSize
, sal_Bool bUseWholeStream
= sal_False
);
281 void processEMFPlus( MetaCommentAction
* pAct
, const ActionFactoryParameters
& rFactoryParms
, OutDevState
& rState
, const CanvasSharedPtr
& rCanvas
);
282 double setFont( sal_uInt8 objectId
, const ActionFactoryParameters
& rParms
, OutDevState
& rState
);
284 /// Render LineCap, like the start or end arrow of a polygon.
285 /// @return how much we should shorten the original polygon.
286 double EMFPPlusDrawLineCap(const ::basegfx::B2DPolygon
& rPolygon
, double fPolyLength
,
287 const ::basegfx::B2DPolyPolygon
& rLineCap
, bool isFilled
, bool bStart
,
288 const com::sun::star::rendering::StrokeAttributes
& rAttributes
,
289 const ActionFactoryParameters
& rParms
, OutDevState
& rState
);
291 void EMFPPlusDrawPolygon (const ::basegfx::B2DPolyPolygon
& polygon
, const ActionFactoryParameters
& rParms
, OutDevState
& rState
, const CanvasSharedPtr
& rCanvas
, sal_uInt32 penIndex
);
292 void EMFPPlusFillPolygon (::basegfx::B2DPolyPolygon
& polygon
, const ActionFactoryParameters
& rParms
, OutDevState
& rState
, const CanvasSharedPtr
& rCanvas
, bool isColor
, sal_uInt32 brushIndexOrColor
);
294 ActionVector maActions
;
297 XForm aBaseTransform
;
298 XForm aWorldTransform
;
299 EMFPObject
* aObjects
[256];
305 /* EMF+ emf header info */
306 sal_Int32 nFrameLeft
;
308 sal_Int32 nFrameRight
;
309 sal_Int32 nFrameBottom
;
314 /* multipart object data */
317 SvMemoryStream mMStream
;
318 /* emf+ graphic state stack */
319 GraphicStateMap mGSStack
;
320 GraphicStateMap mGSContainerStack
;
324 /// Common parameters when creating actions
325 struct ActionFactoryParameters
327 ActionFactoryParameters( VectorOfOutDevStates
& rStates
,
328 const CanvasSharedPtr
& rCanvas
,
329 ::VirtualDevice
& rVDev
,
330 const Renderer::Parameters
& rParms
,
331 sal_Int32
& io_rCurrActionIndex
) :
336 mrCurrActionIndex(io_rCurrActionIndex
)
339 VectorOfOutDevStates
& mrStates
;
340 const CanvasSharedPtr
& mrCanvas
;
341 ::VirtualDevice
& mrVDev
;
342 const Renderer::Parameters
& mrParms
;
343 sal_Int32
& mrCurrActionIndex
;
348 #endif /* _CPPCANVAS_IMPLRENDERER_HXX */
350 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */