Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: Source/core/svg/SVGLengthContext.cpp

Issue 1073803002: SVG doesn't recognize ch units. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Changed font-familt from serif to Ahem and align with review comments Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 break; 165 break;
166 case LengthTypePT: 166 case LengthTypePT:
167 userUnits = value * cssPixelsPerPoint; 167 userUnits = value * cssPixelsPerPoint;
168 break; 168 break;
169 case LengthTypePC: 169 case LengthTypePC:
170 userUnits = value * cssPixelsPerPica; 170 userUnits = value * cssPixelsPerPica;
171 break; 171 break;
172 case LengthTypeREMS: 172 case LengthTypeREMS:
173 userUnits = convertValueFromREMSToUserUnits(value); 173 userUnits = convertValueFromREMSToUserUnits(value);
174 break; 174 break;
175 case LengthTypeCHS:
176 userUnits = convertValueFromCHSToUserUnits(value);
177 break;
175 default: 178 default:
176 ASSERT_NOT_REACHED(); 179 ASSERT_NOT_REACHED();
177 break; 180 break;
178 } 181 }
179 182
180 // Since we mix css <length> values with svg's length values we need to 183 // Since we mix css <length> values with svg's length values we need to
181 // clamp values to the narrowest range, otherwise it can result in 184 // clamp values to the narrowest range, otherwise it can result in
182 // rendering issues. 185 // rendering issues.
183 return CSSPrimitiveValue::clampToCSSLengthRange(userUnits); 186 return CSSPrimitiveValue::clampToCSSLengthRange(userUnits);
184 } 187 }
(...skipping 12 matching lines...) Expand all
197 // LengthTypePercentage is represented with 100% = 100.0. 200 // LengthTypePercentage is represented with 100% = 100.0.
198 // Good for accuracy but could eventually be changed. 201 // Good for accuracy but could eventually be changed.
199 return value * 100 / dimensionForLengthMode(mode, viewportSize); 202 return value * 100 / dimensionForLengthMode(mode, viewportSize);
200 } 203 }
201 case LengthTypeEMS: 204 case LengthTypeEMS:
202 return convertValueFromUserUnitsToEMS(value); 205 return convertValueFromUserUnitsToEMS(value);
203 case LengthTypeEXS: 206 case LengthTypeEXS:
204 return convertValueFromUserUnitsToEXS(value); 207 return convertValueFromUserUnitsToEXS(value);
205 case LengthTypeREMS: 208 case LengthTypeREMS:
206 return convertValueFromUserUnitsToREMS(value); 209 return convertValueFromUserUnitsToREMS(value);
210 case LengthTypeCHS:
211 return convertValueFromUserUnitsToCHS(value);
207 case LengthTypePX: 212 case LengthTypePX:
208 return value; 213 return value;
209 case LengthTypeCM: 214 case LengthTypeCM:
210 return value / cssPixelsPerCentimeter; 215 return value / cssPixelsPerCentimeter;
211 case LengthTypeMM: 216 case LengthTypeMM:
212 return value / cssPixelsPerMillimeter; 217 return value / cssPixelsPerMillimeter;
213 case LengthTypeIN: 218 case LengthTypeIN:
214 return value / cssPixelsPerInch; 219 return value / cssPixelsPerInch;
215 case LengthTypePT: 220 case LengthTypePT:
216 return value / cssPixelsPerPoint; 221 return value / cssPixelsPerPoint;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 style = documentElement && (static_cast<const Node*>(m_context.get()) != doc umentElement) ? documentElement->computedStyle() : documentStyle; 300 style = documentElement && (static_cast<const Node*>(m_context.get()) != doc umentElement) ? documentElement->computedStyle() : documentStyle;
296 if (!style) 301 if (!style)
297 style = documentStyle; 302 style = documentStyle;
298 303
299 if (!style) 304 if (!style)
300 return 0; 305 return 0;
301 306
302 return value * style->specifiedFontSize(); 307 return value * style->specifiedFontSize();
303 } 308 }
304 309
310 float SVGLengthContext::convertValueFromUserUnitsToCHS(float value) const
311 {
312 const ComputedStyle* style = computedStyleForLengthResolving(m_context);
313 if (!style)
314 return 0;
315
316 float zeroWidth = style->fontMetrics().zeroWidth();
317 if (!zeroWidth)
318 return 0;
319
320 return value / zeroWidth;
321 }
322
323 float SVGLengthContext::convertValueFromCHSToUserUnits(float value) const
324 {
325 const ComputedStyle* style = computedStyleForLengthResolving(m_context);
326 if (!style)
327 return 0;
328
329 return value * style->fontMetrics().zeroWidth();
330 }
331
305 float SVGLengthContext::convertValueFromUserUnitsToEXS(float value) const 332 float SVGLengthContext::convertValueFromUserUnitsToEXS(float value) const
306 { 333 {
307 const ComputedStyle* style = computedStyleForLengthResolving(m_context); 334 const ComputedStyle* style = computedStyleForLengthResolving(m_context);
308 if (!style) 335 if (!style)
309 return 0; 336 return 0;
310 337
311 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un its-03-b.svg 338 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un its-03-b.svg
312 // if this causes problems in real world cases maybe it would be best to rem ove this 339 // if this causes problems in real world cases maybe it would be best to rem ove this
313 float xHeight = ceilf(style->fontMetrics().xHeight()); 340 float xHeight = ceilf(style->fontMetrics().xHeight());
314 if (!xHeight) 341 if (!xHeight)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 373
347 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); 374 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement);
348 viewportSize = svg.currentViewBoxRect().size(); 375 viewportSize = svg.currentViewBoxRect().size();
349 if (viewportSize.isEmpty()) 376 if (viewportSize.isEmpty())
350 viewportSize = svg.currentViewportSize(); 377 viewportSize = svg.currentViewportSize();
351 378
352 return true; 379 return true;
353 } 380 }
354 381
355 } 382 }
OLDNEW
« Source/core/svg/SVGLength.cpp ('K') | « Source/core/svg/SVGLengthContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698