Skip to content

Commit

Permalink
Added printer tester
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-cpsn committed Jan 27, 2024
1 parent 7cfa877 commit 2e5b5a3
Show file tree
Hide file tree
Showing 6 changed files with 268 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/preview/printer-tester/0.1.0/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Julien Caposiena

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
42 changes: 42 additions & 0 deletions packages/preview/printer-tester/0.1.0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# [Printer tester](https://github.com/julien-cpsn/typst-printer-tester)

Generate printer tests directly in Typst.
For now, only generates with CMYK colors (as it is by far the most used).

I personally place one of these test on all my exam papers to ensure the printer's quality over time.

## Documentation

To import any of the functions needed, you may want to use the following line:

```typst
#import "@preview/printer-tester:0.1.0": square-printer-test, gradient-printer-test, circular-printer-test, crosshair-printer-test
```

### Square test

```typst
#square-printer-test()
```

### Gradient test

```typst
#gradient-printer-test()
```

### Circular test

```typst
#circular-printer-test()
```

### Crosshair test

```typst
#crosshair-printer-test()
```

## Contributors

- [Julien-cpsn](https://github.com/julien-cpsn)
Binary file not shown.
77 changes: 77 additions & 0 deletions packages/preview/printer-tester/0.1.0/examples/example.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#import "../lib.typ": square-printer-test, gradient-printer-test, circular-printer-test, crosshair-printer-test

#set text(
font: "Arial"
)

= #underline[All together]

#raw("#square-printer-test()", lang: "typst")
#square-printer-test()

#raw("#gradient-printer-test()", lang: "typst")
#gradient-printer-test()

#raw("#circular-printer-test()", lang: "typst")
#circular-printer-test()

#raw("#crosshair-printer-test()", lang: "typst")
#crosshair-printer-test()

#pagebreak()

== #underline[Square test]

#raw("#square-printer-test(dir: rtl)", lang: "typst")
#square-printer-test(dir: rtl)

#raw("#square-printer-test(dir: ttb)", lang: "typst")
#square-printer-test(dir: ttb)

#raw("#square-printer-test(size: 50pt)", lang: "typst")
#square-printer-test(size: 50pt)

#raw("#square-printer-test(dir: ttb, size: 5pt)", lang: "typst")
#square-printer-test(dir: ttb, size: 5pt)

#pagebreak()

== #underline[Gradient test]

#raw("#gradient-printer-test(dir: rtl)", lang: "typst")
#gradient-printer-test(dir: rtl)

#raw("#gradient-printer-test(dir: btt)", lang: "typst")
#gradient-printer-test(dir: btt)

#raw("#gradient-printer-test(width: 50pt)", lang: "typst")
#gradient-printer-test(width: 50pt)

#raw("#gradient-printer-test(height: 40pt)", lang: "typst")
#gradient-printer-test(height: 40pt)

#raw("#gradient-printer-test(width: 400pt, height: 10pt)", lang: "typst")
#gradient-printer-test(width: 400pt, height: 10pt)

#pagebreak()

== #underline[Circular test]

#raw("#circular-printer-test(size: 15pt)", lang: "typst")
#circular-printer-test(size: 15pt)

#raw("#circular-printer-test(size: 200pt)", lang: "typst")
#circular-printer-test(size: 200pt)

#pagebreak()

== #underline[Crosshair test]

#raw("#crosshair-printer-test(dir: rtl)", lang: "typst")
#crosshair-printer-test(dir: rtl)

#raw("#crosshair-printer-test(dir: ttb)", lang: "typst")
#crosshair-printer-test(dir: ttb)

#raw("#crosshair-printer-test(size: 75pt)", lang: "typst")
#crosshair-printer-test(size: 75pt)
109 changes: 109 additions & 0 deletions packages/preview/printer-tester/0.1.0/lib.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#let cyan = cmyk(100%, 0%, 0%, 0%)
#let magenta = cmyk(0%, 100%, 0%, 0%)
#let yellow = cmyk(0%, 0%, 100%, 0%)
#let transparent = rgb(100%, 100%, 100%, 0)

