Skip to content
This repository was archived by the owner on Jul 10, 2023. It is now read-only.

Commit 8b9cf93

Browse files
committed
Merge pull request #20 from metajack/relative-fonts
Fix relative font sizes.
2 parents 7a58480 + 335d926 commit 8b9cf93

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

complete.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ impl<'self> CompleteSelectResults {
3434
let cb: n::c::ComputeFontSizeCb =
3535
|parent: &Option<n::h::CssHint>, child: &n::h::CssHint| -> n::h::CssHint {
3636
match *child {
37+
// Handle relative units
3738
CssHintLength(n::t::CssUnitEm(child_em)) => {
3839
match *parent {
3940
Some(CssHintLength(parent_unit)) => {
@@ -45,9 +46,24 @@ impl<'self> CompleteSelectResults {
4546
new_value));
4647
CssHintLength(unit)
4748
}
48-
_ => n::h::CssHintLength(n::t::CssUnitEm(child_em)),
49+
_ => n::h::CssHintLength(n::t::CssUnitPx(float_to_css_fixed(16.0))),
4950
}
5051
}
52+
CssHintLength(n::t::CssUnitPct(child_pct)) => {
53+
match *parent {
54+
Some(CssHintLength(parent_unit)) => {
55+
// CSS3 Values 5.1.1: Multiply parent unit by child unit.
56+
let mut new_value =
57+
n::u::css_fixed_to_float(parent_unit.to_css_fixed());
58+
new_value *= n::u::css_fixed_to_float(child_pct) / 100.0;
59+
let unit = parent_unit.modify(n::u::float_to_css_fixed(
60+
new_value));
61+
CssHintLength(unit)
62+
}
63+
_ => n::h::CssHintLength(n::t::CssUnitPx(float_to_css_fixed(16.0))),
64+
}
65+
}
66+
// Pass through absolute units
5167
CssHintLength(unit) => CssHintLength(unit),
5268
_ => {
5369
n::h::CssHintLength(n::t::CssUnitPx(float_to_css_fixed(16.0)))

0 commit comments

Comments
 (0)