summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-06-12 17:45:52 +0200
committerLaurenz <laurmaedje@gmail.com>2022-06-12 20:51:31 +0200
commit7660978ee5d842648e244e2972273264d94ca37b (patch)
tree74e1c8bc578afa616ddcd6c4c9e79c3c3d311d78 /src/library
parent6e3b1a2c80428d581d00b9d65e1c45401df2e210 (diff)
Move `Arc` into `Frame`
Diffstat (limited to 'src/library')
-rw-r--r--src/library/graphics/hide.rs4
-rw-r--r--src/library/graphics/image.rs4
-rw-r--r--src/library/graphics/line.rs4
-rw-r--r--src/library/graphics/shape.rs8
-rw-r--r--src/library/graphics/transform.rs8
-rw-r--r--src/library/layout/align.rs4
-rw-r--r--src/library/layout/columns.rs4
-rw-r--r--src/library/layout/flow.rs16
-rw-r--r--src/library/layout/grid.rs8
-rw-r--r--src/library/layout/pad.rs3
-rw-r--r--src/library/layout/page.rs8
-rw-r--r--src/library/layout/place.rs4
-rw-r--r--src/library/layout/stack.rs14
-rw-r--r--src/library/math/rex.rs4
-rw-r--r--src/library/structure/doc.rs6
-rw-r--r--src/library/text/par.rs34
-rw-r--r--src/library/text/repeat.rs2
17 files changed, 59 insertions, 76 deletions
diff --git a/src/library/graphics/hide.rs b/src/library/graphics/hide.rs
index c969ef76..0ed02d1b 100644
--- a/src/library/graphics/hide.rs
+++ b/src/library/graphics/hide.rs
@@ -17,12 +17,12 @@ impl Layout for HideNode {
ctx: &mut Context,
regions: &Regions,
styles: StyleChain,
- ) -> TypResult<Vec<Arc<Frame>>> {
+ ) -> TypResult<Vec<Frame>> {
let mut frames = self.0.layout(ctx, regions, styles)?;
// Clear the frames.
for frame in &mut frames {
- Arc::make_mut(frame).clear();
+ frame.clear();
}
Ok(frames)
diff --git a/src/library/graphics/image.rs b/src/library/graphics/image.rs
index d0bcfa44..1781eb8a 100644
--- a/src/library/graphics/image.rs
+++ b/src/library/graphics/image.rs
@@ -38,7 +38,7 @@ impl Layout for ImageNode {
ctx: &mut Context,
regions: &Regions,
styles: StyleChain,
- ) -> TypResult<Vec<Arc<Frame>>> {
+ ) -> TypResult<Vec<Frame>> {
let img = ctx.images.get(self.0);
let pxw = img.width() as f64;
let pxh = img.height() as f64;
@@ -90,7 +90,7 @@ impl Layout for ImageNode {
frame.link(url.clone());
}
- Ok(vec![Arc::new(frame)])
+ Ok(vec![frame])
}
}
diff --git a/src/library/graphics/line.rs b/src/library/graphics/line.rs
index 8e5ceae1..15c54f46 100644
--- a/src/library/graphics/line.rs
+++ b/src/library/graphics/line.rs
@@ -43,7 +43,7 @@ impl Layout for LineNode {
_: &mut Context,
regions: &Regions,
styles: StyleChain,
- ) -> TypResult<Vec<Arc<Frame>>> {
+ ) -> TypResult<Vec<Frame>> {
let stroke = styles.get(Self::STROKE).unwrap_or_default();
let origin = self
@@ -64,7 +64,7 @@ impl Layout for LineNode {
let shape = Geometry::Line(delta.to_point()).stroked(stroke);
frame.push(origin.to_point(), Element::Shape(shape));
- Ok(vec![Arc::new(frame)])
+ Ok(vec![frame])
}
}
diff --git a/src/library/graphics/shape.rs b/src/library/graphics/shape.rs
index 6c315c24..bf581815 100644
--- a/src/library/graphics/shape.rs
+++ b/src/library/graphics/shape.rs
@@ -79,7 +79,7 @@ impl<const S: ShapeKind> Layout for ShapeNode<S> {
ctx: &mut Context,
regions: &Regions,
styles: StyleChain,
- ) -> TypResult<Vec<Arc<Frame>>> {
+ ) -> TypResult<Vec<Frame>> {
let mut frames;
if let Some(child) = &self.0 {
let mut inset = styles.get(Self::INSET);
@@ -94,7 +94,7 @@ impl<const S: ShapeKind> Layout for ShapeNode<S> {
frames = child.layout(ctx, &pod, styles)?;
for frame in frames.iter_mut() {
- Arc::make_mut(frame).apply_role(Role::GenericBlock);
+ frame.apply_role(Role::GenericBlock);
}
// Relayout with full expansion into square region to make sure
@@ -131,10 +131,10 @@ impl<const S: ShapeKind> Layout for ShapeNode<S> {
size = regions.expand.select(regions.first, size);
}
- frames = vec![Arc::new(Frame::new(size))];
+ frames = vec![Frame::new(size)];
}
- let frame = Arc::make_mut(&mut frames[0]);
+ let frame = &mut frames[0];
// Add fill and/or stroke.
let fill = styles.get(Self::FILL);
diff --git a/src/library/graphics/transform.rs b/src/library/graphics/transform.rs
index 7176a683..2a0149bc 100644
--- a/src/library/graphics/transform.rs
+++ b/src/library/graphics/transform.rs
@@ -28,13 +28,13 @@ impl Layout for MoveNode {
ctx: &mut Context,
regions: &Regions,
styles: StyleChain,
- ) -> TypResult<Vec<Arc<Frame>>> {
+ ) -> TypResult<Vec<Frame>> {
let mut frames = self.child.layout(ctx, regions, styles)?;
let delta = self.delta.resolve(styles);
for frame in &mut frames {
let delta = delta.zip(frame.size()).map(|(d, s)| d.relative_to(s));
- Arc::make_mut(frame).translate(delta.to_point());
+ frame.translate(delta.to_point());
}
Ok(frames)
@@ -89,7 +89,7 @@ impl<const T: TransformKind> Layout for TransformNode<T> {
ctx: &mut Context,
regions: &Regions,
styles: StyleChain,
- ) -> TypResult<Vec<Arc<Frame>>> {
+ ) -> TypResult<Vec<Frame>> {
let origin = styles.get(Self::ORIGIN).unwrap_or(Align::CENTER_HORIZON);
let mut frames = self.child.layout(ctx, regions, styles)?;
@@ -99,7 +99,7 @@ impl<const T: TransformKind> Layout for TransformNode<T> {
.pre_concat(self.transform)
.pre_concat(Transform::translate(-x, -y));
- Arc::make_mut(frame).transform(transform);
+ frame.transform(transform);
}
Ok(frames)
diff --git a/src/library/layout/align.rs b/src/library/layout/align.rs
index c5adcf9f..e7a27c04 100644
--- a/src/library/layout/align.rs
+++ b/src/library/layout/align.rs
@@ -31,7 +31,7 @@ impl Layout for AlignNode {
ctx: &mut Context,
regions: &Regions,
styles: StyleChain,
- ) -> TypResult<Vec<Arc<Frame>>> {
+ ) -> TypResult<Vec<Frame>> {
// The child only needs to expand along an axis if there's no alignment.
let mut pod = regions.clone();
pod.expand &= self.aligns.map_is_none();
@@ -53,7 +53,7 @@ impl Layout for AlignNode {
.map(|align| align.resolve(styles))
.unwrap_or(Spec::new(Align::Left, Align::Top));
- Arc::make_mut(frame).resize(target, aligns);
+ frame.resize(target, aligns);
}
Ok(frames)
diff --git a/src/library/layout/columns.rs b/src/library/layout/columns.rs
index b9e308f2..33ceab86 100644
--- a/src/library/layout/columns.rs
+++ b/src/library/layout/columns.rs
@@ -31,7 +31,7 @@ impl Layout for ColumnsNode {
ctx: &mut Context,
regions: &Regions,
styles: StyleChain,
- ) -> TypResult<Vec<Arc<Frame>>> {
+ ) -> TypResult<Vec<Frame>> {
// Separating the infinite space into infinite columns does not make
// much sense.
if !regions.first.x.is_finite() {
@@ -94,7 +94,7 @@ impl Layout for ColumnsNode {
cursor += width + gutter;
}
- finished.push(Arc::new(output));
+ finished.push(output);
}
Ok(finished)
diff --git a/src/library/layout/flow.rs b/src/library/layout/flow.rs
index b6844f55..c6d2999e 100644
--- a/src/library/layout/flow.rs
+++ b/src/library/layout/flow.rs
@@ -28,7 +28,7 @@ impl Layout for FlowNode {
ctx: &mut Context,
regions: &Regions,
styles: StyleChain,
- ) -> TypResult<Vec<Arc<Frame>>> {
+ ) -> TypResult<Vec<Frame>> {
let mut layouter = FlowLayouter::new(regions);
for (child, map) in self.0.iter() {
@@ -92,7 +92,7 @@ pub struct FlowLayouter {
/// Spacing and layouted nodes.
items: Vec<FlowItem>,
/// Finished frames for previous regions.
- finished: Vec<Arc<Frame>>,
+ finished: Vec<Frame>,
}
/// A prepared item in a flow layout.
@@ -102,9 +102,9 @@ enum FlowItem {
/// Fractional spacing between other items.
Fractional(Fraction),
/// A frame for a layouted child node and how to align it.
- Frame(Arc<Frame>, Spec<Align>),
+ Frame(Frame, Spec<Align>),
/// An absolutely placed frame.
- Placed(Arc<Frame>),
+ Placed(Frame),
}
impl FlowLayouter {
@@ -184,9 +184,7 @@ impl FlowLayouter {
let len = frames.len();
for (i, mut frame) in frames.into_iter().enumerate() {
// Set the generic block role.
- if frame.role().map_or(true, Role::is_weak) {
- Arc::make_mut(&mut frame).apply_role(Role::GenericBlock);
- }
+ frame.apply_role(Role::GenericBlock);
// Grow our size, shrink the region and save the frame for later.
let size = frame.size();
@@ -248,11 +246,11 @@ impl FlowLayouter {
self.full = self.regions.first;
self.used = Size::zero();
self.fr = Fraction::zero();
- self.finished.push(Arc::new(output));
+ self.finished.push(output);
}
/// Finish layouting and return the resulting frames.
- pub fn finish(mut self) -> Vec<Arc<Frame>> {
+ pub fn finish(mut self) -> Vec<Frame> {
if self.expand.y {
while self.regions.backlog.len() > 0 {
self.finish_region();
diff --git a/src/library/layout/grid.rs b/src/library/layout/grid.rs
index c04913a1..c02662a6 100644
--- a/src/library/layout/grid.rs
+++ b/src/library/layout/grid.rs
@@ -36,7 +36,7 @@ impl Layout for GridNode {
ctx: &mut Context,
regions: &Regions,
styles: StyleChain,
- ) -> TypResult<Vec<Arc<Frame>>> {
+ ) -> TypResult<Vec<Frame>> {
// Prepare grid layout by unifying content and gutter tracks.
let layouter = GridLayouter::new(
ctx,
@@ -116,7 +116,7 @@ pub struct GridLayouter<'a> {
/// The sum of fractions in the current region.
fr: Fraction,
/// Frames for finished regions.
- finished: Vec<Arc<Frame>>,
+ finished: Vec<Frame>,
}
/// Produced by initial row layout, auto and relative rows are already finished,
@@ -203,7 +203,7 @@ impl<'a> GridLayouter<'a> {
}
/// Determines the columns sizes and then layouts the grid row-by-row.
- pub fn layout(mut self) -> TypResult<Vec<Arc<Frame>>> {
+ pub fn layout(mut self) -> TypResult<Vec<Frame>> {
self.ctx.pins.freeze();
self.measure_columns()?;
self.ctx.pins.unfreeze();
@@ -567,7 +567,7 @@ impl<'a> GridLayouter<'a> {
pos.y += height;
}
- self.finished.push(Arc::new(output));
+ self.finished.push(output);
self.regions.next();
self.full = self.regions.first.y;
self.used.y = Length::zero();
diff --git a/src/library/layout/pad.rs b/src/library/layout/pad.rs
index 29a72588..dfd425bd 100644
--- a/src/library/layout/pad.rs
+++ b/src/library/layout/pad.rs
@@ -31,7 +31,7 @@ impl Layout for PadNode {
ctx: &mut Context,
regions: &Regions,
styles: StyleChain,
- ) -> TypResult<Vec<Arc<Frame>>> {
+ ) -> TypResult<Vec<Frame>> {
// Layout child into padded regions.
let padding = self.padding.resolve(styles);
let pod = regions.map(|size| shrink(size, padding));
@@ -45,7 +45,6 @@ impl Layout for PadNode {
let offset = Point::new(padding.left, padding.top);
// Grow the frame and translate everything in the frame inwards.
- let frame = Arc::make_mut(frame);
frame.set_size(padded);
frame.translate(offset);
}
diff --git a/src/library/layout/page.rs b/src/library/layout/page.rs
index e22bb4f7..e2f414ab 100644
--- a/src/library/layout/page.rs
+++ b/src/library/layout/page.rs
@@ -60,7 +60,7 @@ impl PageNode {
ctx: &mut Context,
mut page: usize,
styles: StyleChain,
- ) -> TypResult<Vec<Arc<Frame>>> {
+ ) -> TypResult<Vec<Frame>> {
// When one of the lengths is infinite the page fits its content along
// that axis.
let width = styles.get(Self::WIDTH).unwrap_or(Length::inf());
@@ -129,12 +129,12 @@ impl PageNode {
if let Some(content) = marginal.resolve(ctx, page)? {
let pod = Regions::one(area, area, Spec::splat(true));
let mut sub = content.layout(ctx, &pod, styles)?.remove(0);
- Arc::make_mut(&mut sub).apply_role(role);
+ sub.apply_role(role);
if role == Role::Background {
- Arc::make_mut(frame).prepend_frame(pos, sub);
+ frame.prepend_frame(pos, sub);
} else {
- Arc::make_mut(frame).push_frame(pos, sub);
+ frame.push_frame(pos, sub);
}
}
}
diff --git a/src/library/layout/place.rs b/src/library/layout/place.rs
index 408ca129..67e46d3b 100644
--- a/src/library/layout/place.rs
+++ b/src/library/layout/place.rs
@@ -24,7 +24,7 @@ impl Layout for PlaceNode {
ctx: &mut Context,
regions: &Regions,
styles: StyleChain,
- ) -> TypResult<Vec<Arc<Frame>>> {
+ ) -> TypResult<Vec<Frame>> {
let out_of_flow = self.out_of_flow();
// The pod is the base area of the region because for absolute
@@ -41,7 +41,7 @@ impl Layout for PlaceNode {
// space in our parent. Otherwise, respect the expand settings.
let frame = &mut frames[0];
let target = regions.expand.select(regions.first, Size::zero());
- Arc::make_mut(frame).resize(target, Align::LEFT_TOP);
+ frame.resize(target, Align::LEFT_TOP);
Ok(frames)
}
diff --git a/src/library/layout/stack.rs b/src/library/layout/stack.rs
index 5d3e1786..b1268404 100644
--- a/src/library/layout/stack.rs
+++ b/src/library/layout/stack.rs
@@ -30,7 +30,7 @@ impl Layout for StackNode {
ctx: &mut Context,
regions: &Regions,
styles: StyleChain,
- ) -> TypResult<Vec<Arc<Frame>>> {
+ ) -> TypResult<Vec<Frame>> {
let mut layouter = StackLayouter::new(self.dir, regions, styles);
// Spacing to insert before the next node.
@@ -107,7 +107,7 @@ pub struct StackLayouter<'a> {
/// fractional spacing.
items: Vec<StackItem>,
/// Finished frames for previous regions.
- finished: Vec<Arc<Frame>>,
+ finished: Vec<Frame>,
}
/// A prepared item in a stack layout.
@@ -117,7 +117,7 @@ enum StackItem {
/// Fractional spacing between other items.
Fractional(Fraction),
/// A frame for a layouted child node.
- Frame(Arc<Frame>, Align),
+ Frame(Frame, Align),
}
impl<'a> StackLayouter<'a> {
@@ -196,9 +196,7 @@ impl<'a> StackLayouter<'a> {
let len = frames.len();
for (i, mut frame) in frames.into_iter().enumerate() {
// Set the generic block role.
- if frame.role().map_or(true, Role::is_weak) {
- Arc::make_mut(&mut frame).apply_role(Role::GenericBlock);
- }
+ frame.apply_role(Role::GenericBlock);
// Grow our size, shrink the region and save the frame for later.
let size = frame.size().to_gen(self.axis);
@@ -268,11 +266,11 @@ impl<'a> StackLayouter<'a> {
self.full = self.regions.first;
self.used = Gen::zero();
self.fr = Fraction::zero();
- self.finished.push(Arc::new(output));
+ self.finished.push(output);
}
/// Finish layouting and return the resulting frames.
- pub fn finish(mut self) -> Vec<Arc<Frame>> {
+ pub fn finish(mut self) -> Vec<Frame> {
self.finish_region();
self.finished
}
diff --git a/src/library/math/rex.rs b/src/library/math/rex.rs
index 930829de..a8dbd764 100644
--- a/src/library/math/rex.rs
+++ b/src/library/math/rex.rs
@@ -25,7 +25,7 @@ impl Layout for RexNode {
ctx: &mut Context,
_: &Regions,
styles: StyleChain,
- ) -> TypResult<Vec<Arc<Frame>>> {
+ ) -> TypResult<Vec<Frame>> {
// Load the font.
let span = self.tex.span;
let face_id = ctx
@@ -80,7 +80,7 @@ impl Layout for RexNode {
// Render into the frame.
renderer.render(&layout, &mut backend);
- Ok(vec![Arc::new(backend.frame)])
+ Ok(vec![backend.frame])
}
}
diff --git a/src/library/structure/doc.rs b/src/library/structure/doc.rs
index d3fc0b39..80472e24 100644
--- a/src/library/structure/doc.rs
+++ b/src/library/structure/doc.rs
@@ -7,11 +7,7 @@ pub struct DocNode(pub StyleVec<PageNode>);
impl DocNode {
/// Layout the document into a sequence of frames, one per page.
- pub fn layout(
- &self,
- ctx: &mut Context,
- styles: StyleChain,
- ) -> TypResult<Vec<Arc<Frame>>> {
+ pub fn layout(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Vec<Frame>> {
let mut frames = vec![];
for (page, map) in self.0.iter() {
let number = 1 + frames.len();
diff --git a/src/library/text/par.rs b/src/library/text/par.rs
index 7a656a30..e4013163 100644
--- a/src/library/text/par.rs
+++ b/src/library/text/par.rs
@@ -1,5 +1,4 @@
use std::cmp::Ordering;
-use std::sync::Arc;
use unicode_bidi::{BidiInfo, Level};
use unicode_script::{Script, UnicodeScript};
@@ -9,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::{EcoString, MaybeShared};
+use crate::util::EcoString;
/// Arrange text, spacing and inline-level nodes into a paragraph.
#[derive(Hash)]
@@ -71,7 +70,7 @@ impl Layout for ParNode {
ctx: &mut Context,
regions: &Regions,
styles: StyleChain,
- ) -> TypResult<Vec<Arc<Frame>>> {
+ ) -> TypResult<Vec<Frame>> {
// Collect all text into one string for BiDi analysis.
let (text, segments) = collect(self, &styles);
@@ -305,7 +304,7 @@ enum Item<'a> {
/// Fractional spacing between other items.
Fractional(Fraction),
/// A layouted child node.
- Frame(Arc<Frame>),
+ Frame(Frame),
/// A repeating node.
Repeat(&'a RepeatNode, StyleChain<'a>),
/// A pin identified by index.
@@ -551,16 +550,9 @@ fn prepare<'a>(
} else {
let size = Size::new(regions.first.x, regions.base.y);
let pod = Regions::one(size, regions.base, Spec::splat(false));
-
let mut frame = node.layout(ctx, &pod, styles)?.remove(0);
- let shift = styles.get(TextNode::BASELINE);
-
- if !shift.is_zero() || frame.role().map_or(true, Role::is_weak) {
- let frame = Arc::make_mut(&mut frame);
- frame.translate(Point::with_y(shift));
- frame.apply_role(Role::GenericInline);
- }
-
+ frame.translate(Point::with_y(styles.get(TextNode::BASELINE)));
+ frame.apply_role(Role::GenericInline);
items.push(Item::Frame(frame));
}
}
@@ -1053,7 +1045,7 @@ fn stack(
ctx: &mut Context,
lines: &[Line],
regions: &Regions,
-) -> TypResult<Vec<Arc<Frame>>> {
+) -> TypResult<Vec<Frame>> {
// Determine the paragraph's width: Full width of the region if we
// should expand or there's fractional spacing, fit-to-width otherwise.
let mut width = regions.first.x;
@@ -1074,7 +1066,7 @@ fn stack(
let height = frame.size().y;
while !regions.first.y.fits(height) && !regions.in_last() {
- finished.push(Arc::new(output));
+ finished.push(output);
output = Frame::new(Size::with_x(width));
output.apply_role(Role::Paragraph);
regions.next();
@@ -1093,7 +1085,7 @@ fn stack(
first = false;
}
- finished.push(Arc::new(output));
+ finished.push(output);
Ok(finished)
}
@@ -1155,7 +1147,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: MaybeShared<Frame>| {
+ let mut push = |offset: &mut Length, frame: Frame| {
let width = frame.width();
top.set_max(frame.baseline());
bottom.set_max(frame.size().y - frame.baseline());
@@ -1172,10 +1164,10 @@ fn commit(
}
Item::Text(shaped) => {
let frame = shaped.build(&mut ctx.fonts, justification);
- push(&mut offset, MaybeShared::Owned(frame));
+ push(&mut offset, frame);
}
Item::Frame(frame) => {
- push(&mut offset, MaybeShared::Shared(frame.clone()));
+ push(&mut offset, frame.clone());
}
Item::Repeat(node, styles) => {
let before = offset;
@@ -1192,7 +1184,7 @@ fn commit(
}
if width > Length::zero() {
for _ in 0 .. (count as usize).min(1000) {
- push(&mut offset, MaybeShared::Shared(frame.clone()));
+ push(&mut offset, frame.clone());
offset += apart;
}
}
@@ -1201,7 +1193,7 @@ fn commit(
Item::Pin(idx) => {
let mut frame = Frame::new(Size::zero());
frame.push(Point::zero(), Element::Pin(*idx));
- push(&mut offset, MaybeShared::Owned(frame));
+ push(&mut offset, frame);
}
}
}
diff --git a/src/library/text/repeat.rs b/src/library/text/repeat.rs
index 9ee8286b..a3e83ac7 100644
--- a/src/library/text/repeat.rs
+++ b/src/library/text/repeat.rs
@@ -17,7 +17,7 @@ impl Layout for RepeatNode {
ctx: &mut Context,
regions: &Regions,
styles: StyleChain,
- ) -> TypResult<Vec<Arc<Frame>>> {
+ ) -> TypResult<Vec<Frame>> {
// The actual repeating happens directly in the paragraph.
self.0.layout(ctx, regions, styles)
}