From ad9fad097c4d171686b1b7c4f4e6ce27ca633c0d Mon Sep 17 00:00:00 2001 From: Eric Atkinson Date: Mon, 27 May 2013 15:13:12 -0700 Subject: [PATCH 1/2] Tweak inline layout so text is baseline-aligned --- src/components/servo/layout/inline.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/servo/layout/inline.rs b/src/components/servo/layout/inline.rs index 062afd6d5b4..9eba9c966e8 100644 --- a/src/components/servo/layout/inline.rs +++ b/src/components/servo/layout/inline.rs @@ -840,13 +840,23 @@ impl InlineFlowData { // according to the `vertical-align` property of the containing block. let halfleading = match cur_box { TextRenderBoxClass(text_box) => { - (text_box.run.font.metrics.em_size - line_height).scale_by(0.5) + //ad is the AD height as defined by CSS 2.1 § 10.8.1 + let ad = text_box.text_data.run.font.metrics.ascent + text_box.text_data.run.font.metrics.descent; + (line_height - ad).scale_by(0.5) }, _ => Au(0), }; + //FIXME: when line-height is set on an inline element, the half leading + //distance can be negative. + let halfleading = Au::max(halfleading, Au(0)); + + let height = match cur_box { + TextRenderBoxClass(text_box) => text_box.text_data.run.font.metrics.ascent, + _ => cur_box.position().size.height + }; + do cur_box.with_mut_base |base| { - let height = base.position.size.height; base.position.origin.y = cur_y + halfleading + baseline_offset - height; } } From 1fd9a8f162ec1066526fe461bd0cb30c47d713e0 Mon Sep 17 00:00:00 2001 From: Eric Atkinson Date: Tue, 28 May 2013 10:37:49 -0700 Subject: [PATCH 2/2] Merge with TextRenderBox refactor --- src/components/servo/layout/inline.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/servo/layout/inline.rs b/src/components/servo/layout/inline.rs index 9eba9c966e8..237f3ca29de 100644 --- a/src/components/servo/layout/inline.rs +++ b/src/components/servo/layout/inline.rs @@ -841,7 +841,7 @@ impl InlineFlowData { let halfleading = match cur_box { TextRenderBoxClass(text_box) => { //ad is the AD height as defined by CSS 2.1 § 10.8.1 - let ad = text_box.text_data.run.font.metrics.ascent + text_box.text_data.run.font.metrics.descent; + let ad = text_box.run.font.metrics.ascent + text_box.run.font.metrics.descent; (line_height - ad).scale_by(0.5) }, _ => Au(0), @@ -852,7 +852,7 @@ impl InlineFlowData { let halfleading = Au::max(halfleading, Au(0)); let height = match cur_box { - TextRenderBoxClass(text_box) => text_box.text_data.run.font.metrics.ascent, + TextRenderBoxClass(text_box) => text_box.run.font.metrics.ascent, _ => cur_box.position().size.height };