summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/typst/src/visualize/pattern.rs20
-rw-r--r--tests/typ/visualize/pattern-small.typ5
2 files changed, 16 insertions, 9 deletions
diff --git a/crates/typst/src/visualize/pattern.rs b/crates/typst/src/visualize/pattern.rs
index 01dc8ffa..d4609fbf 100644
--- a/crates/typst/src/visualize/pattern.rs
+++ b/crates/typst/src/visualize/pattern.rs
@@ -134,6 +134,8 @@ impl Pattern {
#[func(constructor)]
pub fn construct(
engine: &mut Engine,
+ /// The callsite span.
+ span: Span,
/// The bounding box of each cell of the pattern.
#[named]
#[default(Spanned::new(Smart::Auto, Span::detached()))]
@@ -154,11 +156,11 @@ impl Pattern {
/// The content of each cell of the pattern.
body: Content,
) -> SourceResult<Pattern> {
- let span = size.span;
+ let size_span = size.span;
if let Smart::Custom(size) = size.v {
// Ensure that sizes are absolute.
if !size.x.em.is_zero() || !size.y.em.is_zero() {
- bail!(span, "pattern tile size must be absolute");
+ bail!(size_span, "pattern tile size must be absolute");
}
// Ensure that sizes are non-zero and finite.
@@ -167,7 +169,7 @@ impl Pattern {
|| !size.x.is_finite()
|| !size.y.is_finite()
{
- bail!(span, "pattern tile size must be non-zero and non-infinite");
+ bail!(size_span, "pattern tile size must be non-zero and non-infinite");
}
}
@@ -192,19 +194,19 @@ impl Pattern {
let pod = Regions::one(region, Axes::splat(false));
let mut frame = body.layout(engine, styles, pod)?.into_frame();
+ // Set the size of the frame if the size is enforced.
+ if let Smart::Custom(size) = size {
+ frame.set_size(size);
+ }
+
// Check that the frame is non-zero.
- if size.is_auto() && frame.size().is_zero() {
+ if frame.width().is_zero() || frame.height().is_zero() {
bail!(
span, "pattern tile size must be non-zero";
hint: "try setting the size manually"
);
}
- // Set the size of the frame if the size is enforced.
- if let Smart::Custom(size) = size {
- frame.set_size(size);
- }
-
Ok(Self(Arc::new(Repr {
size: frame.size(),
frame: Prehashed::new(frame),
diff --git a/tests/typ/visualize/pattern-small.typ b/tests/typ/visualize/pattern-small.typ
index 888cfee1..8a63c374 100644
--- a/tests/typ/visualize/pattern-small.typ
+++ b/tests/typ/visualize/pattern-small.typ
@@ -12,3 +12,8 @@
height: 1pt,
fill: pattern(size: (2pt, 1pt), square(size: 1pt, fill: black))
)
+
+---
+// Error: 22-52 pattern tile size must be non-zero
+// Hint: 22-52 try setting the size manually
+#line(stroke: pattern(path((0pt, 0pt), (1em, 0pt))))