mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Store required font metrics on TextFragment
This commit is contained in:
parent
74d9fec9cf
commit
e3c8597ccb
3 changed files with 32 additions and 11 deletions
|
@ -87,7 +87,7 @@ impl Fragment {
|
|||
.to_physical(t.parent_style.writing_mode, containing_block)
|
||||
.translate(containing_block.origin.to_vector());
|
||||
let mut baseline_origin = rect.origin.clone();
|
||||
baseline_origin.y += t.ascent;
|
||||
baseline_origin.y += t.font_metrics.ascent;
|
||||
let glyphs = glyphs(&t.glyphs, baseline_origin);
|
||||
if glyphs.is_empty() {
|
||||
return;
|
||||
|
|
|
@ -9,7 +9,7 @@ use crate::flow::FlowLayout;
|
|||
use crate::formatting_contexts::IndependentFormattingContext;
|
||||
use crate::fragments::{
|
||||
AbsoluteOrFixedPositionedFragment, AnonymousFragment, BoxFragment, CollapsedBlockMargins,
|
||||
DebugId, Fragment, TextFragment,
|
||||
DebugId, FontMetrics, Fragment, TextFragment,
|
||||
};
|
||||
use crate::geom::flow_relative::{Rect, Sides, Vec2};
|
||||
use crate::positioned::{
|
||||
|
@ -631,8 +631,7 @@ fn layout_atomic(
|
|||
}
|
||||
|
||||
struct BreakAndShapeResult {
|
||||
font_ascent: Au,
|
||||
font_line_gap: Au,
|
||||
font_metrics: FontMetrics,
|
||||
font_key: FontInstanceKey,
|
||||
runs: Vec<GlyphRun>,
|
||||
break_at_start: bool,
|
||||
|
@ -699,8 +698,7 @@ impl TextRun {
|
|||
);
|
||||
|
||||
BreakAndShapeResult {
|
||||
font_ascent: font.metrics.ascent,
|
||||
font_line_gap: font.metrics.line_gap,
|
||||
font_metrics: (&font.metrics).into(),
|
||||
font_key: font.font_key,
|
||||
runs,
|
||||
break_at_start,
|
||||
|
@ -712,8 +710,7 @@ impl TextRun {
|
|||
use style::values::generics::text::LineHeight;
|
||||
|
||||
let BreakAndShapeResult {
|
||||
font_ascent,
|
||||
font_line_gap,
|
||||
font_metrics,
|
||||
font_key,
|
||||
runs,
|
||||
break_at_start: _,
|
||||
|
@ -750,7 +747,7 @@ impl TextRun {
|
|||
}
|
||||
}
|
||||
let line_height = match self.parent_style.get_inherited_text().line_height {
|
||||
LineHeight::Normal => font_line_gap.into(),
|
||||
LineHeight::Normal => font_metrics.line_gap,
|
||||
LineHeight::Number(n) => font_size * n.0,
|
||||
LineHeight::Length(l) => l.0,
|
||||
};
|
||||
|
@ -775,7 +772,7 @@ impl TextRun {
|
|||
debug_id: DebugId::new(),
|
||||
parent_style: self.parent_style.clone(),
|
||||
rect,
|
||||
ascent: font_ascent.into(),
|
||||
font_metrics,
|
||||
font_key,
|
||||
glyphs,
|
||||
}));
|
||||
|
|
|
@ -7,6 +7,7 @@ use crate::geom::{PhysicalPoint, PhysicalRect};
|
|||
#[cfg(debug_assertions)]
|
||||
use crate::layout_debug;
|
||||
use crate::positioned::HoistedFragmentId;
|
||||
use gfx::font::FontMetrics as GfxFontMetrics;
|
||||
use gfx::text::glyph::GlyphStore;
|
||||
use gfx_traits::print_tree::PrintTree;
|
||||
#[cfg(not(debug_assertions))]
|
||||
|
@ -86,6 +87,29 @@ pub(crate) struct AnonymousFragment {
|
|||
pub scrollable_overflow: PhysicalRect<Length>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Serialize)]
|
||||
pub(crate) struct FontMetrics {
|
||||
pub ascent: Length,
|
||||
pub line_gap: Length,
|
||||
pub underline_offset: Length,
|
||||
pub underline_size: Length,
|
||||
pub strikeout_offset: Length,
|
||||
pub strikeout_size: Length,
|
||||
}
|
||||
|
||||
impl From<&GfxFontMetrics> for FontMetrics {
|
||||
fn from(metrics: &GfxFontMetrics) -> FontMetrics {
|
||||
FontMetrics {
|
||||
ascent: metrics.ascent.into(),
|
||||
line_gap: metrics.line_gap.into(),
|
||||
underline_offset: metrics.underline_offset.into(),
|
||||
underline_size: metrics.underline_size.into(),
|
||||
strikeout_offset: metrics.strikeout_offset.into(),
|
||||
strikeout_size: metrics.strikeout_size.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub(crate) struct TextFragment {
|
||||
pub debug_id: DebugId,
|
||||
|
@ -93,7 +117,7 @@ pub(crate) struct TextFragment {
|
|||
#[serde(skip_serializing)]
|
||||
pub parent_style: ServoArc<ComputedValues>,
|
||||
pub rect: Rect<Length>,
|
||||
pub ascent: Length,
|
||||
pub font_metrics: FontMetrics,
|
||||
#[serde(skip_serializing)]
|
||||
pub font_key: FontInstanceKey,
|
||||
pub glyphs: Vec<Arc<GlyphStore>>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue