| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005, 2006 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 Apple Inc. All rights reserved. | 4 * Copyright (C) 2007 Apple Inc. All rights reserved. |
| 5 * | 5 * |
| 6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
| 7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
| 8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
| 9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
| 10 * | 10 * |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 ASSERT_NOT_REACHED(); | 66 ASSERT_NOT_REACHED(); |
| 67 return String(); | 67 return String(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 template<typename CharType> | 70 template<typename CharType> |
| 71 SVGLengthType stringToLengthType(const CharType*& ptr, const CharType* end) | 71 SVGLengthType stringToLengthType(const CharType*& ptr, const CharType* end) |
| 72 { | 72 { |
| 73 if (ptr == end) | 73 if (ptr == end) |
| 74 return LengthTypeNumber; | 74 return LengthTypeNumber; |
| 75 | 75 |
| 76 SVGLengthType type = LengthTypeUnknown; | 76 const UChar firstChar = *ptr; |
| 77 const CharType firstChar = *ptr++; | |
| 78 | 77 |
| 79 if (firstChar == '%') { | 78 if (++ptr == end) |
| 80 type = LengthTypePercentage; | 79 return firstChar == '%' ? LengthTypePercentage : LengthTypeUnknown; |
| 81 } else if (isHTMLSpace<CharType>(firstChar)) { | |
| 82 type = LengthTypeNumber; | |
| 83 } else if (ptr < end) { | |
| 84 const CharType secondChar = *ptr++; | |
| 85 | 80 |
| 86 if (firstChar == 'p') { | 81 const UChar secondChar = *ptr; |
| 87 if (secondChar == 'x') | |
| 88 type = LengthTypePX; | |
| 89 if (secondChar == 't') | |
| 90 type = LengthTypePT; | |
| 91 if (secondChar == 'c') | |
| 92 type = LengthTypePC; | |
| 93 } else if (firstChar == 'e') { | |
| 94 if (secondChar == 'm') | |
| 95 type = LengthTypeEMS; | |
| 96 if (secondChar == 'x') | |
| 97 type = LengthTypeEXS; | |
| 98 } else if (firstChar == 'c' && secondChar == 'm') { | |
| 99 type = LengthTypeCM; | |
| 100 } else if (firstChar == 'm' && secondChar == 'm') { | |
| 101 type = LengthTypeMM; | |
| 102 } else if (firstChar == 'i' && secondChar == 'n') { | |
| 103 type = LengthTypeIN; | |
| 104 } else if (isHTMLSpace<CharType>(firstChar) && isHTMLSpace<CharType>(sec
ondChar)) { | |
| 105 type = LengthTypeNumber; | |
| 106 } | |
| 107 } | |
| 108 | 82 |
| 109 if (!skipOptionalSVGSpaces(ptr, end)) | 83 if (++ptr != end) |
| 110 return type; | 84 return LengthTypeUnknown; |
| 85 |
| 86 if (firstChar == 'e' && secondChar == 'm') |
| 87 return LengthTypeEMS; |
| 88 if (firstChar == 'e' && secondChar == 'x') |
| 89 return LengthTypeEXS; |
| 90 if (firstChar == 'p' && secondChar == 'x') |
| 91 return LengthTypePX; |
| 92 if (firstChar == 'c' && secondChar == 'm') |
| 93 return LengthTypeCM; |
| 94 if (firstChar == 'm' && secondChar == 'm') |
| 95 return LengthTypeMM; |
| 96 if (firstChar == 'i' && secondChar == 'n') |
| 97 return LengthTypeIN; |
| 98 if (firstChar == 'p' && secondChar == 't') |
| 99 return LengthTypePT; |
| 100 if (firstChar == 'p' && secondChar == 'c') |
| 101 return LengthTypePC; |
| 111 | 102 |
| 112 return LengthTypeUnknown; | 103 return LengthTypeUnknown; |
| 113 } | 104 } |
| 114 | 105 |
| 115 } // namespace | 106 } // namespace |
| 116 | 107 |
| 117 SVGLength::SVGLength(SVGLengthMode mode) | 108 SVGLength::SVGLength(SVGLengthMode mode) |
| 118 : SVGPropertyBase(classType()) | 109 : SVGPropertyBase(classType()) |
| 119 , m_valueInSpecifiedUnits(0) | 110 , m_valueInSpecifiedUnits(0) |
| 120 , m_unitMode(mode) | 111 , m_unitMode(mode) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 | 182 |
| 192 return m_valueInSpecifiedUnits; | 183 return m_valueInSpecifiedUnits; |
| 193 } | 184 } |
| 194 | 185 |
| 195 template<typename CharType> | 186 template<typename CharType> |
| 196 static bool parseValueInternal(const String& string, float& convertedNumber, SVG
LengthType& type) | 187 static bool parseValueInternal(const String& string, float& convertedNumber, SVG
LengthType& type) |
| 197 { | 188 { |
| 198 const CharType* ptr = string.getCharacters<CharType>(); | 189 const CharType* ptr = string.getCharacters<CharType>(); |
| 199 const CharType* end = ptr + string.length(); | 190 const CharType* end = ptr + string.length(); |
| 200 | 191 |
| 201 if (!parseNumber(ptr, end, convertedNumber, AllowLeadingWhitespace)) | 192 if (!parseNumber(ptr, end, convertedNumber, false)) |
| 202 return false; | 193 return false; |
| 203 | 194 |
| 204 type = stringToLengthType(ptr, end); | 195 type = stringToLengthType(ptr, end); |
| 205 ASSERT(ptr <= end); | 196 ASSERT(ptr <= end); |
| 206 if (type == LengthTypeUnknown) | 197 if (type == LengthTypeUnknown) |
| 207 return false; | 198 return false; |
| 208 | 199 |
| 209 return true; | 200 return true; |
| 210 } | 201 } |
| 211 | 202 |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 | 458 |
| 468 float SVGLength::calculateDistance(PassRefPtr<SVGPropertyBase> toValue, SVGEleme
nt* contextElement) | 459 float SVGLength::calculateDistance(PassRefPtr<SVGPropertyBase> toValue, SVGEleme
nt* contextElement) |
| 469 { | 460 { |
| 470 SVGLengthContext lengthContext(contextElement); | 461 SVGLengthContext lengthContext(contextElement); |
| 471 RefPtr<SVGLength> toLength = toSVGLength(toValue); | 462 RefPtr<SVGLength> toLength = toSVGLength(toValue); |
| 472 | 463 |
| 473 return fabsf(toLength->value(lengthContext, IGNORE_EXCEPTION) - value(length
Context, IGNORE_EXCEPTION)); | 464 return fabsf(toLength->value(lengthContext, IGNORE_EXCEPTION) - value(length
Context, IGNORE_EXCEPTION)); |
| 474 } | 465 } |
| 475 | 466 |
| 476 } | 467 } |
| OLD | NEW |