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>
53*035a2f44SArmin Le Grand #include <drawinglayer/primitive2d/fillgraphicprimitive2d.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,
7095aaf853bSArmin Le Grand 					rLineInfo.GetLineJoin(),
7105aaf853bSArmin 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(),
9670702bc67SArmin Le Grand             3, // same default as VCL, a minimum of three discrete units (pixels) offset
968cdf0e10cSrcweir             false);
969cdf0e10cSrcweir 	}
970cdf0e10cSrcweir 
971cdf0e10cSrcweir 	/** helper to take needed action on ClipRegion change. This method needs to be called
972cdf0e10cSrcweir 		on any Region change, e.g. at the obvious actions doing this, but also at pop-calls
973cdf0e10cSrcweir 		whcih change the Region of the current context. It takes care of creating the
974cdf0e10cSrcweir 		current embeddec context, set the new Region at the context and eventually prepare
975cdf0e10cSrcweir 		a new target for embracing new geometry to the current region
976cdf0e10cSrcweir 	 */
977cdf0e10cSrcweir     void HandleNewClipRegion(
978cdf0e10cSrcweir         const basegfx::B2DPolyPolygon& rClipPolyPolygon,
979cdf0e10cSrcweir         TargetHolders& rTargetHolders,
980cdf0e10cSrcweir         PropertyHolders& rPropertyHolders)
981cdf0e10cSrcweir     {
982cdf0e10cSrcweir         const bool bNewActive(rClipPolyPolygon.count());
983cdf0e10cSrcweir 
984cdf0e10cSrcweir 		// #i108636# The handlig of new ClipPolyPolygons was not done as good as possible
985cdf0e10cSrcweir 		// in the first version of this interpreter; e.g. when a ClipPolyPolygon was set
986cdf0e10cSrcweir 		// initially and then using a lot of push/pop actions, the pop always leads
987cdf0e10cSrcweir 		// to setting a 'new' ClipPolyPolygon which indeed is the return to the ClipPolyPolygon
988cdf0e10cSrcweir 		// of the properties next on the stack.
989cdf0e10cSrcweir         //
990cdf0e10cSrcweir 		// This ClipPolyPolygon is identical to the current one, so there is no need to
991cdf0e10cSrcweir 		// create a MaskPrimitive2D containing the up-to-now created primitives, but
992cdf0e10cSrcweir 		// this was done before. While this does not lead to wrong primitive
993cdf0e10cSrcweir 		// representations of the metafile data, it creates unneccesarily expensive
994cdf0e10cSrcweir 		// representations. Just detecting when no really 'new' ClipPolyPolygon gets set
995cdf0e10cSrcweir 		// solves the problem.
996cdf0e10cSrcweir 
997cdf0e10cSrcweir 		if(!rPropertyHolders.Current().getClipPolyPolygonActive() && !bNewActive)
998cdf0e10cSrcweir 		{
999cdf0e10cSrcweir 			// no active ClipPolyPolygon exchanged by no new one, done
1000cdf0e10cSrcweir 			return;
1001cdf0e10cSrcweir 		}
1002cdf0e10cSrcweir 
1003cdf0e10cSrcweir 		if(rPropertyHolders.Current().getClipPolyPolygonActive() && bNewActive)
1004cdf0e10cSrcweir 		{
1005cdf0e10cSrcweir 			// active ClipPolyPolygon and new active ClipPolyPolygon
1006cdf0e10cSrcweir 			if(rPropertyHolders.Current().getClipPolyPolygon() == rClipPolyPolygon)
1007cdf0e10cSrcweir 			{
1008cdf0e10cSrcweir 				// new is the same as old, done
1009cdf0e10cSrcweir 				return;
1010cdf0e10cSrcweir 			}
1011cdf0e10cSrcweir 		}
1012cdf0e10cSrcweir 
1013cdf0e10cSrcweir 		// Here the old and the new are definitively different, maybe
1014cdf0e10cSrcweir 		// old one and/or new one is not active.
1015cdf0e10cSrcweir 
1016cdf0e10cSrcweir 		// Handle deletion of old ClipPolyPolygon. The process evtl. created primitives which
1017cdf0e10cSrcweir 		// belong to this active ClipPolyPolygon. These need to be embedded to a
1018cdf0e10cSrcweir 		// MaskPrimitive2D accordingly.
1019cdf0e10cSrcweir         if(rPropertyHolders.Current().getClipPolyPolygonActive() && rTargetHolders.size() > 1)
1020cdf0e10cSrcweir         {
1021cdf0e10cSrcweir             drawinglayer::primitive2d::Primitive2DSequence aSubContent;
1022cdf0e10cSrcweir 
1023cdf0e10cSrcweir             if(rPropertyHolders.Current().getClipPolyPolygon().count()
1024cdf0e10cSrcweir                 && rTargetHolders.Current().size())
1025cdf0e10cSrcweir             {
1026cdf0e10cSrcweir                 aSubContent = rTargetHolders.Current().getPrimitive2DSequence(
1027cdf0e10cSrcweir                     rPropertyHolders.Current());
1028cdf0e10cSrcweir             }
1029cdf0e10cSrcweir 
1030cdf0e10cSrcweir             rTargetHolders.Pop();
1031cdf0e10cSrcweir 
1032cdf0e10cSrcweir             if(aSubContent.hasElements())
1033cdf0e10cSrcweir             {
1034cdf0e10cSrcweir                 rTargetHolders.Current().append(
1035cdf0e10cSrcweir 			        new drawinglayer::primitive2d::GroupPrimitive2D(
1036cdf0e10cSrcweir 				        aSubContent));
1037cdf0e10cSrcweir             }
1038cdf0e10cSrcweir         }
1039cdf0e10cSrcweir 
1040cdf0e10cSrcweir         // apply new settings to current properties by setting
1041cdf0e10cSrcweir 		// the new region now
1042cdf0e10cSrcweir         rPropertyHolders.Current().setClipPolyPolygonActive(bNewActive);
1043cdf0e10cSrcweir 
1044cdf0e10cSrcweir         if(bNewActive)
1045cdf0e10cSrcweir         {
1046cdf0e10cSrcweir             rPropertyHolders.Current().setClipPolyPolygon(rClipPolyPolygon);
1047cdf0e10cSrcweir 
1048cdf0e10cSrcweir             // prepare new content holder for new active region
1049cdf0e10cSrcweir             rTargetHolders.Push();
1050cdf0e10cSrcweir         }
1051cdf0e10cSrcweir     }
1052cdf0e10cSrcweir 
1053cdf0e10cSrcweir 	/** helper to handle the change of RasterOp. It takes care of encapsulating all current
1054cdf0e10cSrcweir 		geometry to the current RasterOp (if changed) and needs to be called on any RasterOp
1055cdf0e10cSrcweir 		change. It will also start a new geometry target to embrace to the new RasterOp if
1056cdf0e10cSrcweir 		a changuing RasterOp is used. Currently, ROP_XOR and ROP_INVERT are supported using
1057cdf0e10cSrcweir 		InvertPrimitive2D, and ROP_0 by using a ModifiedColorPrimitive2D to force to black paint
1058cdf0e10cSrcweir 	 */
1059cdf0e10cSrcweir     void HandleNewRasterOp(
1060cdf0e10cSrcweir         RasterOp aRasterOp,
1061cdf0e10cSrcweir         TargetHolders& rTargetHolders,
1062cdf0e10cSrcweir         PropertyHolders& rPropertyHolders)
1063cdf0e10cSrcweir     {
1064cdf0e10cSrcweir         // check if currently active
1065cdf0e10cSrcweir         if(rPropertyHolders.Current().isRasterOpActive() && rTargetHolders.size() > 1)
1066cdf0e10cSrcweir         {
1067cdf0e10cSrcweir             drawinglayer::primitive2d::Primitive2DSequence aSubContent;
1068cdf0e10cSrcweir 
1069cdf0e10cSrcweir             if(rTargetHolders.Current().size())
1070cdf0e10cSrcweir             {
1071cdf0e10cSrcweir                 aSubContent = rTargetHolders.Current().getPrimitive2DSequence(rPropertyHolders.Current());
1072cdf0e10cSrcweir             }
1073cdf0e10cSrcweir 
1074cdf0e10cSrcweir             rTargetHolders.Pop();
1075cdf0e10cSrcweir 
1076cdf0e10cSrcweir             if(aSubContent.hasElements())
1077cdf0e10cSrcweir             {
1078cdf0e10cSrcweir                 if(rPropertyHolders.Current().isRasterOpForceBlack())
1079cdf0e10cSrcweir                 {
1080cdf0e10cSrcweir                     // force content to black
1081cdf0e10cSrcweir                     rTargetHolders.Current().append(
1082cdf0e10cSrcweir 			            new drawinglayer::primitive2d::ModifiedColorPrimitive2D(
1083cdf0e10cSrcweir 				            aSubContent,
1084cdf0e10cSrcweir                             basegfx::BColorModifier(basegfx::BColor(0.0, 0.0, 0.0))));
1085cdf0e10cSrcweir                 }
1086cdf0e10cSrcweir                 else // if(rPropertyHolders.Current().isRasterOpInvert())
1087cdf0e10cSrcweir                 {
1088cdf0e10cSrcweir                     // invert content
1089cdf0e10cSrcweir                     rTargetHolders.Current().append(
1090cdf0e10cSrcweir 			            new drawinglayer::primitive2d::InvertPrimitive2D(
1091cdf0e10cSrcweir 				            aSubContent));
1092cdf0e10cSrcweir                 }
1093cdf0e10cSrcweir             }
1094cdf0e10cSrcweir         }
1095cdf0e10cSrcweir 
1096cdf0e10cSrcweir         // apply new settings
1097cdf0e10cSrcweir         rPropertyHolders.Current().setRasterOp(aRasterOp);
1098cdf0e10cSrcweir 
1099cdf0e10cSrcweir         // check if now active
1100cdf0e10cSrcweir         if(rPropertyHolders.Current().isRasterOpActive())
1101cdf0e10cSrcweir         {
1102cdf0e10cSrcweir             // prepare new content holder for new invert
1103cdf0e10cSrcweir             rTargetHolders.Push();
1104cdf0e10cSrcweir         }
1105cdf0e10cSrcweir     }
1106cdf0e10cSrcweir 
1107cdf0e10cSrcweir 	/** helper to create needed data to emulate the VCL Wallpaper Metafile action.
1108cdf0e10cSrcweir 		It is a quite mighty action. This helper is for simple color filled background.
1109cdf0e10cSrcweir 	 */
1110cdf0e10cSrcweir     drawinglayer::primitive2d::BasePrimitive2D* CreateColorWallpaper(
1111cdf0e10cSrcweir         const basegfx::B2DRange& rRange,
1112cdf0e10cSrcweir         const basegfx::BColor& rColor,
1113cdf0e10cSrcweir         PropertyHolder& rPropertyHolder)
1114cdf0e10cSrcweir     {
1115cdf0e10cSrcweir         basegfx::B2DPolygon aOutline(basegfx::tools::createPolygonFromRect(rRange));
1116cdf0e10cSrcweir 		aOutline.transform(rPropertyHolder.getTransformation());
1117cdf0e10cSrcweir 
1118cdf0e10cSrcweir         return new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
1119cdf0e10cSrcweir 		    basegfx::B2DPolyPolygon(aOutline),
1120cdf0e10cSrcweir 		    rColor);
1121cdf0e10cSrcweir     }
1122cdf0e10cSrcweir 
1123cdf0e10cSrcweir 	/** helper to create needed data to emulate the VCL Wallpaper Metafile action.
1124cdf0e10cSrcweir 		It is a quite mighty action. This helper is for gradient filled background.
1125cdf0e10cSrcweir 	 */
1126cdf0e10cSrcweir     drawinglayer::primitive2d::BasePrimitive2D* CreateGradientWallpaper(
1127cdf0e10cSrcweir         const basegfx::B2DRange& rRange,
1128cdf0e10cSrcweir         const Gradient& rGradient,
1129cdf0e10cSrcweir         PropertyHolder& rPropertyHolder)
1130cdf0e10cSrcweir     {
1131cdf0e10cSrcweir     	const drawinglayer::attribute::FillGradientAttribute aAttribute(createFillGradientAttribute(rGradient));
1132cdf0e10cSrcweir 
1133cdf0e10cSrcweir 		if(aAttribute.getStartColor() == aAttribute.getEndColor())
1134cdf0e10cSrcweir 		{
1135cdf0e10cSrcweir 			// not really a gradient. Create filled rectangle
1136cdf0e10cSrcweir             return CreateColorWallpaper(rRange, aAttribute.getStartColor(), rPropertyHolder);
1137cdf0e10cSrcweir 		}
1138cdf0e10cSrcweir 		else
1139cdf0e10cSrcweir 		{
1140cdf0e10cSrcweir 			// really a gradient
1141cdf0e10cSrcweir 		    drawinglayer::primitive2d::BasePrimitive2D* pRetval =
1142cdf0e10cSrcweir 				new drawinglayer::primitive2d::FillGradientPrimitive2D(
1143cdf0e10cSrcweir 					rRange,
1144cdf0e10cSrcweir 				    aAttribute);
1145cdf0e10cSrcweir 
1146cdf0e10cSrcweir 			if(!rPropertyHolder.getTransformation().isIdentity())
1147cdf0e10cSrcweir             {
1148cdf0e10cSrcweir                 const drawinglayer::primitive2d::Primitive2DReference xPrim(pRetval);
1149cdf0e10cSrcweir                 const drawinglayer::primitive2d::Primitive2DSequence xSeq(&xPrim, 1);
1150cdf0e10cSrcweir 
1151cdf0e10cSrcweir 			    pRetval = new drawinglayer::primitive2d::TransformPrimitive2D(
1152cdf0e10cSrcweir 			        rPropertyHolder.getTransformation(),
1153cdf0e10cSrcweir 			        xSeq);
1154cdf0e10cSrcweir             }
1155cdf0e10cSrcweir 
1156cdf0e10cSrcweir 			return pRetval;
1157cdf0e10cSrcweir 		}
1158cdf0e10cSrcweir     }
1159cdf0e10cSrcweir 
1160cdf0e10cSrcweir 	/** helper to create needed data to emulate the VCL Wallpaper Metafile action.
1161cdf0e10cSrcweir 		It is a quite mighty action. This helper decides if color and/or gradient
1162cdf0e10cSrcweir 		background is needed for the wnated bitmap fill and then creates the needed
1163cdf0e10cSrcweir 		WallpaperBitmapPrimitive2D. This primitive was created for this purpose and
1164cdf0e10cSrcweir 		takes over all needed logic of orientations and tiling.
1165cdf0e10cSrcweir 	 */
1166cdf0e10cSrcweir     void CreateAndAppendBitmapWallpaper(
1167cdf0e10cSrcweir         basegfx::B2DRange aWallpaperRange,
1168cdf0e10cSrcweir 		const Wallpaper& rWallpaper,
1169cdf0e10cSrcweir 		TargetHolder& rTarget,
1170cdf0e10cSrcweir 		PropertyHolder& rProperty)
1171cdf0e10cSrcweir 	{
1172cdf0e10cSrcweir 	    const BitmapEx aBitmapEx(rWallpaper.GetBitmap());
1173cdf0e10cSrcweir 		const WallpaperStyle eWallpaperStyle(rWallpaper.GetStyle());
1174cdf0e10cSrcweir 
1175cdf0e10cSrcweir         // if bitmap visualisation is transparent, maybe background
1176cdf0e10cSrcweir         // needs to be filled. Create background
1177cdf0e10cSrcweir         if(aBitmapEx.IsTransparent()
1178cdf0e10cSrcweir             || (WALLPAPER_TILE != eWallpaperStyle && WALLPAPER_SCALE != eWallpaperStyle))
1179cdf0e10cSrcweir         {
1180cdf0e10cSrcweir             if(rWallpaper.IsGradient())
1181cdf0e10cSrcweir             {
1182cdf0e10cSrcweir                 rTarget.append(
1183cdf0e10cSrcweir 	                CreateGradientWallpaper(
1184cdf0e10cSrcweir 		                aWallpaperRange,
1185cdf0e10cSrcweir                         rWallpaper.GetGradient(),
1186cdf0e10cSrcweir                         rProperty));
1187cdf0e10cSrcweir             }
1188cdf0e10cSrcweir             else if(!rWallpaper.GetColor().GetTransparency())
1189cdf0e10cSrcweir             {
1190cdf0e10cSrcweir                 rTarget.append(
1191cdf0e10cSrcweir 	                CreateColorWallpaper(
1192cdf0e10cSrcweir 		                aWallpaperRange,
1193cdf0e10cSrcweir                         rWallpaper.GetColor().getBColor(),
1194cdf0e10cSrcweir                         rProperty));
1195cdf0e10cSrcweir             }
1196cdf0e10cSrcweir         }
1197cdf0e10cSrcweir 
1198cdf0e10cSrcweir         // use wallpaper rect if set
1199cdf0e10cSrcweir         if(rWallpaper.IsRect() && !rWallpaper.GetRect().IsEmpty())
1200cdf0e10cSrcweir         {
1201cdf0e10cSrcweir             aWallpaperRange = basegfx::B2DRange(
1202cdf0e10cSrcweir                 rWallpaper.GetRect().Left(), rWallpaper.GetRect().Top(),
1203cdf0e10cSrcweir                 rWallpaper.GetRect().Right(), rWallpaper.GetRect().Bottom());
1204cdf0e10cSrcweir         }
1205cdf0e10cSrcweir 
1206cdf0e10cSrcweir 		drawinglayer::primitive2d::BasePrimitive2D* pBitmapWallpaperFill =
1207cdf0e10cSrcweir 	        new drawinglayer::primitive2d::WallpaperBitmapPrimitive2D(
1208cdf0e10cSrcweir 		        aWallpaperRange,
1209cdf0e10cSrcweir 				aBitmapEx,
1210cdf0e10cSrcweir 				eWallpaperStyle);
1211cdf0e10cSrcweir 
1212cdf0e10cSrcweir 		if(rProperty.getTransformation().isIdentity())
1213cdf0e10cSrcweir         {
1214cdf0e10cSrcweir 			// add directly
1215cdf0e10cSrcweir             rTarget.append(pBitmapWallpaperFill);
1216cdf0e10cSrcweir         }
1217cdf0e10cSrcweir         else
1218cdf0e10cSrcweir         {
1219cdf0e10cSrcweir 			// when a transformation is set, embed to it
1220cdf0e10cSrcweir             const drawinglayer::primitive2d::Primitive2DReference xPrim(pBitmapWallpaperFill);
1221cdf0e10cSrcweir 
1222cdf0e10cSrcweir 	        rTarget.append(
1223cdf0e10cSrcweir 		        new drawinglayer::primitive2d::TransformPrimitive2D(
1224cdf0e10cSrcweir 			        rProperty.getTransformation(),
1225cdf0e10cSrcweir 			        drawinglayer::primitive2d::Primitive2DSequence(&xPrim, 1)));
1226cdf0e10cSrcweir         }
1227cdf0e10cSrcweir 	}
1228cdf0e10cSrcweir 
1229cdf0e10cSrcweir 	/** helper to decide UnderlineAbove for text primitives */
1230cdf0e10cSrcweir 	bool isUnderlineAbove(const Font& rFont)
1231cdf0e10cSrcweir 	{
1232cdf0e10cSrcweir 		if(!rFont.IsVertical())
1233cdf0e10cSrcweir 		{
1234cdf0e10cSrcweir 			return false;
1235cdf0e10cSrcweir 		}
1236cdf0e10cSrcweir 
1237cdf0e10cSrcweir 		if((LANGUAGE_JAPANESE == rFont.GetLanguage()) || (LANGUAGE_JAPANESE == rFont.GetCJKContextLanguage()))
1238cdf0e10cSrcweir 		{
1239cdf0e10cSrcweir 			// the underline is right for Japanese only
1240cdf0e10cSrcweir 			return true;
1241cdf0e10cSrcweir 		}
1242cdf0e10cSrcweir 
1243cdf0e10cSrcweir 		return false;
1244cdf0e10cSrcweir 	}
1245cdf0e10cSrcweir 
1246cdf0e10cSrcweir 	void createFontAttributeTransformAndAlignment(
1247cdf0e10cSrcweir 		drawinglayer::attribute::FontAttribute& rFontAttribute,
1248cdf0e10cSrcweir 		basegfx::B2DHomMatrix& rTextTransform,
1249cdf0e10cSrcweir 		basegfx::B2DVector& rAlignmentOffset,
1250cdf0e10cSrcweir 		PropertyHolder& rProperty)
1251cdf0e10cSrcweir 	{
1252cdf0e10cSrcweir 		const Font& rFont = rProperty.getFont();
1253cdf0e10cSrcweir 		basegfx::B2DVector aFontScaling;
1254cdf0e10cSrcweir 
1255cdf0e10cSrcweir 		rFontAttribute = drawinglayer::attribute::FontAttribute(
1256cdf0e10cSrcweir 			drawinglayer::primitive2d::getFontAttributeFromVclFont(
1257cdf0e10cSrcweir 				aFontScaling,
1258cdf0e10cSrcweir 				rFont,
1259cdf0e10cSrcweir 				0 != (rProperty.getLayoutMode() & TEXT_LAYOUT_BIDI_RTL),
1260cdf0e10cSrcweir 				0 != (rProperty.getLayoutMode() & TEXT_LAYOUT_BIDI_STRONG)));
1261cdf0e10cSrcweir 
1262cdf0e10cSrcweir 		// add FontScaling
1263cdf0e10cSrcweir 		rTextTransform.scale(aFontScaling.getX(), aFontScaling.getY());
1264cdf0e10cSrcweir 
1265cdf0e10cSrcweir         // take text align into account
1266cdf0e10cSrcweir         if(ALIGN_BASELINE != rFont.GetAlign())
1267cdf0e10cSrcweir         {
1268cdf0e10cSrcweir             drawinglayer::primitive2d::TextLayouterDevice aTextLayouterDevice;
1269cdf0e10cSrcweir             aTextLayouterDevice.setFont(rFont);
1270cdf0e10cSrcweir 
1271cdf0e10cSrcweir             if(ALIGN_TOP == rFont.GetAlign())
1272cdf0e10cSrcweir             {
1273cdf0e10cSrcweir                 rAlignmentOffset.setY(aTextLayouterDevice.getFontAscent());
1274cdf0e10cSrcweir             }
1275cdf0e10cSrcweir             else // ALIGN_BOTTOM
1276cdf0e10cSrcweir             {
1277cdf0e10cSrcweir                 rAlignmentOffset.setY(-aTextLayouterDevice.getFontDescent());
1278cdf0e10cSrcweir             }
1279cdf0e10cSrcweir 
1280cdf0e10cSrcweir             rTextTransform.translate(rAlignmentOffset.getX(), rAlignmentOffset.getY());
1281cdf0e10cSrcweir         }
1282cdf0e10cSrcweir 
1283cdf0e10cSrcweir 		// add FontRotation (if used)
1284cdf0e10cSrcweir 		if(rFont.GetOrientation())
1285cdf0e10cSrcweir 		{
1286cdf0e10cSrcweir 			rTextTransform.rotate(-rFont.GetOrientation() * F_PI1800);
1287cdf0e10cSrcweir 		}
1288cdf0e10cSrcweir 	}
1289cdf0e10cSrcweir 
1290cdf0e10cSrcweir 	/** helper which takes complete care for creating the needed text primitives. It
1291cdf0e10cSrcweir 		takes care of decorated stuff and all the geometry adaptions needed
1292cdf0e10cSrcweir 	 */
1293cdf0e10cSrcweir 	void proccessMetaTextAction(
1294cdf0e10cSrcweir 		const Point& rTextStartPosition,
1295cdf0e10cSrcweir 		const XubString& rText,
1296cdf0e10cSrcweir 		sal_uInt16 nTextStart,
1297cdf0e10cSrcweir 		sal_uInt16 nTextLength,
1298cdf0e10cSrcweir 		const ::std::vector< double >& rDXArray,
1299cdf0e10cSrcweir 		TargetHolder& rTarget,
1300cdf0e10cSrcweir 		PropertyHolder& rProperty)
1301cdf0e10cSrcweir 	{
1302cdf0e10cSrcweir 		drawinglayer::primitive2d::BasePrimitive2D* pResult = 0;
1303cdf0e10cSrcweir 		const Font& rFont = rProperty.getFont();
1304cdf0e10cSrcweir         basegfx::B2DVector aAlignmentOffset(0.0, 0.0);
1305cdf0e10cSrcweir 
1306cdf0e10cSrcweir 		if(nTextLength)
1307cdf0e10cSrcweir 		{
1308cdf0e10cSrcweir 			drawinglayer::attribute::FontAttribute aFontAttribute;
1309cdf0e10cSrcweir 			basegfx::B2DHomMatrix aTextTransform;
1310cdf0e10cSrcweir 
1311cdf0e10cSrcweir 			// fill parameters derived from current font
1312cdf0e10cSrcweir 			createFontAttributeTransformAndAlignment(
1313cdf0e10cSrcweir 				aFontAttribute,
1314cdf0e10cSrcweir 				aTextTransform,
1315cdf0e10cSrcweir 				aAlignmentOffset,
1316cdf0e10cSrcweir 				rProperty);
1317cdf0e10cSrcweir 
1318cdf0e10cSrcweir 			// add TextStartPosition
1319cdf0e10cSrcweir 			aTextTransform.translate(rTextStartPosition.X(), rTextStartPosition.Y());
1320cdf0e10cSrcweir 
1321cdf0e10cSrcweir 			// prepare FontColor and Locale
1322cdf0e10cSrcweir 			const basegfx::BColor aFontColor(rProperty.getTextColor());
1323cdf0e10cSrcweir 		    const com::sun::star::lang::Locale aLocale(MsLangId::convertLanguageToLocale(rProperty.getLanguageType()));
1324cdf0e10cSrcweir 			const bool bWordLineMode(rFont.IsWordLineMode());
1325cdf0e10cSrcweir 
1326cdf0e10cSrcweir 			const bool bDecoratedIsNeeded(
1327cdf0e10cSrcweir 				   UNDERLINE_NONE != rFont.GetOverline()
1328cdf0e10cSrcweir 				|| UNDERLINE_NONE != rFont.GetUnderline()
1329cdf0e10cSrcweir 				|| STRIKEOUT_NONE != rFont.GetStrikeout()
1330cdf0e10cSrcweir 				|| EMPHASISMARK_NONE != (rFont.GetEmphasisMark() & EMPHASISMARK_STYLE)
1331cdf0e10cSrcweir 				|| RELIEF_NONE != rFont.GetRelief()
1332cdf0e10cSrcweir 				|| rFont.IsShadow()
1333cdf0e10cSrcweir                 || bWordLineMode);
1334cdf0e10cSrcweir 
1335cdf0e10cSrcweir 			if(bDecoratedIsNeeded)
1336cdf0e10cSrcweir 			{
1337cdf0e10cSrcweir                 // prepare overline, underline and srikeout data
1338cdf0e10cSrcweir                 const drawinglayer::primitive2d::TextLine eFontOverline(drawinglayer::primitive2d::mapFontUnderlineToTextLine(rFont.GetOverline()));
1339cdf0e10cSrcweir                 const drawinglayer::primitive2d::TextLine eFontUnderline(drawinglayer::primitive2d::mapFontUnderlineToTextLine(rFont.GetUnderline()));
1340cdf0e10cSrcweir 				const drawinglayer::primitive2d::TextStrikeout eTextStrikeout(drawinglayer::primitive2d::mapFontStrikeoutToTextStrikeout(rFont.GetStrikeout()));
1341cdf0e10cSrcweir 
1342cdf0e10cSrcweir                 // check UndelineAbove
1343cdf0e10cSrcweir 				const bool bUnderlineAbove(drawinglayer::primitive2d::TEXT_LINE_NONE != eFontUnderline && isUnderlineAbove(rFont));
1344cdf0e10cSrcweir 
1345cdf0e10cSrcweir 				// prepare emphasis mark data
1346cdf0e10cSrcweir 				drawinglayer::primitive2d::TextEmphasisMark eTextEmphasisMark(drawinglayer::primitive2d::TEXT_EMPHASISMARK_NONE);
1347cdf0e10cSrcweir 
1348cdf0e10cSrcweir 				switch(rFont.GetEmphasisMark() & EMPHASISMARK_STYLE)
1349cdf0e10cSrcweir 				{
1350cdf0e10cSrcweir 					case EMPHASISMARK_DOT : eTextEmphasisMark = drawinglayer::primitive2d::TEXT_EMPHASISMARK_DOT; break;
1351cdf0e10cSrcweir 					case EMPHASISMARK_CIRCLE : eTextEmphasisMark = drawinglayer::primitive2d::TEXT_EMPHASISMARK_CIRCLE; break;
1352cdf0e10cSrcweir 					case EMPHASISMARK_DISC : eTextEmphasisMark = drawinglayer::primitive2d::TEXT_EMPHASISMARK_DISC; break;
1353cdf0e10cSrcweir 					case EMPHASISMARK_ACCENT : eTextEmphasisMark = drawinglayer::primitive2d::TEXT_EMPHASISMARK_ACCENT; break;
1354cdf0e10cSrcweir 				}
1355cdf0e10cSrcweir 
1356cdf0e10cSrcweir 				const bool bEmphasisMarkAbove(rFont.GetEmphasisMark() & EMPHASISMARK_POS_ABOVE);
1357cdf0e10cSrcweir 				const bool bEmphasisMarkBelow(rFont.GetEmphasisMark() & EMPHASISMARK_POS_BELOW);
1358cdf0e10cSrcweir 
1359cdf0e10cSrcweir 				// prepare font relief data
1360cdf0e10cSrcweir 				drawinglayer::primitive2d::TextRelief eTextRelief(drawinglayer::primitive2d::TEXT_RELIEF_NONE);
1361cdf0e10cSrcweir 
1362cdf0e10cSrcweir 				switch(rFont.GetRelief())
1363cdf0e10cSrcweir 				{
1364cdf0e10cSrcweir 					case RELIEF_EMBOSSED : eTextRelief = drawinglayer::primitive2d::TEXT_RELIEF_EMBOSSED; break;
1365cdf0e10cSrcweir 					case RELIEF_ENGRAVED : eTextRelief = drawinglayer::primitive2d::TEXT_RELIEF_ENGRAVED; break;
1366cdf0e10cSrcweir 					default : break; // RELIEF_NONE, FontRelief_FORCE_EQUAL_SIZE
1367cdf0e10cSrcweir 				}
1368cdf0e10cSrcweir 
1369cdf0e10cSrcweir 				// prepare shadow/outline data
1370cdf0e10cSrcweir 				const bool bShadow(rFont.IsShadow());
1371cdf0e10cSrcweir 
1372cdf0e10cSrcweir 				// TextDecoratedPortionPrimitive2D is needed, create one
1373cdf0e10cSrcweir                 pResult = new drawinglayer::primitive2d::TextDecoratedPortionPrimitive2D(
1374cdf0e10cSrcweir 
1375cdf0e10cSrcweir 					// attributes for TextSimplePortionPrimitive2D
1376cdf0e10cSrcweir 					aTextTransform,
1377cdf0e10cSrcweir 					rText,
1378cdf0e10cSrcweir 					nTextStart,
1379cdf0e10cSrcweir 					nTextLength,
1380cdf0e10cSrcweir 					rDXArray,
1381cdf0e10cSrcweir 					aFontAttribute,
1382cdf0e10cSrcweir 					aLocale,
1383cdf0e10cSrcweir 					aFontColor,
1384cdf0e10cSrcweir 
1385cdf0e10cSrcweir 					// attributes for TextDecoratedPortionPrimitive2D
1386cdf0e10cSrcweir 					rProperty.getOverlineColorActive() ? rProperty.getOverlineColor() : aFontColor,
1387cdf0e10cSrcweir 					rProperty.getTextLineColorActive() ? rProperty.getTextLineColor() : aFontColor,
1388cdf0e10cSrcweir                     eFontOverline,
1389cdf0e10cSrcweir                     eFontUnderline,
1390cdf0e10cSrcweir 					bUnderlineAbove,
1391cdf0e10cSrcweir 					eTextStrikeout,
1392cdf0e10cSrcweir 					bWordLineMode,
1393cdf0e10cSrcweir 					eTextEmphasisMark,
1394cdf0e10cSrcweir 					bEmphasisMarkAbove,
1395cdf0e10cSrcweir 					bEmphasisMarkBelow,
1396cdf0e10cSrcweir 					eTextRelief,
1397cdf0e10cSrcweir 					bShadow);
1398cdf0e10cSrcweir 			}
1399cdf0e10cSrcweir 			else
1400cdf0e10cSrcweir 			{
1401cdf0e10cSrcweir 				// TextSimplePortionPrimitive2D is enough
1402cdf0e10cSrcweir 				pResult = new drawinglayer::primitive2d::TextSimplePortionPrimitive2D(
1403cdf0e10cSrcweir 					aTextTransform,
1404cdf0e10cSrcweir 					rText,
1405cdf0e10cSrcweir 					nTextStart,
1406cdf0e10cSrcweir 					nTextLength,
1407cdf0e10cSrcweir 					rDXArray,
1408cdf0e10cSrcweir 					aFontAttribute,
1409cdf0e10cSrcweir 					aLocale,
1410cdf0e10cSrcweir 					aFontColor);
1411cdf0e10cSrcweir 			}
1412cdf0e10cSrcweir 		}
1413cdf0e10cSrcweir 
1414cdf0e10cSrcweir         if(pResult && rProperty.getTextFillColorActive())
1415cdf0e10cSrcweir         {
1416cdf0e10cSrcweir             // text background is requested, add and encapsulate both to new primitive
1417cdf0e10cSrcweir             drawinglayer::primitive2d::TextLayouterDevice aTextLayouterDevice;
1418cdf0e10cSrcweir             aTextLayouterDevice.setFont(rFont);
1419cdf0e10cSrcweir 
1420cdf0e10cSrcweir 			// get text width
1421cdf0e10cSrcweir 			double fTextWidth(0.0);
1422cdf0e10cSrcweir 
1423cdf0e10cSrcweir 			if(rDXArray.empty())
1424cdf0e10cSrcweir 			{
1425cdf0e10cSrcweir 				fTextWidth = aTextLayouterDevice.getTextWidth(rText, nTextStart, nTextLength);
1426cdf0e10cSrcweir 			}
1427cdf0e10cSrcweir 			else
1428cdf0e10cSrcweir 			{
1429cdf0e10cSrcweir 				fTextWidth = rDXArray.back();
1430cdf0e10cSrcweir 			}
1431cdf0e10cSrcweir 
1432cdf0e10cSrcweir             if(basegfx::fTools::more(fTextWidth, 0.0))
1433cdf0e10cSrcweir             {
1434cdf0e10cSrcweir                 // build text range
1435cdf0e10cSrcweir                 const basegfx::B2DRange aTextRange(
1436cdf0e10cSrcweir                     0.0, -aTextLayouterDevice.getFontAscent(),
1437cdf0e10cSrcweir                     fTextWidth, aTextLayouterDevice.getFontDescent());
1438cdf0e10cSrcweir 
1439cdf0e10cSrcweir                 // create Transform
1440cdf0e10cSrcweir 			    basegfx::B2DHomMatrix aTextTransform;
1441cdf0e10cSrcweir 
1442cdf0e10cSrcweir                 aTextTransform.translate(aAlignmentOffset.getX(), aAlignmentOffset.getY());
1443cdf0e10cSrcweir 
1444cdf0e10cSrcweir                 if(rFont.GetOrientation())
1445cdf0e10cSrcweir 			    {
1446cdf0e10cSrcweir 				    aTextTransform.rotate(-rFont.GetOrientation() * F_PI1800);
1447cdf0e10cSrcweir 			    }
1448cdf0e10cSrcweir 
1449cdf0e10cSrcweir                 aTextTransform.translate(rTextStartPosition.X(), rTextStartPosition.Y());
1450cdf0e10cSrcweir 
1451cdf0e10cSrcweir                 // prepare Primitive2DSequence, put text in foreground
1452cdf0e10cSrcweir                 drawinglayer::primitive2d::Primitive2DSequence aSequence(2);
1453cdf0e10cSrcweir                 aSequence[1] = drawinglayer::primitive2d::Primitive2DReference(pResult);
1454cdf0e10cSrcweir 
1455cdf0e10cSrcweir                 // prepare filled polygon
1456cdf0e10cSrcweir                 basegfx::B2DPolygon aOutline(basegfx::tools::createPolygonFromRect(aTextRange));
1457cdf0e10cSrcweir 		        aOutline.transform(aTextTransform);
1458cdf0e10cSrcweir 
1459cdf0e10cSrcweir                 aSequence[0] = drawinglayer::primitive2d::Primitive2DReference(
1460cdf0e10cSrcweir 				    new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
1461cdf0e10cSrcweir                         basegfx::B2DPolyPolygon(aOutline),
1462cdf0e10cSrcweir                         rProperty.getTextFillColor()));
1463cdf0e10cSrcweir 
1464cdf0e10cSrcweir                 // set as group at pResult
1465cdf0e10cSrcweir 			    pResult = new drawinglayer::primitive2d::GroupPrimitive2D(aSequence);
1466cdf0e10cSrcweir             }
1467cdf0e10cSrcweir         }
1468cdf0e10cSrcweir 
1469cdf0e10cSrcweir 		if(pResult)
1470cdf0e10cSrcweir 		{
1471cdf0e10cSrcweir 			// add created text primitive to target
1472cdf0e10cSrcweir 			if(rProperty.getTransformation().isIdentity())
1473cdf0e10cSrcweir 			{
1474cdf0e10cSrcweir 		        rTarget.append(pResult);
1475cdf0e10cSrcweir 			}
1476cdf0e10cSrcweir 			else
1477cdf0e10cSrcweir 			{
1478cdf0e10cSrcweir 				// when a transformation is set, embed to it
1479cdf0e10cSrcweir 	            const drawinglayer::primitive2d::Primitive2DReference aReference(pResult);
1480cdf0e10cSrcweir 
1481cdf0e10cSrcweir 				rTarget.append(
1482cdf0e10cSrcweir 					new drawinglayer::primitive2d::TransformPrimitive2D(
1483cdf0e10cSrcweir 						rProperty.getTransformation(),
1484cdf0e10cSrcweir 						drawinglayer::primitive2d::Primitive2DSequence(&aReference, 1)));
1485cdf0e10cSrcweir 			}
1486cdf0e10cSrcweir 		}
1487cdf0e10cSrcweir 	}
1488cdf0e10cSrcweir 
1489cdf0e10cSrcweir 	/** helper which takes complete care for creating the needed textLine primitives */
1490cdf0e10cSrcweir 	void proccessMetaTextLineAction(
1491cdf0e10cSrcweir 		const MetaTextLineAction& rAction,
1492cdf0e10cSrcweir 		TargetHolder& rTarget,
1493cdf0e10cSrcweir 		PropertyHolder& rProperty)
1494cdf0e10cSrcweir 	{
1495cdf0e10cSrcweir 		const double fLineWidth(fabs((double)rAction.GetWidth()));
1496cdf0e10cSrcweir 
1497cdf0e10cSrcweir 		if(fLineWidth > 0.0)
1498cdf0e10cSrcweir 		{
1499cdf0e10cSrcweir 		    const drawinglayer::primitive2d::TextLine aOverlineMode(drawinglayer::primitive2d::mapFontUnderlineToTextLine(rAction.GetOverline()));
1500cdf0e10cSrcweir 		    const drawinglayer::primitive2d::TextLine aUnderlineMode(drawinglayer::primitive2d::mapFontUnderlineToTextLine(rAction.GetUnderline()));
1501cdf0e10cSrcweir 			const drawinglayer::primitive2d::TextStrikeout aTextStrikeout(drawinglayer::primitive2d::mapFontStrikeoutToTextStrikeout(rAction.GetStrikeout()));
1502cdf0e10cSrcweir 
1503cdf0e10cSrcweir 			const bool bOverlineUsed(drawinglayer::primitive2d::TEXT_LINE_NONE != aOverlineMode);
1504cdf0e10cSrcweir 			const bool bUnderlineUsed(drawinglayer::primitive2d::TEXT_LINE_NONE != aUnderlineMode);
1505cdf0e10cSrcweir 			const bool bStrikeoutUsed(drawinglayer::primitive2d::TEXT_STRIKEOUT_NONE != aTextStrikeout);
1506cdf0e10cSrcweir 
1507cdf0e10cSrcweir 			if(bUnderlineUsed || bStrikeoutUsed || bOverlineUsed)
1508cdf0e10cSrcweir 			{
1509cdf0e10cSrcweir 				std::vector< drawinglayer::primitive2d::BasePrimitive2D* > aTargetVector;
1510cdf0e10cSrcweir 				basegfx::B2DVector aAlignmentOffset(0.0, 0.0);
1511cdf0e10cSrcweir 				drawinglayer::attribute::FontAttribute aFontAttribute;
1512cdf0e10cSrcweir 				basegfx::B2DHomMatrix aTextTransform;
1513cdf0e10cSrcweir 
1514cdf0e10cSrcweir 				// fill parameters derived from current font
1515cdf0e10cSrcweir 				createFontAttributeTransformAndAlignment(
1516cdf0e10cSrcweir 					aFontAttribute,
1517cdf0e10cSrcweir 					aTextTransform,
1518cdf0e10cSrcweir 					aAlignmentOffset,
1519cdf0e10cSrcweir 					rProperty);
1520cdf0e10cSrcweir 
1521cdf0e10cSrcweir 				// add TextStartPosition
1522cdf0e10cSrcweir 				aTextTransform.translate(rAction.GetStartPoint().X(), rAction.GetStartPoint().Y());
1523cdf0e10cSrcweir 
1524cdf0e10cSrcweir 				// prepare TextLayouter (used in most cases)
1525cdf0e10cSrcweir 				drawinglayer::primitive2d::TextLayouterDevice aTextLayouter;
1526cdf0e10cSrcweir 				aTextLayouter.setFont(rProperty.getFont());
1527cdf0e10cSrcweir 
1528cdf0e10cSrcweir 				if(bOverlineUsed)
1529cdf0e10cSrcweir 				{
1530cdf0e10cSrcweir 					// create primitive geometry for overline
1531cdf0e10cSrcweir 					aTargetVector.push_back(
1532cdf0e10cSrcweir 						new drawinglayer::primitive2d::TextLinePrimitive2D(
1533cdf0e10cSrcweir 							aTextTransform,
1534cdf0e10cSrcweir 							fLineWidth,
1535cdf0e10cSrcweir 							aTextLayouter.getOverlineOffset(),
1536cdf0e10cSrcweir 							aTextLayouter.getOverlineHeight(),
1537cdf0e10cSrcweir 							aOverlineMode,
1538cdf0e10cSrcweir 							rProperty.getOverlineColor()));
1539cdf0e10cSrcweir 				}
1540cdf0e10cSrcweir 
1541cdf0e10cSrcweir 				if(bUnderlineUsed)
1542cdf0e10cSrcweir 				{
1543cdf0e10cSrcweir 					// create primitive geometry for underline
1544cdf0e10cSrcweir 					aTargetVector.push_back(
1545cdf0e10cSrcweir 						new drawinglayer::primitive2d::TextLinePrimitive2D(
1546cdf0e10cSrcweir 							aTextTransform,
1547cdf0e10cSrcweir 							fLineWidth,
1548cdf0e10cSrcweir 							aTextLayouter.getUnderlineOffset(),
1549cdf0e10cSrcweir 							aTextLayouter.getUnderlineHeight(),
1550cdf0e10cSrcweir 							aUnderlineMode,
1551cdf0e10cSrcweir 							rProperty.getTextLineColor()));
1552cdf0e10cSrcweir 				}
1553cdf0e10cSrcweir 
1554cdf0e10cSrcweir 				if(bStrikeoutUsed)
1555cdf0e10cSrcweir 				{
1556cdf0e10cSrcweir 					// create primitive geometry for strikeout
1557cdf0e10cSrcweir 					if(drawinglayer::primitive2d::TEXT_STRIKEOUT_SLASH == aTextStrikeout
1558cdf0e10cSrcweir 						|| drawinglayer::primitive2d::TEXT_STRIKEOUT_X == aTextStrikeout)
1559cdf0e10cSrcweir 					{
1560cdf0e10cSrcweir 						// strikeout with character
1561cdf0e10cSrcweir 						const sal_Unicode aStrikeoutChar(
1562cdf0e10cSrcweir 							drawinglayer::primitive2d::TEXT_STRIKEOUT_SLASH == aTextStrikeout ? '/' : 'X');
1563cdf0e10cSrcweir 					    const com::sun::star::lang::Locale aLocale(MsLangId::convertLanguageToLocale(
1564cdf0e10cSrcweir 							rProperty.getLanguageType()));
1565cdf0e10cSrcweir 
1566cdf0e10cSrcweir 						aTargetVector.push_back(
1567cdf0e10cSrcweir 							new drawinglayer::primitive2d::TextCharacterStrikeoutPrimitive2D(
1568cdf0e10cSrcweir 								aTextTransform,
1569cdf0e10cSrcweir 								fLineWidth,
1570cdf0e10cSrcweir 								rProperty.getTextColor(),
1571cdf0e10cSrcweir 								aStrikeoutChar,
1572cdf0e10cSrcweir 								aFontAttribute,
1573cdf0e10cSrcweir 								aLocale));
1574cdf0e10cSrcweir 					}
1575cdf0e10cSrcweir 					else
1576cdf0e10cSrcweir 					{
1577cdf0e10cSrcweir 						// strikeout with geometry
1578cdf0e10cSrcweir 						aTargetVector.push_back(
1579cdf0e10cSrcweir 							new drawinglayer::primitive2d::TextGeometryStrikeoutPrimitive2D(
1580cdf0e10cSrcweir 								aTextTransform,
1581cdf0e10cSrcweir 								fLineWidth,
1582cdf0e10cSrcweir 								rProperty.getTextColor(),
1583cdf0e10cSrcweir 								aTextLayouter.getUnderlineHeight(),
1584cdf0e10cSrcweir 								aTextLayouter.getStrikeoutOffset(),
1585cdf0e10cSrcweir 								aTextStrikeout));
1586cdf0e10cSrcweir 					}
1587cdf0e10cSrcweir 				}
1588cdf0e10cSrcweir 
1589cdf0e10cSrcweir 				if(aTargetVector.size())
1590cdf0e10cSrcweir 				{
1591cdf0e10cSrcweir 					// add created text primitive to target
1592cdf0e10cSrcweir 					if(rProperty.getTransformation().isIdentity())
1593cdf0e10cSrcweir 					{
1594cdf0e10cSrcweir 						for(sal_uInt32 a(0); a < aTargetVector.size(); a++)
1595cdf0e10cSrcweir 						{
1596cdf0e10cSrcweir 							rTarget.append(aTargetVector[a]);
1597cdf0e10cSrcweir 						}
1598cdf0e10cSrcweir 					}
1599cdf0e10cSrcweir 					else
1600cdf0e10cSrcweir 					{
1601cdf0e10cSrcweir 						// when a transformation is set, embed to it
1602cdf0e10cSrcweir 						drawinglayer::primitive2d::Primitive2DSequence xTargets(aTargetVector.size());
1603cdf0e10cSrcweir 
1604cdf0e10cSrcweir 						for(sal_uInt32 a(0); a < aTargetVector.size(); a++)
1605cdf0e10cSrcweir 						{
1606cdf0e10cSrcweir 							xTargets[a] = drawinglayer::primitive2d::Primitive2DReference(aTargetVector[a]);
1607cdf0e10cSrcweir 						}
1608cdf0e10cSrcweir 
1609cdf0e10cSrcweir 						rTarget.append(
1610cdf0e10cSrcweir 							new drawinglayer::primitive2d::TransformPrimitive2D(
1611cdf0e10cSrcweir 								rProperty.getTransformation(),
1612cdf0e10cSrcweir 								xTargets));
1613cdf0e10cSrcweir 					}
1614cdf0e10cSrcweir 				}
1615cdf0e10cSrcweir 			}
1616cdf0e10cSrcweir 		}
1617cdf0e10cSrcweir 
1618cdf0e10cSrcweir 	}
1619cdf0e10cSrcweir 
1620cdf0e10cSrcweir 	/** This is the main interpreter method. It is designed to handle the given Metafile
1621cdf0e10cSrcweir 		completely inside the given context and target. It may use and modify the context and
1622cdf0e10cSrcweir 		target. This design allows to call itself recursively wich adapted contexts and
1623cdf0e10cSrcweir 		targets as e.g. needed for the META_FLOATTRANSPARENT_ACTION where the content is expressed
1624cdf0e10cSrcweir 		as a metafile as sub-content.
1625cdf0e10cSrcweir 
1626cdf0e10cSrcweir 		This interpreter is as free of VCL functionality as possible. It uses VCL data classes
1627cdf0e10cSrcweir 		(else reading the data would not be possible), but e.g. does NOT use a local OutputDevice
1628cdf0e10cSrcweir 		as most other MetaFile interpreters/exporters do to hold and work with the current context.
1629cdf0e10cSrcweir 		This is necessary to be able to get away from the strong internal VCL-binding.
1630cdf0e10cSrcweir 
1631cdf0e10cSrcweir 		It tries to combine e.g. pixel and/or point actions and to stitch together single line primitives
1632cdf0e10cSrcweir 		where possible (which is not trivial with the possible line geometry definitions).
1633cdf0e10cSrcweir 
1634cdf0e10cSrcweir 		It tries to handle clipping no longer as Regions and spans of Rectangles, but as PolyPolygon
1635cdf0e10cSrcweir 		ClipRegions with (where possible) high precision by using the best possible data quality
1636cdf0e10cSrcweir 		from the Region. The Region is unavoidable as data container, but nowadays allows the transport
1637cdf0e10cSrcweir 		of Polygon-based clip regions. Where this is not used, a Polygon is constructed from the
1638cdf0e10cSrcweir 		Region ranges. All primitive clipping uses the MaskPrimitive2D with Polygon-based clipping.
1639cdf0e10cSrcweir 
1640cdf0e10cSrcweir 		I have marked the single MetaActions with:
1641cdf0e10cSrcweir 
1642cdf0e10cSrcweir 		SIMPLE, DONE:
1643cdf0e10cSrcweir 		Simple, e.g nothing to do or value setting in the context
1644cdf0e10cSrcweir 
1645cdf0e10cSrcweir 		CHECKED, WORKS WELL:
1646cdf0e10cSrcweir 		Thoroughly tested with extra written test code which created a replacement
1647cdf0e10cSrcweir 		Metafile just to test this action in various combinations
1648cdf0e10cSrcweir 
1649cdf0e10cSrcweir 		NEEDS IMPLEMENTATION:
1650cdf0e10cSrcweir 		Not implemented and asserted, but also no usage found, neither in own Metafile
1651cdf0e10cSrcweir 		creations, nor in EMF/WMF imports (checked with a whole bunch of critical EMF/WMF
1652cdf0e10cSrcweir 		bugdocs)
1653cdf0e10cSrcweir 
1654cdf0e10cSrcweir 		For more commens, see the single action implementations.
1655cdf0e10cSrcweir 	*/
1656cdf0e10cSrcweir     void interpretMetafile(
1657cdf0e10cSrcweir         const GDIMetaFile& rMetaFile,
1658cdf0e10cSrcweir         TargetHolders& rTargetHolders,
1659cdf0e10cSrcweir         PropertyHolders& rPropertyHolders,
1660cdf0e10cSrcweir 		const drawinglayer::geometry::ViewInformation2D& rViewInformation)
1661cdf0e10cSrcweir     {
1662cdf0e10cSrcweir         const sal_uInt32 nCount(rMetaFile.GetActionCount());
1663cdf0e10cSrcweir 
1664cdf0e10cSrcweir         for(sal_uInt32 nAction(0); nAction < nCount; nAction++)
1665cdf0e10cSrcweir         {
1666cdf0e10cSrcweir             MetaAction* pAction = rMetaFile.GetAction(nAction);
1667cdf0e10cSrcweir 
1668cdf0e10cSrcweir             switch(pAction->GetType())
1669cdf0e10cSrcweir             {
1670cdf0e10cSrcweir                 case META_NULL_ACTION :
1671cdf0e10cSrcweir                 {
1672cdf0e10cSrcweir 					/** SIMPLE, DONE */
1673cdf0e10cSrcweir                     break;
1674cdf0e10cSrcweir                 }
1675cdf0e10cSrcweir                 case META_PIXEL_ACTION :
1676cdf0e10cSrcweir                 {
1677cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
1678cdf0e10cSrcweir     			    std::vector< basegfx::B2DPoint > aPositions;
1679cdf0e10cSrcweir                     Color aLastColor(COL_BLACK);
1680cdf0e10cSrcweir 
1681cdf0e10cSrcweir                     while(META_PIXEL_ACTION == pAction->GetType() && nAction < nCount)
1682cdf0e10cSrcweir                     {
1683cdf0e10cSrcweir                         const MetaPixelAction* pA = (const MetaPixelAction*)pAction;
1684cdf0e10cSrcweir 
1685cdf0e10cSrcweir                         if(pA->GetColor() != aLastColor)
1686cdf0e10cSrcweir                         {
1687cdf0e10cSrcweir                             if(aPositions.size())
1688cdf0e10cSrcweir                             {
1689cdf0e10cSrcweir                                 createPointArrayPrimitive(aPositions, rTargetHolders.Current(), rPropertyHolders.Current(), aLastColor.getBColor());
1690cdf0e10cSrcweir                                 aPositions.clear();
1691cdf0e10cSrcweir                             }
1692cdf0e10cSrcweir 
1693cdf0e10cSrcweir                             aLastColor = pA->GetColor();
1694cdf0e10cSrcweir                         }
1695cdf0e10cSrcweir 
1696cdf0e10cSrcweir                         const Point& rPoint = pA->GetPoint();
1697cdf0e10cSrcweir                         aPositions.push_back(basegfx::B2DPoint(rPoint.X(), rPoint.Y()));
1698cdf0e10cSrcweir 						nAction++; if(nAction < nCount) pAction = rMetaFile.GetAction(nAction);
1699cdf0e10cSrcweir                     }
1700cdf0e10cSrcweir 
1701cdf0e10cSrcweir                     nAction--;
1702cdf0e10cSrcweir 
1703cdf0e10cSrcweir                     if(aPositions.size())
1704cdf0e10cSrcweir                     {
1705cdf0e10cSrcweir                         createPointArrayPrimitive(aPositions, rTargetHolders.Current(), rPropertyHolders.Current(), aLastColor.getBColor());
1706cdf0e10cSrcweir                     }
1707cdf0e10cSrcweir 
1708cdf0e10cSrcweir                     break;
1709cdf0e10cSrcweir                 }
1710cdf0e10cSrcweir                 case META_POINT_ACTION :
1711cdf0e10cSrcweir                 {
1712cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
1713cdf0e10cSrcweir                     if(rPropertyHolders.Current().getLineColorActive())
1714cdf0e10cSrcweir                     {
1715cdf0e10cSrcweir         			    std::vector< basegfx::B2DPoint > aPositions;
1716cdf0e10cSrcweir 
1717cdf0e10cSrcweir                         while(META_POINT_ACTION == pAction->GetType() && nAction < nCount)
1718cdf0e10cSrcweir                         {
1719cdf0e10cSrcweir                             const MetaPointAction* pA = (const MetaPointAction*)pAction;
1720cdf0e10cSrcweir                             const Point& rPoint = pA->GetPoint();
1721cdf0e10cSrcweir                             aPositions.push_back(basegfx::B2DPoint(rPoint.X(), rPoint.Y()));
1722cdf0e10cSrcweir 							nAction++; if(nAction < nCount) pAction = rMetaFile.GetAction(nAction);
1723cdf0e10cSrcweir                         }
1724cdf0e10cSrcweir 
1725cdf0e10cSrcweir                         nAction--;
1726cdf0e10cSrcweir 
1727cdf0e10cSrcweir                         if(aPositions.size())
1728cdf0e10cSrcweir                         {
1729cdf0e10cSrcweir                             createPointArrayPrimitive(aPositions, rTargetHolders.Current(), rPropertyHolders.Current(), rPropertyHolders.Current().getLineColor());
1730cdf0e10cSrcweir                         }
1731cdf0e10cSrcweir                     }
1732cdf0e10cSrcweir 
1733cdf0e10cSrcweir                     break;
1734cdf0e10cSrcweir                 }
1735cdf0e10cSrcweir                 case META_LINE_ACTION :
1736cdf0e10cSrcweir                 {
1737cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
1738cdf0e10cSrcweir                     if(rPropertyHolders.Current().getLineColorActive())
1739cdf0e10cSrcweir                     {
1740cdf0e10cSrcweir                         basegfx::B2DPolygon aLinePolygon;
1741cdf0e10cSrcweir                         LineInfo aLineInfo;
1742cdf0e10cSrcweir 
1743cdf0e10cSrcweir                         while(META_LINE_ACTION == pAction->GetType() && nAction < nCount)
1744cdf0e10cSrcweir                         {
1745cdf0e10cSrcweir                             const MetaLineAction* pA = (const MetaLineAction*)pAction;
1746cdf0e10cSrcweir                             const Point& rStartPoint = pA->GetStartPoint();
1747cdf0e10cSrcweir                             const Point& rEndPoint = pA->GetEndPoint();
1748cdf0e10cSrcweir                             const basegfx::B2DPoint aStart(rStartPoint.X(), rStartPoint.Y());
1749cdf0e10cSrcweir                             const basegfx::B2DPoint aEnd(rEndPoint.X(), rEndPoint.Y());
1750cdf0e10cSrcweir 
1751cdf0e10cSrcweir                             if(aLinePolygon.count())
1752cdf0e10cSrcweir                             {
1753cdf0e10cSrcweir                                 if(pA->GetLineInfo() == aLineInfo
1754cdf0e10cSrcweir                                     && aStart == aLinePolygon.getB2DPoint(aLinePolygon.count() - 1))
1755cdf0e10cSrcweir                                 {
1756cdf0e10cSrcweir                                     aLinePolygon.append(aEnd);
1757cdf0e10cSrcweir                                 }
1758cdf0e10cSrcweir                                 else
1759cdf0e10cSrcweir                                 {
1760cdf0e10cSrcweir 									aLineInfo.SetLineJoin(basegfx::B2DLINEJOIN_NONE); // It were lines; force to NONE
1761cdf0e10cSrcweir                                     createLinePrimitive(aLinePolygon, aLineInfo, rTargetHolders.Current(), rPropertyHolders.Current());
1762cdf0e10cSrcweir                                     aLinePolygon.clear();
1763cdf0e10cSrcweir 	                                aLineInfo = pA->GetLineInfo();
1764cdf0e10cSrcweir 									aLinePolygon.append(aStart);
1765cdf0e10cSrcweir 									aLinePolygon.append(aEnd);
1766cdf0e10cSrcweir                                 }
1767cdf0e10cSrcweir                             }
1768cdf0e10cSrcweir                             else
1769cdf0e10cSrcweir                             {
1770cdf0e10cSrcweir                                 aLineInfo = pA->GetLineInfo();
1771cdf0e10cSrcweir                                 aLinePolygon.append(aStart);
1772cdf0e10cSrcweir                                 aLinePolygon.append(aEnd);
1773cdf0e10cSrcweir                             }
1774cdf0e10cSrcweir 
1775cdf0e10cSrcweir 							nAction++; if(nAction < nCount) pAction = rMetaFile.GetAction(nAction);
1776cdf0e10cSrcweir                         }
1777cdf0e10cSrcweir 
1778cdf0e10cSrcweir                         nAction--;
1779cdf0e10cSrcweir 
1780cdf0e10cSrcweir                         if(aLinePolygon.count())
1781cdf0e10cSrcweir                         {
1782cdf0e10cSrcweir 							aLineInfo.SetLineJoin(basegfx::B2DLINEJOIN_NONE); // It were lines; force to NONE
1783cdf0e10cSrcweir                             createLinePrimitive(aLinePolygon, aLineInfo, rTargetHolders.Current(), rPropertyHolders.Current());
1784cdf0e10cSrcweir                         }
1785cdf0e10cSrcweir                     }
1786cdf0e10cSrcweir 
1787cdf0e10cSrcweir                     break;
1788cdf0e10cSrcweir                 }
1789cdf0e10cSrcweir                 case META_RECT_ACTION :
1790cdf0e10cSrcweir                 {
1791cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
1792cdf0e10cSrcweir 					if(rPropertyHolders.Current().getLineOrFillActive())
1793cdf0e10cSrcweir 					{
1794cdf0e10cSrcweir                         const MetaRectAction* pA = (const MetaRectAction*)pAction;
1795cdf0e10cSrcweir 						const Rectangle& rRectangle = pA->GetRect();
1796cdf0e10cSrcweir 
1797cdf0e10cSrcweir 						if(!rRectangle.IsEmpty())
1798cdf0e10cSrcweir 						{
1799cdf0e10cSrcweir 							const basegfx::B2DRange aRange(rRectangle.Left(), rRectangle.Top(), rRectangle.Right(), rRectangle.Bottom());
1800cdf0e10cSrcweir 
1801cdf0e10cSrcweir 							if(!aRange.isEmpty())
1802cdf0e10cSrcweir 							{
1803cdf0e10cSrcweir 								const basegfx::B2DPolygon aOutline(basegfx::tools::createPolygonFromRect(aRange));
1804cdf0e10cSrcweir 								createHairlineAndFillPrimitive(aOutline, rTargetHolders.Current(), rPropertyHolders.Current());
1805cdf0e10cSrcweir 							}
1806cdf0e10cSrcweir 						}
1807cdf0e10cSrcweir 					}
1808cdf0e10cSrcweir 
1809cdf0e10cSrcweir                     break;
1810cdf0e10cSrcweir                 }
1811cdf0e10cSrcweir                 case META_ROUNDRECT_ACTION :
1812cdf0e10cSrcweir                 {
1813cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
1814cdf0e10cSrcweir 					/**	The original OutputDevice::DrawRect paints nothing when nHor or nVer is zero; but just
1815cdf0e10cSrcweir 						because the tools::Polygon operator creating the rounding does produce nonsense. I assume
1816cdf0e10cSrcweir 						this an error and create an unrounded rectangle in that case (implicit in
1817cdf0e10cSrcweir 						createPolygonFromRect)
1818cdf0e10cSrcweir 					 */
1819cdf0e10cSrcweir 					if(rPropertyHolders.Current().getLineOrFillActive())
1820cdf0e10cSrcweir 					{
1821cdf0e10cSrcweir                         const MetaRoundRectAction* pA = (const MetaRoundRectAction*)pAction;
1822cdf0e10cSrcweir 						const Rectangle& rRectangle = pA->GetRect();
1823cdf0e10cSrcweir 
1824cdf0e10cSrcweir 						if(!rRectangle.IsEmpty())
1825cdf0e10cSrcweir 						{
1826cdf0e10cSrcweir 							const basegfx::B2DRange aRange(rRectangle.Left(), rRectangle.Top(), rRectangle.Right(), rRectangle.Bottom());
1827cdf0e10cSrcweir 
1828cdf0e10cSrcweir 							if(!aRange.isEmpty())
1829cdf0e10cSrcweir 							{
1830cdf0e10cSrcweir 								const sal_uInt32 nHor(pA->GetHorzRound());
1831cdf0e10cSrcweir 								const sal_uInt32 nVer(pA->GetVertRound());
1832cdf0e10cSrcweir 								basegfx::B2DPolygon aOutline;
1833cdf0e10cSrcweir 
1834cdf0e10cSrcweir 								if(nHor || nVer)
1835cdf0e10cSrcweir 								{
1836cdf0e10cSrcweir 									double fRadiusX((nHor * 2.0) / (aRange.getWidth() > 0.0 ? aRange.getWidth() : 1.0));
1837cdf0e10cSrcweir 									double fRadiusY((nVer * 2.0) / (aRange.getHeight() > 0.0 ? aRange.getHeight() : 1.0));
1838cdf0e10cSrcweir 									fRadiusX = std::max(0.0, std::min(1.0, fRadiusX));
1839cdf0e10cSrcweir 									fRadiusY = std::max(0.0, std::min(1.0, fRadiusY));
1840cdf0e10cSrcweir 
1841cdf0e10cSrcweir 									aOutline = basegfx::tools::createPolygonFromRect(aRange, fRadiusX, fRadiusY);
1842cdf0e10cSrcweir 								}
1843cdf0e10cSrcweir 								else
1844cdf0e10cSrcweir 								{
1845cdf0e10cSrcweir 									aOutline = basegfx::tools::createPolygonFromRect(aRange);
1846cdf0e10cSrcweir 								}
1847cdf0e10cSrcweir 
1848cdf0e10cSrcweir 								createHairlineAndFillPrimitive(aOutline, rTargetHolders.Current(), rPropertyHolders.Current());
1849cdf0e10cSrcweir 							}
1850cdf0e10cSrcweir 						}
1851cdf0e10cSrcweir 					}
1852cdf0e10cSrcweir 
1853cdf0e10cSrcweir                     break;
1854cdf0e10cSrcweir                 }
1855cdf0e10cSrcweir                 case META_ELLIPSE_ACTION :
1856cdf0e10cSrcweir                 {
1857cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
1858cdf0e10cSrcweir 					if(rPropertyHolders.Current().getLineOrFillActive())
1859cdf0e10cSrcweir 					{
1860cdf0e10cSrcweir                         const MetaEllipseAction* pA = (const MetaEllipseAction*)pAction;
1861cdf0e10cSrcweir 						const Rectangle& rRectangle = pA->GetRect();
1862cdf0e10cSrcweir 
1863cdf0e10cSrcweir 						if(!rRectangle.IsEmpty())
1864cdf0e10cSrcweir 						{
1865cdf0e10cSrcweir 							const basegfx::B2DRange aRange(rRectangle.Left(), rRectangle.Top(), rRectangle.Right(), rRectangle.Bottom());
1866cdf0e10cSrcweir 
1867cdf0e10cSrcweir 							if(!aRange.isEmpty())
1868cdf0e10cSrcweir 							{
1869cdf0e10cSrcweir 								const basegfx::B2DPolygon aOutline(basegfx::tools::createPolygonFromEllipse(
1870cdf0e10cSrcweir 									aRange.getCenter(), aRange.getWidth() * 0.5, aRange.getHeight() * 0.5));
1871cdf0e10cSrcweir 
1872cdf0e10cSrcweir 								createHairlineAndFillPrimitive(aOutline, rTargetHolders.Current(), rPropertyHolders.Current());
1873cdf0e10cSrcweir 							}
1874cdf0e10cSrcweir 						}
1875cdf0e10cSrcweir 					}
1876cdf0e10cSrcweir 
1877cdf0e10cSrcweir                     break;
1878cdf0e10cSrcweir                 }
1879cdf0e10cSrcweir                 case META_ARC_ACTION :
1880cdf0e10cSrcweir                 {
1881cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
1882cdf0e10cSrcweir 					if(rPropertyHolders.Current().getLineColorActive())
1883cdf0e10cSrcweir 					{
1884cdf0e10cSrcweir                         const MetaArcAction* pA = (const MetaArcAction*)pAction;
1885cdf0e10cSrcweir                         const Polygon aToolsPoly(pA->GetRect(), pA->GetStartPoint(), pA->GetEndPoint(), POLY_ARC);
1886cdf0e10cSrcweir 						const basegfx::B2DPolygon aOutline(aToolsPoly.getB2DPolygon());
1887cdf0e10cSrcweir 
1888cdf0e10cSrcweir 						createHairlinePrimitive(aOutline, rTargetHolders.Current(), rPropertyHolders.Current());
1889cdf0e10cSrcweir 					}
1890cdf0e10cSrcweir 
1891cdf0e10cSrcweir                     break;
1892cdf0e10cSrcweir                 }
1893cdf0e10cSrcweir                 case META_PIE_ACTION :
1894cdf0e10cSrcweir                 {
1895cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
1896cdf0e10cSrcweir 					if(rPropertyHolders.Current().getLineOrFillActive())
1897cdf0e10cSrcweir 					{
1898cdf0e10cSrcweir                         const MetaPieAction* pA = (const MetaPieAction*)pAction;
1899cdf0e10cSrcweir                         const Polygon aToolsPoly(pA->GetRect(), pA->GetStartPoint(), pA->GetEndPoint(), POLY_PIE);
1900cdf0e10cSrcweir 						const basegfx::B2DPolygon aOutline(aToolsPoly.getB2DPolygon());
1901cdf0e10cSrcweir 
1902cdf0e10cSrcweir 						createHairlineAndFillPrimitive(aOutline, rTargetHolders.Current(), rPropertyHolders.Current());
1903cdf0e10cSrcweir 					}
1904cdf0e10cSrcweir 
1905cdf0e10cSrcweir                     break;
1906cdf0e10cSrcweir                 }
1907cdf0e10cSrcweir                 case META_CHORD_ACTION :
1908cdf0e10cSrcweir                 {
1909cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
1910cdf0e10cSrcweir 					if(rPropertyHolders.Current().getLineOrFillActive())
1911cdf0e10cSrcweir 					{
1912cdf0e10cSrcweir                         const MetaChordAction* pA = (const MetaChordAction*)pAction;
1913cdf0e10cSrcweir                         const Polygon aToolsPoly(pA->GetRect(), pA->GetStartPoint(), pA->GetEndPoint(), POLY_CHORD);
1914cdf0e10cSrcweir 						const basegfx::B2DPolygon aOutline(aToolsPoly.getB2DPolygon());
1915cdf0e10cSrcweir 
1916cdf0e10cSrcweir 						createHairlineAndFillPrimitive(aOutline, rTargetHolders.Current(), rPropertyHolders.Current());
1917cdf0e10cSrcweir 					}
1918cdf0e10cSrcweir 
1919cdf0e10cSrcweir                     break;
1920cdf0e10cSrcweir                 }
1921cdf0e10cSrcweir                 case META_POLYLINE_ACTION :
1922cdf0e10cSrcweir                 {
1923cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
1924cdf0e10cSrcweir                     if(rPropertyHolders.Current().getLineColorActive())
1925cdf0e10cSrcweir                     {
1926cdf0e10cSrcweir                         const MetaPolyLineAction* pA = (const MetaPolyLineAction*)pAction;
1927cdf0e10cSrcweir                         createLinePrimitive(pA->GetPolygon().getB2DPolygon(), pA->GetLineInfo(), rTargetHolders.Current(), rPropertyHolders.Current());
1928cdf0e10cSrcweir                     }
1929cdf0e10cSrcweir 
1930cdf0e10cSrcweir                     break;
1931cdf0e10cSrcweir                 }
1932cdf0e10cSrcweir                 case META_POLYGON_ACTION :
1933cdf0e10cSrcweir                 {
1934cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
1935cdf0e10cSrcweir 					if(rPropertyHolders.Current().getLineOrFillActive())
1936cdf0e10cSrcweir 					{
1937cdf0e10cSrcweir                         const MetaPolygonAction* pA = (const MetaPolygonAction*)pAction;
1938cdf0e10cSrcweir 						basegfx::B2DPolygon aOutline(pA->GetPolygon().getB2DPolygon());
1939cdf0e10cSrcweir 
1940cdf0e10cSrcweir 						// the metafile play interprets the polygons from MetaPolygonAction
1941cdf0e10cSrcweir 						// always as closed and always paints an edge from last to first point,
1942cdf0e10cSrcweir 						// so force to closed here to emulate that
1943cdf0e10cSrcweir 						if(aOutline.count() > 1 && !aOutline.isClosed())
1944cdf0e10cSrcweir 						{
1945cdf0e10cSrcweir 							aOutline.setClosed(true);
1946cdf0e10cSrcweir 						}
1947cdf0e10cSrcweir 
1948cdf0e10cSrcweir 						createHairlineAndFillPrimitive(aOutline, rTargetHolders.Current(), rPropertyHolders.Current());
1949cdf0e10cSrcweir 					}
1950cdf0e10cSrcweir 
1951cdf0e10cSrcweir                     break;
1952cdf0e10cSrcweir                 }
1953cdf0e10cSrcweir                 case META_POLYPOLYGON_ACTION :
1954cdf0e10cSrcweir                 {
1955cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
1956cdf0e10cSrcweir 					if(rPropertyHolders.Current().getLineOrFillActive())
1957cdf0e10cSrcweir 					{
1958cdf0e10cSrcweir                         const MetaPolyPolygonAction* pA = (const MetaPolyPolygonAction*)pAction;
1959cdf0e10cSrcweir 						basegfx::B2DPolyPolygon aPolyPolygonOutline(pA->GetPolyPolygon().getB2DPolyPolygon());
1960cdf0e10cSrcweir 
1961cdf0e10cSrcweir 						// the metafile play interprets the single polygons from MetaPolyPolygonAction
1962cdf0e10cSrcweir 						// always as closed and always paints an edge from last to first point,
1963cdf0e10cSrcweir 						// so force to closed here to emulate that
1964cdf0e10cSrcweir 						for(sal_uInt32 b(0); b < aPolyPolygonOutline.count(); b++)
1965cdf0e10cSrcweir 						{
1966cdf0e10cSrcweir 							basegfx::B2DPolygon aPolygonOutline(aPolyPolygonOutline.getB2DPolygon(b));
1967cdf0e10cSrcweir 
1968cdf0e10cSrcweir 							if(aPolygonOutline.count() > 1 && !aPolygonOutline.isClosed())
1969cdf0e10cSrcweir 							{
1970cdf0e10cSrcweir 								aPolygonOutline.setClosed(true);
1971cdf0e10cSrcweir 								aPolyPolygonOutline.setB2DPolygon(b, aPolygonOutline);
1972cdf0e10cSrcweir 							}
1973cdf0e10cSrcweir 						}
1974cdf0e10cSrcweir 
1975cdf0e10cSrcweir 						createHairlineAndFillPrimitive(aPolyPolygonOutline, rTargetHolders.Current(), rPropertyHolders.Current());
1976cdf0e10cSrcweir 					}
1977cdf0e10cSrcweir 
1978cdf0e10cSrcweir                     break;
1979cdf0e10cSrcweir                 }
1980cdf0e10cSrcweir                 case META_TEXT_ACTION :
1981cdf0e10cSrcweir                 {
1982cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
1983cdf0e10cSrcweir                     const MetaTextAction* pA = (const MetaTextAction*)pAction;
1984cdf0e10cSrcweir 					sal_uInt32 nTextLength(pA->GetLen());
1985cdf0e10cSrcweir 					const sal_uInt32 nTextIndex(pA->GetIndex());
1986cdf0e10cSrcweir 					const sal_uInt32 nStringLength(pA->GetText().Len());
1987cdf0e10cSrcweir 
1988cdf0e10cSrcweir 					if(nTextLength + nTextIndex > nStringLength)
1989cdf0e10cSrcweir 					{
1990cdf0e10cSrcweir 						nTextLength = nStringLength - nTextIndex;
1991cdf0e10cSrcweir 					}
1992cdf0e10cSrcweir 
1993cdf0e10cSrcweir 					if(nTextLength && rPropertyHolders.Current().getTextColorActive())
1994cdf0e10cSrcweir 					{
1995cdf0e10cSrcweir 						const std::vector< double > aDXArray;
1996cdf0e10cSrcweir 						proccessMetaTextAction(
1997cdf0e10cSrcweir 							pA->GetPoint(),
1998cdf0e10cSrcweir 							pA->GetText(),
1999cdf0e10cSrcweir 							nTextIndex,
2000cdf0e10cSrcweir 							nTextLength,
2001cdf0e10cSrcweir 							aDXArray,
2002cdf0e10cSrcweir 							rTargetHolders.Current(),
2003cdf0e10cSrcweir 							rPropertyHolders.Current());
2004cdf0e10cSrcweir 					}
2005cdf0e10cSrcweir 
2006cdf0e10cSrcweir                     break;
2007cdf0e10cSrcweir                 }
2008cdf0e10cSrcweir                 case META_TEXTARRAY_ACTION :
2009cdf0e10cSrcweir                 {
2010cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2011cdf0e10cSrcweir                     const MetaTextArrayAction* pA = (const MetaTextArrayAction*)pAction;
2012cdf0e10cSrcweir 					sal_uInt32 nTextLength(pA->GetLen());
2013cdf0e10cSrcweir 					const sal_uInt32 nTextIndex(pA->GetIndex());
2014cdf0e10cSrcweir 					const sal_uInt32 nStringLength(pA->GetText().Len());
2015cdf0e10cSrcweir 
2016cdf0e10cSrcweir 					if(nTextLength + nTextIndex > nStringLength)
2017cdf0e10cSrcweir 					{
2018cdf0e10cSrcweir 						nTextLength = nTextIndex > nStringLength ? 0 : nStringLength - nTextIndex;
2019cdf0e10cSrcweir 					}
2020cdf0e10cSrcweir 
2021cdf0e10cSrcweir 					if(nTextLength && rPropertyHolders.Current().getTextColorActive())
2022cdf0e10cSrcweir 					{
2023cdf0e10cSrcweir 						// preapare DXArray (if used)
2024cdf0e10cSrcweir 						std::vector< double > aDXArray;
2025cdf0e10cSrcweir 						sal_Int32* pDXArray = pA->GetDXArray();
2026cdf0e10cSrcweir 
2027cdf0e10cSrcweir 						if(pDXArray)
2028cdf0e10cSrcweir 						{
2029cdf0e10cSrcweir 							aDXArray.reserve(nTextLength);
2030cdf0e10cSrcweir 
2031cdf0e10cSrcweir 							for(sal_uInt32 a(0); a < nTextLength; a++)
2032cdf0e10cSrcweir 							{
2033cdf0e10cSrcweir 								aDXArray.push_back((double)(*(pDXArray + a)));
2034cdf0e10cSrcweir 							}
2035cdf0e10cSrcweir 						}
2036cdf0e10cSrcweir 
2037cdf0e10cSrcweir 						proccessMetaTextAction(
2038cdf0e10cSrcweir 							pA->GetPoint(),
2039cdf0e10cSrcweir 							pA->GetText(),
2040cdf0e10cSrcweir 							nTextIndex,
2041cdf0e10cSrcweir 							nTextLength,
2042cdf0e10cSrcweir 							aDXArray,
2043cdf0e10cSrcweir 							rTargetHolders.Current(),
2044cdf0e10cSrcweir 							rPropertyHolders.Current());
2045cdf0e10cSrcweir 					}
2046cdf0e10cSrcweir 
2047cdf0e10cSrcweir 					break;
2048cdf0e10cSrcweir                 }
2049cdf0e10cSrcweir                 case META_STRETCHTEXT_ACTION :
2050cdf0e10cSrcweir                 {
2051cdf0e10cSrcweir                     // #i108440# StarMath uses MetaStretchTextAction, thus support is needed.
2052cdf0e10cSrcweir                     // It looks as if it pretty never really uses a width different from
2053cdf0e10cSrcweir                     // the default text-layout width, but it's not possible to be sure.
2054cdf0e10cSrcweir                     // Implemented getting the DXArray and checking for scale at all. If
2055cdf0e10cSrcweir                     // scale is more than 3.5% different, scale the DXArray before usage.
2056cdf0e10cSrcweir                     // New status:
2057cdf0e10cSrcweir 
2058cdf0e10cSrcweir                     /** CHECKED, WORKS WELL */
2059cdf0e10cSrcweir                     const MetaStretchTextAction* pA = (const MetaStretchTextAction*)pAction;
2060cdf0e10cSrcweir 					sal_uInt32 nTextLength(pA->GetLen());
2061cdf0e10cSrcweir 					const sal_uInt32 nTextIndex(pA->GetIndex());
2062cdf0e10cSrcweir 					const sal_uInt32 nStringLength(pA->GetText().Len());
2063cdf0e10cSrcweir 
2064cdf0e10cSrcweir 					if(nTextLength + nTextIndex > nStringLength)
2065cdf0e10cSrcweir 					{
2066cdf0e10cSrcweir 						nTextLength = nStringLength - nTextIndex;
2067cdf0e10cSrcweir 					}
2068cdf0e10cSrcweir 
2069cdf0e10cSrcweir 					if(nTextLength && rPropertyHolders.Current().getTextColorActive())
2070cdf0e10cSrcweir 					{
2071cdf0e10cSrcweir 						drawinglayer::primitive2d::TextLayouterDevice aTextLayouterDevice;
2072cdf0e10cSrcweir 						aTextLayouterDevice.setFont(rPropertyHolders.Current().getFont());
2073cdf0e10cSrcweir 
2074cdf0e10cSrcweir 						::std::vector< double > aTextArray(
2075cdf0e10cSrcweir 							aTextLayouterDevice.getTextArray(
2076cdf0e10cSrcweir 								pA->GetText(),
2077cdf0e10cSrcweir 								nTextIndex,
2078cdf0e10cSrcweir 								nTextLength));
2079cdf0e10cSrcweir 
2080cdf0e10cSrcweir                         if(!aTextArray.empty())
2081cdf0e10cSrcweir                         {
2082cdf0e10cSrcweir     						const double fTextLength(aTextArray.back());
2083cdf0e10cSrcweir 
2084cdf0e10cSrcweir                             if(0.0 != fTextLength && pA->GetWidth())
2085cdf0e10cSrcweir                             {
2086cdf0e10cSrcweir                                 const double fRelative(pA->GetWidth() / fTextLength);
2087cdf0e10cSrcweir 
2088cdf0e10cSrcweir                                 if(fabs(fRelative - 1.0) >= 0.035)
2089cdf0e10cSrcweir                                 {
2090cdf0e10cSrcweir                                     // when derivation is more than 3,5% from default text size,
2091cdf0e10cSrcweir                                     // scale the DXArray
2092cdf0e10cSrcweir                                     for(sal_uInt32 a(0); a < aTextArray.size(); a++)
2093cdf0e10cSrcweir                                     {
2094cdf0e10cSrcweir                                         aTextArray[a] *= fRelative;
2095cdf0e10cSrcweir                                     }
2096cdf0e10cSrcweir                                 }
2097cdf0e10cSrcweir                             }
2098cdf0e10cSrcweir                         }
2099cdf0e10cSrcweir 
2100cdf0e10cSrcweir 						proccessMetaTextAction(
2101cdf0e10cSrcweir 							pA->GetPoint(),
2102cdf0e10cSrcweir 							pA->GetText(),
2103cdf0e10cSrcweir 							nTextIndex,
2104cdf0e10cSrcweir 							nTextLength,
2105cdf0e10cSrcweir 							aTextArray,
2106cdf0e10cSrcweir 							rTargetHolders.Current(),
2107cdf0e10cSrcweir 							rPropertyHolders.Current());
2108cdf0e10cSrcweir 					}
2109cdf0e10cSrcweir 
2110cdf0e10cSrcweir 					break;
2111cdf0e10cSrcweir                 }
2112cdf0e10cSrcweir                 case META_TEXTRECT_ACTION :
2113cdf0e10cSrcweir                 {
2114cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2115cdf0e10cSrcweir                     // OSL_ENSURE(false, "META_TEXTRECT_ACTION requested (!)");
2116cdf0e10cSrcweir                     const MetaTextRectAction* pA = (const MetaTextRectAction*)pAction;
2117cdf0e10cSrcweir 					const Rectangle& rRectangle = pA->GetRect();
2118cdf0e10cSrcweir 					const sal_uInt32 nStringLength(pA->GetText().Len());
2119cdf0e10cSrcweir 
2120cdf0e10cSrcweir 					if(!rRectangle.IsEmpty() && 0 != nStringLength)
2121cdf0e10cSrcweir 					{
2122cdf0e10cSrcweir 						// The problem with this action is that it describes unlayouted text
2123cdf0e10cSrcweir 						// and the layout capabilities are in EditEngine/Outliner in SVX. The
2124cdf0e10cSrcweir 						// same problem is true for VCL which internally has implementations
2125cdf0e10cSrcweir 						// to layout text in this case. There exists even a call
2126cdf0e10cSrcweir 						// OutputDevice::AddTextRectActions(...) to create the needed actions
2127cdf0e10cSrcweir 						// as 'sub-content' of a Metafile. Unfortunately i do not have an
2128cdf0e10cSrcweir 						// OutputDevice here since this interpreter tries to work without
2129cdf0e10cSrcweir 						// VCL AFAP.
2130cdf0e10cSrcweir 						// Since AddTextRectActions is the only way as long as we do not have
2131cdf0e10cSrcweir 						// a simple text layouter available, i will try to add it to the
2132cdf0e10cSrcweir 						// TextLayouterDevice isloation.
2133cdf0e10cSrcweir 						drawinglayer::primitive2d::TextLayouterDevice aTextLayouterDevice;
2134cdf0e10cSrcweir 						aTextLayouterDevice.setFont(rPropertyHolders.Current().getFont());
2135cdf0e10cSrcweir 						GDIMetaFile aGDIMetaFile;
2136cdf0e10cSrcweir 
2137cdf0e10cSrcweir 						aTextLayouterDevice.addTextRectActions(
2138cdf0e10cSrcweir 							rRectangle, pA->GetText(), pA->GetStyle(), aGDIMetaFile);
2139cdf0e10cSrcweir 
2140cdf0e10cSrcweir 						if(aGDIMetaFile.GetActionCount())
2141cdf0e10cSrcweir 						{
2142cdf0e10cSrcweir 							// cerate sub-content
2143cdf0e10cSrcweir 							drawinglayer::primitive2d::Primitive2DSequence xSubContent;
2144cdf0e10cSrcweir 							{
2145cdf0e10cSrcweir                                 rTargetHolders.Push();
2146cdf0e10cSrcweir 								// #i# for sub-Mteafile contents, do start with new, default render state
2147cdf0e10cSrcweir 								rPropertyHolders.PushDefault();
2148cdf0e10cSrcweir 								interpretMetafile(aGDIMetaFile, rTargetHolders, rPropertyHolders, rViewInformation);
2149cdf0e10cSrcweir 								xSubContent = rTargetHolders.Current().getPrimitive2DSequence(rPropertyHolders.Current());
2150cdf0e10cSrcweir 								rPropertyHolders.Pop();
2151cdf0e10cSrcweir                                 rTargetHolders.Pop();
2152cdf0e10cSrcweir 							}
2153cdf0e10cSrcweir 
2154cdf0e10cSrcweir 							if(xSubContent.hasElements())
2155cdf0e10cSrcweir 							{
2156cdf0e10cSrcweir 								// add with transformation
2157cdf0e10cSrcweir 								rTargetHolders.Current().append(
2158cdf0e10cSrcweir 									new drawinglayer::primitive2d::TransformPrimitive2D(
2159cdf0e10cSrcweir 										rPropertyHolders.Current().getTransformation(),
2160cdf0e10cSrcweir 										xSubContent));
2161cdf0e10cSrcweir 							}
2162cdf0e10cSrcweir 						}
2163cdf0e10cSrcweir 					}
2164cdf0e10cSrcweir 
2165cdf0e10cSrcweir 					break;
2166cdf0e10cSrcweir                 }
2167cdf0e10cSrcweir                 case META_BMP_ACTION :
2168cdf0e10cSrcweir                 {
2169cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2170cdf0e10cSrcweir                     const MetaBmpAction* pA = (const MetaBmpAction*)pAction;
2171cdf0e10cSrcweir 					const BitmapEx aBitmapEx(pA->GetBitmap());
2172cdf0e10cSrcweir 
2173cdf0e10cSrcweir 					createBitmapExPrimitive(aBitmapEx, pA->GetPoint(), rTargetHolders.Current(), rPropertyHolders.Current());
2174cdf0e10cSrcweir 
2175cdf0e10cSrcweir                     break;
2176cdf0e10cSrcweir                 }
2177cdf0e10cSrcweir                 case META_BMPSCALE_ACTION :
2178cdf0e10cSrcweir                 {
2179cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2180cdf0e10cSrcweir                     const MetaBmpScaleAction* pA = (const MetaBmpScaleAction*)pAction;
2181cdf0e10cSrcweir 					const Bitmap aBitmapEx(pA->GetBitmap());
2182cdf0e10cSrcweir 
2183cdf0e10cSrcweir 					createBitmapExPrimitive(aBitmapEx, pA->GetPoint(), pA->GetSize(), rTargetHolders.Current(), rPropertyHolders.Current());
2184cdf0e10cSrcweir 
2185cdf0e10cSrcweir                     break;
2186cdf0e10cSrcweir                 }
2187cdf0e10cSrcweir                 case META_BMPSCALEPART_ACTION :
2188cdf0e10cSrcweir                 {
2189cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2190cdf0e10cSrcweir                     const MetaBmpScalePartAction* pA = (const MetaBmpScalePartAction*)pAction;
2191cdf0e10cSrcweir 					const Bitmap& rBitmap = pA->GetBitmap();
2192cdf0e10cSrcweir 
2193cdf0e10cSrcweir 					if(!rBitmap.IsEmpty())
2194cdf0e10cSrcweir 					{
2195cdf0e10cSrcweir 						Bitmap aCroppedBitmap(rBitmap);
2196cdf0e10cSrcweir 						const Rectangle aCropRectangle(pA->GetSrcPoint(), pA->GetSrcSize());
2197cdf0e10cSrcweir 
2198cdf0e10cSrcweir 						if(!aCropRectangle.IsEmpty())
2199cdf0e10cSrcweir 						{
2200cdf0e10cSrcweir 							aCroppedBitmap.Crop(aCropRectangle);
2201cdf0e10cSrcweir 						}
2202cdf0e10cSrcweir 
2203cdf0e10cSrcweir 						const BitmapEx aCroppedBitmapEx(aCroppedBitmap);
2204cdf0e10cSrcweir 						createBitmapExPrimitive(aCroppedBitmapEx, pA->GetDestPoint(), pA->GetDestSize(), rTargetHolders.Current(), rPropertyHolders.Current());
2205cdf0e10cSrcweir 					}
2206cdf0e10cSrcweir 
2207cdf0e10cSrcweir                     break;
2208cdf0e10cSrcweir                 }
2209cdf0e10cSrcweir                 case META_BMPEX_ACTION :
2210cdf0e10cSrcweir                 {
2211cdf0e10cSrcweir 					/** CHECKED, WORKS WELL: Simply same as META_BMP_ACTION */
2212cdf0e10cSrcweir                     const MetaBmpExAction* pA = (const MetaBmpExAction*)pAction;
2213cdf0e10cSrcweir 					const BitmapEx& rBitmapEx = pA->GetBitmapEx();
2214cdf0e10cSrcweir 
2215cdf0e10cSrcweir 					createBitmapExPrimitive(rBitmapEx, pA->GetPoint(), rTargetHolders.Current(), rPropertyHolders.Current());
2216cdf0e10cSrcweir 
2217cdf0e10cSrcweir                     break;
2218cdf0e10cSrcweir                 }
2219cdf0e10cSrcweir                 case META_BMPEXSCALE_ACTION :
2220cdf0e10cSrcweir                 {
2221cdf0e10cSrcweir 					/** CHECKED, WORKS WELL: Simply same as META_BMPSCALE_ACTION */
2222cdf0e10cSrcweir                     const MetaBmpExScaleAction* pA = (const MetaBmpExScaleAction*)pAction;
2223cdf0e10cSrcweir 					const BitmapEx& rBitmapEx = pA->GetBitmapEx();
2224cdf0e10cSrcweir 
2225cdf0e10cSrcweir 					createBitmapExPrimitive(rBitmapEx, pA->GetPoint(), pA->GetSize(), rTargetHolders.Current(), rPropertyHolders.Current());
2226cdf0e10cSrcweir 
2227cdf0e10cSrcweir                     break;
2228cdf0e10cSrcweir                 }
2229cdf0e10cSrcweir                 case META_BMPEXSCALEPART_ACTION :
2230cdf0e10cSrcweir                 {
2231cdf0e10cSrcweir 					/** CHECKED, WORKS WELL: Simply same as META_BMPSCALEPART_ACTION */
2232cdf0e10cSrcweir                     const MetaBmpExScalePartAction* pA = (const MetaBmpExScalePartAction*)pAction;
2233cdf0e10cSrcweir 					const BitmapEx& rBitmapEx = pA->GetBitmapEx();
2234cdf0e10cSrcweir 
2235cdf0e10cSrcweir 					if(!rBitmapEx.IsEmpty())
2236cdf0e10cSrcweir 					{
2237cdf0e10cSrcweir 						BitmapEx aCroppedBitmapEx(rBitmapEx);
2238cdf0e10cSrcweir 						const Rectangle aCropRectangle(pA->GetSrcPoint(), pA->GetSrcSize());
2239cdf0e10cSrcweir 
2240cdf0e10cSrcweir 						if(!aCropRectangle.IsEmpty())
2241cdf0e10cSrcweir 						{
2242cdf0e10cSrcweir 							aCroppedBitmapEx.Crop(aCropRectangle);
2243cdf0e10cSrcweir 						}
2244cdf0e10cSrcweir 
2245cdf0e10cSrcweir 						createBitmapExPrimitive(aCroppedBitmapEx, pA->GetDestPoint(), pA->GetDestSize(), rTargetHolders.Current(), rPropertyHolders.Current());
2246cdf0e10cSrcweir 					}
2247cdf0e10cSrcweir 
2248cdf0e10cSrcweir                     break;
2249cdf0e10cSrcweir                 }
2250cdf0e10cSrcweir                 case META_MASK_ACTION :
2251cdf0e10cSrcweir                 {
2252cdf0e10cSrcweir 					/** CHECKED, WORKS WELL: Simply same as META_BMP_ACTION */
2253cdf0e10cSrcweir                     const MetaMaskAction* pA = (const MetaMaskAction*)pAction;
2254cdf0e10cSrcweir 					const BitmapEx aBitmapEx(createMaskBmpEx(pA->GetBitmap(), pA->GetColor()));
2255cdf0e10cSrcweir 
2256cdf0e10cSrcweir 					createBitmapExPrimitive(aBitmapEx, pA->GetPoint(), rTargetHolders.Current(), rPropertyHolders.Current());
2257cdf0e10cSrcweir 
2258cdf0e10cSrcweir                     break;
2259cdf0e10cSrcweir                 }
2260cdf0e10cSrcweir                 case META_MASKSCALE_ACTION :
2261cdf0e10cSrcweir                 {
2262cdf0e10cSrcweir 					/** CHECKED, WORKS WELL: Simply same as META_BMPSCALE_ACTION */
2263cdf0e10cSrcweir                     const MetaMaskScaleAction* pA = (const MetaMaskScaleAction*)pAction;
2264cdf0e10cSrcweir 					const BitmapEx aBitmapEx(createMaskBmpEx(pA->GetBitmap(), pA->GetColor()));
2265cdf0e10cSrcweir 
2266cdf0e10cSrcweir 					createBitmapExPrimitive(aBitmapEx, pA->GetPoint(), pA->GetSize(), rTargetHolders.Current(), rPropertyHolders.Current());
2267cdf0e10cSrcweir 
2268cdf0e10cSrcweir                     break;
2269cdf0e10cSrcweir                 }
2270cdf0e10cSrcweir                 case META_MASKSCALEPART_ACTION :
2271cdf0e10cSrcweir                 {
2272cdf0e10cSrcweir 					/** CHECKED, WORKS WELL: Simply same as META_BMPSCALEPART_ACTION */
2273cdf0e10cSrcweir                     const MetaMaskScalePartAction* pA = (const MetaMaskScalePartAction*)pAction;
2274cdf0e10cSrcweir 					const Bitmap& rBitmap = pA->GetBitmap();
2275cdf0e10cSrcweir 
2276cdf0e10cSrcweir 					if(!rBitmap.IsEmpty())
2277cdf0e10cSrcweir 					{
2278cdf0e10cSrcweir 						Bitmap aCroppedBitmap(rBitmap);
2279cdf0e10cSrcweir 						const Rectangle aCropRectangle(pA->GetSrcPoint(), pA->GetSrcSize());
2280cdf0e10cSrcweir 
2281cdf0e10cSrcweir 						if(!aCropRectangle.IsEmpty())
2282cdf0e10cSrcweir 						{
2283cdf0e10cSrcweir 							aCroppedBitmap.Crop(aCropRectangle);
2284cdf0e10cSrcweir 						}
2285cdf0e10cSrcweir 
2286cdf0e10cSrcweir 						const BitmapEx aCroppedBitmapEx(createMaskBmpEx(aCroppedBitmap, pA->GetColor()));
2287cdf0e10cSrcweir 						createBitmapExPrimitive(aCroppedBitmapEx, pA->GetDestPoint(), pA->GetDestSize(), rTargetHolders.Current(), rPropertyHolders.Current());
2288cdf0e10cSrcweir 					}
2289cdf0e10cSrcweir 
2290cdf0e10cSrcweir                     break;
2291cdf0e10cSrcweir                 }
2292cdf0e10cSrcweir                 case META_GRADIENT_ACTION :
2293cdf0e10cSrcweir                 {
2294cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2295cdf0e10cSrcweir                     const MetaGradientAction* pA = (const MetaGradientAction*)pAction;
2296cdf0e10cSrcweir 					const Rectangle& rRectangle = pA->GetRect();
2297cdf0e10cSrcweir 
2298cdf0e10cSrcweir 					if(!rRectangle.IsEmpty())
2299cdf0e10cSrcweir 					{
2300cdf0e10cSrcweir 						basegfx::B2DRange aRange(rRectangle.Left(), rRectangle.Top(), rRectangle.Right(), rRectangle.Bottom());
2301cdf0e10cSrcweir 
2302cdf0e10cSrcweir 						if(!aRange.isEmpty())
2303cdf0e10cSrcweir 						{
2304cdf0e10cSrcweir 							const Gradient& rGradient = pA->GetGradient();
2305cdf0e10cSrcweir 							const drawinglayer::attribute::FillGradientAttribute aAttribute(createFillGradientAttribute(rGradient));
2306cdf0e10cSrcweir 							basegfx::B2DPolyPolygon aOutline(basegfx::tools::createPolygonFromRect(aRange));
2307cdf0e10cSrcweir 
2308cdf0e10cSrcweir 							if(aAttribute.getStartColor() == aAttribute.getEndColor())
2309cdf0e10cSrcweir 							{
2310cdf0e10cSrcweir 								// not really a gradient. Create filled rectangle
2311cdf0e10cSrcweir 								createFillPrimitive(
2312cdf0e10cSrcweir                                     aOutline,
2313cdf0e10cSrcweir                                     rTargetHolders.Current(),
2314cdf0e10cSrcweir                                     rPropertyHolders.Current());
2315cdf0e10cSrcweir 							}
2316cdf0e10cSrcweir 							else
2317cdf0e10cSrcweir 							{
2318cdf0e10cSrcweir 								// really a gradient
2319cdf0e10cSrcweir 								aRange.transform(rPropertyHolders.Current().getTransformation());
2320cdf0e10cSrcweir                                 drawinglayer::primitive2d::Primitive2DSequence xGradient(1);
2321cdf0e10cSrcweir 
2322cdf0e10cSrcweir                                 if(rPropertyHolders.Current().isRasterOpInvert())
2323cdf0e10cSrcweir                                 {
2324cdf0e10cSrcweir                                     // use a special version of FillGradientPrimitive2D which creates
2325cdf0e10cSrcweir                                     // non-overlapping geometry on decomposition to makethe old XOR
2326cdf0e10cSrcweir                                     // paint 'trick' work.
2327cdf0e10cSrcweir                                     xGradient[0] = drawinglayer::primitive2d::Primitive2DReference(
2328cdf0e10cSrcweir 									    new drawinglayer::primitive2d::NonOverlappingFillGradientPrimitive2D(
2329cdf0e10cSrcweir 										    aRange,
2330cdf0e10cSrcweir 										    aAttribute));
2331cdf0e10cSrcweir                                 }
2332cdf0e10cSrcweir                                 else
2333cdf0e10cSrcweir                                 {
2334cdf0e10cSrcweir                                     xGradient[0] = drawinglayer::primitive2d::Primitive2DReference(
2335cdf0e10cSrcweir 									    new drawinglayer::primitive2d::FillGradientPrimitive2D(
2336cdf0e10cSrcweir 										    aRange,
2337cdf0e10cSrcweir 										    aAttribute));
2338cdf0e10cSrcweir                                 }
2339cdf0e10cSrcweir 
2340cdf0e10cSrcweir                                 // #i112300# clip against polygon representing the rectangle from
2341cdf0e10cSrcweir                                 // the action. This is implicitely done using a temp Clipping in VCL
2342cdf0e10cSrcweir                                 // when a MetaGradientAction is executed
2343cdf0e10cSrcweir                     			aOutline.transform(rPropertyHolders.Current().getTransformation());
2344cdf0e10cSrcweir                                 rTargetHolders.Current().append(
2345cdf0e10cSrcweir 								    new drawinglayer::primitive2d::MaskPrimitive2D(
2346cdf0e10cSrcweir 									    aOutline,
2347cdf0e10cSrcweir 									    xGradient));
2348cdf0e10cSrcweir 							}
2349cdf0e10cSrcweir 						}
2350cdf0e10cSrcweir 					}
2351cdf0e10cSrcweir 
2352cdf0e10cSrcweir                     break;
2353cdf0e10cSrcweir                 }
2354cdf0e10cSrcweir                 case META_HATCH_ACTION :
2355cdf0e10cSrcweir                 {
2356cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2357cdf0e10cSrcweir                     const MetaHatchAction* pA = (const MetaHatchAction*)pAction;
2358cdf0e10cSrcweir 					basegfx::B2DPolyPolygon aOutline(pA->GetPolyPolygon().getB2DPolyPolygon());
2359cdf0e10cSrcweir 
2360cdf0e10cSrcweir 					if(aOutline.count())
2361cdf0e10cSrcweir 					{
2362cdf0e10cSrcweir                     	const Hatch& rHatch = pA->GetHatch();
2363cdf0e10cSrcweir 						const drawinglayer::attribute::FillHatchAttribute aAttribute(createFillHatchAttribute(rHatch));
2364cdf0e10cSrcweir 
2365cdf0e10cSrcweir                         aOutline.transform(rPropertyHolders.Current().getTransformation());
2366cdf0e10cSrcweir 
2367cdf0e10cSrcweir                         const basegfx::B2DRange aObjectRange(aOutline.getB2DRange());
2368cdf0e10cSrcweir 						const drawinglayer::primitive2d::Primitive2DReference aFillHatch(
2369cdf0e10cSrcweir 							new drawinglayer::primitive2d::FillHatchPrimitive2D(
2370cdf0e10cSrcweir 								aObjectRange,
2371cdf0e10cSrcweir                                 basegfx::BColor(),
2372cdf0e10cSrcweir 								aAttribute));
2373cdf0e10cSrcweir 
2374cdf0e10cSrcweir                         rTargetHolders.Current().append(
2375cdf0e10cSrcweir 							new drawinglayer::primitive2d::MaskPrimitive2D(
2376cdf0e10cSrcweir 								aOutline,
2377cdf0e10cSrcweir 								drawinglayer::primitive2d::Primitive2DSequence(&aFillHatch, 1)));
2378cdf0e10cSrcweir                     }
2379cdf0e10cSrcweir 
2380cdf0e10cSrcweir                     break;
2381cdf0e10cSrcweir                 }
2382cdf0e10cSrcweir                 case META_WALLPAPER_ACTION :
2383cdf0e10cSrcweir                 {
2384cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2385cdf0e10cSrcweir                     const MetaWallpaperAction* pA = (const MetaWallpaperAction*)pAction;
2386cdf0e10cSrcweir                 	Rectangle aWallpaperRectangle(pA->GetRect());
2387cdf0e10cSrcweir 
2388cdf0e10cSrcweir                     if(!aWallpaperRectangle.IsEmpty())
2389cdf0e10cSrcweir                     {
2390cdf0e10cSrcweir                     	const Wallpaper& rWallpaper = pA->GetWallpaper();
2391cdf0e10cSrcweir                        	const WallpaperStyle eWallpaperStyle(rWallpaper.GetStyle());
2392cdf0e10cSrcweir 		                basegfx::B2DRange aWallpaperRange(
2393cdf0e10cSrcweir                             aWallpaperRectangle.Left(), aWallpaperRectangle.Top(),
2394cdf0e10cSrcweir                             aWallpaperRectangle.Right(), aWallpaperRectangle.Bottom());
2395cdf0e10cSrcweir 
2396cdf0e10cSrcweir                         if(WALLPAPER_NULL != eWallpaperStyle)
2397cdf0e10cSrcweir                         {
2398cdf0e10cSrcweir 	                        if(rWallpaper.IsBitmap())
2399cdf0e10cSrcweir                             {
2400cdf0e10cSrcweir                                 // create bitmap background. Caution: This
2401cdf0e10cSrcweir                                 // also will create gradient/color background(s)
2402cdf0e10cSrcweir                                 // when the bitmap is transparent or not tiled
2403cdf0e10cSrcweir 				                CreateAndAppendBitmapWallpaper(
2404cdf0e10cSrcweir 					                aWallpaperRange,
2405cdf0e10cSrcweir                                     rWallpaper,
2406cdf0e10cSrcweir 									rTargetHolders.Current(),
2407cdf0e10cSrcweir                                     rPropertyHolders.Current());
2408cdf0e10cSrcweir                             }
2409cdf0e10cSrcweir 	                        else if(rWallpaper.IsGradient())
2410cdf0e10cSrcweir                             {
2411cdf0e10cSrcweir                                 // create gradient background
2412cdf0e10cSrcweir                                 rTargetHolders.Current().append(
2413cdf0e10cSrcweir 							        CreateGradientWallpaper(
2414cdf0e10cSrcweir 								        aWallpaperRange,
2415cdf0e10cSrcweir                                         rWallpaper.GetGradient(),
2416cdf0e10cSrcweir                                         rPropertyHolders.Current()));
2417cdf0e10cSrcweir                             }
2418cdf0e10cSrcweir 	                        else if(!rWallpaper.GetColor().GetTransparency())
2419cdf0e10cSrcweir                             {
2420cdf0e10cSrcweir                                 // create color background
2421cdf0e10cSrcweir                                 rTargetHolders.Current().append(
2422cdf0e10cSrcweir 							        CreateColorWallpaper(
2423cdf0e10cSrcweir 								        aWallpaperRange,
2424cdf0e10cSrcweir                                         rWallpaper.GetColor().getBColor(),
2425cdf0e10cSrcweir                                         rPropertyHolders.Current()));
2426cdf0e10cSrcweir                             }
2427cdf0e10cSrcweir                         }
2428cdf0e10cSrcweir                     }
2429cdf0e10cSrcweir 
2430cdf0e10cSrcweir                     break;
2431cdf0e10cSrcweir                 }
2432cdf0e10cSrcweir                 case META_CLIPREGION_ACTION :
2433cdf0e10cSrcweir                 {
2434cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2435cdf0e10cSrcweir                     const MetaClipRegionAction* pA = (const MetaClipRegionAction*)pAction;
2436cdf0e10cSrcweir 
2437cdf0e10cSrcweir                     if(pA->IsClipping())
2438cdf0e10cSrcweir                     {
2439cdf0e10cSrcweir                         // new clipping. Get PolyPolygon and transform with current transformation
2440cdf0e10cSrcweir                         basegfx::B2DPolyPolygon aNewClipPolyPolygon(getB2DPolyPolygonFromRegion(pA->GetRegion()));
2441cdf0e10cSrcweir 
2442cdf0e10cSrcweir                         aNewClipPolyPolygon.transform(rPropertyHolders.Current().getTransformation());
2443cdf0e10cSrcweir                         HandleNewClipRegion(aNewClipPolyPolygon, rTargetHolders, rPropertyHolders);
2444cdf0e10cSrcweir                     }
2445cdf0e10cSrcweir                     else
2446cdf0e10cSrcweir                     {
2447cdf0e10cSrcweir                         // end clipping
2448cdf0e10cSrcweir                         const basegfx::B2DPolyPolygon aEmptyPolyPolygon;
2449cdf0e10cSrcweir 
2450cdf0e10cSrcweir                         HandleNewClipRegion(aEmptyPolyPolygon, rTargetHolders, rPropertyHolders);
2451cdf0e10cSrcweir                     }
2452cdf0e10cSrcweir 
2453cdf0e10cSrcweir                     break;
2454cdf0e10cSrcweir                 }
2455cdf0e10cSrcweir                 case META_ISECTRECTCLIPREGION_ACTION :
2456cdf0e10cSrcweir                 {
2457cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2458cdf0e10cSrcweir                     const MetaISectRectClipRegionAction* pA = (const MetaISectRectClipRegionAction*)pAction;
2459cdf0e10cSrcweir 					const Rectangle& rRectangle = pA->GetRect();
2460cdf0e10cSrcweir 
2461cdf0e10cSrcweir 					if(rRectangle.IsEmpty())
2462cdf0e10cSrcweir                     {
2463cdf0e10cSrcweir                         // intersect with empty rectangle will always give empty
2464cdf0e10cSrcweir                         // ClipPolyPolygon; start new clipping with empty PolyPolygon
2465cdf0e10cSrcweir                         const basegfx::B2DPolyPolygon aEmptyPolyPolygon;
2466cdf0e10cSrcweir 
2467cdf0e10cSrcweir                         HandleNewClipRegion(aEmptyPolyPolygon, rTargetHolders, rPropertyHolders);
2468cdf0e10cSrcweir                     }
2469cdf0e10cSrcweir                     else
2470cdf0e10cSrcweir 					{
2471cdf0e10cSrcweir                         // create transformed ClipRange
2472cdf0e10cSrcweir                         basegfx::B2DRange aClipRange(
2473cdf0e10cSrcweir                             rRectangle.Left(), rRectangle.Top(),
2474cdf0e10cSrcweir                             rRectangle.Right(), rRectangle.Bottom());
2475cdf0e10cSrcweir 
2476cdf0e10cSrcweir                         aClipRange.transform(rPropertyHolders.Current().getTransformation());
2477cdf0e10cSrcweir 
2478cdf0e10cSrcweir                         if(rPropertyHolders.Current().getClipPolyPolygonActive())
2479cdf0e10cSrcweir                         {
2480cdf0e10cSrcweir                             if(0 == rPropertyHolders.Current().getClipPolyPolygon().count())
2481cdf0e10cSrcweir                             {
2482cdf0e10cSrcweir                                 // nothing to do, empty active clipPolyPolygon will stay
2483cdf0e10cSrcweir                                 // empty when intersecting
2484cdf0e10cSrcweir                             }
2485cdf0e10cSrcweir                             else
2486cdf0e10cSrcweir                             {
2487cdf0e10cSrcweir                                 // AND existing region and new ClipRange
2488cdf0e10cSrcweir                                 const basegfx::B2DPolyPolygon aOriginalPolyPolygon(
2489cdf0e10cSrcweir                                     rPropertyHolders.Current().getClipPolyPolygon());
2490cdf0e10cSrcweir                                 basegfx::B2DPolyPolygon aClippedPolyPolygon;
2491cdf0e10cSrcweir 
2492cdf0e10cSrcweir                                 if(aOriginalPolyPolygon.count())
2493cdf0e10cSrcweir                                 {
2494cdf0e10cSrcweir                                     aClippedPolyPolygon = basegfx::tools::clipPolyPolygonOnRange(
2495cdf0e10cSrcweir                                         aOriginalPolyPolygon,
2496cdf0e10cSrcweir                                         aClipRange,
2497cdf0e10cSrcweir                                         true,
2498cdf0e10cSrcweir                                         false);
2499cdf0e10cSrcweir                                 }
2500cdf0e10cSrcweir 
2501cdf0e10cSrcweir                                 if(aClippedPolyPolygon != aOriginalPolyPolygon)
2502cdf0e10cSrcweir                                 {
2503cdf0e10cSrcweir                                     // start new clipping with intersected region
2504cdf0e10cSrcweir                                     HandleNewClipRegion(
2505cdf0e10cSrcweir                                         aClippedPolyPolygon,
2506cdf0e10cSrcweir                                         rTargetHolders,
2507cdf0e10cSrcweir                                         rPropertyHolders);
2508cdf0e10cSrcweir                                 }
2509cdf0e10cSrcweir                             }
2510cdf0e10cSrcweir                         }
2511cdf0e10cSrcweir                         else
2512cdf0e10cSrcweir                         {
2513cdf0e10cSrcweir                             // start new clipping with ClipRange
2514cdf0e10cSrcweir                             const basegfx::B2DPolyPolygon aNewClipPolyPolygon(
2515cdf0e10cSrcweir                                 basegfx::tools::createPolygonFromRect(aClipRange));
2516cdf0e10cSrcweir 
2517cdf0e10cSrcweir                             HandleNewClipRegion(aNewClipPolyPolygon, rTargetHolders, rPropertyHolders);
2518cdf0e10cSrcweir                         }
2519cdf0e10cSrcweir                     }
2520cdf0e10cSrcweir 
2521cdf0e10cSrcweir                     break;
2522cdf0e10cSrcweir                 }
2523cdf0e10cSrcweir                 case META_ISECTREGIONCLIPREGION_ACTION :
2524cdf0e10cSrcweir                 {
2525cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2526cdf0e10cSrcweir                     const MetaISectRegionClipRegionAction* pA = (const MetaISectRegionClipRegionAction*)pAction;
2527cdf0e10cSrcweir                 	const Region& rNewRegion = pA->GetRegion();
2528cdf0e10cSrcweir 
2529cdf0e10cSrcweir 					if(rNewRegion.IsEmpty())
2530cdf0e10cSrcweir                     {
2531cdf0e10cSrcweir                         // intersect with empty region will always give empty
2532cdf0e10cSrcweir                         // region; start new clipping with empty PolyPolygon
2533cdf0e10cSrcweir                         const basegfx::B2DPolyPolygon aEmptyPolyPolygon;
2534cdf0e10cSrcweir 
2535cdf0e10cSrcweir                         HandleNewClipRegion(aEmptyPolyPolygon, rTargetHolders, rPropertyHolders);
2536cdf0e10cSrcweir                     }
2537cdf0e10cSrcweir                     else
2538cdf0e10cSrcweir 					{
2539cdf0e10cSrcweir                         // get new ClipPolyPolygon, transform it with current transformation
2540cdf0e10cSrcweir                         basegfx::B2DPolyPolygon aNewClipPolyPolygon(getB2DPolyPolygonFromRegion(rNewRegion));
2541cdf0e10cSrcweir                         aNewClipPolyPolygon.transform(rPropertyHolders.Current().getTransformation());
2542cdf0e10cSrcweir 
2543cdf0e10cSrcweir                         if(rPropertyHolders.Current().getClipPolyPolygonActive())
2544cdf0e10cSrcweir                         {
2545cdf0e10cSrcweir                             if(0 == rPropertyHolders.Current().getClipPolyPolygon().count())
2546cdf0e10cSrcweir                             {
2547cdf0e10cSrcweir                                 // nothing to do, empty active clipPolyPolygon will stay empty
2548cdf0e10cSrcweir                                 // when intersecting with any region
2549cdf0e10cSrcweir                             }
2550cdf0e10cSrcweir                             else
2551cdf0e10cSrcweir                             {
2552cdf0e10cSrcweir                                 // AND existing and new region
2553cdf0e10cSrcweir                                 const basegfx::B2DPolyPolygon aOriginalPolyPolygon(
2554cdf0e10cSrcweir                                     rPropertyHolders.Current().getClipPolyPolygon());
2555cdf0e10cSrcweir                                 basegfx::B2DPolyPolygon aClippedPolyPolygon;
2556cdf0e10cSrcweir 
2557cdf0e10cSrcweir                                 if(aOriginalPolyPolygon.count())
2558cdf0e10cSrcweir                                 {
2559cdf0e10cSrcweir                                     aClippedPolyPolygon = basegfx::tools::clipPolyPolygonOnPolyPolygon(
2560cdf0e10cSrcweir                                         aOriginalPolyPolygon, aNewClipPolyPolygon, true, false);
2561cdf0e10cSrcweir                                 }
2562cdf0e10cSrcweir 
2563cdf0e10cSrcweir                                 if(aClippedPolyPolygon != aOriginalPolyPolygon)
2564cdf0e10cSrcweir                                 {
2565cdf0e10cSrcweir                                     // start new clipping with intersected ClipPolyPolygon
2566cdf0e10cSrcweir                                     HandleNewClipRegion(aClippedPolyPolygon, rTargetHolders, rPropertyHolders);
2567cdf0e10cSrcweir                                 }
2568cdf0e10cSrcweir                             }
2569cdf0e10cSrcweir                         }
2570cdf0e10cSrcweir                         else
2571cdf0e10cSrcweir                         {
2572cdf0e10cSrcweir                             // start new clipping with new ClipPolyPolygon
2573cdf0e10cSrcweir                             HandleNewClipRegion(aNewClipPolyPolygon, rTargetHolders, rPropertyHolders);
2574cdf0e10cSrcweir                         }
2575cdf0e10cSrcweir                     }
2576cdf0e10cSrcweir 
2577cdf0e10cSrcweir                     break;
2578cdf0e10cSrcweir                 }
2579cdf0e10cSrcweir                 case META_MOVECLIPREGION_ACTION :
2580cdf0e10cSrcweir                 {
2581cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2582cdf0e10cSrcweir                     const MetaMoveClipRegionAction* pA = (const MetaMoveClipRegionAction*)pAction;
2583cdf0e10cSrcweir 
2584cdf0e10cSrcweir                     if(rPropertyHolders.Current().getClipPolyPolygonActive())
2585cdf0e10cSrcweir                     {
2586cdf0e10cSrcweir                         if(0 == rPropertyHolders.Current().getClipPolyPolygon().count())
2587cdf0e10cSrcweir                         {
2588cdf0e10cSrcweir                             // nothing to do
2589cdf0e10cSrcweir                         }
2590cdf0e10cSrcweir                         else
2591cdf0e10cSrcweir                         {
2592cdf0e10cSrcweir                             const sal_Int32 nHor(pA->GetHorzMove());
2593cdf0e10cSrcweir                             const sal_Int32 nVer(pA->GetVertMove());
2594cdf0e10cSrcweir 
2595cdf0e10cSrcweir                             if(0 != nHor || 0 != nVer)
2596cdf0e10cSrcweir                             {
2597cdf0e10cSrcweir                                 // prepare translation, add current transformation
2598cdf0e10cSrcweir                                 basegfx::B2DVector aVector(pA->GetHorzMove(), pA->GetVertMove());
2599cdf0e10cSrcweir                                 aVector *= rPropertyHolders.Current().getTransformation();
2600cdf0e10cSrcweir                                 basegfx::B2DHomMatrix aTransform(
2601cdf0e10cSrcweir                                     basegfx::tools::createTranslateB2DHomMatrix(aVector));
2602cdf0e10cSrcweir 
2603cdf0e10cSrcweir                                 // transform existing region
2604cdf0e10cSrcweir                                 basegfx::B2DPolyPolygon aClipPolyPolygon(
2605cdf0e10cSrcweir                                     rPropertyHolders.Current().getClipPolyPolygon());
2606cdf0e10cSrcweir 
2607cdf0e10cSrcweir                                 aClipPolyPolygon.transform(aTransform);
2608cdf0e10cSrcweir                                 HandleNewClipRegion(aClipPolyPolygon, rTargetHolders, rPropertyHolders);
2609cdf0e10cSrcweir                             }
2610cdf0e10cSrcweir                         }
2611cdf0e10cSrcweir                     }
2612cdf0e10cSrcweir 
2613cdf0e10cSrcweir                     break;
2614cdf0e10cSrcweir                 }
2615cdf0e10cSrcweir                 case META_LINECOLOR_ACTION :
2616cdf0e10cSrcweir                 {
2617cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2618cdf0e10cSrcweir                     const MetaLineColorAction* pA = (const MetaLineColorAction*)pAction;
2619cdf0e10cSrcweir                     const bool bActive(pA->IsSetting());
2620cdf0e10cSrcweir 
2621cdf0e10cSrcweir                     rPropertyHolders.Current().setLineColorActive(bActive);
2622cdf0e10cSrcweir                     if(bActive)
2623cdf0e10cSrcweir                         rPropertyHolders.Current().setLineColor(pA->GetColor().getBColor());
2624cdf0e10cSrcweir 
2625cdf0e10cSrcweir                     break;
2626cdf0e10cSrcweir                 }
2627cdf0e10cSrcweir                 case META_FILLCOLOR_ACTION :
2628cdf0e10cSrcweir                 {
2629cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2630cdf0e10cSrcweir                     const MetaFillColorAction* pA = (const MetaFillColorAction*)pAction;
2631cdf0e10cSrcweir                     const bool bActive(pA->IsSetting());
2632cdf0e10cSrcweir 
2633cdf0e10cSrcweir                     rPropertyHolders.Current().setFillColorActive(bActive);
2634cdf0e10cSrcweir                     if(bActive)
2635cdf0e10cSrcweir                         rPropertyHolders.Current().setFillColor(pA->GetColor().getBColor());
2636cdf0e10cSrcweir 
2637cdf0e10cSrcweir                     break;
2638cdf0e10cSrcweir                 }
2639cdf0e10cSrcweir                 case META_TEXTCOLOR_ACTION :
2640cdf0e10cSrcweir                 {
2641cdf0e10cSrcweir 					/** SIMPLE, DONE */
2642cdf0e10cSrcweir                     const MetaTextColorAction* pA = (const MetaTextColorAction*)pAction;
2643cdf0e10cSrcweir                     const bool bActivate(COL_TRANSPARENT != pA->GetColor().GetColor());
2644cdf0e10cSrcweir 
2645cdf0e10cSrcweir                     rPropertyHolders.Current().setTextColorActive(bActivate);
2646cdf0e10cSrcweir                     rPropertyHolders.Current().setTextColor(pA->GetColor().getBColor());
2647cdf0e10cSrcweir 
2648cdf0e10cSrcweir                     break;
2649cdf0e10cSrcweir                 }
2650cdf0e10cSrcweir                 case META_TEXTFILLCOLOR_ACTION :
2651cdf0e10cSrcweir                 {
2652cdf0e10cSrcweir 					/** SIMPLE, DONE */
2653cdf0e10cSrcweir                     const MetaTextFillColorAction* pA = (const MetaTextFillColorAction*)pAction;
2654cdf0e10cSrcweir                     const bool bWithColorArgument(pA->IsSetting());
2655cdf0e10cSrcweir 
2656cdf0e10cSrcweir                     if(bWithColorArgument)
2657cdf0e10cSrcweir                     {
2658cdf0e10cSrcweir                         // emulate OutputDevice::SetTextFillColor(...) WITH argument
2659cdf0e10cSrcweir                     	const Color& rFontFillColor = pA->GetColor();
2660cdf0e10cSrcweir                         rPropertyHolders.Current().setTextFillColor(rFontFillColor.getBColor());
2661cdf0e10cSrcweir                         rPropertyHolders.Current().setTextFillColorActive(COL_TRANSPARENT != rFontFillColor.GetColor());
2662cdf0e10cSrcweir                     }
2663cdf0e10cSrcweir                     else
2664cdf0e10cSrcweir                     {
2665cdf0e10cSrcweir                         // emulate SetFillColor() <- NO argument (!)
2666cdf0e10cSrcweir                         rPropertyHolders.Current().setTextFillColorActive(false);
2667cdf0e10cSrcweir                     }
2668cdf0e10cSrcweir 
2669cdf0e10cSrcweir                     break;
2670cdf0e10cSrcweir                 }
2671cdf0e10cSrcweir                 case META_TEXTALIGN_ACTION :
2672cdf0e10cSrcweir                 {
2673cdf0e10cSrcweir 					/** SIMPLE, DONE */
2674cdf0e10cSrcweir                     const MetaTextAlignAction* pA = (const MetaTextAlignAction*)pAction;
2675cdf0e10cSrcweir             	    const TextAlign aNewTextAlign = pA->GetTextAlign();
2676cdf0e10cSrcweir 
2677cdf0e10cSrcweir                     // TextAlign is applied to the current font (as in
2678cdf0e10cSrcweir                     // OutputDevice::SetTextAlign which would be used when
2679cdf0e10cSrcweir                     // playing the Metafile)
2680cdf0e10cSrcweir                     if(rPropertyHolders.Current().getFont().GetAlign() != aNewTextAlign)
2681cdf0e10cSrcweir                     {
2682cdf0e10cSrcweir                         Font aNewFont(rPropertyHolders.Current().getFont());
2683cdf0e10cSrcweir                         aNewFont.SetAlign(aNewTextAlign);
2684cdf0e10cSrcweir                         rPropertyHolders.Current().setFont(aNewFont);
2685cdf0e10cSrcweir                     }
2686cdf0e10cSrcweir 
2687cdf0e10cSrcweir                     break;
2688cdf0e10cSrcweir                 }
2689cdf0e10cSrcweir                 case META_MAPMODE_ACTION :
2690cdf0e10cSrcweir                 {
2691cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2692cdf0e10cSrcweir                     // the most necessary MapMode to be interpreted is MAP_RELATIVE,
2693cdf0e10cSrcweir                     // but also the others may occur. Even not yet supported ones
2694cdf0e10cSrcweir                     // may need to be added here later
2695cdf0e10cSrcweir                     const MetaMapModeAction* pA = (const MetaMapModeAction*)pAction;
2696cdf0e10cSrcweir 					const MapMode& rMapMode = pA->GetMapMode();
2697cdf0e10cSrcweir 					basegfx::B2DHomMatrix aMapping;
2698cdf0e10cSrcweir 
2699cdf0e10cSrcweir 					if(MAP_RELATIVE == rMapMode.GetMapUnit())
2700cdf0e10cSrcweir 					{
2701cdf0e10cSrcweir 						aMapping = getTransformFromMapMode(rMapMode);
2702cdf0e10cSrcweir 					}
2703cdf0e10cSrcweir 					else
2704cdf0e10cSrcweir 					{
2705cdf0e10cSrcweir 						switch(rMapMode.GetMapUnit())
2706cdf0e10cSrcweir 						{
2707cdf0e10cSrcweir 							case MAP_100TH_MM :
2708cdf0e10cSrcweir 							{
2709cdf0e10cSrcweir 								if(MAP_TWIP == rPropertyHolders.Current().getMapUnit())
2710cdf0e10cSrcweir 								{
2711cdf0e10cSrcweir 									// MAP_TWIP -> MAP_100TH_MM
2712cdf0e10cSrcweir 									const double fTwipTo100thMm(127.0 / 72.0);
2713cdf0e10cSrcweir 									aMapping.scale(fTwipTo100thMm, fTwipTo100thMm);
2714cdf0e10cSrcweir 								}
2715cdf0e10cSrcweir 								break;
2716cdf0e10cSrcweir 							}
2717cdf0e10cSrcweir 							case MAP_TWIP :
2718cdf0e10cSrcweir 							{
2719cdf0e10cSrcweir 								if(MAP_100TH_MM == rPropertyHolders.Current().getMapUnit())
2720cdf0e10cSrcweir 								{
2721cdf0e10cSrcweir 									// MAP_100TH_MM -> MAP_TWIP
2722cdf0e10cSrcweir 									const double f100thMmToTwip(72.0 / 127.0);
2723cdf0e10cSrcweir 									aMapping.scale(f100thMmToTwip, f100thMmToTwip);
2724cdf0e10cSrcweir 								}
2725cdf0e10cSrcweir 								break;
2726cdf0e10cSrcweir 							}
2727cdf0e10cSrcweir 							default :
2728cdf0e10cSrcweir 							{
2729cdf0e10cSrcweir 								OSL_ENSURE(false, "interpretMetafile: META_MAPMODE_ACTION with unsupported MapUnit (!)");
2730cdf0e10cSrcweir 								break;
2731cdf0e10cSrcweir 							}
2732cdf0e10cSrcweir 						}
2733cdf0e10cSrcweir 
2734cdf0e10cSrcweir 						aMapping = getTransformFromMapMode(rMapMode) * aMapping;
2735cdf0e10cSrcweir 						rPropertyHolders.Current().setMapUnit(rMapMode.GetMapUnit());
2736cdf0e10cSrcweir 					}
2737cdf0e10cSrcweir 
2738cdf0e10cSrcweir 					if(!aMapping.isIdentity())
2739cdf0e10cSrcweir 					{
2740cdf0e10cSrcweir 						aMapping = aMapping * rPropertyHolders.Current().getTransformation();
2741cdf0e10cSrcweir 						rPropertyHolders.Current().setTransformation(aMapping);
2742cdf0e10cSrcweir 					}
2743cdf0e10cSrcweir 
2744cdf0e10cSrcweir 					break;
2745cdf0e10cSrcweir                 }
2746cdf0e10cSrcweir                 case META_FONT_ACTION :
2747cdf0e10cSrcweir                 {
2748cdf0e10cSrcweir 					/** SIMPLE, DONE */
2749cdf0e10cSrcweir                     const MetaFontAction* pA = (const MetaFontAction*)pAction;
2750cdf0e10cSrcweir                     rPropertyHolders.Current().setFont(pA->GetFont());
2751cdf0e10cSrcweir                     Size aFontSize(pA->GetFont().GetSize());
2752cdf0e10cSrcweir 
2753cdf0e10cSrcweir                     if(0 == aFontSize.Height())
2754cdf0e10cSrcweir                     {
2755cdf0e10cSrcweir                         // this should not happen but i got Metafiles where this was the
2756cdf0e10cSrcweir                         // case. A height needs to be guessed (similar to OutputDevice::ImplNewFont())
2757cdf0e10cSrcweir                         Font aCorrectedFont(pA->GetFont());
2758cdf0e10cSrcweir 
2759cdf0e10cSrcweir                         // guess 16 pixel (as in VCL)
2760cdf0e10cSrcweir                         aFontSize = Size(0, 16);
2761cdf0e10cSrcweir 
2762cdf0e10cSrcweir                         // convert to target MapUnit if not pixels
2763cdf0e10cSrcweir 					    aFontSize = Application::GetDefaultDevice()->LogicToLogic(
2764cdf0e10cSrcweir 							aFontSize, MAP_PIXEL, rPropertyHolders.Current().getMapUnit());
2765cdf0e10cSrcweir 
2766cdf0e10cSrcweir                         aCorrectedFont.SetSize(aFontSize);
2767cdf0e10cSrcweir                         rPropertyHolders.Current().setFont(aCorrectedFont);
2768cdf0e10cSrcweir                     }
2769cdf0e10cSrcweir 
2770cdf0e10cSrcweir                     // older Metafiles have no META_TEXTCOLOR_ACTION which defines
2771cdf0e10cSrcweir                     // the FontColor now, so use the Font's color when not transparent
2772cdf0e10cSrcweir                     const Color& rFontColor = pA->GetFont().GetColor();
2773cdf0e10cSrcweir                     const bool bActivate(COL_TRANSPARENT != rFontColor.GetColor());
2774cdf0e10cSrcweir 
2775cdf0e10cSrcweir                     if(bActivate)
2776cdf0e10cSrcweir                     {
2777cdf0e10cSrcweir                         rPropertyHolders.Current().setTextColor(rFontColor.getBColor());
2778cdf0e10cSrcweir                     }
2779cdf0e10cSrcweir 
2780cdf0e10cSrcweir                     // caution: do NOT decativate here on transparet, see
2781cdf0e10cSrcweir                     // OutputDevice::SetFont(..) for more info
2782cdf0e10cSrcweir                     // rPropertyHolders.Current().setTextColorActive(bActivate);
2783cdf0e10cSrcweir 
2784cdf0e10cSrcweir                     // for fill color emulate a MetaTextFillColorAction with !transparent as bool,
2785cdf0e10cSrcweir                     // see OutputDevice::SetFont(..) the if(mpMetaFile) case
2786cdf0e10cSrcweir                     if(bActivate)
2787cdf0e10cSrcweir                     {
2788cdf0e10cSrcweir                     	const Color& rFontFillColor = pA->GetFont().GetFillColor();
2789cdf0e10cSrcweir                         rPropertyHolders.Current().setTextFillColor(rFontFillColor.getBColor());
2790cdf0e10cSrcweir                         rPropertyHolders.Current().setTextFillColorActive(COL_TRANSPARENT != rFontFillColor.GetColor());
2791cdf0e10cSrcweir                     }
2792cdf0e10cSrcweir                     else
2793cdf0e10cSrcweir                     {
2794cdf0e10cSrcweir                         rPropertyHolders.Current().setTextFillColorActive(false);
2795cdf0e10cSrcweir                     }
2796cdf0e10cSrcweir 
2797cdf0e10cSrcweir                     break;
2798cdf0e10cSrcweir                 }
2799cdf0e10cSrcweir                 case META_PUSH_ACTION :
2800cdf0e10cSrcweir                 {
2801cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2802cdf0e10cSrcweir                     const MetaPushAction* pA = (const MetaPushAction*)pAction;
2803cdf0e10cSrcweir                     rPropertyHolders.Push(pA->GetFlags());
2804cdf0e10cSrcweir 
2805cdf0e10cSrcweir                     break;
2806cdf0e10cSrcweir                 }
2807cdf0e10cSrcweir                 case META_POP_ACTION :
2808cdf0e10cSrcweir                 {
2809cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2810cdf0e10cSrcweir                     const bool bRegionMayChange(rPropertyHolders.Current().getPushFlags() & PUSH_CLIPREGION);
2811cdf0e10cSrcweir                     const bool bRasterOpMayChange(rPropertyHolders.Current().getPushFlags() & PUSH_RASTEROP);
2812cdf0e10cSrcweir 
2813cdf0e10cSrcweir                     if(bRegionMayChange && rPropertyHolders.Current().getClipPolyPolygonActive())
2814cdf0e10cSrcweir                     {
2815cdf0e10cSrcweir                         // end evtl. clipping
2816cdf0e10cSrcweir                         const basegfx::B2DPolyPolygon aEmptyPolyPolygon;
2817cdf0e10cSrcweir 
2818cdf0e10cSrcweir                         HandleNewClipRegion(aEmptyPolyPolygon, rTargetHolders, rPropertyHolders);
2819cdf0e10cSrcweir                     }
2820cdf0e10cSrcweir 
2821cdf0e10cSrcweir                     if(bRasterOpMayChange && rPropertyHolders.Current().isRasterOpActive())
2822cdf0e10cSrcweir                     {
2823cdf0e10cSrcweir                         // end evtl. RasterOp
2824cdf0e10cSrcweir                         HandleNewRasterOp(ROP_OVERPAINT, rTargetHolders, rPropertyHolders);
2825cdf0e10cSrcweir                     }
2826cdf0e10cSrcweir 
2827cdf0e10cSrcweir                     rPropertyHolders.Pop();
2828cdf0e10cSrcweir 
2829cdf0e10cSrcweir                     if(bRasterOpMayChange && rPropertyHolders.Current().isRasterOpActive())
2830cdf0e10cSrcweir                     {
2831cdf0e10cSrcweir                         // start evtl. RasterOp
2832cdf0e10cSrcweir                         HandleNewRasterOp(rPropertyHolders.Current().getRasterOp(), rTargetHolders, rPropertyHolders);
2833cdf0e10cSrcweir                     }
2834cdf0e10cSrcweir 
2835cdf0e10cSrcweir                     if(bRegionMayChange && rPropertyHolders.Current().getClipPolyPolygonActive())
2836cdf0e10cSrcweir                     {
2837cdf0e10cSrcweir                         // start evtl. clipping
2838cdf0e10cSrcweir                         HandleNewClipRegion(
2839cdf0e10cSrcweir                             rPropertyHolders.Current().getClipPolyPolygon(), rTargetHolders, rPropertyHolders);
2840cdf0e10cSrcweir                     }
2841cdf0e10cSrcweir 
2842cdf0e10cSrcweir                     break;
2843cdf0e10cSrcweir                 }
2844cdf0e10cSrcweir                 case META_RASTEROP_ACTION :
2845cdf0e10cSrcweir                 {
2846cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2847cdf0e10cSrcweir                     const MetaRasterOpAction* pA = (const MetaRasterOpAction*)pAction;
2848cdf0e10cSrcweir                 	const RasterOp aRasterOp = pA->GetRasterOp();
2849cdf0e10cSrcweir 
2850cdf0e10cSrcweir                     HandleNewRasterOp(aRasterOp, rTargetHolders, rPropertyHolders);
2851cdf0e10cSrcweir 
2852cdf0e10cSrcweir                     break;
2853cdf0e10cSrcweir                 }
2854cdf0e10cSrcweir                 case META_TRANSPARENT_ACTION :
2855cdf0e10cSrcweir                 {
2856cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2857cdf0e10cSrcweir                     const MetaTransparentAction* pA = (const MetaTransparentAction*)pAction;
2858cdf0e10cSrcweir 					const basegfx::B2DPolyPolygon aOutline(pA->GetPolyPolygon().getB2DPolyPolygon());
2859cdf0e10cSrcweir 
2860cdf0e10cSrcweir 					if(aOutline.count())
2861cdf0e10cSrcweir 					{
2862cdf0e10cSrcweir 						const sal_uInt16 nTransparence(pA->GetTransparence());
2863cdf0e10cSrcweir 
2864cdf0e10cSrcweir 						if(0 == nTransparence)
2865cdf0e10cSrcweir 						{
2866cdf0e10cSrcweir 							// not transparent
2867cdf0e10cSrcweir 							createHairlineAndFillPrimitive(aOutline, rTargetHolders.Current(), rPropertyHolders.Current());
2868cdf0e10cSrcweir 						}
2869cdf0e10cSrcweir 						else if(nTransparence >= 100)
2870cdf0e10cSrcweir 						{
2871cdf0e10cSrcweir 							// fully or more than transparent
2872cdf0e10cSrcweir 						}
2873cdf0e10cSrcweir 						else
2874cdf0e10cSrcweir 						{
2875cdf0e10cSrcweir 							// transparent. Create new target
2876cdf0e10cSrcweir                             rTargetHolders.Push();
2877cdf0e10cSrcweir 
2878cdf0e10cSrcweir 							// create primitives there and get them
2879cdf0e10cSrcweir 							createHairlineAndFillPrimitive(aOutline, rTargetHolders.Current(), rPropertyHolders.Current());
2880cdf0e10cSrcweir 							const drawinglayer::primitive2d::Primitive2DSequence aSubContent(
2881cdf0e10cSrcweir                                 rTargetHolders.Current().getPrimitive2DSequence(rPropertyHolders.Current()));
2882cdf0e10cSrcweir 
2883cdf0e10cSrcweir 							// back to old target
2884cdf0e10cSrcweir                             rTargetHolders.Pop();
2885cdf0e10cSrcweir 
2886cdf0e10cSrcweir 							if(aSubContent.hasElements())
2887cdf0e10cSrcweir 							{
2888cdf0e10cSrcweir 								rTargetHolders.Current().append(
2889cdf0e10cSrcweir 									new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D(
2890cdf0e10cSrcweir 										aSubContent,
2891cdf0e10cSrcweir 										nTransparence * 0.01));
2892cdf0e10cSrcweir 							}
2893cdf0e10cSrcweir 						}
2894cdf0e10cSrcweir 					}
2895cdf0e10cSrcweir 
2896cdf0e10cSrcweir                     break;
2897cdf0e10cSrcweir                 }
2898cdf0e10cSrcweir                 case META_EPS_ACTION :
2899cdf0e10cSrcweir                 {
2900cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2901cdf0e10cSrcweir 					// To support this action, i have added a EpsPrimitive2D which will
2902cdf0e10cSrcweir 					// by default decompose to the Metafile replacement data. To support
2903cdf0e10cSrcweir 					// this EPS on screen, the renderer visualizing this has to support
2904cdf0e10cSrcweir 					// that primitive and visualize the Eps file (e.g. printing)
2905cdf0e10cSrcweir                     const MetaEPSAction* pA = (const MetaEPSAction*)pAction;
2906cdf0e10cSrcweir 					const Rectangle aRectangle(pA->GetPoint(), pA->GetSize());
2907cdf0e10cSrcweir 
2908cdf0e10cSrcweir 					if(!aRectangle.IsEmpty())
2909cdf0e10cSrcweir                     {
2910cdf0e10cSrcweir 						// create object transform
2911cdf0e10cSrcweir 						basegfx::B2DHomMatrix aObjectTransform;
2912cdf0e10cSrcweir 
2913cdf0e10cSrcweir 						aObjectTransform.set(0, 0, aRectangle.GetWidth());
2914cdf0e10cSrcweir 						aObjectTransform.set(1, 1, aRectangle.GetHeight());
2915cdf0e10cSrcweir 						aObjectTransform.set(0, 2, aRectangle.Left());
2916cdf0e10cSrcweir 						aObjectTransform.set(1, 2, aRectangle.Top());
2917cdf0e10cSrcweir 
2918cdf0e10cSrcweir 						// add current transformation
2919cdf0e10cSrcweir 						aObjectTransform = rPropertyHolders.Current().getTransformation() * aObjectTransform;
2920cdf0e10cSrcweir 
2921cdf0e10cSrcweir 						// embed using EpsPrimitive
2922cdf0e10cSrcweir 						rTargetHolders.Current().append(
2923cdf0e10cSrcweir 							new drawinglayer::primitive2d::EpsPrimitive2D(
2924cdf0e10cSrcweir 								aObjectTransform,
2925cdf0e10cSrcweir 								pA->GetLink(),
2926cdf0e10cSrcweir 								pA->GetSubstitute()));
2927cdf0e10cSrcweir 					}
2928cdf0e10cSrcweir 
2929cdf0e10cSrcweir 					break;
2930cdf0e10cSrcweir                 }
2931cdf0e10cSrcweir                 case META_REFPOINT_ACTION :
2932cdf0e10cSrcweir                 {
2933cdf0e10cSrcweir 					/** SIMPLE, DONE */
2934cdf0e10cSrcweir                     // only used for hatch and line pattern offsets, pretty much no longer
2935cdf0e10cSrcweir                     // supported today
2936cdf0e10cSrcweir                     // const MetaRefPointAction* pA = (const MetaRefPointAction*)pAction;
2937cdf0e10cSrcweir                     break;
2938cdf0e10cSrcweir                 }
2939cdf0e10cSrcweir                 case META_TEXTLINECOLOR_ACTION :
2940cdf0e10cSrcweir                 {
2941cdf0e10cSrcweir 					/** SIMPLE, DONE */
2942cdf0e10cSrcweir                     const MetaTextLineColorAction* pA = (const MetaTextLineColorAction*)pAction;
2943cdf0e10cSrcweir                     const bool bActive(pA->IsSetting());
2944cdf0e10cSrcweir 
2945cdf0e10cSrcweir                     rPropertyHolders.Current().setTextLineColorActive(bActive);
2946cdf0e10cSrcweir                     if(bActive)
2947cdf0e10cSrcweir                         rPropertyHolders.Current().setTextLineColor(pA->GetColor().getBColor());
2948cdf0e10cSrcweir 
2949cdf0e10cSrcweir                     break;
2950cdf0e10cSrcweir                 }
2951cdf0e10cSrcweir                 case META_TEXTLINE_ACTION :
2952cdf0e10cSrcweir                 {
2953cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2954cdf0e10cSrcweir 					// actually creates overline, underline and strikeouts, so
2955cdf0e10cSrcweir 					// these should be isolated from TextDecoratedPortionPrimitive2D
2956cdf0e10cSrcweir 					// to own primitives. Done, available now.
2957cdf0e10cSrcweir 					//
2958cdf0e10cSrcweir 					// This Metaaction seems not to be used (was not used in any
2959cdf0e10cSrcweir 					// checked files). It's used in combination with the current
2960cdf0e10cSrcweir 					// Font.
2961cdf0e10cSrcweir                     const MetaTextLineAction* pA = (const MetaTextLineAction*)pAction;
2962cdf0e10cSrcweir 
2963cdf0e10cSrcweir 					proccessMetaTextLineAction(
2964cdf0e10cSrcweir 						*pA,
2965cdf0e10cSrcweir 						rTargetHolders.Current(),
2966cdf0e10cSrcweir 						rPropertyHolders.Current());
2967cdf0e10cSrcweir 
2968cdf0e10cSrcweir                     break;
2969cdf0e10cSrcweir                 }
2970cdf0e10cSrcweir                 case META_FLOATTRANSPARENT_ACTION :
2971cdf0e10cSrcweir                 {
2972cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
2973cdf0e10cSrcweir                     const MetaFloatTransparentAction* pA = (const MetaFloatTransparentAction*)pAction;
29748718d260SArmin Le Grand 					const basegfx::B2DRange aTargetRange(
29758718d260SArmin Le Grand                         pA->GetPoint().X(),
29768718d260SArmin Le Grand                         pA->GetPoint().Y(),
29778718d260SArmin Le Grand                         pA->GetPoint().X() + pA->GetSize().Width(),
29788718d260SArmin Le Grand                         pA->GetPoint().Y() + pA->GetSize().Height());
2979cdf0e10cSrcweir 
29808718d260SArmin Le Grand 					if(!aTargetRange.isEmpty())
2981cdf0e10cSrcweir 					{
2982cdf0e10cSrcweir 						const GDIMetaFile& rContent = pA->GetGDIMetaFile();
2983cdf0e10cSrcweir 
2984cdf0e10cSrcweir 						if(rContent.GetActionCount())
2985cdf0e10cSrcweir 						{
2986cdf0e10cSrcweir 							// create the sub-content with no embedding specific to the
2987cdf0e10cSrcweir 							// sub-metafile, this seems not to be used.
2988cdf0e10cSrcweir 							drawinglayer::primitive2d::Primitive2DSequence xSubContent;
2989cdf0e10cSrcweir 							{
2990cdf0e10cSrcweir                                 rTargetHolders.Push();
2991cdf0e10cSrcweir 								// #i# for sub-Mteafile contents, do start with new, default render state
2992cdf0e10cSrcweir 								rPropertyHolders.PushDefault();
2993cdf0e10cSrcweir 								interpretMetafile(rContent, rTargetHolders, rPropertyHolders, rViewInformation);
2994cdf0e10cSrcweir 								xSubContent = rTargetHolders.Current().getPrimitive2DSequence(rPropertyHolders.Current());
2995cdf0e10cSrcweir 								rPropertyHolders.Pop();
2996cdf0e10cSrcweir                                 rTargetHolders.Pop();
2997cdf0e10cSrcweir 							}
2998cdf0e10cSrcweir 
2999cdf0e10cSrcweir 							if(xSubContent.hasElements())
3000cdf0e10cSrcweir 							{
30018718d260SArmin Le Grand                                 // create SourceRange
30028718d260SArmin Le Grand                                 const basegfx::B2DRange aSourceRange(
30038718d260SArmin Le Grand                                     rContent.GetPrefMapMode().GetOrigin().X(),
30048718d260SArmin Le Grand                                     rContent.GetPrefMapMode().GetOrigin().Y(),
30058718d260SArmin Le Grand                                     rContent.GetPrefMapMode().GetOrigin().X() + rContent.GetPrefSize().Width(),
30068718d260SArmin Le Grand                                     rContent.GetPrefMapMode().GetOrigin().Y() + rContent.GetPrefSize().Height());
30078718d260SArmin Le Grand 
30088718d260SArmin Le Grand                                 // apply mapping if aTargetRange and aSourceRange are not equal
30098718d260SArmin Le Grand                                 if(!aSourceRange.equal(aTargetRange))
30108718d260SArmin Le Grand                                 {
30118718d260SArmin Le Grand                                     basegfx::B2DHomMatrix aTransform;
30128718d260SArmin Le Grand 
30138718d260SArmin Le Grand                                     aTransform.translate(-aSourceRange.getMinX(), -aSourceRange.getMinY());
30148718d260SArmin Le Grand                                     aTransform.scale(
30158718d260SArmin Le Grand                                         aTargetRange.getWidth() / (basegfx::fTools::equalZero(aSourceRange.getWidth()) ? 1.0 : aSourceRange.getWidth()),
30168718d260SArmin Le Grand                                         aTargetRange.getHeight() / (basegfx::fTools::equalZero(aSourceRange.getHeight()) ? 1.0 : aSourceRange.getHeight()));
30178718d260SArmin Le Grand                                     aTransform.translate(aTargetRange.getMinX(), aTargetRange.getMinY());
30188718d260SArmin Le Grand 
30198718d260SArmin Le Grand 				                    const drawinglayer::primitive2d::Primitive2DReference aEmbeddedTransform(
30208718d260SArmin Le Grand 					                    new drawinglayer::primitive2d::TransformPrimitive2D(
30218718d260SArmin Le Grand 						                    aTransform,
30228718d260SArmin Le Grand 						                    xSubContent));
30238718d260SArmin Le Grand 
30248718d260SArmin Le Grand 				                    xSubContent = drawinglayer::primitive2d::Primitive2DSequence(&aEmbeddedTransform, 1);
30258718d260SArmin Le Grand                                 }
30268718d260SArmin Le Grand 
3027cdf0e10cSrcweir 								// check if gradient is a real gradient
3028cdf0e10cSrcweir 								const Gradient& rGradient = pA->GetGradient();
3029cdf0e10cSrcweir 								const drawinglayer::attribute::FillGradientAttribute aAttribute(createFillGradientAttribute(rGradient));
3030cdf0e10cSrcweir 
3031cdf0e10cSrcweir 								if(aAttribute.getStartColor() == aAttribute.getEndColor())
3032cdf0e10cSrcweir 								{
3033cdf0e10cSrcweir 									// not really a gradient; create UnifiedTransparencePrimitive2D
3034cdf0e10cSrcweir 									rTargetHolders.Current().append(
3035cdf0e10cSrcweir 										new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D(
3036cdf0e10cSrcweir 											xSubContent,
3037cdf0e10cSrcweir 											aAttribute.getStartColor().luminance()));
3038cdf0e10cSrcweir 								}
3039cdf0e10cSrcweir 								else
3040cdf0e10cSrcweir 								{
3041cdf0e10cSrcweir 									// really a gradient. Create gradient sub-content (with correct scaling)
30428718d260SArmin Le Grand 									basegfx::B2DRange aRange(aTargetRange);
3043cdf0e10cSrcweir 									aRange.transform(rPropertyHolders.Current().getTransformation());
3044cdf0e10cSrcweir 
3045cdf0e10cSrcweir                                     // prepare gradient for transparent content
3046cdf0e10cSrcweir 			                        const drawinglayer::primitive2d::Primitive2DReference xTransparence(
3047cdf0e10cSrcweir 				                        new drawinglayer::primitive2d::FillGradientPrimitive2D(
3048cdf0e10cSrcweir 										    aRange,
3049cdf0e10cSrcweir 										    aAttribute));
3050cdf0e10cSrcweir 
3051cdf0e10cSrcweir 									// create transparence primitive
3052cdf0e10cSrcweir 									rTargetHolders.Current().append(
3053cdf0e10cSrcweir 										new drawinglayer::primitive2d::TransparencePrimitive2D(
3054cdf0e10cSrcweir 											xSubContent,
3055cdf0e10cSrcweir                                             drawinglayer::primitive2d::Primitive2DSequence(&xTransparence, 1)));
3056cdf0e10cSrcweir 								}
3057cdf0e10cSrcweir 							}
3058cdf0e10cSrcweir 						}
3059cdf0e10cSrcweir 					}
3060cdf0e10cSrcweir 
3061cdf0e10cSrcweir                     break;
3062cdf0e10cSrcweir                 }
3063cdf0e10cSrcweir                 case META_GRADIENTEX_ACTION :
3064cdf0e10cSrcweir                 {
3065cdf0e10cSrcweir 					/** SIMPLE, DONE */
3066cdf0e10cSrcweir                     // This is only a data holder which is interpreted inside comment actions,
3067cdf0e10cSrcweir                     // see META_COMMENT_ACTION for more info
3068cdf0e10cSrcweir                     // const MetaGradientExAction* pA = (const MetaGradientExAction*)pAction;
3069cdf0e10cSrcweir                     break;
3070cdf0e10cSrcweir                 }
3071cdf0e10cSrcweir                 case META_LAYOUTMODE_ACTION :
3072cdf0e10cSrcweir                 {
3073cdf0e10cSrcweir 					/** SIMPLE, DONE */
3074cdf0e10cSrcweir                     const MetaLayoutModeAction* pA = (const MetaLayoutModeAction*)pAction;
3075cdf0e10cSrcweir                     rPropertyHolders.Current().setLayoutMode(pA->GetLayoutMode());
3076cdf0e10cSrcweir                     break;
3077cdf0e10cSrcweir                 }
3078cdf0e10cSrcweir                 case META_TEXTLANGUAGE_ACTION :
3079cdf0e10cSrcweir                 {
3080cdf0e10cSrcweir 					/** SIMPLE, DONE */
3081cdf0e10cSrcweir                     const MetaTextLanguageAction* pA = (const MetaTextLanguageAction*)pAction;
3082cdf0e10cSrcweir                     rPropertyHolders.Current().setLanguageType(pA->GetTextLanguage());
3083cdf0e10cSrcweir                     break;
3084cdf0e10cSrcweir                 }
3085cdf0e10cSrcweir                 case META_OVERLINECOLOR_ACTION :
3086cdf0e10cSrcweir                 {
3087cdf0e10cSrcweir 					/** SIMPLE, DONE */
3088cdf0e10cSrcweir                     const MetaOverlineColorAction* pA = (const MetaOverlineColorAction*)pAction;
3089cdf0e10cSrcweir                     const bool bActive(pA->IsSetting());
3090cdf0e10cSrcweir 
3091cdf0e10cSrcweir                     rPropertyHolders.Current().setOverlineColorActive(bActive);
3092cdf0e10cSrcweir                     if(bActive)
3093cdf0e10cSrcweir                         rPropertyHolders.Current().setOverlineColor(pA->GetColor().getBColor());
3094cdf0e10cSrcweir 
3095cdf0e10cSrcweir                     break;
3096cdf0e10cSrcweir                 }
3097cdf0e10cSrcweir                 case META_COMMENT_ACTION :
3098cdf0e10cSrcweir                 {
3099cdf0e10cSrcweir 					/** CHECKED, WORKS WELL */
3100cdf0e10cSrcweir                     // I already implemented
3101cdf0e10cSrcweir                     //     XPATHFILL_SEQ_BEGIN, XPATHFILL_SEQ_END
3102cdf0e10cSrcweir                     //     XPATHSTROKE_SEQ_BEGIN, XPATHSTROKE_SEQ_END,
3103cdf0e10cSrcweir                     // but opted to remove these again; it works well without them
3104cdf0e10cSrcweir                     // and makes the code less dependent from those Metafile Add-Ons
3105cdf0e10cSrcweir                     const MetaCommentAction* pA = (const MetaCommentAction*)pAction;
3106cdf0e10cSrcweir 
3107cdf0e10cSrcweir 					if(COMPARE_EQUAL == pA->GetComment().CompareIgnoreCaseToAscii("XGRAD_SEQ_BEGIN"))
3108cdf0e10cSrcweir 					{
3109cdf0e10cSrcweir                         // XGRAD_SEQ_BEGIN, XGRAD_SEQ_END should be supported since the
3110cdf0e10cSrcweir                         // pure recorded paint of the gradients uses the XOR paint functionality
3111cdf0e10cSrcweir                         // ('trick'). This is (and will be) broblematic with AntAliasing, so it's
3112cdf0e10cSrcweir                         // better to use this info
3113cdf0e10cSrcweir 						const MetaGradientExAction*	pMetaGradientExAction = 0;
3114cdf0e10cSrcweir 						bool bDone(false);
3115cdf0e10cSrcweir 						sal_uInt32 b(nAction + 1);
3116cdf0e10cSrcweir 
3117cdf0e10cSrcweir 						for(; !bDone && b < nCount; b++)
3118cdf0e10cSrcweir 						{
3119cdf0e10cSrcweir 							pAction = rMetaFile.GetAction(b);
3120cdf0e10cSrcweir 
3121cdf0e10cSrcweir 							if(META_GRADIENTEX_ACTION == pAction->GetType())
3122cdf0e10cSrcweir 							{
3123cdf0e10cSrcweir 								pMetaGradientExAction = (const MetaGradientExAction*)pAction;
3124cdf0e10cSrcweir 							}
3125cdf0e10cSrcweir 							else if(META_COMMENT_ACTION == pAction->GetType())
3126cdf0e10cSrcweir 							{
3127cdf0e10cSrcweir 								if(COMPARE_EQUAL == ((const MetaCommentAction*)pAction)->GetComment().CompareIgnoreCaseToAscii("XGRAD_SEQ_END"))
3128cdf0e10cSrcweir 								{
3129cdf0e10cSrcweir 									bDone = true;
3130cdf0e10cSrcweir 								}
3131cdf0e10cSrcweir 							}
3132cdf0e10cSrcweir 						}
3133cdf0e10cSrcweir 
3134cdf0e10cSrcweir 						if(bDone && pMetaGradientExAction)
3135cdf0e10cSrcweir 						{
3136cdf0e10cSrcweir 							// consume actions and skip forward
3137cdf0e10cSrcweir 							nAction = b - 1;
3138cdf0e10cSrcweir 
3139cdf0e10cSrcweir 							// get geometry data
3140cdf0e10cSrcweir 							basegfx::B2DPolyPolygon aPolyPolygon(pMetaGradientExAction->GetPolyPolygon().getB2DPolyPolygon());
3141cdf0e10cSrcweir 
3142cdf0e10cSrcweir 							if(aPolyPolygon.count())
3143cdf0e10cSrcweir 							{
3144cdf0e10cSrcweir 								// transform geometry
3145cdf0e10cSrcweir 								aPolyPolygon.transform(rPropertyHolders.Current().getTransformation());
3146cdf0e10cSrcweir 
3147cdf0e10cSrcweir 								// get and check if gradient is a real gradient
3148cdf0e10cSrcweir 								const Gradient& rGradient = pMetaGradientExAction->GetGradient();
3149cdf0e10cSrcweir 								const drawinglayer::attribute::FillGradientAttribute aAttribute(createFillGradientAttribute(rGradient));
3150cdf0e10cSrcweir 
3151cdf0e10cSrcweir 								if(aAttribute.getStartColor() == aAttribute.getEndColor())
3152cdf0e10cSrcweir 								{
3153cdf0e10cSrcweir 									// not really a gradient
3154cdf0e10cSrcweir 									rTargetHolders.Current().append(
3155cdf0e10cSrcweir 										new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
3156cdf0e10cSrcweir 											aPolyPolygon,
3157cdf0e10cSrcweir 											aAttribute.getStartColor()));
3158cdf0e10cSrcweir 								}
3159cdf0e10cSrcweir 								else
3160cdf0e10cSrcweir 								{
3161cdf0e10cSrcweir 									// really a gradient
3162cdf0e10cSrcweir 									rTargetHolders.Current().append(
3163cdf0e10cSrcweir 										new drawinglayer::primitive2d::PolyPolygonGradientPrimitive2D(
3164cdf0e10cSrcweir 											aPolyPolygon,
3165cdf0e10cSrcweir 											aAttribute));
3166cdf0e10cSrcweir 								}
3167cdf0e10cSrcweir 							}
3168cdf0e10cSrcweir 						}
3169cdf0e10cSrcweir 					}
3170cdf0e10cSrcweir 
3171cdf0e10cSrcweir 					break;
3172cdf0e10cSrcweir                 }
3173cdf0e10cSrcweir                 default:
3174cdf0e10cSrcweir                 {
3175cdf0e10cSrcweir                     OSL_ENSURE(false, "Unknown MetaFile Action (!)");
3176cdf0e10cSrcweir                     break;
3177cdf0e10cSrcweir                 }
3178cdf0e10cSrcweir             }
3179cdf0e10cSrcweir         }
3180cdf0e10cSrcweir     }
3181cdf0e10cSrcweir } // end of anonymous namespace
3182cdf0e10cSrcweir 
3183cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
3184cdf0e10cSrcweir 
3185cdf0e10cSrcweir namespace drawinglayer
3186cdf0e10cSrcweir {
3187cdf0e10cSrcweir 	namespace primitive2d
3188cdf0e10cSrcweir 	{
3189cdf0e10cSrcweir 		Primitive2DSequence MetafilePrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
3190cdf0e10cSrcweir         {
3191cdf0e10cSrcweir 			// prepare target and porperties; each will have one default entry
3192cdf0e10cSrcweir             TargetHolders aTargetHolders;
3193cdf0e10cSrcweir             PropertyHolders aPropertyHolders;
3194cdf0e10cSrcweir 
3195cdf0e10cSrcweir 			// set target MapUnit at Properties
3196cdf0e10cSrcweir 			aPropertyHolders.Current().setMapUnit(getMetaFile().GetPrefMapMode().GetMapUnit());
3197cdf0e10cSrcweir 
3198cdf0e10cSrcweir 			// interpret the Metafile
3199cdf0e10cSrcweir             interpretMetafile(getMetaFile(), aTargetHolders, aPropertyHolders, rViewInformation);
3200cdf0e10cSrcweir 
3201cdf0e10cSrcweir 			// get the content. There should be ony one target, as in the start condition,
3202cdf0e10cSrcweir             // but iterating will be the right thing to do when some push/pop is not closed
3203cdf0e10cSrcweir 			Primitive2DSequence xRetval;
3204cdf0e10cSrcweir 
3205cdf0e10cSrcweir             while(aTargetHolders.size() > 1)
3206cdf0e10cSrcweir             {
3207cdf0e10cSrcweir                 appendPrimitive2DSequenceToPrimitive2DSequence(xRetval,
3208cdf0e10cSrcweir                     aTargetHolders.Current().getPrimitive2DSequence(aPropertyHolders.Current()));
3209cdf0e10cSrcweir                 aTargetHolders.Pop();
3210cdf0e10cSrcweir             }
3211cdf0e10cSrcweir 
3212cdf0e10cSrcweir             appendPrimitive2DSequenceToPrimitive2DSequence(xRetval,
3213cdf0e10cSrcweir                 aTargetHolders.Current().getPrimitive2DSequence(aPropertyHolders.Current()));
3214cdf0e10cSrcweir 
3215cdf0e10cSrcweir 			if(xRetval.hasElements())
3216cdf0e10cSrcweir 			{
3217cdf0e10cSrcweir 				// get target size
3218cdf0e10cSrcweir 				const Rectangle aMtfTarget(getMetaFile().GetPrefMapMode().GetOrigin(), getMetaFile().GetPrefSize());
3219cdf0e10cSrcweir 
3220cdf0e10cSrcweir                 // create transformation
3221cdf0e10cSrcweir 				basegfx::B2DHomMatrix aAdaptedTransform;
3222cdf0e10cSrcweir 
3223cdf0e10cSrcweir 				aAdaptedTransform.translate(-aMtfTarget.Left(), -aMtfTarget.Top());
3224cdf0e10cSrcweir 				aAdaptedTransform.scale(
3225cdf0e10cSrcweir 					aMtfTarget.getWidth() ? 1.0 / aMtfTarget.getWidth() : 1.0,
3226cdf0e10cSrcweir 					aMtfTarget.getHeight() ? 1.0 / aMtfTarget.getHeight() : 1.0);
3227cdf0e10cSrcweir 				aAdaptedTransform = getTransform() * aAdaptedTransform;
3228cdf0e10cSrcweir 
3229cdf0e10cSrcweir 				// embed to target transformation
3230cdf0e10cSrcweir 				const Primitive2DReference aEmbeddedTransform(
3231cdf0e10cSrcweir 					new TransformPrimitive2D(
3232cdf0e10cSrcweir 						aAdaptedTransform,
3233cdf0e10cSrcweir 						xRetval));
3234cdf0e10cSrcweir 
3235cdf0e10cSrcweir 				xRetval = Primitive2DSequence(&aEmbeddedTransform, 1);
3236cdf0e10cSrcweir 			}
3237cdf0e10cSrcweir 
3238cdf0e10cSrcweir             return xRetval;
3239cdf0e10cSrcweir         }
3240cdf0e10cSrcweir 
3241cdf0e10cSrcweir 		MetafilePrimitive2D::MetafilePrimitive2D(
3242cdf0e10cSrcweir 			const basegfx::B2DHomMatrix& rMetaFileTransform,
3243cdf0e10cSrcweir 			const GDIMetaFile& rMetaFile)
3244cdf0e10cSrcweir 		:	BufferedDecompositionPrimitive2D(),
3245cdf0e10cSrcweir 			maMetaFileTransform(rMetaFileTransform),
3246cdf0e10cSrcweir 			maMetaFile(rMetaFile)
3247cdf0e10cSrcweir 		{
3248cdf0e10cSrcweir 		}
3249cdf0e10cSrcweir 
3250cdf0e10cSrcweir 		bool MetafilePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
3251cdf0e10cSrcweir 		{
3252cdf0e10cSrcweir 			if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
3253cdf0e10cSrcweir 			{
3254cdf0e10cSrcweir 				const MetafilePrimitive2D& rCompare = (MetafilePrimitive2D&)rPrimitive;
3255cdf0e10cSrcweir 
3256cdf0e10cSrcweir 				return (getTransform() == rCompare.getTransform()
3257cdf0e10cSrcweir 					&& getMetaFile() == rCompare.getMetaFile());
3258cdf0e10cSrcweir 			}
3259cdf0e10cSrcweir 
3260cdf0e10cSrcweir 			return false;
3261cdf0e10cSrcweir 		}
3262cdf0e10cSrcweir 
3263cdf0e10cSrcweir 		basegfx::B2DRange MetafilePrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
3264cdf0e10cSrcweir 		{
3265cdf0e10cSrcweir 			// use own implementation to quickly answer the getB2DRange question. The
3266cdf0e10cSrcweir             // MetafilePrimitive2D assumes that all geometry is inside of the shape. If
3267cdf0e10cSrcweir             // this is not the case (i have already seen some wrong Metafiles) it should
3268cdf0e10cSrcweir             // be embedded to a MaskPrimitive2D
3269cdf0e10cSrcweir 			basegfx::B2DRange aRetval(0.0, 0.0, 1.0, 1.0);
3270cdf0e10cSrcweir 			aRetval.transform(getTransform());
3271cdf0e10cSrcweir 
3272cdf0e10cSrcweir             return aRetval;
3273cdf0e10cSrcweir 		}
3274cdf0e10cSrcweir 
3275cdf0e10cSrcweir 		// provide unique ID
3276cdf0e10cSrcweir 		ImplPrimitrive2DIDBlock(MetafilePrimitive2D, PRIMITIVE2D_ID_METAFILEPRIMITIVE2D)
3277cdf0e10cSrcweir 
3278cdf0e10cSrcweir 	} // end of namespace primitive2d
3279cdf0e10cSrcweir } // end of namespace drawinglayer
3280cdf0e10cSrcweir 
3281cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
3282cdf0e10cSrcweir // eof
3283