| 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 float SVGLengthContext::convertValueFromPercentageToUserUnits(float value, SVGLe
ngthMode mode, const FloatSize& viewportSize) | 178 float SVGLengthContext::convertValueFromPercentageToUserUnits(float value, SVGLe
ngthMode mode, const FloatSize& viewportSize) |
| 179 { | 179 { |
| 180 return value * dimensionForLengthMode(mode, viewportSize); | 180 return value * dimensionForLengthMode(mode, viewportSize); |
| 181 } | 181 } |
| 182 | 182 |
| 183 float SVGLengthContext::convertValueFromPercentageToUserUnits(const SVGLength& v
alue, const FloatSize& viewportSize) | 183 float SVGLengthContext::convertValueFromPercentageToUserUnits(const SVGLength& v
alue, const FloatSize& viewportSize) |
| 184 { | 184 { |
| 185 return value.scaleByPercentage(dimensionForLengthMode(value.unitMode(), view
portSize)); | 185 return value.scaleByPercentage(dimensionForLengthMode(value.unitMode(), view
portSize)); |
| 186 } | 186 } |
| 187 | 187 |
| 188 static inline LayoutStyle* layoutStyleForLengthResolving(const SVGElement* conte
xt) | 188 static inline const LayoutStyle* layoutStyleForLengthResolving(const SVGElement*
context) |
| 189 { | 189 { |
| 190 if (!context) | 190 if (!context) |
| 191 return 0; | 191 return 0; |
| 192 | 192 |
| 193 const ContainerNode* currentContext = context; | 193 const ContainerNode* currentContext = context; |
| 194 do { | 194 do { |
| 195 if (currentContext->renderer()) | 195 if (currentContext->renderer()) |
| 196 return currentContext->renderer()->style(); | 196 return currentContext->renderer()->style(); |
| 197 currentContext = currentContext->parentNode(); | 197 currentContext = currentContext->parentNode(); |
| 198 } while (currentContext); | 198 } while (currentContext); |
| 199 | 199 |
| 200 // There must be at least a RenderSVGRoot renderer, carrying a style. | 200 // There must be at least a RenderSVGRoot renderer, carrying a style. |
| 201 ASSERT_NOT_REACHED(); | 201 ASSERT_NOT_REACHED(); |
| 202 return 0; | 202 return 0; |
| 203 } | 203 } |
| 204 | 204 |
| 205 float SVGLengthContext::convertValueFromUserUnitsToEMS(float value) const | 205 float SVGLengthContext::convertValueFromUserUnitsToEMS(float value) const |
| 206 { | 206 { |
| 207 LayoutStyle* style = layoutStyleForLengthResolving(m_context); | 207 const LayoutStyle* style = layoutStyleForLengthResolving(m_context); |
| 208 if (!style) | 208 if (!style) |
| 209 return 0; | 209 return 0; |
| 210 | 210 |
| 211 float fontSize = style->specifiedFontSize(); | 211 float fontSize = style->specifiedFontSize(); |
| 212 if (!fontSize) | 212 if (!fontSize) |
| 213 return 0; | 213 return 0; |
| 214 | 214 |
| 215 return value / fontSize; | 215 return value / fontSize; |
| 216 } | 216 } |
| 217 | 217 |
| 218 float SVGLengthContext::convertValueFromEMSToUserUnits(float value) const | 218 float SVGLengthContext::convertValueFromEMSToUserUnits(float value) const |
| 219 { | 219 { |
| 220 LayoutStyle* style = layoutStyleForLengthResolving(m_context); | 220 const LayoutStyle* style = layoutStyleForLengthResolving(m_context); |
| 221 if (!style) | 221 if (!style) |
| 222 return 0; | 222 return 0; |
| 223 return value * style->specifiedFontSize(); | 223 return value * style->specifiedFontSize(); |
| 224 } | 224 } |
| 225 | 225 |
| 226 float SVGLengthContext::convertValueFromUserUnitsToEXS(float value) const | 226 float SVGLengthContext::convertValueFromUserUnitsToEXS(float value) const |
| 227 { | 227 { |
| 228 LayoutStyle* style = layoutStyleForLengthResolving(m_context); | 228 const LayoutStyle* style = layoutStyleForLengthResolving(m_context); |
| 229 if (!style) | 229 if (!style) |
| 230 return 0; | 230 return 0; |
| 231 | 231 |
| 232 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un
its-03-b.svg | 232 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un
its-03-b.svg |
| 233 // if this causes problems in real world cases maybe it would be best to rem
ove this | 233 // if this causes problems in real world cases maybe it would be best to rem
ove this |
| 234 float xHeight = ceilf(style->fontMetrics().xHeight()); | 234 float xHeight = ceilf(style->fontMetrics().xHeight()); |
| 235 if (!xHeight) | 235 if (!xHeight) |
| 236 return 0; | 236 return 0; |
| 237 | 237 |
| 238 return value / xHeight; | 238 return value / xHeight; |
| 239 } | 239 } |
| 240 | 240 |
| 241 float SVGLengthContext::convertValueFromEXSToUserUnits(float value) const | 241 float SVGLengthContext::convertValueFromEXSToUserUnits(float value) const |
| 242 { | 242 { |
| 243 LayoutStyle* style = layoutStyleForLengthResolving(m_context); | 243 const LayoutStyle* style = layoutStyleForLengthResolving(m_context); |
| 244 if (!style) | 244 if (!style) |
| 245 return 0; | 245 return 0; |
| 246 | 246 |
| 247 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un
its-03-b.svg | 247 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un
its-03-b.svg |
| 248 // if this causes problems in real world cases maybe it would be best to rem
ove this | 248 // if this causes problems in real world cases maybe it would be best to rem
ove this |
| 249 return value * ceilf(style->fontMetrics().xHeight()); | 249 return value * ceilf(style->fontMetrics().xHeight()); |
| 250 } | 250 } |
| 251 | 251 |
| 252 bool SVGLengthContext::determineViewport(FloatSize& viewportSize) const | 252 bool SVGLengthContext::determineViewport(FloatSize& viewportSize) const |
| 253 { | 253 { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 267 | 267 |
| 268 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); | 268 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); |
| 269 viewportSize = svg.currentViewBoxRect().size(); | 269 viewportSize = svg.currentViewBoxRect().size(); |
| 270 if (viewportSize.isEmpty()) | 270 if (viewportSize.isEmpty()) |
| 271 viewportSize = svg.currentViewportSize(); | 271 viewportSize = svg.currentViewportSize(); |
| 272 | 272 |
| 273 return true; | 273 return true; |
| 274 } | 274 } |
| 275 | 275 |
| 276 } | 276 } |
| OLD | NEW |