diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-11-29 13:37:25 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-11-29 14:18:13 +0100 |
| commit | 0efe669278a5e1c3f2985eba2f3360e91159c54a (patch) | |
| tree | 502712857c48f0decb5e698257c0a96d358a436e /tests/typ/visualize | |
| parent | 836692e73cff0356e409a9ba5b4887b86809d4ca (diff) | |
Reorganize library and tests
Diffstat (limited to 'tests/typ/visualize')
| -rw-r--r-- | tests/typ/visualize/image.typ | 63 | ||||
| -rw-r--r-- | tests/typ/visualize/line.typ | 52 | ||||
| -rw-r--r-- | tests/typ/visualize/shape-aspect.typ | 46 | ||||
| -rw-r--r-- | tests/typ/visualize/shape-circle.typ | 51 | ||||
| -rw-r--r-- | tests/typ/visualize/shape-ellipse.typ | 26 | ||||
| -rw-r--r-- | tests/typ/visualize/shape-fill-stroke.typ | 50 | ||||
| -rw-r--r-- | tests/typ/visualize/shape-rect.typ | 69 | ||||
| -rw-r--r-- | tests/typ/visualize/shape-square.typ | 39 |
8 files changed, 396 insertions, 0 deletions
diff --git a/tests/typ/visualize/image.typ b/tests/typ/visualize/image.typ new file mode 100644 index 00000000..6a2c37e1 --- /dev/null +++ b/tests/typ/visualize/image.typ @@ -0,0 +1,63 @@ +// Test the `image` function. + +--- +// Test loading different image formats. + +// Load an RGBA PNG image. +#image("/res/rhino.png") + +// Load an RGB JPEG image. +#set page(height: 60pt) +#image("../../res/tiger.jpg") + +--- +// Test configuring the size and fitting behaviour of images. + +// Set width and height explicitly. +#image("/res/rhino.png", width: 30pt) +#image("/res/rhino.png", height: 30pt) + +// Set width and height explicitly and force stretching. +#image("/res/monkey.svg", width: 100%, height: 20pt, fit: "stretch") + +// Make sure the bounding-box of the image is correct. +#align(bottom + right, image("/res/tiger.jpg", width: 40pt)) + +--- +// Test all three fit modes. +#set page(height: 50pt, margin: 0pt) +#grid( + columns: (1fr, 1fr, 1fr), + rows: 100%, + gutter: 3pt, + image("/res/tiger.jpg", width: 100%, height: 100%, fit: "contain"), + image("/res/tiger.jpg", width: 100%, height: 100%, fit: "cover"), + image("/res/monkey.svg", width: 100%, height: 100%, fit: "stretch"), +) + +--- +// Does not fit to remaining height of page. +#set page(height: 60pt) +Stuff #parbreak() +Stuff +#image("/res/rhino.png") + +--- +// Test baseline. +A #image("/res/tiger.jpg", height: 1cm, width: 80%) B + +--- +// Test advanced SVG features. +#image("/res/pattern.svg") + +--- +// Error: 8-29 file not found (searched at typ/visualize/path/does/not/exist) +#image("path/does/not/exist") + +--- +// Error: 8-21 unknown image format +#image("./image.typ") + +--- +// Error: 8-22 failed to parse svg: found closing tag 'g' instead of 'style' in line 4 +#image("/res/bad.svg") diff --git a/tests/typ/visualize/line.typ b/tests/typ/visualize/line.typ new file mode 100644 index 00000000..2cb2fc9c --- /dev/null +++ b/tests/typ/visualize/line.typ @@ -0,0 +1,52 @@ +// Test lines + +--- +// Default line. +#line() + +--- +// Test the to argument. +{ + line(to: (10pt, 0pt)) + line(origin: (0pt, 10pt), to: (0pt, 0pt)) + line(to: (15pt, 15pt)) +} +#v(.5cm) + +--- +// Test the angle argument and positioning. + +#set page(fill: rgb("0B1026")) +#set line(stroke: white) + +#let star(width, ..args) = box(width: width, height: width)[ + #set text(spacing: 0%) + #set line(..args) + #set par(align: left) + #line(length: +30%, origin: (09.0%, 02%)) + #line(length: +30%, origin: (38.7%, 02%), angle: -72deg) + #line(length: +30%, origin: (57.5%, 02%), angle: 252deg) + #line(length: +30%, origin: (57.3%, 02%)) + #line(length: -30%, origin: (88.0%, 02%), angle: -36deg) + #line(length: +30%, origin: (73.3%, 48%), angle: 252deg) + #line(length: -30%, origin: (73.5%, 48%), angle: 36deg) + #line(length: +30%, origin: (25.4%, 48%), angle: -36deg) + #line(length: +30%, origin: (25.6%, 48%), angle: -72deg) + #line(length: +32%, origin: (8.50%, 02%), angle: 34deg) +] + +#align(center, grid( + columns: 3, + column-gutter: 10pt, + ..((star(20pt, stroke: 0.5pt),) * 9) +)) + +--- +// Test errors. + +// Error: 11-18 point array must contain exactly two entries +#line(to: (50pt,)) + +--- +// Error: 15-27 expected relative length, found angle +#line(origin: (3deg, 10pt), length: 5cm) diff --git a/tests/typ/visualize/shape-aspect.typ b/tests/typ/visualize/shape-aspect.typ new file mode 100644 index 00000000..f2dd9b51 --- /dev/null +++ b/tests/typ/visualize/shape-aspect.typ @@ -0,0 +1,46 @@ +// Test that squares and circles respect their 1-1 aspect ratio. + +--- +// Test relative width and height and size that is smaller +// than default size. +#set page(width: 120pt, height: 70pt) +#square(width: 50%, align(bottom)[A]) +#square(height: 50%) +#box(stack(square(size: 10pt), 5pt, square(size: 10pt, [B]))) + +--- +// Test alignment in automatically sized square and circle. +#set text(8pt) +#square(inset: 4pt)[ + Hey there, #align(center + bottom, rotate(180deg, [you!])) +] +#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 square that is limited by region size. +#set page(width: 20pt, height: 10pt, margin: 0pt) +#stack(dir: ltr, square(fill: forest), square(fill: conifer)) + +--- +// Test different ways of sizing. +#set page(width: 120pt, height: 40pt) +#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%)[Hello] + +--- +// Size cannot be relative because we wouldn't know +// relative to which axis. +// Error: 15-18 expected length, found ratio +#square(size: 50%) diff --git a/tests/typ/visualize/shape-circle.typ b/tests/typ/visualize/shape-circle.typ new file mode 100644 index 00000000..13ff67de --- /dev/null +++ b/tests/typ/visualize/shape-circle.typ @@ -0,0 +1,51 @@ +// Test the `circle` function. + +--- +// Default circle. +#circle() +#circle[Hey] + +--- +// Test auto sizing. + +Auto-sized circle. \ +#circle(fill: rgb("eb5278"), stroke: 2pt + black, + align(center + horizon)[But, soft!] +) + +Center-aligned rect in auto-sized circle. +#circle(fill: forest, stroke: conifer, + align(center + horizon, + rect(fill: conifer, inset: 5pt)[But, soft!] + ) +) + +Rect in auto-sized circle. \ +#circle(fill: forest, + rect(fill: conifer, stroke: white, inset: 4pt)[ + #set text(8pt) + But, soft! what light through yonder window breaks? + ] +) + +Expanded by height. +#circle(stroke: black, align(center)[A \ B \ C]) + +--- +// Ensure circle directly in rect works. +#rect(width: 40pt, height: 30pt, fill: forest, circle(fill: conifer)) + +--- +// Test relative sizing. +#let centered(body) = align(center + horizon, body) +#set text(fill: white) +#rect(width: 100pt, height: 50pt, 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 +]) + +--- +// Radius wins over width and height. +// Error: 23-34 unexpected argument +#circle(radius: 10pt, width: 50pt, height: 100pt, fill: eastern) diff --git a/tests/typ/visualize/shape-ellipse.typ b/tests/typ/visualize/shape-ellipse.typ new file mode 100644 index 00000000..ba4d0d0a --- /dev/null +++ b/tests/typ/visualize/shape-ellipse.typ @@ -0,0 +1,26 @@ +// Test the `ellipse` function. + +--- +// Default ellipse. +#ellipse() + +--- +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%, + align(center + horizon)[ + Stuff inside an 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.
\ No newline at end of file diff --git a/tests/typ/visualize/shape-fill-stroke.typ b/tests/typ/visualize/shape-fill-stroke.typ new file mode 100644 index 00000000..d14d0981 --- /dev/null +++ b/tests/typ/visualize/shape-fill-stroke.typ @@ -0,0 +1,50 @@ +// Test shape fill & stroke. + +--- +#let variant = rect.with(width: 20pt, height: 10pt) +#let items = for i, item in ( + variant(stroke: none), + variant(), + variant(fill: none), + variant(stroke: 2pt), + variant(stroke: eastern), + variant(stroke: eastern + 2pt), + variant(fill: eastern), + variant(fill: eastern, stroke: none), + variant(fill: forest, stroke: none), + variant(fill: forest, stroke: conifer), + variant(fill: forest, stroke: black + 2pt), + variant(fill: forest, stroke: conifer + 2pt), +) { + (align(horizon)[{i + 1}.], item, []) +} + +#grid( + columns: (auto, auto, 1fr, auto, auto, 0fr), + gutter: 5pt, + ..items, +) + +--- +// Test stroke folding. +#let sq = square.with(size: 10pt) + +#set square(stroke: none) +#sq() +#set square(stroke: auto) +#sq() +#sq(fill: teal) +#sq(stroke: 2pt) +#sq(stroke: blue) +#sq(fill: teal, stroke: blue) +#sq(fill: teal, stroke: 2pt + blue) + +--- +// Test stroke composition. +#set square(stroke: 4pt) +#set text("Roboto") +#square( + stroke: (left: red, top: yellow, right: green, bottom: blue), + radius: 100%, align(center+horizon)[*G*], + inset: 8pt +) diff --git a/tests/typ/visualize/shape-rect.typ b/tests/typ/visualize/shape-rect.typ new file mode 100644 index 00000000..94686da2 --- /dev/null +++ b/tests/typ/visualize/shape-rect.typ @@ -0,0 +1,69 @@ +// Test the `rect` function. + +--- +// Default rectangle. +#rect() + +--- +#set page(width: 150pt) + +// Fit to text. +#rect(fill: conifer, inset: 3pt)[Textbox] + +// Empty with fixed width and height. +#block(rect( + height: 15pt, + fill: rgb("46b3c2"), + stroke: 2pt + rgb("234994"), +)) + +// Fixed width, text height. +#rect(width: 2cm, fill: rgb("9650d6"), inset: 5pt)[Fixed and padded] + +// Page width, fixed height. +#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"))\} + +// 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 +)) + +// Different strokes. +[ + #set rect(stroke: (right: red)) + #rect(width: 100%, fill: lime, stroke: (x: 5pt, y: 1pt)) +] + +--- +// Outset padding. +#set raw(lang: "rust") +#show raw: it => [ + #set text(8pt) + #h(5.6pt, weak: true) + #rect(radius: 3pt, outset: (y: 3pt, x: 2.5pt), fill: rgb(239, 241, 243), it) + #h(5.6pt, weak: true) +] + +Use the `*const T` pointer or the `&mut T` reference. + +--- +// Error: 15-38 unexpected key "cake" +#rect(radius: (left: 10pt, cake: 5pt)) + +--- +// Error: 15-21 expected stroke or none or dictionary with any of `left`, `top`, `right`, `bottom`, `x`, `y`, or `rest` as keys or auto, found array +#rect(stroke: (1, 2)) + +--- +// Error: 15-19 expected relative length or none or dictionary with any of `top-left`, `top-right`, `bottom-right`, `bottom-left`, `left`, `top`, `right`, `bottom`, or `rest` as keys, found color +#rect(radius: blue) diff --git a/tests/typ/visualize/shape-square.typ b/tests/typ/visualize/shape-square.typ new file mode 100644 index 00000000..622fa9c8 --- /dev/null +++ b/tests/typ/visualize/shape-square.typ @@ -0,0 +1,39 @@ +// Test the `square` function. + +--- +// Default square. +#square() +#square[hey!] + +--- +// Test auto-sized square. +#square(fill: eastern, inset: 5pt)[ + #set text(fill: white, weight: "bold") + Typst +] + +--- +// Test relative-sized child. +#square(fill: eastern)[ + #rect(width: 10pt, height: 5pt, fill: conifer) \ + #rect(width: 40%, height: 5pt, stroke: conifer) +] + +--- +// Test text overflowing height. +#set page(width: 75pt, height: 100pt) +#square(fill: conifer)[ + But, soft! what light through yonder window breaks? +] + +--- +// Test that square does not overflow page. +#set page(width: 100pt, height: 75pt) +#square(fill: conifer)[ + But, soft! what light through yonder window breaks? +] + +--- +// Size wins over width and height. +// Error: 09-20 unexpected argument +#square(width: 10cm, height: 20cm, size: 1cm, fill: rgb("eb5278")) |
