diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-10-10 20:54:13 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-10-10 21:04:10 +0200 |
| commit | 9ac125dea8d6ea6cc01814d04413225845b69d65 (patch) | |
| tree | c7dabcda703e5f5b2704c67920efc490f2f8fb57 /src/layout | |
| parent | d4cc8c775d4c579aeac69ca2d212a604c67043b0 (diff) | |
Rename `State` to `Style` and move it into its own module
Diffstat (limited to 'src/layout')
| -rw-r--r-- | src/layout/par.rs | 8 | ||||
| -rw-r--r-- | src/layout/shaping.rs | 38 |
2 files changed, 23 insertions, 23 deletions
diff --git a/src/layout/par.rs b/src/layout/par.rs index 7f087eb3..cf37f005 100644 --- a/src/layout/par.rs +++ b/src/layout/par.rs @@ -6,7 +6,7 @@ use unicode_bidi::{BidiInfo, Level}; use xi_unicode::LineBreakIterator; use super::*; -use crate::eval::FontState; +use crate::style::TextStyle; use crate::util::{EcoString, RangeExt, SliceExt}; type Range = std::ops::Range<usize>; @@ -29,7 +29,7 @@ pub enum ParChild { /// Spacing between other nodes. Spacing(Linear), /// A run of text and how to align it in its line. - Text(EcoString, Align, Rc<FontState>, Vec<Decoration>), + Text(EcoString, Align, Rc<TextStyle>, Vec<Decoration>), /// Any child node and how to align it in its line. Any(LayoutNode, Align, Vec<Decoration>), } @@ -139,11 +139,11 @@ impl<'a> ParLayouter<'a> { items.push(ParItem::Spacing(resolved)); ranges.push(range); } - ParChild::Text(_, align, state, decos) => { + ParChild::Text(_, align, style, decos) => { // TODO: Also split by language and script. for (subrange, dir) in split_runs(&bidi, range) { let text = &bidi.text[subrange.clone()]; - let shaped = shape(ctx, text, dir, state); + let shaped = shape(ctx, text, dir, style); items.push(ParItem::Text(shaped, *align, decos)); ranges.push(subrange); } diff --git a/src/layout/shaping.rs b/src/layout/shaping.rs index dc680276..4580ebf5 100644 --- a/src/layout/shaping.rs +++ b/src/layout/shaping.rs @@ -4,9 +4,9 @@ use std::ops::Range; use rustybuzz::UnicodeBuffer; use super::{Element, Frame, Glyph, LayoutContext, Text}; -use crate::eval::FontState; use crate::font::{Face, FaceId, FontVariant}; use crate::geom::{Dir, Em, Length, Point, Size}; +use crate::style::TextStyle; use crate::util::SliceExt; /// Shape text into [`ShapedText`]. @@ -14,7 +14,7 @@ pub fn shape<'a>( ctx: &mut LayoutContext, text: &'a str, dir: Dir, - state: &'a FontState, + style: &'a TextStyle, ) -> ShapedText<'a> { let mut glyphs = vec![]; if !text.is_empty() { @@ -24,19 +24,19 @@ pub fn shape<'a>( 0, text, dir, - state.size, - state.variant(), - state.families(), + style.size, + style.variant(), + style.families(), None, ); } - let (size, baseline) = measure(ctx, &glyphs, state); + let (size, baseline) = measure(ctx, &glyphs, style); ShapedText { text, dir, - state, + style, size, baseline, glyphs: Cow::Owned(glyphs), @@ -54,7 +54,7 @@ pub struct ShapedText<'a> { /// The text direction. pub dir: Dir, /// The properties used for font selection. - pub state: &'a FontState, + pub style: &'a TextStyle, /// The font size. pub size: Size, /// The baseline from the top of the frame. @@ -93,9 +93,9 @@ impl<'a> ShapedText<'a> { let mut text = Text { face_id, - size: self.state.size, + size: self.style.size, width: Length::zero(), - fill: self.state.fill, + fill: self.style.fill, glyphs: vec![], }; @@ -123,17 +123,17 @@ impl<'a> ShapedText<'a> { text_range: Range<usize>, ) -> ShapedText<'a> { if let Some(glyphs) = self.slice_safe_to_break(text_range.clone()) { - let (size, baseline) = measure(ctx, glyphs, self.state); + let (size, baseline) = measure(ctx, glyphs, self.style); Self { text: &self.text[text_range], dir: self.dir, - state: self.state, + style: self.style, size, baseline, glyphs: Cow::Borrowed(glyphs), } } else { - shape(ctx, &self.text[text_range], self.dir, self.state) + shape(ctx, &self.text[text_range], self.dir, self.style) } } @@ -334,7 +334,7 @@ fn shape_segment<'a>( fn measure( ctx: &mut LayoutContext, glyphs: &[ShapedGlyph], - state: &FontState, + style: &TextStyle, ) -> (Size, Length) { let mut width = Length::zero(); let mut top = Length::zero(); @@ -342,15 +342,15 @@ fn measure( // Expand top and bottom by reading the face's vertical metrics. let mut expand = |face: &Face| { - top.set_max(face.vertical_metric(state.top_edge, state.size)); - bottom.set_max(-face.vertical_metric(state.bottom_edge, state.size)); + top.set_max(face.vertical_metric(style.top_edge, style.size)); + bottom.set_max(-face.vertical_metric(style.bottom_edge, style.size)); }; if glyphs.is_empty() { // When there are no glyphs, we just use the vertical metrics of the // first available font. - for family in state.families() { - if let Some(face_id) = ctx.fonts.select(family, state.variant) { + for family in style.families() { + if let Some(face_id) = ctx.fonts.select(family, style.variant) { expand(ctx.fonts.get(face_id)); break; } @@ -361,7 +361,7 @@ fn measure( expand(face); for glyph in group { - width += glyph.x_advance.to_length(state.size); + width += glyph.x_advance.to_length(style.size); } } } |
