1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <drawinglayer/processor2d/textaspolygonextractor2d.hxx>
32*cdf0e10cSrcweir #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
33*cdf0e10cSrcweir #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
34*cdf0e10cSrcweir #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
35*cdf0e10cSrcweir #include <drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx>
36*cdf0e10cSrcweir #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir namespace drawinglayer
41*cdf0e10cSrcweir {
42*cdf0e10cSrcweir 	namespace processor2d
43*cdf0e10cSrcweir 	{
44*cdf0e10cSrcweir 		void TextAsPolygonExtractor2D::processBasePrimitive2D(const primitive2d::BasePrimitive2D& rCandidate)
45*cdf0e10cSrcweir 		{
46*cdf0e10cSrcweir 			switch(rCandidate.getPrimitive2DID())
47*cdf0e10cSrcweir 			{
48*cdf0e10cSrcweir 				case PRIMITIVE2D_ID_TEXTDECORATEDPORTIONPRIMITIVE2D :
49*cdf0e10cSrcweir 				{
50*cdf0e10cSrcweir 					// TextDecoratedPortionPrimitive2D can produce the following primitives
51*cdf0e10cSrcweir 					// when being decomposed:
52*cdf0e10cSrcweir 					//
53*cdf0e10cSrcweir 					// - TextSimplePortionPrimitive2D
54*cdf0e10cSrcweir 					// - PolygonWavePrimitive2D
55*cdf0e10cSrcweir 					//		- PolygonStrokePrimitive2D
56*cdf0e10cSrcweir 					// - PolygonStrokePrimitive2D
57*cdf0e10cSrcweir 					//		- PolyPolygonColorPrimitive2D
58*cdf0e10cSrcweir 					//		- PolyPolygonHairlinePrimitive2D
59*cdf0e10cSrcweir 					//			- PolygonHairlinePrimitive2D
60*cdf0e10cSrcweir 					// - ShadowPrimitive2D
61*cdf0e10cSrcweir 					//		- ModifiedColorPrimitive2D
62*cdf0e10cSrcweir 					//		- TransformPrimitive2D
63*cdf0e10cSrcweir 					// - TextEffectPrimitive2D
64*cdf0e10cSrcweir 					//		- ModifiedColorPrimitive2D
65*cdf0e10cSrcweir 					//		- TransformPrimitive2D
66*cdf0e10cSrcweir 					//		- GroupPrimitive2D
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir 					// encapsulate with flag and use decomposition
69*cdf0e10cSrcweir 					mnInText++;
70*cdf0e10cSrcweir 					process(rCandidate.get2DDecomposition(getViewInformation2D()));
71*cdf0e10cSrcweir 					mnInText--;
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir 					break;
74*cdf0e10cSrcweir 				}
75*cdf0e10cSrcweir 				case PRIMITIVE2D_ID_TEXTSIMPLEPORTIONPRIMITIVE2D :
76*cdf0e10cSrcweir 				{
77*cdf0e10cSrcweir 					// TextSimplePortionPrimitive2D can produce the following primitives
78*cdf0e10cSrcweir 					// when being decomposed:
79*cdf0e10cSrcweir 					//
80*cdf0e10cSrcweir 					// - PolyPolygonColorPrimitive2D
81*cdf0e10cSrcweir 					// - TextEffectPrimitive2D
82*cdf0e10cSrcweir 					//		- ModifiedColorPrimitive2D
83*cdf0e10cSrcweir 					//		- TransformPrimitive2D
84*cdf0e10cSrcweir 					//		- GroupPrimitive2D
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir 					// encapsulate with flag and use decomposition
87*cdf0e10cSrcweir 					mnInText++;
88*cdf0e10cSrcweir 					process(rCandidate.get2DDecomposition(getViewInformation2D()));
89*cdf0e10cSrcweir 					mnInText--;
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir 					break;
92*cdf0e10cSrcweir 				}
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir 				// as can be seen from the TextSimplePortionPrimitive2D and the
95*cdf0e10cSrcweir 				// TextDecoratedPortionPrimitive2D, inside of the mnInText marks
96*cdf0e10cSrcweir 				// the following primitives can occurr containing geometry data
97*cdf0e10cSrcweir 				// from text decomposition:
98*cdf0e10cSrcweir 				//
99*cdf0e10cSrcweir 				// - PolyPolygonColorPrimitive2D
100*cdf0e10cSrcweir 				// - PolygonHairlinePrimitive2D
101*cdf0e10cSrcweir 				// - PolyPolygonHairlinePrimitive2D (for convenience)
102*cdf0e10cSrcweir 				//
103*cdf0e10cSrcweir 				case PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D :
104*cdf0e10cSrcweir 				{
105*cdf0e10cSrcweir 					if(mnInText)
106*cdf0e10cSrcweir 					{
107*cdf0e10cSrcweir 						const primitive2d::PolyPolygonColorPrimitive2D& rPoPoCoCandidate(static_cast< const primitive2d::PolyPolygonColorPrimitive2D& >(rCandidate));
108*cdf0e10cSrcweir 						basegfx::B2DPolyPolygon aPolyPolygon(rPoPoCoCandidate.getB2DPolyPolygon());
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir 						if(aPolyPolygon.count())
111*cdf0e10cSrcweir 						{
112*cdf0e10cSrcweir 							// transform the PolyPolygon
113*cdf0e10cSrcweir 							aPolyPolygon.transform(getViewInformation2D().getObjectToViewTransformation());
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 							// get evtl. corrected color
116*cdf0e10cSrcweir 							const basegfx::BColor aColor(maBColorModifierStack.getModifiedColor(rPoPoCoCandidate.getBColor()));
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 							// add to result vector
119*cdf0e10cSrcweir 							maTarget.push_back(TextAsPolygonDataNode(aPolyPolygon, aColor, true));
120*cdf0e10cSrcweir 						}
121*cdf0e10cSrcweir 					}
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir 					break;
124*cdf0e10cSrcweir 				}
125*cdf0e10cSrcweir 				case PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D :
126*cdf0e10cSrcweir 				{
127*cdf0e10cSrcweir 					if(mnInText)
128*cdf0e10cSrcweir 					{
129*cdf0e10cSrcweir 						const primitive2d::PolygonHairlinePrimitive2D& rPoHaCandidate(static_cast< const primitive2d::PolygonHairlinePrimitive2D& >(rCandidate));
130*cdf0e10cSrcweir 						basegfx::B2DPolygon aPolygon(rPoHaCandidate.getB2DPolygon());
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 						if(aPolygon.count())
133*cdf0e10cSrcweir 						{
134*cdf0e10cSrcweir 							// transform the Polygon
135*cdf0e10cSrcweir 							aPolygon.transform(getViewInformation2D().getObjectToViewTransformation());
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir 							// get evtl. corrected color
138*cdf0e10cSrcweir 							const basegfx::BColor aColor(maBColorModifierStack.getModifiedColor(rPoHaCandidate.getBColor()));
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 							// add to result vector
141*cdf0e10cSrcweir 							maTarget.push_back(TextAsPolygonDataNode(basegfx::B2DPolyPolygon(aPolygon), aColor, false));
142*cdf0e10cSrcweir 						}
143*cdf0e10cSrcweir 					}
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 					break;
146*cdf0e10cSrcweir 				}
147*cdf0e10cSrcweir 				case PRIMITIVE2D_ID_POLYPOLYGONHAIRLINEPRIMITIVE2D :
148*cdf0e10cSrcweir 				{
149*cdf0e10cSrcweir 					if(mnInText)
150*cdf0e10cSrcweir 					{
151*cdf0e10cSrcweir 						const primitive2d::PolyPolygonHairlinePrimitive2D& rPoPoHaCandidate(static_cast< const primitive2d::PolyPolygonHairlinePrimitive2D& >(rCandidate));
152*cdf0e10cSrcweir 						basegfx::B2DPolyPolygon aPolyPolygon(rPoPoHaCandidate.getB2DPolyPolygon());
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 						if(aPolyPolygon.count())
155*cdf0e10cSrcweir 						{
156*cdf0e10cSrcweir 							// transform the Polygon
157*cdf0e10cSrcweir 							aPolyPolygon.transform(getViewInformation2D().getObjectToViewTransformation());
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 							// get evtl. corrected color
160*cdf0e10cSrcweir 							const basegfx::BColor aColor(maBColorModifierStack.getModifiedColor(rPoPoHaCandidate.getBColor()));
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 							// add to result vector
163*cdf0e10cSrcweir 							maTarget.push_back(TextAsPolygonDataNode(aPolyPolygon, aColor, false));
164*cdf0e10cSrcweir 						}
165*cdf0e10cSrcweir 					}
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir 					break;
168*cdf0e10cSrcweir 				}
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir 				// usage of color modification stack is needed
171*cdf0e10cSrcweir 				case PRIMITIVE2D_ID_MODIFIEDCOLORPRIMITIVE2D :
172*cdf0e10cSrcweir 				{
173*cdf0e10cSrcweir 					const primitive2d::ModifiedColorPrimitive2D& rModifiedColorCandidate(static_cast< const primitive2d::ModifiedColorPrimitive2D& >(rCandidate));
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 					if(rModifiedColorCandidate.getChildren().hasElements())
176*cdf0e10cSrcweir 					{
177*cdf0e10cSrcweir 						maBColorModifierStack.push(rModifiedColorCandidate.getColorModifier());
178*cdf0e10cSrcweir 						process(rModifiedColorCandidate.getChildren());
179*cdf0e10cSrcweir 						maBColorModifierStack.pop();
180*cdf0e10cSrcweir 					}
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 					break;
183*cdf0e10cSrcweir 				}
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 				// usage of transformation stack is needed
186*cdf0e10cSrcweir 				case PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D :
187*cdf0e10cSrcweir 				{
188*cdf0e10cSrcweir 					// remember current transformation and ViewInformation
189*cdf0e10cSrcweir 					const primitive2d::TransformPrimitive2D& rTransformCandidate(static_cast< const primitive2d::TransformPrimitive2D& >(rCandidate));
190*cdf0e10cSrcweir 					const geometry::ViewInformation2D aLastViewInformation2D(getViewInformation2D());
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir 					// create new transformations for CurrentTransformation and for local ViewInformation2D
193*cdf0e10cSrcweir 					const geometry::ViewInformation2D aViewInformation2D(
194*cdf0e10cSrcweir 						getViewInformation2D().getObjectTransformation() * rTransformCandidate.getTransformation(),
195*cdf0e10cSrcweir 						getViewInformation2D().getViewTransformation(),
196*cdf0e10cSrcweir 						getViewInformation2D().getViewport(),
197*cdf0e10cSrcweir 						getViewInformation2D().getVisualizedPage(),
198*cdf0e10cSrcweir 						getViewInformation2D().getViewTime(),
199*cdf0e10cSrcweir 						getViewInformation2D().getExtendedInformationSequence());
200*cdf0e10cSrcweir 					updateViewInformation(aViewInformation2D);
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir 					// proccess content
203*cdf0e10cSrcweir 					process(rTransformCandidate.getChildren());
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir 					// restore transformations
206*cdf0e10cSrcweir 					updateViewInformation(aLastViewInformation2D);
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir 					break;
209*cdf0e10cSrcweir 				}
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir 				// ignorable primitives
212*cdf0e10cSrcweir 				case PRIMITIVE2D_ID_SCENEPRIMITIVE2D :
213*cdf0e10cSrcweir                 case PRIMITIVE2D_ID_WRONGSPELLPRIMITIVE2D :
214*cdf0e10cSrcweir 				case PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D :
215*cdf0e10cSrcweir 				case PRIMITIVE2D_ID_POINTARRAYPRIMITIVE2D :
216*cdf0e10cSrcweir 				case PRIMITIVE2D_ID_BITMAPPRIMITIVE2D :
217*cdf0e10cSrcweir 				case PRIMITIVE2D_ID_RENDERGRAPHICPRIMITIVE2D :
218*cdf0e10cSrcweir 				case PRIMITIVE2D_ID_METAFILEPRIMITIVE2D :
219*cdf0e10cSrcweir 				case PRIMITIVE2D_ID_MASKPRIMITIVE2D :
220*cdf0e10cSrcweir                 {
221*cdf0e10cSrcweir 					break;
222*cdf0e10cSrcweir 				}
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir 				default :
225*cdf0e10cSrcweir 				{
226*cdf0e10cSrcweir 					// process recursively
227*cdf0e10cSrcweir 					process(rCandidate.get2DDecomposition(getViewInformation2D()));
228*cdf0e10cSrcweir 					break;
229*cdf0e10cSrcweir 				}
230*cdf0e10cSrcweir 			}
231*cdf0e10cSrcweir 		}
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir 		TextAsPolygonExtractor2D::TextAsPolygonExtractor2D(const geometry::ViewInformation2D& rViewInformation)
234*cdf0e10cSrcweir 		:	BaseProcessor2D(rViewInformation),
235*cdf0e10cSrcweir 			maTarget(),
236*cdf0e10cSrcweir 			maBColorModifierStack(),
237*cdf0e10cSrcweir 			mnInText(0)
238*cdf0e10cSrcweir 		{
239*cdf0e10cSrcweir 		}
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir 		TextAsPolygonExtractor2D::~TextAsPolygonExtractor2D()
242*cdf0e10cSrcweir 		{
243*cdf0e10cSrcweir 		}
244*cdf0e10cSrcweir 	} // end of namespace processor2d
245*cdf0e10cSrcweir } // end of namespace drawinglayer
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
248*cdf0e10cSrcweir // eof
249