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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 break; | 213 break; |
214 case LengthTypePT: | 214 case LengthTypePT: |
215 userUnits = value * cssPixelsPerPoint; | 215 userUnits = value * cssPixelsPerPoint; |
216 break; | 216 break; |
217 case LengthTypePC: | 217 case LengthTypePC: |
218 userUnits = value * cssPixelsPerPica; | 218 userUnits = value * cssPixelsPerPica; |
219 break; | 219 break; |
220 case LengthTypeREMS: | 220 case LengthTypeREMS: |
221 userUnits = convertValueFromEMSToUserUnits(rootElementStyle(m_context),
value); | 221 userUnits = convertValueFromEMSToUserUnits(rootElementStyle(m_context),
value); |
222 break; | 222 break; |
| 223 case LengthTypeCHS: |
| 224 userUnits = convertValueFromCHSToUserUnits(value); |
| 225 break; |
223 default: | 226 default: |
224 ASSERT_NOT_REACHED(); | 227 ASSERT_NOT_REACHED(); |
225 break; | 228 break; |
226 } | 229 } |
227 | 230 |
228 // Since we mix css <length> values with svg's length values we need to | 231 // Since we mix css <length> values with svg's length values we need to |
229 // clamp values to the narrowest range, otherwise it can result in | 232 // clamp values to the narrowest range, otherwise it can result in |
230 // rendering issues. | 233 // rendering issues. |
231 return CSSPrimitiveValue::clampToCSSLengthRange(userUnits); | 234 return CSSPrimitiveValue::clampToCSSLengthRange(userUnits); |
232 } | 235 } |
(...skipping 12 matching lines...) Expand all Loading... |
245 // LengthTypePercentage is represented with 100% = 100.0. | 248 // LengthTypePercentage is represented with 100% = 100.0. |
246 // Good for accuracy but could eventually be changed. | 249 // Good for accuracy but could eventually be changed. |
247 return value * 100 / dimensionForLengthMode(mode, viewportSize); | 250 return value * 100 / dimensionForLengthMode(mode, viewportSize); |
248 } | 251 } |
249 case LengthTypeEMS: | 252 case LengthTypeEMS: |
250 return convertValueFromUserUnitsToEMS(computedStyleForLengthResolving(m_
context), value); | 253 return convertValueFromUserUnitsToEMS(computedStyleForLengthResolving(m_
context), value); |
251 case LengthTypeEXS: | 254 case LengthTypeEXS: |
252 return convertValueFromUserUnitsToEXS(value); | 255 return convertValueFromUserUnitsToEXS(value); |
253 case LengthTypeREMS: | 256 case LengthTypeREMS: |
254 return convertValueFromUserUnitsToEMS(rootElementStyle(m_context), value
); | 257 return convertValueFromUserUnitsToEMS(rootElementStyle(m_context), value
); |
| 258 case LengthTypeCHS: |
| 259 return convertValueFromUserUnitsToCHS(value); |
255 case LengthTypePX: | 260 case LengthTypePX: |
256 return value; | 261 return value; |
257 case LengthTypeCM: | 262 case LengthTypeCM: |
258 return value / cssPixelsPerCentimeter; | 263 return value / cssPixelsPerCentimeter; |
259 case LengthTypeMM: | 264 case LengthTypeMM: |
260 return value / cssPixelsPerMillimeter; | 265 return value / cssPixelsPerMillimeter; |
261 case LengthTypeIN: | 266 case LengthTypeIN: |
262 return value / cssPixelsPerInch; | 267 return value / cssPixelsPerInch; |
263 case LengthTypePT: | 268 case LengthTypePT: |
264 return value / cssPixelsPerPoint; | 269 return value / cssPixelsPerPoint; |
265 case LengthTypePC: | 270 case LengthTypePC: |
266 return value / cssPixelsPerPica; | 271 return value / cssPixelsPerPica; |
267 } | 272 } |
268 | 273 |
269 ASSERT_NOT_REACHED(); | 274 ASSERT_NOT_REACHED(); |
270 return 0; | 275 return 0; |
271 } | 276 } |
272 | 277 |
| 278 float SVGLengthContext::convertValueFromUserUnitsToCHS(float value) const |
| 279 { |
| 280 const ComputedStyle* style = computedStyleForLengthResolving(m_context); |
| 281 if (!style) |
| 282 return 0; |
| 283 |
| 284 float zeroWidth = style->fontMetrics().zeroWidth(); |
| 285 if (!zeroWidth) |
| 286 return 0; |
| 287 |
| 288 return value / zeroWidth; |
| 289 } |
| 290 |
| 291 float SVGLengthContext::convertValueFromCHSToUserUnits(float value) const |
| 292 { |
| 293 const ComputedStyle* style = computedStyleForLengthResolving(m_context); |
| 294 if (!style) |
| 295 return 0; |
| 296 |
| 297 return value * style->fontMetrics().zeroWidth(); |
| 298 } |
| 299 |
273 float SVGLengthContext::convertValueFromUserUnitsToEXS(float value) const | 300 float SVGLengthContext::convertValueFromUserUnitsToEXS(float value) const |
274 { | 301 { |
275 const ComputedStyle* style = computedStyleForLengthResolving(m_context); | 302 const ComputedStyle* style = computedStyleForLengthResolving(m_context); |
276 if (!style) | 303 if (!style) |
277 return 0; | 304 return 0; |
278 | 305 |
279 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un
its-03-b.svg | 306 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un
its-03-b.svg |
280 // if this causes problems in real world cases maybe it would be best to rem
ove this | 307 // if this causes problems in real world cases maybe it would be best to rem
ove this |
281 float xHeight = ceilf(style->fontMetrics().xHeight()); | 308 float xHeight = ceilf(style->fontMetrics().xHeight()); |
282 if (!xHeight) | 309 if (!xHeight) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 | 341 |
315 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); | 342 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); |
316 viewportSize = svg.currentViewBoxRect().size(); | 343 viewportSize = svg.currentViewBoxRect().size(); |
317 if (viewportSize.isEmpty()) | 344 if (viewportSize.isEmpty()) |
318 viewportSize = svg.currentViewportSize(); | 345 viewportSize = svg.currentViewportSize(); |
319 | 346 |
320 return true; | 347 return true; |
321 } | 348 } |
322 | 349 |
323 } | 350 } |
OLD | NEW |