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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 && m_valueInSpecifiedUnits == other.m_valueInSpecifiedUnits; | 159 && m_valueInSpecifiedUnits == other.m_valueInSpecifiedUnits; |
160 } | 160 } |
161 | 161 |
162 float SVGLength::value(const SVGLengthContext& context, ExceptionState& es) cons
t | 162 float SVGLength::value(const SVGLengthContext& context, ExceptionState& es) cons
t |
163 { | 163 { |
164 return context.convertValueToUserUnits(m_valueInSpecifiedUnits, unitMode(),
unitType(), es); | 164 return context.convertValueToUserUnits(m_valueInSpecifiedUnits, unitMode(),
unitType(), es); |
165 } | 165 } |
166 | 166 |
167 void SVGLength::setValue(float value, const SVGLengthContext& context, Exception
State& es) | 167 void SVGLength::setValue(float value, const SVGLengthContext& context, Exception
State& es) |
168 { | 168 { |
169 // 100% = 100.0 instead of 1.0 for historical reasons, this could eventually
be changed | 169 // LengthTypePercentage is represented with 100% = 100.0. Good for accuracy
but could eventually be changed. |
170 if (m_unitType == LengthTypePercentage) | 170 if (m_unitType == LengthTypePercentage) |
171 value = value / 100; | 171 value = value / 100; |
172 | 172 |
173 float convertedValue = context.convertValueFromUserUnits(value, unitMode(),
unitType(), es); | 173 float convertedValue = context.convertValueFromUserUnits(value, unitMode(),
unitType(), es); |
174 if (es.hadException()) | 174 if (es.hadException()) |
175 return; | 175 return; |
176 | 176 |
177 m_valueInSpecifiedUnits = convertedValue; | 177 m_valueInSpecifiedUnits = convertedValue; |
178 } | 178 } |
179 | 179 |
180 void SVGLength::setUnitType(SVGLengthType type) | 180 void SVGLength::setUnitType(SVGLengthType type) |
181 { | 181 { |
182 ASSERT(type != LengthTypeUnknown && type <= LengthTypePC); | 182 ASSERT(type != LengthTypeUnknown && type <= LengthTypePC); |
183 m_unitType = type; | 183 m_unitType = type; |
184 } | 184 } |
185 | 185 |
186 float SVGLength::valueAsPercentage() const | 186 float SVGLength::valueAsPercentage() const |
187 { | 187 { |
188 // 100% = 100.0 instead of 1.0 for historical reasons, this could eventually
be changed | 188 // LengthTypePercentage is represented with 100% = 100.0. Good for accuracy
but could eventually be changed. |
189 if (m_unitType == LengthTypePercentage) | 189 if (m_unitType == LengthTypePercentage) { |
| 190 // Note: This division is a source of floating point inaccuracy. |
190 return m_valueInSpecifiedUnits / 100; | 191 return m_valueInSpecifiedUnits / 100; |
| 192 } |
191 | 193 |
192 return m_valueInSpecifiedUnits; | 194 return m_valueInSpecifiedUnits; |
193 } | 195 } |
194 | 196 |
| 197 float SVGLength::valueAsPercentage100() const |
| 198 { |
| 199 // LengthTypePercentage is represented with 100% = 100.0. Good for accuracy
but could eventually be changed. |
| 200 if (m_unitType == LengthTypePercentage) |
| 201 return m_valueInSpecifiedUnits; |
| 202 |
| 203 return m_valueInSpecifiedUnits * 100; |
| 204 } |
| 205 |
| 206 float SVGLength::scaleByPercentage(float input) const |
| 207 { |
| 208 float result = input * m_valueInSpecifiedUnits; |
| 209 if (m_unitType == LengthTypePercentage) { |
| 210 // Delaying division by 100 as long as possible since it introduces floa
ting point errors. |
| 211 result = result / 100; |
| 212 } |
| 213 return result; |
| 214 } |
| 215 |
195 template<typename CharType> | 216 template<typename CharType> |
196 static bool parseValueInternal(const String& string, float& convertedNumber, SVG
LengthType& type) | 217 static bool parseValueInternal(const String& string, float& convertedNumber, SVG
LengthType& type) |
197 { | 218 { |
198 const CharType* ptr = string.getCharacters<CharType>(); | 219 const CharType* ptr = string.getCharacters<CharType>(); |
199 const CharType* end = ptr + string.length(); | 220 const CharType* end = ptr + string.length(); |
200 | 221 |
201 if (!parseNumber(ptr, end, convertedNumber, AllowLeadingWhitespace)) | 222 if (!parseNumber(ptr, end, convertedNumber, AllowLeadingWhitespace)) |
202 return false; | 223 return false; |
203 | 224 |
204 type = stringToLengthType(ptr, end); | 225 type = stringToLengthType(ptr, end); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 || fromType == LengthTypeUnknown | 417 || fromType == LengthTypeUnknown |
397 || toType == LengthTypeUnknown | 418 || toType == LengthTypeUnknown |
398 || (!from->isZero() && fromType != LengthTypePercentage && toType == Len
gthTypePercentage) | 419 || (!from->isZero() && fromType != LengthTypePercentage && toType == Len
gthTypePercentage) |
399 || (!isZero() && fromType == LengthTypePercentage && toType != LengthTyp
ePercentage) | 420 || (!isZero() && fromType == LengthTypePercentage && toType != LengthTyp
ePercentage) |
400 || (!from->isZero() && !isZero() && (fromType == LengthTypeEMS || fromTy
pe == LengthTypeEXS) && fromType != toType)) | 421 || (!from->isZero() && !isZero() && (fromType == LengthTypeEMS || fromTy
pe == LengthTypeEXS) && fromType != toType)) |
401 return clone(); | 422 return clone(); |
402 | 423 |
403 RefPtrWillBeRawPtr<SVGLength> length = create(); | 424 RefPtrWillBeRawPtr<SVGLength> length = create(); |
404 | 425 |
405 if (fromType == LengthTypePercentage || toType == LengthTypePercentage) { | 426 if (fromType == LengthTypePercentage || toType == LengthTypePercentage) { |
406 float fromPercent = from->valueAsPercentage() * 100; | 427 float fromPercent = from->valueAsPercentage100(); |
407 float toPercent = valueAsPercentage() * 100; | 428 float toPercent = valueAsPercentage100(); |
408 length->newValueSpecifiedUnits(LengthTypePercentage, blink::blend(fromPe
rcent, toPercent, progress)); | 429 length->newValueSpecifiedUnits(LengthTypePercentage, blink::blend(fromPe
rcent, toPercent, progress)); |
409 return length; | 430 return length; |
410 } | 431 } |
411 | 432 |
412 if (fromType == toType || from->isZero() || isZero() || fromType == LengthTy
peEMS || fromType == LengthTypeEXS) { | 433 if (fromType == toType || from->isZero() || isZero() || fromType == LengthTy
peEMS || fromType == LengthTypeEXS) { |
413 float fromValue = from->valueInSpecifiedUnits(); | 434 float fromValue = from->valueInSpecifiedUnits(); |
414 float toValue = valueInSpecifiedUnits(); | 435 float toValue = valueInSpecifiedUnits(); |
415 if (isZero()) | 436 if (isZero()) |
416 length->newValueSpecifiedUnits(fromType, blink::blend(fromValue, toV
alue, progress)); | 437 length->newValueSpecifiedUnits(fromType, blink::blend(fromValue, toV
alue, progress)); |
417 else | 438 else |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 | 482 |
462 float SVGLength::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> toVal
ue, SVGElement* contextElement) | 483 float SVGLength::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> toVal
ue, SVGElement* contextElement) |
463 { | 484 { |
464 SVGLengthContext lengthContext(contextElement); | 485 SVGLengthContext lengthContext(contextElement); |
465 RefPtrWillBeRawPtr<SVGLength> toLength = toSVGLength(toValue); | 486 RefPtrWillBeRawPtr<SVGLength> toLength = toSVGLength(toValue); |
466 | 487 |
467 return fabsf(toLength->value(lengthContext, IGNORE_EXCEPTION) - value(length
Context, IGNORE_EXCEPTION)); | 488 return fabsf(toLength->value(lengthContext, IGNORE_EXCEPTION) - value(length
Context, IGNORE_EXCEPTION)); |
468 } | 489 } |
469 | 490 |
470 } | 491 } |
OLD | NEW |