diff options
Diffstat (limited to 'tests/typ/layout')
| -rw-r--r-- | tests/typ/layout/box-block.typ (renamed from tests/typ/layout/containers.typ) | 0 | ||||
| -rw-r--r-- | tests/typ/layout/image.typ | 59 | ||||
| -rw-r--r-- | tests/typ/layout/place-background.typ (renamed from tests/typ/layout/background.typ) | 0 | ||||
| -rw-r--r-- | tests/typ/layout/place.typ (renamed from tests/typ/layout/placed.typ) | 0 | ||||
| -rw-r--r-- | tests/typ/layout/shape-aspect.typ (renamed from tests/typ/layout/aspect.typ) | 0 | ||||
| -rw-r--r-- | tests/typ/layout/shape-circle.typ | 51 | ||||
| -rw-r--r-- | tests/typ/layout/shape-ellipse.typ | 23 | ||||
| -rw-r--r-- | tests/typ/layout/shape-fill-stroke.typ | 26 | ||||
| -rw-r--r-- | tests/typ/layout/shape-rect.typ | 30 | ||||
| -rw-r--r-- | tests/typ/layout/shape-square.typ | 39 | ||||
| -rw-r--r-- | tests/typ/layout/spacing.typ | 12 |
11 files changed, 239 insertions, 1 deletions
diff --git a/tests/typ/layout/containers.typ b/tests/typ/layout/box-block.typ index 14258c1e..14258c1e 100644 --- a/tests/typ/layout/containers.typ +++ b/tests/typ/layout/box-block.typ diff --git a/tests/typ/layout/image.typ b/tests/typ/layout/image.typ new file mode 100644 index 00000000..8817713f --- /dev/null +++ b/tests/typ/layout/image.typ @@ -0,0 +1,59 @@ +// 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, margins: 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 \ +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 +#image("path/does/not/exist") + +--- +// Error: 8-21 failed to load image (unknown image format) +#image("./image.typ") diff --git a/tests/typ/layout/background.typ b/tests/typ/layout/place-background.typ index f64bf0ee..f64bf0ee 100644 --- a/tests/typ/layout/background.typ +++ b/tests/typ/layout/place-background.typ diff --git a/tests/typ/layout/placed.typ b/tests/typ/layout/place.typ index 527e0559..527e0559 100644 --- a/tests/typ/layout/placed.typ +++ b/tests/typ/layout/place.typ diff --git a/tests/typ/layout/aspect.typ b/tests/typ/layout/shape-aspect.typ index 2c3e9b0c..2c3e9b0c 100644 --- a/tests/typ/layout/aspect.typ +++ b/tests/typ/layout/shape-aspect.typ diff --git a/tests/typ/layout/shape-circle.typ b/tests/typ/layout/shape-circle.typ new file mode 100644 index 00000000..8b795830 --- /dev/null +++ b/tests/typ/layout/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"), thickness: 2pt, + align(center + horizon)[But, soft!] +) + +Center-aligned rect in auto-sized circle. +#circle(fill: forest, stroke: conifer, + align(center + horizon, + rect(fill: conifer, padding: 5pt)[But, soft!] + ) +) + +Rect in auto-sized circle. \ +#circle(fill: forest, + rect(fill: conifer, stroke: white, padding: 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/layout/shape-ellipse.typ b/tests/typ/layout/shape-ellipse.typ new file mode 100644 index 00000000..154144c4 --- /dev/null +++ b/tests/typ/layout/shape-ellipse.typ @@ -0,0 +1,23 @@ +// 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: forest, thickness: 3pt, padding: 3pt)[ + #set text(8pt) + But, soft! what light through yonder window breaks? +] diff --git a/tests/typ/layout/shape-fill-stroke.typ b/tests/typ/layout/shape-fill-stroke.typ new file mode 100644 index 00000000..3ae5f987 --- /dev/null +++ b/tests/typ/layout/shape-fill-stroke.typ @@ -0,0 +1,26 @@ +// Test shape fill & stroke. + +--- +#let rect with (width: 20pt, height: 10pt) +#let items = for i, rect in ( + rect(stroke: none), + rect(), + rect(fill: none), + rect(thickness: 2pt), + rect(stroke: eastern), + rect(stroke: eastern, thickness: 2pt), + rect(fill: eastern), + rect(fill: eastern, stroke: none), + rect(fill: forest, stroke: none, thickness: 2pt), + rect(fill: forest, stroke: conifer), + rect(fill: forest, thickness: 2pt), + rect(fill: forest, stroke: conifer, thickness: 2pt), +) { + (align(horizon)[{i + 1}.], rect, []) +} + +#grid( + columns: (auto, auto, 1fr, auto, auto, 0fr), + gutter: 5pt, + ..items, +) diff --git a/tests/typ/layout/shape-rect.typ b/tests/typ/layout/shape-rect.typ new file mode 100644 index 00000000..add39b80 --- /dev/null +++ b/tests/typ/layout/shape-rect.typ @@ -0,0 +1,30 @@ +// Test the `rect` function. + +--- +// Default rectangle. +#rect() + +--- +#set page(width: 150pt) + +// Fit to text. +#rect(fill: conifer, padding: 3pt)[Textbox] + +// Empty with fixed width and height. +#block(rect( + height: 15pt, + fill: rgb("46b3c2"), + stroke: rgb("234994"), + thickness: 2pt, +)) + +// Fixed width, text height. +#rect(width: 2cm, fill: rgb("9650d6"), padding: 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"))\} diff --git a/tests/typ/layout/shape-square.typ b/tests/typ/layout/shape-square.typ new file mode 100644 index 00000000..c4ece778 --- /dev/null +++ b/tests/typ/layout/shape-square.typ @@ -0,0 +1,39 @@ +// Test the `square` function. + +--- +// Default square. +#square() +#square[hey!] + +--- +// Test auto-sized square. +#square(fill: eastern, padding: 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")) diff --git a/tests/typ/layout/spacing.typ b/tests/typ/layout/spacing.typ index 98a6100c..37aa8eaa 100644 --- a/tests/typ/layout/spacing.typ +++ b/tests/typ/layout/spacing.typ @@ -18,7 +18,17 @@ Add #h(10pt) #h(10pt) up | #h(1fr) | #h(2fr) | #h(1fr) | --- -// Test that spacing has style properties. +// Test spacing collapsing with parbreaks. +#v(0pt) +A +#v(0pt) +B +#v(0pt) + +C #parbreak() D + +--- +// Test that spacing can carry paragraph and page style properties. A[#set par(align: right);#h(1cm)]B [#set page(height: 20pt);#v(1cm)] |
