summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-09-20 13:05:55 +0200
committerLaurenz <laurmaedje@gmail.com>2022-09-20 16:37:15 +0200
commit757a701c1aa2a6fb80033c7e75666661818da6f9 (patch)
tree0415fec94d3856f4ebc97a1744cf2ba75fe8e7aa /src/library
parente29f55bb294cc298daad97accf6d8a76976b409c (diff)
A New World
Diffstat (limited to 'src/library')
-rw-r--r--src/library/graphics/hide.rs6
-rw-r--r--src/library/graphics/image.rs7
-rw-r--r--src/library/graphics/line.rs4
-rw-r--r--src/library/graphics/shape.rs8
-rw-r--r--src/library/graphics/transform.rs12
-rw-r--r--src/library/layout/align.rs6
-rw-r--r--src/library/layout/columns.rs10
-rw-r--r--src/library/layout/container.rs4
-rw-r--r--src/library/layout/flow.rs10
-rw-r--r--src/library/layout/grid.rs20
-rw-r--r--src/library/layout/pad.rs6
-rw-r--r--src/library/layout/page.rs16
-rw-r--r--src/library/layout/place.rs6
-rw-r--r--src/library/layout/spacing.rs4
-rw-r--r--src/library/layout/stack.rs10
-rw-r--r--src/library/math/mod.rs6
-rw-r--r--src/library/math/rex.rs7
-rw-r--r--src/library/prelude.rs7
-rw-r--r--src/library/structure/doc.rs4
-rw-r--r--src/library/structure/heading.rs12
-rw-r--r--src/library/structure/list.rs12
-rw-r--r--src/library/structure/reference.rs4
-rw-r--r--src/library/structure/table.rs12
-rw-r--r--src/library/text/deco.rs4
-rw-r--r--src/library/text/link.rs6
-rw-r--r--src/library/text/mod.rs16
-rw-r--r--src/library/text/par.rs66
-rw-r--r--src/library/text/raw.rs6
-rw-r--r--src/library/text/repeat.rs6
-rw-r--r--src/library/text/shaping.rs32
-rw-r--r--src/library/text/shift.rs14
-rw-r--r--src/library/utility/color.rs6
-rw-r--r--src/library/utility/data.rs4
-rw-r--r--src/library/utility/math.rs18
-rw-r--r--src/library/utility/mod.rs19
-rw-r--r--src/library/utility/string.rs14
36 files changed, 197 insertions, 207 deletions
diff --git a/src/library/graphics/hide.rs b/src/library/graphics/hide.rs
index f40635a0..f2a423ce 100644
--- a/src/library/graphics/hide.rs
+++ b/src/library/graphics/hide.rs
@@ -6,7 +6,7 @@ pub struct HideNode(pub LayoutNode);
#[node]
impl HideNode {
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
Ok(Content::inline(Self(args.expect("body")?)))
}
}
@@ -14,11 +14,11 @@ impl HideNode {
impl Layout for HideNode {
fn layout(
&self,
- ctx: &mut Context,
+ world: &dyn World,
regions: &Regions,
styles: StyleChain,
) -> TypResult<Vec<Frame>> {
- let mut frames = self.0.layout(ctx, regions, styles)?;
+ let mut frames = self.0.layout(world, regions, styles)?;
for frame in &mut frames {
frame.clear();
}
diff --git a/src/library/graphics/image.rs b/src/library/graphics/image.rs
index f8cdc4cd..1642c7b0 100644
--- a/src/library/graphics/image.rs
+++ b/src/library/graphics/image.rs
@@ -13,15 +13,14 @@ impl ImageNode {
/// How the image should adjust itself to a given area.
pub const FIT: ImageFit = ImageFit::Cover;
- fn construct(vm: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(vm: &mut Vm, args: &mut Args) -> TypResult<Content> {
let Spanned { v: path, span } =
args.expect::<Spanned<EcoString>>("path to image file")?;
let full = vm.locate(&path).at(span)?;
let ext = full.extension().and_then(OsStr::to_str).unwrap_or_default();
let image = vm
- .ctx
- .loader
+ .world
.file(&full)
.and_then(|buffer| Image::new(buffer, ext))
.map_err(|err| failed_to_load("image", &full, err))
@@ -39,7 +38,7 @@ impl ImageNode {
impl Layout for ImageNode {
fn layout(
&self,
- _: &mut Context,
+ _: &dyn World,
regions: &Regions,
styles: StyleChain,
) -> TypResult<Vec<Frame>> {
diff --git a/src/library/graphics/line.rs b/src/library/graphics/line.rs
index 15c54f46..95c3a709 100644
--- a/src/library/graphics/line.rs
+++ b/src/library/graphics/line.rs
@@ -15,7 +15,7 @@ impl LineNode {
#[property(resolve, fold)]
pub const STROKE: RawStroke = RawStroke::default();
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
let origin = args.named("origin")?.unwrap_or_default();
let delta = match args.named::<Spec<Relative<RawLength>>>("to")? {
@@ -40,7 +40,7 @@ impl LineNode {
impl Layout for LineNode {
fn layout(
&self,
- _: &mut Context,
+ _: &dyn World,
regions: &Regions,
styles: StyleChain,
) -> TypResult<Vec<Frame>> {
diff --git a/src/library/graphics/shape.rs b/src/library/graphics/shape.rs
index 5cc5a76d..ee5e43e8 100644
--- a/src/library/graphics/shape.rs
+++ b/src/library/graphics/shape.rs
@@ -39,7 +39,7 @@ impl<const S: ShapeKind> ShapeNode<S> {
pub const RADIUS: Corners<Option<Relative<RawLength>>> =
Corners::splat(Relative::zero());
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
let size = match S {
SQUARE => args.named::<RawLength>("size")?.map(Relative::from),
CIRCLE => args.named::<RawLength>("radius")?.map(|r| 2.0 * Relative::from(r)),
@@ -78,7 +78,7 @@ impl<const S: ShapeKind> ShapeNode<S> {
impl<const S: ShapeKind> Layout for ShapeNode<S> {
fn layout(
&self,
- ctx: &mut Context,
+ world: &dyn World,
regions: &Regions,
styles: StyleChain,
) -> TypResult<Vec<Frame>> {
@@ -93,7 +93,7 @@ impl<const S: ShapeKind> Layout for ShapeNode<S> {
let child = child.clone().padded(inset.map(|side| side.map(RawLength::from)));
let mut pod = Regions::one(regions.first, regions.base, regions.expand);
- frames = child.layout(ctx, &pod, styles)?;
+ frames = child.layout(world, &pod, styles)?;
for frame in frames.iter_mut() {
frame.apply_role(Role::GenericBlock);
@@ -113,7 +113,7 @@ impl<const S: ShapeKind> Layout for ShapeNode<S> {
pod.first = Size::splat(length);
pod.expand = Spec::splat(true);
- frames = child.layout(ctx, &pod, styles)?;
+ frames = child.layout(world, &pod, styles)?;
}
} else {
// The default size that a shape takes on if it has no child and
diff --git a/src/library/graphics/transform.rs b/src/library/graphics/transform.rs
index 48cadb1b..0a4f5b5f 100644
--- a/src/library/graphics/transform.rs
+++ b/src/library/graphics/transform.rs
@@ -12,7 +12,7 @@ pub struct MoveNode {
#[node]
impl MoveNode {
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
let dx = args.named("dx")?.unwrap_or_default();
let dy = args.named("dy")?.unwrap_or_default();
Ok(Content::inline(Self {
@@ -25,11 +25,11 @@ impl MoveNode {
impl Layout for MoveNode {
fn layout(
&self,
- ctx: &mut Context,
+ world: &dyn World,
regions: &Regions,
styles: StyleChain,
) -> TypResult<Vec<Frame>> {
- let mut frames = self.child.layout(ctx, regions, styles)?;
+ let mut frames = self.child.layout(world, regions, styles)?;
let delta = self.delta.resolve(styles);
for frame in &mut frames {
@@ -62,7 +62,7 @@ impl<const T: TransformKind> TransformNode<T> {
#[property(resolve)]
pub const ORIGIN: Spec<Option<RawAlign>> = Spec::default();
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
let transform = match T {
ROTATE => {
let angle = args.named_or_find("angle")?.unwrap_or_default();
@@ -86,12 +86,12 @@ impl<const T: TransformKind> TransformNode<T> {
impl<const T: TransformKind> Layout for TransformNode<T> {
fn layout(
&self,
- ctx: &mut Context,
+ world: &dyn World,
regions: &Regions,
styles: StyleChain,
) -> TypResult<Vec<Frame>> {
let origin = styles.get(Self::ORIGIN).unwrap_or(Align::CENTER_HORIZON);
- let mut frames = self.child.layout(ctx, regions, styles)?;
+ let mut frames = self.child.layout(world, regions, styles)?;
for frame in &mut frames {
let Spec { x, y } = origin.zip(frame.size()).map(|(o, s)| o.position(s));
diff --git a/src/library/layout/align.rs b/src/library/layout/align.rs
index e7a27c04..3b1a4aaf 100644
--- a/src/library/layout/align.rs
+++ b/src/library/layout/align.rs
@@ -12,7 +12,7 @@ pub struct AlignNode {
#[node]
impl AlignNode {
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
let aligns: Spec<Option<RawAlign>> = args.find()?.unwrap_or_default();
let body: Content = args.expect("body")?;
Ok(match (body, aligns) {
@@ -28,7 +28,7 @@ impl AlignNode {
impl Layout for AlignNode {
fn layout(
&self,
- ctx: &mut Context,
+ world: &dyn World,
regions: &Regions,
styles: StyleChain,
) -> TypResult<Vec<Frame>> {
@@ -43,7 +43,7 @@ impl Layout for AlignNode {
}
// Layout the child.
- let mut frames = self.child.layout(ctx, &pod, passed.chain(&styles))?;
+ let mut frames = self.child.layout(world, &pod, passed.chain(&styles))?;
for (region, frame) in regions.iter().zip(&mut frames) {
// Align in the target size. The target size depends on whether we
// should expand.
diff --git a/src/library/layout/columns.rs b/src/library/layout/columns.rs
index efc435aa..bfbbfd8d 100644
--- a/src/library/layout/columns.rs
+++ b/src/library/layout/columns.rs
@@ -17,7 +17,7 @@ impl ColumnsNode {
#[property(resolve)]
pub const GUTTER: Relative<RawLength> = Ratio::new(0.04).into();
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
Ok(Content::block(Self {
columns: args.expect("column count")?,
child: args.expect("body")?,
@@ -28,14 +28,14 @@ impl ColumnsNode {
impl Layout for ColumnsNode {
fn layout(
&self,
- ctx: &mut Context,
+ world: &dyn World,
regions: &Regions,
styles: StyleChain,
) -> TypResult<Vec<Frame>> {
// Separating the infinite space into infinite columns does not make
// much sense.
if !regions.first.x.is_finite() {
- return self.child.layout(ctx, regions, styles);
+ return self.child.layout(world, regions, styles);
}
// Determine the width of the gutter and each column.
@@ -57,7 +57,7 @@ impl Layout for ColumnsNode {
};
// Layout the children.
- let mut frames = self.child.layout(ctx, &pod, styles)?.into_iter();
+ let mut frames = self.child.layout(world, &pod, styles)?.into_iter();
let mut finished = vec![];
let dir = styles.get(TextNode::DIR);
@@ -106,7 +106,7 @@ pub struct ColbreakNode;
#[node]
impl ColbreakNode {
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
let weak = args.named("weak")?.unwrap_or(false);
Ok(Content::Colbreak { weak })
}
diff --git a/src/library/layout/container.rs b/src/library/layout/container.rs
index df03ac91..66a43751 100644
--- a/src/library/layout/container.rs
+++ b/src/library/layout/container.rs
@@ -5,7 +5,7 @@ pub struct BoxNode;
#[node]
impl BoxNode {
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
let width = args.named("width")?;
let height = args.named("height")?;
let body: LayoutNode = args.eat()?.unwrap_or_default();
@@ -18,7 +18,7 @@ pub struct BlockNode;
#[node]
impl BlockNode {
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
Ok(Content::Block(args.eat()?.unwrap_or_default()))
}
}
diff --git a/src/library/layout/flow.rs b/src/library/layout/flow.rs
index c6d2999e..841b80aa 100644
--- a/src/library/layout/flow.rs
+++ b/src/library/layout/flow.rs
@@ -25,7 +25,7 @@ pub enum FlowChild {
impl Layout for FlowNode {
fn layout(
&self,
- ctx: &mut Context,
+ world: &dyn World,
regions: &Regions,
styles: StyleChain,
) -> TypResult<Vec<Frame>> {
@@ -38,7 +38,7 @@ impl Layout for FlowNode {
layouter.layout_spacing(*kind, styles);
}
FlowChild::Node(ref node) => {
- layouter.layout_node(ctx, node, styles)?;
+ layouter.layout_node(world, node, styles)?;
}
FlowChild::Colbreak => {
layouter.finish_region();
@@ -149,7 +149,7 @@ impl FlowLayouter {
/// Layout a node.
pub fn layout_node(
&mut self,
- ctx: &mut Context,
+ world: &dyn World,
node: &LayoutNode,
styles: StyleChain,
) -> TypResult<()> {
@@ -162,7 +162,7 @@ impl FlowLayouter {
// aligned later.
if let Some(placed) = node.downcast::<PlaceNode>() {
if placed.out_of_flow() {
- let frame = node.layout(ctx, &self.regions, styles)?.remove(0);
+ let frame = node.layout(world, &self.regions, styles)?.remove(0);
self.items.push(FlowItem::Placed(frame));
return Ok(());
}
@@ -180,7 +180,7 @@ impl FlowLayouter {
.unwrap_or(Align::Top),
);
- let frames = node.layout(ctx, &self.regions, styles)?;
+ let frames = node.layout(world, &self.regions, styles)?;
let len = frames.len();
for (i, mut frame) in frames.into_iter().enumerate() {
// Set the generic block role.
diff --git a/src/library/layout/grid.rs b/src/library/layout/grid.rs
index 93dbf97e..3fde9c10 100644
--- a/src/library/layout/grid.rs
+++ b/src/library/layout/grid.rs
@@ -13,7 +13,7 @@ pub struct GridNode {
#[node]
impl GridNode {
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
let columns = args.named("columns")?.unwrap_or_default();
let rows = args.named("rows")?.unwrap_or_default();
let base_gutter: Vec<TrackSizing> = args.named("gutter")?.unwrap_or_default();
@@ -33,13 +33,13 @@ impl GridNode {
impl Layout for GridNode {
fn layout(
&self,
- ctx: &mut Context,
+ world: &dyn World,
regions: &Regions,
styles: StyleChain,
) -> TypResult<Vec<Frame>> {
// Prepare grid layout by unifying content and gutter tracks.
let layouter = GridLayouter::new(
- ctx,
+ world,
self.tracks.as_deref(),
self.gutter.as_deref(),
&self.cells,
@@ -93,7 +93,7 @@ castable! {
/// Performs grid layout.
pub struct GridLayouter<'a> {
/// The core context.
- ctx: &'a mut Context,
+ world: &'a dyn World,
/// The grid cells.
cells: &'a [LayoutNode],
/// The column tracks including gutter tracks.
@@ -133,7 +133,7 @@ impl<'a> GridLayouter<'a> {
///
/// This prepares grid layout by unifying content and gutter tracks.
pub fn new(
- ctx: &'a mut Context,
+ world: &'a dyn World,
tracks: Spec<&[TrackSizing]>,
gutter: Spec<&[TrackSizing]>,
cells: &'a [LayoutNode],
@@ -187,7 +187,7 @@ impl<'a> GridLayouter<'a> {
regions.expand = Spec::new(true, false);
Self {
- ctx,
+ world,
cells,
cols,
rows,
@@ -301,7 +301,7 @@ impl<'a> GridLayouter<'a> {
v.resolve(self.styles).relative_to(self.regions.base.y);
}
- let frame = node.layout(self.ctx, &pod, self.styles)?.remove(0);
+ let frame = node.layout(self.world, &pod, self.styles)?.remove(0);
resolved.set_max(frame.width());
}
}
@@ -371,7 +371,7 @@ impl<'a> GridLayouter<'a> {
}
let mut sizes = node
- .layout(self.ctx, &pod, self.styles)?
+ .layout(self.world, &pod, self.styles)?
.into_iter()
.map(|frame| frame.height());
@@ -460,7 +460,7 @@ impl<'a> GridLayouter<'a> {
.select(self.regions.base, size);
let pod = Regions::one(size, base, Spec::splat(true));
- let frame = node.layout(self.ctx, &pod, self.styles)?.remove(0);
+ let frame = node.layout(self.world, &pod, self.styles)?.remove(0);
match frame.role() {
Some(Role::ListLabel | Role::ListItemBody) => {
output.apply_role(Role::ListItem)
@@ -508,7 +508,7 @@ impl<'a> GridLayouter<'a> {
}
// Push the layouted frames into the individual output frames.
- let frames = node.layout(self.ctx, &pod, self.styles)?;
+ let frames = node.layout(self.world, &pod, self.styles)?;
for (output, frame) in outputs.iter_mut().zip(frames) {
match frame.role() {
Some(Role::ListLabel | Role::ListItemBody) => {
diff --git a/src/library/layout/pad.rs b/src/library/layout/pad.rs
index 9d91c641..72235ccd 100644
--- a/src/library/layout/pad.rs
+++ b/src/library/layout/pad.rs
@@ -11,7 +11,7 @@ pub struct PadNode {
#[node]
impl PadNode {
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
let all = args.named("rest")?.or(args.find()?);
let x = args.named("x")?;
let y = args.named("y")?;
@@ -28,14 +28,14 @@ impl PadNode {
impl Layout for PadNode {
fn layout(
&self,
- ctx: &mut Context,
+ world: &dyn World,
regions: &Regions,
styles: StyleChain,
) -> TypResult<Vec<Frame>> {
// Layout child into padded regions.
let padding = self.padding.resolve(styles);
let pod = regions.map(|size| shrink(size, padding));
- let mut frames = self.child.layout(ctx, &pod, styles)?;
+ let mut frames = self.child.layout(world, &pod, styles)?;
for frame in &mut frames {
// Apply the padding inversely such that the grown size padded
diff --git a/src/library/layout/page.rs b/src/library/layout/page.rs
index afcc4855..6e43c4ef 100644
--- a/src/library/layout/page.rs
+++ b/src/library/layout/page.rs
@@ -41,7 +41,7 @@ impl PageNode {
#[property(referenced)]
pub const FOREGROUND: Marginal = Marginal::None;
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
Ok(Content::Page(Self(args.expect("body")?)))
}
@@ -57,7 +57,7 @@ impl PageNode {
/// Layout the page run into a sequence of frames, one per page.
pub fn layout(
&self,
- ctx: &mut Context,
+ world: &dyn World,
mut page: usize,
styles: StyleChain,
) -> TypResult<Vec<Frame>> {
@@ -97,7 +97,7 @@ impl PageNode {
// Layout the child.
let regions = Regions::repeat(size, size, size.map(Length::is_finite));
- let mut frames = child.layout(ctx, &regions, styles)?;
+ let mut frames = child.layout(world, &regions, styles)?;
let header = styles.get(Self::HEADER);
let footer = styles.get(Self::FOOTER);
@@ -126,9 +126,9 @@ impl PageNode {
(Role::Foreground, foreground, Point::zero(), size),
(Role::Background, background, Point::zero(), size),
] {
- if let Some(content) = marginal.resolve(ctx, page)? {
+ if let Some(content) = marginal.resolve(world, page)? {
let pod = Regions::one(area, area, Spec::splat(true));
- let mut sub = content.layout(ctx, &pod, styles)?.remove(0);
+ let mut sub = content.layout(world, &pod, styles)?.remove(0);
sub.apply_role(role);
if role == Role::Background {
@@ -159,7 +159,7 @@ pub struct PagebreakNode;
#[node]
impl PagebreakNode {
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
let weak = args.named("weak")?.unwrap_or(false);
Ok(Content::Pagebreak { weak })
}
@@ -178,13 +178,13 @@ pub enum Marginal {
impl Marginal {
/// Resolve the marginal based on the page number.
- pub fn resolve(&self, ctx: &mut Context, page: usize) -> TypResult<Option<Content>> {
+ pub fn resolve(&self, world: &dyn World, page: usize) -> TypResult<Option<Content>> {
Ok(match self {
Self::None => None,
Self::Content(content) => Some(content.clone()),
Self::Func(func, span) => {
let args = Args::new(*span, [Value::Int(page as i64)]);
- Some(func.call_detached(ctx, args)?.display())
+ Some(func.call_detached(world, args)?.display())
}
})
}
diff --git a/src/library/layout/place.rs b/src/library/layout/place.rs
index 4c6d0062..bb3aac2d 100644
--- a/src/library/layout/place.rs
+++ b/src/library/layout/place.rs
@@ -7,7 +7,7 @@ pub struct PlaceNode(pub LayoutNode);
#[node]
impl PlaceNode {
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
let aligns = args.find()?.unwrap_or(Spec::with_x(Some(RawAlign::Start)));
let dx = args.named("dx")?.unwrap_or_default();
let dy = args.named("dy")?.unwrap_or_default();
@@ -21,7 +21,7 @@ impl PlaceNode {
impl Layout for PlaceNode {
fn layout(
&self,
- ctx: &mut Context,
+ world: &dyn World,
regions: &Regions,
styles: StyleChain,
) -> TypResult<Vec<Frame>> {
@@ -35,7 +35,7 @@ impl Layout for PlaceNode {
Regions::one(regions.base, regions.base, expand)
};
- let mut frames = self.0.layout(ctx, &pod, styles)?;
+ let mut frames = self.0.layout(world, &pod, styles)?;
// If expansion is off, zero all sizes so that we don't take up any
// space in our parent. Otherwise, respect the expand settings.
diff --git a/src/library/layout/spacing.rs b/src/library/layout/spacing.rs
index da4a96b6..e435e60c 100644
--- a/src/library/layout/spacing.rs
+++ b/src/library/layout/spacing.rs
@@ -8,7 +8,7 @@ pub struct HNode;
#[node]
impl HNode {
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
let amount = args.expect("spacing")?;
let weak = args.named("weak")?.unwrap_or(false);
Ok(Content::Horizontal { amount, weak })
@@ -20,7 +20,7 @@ pub struct VNode;
#[node]
impl VNode {
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
let amount = args.expect("spacing")?;
let weak = args.named("weak")?.unwrap_or(false);
Ok(Content::Vertical { amount, weak, generated: false })
diff --git a/src/library/layout/stack.rs b/src/library/layout/stack.rs
index d8dc0e1a..d07dc35e 100644
--- a/src/library/layout/stack.rs
+++ b/src/library/layout/stack.rs
@@ -15,7 +15,7 @@ pub struct StackNode {
#[node]
impl StackNode {
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
Ok(Content::block(Self {
dir: args.named("dir")?.unwrap_or(Dir::TTB),
spacing: args.named("spacing")?,
@@ -27,7 +27,7 @@ impl StackNode {
impl Layout for StackNode {
fn layout(
&self,
- ctx: &mut Context,
+ world: &dyn World,
regions: &Regions,
styles: StyleChain,
) -> TypResult<Vec<Frame>> {
@@ -47,7 +47,7 @@ impl Layout for StackNode {
layouter.layout_spacing(kind);
}
- layouter.layout_node(ctx, node, styles)?;
+ layouter.layout_node(world, node, styles)?;
deferred = self.spacing;
}
}
@@ -168,7 +168,7 @@ impl<'a> StackLayouter<'a> {
/// Layout an arbitrary node.
pub fn layout_node(
&mut self,
- ctx: &mut Context,
+ world: &dyn World,
node: &LayoutNode,
styles: StyleChain,
) -> TypResult<()> {
@@ -193,7 +193,7 @@ impl<'a> StackLayouter<'a> {
self.dir.start().into()
});
- let frames = node.layout(ctx, &self.regions, styles)?;
+ let frames = node.layout(world, &self.regions, styles)?;
let len = frames.len();
for (i, mut frame) in frames.into_iter().enumerate() {
// Set the generic block role.
diff --git a/src/library/math/mod.rs b/src/library/math/mod.rs
index 81593c4f..ed98ab1c 100644
--- a/src/library/math/mod.rs
+++ b/src/library/math/mod.rs
@@ -28,7 +28,7 @@ impl MathNode {
#[property(resolve, shorthand(around))]
pub const BELOW: Option<BlockSpacing> = Some(Ratio::one().into());
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
Ok(Content::show(Self {
formula: args.expect("formula")?,
display: args.named("display")?.unwrap_or(false),
@@ -48,7 +48,7 @@ impl Show for MathNode {
}
}
- fn realize(&self, _: &mut Context, styles: StyleChain) -> TypResult<Content> {
+ fn realize(&self, _: &dyn World, styles: StyleChain) -> TypResult<Content> {
let node = self::rex::RexNode {
tex: self.formula.clone(),
display: self.display,
@@ -64,7 +64,7 @@ impl Show for MathNode {
fn finalize(
&self,
- _: &mut Context,
+ _: &dyn World,
styles: StyleChain,
mut realized: Content,
) -> TypResult<Content> {
diff --git a/src/library/math/rex.rs b/src/library/math/rex.rs
index 0116b4b2..7bfdeb7a 100644
--- a/src/library/math/rex.rs
+++ b/src/library/math/rex.rs
@@ -22,17 +22,16 @@ pub struct RexNode {
impl Layout for RexNode {
fn layout(
&self,
- ctx: &mut Context,
+ world: &dyn World,
_: &Regions,
styles: StyleChain,
) -> TypResult<Vec<Frame>> {
// Load the font.
let span = self.tex.span;
- let font = ctx
- .loader
+ let font = world
.book()
.select(self.family.as_str(), variant(styles))
- .and_then(|id| ctx.loader.font(id).ok())
+ .and_then(|id| world.font(id).ok())
.ok_or("failed to find math font")
.at(span)?;
diff --git a/src/library/prelude.rs b/src/library/prelude.rs
index 8bd3b815..a69d9791 100644
--- a/src/library/prelude.rs
+++ b/src/library/prelude.rs
@@ -12,16 +12,15 @@ pub use crate::diag::{
failed_to_load, with_alternative, At, Error, StrResult, TypError, TypResult,
};
pub use crate::eval::{
- Arg, Args, Array, Cast, Dict, Dynamic, Func, Machine, Node, RawAlign, RawLength,
- RawStroke, Scope, Smart, Value,
+ Arg, Args, Array, Cast, Dict, Dynamic, Func, Node, RawAlign, RawLength, RawStroke,
+ Scope, Smart, Value, Vm,
};
pub use crate::frame::*;
pub use crate::geom::*;
-pub use crate::loading::Loader;
pub use crate::model::{
Content, Fold, Key, Layout, LayoutNode, Regions, Resolve, Selector, Show, ShowNode,
StyleChain, StyleMap, StyleVec,
};
pub use crate::syntax::{Span, Spanned};
pub use crate::util::EcoString;
-pub use crate::Context;
+pub use crate::World;
diff --git a/src/library/structure/doc.rs b/src/library/structure/doc.rs
index 80472e24..cabdb4dc 100644
--- a/src/library/structure/doc.rs
+++ b/src/library/structure/doc.rs
@@ -7,11 +7,11 @@ 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<Frame>> {
+ pub fn layout(&self, world: &dyn World, styles: StyleChain) -> TypResult<Vec<Frame>> {
let mut frames = vec![];
for (page, map) in self.0.iter() {
let number = 1 + frames.len();
- frames.extend(page.layout(ctx, number, map.chain(&styles))?);
+ frames.extend(page.layout(world, number, map.chain(&styles))?);
}
Ok(frames)
}
diff --git a/src/library/structure/heading.rs b/src/library/structure/heading.rs
index 24054f81..c177481f 100644
--- a/src/library/structure/heading.rs
+++ b/src/library/structure/heading.rs
@@ -60,7 +60,7 @@ impl HeadingNode {
/// Whether the heading is numbered.
pub const NUMBERED: bool = true;
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
Ok(Content::show(Self {
body: args.expect("body")?,
level: args.named("level")?.unwrap_or(NonZeroUsize::new(1).unwrap()),
@@ -82,19 +82,19 @@ impl Show for HeadingNode {
}
}
- fn realize(&self, _: &mut Context, _: StyleChain) -> TypResult<Content> {
+ fn realize(&self, _: &dyn World, _: StyleChain) -> TypResult<Content> {
Ok(Content::block(self.body.clone()))
}
fn finalize(
&self,
- ctx: &mut Context,
+ world: &dyn World,
styles: StyleChain,
mut realized: Content,
) -> TypResult<Content> {
macro_rules! resolve {
($key:expr) => {
- styles.get($key).resolve(ctx, self.level)?
+ styles.get($key).resolve(world, self.level)?
};
}
@@ -149,13 +149,13 @@ pub enum Leveled<T> {
impl<T: Cast + Clone> Leveled<T> {
/// Resolve the value based on the level.
- pub fn resolve(&self, ctx: &mut Context, level: NonZeroUsize) -> TypResult<T> {
+ pub fn resolve(&self, world: &dyn World, level: NonZeroUsize) -> TypResult<T> {
Ok(match self {
Self::Value(value) => value.clone(),
Self::Mapping(mapping) => mapping(level),
Self::Func(func, span) => {
let args = Args::new(*span, [Value::Int(level.get() as i64)]);
- func.call_detached(ctx, args)?.cast().at(*span)?
+ func.call_detached(world, args)?.cast().at(*span)?
}
})
}
diff --git a/src/library/structure/list.rs b/src/library/structure/list.rs
index c4167cf9..e9365cd6 100644
--- a/src/library/structure/list.rs
+++ b/src/library/structure/list.rs
@@ -56,7 +56,7 @@ impl<const L: ListKind> ListNode<L> {
#[property(resolve)]
pub const SPACING: BlockSpacing = Ratio::one().into();
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
Ok(Content::show(Self {
start: args.named("start")?.unwrap_or(1),
tight: args.named("tight")?.unwrap_or(true),
@@ -100,7 +100,7 @@ impl<const L: ListKind> Show for ListNode<L> {
}
}
- fn realize(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Content> {
+ fn realize(&self, world: &dyn World, styles: StyleChain) -> TypResult<Content> {
let mut cells = vec![];
let mut number = self.start;
@@ -112,7 +112,7 @@ impl<const L: ListKind> Show for ListNode<L> {
cells.push(LayoutNode::default());
cells.push(
label
- .resolve(ctx, L, number)?
+ .resolve(world, L, number)?
.styled_with_map(map.clone())
.role(Role::ListLabel)
.pack(),
@@ -145,7 +145,7 @@ impl<const L: ListKind> Show for ListNode<L> {
fn finalize(
&self,
- _: &mut Context,
+ _: &dyn World,
styles: StyleChain,
realized: Content,
) -> TypResult<Content> {
@@ -208,7 +208,7 @@ impl Label {
/// Resolve the value based on the level.
pub fn resolve(
&self,
- ctx: &mut Context,
+ world: &dyn World,
kind: ListKind,
number: usize,
) -> TypResult<Content> {
@@ -225,7 +225,7 @@ impl Label {
Self::Content(content) => content.clone(),
Self::Func(func, span) => {
let args = Args::new(*span, [Value::Int(number as i64)]);
- func.call_detached(ctx, args)?.display()
+ func.call_detached(world, args)?.display()
}
})
}
diff --git a/src/library/structure/reference.rs b/src/library/structure/reference.rs
index 0eeb4bf5..22dbec01 100644
--- a/src/library/structure/reference.rs
+++ b/src/library/structure/reference.rs
@@ -6,7 +6,7 @@ pub struct RefNode(pub EcoString);
#[node(showable)]
impl RefNode {
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
Ok(Content::show(Self(args.expect("label")?)))
}
}
@@ -22,7 +22,7 @@ impl Show for RefNode {
}
}
- fn realize(&self, _: &mut Context, _: StyleChain) -> TypResult<Content> {
+ fn realize(&self, _: &dyn World, _: StyleChain) -> TypResult<Content> {
Ok(Content::Text(format_eco!("@{}", self.0)))
}
}
diff --git a/src/library/structure/table.rs b/src/library/structure/table.rs
index 0f74fc96..08fa5386 100644
--- a/src/library/structure/table.rs
+++ b/src/library/structure/table.rs
@@ -30,7 +30,7 @@ impl TableNode {
#[property(resolve, shorthand(around))]
pub const BELOW: Option<BlockSpacing> = Some(Ratio::one().into());
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
let columns = args.named("columns")?.unwrap_or_default();
let rows = args.named("rows")?.unwrap_or_default();
let base_gutter: Vec<TrackSizing> = args.named("gutter")?.unwrap_or_default();
@@ -72,7 +72,7 @@ impl Show for TableNode {
}
}
- fn realize(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Content> {
+ fn realize(&self, world: &dyn World, styles: StyleChain) -> TypResult<Content> {
let fill = styles.get(Self::FILL);
let stroke = styles.get(Self::STROKE).map(RawStroke::unwrap_or_default);
let padding = styles.get(Self::PADDING);
@@ -92,7 +92,7 @@ impl Show for TableNode {
let x = i % cols;
let y = i / cols;
- if let Some(fill) = fill.resolve(ctx, x, y)? {
+ if let Some(fill) = fill.resolve(world, x, y)? {
child = child.filled(fill);
}
@@ -110,7 +110,7 @@ impl Show for TableNode {
fn finalize(
&self,
- _: &mut Context,
+ _: &dyn World,
styles: StyleChain,
realized: Content,
) -> TypResult<Content> {
@@ -129,12 +129,12 @@ pub enum Celled<T> {
impl<T: Cast + Clone> Celled<T> {
/// Resolve the value based on the cell position.
- pub fn resolve(&self, ctx: &mut Context, x: usize, y: usize) -> TypResult<T> {
+ pub fn resolve(&self, world: &dyn World, x: usize, y: usize) -> TypResult<T> {
Ok(match self {
Self::Value(value) => value.clone(),
Self::Func(func, span) => {
let args = Args::new(*span, [Value::Int(x as i64), Value::Int(y as i64)]);
- func.call_detached(ctx, args)?.cast().at(*span)?
+ func.call_detached(world, args)?.cast().at(*span)?
}
})
}
diff --git a/src/library/text/deco.rs b/src/library/text/deco.rs
index 8295f1a2..c58148b4 100644
--- a/src/library/text/deco.rs
+++ b/src/library/text/deco.rs
@@ -34,7 +34,7 @@ impl<const L: DecoLine> DecoNode<L> {
/// with the glyphs. Does not apply to strikethrough.
pub const EVADE: bool = true;
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
Ok(Content::show(Self(args.expect("body")?)))
}
}
@@ -48,7 +48,7 @@ impl<const L: DecoLine> Show for DecoNode<L> {
dict! { "body" => Value::Content(self.0.clone()) }
}
- fn realize(&self, _: &mut Context, styles: StyleChain) -> TypResult<Content> {
+ fn realize(&self, _: &dyn World, styles: StyleChain) -> TypResult<Content> {
Ok(self.0.clone().styled(TextNode::DECO, Decoration {
line: L,
stroke: styles.get(Self::STROKE).unwrap_or_default(),
diff --git a/src/library/text/link.rs b/src/library/text/link.rs
index c4898eb0..7d5c3109 100644
--- a/src/library/text/link.rs
+++ b/src/library/text/link.rs
@@ -18,7 +18,7 @@ impl LinkNode {
/// Whether to underline the link.
pub const UNDERLINE: Smart<bool> = Smart::Auto;
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
Ok(Content::show({
let dest = args.expect::<Destination>("destination")?;
let body = match dest {
@@ -64,7 +64,7 @@ impl Show for LinkNode {
}
}
- fn realize(&self, _: &mut Context, _: StyleChain) -> TypResult<Content> {
+ fn realize(&self, _: &dyn World, _: StyleChain) -> TypResult<Content> {
Ok(self.body.clone().unwrap_or_else(|| match &self.dest {
Destination::Url(url) => {
let mut text = url.as_str();
@@ -80,7 +80,7 @@ impl Show for LinkNode {
fn finalize(
&self,
- _: &mut Context,
+ _: &dyn World,
styles: StyleChain,
mut realized: Content,
) -> TypResult<Content> {
diff --git a/src/library/text/mod.rs b/src/library/text/mod.rs
index 35780186..be586874 100644
--- a/src/library/text/mod.rs
+++ b/src/library/text/mod.rs
@@ -128,7 +128,7 @@ impl TextNode {
#[property(skip, fold)]
pub const DECO: Decoration = vec![];
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
// The text constructor is special: It doesn't create a text node.
// Instead, it leaves the passed argument structurally unchanged, but
// styles all text in it.
@@ -422,12 +422,12 @@ impl Fold for Vec<(Tag, u32)> {
}
/// Convert a string or content to lowercase.
-pub fn lower(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
+pub fn lower(_: &mut Vm, args: &mut Args) -> TypResult<Value> {
case(Case::Lower, args)
}
/// Convert a string or content to uppercase.
-pub fn upper(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
+pub fn upper(_: &mut Vm, args: &mut Args) -> TypResult<Value> {
case(Case::Upper, args)
}
@@ -461,7 +461,7 @@ impl Case {
}
/// Display text in small capitals.
-pub fn smallcaps(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
+pub fn smallcaps(_: &mut Vm, args: &mut Args) -> TypResult<Value> {
let body: Content = args.expect("content")?;
Ok(Value::Content(body.styled(TextNode::SMALLCAPS, true)))
}
@@ -493,7 +493,7 @@ pub struct StrongNode(pub Content);
#[node(showable)]
impl StrongNode {
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
Ok(Content::show(Self(args.expect("body")?)))
}
}
@@ -507,7 +507,7 @@ impl Show for StrongNode {
dict! { "body" => Value::Content(self.0.clone()) }
}
- fn realize(&self, _: &mut Context, _: StyleChain) -> TypResult<Content> {
+ fn realize(&self, _: &dyn World, _: StyleChain) -> TypResult<Content> {
Ok(self.0.clone().styled(TextNode::BOLD, Toggle))
}
}
@@ -518,7 +518,7 @@ pub struct EmphNode(pub Content);
#[node(showable)]
impl EmphNode {
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
Ok(Content::show(Self(args.expect("body")?)))
}
}
@@ -532,7 +532,7 @@ impl Show for EmphNode {
dict! { "body" => Value::Content(self.0.clone()) }
}
- fn realize(&self, _: &mut Context, _: StyleChain) -> TypResult<Content> {
+ fn realize(&self, _: &dyn World, _: StyleChain) -> TypResult<Content> {
Ok(self.0.clone().styled(TextNode::ITALIC, Toggle))
}
}
diff --git a/src/library/text/par.rs b/src/library/text/par.rs
index 8309bcc8..e8282ef1 100644
--- a/src/library/text/par.rs
+++ b/src/library/text/par.rs
@@ -49,7 +49,7 @@ impl ParNode {
#[property(resolve)]
pub const LINEBREAKS: Smart<Linebreaks> = Smart::Auto;
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
// The paragraph constructor is special: It doesn't create a paragraph
// node. Instead, it just ensures that the passed content lives is in a
// separate paragraph and styles it.
@@ -64,7 +64,7 @@ impl ParNode {
impl Layout for ParNode {
fn layout(
&self,
- ctx: &mut Context,
+ world: &dyn World,
regions: &Regions,
styles: StyleChain,
) -> TypResult<Vec<Frame>> {
@@ -74,13 +74,13 @@ impl Layout for ParNode {
// Perform BiDi analysis and then prepare paragraph layout by building a
// representation on which we can do line breaking without layouting
// each and every line from scratch.
- let p = prepare(ctx, self, &text, segments, regions, styles)?;
+ let p = prepare(world, self, &text, segments, regions, styles)?;
// Break the paragraph into lines.
- let lines = linebreak(&p, ctx.loader.as_ref(), regions.first.x);
+ let lines = linebreak(&p, world, regions.first.x);
// Stack the lines into one frame per region.
- stack(&p, ctx, &lines, regions)
+ stack(&p, world, &lines, regions)
}
}
@@ -170,7 +170,7 @@ pub struct ParbreakNode;
#[node]
impl ParbreakNode {
- fn construct(_: &mut Machine, _: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, _: &mut Args) -> TypResult<Content> {
Ok(Content::Parbreak)
}
}
@@ -180,7 +180,7 @@ pub struct LinebreakNode;
#[node]
impl LinebreakNode {
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
let justified = args.named("justified")?.unwrap_or(false);
Ok(Content::Linebreak { justified })
}
@@ -496,7 +496,7 @@ fn collect<'a>(
/// Prepare paragraph layout by shaping the whole paragraph and layouting all
/// contained inline-level nodes.
fn prepare<'a>(
- ctx: &mut Context,
+ world: &dyn World,
par: &'a ParNode,
text: &'a str,
segments: Vec<(Segment<'a>, StyleChain<'a>)>,
@@ -517,13 +517,7 @@ fn prepare<'a>(
let end = cursor + segment.len();
match segment {
Segment::Text(_) => {
- shape_range(
- &mut items,
- ctx.loader.as_ref(),
- &bidi,
- cursor .. end,
- styles,
- );
+ shape_range(&mut items, world, &bidi, cursor .. end, styles);
}
Segment::Spacing(spacing) => match spacing {
Spacing::Relative(v) => {
@@ -540,7 +534,7 @@ 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 mut frame = node.layout(world, &pod, styles)?.remove(0);
frame.translate(Point::with_y(styles.get(TextNode::BASELINE)));
frame.apply_role(Role::GenericInline);
items.push(Item::Frame(frame));
@@ -567,14 +561,14 @@ fn prepare<'a>(
/// items for them.
fn shape_range<'a>(
items: &mut Vec<Item<'a>>,
- loader: &dyn Loader,
+ world: &dyn World,
bidi: &BidiInfo<'a>,
range: Range,
styles: StyleChain<'a>,
) {
let mut process = |text, level: Level| {
let dir = if level.is_ltr() { Dir::LTR } else { Dir::RTL };
- let shaped = shape(loader, text, styles, dir);
+ let shaped = shape(world, text, styles, dir);
items.push(Item::Text(shaped));
};
@@ -633,12 +627,12 @@ fn shared_get<'a, K: Key<'a>>(
/// Find suitable linebreaks.
fn linebreak<'a>(
p: &'a Preparation<'a>,
- loader: &dyn Loader,
+ world: &dyn World,
width: Length,
) -> Vec<Line<'a>> {
match p.styles.get(ParNode::LINEBREAKS) {
- Linebreaks::Simple => linebreak_simple(p, loader, width),
- Linebreaks::Optimized => linebreak_optimized(p, loader, width),
+ Linebreaks::Simple => linebreak_simple(p, world, width),
+ Linebreaks::Optimized => linebreak_optimized(p, world, width),
}
}
@@ -647,7 +641,7 @@ fn linebreak<'a>(
/// very unbalanced line, but is fast and simple.
fn linebreak_simple<'a>(
p: &'a Preparation<'a>,
- loader: &dyn Loader,
+ world: &dyn World,
width: Length,
) -> Vec<Line<'a>> {
let mut lines = vec![];
@@ -656,7 +650,7 @@ fn linebreak_simple<'a>(
for (end, mandatory, hyphen) in breakpoints(p) {
// Compute the line and its size.
- let mut attempt = line(p, loader, start .. end, mandatory, hyphen);
+ let mut attempt = line(p, world, start .. end, mandatory, hyphen);
// If the line doesn't fit anymore, we push the last fitting attempt
// into the stack and rebuild the line from the attempt's end. The
@@ -665,7 +659,7 @@ fn linebreak_simple<'a>(
if let Some((last_attempt, last_end)) = last.take() {
lines.push(last_attempt);
start = last_end;
- attempt = line(p, loader, start .. end, mandatory, hyphen);
+ attempt = line(p, world, start .. end, mandatory, hyphen);
}
}
@@ -707,7 +701,7 @@ fn linebreak_simple<'a>(
/// text.
fn linebreak_optimized<'a>(
p: &'a Preparation<'a>,
- loader: &dyn Loader,
+ world: &dyn World,
width: Length,
) -> Vec<Line<'a>> {
/// The cost of a line or paragraph layout.
@@ -732,7 +726,7 @@ fn linebreak_optimized<'a>(
let mut table = vec![Entry {
pred: 0,
total: 0.0,
- line: line(p, loader, 0 .. 0, false, false),
+ line: line(p, world, 0 .. 0, false, false),
}];
let em = p.styles.get(TextNode::SIZE);
@@ -746,7 +740,7 @@ fn linebreak_optimized<'a>(
for (i, pred) in table.iter_mut().enumerate().skip(active) {
// Layout the line.
let start = pred.line.end;
- let attempt = line(p, loader, start .. end, mandatory, hyphen);
+ let attempt = line(p, world, start .. end, mandatory, hyphen);
// Determine how much the line's spaces would need to be stretched
// to make it the desired width.
@@ -920,7 +914,7 @@ impl Breakpoints<'_> {
/// Create a line which spans the given range.
fn line<'a>(
p: &'a Preparation,
- loader: &dyn Loader,
+ world: &dyn World,
mut range: Range,
mandatory: bool,
hyphen: bool,
@@ -975,9 +969,9 @@ fn line<'a>(
if hyphen || start + shaped.text.len() > range.end {
if hyphen || start < range.end || before.is_empty() {
let shifted = start - base .. range.end - base;
- let mut reshaped = shaped.reshape(loader, shifted);
+ let mut reshaped = shaped.reshape(world, shifted);
if hyphen || shy {
- reshaped.push_hyphen(loader);
+ reshaped.push_hyphen(world);
}
width += reshaped.width;
last = Some(Item::Text(reshaped));
@@ -998,7 +992,7 @@ fn line<'a>(
if range.start + shaped.text.len() > end {
if range.start < end {
let shifted = range.start - base .. end - base;
- let reshaped = shaped.reshape(loader, shifted);
+ let reshaped = shaped.reshape(world, shifted);
width += reshaped.width;
first = Some(Item::Text(reshaped));
}
@@ -1028,7 +1022,7 @@ fn line<'a>(
/// Combine layouted lines into one frame per region.
fn stack(
p: &Preparation,
- ctx: &mut Context,
+ world: &dyn World,
lines: &[Line],
regions: &Regions,
) -> TypResult<Vec<Frame>> {
@@ -1048,7 +1042,7 @@ fn stack(
// Stack the lines into one frame per region.
for line in lines {
- let frame = commit(p, ctx, line, &regions, width)?;
+ let frame = commit(p, world, line, &regions, width)?;
let height = frame.size().y;
while !regions.first.y.fits(height) && !regions.in_last() {
@@ -1078,7 +1072,7 @@ fn stack(
/// Commit to a line and build its frame.
fn commit(
p: &Preparation,
- ctx: &mut Context,
+ world: &dyn World,
line: &Line,
regions: &Regions,
width: Length,
@@ -1149,7 +1143,7 @@ fn commit(
offset += v.share(fr, remaining);
}
Item::Text(shaped) => {
- let frame = shaped.build(ctx.loader.as_ref(), justification);
+ let frame = shaped.build(world, justification);
push(&mut offset, frame);
}
Item::Frame(frame) => {
@@ -1160,7 +1154,7 @@ fn commit(
let fill = Fraction::one().share(fr, remaining);
let size = Size::new(fill, regions.base.y);
let pod = Regions::one(size, regions.base, Spec::new(false, false));
- let frame = node.layout(ctx, &pod, *styles)?.remove(0);
+ let frame = node.layout(world, &pod, *styles)?.remove(0);
let width = frame.width();
let count = (fill / width).floor();
let remaining = fill % width;
diff --git a/src/library/text/raw.rs b/src/library/text/raw.rs
index a2a57fa1..c729fa40 100644
--- a/src/library/text/raw.rs
+++ b/src/library/text/raw.rs
@@ -35,7 +35,7 @@ impl RawNode {
#[property(resolve, shorthand(around))]
pub const BELOW: Option<BlockSpacing> = Some(Ratio::one().into());
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
Ok(Content::show(Self {
text: args.expect("text")?,
block: args.named("block")?.unwrap_or(false),
@@ -59,7 +59,7 @@ impl Show for RawNode {
}
}
- fn realize(&self, _: &mut Context, styles: StyleChain) -> TypResult<Content> {
+ fn realize(&self, _: &dyn World, styles: StyleChain) -> TypResult<Content> {
let lang = styles.get(Self::LANG).as_ref().map(|s| s.to_lowercase());
let foreground = THEME
.settings
@@ -111,7 +111,7 @@ impl Show for RawNode {
fn finalize(
&self,
- _: &mut Context,
+ _: &dyn World,
styles: StyleChain,
mut realized: Content,
) -> TypResult<Content> {
diff --git a/src/library/text/repeat.rs b/src/library/text/repeat.rs
index aca281fc..c2a0de70 100644
--- a/src/library/text/repeat.rs
+++ b/src/library/text/repeat.rs
@@ -6,7 +6,7 @@ pub struct RepeatNode(pub LayoutNode);
#[node]
impl RepeatNode {
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
Ok(Content::inline(Self(args.expect("body")?)))
}
}
@@ -14,11 +14,11 @@ impl RepeatNode {
impl Layout for RepeatNode {
fn layout(
&self,
- ctx: &mut Context,
+ world: &dyn World,
regions: &Regions,
styles: StyleChain,
) -> TypResult<Vec<Frame>> {
// The actual repeating happens directly in the paragraph.
- self.0.layout(ctx, regions, styles)
+ self.0.layout(world, regions, styles)
}
}
diff --git a/src/library/text/shaping.rs b/src/library/text/shaping.rs
index 3d905c99..6e505702 100644
--- a/src/library/text/shaping.rs
+++ b/src/library/text/shaping.rs
@@ -80,8 +80,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, loader: &dyn Loader, justification: Length) -> Frame {
- let (top, bottom) = self.measure(loader);
+ pub fn build(&self, world: &dyn World, justification: Length) -> Frame {
+ let (top, bottom) = self.measure(world);
let size = Size::new(self.width, top + bottom);
let mut offset = Length::zero();
@@ -144,7 +144,7 @@ impl<'a> ShapedText<'a> {
}
/// Measure the top and bottom extent of this text.
- fn measure(&self, loader: &dyn Loader) -> (Length, Length) {
+ fn measure(&self, world: &dyn World) -> (Length, Length) {
let mut top = Length::zero();
let mut bottom = Length::zero();
@@ -162,10 +162,10 @@ impl<'a> ShapedText<'a> {
// When there are no glyphs, we just use the vertical metrics of the
// first available font.
for family in families(self.styles) {
- if let Some(font) = loader
+ if let Some(font) = world
.book()
.select(family, self.variant)
- .and_then(|id| loader.font(id).ok())
+ .and_then(|id| world.font(id).ok())
{
expand(&font);
break;
@@ -199,7 +199,7 @@ impl<'a> ShapedText<'a> {
/// shaping process if possible.
pub fn reshape(
&'a self,
- loader: &dyn Loader,
+ world: &dyn World,
text_range: Range<usize>,
) -> ShapedText<'a> {
if let Some(glyphs) = self.slice_safe_to_break(text_range.clone()) {
@@ -213,17 +213,17 @@ impl<'a> ShapedText<'a> {
glyphs: Cow::Borrowed(glyphs),
}
} else {
- shape(loader, &self.text[text_range], self.styles, self.dir)
+ shape(world, &self.text[text_range], self.styles, self.dir)
}
}
/// Push a hyphen to end of the text.
- pub fn push_hyphen(&mut self, loader: &dyn Loader) {
+ pub fn push_hyphen(&mut self, world: &dyn World) {
families(self.styles).find_map(|family| {
- let font = loader
+ let font = world
.book()
.select(family, self.variant)
- .and_then(|id| loader.font(id).ok())?;
+ .and_then(|id| world.font(id).ok())?;
let ttf = font.ttf();
let glyph_id = ttf.glyph_index('-')?;
let x_advance = font.to_em(ttf.glyph_hor_advance(glyph_id)?);
@@ -306,7 +306,7 @@ impl Debug for ShapedText<'_> {
/// Holds shaping results and metadata common to all shaped segments.
struct ShapingContext<'a> {
- loader: &'a dyn Loader,
+ world: &'a dyn World,
glyphs: Vec<ShapedGlyph>,
used: Vec<Font>,
styles: StyleChain<'a>,
@@ -319,7 +319,7 @@ struct ShapingContext<'a> {
/// Shape text into [`ShapedText`].
pub fn shape<'a>(
- loader: &dyn Loader,
+ world: &dyn World,
text: &'a str,
styles: StyleChain<'a>,
dir: Dir,
@@ -327,7 +327,7 @@ pub fn shape<'a>(
let size = styles.get(TextNode::SIZE);
let mut ctx = ShapingContext {
- loader,
+ world,
size,
glyphs: vec![],
used: vec![],
@@ -368,10 +368,10 @@ fn shape_segment<'a>(
}
// Find the next available family.
- let book = ctx.loader.book();
+ let book = ctx.world.book();
let mut selection = families.find_map(|family| {
book.select(family, ctx.variant)
- .and_then(|id| ctx.loader.font(id).ok())
+ .and_then(|id| ctx.world.font(id).ok())
.filter(|font| !ctx.used.contains(font))
});
@@ -380,7 +380,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.loader.font(id).ok())
+ .and_then(|id| ctx.world.font(id).ok())
.filter(|font| !ctx.used.contains(font));
}
diff --git a/src/library/text/shift.rs b/src/library/text/shift.rs
index 75b2a579..5da36da1 100644
--- a/src/library/text/shift.rs
+++ b/src/library/text/shift.rs
@@ -28,7 +28,7 @@ impl<const S: ScriptKind> ShiftNode<S> {
/// The font size for synthetic sub- and superscripts.
pub const SIZE: TextSize = TextSize(Em::new(0.6).into());
- fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
+ fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> {
Ok(Content::show(Self(args.expect("body")?)))
}
}
@@ -42,11 +42,11 @@ impl<const S: ScriptKind> Show for ShiftNode<S> {
dict! { "body" => Value::Content(self.0.clone()) }
}
- fn realize(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Content> {
+ fn realize(&self, world: &dyn World, styles: StyleChain) -> TypResult<Content> {
let mut transformed = None;
if styles.get(Self::TYPOGRAPHIC) {
if let Some(text) = search_text(&self.0, S) {
- if is_shapable(ctx.loader.as_ref(), &text, styles) {
+ if is_shapable(world, &text, styles) {
transformed = Some(Content::Text(text));
}
}
@@ -91,12 +91,12 @@ fn search_text(content: &Content, mode: ScriptKind) -> Option<EcoString> {
/// Checks whether the first retrievable family contains all code points of the
/// given string.
-fn is_shapable(loader: &dyn Loader, text: &str, styles: StyleChain) -> bool {
- let book = loader.book();
+fn is_shapable(world: &dyn World, text: &str, styles: StyleChain) -> bool {
for family in styles.get(TextNode::FAMILY).iter() {
- if let Some(font) = book
+ if let Some(font) = world
+ .book()
.select(family.as_str(), variant(styles))
- .and_then(|id| loader.font(id).ok())
+ .and_then(|id| world.font(id).ok())
{
return text.chars().all(|c| font.ttf().glyph_index(c).is_some());
}
diff --git a/src/library/utility/color.rs b/src/library/utility/color.rs
index 7c6ed873..a7d55d1c 100644
--- a/src/library/utility/color.rs
+++ b/src/library/utility/color.rs
@@ -3,13 +3,13 @@ use std::str::FromStr;
use crate::library::prelude::*;
/// Create a grayscale color.
-pub fn luma(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
+pub fn luma(_: &mut Vm, args: &mut Args) -> TypResult<Value> {
let Component(luma) = args.expect("gray component")?;
Ok(Value::Color(LumaColor::new(luma).into()))
}
/// Create an RGB(A) color.
-pub fn rgb(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
+pub fn rgb(_: &mut Vm, args: &mut Args) -> TypResult<Value> {
Ok(Value::Color(
if let Some(string) = args.find::<Spanned<EcoString>>()? {
match RgbaColor::from_str(&string.v) {
@@ -27,7 +27,7 @@ pub fn rgb(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
}
/// Create a CMYK color.
-pub fn cmyk(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
+pub fn cmyk(_: &mut Vm, args: &mut Args) -> TypResult<Value> {
let RatioComponent(c) = args.expect("cyan component")?;
let RatioComponent(m) = args.expect("magenta component")?;
let RatioComponent(y) = args.expect("yellow component")?;
diff --git a/src/library/utility/data.rs b/src/library/utility/data.rs
index f9e970dc..59f3d351 100644
--- a/src/library/utility/data.rs
+++ b/src/library/utility/data.rs
@@ -1,13 +1,13 @@
use crate::library::prelude::*;
/// Read structured data from a CSV file.
-pub fn csv(vm: &mut Machine, args: &mut Args) -> TypResult<Value> {
+pub fn csv(vm: &mut Vm, args: &mut Args) -> TypResult<Value> {
let Spanned { v: path, span } =
args.expect::<Spanned<EcoString>>("path to csv file")?;
let path = vm.locate(&path).at(span)?;
let try_load = || -> io::Result<Value> {
- let data = vm.ctx.loader.file(&path)?;
+ let data = vm.world.file(&path)?;
let mut builder = csv::ReaderBuilder::new();
builder.has_headers(false);
diff --git a/src/library/utility/math.rs b/src/library/utility/math.rs
index f68cc1bf..47648282 100644
--- a/src/library/utility/math.rs
+++ b/src/library/utility/math.rs
@@ -3,7 +3,7 @@ use std::cmp::Ordering;
use crate::library::prelude::*;
/// Convert a value to an integer.
-pub fn int(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
+pub fn int(_: &mut Vm, args: &mut Args) -> TypResult<Value> {
let Spanned { v, span } = args.expect("value")?;
Ok(Value::Int(match v {
Value::Bool(v) => v as i64,
@@ -18,7 +18,7 @@ pub fn int(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
}
/// Convert a value to a float.
-pub fn float(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
+pub fn float(_: &mut Vm, args: &mut Args) -> TypResult<Value> {
let Spanned { v, span } = args.expect("value")?;
Ok(Value::Float(match v {
Value::Int(v) => v as f64,
@@ -32,7 +32,7 @@ pub fn float(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
}
/// The absolute value of a numeric value.
-pub fn abs(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
+pub fn abs(_: &mut Vm, args: &mut Args) -> TypResult<Value> {
let Spanned { v, span } = args.expect("numeric value")?;
Ok(match v {
Value::Int(v) => Value::Int(v.abs()),
@@ -48,12 +48,12 @@ pub fn abs(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
}
/// The minimum of a sequence of values.
-pub fn min(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
+pub fn min(_: &mut Vm, args: &mut Args) -> TypResult<Value> {
minmax(args, Ordering::Less)
}
/// The maximum of a sequence of values.
-pub fn max(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
+pub fn max(_: &mut Vm, args: &mut Args) -> TypResult<Value> {
minmax(args, Ordering::Greater)
}
@@ -79,17 +79,17 @@ fn minmax(args: &mut Args, goal: Ordering) -> TypResult<Value> {
}
/// Whether an integer is even.
-pub fn even(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
+pub fn even(_: &mut Vm, args: &mut Args) -> TypResult<Value> {
Ok(Value::Bool(args.expect::<i64>("integer")? % 2 == 0))
}
/// Whether an integer is odd.
-pub fn odd(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
+pub fn odd(_: &mut Vm, args: &mut Args) -> TypResult<Value> {
Ok(Value::Bool(args.expect::<i64>("integer")? % 2 != 0))
}
/// The modulo of two numbers.
-pub fn mod_(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
+pub fn mod_(_: &mut Vm, args: &mut Args) -> TypResult<Value> {
let Spanned { v: v1, span: span1 } = args.expect("integer or float")?;
let Spanned { v: v2, span: span2 } = args.expect("integer or float")?;
@@ -119,7 +119,7 @@ pub fn mod_(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
}
/// Create a sequence of numbers.
-pub fn range(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
+pub fn range(_: &mut Vm, args: &mut Args) -> TypResult<Value> {
let first = args.expect::<i64>("end")?;
let (start, end) = match args.eat::<i64>()? {
Some(second) => (first, second),
diff --git a/src/library/utility/mod.rs b/src/library/utility/mod.rs
index bc7c6f25..40a107ba 100644
--- a/src/library/utility/mod.rs
+++ b/src/library/utility/mod.rs
@@ -10,17 +10,17 @@ pub use data::*;
pub use math::*;
pub use string::*;
-use crate::eval::{Eval, Machine, Scopes};
+use crate::eval::{Eval, Scopes, Vm};
use crate::library::prelude::*;
use crate::source::Source;
/// The name of a value's type.
-pub fn type_(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
+pub fn type_(_: &mut Vm, args: &mut Args) -> TypResult<Value> {
Ok(args.expect::<Value>("value")?.type_name().into())
}
/// Ensure that a condition is fulfilled.
-pub fn assert(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
+pub fn assert(_: &mut Vm, args: &mut Args) -> TypResult<Value> {
let Spanned { v, span } = args.expect::<Spanned<bool>>("condition")?;
if !v {
bail!(span, "assertion failed");
@@ -29,19 +29,18 @@ pub fn assert(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
}
/// Evaluate a string as Typst markup.
-pub fn eval(vm: &mut Machine, args: &mut Args) -> TypResult<Value> {
- let Spanned { v: src, span } = args.expect::<Spanned<String>>("source")?;
+pub fn eval(vm: &mut Vm, args: &mut Args) -> TypResult<Value> {
+ let Spanned { v: text, span } = args.expect::<Spanned<String>>("source")?;
// Parse the source and set a synthetic span for all nodes.
- let source = Source::synthesized(src, span);
+ let source = Source::synthesized(text, span);
let ast = source.ast()?;
// Evaluate the source.
- let std = vm.ctx.config.std.clone();
- let scopes = Scopes::new(Some(&std));
- let mut sub = Machine::new(vm.ctx, vec![], scopes);
+ let std = &vm.world.config().std;
+ let scopes = Scopes::new(Some(std));
+ let mut sub = Vm::new(vm.world, vec![], scopes);
let result = ast.eval(&mut sub);
- assert!(vm.deps.is_empty());
// Handle control flow.
if let Some(flow) = sub.flow {
diff --git a/src/library/utility/string.rs b/src/library/utility/string.rs
index 972b44d7..d825d84b 100644
--- a/src/library/utility/string.rs
+++ b/src/library/utility/string.rs
@@ -2,12 +2,12 @@ use crate::eval::Regex;
use crate::library::prelude::*;
/// The string representation of a value.
-pub fn repr(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
+pub fn repr(_: &mut Vm, args: &mut Args) -> TypResult<Value> {
Ok(args.expect::<Value>("value")?.repr().into())
}
/// Convert a value to a string.
-pub fn str(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
+pub fn str(_: &mut Vm, args: &mut Args) -> TypResult<Value> {
let Spanned { v, span } = args.expect("value")?;
Ok(Value::Str(match v {
Value::Int(v) => format_str!("{}", v),
@@ -18,29 +18,29 @@ pub fn str(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
}
/// Create blind text.
-pub fn lorem(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
+pub fn lorem(_: &mut Vm, args: &mut Args) -> TypResult<Value> {
let words: usize = args.expect("number of words")?;
Ok(Value::Str(lipsum::lipsum(words).into()))
}
/// Create a regular expression.
-pub fn regex(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
+pub fn regex(_: &mut Vm, args: &mut Args) -> TypResult<Value> {
let Spanned { v, span } = args.expect::<Spanned<EcoString>>("regular expression")?;
Ok(Regex::new(&v).at(span)?.into())
}
/// Converts an integer into one or multiple letters.
-pub fn letter(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
+pub fn letter(_: &mut Vm, args: &mut Args) -> TypResult<Value> {
numbered(Numbering::Letter, args)
}
/// Converts an integer into a roman numeral.
-pub fn roman(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
+pub fn roman(_: &mut Vm, args: &mut Args) -> TypResult<Value> {
numbered(Numbering::Roman, args)
}
/// Convert a number into a symbol.
-pub fn symbol(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
+pub fn symbol(_: &mut Vm, args: &mut Args) -> TypResult<Value> {
numbered(Numbering::Symbol, args)
}