summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-01-31 16:06:44 +0100
committerLaurenz <laurmaedje@gmail.com>2022-01-31 16:47:00 +0100
commit20b1a38414101f842a6d9201133a5aaaa45a7cec (patch)
tree2365453d4dfdebfa11d618baad1a36c65b62d7c7 /src/library
parentfa57d86ed981373b66804972147bf59cab920e6b (diff)
Switch from `Rc` to `Arc`
Diffstat (limited to 'src/library')
-rw-r--r--src/library/align.rs4
-rw-r--r--src/library/columns.rs2
-rw-r--r--src/library/flow.rs10
-rw-r--r--src/library/grid.rs6
-rw-r--r--src/library/heading.rs4
-rw-r--r--src/library/hidden.rs4
-rw-r--r--src/library/image.rs2
-rw-r--r--src/library/link.rs5
-rw-r--r--src/library/list.rs4
-rw-r--r--src/library/mod.rs2
-rw-r--r--src/library/pad.rs4
-rw-r--r--src/library/page.rs2
-rw-r--r--src/library/par.rs14
-rw-r--r--src/library/place.rs4
-rw-r--r--src/library/shape.rs6
-rw-r--r--src/library/stack.rs8
-rw-r--r--src/library/table.rs2
-rw-r--r--src/library/text.rs6
-rw-r--r--src/library/transform.rs6
19 files changed, 48 insertions, 47 deletions
diff --git a/src/library/align.rs b/src/library/align.rs
index 8eee116e..ecf50cc4 100644
--- a/src/library/align.rs
+++ b/src/library/align.rs
@@ -27,7 +27,7 @@ impl Layout for AlignNode {
ctx: &mut LayoutContext,
regions: &Regions,
styles: StyleChain,
- ) -> Vec<Constrained<Rc<Frame>>> {
+ ) -> Vec<Constrained<Arc<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();
@@ -49,7 +49,7 @@ impl Layout for AlignNode {
let target = regions.expand.select(current, frame.size);
let default = Spec::new(Align::Left, Align::Top);
let aligns = self.aligns.unwrap_or(default);
- Rc::make_mut(frame).resize(target, aligns);
+ Arc::make_mut(frame).resize(target, aligns);
// Set constraints.
cts.expand = regions.expand;
diff --git a/src/library/columns.rs b/src/library/columns.rs
index d2dc350f..149da755 100644
--- a/src/library/columns.rs
+++ b/src/library/columns.rs
@@ -37,7 +37,7 @@ impl Layout for ColumnsNode {
ctx: &mut LayoutContext,
regions: &Regions,
styles: StyleChain,
- ) -> Vec<Constrained<Rc<Frame>>> {
+ ) -> Vec<Constrained<Arc<Frame>>> {
let columns = self.columns.get();
// Separating the infinite space into infinite columns does not make
diff --git a/src/library/flow.rs b/src/library/flow.rs
index 3405b04a..95426731 100644
--- a/src/library/flow.rs
+++ b/src/library/flow.rs
@@ -18,7 +18,7 @@ impl Layout for FlowNode {
ctx: &mut LayoutContext,
regions: &Regions,
styles: StyleChain,
- ) -> Vec<Constrained<Rc<Frame>>> {
+ ) -> Vec<Constrained<Arc<Frame>>> {
FlowLayouter::new(self, regions.clone()).layout(ctx, styles)
}
}
@@ -72,7 +72,7 @@ struct FlowLayouter<'a> {
/// Spacing and layouted nodes.
items: Vec<FlowItem>,
/// Finished frames for previous regions.
- finished: Vec<Constrained<Rc<Frame>>>,
+ finished: Vec<Constrained<Arc<Frame>>>,
}
/// A prepared item in a flow layout.
@@ -82,9 +82,9 @@ enum FlowItem {
/// Fractional spacing between other items.
Fractional(Fractional),
/// A frame for a layouted child node and how to align it.
- Frame(Rc<Frame>, Spec<Align>),
+ Frame(Arc<Frame>, Spec<Align>),
/// An absolutely placed frame.
- Placed(Rc<Frame>),
+ Placed(Arc<Frame>),
}
impl<'a> FlowLayouter<'a> {
@@ -113,7 +113,7 @@ impl<'a> FlowLayouter<'a> {
mut self,
ctx: &mut LayoutContext,
styles: StyleChain,
- ) -> Vec<Constrained<Rc<Frame>>> {
+ ) -> Vec<Constrained<Arc<Frame>>> {
for styled in self.children {
let styles = styled.map.chain(&styles);
match styled.item {
diff --git a/src/library/grid.rs b/src/library/grid.rs
index 59f52427..c49ac84f 100644
--- a/src/library/grid.rs
+++ b/src/library/grid.rs
@@ -38,7 +38,7 @@ impl Layout for GridNode {
ctx: &mut LayoutContext,
regions: &Regions,
styles: StyleChain,
- ) -> Vec<Constrained<Rc<Frame>>> {
+ ) -> Vec<Constrained<Arc<Frame>>> {
// Prepare grid layout by unifying content and gutter tracks.
let mut layouter = GridLayouter::new(self, regions.clone(), styles);
@@ -114,7 +114,7 @@ struct GridLayouter<'a> {
/// Constraints for the active region.
cts: Constraints,
/// Frames for finished regions.
- finished: Vec<Constrained<Rc<Frame>>>,
+ finished: Vec<Constrained<Arc<Frame>>>,
}
/// Produced by initial row layout, auto and linear rows are already finished,
@@ -355,7 +355,7 @@ impl<'a> GridLayouter<'a> {
}
/// Layout the grid row-by-row.
- fn layout(mut self, ctx: &mut LayoutContext) -> Vec<Constrained<Rc<Frame>>> {
+ fn layout(mut self, ctx: &mut LayoutContext) -> Vec<Constrained<Arc<Frame>>> {
for y in 0 .. self.rows.len() {
// Skip to next region if current one is full, but only for content
// rows, not for gutter rows.
diff --git a/src/library/heading.rs b/src/library/heading.rs
index 4c7bcc7d..17efb5e4 100644
--- a/src/library/heading.rs
+++ b/src/library/heading.rs
@@ -51,7 +51,7 @@ impl Layout for HeadingNode {
ctx: &mut LayoutContext,
regions: &Regions,
styles: StyleChain,
- ) -> Vec<Constrained<Rc<Frame>>> {
+ ) -> Vec<Constrained<Arc<Frame>>> {
let upscale = (1.6 - 0.1 * self.level as f64).max(0.75);
let mut passed = StyleMap::new();
@@ -82,7 +82,7 @@ impl Layout for HeadingNode {
// FIXME: Constraints and region size.
for Constrained { item: frame, .. } in &mut frames {
- let frame = Rc::make_mut(frame);
+ let frame = Arc::make_mut(frame);
frame.size.y += above + below;
frame.translate(Point::with_y(above));
}
diff --git a/src/library/hidden.rs b/src/library/hidden.rs
index 7287bf3d..5025fefb 100644
--- a/src/library/hidden.rs
+++ b/src/library/hidden.rs
@@ -19,12 +19,12 @@ impl Layout for HideNode {
ctx: &mut LayoutContext,
regions: &Regions,
styles: StyleChain,
- ) -> Vec<Constrained<Rc<Frame>>> {
+ ) -> Vec<Constrained<Arc<Frame>>> {
let mut frames = self.0.layout(ctx, regions, styles);
// Clear the frames.
for Constrained { item: frame, .. } in &mut frames {
- *frame = Rc::new(Frame { elements: vec![], ..**frame });
+ *frame = Arc::new(Frame { elements: vec![], ..**frame });
}
frames
diff --git a/src/library/image.rs b/src/library/image.rs
index a5423ccb..06b3fe31 100644
--- a/src/library/image.rs
+++ b/src/library/image.rs
@@ -44,7 +44,7 @@ impl Layout for ImageNode {
ctx: &mut LayoutContext,
regions: &Regions,
styles: StyleChain,
- ) -> Vec<Constrained<Rc<Frame>>> {
+ ) -> Vec<Constrained<Arc<Frame>>> {
let img = ctx.images.get(self.0);
let pxw = img.width() as f64;
let pxh = img.height() as f64;
diff --git a/src/library/link.rs b/src/library/link.rs
index dc523ffd..0ecd317b 100644
--- a/src/library/link.rs
+++ b/src/library/link.rs
@@ -10,13 +10,14 @@ pub struct LinkNode;
#[class]
impl LinkNode {
fn construct(_: &mut EvalContext, args: &mut Args) -> TypResult<Node> {
- let url: String = args.expect::<EcoString>("url")?.into();
+ let url = args.expect::<EcoString>("url")?;
let body = args.find().unwrap_or_else(|| {
let mut text = url.as_str();
for prefix in ["mailto:", "tel:"] {
text = text.trim_start_matches(prefix);
}
- Node::Text(text.into())
+ let shorter = text.len() < url.len();
+ Node::Text(if shorter { text.into() } else { url.clone() })
});
Ok(body.styled(TextNode::LINK, Some(url)))
diff --git a/src/library/list.rs b/src/library/list.rs
index 9f742a32..94f7aa44 100644
--- a/src/library/list.rs
+++ b/src/library/list.rs
@@ -39,7 +39,7 @@ impl<L: ListKind> Layout for ListNode<L> {
ctx: &mut LayoutContext,
regions: &Regions,
styles: StyleChain,
- ) -> Vec<Constrained<Rc<Frame>>> {
+ ) -> Vec<Constrained<Arc<Frame>>> {
let em = styles.get(TextNode::SIZE).abs;
let label_indent = styles.get(Self::LABEL_INDENT).resolve(em);
let body_indent = styles.get(Self::BODY_INDENT).resolve(em);
@@ -65,7 +65,7 @@ impl<L: ListKind> Layout for ListNode<L> {
}
/// How to label a list.
-pub trait ListKind: Debug + Default + Hash + 'static {
+pub trait ListKind: Debug + Default + Hash + Sync + Send + 'static {
/// Return the item's label.
fn label(&self) -> EcoString;
}
diff --git a/src/library/mod.rs b/src/library/mod.rs
index 3115cc7a..ae7fc3a1 100644
--- a/src/library/mod.rs
+++ b/src/library/mod.rs
@@ -61,7 +61,7 @@ macro_rules! prelude {
prelude! {
pub use std::fmt::{self, Debug, Formatter};
pub use std::num::NonZeroUsize;
- pub use std::rc::Rc;
+ pub use std::sync::Arc;
pub use std::hash::Hash;
pub use typst_macros::class;
diff --git a/src/library/pad.rs b/src/library/pad.rs
index 394d3c17..8bfc6d17 100644
--- a/src/library/pad.rs
+++ b/src/library/pad.rs
@@ -37,7 +37,7 @@ impl Layout for PadNode {
ctx: &mut LayoutContext,
regions: &Regions,
styles: StyleChain,
- ) -> Vec<Constrained<Rc<Frame>>> {
+ ) -> Vec<Constrained<Arc<Frame>>> {
// Layout child into padded regions.
let pod = regions.map(|size| shrink(size, self.padding));
let mut frames = self.child.layout(ctx, &pod, styles);
@@ -52,7 +52,7 @@ impl Layout for PadNode {
let offset = Point::new(padding.left, padding.top);
// Grow the frame and translate everything in the frame inwards.
- let frame = Rc::make_mut(frame);
+ let frame = Arc::make_mut(frame);
frame.size = padded;
frame.translate(offset);
diff --git a/src/library/page.rs b/src/library/page.rs
index f3a287dc..9949e1e7 100644
--- a/src/library/page.rs
+++ b/src/library/page.rs
@@ -70,7 +70,7 @@ impl PageNode {
impl PageNode {
/// Layout the page run into a sequence of frames, one per page.
- pub fn layout(&self, ctx: &mut LayoutContext, styles: StyleChain) -> Vec<Rc<Frame>> {
+ pub fn layout(&self, ctx: &mut LayoutContext, styles: StyleChain) -> Vec<Arc<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());
diff --git a/src/library/par.rs b/src/library/par.rs
index 4f711e76..913d2253 100644
--- a/src/library/par.rs
+++ b/src/library/par.rs
@@ -1,7 +1,7 @@
//! Paragraph layout.
use std::fmt::{self, Debug, Formatter};
-use std::rc::Rc;
+use std::sync::Arc;
use itertools::Either;
use unicode_bidi::{BidiInfo, Level};
@@ -9,7 +9,7 @@ use xi_unicode::LineBreakIterator;
use super::prelude::*;
use super::{shape, ShapedText, SpacingKind, TextNode};
-use crate::util::{EcoString, RangeExt, RcExt, SliceExt};
+use crate::util::{ArcExt, EcoString, RangeExt, SliceExt};
/// A node that arranges its children into a paragraph.
#[derive(Hash)]
@@ -75,7 +75,7 @@ impl Layout for ParNode {
ctx: &mut LayoutContext,
regions: &Regions,
styles: StyleChain,
- ) -> Vec<Constrained<Rc<Frame>>> {
+ ) -> Vec<Constrained<Arc<Frame>>> {
// Collect all text into one string used for BiDi analysis.
let text = self.collect_text();
@@ -253,7 +253,7 @@ impl<'a> ParLayouter<'a> {
let size = Size::new(regions.current.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(ParItem::Frame(Rc::take(frame.item)));
+ items.push(ParItem::Frame(Arc::take(frame.item)));
ranges.push(range);
}
}
@@ -271,7 +271,7 @@ impl<'a> ParLayouter<'a> {
self,
ctx: &mut LayoutContext,
regions: Regions,
- ) -> Vec<Constrained<Rc<Frame>>> {
+ ) -> Vec<Constrained<Arc<Frame>>> {
let mut stack = LineStack::new(self.leading, regions);
// The current line attempt.
@@ -582,7 +582,7 @@ struct LineStack<'a> {
regions: Regions,
size: Size,
lines: Vec<LineLayout<'a>>,
- finished: Vec<Constrained<Rc<Frame>>>,
+ finished: Vec<Constrained<Arc<Frame>>>,
cts: Constraints,
overflowing: bool,
fractional: bool,
@@ -650,7 +650,7 @@ impl<'a> LineStack<'a> {
}
/// Finish the last region and return the built frames.
- fn finish(mut self, ctx: &LayoutContext) -> Vec<Constrained<Rc<Frame>>> {
+ fn finish(mut self, ctx: &LayoutContext) -> Vec<Constrained<Arc<Frame>>> {
self.finish_region(ctx);
self.finished
}
diff --git a/src/library/place.rs b/src/library/place.rs
index cee687fa..d5880995 100644
--- a/src/library/place.rs
+++ b/src/library/place.rs
@@ -26,7 +26,7 @@ impl Layout for PlaceNode {
ctx: &mut LayoutContext,
regions: &Regions,
styles: StyleChain,
- ) -> Vec<Constrained<Rc<Frame>>> {
+ ) -> Vec<Constrained<Arc<Frame>>> {
let out_of_flow = self.out_of_flow();
// The pod is the base area of the region because for absolute
@@ -43,7 +43,7 @@ impl Layout for PlaceNode {
// If expansion is off, zero all sizes so that we don't take up any
// space in our parent. Otherwise, respect the expand settings.
let target = regions.expand.select(regions.current, Size::zero());
- Rc::make_mut(frame).resize(target, Align::LEFT_TOP);
+ Arc::make_mut(frame).resize(target, Align::LEFT_TOP);
// Set base constraint because our pod size is base and exact
// constraints if we needed to expand or offset.
diff --git a/src/library/shape.rs b/src/library/shape.rs
index 12126ab4..5d31d570 100644
--- a/src/library/shape.rs
+++ b/src/library/shape.rs
@@ -66,7 +66,7 @@ impl<S: ShapeKind> Layout for ShapeNode<S> {
ctx: &mut LayoutContext,
regions: &Regions,
styles: StyleChain,
- ) -> Vec<Constrained<Rc<Frame>>> {
+ ) -> Vec<Constrained<Arc<Frame>>> {
let mut frames;
if let Some(child) = &self.child {
let mut padding = styles.get(Self::PADDING);
@@ -118,7 +118,7 @@ impl<S: ShapeKind> Layout for ShapeNode<S> {
frames = vec![Frame::new(size).constrain(Constraints::tight(regions))];
}
- let frame = Rc::make_mut(&mut frames[0].item);
+ let frame = Arc::make_mut(&mut frames[0].item);
// Add fill and/or stroke.
let fill = styles.get(Self::FILL);
@@ -149,7 +149,7 @@ impl<S: ShapeKind> Layout for ShapeNode<S> {
}
/// Categorizes shapes.
-pub trait ShapeKind: Debug + Default + Hash + 'static {
+pub trait ShapeKind: Debug + Default + Hash + Sync + Send + 'static {
const ROUND: bool;
const QUADRATIC: bool;
}
diff --git a/src/library/stack.rs b/src/library/stack.rs
index 8c8a9f60..14b268c2 100644
--- a/src/library/stack.rs
+++ b/src/library/stack.rs
@@ -31,7 +31,7 @@ impl Layout for StackNode {
ctx: &mut LayoutContext,
regions: &Regions,
styles: StyleChain,
- ) -> Vec<Constrained<Rc<Frame>>> {
+ ) -> Vec<Constrained<Arc<Frame>>> {
StackLayouter::new(self, regions.clone(), styles).layout(ctx)
}
}
@@ -90,7 +90,7 @@ struct StackLayouter<'a> {
/// Spacing and layouted nodes.
items: Vec<StackItem>,
/// Finished frames for previous regions.
- finished: Vec<Constrained<Rc<Frame>>>,
+ finished: Vec<Constrained<Arc<Frame>>>,
}
/// A prepared item in a stack layout.
@@ -100,7 +100,7 @@ enum StackItem {
/// Fractional spacing between other items.
Fractional(Fractional),
/// A layouted child node.
- Frame(Rc<Frame>, Align),
+ Frame(Arc<Frame>, Align),
}
impl<'a> StackLayouter<'a> {
@@ -131,7 +131,7 @@ impl<'a> StackLayouter<'a> {
}
/// Layout all children.
- fn layout(mut self, ctx: &mut LayoutContext) -> Vec<Constrained<Rc<Frame>>> {
+ fn layout(mut self, ctx: &mut LayoutContext) -> Vec<Constrained<Arc<Frame>>> {
// Spacing to insert before the next node.
let mut deferred = None;
diff --git a/src/library/table.rs b/src/library/table.rs
index 0e41ad78..d7aa61db 100644
--- a/src/library/table.rs
+++ b/src/library/table.rs
@@ -60,7 +60,7 @@ impl Layout for TableNode {
ctx: &mut LayoutContext,
regions: &Regions,
styles: StyleChain,
- ) -> Vec<Constrained<Rc<Frame>>> {
+ ) -> Vec<Constrained<Arc<Frame>>> {
let primary = styles.get(Self::PRIMARY);
let secondary = styles.get(Self::SECONDARY);
let thickness = styles.get(Self::THICKNESS);
diff --git a/src/library/text.rs b/src/library/text.rs
index 6d7be323..c6c1ab80 100644
--- a/src/library/text.rs
+++ b/src/library/text.rs
@@ -55,7 +55,7 @@ impl TextNode {
#[fold(|a, b| a.into_iter().chain(b).collect())]
pub const LINES: Vec<Decoration> = vec![];
/// An URL the text should link to.
- pub const LINK: Option<String> = None;
+ pub const LINK: Option<EcoString> = None;
/// The size of the glyphs.
#[fold(Linear::compose)]
@@ -211,12 +211,12 @@ castable! {
/// A specific font family like "Arial".
#[derive(Clone, Eq, PartialEq, Hash)]
-pub struct NamedFamily(String);
+pub struct NamedFamily(EcoString);
impl NamedFamily {
/// Create a named font family variant.
pub fn new(string: &str) -> Self {
- Self(string.to_lowercase())
+ Self(string.to_lowercase().into())
}
/// The lowercased family name.
diff --git a/src/library/transform.rs b/src/library/transform.rs
index aceb4197..e9a41a98 100644
--- a/src/library/transform.rs
+++ b/src/library/transform.rs
@@ -36,7 +36,7 @@ impl<T: TransformKind> Layout for TransformNode<T> {
ctx: &mut LayoutContext,
regions: &Regions,
styles: StyleChain,
- ) -> Vec<Constrained<Rc<Frame>>> {
+ ) -> Vec<Constrained<Arc<Frame>>> {
let origin = styles.get(Self::ORIGIN).unwrap_or(Align::CENTER_HORIZON);
let matrix = self.kind.matrix();
@@ -48,7 +48,7 @@ impl<T: TransformKind> Layout for TransformNode<T> {
.pre_concat(matrix)
.pre_concat(Transform::translation(-x, -y));
- Rc::make_mut(frame).transform(transform);
+ Arc::make_mut(frame).transform(transform);
}
frames
@@ -56,7 +56,7 @@ impl<T: TransformKind> Layout for TransformNode<T> {
}
/// Kinds of transformations.
-pub trait TransformKind: Debug + Hash + Sized + 'static {
+pub trait TransformKind: Debug + Hash + Sized + Sync + Send + 'static {
fn construct(args: &mut Args) -> TypResult<Self>;
fn matrix(&self) -> Transform;
}