| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> |
| 4 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 4 * Copyright (C) Research In Motion Limited 2010. 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 m_orientType->setEnumValue(SVGMarkerOrientAngle); | 145 m_orientType->setEnumValue(SVGMarkerOrientAngle); |
| 146 } | 146 } |
| 147 | 147 |
| 148 template<typename CharType> | 148 template<typename CharType> |
| 149 static SVGAngle::SVGAngleType stringToAngleType(const CharType*& ptr, const Char
Type* end) | 149 static SVGAngle::SVGAngleType stringToAngleType(const CharType*& ptr, const Char
Type* end) |
| 150 { | 150 { |
| 151 // If there's no unit given, the angle type is unspecified. | 151 // If there's no unit given, the angle type is unspecified. |
| 152 if (ptr == end) | 152 if (ptr == end) |
| 153 return SVGAngle::SVG_ANGLETYPE_UNSPECIFIED; | 153 return SVGAngle::SVG_ANGLETYPE_UNSPECIFIED; |
| 154 | 154 |
| 155 SVGAngle::SVGAngleType type = SVGAngle::SVG_ANGLETYPE_UNKNOWN; | 155 const CharType firstChar = *ptr; |
| 156 const CharType firstChar = *ptr++; | |
| 157 | 156 |
| 158 if (isHTMLSpace<CharType>(firstChar)) { | 157 // If the unit contains only one character, the angle type is unknown. |
| 159 type = SVGAngle::SVG_ANGLETYPE_UNSPECIFIED; | 158 ++ptr; |
| 160 } else if (end - ptr >= 2) { | 159 if (ptr == end) |
| 161 const CharType secondChar = *ptr++; | 160 return SVGAngle::SVG_ANGLETYPE_UNKNOWN; |
| 162 const CharType thirdChar = *ptr++; | |
| 163 if (firstChar == 'd' && secondChar == 'e' && thirdChar == 'g') { | |
| 164 type = SVGAngle::SVG_ANGLETYPE_DEG; | |
| 165 } else if (firstChar == 'r' && secondChar == 'a' && thirdChar == 'd') { | |
| 166 type = SVGAngle::SVG_ANGLETYPE_RAD; | |
| 167 } else if (ptr != end) { | |
| 168 const CharType fourthChar = *ptr++; | |
| 169 if (firstChar == 'g' && secondChar == 'r' && thirdChar == 'a' && fou
rthChar == 'd') | |
| 170 type = SVGAngle::SVG_ANGLETYPE_GRAD; | |
| 171 } | |
| 172 } | |
| 173 | 161 |
| 174 if (!skipOptionalSVGSpaces(ptr, end)) | 162 const CharType secondChar = *ptr; |
| 175 return type; | 163 |
| 164 // If the unit contains only two characters, the angle type is unknown. |
| 165 ++ptr; |
| 166 if (ptr == end) |
| 167 return SVGAngle::SVG_ANGLETYPE_UNKNOWN; |
| 168 |
| 169 const CharType thirdChar = *ptr; |
| 170 if (firstChar == 'd' && secondChar == 'e' && thirdChar == 'g') |
| 171 return SVGAngle::SVG_ANGLETYPE_DEG; |
| 172 if (firstChar == 'r' && secondChar == 'a' && thirdChar == 'd') |
| 173 return SVGAngle::SVG_ANGLETYPE_RAD; |
| 174 |
| 175 // If the unit contains three characters, but is not deg or rad, then it's u
nknown. |
| 176 ++ptr; |
| 177 if (ptr == end) |
| 178 return SVGAngle::SVG_ANGLETYPE_UNKNOWN; |
| 179 |
| 180 const CharType fourthChar = *ptr; |
| 181 |
| 182 if (firstChar == 'g' && secondChar == 'r' && thirdChar == 'a' && fourthChar
== 'd') |
| 183 return SVGAngle::SVG_ANGLETYPE_GRAD; |
| 176 | 184 |
| 177 return SVGAngle::SVG_ANGLETYPE_UNKNOWN; | 185 return SVGAngle::SVG_ANGLETYPE_UNKNOWN; |
| 178 } | 186 } |
| 179 | 187 |
| 180 String SVGAngle::valueAsString() const | 188 String SVGAngle::valueAsString() const |
| 181 { | 189 { |
| 182 switch (m_unitType) { | 190 switch (m_unitType) { |
| 183 case SVG_ANGLETYPE_DEG: { | 191 case SVG_ANGLETYPE_DEG: { |
| 184 DEFINE_STATIC_LOCAL(String, degString, ("deg")); | 192 DEFINE_STATIC_LOCAL(String, degString, ("deg")); |
| 185 return String::number(m_valueInSpecifiedUnits) + degString; | 193 return String::number(m_valueInSpecifiedUnits) + degString; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 200 ASSERT_NOT_REACHED(); | 208 ASSERT_NOT_REACHED(); |
| 201 return String(); | 209 return String(); |
| 202 } | 210 } |
| 203 | 211 |
| 204 template<typename CharType> | 212 template<typename CharType> |
| 205 static bool parseValue(const String& value, float& valueInSpecifiedUnits, SVGAng
le::SVGAngleType& unitType) | 213 static bool parseValue(const String& value, float& valueInSpecifiedUnits, SVGAng
le::SVGAngleType& unitType) |
| 206 { | 214 { |
| 207 const CharType* ptr = value.getCharacters<CharType>(); | 215 const CharType* ptr = value.getCharacters<CharType>(); |
| 208 const CharType* end = ptr + value.length(); | 216 const CharType* end = ptr + value.length(); |
| 209 | 217 |
| 210 if (!parseNumber(ptr, end, valueInSpecifiedUnits, AllowLeadingWhitespace)) | 218 if (!parseNumber(ptr, end, valueInSpecifiedUnits, false)) |
| 211 return false; | 219 return false; |
| 212 | 220 |
| 213 unitType = stringToAngleType(ptr, end); | 221 unitType = stringToAngleType(ptr, end); |
| 214 if (unitType == SVGAngle::SVG_ANGLETYPE_UNKNOWN) | 222 if (unitType == SVGAngle::SVG_ANGLETYPE_UNKNOWN) |
| 215 return false; | 223 return false; |
| 216 | 224 |
| 217 return true; | 225 return true; |
| 218 } | 226 } |
| 219 | 227 |
| 220 void SVGAngle::setValueAsString(const String& value, ExceptionState& exceptionSt
ate) | 228 void SVGAngle::setValueAsString(const String& value, ExceptionState& exceptionSt
ate) |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 | 397 |
| 390 void SVGAngle::orientTypeChanged() | 398 void SVGAngle::orientTypeChanged() |
| 391 { | 399 { |
| 392 if (orientType()->enumValue() == SVGMarkerOrientAuto) { | 400 if (orientType()->enumValue() == SVGMarkerOrientAuto) { |
| 393 m_unitType = SVG_ANGLETYPE_UNSPECIFIED; | 401 m_unitType = SVG_ANGLETYPE_UNSPECIFIED; |
| 394 m_valueInSpecifiedUnits = 0; | 402 m_valueInSpecifiedUnits = 0; |
| 395 } | 403 } |
| 396 } | 404 } |
| 397 | 405 |
| 398 } | 406 } |
| OLD | NEW |