| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2002, 2003 The Karbon Developers | 2 * Copyright (C) 2002, 2003 The Karbon Developers |
| 3 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> | 3 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> |
| 4 * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org> | 4 * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org> |
| 5 * Copyright (C) 2007, 2009, 2013 Apple Inc. All rights reserved. | 5 * Copyright (C) 2007, 2009, 2013 Apple Inc. All rights reserved. |
| 6 * | 6 * |
| 7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
| 11 * | 11 * |
| 12 * This library is distributed in the hope that it will be useful, | 12 * This library is distributed in the hope that it will be useful, |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 * Library General Public License for more details. | 15 * Library General Public License for more details. |
| 16 * | 16 * |
| 17 * You should have received a copy of the GNU Library General Public License | 17 * You should have received a copy of the GNU Library General Public License |
| 18 * along with this library; see the file COPYING.LIB. If not, write to | 18 * along with this library; see the file COPYING.LIB. If not, write to |
| 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 * Boston, MA 02110-1301, USA. | 20 * Boston, MA 02110-1301, USA. |
| 21 */ | 21 */ |
| 22 | 22 |
| 23 #include "config.h" | 23 #include "config.h" |
| 24 #include "core/svg/SVGParserUtilities.h" | 24 #include "core/svg/SVGParserUtilities.h" |
| 25 | 25 |
| 26 #include "core/svg/SVGPointList.h" | 26 #include "wtf/MathExtras.h" |
| 27 #include "platform/geometry/FloatRect.h" | |
| 28 #include "platform/transforms/AffineTransform.h" | |
| 29 #include "wtf/ASCIICType.h" | |
| 30 #include "wtf/text/StringHash.h" | |
| 31 #include <limits> | 27 #include <limits> |
| 32 | 28 |
| 33 namespace blink { | 29 namespace blink { |
| 34 | 30 |
| 35 template <typename FloatType> | 31 template <typename FloatType> |
| 36 static inline bool isValidRange(const FloatType& x) | 32 static inline bool isValidRange(const FloatType& x) |
| 37 { | 33 { |
| 38 static const FloatType max = std::numeric_limits<FloatType>::max(); | 34 static const FloatType max = std::numeric_limits<FloatType>::max(); |
| 39 return x >= -max && x <= max; | 35 return x >= -max && x <= max; |
| 40 } | 36 } |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 if (string.is8Bit()) { | 240 if (string.is8Bit()) { |
| 245 const LChar* ptr = string.characters8(); | 241 const LChar* ptr = string.characters8(); |
| 246 const LChar* end = ptr + string.length(); | 242 const LChar* end = ptr + string.length(); |
| 247 return genericParseNumberOrPercentage(ptr, end, number); | 243 return genericParseNumberOrPercentage(ptr, end, number); |
| 248 } | 244 } |
| 249 const UChar* ptr = string.characters16(); | 245 const UChar* ptr = string.characters16(); |
| 250 const UChar* end = ptr + string.length(); | 246 const UChar* end = ptr + string.length(); |
| 251 return genericParseNumberOrPercentage(ptr, end, number); | 247 return genericParseNumberOrPercentage(ptr, end, number); |
| 252 } | 248 } |
| 253 | 249 |
| 254 static const LChar skewXDesc[] = {'s', 'k', 'e', 'w', 'X'}; | |
| 255 static const LChar skewYDesc[] = {'s', 'k', 'e', 'w', 'Y'}; | |
| 256 static const LChar scaleDesc[] = {'s', 'c', 'a', 'l', 'e'}; | |
| 257 static const LChar translateDesc[] = {'t', 'r', 'a', 'n', 's', 'l', 'a', 't', '
e'}; | |
| 258 static const LChar rotateDesc[] = {'r', 'o', 't', 'a', 't', 'e'}; | |
| 259 static const LChar matrixDesc[] = {'m', 'a', 't', 'r', 'i', 'x'}; | |
| 260 | |
| 261 template<typename CharType> | |
| 262 bool parseAndSkipTransformType(const CharType*& ptr, const CharType* end, SVGTra
nsformType& type) | |
| 263 { | |
| 264 if (ptr >= end) | |
| 265 return false; | |
| 266 | |
| 267 if (*ptr == 's') { | |
| 268 if (skipString(ptr, end, skewXDesc, WTF_ARRAY_LENGTH(skewXDesc))) | |
| 269 type = SVG_TRANSFORM_SKEWX; | |
| 270 else if (skipString(ptr, end, skewYDesc, WTF_ARRAY_LENGTH(skewYDesc))) | |
| 271 type = SVG_TRANSFORM_SKEWY; | |
| 272 else if (skipString(ptr, end, scaleDesc, WTF_ARRAY_LENGTH(scaleDesc))) | |
| 273 type = SVG_TRANSFORM_SCALE; | |
| 274 else | |
| 275 return false; | |
| 276 } else if (skipString(ptr, end, translateDesc, WTF_ARRAY_LENGTH(translateDes
c))) | |
| 277 type = SVG_TRANSFORM_TRANSLATE; | |
| 278 else if (skipString(ptr, end, rotateDesc, WTF_ARRAY_LENGTH(rotateDesc))) | |
| 279 type = SVG_TRANSFORM_ROTATE; | |
| 280 else if (skipString(ptr, end, matrixDesc, WTF_ARRAY_LENGTH(matrixDesc))) | |
| 281 type = SVG_TRANSFORM_MATRIX; | |
| 282 else | |
| 283 return false; | |
| 284 | |
| 285 return true; | |
| 286 } | 250 } |
| 287 | |
| 288 template bool parseAndSkipTransformType(const UChar*& current, const UChar* end,
SVGTransformType&); | |
| 289 template bool parseAndSkipTransformType(const LChar*& current, const LChar* end,
SVGTransformType&); | |
| 290 | |
| 291 SVGTransformType parseTransformType(const String& string) | |
| 292 { | |
| 293 if (string.isEmpty()) | |
| 294 return SVG_TRANSFORM_UNKNOWN; | |
| 295 SVGTransformType type = SVG_TRANSFORM_UNKNOWN; | |
| 296 if (string.is8Bit()) { | |
| 297 const LChar* ptr = string.characters8(); | |
| 298 const LChar* end = ptr + string.length(); | |
| 299 parseAndSkipTransformType(ptr, end, type); | |
| 300 } else { | |
| 301 const UChar* ptr = string.characters16(); | |
| 302 const UChar* end = ptr + string.length(); | |
| 303 parseAndSkipTransformType(ptr, end, type); | |
| 304 } | |
| 305 return type; | |
| 306 } | |
| 307 | |
| 308 } | |
| OLD | NEW |