mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Change calculate_line_height to use font-size from style.
This commit is contained in:
parent
3670ee6f1f
commit
383ce249dc
3 changed files with 9 additions and 18 deletions
|
@ -455,8 +455,8 @@ impl Fragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn calculate_line_height(&self, font_size: Au) -> Au {
|
pub fn calculate_line_height(&self) -> Au {
|
||||||
text::line_height_from_style(self.style(), font_size)
|
text::line_height_from_style(self.style())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the sum of the inline-sizes of all the borders of this fragment. This is private because
|
/// Returns the sum of the inline-sizes of all the borders of this fragment. This is private because
|
||||||
|
@ -1089,15 +1089,9 @@ impl Fragment {
|
||||||
ImageFragment(ref image_fragment_info) => {
|
ImageFragment(ref image_fragment_info) => {
|
||||||
image_fragment_info.computed_block_size()
|
image_fragment_info.computed_block_size()
|
||||||
}
|
}
|
||||||
ScannedTextFragment(ref text_fragment_info) => {
|
ScannedTextFragment(_) => {
|
||||||
// Compute the block-size based on the line-block-size and font size.
|
// Compute the block-size based on the line-block-size and font size.
|
||||||
//
|
self.calculate_line_height()
|
||||||
// FIXME(pcwalton): Shouldn't we use the value of the `font-size` property below
|
|
||||||
// instead of the bounding box of the text run?
|
|
||||||
let (range, run) = (&text_fragment_info.range, &text_fragment_info.run);
|
|
||||||
let text_bounds = run.metrics_for_range(range).bounding_box;
|
|
||||||
let em_size = text_bounds.size.height;
|
|
||||||
self.calculate_line_height(em_size)
|
|
||||||
}
|
}
|
||||||
TableColumnFragment(_) => fail!("Table column fragments do not have block_size"),
|
TableColumnFragment(_) => fail!("Table column fragments do not have block_size"),
|
||||||
UnscannedTextFragment(_) => fail!("Unscanned text fragments should have been scanned by now!"),
|
UnscannedTextFragment(_) => fail!("Unscanned text fragments should have been scanned by now!"),
|
||||||
|
@ -1388,8 +1382,7 @@ impl Fragment {
|
||||||
}
|
}
|
||||||
ScannedTextFragment(ref text_fragment) => {
|
ScannedTextFragment(ref text_fragment) => {
|
||||||
// See CSS 2.1 § 10.8.1.
|
// See CSS 2.1 § 10.8.1.
|
||||||
let font_size = self.style().get_font().font_size;
|
let line_height = self.calculate_line_height();
|
||||||
let line_height = self.calculate_line_height(font_size);
|
|
||||||
InlineMetrics::from_font_metrics(&text_fragment.run.font_metrics, line_height)
|
InlineMetrics::from_font_metrics(&text_fragment.run.font_metrics, line_height)
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
|
|
@ -1027,8 +1027,7 @@ impl InlineFlow {
|
||||||
},
|
},
|
||||||
vertical_align::Length(length) => (-(length + ascent), false),
|
vertical_align::Length(length) => (-(length + ascent), false),
|
||||||
vertical_align::Percentage(p) => {
|
vertical_align::Percentage(p) => {
|
||||||
let pt_size = fragment.font_style().pt_size;
|
let line_height = fragment.calculate_line_height();
|
||||||
let line_height = fragment.calculate_line_height(Au::from_pt(pt_size));
|
|
||||||
let percent_offset = line_height.scale_by(p);
|
let percent_offset = line_height.scale_by(p);
|
||||||
(-(percent_offset + ascent), false)
|
(-(percent_offset + ascent), false)
|
||||||
}
|
}
|
||||||
|
@ -1073,7 +1072,7 @@ impl InlineFlow {
|
||||||
style: &ComputedValues) -> (Au, Au) {
|
style: &ComputedValues) -> (Au, Au) {
|
||||||
let font_style = text::computed_style_to_font_style(style);
|
let font_style = text::computed_style_to_font_style(style);
|
||||||
let font_metrics = text::font_metrics_for_style(font_context, &font_style);
|
let font_metrics = text::font_metrics_for_style(font_context, &font_style);
|
||||||
let line_height = text::line_height_from_style(style, style.get_font().font_size);
|
let line_height = text::line_height_from_style(style);
|
||||||
let inline_metrics = InlineMetrics::from_font_metrics(&font_metrics, line_height);
|
let inline_metrics = InlineMetrics::from_font_metrics(&font_metrics, line_height);
|
||||||
(inline_metrics.block_size_above_baseline, inline_metrics.depth_below_baseline)
|
(inline_metrics.block_size_above_baseline, inline_metrics.depth_below_baseline)
|
||||||
}
|
}
|
||||||
|
|
|
@ -293,9 +293,8 @@ pub fn computed_style_to_font_style(style: &ComputedValues) -> FontStyle {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the line block-size needed by the given computed style and font size.
|
/// Returns the line block-size needed by the given computed style and font size.
|
||||||
///
|
pub fn line_height_from_style(style: &ComputedValues) -> Au {
|
||||||
/// FIXME(pcwalton): I believe this should not take a separate `font-size` parameter.
|
let font_size = style.get_font().font_size;
|
||||||
pub fn line_height_from_style(style: &ComputedValues, font_size: Au) -> Au {
|
|
||||||
let from_inline = match style.get_inheritedbox().line_height {
|
let from_inline = match style.get_inheritedbox().line_height {
|
||||||
line_height::Normal => font_size.scale_by(1.14),
|
line_height::Normal => font_size.scale_by(1.14),
|
||||||
line_height::Number(l) => font_size.scale_by(l),
|
line_height::Number(l) => font_size.scale_by(l),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue