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. |
11 * | 11 * |
12 * This library is distributed in the hope that it will be useful, | 12 * This library is distributed in the hope that it will be useful, |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Library General Public License for more details. | 15 * Library General Public License for more details. |
16 * | 16 * |
17 * You should have received a copy of the GNU Library General Public License | 17 * You should have received a copy of the GNU Library General Public License |
18 * along with this library; see the file COPYING.LIB. If not, write to | 18 * along with this library; see the file COPYING.LIB. If not, write to |
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 * Boston, MA 02110-1301, USA. | 20 * Boston, MA 02110-1301, USA. |
21 */ | 21 */ |
22 | 22 |
23 #include "config.h" | 23 #include "config.h" |
24 #include "core/svg/SVGLengthContext.h" | 24 #include "core/svg/SVGLengthContext.h" |
25 | 25 |
26 #include "core/css/CSSHelper.h" | 26 #include "core/css/CSSHelper.h" |
27 #include "core/css/CSSPrimitiveValue.h" | 27 #include "core/css/CSSPrimitiveValue.h" |
28 #include "core/dom/NodeLayoutStyle.h" | |
28 #include "core/layout/LayoutObject.h" | 29 #include "core/layout/LayoutObject.h" |
29 #include "core/layout/style/LayoutStyle.h" | 30 #include "core/layout/style/LayoutStyle.h" |
30 #include "core/svg/SVGSVGElement.h" | 31 #include "core/svg/SVGSVGElement.h" |
31 #include "platform/LengthFunctions.h" | 32 #include "platform/LengthFunctions.h" |
32 #include "platform/fonts/FontMetrics.h" | 33 #include "platform/fonts/FontMetrics.h" |
33 | 34 |
34 namespace blink { | 35 namespace blink { |
35 | 36 |
36 static inline float dimensionForLengthMode(SVGLengthMode mode, const FloatSize& viewportSize) | 37 static inline float dimensionForLengthMode(SVGLengthMode mode, const FloatSize& viewportSize) |
37 { | 38 { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 break; | 162 break; |
162 case LengthTypeIN: | 163 case LengthTypeIN: |
163 userUnits = value * cssPixelsPerInch; | 164 userUnits = value * cssPixelsPerInch; |
164 break; | 165 break; |
165 case LengthTypePT: | 166 case LengthTypePT: |
166 userUnits = value * cssPixelsPerPoint; | 167 userUnits = value * cssPixelsPerPoint; |
167 break; | 168 break; |
168 case LengthTypePC: | 169 case LengthTypePC: |
169 userUnits = value * cssPixelsPerPica; | 170 userUnits = value * cssPixelsPerPica; |
170 break; | 171 break; |
172 case LengthTypeREMS: | |
173 userUnits = convertValueFromREMSToUserUnits(value); | |
174 break; | |
171 default: | 175 default: |
172 ASSERT_NOT_REACHED(); | 176 ASSERT_NOT_REACHED(); |
173 break; | 177 break; |
174 } | 178 } |
175 | 179 |
176 // Since we mix css <length> values with svg's length values we need to | 180 // Since we mix css <length> values with svg's length values we need to |
177 // clamp values to the narrowest range, otherwise it can result in | 181 // clamp values to the narrowest range, otherwise it can result in |
178 // rendering issues. | 182 // rendering issues. |
179 return CSSPrimitiveValue::clampToCSSLengthRange(userUnits); | 183 return CSSPrimitiveValue::clampToCSSLengthRange(userUnits); |
180 } | 184 } |
(...skipping 10 matching lines...) Expand all Loading... | |
191 if (!determineViewport(viewportSize)) | 195 if (!determineViewport(viewportSize)) |
192 return 0; | 196 return 0; |
193 // LengthTypePercentage is represented with 100% = 100.0. | 197 // LengthTypePercentage is represented with 100% = 100.0. |
194 // Good for accuracy but could eventually be changed. | 198 // Good for accuracy but could eventually be changed. |
195 return value * 100 / dimensionForLengthMode(mode, viewportSize); | 199 return value * 100 / dimensionForLengthMode(mode, viewportSize); |
196 } | 200 } |
197 case LengthTypeEMS: | 201 case LengthTypeEMS: |
198 return convertValueFromUserUnitsToEMS(value); | 202 return convertValueFromUserUnitsToEMS(value); |
199 case LengthTypeEXS: | 203 case LengthTypeEXS: |
200 return convertValueFromUserUnitsToEXS(value); | 204 return convertValueFromUserUnitsToEXS(value); |
205 case LengthTypeREMS: | |
206 return convertValueFromUserUnitsToREMS(value); | |
201 case LengthTypePX: | 207 case LengthTypePX: |
202 return value; | 208 return value; |
203 case LengthTypeCM: | 209 case LengthTypeCM: |
204 return value / cssPixelsPerCentimeter; | 210 return value / cssPixelsPerCentimeter; |
205 case LengthTypeMM: | 211 case LengthTypeMM: |
206 return value / cssPixelsPerMillimeter; | 212 return value / cssPixelsPerMillimeter; |
207 case LengthTypeIN: | 213 case LengthTypeIN: |
208 return value / cssPixelsPerInch; | 214 return value / cssPixelsPerInch; |
209 case LengthTypePT: | 215 case LengthTypePT: |
210 return value / cssPixelsPerPoint; | 216 return value / cssPixelsPerPoint; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 } | 253 } |
248 | 254 |
249 float SVGLengthContext::convertValueFromEMSToUserUnits(float value) const | 255 float SVGLengthContext::convertValueFromEMSToUserUnits(float value) const |
250 { | 256 { |
251 const LayoutStyle* style = layoutStyleForLengthResolving(m_context); | 257 const LayoutStyle* style = layoutStyleForLengthResolving(m_context); |
252 if (!style) | 258 if (!style) |
253 return 0; | 259 return 0; |
254 return value * style->specifiedFontSize(); | 260 return value * style->specifiedFontSize(); |
255 } | 261 } |
256 | 262 |
263 float SVGLengthContext::convertValueFromUserUnitsToREMS(float value) const | |
264 { | |
265 if (!m_context) | |
266 return 0; | |
267 | |
268 const LayoutStyle* style = 0; | |
269 const ContainerNode* currentContext = m_context; | |
270 | |
271 do { | |
272 if (currentContext->layoutObject()) { | |
273 const Document& document = currentContext->layoutObject()->document( ); | |
274 Node* documentElement = document.documentElement(); | |
275 const LayoutStyle* documentStyle = document.layoutStyle(); | |
276 style = documentElement && !currentContext->layoutObject()->isDocume ntElement() ? documentElement->layoutStyle() : documentStyle; | |
277 break; | |
278 } | |
279 currentContext = currentContext->parentNode(); | |
280 } while (currentContext); | |
281 | |
282 if (!style) | |
283 return 0; | |
284 | |
285 float fontSize = style->specifiedFontSize(); | |
286 if (!fontSize) | |
287 return 0; | |
288 | |
289 return value / fontSize; | |
290 } | |
291 | |
292 float SVGLengthContext::convertValueFromREMSToUserUnits(float value) const | |
293 { | |
294 if (!m_context) | |
295 return 0; | |
296 | |
297 const LayoutStyle* style = 0; | |
298 const ContainerNode* currentContext = m_context; | |
299 | |
300 do { | |
301 if (currentContext->layoutObject()) { | |
302 const Document& document = currentContext->layoutObject()->document( ); | |
Erik Dahlström (inactive)
2015/03/31 09:20:50
This warrants another test, along the lines of the
Shanmuga Pandi
2015/04/01 15:01:37
I had checked this test case, and found test.svg r
Erik Dahlström (inactive)
2015/04/02 07:58:40
Ok, I suspected that it would be broken for that c
| |
303 Node* documentElement = document.documentElement(); | |
304 const LayoutStyle* documentStyle = document.layoutStyle(); | |
305 style = documentElement && !currentContext->layoutObject()->isDocume ntElement() ? documentElement->layoutStyle() : documentStyle; | |
306 break; | |
307 } | |
308 currentContext = currentContext->parentNode(); | |
309 } while (currentContext); | |
310 | |
311 if (!style) | |
312 return 0; | |
313 return value * style->specifiedFontSize(); | |
314 } | |
315 | |
257 float SVGLengthContext::convertValueFromUserUnitsToEXS(float value) const | 316 float SVGLengthContext::convertValueFromUserUnitsToEXS(float value) const |
258 { | 317 { |
259 const LayoutStyle* style = layoutStyleForLengthResolving(m_context); | 318 const LayoutStyle* style = layoutStyleForLengthResolving(m_context); |
260 if (!style) | 319 if (!style) |
261 return 0; | 320 return 0; |
262 | 321 |
263 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un its-03-b.svg | 322 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un its-03-b.svg |
264 // if this causes problems in real world cases maybe it would be best to rem ove this | 323 // if this causes problems in real world cases maybe it would be best to rem ove this |
265 float xHeight = ceilf(style->fontMetrics().xHeight()); | 324 float xHeight = ceilf(style->fontMetrics().xHeight()); |
266 if (!xHeight) | 325 if (!xHeight) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 | 357 |
299 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); | 358 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); |
300 viewportSize = svg.currentViewBoxRect().size(); | 359 viewportSize = svg.currentViewBoxRect().size(); |
301 if (viewportSize.isEmpty()) | 360 if (viewportSize.isEmpty()) |
302 viewportSize = svg.currentViewportSize(); | 361 viewportSize = svg.currentViewportSize(); |
303 | 362 |
304 return true; | 363 return true; |
305 } | 364 } |
306 | 365 |
307 } | 366 } |
OLD | NEW |