#let cyan-gradient = gradient.linear(cyan, transparent, angle: 0deg)
#let magenta-gradient = gradient.linear(magenta, transparent, angle: 0deg)
#let yellow-gradient = gradient.linear(yellow, transparent, angle: 0deg)
#let black-gradient = gradient.linear(black, transparent, angle: 0deg)

#let cyan-mid-opacity = rgb(cyan.to-hex() + "88")
#let magenta-mid-opacity = rgb(magenta.to-hex() + "88")
#let yellow-mid-opacity = rgb(yellow.to-hex() + "88")

#let square-printer-test(dir: ltr, size: 15pt) = [
#stack(
dir: dir,
spacing: 5pt,
square(width: size, height: size, fill: cyan),
square(width: size, height: size, fill: magenta),
square(width: size, height: size, fill: yellow),
square(width: size, height: size, fill: black)
)
]

#let gradient-printer-test(dir: ttb, width: 100pt, height: 15pt) = [
#stack(
dir: dir,
spacing: 5pt,
rect(width: width, height: height, fill: cyan-gradient),
rect(width: width, height: height, fill: magenta-gradient),
rect(width: width, height: height, fill: yellow-gradient),
rect(width: width, height: height, fill: black-gradient)
)
]

#let circular-printer-test(size: 100pt) = [
#let adjusted-size = size/3.5

#rect(width: size, height: size*0.93, fill: transparent)

#place(
dx: 0pt,
dy: -size - 6pt,
circle(radius: adjusted-size, fill: cyan-mid-opacity)
)
#place(
dx: adjusted-size*0.75,
dy: -size - 6pt + adjusted-size*1.25,
circle(radius: adjusted-size, fill: magenta-mid-opacity)
)
#place(
dx: adjusted-size*1.5,
dy: -size - 6pt,
circle(radius: adjusted-size, fill: yellow-mid-opacity)
)
]

#let crosshair(size: 20pt, stroke: black) = [
#place(
line(start: (0pt, size/2), end: (size, size/2), stroke: stroke)
)
#place(
line(start: (size/2, 0pt), end: (size/2, size), stroke: stroke)
)
#place(
dx: size*0.1,
dy: size*0.1,
circle(radius: size*0.4, stroke: stroke)
)
#place(
dx: size*0.15,
dy: size*0.15,
circle(radius: size*0.35, stroke: stroke)
)
#place(
dx: size*0.2,
dy: size*0.2,
circle(radius: size*0.3, stroke: stroke)
)
#place(
dx: size*0.25,
dy: size*0.25,
circle(radius: size*0.25, stroke: stroke)
)
#place(
dx: size*0.3,
dy: size*0.3,
circle(radius: size*0.2, stroke: stroke)
)
#place(
dx: size*0.35,
dy: size*0.35,
circle(radius: size*0.15, stroke: stroke)
)

#square(size: size, fill: transparent)
]

#let crosshair-printer-test(dir: ltr, size: 40pt) = [
#stack(
dir: dir,
spacing: 5pt,
crosshair(size: size, stroke: cyan),
crosshair(size: size, stroke: magenta),
crosshair(size: size, stroke: yellow),
crosshair(size: size, stroke: black)
)
]
19 changes: 19 additions & 0 deletions packages/preview/printer-tester/0.1.0/typst.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "printer-tester"
version = "0.1.0"
entrypoint = "lib.typ"
authors = ["Julien Caposiena"]
license = "MIT"
description = "Generate printer tests (likely CMYK) in typst."

homepage = "https://github.com/julien-cpsn/typst-printer-tester"
repository = "https://github.com/julien-cpsn/typst-printer-tester"
keywords = [
"printer",
"test",
"color",
"colour",
"generate",
"generator",
"CMYK"
]

0 comments on commit 2e5b5a3

Please sign in to comment.