From a1bdaa2785f8f849bdcf7fa0df6a970a4852448d Mon Sep 17 00:00:00 2001 From: Artemis Tosini Date: Sat, 20 Jan 2024 08:43:53 +0000 Subject: [PATCH] add iso216 card sheets --- cards_a6_a4sheet.typ | 9 ++++++ common.typ | 65 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 cards_a6_a4sheet.typ diff --git a/cards_a6_a4sheet.typ b/cards_a6_a4sheet.typ new file mode 100644 index 0000000..b4017f2 --- /dev/null +++ b/cards_a6_a4sheet.typ @@ -0,0 +1,9 @@ +#{ + import "common.typ" + + let options = json("cache/options.json") + let cards = options.cards + let args = options.args + + common.iso216_a_card_sheets(4, 6, args, cards) +} diff --git a/common.typ b/common.typ index 7ea721c..22b011b 100644 --- a/common.typ +++ b/common.typ @@ -114,13 +114,17 @@ ) } -#let card_sheets(width, height, margin, args, cards) = { - let content_fn = if args.no_content { +#let get_content_fn(args) = { + if args.no_content { _ => [] } else { import "cache/content/content.typ" content.content } +} + +#let card_sheets(width, height, margin, args, cards) = { + let content_fn = get_content_fn() for (idx, card) in cards.enumerate() { let row = calc.rem(idx + args.skip, 2) @@ -136,3 +140,60 @@ ) } } + +// It would be nice to calculate this but the rounding makes no sense, +// hardcode it. +#let iso216_lengths = ( + 1189mm, + 841mm, + 594mm, + 420mm, + 297mm, + 210mm, + 148mm, + 105mm, + 74mm, + 52mm, + 37mm, + 26mm +) + +#let iso216_a_size(format) = { + (iso216_lengths.at(format), iso216_lengths.at(format + 1)) +} + +// Pack together smaller ISO 216 A-series cards to make a full-size card. +// Useful to print on a large printer or plotter then use a paper cutter +#let iso216_a_card_sheets(page_format, card_format, args, cards) = { + let is_landscape = calc.even(card_format - page_format) + let (num_rows, num_cols) = if is_landscape { + let num = calc.pow(2, (card_format - page_format) / 2) + (num, num) + } else { + let cols = calc.pow(2, (card_format - 1 - page_format) / 2) + (cols * 2, cols) + } + + let (page_long, page_short) = iso216_a_size(page_format) + set page(margin: 0mm, width: page_short, height: page_long, flipped: is_landscape) + + let (card_long, card_short) = iso216_a_size(card_format) + let content_fn = get_content_fn(args) + + for (idx, card) in cards.enumerate() { + if idx != 0 and calc.rem(idx + args.skip, num_rows * num_cols) == 0 { + pagebreak() + } + + let offset_idx = idx + args.skip + let col = calc.rem(offset_idx, num_cols) + let row = calc.rem(calc.floor(offset_idx / num_cols), num_rows) + + place( + top + left, + dx: col * card_long, + dy: row * card_short, + postcard_block(card_long, card_short, content_fn, args, card) + ) + } +}