/src/libreoffice/drawinglayer/source/processor2d/textaspolygonextractor2d.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | #include <drawinglayer/processor2d/textaspolygonextractor2d.hxx> |
21 | | #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> |
22 | | #include <drawinglayer/primitive2d/PolygonHairlinePrimitive2D.hxx> |
23 | | #include <drawinglayer/primitive2d/PolyPolygonHairlinePrimitive2D.hxx> |
24 | | #include <drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx> |
25 | | #include <drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx> |
26 | | #include <drawinglayer/primitive2d/transformprimitive2d.hxx> |
27 | | |
28 | | |
29 | | namespace drawinglayer::processor2d |
30 | | { |
31 | | void TextAsPolygonExtractor2D::processTextPrimitive2D(const primitive2d::BasePrimitive2D& rCandidate) |
32 | 0 | { |
33 | | // PRIMITIVE2D_ID_TEXTDECORATEDPORTIONPRIMITIVE2D |
34 | | // TextDecoratedPortionPrimitive2D can produce the following primitives |
35 | | // when being decomposed: |
36 | | // |
37 | | // - TextSimplePortionPrimitive2D |
38 | | // - PolygonWavePrimitive2D |
39 | | // - PolygonStrokePrimitive2D |
40 | | // - PolygonStrokePrimitive2D |
41 | | // - PolyPolygonColorPrimitive2D |
42 | | // - PolyPolygonHairlinePrimitive2D |
43 | | // - PolygonHairlinePrimitive2D |
44 | | // - ShadowPrimitive2D |
45 | | // - ModifiedColorPrimitive2D |
46 | | // - TransformPrimitive2D |
47 | | // - TextEffectPrimitive2D |
48 | | // - ModifiedColorPrimitive2D |
49 | | // - TransformPrimitive2D |
50 | | // - GroupPrimitive2D |
51 | | |
52 | | // PRIMITIVE2D_ID_TEXTSIMPLEPORTIONPRIMITIVE2D |
53 | | // TextSimplePortionPrimitive2D can produce the following primitives |
54 | | // when being decomposed: |
55 | | // |
56 | | // - PolyPolygonColorPrimitive2D |
57 | | // - TextEffectPrimitive2D |
58 | | // - ModifiedColorPrimitive2D |
59 | | // - TransformPrimitive2D |
60 | | // - GroupPrimitive2D |
61 | | |
62 | | // encapsulate with flag and use decomposition |
63 | 0 | mnInText++; |
64 | 0 | process(rCandidate); |
65 | 0 | mnInText--; |
66 | 0 | } |
67 | | |
68 | | void TextAsPolygonExtractor2D::processBasePrimitive2D(const primitive2d::BasePrimitive2D& rCandidate) |
69 | 0 | { |
70 | 0 | switch (rCandidate.getPrimitive2DID()) |
71 | 0 | { |
72 | | // as can be seen from the TextSimplePortionPrimitive2D and the |
73 | | // TextDecoratedPortionPrimitive2D, inside of the mnInText marks |
74 | | // the following primitives can occur containing geometry data |
75 | | // from text decomposition: |
76 | | // |
77 | | // - PolyPolygonColorPrimitive2D |
78 | | // - PolygonHairlinePrimitive2D |
79 | | // - PolyPolygonHairlinePrimitive2D (for convenience) |
80 | | // |
81 | 0 | case PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D : |
82 | 0 | { |
83 | 0 | if(mnInText) |
84 | 0 | { |
85 | 0 | const primitive2d::PolyPolygonColorPrimitive2D& rPoPoCoCandidate(static_cast< const primitive2d::PolyPolygonColorPrimitive2D& >(rCandidate)); |
86 | 0 | basegfx::B2DPolyPolygon aPolyPolygon(rPoPoCoCandidate.getB2DPolyPolygon()); |
87 | |
|
88 | 0 | if(aPolyPolygon.count()) |
89 | 0 | { |
90 | | // transform the PolyPolygon |
91 | 0 | aPolyPolygon.transform(getViewInformation2D().getObjectToViewTransformation()); |
92 | | |
93 | | // get evtl. corrected color |
94 | 0 | const basegfx::BColor aColor(maBColorModifierStack.getModifiedColor(rPoPoCoCandidate.getBColor())); |
95 | | |
96 | | // add to result vector |
97 | 0 | maTarget.emplace_back(aPolyPolygon, aColor, true); |
98 | 0 | } |
99 | 0 | } |
100 | |
|
101 | 0 | break; |
102 | 0 | } |
103 | 0 | case PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D : |
104 | 0 | { |
105 | 0 | if(mnInText) |
106 | 0 | { |
107 | 0 | const primitive2d::PolygonHairlinePrimitive2D& rPoHaCandidate(static_cast< const primitive2d::PolygonHairlinePrimitive2D& >(rCandidate)); |
108 | 0 | basegfx::B2DPolygon aPolygon(rPoHaCandidate.getB2DPolygon()); |
109 | |
|
110 | 0 | if(aPolygon.count()) |
111 | 0 | { |
112 | | // transform the Polygon |
113 | 0 | aPolygon.transform(getViewInformation2D().getObjectToViewTransformation()); |
114 | | |
115 | | // get evtl. corrected color |
116 | 0 | const basegfx::BColor aColor(maBColorModifierStack.getModifiedColor(rPoHaCandidate.getBColor())); |
117 | | |
118 | | // add to result vector |
119 | 0 | maTarget.emplace_back(basegfx::B2DPolyPolygon(aPolygon), aColor, false); |
120 | 0 | } |
121 | 0 | } |
122 | |
|
123 | 0 | break; |
124 | 0 | } |
125 | 0 | case PRIMITIVE2D_ID_POLYPOLYGONHAIRLINEPRIMITIVE2D : |
126 | 0 | { |
127 | 0 | if(mnInText) |
128 | 0 | { |
129 | 0 | const primitive2d::PolyPolygonHairlinePrimitive2D& rPoPoHaCandidate(static_cast< const primitive2d::PolyPolygonHairlinePrimitive2D& >(rCandidate)); |
130 | 0 | basegfx::B2DPolyPolygon aPolyPolygon(rPoPoHaCandidate.getB2DPolyPolygon()); |
131 | |
|
132 | 0 | if(aPolyPolygon.count()) |
133 | 0 | { |
134 | | // transform the Polygon |
135 | 0 | aPolyPolygon.transform(getViewInformation2D().getObjectToViewTransformation()); |
136 | | |
137 | | // get evtl. corrected color |
138 | 0 | const basegfx::BColor aColor(maBColorModifierStack.getModifiedColor(rPoPoHaCandidate.getBColor())); |
139 | | |
140 | | // add to result vector |
141 | 0 | maTarget.emplace_back(aPolyPolygon, aColor, false); |
142 | 0 | } |
143 | 0 | } |
144 | |
|
145 | 0 | break; |
146 | 0 | } |
147 | | |
148 | | // usage of color modification stack is needed |
149 | 0 | case PRIMITIVE2D_ID_MODIFIEDCOLORPRIMITIVE2D : |
150 | 0 | { |
151 | 0 | const primitive2d::ModifiedColorPrimitive2D& rModifiedColorCandidate(static_cast< const primitive2d::ModifiedColorPrimitive2D& >(rCandidate)); |
152 | |
|
153 | 0 | if(!rModifiedColorCandidate.getChildren().empty()) |
154 | 0 | { |
155 | 0 | maBColorModifierStack.push(rModifiedColorCandidate.getColorModifier()); |
156 | 0 | process(rModifiedColorCandidate.getChildren()); |
157 | 0 | maBColorModifierStack.pop(); |
158 | 0 | } |
159 | |
|
160 | 0 | break; |
161 | 0 | } |
162 | | |
163 | | // usage of transformation stack is needed |
164 | 0 | case PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D : |
165 | 0 | { |
166 | | // remember current transformation and ViewInformation |
167 | 0 | const primitive2d::TransformPrimitive2D& rTransformCandidate(static_cast< const primitive2d::TransformPrimitive2D& >(rCandidate)); |
168 | 0 | const geometry::ViewInformation2D aLastViewInformation2D(getViewInformation2D()); |
169 | | |
170 | | // create new transformations for CurrentTransformation and for local ViewInformation2D |
171 | 0 | geometry::ViewInformation2D aViewInformation2D(getViewInformation2D()); |
172 | 0 | aViewInformation2D.setObjectTransformation(getViewInformation2D().getObjectTransformation() * rTransformCandidate.getTransformation()); |
173 | 0 | setViewInformation2D(aViewInformation2D); |
174 | | |
175 | | // process content |
176 | 0 | process(rTransformCandidate.getChildren()); |
177 | | |
178 | | // restore transformations |
179 | 0 | setViewInformation2D(aLastViewInformation2D); |
180 | |
|
181 | 0 | break; |
182 | 0 | } |
183 | | |
184 | 0 | default: |
185 | 0 | TextExtractor2D::processBasePrimitive2D(rCandidate); |
186 | 0 | break; |
187 | 0 | } |
188 | 0 | } |
189 | | |
190 | | TextAsPolygonExtractor2D::TextAsPolygonExtractor2D(const geometry::ViewInformation2D& rViewInformation) |
191 | 0 | : TextExtractor2D(rViewInformation), |
192 | 0 | maBColorModifierStack(), |
193 | 0 | mnInText(0) |
194 | 0 | { |
195 | 0 | } |
196 | | |
197 | | TextAsPolygonExtractor2D::~TextAsPolygonExtractor2D() |
198 | 0 | { |
199 | 0 | } |
200 | | |
201 | | } // end of namespace |
202 | | |
203 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |