diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-02-18 17:48:15 +0530 |
---|---|---|
committer | bors-servo <lbergstrom+bors@mozilla.com> | 2016-02-18 17:48:15 +0530 |
commit | 83be388f59b1bb4dfccc6ccd89022caa13b37a94 (patch) | |
tree | 1b7d2e903ff23eeabf6ebb8ce20e1157665a8d42 /components/layout/inline.rs | |
parent | 9778e5e84d95af1d1dadf71ad8a28701762bf8fc (diff) | |
parent | 286130b051430045d43d8a5917cb36f2f8f9b8cf (diff) | |
download | servo-83be388f59b1bb4dfccc6ccd89022caa13b37a94.tar.gz servo-83be388f59b1bb4dfccc6ccd89022caa13b37a94.zip |
Auto merge of #9668 - glennw:inline-accuracy, r=pcwalton
Ensure when calculating font metrics that the total line height matches requested line height.
This fixes rounding accuracy issues that could result in layout producing results off by a small number of Au.
<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9668)
<!-- Reviewable:end -->
Diffstat (limited to 'components/layout/inline.rs')
-rw-r--r-- | components/layout/inline.rs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/components/layout/inline.rs b/components/layout/inline.rs index c95012a6f2a..3e3e6506cb7 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -1928,9 +1928,14 @@ impl InlineMetrics { #[inline] pub fn from_font_metrics(font_metrics: &FontMetrics, line_height: Au) -> InlineMetrics { let leading = line_height - (font_metrics.ascent + font_metrics.descent); + // Calculating the half leading here and then using leading - half_leading + // below ensure that we don't introduce any rounding accuracy issues here. + // The invariant is that the resulting total line height must exactly + // equal the requested line_height. + let half_leading = leading.scale_by(0.5); InlineMetrics { - block_size_above_baseline: font_metrics.ascent + leading.scale_by(0.5), - depth_below_baseline: font_metrics.descent + leading.scale_by(0.5), + block_size_above_baseline: font_metrics.ascent + half_leading, + depth_below_baseline: font_metrics.descent + leading - half_leading, ascent: font_metrics.ascent, } } |