diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-12-02 13:17:07 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-12-02 13:21:36 +0100 |
| commit | 5110a41de1ca2236739ace2d37a1af912bb029f1 (patch) | |
| tree | 22cc223140052bd7ec10798f5ecbffaae7c934a8 /library/src/text | |
| parent | 33ab1fdbdda4e95e48b767a3f7f8f66413b6de0e (diff) | |
Introduce virtual typesetter
Diffstat (limited to 'library/src/text')
| -rw-r--r-- | library/src/text/deco.rs | 2 | ||||
| -rw-r--r-- | library/src/text/misc.rs | 4 | ||||
| -rw-r--r-- | library/src/text/raw.rs | 2 | ||||
| -rw-r--r-- | library/src/text/shaping.rs | 31 | ||||
| -rw-r--r-- | library/src/text/shift.rs | 7 |
5 files changed, 23 insertions, 23 deletions
diff --git a/library/src/text/deco.rs b/library/src/text/deco.rs index e81b219c..4c9f6dcd 100644 --- a/library/src/text/deco.rs +++ b/library/src/text/deco.rs @@ -47,7 +47,7 @@ impl<const L: DecoLine> DecoNode<L> { } impl<const L: DecoLine> Show for DecoNode<L> { - fn show(&self, _: Tracked<dyn World>, styles: StyleChain) -> Content { + fn show(&self, _: &mut Vt, _: &Content, styles: StyleChain) -> Content { self.0.clone().styled( TextNode::DECO, Decoration { diff --git a/library/src/text/misc.rs b/library/src/text/misc.rs index 32e0cc1d..c3897a8e 100644 --- a/library/src/text/misc.rs +++ b/library/src/text/misc.rs @@ -62,7 +62,7 @@ impl StrongNode { } impl Show for StrongNode { - fn show(&self, _: Tracked<dyn World>, styles: StyleChain) -> Content { + fn show(&self, _: &mut Vt, _: &Content, styles: StyleChain) -> Content { self.0.clone().styled(TextNode::DELTA, Delta(styles.get(Self::DELTA))) } } @@ -104,7 +104,7 @@ impl EmphNode { } impl Show for EmphNode { - fn show(&self, _: Tracked<dyn World>, _: StyleChain) -> Content { + fn show(&self, _: &mut Vt, _: &Content, _: StyleChain) -> Content { self.0.clone().styled(TextNode::EMPH, Toggle) } } diff --git a/library/src/text/raw.rs b/library/src/text/raw.rs index 6c726513..c0bf105f 100644 --- a/library/src/text/raw.rs +++ b/library/src/text/raw.rs @@ -43,7 +43,7 @@ impl RawNode { } impl Show for RawNode { - fn show(&self, _: Tracked<dyn World>, styles: StyleChain) -> Content { + fn show(&self, _: &mut Vt, _: &Content, styles: StyleChain) -> Content { let lang = styles.get(Self::LANG).as_ref().map(|s| s.to_lowercase()); let foreground = THEME .settings diff --git a/library/src/text/shaping.rs b/library/src/text/shaping.rs index 88fec39d..6dbbb535 100644 --- a/library/src/text/shaping.rs +++ b/library/src/text/shaping.rs @@ -81,8 +81,8 @@ impl<'a> ShapedText<'a> { /// /// The `justification` defines how much extra advance width each /// [justifiable glyph](ShapedGlyph::is_justifiable) will get. - pub fn build(&self, world: Tracked<dyn World>, justification: Abs) -> Frame { - let (top, bottom) = self.measure(world); + pub fn build(&self, vt: &Vt, justification: Abs) -> Frame { + let (top, bottom) = self.measure(vt); let size = Size::new(self.width, top + bottom); let mut offset = Abs::zero(); @@ -137,7 +137,7 @@ impl<'a> ShapedText<'a> { } /// Measure the top and bottom extent of this text. - fn measure(&self, world: Tracked<dyn World>) -> (Abs, Abs) { + fn measure(&self, vt: &Vt) -> (Abs, Abs) { let mut top = Abs::zero(); let mut bottom = Abs::zero(); @@ -154,6 +154,7 @@ impl<'a> ShapedText<'a> { if self.glyphs.is_empty() { // When there are no glyphs, we just use the vertical metrics of the // first available font. + let world = vt.world(); for family in families(self.styles) { if let Some(font) = world .book() @@ -190,11 +191,7 @@ impl<'a> ShapedText<'a> { /// Reshape a range of the shaped text, reusing information from this /// shaping process if possible. - pub fn reshape( - &'a self, - world: Tracked<dyn World>, - text_range: Range<usize>, - ) -> ShapedText<'a> { + pub fn reshape(&'a self, vt: &Vt, text_range: Range<usize>) -> ShapedText<'a> { if let Some(glyphs) = self.slice_safe_to_break(text_range.clone()) { Self { text: &self.text[text_range], @@ -206,13 +203,14 @@ impl<'a> ShapedText<'a> { glyphs: Cow::Borrowed(glyphs), } } else { - shape(world, &self.text[text_range], self.styles, self.dir) + shape(vt, &self.text[text_range], self.styles, self.dir) } } /// Push a hyphen to end of the text. - pub fn push_hyphen(&mut self, world: Tracked<dyn World>) { + pub fn push_hyphen(&mut self, vt: &Vt) { families(self.styles).find_map(|family| { + let world = vt.world(); let font = world .book() .select(family, self.variant) @@ -303,7 +301,7 @@ impl Debug for ShapedText<'_> { /// Holds shaping results and metadata common to all shaped segments. struct ShapingContext<'a> { - world: Tracked<'a, dyn World>, + vt: &'a Vt<'a>, glyphs: Vec<ShapedGlyph>, used: Vec<Font>, styles: StyleChain<'a>, @@ -316,7 +314,7 @@ struct ShapingContext<'a> { /// Shape text into [`ShapedText`]. pub fn shape<'a>( - world: Tracked<dyn World>, + vt: &Vt, text: &'a str, styles: StyleChain<'a>, dir: Dir, @@ -324,7 +322,7 @@ pub fn shape<'a>( let size = styles.get(TextNode::SIZE); let mut ctx = ShapingContext { - world, + vt, size, glyphs: vec![], used: vec![], @@ -365,10 +363,11 @@ fn shape_segment<'a>( } // Find the next available family. - let book = ctx.world.book(); + let world = ctx.vt.world(); + let book = world.book(); let mut selection = families.find_map(|family| { book.select(family, ctx.variant) - .and_then(|id| ctx.world.font(id)) + .and_then(|id| world.font(id)) .filter(|font| !ctx.used.contains(font)) }); @@ -377,7 +376,7 @@ fn shape_segment<'a>( let first = ctx.used.first().map(Font::info); selection = book .select_fallback(first, ctx.variant, text) - .and_then(|id| ctx.world.font(id)) + .and_then(|id| world.font(id)) .filter(|font| !ctx.used.contains(font)); } diff --git a/library/src/text/shift.rs b/library/src/text/shift.rs index df8ec5e6..3419cc91 100644 --- a/library/src/text/shift.rs +++ b/library/src/text/shift.rs @@ -43,11 +43,11 @@ impl<const S: ShiftKind> ShiftNode<S> { } impl<const S: ShiftKind> Show for ShiftNode<S> { - fn show(&self, world: Tracked<dyn World>, styles: StyleChain) -> Content { + fn show(&self, vt: &mut Vt, _: &Content, styles: StyleChain) -> Content { let mut transformed = None; if styles.get(Self::TYPOGRAPHIC) { if let Some(text) = search_text(&self.0, S) { - if is_shapable(world, &text, styles) { + if is_shapable(vt, &text, styles) { transformed = Some(TextNode::packed(text)); } } @@ -85,7 +85,8 @@ fn search_text(content: &Content, mode: ShiftKind) -> Option<EcoString> { /// Checks whether the first retrievable family contains all code points of the /// given string. -fn is_shapable(world: Tracked<dyn World>, text: &str, styles: StyleChain) -> bool { +fn is_shapable(vt: &Vt, text: &str, styles: StyleChain) -> bool { + let world = vt.world(); for family in styles.get(TextNode::FAMILY).0.iter() { if let Some(font) = world .book() |
