diff --git a/library/src/layout/container.rs b/library/src/layout/container.rs index b7e7aa181..7bb6a6e94 100644 --- a/library/src/layout/container.rs +++ b/library/src/layout/container.rs @@ -38,7 +38,7 @@ use crate::prelude::*; /// ## Category /// layout #[func] -#[capable(Layout, Inline)] +#[capable(Layout)] #[derive(Debug, Hash)] pub struct BoxNode { /// How to size the content horizontally and vertically. @@ -99,8 +99,6 @@ impl Layout for BoxNode { } } -impl Inline for BoxNode {} - /// # Block /// A block-level container that places content into a separate flow. /// diff --git a/library/src/layout/flow.rs b/library/src/layout/flow.rs index e21dcd2af..7b721c594 100644 --- a/library/src/layout/flow.rs +++ b/library/src/layout/flow.rs @@ -2,6 +2,7 @@ use typst::model::Style; use super::{AlignNode, BlockNode, ColbreakNode, ParNode, PlaceNode, Spacing, VNode}; use crate::prelude::*; +use crate::visualize::{CircleNode, EllipseNode, ImageNode, RectNode, SquareNode}; /// Arrange spacing, paragraphs and block-level nodes into a flow. /// @@ -31,8 +32,17 @@ impl Layout for FlowNode { let barrier = Style::Barrier(child.id()); let styles = styles.chain_one(&barrier); layouter.layout_par(vt, node, styles)?; + } else if child.is::() + || child.is::() + || child.is::() + || child.is::() + || child.is::() + { + let barrier = Style::Barrier(child.id()); + let styles = styles.chain_one(&barrier); + layouter.layout_single(vt, child, styles)?; } else if child.has::() { - layouter.layout_block(vt, child, styles)?; + layouter.layout_multiple(vt, child, styles)?; } else if child.is::() { layouter.finish_region(); } else { @@ -157,8 +167,25 @@ impl<'a> FlowLayouter<'a> { Ok(()) } - /// Layout a block. - fn layout_block( + /// Layout into a single region. + fn layout_single( + &mut self, + vt: &mut Vt, + content: &Content, + styles: StyleChain, + ) -> SourceResult<()> { + let aligns = styles.get(AlignNode::ALIGNS).resolve(styles); + let sticky = styles.get(BlockNode::STICKY); + let pod = Regions::one(self.regions.base(), Axes::splat(false)); + let layoutable = content.with::().unwrap(); + let frame = layoutable.layout(vt, styles, pod)?.into_frame(); + self.layout_item(FlowItem::Frame(frame, aligns, sticky)); + self.last_was_par = false; + Ok(()) + } + + /// Layout into multiple regions. + fn layout_multiple( &mut self, vt: &mut Vt, block: &Content, diff --git a/library/src/layout/hide.rs b/library/src/layout/hide.rs index cedc24894..4f46324f7 100644 --- a/library/src/layout/hide.rs +++ b/library/src/layout/hide.rs @@ -21,7 +21,7 @@ use crate::prelude::*; /// ## Category /// layout #[func] -#[capable(Layout, Inline)] +#[capable(Show)] #[derive(Debug, Hash)] pub struct HideNode(pub Content); @@ -39,19 +39,8 @@ impl HideNode { } } -impl Layout for HideNode { - fn layout( - &self, - vt: &mut Vt, - styles: StyleChain, - regions: Regions, - ) -> SourceResult { - let mut fragment = self.0.layout(vt, styles, regions)?; - for frame in &mut fragment { - frame.clear(); - } - Ok(fragment) +impl Show for HideNode { + fn show(&self, _: &mut Vt, _: &Content, _: StyleChain) -> SourceResult { + Ok(self.0.clone().styled(Meta::DATA, vec![Meta::Hidden])) } } - -impl Inline for HideNode {} diff --git a/library/src/layout/mod.rs b/library/src/layout/mod.rs index f603ef6c1..3294a96c2 100644 --- a/library/src/layout/mod.rs +++ b/library/src/layout/mod.rs @@ -57,6 +57,7 @@ use crate::meta::DocumentNode; use crate::prelude::*; use crate::shared::BehavedBuilder; use crate::text::{LinebreakNode, SmartQuoteNode, SpaceNode, TextNode}; +use crate::visualize::{CircleNode, EllipseNode, ImageNode, RectNode, SquareNode}; /// Root-level layout. #[capability] @@ -144,10 +145,6 @@ impl Layout for Content { } } -/// Inline-level layout. -#[capability] -pub trait Inline: Layout {} - /// Realize into a node that is capable of root-level layout. fn realize_root<'a>( vt: &mut Vt, @@ -173,7 +170,14 @@ fn realize_block<'a>( content: &'a Content, styles: StyleChain<'a>, ) -> SourceResult<(Content, StyleChain<'a>)> { - if content.has::() && !applicable(content, styles) { + if content.has::() + && !content.is::() + && !content.is::() + && !content.is::() + && !content.is::() + && !content.is::() + && !applicable(content, styles) + { return Ok((content.clone(), styles)); } @@ -464,18 +468,19 @@ struct ParBuilder<'a>(BehavedBuilder<'a>); impl<'a> ParBuilder<'a> { fn accept(&mut self, content: &'a Content, styles: StyleChain<'a>) -> bool { if content.is::() - || content.is::() + || content.is::() || content.is::() || content.is::() - || content.is::() - || content.is::() - || content.has::() + || content.is::() + || content.is::() + || content.is::() + || content.to::().map_or(false, |node| !node.block) { self.0.push(content.clone(), styles); return true; } - if content.has::() { + if !content.is::() && content.has::() { let formula = FormulaNode { body: content.clone(), block: false }.pack(); self.0.push(formula, styles); return true; diff --git a/library/src/layout/par.rs b/library/src/layout/par.rs index 21551268e..b712d8b17 100644 --- a/library/src/layout/par.rs +++ b/library/src/layout/par.rs @@ -500,12 +500,14 @@ fn collect<'a>( .0 .items() .find_map(|child| { - if child.is::() || child.is::() { - Some(true) - } else if child.has::() { - Some(false) - } else { + if child.with::().map_or(false, |behaved| { + behaved.behaviour() == Behaviour::Ignorant + }) { None + } else if child.is::() || child.is::() { + Some(true) + } else { + Some(false) } }) .unwrap_or_default() @@ -558,11 +560,9 @@ fn collect<'a>( } else if let Some(&node) = child.to::() { full.push(SPACING_REPLACE); Segment::Spacing(node.amount) - } else if child.has::() { + } else { full.push(NODE_REPLACE); Segment::Inline(child) - } else { - panic!("unexpected par child: {child:?}"); }; if let Some(last) = full.chars().last() { diff --git a/library/src/layout/repeat.rs b/library/src/layout/repeat.rs index 06806fb07..10cd1d254 100644 --- a/library/src/layout/repeat.rs +++ b/library/src/layout/repeat.rs @@ -26,7 +26,7 @@ use crate::prelude::*; /// ## Category /// layout #[func] -#[capable(Layout, Inline)] +#[capable(Layout)] #[derive(Debug, Hash)] pub struct RepeatNode(pub Content); @@ -54,5 +54,3 @@ impl Layout for RepeatNode { self.0.layout(vt, styles, regions) } } - -impl Inline for RepeatNode {} diff --git a/library/src/layout/stack.rs b/library/src/layout/stack.rs index 5c1a471cf..35a0ff6fd 100644 --- a/library/src/layout/stack.rs +++ b/library/src/layout/stack.rs @@ -169,7 +169,7 @@ enum StackItem { /// Fractional spacing between other items. Fractional(Fr), /// A frame for a layouted block. - Frame(Frame, Align), + Frame(Frame, Axes), } impl<'a> StackLayouter<'a> { @@ -239,7 +239,7 @@ impl<'a> StackLayouter<'a> { styles.get(AlignNode::ALIGNS) }; - let align = aligns.get(self.axis).resolve(styles); + let aligns = aligns.resolve(styles); let fragment = block.layout(vt, styles, self.regions)?; let len = fragment.len(); for (i, frame) in fragment.into_iter().enumerate() { @@ -257,7 +257,7 @@ impl<'a> StackLayouter<'a> { self.used.main += gen.main; self.used.cross.set_max(gen.cross); - self.items.push(StackItem::Frame(frame, align)); + self.items.push(StackItem::Frame(frame, aligns)); if i + 1 < len { self.finish_region(); @@ -291,24 +291,30 @@ impl<'a> StackLayouter<'a> { match item { StackItem::Absolute(v) => cursor += v, StackItem::Fractional(v) => cursor += v.share(self.fr, remaining), - StackItem::Frame(frame, align) => { + StackItem::Frame(frame, aligns) => { if self.dir.is_positive() { - ruler = ruler.max(align); + ruler = ruler.max(aligns.get(self.axis)); } else { - ruler = ruler.min(align); + ruler = ruler.min(aligns.get(self.axis)); } - // Align along the block axis. + // Align along the main axis. let parent = size.get(self.axis); let child = frame.size().get(self.axis); - let block = ruler.position(parent - self.used.main) + let main = ruler.position(parent - self.used.main) + if self.dir.is_positive() { cursor } else { self.used.main - child - cursor }; - let pos = Gen::new(Abs::zero(), block).to_point(self.axis); + // Align along the cross axis. + let other = self.axis.other(); + let cross = aligns + .get(other) + .position(size.get(other) - frame.size().get(other)); + + let pos = Gen::new(cross, main).to_point(self.axis); cursor += child; output.push_frame(pos, frame); } diff --git a/library/src/layout/transform.rs b/library/src/layout/transform.rs index 1c9dfce5c..5977e90b8 100644 --- a/library/src/layout/transform.rs +++ b/library/src/layout/transform.rs @@ -39,7 +39,7 @@ use crate::prelude::*; /// ## Category /// layout #[func] -#[capable(Layout, Inline)] +#[capable(Layout)] #[derive(Debug, Hash)] pub struct MoveNode { /// The offset by which to move the content. @@ -75,18 +75,15 @@ impl Layout for MoveNode { styles: StyleChain, regions: Regions, ) -> SourceResult { - let mut fragment = self.body.layout(vt, styles, regions)?; - for frame in &mut fragment { - let delta = self.delta.resolve(styles); - let delta = delta.zip(regions.base()).map(|(d, s)| d.relative_to(s)); - frame.translate(delta.to_point()); - } - Ok(fragment) + let pod = Regions::one(regions.base(), Axes::splat(false)); + let mut frame = self.body.layout(vt, styles, pod)?.into_frame(); + let delta = self.delta.resolve(styles); + let delta = delta.zip(regions.base()).map(|(d, s)| d.relative_to(s)); + frame.translate(delta.to_point()); + Ok(Fragment::frame(frame)) } } -impl Inline for MoveNode {} - /// # Rotate /// Rotate content with affecting layout. /// @@ -116,7 +113,7 @@ impl Inline for MoveNode {} /// ## Category /// layout #[func] -#[capable(Layout, Inline)] +#[capable(Layout)] #[derive(Debug, Hash)] pub struct RotateNode { /// The angle by which to rotate the node. @@ -169,21 +166,18 @@ impl Layout for RotateNode { styles: StyleChain, regions: Regions, ) -> SourceResult { - let mut fragment = self.body.layout(vt, styles, regions)?; - for frame in &mut fragment { - let origin = styles.get(Self::ORIGIN).unwrap_or(Align::CENTER_HORIZON); - let Axes { x, y } = origin.zip(frame.size()).map(|(o, s)| o.position(s)); - let transform = Transform::translate(x, y) - .pre_concat(Transform::rotate(self.angle)) - .pre_concat(Transform::translate(-x, -y)); - frame.transform(transform); - } - Ok(fragment) + let pod = Regions::one(regions.base(), Axes::splat(false)); + let mut frame = self.body.layout(vt, styles, pod)?.into_frame(); + let origin = styles.get(Self::ORIGIN).unwrap_or(Align::CENTER_HORIZON); + let Axes { x, y } = origin.zip(frame.size()).map(|(o, s)| o.position(s)); + let ts = Transform::translate(x, y) + .pre_concat(Transform::rotate(self.angle)) + .pre_concat(Transform::translate(-x, -y)); + frame.transform(ts); + Ok(Fragment::frame(frame)) } } -impl Inline for RotateNode {} - /// # Scale /// Scale content without affecting layout. /// @@ -214,7 +208,7 @@ impl Inline for RotateNode {} /// ## Category /// layout #[func] -#[capable(Layout, Inline)] +#[capable(Layout)] #[derive(Debug, Hash)] pub struct ScaleNode { /// Scaling factor. @@ -262,17 +256,14 @@ impl Layout for ScaleNode { styles: StyleChain, regions: Regions, ) -> SourceResult { - let mut fragment = self.body.layout(vt, styles, regions)?; - for frame in &mut fragment { - let origin = styles.get(Self::ORIGIN).unwrap_or(Align::CENTER_HORIZON); - let Axes { x, y } = origin.zip(frame.size()).map(|(o, s)| o.position(s)); - let transform = Transform::translate(x, y) - .pre_concat(Transform::scale(self.factor.x, self.factor.y)) - .pre_concat(Transform::translate(-x, -y)); - frame.transform(transform); - } - Ok(fragment) + let pod = Regions::one(regions.base(), Axes::splat(false)); + let mut frame = self.body.layout(vt, styles, pod)?.into_frame(); + let origin = styles.get(Self::ORIGIN).unwrap_or(Align::CENTER_HORIZON); + let Axes { x, y } = origin.zip(frame.size()).map(|(o, s)| o.position(s)); + let transform = Transform::translate(x, y) + .pre_concat(Transform::scale(self.factor.x, self.factor.y)) + .pre_concat(Transform::translate(-x, -y)); + frame.transform(transform); + Ok(Fragment::frame(frame)) } } - -impl Inline for ScaleNode {} diff --git a/library/src/math/mod.rs b/library/src/math/mod.rs index 105940c73..85bf56ca0 100644 --- a/library/src/math/mod.rs +++ b/library/src/math/mod.rs @@ -141,7 +141,7 @@ pub fn module() -> Module { /// ## Category /// math #[func] -#[capable(Show, Finalize, Layout, Inline, LayoutMath)] +#[capable(Show, Finalize, Layout, LayoutMath)] #[derive(Debug, Clone, Hash)] pub struct FormulaNode { /// Whether the formula is displayed as a separate block. @@ -229,8 +229,6 @@ impl Layout for FormulaNode { } } -impl Inline for FormulaNode {} - #[capability] pub trait LayoutMath { fn layout_math(&self, ctx: &mut MathContext) -> SourceResult<()>; diff --git a/library/src/prelude.rs b/library/src/prelude.rs index 98ec1ccb9..5bb1d08a9 100644 --- a/library/src/prelude.rs +++ b/library/src/prelude.rs @@ -28,6 +28,6 @@ pub use typst::util::{format_eco, EcoString}; pub use typst::World; #[doc(no_inline)] -pub use crate::layout::{Fragment, Inline, Layout, Regions}; +pub use crate::layout::{Fragment, Layout, Regions}; #[doc(no_inline)] pub use crate::shared::{Behave, Behaviour, ContentExt, StyleMapExt}; diff --git a/library/src/visualize/image.rs b/library/src/visualize/image.rs index 330f1d04d..3a6eb3b08 100644 --- a/library/src/visualize/image.rs +++ b/library/src/visualize/image.rs @@ -32,9 +32,13 @@ use crate::prelude::*; /// ## Category /// visualize #[func] -#[capable(Layout, Inline)] +#[capable(Layout)] #[derive(Debug, Hash)] -pub struct ImageNode(pub Image); +pub struct ImageNode { + pub image: Image, + pub width: Smart>, + pub height: Smart>, +} #[node] impl ImageNode { @@ -57,10 +61,9 @@ impl ImageNode { }; let image = Image::new(buffer, format).at(span)?; - let width = args.named("width")?; - let height = args.named("height")?; - - Ok(ImageNode(image).pack().boxed(Axes::new(width, height))) + let width = args.named("width")?.unwrap_or_default(); + let height = args.named("height")?.unwrap_or_default(); + Ok(ImageNode { image, width, height }.pack()) } } @@ -71,22 +74,28 @@ impl Layout for ImageNode { styles: StyleChain, regions: Regions, ) -> SourceResult { - let pxw = self.0.width() as f64; - let pxh = self.0.height() as f64; - let px_ratio = pxw / pxh; + let sizing = Axes::new(self.width, self.height); + let region = sizing + .zip(regions.base()) + .map(|(s, r)| s.map(|v| v.resolve(styles).relative_to(r))) + .unwrap_or(regions.base()); + + let expand = sizing.as_ref().map(Smart::is_custom) | regions.expand; + let region_ratio = region.x / region.y; // Find out whether the image is wider or taller than the target size. - let Regions { size: first, expand, .. } = regions; - let region_ratio = first.x / first.y; + let pxw = self.image.width() as f64; + let pxh = self.image.height() as f64; + let px_ratio = pxw / pxh; let wide = px_ratio > region_ratio; // The space into which the image will be placed according to its fit. let target = if expand.x && expand.y { - first - } else if expand.x || (!expand.y && wide && first.x.is_finite()) { - Size::new(first.x, first.y.min(first.x.safe_div(px_ratio))) - } else if first.y.is_finite() { - Size::new(first.x.min(first.y * px_ratio), first.y) + region + } else if expand.x || (!expand.y && wide && region.x.is_finite()) { + Size::new(region.x, region.y.min(region.x.safe_div(px_ratio))) + } else if region.y.is_finite() { + Size::new(region.x.min(region.y * px_ratio), region.y) } else { Size::new(Abs::pt(pxw), Abs::pt(pxh)) }; @@ -108,7 +117,7 @@ impl Layout for ImageNode { // the frame to the target size, center aligning the image in the // process. let mut frame = Frame::new(fitted); - frame.push(Point::zero(), Element::Image(self.0.clone(), fitted)); + frame.push(Point::zero(), Element::Image(self.image.clone(), fitted)); frame.resize(target, Align::CENTER_HORIZON); // Create a clipping group if only part of the image should be visible. @@ -123,8 +132,6 @@ impl Layout for ImageNode { } } -impl Inline for ImageNode {} - /// How an image should adjust itself to a given area. #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] pub enum ImageFit { diff --git a/library/src/visualize/line.rs b/library/src/visualize/line.rs index 28910a262..890373ee6 100644 --- a/library/src/visualize/line.rs +++ b/library/src/visualize/line.rs @@ -28,7 +28,7 @@ use crate::prelude::*; /// ## Category /// visualize #[func] -#[capable(Layout, Inline)] +#[capable(Layout)] #[derive(Debug, Hash)] pub struct LineNode { /// Where the line starts. @@ -61,7 +61,7 @@ impl LineNode { Some(end) => end.zip(start).map(|(to, from)| to - from), None => { let length = - args.named::>("length")?.unwrap_or(Abs::cm(1.0).into()); + args.named::>("length")?.unwrap_or(Abs::pt(30.0).into()); let angle = args.named::("angle")?.unwrap_or_default(); let x = angle.cos() * length; @@ -106,5 +106,3 @@ impl Layout for LineNode { Ok(Fragment::frame(frame)) } } - -impl Inline for LineNode {} diff --git a/library/src/visualize/shape.rs b/library/src/visualize/shape.rs index 6f70b6c14..81309f935 100644 --- a/library/src/visualize/shape.rs +++ b/library/src/visualize/shape.rs @@ -33,9 +33,13 @@ use crate::prelude::*; /// ## Category /// visualize #[func] -#[capable(Layout, Inline)] +#[capable(Layout)] #[derive(Debug, Hash)] -pub struct RectNode(pub Option); +pub struct RectNode { + pub body: Option, + pub width: Smart>, + pub height: Smart>, +} #[node] impl RectNode { @@ -155,14 +159,15 @@ impl RectNode { pub const OUTSET: Sides>> = Sides::splat(Rel::zero()); fn construct(_: &Vm, args: &mut Args) -> SourceResult { - let width = args.named("width")?; - let height = args.named("height")?; - Ok(Self(args.eat()?).pack().boxed(Axes::new(width, height))) + let width = args.named("width")?.unwrap_or_default(); + let height = args.named("height")?.unwrap_or_default(); + let body = args.eat()?; + Ok(Self { body, width, height }.pack()) } fn field(&self, name: &str) -> Option { match name { - "body" => match &self.0 { + "body" => match &self.body { Some(body) => Some(Value::Content(body.clone())), None => Some(Value::None), }, @@ -181,7 +186,8 @@ impl Layout for RectNode { layout( vt, ShapeKind::Rect, - &self.0, + &self.body, + Axes::new(self.width, self.height), styles.get(Self::FILL), styles.get(Self::STROKE), styles.get(Self::INSET), @@ -193,8 +199,6 @@ impl Layout for RectNode { } } -impl Inline for RectNode {} - /// # Square /// A square with optional content. /// @@ -237,9 +241,13 @@ impl Inline for RectNode {} /// ## Category /// visualize #[func] -#[capable(Layout, Inline)] +#[capable(Layout)] #[derive(Debug, Hash)] -pub struct SquareNode(pub Option); +pub struct SquareNode { + pub body: Option, + pub width: Smart>, + pub height: Smart>, +} #[node] impl SquareNode { @@ -270,22 +278,24 @@ impl SquareNode { pub const OUTSET: Sides>> = Sides::splat(Rel::zero()); fn construct(_: &Vm, args: &mut Args) -> SourceResult { - let size = args.named::("size")?.map(Rel::from); + let size = args.named::>("size")?.map(|s| s.map(Rel::from)); let width = match size { None => args.named("width")?, size => size, - }; - + } + .unwrap_or_default(); let height = match size { None => args.named("height")?, size => size, - }; - Ok(Self(args.eat()?).pack().boxed(Axes::new(width, height))) + } + .unwrap_or_default(); + let body = args.eat()?; + Ok(Self { body, width, height }.pack()) } fn field(&self, name: &str) -> Option { match name { - "body" => match &self.0 { + "body" => match &self.body { Some(body) => Some(Value::Content(body.clone())), None => Some(Value::None), }, @@ -304,7 +314,8 @@ impl Layout for SquareNode { layout( vt, ShapeKind::Square, - &self.0, + &self.body, + Axes::new(self.width, self.height), styles.get(Self::FILL), styles.get(Self::STROKE), styles.get(Self::INSET), @@ -316,8 +327,6 @@ impl Layout for SquareNode { } } -impl Inline for SquareNode {} - /// # Ellipse /// An ellipse with optional content. /// @@ -350,9 +359,13 @@ impl Inline for SquareNode {} /// ## Category /// visualize #[func] -#[capable(Layout, Inline)] +#[capable(Layout)] #[derive(Debug, Hash)] -pub struct EllipseNode(pub Option); +pub struct EllipseNode { + pub body: Option, + pub width: Smart>, + pub height: Smart>, +} #[node] impl EllipseNode { @@ -378,14 +391,15 @@ impl EllipseNode { pub const OUTSET: Sides>> = Sides::splat(Rel::zero()); fn construct(_: &Vm, args: &mut Args) -> SourceResult { - let width = args.named("width")?; - let height = args.named("height")?; - Ok(Self(args.eat()?).pack().boxed(Axes::new(width, height))) + let width = args.named("width")?.unwrap_or_default(); + let height = args.named("height")?.unwrap_or_default(); + let body = args.eat()?; + Ok(Self { body, width, height }.pack()) } fn field(&self, name: &str) -> Option { match name { - "body" => match &self.0 { + "body" => match &self.body { Some(body) => Some(Value::Content(body.clone())), None => Some(Value::None), }, @@ -404,7 +418,8 @@ impl Layout for EllipseNode { layout( vt, ShapeKind::Ellipse, - &self.0, + &self.body, + Axes::new(self.width, self.height), styles.get(Self::FILL), styles.get(Self::STROKE).map(Sides::splat), styles.get(Self::INSET), @@ -416,8 +431,6 @@ impl Layout for EllipseNode { } } -impl Inline for EllipseNode {} - /// # Circle /// A circle with optional content. /// @@ -458,9 +471,13 @@ impl Inline for EllipseNode {} /// ## Category /// visualize #[func] -#[capable(Layout, Inline)] +#[capable(Layout)] #[derive(Debug, Hash)] -pub struct CircleNode(pub Option); +pub struct CircleNode { + pub body: Option, + pub width: Smart>, + pub height: Smart>, +} #[node] impl CircleNode { @@ -486,22 +503,26 @@ impl CircleNode { pub const OUTSET: Sides>> = Sides::splat(Rel::zero()); fn construct(_: &Vm, args: &mut Args) -> SourceResult { - let size = args.named::("radius")?.map(|r| 2.0 * Rel::from(r)); + let size = args + .named::>("radius")? + .map(|s| s.map(|r| 2.0 * Rel::from(r))); let width = match size { None => args.named("width")?, size => size, - }; - + } + .unwrap_or_default(); let height = match size { None => args.named("height")?, size => size, - }; - Ok(Self(args.eat()?).pack().boxed(Axes::new(width, height))) + } + .unwrap_or_default(); + let body = args.eat()?; + Ok(Self { body, width, height }.pack()) } fn field(&self, name: &str) -> Option { match name { - "body" => match &self.0 { + "body" => match &self.body { Some(body) => Some(Value::Content(body.clone())), None => Some(Value::None), }, @@ -520,7 +541,8 @@ impl Layout for CircleNode { layout( vt, ShapeKind::Circle, - &self.0, + &self.body, + Axes::new(self.width, self.height), styles.get(Self::FILL), styles.get(Self::STROKE).map(Sides::splat), styles.get(Self::INSET), @@ -532,13 +554,12 @@ impl Layout for CircleNode { } } -impl Inline for CircleNode {} - /// Layout a shape. fn layout( vt: &mut Vt, kind: ShapeKind, body: &Option, + sizing: Axes>>, fill: Option, stroke: Smart>>>, mut inset: Sides>, @@ -547,29 +568,28 @@ fn layout( styles: StyleChain, regions: Regions, ) -> SourceResult { + let resolved = sizing + .zip(regions.base()) + .map(|(s, r)| s.map(|v| v.resolve(styles).relative_to(r))); + let mut frame; if let Some(child) = body { + let region = resolved.unwrap_or(regions.base()); + if kind.is_round() { inset = inset.map(|side| side + Ratio::new(0.5 - SQRT_2 / 4.0)); } // Pad the child. let child = child.clone().padded(inset.map(|side| side.map(Length::from))); - let pod = Regions::one(regions.size, regions.expand); + let expand = sizing.as_ref().map(Smart::is_custom); + let pod = Regions::one(region, expand); frame = child.layout(vt, styles, pod)?.into_frame(); // Relayout with full expansion into square region to make sure // the result is really a square or circle. if kind.is_quadratic() { - let length = if regions.expand.x || regions.expand.y { - let target = regions.expand.select(regions.size, Size::zero()); - target.x.max(target.y) - } else { - let size = frame.size(); - let desired = size.x.max(size.y); - desired.min(regions.size.x).min(regions.size.y) - }; - + let length = frame.size().max_by_side().min(region.min_by_side()); let size = Size::splat(length); let pod = Regions::one(size, Axes::splat(true)); frame = child.layout(vt, styles, pod)?.into_frame(); @@ -577,20 +597,11 @@ fn layout( } else { // The default size that a shape takes on if it has no child and // enough space. - let mut size = Size::new(Abs::pt(45.0), Abs::pt(30.0)).min(regions.size); - + let default = Size::new(Abs::pt(45.0), Abs::pt(30.0)); + let mut size = resolved.unwrap_or(default.min(regions.base())); if kind.is_quadratic() { - let length = if regions.expand.x || regions.expand.y { - let target = regions.expand.select(regions.size, Size::zero()); - target.x.max(target.y) - } else { - size.x.min(size.y) - }; - size = Size::splat(length); - } else { - size = regions.expand.select(regions.size, size); + size = Size::splat(size.min_by_side()); } - frame = Frame::new(size); } diff --git a/src/doc.rs b/src/doc.rs index 988520c5e..47bdb23d0 100644 --- a/src/doc.rs +++ b/src/doc.rs @@ -267,6 +267,10 @@ impl Frame { /// Attach the metadata from this style chain to the frame. pub fn meta(&mut self, styles: StyleChain) { for meta in styles.get(Meta::DATA) { + if matches!(meta, Meta::Hidden) { + self.clear(); + break; + } self.push(Point::zero(), Element::Meta(meta, self.size)); } } @@ -533,6 +537,8 @@ pub enum Meta { /// An identifiable piece of content that produces something within the /// area this metadata is attached to. Node(StableId, Content), + /// Indicates that the content is hidden. + Hidden, } #[node] diff --git a/src/export/pdf/page.rs b/src/export/pdf/page.rs index ef6c0ccc0..1131f7608 100644 --- a/src/export/pdf/page.rs +++ b/src/export/pdf/page.rs @@ -288,6 +288,7 @@ fn write_frame(ctx: &mut PageContext, frame: &Frame) { Element::Meta(meta, size) => match meta { Meta::Link(dest) => write_link(ctx, pos, dest, *size), Meta::Node(_, _) => {} + Meta::Hidden => {} }, } } diff --git a/src/export/render.rs b/src/export/render.rs index b018608cb..fcf7458a5 100644 --- a/src/export/render.rs +++ b/src/export/render.rs @@ -61,6 +61,7 @@ fn render_frame( Element::Meta(meta, _) => match meta { Meta::Link(_) => {} Meta::Node(_, _) => {} + Meta::Hidden => {} }, } } diff --git a/src/geom/axes.rs b/src/geom/axes.rs index 040238988..48f8c0e88 100644 --- a/src/geom/axes.rs +++ b/src/geom/axes.rs @@ -104,6 +104,16 @@ impl Axes { pub fn max(self, other: Self) -> Self { Self { x: self.x.max(other.x), y: self.y.max(other.y) } } + + /// The minimum of width and height. + pub fn min_by_side(self) -> T { + self.x.min(self.y) + } + + /// The minimum of width and height. + pub fn max_by_side(self) -> T { + self.x.max(self.y) + } } impl Get for Axes { @@ -189,6 +199,16 @@ impl Axes> { } } +impl Axes> { + /// Unwrap the individual fields. + pub fn unwrap_or(self, other: Axes) -> Axes { + Axes { + x: self.x.unwrap_or(other.x), + y: self.y.unwrap_or(other.y), + } + } +} + impl Axes { /// Select `t.x` if `self.x` is true and `f.x` otherwise and same for `y`. pub fn select(self, t: Axes, f: Axes) -> Axes { diff --git a/src/geom/point.rs b/src/geom/point.rs index 34d3dcd8e..ce3a6ff2f 100644 --- a/src/geom/point.rs +++ b/src/geom/point.rs @@ -35,6 +35,16 @@ impl Point { Self { x: Abs::zero(), y } } + /// The component-wise minimum of this and another point. + pub fn min(self, other: Self) -> Self { + Self { x: self.x.min(other.x), y: self.y.min(other.y) } + } + + /// The component-wise minimum of this and another point. + pub fn max(self, other: Self) -> Self { + Self { x: self.x.max(other.x), y: self.y.max(other.y) } + } + /// Transform the point with the given transformation. pub fn transform(self, ts: Transform) -> Self { Self::new( @@ -42,6 +52,11 @@ impl Point { ts.ky.of(self.x) + ts.sy.of(self.y) + ts.ty, ) } + + /// Convert to a size. + pub fn to_size(self) -> Size { + Size::new(self.x, self.y) + } } impl Numeric for Point { diff --git a/src/geom/smart.rs b/src/geom/smart.rs index d20bcdfee..e115e99da 100644 --- a/src/geom/smart.rs +++ b/src/geom/smart.rs @@ -10,6 +10,16 @@ pub enum Smart { } impl Smart { + /// Whether the value is `Auto`. + pub fn is_auto(&self) -> bool { + matches!(self, Self::Auto) + } + + /// Whether this holds a custom value. + pub fn is_custom(&self) -> bool { + matches!(self, Self::Custom(_)) + } + /// Map the contained custom value with `f`. pub fn map(self, f: F) -> Smart where diff --git a/tests/ref/compiler/color.png b/tests/ref/compiler/color.png index 9b65c16d3..8f329fab4 100644 Binary files a/tests/ref/compiler/color.png and b/tests/ref/compiler/color.png differ diff --git a/tests/ref/compiler/import.png b/tests/ref/compiler/import.png index 898800862..5fbd6e899 100644 Binary files a/tests/ref/compiler/import.png and b/tests/ref/compiler/import.png differ diff --git a/tests/ref/compiler/show-text.png b/tests/ref/compiler/show-text.png index d0ed2f927..fc76f1329 100644 Binary files a/tests/ref/compiler/show-text.png and b/tests/ref/compiler/show-text.png differ diff --git a/tests/ref/compute/construct.png b/tests/ref/compute/construct.png index 6e637f342..66ccd3ba8 100644 Binary files a/tests/ref/compute/construct.png and b/tests/ref/compute/construct.png differ diff --git a/tests/ref/text/edge.png b/tests/ref/text/edge.png index 817e33005..0ae2ec12d 100644 Binary files a/tests/ref/text/edge.png and b/tests/ref/text/edge.png differ diff --git a/tests/ref/text/em.png b/tests/ref/text/em.png index c0afa6fb5..6440e6291 100644 Binary files a/tests/ref/text/em.png and b/tests/ref/text/em.png differ diff --git a/tests/ref/visualize/image.png b/tests/ref/visualize/image.png index a89f1963b..eaea34999 100644 Binary files a/tests/ref/visualize/image.png and b/tests/ref/visualize/image.png differ diff --git a/tests/ref/visualize/shape-aspect.png b/tests/ref/visualize/shape-aspect.png index 46cb12ade..331c5fe5c 100644 Binary files a/tests/ref/visualize/shape-aspect.png and b/tests/ref/visualize/shape-aspect.png differ diff --git a/tests/ref/visualize/shape-circle.png b/tests/ref/visualize/shape-circle.png index acb1d02a9..27aaf8194 100644 Binary files a/tests/ref/visualize/shape-circle.png and b/tests/ref/visualize/shape-circle.png differ diff --git a/tests/ref/visualize/shape-ellipse.png b/tests/ref/visualize/shape-ellipse.png index 50467dce6..da9278d5b 100644 Binary files a/tests/ref/visualize/shape-ellipse.png and b/tests/ref/visualize/shape-ellipse.png differ diff --git a/tests/ref/visualize/shape-rect.png b/tests/ref/visualize/shape-rect.png index 5eeab37f0..9586d0057 100644 Binary files a/tests/ref/visualize/shape-rect.png and b/tests/ref/visualize/shape-rect.png differ diff --git a/tests/ref/visualize/shape-rounded.png b/tests/ref/visualize/shape-rounded.png index ae8df178c..5e761a4d8 100644 Binary files a/tests/ref/visualize/shape-rounded.png and b/tests/ref/visualize/shape-rounded.png differ diff --git a/tests/ref/visualize/shape-square.png b/tests/ref/visualize/shape-square.png index e8433a568..d710b84c4 100644 Binary files a/tests/ref/visualize/shape-square.png and b/tests/ref/visualize/shape-square.png differ diff --git a/tests/typ/compiler/color.typ b/tests/typ/compiler/color.typ index 3b165d14e..fbb1749ba 100644 --- a/tests/typ/compiler/color.typ +++ b/tests/typ/compiler/color.typ @@ -1,22 +1,26 @@ // Test color modification methods. +--- +// Test CMYK color conversion. +#let c = cmyk(50%, 64%, 16%, 17%) +#stack( + dir: ltr, + spacing: 1fr, + rect(width: 1cm, fill: cmyk(69%, 11%, 69%, 41%)), + rect(width: 1cm, fill: c), + rect(width: 1cm, fill: c.negate()), +) + +#for x in range(0, 11) { + box(square(size: 9pt, fill: c.lighten(x * 10%))) +} +#for x in range(0, 11) { + box(square(size: 9pt, fill: c.darken(x * 10%))) +} + --- // Test gray color modification. +// Ref: false #test(luma(20%).lighten(50%), luma(60%)) #test(luma(80%).darken(20%), luma(63.9%)) #test(luma(80%).negate(), luma(20%)) - ---- -// Test CMYK color conversion. -// Ref: true -#let c = cmyk(50%, 64%, 16%, 17%) -#rect(width: 1cm, fill: cmyk(69%, 11%, 69%, 41%)) -#rect(width: 1cm, fill: c) -#rect(width: 1cm, fill: c.negate()) - -#for x in range(0, 11) { - square(size: 9pt, fill: c.lighten(x * 10%)) -} -#for x in range(0, 11) { - square(size: 9pt, fill: c.darken(x * 10%)) -} diff --git a/tests/typ/compiler/construct.typ b/tests/typ/compiler/construct.typ index 161827cb4..53fcfefb4 100644 --- a/tests/typ/compiler/construct.typ +++ b/tests/typ/compiler/construct.typ @@ -22,7 +22,7 @@ --- // The inner rectangle should not be yellow here. -A #rect(fill: yellow, inset: 5pt, rect()) B +A #box(rect(fill: yellow, inset: 5pt, rect())) B --- // The constructor property should still work diff --git a/tests/typ/compiler/show-node.typ b/tests/typ/compiler/show-node.typ index 4aba4e9be..f6298a285 100644 --- a/tests/typ/compiler/show-node.typ +++ b/tests/typ/compiler/show-node.typ @@ -28,7 +28,7 @@ my heading? // Test integrated example. #show heading: it => block({ set text(10pt) - move(dy: -1pt)[📖] + box(move(dy: -1pt)[📖]) h(5pt) if it.level == 1 { underline(text(1.25em, blue, it.title)) diff --git a/tests/typ/compiler/show-selector.typ b/tests/typ/compiler/show-selector.typ index 56e827696..ebd84837d 100644 --- a/tests/typ/compiler/show-selector.typ +++ b/tests/typ/compiler/show-selector.typ @@ -2,12 +2,13 @@ --- // Inline code. -#show raw.where(block: false): rect.with( +#show raw.where(block: false): it => box(rect( radius: 2pt, outset: (y: 3pt), inset: (x: 3pt, y: 0pt), fill: luma(230), -) + it, +)) // Code blocks. #show raw.where(block: true): rect.with( diff --git a/tests/typ/compiler/show-text.typ b/tests/typ/compiler/show-text.typ index c867ff9f9..e0fdb7930 100644 --- a/tests/typ/compiler/show-text.typ +++ b/tests/typ/compiler/show-text.typ @@ -8,7 +8,7 @@ Die Zeitung Der Spiegel existiert. --- // Another classic example. -#show "TeX": [T#h(-0.145em)#move(dy: 0.233em)[E]#h(-0.135em)X] +#show "TeX": [T#h(-0.145em)#box(move(dy: 0.233em)[E])#h(-0.135em)X] #show regex("(Lua)?(La)?TeX"): name => box(text("Latin Modern Roman")[#name]) TeX, LaTeX, LuaTeX and LuaLaTeX! @@ -28,7 +28,7 @@ Treeworld, the World of worlds, is a world. --- // This is a fun one. #set par(justify: true) -#show regex("\S"): letter => rect(inset: 2pt)[#upper(letter)] +#show regex("\S"): letter => box(rect(inset: 2pt, upper(letter))) #lorem(5) --- diff --git a/tests/typ/compute/construct.typ b/tests/typ/compute/construct.typ index 50fa4e3e1..80fa9a2b2 100644 --- a/tests/typ/compute/construct.typ +++ b/tests/typ/compute/construct.typ @@ -17,8 +17,7 @@ --- // Test gray color conversion. // Ref: true -#rect(fill: luma(0)) -#rect(fill: luma(80%)) +#stack(dir: ltr, rect(fill: luma(0)), rect(fill: luma(80%))) --- // Error for values that are out of range. diff --git a/tests/typ/layout/columns.typ b/tests/typ/layout/columns.typ index 8702688c9..1d82113c3 100644 --- a/tests/typ/layout/columns.typ +++ b/tests/typ/layout/columns.typ @@ -6,10 +6,10 @@ #set text(lang: "ar", "Noto Sans Arabic", "IBM Plex Serif") #set columns(gutter: 30pt) -#rect(fill: conifer, height: 8pt, width: 6pt) وتحفيز +#box(rect(fill: conifer, height: 8pt, width: 6pt)) وتحفيز العديد من التفاعلات الكيميائية. (DNA) من أهم الأحماض النووية التي تُشكِّل إلى جانب كل من البروتينات والليبيدات والسكريات المتعددة -#rect(fill: eastern, height: 8pt, width: 6pt) +#box(rect(fill: eastern, height: 8pt, width: 6pt)) الجزيئات الضخمة الأربعة الضرورية للحياة. --- diff --git a/tests/typ/layout/par-bidi.typ b/tests/typ/layout/par-bidi.typ index 31e3fded2..a7274e8a3 100644 --- a/tests/typ/layout/par-bidi.typ +++ b/tests/typ/layout/par-bidi.typ @@ -43,7 +43,7 @@ Lריווח #h(1cm) R --- // Test inline object. #set text(lang: "he", "IBM Plex Serif") -קרנפיםRh#image("/rhino.png", height: 11pt)inoחיים +קרנפיםRh#box(image("/rhino.png", height: 11pt))inoחיים --- // Test whether L1 whitespace resetting destroys stuff. diff --git a/tests/typ/layout/par-indent.typ b/tests/typ/layout/par-indent.typ index d328da410..3e44d73b7 100644 --- a/tests/typ/layout/par-indent.typ +++ b/tests/typ/layout/par-indent.typ @@ -9,7 +9,7 @@ The first paragraph has no indent. But the second one does. -#image("/tiger.jpg", height: 6pt) +#box(image("/tiger.jpg", height: 6pt)) starts a paragraph without indent. #align(center, image("/rhino.png", width: 1cm)) diff --git a/tests/typ/layout/transform.typ b/tests/typ/layout/transform.typ index cc7494b3a..cc7449523 100644 --- a/tests/typ/layout/transform.typ +++ b/tests/typ/layout/transform.typ @@ -6,7 +6,7 @@ #let tex = { [T] h(-0.14 * size) - move(dy: 0.22 * size)[E] + box(move(dy: 0.22 * size)[E]) h(-0.12 * size) [X] } @@ -14,11 +14,11 @@ #let xetex = { [X] h(-0.14 * size) - scale(x: -100%, move(dy: 0.26 * size)[E]) + box(scale(x: -100%, move(dy: 0.26 * size)[E])) h(-0.14 * size) [T] h(-0.14 * size) - move(dy: 0.26 * size)[E] + box(move(dy: 0.26 * size)[E]) h(-0.12 * size) [X] } @@ -44,6 +44,6 @@ nor #xetex! // Test setting scaling origin. #let r = rect(width: 100pt, height: 10pt, fill: forest) #set page(height: 65pt) -#scale(r, x: 50%, y: 200%, origin: left + top) -#scale(r, x: 50%, origin: center) -#scale(r, x: 50%, y: 200%, origin: right + bottom) +#box(scale(r, x: 50%, y: 200%, origin: left + top)) +#box(scale(r, x: 50%, origin: center)) +#box(scale(r, x: 50%, y: 200%, origin: right + bottom)) diff --git a/tests/typ/meta/link.typ b/tests/typ/meta/link.typ index 4ed7e58dc..3ceb261d9 100644 --- a/tests/typ/meta/link.typ +++ b/tests/typ/meta/link.typ @@ -32,13 +32,13 @@ You could also make the // Transformed link. #set page(height: 60pt) #let mylink = link("https://typst.org/")[LINK] -My cool #move(dx: 0.7cm, dy: 0.7cm, rotate(10deg, scale(200%, mylink))) +My cool #box(move(dx: 0.7cm, dy: 0.7cm, rotate(10deg, scale(200%, mylink)))) --- // Link containing a block. #link("https://example.com/", block[ My cool rhino - #move(dx: 10pt, image("/rhino.png", width: 1cm)) + #box(move(dx: 10pt, image("/rhino.png", width: 1cm))) ]) --- diff --git a/tests/typ/text/baseline.typ b/tests/typ/text/baseline.typ index cd331c777..57963195d 100644 --- a/tests/typ/text/baseline.typ +++ b/tests/typ/text/baseline.typ @@ -4,6 +4,6 @@ Hi #text(1.5em)[You], #text(0.75em)[how are you?] Our cockatoo was one of the -#text(baseline: -0.2em)[#circle(radius: 2pt) first] -#text(baseline: 0.2em)[birds #circle(radius: 2pt)] +#text(baseline: -0.2em)[#box(circle(radius: 2pt)) first] +#text(baseline: 0.2em)[birds #box(circle(radius: 2pt))] that ever learned to mimic a human voice. diff --git a/tests/typ/text/em.typ b/tests/typ/text/em.typ index f901aae4b..bf191c1fd 100644 --- a/tests/typ/text/em.typ +++ b/tests/typ/text/em.typ @@ -30,5 +30,4 @@ G // 5pt size - 3pt } -#square(size: size) -#square(size: 25pt) +#stack(dir: ltr, spacing: 1fr, square(size: size), square(size: 25pt)) diff --git a/tests/typ/text/shift.typ b/tests/typ/text/shift.typ index 6fe31bec0..2b1b89845 100644 --- a/tests/typ/text/shift.typ +++ b/tests/typ/text/shift.typ @@ -4,8 +4,8 @@ #table( columns: 3, [Typo.], [Fallb.], [Synth], - [x#super[1]], [x#super[5n]], [x#super[2 #square(size: 6pt)]], - [x#sub[1]], [x#sub[5n]], [x#sub[2 #square(size: 6pt)]], + [x#super[1]], [x#super[5n]], [x#super[2 #box(square(size: 6pt))]], + [x#sub[1]], [x#sub[5n]], [x#sub[2 #box(square(size: 6pt))]], ) --- diff --git a/tests/typ/visualize/image.typ b/tests/typ/visualize/image.typ index 893819555..4b3d390f1 100644 --- a/tests/typ/visualize/image.typ +++ b/tests/typ/visualize/image.typ @@ -14,8 +14,8 @@ // Test configuring the size and fitting behaviour of images. // Set width and height explicitly. -#image("/rhino.png", width: 30pt) -#image("/rhino.png", height: 30pt) +#box(image("/rhino.png", width: 30pt)) +#box(image("/rhino.png", height: 30pt)) // Set width and height explicitly and force stretching. #image("/monkey.svg", width: 100%, height: 20pt, fit: "stretch") @@ -38,13 +38,12 @@ --- // Does not fit to remaining height of page. #set page(height: 60pt) -Stuff #parbreak() Stuff #image("/rhino.png") --- // Test baseline. -A #image("/tiger.jpg", height: 1cm, width: 80%) B +A #box(image("/tiger.jpg", height: 1cm, width: 80%)) B --- // Test advanced SVG features. diff --git a/tests/typ/visualize/line.typ b/tests/typ/visualize/line.typ index a7bca6135..8c4059322 100644 --- a/tests/typ/visualize/line.typ +++ b/tests/typ/visualize/line.typ @@ -7,8 +7,7 @@ place(line(end: (0.4em, 0pt))) place(line(start: (0pt, 0.4em), end: (0pt, 0pt))) line(end: (0.6em, 0.6em)) -}) -Hello #line()! +}) Hello #box(line(length: 1cm))! #line(end: (70%, 50%)) diff --git a/tests/typ/visualize/shape-aspect.typ b/tests/typ/visualize/shape-aspect.typ index d2dc11404..d36068088 100644 --- a/tests/typ/visualize/shape-aspect.typ +++ b/tests/typ/visualize/shape-aspect.typ @@ -4,26 +4,35 @@ // Test relative width and height and size that is smaller // than default size. #set page(width: 120pt, height: 70pt) -#set align(center + horizon) -#square(width: 50%, [A]) -#square(height: 50%) -#box(stack( - square(size: 10pt), - square(size: 20pt, [B]) -)) +#set align(bottom) +#let centered = align.with(center + horizon) +#stack( + dir: ltr, + spacing: 1fr, + square(width: 50%, centered[A]), + square(height: 50%), + stack( + square(size: 10pt), + square(size: 20pt, centered[B]) + ), +) --- // Test alignment in automatically sized square and circle. #set text(8pt) -#square(inset: 4pt)[ +#box(square(inset: 4pt)[ Hey there, #align(center + bottom, rotate(180deg, [you!])) -] -#circle(align(center + horizon, [Hey.])) +]) +#box(circle(align(center + horizon, [Hey.]))) --- -// Test that maximum wins if both width and height are given. -#square(width: 10pt, height: 20pt) -#circle(width: 20%, height: 10pt) +// Test that minimum wins if both width and height are given. +#stack( + dir: ltr, + spacing: 2pt, + square(width: 20pt, height: 40pt), + circle(width: 20%, height: 100pt), +) --- // Test square that is limited by region size. @@ -33,18 +42,22 @@ --- // Test different ways of sizing. #set page(width: 120pt, height: 40pt) -#circle(radius: 5pt) -#circle(width: 10%) -#circle(height: 50%) +#stack( + dir: ltr, + spacing: 2pt, + circle(radius: 5pt), + circle(width: 10%), + circle(height: 50%), +) --- -// Test square that is overflowing due to its aspect ratio. -#set page(width: 40pt, height: 20pt, margin: 5pt) -#square(width: 100%) #parbreak() -#square(width: 100%)[Hey] +// Test that square doesn't overflow due to its aspect ratio. +#set page(width: 40pt, height: 25pt, margin: 5pt) +#square(width: 100%) +#square(width: 100%)[Hello there] --- // Size cannot be relative because we wouldn't know // relative to which axis. -// Error: 15-18 expected length, found ratio +// Error: 15-18 expected length or auto, found ratio #square(size: 50%) diff --git a/tests/typ/visualize/shape-circle.typ b/tests/typ/visualize/shape-circle.typ index 23c6fcbdb..94facdeb1 100644 --- a/tests/typ/visualize/shape-circle.typ +++ b/tests/typ/visualize/shape-circle.typ @@ -2,14 +2,14 @@ --- // Default circle. -#circle() -#circle[Hey] +#box(circle()) +#box(circle[Hey]) --- // Test auto sizing. #set circle(inset: 0pt) -Auto-sized circle. \ +Auto-sized circle. #circle(fill: rgb("eb5278"), stroke: 2pt + black, align(center + horizon)[But, soft!] ) @@ -21,7 +21,7 @@ Center-aligned rect in auto-sized circle. ) ) -Rect in auto-sized circle. \ +Rect in auto-sized circle. #circle(fill: forest, rect(fill: conifer, stroke: white, inset: 4pt)[ #set text(8pt) @@ -39,13 +39,18 @@ Expanded by height. --- // Test relative sizing. -#let centered(body) = align(center + horizon, body) #set text(fill: white) -#rect(width: 100pt, height: 50pt, inset: 0pt, fill: rgb("aaa"), centered[ - #circle(radius: 10pt, fill: eastern, centered[A]) // D=20pt - #circle(height: 60%, fill: eastern, centered[B]) // D=30pt - #circle(width: 20% + 20pt, fill: eastern, centered[C]) // D=40pt -]) +#show rect.with(width: 100pt, height: 50pt, inset: 0pt, fill: rgb("aaa")) +#set align(center + horizon) +#stack( + dir: ltr, + spacing: 1fr, + 1fr, + circle(radius: 10pt, fill: eastern, [A]), // D=20pt + circle(height: 60%, fill: eastern, [B]), // D=30pt + circle(width: 20% + 20pt, fill: eastern, [C]), // D=40pt + 1fr, +) --- // Radius wins over width and height. diff --git a/tests/typ/visualize/shape-ellipse.typ b/tests/typ/visualize/shape-ellipse.typ index 6447d1d09..2fd4acd9b 100644 --- a/tests/typ/visualize/shape-ellipse.typ +++ b/tests/typ/visualize/shape-ellipse.typ @@ -8,7 +8,7 @@ #set rect(inset: 0pt) #set ellipse(inset: 0pt) -Rect in ellipse in fixed rect. \ +Rect in ellipse in fixed rect. #rect(width: 3cm, height: 2cm, fill: rgb("2a631a"), ellipse(fill: forest, width: 100%, height: 100%, rect(fill: conifer, width: 100%, height: 100%, @@ -19,11 +19,13 @@ Rect in ellipse in fixed rect. \ ) ) -Auto-sized ellipse. \ +Auto-sized ellipse. #ellipse(fill: conifer, stroke: 3pt + forest, inset: 3pt)[ #set text(8pt) But, soft! what light through yonder window breaks? ] -An inline #ellipse(width: 8pt, height: 6pt, outset: (top: 3pt, rest: 5.5pt)) ellipse. +An inline +#box(ellipse(width: 8pt, height: 6pt, outset: (top: 3pt, rest: 5.5pt))) +ellipse. diff --git a/tests/typ/visualize/shape-fill-stroke.typ b/tests/typ/visualize/shape-fill-stroke.typ index 8820a9fd7..0edbd5516 100644 --- a/tests/typ/visualize/shape-fill-stroke.typ +++ b/tests/typ/visualize/shape-fill-stroke.typ @@ -27,7 +27,7 @@ --- // Test stroke folding. -#let sq = square.with(size: 10pt) +#let sq(..args) = box(square(size: 10pt, ..args)) #set square(stroke: none) #sq() diff --git a/tests/typ/visualize/shape-rect.typ b/tests/typ/visualize/shape-rect.typ index ff80dfb93..a95f2750a 100644 --- a/tests/typ/visualize/shape-rect.typ +++ b/tests/typ/visualize/shape-rect.typ @@ -24,19 +24,23 @@ #rect(height: 1cm, width: 100%, fill: rgb("734ced"))[Topleft] // These are inline with text. -{#rect(width: 0.5in, height: 7pt, fill: rgb("d6cd67")) - #rect(width: 0.5in, height: 7pt, fill: rgb("edd466")) - #rect(width: 0.5in, height: 7pt, fill: rgb("e3be62"))} +{#box(rect(width: 0.5in, height: 7pt, fill: rgb("d6cd67"))) + #box(rect(width: 0.5in, height: 7pt, fill: rgb("edd466"))) + #box(rect(width: 0.5in, height: 7pt, fill: rgb("e3be62")))} // Rounded corners. -#rect(width: 2cm, radius: 60%) -#rect(width: 1cm, radius: (left: 10pt, right: 5pt)) -#rect(width: 1.25cm, radius: ( - top-left: 2pt, - top-right: 5pt, - bottom-right: 8pt, - bottom-left: 11pt -)) +#stack( + dir: ltr, + spacing: 1fr, + rect(width: 2cm, radius: 60%), + rect(width: 1cm, radius: (left: 10pt, right: 5pt)), + rect(width: 1.25cm, radius: ( + top-left: 2pt, + top-right: 5pt, + bottom-right: 8pt, + bottom-left: 11pt + )), +) // Different strokes. #set rect(stroke: (right: red)) diff --git a/tests/typ/visualize/shape-square.typ b/tests/typ/visualize/shape-square.typ index 8ac9001f4..cb6552e48 100644 --- a/tests/typ/visualize/shape-square.typ +++ b/tests/typ/visualize/shape-square.typ @@ -2,8 +2,8 @@ --- // Default square. -#square() -#square[hey!] +#box(square()) +#box(square[hey!]) --- // Test auto-sized square. @@ -15,7 +15,7 @@ --- // Test relative-sized child. #square(fill: eastern)[ - #rect(width: 10pt, height: 5pt, fill: conifer) \ + #rect(width: 10pt, height: 5pt, fill: conifer) #rect(width: 40%, height: 5pt, stroke: conifer) ]