diff options
| author | Martin <mhaug@live.de> | 2021-12-22 20:37:34 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-22 20:37:34 +0100 |
| commit | f6c7a8292dc1ab0560408fca9d74505e9d7cf13a (patch) | |
| tree | badd3076f6146cec34c55764600df5124c408521 /tests/typ/layout | |
| parent | 738ff7e1f573bef678932b313be9969a17af8d22 (diff) | |
| parent | 438255519e88bb790480306b9a9b452aaf054519 (diff) | |
Merge pull request #51 from typst/set-rules
Set rules
Diffstat (limited to 'tests/typ/layout')
23 files changed, 314 insertions, 55 deletions
diff --git a/tests/typ/layout/align.typ b/tests/typ/layout/align.typ index 13b88ac1..09c4dee5 100644 --- a/tests/typ/layout/align.typ +++ b/tests/typ/layout/align.typ @@ -1,7 +1,7 @@ // Test alignment. --- -#page(height: 100pt) +#set page(height: 100pt) #stack(dir: ltr, align(left, square(size: 15pt, fill: eastern)), align(center, square(size: 20pt, fill: eastern)), diff --git a/tests/typ/layout/containers.typ b/tests/typ/layout/box-block.typ index d4556a0f..14258c1e 100644 --- a/tests/typ/layout/containers.typ +++ b/tests/typ/layout/box-block.typ @@ -12,7 +12,7 @@ Apart --- // Test block over multiple pages. -#page(height: 60pt) +#set page(height: 60pt) First! #block[ diff --git a/tests/typ/layout/grid-1.typ b/tests/typ/layout/grid-1.typ index 647e366f..a6596c98 100644 --- a/tests/typ/layout/grid-1.typ +++ b/tests/typ/layout/grid-1.typ @@ -3,7 +3,7 @@ --- #let cell(width, color) = rect(width: width, height: 2cm, fill: color) -#page(width: 100pt, height: 140pt) +#set page(width: 100pt, height: 140pt) #grid( columns: (auto, 1fr, 3fr, 0.25cm, 3%, 2mm + 10%), cell(0.5cm, rgb("2a631a")), @@ -31,7 +31,7 @@ ) --- -#page(height: 3cm, margins: 0pt) +#set page(height: 3cm, margins: 0pt) #grid( columns: (1fr,), rows: (1fr, auto, 2fr), diff --git a/tests/typ/layout/grid-2.typ b/tests/typ/layout/grid-2.typ index c522a402..7df64a56 100644 --- a/tests/typ/layout/grid-2.typ +++ b/tests/typ/layout/grid-2.typ @@ -1,7 +1,7 @@ // Test using the `grid` function to create a finance table. --- -#page(width: 12cm, height: 2.5cm) +#set page(width: 12cm, height: 2.5cm) #grid( columns: 5, column-gutter: (2fr, 1fr, 1fr), diff --git a/tests/typ/layout/grid-3.typ b/tests/typ/layout/grid-3.typ index 6f7f6977..8d04722e 100644 --- a/tests/typ/layout/grid-3.typ +++ b/tests/typ/layout/grid-3.typ @@ -1,7 +1,7 @@ // Test grid cells that overflow to the next region. --- -#page(width: 5cm, height: 3cm) +#set page(width: 5cm, height: 3cm) #grid( columns: 2, row-gutter: 8pt, @@ -18,7 +18,7 @@ --- // Test a column that starts overflowing right after another row/column did // that. -#page(width: 5cm, height: 2cm) +#set page(width: 5cm, height: 2cm) #grid( columns: 4 * (1fr,), row-gutter: 10pt, @@ -32,7 +32,7 @@ --- // Test two columns in the same row overflowing by a different amount. -#page(width: 5cm, height: 2cm) +#set page(width: 5cm, height: 2cm) #grid( columns: 3 * (1fr,), row-gutter: 8pt, @@ -48,7 +48,7 @@ --- // Test grid within a grid, overflowing. -#page(width: 5cm, height: 2.25cm) +#set page(width: 5cm, height: 2.25cm) #grid( columns: 4 * (1fr,), row-gutter: 10pt, @@ -62,7 +62,7 @@ --- // Test partition of `fr` units before and after multi-region layout. -#page(width: 5cm, height: 4cm) +#set page(width: 5cm, height: 4cm) #grid( columns: 2 * (1fr,), rows: (1fr, 2fr, auto, 1fr, 1cm), diff --git a/tests/typ/layout/grid-4.typ b/tests/typ/layout/grid-4.typ index d6aa6358..e02d98c5 100644 --- a/tests/typ/layout/grid-4.typ +++ b/tests/typ/layout/grid-4.typ @@ -23,7 +23,7 @@ --- // Test that all three kinds of rows use the correct bases. -#page(height: 4cm, margins: 0cm) +#set page(height: 4cm, margins: 0cm) #grid( rows: (1cm, 1fr, 1fr, auto), rect(height: 50%, width: 100%, fill: conifer), diff --git a/tests/typ/layout/grid-5.typ b/tests/typ/layout/grid-5.typ index 585fc6ce..db7c525a 100644 --- a/tests/typ/layout/grid-5.typ +++ b/tests/typ/layout/grid-5.typ @@ -1,7 +1,7 @@ --- // Test that trailing linebreak doesn't overflow the region. -#page(height: 2cm) +#set page(height: 2cm) #grid[ Hello \ Hello \ @@ -12,7 +12,7 @@ --- // Test that broken cell expands vertically. -#page(height: 2.25cm) +#set page(height: 2.25cm) #grid( columns: 2, gutter: 10pt, 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/pad.typ b/tests/typ/layout/pad.typ index 1fa0f79d..502137ec 100644 --- a/tests/typ/layout/pad.typ +++ b/tests/typ/layout/pad.typ @@ -19,7 +19,7 @@ Hi #box(pad(left: 10pt)[A]) there --- // Test that the pad node doesn't consume the whole region. -#page(height: 6cm) +#set page(height: 6cm) #align(left)[Before] #pad(10pt, image("../../res/tiger.jpg")) #align(right)[After] diff --git a/tests/typ/layout/page.typ b/tests/typ/layout/page.typ index dc6c7c81..35f338f4 100644 --- a/tests/typ/layout/page.typ +++ b/tests/typ/layout/page.typ @@ -2,33 +2,33 @@ --- // Set width and height. -#page(width: 80pt, height: 80pt) -[#page(width: 40pt) High] -[#page(height: 40pt) Wide] +#set page(width: 80pt, height: 80pt) +[#set page(width: 40pt);High] +[#set page(height: 40pt);Wide] // Set all margins at once. [ - #page(margins: 5pt) + #set page(margins: 5pt) #place(top + left)[TL] #place(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]] +#set page(height: 40pt) +[#set page(left: 0pt); #align(left)[Left]] +[#set page(right: 0pt); #align(right)[Right]] +[#set page(top: 0pt); #align(top)[Top]] +[#set page(bottom: 0pt); #align(bottom)[Bottom]] // Ensure that specific margins override general margins. -[#page(margins: 0pt, left: 20pt) Overriden] +[#set page(margins: 0pt, left: 20pt); Overriden] // Flipped predefined paper. -[#page(paper: "a11", flip: true) Flipped A11] +[#set page(paper: "a11", flipped: true);Flipped A11] --- -#page(width: 80pt, height: 40pt, fill: eastern) -#font(15pt, "Roboto", fill: white, smallcaps: true)[Typst] +#set page(width: 80pt, height: 40pt, fill: eastern) +#text(15pt, "Roboto", fill: white, smallcaps: true)[Typst] -#page(width: 40pt, fill: none, margins: auto, top: 10pt) +#set page(width: 40pt, fill: none, margins: auto, top: 10pt) Hi diff --git a/tests/typ/layout/pagebreak.typ b/tests/typ/layout/pagebreak.typ index f9a935bc..9a74d2bf 100644 --- a/tests/typ/layout/pagebreak.typ +++ b/tests/typ/layout/pagebreak.typ @@ -3,7 +3,8 @@ --- First of two #pagebreak() -#page(height: 40pt) +#set page(height: 40pt) +Second of two --- // Make sure that you can't do page related stuff in a container. @@ -11,7 +12,7 @@ A #box[ B #pagebreak() - #page("a4") + #set page("a4") ] C @@ -22,13 +23,13 @@ D --- // Test a combination of pages with bodies and normal content. -#page(width: 80pt, height: 30pt) +#set page(width: 80pt, height: 30pt) -[#page() First] -[#page() Second] +Fi[#set page(width: 80pt);rst] +[#set page(width: 70pt); Second] #pagebreak() #pagebreak() Fourth -[#page(height: 25pt)] +#page(height: 20pt)[] Sixth -[#page() Seventh] +[#set page(); Seventh] diff --git a/tests/typ/layout/background.typ b/tests/typ/layout/place-background.typ index 6303a83b..f64bf0ee 100644 --- a/tests/typ/layout/background.typ +++ b/tests/typ/layout/place-background.typ @@ -1,8 +1,8 @@ // Test placing a background image on a page. --- -#page(paper: "a10", flip: true) -#font(fill: white) +#set page(paper: "a10", flipped: true) +#set text(fill: white) #place( dx: -10pt, dy: -10pt, diff --git a/tests/typ/layout/placed.typ b/tests/typ/layout/place.typ index 334ff80d..527e0559 100644 --- a/tests/typ/layout/placed.typ +++ b/tests/typ/layout/place.typ @@ -1,4 +1,7 @@ -#page("a8") +// Test the `place` function. + +--- +#set page("a8") #place(bottom + center)[© Typst] = Placement @@ -20,3 +23,13 @@ the line breaks still had to be inserted manually. #place(center, dx: 7pt, dy: 5pt)[Hello] Hello #h(1fr) Hello ] + +--- +// Test how the placed node interacts with paragraph spacing around it. +#set page("a8", height: 60pt) + +First + +#place(bottom + right)[Placed] + +Second diff --git a/tests/typ/layout/aspect.typ b/tests/typ/layout/shape-aspect.typ index c9b8ee41..2c3e9b0c 100644 --- a/tests/typ/layout/aspect.typ +++ b/tests/typ/layout/shape-aspect.typ @@ -3,14 +3,14 @@ --- // Test relative width and height and size that is smaller // than default size. -#page(width: 120pt, height: 70pt) +#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. -#font(8pt) +#set text(8pt) #square(padding: 4pt)[ Hey there, #align(center + bottom, rotate(180deg, [you!])) ] @@ -23,19 +23,19 @@ --- // Test square that is limited by region size. -#page(width: 20pt, height: 10pt, margins: 0pt) +#set page(width: 20pt, height: 10pt, margins: 0pt) #stack(dir: ltr, square(fill: forest), square(fill: conifer)) --- // Test different ways of sizing. -#page(width: 120pt, height: 40pt) +#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. -#page(width: 40pt, height: 20pt, margins: 5pt) +#set page(width: 40pt, height: 20pt, margins: 5pt) #square(width: 100%) #square(width: 100%)[Hello] 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 7cf6760f..37aa8eaa 100644 --- a/tests/typ/layout/spacing.typ +++ b/tests/typ/layout/spacing.typ @@ -18,6 +18,23 @@ Add #h(10pt) #h(10pt) up | #h(1fr) | #h(2fr) | #h(1fr) | --- +// 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)] +B + +--- // Missing spacing. // Error: 11-13 missing argument: spacing Totally #h() ignored diff --git a/tests/typ/layout/stack-1.typ b/tests/typ/layout/stack-1.typ index 02083d2b..a4a0d6b8 100644 --- a/tests/typ/layout/stack-1.typ +++ b/tests/typ/layout/stack-1.typ @@ -15,13 +15,13 @@ #let items = for w in widths { (align(right, shaded(w)),) } -#page(width: 50pt, margins: 0pt) +#set page(width: 50pt, margins: 0pt) #stack(dir: btt, ..items) --- // Test RTL alignment. -#page(width: 50pt, margins: 5pt) -#font(8pt) +#set page(width: 50pt, margins: 5pt) +#set text(8pt) #stack(dir: rtl, align(center, [A]), align(left, [B]), @@ -30,8 +30,8 @@ --- // Test spacing. -#page(width: 50pt, margins: 0pt) -#par(spacing: 5pt) +#set page(width: 50pt, margins: 0pt) +#set par(spacing: 5pt) #let x = square(size: 10pt, fill: eastern) #stack(dir: rtl, spacing: 5pt, x, x, x) @@ -40,7 +40,7 @@ --- // Test overflow. -#page(width: 50pt, height: 30pt, margins: 0pt) +#set page(width: 50pt, height: 30pt, margins: 0pt) #box(stack( rect(width: 40pt, height: 20pt, fill: conifer), rect(width: 30pt, height: 13pt, fill: forest), diff --git a/tests/typ/layout/stack-2.typ b/tests/typ/layout/stack-2.typ index 2167f48f..f88f7a58 100644 --- a/tests/typ/layout/stack-2.typ +++ b/tests/typ/layout/stack-2.typ @@ -1,7 +1,7 @@ // Test fr units in stacks. --- -#page(height: 3.5cm) +#set page(height: 3.5cm) #stack( dir: ltr, spacing: 1fr, @@ -15,8 +15,8 @@ from #h(1fr) the #h(1fr) wonderful World! 🌍 --- -#page(height: 2cm) -#font(white) +#set page(height: 2cm) +#set text(white) #rect(fill: forest)[ #v(1fr) #h(1fr) Hi you! #h(5pt) diff --git a/tests/typ/layout/transform.typ b/tests/typ/layout/transform.typ index 5b1fa2a1..82ee1390 100644 --- a/tests/typ/layout/transform.typ +++ b/tests/typ/layout/transform.typ @@ -23,13 +23,13 @@ [X] } -#font("Latin Modern Math", size) +#set text("Latin Modern Math", size) Neither #tex, \ nor #xetex! --- // Test combination of scaling and rotation. -#page(height: 80pt) +#set page(height: 80pt) #align(center + horizon, rotate(20deg, scale(70%, image("../../res/tiger.jpg"))) ) @@ -43,7 +43,7 @@ nor #xetex! --- // Test setting scaling origin. #let r = rect(width: 100pt, height: 10pt, fill: forest) -#page(height: 65pt) +#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) |
