| 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 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 5 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
| 6 * | 6 * |
| 7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 // If the SVGLengthContext carries a custom viewport, force resolving agains
t it. | 91 // If the SVGLengthContext carries a custom viewport, force resolving agains
t it. |
| 92 if (!m_overridenViewport.isEmpty()) { | 92 if (!m_overridenViewport.isEmpty()) { |
| 93 // 100% = 100.0 instead of 1.0 for historical reasons, this could eventu
ally be changed | 93 // 100% = 100.0 instead of 1.0 for historical reasons, this could eventu
ally be changed |
| 94 if (fromUnit == LengthTypePercentage) | 94 if (fromUnit == LengthTypePercentage) |
| 95 value /= 100; | 95 value /= 100; |
| 96 return convertValueFromPercentageToUserUnits(value, mode, es); | 96 return convertValueFromPercentageToUserUnits(value, mode, es); |
| 97 } | 97 } |
| 98 | 98 |
| 99 switch (fromUnit) { | 99 switch (fromUnit) { |
| 100 case LengthTypeUnknown: | 100 case LengthTypeUnknown: |
| 101 es.throwDOMException(NotSupportedError); | 101 es.throwUninformativeAndGenericDOMException(NotSupportedError); |
| 102 return 0; | 102 return 0; |
| 103 case LengthTypeNumber: | 103 case LengthTypeNumber: |
| 104 return value; | 104 return value; |
| 105 case LengthTypePX: | 105 case LengthTypePX: |
| 106 return value; | 106 return value; |
| 107 case LengthTypePercentage: | 107 case LengthTypePercentage: |
| 108 return convertValueFromPercentageToUserUnits(value / 100, mode, es); | 108 return convertValueFromPercentageToUserUnits(value / 100, mode, es); |
| 109 case LengthTypeEMS: | 109 case LengthTypeEMS: |
| 110 return convertValueFromEMSToUserUnits(value, es); | 110 return convertValueFromEMSToUserUnits(value, es); |
| 111 case LengthTypeEXS: | 111 case LengthTypeEXS: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 123 } | 123 } |
| 124 | 124 |
| 125 ASSERT_NOT_REACHED(); | 125 ASSERT_NOT_REACHED(); |
| 126 return 0; | 126 return 0; |
| 127 } | 127 } |
| 128 | 128 |
| 129 float SVGLengthContext::convertValueFromUserUnits(float value, SVGLengthMode mod
e, SVGLengthType toUnit, ExceptionState& es) const | 129 float SVGLengthContext::convertValueFromUserUnits(float value, SVGLengthMode mod
e, SVGLengthType toUnit, ExceptionState& es) const |
| 130 { | 130 { |
| 131 switch (toUnit) { | 131 switch (toUnit) { |
| 132 case LengthTypeUnknown: | 132 case LengthTypeUnknown: |
| 133 es.throwDOMException(NotSupportedError); | 133 es.throwUninformativeAndGenericDOMException(NotSupportedError); |
| 134 return 0; | 134 return 0; |
| 135 case LengthTypeNumber: | 135 case LengthTypeNumber: |
| 136 return value; | 136 return value; |
| 137 case LengthTypePercentage: | 137 case LengthTypePercentage: |
| 138 return convertValueFromUserUnitsToPercentage(value * 100, mode, es); | 138 return convertValueFromUserUnitsToPercentage(value * 100, mode, es); |
| 139 case LengthTypeEMS: | 139 case LengthTypeEMS: |
| 140 return convertValueFromUserUnitsToEMS(value, es); | 140 return convertValueFromUserUnitsToEMS(value, es); |
| 141 case LengthTypeEXS: | 141 case LengthTypeEXS: |
| 142 return convertValueFromUserUnitsToEXS(value, es); | 142 return convertValueFromUserUnitsToEXS(value, es); |
| 143 case LengthTypePX: | 143 case LengthTypePX: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 156 | 156 |
| 157 ASSERT_NOT_REACHED(); | 157 ASSERT_NOT_REACHED(); |
| 158 return 0; | 158 return 0; |
| 159 } | 159 } |
| 160 | 160 |
| 161 float SVGLengthContext::convertValueFromUserUnitsToPercentage(float value, SVGLe
ngthMode mode, ExceptionState& es) const | 161 float SVGLengthContext::convertValueFromUserUnitsToPercentage(float value, SVGLe
ngthMode mode, ExceptionState& es) const |
| 162 { | 162 { |
| 163 float width = 0; | 163 float width = 0; |
| 164 float height = 0; | 164 float height = 0; |
| 165 if (!determineViewport(width, height)) { | 165 if (!determineViewport(width, height)) { |
| 166 es.throwDOMException(NotSupportedError); | 166 es.throwUninformativeAndGenericDOMException(NotSupportedError); |
| 167 return 0; | 167 return 0; |
| 168 } | 168 } |
| 169 | 169 |
| 170 switch (mode) { | 170 switch (mode) { |
| 171 case LengthModeWidth: | 171 case LengthModeWidth: |
| 172 return value / width * 100; | 172 return value / width * 100; |
| 173 case LengthModeHeight: | 173 case LengthModeHeight: |
| 174 return value / height * 100; | 174 return value / height * 100; |
| 175 case LengthModeOther: | 175 case LengthModeOther: |
| 176 return value / (sqrtf((width * width + height * height) / 2)) * 100; | 176 return value / (sqrtf((width * width + height * height) / 2)) * 100; |
| 177 }; | 177 }; |
| 178 | 178 |
| 179 ASSERT_NOT_REACHED(); | 179 ASSERT_NOT_REACHED(); |
| 180 return 0; | 180 return 0; |
| 181 } | 181 } |
| 182 | 182 |
| 183 float SVGLengthContext::convertValueFromPercentageToUserUnits(float value, SVGLe
ngthMode mode, ExceptionState& es) const | 183 float SVGLengthContext::convertValueFromPercentageToUserUnits(float value, SVGLe
ngthMode mode, ExceptionState& es) const |
| 184 { | 184 { |
| 185 float width = 0; | 185 float width = 0; |
| 186 float height = 0; | 186 float height = 0; |
| 187 if (!determineViewport(width, height)) { | 187 if (!determineViewport(width, height)) { |
| 188 es.throwDOMException(NotSupportedError); | 188 es.throwUninformativeAndGenericDOMException(NotSupportedError); |
| 189 return 0; | 189 return 0; |
| 190 } | 190 } |
| 191 | 191 |
| 192 switch (mode) { | 192 switch (mode) { |
| 193 case LengthModeWidth: | 193 case LengthModeWidth: |
| 194 return value * width; | 194 return value * width; |
| 195 case LengthModeHeight: | 195 case LengthModeHeight: |
| 196 return value * height; | 196 return value * height; |
| 197 case LengthModeOther: | 197 case LengthModeOther: |
| 198 return value * sqrtf((width * width + height * height) / 2); | 198 return value * sqrtf((width * width + height * height) / 2); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 216 | 216 |
| 217 // There must be at least a RenderSVGRoot renderer, carrying a style. | 217 // There must be at least a RenderSVGRoot renderer, carrying a style. |
| 218 ASSERT_NOT_REACHED(); | 218 ASSERT_NOT_REACHED(); |
| 219 return 0; | 219 return 0; |
| 220 } | 220 } |
| 221 | 221 |
| 222 float SVGLengthContext::convertValueFromUserUnitsToEMS(float value, ExceptionSta
te& es) const | 222 float SVGLengthContext::convertValueFromUserUnitsToEMS(float value, ExceptionSta
te& es) const |
| 223 { | 223 { |
| 224 RenderStyle* style = renderStyleForLengthResolving(m_context); | 224 RenderStyle* style = renderStyleForLengthResolving(m_context); |
| 225 if (!style) { | 225 if (!style) { |
| 226 es.throwDOMException(NotSupportedError); | 226 es.throwUninformativeAndGenericDOMException(NotSupportedError); |
| 227 return 0; | 227 return 0; |
| 228 } | 228 } |
| 229 | 229 |
| 230 float fontSize = style->specifiedFontSize(); | 230 float fontSize = style->specifiedFontSize(); |
| 231 if (!fontSize) { | 231 if (!fontSize) { |
| 232 es.throwDOMException(NotSupportedError); | 232 es.throwUninformativeAndGenericDOMException(NotSupportedError); |
| 233 return 0; | 233 return 0; |
| 234 } | 234 } |
| 235 | 235 |
| 236 return value / fontSize; | 236 return value / fontSize; |
| 237 } | 237 } |
| 238 | 238 |
| 239 float SVGLengthContext::convertValueFromEMSToUserUnits(float value, ExceptionSta
te& es) const | 239 float SVGLengthContext::convertValueFromEMSToUserUnits(float value, ExceptionSta
te& es) const |
| 240 { | 240 { |
| 241 RenderStyle* style = renderStyleForLengthResolving(m_context); | 241 RenderStyle* style = renderStyleForLengthResolving(m_context); |
| 242 if (!style) { | 242 if (!style) { |
| 243 es.throwDOMException(NotSupportedError); | 243 es.throwUninformativeAndGenericDOMException(NotSupportedError); |
| 244 return 0; | 244 return 0; |
| 245 } | 245 } |
| 246 | 246 |
| 247 return value * style->specifiedFontSize(); | 247 return value * style->specifiedFontSize(); |
| 248 } | 248 } |
| 249 | 249 |
| 250 float SVGLengthContext::convertValueFromUserUnitsToEXS(float value, ExceptionSta
te& es) const | 250 float SVGLengthContext::convertValueFromUserUnitsToEXS(float value, ExceptionSta
te& es) const |
| 251 { | 251 { |
| 252 RenderStyle* style = renderStyleForLengthResolving(m_context); | 252 RenderStyle* style = renderStyleForLengthResolving(m_context); |
| 253 if (!style) { | 253 if (!style) { |
| 254 es.throwDOMException(NotSupportedError); | 254 es.throwUninformativeAndGenericDOMException(NotSupportedError); |
| 255 return 0; | 255 return 0; |
| 256 } | 256 } |
| 257 | 257 |
| 258 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un
its-03-b.svg | 258 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un
its-03-b.svg |
| 259 // if this causes problems in real world cases maybe it would be best to rem
ove this | 259 // if this causes problems in real world cases maybe it would be best to rem
ove this |
| 260 float xHeight = ceilf(style->fontMetrics().xHeight()); | 260 float xHeight = ceilf(style->fontMetrics().xHeight()); |
| 261 if (!xHeight) { | 261 if (!xHeight) { |
| 262 es.throwDOMException(NotSupportedError); | 262 es.throwUninformativeAndGenericDOMException(NotSupportedError); |
| 263 return 0; | 263 return 0; |
| 264 } | 264 } |
| 265 | 265 |
| 266 return value / xHeight; | 266 return value / xHeight; |
| 267 } | 267 } |
| 268 | 268 |
| 269 float SVGLengthContext::convertValueFromEXSToUserUnits(float value, ExceptionSta
te& es) const | 269 float SVGLengthContext::convertValueFromEXSToUserUnits(float value, ExceptionSta
te& es) const |
| 270 { | 270 { |
| 271 RenderStyle* style = renderStyleForLengthResolving(m_context); | 271 RenderStyle* style = renderStyleForLengthResolving(m_context); |
| 272 if (!style) { | 272 if (!style) { |
| 273 es.throwDOMException(NotSupportedError); | 273 es.throwUninformativeAndGenericDOMException(NotSupportedError); |
| 274 return 0; | 274 return 0; |
| 275 } | 275 } |
| 276 | 276 |
| 277 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un
its-03-b.svg | 277 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un
its-03-b.svg |
| 278 // if this causes problems in real world cases maybe it would be best to rem
ove this | 278 // if this causes problems in real world cases maybe it would be best to rem
ove this |
| 279 return value * ceilf(style->fontMetrics().xHeight()); | 279 return value * ceilf(style->fontMetrics().xHeight()); |
| 280 } | 280 } |
| 281 | 281 |
| 282 bool SVGLengthContext::determineViewport(float& width, float& height) const | 282 bool SVGLengthContext::determineViewport(float& width, float& height) const |
| 283 { | 283 { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 304 FloatSize viewportSize = svg->currentViewBoxRect().size(); | 304 FloatSize viewportSize = svg->currentViewBoxRect().size(); |
| 305 if (viewportSize.isEmpty()) | 305 if (viewportSize.isEmpty()) |
| 306 viewportSize = svg->currentViewportSize(); | 306 viewportSize = svg->currentViewportSize(); |
| 307 | 307 |
| 308 width = viewportSize.width(); | 308 width = viewportSize.width(); |
| 309 height = viewportSize.height(); | 309 height = viewportSize.height(); |
| 310 return true; | 310 return true; |
| 311 } | 311 } |
| 312 | 312 |
| 313 } | 313 } |
| OLD | NEW |