Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
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.
15 : : *
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).
21 : : *
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.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _CPPCANVAS_IMPLRENDERER_HXX
30 : : #define _CPPCANVAS_IMPLRENDERER_HXX
31 : :
32 : : #include <sal/types.h>
33 : :
34 : : #include <boost/shared_ptr.hpp>
35 : : #include <cppcanvas/renderer.hxx>
36 : : #include <cppcanvas/canvas.hxx>
37 : :
38 : : #include <canvasgraphichelper.hxx>
39 : : #include <action.hxx>
40 : :
41 : : #include <vector>
42 : :
43 : : class GDIMetaFile;
44 : : class VirtualDevice;
45 : : class Gradient;
46 : : class Rectangle;
47 : : class Font;
48 : : class PolyPolygon;
49 : : class Point;
50 : : class MetaCommentAction;
51 : :
52 : : namespace basegfx {
53 : : class B2DPolyPolygon;
54 : : class B2DPolygon;
55 : : }
56 : :
57 : : namespace cppcanvas
58 : : {
59 : :
60 : : namespace internal
61 : : {
62 : : struct OutDevState;
63 : : struct ActionFactoryParameters;
64 : : struct EMFPObject;
65 : : struct XForm;
66 : :
67 : : // state stack of OutputDevice, to correctly handle
68 : : // push/pop actions
69 : 0 : class VectorOfOutDevStates
70 : : {
71 : : public:
72 : : OutDevState& getState();
73 : : const OutDevState& getState() const;
74 : : void pushState(sal_uInt16 nFlags);
75 : : void popState();
76 : : void clearStateStack();
77 : : private:
78 : : ::std::vector< OutDevState > m_aStates;
79 : : };
80 : :
81 : : // EMF+
82 : : // TODO: replace?
83 : : struct XForm
84 : : {
85 : : float eM11;
86 : : float eM12;
87 : : float eM21;
88 : : float eM22;
89 : : float eDx;
90 : : float eDy;
91 : 0 : XForm()
92 : : {
93 : 0 : SetIdentity ();
94 : 0 : };
95 : :
96 : 0 : void SetIdentity ()
97 : : {
98 : 0 : eM11 = eM22 = 1.0f;
99 : 0 : eDx = eDy = eM12 = eM21 = 0.0f;
100 : 0 : }
101 : :
102 : : void Set (float m11, float m12, float dx, float m21, float m22, float dy)
103 : : {
104 : : eM11 = m11;
105 : : eM12 = m12;
106 : : eDx = dx;
107 : : eM21 = m21;
108 : : eM22 = m22;
109 : : eDy = dy;
110 : : }
111 : :
112 : 0 : void Set (XForm f)
113 : : {
114 : 0 : eM11 = f.eM11;
115 : 0 : eM12 = f.eM12;
116 : 0 : eM21 = f.eM21;
117 : 0 : eM22 = f.eM22;
118 : 0 : eDx = f.eDx;
119 : 0 : eDy = f.eDy;
120 : 0 : }
121 : :
122 : : void Multiply (float m11, float m12, float dx, float m21, float m22, float dy)
123 : : {
124 : : eM11 = eM11*m11 + eM12*m21;
125 : : eM12 = eM11*m12 + eM12*m22;
126 : : eM21 = eM21*m11 + eM22*m21;
127 : : eM22 = eM21*m12 + eM22*m22;
128 : : eDx *= eDx*m11 + eDy*m21 + dx;
129 : : eDy *= eDx*m12 + eDy*m22 + dy;
130 : : }
131 : :
132 : 0 : void Multiply (XForm f)
133 : : {
134 : 0 : eM11 = eM11*f.eM11 + eM12*f.eM21;
135 : 0 : eM12 = eM11*f.eM12 + eM12*f.eM22;
136 : 0 : eM21 = eM21*f.eM11 + eM22*f.eM21;
137 : 0 : eM22 = eM21*f.eM12 + eM22*f.eM22;
138 : 0 : eDx *= eDx*f.eM11 + eDy*f.eM21 + f.eDx;
139 : 0 : eDy *= eDx*f.eM12 + eDy*f.eM22 + f.eDy;
140 : 0 : }
141 : :
142 : : #ifdef OSL_BIGENDIAN
143 : : // currently unused
144 : : static float GetSwapFloat( SvStream& rSt )
145 : : {
146 : : float fTmp;
147 : : sal_Int8* pPtr = (sal_Int8*)&fTmp;
148 : : rSt >> pPtr[3] >> pPtr[2] >> pPtr[1] >> pPtr[0]; // Little Endian <-> Big Endian switch
149 : : return fTmp;
150 : : }
151 : : #endif
152 : :
153 : 0 : friend SvStream& operator>>( SvStream& rIn, XForm& rXForm )
154 : : {
155 : : if ( sizeof( float ) != 4 )
156 : : {
157 : : OSL_FAIL( "EnhWMFReader::sizeof( float ) != 4" );
158 : : rXForm = XForm();
159 : : }
160 : : else
161 : : {
162 : : #ifdef OSL_BIGENDIAN
163 : : rXForm.eM11 = GetSwapFloat( rIn );
164 : : rXForm.eM12 = GetSwapFloat( rIn );
165 : : rXForm.eM21 = GetSwapFloat( rIn );
166 : : rXForm.eM22 = GetSwapFloat( rIn );
167 : : rXForm.eDx = GetSwapFloat( rIn );
168 : : rXForm.eDy = GetSwapFloat( rIn );
169 : : #else
170 : 0 : rIn >> rXForm.eM11 >> rXForm.eM12 >> rXForm.eM21 >> rXForm.eM22
171 : 0 : >> rXForm.eDx >> rXForm.eDy;
172 : : #endif
173 : : }
174 : 0 : return rIn;
175 : : }
176 : : };
177 : :
178 : : class ImplRenderer : public virtual Renderer, protected CanvasGraphicHelper
179 : : {
180 : : public:
181 : : ImplRenderer( const CanvasSharedPtr& rCanvas,
182 : : const GDIMetaFile& rMtf,
183 : : const Parameters& rParms );
184 : :
185 : : virtual ~ImplRenderer();
186 : :
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;
192 : :
193 : :
194 : : // element of the Renderer's action vector. Need to be
195 : : // public, since some functors need it, too.
196 : 0 : struct MtfAction
197 : : {
198 : 0 : MtfAction( const ActionSharedPtr& rAction,
199 : : sal_Int32 nOrigIndex ) :
200 : : mpAction( rAction ),
201 : 0 : mnOrigIndex( nOrigIndex )
202 : : {
203 : 0 : }
204 : :
205 : : ActionSharedPtr mpAction;
206 : : sal_Int32 mnOrigIndex;
207 : : };
208 : :
209 : : // prefetched and prepared canvas actions
210 : : // (externally not visible)
211 : : typedef ::std::vector< MtfAction > ActionVector;
212 : :
213 : : /* EMF+ */
214 : : void ReadRectangle (SvStream& s, float& x, float& y, float &width, float& height, bool bCompressed = false);
215 : : void ReadPoint (SvStream& s, float& x, float& y, sal_uInt32 flags);
216 : : void MapToDevice (double &x, double &y);
217 : : ::basegfx::B2DPoint Map (double ix, double iy);
218 : : ::basegfx::B2DSize MapSize (double iwidth, double iheight);
219 : :
220 : : private:
221 : : // default: disabled copy/assignment
222 : : ImplRenderer(const ImplRenderer&);
223 : : ImplRenderer& operator=( const ImplRenderer& );
224 : :
225 : : void updateClipping( const ::basegfx::B2DPolyPolygon& rClipPoly,
226 : : const ActionFactoryParameters& rParms,
227 : : bool bIntersect );
228 : :
229 : : void updateClipping( const ::Rectangle& rClipRect,
230 : : const ActionFactoryParameters& rParms,
231 : : bool bIntersect );
232 : :
233 : : ::com::sun::star::uno::Reference<
234 : : ::com::sun::star::rendering::XCanvasFont > createFont( double& o_rFontRotation,
235 : : const ::Font& rFont,
236 : : const ActionFactoryParameters& rParms ) const;
237 : : bool createActions( GDIMetaFile& rMtf,
238 : : const ActionFactoryParameters& rParms,
239 : : bool bSubsettableActions );
240 : : bool createFillAndStroke( const ::basegfx::B2DPolyPolygon& rPolyPoly,
241 : : const ActionFactoryParameters& rParms );
242 : : bool createFillAndStroke( const ::basegfx::B2DPolygon& rPoly,
243 : : const ActionFactoryParameters& rParms );
244 : : void skipContent( GDIMetaFile& rMtf,
245 : : const char* pCommentString,
246 : : sal_Int32& io_rCurrActionIndex ) const;
247 : :
248 : : bool isActionContained( GDIMetaFile& rMtf,
249 : : const char* pCommentString,
250 : : sal_uInt16 nType ) const;
251 : :
252 : : void createGradientAction( const ::PolyPolygon& rPoly,
253 : : const ::Gradient& rGradient,
254 : : const ActionFactoryParameters& rParms,
255 : : bool bIsPolygonRectangle,
256 : : bool bSubsettableActions );
257 : :
258 : : void createTextAction( const ::Point& rStartPoint,
259 : : const String rString,
260 : : int nIndex,
261 : : int nLength,
262 : : const sal_Int32* pCharWidths,
263 : : const ActionFactoryParameters& rParms,
264 : : bool bSubsettable );
265 : :
266 : : bool getSubsetIndices( sal_Int32& io_rStartIndex,
267 : : sal_Int32& io_rEndIndex,
268 : : ActionVector::const_iterator& o_rRangeBegin,
269 : : ActionVector::const_iterator& o_rRangeEnd ) const;
270 : :
271 : : void processObjectRecord(SvMemoryStream& rObjectStream, sal_uInt16 flags, sal_Bool bUseWholeStream = sal_False);
272 : :
273 : : /* EMF+ */
274 : : void processEMFPlus( MetaCommentAction* pAct, const ActionFactoryParameters& rFactoryParms, OutDevState& rState, const CanvasSharedPtr& rCanvas );
275 : : double setFont( sal_uInt8 objectId, const ActionFactoryParameters& rParms, OutDevState& rState );
276 : : void EMFPPlusFillPolygon (::basegfx::B2DPolyPolygon& polygon, const ActionFactoryParameters& rParms, OutDevState& rState, const CanvasSharedPtr& rCanvas, bool isColor, sal_uInt32 brushIndexOrColor);
277 : :
278 : : ActionVector maActions;
279 : :
280 : : /* EMF+ */
281 : : XForm aBaseTransform;
282 : : XForm aWorldTransform;
283 : : EMFPObject* aObjects [256];
284 : : float fPageScale;
285 : : sal_Int32 nOriginX;
286 : : sal_Int32 nOriginY;
287 : : sal_Int32 nHDPI;
288 : : sal_Int32 nVDPI;
289 : : ::PolyPolygon aClippingPolygon;
290 : : /* EMF+ emf header info */
291 : : sal_Int32 nFrameLeft;
292 : : sal_Int32 nFrameTop;
293 : : sal_Int32 nFrameRight;
294 : : sal_Int32 nFrameBottom;
295 : : sal_Int32 nPixX;
296 : : sal_Int32 nPixY;
297 : : sal_Int32 nMmX;
298 : : sal_Int32 nMmY;
299 : : /* multipart object data */
300 : : bool mbMultipart;
301 : : sal_uInt16 mMFlags;
302 : : SvMemoryStream mMStream;
303 : : };
304 : :
305 : :
306 : : /// Common parameters when creating actions
307 : : struct ActionFactoryParameters
308 : : {
309 : 0 : ActionFactoryParameters( VectorOfOutDevStates& rStates,
310 : : const CanvasSharedPtr& rCanvas,
311 : : ::VirtualDevice& rVDev,
312 : : const Renderer::Parameters& rParms,
313 : : sal_Int32& io_rCurrActionIndex ) :
314 : : mrStates(rStates),
315 : : mrCanvas(rCanvas),
316 : : mrVDev(rVDev),
317 : : mrParms(rParms),
318 : 0 : mrCurrActionIndex(io_rCurrActionIndex)
319 : 0 : {}
320 : :
321 : : VectorOfOutDevStates& mrStates;
322 : : const CanvasSharedPtr& mrCanvas;
323 : : ::VirtualDevice& mrVDev;
324 : : const Renderer::Parameters& mrParms;
325 : : sal_Int32& mrCurrActionIndex;
326 : : };
327 : : }
328 : : }
329 : :
330 : : #endif /* _CPPCANVAS_IMPLRENDERER_HXX */
331 : :
332 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|