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