Skip to content

Commit 2d447f0

Browse files
kbhomesemilio
authored andcommitted
Bug 1740584 - Implement relative root font lengths for SVG. r=emilio,firefox-style-system-reviewers,jwatt
Differential Revision: https://phabricator.services.mozilla.com/D274528
1 parent 2763574 commit 2d447f0

File tree

6 files changed

+61
-29
lines changed

6 files changed

+61
-29
lines changed

dom/svg/SVGLength.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@ const unsigned short SVG_LENGTHTYPE_IC = 14;
2828
const unsigned short SVG_LENGTHTYPE_CAP = 15;
2929
const unsigned short SVG_LENGTHTYPE_LH = 16;
3030
const unsigned short SVG_LENGTHTYPE_RLH = 17;
31-
const unsigned short SVG_LENGTHTYPE_VW = 18;
32-
const unsigned short SVG_LENGTHTYPE_VH = 19;
33-
const unsigned short SVG_LENGTHTYPE_VMIN = 20;
34-
const unsigned short SVG_LENGTHTYPE_VMAX = 21;
31+
const unsigned short SVG_LENGTHTYPE_REX = 18;
32+
const unsigned short SVG_LENGTHTYPE_RCH = 19;
33+
const unsigned short SVG_LENGTHTYPE_RIC = 20;
34+
const unsigned short SVG_LENGTHTYPE_RCAP = 21;
35+
const unsigned short SVG_LENGTHTYPE_VW = 22;
36+
const unsigned short SVG_LENGTHTYPE_VH = 23;
37+
const unsigned short SVG_LENGTHTYPE_VMIN = 24;
38+
const unsigned short SVG_LENGTHTYPE_VMAX = 25;
3539

