diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ref/arrays.png | bin | 3601 -> 3479 bytes | |||
| -rw-r--r-- | tests/ref/basics.png | bin | 5623 -> 5179 bytes | |||
| -rw-r--r-- | tests/ref/comments.png | bin | 1469 -> 1332 bytes | |||
| -rw-r--r-- | tests/ref/dictionaries.png | bin | 1857 -> 1769 bytes | |||
| -rw-r--r-- | tests/ref/empty.png | bin | 120 -> 94 bytes | |||
| -rw-r--r-- | tests/ref/escaping.png | bin | 4401 -> 4148 bytes | |||
| -rw-r--r-- | tests/ref/func-font.png | bin | 5517 -> 5386 bytes | |||
| -rw-r--r-- | tests/ref/func-hv.png | bin | 4449 -> 3961 bytes | |||
| -rw-r--r-- | tests/ref/func-image.png | bin | 301847 -> 220343 bytes | |||
| -rw-r--r-- | tests/ref/func-page.png | bin | 8858 -> 8099 bytes | |||
| -rw-r--r-- | tests/ref/func-pagebreak.png | bin | 1039 -> 821 bytes | |||
| -rw-r--r-- | tests/ref/func-rgb.png | bin | 2727 -> 2688 bytes | |||
| -rw-r--r-- | tests/ref/headings.png | bin | 8197 -> 7850 bytes | |||
| -rw-r--r-- | tests/typ/func-hv.typ | 10 | ||||
| -rw-r--r-- | tests/typ/func-image.typ | 4 | ||||
| -rw-r--r-- | tests/typ/func-page.typ | 28 | ||||
| -rw-r--r-- | tests/typ/headings.typ | 5 | ||||
| -rw-r--r-- | tests/typeset.rs | 20 |
18 files changed, 40 insertions, 27 deletions
diff --git a/tests/ref/arrays.png b/tests/ref/arrays.png Binary files differindex 8fda7cf6..2d70a3f6 100644 --- a/tests/ref/arrays.png +++ b/tests/ref/arrays.png diff --git a/tests/ref/basics.png b/tests/ref/basics.png Binary files differindex d65b7fe5..fbe85320 100644 --- a/tests/ref/basics.png +++ b/tests/ref/basics.png diff --git a/tests/ref/comments.png b/tests/ref/comments.png Binary files differindex 399d25a1..e3e42d23 100644 --- a/tests/ref/comments.png +++ b/tests/ref/comments.png diff --git a/tests/ref/dictionaries.png b/tests/ref/dictionaries.png Binary files differindex 42cb431d..aa40549e 100644 --- a/tests/ref/dictionaries.png +++ b/tests/ref/dictionaries.png diff --git a/tests/ref/empty.png b/tests/ref/empty.png Binary files differindex 812a3758..87c06b0a 100644 --- a/tests/ref/empty.png +++ b/tests/ref/empty.png diff --git a/tests/ref/escaping.png b/tests/ref/escaping.png Binary files differindex 06c0310d..575a4b2f 100644 --- a/tests/ref/escaping.png +++ b/tests/ref/escaping.png diff --git a/tests/ref/func-font.png b/tests/ref/func-font.png Binary files differindex 18841490..1e025c6f 100644 --- a/tests/ref/func-font.png +++ b/tests/ref/func-font.png diff --git a/tests/ref/func-hv.png b/tests/ref/func-hv.png Binary files differindex 6f47ae09..ee649fb6 100644 --- a/tests/ref/func-hv.png +++ b/tests/ref/func-hv.png diff --git a/tests/ref/func-image.png b/tests/ref/func-image.png Binary files differindex e2b647bf..70f263e6 100644 --- a/tests/ref/func-image.png +++ b/tests/ref/func-image.png diff --git a/tests/ref/func-page.png b/tests/ref/func-page.png Binary files differindex 9bde2dae..fb1b7b39 100644 --- a/tests/ref/func-page.png +++ b/tests/ref/func-page.png diff --git a/tests/ref/func-pagebreak.png b/tests/ref/func-pagebreak.png Binary files differindex 50686ff9..16eae0e4 100644 --- a/tests/ref/func-pagebreak.png +++ b/tests/ref/func-pagebreak.png diff --git a/tests/ref/func-rgb.png b/tests/ref/func-rgb.png Binary files differindex 239a9e5a..3060e42c 100644 --- a/tests/ref/func-rgb.png +++ b/tests/ref/func-rgb.png diff --git a/tests/ref/headings.png b/tests/ref/headings.png Binary files differindex 3deecf8f..1f374cce 100644 --- a/tests/ref/headings.png +++ b/tests/ref/headings.png diff --git a/tests/typ/func-hv.typ b/tests/typ/func-hv.typ index f930bc12..b32a645c 100644 --- a/tests/typ/func-hv.typ +++ b/tests/typ/func-hv.typ @@ -12,13 +12,13 @@ Add [h 10pt] [h 10pt] up // Relative to font size. Relative [h 100%] spacing +// Missing spacing. +// Error: 1:11-1:11 missing argument: spacing +Totally [h] ignored + // Swapped axes. -[page main-dir: rtl, cross-dir: ttb][ +[page main-dir: rtl, cross-dir: ttb, height: 80pt][ 1 [h 1cm] 2 3 [v 1cm] 4 [v -1cm] 5 ] - -// Missing spacing. -// Error: 1:11-1:11 missing argument: spacing -Totally [h] ignored diff --git a/tests/typ/func-image.typ b/tests/typ/func-image.typ index b0ca0357..1f94a66f 100644 --- a/tests/typ/func-image.typ +++ b/tests/typ/func-image.typ @@ -14,7 +14,7 @@ [image "res/rhino.png"] // Fit to height of page. -[page width: 270pt][ +[page height: 40pt][ [image "res/rhino.png"] ] @@ -29,7 +29,7 @@ // Make sure the bounding-box of the image is correct. [align bottom, right][ - [image "res/tiger.jpg"] + [image "res/tiger.jpg", width: 60pt] ] --- diff --git a/tests/typ/func-page.typ b/tests/typ/func-page.typ index 465a3469..49671e14 100644 --- a/tests/typ/func-page.typ +++ b/tests/typ/func-page.typ @@ -1,28 +1,36 @@ // Test configuring page sizes and margins. -// Set width. -[page width: 50pt][High] - -// Set height. -[page height: 50pt][Wide] +// Set width and height. +[page width: 120pt, height: 120pt] +[page width: 40pt][High] +[page height: 40pt][Wide] // Set all margins at once. -[page margins: 40pt][ +[page margins: 30pt][ [align top, left][TL] [align bottom, right][BR] ] // Set individual margins. +[page height: 40pt] [page left: 0pt | align left][Left] [page right: 0pt | align right][Right] [page top: 0pt | align top][Top] [page bottom: 0pt | align bottom][Bottom] // Ensure that specific margins override general margins. -[page margins: 0pt, left: 40pt][Overriden] +[page margins: 0pt, left: 20pt][Overriden] + +--- +// Test flipping. + +// Flipped predefined paper. +[page "a11", flip: true][Flipped A11] -// Flip the page. -[page "a10", flip: true][Flipped] +// Flipped custom page size. +[page width: 40pt, height: 120pt] +[page flip: true] +Wide --- // Test a combination of pages with bodies and normal content. @@ -40,7 +48,7 @@ Sixth --- // Test changing the layouting directions of pages. -[page main-dir: btt, cross-dir: rtl] +[page height: 50pt, main-dir: btt, cross-dir: rtl] Right to left! diff --git a/tests/typ/headings.typ b/tests/typ/headings.typ index de98eddb..0f364a9b 100644 --- a/tests/typ/headings.typ +++ b/tests/typ/headings.typ @@ -8,15 +8,12 @@ ####### Seven --- -// Is a heading. +// Heading vs. no heading. /**/ # Heading {[## Heading]} [box][### Heading] ---- -// Is no heading. - \# No heading Text with # hashtag diff --git a/tests/typeset.rs b/tests/typeset.rs index 499c5c04..f67649b0 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -18,8 +18,8 @@ use typst::env::{Env, ImageResource, ResourceLoader, SharedEnv}; use typst::eval::{Args, EvalContext, State, Value, ValueFunc}; use typst::export::pdf; use typst::font::FontLoader; -use typst::geom::{Length, Point, Sides, Size}; -use typst::layout::{Element, Frame, Image}; +use typst::geom::{Length, Point, Sides, Size, Spec}; +use typst::layout::{Element, Expansion, Frame, Image}; use typst::parse::{LineMap, Scanner}; use typst::shaping::Shaped; use typst::syntax::{Location, Pos, SpanVec, Spanned, WithSpan}; @@ -153,12 +153,12 @@ fn test( let env = env.borrow(); if !frames.is_empty() { - let canvas = draw(&frames, &env, 2.0); - canvas.pixmap.save_png(png_path).unwrap(); - let pdf_data = pdf::export(&frames, &env); fs::write(pdf_path, pdf_data).unwrap(); + let canvas = draw(&frames, &env, 2.0); + canvas.pixmap.save_png(png_path).unwrap(); + if let Some(ref_path) = ref_path { if let Ok(ref_pixmap) = Pixmap::load_png(ref_path) { if canvas.pixmap != ref_pixmap { @@ -184,7 +184,11 @@ fn test_part(i: usize, src: &str, env: &SharedEnv) -> (bool, Vec<Frame>) { let (compare_ref, ref_diags) = parse_metadata(src, &map); let mut state = State::default(); - state.page.size = Size::uniform(Length::pt(120.0)); + + // We want to have "unbounded" pages, so we allow them to be infinitely + // large and fit them to match their content. + state.page.size = Size::new(Length::pt(120.0), Length::raw(f64::INFINITY)); + state.page.expand = Spec::new(Expansion::Fill, Expansion::Fit); state.page.margins = Sides::uniform(Some(Length::pt(10.0).into())); pub fn dump(_: &mut EvalContext, args: &mut Args) -> Value { @@ -283,6 +287,10 @@ fn draw(frames: &[Frame], env: &Env, pixel_per_pt: f32) -> Canvas { let pixel_width = (pixel_per_pt * width.to_pt() as f32) as u32; let pixel_height = (pixel_per_pt * height.to_pt() as f32) as u32; + if pixel_width > 4000 || pixel_height > 4000 { + panic!("overlarge image: {} by {}", pixel_width, pixel_height); + } + let mut canvas = Canvas::new(pixel_width, pixel_height).unwrap(); canvas.scale(pixel_per_pt, pixel_per_pt); canvas.pixmap.fill(Color::BLACK); |
