Skip to content
Permalink
Browse files

stylo: Compute font-size calcs against appropriate base size

  • Loading branch information
Manishearth committed Sep 1, 2017
1 parent 09df9c4 commit 343eb2318752573d1dab54cc48225481b1ea2e09
@@ -859,7 +859,7 @@ ${helpers.single_keyword_system("font-variant-caps",
base_size.resolve(context).scale_by(pc.0).into()
}
SpecifiedValue::Length(LengthOrPercentage::Calc(ref calc)) => {
let calc = calc.to_computed_value_zoomed(context);
let calc = calc.to_computed_value_zoomed(context, base_size);
calc.to_used_value(Some(base_size.resolve(context))).unwrap().into()
}
SpecifiedValue::Keyword(ref key, fraction) => {
@@ -217,7 +217,8 @@ impl ToCss for CalcLengthOrPercentage {

impl specified::CalcLengthOrPercentage {
/// Compute the value, zooming any absolute units by the zoom function.
fn to_computed_value_with_zoom<F>(&self, context: &Context, zoom_fn: F) -> CalcLengthOrPercentage
fn to_computed_value_with_zoom<F>(&self, context: &Context, zoom_fn: F,
base_size: FontBaseSize) -> CalcLengthOrPercentage
where F: Fn(Au) -> Au {
let mut length = Au(0);

@@ -239,7 +240,7 @@ impl specified::CalcLengthOrPercentage {
self.ex.map(FontRelativeLength::Ex),
self.rem.map(FontRelativeLength::Rem)] {
if let Some(val) = *val {
length += val.to_computed_value(context, FontBaseSize::CurrentStyle);
length += val.to_computed_value(context, base_size);
}
}

@@ -251,16 +252,17 @@ impl specified::CalcLengthOrPercentage {
}

/// Compute font-size or line-height taking into account text-zoom if necessary.
pub fn to_computed_value_zoomed(&self, context: &Context) -> CalcLengthOrPercentage {
self.to_computed_value_with_zoom(context, |abs| context.maybe_zoom_text(abs.into()).0)
pub fn to_computed_value_zoomed(&self, context: &Context, base_size: FontBaseSize) -> CalcLengthOrPercentage {
self.to_computed_value_with_zoom(context, |abs| context.maybe_zoom_text(abs.into()).0, base_size)
}
}

impl ToComputedValue for specified::CalcLengthOrPercentage {
type ComputedValue = CalcLengthOrPercentage;

fn to_computed_value(&self, context: &Context) -> CalcLengthOrPercentage {
self.to_computed_value_with_zoom(context, |abs| abs)
// normal properties don't zoom, and compute em units against the current style's font-size
self.to_computed_value_with_zoom(context, |abs| abs, FontBaseSize::CurrentStyle)
}

#[inline]
@@ -80,6 +80,7 @@ impl ToCss for FontRelativeLength {
}

/// A source to resolve font-relative units against
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum FontBaseSize {
/// Use the font-size of the current element
CurrentStyle,
@@ -112,7 +112,7 @@ impl ToComputedValue for LineHeight {
).into()
}
LengthOrPercentage::Calc(ref calc) => {
let computed_calc = calc.to_computed_value_zoomed(context);
let computed_calc = calc.to_computed_value_zoomed(context, FontBaseSize::CurrentStyle);
let font_relative_length =
FontRelativeLength::Em(computed_calc.percentage())
.to_computed_value(

0 comments on commit 343eb23

Please sign in to comment.
You can’t perform that action at this time.