| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 ASSERT(type != SVGUnitTypes::SVG_UNIT_TYPE_UNKNOWN); | 79 ASSERT(type != SVGUnitTypes::SVG_UNIT_TYPE_UNKNOWN); |
| 80 if (type == SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE) { | 80 if (type == SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE) { |
| 81 SVGLengthContext lengthContext(context); | 81 SVGLengthContext lengthContext(context); |
| 82 return x.value(lengthContext); | 82 return x.value(lengthContext); |
| 83 } | 83 } |
| 84 | 84 |
| 85 // FIXME: valueAsPercentage() won't be correct for eg. cm units. They need t
o be resolved in user space and then be considered in objectBoundingBox space. | 85 // FIXME: valueAsPercentage() won't be correct for eg. cm units. They need t
o be resolved in user space and then be considered in objectBoundingBox space. |
| 86 return x.valueAsPercentage(); | 86 return x.valueAsPercentage(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 float SVGLengthContext::convertValueToUserUnits(float value, SVGLengthMode mode,
SVGLengthType fromUnit, ExceptionState& es) const | 89 float SVGLengthContext::convertValueToUserUnits(float value, SVGLengthMode mode,
SVGLengthType fromUnit, ExceptionState& exceptionState) const |
| 90 { | 90 { |
| 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, exceptionState
); |
| 97 } | 97 } |
| 98 | 98 |
| 99 switch (fromUnit) { | 99 switch (fromUnit) { |
| 100 case LengthTypeUnknown: | 100 case LengthTypeUnknown: |
| 101 es.throwUninformativeAndGenericDOMException(NotSupportedError); | 101 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro
r); |
| 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, exceptio
nState); |
| 109 case LengthTypeEMS: | 109 case LengthTypeEMS: |
| 110 return convertValueFromEMSToUserUnits(value, es); | 110 return convertValueFromEMSToUserUnits(value, exceptionState); |
| 111 case LengthTypeEXS: | 111 case LengthTypeEXS: |
| 112 return convertValueFromEXSToUserUnits(value, es); | 112 return convertValueFromEXSToUserUnits(value, exceptionState); |
| 113 case LengthTypeCM: | 113 case LengthTypeCM: |
| 114 return value * cssPixelsPerInch / 2.54f; | 114 return value * cssPixelsPerInch / 2.54f; |
| 115 case LengthTypeMM: | 115 case LengthTypeMM: |
| 116 return value * cssPixelsPerInch / 25.4f; | 116 return value * cssPixelsPerInch / 25.4f; |
| 117 case LengthTypeIN: | 117 case LengthTypeIN: |
| 118 return value * cssPixelsPerInch; | 118 return value * cssPixelsPerInch; |
| 119 case LengthTypePT: | 119 case LengthTypePT: |
| 120 return value * cssPixelsPerInch / 72; | 120 return value * cssPixelsPerInch / 72; |
| 121 case LengthTypePC: | 121 case LengthTypePC: |
| 122 return value * cssPixelsPerInch / 6; | 122 return value * cssPixelsPerInch / 6; |
| 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& exceptionState) const |
| 130 { | 130 { |
| 131 switch (toUnit) { | 131 switch (toUnit) { |
| 132 case LengthTypeUnknown: | 132 case LengthTypeUnknown: |
| 133 es.throwUninformativeAndGenericDOMException(NotSupportedError); | 133 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro
r); |
| 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, exceptio
nState); |
| 139 case LengthTypeEMS: | 139 case LengthTypeEMS: |
| 140 return convertValueFromUserUnitsToEMS(value, es); | 140 return convertValueFromUserUnitsToEMS(value, exceptionState); |
| 141 case LengthTypeEXS: | 141 case LengthTypeEXS: |
| 142 return convertValueFromUserUnitsToEXS(value, es); | 142 return convertValueFromUserUnitsToEXS(value, exceptionState); |
| 143 case LengthTypePX: | 143 case LengthTypePX: |
| 144 return value; | 144 return value; |
| 145 case LengthTypeCM: | 145 case LengthTypeCM: |
| 146 return value * 2.54f / cssPixelsPerInch; | 146 return value * 2.54f / cssPixelsPerInch; |
| 147 case LengthTypeMM: | 147 case LengthTypeMM: |
| 148 return value * 25.4f / cssPixelsPerInch; | 148 return value * 25.4f / cssPixelsPerInch; |
| 149 case LengthTypeIN: | 149 case LengthTypeIN: |
| 150 return value / cssPixelsPerInch; | 150 return value / cssPixelsPerInch; |
| 151 case LengthTypePT: | 151 case LengthTypePT: |
| 152 return value * 72 / cssPixelsPerInch; | 152 return value * 72 / cssPixelsPerInch; |
| 153 case LengthTypePC: | 153 case LengthTypePC: |
| 154 return value * 6 / cssPixelsPerInch; | 154 return value * 6 / cssPixelsPerInch; |
| 155 } | 155 } |
| 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& exceptionState) const |
| 162 { | 162 { |
| 163 FloatSize viewportSize; | 163 FloatSize viewportSize; |
| 164 if (!determineViewport(viewportSize)) { | 164 if (!determineViewport(viewportSize)) { |
| 165 es.throwUninformativeAndGenericDOMException(NotSupportedError); | 165 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro
r); |
| 166 return 0; | 166 return 0; |
| 167 } | 167 } |
| 168 | 168 |
| 169 switch (mode) { | 169 switch (mode) { |
| 170 case LengthModeWidth: | 170 case LengthModeWidth: |
| 171 return value / viewportSize.width() * 100; | 171 return value / viewportSize.width() * 100; |
| 172 case LengthModeHeight: | 172 case LengthModeHeight: |
| 173 return value / viewportSize.height() * 100; | 173 return value / viewportSize.height() * 100; |
| 174 case LengthModeOther: | 174 case LengthModeOther: |
| 175 return value / sqrtf(viewportSize.diagonalLengthSquared() / 2) * 100; | 175 return value / sqrtf(viewportSize.diagonalLengthSquared() / 2) * 100; |
| 176 }; | 176 }; |
| 177 | 177 |
| 178 ASSERT_NOT_REACHED(); | 178 ASSERT_NOT_REACHED(); |
| 179 return 0; | 179 return 0; |
| 180 } | 180 } |
| 181 | 181 |
| 182 float SVGLengthContext::convertValueFromPercentageToUserUnits(float value, SVGLe
ngthMode mode, ExceptionState& es) const | 182 float SVGLengthContext::convertValueFromPercentageToUserUnits(float value, SVGLe
ngthMode mode, ExceptionState& exceptionState) const |
| 183 { | 183 { |
| 184 FloatSize viewportSize; | 184 FloatSize viewportSize; |
| 185 if (!determineViewport(viewportSize)) { | 185 if (!determineViewport(viewportSize)) { |
| 186 es.throwUninformativeAndGenericDOMException(NotSupportedError); | 186 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro
r); |
| 187 return 0; | 187 return 0; |
| 188 } | 188 } |
| 189 | 189 |
| 190 switch (mode) { | 190 switch (mode) { |
| 191 case LengthModeWidth: | 191 case LengthModeWidth: |
| 192 return value * viewportSize.width(); | 192 return value * viewportSize.width(); |
| 193 case LengthModeHeight: | 193 case LengthModeHeight: |
| 194 return value * viewportSize.height(); | 194 return value * viewportSize.height(); |
| 195 case LengthModeOther: | 195 case LengthModeOther: |
| 196 return value * sqrtf(viewportSize.diagonalLengthSquared() / 2); | 196 return value * sqrtf(viewportSize.diagonalLengthSquared() / 2); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 210 if (currentContext->renderer()) | 210 if (currentContext->renderer()) |
| 211 return currentContext->renderer()->style(); | 211 return currentContext->renderer()->style(); |
| 212 currentContext = currentContext->parentNode(); | 212 currentContext = currentContext->parentNode(); |
| 213 } | 213 } |
| 214 | 214 |
| 215 // There must be at least a RenderSVGRoot renderer, carrying a style. | 215 // There must be at least a RenderSVGRoot renderer, carrying a style. |
| 216 ASSERT_NOT_REACHED(); | 216 ASSERT_NOT_REACHED(); |
| 217 return 0; | 217 return 0; |
| 218 } | 218 } |
| 219 | 219 |
| 220 float SVGLengthContext::convertValueFromUserUnitsToEMS(float value, ExceptionSta
te& es) const | 220 float SVGLengthContext::convertValueFromUserUnitsToEMS(float value, ExceptionSta
te& exceptionState) const |
| 221 { | 221 { |
| 222 RenderStyle* style = renderStyleForLengthResolving(m_context); | 222 RenderStyle* style = renderStyleForLengthResolving(m_context); |
| 223 if (!style) { | 223 if (!style) { |
| 224 es.throwUninformativeAndGenericDOMException(NotSupportedError); | 224 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro
r); |
| 225 return 0; | 225 return 0; |
| 226 } | 226 } |
| 227 | 227 |
| 228 float fontSize = style->specifiedFontSize(); | 228 float fontSize = style->specifiedFontSize(); |
| 229 if (!fontSize) { | 229 if (!fontSize) { |
| 230 es.throwUninformativeAndGenericDOMException(NotSupportedError); | 230 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro
r); |
| 231 return 0; | 231 return 0; |
| 232 } | 232 } |
| 233 | 233 |
| 234 return value / fontSize; | 234 return value / fontSize; |
| 235 } | 235 } |
| 236 | 236 |
| 237 float SVGLengthContext::convertValueFromEMSToUserUnits(float value, ExceptionSta
te& es) const | 237 float SVGLengthContext::convertValueFromEMSToUserUnits(float value, ExceptionSta
te& exceptionState) const |
| 238 { | 238 { |
| 239 RenderStyle* style = renderStyleForLengthResolving(m_context); | 239 RenderStyle* style = renderStyleForLengthResolving(m_context); |
| 240 if (!style) { | 240 if (!style) { |
| 241 es.throwUninformativeAndGenericDOMException(NotSupportedError); | 241 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro
r); |
| 242 return 0; | 242 return 0; |
| 243 } | 243 } |
| 244 | 244 |
| 245 return value * style->specifiedFontSize(); | 245 return value * style->specifiedFontSize(); |
| 246 } | 246 } |
| 247 | 247 |
| 248 float SVGLengthContext::convertValueFromUserUnitsToEXS(float value, ExceptionSta
te& es) const | 248 float SVGLengthContext::convertValueFromUserUnitsToEXS(float value, ExceptionSta
te& exceptionState) const |
| 249 { | 249 { |
| 250 RenderStyle* style = renderStyleForLengthResolving(m_context); | 250 RenderStyle* style = renderStyleForLengthResolving(m_context); |
| 251 if (!style) { | 251 if (!style) { |
| 252 es.throwUninformativeAndGenericDOMException(NotSupportedError); | 252 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro
r); |
| 253 return 0; | 253 return 0; |
| 254 } | 254 } |
| 255 | 255 |
| 256 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un
its-03-b.svg | 256 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un
its-03-b.svg |
| 257 // if this causes problems in real world cases maybe it would be best to rem
ove this | 257 // if this causes problems in real world cases maybe it would be best to rem
ove this |
| 258 float xHeight = ceilf(style->fontMetrics().xHeight()); | 258 float xHeight = ceilf(style->fontMetrics().xHeight()); |
| 259 if (!xHeight) { | 259 if (!xHeight) { |
| 260 es.throwUninformativeAndGenericDOMException(NotSupportedError); | 260 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro
r); |
| 261 return 0; | 261 return 0; |
| 262 } | 262 } |
| 263 | 263 |
| 264 return value / xHeight; | 264 return value / xHeight; |
| 265 } | 265 } |
| 266 | 266 |
| 267 float SVGLengthContext::convertValueFromEXSToUserUnits(float value, ExceptionSta
te& es) const | 267 float SVGLengthContext::convertValueFromEXSToUserUnits(float value, ExceptionSta
te& exceptionState) const |
| 268 { | 268 { |
| 269 RenderStyle* style = renderStyleForLengthResolving(m_context); | 269 RenderStyle* style = renderStyleForLengthResolving(m_context); |
| 270 if (!style) { | 270 if (!style) { |
| 271 es.throwUninformativeAndGenericDOMException(NotSupportedError); | 271 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro
r); |
| 272 return 0; | 272 return 0; |
| 273 } | 273 } |
| 274 | 274 |
| 275 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un
its-03-b.svg | 275 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un
its-03-b.svg |
| 276 // if this causes problems in real world cases maybe it would be best to rem
ove this | 276 // if this causes problems in real world cases maybe it would be best to rem
ove this |
| 277 return value * ceilf(style->fontMetrics().xHeight()); | 277 return value * ceilf(style->fontMetrics().xHeight()); |
| 278 } | 278 } |
| 279 | 279 |
| 280 bool SVGLengthContext::determineViewport(FloatSize& viewportSize) const | 280 bool SVGLengthContext::determineViewport(FloatSize& viewportSize) const |
| 281 { | 281 { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 301 | 301 |
| 302 const SVGSVGElement* svg = static_cast<const SVGSVGElement*>(viewportElement
); | 302 const SVGSVGElement* svg = static_cast<const SVGSVGElement*>(viewportElement
); |
| 303 viewportSize = svg->currentViewBoxRect().size(); | 303 viewportSize = svg->currentViewBoxRect().size(); |
| 304 if (viewportSize.isEmpty()) | 304 if (viewportSize.isEmpty()) |
| 305 viewportSize = svg->currentViewportSize(); | 305 viewportSize = svg->currentViewportSize(); |
| 306 | 306 |
| 307 return true; | 307 return true; |
| 308 } | 308 } |
| 309 | 309 |
| 310 } | 310 } |
| OLD | NEW |