Line data Source code
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 :
10 : #include "parserfragments.hxx"
11 : #include "spirit_supplements.hxx"
12 : #include "gfxtypes.hxx"
13 :
14 : #include <basegfx/tools/canvastools.hxx>
15 : #include <com/sun/star/geometry/AffineMatrix2D.hpp>
16 : #include <osl/diagnose.h>
17 :
18 : #include <string.h>
19 : #include <limits.h>
20 : #include <boost/bind.hpp>
21 : #include <boost/spirit/include/classic.hpp>
22 : #include <boost/spirit/include/classic_while.hpp>
23 : #include <numeric>
24 : #include <algorithm>
25 :
26 : #include "units.hxx"
27 : #include "tokenmap.hxx"
28 : #include "sal/log.hxx"
29 :
30 : using namespace ::com::sun::star;
31 :
32 : namespace svgi
33 : {
34 :
35 0 : inline sal_uInt8 hex2int( char val )
36 : {
37 0 : return val <= '9' ? val-'0' : (val < 'a' ? val+10-'A' : val+10-'a');
38 : }
39 :
40 0 : void setFourBitColor( double& rChannel, char nChar )
41 : {
42 0 : const sal_uInt8 nVal(hex2int(nChar));
43 : OSL_TRACE( "setFourBitCOlor %d color", nVal );
44 0 : rChannel = (nVal*16+nVal)/255.0;
45 0 : }
46 :
47 0 : void setEightBitColor( double& rChannel, const char* pStart, const char* )
48 : {
49 0 : const sal_uInt8 nVal0(hex2int(pStart[0]));
50 0 : const sal_uInt8 nVal1(hex2int(pStart[1]));
51 : OSL_TRACE( "setEightbitCOlor %d, %d color", nVal0, nVal1 );
52 0 : rChannel = (nVal0*16+nVal1)/255.0;
53 0 : }
54 :
55 0 : void setIntColor( double& rChannel, sal_uInt8 nVal )
56 : {
57 : OSL_TRACE( "setIntColor %d color", nVal );
58 0 : rChannel = nVal/255.0;
59 0 : }
60 :
61 0 : void setPercentColor( double& rChannel, double nVal )
62 : {
63 0 : rChannel = nVal/100.0;
64 : SAL_INFO("svg", "setPercentColor " << nVal << " " << rChannel);
65 0 : }
66 :
67 0 : void calcRotation(std::vector<geometry::AffineMatrix2D>& rTransforms,
68 : geometry::AffineMatrix2D& rCurrTransform,
69 : double fRotationAngle)
70 : {
71 0 : ::basegfx::B2DHomMatrix aCurr;
72 0 : aCurr.translate(-rCurrTransform.m02,-rCurrTransform.m12);
73 0 : aCurr.rotate(fRotationAngle*M_PI/180);
74 0 : aCurr.translate(rCurrTransform.m02,rCurrTransform.m12);
75 :
76 : OSL_TRACE("calcRotation - fRotationAngle - %f", fRotationAngle);
77 : rTransforms.push_back(
78 : basegfx::unotools::affineMatrixFromHomMatrix(
79 : rCurrTransform,
80 0 : aCurr));
81 0 : }
82 :
83 0 : void calcSkewX(std::vector<geometry::AffineMatrix2D>& rTransforms,
84 : double fSkewAngle)
85 : {
86 0 : geometry::AffineMatrix2D aMat(1.0,tan(fSkewAngle*M_PI/180),0.0,
87 0 : 0.0,1.0,0.0);
88 0 : rTransforms.push_back(aMat);
89 0 : }
90 :
91 0 : void calcSkewY(std::vector<geometry::AffineMatrix2D>& rTransforms,
92 : double fSkewAngle)
93 : {
94 : geometry::AffineMatrix2D aMat(1.0,0.0,0.0,
95 0 : tan(fSkewAngle*M_PI/180),1.0,0.0);
96 0 : rTransforms.push_back(aMat);
97 0 : }
98 :
99 0 : void assign_twice(double& r_oVal1, double& r_oVal2, const double& rInVal )
100 : {
101 0 : r_oVal1 = r_oVal2 = rInVal;
102 0 : }
103 :
104 0 : geometry::AffineMatrix2D multiplyMatrix( const geometry::AffineMatrix2D& rLHS,
105 : const geometry::AffineMatrix2D& rRHS )
106 : {
107 0 : basegfx::B2DHomMatrix aLHS;
108 0 : basegfx::B2DHomMatrix aRHS;
109 :
110 0 : basegfx::unotools::homMatrixFromAffineMatrix(aLHS,rLHS);
111 0 : basegfx::unotools::homMatrixFromAffineMatrix(aRHS,rRHS);
112 :
113 0 : aRHS*=aLHS;
114 :
115 0 : geometry::AffineMatrix2D aRet;
116 0 : return basegfx::unotools::affineMatrixFromHomMatrix(aRet,aRHS);
117 : }
118 :
119 : namespace
120 : {
121 0 : struct ColorGrammar : public ::boost::spirit::classic::grammar< ColorGrammar >
122 : {
123 : public:
124 : ARGBColor& m_rColor;
125 0 : explicit ColorGrammar( ARGBColor& rColor ) : m_rColor(rColor) {}
126 : template< typename ScannerT >
127 0 : struct definition
128 : {
129 : ::boost::spirit::classic::rule< ScannerT > colorExpression;
130 0 : definition( const ColorGrammar& self )
131 0 : {
132 : using namespace ::boost::spirit::classic;
133 :
134 : int_parser<sal_uInt8,10,1,3> byte_p;
135 0 : colorExpression =
136 : (
137 : // the #rrggbb form
138 0 : ('#' >> (xdigit_p >> xdigit_p)[boost::bind(&setEightBitColor,
139 0 : boost::ref(self.m_rColor.r),_1,_2)]
140 0 : >> (xdigit_p >> xdigit_p)[boost::bind(&setEightBitColor,
141 0 : boost::ref(self.m_rColor.g),_1,_2)]
142 0 : >> (xdigit_p >> xdigit_p)[boost::bind(&setEightBitColor,
143 0 : boost::ref(self.m_rColor.b),_1,_2)])
144 0 : |
145 : // the #rgb form
146 0 : ('#' >> xdigit_p[boost::bind(&setFourBitColor,
147 0 : boost::ref(self.m_rColor.r),_1)]
148 0 : >> xdigit_p[boost::bind(&setFourBitColor,
149 0 : boost::ref(self.m_rColor.g),_1)]
150 0 : >> xdigit_p[boost::bind(&setFourBitColor,
151 0 : boost::ref(self.m_rColor.b),_1)])
152 0 : |
153 : // rgb() form
154 : (str_p("rgb")
155 0 : >> '(' >>
156 : (
157 : // rgb(int,int,int)
158 : (byte_p[boost::bind(&setIntColor,
159 0 : boost::ref(self.m_rColor.r),_1)] >> ',' >>
160 : byte_p[boost::bind(&setIntColor,
161 0 : boost::ref(self.m_rColor.g),_1)] >> ',' >>
162 : byte_p[boost::bind(&setIntColor,
163 0 : boost::ref(self.m_rColor.b),_1)])
164 0 : |
165 : // rgb(double,double,double)
166 0 : (real_p[assign_a(self.m_rColor.r)] >> ',' >>
167 0 : real_p[assign_a(self.m_rColor.g)] >> ',' >>
168 0 : real_p[assign_a(self.m_rColor.b)])
169 0 : |
170 : // rgb(percent,percent,percent)
171 : (real_p[boost::bind(&setPercentColor,
172 0 : boost::ref(self.m_rColor.r),_1)] >> "%," >>
173 : real_p[boost::bind(&setPercentColor,
174 0 : boost::ref(self.m_rColor.g),_1)] >> "%," >>
175 : real_p[boost::bind(&setPercentColor,
176 0 : boost::ref(self.m_rColor.b),_1)] >> "%")
177 : )
178 0 : >> ')')
179 : );
180 0 : }
181 0 : ::boost::spirit::classic::rule<ScannerT> const& start() const { return colorExpression; }
182 : };
183 : };
184 : }
185 :
186 0 : bool parseColor( const char* sColor, ARGBColor& rColor )
187 : {
188 : using namespace ::boost::spirit::classic;
189 :
190 0 : if( parse(sColor,
191 0 : ColorGrammar(rColor) >> end_p,
192 : space_p).full )
193 : {
194 : // free-form color found & parsed
195 0 : return true;
196 : }
197 :
198 : // no free-form color - maybe a color name?
199 : // trim white space before
200 0 : while( *sColor &&
201 0 : (*sColor==' ' || *sColor=='\t' || *sColor=='\r' || *sColor=='\n') )
202 0 : ++sColor;
203 : // trim white space after
204 0 : int nLen=strlen(sColor)-1;
205 0 : while( nLen &&
206 0 : (sColor[nLen]==' ' || sColor[nLen]=='\t' || sColor[nLen]=='\r' || sColor[nLen]=='\n') )
207 0 : --nLen;
208 0 : switch (getTokenId(sColor, nLen+1))
209 : {
210 0 : case XML_ALICEBLUE: rColor = ARGBColor(240,248,255); return true;
211 0 : case XML_ANTIQUEWHITE: rColor = ARGBColor(250,235,215); return true;
212 0 : case XML_AQUA: rColor = ARGBColor(0,255,255); return true;
213 0 : case XML_AQUAMARINE: rColor = ARGBColor(127,255,212); return true;
214 0 : case XML_AZURE: rColor = ARGBColor(240,255,255); return true;
215 0 : case XML_BEIGE: rColor = ARGBColor(245,245,220); return true;
216 0 : case XML_BISQUE: rColor = ARGBColor(255,228,196); return true;
217 0 : case XML_BLACK: rColor = ARGBColor(0,0,0); return true;
218 0 : case XML_BLANCHEDALMOND: rColor = ARGBColor(255,235,205); return true;
219 0 : case XML_BLUE: rColor = ARGBColor(0,0,255); return true;
220 0 : case XML_BLUEVIOLET: rColor = ARGBColor(138,43,226); return true;
221 0 : case XML_BROWN: rColor = ARGBColor(165,42,42); return true;
222 0 : case XML_BURLYWOOD: rColor = ARGBColor(222,184,135); return true;
223 0 : case XML_CADETBLUE: rColor = ARGBColor(95,158,160); return true;
224 0 : case XML_CHARTREUSE: rColor = ARGBColor(127,255,0); return true;
225 0 : case XML_CHOCOLATE: rColor = ARGBColor(210,105,30); return true;
226 0 : case XML_CORAL: rColor = ARGBColor(255,127,80); return true;
227 0 : case XML_CORNFLOWERBLUE: rColor = ARGBColor(100,149,237); return true;
228 0 : case XML_CORNSILK: rColor = ARGBColor(255,248,220); return true;
229 0 : case XML_CRIMSON: rColor = ARGBColor(220,20,60); return true;
230 0 : case XML_CYAN: rColor = ARGBColor(0,255,255); return true;
231 0 : case XML_DARKBLUE: rColor = ARGBColor(0,0,139); return true;
232 0 : case XML_DARKCYAN: rColor = ARGBColor(0,139,139); return true;
233 0 : case XML_DARKGOLDENROD: rColor = ARGBColor(184,134,11); return true;
234 0 : case XML_DARKGRAY: rColor = ARGBColor(169,169,169); return true;
235 0 : case XML_DARKGREEN: rColor = ARGBColor(0,100,0); return true;
236 0 : case XML_DARKGREY: rColor = ARGBColor(169,169,169); return true;
237 0 : case XML_DARKKHAKI: rColor = ARGBColor(189,183,107); return true;
238 0 : case XML_DARKMAGENTA: rColor = ARGBColor(139,0,139); return true;
239 0 : case XML_DARKOLIVEGREEN: rColor = ARGBColor(85,107,47); return true;
240 0 : case XML_DARKORANGE: rColor = ARGBColor(255,140,0); return true;
241 0 : case XML_DARKORCHID: rColor = ARGBColor(153,50,204); return true;
242 0 : case XML_DARKRED: rColor = ARGBColor(139,0,0); return true;
243 0 : case XML_DARKSALMON: rColor = ARGBColor(233,150,122); return true;
244 0 : case XML_DARKSEAGREEN: rColor = ARGBColor(143,188,143); return true;
245 0 : case XML_DARKSLATEBLUE: rColor = ARGBColor(72,61,139); return true;
246 0 : case XML_DARKSLATEGRAY: rColor = ARGBColor(47,79,79); return true;
247 0 : case XML_DARKSLATEGREY: rColor = ARGBColor(47,79,79); return true;
248 0 : case XML_DARKTURQUOISE: rColor = ARGBColor(0,206,209); return true;
249 0 : case XML_DARKVIOLET: rColor = ARGBColor(148,0,211); return true;
250 0 : case XML_DEEPPINK: rColor = ARGBColor(255,20,147); return true;
251 0 : case XML_DEEPSKYBLUE: rColor = ARGBColor(0,191,255); return true;
252 0 : case XML_DIMGRAY: rColor = ARGBColor(105,105,105); return true;
253 0 : case XML_DIMGREY: rColor = ARGBColor(105,105,105); return true;
254 0 : case XML_DODGERBLUE: rColor = ARGBColor(30,144,255); return true;
255 0 : case XML_FIREBRICK: rColor = ARGBColor(178,34,34); return true;
256 0 : case XML_FLORALWHITE: rColor = ARGBColor(255,250,240); return true;
257 0 : case XML_FORESTGREEN: rColor = ARGBColor(34,139,34); return true;
258 0 : case XML_FUCHSIA: rColor = ARGBColor(255,0,255); return true;
259 0 : case XML_GAINSBORO: rColor = ARGBColor(220,220,220); return true;
260 0 : case XML_GHOSTWHITE: rColor = ARGBColor(248,248,255); return true;
261 0 : case XML_GOLD: rColor = ARGBColor(255,215,0); return true;
262 0 : case XML_GOLDENROD: rColor = ARGBColor(218,165,32); return true;
263 0 : case XML_GRAY: rColor = ARGBColor(128,128,128); return true;
264 0 : case XML_GREY: rColor = ARGBColor(128,128,128); return true;
265 0 : case XML_GREEN: rColor = ARGBColor(0,128,0); return true;
266 0 : case XML_GREENYELLOW: rColor = ARGBColor(173,255,47); return true;
267 0 : case XML_HONEYDEW: rColor = ARGBColor(240,255,240); return true;
268 0 : case XML_HOTPINK: rColor = ARGBColor(255,105,180); return true;
269 0 : case XML_INDIANRED: rColor = ARGBColor(205,92,92); return true;
270 0 : case XML_INDIGO: rColor = ARGBColor(75,0,130); return true;
271 0 : case XML_IVORY: rColor = ARGBColor(255,255,240); return true;
272 0 : case XML_KHAKI: rColor = ARGBColor(240,230,140); return true;
273 0 : case XML_LAVENDER: rColor = ARGBColor(230,230,250); return true;
274 0 : case XML_LAVENDERBLUSH: rColor = ARGBColor(255,240,245); return true;
275 0 : case XML_LAWNGREEN: rColor = ARGBColor(124,252,0); return true;
276 0 : case XML_LEMONCHIFFON: rColor = ARGBColor(255,250,205); return true;
277 0 : case XML_LIGHTBLUE: rColor = ARGBColor(173,216,230); return true;
278 0 : case XML_LIGHTCORAL: rColor = ARGBColor(240,128,128); return true;
279 0 : case XML_LIGHTCYAN: rColor = ARGBColor(224,255,255); return true;
280 0 : case XML_LIGHTGOLDENRODYELLOW: rColor = ARGBColor(250,250,210); return true;
281 0 : case XML_LIGHTGRAY: rColor = ARGBColor(211,211,211); return true;
282 0 : case XML_LIGHTGREEN: rColor = ARGBColor(144,238,144); return true;
283 0 : case XML_LIGHTGREY: rColor = ARGBColor(211,211,211); return true;
284 0 : case XML_LIGHTPINK: rColor = ARGBColor(255,182,193); return true;
285 0 : case XML_LIGHTSALMON: rColor = ARGBColor(255,160,122); return true;
286 0 : case XML_LIGHTSEAGREEN: rColor = ARGBColor(32,178,170); return true;
287 0 : case XML_LIGHTSKYBLUE: rColor = ARGBColor(135,206,250); return true;
288 0 : case XML_LIGHTSLATEGRAY: rColor = ARGBColor(119,136,153); return true;
289 0 : case XML_LIGHTSLATEGREY: rColor = ARGBColor(119,136,153); return true;
290 0 : case XML_LIGHTSTEELBLUE: rColor = ARGBColor(176,196,222); return true;
291 0 : case XML_LIGHTYELLOW: rColor = ARGBColor(255,255,224); return true;
292 0 : case XML_LIME: rColor = ARGBColor(0,255,0); return true;
293 0 : case XML_LIMEGREEN: rColor = ARGBColor(50,205,50); return true;
294 0 : case XML_LINEN: rColor = ARGBColor(250,240,230); return true;
295 0 : case XML_MAGENTA: rColor = ARGBColor(255,0,255); return true;
296 0 : case XML_MAROON: rColor = ARGBColor(128,0,0); return true;
297 0 : case XML_MEDIUMAQUAMARINE: rColor = ARGBColor(102,205,170); return true;
298 0 : case XML_MEDIUMBLUE: rColor = ARGBColor(0,0,205); return true;
299 0 : case XML_MEDIUMORCHID: rColor = ARGBColor(186,85,211); return true;
300 0 : case XML_MEDIUMPURPLE: rColor = ARGBColor(147,112,219); return true;
301 0 : case XML_MEDIUMSEAGREEN: rColor = ARGBColor(60,179,113); return true;
302 0 : case XML_MEDIUMSLATEBLUE: rColor = ARGBColor(123,104,238); return true;
303 0 : case XML_MEDIUMSPRINGGREEN: rColor = ARGBColor(0,250,154); return true;
304 0 : case XML_MEDIUMTURQUOISE: rColor = ARGBColor(72,209,204); return true;
305 0 : case XML_MEDIUMVIOLETRED: rColor = ARGBColor(199,21,133); return true;
306 0 : case XML_MIDNIGHTBLUE: rColor = ARGBColor(25,25,112); return true;
307 0 : case XML_MINTCREAM: rColor = ARGBColor(245,255,250); return true;
308 0 : case XML_MISTYROSE: rColor = ARGBColor(255,228,225); return true;
309 0 : case XML_MOCCASIN: rColor = ARGBColor(255,228,181); return true;
310 0 : case XML_NAVAJOWHITE: rColor = ARGBColor(255,222,173); return true;
311 0 : case XML_NAVY: rColor = ARGBColor(0,0,128); return true;
312 0 : case XML_OLDLACE: rColor = ARGBColor(253,245,230); return true;
313 0 : case XML_OLIVE: rColor = ARGBColor(128,128,0); return true;
314 0 : case XML_OLIVEDRAB: rColor = ARGBColor(107,142,35); return true;
315 0 : case XML_ORANGE: rColor = ARGBColor(255,165,0); return true;
316 0 : case XML_ORANGERED: rColor = ARGBColor(255,69,0); return true;
317 0 : case XML_ORCHID: rColor = ARGBColor(218,112,214); return true;
318 0 : case XML_PALEGOLDENROD: rColor = ARGBColor(238,232,170); return true;
319 0 : case XML_PALEGREEN: rColor = ARGBColor(152,251,152); return true;
320 0 : case XML_PALETURQUOISE: rColor = ARGBColor(175,238,238); return true;
321 0 : case XML_PALEVIOLETRED: rColor = ARGBColor(219,112,147); return true;
322 0 : case XML_PAPAYAWHIP: rColor = ARGBColor(255,239,213); return true;
323 0 : case XML_PEACHPUFF: rColor = ARGBColor(255,218,185); return true;
324 0 : case XML_PERU: rColor = ARGBColor(205,133,63); return true;
325 0 : case XML_PINK: rColor = ARGBColor(255,192,203); return true;
326 0 : case XML_PLUM: rColor = ARGBColor(221,160,221); return true;
327 0 : case XML_POWDERBLUE: rColor = ARGBColor(176,224,230); return true;
328 0 : case XML_PURPLE: rColor = ARGBColor(128,0,128); return true;
329 0 : case XML_RED: rColor = ARGBColor(255,0,0); return true;
330 0 : case XML_ROSYBROWN: rColor = ARGBColor(188,143,143); return true;
331 0 : case XML_ROYALBLUE: rColor = ARGBColor(65,105,225); return true;
332 0 : case XML_SADDLEBROWN: rColor = ARGBColor(139,69,19); return true;
333 0 : case XML_SALMON: rColor = ARGBColor(250,128,114); return true;
334 0 : case XML_SANDYBROWN: rColor = ARGBColor(244,164,96); return true;
335 0 : case XML_SEAGREEN: rColor = ARGBColor(46,139,87); return true;
336 0 : case XML_SEASHELL: rColor = ARGBColor(255,245,238); return true;
337 0 : case XML_SIENNA: rColor = ARGBColor(160,82,45); return true;
338 0 : case XML_SILVER: rColor = ARGBColor(192,192,192); return true;
339 0 : case XML_SKYBLUE: rColor = ARGBColor(135,206,235); return true;
340 0 : case XML_SLATEBLUE: rColor = ARGBColor(106,90,205); return true;
341 0 : case XML_SLATEGRAY: rColor = ARGBColor(112,128,144); return true;
342 0 : case XML_SLATEGREY: rColor = ARGBColor(112,128,144); return true;
343 0 : case XML_SNOW: rColor = ARGBColor(255,250,250); return true;
344 0 : case XML_SPRINGGREEN: rColor = ARGBColor(0,255,127); return true;
345 0 : case XML_STEELBLUE: rColor = ARGBColor(70,130,180); return true;
346 0 : case XML_TAN: rColor = ARGBColor(210,180,140); return true;
347 0 : case XML_TEAL: rColor = ARGBColor(0,128,128); return true;
348 0 : case XML_THISTLE: rColor = ARGBColor(216,191,216); return true;
349 0 : case XML_TOMATO: rColor = ARGBColor(255,99,71); return true;
350 0 : case XML_TURQUOISE: rColor = ARGBColor(64,224,208); return true;
351 0 : case XML_VIOLET: rColor = ARGBColor(238,130,238); return true;
352 0 : case XML_WHEAT: rColor = ARGBColor(245,222,179); return true;
353 0 : case XML_WHITE: rColor = ARGBColor(255,255,255); return true;
354 0 : case XML_WHITESMOKE: rColor = ARGBColor(245,245,245); return true;
355 0 : case XML_YELLOW: rColor = ARGBColor(255,255,0); return true;
356 0 : case XML_YELLOWGREEN: rColor = ARGBColor(154,205,50); return true;
357 :
358 : default:
359 0 : return false; // no color at all, I'd guess.
360 : }
361 : }
362 :
363 0 : bool parseOpacity (const char* sOpacity, ARGBColor& rColor )
364 : {
365 : using namespace ::boost::spirit::classic;
366 :
367 0 : if( parse(sOpacity,
368 : // Begin grammar
369 : (
370 0 : real_p[assign_a(rColor.a)]
371 0 : ) >> end_p,
372 : // End grammar
373 : space_p).full )
374 : {
375 0 : return true;
376 : }
377 0 : return false;
378 : }
379 :
380 :
381 :
382 0 : bool parseTransform( const char* sTransform, basegfx::B2DHomMatrix& rTransform )
383 : {
384 : using namespace ::boost::spirit::classic;
385 :
386 0 : double fRefOffsetX(0.0);
387 0 : double fRefOffsetY(0.0);
388 0 : bool bRefTransform(false);
389 :
390 0 : double fRotationAngle=0.0;
391 0 : double fSkewAngle=0.0;
392 0 : geometry::AffineMatrix2D aIdentityTransform;
393 0 : geometry::AffineMatrix2D aCurrTransform;
394 0 : std::vector<geometry::AffineMatrix2D> aTransforms;
395 0 : aIdentityTransform.m00 = 1.0; aIdentityTransform.m11 = 1.0;
396 0 : aCurrTransform = aIdentityTransform;
397 :
398 : const bool bRes = parse(sTransform,
399 : // Begin grammar
400 : (
401 : // identity transform
402 : str_p("none")
403 0 : |
404 : // the ref() form
405 : (str_p("ref")
406 0 : >> '('
407 0 : >> str_p("svg")[assign_a(bRefTransform,true)]
408 0 : >> !(real_p[assign_a(fRefOffsetX)] >> (',' | eps_p) >>
409 0 : real_p[assign_a(fRefOffsetY)])
410 0 : >> ')')
411 0 : |
412 : // the transform-list form
413 : (list_p(
414 : (
415 : // matrix(a,b,c,d,e,f)
416 : (str_p("matrix")
417 0 : >> '('
418 0 : >> real_p[assign_a(aCurrTransform.m00)] >> (',' | eps_p)
419 0 : >> real_p[assign_a(aCurrTransform.m10)] >> (',' | eps_p)
420 0 : >> real_p[assign_a(aCurrTransform.m01)] >> (',' | eps_p)
421 0 : >> real_p[assign_a(aCurrTransform.m11)] >> (',' | eps_p)
422 0 : >> real_p[assign_a(aCurrTransform.m02)] >> (',' | eps_p)
423 0 : >> real_p[assign_a(aCurrTransform.m12)]
424 0 : >> ')')[push_back_a(aTransforms,aCurrTransform)]
425 0 : |
426 : // translate(x,[y])
427 : (str_p("translate")
428 0 : >> '('
429 0 : >> real_p[boost::bind(&assign_twice,
430 : boost::ref(aCurrTransform.m02),
431 0 : boost::ref(aCurrTransform.m12),_1)]
432 0 : >> !((',' | eps_p) >> real_p[assign_a(aCurrTransform.m12)])
433 0 : >> ')')[push_back_a(aTransforms,aCurrTransform)]
434 0 : |
435 : // scale(x,[y])
436 : (str_p("scale")
437 0 : >> '('
438 0 : >> real_p[boost::bind(&assign_twice,
439 : boost::ref(aCurrTransform.m00),
440 0 : boost::ref(aCurrTransform.m11),_1)]
441 0 : >> !((',' | eps_p) >> real_p[assign_a(aCurrTransform.m11)])
442 0 : >> ')')[push_back_a(aTransforms,aCurrTransform)]
443 0 : |
444 : // rotate(phi,[cx, cy])
445 : (str_p("rotate")
446 0 : >> '('
447 0 : >> real_p[assign_a(fRotationAngle)]
448 0 : >> !((',' | eps_p) >> real_p[assign_a(aCurrTransform.m02)]
449 0 : >> real_p[assign_a(aCurrTransform.m12)])
450 0 : >> ')')[boost::bind(&calcRotation,
451 : boost::ref(aTransforms),
452 : boost::ref(aCurrTransform),
453 0 : boost::cref(fRotationAngle))]
454 0 : |
455 : // skewX(phi)
456 : (str_p("skewX")
457 0 : >> '('
458 0 : >> real_p[assign_a(fSkewAngle)]
459 0 : >> ')')[boost::bind(&calcSkewX,
460 : boost::ref(aTransforms),
461 0 : boost::cref(fSkewAngle))]
462 0 : |
463 : // skewY(phi)
464 : (str_p("skewY")
465 0 : >> '('
466 0 : >> real_p[assign_a(fSkewAngle)]
467 0 : >> ')')[boost::bind(&calcSkewY,
468 : boost::ref(aTransforms),
469 0 : boost::cref(fSkewAngle))]
470 : // reset current transform after every push
471 0 : )[assign_a(aCurrTransform,aIdentityTransform)],
472 : // list delimiter is either ',' or space
473 0 : ',' | eps_p ))
474 0 : ) >> end_p,
475 : // End grammar
476 0 : space_p).full;
477 :
478 0 : if( !bRes )
479 0 : return false;
480 :
481 : // fold all transformations into one
482 : const geometry::AffineMatrix2D aTotalTransform(
483 : std::accumulate(aTransforms.begin(),
484 : aTransforms.end(),
485 : aIdentityTransform,
486 0 : &multiplyMatrix));
487 :
488 : basegfx::unotools::homMatrixFromAffineMatrix(
489 : rTransform,
490 0 : aTotalTransform);
491 :
492 : // TODO(F1): handle the ref case
493 0 : return bRes;
494 : }
495 :
496 :
497 :
498 0 : bool parseViewBox( const char* sViewbox, basegfx::B2DRange& rRect )
499 : {
500 : using namespace ::boost::spirit::classic;
501 :
502 0 : double x=0.0,y=0.0,w=0.0,h=0.0;
503 :
504 : const bool bRes = parse(sViewbox,
505 : // Begin grammar
506 : (
507 : // either comma- or space-delimited list of four doubles
508 0 : real_p[assign_a(x)] >> (',' | eps_p) >>
509 0 : real_p[assign_a(y)] >> (',' | eps_p) >>
510 0 : real_p[assign_a(w)] >> (',' | eps_p) >>
511 0 : real_p[assign_a(h)] >> end_p
512 : ),
513 : // End grammar
514 0 : space_p).full;
515 :
516 0 : if( !bRes )
517 0 : return false;
518 :
519 0 : rRect = basegfx::B2DRange(x,y,x+w,y+h);
520 :
521 0 : return true;
522 : }
523 :
524 :
525 :
526 0 : bool parseDashArray( const char* sDashArray, std::vector<double>& rOutputVector )
527 : {
528 : using namespace ::boost::spirit::classic;
529 :
530 0 : rOutputVector.clear();
531 : return parse(sDashArray,
532 : // Begin grammar
533 : (
534 : // parse comma-delimited list of doubles (have to use the
535 : // 'direct' variant, as otherwise spirit refactors our
536 : // parser to push both real num and comma to push_back_a)
537 : list_p.direct
538 : (
539 0 : real_p[push_back_a(rOutputVector)],
540 : // list delimiter is either ',' or space
541 0 : ',' | eps_p
542 0 : )
543 0 : ) >> end_p,
544 : // End grammar
545 0 : space_p).full;
546 : }
547 :
548 :
549 :
550 0 : bool parsePaintUri( std::pair<const char*,const char*>& o_rPaintUri,
551 : std::pair<ARGBColor,bool>& io_rColor,
552 : const char* sPaintUri )
553 : {
554 : using namespace ::boost::spirit::classic;
555 :
556 : const bool bRes = parse(sPaintUri,
557 : // Begin grammar
558 : (
559 0 : str_p("url(") >> !( str_p("'") | str_p("\"") ) >> ("#") >>
560 0 : (+alnum_p)[assign_a(o_rPaintUri)] >>
561 0 : !( str_p("'") | str_p("\"") ) >> str_p(")") >>
562 0 : *( str_p("none")[assign_a(io_rColor.second,false)] |
563 0 : str_p("currentColor")[assign_a(io_rColor.second,true)] |
564 0 : ColorGrammar(io_rColor.first)
565 : // TODO(F1): named color
566 0 : )
567 0 : ) >> end_p,
568 : // End grammar
569 0 : space_p).full;
570 :
571 0 : return bRes;
572 : }
573 :
574 :
575 :
576 0 : bool parseXlinkHref( const char* sXlinkHref, std::string& data )
577 : {
578 : using namespace ::boost::spirit::classic;
579 :
580 0 : data.erase(data.begin(),data.end());
581 :
582 0 : std::string sLink(sXlinkHref);
583 :
584 0 : if (!sLink.compare(0,5,"data:"))
585 : {
586 : // the inplace "data" uri
587 0 : size_t position = sLink.rfind(',');
588 0 : if (position > 0 && position < std::string::npos)
589 : {
590 0 : data = sLink.substr(position+1);
591 : OSL_TRACE("%s", data.c_str());
592 0 : return true;
593 : }
594 : }
595 :
596 0 : return false;
597 : }
598 :
599 9 : } // namespace svgi
600 :
601 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|