1*464702f4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*464702f4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*464702f4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*464702f4SAndrew Rist  * distributed with this work for additional information
6*464702f4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*464702f4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*464702f4SAndrew Rist  * "License"); you may not use this file except in compliance
9*464702f4SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*464702f4SAndrew Rist  *
11*464702f4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*464702f4SAndrew Rist  *
13*464702f4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*464702f4SAndrew Rist  * software distributed under the License is distributed on an
15*464702f4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*464702f4SAndrew Rist  * KIND, either express or implied.  See the License for the
17*464702f4SAndrew Rist  * specific language governing permissions and limitations
18*464702f4SAndrew Rist  * under the License.
19*464702f4SAndrew Rist  *
20*464702f4SAndrew Rist  *************************************************************/
21*464702f4SAndrew Rist 
22*464702f4SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <drawinglayer/processor2d/textaspolygonextractor2d.hxx>
28cdf0e10cSrcweir #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
29cdf0e10cSrcweir #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
30cdf0e10cSrcweir #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
31cdf0e10cSrcweir #include <drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx>
32cdf0e10cSrcweir #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
35cdf0e10cSrcweir 
36cdf0e10cSrcweir namespace drawinglayer
37cdf0e10cSrcweir {
38cdf0e10cSrcweir 	namespace processor2d
39cdf0e10cSrcweir 	{
processBasePrimitive2D(const primitive2d::BasePrimitive2D & rCandidate)40cdf0e10cSrcweir 		void TextAsPolygonExtractor2D::processBasePrimitive2D(const primitive2d::BasePrimitive2D& rCandidate)
41cdf0e10cSrcweir 		{
42cdf0e10cSrcweir 			switch(rCandidate.getPrimitive2DID())
43cdf0e10cSrcweir 			{
44cdf0e10cSrcweir 				case PRIMITIVE2D_ID_TEXTDECORATEDPORTIONPRIMITIVE2D :
45cdf0e10cSrcweir 				{
46cdf0e10cSrcweir 					// TextDecoratedPortionPrimitive2D can produce the following primitives
47cdf0e10cSrcweir 					// when being decomposed:
48cdf0e10cSrcweir 					//
49cdf0e10cSrcweir 					// - TextSimplePortionPrimitive2D
50cdf0e10cSrcweir 					// - PolygonWavePrimitive2D
51cdf0e10cSrcweir 					//		- PolygonStrokePrimitive2D
52cdf0e10cSrcweir 					// - PolygonStrokePrimitive2D
53cdf0e10cSrcweir 					//		- PolyPolygonColorPrimitive2D
54cdf0e10cSrcweir 					//		- PolyPolygonHairlinePrimitive2D
55cdf0e10cSrcweir 					//			- PolygonHairlinePrimitive2D
56cdf0e10cSrcweir 					// - ShadowPrimitive2D
57cdf0e10cSrcweir 					//		- ModifiedColorPrimitive2D
58cdf0e10cSrcweir 					//		- TransformPrimitive2D
59cdf0e10cSrcweir 					// - TextEffectPrimitive2D
60cdf0e10cSrcweir 					//		- ModifiedColorPrimitive2D
61cdf0e10cSrcweir 					//		- TransformPrimitive2D
62cdf0e10cSrcweir 					//		- GroupPrimitive2D
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 					// encapsulate with flag and use decomposition
65cdf0e10cSrcweir 					mnInText++;
66cdf0e10cSrcweir 					process(rCandidate.get2DDecomposition(getViewInformation2D()));
67cdf0e10cSrcweir 					mnInText--;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 					break;
70cdf0e10cSrcweir 				}
71cdf0e10cSrcweir 				case PRIMITIVE2D_ID_TEXTSIMPLEPORTIONPRIMITIVE2D :
72cdf0e10cSrcweir 				{
73cdf0e10cSrcweir 					// TextSimplePortionPrimitive2D can produce the following primitives
74cdf0e10cSrcweir 					// when being decomposed:
75cdf0e10cSrcweir 					//
76cdf0e10cSrcweir 					// - PolyPolygonColorPrimitive2D
77cdf0e10cSrcweir 					// - TextEffectPrimitive2D
78cdf0e10cSrcweir 					//		- ModifiedColorPrimitive2D
79cdf0e10cSrcweir 					//		- TransformPrimitive2D
80cdf0e10cSrcweir 					//		- GroupPrimitive2D
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 					// encapsulate with flag and use decomposition
83cdf0e10cSrcweir 					mnInText++;
84cdf0e10cSrcweir 					process(rCandidate.get2DDecomposition(getViewInformation2D()));
85cdf0e10cSrcweir 					mnInText--;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 					break;
88cdf0e10cSrcweir 				}
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 				// as can be seen from the TextSimplePortionPrimitive2D and the
91cdf0e10cSrcweir 				// TextDecoratedPortionPrimitive2D, inside of the mnInText marks
92cdf0e10cSrcweir 				// the following primitives can occurr containing geometry data
93cdf0e10cSrcweir 				// from text decomposition:
94cdf0e10cSrcweir 				//
95cdf0e10cSrcweir 				// - PolyPolygonColorPrimitive2D
96cdf0e10cSrcweir 				// - PolygonHairlinePrimitive2D
97cdf0e10cSrcweir 				// - PolyPolygonHairlinePrimitive2D (for convenience)
98cdf0e10cSrcweir 				//
99cdf0e10cSrcweir 				case PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D :
100cdf0e10cSrcweir 				{
101cdf0e10cSrcweir 					if(mnInText)
102cdf0e10cSrcweir 					{
103cdf0e10cSrcweir 						const primitive2d::PolyPolygonColorPrimitive2D& rPoPoCoCandidate(static_cast< const primitive2d::PolyPolygonColorPrimitive2D& >(rCandidate));
104cdf0e10cSrcweir 						basegfx::B2DPolyPolygon aPolyPolygon(rPoPoCoCandidate.getB2DPolyPolygon());
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 						if(aPolyPolygon.count())
107cdf0e10cSrcweir 						{
108cdf0e10cSrcweir 							// transform the PolyPolygon
109cdf0e10cSrcweir 							aPolyPolygon.transform(getViewInformation2D().getObjectToViewTransformation());
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 							// get evtl. corrected color
112cdf0e10cSrcweir 							const basegfx::BColor aColor(maBColorModifierStack.getModifiedColor(rPoPoCoCandidate.getBColor()));
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 							// add to result vector
115cdf0e10cSrcweir 							maTarget.push_back(TextAsPolygonDataNode(aPolyPolygon, aColor, true));
116cdf0e10cSrcweir 						}
117cdf0e10cSrcweir 					}
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 					break;
120cdf0e10cSrcweir 				}
121cdf0e10cSrcweir 				case PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D :
122cdf0e10cSrcweir 				{
123cdf0e10cSrcweir 					if(mnInText)
124cdf0e10cSrcweir 					{
125cdf0e10cSrcweir 						const primitive2d::PolygonHairlinePrimitive2D& rPoHaCandidate(static_cast< const primitive2d::PolygonHairlinePrimitive2D& >(rCandidate));
126cdf0e10cSrcweir 						basegfx::B2DPolygon aPolygon(rPoHaCandidate.getB2DPolygon());
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 						if(aPolygon.count())
129cdf0e10cSrcweir 						{
130cdf0e10cSrcweir 							// transform the Polygon
131cdf0e10cSrcweir 							aPolygon.transform(getViewInformation2D().getObjectToViewTransformation());
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 							// get evtl. corrected color
134cdf0e10cSrcweir 							const basegfx::BColor aColor(maBColorModifierStack.getModifiedColor(rPoHaCandidate.getBColor()));
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 							// add to result vector
137cdf0e10cSrcweir 							maTarget.push_back(TextAsPolygonDataNode(basegfx::B2DPolyPolygon(aPolygon), aColor, false));
138cdf0e10cSrcweir 						}
139cdf0e10cSrcweir 					}
140cdf0e10cSrcweir 
141cdf0e10cSrcweir 					break;
142cdf0e10cSrcweir 				}
143cdf0e10cSrcweir 				case PRIMITIVE2D_ID_POLYPOLYGONHAIRLINEPRIMITIVE2D :
144cdf0e10cSrcweir 				{
145cdf0e10cSrcweir 					if(mnInText)
146cdf0e10cSrcweir 					{
147cdf0e10cSrcweir 						const primitive2d::PolyPolygonHairlinePrimitive2D& rPoPoHaCandidate(static_cast< const primitive2d::PolyPolygonHairlinePrimitive2D& >(rCandidate));
148cdf0e10cSrcweir 						basegfx::B2DPolyPolygon aPolyPolygon(rPoPoHaCandidate.getB2DPolyPolygon());
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 						if(aPolyPolygon.count())
151cdf0e10cSrcweir 						{
152cdf0e10cSrcweir 							// transform the Polygon
153cdf0e10cSrcweir 							aPolyPolygon.transform(getViewInformation2D().getObjectToViewTransformation());
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 							// get evtl. corrected color
156cdf0e10cSrcweir 							const basegfx::BColor aColor(maBColorModifierStack.getModifiedColor(rPoPoHaCandidate.getBColor()));
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 							// add to result vector
159cdf0e10cSrcweir 							maTarget.push_back(TextAsPolygonDataNode(aPolyPolygon, aColor, false));
160cdf0e10cSrcweir 						}
161cdf0e10cSrcweir 					}
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 					break;
164cdf0e10cSrcweir 				}
165cdf0e10cSrcweir 
166cdf0e10cSrcweir 				// usage of color modification stack is needed
167cdf0e10cSrcweir 				case PRIMITIVE2D_ID_MODIFIEDCOLORPRIMITIVE2D :
168cdf0e10cSrcweir 				{
169cdf0e10cSrcweir 					const primitive2d::ModifiedColorPrimitive2D& rModifiedColorCandidate(static_cast< const primitive2d::ModifiedColorPrimitive2D& >(rCandidate));
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 					if(rModifiedColorCandidate.getChildren().hasElements())
172cdf0e10cSrcweir 					{
173cdf0e10cSrcweir 						maBColorModifierStack.push(rModifiedColorCandidate.getColorModifier());
174cdf0e10cSrcweir 						process(rModifiedColorCandidate.getChildren());
175cdf0e10cSrcweir 						maBColorModifierStack.pop();
176cdf0e10cSrcweir 					}
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 					break;
179cdf0e10cSrcweir 				}
180cdf0e10cSrcweir 
181cdf0e10cSrcweir 				// usage of transformation stack is needed
182cdf0e10cSrcweir 				case PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D :
183cdf0e10cSrcweir 				{
184cdf0e10cSrcweir 					// remember current transformation and ViewInformation
185cdf0e10cSrcweir 					const primitive2d::TransformPrimitive2D& rTransformCandidate(static_cast< const primitive2d::TransformPrimitive2D& >(rCandidate));
186cdf0e10cSrcweir 					const geometry::ViewInformation2D aLastViewInformation2D(getViewInformation2D());
187cdf0e10cSrcweir 
188cdf0e10cSrcweir 					// create new transformations for CurrentTransformation and for local ViewInformation2D
189cdf0e10cSrcweir 					const geometry::ViewInformation2D aViewInformation2D(
190cdf0e10cSrcweir 						getViewInformation2D().getObjectTransformation() * rTransformCandidate.getTransformation(),
191cdf0e10cSrcweir 						getViewInformation2D().getViewTransformation(),
192cdf0e10cSrcweir 						getViewInformation2D().getViewport(),
193cdf0e10cSrcweir 						getViewInformation2D().getVisualizedPage(),
194cdf0e10cSrcweir 						getViewInformation2D().getViewTime(),
195cdf0e10cSrcweir 						getViewInformation2D().getExtendedInformationSequence());
196cdf0e10cSrcweir 					updateViewInformation(aViewInformation2D);
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 					// proccess content
199cdf0e10cSrcweir 					process(rTransformCandidate.getChildren());
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 					// restore transformations
202cdf0e10cSrcweir 					updateViewInformation(aLastViewInformation2D);
203cdf0e10cSrcweir 
204cdf0e10cSrcweir 					break;
205cdf0e10cSrcweir 				}
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 				// ignorable primitives
208cdf0e10cSrcweir 				case PRIMITIVE2D_ID_SCENEPRIMITIVE2D :
209cdf0e10cSrcweir                 case PRIMITIVE2D_ID_WRONGSPELLPRIMITIVE2D :
210cdf0e10cSrcweir 				case PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D :
211cdf0e10cSrcweir 				case PRIMITIVE2D_ID_POINTARRAYPRIMITIVE2D :
212cdf0e10cSrcweir 				case PRIMITIVE2D_ID_BITMAPPRIMITIVE2D :
213cdf0e10cSrcweir 				case PRIMITIVE2D_ID_METAFILEPRIMITIVE2D :
214cdf0e10cSrcweir 				case PRIMITIVE2D_ID_MASKPRIMITIVE2D :
215cdf0e10cSrcweir                 {
216cdf0e10cSrcweir 					break;
217cdf0e10cSrcweir 				}
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 				default :
220cdf0e10cSrcweir 				{
221cdf0e10cSrcweir 					// process recursively
222cdf0e10cSrcweir 					process(rCandidate.get2DDecomposition(getViewInformation2D()));
223cdf0e10cSrcweir 					break;
224cdf0e10cSrcweir 				}
225cdf0e10cSrcweir 			}
226cdf0e10cSrcweir 		}
227cdf0e10cSrcweir 
TextAsPolygonExtractor2D(const geometry::ViewInformation2D & rViewInformation)228cdf0e10cSrcweir 		TextAsPolygonExtractor2D::TextAsPolygonExtractor2D(const geometry::ViewInformation2D& rViewInformation)
229cdf0e10cSrcweir 		:	BaseProcessor2D(rViewInformation),
230cdf0e10cSrcweir 			maTarget(),
231cdf0e10cSrcweir 			maBColorModifierStack(),
232cdf0e10cSrcweir 			mnInText(0)
233cdf0e10cSrcweir 		{
234cdf0e10cSrcweir 		}
235cdf0e10cSrcweir 
~TextAsPolygonExtractor2D()236cdf0e10cSrcweir 		TextAsPolygonExtractor2D::~TextAsPolygonExtractor2D()
237cdf0e10cSrcweir 		{
238cdf0e10cSrcweir 		}
239cdf0e10cSrcweir 	} // end of namespace processor2d
240cdf0e10cSrcweir } // end of namespace drawinglayer
241cdf0e10cSrcweir 
242cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
243cdf0e10cSrcweir // eof
244