| 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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 case LengthModeHeight: | 209 case LengthModeHeight: |
| 210 return value.scaleByPercentage(viewportSize.height()); | 210 return value.scaleByPercentage(viewportSize.height()); |
| 211 case LengthModeOther: | 211 case LengthModeOther: |
| 212 return value.scaleByPercentage(sqrtf(viewportSize.diagonalLengthSquared(
) / 2)); | 212 return value.scaleByPercentage(sqrtf(viewportSize.diagonalLengthSquared(
) / 2)); |
| 213 } | 213 } |
| 214 | 214 |
| 215 ASSERT_NOT_REACHED(); | 215 ASSERT_NOT_REACHED(); |
| 216 return 0; | 216 return 0; |
| 217 } | 217 } |
| 218 | 218 |
| 219 static inline RenderStyle* renderStyleForLengthResolving(const SVGElement* conte
xt) | 219 static inline const RenderStyle* renderStyleForLengthResolving(const SVGElement*
context) |
| 220 { | 220 { |
| 221 if (!context) | 221 if (!context) |
| 222 return 0; | 222 return 0; |
| 223 | 223 |
| 224 const ContainerNode* currentContext = context; | 224 const ContainerNode* currentContext = context; |
| 225 do { | 225 do { |
| 226 if (currentContext->renderer()) | 226 if (currentContext->renderer()) |
| 227 return currentContext->renderer()->style(); | 227 return currentContext->renderer()->style(); |
| 228 currentContext = currentContext->parentNode(); | 228 currentContext = currentContext->parentNode(); |
| 229 } while (currentContext); | 229 } while (currentContext); |
| 230 | 230 |
| 231 // There must be at least a RenderSVGRoot renderer, carrying a style. | 231 // There must be at least a RenderSVGRoot renderer, carrying a style. |
| 232 ASSERT_NOT_REACHED(); | 232 ASSERT_NOT_REACHED(); |
| 233 return 0; | 233 return 0; |
| 234 } | 234 } |
| 235 | 235 |
| 236 float SVGLengthContext::convertValueFromUserUnitsToEMS(float value, ExceptionSta
te& exceptionState) const | 236 float SVGLengthContext::convertValueFromUserUnitsToEMS(float value, ExceptionSta
te& exceptionState) const |
| 237 { | 237 { |
| 238 RenderStyle* style = renderStyleForLengthResolving(m_context); | 238 const RenderStyle* style = renderStyleForLengthResolving(m_context); |
| 239 if (!style) { | 239 if (!style) { |
| 240 exceptionState.throwDOMException(NotSupportedError, "No context could be
found."); | 240 exceptionState.throwDOMException(NotSupportedError, "No context could be
found."); |
| 241 return 0; | 241 return 0; |
| 242 } | 242 } |
| 243 | 243 |
| 244 float fontSize = style->specifiedFontSize(); | 244 float fontSize = style->specifiedFontSize(); |
| 245 if (!fontSize) { | 245 if (!fontSize) { |
| 246 exceptionState.throwDOMException(NotSupportedError, "No font-size could
be determined."); | 246 exceptionState.throwDOMException(NotSupportedError, "No font-size could
be determined."); |
| 247 return 0; | 247 return 0; |
| 248 } | 248 } |
| 249 | 249 |
| 250 return value / fontSize; | 250 return value / fontSize; |
| 251 } | 251 } |
| 252 | 252 |
| 253 float SVGLengthContext::convertValueFromEMSToUserUnits(float value, ExceptionSta
te& exceptionState) const | 253 float SVGLengthContext::convertValueFromEMSToUserUnits(float value, ExceptionSta
te& exceptionState) const |
| 254 { | 254 { |
| 255 RenderStyle* style = renderStyleForLengthResolving(m_context); | 255 const RenderStyle* style = renderStyleForLengthResolving(m_context); |
| 256 if (!style) { | 256 if (!style) { |
| 257 exceptionState.throwDOMException(NotSupportedError, "No context could be
found."); | 257 exceptionState.throwDOMException(NotSupportedError, "No context could be
found."); |
| 258 return 0; | 258 return 0; |
| 259 } | 259 } |
| 260 | 260 |
| 261 return value * style->specifiedFontSize(); | 261 return value * style->specifiedFontSize(); |
| 262 } | 262 } |
| 263 | 263 |
| 264 float SVGLengthContext::convertValueFromUserUnitsToEXS(float value, ExceptionSta
te& exceptionState) const | 264 float SVGLengthContext::convertValueFromUserUnitsToEXS(float value, ExceptionSta
te& exceptionState) const |
| 265 { | 265 { |
| 266 RenderStyle* style = renderStyleForLengthResolving(m_context); | 266 const RenderStyle* style = renderStyleForLengthResolving(m_context); |
| 267 if (!style) { | 267 if (!style) { |
| 268 exceptionState.throwDOMException(NotSupportedError, "No context could be
found."); | 268 exceptionState.throwDOMException(NotSupportedError, "No context could be
found."); |
| 269 return 0; | 269 return 0; |
| 270 } | 270 } |
| 271 | 271 |
| 272 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un
its-03-b.svg | 272 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un
its-03-b.svg |
| 273 // if this causes problems in real world cases maybe it would be best to rem
ove this | 273 // if this causes problems in real world cases maybe it would be best to rem
ove this |
| 274 float xHeight = ceilf(style->fontMetrics().xHeight()); | 274 float xHeight = ceilf(style->fontMetrics().xHeight()); |
| 275 if (!xHeight) { | 275 if (!xHeight) { |
| 276 exceptionState.throwDOMException(NotSupportedError, "No x-height could b
e determined."); | 276 exceptionState.throwDOMException(NotSupportedError, "No x-height could b
e determined."); |
| 277 return 0; | 277 return 0; |
| 278 } | 278 } |
| 279 | 279 |
| 280 return value / xHeight; | 280 return value / xHeight; |
| 281 } | 281 } |
| 282 | 282 |
| 283 float SVGLengthContext::convertValueFromEXSToUserUnits(float value, ExceptionSta
te& exceptionState) const | 283 float SVGLengthContext::convertValueFromEXSToUserUnits(float value, ExceptionSta
te& exceptionState) const |
| 284 { | 284 { |
| 285 RenderStyle* style = renderStyleForLengthResolving(m_context); | 285 const RenderStyle* style = renderStyleForLengthResolving(m_context); |
| 286 if (!style) { | 286 if (!style) { |
| 287 exceptionState.throwDOMException(NotSupportedError, "No context could be
found."); | 287 exceptionState.throwDOMException(NotSupportedError, "No context could be
found."); |
| 288 return 0; | 288 return 0; |
| 289 } | 289 } |
| 290 | 290 |
| 291 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un
its-03-b.svg | 291 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un
its-03-b.svg |
| 292 // if this causes problems in real world cases maybe it would be best to rem
ove this | 292 // if this causes problems in real world cases maybe it would be best to rem
ove this |
| 293 return value * ceilf(style->fontMetrics().xHeight()); | 293 return value * ceilf(style->fontMetrics().xHeight()); |
| 294 } | 294 } |
| 295 | 295 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 311 | 311 |
| 312 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); | 312 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); |
| 313 viewportSize = svg.currentViewBoxRect().size(); | 313 viewportSize = svg.currentViewBoxRect().size(); |
| 314 if (viewportSize.isEmpty()) | 314 if (viewportSize.isEmpty()) |
| 315 viewportSize = svg.currentViewportSize(); | 315 viewportSize = svg.currentViewportSize(); |
| 316 | 316 |
| 317 return true; | 317 return true; |
| 318 } | 318 } |
| 319 | 319 |
| 320 } | 320 } |
| OLD | NEW |