Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(408)

Side by Side Diff: third_party/WebKit/Source/core/svg/SVGTransformList.cpp

Issue 1527993002: Tidy up SVGParserUtilities (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Extra math for Android. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> 4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
5 * Copyright (C) 2008 Apple Inc. All rights reserved. 5 * Copyright (C) 2008 Apple Inc. All rights reserved.
6 * Copyright (C) Research In Motion Limited 2012. All rights reserved. 6 * Copyright (C) Research In Motion Limited 2012. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version. 11 * version 2 of the License, or (at your option) any later version.
12 * 12 *
13 * This library is distributed in the hope that it will be useful, 13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details. 16 * Library General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU Library General Public License 18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to 19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA. 21 * Boston, MA 02110-1301, USA.
22 */ 22 */
23 23
24 #include "config.h" 24 #include "config.h"
25
26 #include "core/svg/SVGTransformList.h" 25 #include "core/svg/SVGTransformList.h"
27 26
28 #include "core/SVGNames.h" 27 #include "core/SVGNames.h"
29 #include "core/svg/SVGAnimateTransformElement.h"
30 #include "core/svg/SVGAnimatedNumber.h"
31 #include "core/svg/SVGParserUtilities.h" 28 #include "core/svg/SVGParserUtilities.h"
32 #include "core/svg/SVGTransformDistance.h" 29 #include "core/svg/SVGTransformDistance.h"
30 #include "platform/text/ParserUtilities.h"
33 #include "wtf/text/StringBuilder.h" 31 #include "wtf/text/StringBuilder.h"
34 #include "wtf/text/WTFString.h" 32 #include "wtf/text/WTFString.h"
35 33
36 namespace blink { 34 namespace blink {
37 35
38 SVGTransformList::SVGTransformList() 36 SVGTransformList::SVGTransformList()
39 { 37 {
40 } 38 }
41 39
42 SVGTransformList::~SVGTransformList() 40 SVGTransformList::~SVGTransformList()
(...skipping 19 matching lines...) Expand all
62 ConstIterator it = begin(); 60 ConstIterator it = begin();
63 ConstIterator itEnd = end(); 61 ConstIterator itEnd = end();
64 for (; it != itEnd; ++it) 62 for (; it != itEnd; ++it)
65 result *= it->matrix(); 63 result *= it->matrix();
66 64
67 return true; 65 return true;
68 } 66 }
69 67
70 namespace { 68 namespace {
71 69
70 const LChar skewXDesc[] = {'s', 'k', 'e', 'w', 'X'};
71 const LChar skewYDesc[] = {'s', 'k', 'e', 'w', 'Y'};
72 const LChar scaleDesc[] = {'s', 'c', 'a', 'l', 'e'};
73 const LChar translateDesc[] = {'t', 'r', 'a', 'n', 's', 'l', 'a', 't', 'e'};
74 const LChar rotateDesc[] = {'r', 'o', 't', 'a', 't', 'e'};
75 const LChar matrixDesc[] = {'m', 'a', 't', 'r', 'i', 'x'};
76
77 template<typename CharType>
78 bool parseAndSkipTransformType(const CharType*& ptr, const CharType* end, SVGTra nsformType& type)
79 {
80 if (ptr >= end)
81 return false;
82
83 if (*ptr == 's') {
84 if (skipString(ptr, end, skewXDesc, WTF_ARRAY_LENGTH(skewXDesc)))
85 type = SVG_TRANSFORM_SKEWX;
86 else if (skipString(ptr, end, skewYDesc, WTF_ARRAY_LENGTH(skewYDesc)))
87 type = SVG_TRANSFORM_SKEWY;
88 else if (skipString(ptr, end, scaleDesc, WTF_ARRAY_LENGTH(scaleDesc)))
89 type = SVG_TRANSFORM_SCALE;
90 else
91 return false;
92 } else if (skipString(ptr, end, translateDesc, WTF_ARRAY_LENGTH(translateDes c))) {
93 type = SVG_TRANSFORM_TRANSLATE;
94 } else if (skipString(ptr, end, rotateDesc, WTF_ARRAY_LENGTH(rotateDesc))) {
95 type = SVG_TRANSFORM_ROTATE;
96 } else if (skipString(ptr, end, matrixDesc, WTF_ARRAY_LENGTH(matrixDesc))) {
97 type = SVG_TRANSFORM_MATRIX;
98 } else {
99 return false;
100 }
101 return true;
102 }
103
72 template<typename CharType> 104 template<typename CharType>
73 int parseTransformParamList(const CharType*& ptr, const CharType* end, float* va lues, int required, int optional) 105 int parseTransformParamList(const CharType*& ptr, const CharType* end, float* va lues, int required, int optional)
74 { 106 {
75 int parsedParams = 0; 107 int parsedParams = 0;
76 int maxPossibleParams = required + optional; 108 int maxPossibleParams = required + optional;
77 109
78 bool trailingDelimiter = false; 110 bool trailingDelimiter = false;
79 111
80 skipOptionalSVGSpaces(ptr, end); 112 skipOptionalSVGSpaces(ptr, end);
81 while (parsedParams < maxPossibleParams) { 113 while (parsedParams < maxPossibleParams) {
(...skipping 12 matching lines...) Expand all
94 } 126 }
95 } 127 }
96 128
97 if (trailingDelimiter || !(parsedParams == required || parsedParams == maxPo ssibleParams)) 129 if (trailingDelimiter || !(parsedParams == required || parsedParams == maxPo ssibleParams))
98 return -1; 130 return -1;
99 131
100 return parsedParams; 132 return parsedParams;
101 } 133 }
102 134
103 // These should be kept in sync with enum SVGTransformType 135 // These should be kept in sync with enum SVGTransformType
104 static const int requiredValuesForType[] = {0, 6, 1, 1, 1, 1, 1}; 136 const int requiredValuesForType[] = {0, 6, 1, 1, 1, 1, 1};
105 static const int optionalValuesForType[] = {0, 0, 1, 1, 2, 0, 0}; 137 const int optionalValuesForType[] = {0, 0, 1, 1, 2, 0, 0};
106 138
107 template<typename CharType> 139 template<typename CharType>
108 PassRefPtrWillBeRawPtr<SVGTransform> parseTransformOfType(unsigned type, const C harType*& ptr, const CharType* end) 140 PassRefPtrWillBeRawPtr<SVGTransform> parseTransformOfType(unsigned type, const C harType*& ptr, const CharType* end)
109 { 141 {
110 if (type == SVG_TRANSFORM_UNKNOWN) 142 if (type == SVG_TRANSFORM_UNKNOWN)
111 return nullptr; 143 return nullptr;
112 144
113 int valueCount = 0; 145 int valueCount = 0;
114 float values[] = {0, 0, 0, 0, 0, 0}; 146 float values[] = {0, 0, 0, 0, 0, 0};
115 if ((valueCount = parseTransformParamList(ptr, end, values, requiredValuesFo rType[type], optionalValuesForType[type])) < 0) { 147 if ((valueCount = parseTransformParamList(ptr, end, values, requiredValuesFo rType[type], optionalValuesForType[type])) < 0) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 bool SVGTransformList::parse(const UChar*& ptr, const UChar* end) 227 bool SVGTransformList::parse(const UChar*& ptr, const UChar* end)
196 { 228 {
197 return parseInternal(ptr, end); 229 return parseInternal(ptr, end);
198 } 230 }
199 231
200 bool SVGTransformList::parse(const LChar*& ptr, const LChar* end) 232 bool SVGTransformList::parse(const LChar*& ptr, const LChar* end)
201 { 233 {
202 return parseInternal(ptr, end); 234 return parseInternal(ptr, end);
203 } 235 }
204 236
237 SVGTransformType parseTransformType(const String& string)
238 {
239 if (string.isEmpty())
240 return SVG_TRANSFORM_UNKNOWN;
241 SVGTransformType type = SVG_TRANSFORM_UNKNOWN;
242 if (string.is8Bit()) {
243 const LChar* ptr = string.characters8();
244 const LChar* end = ptr + string.length();
245 parseAndSkipTransformType(ptr, end, type);
246 } else {
247 const UChar* ptr = string.characters16();
248 const UChar* end = ptr + string.length();
249 parseAndSkipTransformType(ptr, end, type);
250 }
251 return type;
252 }
253
205 String SVGTransformList::valueAsString() const 254 String SVGTransformList::valueAsString() const
206 { 255 {
207 StringBuilder builder; 256 StringBuilder builder;
208 257
209 ConstIterator it = begin(); 258 ConstIterator it = begin();
210 ConstIterator itEnd = end(); 259 ConstIterator itEnd = end();
211 while (it != itEnd) { 260 while (it != itEnd) {
212 builder.append(it->valueAsString()); 261 builder.append(it->valueAsString());
213 ++it; 262 ++it;
214 if (it != itEnd) 263 if (it != itEnd)
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 if (at(0)->transformType() == toList->at(0)->transformType()) 387 if (at(0)->transformType() == toList->at(0)->transformType())
339 return -1; 388 return -1;
340 389
341 // Spec: http://www.w3.org/TR/SVG/animate.html#complexDistances 390 // Spec: http://www.w3.org/TR/SVG/animate.html#complexDistances
342 // Paced animations assume a notion of distance between the various animatio n values defined by the 'to', 'from', 'by' and 'values' attributes. 391 // Paced animations assume a notion of distance between the various animatio n values defined by the 'to', 'from', 'by' and 'values' attributes.
343 // Distance is defined only for scalar types (such as <length>), colors and the subset of transformation types that are supported by 'animateTransform'. 392 // Distance is defined only for scalar types (such as <length>), colors and the subset of transformation types that are supported by 'animateTransform'.
344 return SVGTransformDistance(at(0), toList->at(0)).distance(); 393 return SVGTransformDistance(at(0), toList->at(0)).distance();
345 } 394 }
346 395
347 } 396 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGTransformList.h ('k') | third_party/WebKit/Source/core/svg/SVGViewSpec.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698