| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 : m_value(point) | 46 : m_value(point) |
| 47 { | 47 { |
| 48 } | 48 } |
| 49 | 49 |
| 50 PassRefPtrWillBeRawPtr<SVGPoint> SVGPoint::clone() const | 50 PassRefPtrWillBeRawPtr<SVGPoint> SVGPoint::clone() const |
| 51 { | 51 { |
| 52 return SVGPoint::create(m_value); | 52 return SVGPoint::create(m_value); |
| 53 } | 53 } |
| 54 | 54 |
| 55 template<typename CharType> | 55 template<typename CharType> |
| 56 bool SVGPoint::parse(const CharType*& ptr, const CharType* end) | 56 SVGParsingError SVGPoint::parse(const CharType*& ptr, const CharType* end) |
| 57 { | 57 { |
| 58 skipOptionalSVGSpaces(ptr, end); | 58 float x = 0; |
| 59 | 59 float y = 0; |
| 60 float x = 0.0f; | 60 if (!parseNumber(ptr, end, x) |
| 61 float y = 0.0f; | 61 || !parseNumber(ptr, end, y, DisallowWhitespace)) |
| 62 bool valid = parseNumber(ptr, end, x) && parseNumber(ptr, end, y, DisallowWh
itespace); | 62 return SVGParseStatus::ExpectedNumber; |
| 63 | |
| 64 if (!valid) | |
| 65 return false; | |
| 66 | 63 |
| 67 if (skipOptionalSVGSpaces(ptr, end)) { | 64 if (skipOptionalSVGSpaces(ptr, end)) { |
| 68 // Nothing should come after the second number. | 65 // Nothing should come after the second number. |
| 69 return false; | 66 return SVGParseStatus::TrailingGarbage; |
| 70 } | 67 } |
| 71 | 68 |
| 72 m_value = FloatPoint(x, y); | 69 m_value = FloatPoint(x, y); |
| 73 return true; | 70 return SVGParseStatus::NoError; |
| 74 } | 71 } |
| 75 | 72 |
| 76 FloatPoint SVGPoint::matrixTransform(const AffineTransform& transform) const | 73 FloatPoint SVGPoint::matrixTransform(const AffineTransform& transform) const |
| 77 { | 74 { |
| 78 double newX, newY; | 75 double newX, newY; |
| 79 transform.map(static_cast<double>(x()), static_cast<double>(y()), newX, newY
); | 76 transform.map(static_cast<double>(x()), static_cast<double>(y()), newX, newY
); |
| 80 return FloatPoint::narrowPrecision(newX, newY); | 77 return FloatPoint::narrowPrecision(newX, newY); |
| 81 } | 78 } |
| 82 | 79 |
| 83 SVGParsingError SVGPoint::setValueAsString(const String& string) | 80 SVGParsingError SVGPoint::setValueAsString(const String& string) |
| 84 { | 81 { |
| 85 if (string.isEmpty()) { | 82 if (string.isEmpty()) { |
| 86 m_value = FloatPoint(0.0f, 0.0f); | 83 m_value = FloatPoint(0.0f, 0.0f); |
| 87 return SVGParseStatus::NoError; | 84 return SVGParseStatus::NoError; |
| 88 } | 85 } |
| 89 | 86 |
| 90 bool valid; | |
| 91 if (string.is8Bit()) { | 87 if (string.is8Bit()) { |
| 92 const LChar* ptr = string.characters8(); | 88 const LChar* ptr = string.characters8(); |
| 93 const LChar* end = ptr + string.length(); | 89 const LChar* end = ptr + string.length(); |
| 94 valid = parse(ptr, end); | 90 return parse(ptr, end); |
| 95 } else { | |
| 96 const UChar* ptr = string.characters16(); | |
| 97 const UChar* end = ptr + string.length(); | |
| 98 valid = parse(ptr, end); | |
| 99 } | 91 } |
| 100 return valid ? SVGParseStatus::NoError : SVGParseStatus::ParsingFailed; | 92 const UChar* ptr = string.characters16(); |
| 93 const UChar* end = ptr + string.length(); |
| 94 return parse(ptr, end); |
| 101 } | 95 } |
| 102 | 96 |
| 103 String SVGPoint::valueAsString() const | 97 String SVGPoint::valueAsString() const |
| 104 { | 98 { |
| 105 StringBuilder builder; | 99 StringBuilder builder; |
| 106 builder.appendNumber(x()); | 100 builder.appendNumber(x()); |
| 107 builder.append(' '); | 101 builder.append(' '); |
| 108 builder.appendNumber(y()); | 102 builder.appendNumber(y()); |
| 109 return builder.toString(); | 103 return builder.toString(); |
| 110 } | 104 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 122 } | 116 } |
| 123 | 117 |
| 124 float SVGPoint::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> to, SV
GElement* contextElement) | 118 float SVGPoint::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> to, SV
GElement* contextElement) |
| 125 { | 119 { |
| 126 // SVGPoint is not animated by itself | 120 // SVGPoint is not animated by itself |
| 127 ASSERT_NOT_REACHED(); | 121 ASSERT_NOT_REACHED(); |
| 128 return 0.0f; | 122 return 0.0f; |
| 129 } | 123 } |
| 130 | 124 |
| 131 } | 125 } |
| OLD | NEW |