Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : : *
5 : : * The contents of this file are subject to the Mozilla Public License Version
6 : : * 1.1 (the "License"); you may not use this file except in compliance with
7 : : * the License. You may obtain a copy of the License at
8 : : * http://www.mozilla.org/MPL/
9 : : *
10 : : * Software distributed under the License is distributed on an "AS IS" basis,
11 : : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : : * for the specific language governing rights and limitations under the
13 : : * License.
14 : : *
15 : : * The Initial Developer of the Original Code is
16 : : * Fridrich Strba <fridrich.strba@bluewin.ch>
17 : : * Thorsten Behrens <tbehrens@novell.com>
18 : : *
19 : : * Contributor(s):
20 : : *
21 : : * Alternatively, the contents of this file may be used under the terms of
22 : : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
23 : : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
24 : : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
25 : : * instead of those above.
26 : : */
27 : : #ifndef INCLUDED_GFXTYPES_HXX
28 : : #define INCLUDED_GFXTYPES_HXX
29 : :
30 : : #include <basegfx/range/b2drange.hxx>
31 : : #include <basegfx/matrix/b2dhommatrix.hxx>
32 : : #include <basegfx/polygon/b2dlinegeometry.hxx>
33 : :
34 : : #include <boost/unordered_set.hpp>
35 : : #include <boost/unordered_map.hpp>
36 : : #include <rtl/ustring.hxx>
37 : :
38 : : namespace svgi
39 : : {
40 : :
41 : : struct ARGBColor
42 : : {
43 : 0 : double toDoubleColor( sal_uInt8 val ) const { return val/255.0; }
44 : :
45 : 0 : ARGBColor() : a(1.0), r(0.0), g(0.0), b(0.0)
46 : 0 : {}
47 : 0 : explicit ARGBColor(double fGrey) : a(1.0), r(fGrey), g(fGrey), b(fGrey)
48 : 0 : {}
49 : : ARGBColor( double r_, double g_, double b_ ) :
50 : : a(1.0), r(r_), g(g_), b(b_)
51 : : {}
52 : : ARGBColor( double a_, double r_, double g_, double b_ ) :
53 : : a(a_), r(r_), g(g_), b(b_)
54 : : {}
55 : 0 : ARGBColor( int r_, int g_, int b_ ) :
56 : : a(1.0),
57 : 0 : r(toDoubleColor(sal::static_int_cast<sal_uInt8>(r_))),
58 : 0 : g(toDoubleColor(sal::static_int_cast<sal_uInt8>(g_))),
59 : 0 : b(toDoubleColor(sal::static_int_cast<sal_uInt8>(b_)))
60 : 0 : {}
61 : : ARGBColor( int a_, int r_, int g_, int b_ ) :
62 : : a(toDoubleColor(sal::static_int_cast<sal_uInt8>(a_))),
63 : : r(toDoubleColor(sal::static_int_cast<sal_uInt8>(r_))),
64 : : g(toDoubleColor(sal::static_int_cast<sal_uInt8>(g_))),
65 : : b(toDoubleColor(sal::static_int_cast<sal_uInt8>(b_)))
66 : : {}
67 : : double a;
68 : : double r;
69 : : double g;
70 : : double b;
71 : : };
72 : 0 : inline bool operator==( const ARGBColor& rLHS, const ARGBColor& rRHS )
73 [ # # ][ # # ]: 0 : { return rLHS.a==rRHS.a && rLHS.r==rRHS.r && rLHS.g==rRHS.g && rLHS.b==rRHS.b; }
[ # # ][ # # ]
74 : 0 : inline bool operator!=( const ARGBColor& rLHS, const ARGBColor& rRHS )
75 : 0 : { return !(rLHS==rRHS); }
76 : :
77 : : struct GradientStop
78 : : {
79 : 0 : GradientStop() : maStopColor(), mnStopPosition(0.0)
80 : 0 : {}
81 : : ARGBColor maStopColor;
82 : : double mnStopPosition;
83 : : };
84 : : inline bool operator==( const GradientStop& rLHS, const GradientStop& rRHS )
85 : : { return rLHS.mnStopPosition==rRHS.mnStopPosition && rLHS.maStopColor==rRHS.maStopColor; }
86 : :
87 [ # # ][ # # ]: 0 : struct Gradient
88 : : {
89 : : enum GradientType { LINEAR, RADIAL};
90 : : std::vector<sal_Size> maStops;
91 : : basegfx::B2DHomMatrix maTransform;
92 : : GradientType meType;
93 : : union
94 : : {
95 : : double test;
96 : : struct
97 : : {
98 : : double mfX1;
99 : : double mfX2;
100 : : double mfY1;
101 : : double mfY2;
102 : : } linear;
103 : : struct
104 : : {
105 : : double mfCX;
106 : : double mfCY;
107 : : double mfFX;
108 : : double mfFY;
109 : : double mfR;
110 : : } radial;
111 : : } maCoords;
112 : : sal_Int32 mnId;
113 : : bool mbBoundingBoxUnits;
114 : : bool mbLinearBoundingBoxUnits;
115 : :
116 : : // explicit Gradient(GradientType eType) : maStops(), maTransform(), meType(eType), maCoords.mfCX(0.0), maCoords.mfCY(0.0), maCoords.mfFX(0.0), maCoords.mfFY(0.0), maCoords.mfR(0.0), mnId(0), mbBoundingBoxUnits(false)
117 [ # # ]: 0 : explicit Gradient(GradientType eType) : maStops(), maTransform(), meType(eType), mnId(0), mbBoundingBoxUnits(false)
118 : : {
119 : 0 : maCoords.radial.mfCX = 0.0;
120 : 0 : maCoords.radial.mfCY = 0.0;
121 : 0 : maCoords.radial.mfFX = 0.0;
122 : 0 : maCoords.radial.mfFY = 0.0;
123 : 0 : maCoords.radial.mfR = 0.0;
124 : 0 : }
125 : : };
126 : :
127 : 0 : inline bool operator==( const Gradient& rLHS, const Gradient& rRHS )
128 : : {
129 [ # # ]: 0 : if( rLHS.meType != rRHS.meType )
130 : 0 : return false;
131 [ # # ]: 0 : if( rLHS.meType == Gradient::LINEAR )
132 : 0 : return rLHS.mbBoundingBoxUnits==rRHS.mbBoundingBoxUnits && rLHS.maStops==rRHS.maStops &&
133 : : rLHS.maCoords.linear.mfX1 == rRHS.maCoords.linear.mfX1 && rLHS.maCoords.linear.mfX2 == rRHS.maCoords.linear.mfX2 &&
134 [ # # # # ]: 0 : rLHS.maCoords.linear.mfY1 == rRHS.maCoords.linear.mfY1 && rLHS.maCoords.linear.mfY2 == rRHS.maCoords.linear.mfY2;
[ # # ][ # # ]
[ # # ][ # # ]
135 : : else
136 : 0 : return rLHS.mbBoundingBoxUnits==rRHS.mbBoundingBoxUnits && rLHS.maStops==rRHS.maStops &&
137 : : rLHS.maCoords.radial.mfCX == rRHS.maCoords.radial.mfCX && rLHS.maCoords.radial.mfCY == rRHS.maCoords.radial.mfCY &&
138 : : rLHS.maCoords.radial.mfFX == rRHS.maCoords.radial.mfFX && rLHS.maCoords.radial.mfFY == rRHS.maCoords.radial.mfFY &&
139 [ # # # # ]: 0 : rLHS.maCoords.radial.mfR == rRHS.maCoords.radial.mfR;
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
140 : : }
141 : :
142 : : enum PaintType
143 : : {
144 : : NONE,
145 : : SOLID,
146 : : GRADIENT,
147 : : DASH
148 : : };
149 : :
150 : : enum FillRule
151 : : {
152 : : NON_ZERO,
153 : : EVEN_ODD
154 : : };
155 : :
156 : : enum TextAlign
157 : : {
158 : : BEFORE,
159 : : CENTER,
160 : : AFTER
161 : : };
162 : :
163 : : enum CapStyle
164 : : {
165 : : BUTT,
166 : : RECT,
167 : : ROUND
168 : : };
169 : :
170 [ # # ][ # # ]: 0 : struct State
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
171 : : {
172 : 0 : State() :
173 : : maCTM(),
174 : : maTransform(),
175 : : maViewport(),
176 : : maViewBox(),
177 : : mbIsText(false),
178 : : maFontFamily(), // app-default
179 : : mnFontSize(12),
180 : : maFontStyle("normal"),
181 : : maFontVariant("normal"),
182 : : mnFontWeight(400.0),
183 : : meTextAnchor(BEFORE),
184 : : meTextDisplayAlign(BEFORE),
185 : : mnTextLineIncrement(0.0),
186 : : maCurrentColor(1.0),
187 : : mbVisibility(true),
188 : : meFillType(SOLID),
189 : : mnFillOpacity(1.0),
190 : : mnOpacity(1.0),
191 : : meStrokeType(NONE),
192 : : mnStrokeOpacity(1.0),
193 : : meViewportFillType(NONE),
194 : : mnViewportFillOpacity(1.0),
195 : : maFillColor(0.0),
196 : : maFillGradient(Gradient::LINEAR),
197 : : meFillRule(NON_ZERO),
198 : : maStrokeColor(0.0),
199 : : maStrokeGradient(Gradient::LINEAR),
200 : : maDashArray(),
201 : : mnDashOffset(0.0),
202 : : meLineCap(BUTT),
203 : : meLineJoin(basegfx::B2DLINEJOIN_MITER),
204 : : mnMiterLimit(4.0),
205 : : mnStrokeWidth(1.0),
206 : : maViewportFillColor(1.0),
207 : : maViewportFillGradient(Gradient::LINEAR),
208 [ # # ][ # # ]: 0 : mnStyleId(0)
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
209 : 0 : {}
210 : :
211 : : basegfx::B2DHomMatrix maCTM;
212 : : basegfx::B2DHomMatrix maTransform;
213 : : basegfx::B2DRange maViewport;
214 : : basegfx::B2DRange maViewBox;
215 : :
216 : : bool mbIsText;
217 : : rtl::OUString maFontFamily;
218 : : /** Absolute: xx-small=6.94 | x-small=8.33 | small=10 | medium=12 | large=14.4 | x-large=17.28 | xx-large=20.736
219 : :
220 : : Relative(to parent): larger (enlarge by 1.2)
221 : : smaller (shrink by 1.2)
222 : :
223 : : */
224 : : double mnFontSize;
225 : : rtl::OUString maFontStyle;
226 : : rtl::OUString maFontVariant;
227 : : double mnFontWeight;
228 : :
229 : : TextAlign meTextAnchor; // text-anchor
230 : : TextAlign meTextDisplayAlign; // display-align
231 : : double mnTextLineIncrement; // 0.0 means auto
232 : :
233 : : ARGBColor maCurrentColor;
234 : : bool mbVisibility;
235 : :
236 : : PaintType meFillType;
237 : : double mnFillOpacity;
238 : : double mnOpacity;
239 : : PaintType meStrokeType;
240 : : double mnStrokeOpacity;
241 : : PaintType meViewportFillType;
242 : : double mnViewportFillOpacity;
243 : :
244 : : ARGBColor maFillColor;
245 : : Gradient maFillGradient;
246 : : FillRule meFillRule;
247 : :
248 : : ARGBColor maStrokeColor;
249 : : Gradient maStrokeGradient;
250 : : std::vector<double> maDashArray;
251 : : double mnDashOffset;
252 : : CapStyle meLineCap;
253 : : basegfx::B2DLineJoin meLineJoin;
254 : : double mnMiterLimit;
255 : : double mnStrokeWidth;
256 : :
257 : : ARGBColor maViewportFillColor;
258 : : Gradient maViewportFillGradient;
259 : :
260 : : sal_Int32 mnStyleId;
261 : : };
262 : :
263 : 0 : inline bool operator==(const State& rLHS, const State& rRHS )
264 : : {
265 : 0 : return rLHS.maCTM==rRHS.maCTM &&
266 : 0 : rLHS.maTransform==rRHS.maTransform &&
267 : 0 : rLHS.maViewport==rRHS.maViewport &&
268 : 0 : rLHS.maViewBox==rRHS.maViewBox &&
269 : : rLHS.mbIsText==rRHS.mbIsText &&
270 : 0 : rLHS.maFontFamily==rRHS.maFontFamily &&
271 : : rLHS.mnFontSize==rRHS.mnFontSize &&
272 : 0 : rLHS.maFontStyle==rRHS.maFontStyle &&
273 : 0 : rLHS.maFontVariant==rRHS.maFontVariant &&
274 : : rLHS.mnFontWeight==rRHS.mnFontWeight &&
275 : : rLHS.meTextAnchor==rRHS.meTextAnchor &&
276 : : rLHS.meTextDisplayAlign==rRHS.meTextDisplayAlign &&
277 : : rLHS.mnTextLineIncrement==rRHS.mnTextLineIncrement &&
278 : 0 : rLHS.maCurrentColor==rRHS.maCurrentColor &&
279 : : rLHS.mbVisibility==rRHS.mbVisibility &&
280 : : rLHS.meFillType==rRHS.meFillType &&
281 : : rLHS.mnFillOpacity==rRHS.mnFillOpacity &&
282 : : rLHS.mnOpacity==rRHS.mnOpacity &&
283 : : rLHS.meStrokeType==rRHS.meStrokeType &&
284 : : rLHS.mnStrokeOpacity==rRHS.mnStrokeOpacity &&
285 : : rLHS.meViewportFillType==rRHS.meViewportFillType &&
286 : : rLHS.mnViewportFillOpacity==rRHS.mnViewportFillOpacity &&
287 : 0 : rLHS.maFillColor==rRHS.maFillColor &&
288 : 0 : rLHS.maFillGradient==rRHS.maFillGradient &&
289 : : rLHS.meFillRule==rRHS.meFillRule &&
290 : 0 : rLHS.maStrokeColor==rRHS.maStrokeColor &&
291 : 0 : rLHS.maStrokeGradient==rRHS.maStrokeGradient &&
292 : 0 : rLHS.maDashArray==rRHS.maDashArray &&
293 : : rLHS.mnDashOffset==rRHS.mnDashOffset &&
294 : : rLHS.meLineCap==rRHS.meLineCap &&
295 : : rLHS.meLineJoin==rRHS.meLineJoin &&
296 : : rLHS.mnMiterLimit==rRHS.mnMiterLimit &&
297 : : rLHS.mnStrokeWidth==rRHS.mnStrokeWidth &&
298 : 0 : rLHS.maViewportFillColor==rRHS.maViewportFillColor &&
299 [ # # # # ]: 0 : rLHS.maViewportFillGradient==rRHS.maViewportFillGradient;
[ # # # #
# # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # #
# # # # ]
[ # # # #
# # # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
[ # # ][ # #
# # # # #
# ]
300 : : }
301 : :
302 : : struct StateHash
303 : : {
304 : 0 : size_t operator()(const State& rState ) const
305 : : {
306 : 0 : return size_t(rState.maCTM.get( 0, 0 ))
307 : 0 : ^ size_t(rState.maCTM.get( 1, 0 ))
308 : 0 : ^ size_t(rState.maCTM.get( 0, 1 ))
309 : 0 : ^ size_t(rState.maCTM.get( 1, 1 ))
310 : 0 : ^ size_t(rState.maCTM.get( 0, 2 ))
311 : 0 : ^ size_t(rState.maCTM.get( 1, 2 ))
312 : 0 : ^ size_t(rState.maViewport.getWidth())
313 : 0 : ^ size_t(rState.maViewport.getHeight())
314 : 0 : ^ size_t(rState.maViewBox.getWidth())
315 : 0 : ^ size_t(rState.maViewBox.getHeight())
316 : : ^ size_t(rState.mbIsText)
317 : 0 : ^ size_t(rState.maFontFamily.hashCode())
318 : : ^ size_t(rState.mnFontSize)
319 : 0 : ^ size_t(rState.maFontStyle.hashCode())
320 : 0 : ^ size_t(rState.maFontVariant.hashCode())
321 : : ^ size_t(rState.mnFontWeight)
322 : : ^ size_t(rState.meTextAnchor)
323 : : ^ size_t(rState.meTextDisplayAlign)
324 : : ^ size_t(rState.mnTextLineIncrement)
325 : : ^ size_t(rState.mbVisibility)
326 : : ^ size_t(rState.meFillType)
327 : : ^ size_t(rState.mnFillOpacity)
328 : : ^ size_t(rState.mnOpacity)
329 : : ^ size_t(rState.meStrokeType)
330 : : ^ size_t(rState.mnStrokeOpacity)
331 : : ^ size_t(rState.meViewportFillType)
332 : : ^ size_t(rState.mnViewportFillOpacity)
333 : : ^ size_t(rState.maFillColor.a)
334 : : ^ size_t(rState.maFillColor.r)
335 : : ^ size_t(rState.maFillColor.g)
336 : : ^ size_t(rState.maFillColor.b)
337 : 0 : ^ size_t(rState.maFillGradient.maStops.size())
338 : : ^ size_t(rState.meFillRule)
339 : : ^ size_t(rState.maStrokeColor.a)
340 : : ^ size_t(rState.maStrokeColor.r)
341 : : ^ size_t(rState.maStrokeColor.g)
342 : : ^ size_t(rState.maStrokeColor.b)
343 : 0 : ^ size_t(rState.maStrokeGradient.maStops.size())
344 : 0 : ^ size_t(rState.maDashArray.size())
345 : : ^ size_t(rState.mnDashOffset)
346 : : ^ size_t(rState.meLineCap)
347 : : ^ size_t(rState.meLineJoin)
348 : : ^ size_t(rState.mnMiterLimit)
349 : : ^ size_t(rState.mnStrokeWidth)
350 : : ^ size_t(rState.maViewportFillColor.a)
351 : : ^ size_t(rState.maViewportFillColor.r)
352 : : ^ size_t(rState.maViewportFillColor.g)
353 : : ^ size_t(rState.maViewportFillColor.b)
354 : 0 : ^ size_t(rState.maViewportFillGradient.maStops.size());
355 : : }
356 : : };
357 : :
358 : : typedef boost::unordered_set<State, StateHash> StatePool;
359 : : typedef boost::unordered_map<sal_Int32, State> StateMap;
360 : :
361 : : } // namespace svgi
362 : :
363 : : #endif
364 : :
365 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|