3640
void SVGLength::GetValueAsString(nsAString& aValue) const {
3741
nsTextFormatter::ssprintf(aValue, u"%g", (double)mValue);
@@ -78,7 +82,7 @@ bool SVGLength::IsAbsoluteUnit(uint8_t aUnit) {
7882
/*static*/
7983
bool SVGLength::IsFontRelativeUnit(uint8_t aUnit) {
8084
return aUnit == SVG_LENGTHTYPE_EMS || aUnit == SVG_LENGTHTYPE_EXS ||
81-
(aUnit >= SVG_LENGTHTYPE_CH && aUnit <= SVG_LENGTHTYPE_RLH);
85+
(aUnit >= SVG_LENGTHTYPE_CH && aUnit <= SVG_LENGTHTYPE_RCAP);
8286
}
8387

8488
/**
@@ -214,6 +218,18 @@ float SVGLength::GetPixelsPerUnit(const UserSpaceMetrics& aMetrics,
214218
case SVG_LENGTHTYPE_RLH:
215219
zoomType = ZoomType::SelfFromRoot;
216220
return aMetrics.GetLineHeight(UserSpaceMetrics::Type::Root);
221+
case SVG_LENGTHTYPE_REX:
222+
zoomType = ZoomType::SelfFromRoot;
223+
return aMetrics.GetExLength(UserSpaceMetrics::Type::Root);
224+
case SVG_LENGTHTYPE_RCH:
225+
zoomType = ZoomType::SelfFromRoot;
226+
return aMetrics.GetChSize(UserSpaceMetrics::Type::Root);
227+
case SVG_LENGTHTYPE_RIC:
228+
zoomType = ZoomType::SelfFromRoot;
229+
return aMetrics.GetIcWidth(UserSpaceMetrics::Type::Root);
230+
case SVG_LENGTHTYPE_RCAP:
231+
zoomType = ZoomType::SelfFromRoot;
232+
return aMetrics.GetCapHeight(UserSpaceMetrics::Type::Root);
217233
default:
218234
MOZ_ASSERT(IsAbsoluteUnit(aUnitType));
219235
return GetAbsUnitsPerAbsUnit(SVG_LENGTHTYPE_PX, aUnitType);

dom/svg/SVGLengthUnits.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ SVG_LENGTH_UNIT(SVG_LENGTHTYPE_VMIN, "vmin", nsCSSUnit::eCSSUnit_VMin)
3030
SVG_LENGTH_UNIT(SVG_LENGTHTYPE_VMAX, "vmax", nsCSSUnit::eCSSUnit_VMax)
3131
SVG_LENGTH_UNIT(SVG_LENGTHTYPE_LH, "lh", nsCSSUnit::eCSSUnit_LineHeight)
3232
SVG_LENGTH_UNIT(SVG_LENGTHTYPE_RLH, "rlh", nsCSSUnit::eCSSUnit_RootLineHeight)
33+
SVG_LENGTH_UNIT(SVG_LENGTHTYPE_REX, "rex", nsCSSUnit::eCSSUnit_RootXHeight)
34+
SVG_LENGTH_UNIT(SVG_LENGTHTYPE_RCH, "rch", nsCSSUnit::eCSSUnit_RootChar)
35+
SVG_LENGTH_UNIT(SVG_LENGTHTYPE_RIC, "ric", nsCSSUnit::eCSSUnit_RootIdeographic)
36+
SVG_LENGTH_UNIT(SVG_LENGTHTYPE_RCAP, "rcap", nsCSSUnit::eCSSUnit_RootCapHeight)

layout/style/nsCSSValue.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,20 @@ enum nsCSSUnit : uint32_t {
3333
// different behavior than percent)
3434

3535
// Font relative measure
36-
eCSSUnit_EM = 800, // == current font size
37-
eCSSUnit_XHeight = 801, // distance from top of lower case x to
38-
// baseline
39-
eCSSUnit_Char = 802, // number of characters, used for width with
40-
// monospace font
41-
eCSSUnit_RootEM = 803, // == root element font size
42-
eCSSUnit_Ideographic = 804, // == CJK water ideograph width
43-
eCSSUnit_CapHeight = 805, // == Capital letter height
44-
eCSSUnit_LineHeight = 806, // == Line height
45-
eCSSUnit_RootLineHeight = 807, // == Root line height
36+
eCSSUnit_EM = 800, // == current font size (em)
37+
eCSSUnit_XHeight = 801, // distance from top of lower case x to
38+
// baseline (ex)
39+
eCSSUnit_Char = 802, // number of characters, used for width with
40+
// monospace font (ch)
41+
eCSSUnit_RootEM = 803, // == root element font size (rem)
42+
eCSSUnit_Ideographic = 804, // == CJK water ideograph width (ic)
43+
eCSSUnit_CapHeight = 805, // == Capital letter height (cap)
44+
eCSSUnit_LineHeight = 806, // == Line height (lh)
45+
eCSSUnit_RootLineHeight = 807, // == Root line height (rlh)
46+
eCSSUnit_RootXHeight = 808, // == Root x-height (rex)
47+
eCSSUnit_RootChar = 809, // == Root advance measure (rch)
48+
eCSSUnit_RootIdeographic = 810, // == Root ideographic advance measure (ric)
49+
eCSSUnit_RootCapHeight = 811, // == Root capital letter height (rch)
4650

4751
// Screen relative measure
4852
eCSSUnit_Point = 900, // 4/3 of a CSS pixel

testing/web-platform/meta/css/css-viewport/zoom/svg-font-relative-units.html.ini

Lines changed: 0 additions & 2 deletions
This file was deleted.

testing/web-platform/tests/css/css-viewport/zoom/svg-font-relative-units-ref.html

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@
1818
</style>
1919
<div class="container">
2020
<svg width=400 height=400>
21-
<line y1=40 y2=40 x1=0 x2=80 />
22-
<line y1=120 y2=120 x1=0 x2=80 />
23-
<line y1=140 y2=140 x1=0 x2=80 />
21+
<line y1=40 y2=40 x1=0 x2=80 /> <!-- em -->
22+
<line y1=60 y2=60 x1=0 x2=64 /> <!-- ex -->
23+
<line y1=80 y2=80 x1=0 x2=64 /> <!-- cap -->
24+
<line y1=100 y2=100 x1=0 x2=80 /> <!-- ch -->
25+
<line y1=120 y2=120 x1=0 x2=80 /> <!-- ic -->
26+
<line y1=140 y2=140 x1=0 x2=80 /> <!-- lh -->
2427

25-
<line y1=220 y2=220 x1=0 x2=40 />
26-
<line y1=240 y2=240 x1=0 x2=40 />
27-
<line y1=280 y2=280 x1=0 x2=40 />
28-
<line y1=300 y2=300 x1=0 x2=40 />
28+
<line y1=240 y2=240 x1=0 x2=40 /> <!-- em -->
29+
<line y1=260 y2=260 x1=0 x2=32 /> <!-- ex -->
30+
<line y1=280 y2=280 x1=0 x2=32 /> <!-- cap -->
31+
<line y1=300 y2=300 x1=0 x2=40 /> <!-- ch -->
32+
<line y1=320 y2=320 x1=0 x2=40 /> <!-- ic -->
33+
<line y1=340 y2=340 x1=0 x2=40 /> <!-- lh -->
2934
</svg>
3035
</div>

testing/web-platform/tests/css/css-viewport/zoom/svg-font-relative-units.html

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,19 @@
2828
<svg width=100 height=100>
2929
<!-- Font-relative units -->
3030
<line y1=10 y2=10 x1=0 x2=1em />
31-
<line y1=30 y2=30 x1=0 x2=1ch />
32-
<line y1=35 y2=35 x1=0 x2=1ic />
31+
<line y1=15 y2=15 x1=0 x2=1ex />
32+
<line y1=20 y2=20 x1=0 x2=1cap />
33+
<line y1=25 y2=25 x1=0 x2=1ch />
34+
<line y1=30 y2=30 x1=0 x2=1ic />
35+
<line y1=35 y2=35 x1=0 x2=1lh />
3336

3437
<!-- Root font-relative units -->
35-
<line y1=55 y2=55 x1=0 x2=1rch />
3638
<line y1=60 y2=60 x1=0 x2=1rem />
37-
<line y1=70 y2=70 x1=0 x2=1ric />
38-
<line y1=75 y2=75 x1=0 x2=1rlh />
39+
<line y1=65 y2=65 x1=0 x2=1rex />
40+
<line y1=70 y2=70 x1=0 x2=1rcap />
41+
<line y1=75 y2=75 x1=0 x2=1rch />
42+
<line y1=80 y2=80 x1=0 x2=1ric />
43+
<line y1=85 y2=85 x1=0 x2=1rlh />
3944
</svg>
4045
</div>
4146
</div>

0 commit comments

Comments
 (0)