diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-04-19 13:54:04 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-04-19 13:54:04 +0200 |
| commit | 255d4c620f39133b40a9132843781f2a620a6008 (patch) | |
| tree | acf95fdc671f2bb163d0b819b87e778bc7502d93 /src/library | |
| parent | f27f7a05ab24e57da99af9b4b96bab82bb31276a (diff) | |
Automatic frame merging
Diffstat (limited to 'src/library')
| -rw-r--r-- | src/library/graphics/image.rs | 2 | ||||
| -rw-r--r-- | src/library/graphics/shape.rs | 2 | ||||
| -rw-r--r-- | src/library/layout/grid.rs | 2 | ||||
| -rw-r--r-- | src/library/text/par.rs | 19 | ||||
| -rw-r--r-- | src/library/text/shaping.rs | 3 |
5 files changed, 15 insertions, 13 deletions
diff --git a/src/library/graphics/image.rs b/src/library/graphics/image.rs index 193dc60e..ee854130 100644 --- a/src/library/graphics/image.rs +++ b/src/library/graphics/image.rs @@ -83,7 +83,7 @@ impl Layout for ImageNode { // Apply link if it exists. if let Some(url) = styles.get(TextNode::LINK) { - frame.link(url); + frame.link(url.clone()); } Ok(vec![Arc::new(frame)]) diff --git a/src/library/graphics/shape.rs b/src/library/graphics/shape.rs index 236406c0..e4c832f0 100644 --- a/src/library/graphics/shape.rs +++ b/src/library/graphics/shape.rs @@ -132,7 +132,7 @@ impl<const S: ShapeKind> Layout for ShapeNode<S> { // Apply link if it exists. if let Some(url) = styles.get(TextNode::LINK) { - frame.link(url); + frame.link(url.clone()); } Ok(frames) diff --git a/src/library/layout/grid.rs b/src/library/layout/grid.rs index ad6323d5..4908d4d8 100644 --- a/src/library/layout/grid.rs +++ b/src/library/layout/grid.rs @@ -551,7 +551,7 @@ impl<'a> GridLayouter<'a> { }; let height = frame.size.y; - output.merge_frame(pos, frame); + output.push_frame(pos, frame); pos.y += height; } diff --git a/src/library/text/par.rs b/src/library/text/par.rs index 9f45a411..17fcea75 100644 --- a/src/library/text/par.rs +++ b/src/library/text/par.rs @@ -8,7 +8,7 @@ use super::{shape, Lang, Quoter, Quotes, RepeatNode, ShapedText, TextNode}; use crate::font::FontStore; use crate::library::layout::Spacing; use crate::library::prelude::*; -use crate::util::{ArcExt, EcoString}; +use crate::util::{EcoString, MaybeShared}; /// Arrange text, spacing and inline-level nodes into a paragraph. #[derive(Hash)] @@ -283,7 +283,7 @@ enum Item<'a> { /// Fractional spacing between other items. Fractional(Fraction), /// A layouted child node. - Frame(Frame), + Frame(Arc<Frame>), /// A repeating node. Repeat(&'a RepeatNode, StyleChain<'a>), } @@ -522,7 +522,7 @@ fn prepare<'a>( let size = Size::new(regions.first.x, regions.base.y); let pod = Regions::one(size, regions.base, Spec::splat(false)); let frame = node.layout(ctx, &pod, styles)?.remove(0); - items.push(Item::Frame(Arc::take(frame))); + items.push(Item::Frame(frame)); } } } @@ -1041,7 +1041,7 @@ fn stack( let pos = Point::with_y(output.size.y); output.size.y += height; - output.merge_frame(pos, frame); + output.push_frame(pos, frame); regions.first.y -= height + p.leading; first = false; @@ -1111,7 +1111,7 @@ fn commit( // Build the frames and determine the height and baseline. let mut frames = vec![]; for item in reordered { - let mut push = |offset: &mut Length, frame: Frame| { + let mut push = |offset: &mut Length, frame: MaybeShared<Frame>| { let width = frame.size.x; top.set_max(frame.baseline()); bottom.set_max(frame.size.y - frame.baseline()); @@ -1127,10 +1127,11 @@ fn commit( offset += v.share(fr, remaining); } Item::Text(shaped) => { - push(&mut offset, shaped.build(&mut ctx.fonts, justification)); + let frame = shaped.build(&mut ctx.fonts, justification); + push(&mut offset, MaybeShared::Owned(frame)); } Item::Frame(frame) => { - push(&mut offset, frame.clone()); + push(&mut offset, MaybeShared::Shared(frame.clone())); } Item::Repeat(node, styles) => { let before = offset; @@ -1146,7 +1147,7 @@ fn commit( } if frame.size.x > Length::zero() { for _ in 0 .. (count as usize).min(1000) { - push(&mut offset, frame.as_ref().clone()); + push(&mut offset, MaybeShared::Shared(frame.clone())); offset += apart; } } @@ -1168,7 +1169,7 @@ fn commit( for (offset, frame) in frames { let x = offset + p.align.position(remaining); let y = top - frame.baseline(); - output.merge_frame(Point::new(x, y), frame); + output.push_frame(Point::new(x, y), frame); } Ok(output) diff --git a/src/library/text/shaping.rs b/src/library/text/shaping.rs index 055761df..80f1b17d 100644 --- a/src/library/text/shaping.rs +++ b/src/library/text/shaping.rs @@ -100,6 +100,7 @@ impl<'a> ShapedText<'a> { Em::zero() }, x_offset: glyph.x_offset, + c: glyph.c, }) .collect(); @@ -118,7 +119,7 @@ impl<'a> ShapedText<'a> { // Apply link if it exists. if let Some(url) = self.styles.get(TextNode::LINK) { - frame.link(url); + frame.link(url.clone()); } frame |
