1464702f4SAndrew Rist /**************************************************************
2464702f4SAndrew Rist  *
3464702f4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4464702f4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5464702f4SAndrew Rist  * distributed with this work for additional information
6464702f4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7464702f4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8464702f4SAndrew Rist  * "License"); you may not use this file except in compliance
9464702f4SAndrew Rist  * with the License.  You may obtain a copy of the License at
10464702f4SAndrew Rist  *
11464702f4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12464702f4SAndrew Rist  *
13464702f4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14464702f4SAndrew Rist  * software distributed under the License is distributed on an
15464702f4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16464702f4SAndrew Rist  * KIND, either express or implied.  See the License for the
17464702f4SAndrew Rist  * specific language governing permissions and limitations
18464702f4SAndrew Rist  * under the License.
19464702f4SAndrew Rist  *
20464702f4SAndrew Rist  *************************************************************/
21464702f4SAndrew Rist 
22464702f4SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <drawinglayer/primitive2d/metafileprimitive2d.hxx>
28cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx>
29cdf0e10cSrcweir #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
30cdf0e10cSrcweir #include <basegfx/color/bcolor.hxx>
31cdf0e10cSrcweir #include <drawinglayer/primitive2d/pointarrayprimitive2d.hxx>
32cdf0e10cSrcweir #include <vcl/lineinfo.hxx>
33cdf0e10cSrcweir #include <drawinglayer/attribute/lineattribute.hxx>
34cdf0e10cSrcweir #include <drawinglayer/attribute/strokeattribute.hxx>
35cdf0e10cSrcweir #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
36cdf0e10cSrcweir #include <vcl/metaact.hxx>
37cdf0e10cSrcweir #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
38cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrixtools.hxx>
39cdf0e10cSrcweir #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
40cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
41cdf0e10cSrcweir #include <drawinglayer/primitive2d/discretebitmapprimitive2d.hxx>
42cdf0e10cSrcweir #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
43cdf0e10cSrcweir #include <vcl/salbtype.hxx>
44cdf0e10cSrcweir #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
45cdf0e10cSrcweir #include <drawinglayer/primitive2d/fillgradientprimitive2d.hxx>
46cdf0e10cSrcweir #include <vcl/svapp.hxx>
47cdf0e10cSrcweir #include <drawinglayer/primitive2d/transparenceprimitive2d.hxx>
48cdf0e10cSrcweir #include <drawinglayer/primitive2d/fillhatchprimitive2d.hxx>
49cdf0e10cSrcweir #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
50cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygonclipper.hxx>
51cdf0e10cSrcweir #include <drawinglayer/primitive2d/invertprimitive2d.hxx>
52cdf0e10cSrcweir #include <drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx>
53cdf0e10cSrcweir #include <drawinglayer/primitive2d/fillbitmapprimitive2d.hxx>
54cdf0e10cSrcweir #include <drawinglayer/primitive2d/wallpaperprimitive2d.hxx>
55cdf0e10cSrcweir #include <drawinglayer/primitive2d/textprimitive2d.hxx>
56cdf0e10cSrcweir #include <drawinglayer/primitive2d/textlayoutdevice.hxx>
57cdf0e10cSrcweir #include <drawinglayer/primitive2d/textdecoratedprimitive2d.hxx>
58cdf0e10cSrcweir #include <i18npool/mslangid.hxx>
59cdf0e10cSrcweir #include <drawinglayer/primitive2d/textlineprimitive2d.hxx>
60cdf0e10cSrcweir #include <drawinglayer/primitive2d/textstrikeoutprimitive2d.hxx>
61cdf0e10cSrcweir #include <drawinglayer/primitive2d/epsprimitive2d.hxx>
62cdf0e10cSrcweir #include <numeric>
63cdf0e10cSrcweir 
64cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
65cdf0e10cSrcweir 
66cdf0e10cSrcweir using namespace com::sun::star;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
69cdf0e10cSrcweir 
70cdf0e10cSrcweir namespace
71cdf0e10cSrcweir {
72cdf0e10cSrcweir 	/** helper class for graphic context
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 		This class allows to hold a complete status of classic
75cdf0e10cSrcweir 		VCL OutputDevice stati. This data is needed for correct
76cdf0e10cSrcweir 		interpretation of the MetaFile action flow.
77cdf0e10cSrcweir 	*/
78cdf0e10cSrcweir     class PropertyHolder
79cdf0e10cSrcweir     {
80cdf0e10cSrcweir     private:
81cdf0e10cSrcweir 		/// current transformation (aka MapMode)
82cdf0e10cSrcweir 		basegfx::B2DHomMatrix	maTransformation;
83cdf0e10cSrcweir 		MapUnit					maMapUnit;
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 		/// current colors
86cdf0e10cSrcweir         basegfx::BColor			maLineColor;
87cdf0e10cSrcweir         basegfx::BColor			maFillColor;
88cdf0e10cSrcweir         basegfx::BColor			maTextColor;
89cdf0e10cSrcweir         basegfx::BColor			maTextFillColor;
90cdf0e10cSrcweir         basegfx::BColor			maTextLineColor;
91cdf0e10cSrcweir         basegfx::BColor			maOverlineColor;
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 		/// clipping
94cdf0e10cSrcweir         basegfx::B2DPolyPolygon maClipPolyPoygon;
95cdf0e10cSrcweir 
96cdf0e10cSrcweir         /// font, etc.
97cdf0e10cSrcweir     	Font                    maFont;
98cdf0e10cSrcweir     	RasterOp                maRasterOp;
99cdf0e10cSrcweir         sal_uInt32              mnLayoutMode;
100cdf0e10cSrcweir         LanguageType            maLanguageType;
101cdf0e10cSrcweir         sal_uInt16              mnPushFlags;
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         /// bitfield
104cdf0e10cSrcweir 		/// contains all active markers
105cdf0e10cSrcweir         bool					mbLineColor : 1;
106cdf0e10cSrcweir         bool					mbFillColor : 1;
107cdf0e10cSrcweir         bool					mbTextColor : 1;
108cdf0e10cSrcweir         bool					mbTextFillColor : 1;
109cdf0e10cSrcweir         bool					mbTextLineColor : 1;
110cdf0e10cSrcweir         bool					mbOverlineColor : 1;
111cdf0e10cSrcweir         bool					mbClipPolyPolygonActive : 1;
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     public:
114cdf0e10cSrcweir         PropertyHolder()
115cdf0e10cSrcweir         :   maTransformation(),
116cdf0e10cSrcweir 			maMapUnit(MAP_100TH_MM),
117cdf0e10cSrcweir 			maLineColor(),
118cdf0e10cSrcweir             maFillColor(),
119cdf0e10cSrcweir             maTextColor(COL_BLACK),
120cdf0e10cSrcweir             maTextFillColor(),
121cdf0e10cSrcweir             maTextLineColor(),
122cdf0e10cSrcweir             maOverlineColor(),
123cdf0e10cSrcweir             maClipPolyPoygon(),
124cdf0e10cSrcweir             maFont(),
125cdf0e10cSrcweir             maRasterOp(ROP_OVERPAINT),
126cdf0e10cSrcweir             mnLayoutMode(0),
127cdf0e10cSrcweir             maLanguageType(0),
128cdf0e10cSrcweir             mnPushFlags(0),
129cdf0e10cSrcweir             mbLineColor(false),
130cdf0e10cSrcweir             mbFillColor(false),
131cdf0e10cSrcweir             mbTextColor(true),
132cdf0e10cSrcweir             mbTextFillColor(false),
133cdf0e10cSrcweir             mbTextLineColor(false),
134cdf0e10cSrcweir             mbOverlineColor(false),
135cdf0e10cSrcweir             mbClipPolyPolygonActive(false)
136cdf0e10cSrcweir         {
137cdf0e10cSrcweir         }
138cdf0e10cSrcweir 
139cdf0e10cSrcweir         ~PropertyHolder()
140cdf0e10cSrcweir         {
141cdf0e10cSrcweir         }
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 		/// read/write accesses
144cdf0e10cSrcweir 		const basegfx::B2DHomMatrix& getTransformation() const { return maTransformation; }
145cdf0e10cSrcweir 		void setTransformation(const basegfx::B2DHomMatrix& rNew) { if(rNew != maTransformation) maTransformation = rNew; }
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 		MapUnit getMapUnit() const { return maMapUnit; }
148cdf0e10cSrcweir 		void setMapUnit(MapUnit eNew) { if(eNew != maMapUnit) maMapUnit = eNew; }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 		const basegfx::BColor& getLineColor() const { return maLineColor; }
151cdf0e10cSrcweir         void setLineColor(const basegfx::BColor& rNew) { if(rNew != maLineColor) maLineColor = rNew; }
152cdf0e10cSrcweir         bool getLineColorActive() const { return mbLineColor; }
153cdf0e10cSrcweir         void setLineColorActive(bool bNew) { if(bNew != mbLineColor) mbLineColor = bNew; }
154cdf0e10cSrcweir 
155cdf0e10cSrcweir         const basegfx::BColor& getFillColor() const { return maFillColor; }
156cdf0e10cSrcweir         void setFillColor(const basegfx::BColor& rNew) { if(rNew != maFillColor) maFillColor = rNew; }
157cdf0e10cSrcweir         bool getFillColorActive() const { return mbFillColor; }
158cdf0e10cSrcweir         void setFillColorActive(bool bNew) { if(bNew != mbFillColor) mbFillColor = bNew; }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir         const basegfx::BColor& getTextColor() const { return maTextColor; }
161cdf0e10cSrcweir         void setTextColor(const basegfx::BColor& rNew) { if(rNew != maTextColor) maTextColor = rNew; }
162cdf0e10cSrcweir         bool getTextColorActive() const { return mbTextColor; }
163cdf0e10cSrcweir         void setTextColorActive(bool bNew) { if(bNew != mbTextColor) mbTextColor = bNew; }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir         const basegfx::BColor& getTextFillColor() const { return maTextFillColor; }
166cdf0e10cSrcweir         void setTextFillColor(const basegfx::BColor& rNew) { if(rNew != maTextFillColor) maTextFillColor = rNew; }
167cdf0e10cSrcweir         bool getTextFillColorActive() const { return mbTextFillColor; }
168cdf0e10cSrcweir         void setTextFillColorActive(bool bNew) { if(bNew != mbTextFillColor) mbTextFillColor = bNew; }
169cdf0e10cSrcweir 
170cdf0e10cSrcweir         const basegfx::BColor& getTextLineColor() const { return maTextLineColor; }
171cdf0e10cSrcweir         void setTextLineColor(const basegfx::BColor& rNew) { if(rNew != maTextLineColor) maTextLineColor = rNew; }
172cdf0e10cSrcweir         bool getTextLineColorActive() const { return mbTextLineColor; }
173cdf0e10cSrcweir         void setTextLineColorActive(bool bNew) { if(bNew != mbTextLineColor) mbTextLineColor = bNew; }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir         const basegfx::BColor& getOverlineColor() const { return maOverlineColor; }
176cdf0e10cSrcweir         void setOverlineColor(const basegfx::BColor& rNew) { if(rNew != maOverlineColor) maOverlineColor = rNew; }
177cdf0e10cSrcweir         bool getOverlineColorActive() const { return mbOverlineColor; }
178cdf0e10cSrcweir         void setOverlineColorActive(bool bNew) { if(bNew != mbOverlineColor) mbOverlineColor = bNew; }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir         const basegfx::B2DPolyPolygon& getClipPolyPolygon() const { return maClipPolyPoygon; }
181cdf0e10cSrcweir         void setClipPolyPolygon(const basegfx::B2DPolyPolygon& rNew) { if(rNew != maClipPolyPoygon) maClipPolyPoygon = rNew; }
182cdf0e10cSrcweir         bool getClipPolyPolygonActive() const { return mbClipPolyPolygonActive; }
183cdf0e10cSrcweir         void setClipPolyPolygonActive(bool bNew) { if(bNew != mbClipPolyPolygonActive) mbClipPolyPolygonActive = bNew; }
184cdf0e10cSrcweir 
185cdf0e10cSrcweir         const Font& getFont() const { return maFont; }
186cdf0e10cSrcweir         void setFont(const Font& rFont) { if(rFont != maFont) maFont = rFont; }
187cdf0e10cSrcweir 
188cdf0e10cSrcweir         const RasterOp& getRasterOp() const { return maRasterOp; }
189cdf0e10cSrcweir         void setRasterOp(const RasterOp& rRasterOp) { if(rRasterOp != maRasterOp) maRasterOp = rRasterOp; }
190cdf0e10cSrcweir         bool isRasterOpInvert() const { return (ROP_XOR == maRasterOp || ROP_INVERT == maRasterOp); }
191cdf0e10cSrcweir         bool isRasterOpForceBlack() const { return ROP_0 == maRasterOp; }
192cdf0e10cSrcweir         bool isRasterOpActive() const { return isRasterOpInvert() || isRasterOpForceBlack(); }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir         sal_uInt32 getLayoutMode() const { return mnLayoutMode; }
195cdf0e10cSrcweir         void setLayoutMode(sal_uInt32 nNew) { if(nNew != mnLayoutMode) mnLayoutMode = nNew; }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir         LanguageType getLanguageType() const { return maLanguageType; }
198cdf0e10cSrcweir         void setLanguageType(LanguageType aNew) { if(aNew != maLanguageType) maLanguageType = aNew; }
199cdf0e10cSrcweir 
200cdf0e10cSrcweir         sal_uInt16 getPushFlags() const { return mnPushFlags; }
201cdf0e10cSrcweir         void setPushFlags(sal_uInt16 nNew) { if(nNew != mnPushFlags) mnPushFlags = nNew; }
202cdf0e10cSrcweir 
203cdf0e10cSrcweir         bool getLineOrFillActive() const { return (mbLineColor || mbFillColor); }
204cdf0e10cSrcweir     };
205cdf0e10cSrcweir } // end of anonymous namespace
206cdf0e10cSrcweir 
207cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
208cdf0e10cSrcweir 
209cdf0e10cSrcweir namespace
210cdf0e10cSrcweir {
211cdf0e10cSrcweir 	/** stack for properites
212cdf0e10cSrcweir 
213cdf0e10cSrcweir 		This class builds a stack based on the PropertyHolder
214cdf0e10cSrcweir 		class. It encapsulates the pointer/new/delete usage to
215cdf0e10cSrcweir 		make it safe and implements the push/pop as needed by a
216cdf0e10cSrcweir 		VCL Metafile interpreter. The critical part here are the
217cdf0e10cSrcweir 		flag values VCL OutputDevice uses here; not all stuff is
218cdf0e10cSrcweir 		pushed and thus needs to be copied at pop.
219cdf0e10cSrcweir 	*/
220cdf0e10cSrcweir     class PropertyHolders
221cdf0e10cSrcweir     {
222cdf0e10cSrcweir     private:
223cdf0e10cSrcweir         std::vector< PropertyHolder* >          maPropertyHolders;
224cdf0e10cSrcweir 
225cdf0e10cSrcweir     public:
226cdf0e10cSrcweir         PropertyHolders()
227cdf0e10cSrcweir         {
228cdf0e10cSrcweir             maPropertyHolders.push_back(new PropertyHolder());
229cdf0e10cSrcweir         }
230cdf0e10cSrcweir 
231cdf0e10cSrcweir         sal_uInt32 size()
232cdf0e10cSrcweir         {
233cdf0e10cSrcweir             return maPropertyHolders.size();
234cdf0e10cSrcweir         }
235cdf0e10cSrcweir 
236cdf0e10cSrcweir 		void PushDefault()
237cdf0e10cSrcweir 		{
238cdf0e10cSrcweir             PropertyHolder* pNew = new PropertyHolder();
239cdf0e10cSrcweir             maPropertyHolders.push_back(pNew);
240cdf0e10cSrcweir 		}
241cdf0e10cSrcweir 
242cdf0e10cSrcweir         void Push(sal_uInt16 nPushFlags)
243cdf0e10cSrcweir         {
244cdf0e10cSrcweir             if(nPushFlags)
245cdf0e10cSrcweir             {
246cdf0e10cSrcweir                 OSL_ENSURE(maPropertyHolders.size(), "PropertyHolders: PUSH with no property holders (!)");
247cdf0e10cSrcweir 				if ( !maPropertyHolders.empty() )
248cdf0e10cSrcweir 				{
249cdf0e10cSrcweir 					PropertyHolder* pNew = new PropertyHolder(*maPropertyHolders.back());
250cdf0e10cSrcweir 					pNew->setPushFlags(nPushFlags);
251cdf0e10cSrcweir 					maPropertyHolders.push_back(pNew);
252cdf0e10cSrcweir 				}
253cdf0e10cSrcweir             }
254cdf0e10cSrcweir         }
255cdf0e10cSrcweir 
256cdf0e10cSrcweir         void Pop()
257cdf0e10cSrcweir         {
258cdf0e10cSrcweir             OSL_ENSURE(maPropertyHolders.size(), "PropertyHolders: POP with no property holders (!)");
259cdf0e10cSrcweir             const sal_uInt32 nSize(maPropertyHolders.size());
260cdf0e10cSrcweir 
261cdf0e10cSrcweir             if(nSize)
262cdf0e10cSrcweir             {
263cdf0e10cSrcweir                 const PropertyHolder* pTip = maPropertyHolders.back();
264cdf0e10cSrcweir                 const sal_uInt16 nPushFlags(pTip->getPushFlags());
265cdf0e10cSrcweir 
266cdf0e10cSrcweir                 if(nPushFlags)
267cdf0e10cSrcweir                 {
268cdf0e10cSrcweir                     if(nSize > 1)
269cdf0e10cSrcweir                     {
270cdf0e10cSrcweir                         // copy back content for all non-set flags
271cdf0e10cSrcweir                         PropertyHolder* pLast = maPropertyHolders[nSize - 2];
272cdf0e10cSrcweir 
273cdf0e10cSrcweir                         if(PUSH_ALL != nPushFlags)
274cdf0e10cSrcweir                         {
275cdf0e10cSrcweir                             if(!(nPushFlags & PUSH_LINECOLOR      ))
276cdf0e10cSrcweir                             {
277cdf0e10cSrcweir                                 pLast->setLineColor(pTip->getLineColor());
278cdf0e10cSrcweir                                 pLast->setLineColorActive(pTip->getLineColorActive());
279cdf0e10cSrcweir                             }
280cdf0e10cSrcweir                             if(!(nPushFlags & PUSH_FILLCOLOR      ))
281cdf0e10cSrcweir                             {
282cdf0e10cSrcweir                                 pLast->setFillColor(pTip->getFillColor());
283cdf0e10cSrcweir                                 pLast->setFillColorActive(pTip->getFillColorActive());
284cdf0e10cSrcweir                             }
285cdf0e10cSrcweir                             if(!(nPushFlags & PUSH_FONT           ))
286cdf0e10cSrcweir                             {
287cdf0e10cSrcweir                                 pLast->setFont(pTip->getFont());
288cdf0e10cSrcweir                             }
289cdf0e10cSrcweir                             if(!(nPushFlags & PUSH_TEXTCOLOR      ))
290cdf0e10cSrcweir                             {
291cdf0e10cSrcweir                                 pLast->setTextColor(pTip->getTextColor());
292cdf0e10cSrcweir                                 pLast->setTextColorActive(pTip->getTextColorActive());
293cdf0e10cSrcweir                             }
294cdf0e10cSrcweir                             if(!(nPushFlags & PUSH_MAPMODE        ))
295cdf0e10cSrcweir                             {
296cdf0e10cSrcweir                                 pLast->setTransformation(pTip->getTransformation());
297cdf0e10cSrcweir                                 pLast->setMapUnit(pTip->getMapUnit());
298cdf0e10cSrcweir                             }
299cdf0e10cSrcweir                             if(!(nPushFlags & PUSH_CLIPREGION     ))
300cdf0e10cSrcweir                             {
301cdf0e10cSrcweir                                 pLast->setClipPolyPolygon(pTip->getClipPolyPolygon());
302cdf0e10cSrcweir                                 pLast->setClipPolyPolygonActive(pTip->getClipPolyPolygonActive());
303cdf0e10cSrcweir                             }
304cdf0e10cSrcweir                             if(!(nPushFlags & PUSH_RASTEROP       ))
305cdf0e10cSrcweir                             {
306cdf0e10cSrcweir                                 pLast->setRasterOp(pTip->getRasterOp());
307cdf0e10cSrcweir                             }
308cdf0e10cSrcweir                             if(!(nPushFlags & PUSH_TEXTFILLCOLOR  ))
309cdf0e10cSrcweir                             {
310cdf0e10cSrcweir                                 pLast->setTextFillColor(pTip->getTextFillColor());
311cdf0e10cSrcweir                                 pLast->setTextFillColorActive(pTip->getTextFillColorActive());
312cdf0e10cSrcweir                             }
313cdf0e10cSrcweir                             if(!(nPushFlags & PUSH_TEXTALIGN      ))
314cdf0e10cSrcweir                             {
315cdf0e10cSrcweir                                 if(pLast->getFont().GetAlign() != pTip->getFont().GetAlign())
316cdf0e10cSrcweir                                 {
317cdf0e10cSrcweir                                     Font aFont(pLast->getFont());
318cdf0e10cSrcweir                                     aFont.SetAlign(pTip->getFont().GetAlign());
319cdf0e10cSrcweir                                     pLast->setFont(aFont);
320cdf0e10cSrcweir                                 }
321cdf0e10cSrcweir                             }
322cdf0e10cSrcweir                             if(!(nPushFlags & PUSH_REFPOINT       ))
323cdf0e10cSrcweir                             {
324cdf0e10cSrcweir                                 // not supported
325cdf0e10cSrcweir                             }
326cdf0e10cSrcweir                             if(!(nPushFlags & PUSH_TEXTLINECOLOR  ))
327cdf0e10cSrcweir                             {
328cdf0e10cSrcweir                                 pLast->setTextLineColor(pTip->getTextLineColor());
329cdf0e10cSrcweir                                 pLast->setTextLineColorActive(pTip->getTextLineColorActive());
330cdf0e10cSrcweir                             }
331cdf0e10cSrcweir                             if(!(nPushFlags & PUSH_TEXTLAYOUTMODE ))
332cdf0e10cSrcweir                             {
333cdf0e10cSrcweir                                 pLast->setLayoutMode(pTip->getLayoutMode());
334cdf0e10cSrcweir                             }
335cdf0e10cSrcweir                             if(!(nPushFlags & PUSH_TEXTLANGUAGE   ))
336cdf0e10cSrcweir                             {
337cdf0e10cSrcweir                                 pLast->setLanguageType(pTip->getLanguageType());
338cdf0e10cSrcweir                             }
339cdf0e10cSrcweir                             if(!(nPushFlags & PUSH_OVERLINECOLOR  ))
340cdf0e10cSrcweir                             {
341cdf0e10cSrcweir                                 pLast->setOverlineColor(pTip->getOverlineColor());
342cdf0e10cSrcweir                                 pLast->setOverlineColorActive(pTip->getOverlineColorActive());
343cdf0e10cSrcweir                             }
344cdf0e10cSrcweir                         }
345cdf0e10cSrcweir                     }
346cdf0e10cSrcweir                 }
347cdf0e10cSrcweir 
348cdf0e10cSrcweir                 // execute the pop
349cdf0e10cSrcweir                 delete maPropertyHolders.back();
350cdf0e10cSrcweir                 maPropertyHolders.pop_back();
351cdf0e10cSrcweir             }
352cdf0e10cSrcweir         }
353cdf0e10cSrcweir 
354cdf0e10cSrcweir         PropertyHolder& Current()
355cdf0e10cSrcweir         {
356cdf0e10cSrcweir 			static PropertyHolder aDummy;
357cdf0e10cSrcweir             OSL_ENSURE(maPropertyHolders.size(), "PropertyHolders: CURRENT with no property holders (!)");
358cdf0e10cSrcweir 			return maPropertyHolders.empty() ? aDummy : *maPropertyHolders.back();
359cdf0e10cSrcweir         }
360cdf0e10cSrcweir 
361cdf0e10cSrcweir         ~PropertyHolders()
362cdf0e10cSrcweir         {
363cdf0e10cSrcweir             while(maPropertyHolders.size())
364cdf0e10cSrcweir             {
365cdf0e10cSrcweir                 delete maPropertyHolders.back();
366cdf0e10cSrcweir                 maPropertyHolders.pop_back();
367cdf0e10cSrcweir             }
368cdf0e10cSrcweir         }
369cdf0e10cSrcweir     };
370cdf0e10cSrcweir } // end of anonymous namespace
371cdf0e10cSrcweir 
372cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
373cdf0e10cSrcweir 
374cdf0e10cSrcweir namespace
375cdf0e10cSrcweir {
376cdf0e10cSrcweir 	/** helper to convert a Region to a B2DPolyPolygon
377cdf0e10cSrcweir 		when it does not yet contain one. In the future
378cdf0e10cSrcweir 		this may be expanded to merge the polygons created
379cdf0e10cSrcweir 		from rectangles or use a special algo to directly turn
380cdf0e10cSrcweir 		the spans of regions to a single, already merged
381cdf0e10cSrcweir 		PolyPolygon.
382cdf0e10cSrcweir 	 */
383cdf0e10cSrcweir     basegfx::B2DPolyPolygon getB2DPolyPolygonFromRegion(const Region& rRegion)
384cdf0e10cSrcweir     {
385cdf0e10cSrcweir         basegfx::B2DPolyPolygon aRetval;
386cdf0e10cSrcweir 
387cdf0e10cSrcweir         if(!rRegion.IsEmpty())
388cdf0e10cSrcweir         {
389cdf0e10cSrcweir             Region aRegion(rRegion);
390cdf0e10cSrcweir             aRetval = aRegion.GetB2DPolyPolygon();
391cdf0e10cSrcweir 
392cdf0e10cSrcweir             if(!aRetval.count())
393cdf0e10cSrcweir             {
394cdf0e10cSrcweir 		        RegionHandle aRegionHandle(aRegion.BeginEnumRects());
395cdf0e10cSrcweir 		        Rectangle aRegionRectangle;
396cdf0e10cSrcweir 
397cdf0e10cSrcweir                 while(aRegion.GetEnumRects(aRegionHandle, aRegionRectangle))
398cdf0e10cSrcweir 		        {
399cdf0e10cSrcweir                     if(!aRegionRectangle.IsEmpty())
400cdf0e10cSrcweir                     {
401cdf0e10cSrcweir 					    const basegfx::B2DRange aRegionRange(
402cdf0e10cSrcweir                             aRegionRectangle.Left(), aRegionRectangle.Top(),
403cdf0e10cSrcweir                             aRegionRectangle.Right(), aRegionRectangle.Bottom());
404cdf0e10cSrcweir                         aRetval.append(basegfx::tools::createPolygonFromRect(aRegionRange));
405cdf0e10cSrcweir                     }
406cdf0e10cSrcweir                 }
407cdf0e10cSrcweir 
408cdf0e10cSrcweir                 aRegion.EndEnumRects(aRegionHandle);
409cdf0e10cSrcweir             }
410cdf0e10cSrcweir         }
411cdf0e10cSrcweir 
412cdf0e10cSrcweir         return aRetval;
413cdf0e10cSrcweir     }
414cdf0e10cSrcweir } // end of anonymous namespace
415cdf0e10cSrcweir 
416cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
417cdf0e10cSrcweir 
418cdf0e10cSrcweir namespace
419cdf0e10cSrcweir {
420cdf0e10cSrcweir 	/**	Helper class to buffer and hold a Primive target vector. It
421cdf0e10cSrcweir 		encapsulates the new/delete functionality and aloows to work
422cdf0e10cSrcweir 		on pointers of the implementation classes. All data will
423cdf0e10cSrcweir 		be converted to uno sequences of uno references when accessing the
424cdf0e10cSrcweir 		data.
425cdf0e10cSrcweir 	*/
426cdf0e10cSrcweir     class TargetHolder
427cdf0e10cSrcweir     {
428cdf0e10cSrcweir     private:
429cdf0e10cSrcweir         std::vector< drawinglayer::primitive2d::BasePrimitive2D* > aTargets;
430cdf0e10cSrcweir 
431cdf0e10cSrcweir     public:
432cdf0e10cSrcweir         TargetHolder()
433cdf0e10cSrcweir         :   aTargets()
434cdf0e10cSrcweir         {
435cdf0e10cSrcweir         }
436cdf0e10cSrcweir 
437cdf0e10cSrcweir         ~TargetHolder()
438cdf0e10cSrcweir         {
439cdf0e10cSrcweir             const sal_uInt32 nCount(aTargets.size());
440cdf0e10cSrcweir 
441cdf0e10cSrcweir             for(sal_uInt32 a(0); a < nCount; a++)
442cdf0e10cSrcweir             {
443cdf0e10cSrcweir                 delete aTargets[a];
444cdf0e10cSrcweir             }
445cdf0e10cSrcweir         }
446cdf0e10cSrcweir 
447cdf0e10cSrcweir         sal_uInt32 size()
448cdf0e10cSrcweir         {
449cdf0e10cSrcweir             return aTargets.size();
450cdf0e10cSrcweir         }
451cdf0e10cSrcweir 
452cdf0e10cSrcweir         void append(drawinglayer::primitive2d::BasePrimitive2D* pCandidate)
453cdf0e10cSrcweir         {
454cdf0e10cSrcweir             if(pCandidate)
455cdf0e10cSrcweir             {
456cdf0e10cSrcweir                 aTargets.push_back(pCandidate);
457cdf0e10cSrcweir             }
458cdf0e10cSrcweir         }
459cdf0e10cSrcweir 
460cdf0e10cSrcweir         drawinglayer::primitive2d::Primitive2DSequence getPrimitive2DSequence(const PropertyHolder& rPropertyHolder)
461cdf0e10cSrcweir         {
462cdf0e10cSrcweir             const sal_uInt32 nCount(aTargets.size());
463cdf0e10cSrcweir             drawinglayer::primitive2d::Primitive2DSequence xRetval(nCount);
464cdf0e10cSrcweir 
465cdf0e10cSrcweir             for(sal_uInt32 a(0); a < nCount; a++)
466cdf0e10cSrcweir             {
467cdf0e10cSrcweir                 xRetval[a] = aTargets[a];
468cdf0e10cSrcweir             }
469cdf0e10cSrcweir 
470cdf0e10cSrcweir             // All Targets were pointers, but do not need to be deleted since they
471cdf0e10cSrcweir             // were converted to UNO API references now, so they stay as long as
472cdf0e10cSrcweir             // referenced. Do NOT delete the C++ implementation classes here, but clear
473cdf0e10cSrcweir             // the buffer to not delete them in the destructor.
474cdf0e10cSrcweir             aTargets.clear();
475cdf0e10cSrcweir 
476cdf0e10cSrcweir             if(xRetval.hasElements() && rPropertyHolder.getClipPolyPolygonActive())
477cdf0e10cSrcweir             {
478cdf0e10cSrcweir                 const basegfx::B2DPolyPolygon& rClipPolyPolygon = rPropertyHolder.getClipPolyPolygon();
479cdf0e10cSrcweir 
480cdf0e10cSrcweir                 if(rClipPolyPolygon.count())
481cdf0e10cSrcweir                 {
482cdf0e10cSrcweir 		            const drawinglayer::primitive2d::Primitive2DReference xMask(
483cdf0e10cSrcweir 			            new drawinglayer::primitive2d::MaskPrimitive2D(
484cdf0e10cSrcweir 				            rClipPolyPolygon,
485cdf0e10cSrcweir 				            xRetval));
486cdf0e10cSrcweir 
487cdf0e10cSrcweir                     xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xMask, 1);
488cdf0e10cSrcweir                 }
489cdf0e10cSrcweir             }
490cdf0e10cSrcweir 
491cdf0e10cSrcweir             return xRetval;
492cdf0e10cSrcweir         }
493cdf0e10cSrcweir     };
494cdf0e10cSrcweir } // end of anonymous namespace
495cdf0e10cSrcweir 
496cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
497cdf0e10cSrcweir 
498cdf0e10cSrcweir namespace
499cdf0e10cSrcweir {
500cdf0e10cSrcweir 	/** Helper class which builds a stack on the TargetHolder class	*/
501cdf0e10cSrcweir     class TargetHolders
502cdf0e10cSrcweir     {
503cdf0e10cSrcweir     private:
504cdf0e10cSrcweir         std::vector< TargetHolder* >          maTargetHolders;
505cdf0e10cSrcweir 
506cdf0e10cSrcweir     public:
507cdf0e10cSrcweir         TargetHolders()
508cdf0e10cSrcweir         {
509cdf0e10cSrcweir             maTargetHolders.push_back(new TargetHolder());
510cdf0e10cSrcweir         }
511cdf0e10cSrcweir 
512cdf0e10cSrcweir         sal_uInt32 size()
513cdf0e10cSrcweir         {
514cdf0e10cSrcweir             return maTargetHolders.size();
515cdf0e10cSrcweir         }
516cdf0e10cSrcweir 
517cdf0e10cSrcweir         void Push()
518cdf0e10cSrcweir         {
519cdf0e10cSrcweir             maTargetHolders.push_back(new TargetHolder());
520cdf0e10cSrcweir         }
521cdf0e10cSrcweir 
522cdf0e10cSrcweir         void Pop()
523cdf0e10cSrcweir         {
524cdf0e10cSrcweir             OSL_ENSURE(maTargetHolders.size(), "TargetHolders: POP with no property holders (!)");
525cdf0e10cSrcweir             if(maTargetHolders.size())
526cdf0e10cSrcweir             {
527cdf0e10cSrcweir                 delete maTargetHolders.back();
528cdf0e10cSrcweir                 maTargetHolders.pop_back();
529cdf0e10cSrcweir             }
530cdf0e10cSrcweir         }
531cdf0e10cSrcweir 
532cdf0e10cSrcweir         TargetHolder& Current()
533cdf0e10cSrcweir         {
534cdf0e10cSrcweir             OSL_ENSURE(maTargetHolders.size(), "TargetHolders: CURRENT with no property holders (!)");
535cdf0e10cSrcweir             return *maTargetHolders.back();
536cdf0e10cSrcweir         }
537cdf0e10cSrcweir 
538cdf0e10cSrcweir         ~TargetHolders()
539cdf0e10cSrcweir         {
540cdf0e10cSrcweir             while(maTargetHolders.size())
541cdf0e10cSrcweir             {
542cdf0e10cSrcweir                 delete maTargetHolders.back();
543cdf0e10cSrcweir                 maTargetHolders.pop_back();
544cdf0e10cSrcweir             }
545cdf0e10cSrcweir         }
546cdf0e10cSrcweir     };
547cdf0e10cSrcweir } // end of anonymous namespace
548cdf0e10cSrcweir 
549cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
550cdf0e10cSrcweir 
551cdf0e10cSrcweir namespace drawinglayer
552cdf0e10cSrcweir {
553cdf0e10cSrcweir 	namespace primitive2d
554cdf0e10cSrcweir 	{
555cdf0e10cSrcweir         /** NonOverlappingFillGradientPrimitive2D class
556cdf0e10cSrcweir 
557cdf0e10cSrcweir             This is a special version of the FillGradientPrimitive2D which decomposes
558cdf0e10cSrcweir             to a non-overlapping geometry version of the gradient. This needs to be
559cdf0e10cSrcweir             used to support the old XOR paint-'trick'.
560cdf0e10cSrcweir 
561cdf0e10cSrcweir             It does not need an own identifier since a renderer who wants to interpret
562cdf0e10cSrcweir             it itself may do so. It just overloads the decomposition of the C++
563cdf0e10cSrcweir             implementation class to do an alternative decomposition.
564cdf0e10cSrcweir          */
565cdf0e10cSrcweir         class NonOverlappingFillGradientPrimitive2D : public FillGradientPrimitive2D
566cdf0e10cSrcweir         {
567cdf0e10cSrcweir 		protected:
568cdf0e10cSrcweir             /// local decomposition.
569cdf0e10cSrcweir 			virtual Primitive2DSequence create2DDecomposition(
570cdf0e10cSrcweir                 const geometry::ViewInformation2D& rViewInformation) const;
571cdf0e10cSrcweir 
572cdf0e10cSrcweir 		public:
573cdf0e10cSrcweir             /// constructor
574cdf0e10cSrcweir 			NonOverlappingFillGradientPrimitive2D(
575cdf0e10cSrcweir 				const basegfx::B2DRange& rObjectRange,
576cdf0e10cSrcweir 				const attribute::FillGradientAttribute& rFillGradient)
577cdf0e10cSrcweir             :   FillGradientPrimitive2D(rObjectRange, rFillGradient)
578cdf0e10cSrcweir             {
579cdf0e10cSrcweir             }
580cdf0e10cSrcweir         };
581cdf0e10cSrcweir 
582cdf0e10cSrcweir         Primitive2DSequence NonOverlappingFillGradientPrimitive2D::create2DDecomposition(
583cdf0e10cSrcweir             const geometry::ViewInformation2D& /*rViewInformation*/) const
584cdf0e10cSrcweir         {
585cdf0e10cSrcweir             if(!getFillGradient().isDefault())
586cdf0e10cSrcweir             {
587cdf0e10cSrcweir         		return createFill(false);
588cdf0e10cSrcweir             }
589cdf0e10cSrcweir             else
590cdf0e10cSrcweir             {
591cdf0e10cSrcweir                 return Primitive2DSequence();
592cdf0e10cSrcweir             }
593cdf0e10cSrcweir         }
594cdf0e10cSrcweir 	} // end of namespace primitive2d
595cdf0e10cSrcweir } // end of namespace drawinglayer
596cdf0e10cSrcweir 
597cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
598cdf0e10cSrcweir 
599cdf0e10cSrcweir namespace
600cdf0e10cSrcweir {
601cdf0e10cSrcweir 	/** helper to convert a MapMode to a transformation */
602cdf0e10cSrcweir     basegfx::B2DHomMatrix getTransformFromMapMode(const MapMode& rMapMode)
603cdf0e10cSrcweir 	{
604cdf0e10cSrcweir 		basegfx::B2DHomMatrix aMapping;
605cdf0e10cSrcweir 		const Fraction aNoScale(1, 1);
606cdf0e10cSrcweir 		const Point& rOrigin(rMapMode.GetOrigin());
607cdf0e10cSrcweir 
608cdf0e10cSrcweir 		if(0 != rOrigin.X() || 0 != rOrigin.Y())
609cdf0e10cSrcweir 		{
610cdf0e10cSrcweir 			aMapping.translate(rOrigin.X(), rOrigin.Y());
611cdf0e10cSrcweir 		}
612cdf0e10cSrcweir 
613cdf0e10cSrcweir 		if(rMapMode.GetScaleX() != aNoScale || rMapMode.GetScaleY() != aNoScale)
614cdf0e10cSrcweir 		{
615cdf0e10cSrcweir 			aMapping.scale(
616cdf0e10cSrcweir 				double(rMapMode.GetScaleX()),
617cdf0e10cSrcweir 				double(rMapMode.GetScaleY()));
618cdf0e10cSrcweir 		}
619cdf0e10cSrcweir 
620cdf0e10cSrcweir 		return aMapping;
621cdf0e10cSrcweir 	}
622cdf0e10cSrcweir 
623cdf0e10cSrcweir 	/** helper to create a PointArrayPrimitive2D based on current context */
624cdf0e10cSrcweir     void createPointArrayPrimitive(
625cdf0e10cSrcweir         const std::vector< basegfx::B2DPoint >& rPositions,
626cdf0e10cSrcweir         TargetHolder& rTarget,
627cdf0e10cSrcweir 		PropertyHolder& rProperties,
628cdf0e10cSrcweir         basegfx::BColor aBColor)
629cdf0e10cSrcweir     {
630cdf0e10cSrcweir 		if(rPositions.size())
631cdf0e10cSrcweir 		{
632cdf0e10cSrcweir 			if(rProperties.getTransformation().isIdentity())
633cdf0e10cSrcweir 			{
634cdf0e10cSrcweir 				rTarget.append(
635cdf0e10cSrcweir 					new drawinglayer::primitive2d::PointArrayPrimitive2D(
636cdf0e10cSrcweir 						rPositions,
637cdf0e10cSrcweir 						aBColor));
638cdf0e10cSrcweir 			}
639cdf0e10cSrcweir 			else
640cdf0e10cSrcweir 			{
641cdf0e10cSrcweir 		        std::vector< basegfx::B2DPoint > aPositions(rPositions);
642cdf0e10cSrcweir 
643cdf0e10cSrcweir 				for(sal_uInt32 a(0); a < aPositions.size(); a++)
644cdf0e10cSrcweir 				{
645cdf0e10cSrcweir 					aPositions[a] = rProperties.getTransformation() * aPositions[a];
646cdf0e10cSrcweir 				}
647cdf0e10cSrcweir 
648cdf0e10cSrcweir 				rTarget.append(
649cdf0e10cSrcweir 					new drawinglayer::primitive2d::PointArrayPrimitive2D(
650cdf0e10cSrcweir 						aPositions,
651cdf0e10cSrcweir 						aBColor));
652cdf0e10cSrcweir 			}
653cdf0e10cSrcweir 		}
654cdf0e10cSrcweir     }
655cdf0e10cSrcweir 
656cdf0e10cSrcweir 	/** helper to create a PolygonHairlinePrimitive2D based on current context */
657cdf0e10cSrcweir 	void createHairlinePrimitive(
658cdf0e10cSrcweir         const basegfx::B2DPolygon& rLinePolygon,
659cdf0e10cSrcweir         TargetHolder& rTarget,
660cdf0e10cSrcweir         PropertyHolder& rProperties)
661cdf0e10cSrcweir 	{
662cdf0e10cSrcweir 		if(rLinePolygon.count())
663cdf0e10cSrcweir 		{
664cdf0e10cSrcweir 	        basegfx::B2DPolygon aLinePolygon(rLinePolygon);
665cdf0e10cSrcweir 			aLinePolygon.transform(rProperties.getTransformation());
666cdf0e10cSrcweir 			rTarget.append(
667cdf0e10cSrcweir 				new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(
668cdf0e10cSrcweir 					aLinePolygon,
669cdf0e10cSrcweir 					rProperties.getLineColor()));
670cdf0e10cSrcweir 		}
671cdf0e10cSrcweir 	}
672cdf0e10cSrcweir 
673cdf0e10cSrcweir 	/** helper to create a PolyPolygonColorPrimitive2D based on current context */
674cdf0e10cSrcweir 	void createFillPrimitive(
675cdf0e10cSrcweir         const basegfx::B2DPolyPolygon& rFillPolyPolygon,
676cdf0e10cSrcweir         TargetHolder& rTarget,
677cdf0e10cSrcweir         PropertyHolder& rProperties)
678cdf0e10cSrcweir 	{
679cdf0e10cSrcweir 		if(rFillPolyPolygon.count())
680cdf0e10cSrcweir 		{
681cdf0e10cSrcweir 	        basegfx::B2DPolyPolygon aFillPolyPolygon(rFillPolyPolygon);
682cdf0e10cSrcweir 			aFillPolyPolygon.transform(rProperties.getTransformation());
683cdf0e10cSrcweir 			rTarget.append(
684cdf0e10cSrcweir 				new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
685cdf0e10cSrcweir 					aFillPolyPolygon,
686cdf0e10cSrcweir 					rProperties.getFillColor()));
687cdf0e10cSrcweir 		}
688cdf0e10cSrcweir 	}
689cdf0e10cSrcweir 
690cdf0e10cSrcweir 	/** helper to create a PolygonStrokePrimitive2D based on current context */
691cdf0e10cSrcweir     void createLinePrimitive(
692cdf0e10cSrcweir         const basegfx::B2DPolygon& rLinePolygon,
693cdf0e10cSrcweir         const LineInfo& rLineInfo,
694cdf0e10cSrcweir         TargetHolder& rTarget,
695cdf0e10cSrcweir         PropertyHolder& rProperties)
696cdf0e10cSrcweir     {
697cdf0e10cSrcweir 		if(rLinePolygon.count())
698cdf0e10cSrcweir 		{
699cdf0e10cSrcweir 			const bool bDashDotUsed(LINE_DASH == rLineInfo.GetStyle());
700cdf0e10cSrcweir 			const bool bWidthUsed(rLineInfo.GetWidth() > 1);
701cdf0e10cSrcweir 
702cdf0e10cSrcweir 			if(bDashDotUsed || bWidthUsed)
703cdf0e10cSrcweir 			{
704cdf0e10cSrcweir 		        basegfx::B2DPolygon aLinePolygon(rLinePolygon);
705cdf0e10cSrcweir 				aLinePolygon.transform(rProperties.getTransformation());
706cdf0e10cSrcweir 				const drawinglayer::attribute::LineAttribute aLineAttribute(
707cdf0e10cSrcweir 					rProperties.getLineColor(),
708cdf0e10cSrcweir 					bWidthUsed ? rLineInfo.GetWidth() : 0.0,
709*5aaf853bSArmin Le Grand 					rLineInfo.GetLineJoin(),
710*5aaf853bSArmin Le Grand                     rLineInfo.GetLineCap());
711cdf0e10cSrcweir 
712cdf0e10cSrcweir 				if(bDashDotUsed)
713cdf0e10cSrcweir 				{
714cdf0e10cSrcweir 					::std::vector< double > fDotDashArray;
715cdf0e10cSrcweir 					const double fDashLen(rLineInfo.GetDashLen());
716cdf0e10cSrcweir 					const double fDotLen(rLineInfo.GetDotLen());
717cdf0e10cSrcweir 					const double fDistance(rLineInfo.GetDistance());
718cdf0e10cSrcweir 
719cdf0e10cSrcweir 					for(sal_uInt16 a(0); a < rLineInfo.GetDashCount(); a++)
720cdf0e10cSrcweir 					{
721cdf0e10cSrcweir 						fDotDashArray.push_back(fDashLen);
722cdf0e10cSrcweir 						fDotDashArray.push_back(fDistance);
723cdf0e10cSrcweir 					}
724cdf0e10cSrcweir 
725cdf0e10cSrcweir 					for(sal_uInt16 b(0); b < rLineInfo.GetDotCount(); b++)
726cdf0e10cSrcweir 					{
727cdf0e10cSrcweir 						fDotDashArray.push_back(fDotLen);
728cdf0e10cSrcweir 						fDotDashArray.push_back(fDistance);
729cdf0e10cSrcweir 					}
730cdf0e10cSrcweir 
731cdf0e10cSrcweir 					const double fAccumulated(::std::accumulate(fDotDashArray.begin(), fDotDashArray.end(), 0.0));
732cdf0e10cSrcweir 					const drawinglayer::attribute::StrokeAttribute aStrokeAttribute(
733cdf0e10cSrcweir 						fDotDashArray,
734cdf0e10cSrcweir 						fAccumulated);
735cdf0e10cSrcweir 
736cdf0e10cSrcweir 					rTarget.append(
737cdf0e10cSrcweir 						new drawinglayer::primitive2d::PolygonStrokePrimitive2D(
738cdf0e10cSrcweir 							aLinePolygon,
739cdf0e10cSrcweir 							aLineAttribute,
740cdf0e10cSrcweir 							aStrokeAttribute));
741cdf0e10cSrcweir 				}
742cdf0e10cSrcweir 				else
743cdf0e10cSrcweir 				{
744cdf0e10cSrcweir 					rTarget.append(
745cdf0e10cSrcweir 						new drawinglayer::primitive2d::PolygonStrokePrimitive2D(
746cdf0e10cSrcweir 							aLinePolygon,
747cdf0e10cSrcweir 							aLineAttribute));
748cdf0e10cSrcweir 				}
749cdf0e10cSrcweir 			}
750cdf0e10cSrcweir 			else
751cdf0e10cSrcweir 			{
752cdf0e10cSrcweir 				createHairlinePrimitive(rLinePolygon, rTarget, rProperties);
753cdf0e10cSrcweir 			}
754cdf0e10cSrcweir 		}
755cdf0e10cSrcweir     }
756cdf0e10cSrcweir 
757cdf0e10cSrcweir 	/** helper to create needed line and fill primitives based on current context */
758cdf0e10cSrcweir 	void createHairlineAndFillPrimitive(
759cdf0e10cSrcweir         const basegfx::B2DPolygon& rPolygon,
760cdf0e10cSrcweir         TargetHolder& rTarget,
761cdf0e10cSrcweir         PropertyHolder& rProperties)
762cdf0e10cSrcweir 	{
763cdf0e10cSrcweir 		if(rProperties.getFillColorActive())
764cdf0e10cSrcweir 		{
765cdf0e10cSrcweir 			createFillPrimitive(basegfx::B2DPolyPolygon(rPolygon), rTarget, rProperties);
766cdf0e10cSrcweir 		}
767cdf0e10cSrcweir 
768cdf0e10cSrcweir 		if(rProperties.getLineColorActive())
769cdf0e10cSrcweir 		{
770cdf0e10cSrcweir 			createHairlinePrimitive(rPolygon, rTarget, rProperties);
771cdf0e10cSrcweir 		}
772cdf0e10cSrcweir 	}
773cdf0e10cSrcweir 
774cdf0e10cSrcweir 	/** helper to create needed line and fill primitives based on current context */
775cdf0e10cSrcweir 	void createHairlineAndFillPrimitive(
776cdf0e10cSrcweir         const basegfx::B2DPolyPolygon& rPolyPolygon,
777cdf0e10cSrcweir         TargetHolder& rTarget,
778cdf0e10cSrcweir         PropertyHolder& rProperties)
779cdf0e10cSrcweir 	{
780cdf0e10cSrcweir 		if(rProperties.getFillColorActive())
781cdf0e10cSrcweir 		{
782cdf0e10cSrcweir 			createFillPrimitive(rPolyPolygon, rTarget, rProperties);
783cdf0e10cSrcweir 		}
784cdf0e10cSrcweir 
785cdf0e10cSrcweir 		if(rProperties.getLineColorActive())
786cdf0e10cSrcweir 		{
787cdf0e10cSrcweir 			for(sal_uInt32 a(0); a < rPolyPolygon.count(); a++)
788cdf0e10cSrcweir 			{
789cdf0e10cSrcweir 				createHairlinePrimitive(rPolyPolygon.getB2DPolygon(a), rTarget, rProperties);
790cdf0e10cSrcweir 			}
791cdf0e10cSrcweir 		}
792cdf0e10cSrcweir 	}
793cdf0e10cSrcweir 
794cdf0e10cSrcweir 	/** helper to create DiscreteBitmapPrimitive2D based on current context.
795cdf0e10cSrcweir 		The DiscreteBitmapPrimitive2D is especially created for this usage
796cdf0e10cSrcweir 		since no other usage defines a bitmap visualisation based on top-left
797cdf0e10cSrcweir 		position and size in pixels. At the end it will create a view-dependent
798cdf0e10cSrcweir 		transformed embedding of a BitmapPrimitive2D.
799cdf0e10cSrcweir 	*/
800cdf0e10cSrcweir 	void createBitmapExPrimitive(
801cdf0e10cSrcweir 		const BitmapEx& rBitmapEx,
802cdf0e10cSrcweir 		const Point& rPoint,
803cdf0e10cSrcweir         TargetHolder& rTarget,
804cdf0e10cSrcweir         PropertyHolder& rProperties)
805cdf0e10cSrcweir 	{
806cdf0e10cSrcweir 		if(!rBitmapEx.IsEmpty())
807cdf0e10cSrcweir 		{
808cdf0e10cSrcweir 			basegfx::B2DPoint aPoint(rPoint.X(), rPoint.Y());
809cdf0e10cSrcweir 			aPoint = rProperties.getTransformation() * aPoint;
810cdf0e10cSrcweir 
811cdf0e10cSrcweir 			rTarget.append(
812cdf0e10cSrcweir 				new drawinglayer::primitive2d::DiscreteBitmapPrimitive2D(
813cdf0e10cSrcweir 					rBitmapEx,
814cdf0e10cSrcweir 					aPoint));
815cdf0e10cSrcweir 		}
816cdf0e10cSrcweir 	}
817cdf0e10cSrcweir 
818cdf0e10cSrcweir 	/** helper to create BitmapPrimitive2D based on current context */
819cdf0e10cSrcweir 	void createBitmapExPrimitive(
820cdf0e10cSrcweir 		const BitmapEx& rBitmapEx,
821cdf0e10cSrcweir 		const Point& rPoint,
822cdf0e10cSrcweir 		const Size& rSize,
823cdf0e10cSrcweir         TargetHolder& rTarget,
824cdf0e10cSrcweir         PropertyHolder& rProperties)
825cdf0e10cSrcweir 	{
826cdf0e10cSrcweir 		if(!rBitmapEx.IsEmpty())
827cdf0e10cSrcweir 		{
828cdf0e10cSrcweir 			basegfx::B2DHomMatrix aObjectTransform;
829cdf0e10cSrcweir 
830cdf0e10cSrcweir 			aObjectTransform.set(0, 0, rSize.Width());
831cdf0e10cSrcweir 			aObjectTransform.set(1, 1, rSize.Height());
832cdf0e10cSrcweir 			aObjectTransform.set(0, 2, rPoint.X());
833cdf0e10cSrcweir 			aObjectTransform.set(1, 2, rPoint.Y());
834cdf0e10cSrcweir 
835cdf0e10cSrcweir 			aObjectTransform = rProperties.getTransformation() * aObjectTransform;
836cdf0e10cSrcweir 
837cdf0e10cSrcweir 			rTarget.append(
838cdf0e10cSrcweir 				new drawinglayer::primitive2d::BitmapPrimitive2D(
839cdf0e10cSrcweir 					rBitmapEx,
840cdf0e10cSrcweir 					aObjectTransform));
841cdf0e10cSrcweir 		}
842cdf0e10cSrcweir 	}
843cdf0e10cSrcweir 
844cdf0e10cSrcweir 	/** helper to create a regular BotmapEx from a MaskAction (definitions
845cdf0e10cSrcweir 		which use a bitmap without transparence but define one of the colors as
846cdf0e10cSrcweir 		transparent)
847cdf0e10cSrcweir 	 */
848cdf0e10cSrcweir     BitmapEx createMaskBmpEx(const Bitmap& rBitmap, const Color& rMaskColor)
849cdf0e10cSrcweir     {
850cdf0e10cSrcweir         const Color aWhite(COL_WHITE);
851cdf0e10cSrcweir         BitmapPalette aBiLevelPalette(2);
852cdf0e10cSrcweir 
853cdf0e10cSrcweir 		aBiLevelPalette[0] = aWhite;
854cdf0e10cSrcweir         aBiLevelPalette[1] = rMaskColor;
855cdf0e10cSrcweir 
856cdf0e10cSrcweir         Bitmap aMask(rBitmap.CreateMask(aWhite));
857cdf0e10cSrcweir         Bitmap aSolid(rBitmap.GetSizePixel(), 1, &aBiLevelPalette);
858cdf0e10cSrcweir 
859cdf0e10cSrcweir 		aSolid.Erase(rMaskColor);
860cdf0e10cSrcweir 
861cdf0e10cSrcweir         return BitmapEx(aSolid, aMask);
862cdf0e10cSrcweir     }
863cdf0e10cSrcweir 
864cdf0e10cSrcweir 	/** helper to convert from a VCL Gradient definition to the corresponding
865cdf0e10cSrcweir 		data for primitive representation
866cdf0e10cSrcweir 	 */
867cdf0e10cSrcweir 	drawinglayer::attribute::FillGradientAttribute createFillGradientAttribute(const Gradient& rGradient)
868cdf0e10cSrcweir 	{
869cdf0e10cSrcweir 		const Color aStartColor(rGradient.GetStartColor());
870cdf0e10cSrcweir 		const sal_uInt16 nStartIntens(rGradient.GetStartIntensity());
871cdf0e10cSrcweir 		basegfx::BColor aStart(aStartColor.getBColor());
872cdf0e10cSrcweir 
873cdf0e10cSrcweir 		if(nStartIntens != 100)
874cdf0e10cSrcweir 		{
875cdf0e10cSrcweir 			const basegfx::BColor aBlack;
876cdf0e10cSrcweir 			aStart = interpolate(aBlack, aStart, (double)nStartIntens * 0.01);
877cdf0e10cSrcweir 		}
878cdf0e10cSrcweir 
879cdf0e10cSrcweir 		const Color aEndColor(rGradient.GetEndColor());
880cdf0e10cSrcweir 		const sal_uInt16 nEndIntens(rGradient.GetEndIntensity());
881cdf0e10cSrcweir 		basegfx::BColor aEnd(aEndColor.getBColor());
882cdf0e10cSrcweir 
883cdf0e10cSrcweir 		if(nEndIntens != 100)
884cdf0e10cSrcweir 		{
885cdf0e10cSrcweir 			const basegfx::BColor aBlack;
886cdf0e10cSrcweir 			aEnd = interpolate(aBlack, aEnd, (double)nEndIntens * 0.01);
887cdf0e10cSrcweir 		}
888cdf0e10cSrcweir 
889cdf0e10cSrcweir 		drawinglayer::attribute::GradientStyle aGradientStyle(drawinglayer::attribute::GRADIENTSTYLE_RECT);
890cdf0e10cSrcweir 
891cdf0e10cSrcweir 		switch(rGradient.GetStyle())
892cdf0e10cSrcweir 		{
893cdf0e10cSrcweir 			case GRADIENT_LINEAR :
894cdf0e10cSrcweir 			{
895cdf0e10cSrcweir 				aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_LINEAR;
896cdf0e10cSrcweir 				break;
897cdf0e10cSrcweir 			}
898cdf0e10cSrcweir 			case GRADIENT_AXIAL :
899cdf0e10cSrcweir 			{
900cdf0e10cSrcweir 				aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_AXIAL;
901cdf0e10cSrcweir 				break;
902cdf0e10cSrcweir 			}
903cdf0e10cSrcweir 			case GRADIENT_RADIAL :
904cdf0e10cSrcweir 			{
905cdf0e10cSrcweir 				aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_RADIAL;
906cdf0e10cSrcweir 				break;
907cdf0e10cSrcweir 			}
908cdf0e10cSrcweir 			case GRADIENT_ELLIPTICAL :
909cdf0e10cSrcweir 			{
910cdf0e10cSrcweir 				aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_ELLIPTICAL;
911cdf0e10cSrcweir 				break;
912cdf0e10cSrcweir 			}
913cdf0e10cSrcweir 			case GRADIENT_SQUARE :
914cdf0e10cSrcweir 			{
915cdf0e10cSrcweir 				aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_SQUARE;
916cdf0e10cSrcweir 				break;
917cdf0e10cSrcweir 			}
918cdf0e10cSrcweir 			default : // GRADIENT_RECT
919cdf0e10cSrcweir 			{
920cdf0e10cSrcweir 				aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_RECT;
921cdf0e10cSrcweir 				break;
922cdf0e10cSrcweir 			}
923cdf0e10cSrcweir 		}
924cdf0e10cSrcweir 
925cdf0e10cSrcweir 		return drawinglayer::attribute::FillGradientAttribute(
926cdf0e10cSrcweir 			aGradientStyle,
927cdf0e10cSrcweir 			(double)rGradient.GetBorder() * 0.01,
928cdf0e10cSrcweir 			(double)rGradient.GetOfsX() * 0.01,
929cdf0e10cSrcweir 			(double)rGradient.GetOfsY() * 0.01,
930cdf0e10cSrcweir 			(double)rGradient.GetAngle() * F_PI1800,
931cdf0e10cSrcweir 			aStart,
932cdf0e10cSrcweir 			aEnd,
933cdf0e10cSrcweir 			rGradient.GetSteps());
934cdf0e10cSrcweir 	}
935cdf0e10cSrcweir 
936cdf0e10cSrcweir 	/** helper to convert from a VCL Hatch definition to the corresponding
937cdf0e10cSrcweir 		data for primitive representation
938cdf0e10cSrcweir 	 */
939cdf0e10cSrcweir 	drawinglayer::attribute::FillHatchAttribute createFillHatchAttribute(const Hatch& rHatch)
940cdf0e10cSrcweir 	{
941cdf0e10cSrcweir 		drawinglayer::attribute::HatchStyle aHatchStyle(drawinglayer::attribute::HATCHSTYLE_SINGLE);
942cdf0e10cSrcweir 
943cdf0e10cSrcweir 		switch(rHatch.GetStyle())
944cdf0e10cSrcweir 		{
945cdf0e10cSrcweir             default : // case HATCH_SINGLE :
946cdf0e10cSrcweir 			{
947cdf0e10cSrcweir 				aHatchStyle = drawinglayer::attribute::HATCHSTYLE_SINGLE;
948cdf0e10cSrcweir                 break;
949cdf0e10cSrcweir 			}
950cdf0e10cSrcweir 			case HATCH_DOUBLE :
951cdf0e10cSrcweir 			{
952cdf0e10cSrcweir 				aHatchStyle = drawinglayer::attribute::HATCHSTYLE_DOUBLE;
953cdf0e10cSrcweir                 break;
954cdf0e10cSrcweir 			}
955cdf0e10cSrcweir             case HATCH_TRIPLE :
956cdf0e10cSrcweir 			{
957cdf0e10cSrcweir 				aHatchStyle = drawinglayer::attribute::HATCHSTYLE_TRIPLE;
958cdf0e10cSrcweir                 break;
959cdf0e10cSrcweir 			}
960cdf0e10cSrcweir 		}
961cdf0e10cSrcweir 
962cdf0e10cSrcweir         return drawinglayer::attribute::FillHatchAttribute(
963cdf0e10cSrcweir             aHatchStyle,
964cdf0e10cSrcweir             (double)rHatch.GetDistance(),
965cdf0e10cSrcweir             (double)rHatch.GetAngle() * F_PI1800,
966cdf0e10cSrcweir             rHatch.GetColor().getBColor(),
967cdf0e10cSrcweir             false);
968cdf0e10cSrcweir 	}
969cdf0e10cSrcweir 
970cdf0e10cSrcweir 	/** helper to take needed action on ClipRegion change. This method needs to be called
971cdf0e10cSrcweir 		on any Region change, e.g. at the obvious actions doing this, but also at pop-calls
972cdf0e10cSrcweir 		whcih change the Region of the current context. It takes care of creating the
973cdf0e10cSrcweir 		current embeddec context, set the new Region at the context and eventually prepare
974cdf0e10cSrcweir 		a new target for embracing new geometry to the current region
975cdf0e10cSrcweir 	 */
976cdf0e10cSrcweir     void HandleNewClipRegion(
977cdf0e10cSrcweir         const basegfx::B2DPolyPolygon& rClipPolyPolygon,
978cdf0e10cSrcweir         TargetHolders& rTargetHolders,
979cdf0e10cSrcweir         PropertyHolders& rPropertyHolders)
980cdf0e10cSrcweir     {
981cdf0e10cSrcweir         const bool bNewActive(rClipPolyPolygon.count());
982cdf0e10cSrcweir 
983cdf0e10cSrcweir 		// #i108636# The handlig of new ClipPolyPolygons was not done as good as possible
984cdf0e10cSrcweir 		// in the first version of this interpreter; e.g. when a ClipPolyPolygon was set
985cdf0e10cSrcweir 		// initially and then using a lot of push/pop actions, the pop always leads
986cdf0e10cSrcweir 		// to setting a 'new' ClipPolyPolygon which indeed is the return to the ClipPolyPolygon
987cdf0e10cSrcweir 		// of the properties next on the stack.
988cdf0e10cSrcweir         //
989cdf0e10cSrcweir 		// This ClipPolyPolygon is identical to the current one, so there is no need to
990cdf0e10cSrcweir 		// create a MaskPrimitive2D containing the up-to-now created primitives, but
991cdf0e10cSrcweir 		// this was done before. While this does not lead to wrong primitive
992cdf0e10cSrcweir 		// representations of the metafile data, it creates unneccesarily expensive
993cdf0e10cSrcweir 		// representations. Just detecting when no really 'new' ClipPolyPolygon gets set
994cdf0e10cSrcweir 		// solves the problem.
995cdf0e10cSrcweir 
996cdf0e10cSrcweir 		if(!rPropertyHolders.Current().getClipPolyPolygonActive() && !bNewActive)
997cdf0e10cSrcweir 		{
998cdf0e10cSrcweir 			// no active ClipPolyPolygon exchanged by no new one, done
999cdf0e10cSrcweir 			return;
1000cdf0e10cSrcweir 		}
1001cdf0e10cSrcweir 
1002cdf0e10cSrcweir 		if(rPropertyHolders.Current().getClipPolyPolygonActive() && bNewActive)
1003cdf0e10cSrcweir 		{
1004cdf0e10cSrcweir 			// active ClipPolyPolygon and new active ClipPolyPolygon
1005cdf0e10cSrcweir 			if(rPropertyHolders.Current().getClipPolyPolygon() == rClipPolyPolygon)
1006cdf0e10cSrcweir 			{
1007cdf0e10cSrcweir 				// new is the same as old, done
1008cdf0e10cSrcweir 				return;
1009cdf0e10cSrcweir 			}
1010cdf0e10cSrcweir 		}
1011cdf0e10cSrcweir 
1012cdf0e10cSrcweir 		// Here the old and the new are definitively different, maybe
1013cdf0e10cSrcweir 		// old one and/or new one is not active.
1014cdf0e10cSrcweir 
1015cdf0e10cSrcweir 		// Handle deletion of old ClipPolyPolygon. The process evtl. created primitives which
1016cdf0e10cSrcweir 		// belong to this active ClipPolyPolygon. These need to be embedded to a
1017cdf0e10cSrcweir 		// MaskPrimitive2D accordingly.
1018cdf0e10cSrcweir         if(rPropertyHolders.Current().getClipPolyPolygonActive() && rTargetHolders.size() > 1)
1019cdf0e10cSrcweir         {
1020cdf0e10cSrcweir             drawinglayer::primitive2d::Primitive2DSequence aSubContent;
1021cdf0e10cSrcweir 
1022cdf0e10cSrcweir             if(rPropertyHolders.Current().getClipPolyPolygon().count()
1023cdf0e10cSrcweir                 && rTargetHolders.Current().size())
1024cdf0e10cSrcweir             {
1025cdf0e10cSrcweir                 aSubContent = rTargetHolders.Current().getPrimitive2DSequence(
1026cdf0e10cSrcweir                     rPropertyHolders.Current());
1027cdf0e10cSrcweir             }
1028cdf0e10cSrcweir 
1029cdf0e10cSrcweir             rTargetHolders.Pop();
1030cdf0e10cSrcweir 
1031cdf0e10cSrcweir             if(aSubContent.hasElements())
1032cdf0e10cSrcweir             {
1033cdf0e10cSrcweir                 rTargetHolders.Current().append(
1034cdf0e10cSrcweir 			        new drawinglayer::primitive2d::GroupPrimitive2D(
1035cdf0e10cSrcweir 				        aSubContent));
1036cdf0e10cSrcweir             }
1037cdf0e10cSrcweir         }
1038cdf0e10cSrcweir 
1039cdf0e10cSrcweir         // apply new settings to current properties by setting
1040cdf0e10cSrcweir 		// the new region now
1041cdf0e10cSrcweir         rPropertyHolders.Current().setClipPolyPolygonActive(bNewActive);
1042cdf0e10cSrcweir 
1043cdf0e10cSrcweir         if(bNewActive)
1044cdf0e10cSrcweir         {
1045cdf0e10cSrcweir             rPropertyHolders.Current().setClipPolyPolygon(rClipPolyPolygon);
1046cdf0e10cSrcweir 
1047cdf0e10cSrcweir             // prepare new content holder for new active region
1048cdf0e10cSrcweir             rTargetHolders.Push();
1049cdf0e10cSrcweir         }
1050cdf0e10cSrcweir     }
1051cdf0e10cSrcweir 
1052cdf0e10cSrcweir 	/** helper to handle the change of RasterOp. It takes care of encapsulating all current
1053cdf0e10cSrcweir 		geometry to the current RasterOp (if changed) and needs to be called on any RasterOp
1054cdf0e10cSrcweir 		change. It will also start a new geometry target to embrace to the new RasterOp if
1055cdf0e10cSrcweir 		a changuing RasterOp is used. Currently, ROP_XOR and ROP_INVERT are supported using
1056cdf0e10cSrcweir 		InvertPrimitive2D, and ROP_0 by using a ModifiedColorPrimitive2D to force to black paint
1057cdf0e10cSrcweir 	 */
1058cdf0e10cSrcweir     void HandleNewRasterOp(
1059cdf0e10cSrcweir         RasterOp aRasterOp,
1060cdf0e10cSrcweir         TargetHolders& rTargetHolders,
1061cdf0e10cSrcweir         PropertyHolders& rPropertyHolders)
1062cdf0e10cSrcweir     {
1063cdf0e10cSrcweir         // check if currently active
1064cdf0e10cSrcweir         if(rPropertyHolders.Current().isRasterOpActive() && rTargetHolders.size() > 1)
1065cdf0e10cSrcweir         {
1066cdf0e10cSrcweir             drawinglayer::primitive2d::Primitive2DSequence aSubContent;
1067cdf0e10cSrcweir 
1068cdf0e10cSrcweir             if(rTargetHolders.Current().size())
1069cdf0e10cSrcweir             {
1070cdf0e10cSrcweir                 aSubContent = rTargetHolders.Current().getPrimitive2DSequence(rPropertyHolders.Current());
1071cdf0e10cSrcweir             }
1072cdf0e10cSrcweir 
1073cdf0e10cSrcweir             rTargetHolders.Pop();
1074cdf0e10cSrcweir 
1075cdf0e10cSrcweir             if(aSubContent.hasElements())
1076cdf0e10cSrcweir             {
1077cdf0e10cSrcweir                 if(rPropertyHolders.Current().isRasterOpForceBlack())
1078cdf0e10cSrcweir                 {
1079cdf0e10cSrcweir                     // force content to black
1080cdf0e10cSrcweir                     rTargetHolders.Current().append(
1081cdf0e10cSrcweir 			            new drawinglayer::primitive2d::ModifiedColorPrimitive2D(
1082cdf0e10cSrcweir 				            aSubContent,
1083cdf0e10cSrcweir                             basegfx::BColorModifier(basegfx::BColor(0.0, 0.0, 0.0))));
1084cdf0e10cSrcweir                 }
1085cdf0e10cSrcweir                 else // if(rPropertyHolders.Current().isRasterOpInvert())
1086cdf0e10cSrcweir                 {
1087cdf0e10cSrcweir                     // invert content
1088cdf0e10cSrcweir                     rTargetHolders.Current().append(
1089cdf0e10cSrcweir 			            new drawinglayer::primitive2d::InvertPrimitive2D(
1090cdf0e10cSrcweir 				            aSubContent));
1091cdf0e10cSrcweir                 }
1092cdf0e10cSrcweir             }
1093cdf0e10cSrcweir         }
1094cdf0e10cSrcweir 
1095cdf0e10cSrcweir         // apply new settings
1096cdf0e10cSrcweir         rPropertyHolders.Current().setRasterOp(aRasterOp);
1097cdf0e10cSrcweir 
1098cdf0e10cSrcweir         // check if now active
1099cdf0e10cSrcweir         if(rPropertyHolders.Current().isRasterOpActive())
1100cdf0e10cSrcweir         {
1101cdf0e10cSrcweir             // prepare new content holder for new invert
1102cdf0e10cSrcweir             rTargetHolders.Push();
1103cdf0e10cSrcweir         }
1104cdf0e10cSrcweir     }
1105cdf0e10cSrcweir 
1106cdf0e10cSrcweir 	/** helper to create needed data to emulate the VCL Wallpaper Metafile action.
1107cdf0e10cSrcweir 		It is a quite mighty action. This helper is for simple color filled background.
1108cdf0e10cSrcweir 	 */
1109cdf0e10cSrcweir     drawinglayer::primitive2d::BasePrimitive2D* CreateColorWallpaper(
1110cdf0e10cSrcweir         const basegfx::B2DRange& rRange,
1111cdf0e10cSrcweir         const basegfx::BColor& rColor,
1112cdf0e10cSrcweir         PropertyHolder& rPropertyHolder)
1113cdf0e10cSrcweir     {
1114cdf0e10cSrcweir         basegfx::B2DPolygon aOutline(basegfx::tools::createPolygonFromRect(rRange));
1115cdf0e10cSrcweir 		aOutline.transform(rPropertyHolder.getTransformation());
1116cdf0e10cSrcweir 
1117cdf0e10cSrcweir         return new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
1118cdf0e10cSrcweir 		    basegfx::B2DPolyPolygon(aOutline),
1119cdf0e10cSrcweir 		    rColor);
1120cdf0e10cSrcweir     }
1121cdf0e10cSrcweir 
1122cdf0e10cSrcweir 	/** helper to create needed data to emulate the VCL Wallpaper Metafile action.
1123cdf0e10cSrcweir 		It is a quite mighty action. This helper is for gradient filled background.
1124cdf0e10cSrcweir 	 */
1125cdf0e10cSrcweir     drawinglayer::primitive2d::BasePrimitive2D* CreateGradientWallpaper(
1126cdf0e10cSrcweir         const basegfx::B2DRange& rRange,
1127cdf0e10cSrcweir         const Gradient& rGradient,
1128cdf0e10cSrcweir         PropertyHolder& rPropertyHolder)
1129cdf0e10cSrcweir     {
1130cdf0e10cSrcweir     	const drawinglayer::attribute::FillGradientAttribute aAttribute(createFillGradientAttribute(rGradient));
1131cdf0e10cSrcweir 
1132cdf0e10cSrcweir 		if(aAttribute.getStartColor() == aAttribute.getEndColor())
1133cdf0e10cSrcweir 		{
1134cdf0e10cSrcweir 			// not really a gradient. Create filled rectangle
1135cdf0e10cSrcweir             return CreateColorWallpaper(rRange, aAttribute.getStartColor(), rPropertyHolder);
1136cdf0e10cSrcweir 		}
1137cdf0e10cSrcweir 		else
1138cdf0e10cSrcweir 		{
1139cdf0e10cSrcweir 			// really a gradient
1140cdf0e10cSrcweir 		    drawinglayer::primitive2d::BasePrimitive2D* pRetval =
1141cdf0e10cSrcweir 				new drawinglayer::primitive2d::FillGradientPrimitive2D(
1142cdf0e10cSrcweir 					rRange,
1143cdf0e10cSrcweir 				    aAttribute);
1144cdf0e10cSrcweir 
1145cdf0e10cSrcweir 			if(!rPropertyHolder.getTransformation().isIdentity())
1146cdf0e10cSrcweir             {
1147cdf0e10cSrcweir                 const drawinglayer::primitive2d::Primitive2DReference xPrim(pRetval);
1148cdf0e10cSrcweir                 const drawinglayer::primitive2d::Primitive2DSequence xSeq(&xPrim, 1);
1149cdf0e10cSrcweir 
1150cdf0e10cSrcweir 			    pRetval = new drawinglayer::primitive2d::TransformPrimitive2D(
1151cdf0e10cSrcweir 			        rPropertyHolder.getTransformation(),
1152cdf0e10cSrcweir 			        xSeq);
1153cdf0e10cSrcweir             }
1154cdf0e10cSrcweir 
1155cdf0e10cSrcweir 			return pRetval;
1156cdf0e10cSrcweir 		}
1157cdf0e10cSrcweir     }
1158cdf0e10cSrcweir 
1159cdf0e10cSrcweir 	/** helper to create needed data to emulate the VCL Wallpaper Metafile action.
1160cdf0e10cSrcweir 		It is a quite mighty action. This helper decides if color and/or gradient
1161cdf0e10cSrcweir 		background is needed for the wnated bitmap fill and then creates the needed
1162cdf0e10cSrcweir 		WallpaperBitmapPrimitive2D. This primitive was created for this purpose and
1163cdf0e10cSrcweir 		takes over all needed logic of orientations and tiling.
1164cdf0e10cSrcweir 	 */
1165cdf0e10cSrcweir     void CreateAndAppendBitmapWallpaper(
1166cdf0e10cSrcweir         basegfx::B2DRange aWallpaperRange,
1167cdf0e10cSrcweir 		const Wallpaper& rWallpaper,
1168cdf0e10cSrcweir 		TargetHolder& rTarget,
1169cdf0e10cSrcweir 		PropertyHolder& rProperty)
1170cdf0e10cSrcweir 	{
1171cdf0e10cSrcweir 	    const BitmapEx aBitmapEx(rWallpaper.GetBitmap());
1172cdf0e10cSrcweir 		const WallpaperStyle eWallpaperStyle(rWallpaper.GetStyle());
1173cdf0e10cSrcweir 
1174cdf0e10cSrcweir         // if bitmap visualisation is transparent, maybe background
1175cdf0e10cSrcweir         // needs to be filled. Create background
1176cdf0e10cSrcweir         if(aBitmapEx.IsTransparent()
1177cdf0e10cSrcweir             || (WALLPAPER_TILE != eWallpaperStyle && WALLPAPER_SCALE != eWallpaperStyle))
1178cdf0e10cSrcweir         {
1179cdf0e10cSrcweir             if(rWallpaper.IsGradient())
1180cdf0e10cSrcweir             {
1181cdf0e10cSrcweir                 rTarget.append(
1182cdf0e10cSrcweir 	                CreateGradientWallpaper(
1183cdf0e10cSrcweir 		                aWallpaperRange,
1184cdf0e10cSrcweir                         rWallpaper.GetGradient(),
1185cdf0e10cSrcweir                         rProperty));
1186cdf0e10cSrcweir             }
1187cdf0e10cSrcweir             else if(!rWallpaper.GetColor().GetTransparency())
1188cdf0e10cSrcweir             {
1189cdf0e10cSrcweir                 rTarget.append(
1190cdf0e10cSrcweir 	                CreateColorWallpaper(
1191cdf0e10cSrcweir 		                aWallpaperRange,
1192cdf0e10cSrcweir                         rWallpaper.GetColor().getBColor(),
1193cdf0e10cSrcweir                         rProperty));
1194cdf0e10cSrcweir             }
1195cdf0e10cSrcweir         }
1196cdf0e10cSrcweir 
1197cdf0e10cSrcweir         // use wallpaper rect if set
1198cdf0e10cSrcweir         if(rWallpaper.IsRect() && !rWallpaper.GetRect().IsEmpty())
1199cdf0e10cSrcweir         {
1200cdf0e10cSrcweir             aWallpaperRange = basegfx::B2DRange(
1201cdf0e10cSrcweir                 rWallpaper.GetRect().Left(), rWallpaper.GetRect().Top(),
1202cdf0e10cSrcweir                 rWallpaper.GetRect().Right(), rWallpaper.GetRect().Bottom());
1203cdf0e10cSrcweir         }
1204cdf0e10cSrcweir 
1205cdf0e10cSrcweir 		drawinglayer::primitive2d::BasePrimitive2D* pBitmapWallpaperFill =
1206cdf0e10cSrcweir 	        new drawinglayer::primitive2d::WallpaperBitmapPrimitive2D(
1207cdf0e10cSrcweir 		        aWallpaperRange,
1208cdf0e10cSrcweir 				aBitmapEx,
1209cdf0e10cSrcweir 				eWallpaperStyle);
1210cdf0e10cSrcweir 
1211cdf0e10cSrcweir 		if(rProperty.getTransformation().isIdentity())
1212cdf0e10cSrcweir         {
1213cdf0e10cSrcweir 			// add directly
1214cdf0e10cSrcweir             rTarget.append(pBitmapWallpaperFill);
1215cdf0e10cSrcweir         }
1216cdf0e10cSrcweir         else
1217cdf0e10cSrcweir         {
1218cdf0e10cSrcweir 			// when a transformation is set, embed to it
1219cdf0e10cSrcweir             const drawinglayer::primitive2d::Primitive2DReference xPrim(pBitmapWallpaperFill);
1220cdf0e10cSrcweir 
1221cdf0e10cSrcweir 	        rTarget.append(
1222cdf0e10cSrcweir 		        new drawinglayer::primitive2d::TransformPrimitive2D(
1223cdf0e10cSrcweir 			        rProperty.getTransformation(),
1224cdf0e10cSrcweir 			        drawinglayer::primitive2d::Primitive2DSequence(&xPrim, 1)));
1225cdf0e10cSrcweir         }
1226cdf0e10cSrcweir 	}
1227cdf0e10cSrcweir 
1228cdf0e10cSrcweir 	/** helper to decide UnderlineAbove for text primitives */
1229cdf0e10cSrcweir 	bool isUnderlineAbove(const Font& rFont)
1230cdf0e10cSrcweir 	{
1231cdf0e10cSrcweir 		if(!rFont.IsVertical())
1232cdf0e10cSrcweir 		{
1233cdf0e10cSrcweir 			return false;
1234cdf0e10cSrcweir 		}
1235cdf0e10cSrcweir 
1236cdf0e10cSrcweir 		if((LANGUAGE_JAPANESE == rFont.GetLanguage()) || (LANGUAGE_JAPANESE == rFont.GetCJKContextLanguage()))
1237cdf0e10cSrcweir 		{
1238cdf0e10cSrcweir 			// the underline is right for Japanese only
1239cdf0e10cSrcweir 			return true;
1240cdf0e10cSrcweir 		}
1241cdf0e10cSrcweir 
1242cdf0e10cSrcweir 		return false;
1243cdf0e10cSrcweir 	}
1244cdf0e10cSrcweir 
1245cdf0e10cSrcweir 	void createFontAttributeTransformAndAlignment(
1246cdf0e10cSrcweir 		drawinglayer::attribute::FontAttribute& rFontAttribute,
1247cdf0e10cSrcweir 		basegfx::B2DHomMatrix& rTextTransform,
1248cdf0e10cSrcweir 		basegfx::B2DVector& rAlignmentOffset,
1249cdf0e10cSrcweir 		PropertyHolder& rProperty)
1250cdf0e10cSrcweir 	{
1251cdf0e10cSrcweir 		const Font& rFont = rProperty.getFont();
1252cdf0e10cSrcweir 		basegfx::B2DVector aFontScaling;
1253cdf0e10cSrcweir 
1254cdf0e10cSrcweir 		rFontAttribute = drawinglayer::attribute::FontAttribute(
1255cdf0e10cSrcweir 			drawinglayer::primitive2d::getFontAttributeFromVclFont(
1256cdf0e10cSrcweir 				aFontScaling,
1257cdf0e10cSrcweir 				rFont,
1258cdf0e10cSrcweir 				0 != (rProperty.getLayoutMode() & TEXT_LAYOUT_BIDI_RTL),
1259cdf0e10cSrcweir 				0 != (rProperty.getLayoutMode() & TEXT_LAYOUT_BIDI_STRONG)));
1260cdf0e10cSrcweir 
1261cdf0e10cSrcweir 		// add FontScaling
1262cdf0e10cSrcweir 		rTextTransform.scale(aFontScaling.getX(), aFontScaling.getY());
1263cdf0e10cSrcweir 
1264cdf0e10cSrcweir         // take text align into account
1265cdf0e10cSrcweir         if(ALIGN_BASELINE != rFont.GetAlign())
1266cdf0e10cSrcweir         {
1267cdf0e10cSrcweir             drawinglayer::primitive2d::TextLayouterDevice aTextLayouterDevice;
1268cdf0e10cSrcweir             aTextLayouterDevice.setFont(rFont);
1269cdf0e10cSrcweir 
1270cdf0e10cSrcweir             if(ALIGN_TOP == rFont.GetAlign())
1271cdf0e10cSrcweir             {
1272cdf0e10cSrcweir                 rAlignmentOffset.setY(aTextLayouterDevice.getFontAscent());
1273cdf0e10cSrcweir             }
1274cdf0e10cSrcweir             else // ALIGN_BOTTOM
1275cdf0e10cSrcweir             {
1276cdf0e10cSrcweir                 rAlignmentOffset.setY(-aTextLayouterDevice.getFontDescent());
1277cdf0e10cSrcweir             }
1278cdf0e10cSrcweir 
1279cdf0e10cSrcweir             rTextTransform.translate(rAlignmentOffset.getX(), rAlignmentOffset.getY());
1280cdf0e10cSrcweir         }
1281cdf0e10cSrcweir 
1282cdf0e10cSrcweir 		// add FontRotation (if used)
1283cdf0e10cSrcweir 		if(rFont.GetOrientation())
1284cdf0e10cSrcweir 		{
1285cdf0e10cSrcweir 			rTextTransform.rotate(-rFont.GetOrientation() * F_PI1800);
1286cdf0e10cSrcweir 		}
1287cdf0e10cSrcweir 	}
1288cdf0e10cSrcweir 
1289cdf0e10cSrcweir 	/** helper which takes complete care for creating the needed text primitives. It
1290cdf0e10cSrcweir 		takes care of decorated stuff and all the geometry adaptions needed
1291cdf0e10cSrcweir 	 */
1292cdf0e10cSrcweir 	void proccessMetaTextAction(
1293cdf0e10cSrcweir 		const Point& rTextStartPosition,
1294cdf0e10cSrcweir 		const XubString& rText,
1295cdf0e10cSrcweir 		sal_uInt16 nTextStart,
1296cdf0e10cSrcweir 		sal_uInt16 nTextLength,
1297cdf0e10cSrcweir 		const ::std::vector< double >& rDXArray,
1298cdf0e10cSrcweir 		TargetHolder& rTarget,
1299cdf0e10cSrcweir 		PropertyHolder& rProperty)
1300cdf0e10cSrcweir 	{
1301cdf0e10cSrcweir 		drawinglayer::primitive2d::BasePrimitive2D* pResult = 0;
1302cdf0e10cSrcweir 		const Font& rFont = rProperty.getFont();
1303cdf0e10cSrcweir         basegfx::B2DVector aAlignmentOffset(0.0, 0.0);
1304cdf0e10cSrcweir 
1305cdf0e10cSrcweir 		if(nTextLength)
1306cdf0e10cSrcweir 		{
1307cdf0e10cSrcweir 			drawinglayer::attribute::FontAttribute aFontAttribute;
1308cdf0e10cSrcweir 			basegfx::B2DHomMatrix aTextTransform;
1309cdf0e10cSrcweir 
1310cdf0e10cSrcweir 			// fill parameters derived from current font
1311cdf0e10cSrcweir 			createFontAttributeTransformAndAlignment(
1312cdf0e10cSrcweir 				aFontAttribute,
1313cdf0e10cSrcweir 				aTextTransform,
1314cdf0e10cSrcweir 				aAlignmentOffset,
1315cdf0e10cSrcweir 				rProperty);
1316cdf0e10cSrcweir 
1317cdf0e10cSrcweir 			// add TextStartPosition
1318cdf0e10cSrcweir 			aTextTransform.translate(rTextStartPosition.X(), rTextStartPosition.Y());
1319cdf0e10cSrcweir 
1320cdf0e10cSrcweir 			// prepare FontColor and Locale
1321cdf0e10cSrcweir 			const basegfx::BColor aFontColor(rProperty.getTextColor());
1322cdf0e10cSrcweir 		    const com::sun::star::lang::Locale aLocale(MsLangId::convertLanguageToLocale(rProperty.getLanguageType()));
1323cdf0e10cSrcweir 			const bool bWordLineMode(rFont.IsWordLineMode());
1324cdf0e10cSrcweir 
1325cdf0e10cSrcweir 			const bool bDecoratedIsNeeded(
1326cdf0e10cSrcweir 				   UNDERLINE_NONE != rFont.GetOverline()
1327cdf0e10cSrcweir 				|| UNDERLINE_NONE != rFont.GetUnderline()
1328cdf0e10cSrcweir 				|| STRIKEOUT_NONE != rFont.GetStrikeout()
1329cdf0e10cSrcweir 				|| EMPHASISMARK_NONE != (rFont.GetEmphasisMark() & EMPHASISMARK_STYLE)
1330cdf0e10cSrcweir 				|| RELIEF_NONE != rFont.GetRelief()
1331cdf0e10cSrcweir 				|| rFont.IsShadow()
1332cdf0e10cSrcweir                 || bWordLineMode);
1333cdf0e10cSrcweir 
1334cdf0e10cSrcweir 			if(bDecoratedIsNeeded)
1335cdf0e10cSrcweir 			{
1336cdf0e10cSrcweir                 // prepare overline, underline and srikeout data
1337cdf0e10cSrcweir                 const drawinglayer::primitive2d::TextLine eFontOverline(drawinglayer::primitive2d::mapFontUnderlineToTextLine(rFont.GetOverline()));
1338cdf0e10cSrcweir                 const drawinglayer::primitive2d::TextLine eFontUnderline(drawinglayer::primitive2d::mapFontUnderlineToTextLine(rFont.GetUnderline()));
1339cdf0e10cSrcweir 				const drawinglayer::primitive2d::TextStrikeout eTextStrikeout(drawinglayer::primitive2d::mapFontStrikeoutToTextStrikeout(rFont.GetStrikeout()));
1340cdf0e10cSrcweir 
1341cdf0e10cSrcweir                 // check UndelineAbove
1342cdf0e10cSrcweir 				const bool bUnderlineAbove(drawinglayer::primitive2d::TEXT_LINE_NONE != eFontUnderline && isUnderlineAbove(rFont));
1343cdf0e10cSrcweir 
1344cdf0e10cSrcweir 				// prepare emphasis mark data
1345cdf0e10cSrcweir 				drawinglayer::primitive2d::TextEmphasisMark eTextEmphasisMark(drawinglayer::primitive2d::TEXT_EMPHASISMARK_NONE);
1346cdf0e10cSrcweir 
1347cdf0e10cSrcweir 				switch(rFont.GetEmphasisMark() & EMPHASISMARK_STYLE)
1348cdf0e10cSrcweir 				{
1349cdf0e10cSrcweir 					case EMPHASISMARK_DOT : eTextEmphasisMark = drawinglayer::primitive2d::TEXT_EMPHASISMARK_DOT; break;
1350cdf0e10cSrcweir 					case EMPHASISMARK_CIRCLE : eTextEmphasisMark = drawinglayer::primitive2d::TEXT_EMPHASISMARK_CIRCLE; break;
1351cdf0e10cSrcweir 					case EMPHASISMARK_DISC : eTextEmphasisMark = drawinglayer::primitive2d::TEXT_EMPHASISMARK_DISC; break;
1352cdf0e10cSrcweir 					case EMPHASISMARK_ACCENT : eTextEmphasisMark = drawinglayer::primitive2d::TEXT_EMPHASISMARK_ACCENT; break;
1353cdf0e10cSrcweir 				}
1354cdf0e10cSrcweir 
1355cdf0e10cSrcweir 				const bool bEmphasisMarkAbove(rFont.GetEmphasisMark() & EMPHASISMARK_POS_ABOVE);
1356cdf0e10cSrcweir 				const bool bEmphasisMarkBelow(rFont.GetEmphasisMark() & EMPHASISMARK_POS_BELOW);
1357cdf0e10cSrcweir 
1358cdf0e10cSrcweir 				// prepare font relief data
1359cdf0e10cSrcweir 				drawinglayer::primitive2d::TextRelief eTextRelief(drawinglayer::primitive2d::TEXT_RELIEF_NONE);
1360cdf0e10cSrcweir 
1361cdf0e10cSrcweir 				switch(rFont.GetRelief())
1362cdf0e10cSrcweir 				{
1363cdf0e10cSrcweir 					case RELIEF_EMBOSSED : eTextRelief = drawinglayer::primitive2d::TEXT_RELIEF_EMBOSSED; break;
1364cdf0e10cSrcweir 					case RELIEF_ENGRAVED : eTextRelief = drawinglayer::primitive2d::TEXT_RELIEF_ENGRAVED; break;
1365cdf0e10cSrcweir 					default : break; // RELIEF_NONE, FontRelief_FORCE_EQUAL_SIZE
1366cdf0e10cSrcweir 				}
1367cdf0e10cSrcweir 
1368cdf0e10cSrcweir 				// prepare shadow/outline data
1369cdf0e10cSrcweir 				const bool bShadow(rFont.IsShadow());
1370cdf0e10cSrcweir 
1371cdf0e10cSrcweir 				// TextDecoratedPortionPrimitive2D is needed, create one
1372cdf0e10cSrcweir                 pResult = new drawinglayer::primitive2d::TextDecoratedPortionPrimitive2D(
1373cdf0e10cSrcweir 
1374cdf0e10cSrcweir 					// attributes for TextSimplePortionPrimitive2D
1375cdf0e10cSrcweir 					aTextTransform,
1376cdf0e10cSrcweir 					rText,
1377cdf0e10cSrcweir 					nTextStart,
1378cdf0e10cSrcweir 					nTextLength,
1379cdf0e10cSrcweir 					rDXArray,
1380cdf0e10cSrcweir 					aFontAttribute,
1381cdf0e10cSrcweir 					aLocale,
1382cdf0e10cSrcweir 					aFontColor,
1383cdf0e10cSrcweir 
1384cdf0e10cSrcweir 					// attributes for TextDecoratedPortionPrimitive2D
1385cdf0e10cSrcweir 					rProperty.getOverlineColorActive() ? rProperty.getOverlineColor() : aFontColor,
1386cdf0e10cSrcweir 					rProperty.getTextLineColorActive() ? rProperty.getTextLineColor() : aFontColor,
1387cdf0e10cSrcweir                     eFontOverline,
1388cdf0e10cSrcweir                     eFontUnderline,
1389cdf0e10cSrcweir 					bUnderlineAbove,
1390cdf0e10cSrcweir 					eTextStrikeout,
1391cdf0e10cSrcweir 					bWordLineMode,
1392cdf0e10cSrcweir 					eTextEmphasisMark,
1393cdf0e10cSrcweir 					bEmphasisMarkAbove,
1394cdf0e10cSrcweir 					bEmphasisMarkBelow,
1395cdf0e10cSrcweir 					eTextRelief,
1396cdf0e10cSrcweir 					bShadow);
1397cdf0e10cSrcweir 			}
1398cdf0e10cSrcweir 			else
1399cdf0e10cSrcweir 			{
1400cdf0e10cSrcweir 				// TextSimplePortionPrimitive2D is enough
1401cdf0e10cSrcweir 				pResult = new drawinglayer::primitive2d::TextSimplePortionPrimitive2D(
1402cdf0e10cSrcweir 					aTextTransform,
1403cdf0e10cSrcweir 					rText,
1404cdf0e10cSrcweir 					nTextStart,
1405cdf0e10cSrcweir 					nTextLength,
1406cdf0e10cSrcweir 					rDXArray,
1407cdf0e10cSrcweir 					aFontAttribute,
1408cdf0e10cSrcweir 					aLocale,
1409cdf0e10cSrcweir 					aFontColor);
1410cdf0e10cSrcweir 			}
1411cdf0e10cSrcweir 		}
1412cdf0e10cSrcweir 
1413cdf0e10cSrcweir         if(pResult && rProperty.getTextFillColorActive())
1414cdf0e10cSrcweir         {
1415cdf0e10cSrcweir             // text background is requested, add and encapsulate both to new primitive
1416cdf0e10cSrcweir             drawinglayer::primitive2d::TextLayouterDevice aTextLayouterDevice;
1417cdf0e10cSrcweir             aTextLayouterDevice.setFont(rFont);
1418cdf0e10cSrcweir 
1419cdf0e10cSrcweir 			// get text width
1420cdf0e10cSrcweir 			double fTextWidth(0.0);
1421cdf0e10cSrcweir 
1422cdf0e10cSrcweir 			if(rDXArray.empty())
1423cdf0e10cSrcweir 			{
1424cdf0e10cSrcweir 				fTextWidth = aTextLayouterDevice.getTextWidth(rText, nTextStart, nTextLength);
1425cdf0e10cSrcweir 			}
1426cdf0e10cSrcweir 			else
1427cdf0e10cSrcweir 			{
1428cdf0e10cSrcweir 				fTextWidth = rDXArray.back();
1429cdf0e10cSrcweir 			}
1430cdf0e10cSrcweir 
1431cdf0e10cSrcweir             if(basegfx::fTools::more(fTextWidth, 0.0))
1432cdf0e10cSrcweir             {
1433cdf0e10cSrcweir                 // build text range
1434cdf0e10cSrcweir                 const basegfx::B2DRange aTextRange(
1435cdf0e10cSrcweir                     0.0, -aTextLayouterDevice.getFontAscent(),
1436cdf0e10cSrcweir                     fTextWidth, aTextLayouterDevice.getFontDescent());
1437cdf0e10cSrcweir 
1438cdf0e10cSrcweir                 // create Transform
1439cdf0e10cSrcweir 			    basegfx::B2DHomMatrix aTextTransform;
1440cdf0e10cSrcweir 
1441cdf0e10cSrcweir                 aTextTransform.translate(aAlignmentOffset.getX(), aAlignmentOffset.getY());
1442cdf0e10cSrcweir 
1443cdf0e10cSrcweir                 if(rFont.GetOrientation())
1444cdf0e10cSrcweir 			    {
1445cdf0e10cSrcweir 				    aTextTransform.rotate(-rFont.GetOrientation() * F_PI1800);
1446cdf0e10cSrcweir 			    }
1447cdf0e10cSrcweir 
1448cdf0e10cSrcweir                 aTextTransform.translate(rTextStartPosition.X(), rTextStartPosition.Y());
1449cdf0e10cSrcweir 
1450cdf0e10cSrcweir                 // prepare Primitive2DSequence, put text in foreground
1451cdf0e10cSrcweir                 drawinglayer::primitive2d::Primitive2DSequence aSequence(2);
1452cdf0e10cSrcweir                 aSequence[1] = drawinglayer::primitive2d::Primitive2DReference(pResult);
1453cdf0e10cSrcweir 
1454cdf0e10cSrcweir                 // prepare filled polygon
1455cdf0e10cSrcweir                 basegfx::B2DPolygon aOutline(basegfx::tools::createPolygonFromRect(aTextRange));
1456cdf0e10cSrcweir 		        aOutline.transform(aTextTransform);
1457cdf0e10cSrcweir 
1458cdf0e10cSrcweir                 aSequence[0] = drawinglayer::primitive2d::Primitive2DReference(
1459cdf0e10cSrcweir 				    new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
1460cdf0e10cSrcweir                         basegfx::B2DPolyPolygon(aOutline),
1461cdf0e10cSrcweir                         rProperty.getTextFillColor()));
1462cdf0e10cSrcweir 
1463cdf0e10cSrcweir                 // set as group at pResult
1464cdf0e10cSrcweir 			    pResult = new drawinglayer::primitive2d::GroupPrimitive2D(aSequence);
1465cdf0e10cSrcweir             }
1466cdf0e10cSrcweir         }
1467cdf0e10cSrcweir 
1468cdf0e10cSrcweir 		if(pResult)
1469cdf0e10cSrcweir 		{
1470cdf0e10cSrcweir 			// add created text primitive to target
1471cdf0e10cSrcweir 			if(rProperty.getTransformation().isIdentity())
1472cdf0e10cSrcweir 			{
1473cdf0e10cSrcweir 		        rTarget.append(pResult);
1474cdf0e10cSrcweir 			}
1475cdf0e10cSrcweir 			else
1476cdf0e10cSrcweir 			{
1477cdf0e10cSrcweir 				// when a transformation is set, embed to it
1478cdf0e10cSrcweir 	            const drawinglayer::primitive2d::Primitive2DReference aReference(pResult);
1479cdf0e10cSrcweir 
1480cdf0e10cSrcweir 				rTarget.append(
1481cdf0e10cSrcweir 					new drawinglayer::primitive2d::TransformPrimitive2D(
1482cdf0e10cSrcweir 						rProperty.getTransformation(),
1483cdf0e10cSrcweir 						drawinglayer::primitive2d::Primitive2DSequence(&aReference, 1)));
1484cdf0e10cSrcweir 			}
1485cdf0e10cSrcweir 		}
1486cdf0e10cSrcweir 	}
1487cdf0e10cSrcweir 
1488cdf0e10cSrcweir 	/** helper which takes complete care for creating the needed textLine primitives */
1489cdf0e10cSrcweir 	void proccessMetaTextLineAction(
1490cdf0e10cSrcweir 		const MetaTextLineAction& rAction,
1491cdf0e10cSrcweir 		TargetHolder& rTarget,
1492cdf0e10cSrcweir 		PropertyHolder& rProperty)
1493cdf0e10cSrcweir 	{
1494cdf0e10cSrcweir 		const double fLineWidth(fabs((double)rAction.GetWidth()));
1495cdf0e10cSrcweir 
1496cdf0e10cSrcweir 		if(fLineWidth > 0.0)
1497cdf0e10cSrcweir 		{
1498cdf0e10cSrcweir 		    const drawinglayer::primitive2d::TextLine aOverlineMode(drawinglayer::primitive2d::mapFontUnderlineToTextLine(rAction.GetOverline()));
1499cdf0e10cSrcweir 		    const drawinglayer::primitive2d::TextLine aUnderlineMode(drawinglayer::primitive2d::mapFontUnderlineToTextLine(rAction.GetUnderline()));
1500cdf0e10cSrcweir 			const drawinglayer::primitive2d::TextStrikeout aTextStrikeout(drawinglayer::primitive2d::mapFontStrikeoutToTextStrikeout(rAction.GetStrikeout()));
1501cdf0e10cSrcweir 
1502cdf0e10cSrcweir 			const bool bOverlineUsed(drawinglayer::primitive2d::TEXT_LINE_NONE != aOverlineMode);
1503cdf0e10cSrcweir 			const bool bUnderlineUsed(drawinglayer::primitive2d::TEXT_LINE_NONE != aUnderlineMode);
1504cdf0e10cSrcweir 			const bool bStrikeoutUsed(drawinglayer::primitive2d::TEXT_STRIKEOUT_NONE != aTextStrikeout);
1505cdf0e10cSrcweir 
1506cdf0e10cSrcweir 			if(bUnderlineUsed || bStrikeoutUsed || bOverlineUsed)
1507cdf0e10cSrcweir 			{
1508cdf0e10cSrcweir 				std::vector< drawinglayer::primitive2d::BasePrimitive2D* > aTargetVector;
1509cdf0e10cSrcweir 				basegfx::B2DVector aAlignmentOffset(0.0, 0.0);
1510cdf0e10cSrcweir 				drawinglayer::attribute::FontAttribute aFontAttribute;
1511cdf0e10cSrcweir 				basegfx::B2DHomMatrix aTextTransform;
1512cdf0e10cSrcweir 
1513cdf0e10cSrcweir 				// fill parameters derived from current font
1514cdf0e10cSrcweir 				createFontAttributeTransformAndAlignment(
1515cdf0e10cSrcweir 					aFontAttribute,
1516cdf0e10cSrcweir 					aTextTransform,
1517cdf0e10cSrcweir 					aAlignmentOffset,
1518cdf0e10cSrcweir 					rProperty);
1519cdf0e10cSrcweir 
1520cdf0e10cSrcweir 				// add TextStartPosition
1521cdf0e10cSrcweir 				aTextTransform.translate(rAction.GetStartPoint().X(), rAction.GetStartPoint().Y());
1522cdf0e10cSrcweir 
1523cdf0e10cSrcweir 				// prepare TextLayouter (used in most cases)
1524cdf0e10cSrcweir 				drawinglayer::primitive2d::TextLayouterDevice aTextLayouter;
1525cdf0e10cSrcweir 				aTextLayouter.setFont(rProperty.getFont());
1526cdf0e10cSrcweir 
1527cdf0e10cSrcweir 				if(bOverlineUsed)
1528cdf0e10cSrcweir 				{
1529cdf0e10cSrcweir 					// create primitive geometry for overline
1530cdf0e10cSrcweir 					aTargetVector.push_back(
1531cdf0e10cSrcweir 						new drawinglayer::primitive2d::TextLinePrimitive2D(
1532cdf0e10cSrcweir 							aTextTransform,
1533cdf0e10cSrcweir 							fLineWidth,
1534cdf0e10cSrcweir 							aTextLayouter.getOverlineOffset(),
1535cdf0e10cSrcweir 							aTextLayouter.getOverlineHeight(),
1536cdf0e10cSrcweir 							aOverlineMode,
1537cdf0e10cSrcweir 							rProperty.getOverlineColor()));
1538cdf0e10cSrcweir 				}
1539cdf0e10cSrcweir 
1540cdf0e10cSrcweir 				if(bUnderlineUsed)
1541cdf0e10cSrcweir 				{
1542cdf0e10cSrcweir 					// create primitive geometry for underline
1543cdf0e10cSrcweir 					aTargetVector.push_back(
1544cdf0e10cSrcweir 						new drawinglayer::primitive2d::TextLinePrimitive2D(
1545cdf0e10cSrcweir 							aTextTransform,
1546cdf0e10cSrcweir 							fLineWidth,
1547cdf0e10cSrcweir 							aTextLayouter.getUnderlineOffset(),
1548cdf0e10cSrcweir 							aTextLayouter.getUnderlineHeight(),
1549cdf0e10cSrcweir 							aUnderlineMode,
1550cdf0e10cSrcweir 							rProperty.getTextLineColor()));
1551cdf0e10cSrcweir 				}
1552cdf0e10cSrcweir 
1553cdf0e10cSrcweir 				if(bStrikeoutUsed)
1554cdf0e10cSrcweir 				{
1555cdf0e10cSrcweir 					// create primitive geometry for strikeout
1556cdf0e10cSrcweir 					if(drawinglayer::primitive2d::TEXT_STRIKEOUT_SLASH == aTextStrikeout
1557cdf0e10cSrcweir 						|| drawinglayer::primitive2d::TEXT_STRIKEOUT_X == aTextStrikeout)
1558cdf0e10cSrcweir 					{
1559cdf0e10cSrcweir 						// strikeout with character
1560cdf0e10cSrcweir 						const sal_Unicode aStrikeoutChar(
1561cdf0e10cSrcweir 							drawinglayer::primitive2d::TEXT_STRIKEOUT_SLASH == aTextStrikeout ? '/' : 'X');
1562cdf0e10cSrcweir 					    const com::sun::star::lang::Locale aLocale(MsLangId::convertLanguageToLocale(
1563cdf0e10cSrcweir 							rProperty.getLanguageType()));
1564cdf0e10cSrcweir 
1565cdf0e10cSrcweir 						aTargetVector.push_back(
1566cdf0e10cSrcweir 							new drawinglayer::primitive2d::TextCharacterStrikeoutPrimitive2D(
1567cdf0e10cSrcweir 								aTextTransform,
1568cdf0e10cSrcweir 								fLineWidth,
1569cdf0e10cSrcweir 								rProperty.getTextColor(),
1570cdf0e10cSrcweir 								aStrikeoutChar,
1571cdf0e10cSrcweir 								aFontAttribute,
1572cdf0e10cSrcweir 								aLocale));
1573cdf0e10cSrcweir 					}
1574cdf0e10cSrcweir 					else
1575cdf0e10cSrcweir 					{
1576cdf0e10cSrcweir 						// strikeout with geometry
1577cdf0e10cSrcweir 						aTargetVector.push_back(
1578cdf0e10cSrcweir 							new drawinglayer::primitive2d::TextGeometryStrikeoutPrimitive2D(
1579cdf0e10cSrcweir 								aTextTransform,
1580cdf0e10cSrcweir 								fLineWidth,
1581cdf0e10cSrcweir 								rProperty.getTextColor(),
1582cdf0e10cSrcweir 								aTextLayouter.getUnderlineHeight(),
1583cdf0e10cSrcweir 								aTextLayouter.getStrikeoutOffset(),
1584cdf0e10cSrcweir 								aTextStrikeout));
1585cdf0e10cSrcweir 					}
1586cdf0e10cSrcweir 				}
1587cdf0e10cSrcweir 
1588cdf0e10cSrcweir 				if(aTargetVector.size())
1589cdf0e10cSrcweir 				{
1590cdf0e10cSrcweir 					// add created text primitive to target
1591cdf0e10cSrcweir 					if(rProperty.getTransformation().isIdentity())
1592cdf0e10cSrcweir 					{
1593cdf0e10cSrcweir 						for(sal_uInt32 a(0); a < aTargetVector.size(); a++)
1594cdf0e10cSrcweir 						{
1595cdf0e10cSrcweir 							rTarget.append(aTargetVector[a]);
1596cdf0e10cSrcweir 						}
1597cdf0e10cSrcweir 					}
1598cdf0e10cSrcweir 					else
1599cdf0e10cSrcweir 					{
1600cdf0e10cSrcweir 						// when a transformation is set, embed to it
1601cdf0e10cSrcweir 						drawinglayer::primitive2d::Primitive2DSequence xTargets(aTargetVector.size());
1602cdf0e10cSrcweir 
1603cdf0e10cSrcweir 						for(sal_uInt32 a(0); a < aTargetVector.size(); a++)
1604cdf0e10cSrcweir 						{
1605cdf0e10cSrcweir 							xTargets[a] = drawinglayer::primitive2d::Primitive2DReference(aTargetVector[a]);
1606cdf0e10cSrcweir 						}
1607cdf0e10cSrcweir 
1608cdf0e10cSrcweir 						rTarget.append(
1609cdf0e10cSrcweir 							new drawinglayer::primitive2d::TransformPrimitive2D(
1610cdf0e10cSrcweir 								rProperty.getTransformation(),
1611cdf0e10cSrcweir 								xTargets));
1612cdf0e10cSrcweir 					}
1613cdf0e10cSrcweir 				}
1614cdf0e10cSrcweir 			}
1615cdf0e10cSrcweir 		}
1616cdf0e10cSrcweir 
1617cdf0e10cSrcweir 	}
1618cdf0e10cSrcweir 
1619cdf0e10cSrcweir 	/** This is the main interpreter method. It is designed to handle the given Metafile
1620cdf0e10cSrcweir 		completely inside the given context and target. It may use and modify the context and
1621cdf0e10cSrcweir 		target. This design allows to call itself recursively wich adapted contexts and
1622cdf0e10cSrcweir 		targets as e.g. needed for the META_FLOATTRANSPARENT_ACTION where the content is expressed
1623cdf0e10cSrcweir 		as a metafile as sub-content.
1624cdf0e10cSrcweir 
1625cdf0e10cSrcweir 		This interpreter is as free of VCL functionality as possible. It uses VCL data classes
1626cdf0e10cSrcweir 		(else reading the data would not be possible), but e.g. does NOT use a local OutputDevice
1627cdf0e10cSrcweir 		as most other MetaFile interpreters/exporters do to hold and work with the current context.
1628cdf0e10cSrcweir 		This is necessary to be able to get away from the strong internal VCL-binding.
1629cdf0e10cSrcweir 
1630cdf0e10cSrcweir 		It tries to combine e.g. pixel and/or point actions and to stitch together single line primitives
1631cdf0e10cSrcweir 		where possible (which is not trivial with the possible line geometry definitions).
1632cdf0e10cSrcweir 
1633cdf0e10cSrcweir 		It tries to handle clipping no longer as Regions and spans of Rectangles, but as PolyPolygon
1634cdf0e10cSrcweir 		ClipRegions with (where possible) high precision by using the best possible data quality
1635cdf0e10cSrcweir 		from the Region. The Region is unavoidable as data container, but nowadays allows the transport
1636cdf0e10cSrcweir 		of Polygon-based clip regions. Where this is not used, a Polygon is constructed from the
1637cdf0e10cSrcweir 		Region ranges. All primitive clipping uses the MaskPrimitive2D with Polygon-based clipping.
1638cdf0e10cSrcweir 
1639cdf0e10cSrcweir 		I have marked the single MetaActions with:
1640cdf0e10cSrcweir 
1641cdf0e10cSrcweir 		SIMPLE, DONE:
1642cdf0e10cSrcweir 		Simple, e.g nothing to do or value setting in the context
1643cdf0e10cSrcweir 
1644cdf0e10cSrcweir 		CHECKED, WORKS WELL:
1645cdf0e10cSrcweir 		Thoroughly tested with extra written test code which created a replacement
1646cdf0e10cSrcweir 		Metafile just to test this action in various combinations
1647cdf0e10cSrcweir 
1648cdf0e10cSrcweir 		NEEDS IMPLEMENTATION:
1649cdf0e10cSrcweir 		Not implemented and asserted, but also no usage found, neither in own Metafile
1650cdf0e10cSrcweir 		creations, nor in EMF/WMF imports (checked with a whole bunch of critical EMF/WMF
1651cdf0e10cSrcweir 		bugdocs)
1652cdf0e10cSrcweir 
1653cdf0e10cSrcweir 		For more commens, see the single action implementations.
1654cdf0e10cSrcweir 	*/
1655cdf0e10cSrcweir     void interpretMetafile(
1656cdf0e10cSrcweir         const GDIMetaFile& rMetaFile,
1657cdf0e10cSrcweir         TargetHolders& rTargetHolders,
1658cdf0e10cSrcweir         PropertyHolders& rPropertyHolders,
1659cdf0e10cSrcweir 		const drawinglayer::geometry::ViewInformation2D& rViewInformation)
1660cdf0e10cSrcweir     {
1661cdf0e10cSrcweir         const sal_uInt32 nCount(rMetaFile.GetActionCount());
1662cdf0e10cSrcweir 
1663cdf0e10cSrcweir         for(sal_uInt32 nAction(0); nAction < nCount; nAction++)
1664cdf0e10cSrcweir         {
1665cdf0e10cSrcweir             MetaAction* pAction = rMetaFile.GetAction(nAction);
1666cdf0e10cSrcweir 
1667cdf0e10cSrcweir             switch(pAction->GetType())
1668cdf0e10cSrcweir             {
1669cdf0e10cSrcweir                 case META_NULL_ACTION :
1670cdf0e10cSrcweir                 {
1671cdf0e10cSrcweir 					/** SIMPLE, DONE */
1672cdf0e10cSrcweir                     break;
1673cdf0e10cSrcweir                 }
1674cdf0e10cSrcweir                 case META_PIXEL_ACTION :
1675cdf0e10cSrcweir                 {
1676cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
1677cdf0e10cSrcweir     			    std::vector< basegfx::B2DPoint > aPositions;
1678cdf0e10cSrcweir                     Color aLastColor(COL_BLACK);
1679cdf0e10cSrcweir 
1680cdf0e10cSrcweir                     while(META_PIXEL_ACTION == pAction->GetType() && nAction < nCount)
1681cdf0e10cSrcweir                     {
1682cdf0e10cSrcweir                         const MetaPixelAction* pA = (const MetaPixelAction*)pAction;
1683cdf0e10cSrcweir 
1684cdf0e10cSrcweir                         if(pA->GetColor() != aLastColor)
1685cdf0e10cSrcweir                         {
1686cdf0e10cSrcweir                             if(aPositions.size())
1687cdf0e10cSrcweir                             {
1688cdf0e10cSrcweir                                 createPointArrayPrimitive(aPositions, rTargetHolders.Current(), rPropertyHolders.Current(), aLastColor.getBColor());
1689cdf0e10cSrcweir                                 aPositions.clear();
1690cdf0e10cSrcweir                             }
1691cdf0e10cSrcweir 
1692cdf0e10cSrcweir                             aLastColor = pA->GetColor();
1693cdf0e10cSrcweir                         }
1694cdf0e10cSrcweir 
1695cdf0e10cSrcweir                         const Point& rPoint = pA->GetPoint();
1696cdf0e10cSrcweir                         aPositions.push_back(basegfx::B2DPoint(rPoint.X(), rPoint.Y()));
1697cdf0e10cSrcweir 						nAction++; if(nAction < nCount) pAction = rMetaFile.GetAction(nAction);
1698cdf0e10cSrcweir                     }
1699cdf0e10cSrcweir 
1700cdf0e10cSrcweir                     nAction--;
1701cdf0e10cSrcweir 
1702cdf0e10cSrcweir                     if(aPositions.size())
1703cdf0e10cSrcweir                     {
1704cdf0e10cSrcweir                         createPointArrayPrimitive(aPositions, rTargetHolders.Current(), rPropertyHolders.Current(), aLastColor.getBColor());
1705cdf0e10cSrcweir                     }
1706cdf0e10cSrcweir 
1707cdf0e10cSrcweir                     break;
1708cdf0e10cSrcweir                 }
1709cdf0e10cSrcweir                 case META_POINT_ACTION :
1710cdf0e10cSrcweir                 {
1711cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
1712cdf0e10cSrcweir                     if(rPropertyHolders.Current().getLineColorActive())
1713cdf0e10cSrcweir                     {
1714cdf0e10cSrcweir         			    std::vector< basegfx::B2DPoint > aPositions;
1715cdf0e10cSrcweir 
1716cdf0e10cSrcweir                         while(META_POINT_ACTION == pAction->GetType() && nAction < nCount)
1717cdf0e10cSrcweir                         {
1718cdf0e10cSrcweir                             const MetaPointAction* pA = (const MetaPointAction*)pAction;
1719cdf0e10cSrcweir                             const Point& rPoint = pA->GetPoint();
1720cdf0e10cSrcweir                             aPositions.push_back(basegfx::B2DPoint(rPoint.X(), rPoint.Y()));
1721cdf0e10cSrcweir 							nAction++; if(nAction < nCount) pAction = rMetaFile.GetAction(nAction);
1722cdf0e10cSrcweir                         }
1723cdf0e10cSrcweir 
1724cdf0e10cSrcweir                         nAction--;
1725cdf0e10cSrcweir 
1726cdf0e10cSrcweir                         if(aPositions.size())
1727cdf0e10cSrcweir                         {
1728cdf0e10cSrcweir                             createPointArrayPrimitive(aPositions, rTargetHolders.Current(), rPropertyHolders.Current(), rPropertyHolders.Current().getLineColor());
1729cdf0e10cSrcweir                         }
1730cdf0e10cSrcweir                     }
1731cdf0e10cSrcweir 
1732cdf0e10cSrcweir                     break;
1733cdf0e10cSrcweir                 }
1734cdf0e10cSrcweir                 case META_LINE_ACTION :
1735cdf0e10cSrcweir                 {
1736cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
1737cdf0e10cSrcweir                     if(rPropertyHolders.Current().getLineColorActive())
1738cdf0e10cSrcweir                     {
1739cdf0e10cSrcweir                         basegfx::B2DPolygon aLinePolygon;
1740cdf0e10cSrcweir                         LineInfo aLineInfo;
1741cdf0e10cSrcweir 
1742cdf0e10cSrcweir                         while(META_LINE_ACTION == pAction->GetType() && nAction < nCount)
1743cdf0e10cSrcweir                         {
1744cdf0e10cSrcweir                             const MetaLineAction* pA = (const MetaLineAction*)pAction;
1745cdf0e10cSrcweir                             const Point& rStartPoint = pA->GetStartPoint();
1746cdf0e10cSrcweir                             const Point& rEndPoint = pA->GetEndPoint();
1747cdf0e10cSrcweir                             const basegfx::B2DPoint aStart(rStartPoint.X(), rStartPoint.Y());
1748cdf0e10cSrcweir                             const basegfx::B2DPoint aEnd(rEndPoint.X(), rEndPoint.Y());
1749cdf0e10cSrcweir 
1750cdf0e10cSrcweir                             if(aLinePolygon.count())
1751cdf0e10cSrcweir                             {
1752cdf0e10cSrcweir                                 if(pA->GetLineInfo() == aLineInfo
1753cdf0e10cSrcweir                                     && aStart == aLinePolygon.getB2DPoint(aLinePolygon.count() - 1))
1754cdf0e10cSrcweir                                 {
1755cdf0e10cSrcweir                                     aLinePolygon.append(aEnd);
1756cdf0e10cSrcweir                                 }
1757cdf0e10cSrcweir                                 else
1758cdf0e10cSrcweir                                 {
1759cdf0e10cSrcweir 									aLineInfo.SetLineJoin(basegfx::B2DLINEJOIN_NONE); // It were lines; force to NONE
1760cdf0e10cSrcweir                                     createLinePrimitive(aLinePolygon, aLineInfo, rTargetHolders.Current(), rPropertyHolders.Current());
1761cdf0e10cSrcweir                                     aLinePolygon.clear();
1762cdf0e10cSrcweir 	                                aLineInfo = pA->GetLineInfo();
1763cdf0e10cSrcweir 									aLinePolygon.append(aStart);
1764cdf0e10cSrcweir 									aLinePolygon.append(aEnd);
1765cdf0e10cSrcweir                                 }
1766cdf0e10cSrcweir                             }
1767cdf0e10cSrcweir                             else
1768cdf0e10cSrcweir                             {
1769cdf0e10cSrcweir                                 aLineInfo = pA->GetLineInfo();
1770cdf0e10cSrcweir                                 aLinePolygon.append(aStart);
1771cdf0e10cSrcweir                                 aLinePolygon.append(aEnd);
1772cdf0e10cSrcweir                             }
1773cdf0e10cSrcweir 
1774cdf0e10cSrcweir 							nAction++; if(nAction < nCount) pAction = rMetaFile.GetAction(nAction);
1775cdf0e10cSrcweir                         }
1776cdf0e10cSrcweir 
1777cdf0e10cSrcweir                         nAction--;
1778cdf0e10cSrcweir 
1779cdf0e10cSrcweir                         if(aLinePolygon.count())
1780cdf0e10cSrcweir                         {
1781cdf0e10cSrcweir 							aLineInfo.SetLineJoin(basegfx::B2DLINEJOIN_NONE); // It were lines; force to NONE
1782cdf0e10cSrcweir                             createLinePrimitive(aLinePolygon, aLineInfo, rTargetHolders.Current(), rPropertyHolders.Current());
1783cdf0e10cSrcweir                         }
1784cdf0e10cSrcweir                     }
1785cdf0e10cSrcweir 
1786cdf0e10cSrcweir                     break;
1787cdf0e10cSrcweir                 }
1788cdf0e10cSrcweir                 case META_RECT_ACTION :
1789cdf0e10cSrcweir                 {
1790cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
1791cdf0e10cSrcweir 					if(rPropertyHolders.Current().getLineOrFillActive())
1792cdf0e10cSrcweir 					{
1793cdf0e10cSrcweir                         const MetaRectAction* pA = (const MetaRectAction*)pAction;
1794cdf0e10cSrcweir 						const Rectangle& rRectangle = pA->GetRect();
1795cdf0e10cSrcweir 
1796cdf0e10cSrcweir 						if(!rRectangle.IsEmpty())
1797cdf0e10cSrcweir 						{
1798cdf0e10cSrcweir 							const basegfx::B2DRange aRange(rRectangle.Left(), rRectangle.Top(), rRectangle.Right(), rRectangle.Bottom());
1799cdf0e10cSrcweir 
1800cdf0e10cSrcweir 							if(!aRange.isEmpty())
1801cdf0e10cSrcweir 							{
1802cdf0e10cSrcweir 								const basegfx::B2DPolygon aOutline(basegfx::tools::createPolygonFromRect(aRange));
1803cdf0e10cSrcweir 								createHairlineAndFillPrimitive(aOutline, rTargetHolders.Current(), rPropertyHolders.Current());
1804cdf0e10cSrcweir 							}
1805cdf0e10cSrcweir 						}
1806cdf0e10cSrcweir 					}
1807cdf0e10cSrcweir 
1808cdf0e10cSrcweir                     break;
1809cdf0e10cSrcweir                 }
1810cdf0e10cSrcweir                 case META_ROUNDRECT_ACTION :
1811cdf0e10cSrcweir                 {
1812cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
1813cdf0e10cSrcweir 					/**	The original OutputDevice::DrawRect paints nothing when nHor or nVer is zero; but just
1814cdf0e10cSrcweir 						because the tools::Polygon operator creating the rounding does produce nonsense. I assume
1815cdf0e10cSrcweir 						this an error and create an unrounded rectangle in that case (implicit in
1816cdf0e10cSrcweir 						createPolygonFromRect)
1817cdf0e10cSrcweir 					 */
1818cdf0e10cSrcweir 					if(rPropertyHolders.Current().getLineOrFillActive())
1819cdf0e10cSrcweir 					{
1820cdf0e10cSrcweir                         const MetaRoundRectAction* pA = (const MetaRoundRectAction*)pAction;
1821cdf0e10cSrcweir 						const Rectangle& rRectangle = pA->GetRect();
1822cdf0e10cSrcweir 
1823cdf0e10cSrcweir 						if(!rRectangle.IsEmpty())
1824cdf0e10cSrcweir 						{
1825cdf0e10cSrcweir 							const basegfx::B2DRange aRange(rRectangle.Left(), rRectangle.Top(), rRectangle.Right(), rRectangle.Bottom());
1826cdf0e10cSrcweir 
1827cdf0e10cSrcweir 							if(!aRange.isEmpty())
1828cdf0e10cSrcweir 							{
1829cdf0e10cSrcweir 								const sal_uInt32 nHor(pA->GetHorzRound());
1830cdf0e10cSrcweir 								const sal_uInt32 nVer(pA->GetVertRound());
1831cdf0e10cSrcweir 								basegfx::B2DPolygon aOutline;
1832cdf0e10cSrcweir 
1833cdf0e10cSrcweir 								if(nHor || nVer)
1834cdf0e10cSrcweir 								{
1835cdf0e10cSrcweir 									double fRadiusX((nHor * 2.0) / (aRange.getWidth() > 0.0 ? aRange.getWidth() : 1.0));
1836cdf0e10cSrcweir 									double fRadiusY((nVer * 2.0) / (aRange.getHeight() > 0.0 ? aRange.getHeight() : 1.0));
1837cdf0e10cSrcweir 									fRadiusX = std::max(0.0, std::min(1.0, fRadiusX));
1838cdf0e10cSrcweir 									fRadiusY = std::max(0.0, std::min(1.0, fRadiusY));
1839cdf0e10cSrcweir 
1840cdf0e10cSrcweir 									aOutline = basegfx::tools::createPolygonFromRect(aRange, fRadiusX, fRadiusY);
1841cdf0e10cSrcweir 								}
1842cdf0e10cSrcweir 								else
1843cdf0e10cSrcweir 								{
1844cdf0e10cSrcweir 									aOutline = basegfx::tools::createPolygonFromRect(aRange);
1845cdf0e10cSrcweir 								}
1846cdf0e10cSrcweir 
1847cdf0e10cSrcweir 								createHairlineAndFillPrimitive(aOutline, rTargetHolders.Current(), rPropertyHolders.Current());
1848cdf0e10cSrcweir 							}
1849cdf0e10cSrcweir 						}
1850cdf0e10cSrcweir 					}
1851cdf0e10cSrcweir 
1852cdf0e10cSrcweir                     break;
1853cdf0e10cSrcweir                 }
1854cdf0e10cSrcweir                 case META_ELLIPSE_ACTION :
1855cdf0e10cSrcweir                 {
1856cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
1857cdf0e10cSrcweir 					if(rPropertyHolders.Current().getLineOrFillActive())
1858cdf0e10cSrcweir 					{
1859cdf0e10cSrcweir                         const MetaEllipseAction* pA = (const MetaEllipseAction*)pAction;
1860cdf0e10cSrcweir 						const Rectangle& rRectangle = pA->GetRect();
1861cdf0e10cSrcweir 
1862cdf0e10cSrcweir 						if(!rRectangle.IsEmpty())
1863cdf0e10cSrcweir 						{
1864cdf0e10cSrcweir 							const basegfx::B2DRange aRange(rRectangle.Left(), rRectangle.Top(), rRectangle.Right(), rRectangle.Bottom());
1865cdf0e10cSrcweir 
1866cdf0e10cSrcweir 							if(!aRange.isEmpty())
1867cdf0e10cSrcweir 							{
1868cdf0e10cSrcweir 								const basegfx::B2DPolygon aOutline(basegfx::tools::createPolygonFromEllipse(
1869cdf0e10cSrcweir 									aRange.getCenter(), aRange.getWidth() * 0.5, aRange.getHeight() * 0.5));
1870cdf0e10cSrcweir 
1871cdf0e10cSrcweir 								createHairlineAndFillPrimitive(aOutline, rTargetHolders.Current(), rPropertyHolders.Current());
1872cdf0e10cSrcweir 							}
1873cdf0e10cSrcweir 						}
1874cdf0e10cSrcweir 					}
1875cdf0e10cSrcweir 
1876cdf0e10cSrcweir                     break;
1877cdf0e10cSrcweir                 }
1878cdf0e10cSrcweir                 case META_ARC_ACTION :
1879cdf0e10cSrcweir                 {
1880cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
1881cdf0e10cSrcweir 					if(rPropertyHolders.Current().getLineColorActive())
1882cdf0e10cSrcweir 					{
1883cdf0e10cSrcweir                         const MetaArcAction* pA = (const MetaArcAction*)pAction;
1884cdf0e10cSrcweir                         const Polygon aToolsPoly(pA->GetRect(), pA->GetStartPoint(), pA->GetEndPoint(), POLY_ARC);
1885cdf0e10cSrcweir 						const basegfx::B2DPolygon aOutline(aToolsPoly.getB2DPolygon());
1886cdf0e10cSrcweir 
1887cdf0e10cSrcweir 						createHairlinePrimitive(aOutline, rTargetHolders.Current(), rPropertyHolders.Current());
1888cdf0e10cSrcweir 					}
1889cdf0e10cSrcweir 
1890cdf0e10cSrcweir                     break;
1891cdf0e10cSrcweir                 }
1892cdf0e10cSrcweir                 case META_PIE_ACTION :
1893cdf0e10cSrcweir                 {
1894cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
1895cdf0e10cSrcweir 					if(rPropertyHolders.Current().getLineOrFillActive())
1896cdf0e10cSrcweir 					{
1897cdf0e10cSrcweir                         const MetaPieAction* pA = (const MetaPieAction*)pAction;
1898cdf0e10cSrcweir                         const Polygon aToolsPoly(pA->GetRect(), pA->GetStartPoint(), pA->GetEndPoint(), POLY_PIE);
1899cdf0e10cSrcweir 						const basegfx::B2DPolygon aOutline(aToolsPoly.getB2DPolygon());
1900cdf0e10cSrcweir 
1901cdf0e10cSrcweir 						createHairlineAndFillPrimitive(aOutline, rTargetHolders.Current(), rPropertyHolders.Current());
1902cdf0e10cSrcweir 					}
1903cdf0e10cSrcweir 
1904cdf0e10cSrcweir                     break;
1905cdf0e10cSrcweir                 }
1906cdf0e10cSrcweir                 case META_CHORD_ACTION :
1907cdf0e10cSrcweir                 {
1908cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
1909cdf0e10cSrcweir 					if(rPropertyHolders.Current().getLineOrFillActive())
1910cdf0e10cSrcweir 					{
1911cdf0e10cSrcweir                         const MetaChordAction* pA = (const MetaChordAction*)pAction;
1912cdf0e10cSrcweir                         const Polygon aToolsPoly(pA->GetRect(), pA->GetStartPoint(), pA->GetEndPoint(), POLY_CHORD);
1913cdf0e10cSrcweir 						const basegfx::B2DPolygon aOutline(aToolsPoly.getB2DPolygon());
1914cdf0e10cSrcweir 
1915cdf0e10cSrcweir 						createHairlineAndFillPrimitive(aOutline, rTargetHolders.Current(), rPropertyHolders.Current());
1916cdf0e10cSrcweir 					}
1917cdf0e10cSrcweir 
1918cdf0e10cSrcweir                     break;
1919cdf0e10cSrcweir                 }
1920cdf0e10cSrcweir                 case META_POLYLINE_ACTION :
1921cdf0e10cSrcweir                 {
1922cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
1923cdf0e10cSrcweir                     if(rPropertyHolders.Current().getLineColorActive())
1924cdf0e10cSrcweir                     {
1925cdf0e10cSrcweir                         const MetaPolyLineAction* pA = (const MetaPolyLineAction*)pAction;
1926cdf0e10cSrcweir                         createLinePrimitive(pA->GetPolygon().getB2DPolygon(), pA->GetLineInfo(), rTargetHolders.Current(), rPropertyHolders.Current());
1927cdf0e10cSrcweir                     }
1928cdf0e10cSrcweir 
1929cdf0e10cSrcweir                     break;
1930cdf0e10cSrcweir                 }
1931cdf0e10cSrcweir                 case META_POLYGON_ACTION :
1932cdf0e10cSrcweir                 {
1933cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
1934cdf0e10cSrcweir 					if(rPropertyHolders.Current().getLineOrFillActive())
1935cdf0e10cSrcweir 					{
1936cdf0e10cSrcweir                         const MetaPolygonAction* pA = (const MetaPolygonAction*)pAction;
1937cdf0e10cSrcweir 						basegfx::B2DPolygon aOutline(pA->GetPolygon().getB2DPolygon());
1938cdf0e10cSrcweir 
1939cdf0e10cSrcweir 						// the metafile play interprets the polygons from MetaPolygonAction
1940cdf0e10cSrcweir 						// always as closed and always paints an edge from last to first point,
1941cdf0e10cSrcweir 						// so force to closed here to emulate that
1942cdf0e10cSrcweir 						if(aOutline.count() > 1 && !aOutline.isClosed())
1943cdf0e10cSrcweir 						{
1944cdf0e10cSrcweir 							aOutline.setClosed(true);
1945cdf0e10cSrcweir 						}
1946cdf0e10cSrcweir 
1947cdf0e10cSrcweir 						createHairlineAndFillPrimitive(aOutline, rTargetHolders.Current(), rPropertyHolders.Current());
1948cdf0e10cSrcweir 					}
1949cdf0e10cSrcweir 
1950cdf0e10cSrcweir                     break;
1951cdf0e10cSrcweir                 }
1952cdf0e10cSrcweir                 case META_POLYPOLYGON_ACTION :
1953cdf0e10cSrcweir                 {
1954cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
1955cdf0e10cSrcweir 					if(rPropertyHolders.Current().getLineOrFillActive())
1956cdf0e10cSrcweir 					{
1957cdf0e10cSrcweir                         const MetaPolyPolygonAction* pA = (const MetaPolyPolygonAction*)pAction;
1958cdf0e10cSrcweir 						basegfx::B2DPolyPolygon aPolyPolygonOutline(pA->GetPolyPolygon().getB2DPolyPolygon());
1959cdf0e10cSrcweir 
1960cdf0e10cSrcweir 						// the metafile play interprets the single polygons from MetaPolyPolygonAction
1961cdf0e10cSrcweir 						// always as closed and always paints an edge from last to first point,
1962cdf0e10cSrcweir 						// so force to closed here to emulate that
1963cdf0e10cSrcweir 						for(sal_uInt32 b(0); b < aPolyPolygonOutline.count(); b++)
1964cdf0e10cSrcweir 						{
1965cdf0e10cSrcweir 							basegfx::B2DPolygon aPolygonOutline(aPolyPolygonOutline.getB2DPolygon(b));
1966cdf0e10cSrcweir 
1967cdf0e10cSrcweir 							if(aPolygonOutline.count() > 1 && !aPolygonOutline.isClosed())
1968cdf0e10cSrcweir 							{
1969cdf0e10cSrcweir 								aPolygonOutline.setClosed(true);
1970cdf0e10cSrcweir 								aPolyPolygonOutline.setB2DPolygon(b, aPolygonOutline);
1971cdf0e10cSrcweir 							}
1972cdf0e10cSrcweir 						}
1973cdf0e10cSrcweir 
1974cdf0e10cSrcweir 						createHairlineAndFillPrimitive(aPolyPolygonOutline, rTargetHolders.Current(), rPropertyHolders.Current());
1975cdf0e10cSrcweir 					}
1976cdf0e10cSrcweir 
1977cdf0e10cSrcweir                     break;
1978cdf0e10cSrcweir                 }
1979cdf0e10cSrcweir                 case META_TEXT_ACTION :
1980cdf0e10cSrcweir                 {
1981cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
1982cdf0e10cSrcweir                     const MetaTextAction* pA = (const MetaTextAction*)pAction;
1983cdf0e10cSrcweir 					sal_uInt32 nTextLength(pA->GetLen());
1984cdf0e10cSrcweir 					const sal_uInt32 nTextIndex(pA->GetIndex());
1985cdf0e10cSrcweir 					const sal_uInt32 nStringLength(pA->GetText().Len());
1986cdf0e10cSrcweir 
1987cdf0e10cSrcweir 					if(nTextLength + nTextIndex > nStringLength)
1988cdf0e10cSrcweir 					{
1989cdf0e10cSrcweir 						nTextLength = nStringLength - nTextIndex;
1990cdf0e10cSrcweir 					}
1991cdf0e10cSrcweir 
1992cdf0e10cSrcweir 					if(nTextLength && rPropertyHolders.Current().getTextColorActive())
1993cdf0e10cSrcweir 					{
1994cdf0e10cSrcweir 						const std::vector< double > aDXArray;
1995cdf0e10cSrcweir 						proccessMetaTextAction(
1996cdf0e10cSrcweir 							pA->GetPoint(),
1997cdf0e10cSrcweir 							pA->GetText(),
1998cdf0e10cSrcweir 							nTextIndex,
1999cdf0e10cSrcweir 							nTextLength,
2000cdf0e10cSrcweir 							aDXArray,
2001cdf0e10cSrcweir 							rTargetHolders.Current(),
2002cdf0e10cSrcweir 							rPropertyHolders.Current());
2003cdf0e10cSrcweir 					}
2004cdf0e10cSrcweir 
2005cdf0e10cSrcweir                     break;
2006cdf0e10cSrcweir                 }
2007cdf0e10cSrcweir                 case META_TEXTARRAY_ACTION :
2008cdf0e10cSrcweir                 {
2009cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2010cdf0e10cSrcweir                     const MetaTextArrayAction* pA = (const MetaTextArrayAction*)pAction;
2011cdf0e10cSrcweir 					sal_uInt32 nTextLength(pA->GetLen());
2012cdf0e10cSrcweir 					const sal_uInt32 nTextIndex(pA->GetIndex());
2013cdf0e10cSrcweir 					const sal_uInt32 nStringLength(pA->GetText().Len());
2014cdf0e10cSrcweir 
2015cdf0e10cSrcweir 					if(nTextLength + nTextIndex > nStringLength)
2016cdf0e10cSrcweir 					{
2017cdf0e10cSrcweir 						nTextLength = nTextIndex > nStringLength ? 0 : nStringLength - nTextIndex;
2018cdf0e10cSrcweir 					}
2019cdf0e10cSrcweir 
2020cdf0e10cSrcweir 					if(nTextLength && rPropertyHolders.Current().getTextColorActive())
2021cdf0e10cSrcweir 					{
2022cdf0e10cSrcweir 						// preapare DXArray (if used)
2023cdf0e10cSrcweir 						std::vector< double > aDXArray;
2024cdf0e10cSrcweir 						sal_Int32* pDXArray = pA->GetDXArray();
2025cdf0e10cSrcweir 
2026cdf0e10cSrcweir 						if(pDXArray)
2027cdf0e10cSrcweir 						{
2028cdf0e10cSrcweir 							aDXArray.reserve(nTextLength);
2029cdf0e10cSrcweir 
2030cdf0e10cSrcweir 							for(sal_uInt32 a(0); a < nTextLength; a++)
2031cdf0e10cSrcweir 							{
2032cdf0e10cSrcweir 								aDXArray.push_back((double)(*(pDXArray + a)));
2033cdf0e10cSrcweir 							}
2034cdf0e10cSrcweir 						}
2035cdf0e10cSrcweir 
2036cdf0e10cSrcweir 						proccessMetaTextAction(
2037cdf0e10cSrcweir 							pA->GetPoint(),
2038cdf0e10cSrcweir 							pA->GetText(),
2039cdf0e10cSrcweir 							nTextIndex,
2040cdf0e10cSrcweir 							nTextLength,
2041cdf0e10cSrcweir 							aDXArray,
2042cdf0e10cSrcweir 							rTargetHolders.Current(),
2043cdf0e10cSrcweir 							rPropertyHolders.Current());
2044cdf0e10cSrcweir 					}
2045cdf0e10cSrcweir 
2046cdf0e10cSrcweir 					break;
2047cdf0e10cSrcweir                 }
2048cdf0e10cSrcweir                 case META_STRETCHTEXT_ACTION :
2049cdf0e10cSrcweir                 {
2050cdf0e10cSrcweir                     // #i108440# StarMath uses MetaStretchTextAction, thus support is needed.
2051cdf0e10cSrcweir                     // It looks as if it pretty never really uses a width different from
2052cdf0e10cSrcweir                     // the default text-layout width, but it's not possible to be sure.
2053cdf0e10cSrcweir                     // Implemented getting the DXArray and checking for scale at all. If
2054cdf0e10cSrcweir                     // scale is more than 3.5% different, scale the DXArray before usage.
2055cdf0e10cSrcweir                     // New status:
2056cdf0e10cSrcweir 
2057cdf0e10cSrcweir                     /** CHECKED, WORKS WELL */
2058cdf0e10cSrcweir                     const MetaStretchTextAction* pA = (const MetaStretchTextAction*)pAction;
2059cdf0e10cSrcweir 					sal_uInt32 nTextLength(pA->GetLen());
2060cdf0e10cSrcweir 					const sal_uInt32 nTextIndex(pA->GetIndex());
2061cdf0e10cSrcweir 					const sal_uInt32 nStringLength(pA->GetText().Len());
2062cdf0e10cSrcweir 
2063cdf0e10cSrcweir 					if(nTextLength + nTextIndex > nStringLength)
2064cdf0e10cSrcweir 					{
2065cdf0e10cSrcweir 						nTextLength = nStringLength - nTextIndex;
2066cdf0e10cSrcweir 					}
2067cdf0e10cSrcweir 
2068cdf0e10cSrcweir 					if(nTextLength && rPropertyHolders.Current().getTextColorActive())
2069cdf0e10cSrcweir 					{
2070cdf0e10cSrcweir 						drawinglayer::primitive2d::TextLayouterDevice aTextLayouterDevice;
2071cdf0e10cSrcweir 						aTextLayouterDevice.setFont(rPropertyHolders.Current().getFont());
2072cdf0e10cSrcweir 
2073cdf0e10cSrcweir 						::std::vector< double > aTextArray(
2074cdf0e10cSrcweir 							aTextLayouterDevice.getTextArray(
2075cdf0e10cSrcweir 								pA->GetText(),
2076cdf0e10cSrcweir 								nTextIndex,
2077cdf0e10cSrcweir 								nTextLength));
2078cdf0e10cSrcweir 
2079cdf0e10cSrcweir                         if(!aTextArray.empty())
2080cdf0e10cSrcweir                         {
2081cdf0e10cSrcweir     						const double fTextLength(aTextArray.back());
2082cdf0e10cSrcweir 
2083cdf0e10cSrcweir                             if(0.0 != fTextLength && pA->GetWidth())
2084cdf0e10cSrcweir                             {
2085cdf0e10cSrcweir                                 const double fRelative(pA->GetWidth() / fTextLength);
2086cdf0e10cSrcweir 
2087cdf0e10cSrcweir                                 if(fabs(fRelative - 1.0) >= 0.035)
2088cdf0e10cSrcweir                                 {
2089cdf0e10cSrcweir                                     // when derivation is more than 3,5% from default text size,
2090cdf0e10cSrcweir                                     // scale the DXArray
2091cdf0e10cSrcweir                                     for(sal_uInt32 a(0); a < aTextArray.size(); a++)
2092cdf0e10cSrcweir                                     {
2093cdf0e10cSrcweir                                         aTextArray[a] *= fRelative;
2094cdf0e10cSrcweir                                     }
2095cdf0e10cSrcweir                                 }
2096cdf0e10cSrcweir                             }
2097cdf0e10cSrcweir                         }
2098cdf0e10cSrcweir 
2099cdf0e10cSrcweir 						proccessMetaTextAction(
2100cdf0e10cSrcweir 							pA->GetPoint(),
2101cdf0e10cSrcweir 							pA->GetText(),
2102cdf0e10cSrcweir 							nTextIndex,
2103cdf0e10cSrcweir 							nTextLength,
2104cdf0e10cSrcweir 							aTextArray,
2105cdf0e10cSrcweir 							rTargetHolders.Current(),
2106cdf0e10cSrcweir 							rPropertyHolders.Current());
2107cdf0e10cSrcweir 					}
2108cdf0e10cSrcweir 
2109cdf0e10cSrcweir 					break;
2110cdf0e10cSrcweir                 }
2111cdf0e10cSrcweir                 case META_TEXTRECT_ACTION :
2112cdf0e10cSrcweir                 {
2113cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2114cdf0e10cSrcweir                     // OSL_ENSURE(false, "META_TEXTRECT_ACTION requested (!)");
2115cdf0e10cSrcweir                     const MetaTextRectAction* pA = (const MetaTextRectAction*)pAction;
2116cdf0e10cSrcweir 					const Rectangle& rRectangle = pA->GetRect();
2117cdf0e10cSrcweir 					const sal_uInt32 nStringLength(pA->GetText().Len());
2118cdf0e10cSrcweir 
2119cdf0e10cSrcweir 					if(!rRectangle.IsEmpty() && 0 != nStringLength)
2120cdf0e10cSrcweir 					{
2121cdf0e10cSrcweir 						// The problem with this action is that it describes unlayouted text
2122cdf0e10cSrcweir 						// and the layout capabilities are in EditEngine/Outliner in SVX. The
2123cdf0e10cSrcweir 						// same problem is true for VCL which internally has implementations
2124cdf0e10cSrcweir 						// to layout text in this case. There exists even a call
2125cdf0e10cSrcweir 						// OutputDevice::AddTextRectActions(...) to create the needed actions
2126cdf0e10cSrcweir 						// as 'sub-content' of a Metafile. Unfortunately i do not have an
2127cdf0e10cSrcweir 						// OutputDevice here since this interpreter tries to work without
2128cdf0e10cSrcweir 						// VCL AFAP.
2129cdf0e10cSrcweir 						// Since AddTextRectActions is the only way as long as we do not have
2130cdf0e10cSrcweir 						// a simple text layouter available, i will try to add it to the
2131cdf0e10cSrcweir 						// TextLayouterDevice isloation.
2132cdf0e10cSrcweir 						drawinglayer::primitive2d::TextLayouterDevice aTextLayouterDevice;
2133cdf0e10cSrcweir 						aTextLayouterDevice.setFont(rPropertyHolders.Current().getFont());
2134cdf0e10cSrcweir 						GDIMetaFile aGDIMetaFile;
2135cdf0e10cSrcweir 
2136cdf0e10cSrcweir 						aTextLayouterDevice.addTextRectActions(
2137cdf0e10cSrcweir 							rRectangle, pA->GetText(), pA->GetStyle(), aGDIMetaFile);
2138cdf0e10cSrcweir 
2139cdf0e10cSrcweir 						if(aGDIMetaFile.GetActionCount())
2140cdf0e10cSrcweir 						{
2141cdf0e10cSrcweir 							// cerate sub-content
2142cdf0e10cSrcweir 							drawinglayer::primitive2d::Primitive2DSequence xSubContent;
2143cdf0e10cSrcweir 							{
2144cdf0e10cSrcweir                                 rTargetHolders.Push();
2145cdf0e10cSrcweir 								// #i# for sub-Mteafile contents, do start with new, default render state
2146cdf0e10cSrcweir 								rPropertyHolders.PushDefault();
2147cdf0e10cSrcweir 								interpretMetafile(aGDIMetaFile, rTargetHolders, rPropertyHolders, rViewInformation);
2148cdf0e10cSrcweir 								xSubContent = rTargetHolders.Current().getPrimitive2DSequence(rPropertyHolders.Current());
2149cdf0e10cSrcweir 								rPropertyHolders.Pop();
2150cdf0e10cSrcweir                                 rTargetHolders.Pop();
2151cdf0e10cSrcweir 							}
2152cdf0e10cSrcweir 
2153cdf0e10cSrcweir 							if(xSubContent.hasElements())
2154cdf0e10cSrcweir 							{
2155cdf0e10cSrcweir 								// add with transformation
2156cdf0e10cSrcweir 								rTargetHolders.Current().append(
2157cdf0e10cSrcweir 									new drawinglayer::primitive2d::TransformPrimitive2D(
2158cdf0e10cSrcweir 										rPropertyHolders.Current().getTransformation(),
2159cdf0e10cSrcweir 										xSubContent));
2160cdf0e10cSrcweir 							}
2161cdf0e10cSrcweir 						}
2162cdf0e10cSrcweir 					}
2163cdf0e10cSrcweir 
2164cdf0e10cSrcweir 					break;
2165cdf0e10cSrcweir                 }
2166cdf0e10cSrcweir                 case META_BMP_ACTION :
2167cdf0e10cSrcweir                 {
2168cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2169cdf0e10cSrcweir                     const MetaBmpAction* pA = (const MetaBmpAction*)pAction;
2170cdf0e10cSrcweir 					const BitmapEx aBitmapEx(pA->GetBitmap());
2171cdf0e10cSrcweir 
2172cdf0e10cSrcweir 					createBitmapExPrimitive(aBitmapEx, pA->GetPoint(), rTargetHolders.Current(), rPropertyHolders.Current());
2173cdf0e10cSrcweir 
2174cdf0e10cSrcweir                     break;
2175cdf0e10cSrcweir                 }
2176cdf0e10cSrcweir                 case META_BMPSCALE_ACTION :
2177cdf0e10cSrcweir                 {
2178cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2179cdf0e10cSrcweir                     const MetaBmpScaleAction* pA = (const MetaBmpScaleAction*)pAction;
2180cdf0e10cSrcweir 					const Bitmap aBitmapEx(pA->GetBitmap());
2181cdf0e10cSrcweir 
2182cdf0e10cSrcweir 					createBitmapExPrimitive(aBitmapEx, pA->GetPoint(), pA->GetSize(), rTargetHolders.Current(), rPropertyHolders.Current());
2183cdf0e10cSrcweir 
2184cdf0e10cSrcweir                     break;
2185cdf0e10cSrcweir                 }
2186cdf0e10cSrcweir                 case META_BMPSCALEPART_ACTION :
2187cdf0e10cSrcweir                 {
2188cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2189cdf0e10cSrcweir                     const MetaBmpScalePartAction* pA = (const MetaBmpScalePartAction*)pAction;
2190cdf0e10cSrcweir 					const Bitmap& rBitmap = pA->GetBitmap();
2191cdf0e10cSrcweir 
2192cdf0e10cSrcweir 					if(!rBitmap.IsEmpty())
2193cdf0e10cSrcweir 					{
2194cdf0e10cSrcweir 						Bitmap aCroppedBitmap(rBitmap);
2195cdf0e10cSrcweir 						const Rectangle aCropRectangle(pA->GetSrcPoint(), pA->GetSrcSize());
2196cdf0e10cSrcweir 
2197cdf0e10cSrcweir 						if(!aCropRectangle.IsEmpty())
2198cdf0e10cSrcweir 						{
2199cdf0e10cSrcweir 							aCroppedBitmap.Crop(aCropRectangle);
2200cdf0e10cSrcweir 						}
2201cdf0e10cSrcweir 
2202cdf0e10cSrcweir 						const BitmapEx aCroppedBitmapEx(aCroppedBitmap);
2203cdf0e10cSrcweir 						createBitmapExPrimitive(aCroppedBitmapEx, pA->GetDestPoint(), pA->GetDestSize(), rTargetHolders.Current(), rPropertyHolders.Current());
2204cdf0e10cSrcweir 					}
2205cdf0e10cSrcweir 
2206cdf0e10cSrcweir                     break;
2207cdf0e10cSrcweir                 }
2208cdf0e10cSrcweir                 case META_BMPEX_ACTION :
2209cdf0e10cSrcweir                 {
2210cdf0e10cSrcweir 					/** CHECKED, WORKS WELL: Simply same as META_BMP_ACTION */
2211cdf0e10cSrcweir                     const MetaBmpExAction* pA = (const MetaBmpExAction*)pAction;
2212cdf0e10cSrcweir 					const BitmapEx& rBitmapEx = pA->GetBitmapEx();
2213cdf0e10cSrcweir 
2214cdf0e10cSrcweir 					createBitmapExPrimitive(rBitmapEx, pA->GetPoint(), rTargetHolders.Current(), rPropertyHolders.Current());
2215cdf0e10cSrcweir 
2216cdf0e10cSrcweir                     break;
2217cdf0e10cSrcweir                 }
2218cdf0e10cSrcweir                 case META_BMPEXSCALE_ACTION :
2219cdf0e10cSrcweir                 {
2220cdf0e10cSrcweir 					/** CHECKED, WORKS WELL: Simply same as META_BMPSCALE_ACTION */
2221cdf0e10cSrcweir                     const MetaBmpExScaleAction* pA = (const MetaBmpExScaleAction*)pAction;
2222cdf0e10cSrcweir 					const BitmapEx& rBitmapEx = pA->GetBitmapEx();
2223cdf0e10cSrcweir 
2224cdf0e10cSrcweir 					createBitmapExPrimitive(rBitmapEx, pA->GetPoint(), pA->GetSize(), rTargetHolders.Current(), rPropertyHolders.Current());
2225cdf0e10cSrcweir 
2226cdf0e10cSrcweir                     break;
2227cdf0e10cSrcweir                 }
2228cdf0e10cSrcweir                 case META_BMPEXSCALEPART_ACTION :
2229cdf0e10cSrcweir                 {
2230cdf0e10cSrcweir 					/** CHECKED, WORKS WELL: Simply same as META_BMPSCALEPART_ACTION */
2231cdf0e10cSrcweir                     const MetaBmpExScalePartAction* pA = (const MetaBmpExScalePartAction*)pAction;
2232cdf0e10cSrcweir 					const BitmapEx& rBitmapEx = pA->GetBitmapEx();
2233cdf0e10cSrcweir 
2234cdf0e10cSrcweir 					if(!rBitmapEx.IsEmpty())
2235cdf0e10cSrcweir 					{
2236cdf0e10cSrcweir 						BitmapEx aCroppedBitmapEx(rBitmapEx);
2237cdf0e10cSrcweir 						const Rectangle aCropRectangle(pA->GetSrcPoint(), pA->GetSrcSize());
2238cdf0e10cSrcweir 
2239cdf0e10cSrcweir 						if(!aCropRectangle.IsEmpty())
2240cdf0e10cSrcweir 						{
2241cdf0e10cSrcweir 							aCroppedBitmapEx.Crop(aCropRectangle);
2242cdf0e10cSrcweir 						}
2243cdf0e10cSrcweir 
2244cdf0e10cSrcweir 						createBitmapExPrimitive(aCroppedBitmapEx, pA->GetDestPoint(), pA->GetDestSize(), rTargetHolders.Current(), rPropertyHolders.Current());
2245cdf0e10cSrcweir 					}
2246cdf0e10cSrcweir 
2247cdf0e10cSrcweir                     break;
2248cdf0e10cSrcweir                 }
2249cdf0e10cSrcweir                 case META_MASK_ACTION :
2250cdf0e10cSrcweir                 {
2251cdf0e10cSrcweir 					/** CHECKED, WORKS WELL: Simply same as META_BMP_ACTION */
2252cdf0e10cSrcweir                     const MetaMaskAction* pA = (const MetaMaskAction*)pAction;
2253cdf0e10cSrcweir 					const BitmapEx aBitmapEx(createMaskBmpEx(pA->GetBitmap(), pA->GetColor()));
2254cdf0e10cSrcweir 
2255cdf0e10cSrcweir 					createBitmapExPrimitive(aBitmapEx, pA->GetPoint(), rTargetHolders.Current(), rPropertyHolders.Current());
2256cdf0e10cSrcweir 
2257cdf0e10cSrcweir                     break;
2258cdf0e10cSrcweir                 }
2259cdf0e10cSrcweir                 case META_MASKSCALE_ACTION :
2260cdf0e10cSrcweir                 {
2261cdf0e10cSrcweir 					/** CHECKED, WORKS WELL: Simply same as META_BMPSCALE_ACTION */
2262cdf0e10cSrcweir                     const MetaMaskScaleAction* pA = (const MetaMaskScaleAction*)pAction;
2263cdf0e10cSrcweir 					const BitmapEx aBitmapEx(createMaskBmpEx(pA->GetBitmap(), pA->GetColor()));
2264cdf0e10cSrcweir 
2265cdf0e10cSrcweir 					createBitmapExPrimitive(aBitmapEx, pA->GetPoint(), pA->GetSize(), rTargetHolders.Current(), rPropertyHolders.Current());
2266cdf0e10cSrcweir 
2267cdf0e10cSrcweir                     break;
2268cdf0e10cSrcweir                 }
2269cdf0e10cSrcweir                 case META_MASKSCALEPART_ACTION :
2270cdf0e10cSrcweir                 {
2271cdf0e10cSrcweir 					/** CHECKED, WORKS WELL: Simply same as META_BMPSCALEPART_ACTION */
2272cdf0e10cSrcweir                     const MetaMaskScalePartAction* pA = (const MetaMaskScalePartAction*)pAction;
2273cdf0e10cSrcweir 					const Bitmap& rBitmap = pA->GetBitmap();
2274cdf0e10cSrcweir 
2275cdf0e10cSrcweir 					if(!rBitmap.IsEmpty())
2276cdf0e10cSrcweir 					{
2277cdf0e10cSrcweir 						Bitmap aCroppedBitmap(rBitmap);
2278cdf0e10cSrcweir 						const Rectangle aCropRectangle(pA->GetSrcPoint(), pA->GetSrcSize());
2279cdf0e10cSrcweir 
2280cdf0e10cSrcweir 						if(!aCropRectangle.IsEmpty())
2281cdf0e10cSrcweir 						{
2282cdf0e10cSrcweir 							aCroppedBitmap.Crop(aCropRectangle);
2283cdf0e10cSrcweir 						}
2284cdf0e10cSrcweir 
2285cdf0e10cSrcweir 						const BitmapEx aCroppedBitmapEx(createMaskBmpEx(aCroppedBitmap, pA->GetColor()));
2286cdf0e10cSrcweir 						createBitmapExPrimitive(aCroppedBitmapEx, pA->GetDestPoint(), pA->GetDestSize(), rTargetHolders.Current(), rPropertyHolders.Current());
2287cdf0e10cSrcweir 					}
2288cdf0e10cSrcweir 
2289cdf0e10cSrcweir                     break;
2290cdf0e10cSrcweir                 }
2291cdf0e10cSrcweir                 case META_GRADIENT_ACTION :
2292cdf0e10cSrcweir                 {
2293cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2294cdf0e10cSrcweir                     const MetaGradientAction* pA = (const MetaGradientAction*)pAction;
2295cdf0e10cSrcweir 					const Rectangle& rRectangle = pA->GetRect();
2296cdf0e10cSrcweir 
2297cdf0e10cSrcweir 					if(!rRectangle.IsEmpty())
2298cdf0e10cSrcweir 					{
2299cdf0e10cSrcweir 						basegfx::B2DRange aRange(rRectangle.Left(), rRectangle.Top(), rRectangle.Right(), rRectangle.Bottom());
2300cdf0e10cSrcweir 
2301cdf0e10cSrcweir 						if(!aRange.isEmpty())
2302cdf0e10cSrcweir 						{
2303cdf0e10cSrcweir 							const Gradient& rGradient = pA->GetGradient();
2304cdf0e10cSrcweir 							const drawinglayer::attribute::FillGradientAttribute aAttribute(createFillGradientAttribute(rGradient));
2305cdf0e10cSrcweir 							basegfx::B2DPolyPolygon aOutline(basegfx::tools::createPolygonFromRect(aRange));
2306cdf0e10cSrcweir 
2307cdf0e10cSrcweir 							if(aAttribute.getStartColor() == aAttribute.getEndColor())
2308cdf0e10cSrcweir 							{
2309cdf0e10cSrcweir 								// not really a gradient. Create filled rectangle
2310cdf0e10cSrcweir 								createFillPrimitive(
2311cdf0e10cSrcweir                                     aOutline,
2312cdf0e10cSrcweir                                     rTargetHolders.Current(),
2313cdf0e10cSrcweir                                     rPropertyHolders.Current());
2314cdf0e10cSrcweir 							}
2315cdf0e10cSrcweir 							else
2316cdf0e10cSrcweir 							{
2317cdf0e10cSrcweir 								// really a gradient
2318cdf0e10cSrcweir 								aRange.transform(rPropertyHolders.Current().getTransformation());
2319cdf0e10cSrcweir                                 drawinglayer::primitive2d::Primitive2DSequence xGradient(1);
2320cdf0e10cSrcweir 
2321cdf0e10cSrcweir                                 if(rPropertyHolders.Current().isRasterOpInvert())
2322cdf0e10cSrcweir                                 {
2323cdf0e10cSrcweir                                     // use a special version of FillGradientPrimitive2D which creates
2324cdf0e10cSrcweir                                     // non-overlapping geometry on decomposition to makethe old XOR
2325cdf0e10cSrcweir                                     // paint 'trick' work.
2326cdf0e10cSrcweir                                     xGradient[0] = drawinglayer::primitive2d::Primitive2DReference(
2327cdf0e10cSrcweir 									    new drawinglayer::primitive2d::NonOverlappingFillGradientPrimitive2D(
2328cdf0e10cSrcweir 										    aRange,
2329cdf0e10cSrcweir 										    aAttribute));
2330cdf0e10cSrcweir                                 }
2331cdf0e10cSrcweir                                 else
2332cdf0e10cSrcweir                                 {
2333cdf0e10cSrcweir                                     xGradient[0] = drawinglayer::primitive2d::Primitive2DReference(
2334cdf0e10cSrcweir 									    new drawinglayer::primitive2d::FillGradientPrimitive2D(
2335cdf0e10cSrcweir 										    aRange,
2336cdf0e10cSrcweir 										    aAttribute));
2337cdf0e10cSrcweir                                 }
2338cdf0e10cSrcweir 
2339cdf0e10cSrcweir                                 // #i112300# clip against polygon representing the rectangle from
2340cdf0e10cSrcweir                                 // the action. This is implicitely done using a temp Clipping in VCL
2341cdf0e10cSrcweir                                 // when a MetaGradientAction is executed
2342cdf0e10cSrcweir                     			aOutline.transform(rPropertyHolders.Current().getTransformation());
2343cdf0e10cSrcweir                                 rTargetHolders.Current().append(
2344cdf0e10cSrcweir 								    new drawinglayer::primitive2d::MaskPrimitive2D(
2345cdf0e10cSrcweir 									    aOutline,
2346cdf0e10cSrcweir 									    xGradient));
2347cdf0e10cSrcweir 							}
2348cdf0e10cSrcweir 						}
2349cdf0e10cSrcweir 					}
2350cdf0e10cSrcweir 
2351cdf0e10cSrcweir                     break;
2352cdf0e10cSrcweir                 }
2353cdf0e10cSrcweir                 case META_HATCH_ACTION :
2354cdf0e10cSrcweir                 {
2355cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2356cdf0e10cSrcweir                     const MetaHatchAction* pA = (const MetaHatchAction*)pAction;
2357cdf0e10cSrcweir 					basegfx::B2DPolyPolygon aOutline(pA->GetPolyPolygon().getB2DPolyPolygon());
2358cdf0e10cSrcweir 
2359cdf0e10cSrcweir 					if(aOutline.count())
2360cdf0e10cSrcweir 					{
2361cdf0e10cSrcweir                     	const Hatch& rHatch = pA->GetHatch();
2362cdf0e10cSrcweir 						const drawinglayer::attribute::FillHatchAttribute aAttribute(createFillHatchAttribute(rHatch));
2363cdf0e10cSrcweir 
2364cdf0e10cSrcweir                         aOutline.transform(rPropertyHolders.Current().getTransformation());
2365cdf0e10cSrcweir 
2366cdf0e10cSrcweir                         const basegfx::B2DRange aObjectRange(aOutline.getB2DRange());
2367cdf0e10cSrcweir 						const drawinglayer::primitive2d::Primitive2DReference aFillHatch(
2368cdf0e10cSrcweir 							new drawinglayer::primitive2d::FillHatchPrimitive2D(
2369cdf0e10cSrcweir 								aObjectRange,
2370cdf0e10cSrcweir                                 basegfx::BColor(),
2371cdf0e10cSrcweir 								aAttribute));
2372cdf0e10cSrcweir 
2373cdf0e10cSrcweir                         rTargetHolders.Current().append(
2374cdf0e10cSrcweir 							new drawinglayer::primitive2d::MaskPrimitive2D(
2375cdf0e10cSrcweir 								aOutline,
2376cdf0e10cSrcweir 								drawinglayer::primitive2d::Primitive2DSequence(&aFillHatch, 1)));
2377cdf0e10cSrcweir                     }
2378cdf0e10cSrcweir 
2379cdf0e10cSrcweir                     break;
2380cdf0e10cSrcweir                 }
2381cdf0e10cSrcweir                 case META_WALLPAPER_ACTION :
2382cdf0e10cSrcweir                 {
2383cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2384cdf0e10cSrcweir                     const MetaWallpaperAction* pA = (const MetaWallpaperAction*)pAction;
2385cdf0e10cSrcweir                 	Rectangle aWallpaperRectangle(pA->GetRect());
2386cdf0e10cSrcweir 
2387cdf0e10cSrcweir                     if(!aWallpaperRectangle.IsEmpty())
2388cdf0e10cSrcweir                     {
2389cdf0e10cSrcweir                     	const Wallpaper& rWallpaper = pA->GetWallpaper();
2390cdf0e10cSrcweir                        	const WallpaperStyle eWallpaperStyle(rWallpaper.GetStyle());
2391cdf0e10cSrcweir 		                basegfx::B2DRange aWallpaperRange(
2392cdf0e10cSrcweir                             aWallpaperRectangle.Left(), aWallpaperRectangle.Top(),
2393cdf0e10cSrcweir                             aWallpaperRectangle.Right(), aWallpaperRectangle.Bottom());
2394cdf0e10cSrcweir 
2395cdf0e10cSrcweir                         if(WALLPAPER_NULL != eWallpaperStyle)
2396cdf0e10cSrcweir                         {
2397cdf0e10cSrcweir 	                        if(rWallpaper.IsBitmap())
2398cdf0e10cSrcweir                             {
2399cdf0e10cSrcweir                                 // create bitmap background. Caution: This
2400cdf0e10cSrcweir                                 // also will create gradient/color background(s)
2401cdf0e10cSrcweir                                 // when the bitmap is transparent or not tiled
2402cdf0e10cSrcweir 				                CreateAndAppendBitmapWallpaper(
2403cdf0e10cSrcweir 					                aWallpaperRange,
2404cdf0e10cSrcweir                                     rWallpaper,
2405cdf0e10cSrcweir 									rTargetHolders.Current(),
2406cdf0e10cSrcweir                                     rPropertyHolders.Current());
2407cdf0e10cSrcweir                             }
2408cdf0e10cSrcweir 	                        else if(rWallpaper.IsGradient())
2409cdf0e10cSrcweir                             {
2410cdf0e10cSrcweir                                 // create gradient background
2411cdf0e10cSrcweir                                 rTargetHolders.Current().append(
2412cdf0e10cSrcweir 							        CreateGradientWallpaper(
2413cdf0e10cSrcweir 								        aWallpaperRange,
2414cdf0e10cSrcweir                                         rWallpaper.GetGradient(),
2415cdf0e10cSrcweir                                         rPropertyHolders.Current()));
2416cdf0e10cSrcweir                             }
2417cdf0e10cSrcweir 	                        else if(!rWallpaper.GetColor().GetTransparency())
2418cdf0e10cSrcweir                             {
2419cdf0e10cSrcweir                                 // create color background
2420cdf0e10cSrcweir                                 rTargetHolders.Current().append(
2421cdf0e10cSrcweir 							        CreateColorWallpaper(
2422cdf0e10cSrcweir 								        aWallpaperRange,
2423cdf0e10cSrcweir                                         rWallpaper.GetColor().getBColor(),
2424cdf0e10cSrcweir                                         rPropertyHolders.Current()));
2425cdf0e10cSrcweir                             }
2426cdf0e10cSrcweir                         }
2427cdf0e10cSrcweir                     }
2428cdf0e10cSrcweir 
2429cdf0e10cSrcweir                     break;
2430cdf0e10cSrcweir                 }
2431cdf0e10cSrcweir                 case META_CLIPREGION_ACTION :
2432cdf0e10cSrcweir                 {
2433cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2434cdf0e10cSrcweir                     const MetaClipRegionAction* pA = (const MetaClipRegionAction*)pAction;
2435cdf0e10cSrcweir 
2436cdf0e10cSrcweir                     if(pA->IsClipping())
2437cdf0e10cSrcweir                     {
2438cdf0e10cSrcweir                         // new clipping. Get PolyPolygon and transform with current transformation
2439cdf0e10cSrcweir                         basegfx::B2DPolyPolygon aNewClipPolyPolygon(getB2DPolyPolygonFromRegion(pA->GetRegion()));
2440cdf0e10cSrcweir 
2441cdf0e10cSrcweir                         aNewClipPolyPolygon.transform(rPropertyHolders.Current().getTransformation());
2442cdf0e10cSrcweir                         HandleNewClipRegion(aNewClipPolyPolygon, rTargetHolders, rPropertyHolders);
2443cdf0e10cSrcweir                     }
2444cdf0e10cSrcweir                     else
2445cdf0e10cSrcweir                     {
2446cdf0e10cSrcweir                         // end clipping
2447cdf0e10cSrcweir                         const basegfx::B2DPolyPolygon aEmptyPolyPolygon;
2448cdf0e10cSrcweir 
2449cdf0e10cSrcweir                         HandleNewClipRegion(aEmptyPolyPolygon, rTargetHolders, rPropertyHolders);
2450cdf0e10cSrcweir                     }
2451cdf0e10cSrcweir 
2452cdf0e10cSrcweir                     break;
2453cdf0e10cSrcweir                 }
2454cdf0e10cSrcweir                 case META_ISECTRECTCLIPREGION_ACTION :
2455cdf0e10cSrcweir                 {
2456cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2457cdf0e10cSrcweir                     const MetaISectRectClipRegionAction* pA = (const MetaISectRectClipRegionAction*)pAction;
2458cdf0e10cSrcweir 					const Rectangle& rRectangle = pA->GetRect();
2459cdf0e10cSrcweir 
2460cdf0e10cSrcweir 					if(rRectangle.IsEmpty())
2461cdf0e10cSrcweir                     {
2462cdf0e10cSrcweir                         // intersect with empty rectangle will always give empty
2463cdf0e10cSrcweir                         // ClipPolyPolygon; start new clipping with empty PolyPolygon
2464cdf0e10cSrcweir                         const basegfx::B2DPolyPolygon aEmptyPolyPolygon;
2465cdf0e10cSrcweir 
2466cdf0e10cSrcweir                         HandleNewClipRegion(aEmptyPolyPolygon, rTargetHolders, rPropertyHolders);
2467cdf0e10cSrcweir                     }
2468cdf0e10cSrcweir                     else
2469cdf0e10cSrcweir 					{
2470cdf0e10cSrcweir                         // create transformed ClipRange
2471cdf0e10cSrcweir                         basegfx::B2DRange aClipRange(
2472cdf0e10cSrcweir                             rRectangle.Left(), rRectangle.Top(),
2473cdf0e10cSrcweir                             rRectangle.Right(), rRectangle.Bottom());
2474cdf0e10cSrcweir 
2475cdf0e10cSrcweir                         aClipRange.transform(rPropertyHolders.Current().getTransformation());
2476cdf0e10cSrcweir 
2477cdf0e10cSrcweir                         if(rPropertyHolders.Current().getClipPolyPolygonActive())
2478cdf0e10cSrcweir                         {
2479cdf0e10cSrcweir                             if(0 == rPropertyHolders.Current().getClipPolyPolygon().count())
2480cdf0e10cSrcweir                             {
2481cdf0e10cSrcweir                                 // nothing to do, empty active clipPolyPolygon will stay
2482cdf0e10cSrcweir                                 // empty when intersecting
2483cdf0e10cSrcweir                             }
2484cdf0e10cSrcweir                             else
2485cdf0e10cSrcweir                             {
2486cdf0e10cSrcweir                                 // AND existing region and new ClipRange
2487cdf0e10cSrcweir                                 const basegfx::B2DPolyPolygon aOriginalPolyPolygon(
2488cdf0e10cSrcweir                                     rPropertyHolders.Current().getClipPolyPolygon());
2489cdf0e10cSrcweir                                 basegfx::B2DPolyPolygon aClippedPolyPolygon;
2490cdf0e10cSrcweir 
2491cdf0e10cSrcweir                                 if(aOriginalPolyPolygon.count())
2492cdf0e10cSrcweir                                 {
2493cdf0e10cSrcweir                                     aClippedPolyPolygon = basegfx::tools::clipPolyPolygonOnRange(
2494cdf0e10cSrcweir                                         aOriginalPolyPolygon,
2495cdf0e10cSrcweir                                         aClipRange,
2496cdf0e10cSrcweir                                         true,
2497cdf0e10cSrcweir                                         false);
2498cdf0e10cSrcweir                                 }
2499cdf0e10cSrcweir 
2500cdf0e10cSrcweir                                 if(aClippedPolyPolygon != aOriginalPolyPolygon)
2501cdf0e10cSrcweir                                 {
2502cdf0e10cSrcweir                                     // start new clipping with intersected region
2503cdf0e10cSrcweir                                     HandleNewClipRegion(
2504cdf0e10cSrcweir                                         aClippedPolyPolygon,
2505cdf0e10cSrcweir                                         rTargetHolders,
2506cdf0e10cSrcweir                                         rPropertyHolders);
2507cdf0e10cSrcweir                                 }
2508cdf0e10cSrcweir                             }
2509cdf0e10cSrcweir                         }
2510cdf0e10cSrcweir                         else
2511cdf0e10cSrcweir                         {
2512cdf0e10cSrcweir                             // start new clipping with ClipRange
2513cdf0e10cSrcweir                             const basegfx::B2DPolyPolygon aNewClipPolyPolygon(
2514cdf0e10cSrcweir                                 basegfx::tools::createPolygonFromRect(aClipRange));
2515cdf0e10cSrcweir 
2516cdf0e10cSrcweir                             HandleNewClipRegion(aNewClipPolyPolygon, rTargetHolders, rPropertyHolders);
2517cdf0e10cSrcweir                         }
2518cdf0e10cSrcweir                     }
2519cdf0e10cSrcweir 
2520cdf0e10cSrcweir                     break;
2521cdf0e10cSrcweir                 }
2522cdf0e10cSrcweir                 case META_ISECTREGIONCLIPREGION_ACTION :
2523cdf0e10cSrcweir                 {
2524cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2525cdf0e10cSrcweir                     const MetaISectRegionClipRegionAction* pA = (const MetaISectRegionClipRegionAction*)pAction;
2526cdf0e10cSrcweir                 	const Region& rNewRegion = pA->GetRegion();
2527cdf0e10cSrcweir 
2528cdf0e10cSrcweir 					if(rNewRegion.IsEmpty())
2529cdf0e10cSrcweir                     {
2530cdf0e10cSrcweir                         // intersect with empty region will always give empty
2531cdf0e10cSrcweir                         // region; start new clipping with empty PolyPolygon
2532cdf0e10cSrcweir                         const basegfx::B2DPolyPolygon aEmptyPolyPolygon;
2533cdf0e10cSrcweir 
2534cdf0e10cSrcweir                         HandleNewClipRegion(aEmptyPolyPolygon, rTargetHolders, rPropertyHolders);
2535cdf0e10cSrcweir                     }
2536cdf0e10cSrcweir                     else
2537cdf0e10cSrcweir 					{
2538cdf0e10cSrcweir                         // get new ClipPolyPolygon, transform it with current transformation
2539cdf0e10cSrcweir                         basegfx::B2DPolyPolygon aNewClipPolyPolygon(getB2DPolyPolygonFromRegion(rNewRegion));
2540cdf0e10cSrcweir                         aNewClipPolyPolygon.transform(rPropertyHolders.Current().getTransformation());
2541cdf0e10cSrcweir 
2542cdf0e10cSrcweir                         if(rPropertyHolders.Current().getClipPolyPolygonActive())
2543cdf0e10cSrcweir                         {
2544cdf0e10cSrcweir                             if(0 == rPropertyHolders.Current().getClipPolyPolygon().count())
2545cdf0e10cSrcweir                             {
2546cdf0e10cSrcweir                                 // nothing to do, empty active clipPolyPolygon will stay empty
2547cdf0e10cSrcweir                                 // when intersecting with any region
2548cdf0e10cSrcweir                             }
2549cdf0e10cSrcweir                             else
2550cdf0e10cSrcweir                             {
2551cdf0e10cSrcweir                                 // AND existing and new region
2552cdf0e10cSrcweir                                 const basegfx::B2DPolyPolygon aOriginalPolyPolygon(
2553cdf0e10cSrcweir                                     rPropertyHolders.Current().getClipPolyPolygon());
2554cdf0e10cSrcweir                                 basegfx::B2DPolyPolygon aClippedPolyPolygon;
2555cdf0e10cSrcweir 
2556cdf0e10cSrcweir                                 if(aOriginalPolyPolygon.count())
2557cdf0e10cSrcweir                                 {
2558cdf0e10cSrcweir                                     aClippedPolyPolygon = basegfx::tools::clipPolyPolygonOnPolyPolygon(
2559cdf0e10cSrcweir                                         aOriginalPolyPolygon, aNewClipPolyPolygon, true, false);
2560cdf0e10cSrcweir                                 }
2561cdf0e10cSrcweir 
2562cdf0e10cSrcweir                                 if(aClippedPolyPolygon != aOriginalPolyPolygon)
2563cdf0e10cSrcweir                                 {
2564cdf0e10cSrcweir                                     // start new clipping with intersected ClipPolyPolygon
2565cdf0e10cSrcweir                                     HandleNewClipRegion(aClippedPolyPolygon, rTargetHolders, rPropertyHolders);
2566cdf0e10cSrcweir                                 }
2567cdf0e10cSrcweir                             }
2568cdf0e10cSrcweir                         }
2569cdf0e10cSrcweir                         else
2570cdf0e10cSrcweir                         {
2571cdf0e10cSrcweir                             // start new clipping with new ClipPolyPolygon
2572cdf0e10cSrcweir                             HandleNewClipRegion(aNewClipPolyPolygon, rTargetHolders, rPropertyHolders);
2573cdf0e10cSrcweir                         }
2574cdf0e10cSrcweir                     }
2575cdf0e10cSrcweir 
2576cdf0e10cSrcweir                     break;
2577cdf0e10cSrcweir                 }
2578cdf0e10cSrcweir                 case META_MOVECLIPREGION_ACTION :
2579cdf0e10cSrcweir                 {
2580cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2581cdf0e10cSrcweir                     const MetaMoveClipRegionAction* pA = (const MetaMoveClipRegionAction*)pAction;
2582cdf0e10cSrcweir 
2583cdf0e10cSrcweir                     if(rPropertyHolders.Current().getClipPolyPolygonActive())
2584cdf0e10cSrcweir                     {
2585cdf0e10cSrcweir                         if(0 == rPropertyHolders.Current().getClipPolyPolygon().count())
2586cdf0e10cSrcweir                         {
2587cdf0e10cSrcweir                             // nothing to do
2588cdf0e10cSrcweir                         }
2589cdf0e10cSrcweir                         else
2590cdf0e10cSrcweir                         {
2591cdf0e10cSrcweir                             const sal_Int32 nHor(pA->GetHorzMove());
2592cdf0e10cSrcweir                             const sal_Int32 nVer(pA->GetVertMove());
2593cdf0e10cSrcweir 
2594cdf0e10cSrcweir                             if(0 != nHor || 0 != nVer)
2595cdf0e10cSrcweir                             {
2596cdf0e10cSrcweir                                 // prepare translation, add current transformation
2597cdf0e10cSrcweir                                 basegfx::B2DVector aVector(pA->GetHorzMove(), pA->GetVertMove());
2598cdf0e10cSrcweir                                 aVector *= rPropertyHolders.Current().getTransformation();
2599cdf0e10cSrcweir                                 basegfx::B2DHomMatrix aTransform(
2600cdf0e10cSrcweir                                     basegfx::tools::createTranslateB2DHomMatrix(aVector));
2601cdf0e10cSrcweir 
2602cdf0e10cSrcweir                                 // transform existing region
2603cdf0e10cSrcweir                                 basegfx::B2DPolyPolygon aClipPolyPolygon(
2604cdf0e10cSrcweir                                     rPropertyHolders.Current().getClipPolyPolygon());
2605cdf0e10cSrcweir 
2606cdf0e10cSrcweir                                 aClipPolyPolygon.transform(aTransform);
2607cdf0e10cSrcweir                                 HandleNewClipRegion(aClipPolyPolygon, rTargetHolders, rPropertyHolders);
2608cdf0e10cSrcweir                             }
2609cdf0e10cSrcweir                         }
2610cdf0e10cSrcweir                     }
2611cdf0e10cSrcweir 
2612cdf0e10cSrcweir                     break;
2613cdf0e10cSrcweir                 }
2614cdf0e10cSrcweir                 case META_LINECOLOR_ACTION :
2615cdf0e10cSrcweir                 {
2616cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2617cdf0e10cSrcweir                     const MetaLineColorAction* pA = (const MetaLineColorAction*)pAction;
2618cdf0e10cSrcweir                     const bool bActive(pA->IsSetting());
2619cdf0e10cSrcweir 
2620cdf0e10cSrcweir                     rPropertyHolders.Current().setLineColorActive(bActive);
2621cdf0e10cSrcweir                     if(bActive)
2622cdf0e10cSrcweir                         rPropertyHolders.Current().setLineColor(pA->GetColor().getBColor());
2623cdf0e10cSrcweir 
2624cdf0e10cSrcweir                     break;
2625cdf0e10cSrcweir                 }
2626cdf0e10cSrcweir                 case META_FILLCOLOR_ACTION :
2627cdf0e10cSrcweir                 {
2628cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2629cdf0e10cSrcweir                     const MetaFillColorAction* pA = (const MetaFillColorAction*)pAction;
2630cdf0e10cSrcweir                     const bool bActive(pA->IsSetting());
2631cdf0e10cSrcweir 
2632cdf0e10cSrcweir                     rPropertyHolders.Current().setFillColorActive(bActive);
2633cdf0e10cSrcweir                     if(bActive)
2634cdf0e10cSrcweir                         rPropertyHolders.Current().setFillColor(pA->GetColor().getBColor());
2635cdf0e10cSrcweir 
2636cdf0e10cSrcweir                     break;
2637cdf0e10cSrcweir                 }
2638cdf0e10cSrcweir                 case META_TEXTCOLOR_ACTION :
2639cdf0e10cSrcweir                 {
2640cdf0e10cSrcweir 					/** SIMPLE, DONE */
2641cdf0e10cSrcweir                     const MetaTextColorAction* pA = (const MetaTextColorAction*)pAction;
2642cdf0e10cSrcweir                     const bool bActivate(COL_TRANSPARENT != pA->GetColor().GetColor());
2643cdf0e10cSrcweir 
2644cdf0e10cSrcweir                     rPropertyHolders.Current().setTextColorActive(bActivate);
2645cdf0e10cSrcweir                     rPropertyHolders.Current().setTextColor(pA->GetColor().getBColor());
2646cdf0e10cSrcweir 
2647cdf0e10cSrcweir                     break;
2648cdf0e10cSrcweir                 }
2649cdf0e10cSrcweir                 case META_TEXTFILLCOLOR_ACTION :
2650cdf0e10cSrcweir                 {
2651cdf0e10cSrcweir 					/** SIMPLE, DONE */
2652cdf0e10cSrcweir                     const MetaTextFillColorAction* pA = (const MetaTextFillColorAction*)pAction;
2653cdf0e10cSrcweir                     const bool bWithColorArgument(pA->IsSetting());
2654cdf0e10cSrcweir 
2655cdf0e10cSrcweir                     if(bWithColorArgument)
2656cdf0e10cSrcweir                     {
2657cdf0e10cSrcweir                         // emulate OutputDevice::SetTextFillColor(...) WITH argument
2658cdf0e10cSrcweir                     	const Color& rFontFillColor = pA->GetColor();
2659cdf0e10cSrcweir                         rPropertyHolders.Current().setTextFillColor(rFontFillColor.getBColor());
2660cdf0e10cSrcweir                         rPropertyHolders.Current().setTextFillColorActive(COL_TRANSPARENT != rFontFillColor.GetColor());
2661cdf0e10cSrcweir                     }
2662cdf0e10cSrcweir                     else
2663cdf0e10cSrcweir                     {
2664cdf0e10cSrcweir                         // emulate SetFillColor() <- NO argument (!)
2665cdf0e10cSrcweir                         rPropertyHolders.Current().setTextFillColorActive(false);
2666cdf0e10cSrcweir                     }
2667cdf0e10cSrcweir 
2668cdf0e10cSrcweir                     break;
2669cdf0e10cSrcweir                 }
2670cdf0e10cSrcweir                 case META_TEXTALIGN_ACTION :
2671cdf0e10cSrcweir                 {
2672cdf0e10cSrcweir 					/** SIMPLE, DONE */
2673cdf0e10cSrcweir                     const MetaTextAlignAction* pA = (const MetaTextAlignAction*)pAction;
2674cdf0e10cSrcweir             	    const TextAlign aNewTextAlign = pA->GetTextAlign();
2675cdf0e10cSrcweir 
2676cdf0e10cSrcweir                     // TextAlign is applied to the current font (as in
2677cdf0e10cSrcweir                     // OutputDevice::SetTextAlign which would be used when
2678cdf0e10cSrcweir                     // playing the Metafile)
2679cdf0e10cSrcweir                     if(rPropertyHolders.Current().getFont().GetAlign() != aNewTextAlign)
2680cdf0e10cSrcweir                     {
2681cdf0e10cSrcweir                         Font aNewFont(rPropertyHolders.Current().getFont());
2682cdf0e10cSrcweir                         aNewFont.SetAlign(aNewTextAlign);
2683cdf0e10cSrcweir                         rPropertyHolders.Current().setFont(aNewFont);
2684cdf0e10cSrcweir                     }
2685cdf0e10cSrcweir 
2686cdf0e10cSrcweir                     break;
2687cdf0e10cSrcweir                 }
2688cdf0e10cSrcweir                 case META_MAPMODE_ACTION :
2689cdf0e10cSrcweir                 {
2690cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2691cdf0e10cSrcweir                     // the most necessary MapMode to be interpreted is MAP_RELATIVE,
2692cdf0e10cSrcweir                     // but also the others may occur. Even not yet supported ones
2693cdf0e10cSrcweir                     // may need to be added here later
2694cdf0e10cSrcweir                     const MetaMapModeAction* pA = (const MetaMapModeAction*)pAction;
2695cdf0e10cSrcweir 					const MapMode& rMapMode = pA->GetMapMode();
2696cdf0e10cSrcweir 					basegfx::B2DHomMatrix aMapping;
2697cdf0e10cSrcweir 
2698cdf0e10cSrcweir 					if(MAP_RELATIVE == rMapMode.GetMapUnit())
2699cdf0e10cSrcweir 					{
2700cdf0e10cSrcweir 						aMapping = getTransformFromMapMode(rMapMode);
2701cdf0e10cSrcweir 					}
2702cdf0e10cSrcweir 					else
2703cdf0e10cSrcweir 					{
2704cdf0e10cSrcweir 						switch(rMapMode.GetMapUnit())
2705cdf0e10cSrcweir 						{
2706cdf0e10cSrcweir 							case MAP_100TH_MM :
2707cdf0e10cSrcweir 							{
2708cdf0e10cSrcweir 								if(MAP_TWIP == rPropertyHolders.Current().getMapUnit())
2709cdf0e10cSrcweir 								{
2710cdf0e10cSrcweir 									// MAP_TWIP -> MAP_100TH_MM
2711cdf0e10cSrcweir 									const double fTwipTo100thMm(127.0 / 72.0);
2712cdf0e10cSrcweir 									aMapping.scale(fTwipTo100thMm, fTwipTo100thMm);
2713cdf0e10cSrcweir 								}
2714cdf0e10cSrcweir 								break;
2715cdf0e10cSrcweir 							}
2716cdf0e10cSrcweir 							case MAP_TWIP :
2717cdf0e10cSrcweir 							{
2718cdf0e10cSrcweir 								if(MAP_100TH_MM == rPropertyHolders.Current().getMapUnit())
2719cdf0e10cSrcweir 								{
2720cdf0e10cSrcweir 									// MAP_100TH_MM -> MAP_TWIP
2721cdf0e10cSrcweir 									const double f100thMmToTwip(72.0 / 127.0);
2722cdf0e10cSrcweir 									aMapping.scale(f100thMmToTwip, f100thMmToTwip);
2723cdf0e10cSrcweir 								}
2724cdf0e10cSrcweir 								break;
2725cdf0e10cSrcweir 							}
2726cdf0e10cSrcweir 							default :
2727cdf0e10cSrcweir 							{
2728cdf0e10cSrcweir 								OSL_ENSURE(false, "interpretMetafile: META_MAPMODE_ACTION with unsupported MapUnit (!)");
2729cdf0e10cSrcweir 								break;
2730cdf0e10cSrcweir 							}
2731cdf0e10cSrcweir 						}
2732cdf0e10cSrcweir 
2733cdf0e10cSrcweir 						aMapping = getTransformFromMapMode(rMapMode) * aMapping;
2734cdf0e10cSrcweir 						rPropertyHolders.Current().setMapUnit(rMapMode.GetMapUnit());
2735cdf0e10cSrcweir 					}
2736cdf0e10cSrcweir 
2737cdf0e10cSrcweir 					if(!aMapping.isIdentity())
2738cdf0e10cSrcweir 					{
2739cdf0e10cSrcweir 						aMapping = aMapping * rPropertyHolders.Current().getTransformation();
2740cdf0e10cSrcweir 						rPropertyHolders.Current().setTransformation(aMapping);
2741cdf0e10cSrcweir 					}
2742cdf0e10cSrcweir 
2743cdf0e10cSrcweir 					break;
2744cdf0e10cSrcweir                 }
2745cdf0e10cSrcweir                 case META_FONT_ACTION :
2746cdf0e10cSrcweir                 {
2747cdf0e10cSrcweir 					/** SIMPLE, DONE */
2748cdf0e10cSrcweir                     const MetaFontAction* pA = (const MetaFontAction*)pAction;
2749cdf0e10cSrcweir                     rPropertyHolders.Current().setFont(pA->GetFont());
2750cdf0e10cSrcweir                     Size aFontSize(pA->GetFont().GetSize());
2751cdf0e10cSrcweir 
2752cdf0e10cSrcweir                     if(0 == aFontSize.Height())
2753cdf0e10cSrcweir                     {
2754cdf0e10cSrcweir                         // this should not happen but i got Metafiles where this was the
2755cdf0e10cSrcweir                         // case. A height needs to be guessed (similar to OutputDevice::ImplNewFont())
2756cdf0e10cSrcweir                         Font aCorrectedFont(pA->GetFont());
2757cdf0e10cSrcweir 
2758cdf0e10cSrcweir                         // guess 16 pixel (as in VCL)
2759cdf0e10cSrcweir                         aFontSize = Size(0, 16);
2760cdf0e10cSrcweir 
2761cdf0e10cSrcweir                         // convert to target MapUnit if not pixels
2762cdf0e10cSrcweir 					    aFontSize = Application::GetDefaultDevice()->LogicToLogic(
2763cdf0e10cSrcweir 							aFontSize, MAP_PIXEL, rPropertyHolders.Current().getMapUnit());
2764cdf0e10cSrcweir 
2765cdf0e10cSrcweir                         aCorrectedFont.SetSize(aFontSize);
2766cdf0e10cSrcweir                         rPropertyHolders.Current().setFont(aCorrectedFont);
2767cdf0e10cSrcweir                     }
2768cdf0e10cSrcweir 
2769cdf0e10cSrcweir                     // older Metafiles have no META_TEXTCOLOR_ACTION which defines
2770cdf0e10cSrcweir                     // the FontColor now, so use the Font's color when not transparent
2771cdf0e10cSrcweir                     const Color& rFontColor = pA->GetFont().GetColor();
2772cdf0e10cSrcweir                     const bool bActivate(COL_TRANSPARENT != rFontColor.GetColor());
2773cdf0e10cSrcweir 
2774cdf0e10cSrcweir                     if(bActivate)
2775cdf0e10cSrcweir                     {
2776cdf0e10cSrcweir                         rPropertyHolders.Current().setTextColor(rFontColor.getBColor());
2777cdf0e10cSrcweir                     }
2778cdf0e10cSrcweir 
2779cdf0e10cSrcweir                     // caution: do NOT decativate here on transparet, see
2780cdf0e10cSrcweir                     // OutputDevice::SetFont(..) for more info
2781cdf0e10cSrcweir                     // rPropertyHolders.Current().setTextColorActive(bActivate);
2782cdf0e10cSrcweir 
2783cdf0e10cSrcweir                     // for fill color emulate a MetaTextFillColorAction with !transparent as bool,
2784cdf0e10cSrcweir                     // see OutputDevice::SetFont(..) the if(mpMetaFile) case
2785cdf0e10cSrcweir                     if(bActivate)
2786cdf0e10cSrcweir                     {
2787cdf0e10cSrcweir                     	const Color& rFontFillColor = pA->GetFont().GetFillColor();
2788cdf0e10cSrcweir                         rPropertyHolders.Current().setTextFillColor(rFontFillColor.getBColor());
2789cdf0e10cSrcweir                         rPropertyHolders.Current().setTextFillColorActive(COL_TRANSPARENT != rFontFillColor.GetColor());
2790cdf0e10cSrcweir                     }
2791cdf0e10cSrcweir                     else
2792cdf0e10cSrcweir                     {
2793cdf0e10cSrcweir                         rPropertyHolders.Current().setTextFillColorActive(false);
2794cdf0e10cSrcweir                     }
2795cdf0e10cSrcweir 
2796cdf0e10cSrcweir                     break;
2797cdf0e10cSrcweir                 }
2798cdf0e10cSrcweir                 case META_PUSH_ACTION :
2799cdf0e10cSrcweir                 {
2800cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2801cdf0e10cSrcweir                     const MetaPushAction* pA = (const MetaPushAction*)pAction;
2802cdf0e10cSrcweir                     rPropertyHolders.Push(pA->GetFlags());
2803cdf0e10cSrcweir 
2804cdf0e10cSrcweir                     break;
2805cdf0e10cSrcweir                 }
2806cdf0e10cSrcweir                 case META_POP_ACTION :
2807cdf0e10cSrcweir                 {
2808cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2809cdf0e10cSrcweir                     const bool bRegionMayChange(rPropertyHolders.Current().getPushFlags() & PUSH_CLIPREGION);
2810cdf0e10cSrcweir                     const bool bRasterOpMayChange(rPropertyHolders.Current().getPushFlags() & PUSH_RASTEROP);
2811cdf0e10cSrcweir 
2812cdf0e10cSrcweir                     if(bRegionMayChange && rPropertyHolders.Current().getClipPolyPolygonActive())
2813cdf0e10cSrcweir                     {
2814cdf0e10cSrcweir                         // end evtl. clipping
2815cdf0e10cSrcweir                         const basegfx::B2DPolyPolygon aEmptyPolyPolygon;
2816cdf0e10cSrcweir 
2817cdf0e10cSrcweir                         HandleNewClipRegion(aEmptyPolyPolygon, rTargetHolders, rPropertyHolders);
2818cdf0e10cSrcweir                     }
2819cdf0e10cSrcweir 
2820cdf0e10cSrcweir                     if(bRasterOpMayChange && rPropertyHolders.Current().isRasterOpActive())
2821cdf0e10cSrcweir                     {
2822cdf0e10cSrcweir                         // end evtl. RasterOp
2823cdf0e10cSrcweir                         HandleNewRasterOp(ROP_OVERPAINT, rTargetHolders, rPropertyHolders);
2824cdf0e10cSrcweir                     }
2825cdf0e10cSrcweir 
2826cdf0e10cSrcweir                     rPropertyHolders.Pop();
2827cdf0e10cSrcweir 
2828cdf0e10cSrcweir                     if(bRasterOpMayChange && rPropertyHolders.Current().isRasterOpActive())
2829cdf0e10cSrcweir                     {
2830cdf0e10cSrcweir                         // start evtl. RasterOp
2831cdf0e10cSrcweir                         HandleNewRasterOp(rPropertyHolders.Current().getRasterOp(), rTargetHolders, rPropertyHolders);
2832cdf0e10cSrcweir                     }
2833cdf0e10cSrcweir 
2834cdf0e10cSrcweir                     if(bRegionMayChange && rPropertyHolders.Current().getClipPolyPolygonActive())
2835cdf0e10cSrcweir                     {
2836cdf0e10cSrcweir                         // start evtl. clipping
2837cdf0e10cSrcweir                         HandleNewClipRegion(
2838cdf0e10cSrcweir                             rPropertyHolders.Current().getClipPolyPolygon(), rTargetHolders, rPropertyHolders);
2839cdf0e10cSrcweir                     }
2840cdf0e10cSrcweir 
2841cdf0e10cSrcweir                     break;
2842cdf0e10cSrcweir                 }
2843cdf0e10cSrcweir                 case META_RASTEROP_ACTION :
2844cdf0e10cSrcweir                 {
2845cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2846cdf0e10cSrcweir                     const MetaRasterOpAction* pA = (const MetaRasterOpAction*)pAction;
2847cdf0e10cSrcweir                 	const RasterOp aRasterOp = pA->GetRasterOp();
2848cdf0e10cSrcweir 
2849cdf0e10cSrcweir                     HandleNewRasterOp(aRasterOp, rTargetHolders, rPropertyHolders);
2850cdf0e10cSrcweir 
2851cdf0e10cSrcweir                     break;
2852cdf0e10cSrcweir                 }
2853cdf0e10cSrcweir                 case META_TRANSPARENT_ACTION :
2854cdf0e10cSrcweir                 {
2855cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2856cdf0e10cSrcweir                     const MetaTransparentAction* pA = (const MetaTransparentAction*)pAction;
2857cdf0e10cSrcweir 					const basegfx::B2DPolyPolygon aOutline(pA->GetPolyPolygon().getB2DPolyPolygon());
2858cdf0e10cSrcweir 
2859cdf0e10cSrcweir 					if(aOutline.count())
2860cdf0e10cSrcweir 					{
2861cdf0e10cSrcweir 						const sal_uInt16 nTransparence(pA->GetTransparence());
2862cdf0e10cSrcweir 
2863cdf0e10cSrcweir 						if(0 == nTransparence)
2864cdf0e10cSrcweir 						{
2865cdf0e10cSrcweir 							// not transparent
2866cdf0e10cSrcweir 							createHairlineAndFillPrimitive(aOutline, rTargetHolders.Current(), rPropertyHolders.Current());
2867cdf0e10cSrcweir 						}
2868cdf0e10cSrcweir 						else if(nTransparence >= 100)
2869cdf0e10cSrcweir 						{
2870cdf0e10cSrcweir 							// fully or more than transparent
2871cdf0e10cSrcweir 						}
2872cdf0e10cSrcweir 						else
2873cdf0e10cSrcweir 						{
2874cdf0e10cSrcweir 							// transparent. Create new target
2875cdf0e10cSrcweir                             rTargetHolders.Push();
2876cdf0e10cSrcweir 
2877cdf0e10cSrcweir 							// create primitives there and get them
2878cdf0e10cSrcweir 							createHairlineAndFillPrimitive(aOutline, rTargetHolders.Current(), rPropertyHolders.Current());
2879cdf0e10cSrcweir 							const drawinglayer::primitive2d::Primitive2DSequence aSubContent(
2880cdf0e10cSrcweir                                 rTargetHolders.Current().getPrimitive2DSequence(rPropertyHolders.Current()));
2881cdf0e10cSrcweir 
2882cdf0e10cSrcweir 							// back to old target
2883cdf0e10cSrcweir                             rTargetHolders.Pop();
2884cdf0e10cSrcweir 
2885cdf0e10cSrcweir 							if(aSubContent.hasElements())
2886cdf0e10cSrcweir 							{
2887cdf0e10cSrcweir 								rTargetHolders.Current().append(
2888cdf0e10cSrcweir 									new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D(
2889cdf0e10cSrcweir 										aSubContent,
2890cdf0e10cSrcweir 										nTransparence * 0.01));
2891cdf0e10cSrcweir 							}
2892cdf0e10cSrcweir 						}
2893cdf0e10cSrcweir 					}
2894cdf0e10cSrcweir 
2895cdf0e10cSrcweir                     break;
2896cdf0e10cSrcweir                 }
2897cdf0e10cSrcweir                 case META_EPS_ACTION :
2898cdf0e10cSrcweir                 {
2899cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2900cdf0e10cSrcweir 					// To support this action, i have added a EpsPrimitive2D which will
2901cdf0e10cSrcweir 					// by default decompose to the Metafile replacement data. To support
2902cdf0e10cSrcweir 					// this EPS on screen, the renderer visualizing this has to support
2903cdf0e10cSrcweir 					// that primitive and visualize the Eps file (e.g. printing)
2904cdf0e10cSrcweir                     const MetaEPSAction* pA = (const MetaEPSAction*)pAction;
2905cdf0e10cSrcweir 					const Rectangle aRectangle(pA->GetPoint(), pA->GetSize());
2906cdf0e10cSrcweir 
2907cdf0e10cSrcweir 					if(!aRectangle.IsEmpty())
2908cdf0e10cSrcweir                     {
2909cdf0e10cSrcweir 						// create object transform
2910cdf0e10cSrcweir 						basegfx::B2DHomMatrix aObjectTransform;
2911cdf0e10cSrcweir 
2912cdf0e10cSrcweir 						aObjectTransform.set(0, 0, aRectangle.GetWidth());
2913cdf0e10cSrcweir 						aObjectTransform.set(1, 1, aRectangle.GetHeight());
2914cdf0e10cSrcweir 						aObjectTransform.set(0, 2, aRectangle.Left());
2915cdf0e10cSrcweir 						aObjectTransform.set(1, 2, aRectangle.Top());
2916cdf0e10cSrcweir 
2917cdf0e10cSrcweir 						// add current transformation
2918cdf0e10cSrcweir 						aObjectTransform = rPropertyHolders.Current().getTransformation() * aObjectTransform;
2919cdf0e10cSrcweir 
2920cdf0e10cSrcweir 						// embed using EpsPrimitive
2921cdf0e10cSrcweir 						rTargetHolders.Current().append(
2922cdf0e10cSrcweir 							new drawinglayer::primitive2d::EpsPrimitive2D(
2923cdf0e10cSrcweir 								aObjectTransform,
2924cdf0e10cSrcweir 								pA->GetLink(),
2925cdf0e10cSrcweir 								pA->GetSubstitute()));
2926cdf0e10cSrcweir 					}
2927cdf0e10cSrcweir 
2928cdf0e10cSrcweir 					break;
2929cdf0e10cSrcweir                 }
2930cdf0e10cSrcweir                 case META_REFPOINT_ACTION :
2931cdf0e10cSrcweir                 {
2932cdf0e10cSrcweir 					/** SIMPLE, DONE */
2933cdf0e10cSrcweir                     // only used for hatch and line pattern offsets, pretty much no longer
2934cdf0e10cSrcweir                     // supported today
2935cdf0e10cSrcweir                     // const MetaRefPointAction* pA = (const MetaRefPointAction*)pAction;
2936cdf0e10cSrcweir                     break;
2937cdf0e10cSrcweir                 }
2938cdf0e10cSrcweir                 case META_TEXTLINECOLOR_ACTION :
2939cdf0e10cSrcweir                 {
2940cdf0e10cSrcweir 					/** SIMPLE, DONE */
2941cdf0e10cSrcweir                     const MetaTextLineColorAction* pA = (const MetaTextLineColorAction*)pAction;
2942cdf0e10cSrcweir                     const bool bActive(pA->IsSetting());
2943cdf0e10cSrcweir 
2944cdf0e10cSrcweir                     rPropertyHolders.Current().setTextLineColorActive(bActive);
2945cdf0e10cSrcweir                     if(bActive)
2946cdf0e10cSrcweir                         rPropertyHolders.Current().setTextLineColor(pA->GetColor().getBColor());
2947cdf0e10cSrcweir 
2948cdf0e10cSrcweir                     break;
2949cdf0e10cSrcweir                 }
2950cdf0e10cSrcweir                 case META_TEXTLINE_ACTION :
2951cdf0e10cSrcweir                 {
2952cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2953cdf0e10cSrcweir 					// actually creates overline, underline and strikeouts, so
2954cdf0e10cSrcweir 					// these should be isolated from TextDecoratedPortionPrimitive2D
2955cdf0e10cSrcweir 					// to own primitives. Done, available now.
2956cdf0e10cSrcweir 					//
2957cdf0e10cSrcweir 					// This Metaaction seems not to be used (was not used in any
2958cdf0e10cSrcweir 					// checked files). It's used in combination with the current
2959cdf0e10cSrcweir 					// Font.
2960cdf0e10cSrcweir                     const MetaTextLineAction* pA = (const MetaTextLineAction*)pAction;
2961cdf0e10cSrcweir 
2962cdf0e10cSrcweir 					proccessMetaTextLineAction(
2963cdf0e10cSrcweir 						*pA,
2964cdf0e10cSrcweir 						rTargetHolders.Current(),
2965cdf0e10cSrcweir 						rPropertyHolders.Current());
2966cdf0e10cSrcweir 
2967cdf0e10cSrcweir                     break;
2968cdf0e10cSrcweir                 }
2969cdf0e10cSrcweir                 case META_FLOATTRANSPARENT_ACTION :
2970cdf0e10cSrcweir                 {
2971cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2972cdf0e10cSrcweir                     const MetaFloatTransparentAction* pA = (const MetaFloatTransparentAction*)pAction;
2973cdf0e10cSrcweir 					const Rectangle aTargetRectangle(pA->GetPoint(), pA->GetSize());
2974cdf0e10cSrcweir 
2975cdf0e10cSrcweir 					if(!aTargetRectangle.IsEmpty())
2976cdf0e10cSrcweir 					{
2977cdf0e10cSrcweir 						const GDIMetaFile& rContent = pA->GetGDIMetaFile();
2978cdf0e10cSrcweir 
2979cdf0e10cSrcweir 						if(rContent.GetActionCount())
2980cdf0e10cSrcweir 						{
2981cdf0e10cSrcweir 							// create the sub-content with no embedding specific to the
2982cdf0e10cSrcweir 							// sub-metafile, this seems not to be used.
2983cdf0e10cSrcweir 							drawinglayer::primitive2d::Primitive2DSequence xSubContent;
2984cdf0e10cSrcweir 							{
2985cdf0e10cSrcweir                                 rTargetHolders.Push();
2986cdf0e10cSrcweir 								// #i# for sub-Mteafile contents, do start with new, default render state
2987cdf0e10cSrcweir 								rPropertyHolders.PushDefault();
2988cdf0e10cSrcweir 								interpretMetafile(rContent, rTargetHolders, rPropertyHolders, rViewInformation);
2989cdf0e10cSrcweir 								xSubContent = rTargetHolders.Current().getPrimitive2DSequence(rPropertyHolders.Current());
2990cdf0e10cSrcweir 								rPropertyHolders.Pop();
2991cdf0e10cSrcweir                                 rTargetHolders.Pop();
2992cdf0e10cSrcweir 							}
2993cdf0e10cSrcweir 
2994cdf0e10cSrcweir 							if(xSubContent.hasElements())
2995cdf0e10cSrcweir 							{
2996cdf0e10cSrcweir 								// check if gradient is a real gradient
2997cdf0e10cSrcweir 								const Gradient& rGradient = pA->GetGradient();
2998cdf0e10cSrcweir 								const drawinglayer::attribute::FillGradientAttribute aAttribute(createFillGradientAttribute(rGradient));
2999cdf0e10cSrcweir 
3000cdf0e10cSrcweir 								if(aAttribute.getStartColor() == aAttribute.getEndColor())
3001cdf0e10cSrcweir 								{
3002cdf0e10cSrcweir 									// not really a gradient; create UnifiedTransparencePrimitive2D
3003cdf0e10cSrcweir 									rTargetHolders.Current().append(
3004cdf0e10cSrcweir 										new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D(
3005cdf0e10cSrcweir 											xSubContent,
3006cdf0e10cSrcweir 											aAttribute.getStartColor().luminance()));
3007cdf0e10cSrcweir 								}
3008cdf0e10cSrcweir 								else
3009cdf0e10cSrcweir 								{
3010cdf0e10cSrcweir 									// really a gradient. Create gradient sub-content (with correct scaling)
3011cdf0e10cSrcweir 									basegfx::B2DRange aRange(
3012cdf0e10cSrcweir 										aTargetRectangle.Left(), aTargetRectangle.Top(),
3013cdf0e10cSrcweir 										aTargetRectangle.Right(), aTargetRectangle.Bottom());
3014cdf0e10cSrcweir 									aRange.transform(rPropertyHolders.Current().getTransformation());
3015cdf0e10cSrcweir 
3016cdf0e10cSrcweir                                     // prepare gradient for transparent content
3017cdf0e10cSrcweir 			                        const drawinglayer::primitive2d::Primitive2DReference xTransparence(
3018cdf0e10cSrcweir 				                        new drawinglayer::primitive2d::FillGradientPrimitive2D(
3019cdf0e10cSrcweir 										    aRange,
3020cdf0e10cSrcweir 										    aAttribute));
3021cdf0e10cSrcweir 
3022cdf0e10cSrcweir 									// create transparence primitive
3023cdf0e10cSrcweir 									rTargetHolders.Current().append(
3024cdf0e10cSrcweir 										new drawinglayer::primitive2d::TransparencePrimitive2D(
3025cdf0e10cSrcweir 											xSubContent,
3026cdf0e10cSrcweir                                             drawinglayer::primitive2d::Primitive2DSequence(&xTransparence, 1)));
3027cdf0e10cSrcweir 								}
3028cdf0e10cSrcweir 							}
3029cdf0e10cSrcweir 						}
3030cdf0e10cSrcweir 					}
3031cdf0e10cSrcweir 
3032cdf0e10cSrcweir                     break;
3033cdf0e10cSrcweir                 }
3034cdf0e10cSrcweir                 case META_GRADIENTEX_ACTION :
3035cdf0e10cSrcweir                 {
3036cdf0e10cSrcweir 					/** SIMPLE, DONE */
3037cdf0e10cSrcweir                     // This is only a data holder which is interpreted inside comment actions,
3038cdf0e10cSrcweir                     // see META_COMMENT_ACTION for more info
3039cdf0e10cSrcweir                     // const MetaGradientExAction* pA = (const MetaGradientExAction*)pAction;
3040cdf0e10cSrcweir                     break;
3041cdf0e10cSrcweir                 }
3042cdf0e10cSrcweir                 case META_LAYOUTMODE_ACTION :
3043cdf0e10cSrcweir                 {
3044cdf0e10cSrcweir 					/** SIMPLE, DONE */
3045cdf0e10cSrcweir                     const MetaLayoutModeAction* pA = (const MetaLayoutModeAction*)pAction;
3046cdf0e10cSrcweir                     rPropertyHolders.Current().setLayoutMode(pA->GetLayoutMode());
3047cdf0e10cSrcweir                     break;
3048cdf0e10cSrcweir                 }
3049cdf0e10cSrcweir                 case META_TEXTLANGUAGE_ACTION :
3050cdf0e10cSrcweir                 {
3051cdf0e10cSrcweir 					/** SIMPLE, DONE */
3052cdf0e10cSrcweir                     const MetaTextLanguageAction* pA = (const MetaTextLanguageAction*)pAction;
3053cdf0e10cSrcweir                     rPropertyHolders.Current().setLanguageType(pA->GetTextLanguage());
3054cdf0e10cSrcweir                     break;
3055cdf0e10cSrcweir                 }
3056cdf0e10cSrcweir                 case META_OVERLINECOLOR_ACTION :
3057cdf0e10cSrcweir                 {
3058cdf0e10cSrcweir 					/** SIMPLE, DONE */
3059cdf0e10cSrcweir                     const MetaOverlineColorAction* pA = (const MetaOverlineColorAction*)pAction;
3060cdf0e10cSrcweir                     const bool bActive(pA->IsSetting());
3061cdf0e10cSrcweir 
3062cdf0e10cSrcweir                     rPropertyHolders.Current().setOverlineColorActive(bActive);
3063cdf0e10cSrcweir                     if(bActive)
3064cdf0e10cSrcweir                         rPropertyHolders.Current().setOverlineColor(pA->GetColor().getBColor());
3065cdf0e10cSrcweir 
3066cdf0e10cSrcweir                     break;
3067cdf0e10cSrcweir                 }
3068cdf0e10cSrcweir                 case META_COMMENT_ACTION :
3069cdf0e10cSrcweir                 {
3070cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
3071cdf0e10cSrcweir                     // I already implemented
3072cdf0e10cSrcweir                     //     XPATHFILL_SEQ_BEGIN, XPATHFILL_SEQ_END
3073cdf0e10cSrcweir                     //     XPATHSTROKE_SEQ_BEGIN, XPATHSTROKE_SEQ_END,
3074cdf0e10cSrcweir                     // but opted to remove these again; it works well without them
3075cdf0e10cSrcweir                     // and makes the code less dependent from those Metafile Add-Ons
3076cdf0e10cSrcweir                     const MetaCommentAction* pA = (const MetaCommentAction*)pAction;
3077cdf0e10cSrcweir 
3078cdf0e10cSrcweir 					if(COMPARE_EQUAL == pA->GetComment().CompareIgnoreCaseToAscii("XGRAD_SEQ_BEGIN"))
3079cdf0e10cSrcweir 					{
3080cdf0e10cSrcweir                         // XGRAD_SEQ_BEGIN, XGRAD_SEQ_END should be supported since the
3081cdf0e10cSrcweir                         // pure recorded paint of the gradients uses the XOR paint functionality
3082cdf0e10cSrcweir                         // ('trick'). This is (and will be) broblematic with AntAliasing, so it's
3083cdf0e10cSrcweir                         // better to use this info
3084cdf0e10cSrcweir 						const MetaGradientExAction*	pMetaGradientExAction = 0;
3085cdf0e10cSrcweir 						bool bDone(false);
3086cdf0e10cSrcweir 						sal_uInt32 b(nAction + 1);
3087cdf0e10cSrcweir 
3088cdf0e10cSrcweir 						for(; !bDone && b < nCount; b++)
3089cdf0e10cSrcweir 						{
3090cdf0e10cSrcweir 							pAction = rMetaFile.GetAction(b);
3091cdf0e10cSrcweir 
3092cdf0e10cSrcweir 							if(META_GRADIENTEX_ACTION == pAction->GetType())
3093cdf0e10cSrcweir 							{
3094cdf0e10cSrcweir 								pMetaGradientExAction = (const MetaGradientExAction*)pAction;
3095cdf0e10cSrcweir 							}
3096cdf0e10cSrcweir 							else if(META_COMMENT_ACTION == pAction->GetType())
3097cdf0e10cSrcweir 							{
3098cdf0e10cSrcweir 								if(COMPARE_EQUAL == ((const MetaCommentAction*)pAction)->GetComment().CompareIgnoreCaseToAscii("XGRAD_SEQ_END"))
3099cdf0e10cSrcweir 								{
3100cdf0e10cSrcweir 									bDone = true;
3101cdf0e10cSrcweir 								}
3102cdf0e10cSrcweir 							}
3103cdf0e10cSrcweir 						}
3104cdf0e10cSrcweir 
3105cdf0e10cSrcweir 						if(bDone && pMetaGradientExAction)
3106cdf0e10cSrcweir 						{
3107cdf0e10cSrcweir 							// consume actions and skip forward
3108cdf0e10cSrcweir 							nAction = b - 1;
3109cdf0e10cSrcweir 
3110cdf0e10cSrcweir 							// get geometry data
3111cdf0e10cSrcweir 							basegfx::B2DPolyPolygon aPolyPolygon(pMetaGradientExAction->GetPolyPolygon().getB2DPolyPolygon());
3112cdf0e10cSrcweir 
3113cdf0e10cSrcweir 							if(aPolyPolygon.count())
3114cdf0e10cSrcweir 							{
3115cdf0e10cSrcweir 								// transform geometry
3116cdf0e10cSrcweir 								aPolyPolygon.transform(rPropertyHolders.Current().getTransformation());
3117cdf0e10cSrcweir 
3118cdf0e10cSrcweir 								// get and check if gradient is a real gradient
3119cdf0e10cSrcweir 								const Gradient& rGradient = pMetaGradientExAction->GetGradient();
3120cdf0e10cSrcweir 								const drawinglayer::attribute::FillGradientAttribute aAttribute(createFillGradientAttribute(rGradient));
3121cdf0e10cSrcweir 
3122cdf0e10cSrcweir 								if(aAttribute.getStartColor() == aAttribute.getEndColor())
3123cdf0e10cSrcweir 								{
3124cdf0e10cSrcweir 									// not really a gradient
3125cdf0e10cSrcweir 									rTargetHolders.Current().append(
3126cdf0e10cSrcweir 										new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
3127cdf0e10cSrcweir 											aPolyPolygon,
3128cdf0e10cSrcweir 											aAttribute.getStartColor()));
3129cdf0e10cSrcweir 								}
3130cdf0e10cSrcweir 								else
3131cdf0e10cSrcweir 								{
3132cdf0e10cSrcweir 									// really a gradient
3133cdf0e10cSrcweir 									rTargetHolders.Current().append(
3134cdf0e10cSrcweir 										new drawinglayer::primitive2d::PolyPolygonGradientPrimitive2D(
3135cdf0e10cSrcweir 											aPolyPolygon,
3136cdf0e10cSrcweir 											aAttribute));
3137cdf0e10cSrcweir 								}
3138cdf0e10cSrcweir 							}
3139cdf0e10cSrcweir 						}
3140cdf0e10cSrcweir 					}
3141cdf0e10cSrcweir 
3142cdf0e10cSrcweir 					break;
3143cdf0e10cSrcweir                 }
3144cdf0e10cSrcweir                 default:
3145cdf0e10cSrcweir                 {
3146cdf0e10cSrcweir                     OSL_ENSURE(false, "Unknown MetaFile Action (!)");
3147cdf0e10cSrcweir                     break;
3148cdf0e10cSrcweir                 }
3149cdf0e10cSrcweir             }
3150cdf0e10cSrcweir         }
3151cdf0e10cSrcweir     }
3152cdf0e10cSrcweir } // end of anonymous namespace
3153cdf0e10cSrcweir 
3154cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
3155cdf0e10cSrcweir 
3156cdf0e10cSrcweir namespace drawinglayer
3157cdf0e10cSrcweir {
3158cdf0e10cSrcweir 	namespace primitive2d
3159cdf0e10cSrcweir 	{
3160cdf0e10cSrcweir 		Primitive2DSequence MetafilePrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
3161cdf0e10cSrcweir         {
3162cdf0e10cSrcweir 			// prepare target and porperties; each will have one default entry
3163cdf0e10cSrcweir             TargetHolders aTargetHolders;
3164cdf0e10cSrcweir             PropertyHolders aPropertyHolders;
3165cdf0e10cSrcweir 
3166cdf0e10cSrcweir 			// set target MapUnit at Properties
3167cdf0e10cSrcweir 			aPropertyHolders.Current().setMapUnit(getMetaFile().GetPrefMapMode().GetMapUnit());
3168cdf0e10cSrcweir 
3169cdf0e10cSrcweir 			// interpret the Metafile
3170cdf0e10cSrcweir             interpretMetafile(getMetaFile(), aTargetHolders, aPropertyHolders, rViewInformation);
3171cdf0e10cSrcweir 
3172cdf0e10cSrcweir 			// get the content. There should be ony one target, as in the start condition,
3173cdf0e10cSrcweir             // but iterating will be the right thing to do when some push/pop is not closed
3174cdf0e10cSrcweir 			Primitive2DSequence xRetval;
3175cdf0e10cSrcweir 
3176cdf0e10cSrcweir             while(aTargetHolders.size() > 1)
3177cdf0e10cSrcweir             {
3178cdf0e10cSrcweir                 appendPrimitive2DSequenceToPrimitive2DSequence(xRetval,
3179cdf0e10cSrcweir                     aTargetHolders.Current().getPrimitive2DSequence(aPropertyHolders.Current()));
3180cdf0e10cSrcweir                 aTargetHolders.Pop();
3181cdf0e10cSrcweir             }
3182cdf0e10cSrcweir 
3183cdf0e10cSrcweir             appendPrimitive2DSequenceToPrimitive2DSequence(xRetval,
3184cdf0e10cSrcweir                 aTargetHolders.Current().getPrimitive2DSequence(aPropertyHolders.Current()));
3185cdf0e10cSrcweir 
3186cdf0e10cSrcweir 			if(xRetval.hasElements())
3187cdf0e10cSrcweir 			{
3188cdf0e10cSrcweir 				// get target size
3189cdf0e10cSrcweir 				const Rectangle aMtfTarget(getMetaFile().GetPrefMapMode().GetOrigin(), getMetaFile().GetPrefSize());
3190cdf0e10cSrcweir 
3191cdf0e10cSrcweir                 // create transformation
3192cdf0e10cSrcweir 				basegfx::B2DHomMatrix aAdaptedTransform;
3193cdf0e10cSrcweir 
3194cdf0e10cSrcweir 				aAdaptedTransform.translate(-aMtfTarget.Left(), -aMtfTarget.Top());
3195cdf0e10cSrcweir 				aAdaptedTransform.scale(
3196cdf0e10cSrcweir 					aMtfTarget.getWidth() ? 1.0 / aMtfTarget.getWidth() : 1.0,
3197cdf0e10cSrcweir 					aMtfTarget.getHeight() ? 1.0 / aMtfTarget.getHeight() : 1.0);
3198cdf0e10cSrcweir 				aAdaptedTransform = getTransform() * aAdaptedTransform;
3199cdf0e10cSrcweir 
3200cdf0e10cSrcweir 				// embed to target transformation
3201cdf0e10cSrcweir 				const Primitive2DReference aEmbeddedTransform(
3202cdf0e10cSrcweir 					new TransformPrimitive2D(
3203cdf0e10cSrcweir 						aAdaptedTransform,
3204cdf0e10cSrcweir 						xRetval));
3205cdf0e10cSrcweir 
3206cdf0e10cSrcweir 				xRetval = Primitive2DSequence(&aEmbeddedTransform, 1);
3207cdf0e10cSrcweir 			}
3208cdf0e10cSrcweir 
3209cdf0e10cSrcweir             return xRetval;
3210cdf0e10cSrcweir         }
3211cdf0e10cSrcweir 
3212cdf0e10cSrcweir 		MetafilePrimitive2D::MetafilePrimitive2D(
3213cdf0e10cSrcweir 			const basegfx::B2DHomMatrix& rMetaFileTransform,
3214cdf0e10cSrcweir 			const GDIMetaFile& rMetaFile)
3215cdf0e10cSrcweir 		:	BufferedDecompositionPrimitive2D(),
3216cdf0e10cSrcweir 			maMetaFileTransform(rMetaFileTransform),
3217cdf0e10cSrcweir 			maMetaFile(rMetaFile)
3218cdf0e10cSrcweir 		{
3219cdf0e10cSrcweir 		}
3220cdf0e10cSrcweir 
3221cdf0e10cSrcweir 		bool MetafilePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
3222cdf0e10cSrcweir 		{
3223cdf0e10cSrcweir 			if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
3224cdf0e10cSrcweir 			{
3225cdf0e10cSrcweir 				const MetafilePrimitive2D& rCompare = (MetafilePrimitive2D&)rPrimitive;
3226cdf0e10cSrcweir 
3227cdf0e10cSrcweir 				return (getTransform() == rCompare.getTransform()
3228cdf0e10cSrcweir 					&& getMetaFile() == rCompare.getMetaFile());
3229cdf0e10cSrcweir 			}
3230cdf0e10cSrcweir 
3231cdf0e10cSrcweir 			return false;
3232cdf0e10cSrcweir 		}
3233cdf0e10cSrcweir 
3234cdf0e10cSrcweir 		basegfx::B2DRange MetafilePrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
3235cdf0e10cSrcweir 		{
3236cdf0e10cSrcweir 			// use own implementation to quickly answer the getB2DRange question. The
3237cdf0e10cSrcweir             // MetafilePrimitive2D assumes that all geometry is inside of the shape. If
3238cdf0e10cSrcweir             // this is not the case (i have already seen some wrong Metafiles) it should
3239cdf0e10cSrcweir             // be embedded to a MaskPrimitive2D
3240cdf0e10cSrcweir 			basegfx::B2DRange aRetval(0.0, 0.0, 1.0, 1.0);
3241cdf0e10cSrcweir 			aRetval.transform(getTransform());
3242cdf0e10cSrcweir 
3243cdf0e10cSrcweir             return aRetval;
3244cdf0e10cSrcweir 		}
3245cdf0e10cSrcweir 
3246cdf0e10cSrcweir 		// provide unique ID
3247cdf0e10cSrcweir 		ImplPrimitrive2DIDBlock(MetafilePrimitive2D, PRIMITIVE2D_ID_METAFILEPRIMITIVE2D)
3248cdf0e10cSrcweir 
3249cdf0e10cSrcweir 	} // end of namespace primitive2d
3250cdf0e10cSrcweir } // end of namespace drawinglayer
3251cdf0e10cSrcweir 
3252cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
3253cdf0e10cSrcweir // eof
3254