mirror of
https://github.com/servo/servo.git
synced 2025-08-14 18:05:36 +01:00
Re-use the TextMetrics data structure in the Layout 2020 fragment tree (#30823)
This data structure has all of the metrics needed to render a font and is in `Au`. We'll need more of these metrics for implementing `vertical-align` and its use doesn't increase the size of the Fragment tree (as the BoxFragment is still larger). In addition, this will be helpful when switching layout to `Au`.
This commit is contained in:
parent
f0b4162328
commit
8ded1072ce
4 changed files with 20 additions and 46 deletions
|
@ -281,7 +281,7 @@ impl Fragment {
|
|||
.to_physical(fragment.parent_style.writing_mode, containing_block)
|
||||
.translate(containing_block.origin.to_vector());
|
||||
let mut baseline_origin = rect.origin.clone();
|
||||
baseline_origin.y += fragment.font_metrics.ascent;
|
||||
baseline_origin.y += Length::from(fragment.font_metrics.ascent);
|
||||
let glyphs = glyphs(&fragment.glyphs, baseline_origin);
|
||||
if glyphs.is_empty() {
|
||||
return;
|
||||
|
@ -306,10 +306,6 @@ impl Fragment {
|
|||
let color = fragment.parent_style.clone_color();
|
||||
let font_metrics = &fragment.font_metrics;
|
||||
let dppx = builder.context.style_context.device_pixel_ratio().get();
|
||||
let round_to_nearest_device_pixel = |value: Length| -> Length {
|
||||
// Round to the nearest integer device pixel, ensuring at least one device pixel.
|
||||
Length::new((value.px() * dppx).round().max(1.0) / dppx)
|
||||
};
|
||||
|
||||
// Underline.
|
||||
if fragment
|
||||
|
@ -317,8 +313,9 @@ impl Fragment {
|
|||
.contains(TextDecorationLine::UNDERLINE)
|
||||
{
|
||||
let mut rect = rect;
|
||||
rect.origin.y = rect.origin.y + font_metrics.ascent - font_metrics.underline_offset;
|
||||
rect.size.height = round_to_nearest_device_pixel(font_metrics.underline_size);
|
||||
rect.origin.y =
|
||||
rect.origin.y + Length::from(font_metrics.ascent - font_metrics.underline_offset);
|
||||
rect.size.height = Length::new(font_metrics.underline_size.to_nearest_pixel(dppx));
|
||||
self.build_display_list_for_text_decoration(fragment, builder, &rect, &color);
|
||||
}
|
||||
|
||||
|
@ -328,7 +325,7 @@ impl Fragment {
|
|||
.contains(TextDecorationLine::OVERLINE)
|
||||
{
|
||||
let mut rect = rect;
|
||||
rect.size.height = round_to_nearest_device_pixel(font_metrics.underline_size);
|
||||
rect.size.height = Length::new(font_metrics.underline_size.to_nearest_pixel(dppx));
|
||||
self.build_display_list_for_text_decoration(fragment, builder, &rect, &color);
|
||||
}
|
||||
|
||||
|
@ -349,9 +346,10 @@ impl Fragment {
|
|||
.contains(TextDecorationLine::LINE_THROUGH)
|
||||
{
|
||||
let mut rect = rect;
|
||||
rect.origin.y = rect.origin.y + font_metrics.ascent - font_metrics.strikeout_offset;
|
||||
rect.origin.y =
|
||||
rect.origin.y + Length::from(font_metrics.ascent - font_metrics.strikeout_offset);
|
||||
// XXX(ferjm) This does not work on MacOS #942
|
||||
rect.size.height = round_to_nearest_device_pixel(font_metrics.strikeout_size);
|
||||
rect.size.height = Length::new(font_metrics.strikeout_size.to_nearest_pixel(dppx));
|
||||
self.build_display_list_for_text_decoration(fragment, builder, &rect, &color);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue