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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/svg/SVGLengthContext.cpp
diff --git a/Source/core/svg/SVGLengthContext.cpp b/Source/core/svg/SVGLengthContext.cpp
index 3bf1f9a27ad61ef7e4abb842f82c4149cb6ceb4b..1f1e925f29da8f3d5df0b0bbd91db9b71d3fa1de 100644
--- a/Source/core/svg/SVGLengthContext.cpp
+++ b/Source/core/svg/SVGLengthContext.cpp
@@ -172,6 +172,9 @@ float SVGLengthContext::convertValueToUserUnits(float value, SVGLengthMode mode,
case LengthTypeREMS:
userUnits = convertValueFromREMSToUserUnits(value);
break;
+ case LengthTypeCHS:
+ userUnits = convertValueFromCHSToUserUnits(value);
+ break;
default:
ASSERT_NOT_REACHED();
break;
@@ -204,6 +207,8 @@ float SVGLengthContext::convertValueFromUserUnits(float value, SVGLengthMode mod
return convertValueFromUserUnitsToEXS(value);
case LengthTypeREMS:
return convertValueFromUserUnitsToREMS(value);
+ case LengthTypeCHS:
+ return convertValueFromUserUnitsToCHS(value);
case LengthTypePX:
return value;
case LengthTypeCM:
@@ -302,6 +307,32 @@ float SVGLengthContext::convertValueFromREMSToUserUnits(float value) const
return value * style->specifiedFontSize();
}
+float SVGLengthContext::convertValueFromUserUnitsToCHS(float value) const
+{
+ const ComputedStyle* style = computedStyleForLengthResolving(m_context);
+ if (!style)
+ return 0;
+
+ // Use of ceil allows a pixel match to the W3Cs expected output of coords-units-03-b.svg
Erik Dahlström (inactive) 2015/04/10 08:43:18 This test doesn't use ch units, so this comment do
Shanmuga Pandi 2015/04/10 11:46:15 Removed comment and ceilf
+ // if this causes problems in real world cases maybe it would be best to remove this
+ float zeroWidth = ceilf(style->fontMetrics().zeroWidth());
+ if (!zeroWidth)
+ return 0;
+
+ return value / zeroWidth;
+}
+
+float SVGLengthContext::convertValueFromCHSToUserUnits(float value) const
+{
+ const ComputedStyle* style = computedStyleForLengthResolving(m_context);
+ if (!style)
+ return 0;
+
+ // Use of ceil allows a pixel match to the W3Cs expected output of coords-units-03-b.svg
Erik Dahlström (inactive) 2015/04/10 08:43:18 Same as above.
Shanmuga Pandi 2015/04/10 11:46:15 Done.
+ // if this causes problems in real world cases maybe it would be best to remove this
+ return value * ceilf(style->fontMetrics().zeroWidth());
+}
+
float SVGLengthContext::convertValueFromUserUnitsToEXS(float value) const
{
const ComputedStyle* style = computedStyleForLengthResolving(m_context);

Powered by Google App Engine
This is Rietveld 408576698