Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
Adaptive page size and number of columns
Browse files Browse the repository at this point in the history
  • Loading branch information
cu1ch3n committed Apr 3, 2024
1 parent 38dcd34 commit bfe63b1
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 67 deletions.
164 changes: 99 additions & 65 deletions lib/menu.typ
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
font: "Libre Baskerville",
size: size,
style: style,
fill: fill
fill: fill,
)[#body]

#let zh_text(size, body, fill: nord0) = text(
font: "STKaiti",
size: size,
fill: fill
fill: fill,
)[#body]

#let cuisine(name_zh, name_en) = align(center)[
Expand All @@ -30,118 +30,152 @@
#v(-.7em)#h(.14em)#en_text(10pt)[#name_en]
]

#let conf(title: none, update_time: none, doc) = {
#let conf(
title: none,
title_image: none,
update_time: none,
page_height: 595.28pt,
page_width: 841.89pt,
num_columns: 3,
doc,
) = {
let frame_font_size = 40pt
let frame_format = c => text(c, font: "WebOMints GD", size: frame_font_size, fill: nord3)

let frame_format = c => text(
c,
font: "WebOMints GD",
size: frame_font_size,
fill: nord3,
)

let frame = (
chars: ([E], [F], [G], [H]),
dx: 1em,
dy: 2em
dy: 2em,
)

let dx = (1, -1, 1, -1)
let dy = (1, 1, -1, -1)
let border_x = (left, right, left, right)
let border_y = (top, top, bottom, bottom)

let page_height = 595.28pt
let page_width = 841.89pt

let num_columns = 3

let column_width = page_width / num_columns

let frame_vert_line = line(
length: page_height - 2 * (frame.dy + frame_font_size),
angle: 90deg,
stroke: 1pt + nord3
stroke: 1pt + nord3,
)
let frame_vert_line_dy = frame.dy + frame_font_size + .5em

let frame_horiz_line = line(
length: column_width - 2 * (frame.dx + frame_font_size) - .6em,
stroke: 1pt + nord3
stroke: 1pt + nord3,
)
let frame_horiz_line_dx = frame.dx + frame_font_size + .3em

let seperator_vert_line = line(
length: page_height,
angle: 90deg,
stroke: (paint: nord0, thickness: .5pt, dash: "dashed")
stroke: (paint: nord0, thickness: .5pt, dash: "dashed"),
)

set page(
paper: "a4",
fill: nord6,
flipped: true,
height: page_height,
width: page_width,
margin: (x: frame.dx + 2em),
background: [
// Seperator lines
#for i in range(num_columns - 1) {
place(top + left,
dx: (i + 1) * column_width,
seperator_vert_line)
place(
top + left,
dx: (i + 1) * column_width,
seperator_vert_line,
)
}
// Frame
#for i in range(num_columns) {
let offset_xl = i * column_width
let offset_xr = (num_columns - i - 1) * column_width
// Frame characters
for j in range(4) {
place(border_x.at(j) + border_y.at(j),
dx: dx.at(j) * (offset_xl + frame.dx),
dy: dy.at(j) * frame.dy,
frame_format(frame.chars.at(j)))
place(
border_x.at(j) + border_y.at(j),
dx: dx.at(j) * (offset_xl + frame.dx),
dy: dy.at(j) * frame.dy,
frame_format(frame.chars.at(j)),
)
}
place(top + left,
dx: offset_xl + frame.dx + 7pt,
dy: frame_vert_line_dy,
frame_vert_line)
place(top + right,
dx: - (offset_xr + 2 * frame.dx) + 4pt,
dy: frame_vert_line_dy,
frame_vert_line)
place(top + left,
dx: offset_xl + frame_horiz_line_dx,
dy: frame.dy + 4pt,
frame_horiz_line)
place(bottom + left,
dx: offset_xl + frame_horiz_line_dx,
dy: - frame.dy + 4pt,
frame_horiz_line)
place(bottom + left,
dx: offset_xl + 0.5 * column_width,
dy: - frame.dy - 1em,
context([
#let num = (counter(page).get().at(0) - 1) * 3 + i
#if num != 0 { en_text(10pt, style: "normal")[#numbering("I", num)] }
]))
place(
top + left,
dx: offset_xl + frame.dx + 7pt,
dy: frame_vert_line_dy,
frame_vert_line,
)
place(
top + right,
dx: -(offset_xr + 2 * frame.dx) + 4pt,
dy: frame_vert_line_dy,
frame_vert_line,
)
place(
top + left,
dx: offset_xl + frame_horiz_line_dx,
dy: frame.dy + 4pt,
frame_horiz_line,
)
place(
bottom + left,
dx: offset_xl + frame_horiz_line_dx,
dy: -frame.dy + 4pt,
frame_horiz_line,
)
place(
bottom + left,
dx: offset_xl + 0.5 * column_width,
dy: -frame.dy - 1em,
context (
[
#let num = (counter(page).get().at(0) - 1) * 3 + i
#if num != 0 {
en_text(10pt, style: "normal")[#numbering("I", num)]
}
]
),
)
}
]
],
)

let title_page = [
let title_page = context [
#set align(center)
#v(70pt)
#en_text(20pt, fill: nord0)[#title]
#v(30pt)
#image("title.png")
#v(60pt)
#context [
#let num_items = item_counter.final().at(0)
#let title_content = [
#title
#if title_image != none [
#v(3em)
#set image(width: column_width - 2 * frame.dx - 6em)
#title_image
]
#if update_time != none [
#v(5em)
#zh_text(10pt)[
// 共 #num_items 道菜;
更新于:#update_time.display("[year]年[month padding:none]月[day padding:none]日") ] \
更新于:#update_time.display("[year]年[month padding:none]月[day padding:none]日") ] \
#en_text(8pt)[
// #num_items dishes in total;
Updated on #update_time.display("[month repr:long] [day], [year]")]
]
]
#colbreak()
#let text_dy = (page_height - measure(title_content).height) / 2 - frame.dy
#v(text_dy)
#title_content
]
let end_page = [
#colbreak(weak: true)
]
set list(marker: [#v(.8em)#en_text(16pt, fill: nord3)[☐]])
columns(num_columns, gutter: frame.dx * 2 + 4em)[#title_page #doc #end_page]
set list(marker: [#v(.7em)#en_text(16pt, fill: nord3)[☐]])
columns(
num_columns,
gutter: frame.dx * 2 + 4em,
)[#title_page #colbreak(weak: true) #doc #colbreak(weak: true) #end_page]
}
8 changes: 6 additions & 2 deletions main.typ
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#import "lib/menu.typ": *

#show: doc => conf(
title: [Chen's Private Cuisine],
title: [#en_text(22pt, fill: nord0)[Chen's Private Cuisine]],
title_image: image("title.png"),
update_time: datetime.today(),
doc
page_height: 595.28pt,
page_width: 841.89pt,
num_columns: 3,
doc,
)

#let peper(n: 1) = [#emoji.pepper.hot] * n
Expand Down

0 comments on commit bfe63b1

Please sign in to comment.