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 const UChar firstChar = *ptr; | 76 SVGLengthType type = LengthTypeUnknown; |
| 77 const CharType firstChar = *ptr++; |
77 | 78 |
78 if (++ptr == end) | 79 if (firstChar == '%') { |
79 return firstChar == '%' ? LengthTypePercentage : LengthTypeUnknown; | 80 type = LengthTypePercentage; |
| 81 } else if (isHTMLSpace<CharType>(firstChar)) { |
| 82 type = LengthTypeNumber; |
| 83 } else if (ptr < end) { |
| 84 const CharType secondChar = *ptr++; |
80 | 85 |
81 const UChar secondChar = *ptr; | 86 if (firstChar == 'p') { |
| 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 } |
82 | 108 |
83 if (++ptr != end) | 109 if (!skipOptionalSVGSpaces(ptr, end)) |
84 return LengthTypeUnknown; | 110 return type; |
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; | |
102 | 111 |
103 return LengthTypeUnknown; | 112 return LengthTypeUnknown; |
104 } | 113 } |
105 | 114 |
106 } // namespace | 115 } // namespace |
107 | 116 |
108 SVGLength::SVGLength(SVGLengthMode mode) | 117 SVGLength::SVGLength(SVGLengthMode mode) |
109 : SVGPropertyBase(classType()) | 118 : SVGPropertyBase(classType()) |
110 , m_valueInSpecifiedUnits(0) | 119 , m_valueInSpecifiedUnits(0) |
111 , m_unitMode(mode) | 120 , m_unitMode(mode) |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 191 |
183 return m_valueInSpecifiedUnits; | 192 return m_valueInSpecifiedUnits; |
184 } | 193 } |
185 | 194 |
186 template<typename CharType> | 195 template<typename CharType> |
187 static bool parseValueInternal(const String& string, float& convertedNumber, SVG
LengthType& type) | 196 static bool parseValueInternal(const String& string, float& convertedNumber, SVG
LengthType& type) |
188 { | 197 { |
189 const CharType* ptr = string.getCharacters<CharType>(); | 198 const CharType* ptr = string.getCharacters<CharType>(); |
190 const CharType* end = ptr + string.length(); | 199 const CharType* end = ptr + string.length(); |
191 | 200 |
192 if (!parseNumber(ptr, end, convertedNumber, false)) | 201 if (!parseNumber(ptr, end, convertedNumber, AllowLeadingWhitespace)) |
193 return false; | 202 return false; |
194 | 203 |
195 type = stringToLengthType(ptr, end); | 204 type = stringToLengthType(ptr, end); |
196 ASSERT(ptr <= end); | 205 ASSERT(ptr <= end); |
197 if (type == LengthTypeUnknown) | 206 if (type == LengthTypeUnknown) |
198 return false; | 207 return false; |
199 | 208 |
200 return true; | 209 return true; |
201 } | 210 } |
202 | 211 |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 | 467 |
459 float SVGLength::calculateDistance(PassRefPtr<SVGPropertyBase> toValue, SVGEleme
nt* contextElement) | 468 float SVGLength::calculateDistance(PassRefPtr<SVGPropertyBase> toValue, SVGEleme
nt* contextElement) |
460 { | 469 { |
461 SVGLengthContext lengthContext(contextElement); | 470 SVGLengthContext lengthContext(contextElement); |
462 RefPtr<SVGLength> toLength = toSVGLength(toValue); | 471 RefPtr<SVGLength> toLength = toSVGLength(toValue); |
463 | 472 |
464 return fabsf(toLength->value(lengthContext, IGNORE_EXCEPTION) - value(length
Context, IGNORE_EXCEPTION)); | 473 return fabsf(toLength->value(lengthContext, IGNORE_EXCEPTION) - value(length
Context, IGNORE_EXCEPTION)); |
465 } | 474 } |
466 | 475 |
467 } | 476 } |
OLD | NEW |