Skip to content

hagaki:0.1.0 #1505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/preview/hagaki/0.1.0/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2025 34j and contributors
Copyright (c) 2022–2023 いなにわうどん.

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.
26 changes: 26 additions & 0 deletions packages/preview/hagaki/0.1.0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Typst Hagaki

Typst package for printing address labels on Japanese Hagaki paper.

年賀状などのはがきの宛名印刷用のTypstパッケージです。

## Usage

```typst
#import "@preview/hagaki:0.1.0": hagaki-from-csv

#hagaki-from-csv("jyuusyoroku.csv", 0, 1, 2, 3, debug: true)
```

`jyuusyoroku.csv`: first name, last name, postal code, address

```csv
姓,名,郵便番号,住所
,邪神ちゃん,101-0051,東京都千代田区神田神保町1丁目
岸田,文雄,1008981,東京都千代田区永田町2-2-1 衆議院第1議員会館1222号室
```

Below image is just an example.
Please do not maliciously use this image.

![Preview](./tests/test.png)
Binary file added packages/preview/hagaki/0.1.0/hagaki.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
195 changes: 195 additions & 0 deletions packages/preview/hagaki/0.1.0/lib.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
#let vw(
body,
kerning: 0.3em,
leading: 0.5em,
spacing: 1em,
rotate-char: "[-ー\u{FF5E}\u{301C}\p{Open_Punctuation}\p{Close_Punctuation}]",
) = {
set align(right)
stack(
dir: rtl,
spacing: leading,
..for s in body.split(regex("[\n]")) {
(
stack(
dir: ttb,
spacing: spacing,
..for t in s.split(regex("[\p{Zs}]")) {
(
stack(
dir: ttb,
spacing: kerning,
..for l in t.clusters() {
(
if regex(rotate-char) in l {
set align(center)
rotate(90deg, l)
} else {
set align(center)
l
},
)
},
),
)
},
),
)
},
)
}

#let format-address(address) = {
address.replace("-", "ー").replace("1", "一").replace("2", "二").replace("3", "三").replace("4", "四").replace("5", "五").replace("6", "六").replace("7", "七").replace("8", "八").replace("9", "九").replace("0", "〇").replace(" ", "\n")
}

/// Generate an address label for Japanese postcards
/// with the given information.
///
/// - last-name (string): The last name of the recipient, e.g., "岸田".
/// - first-name (string): The first name of the recipient, e.g., "文雄".
/// - postal-code (string): The post code of the recipient, e.g., "1008981".
/// - address (string): The address of the recipient, e.g., "東京都千代田区永田町2-2-1 衆議院第1議員会館1222号室". Arabic numerals are automatically converted to kanji numerals.
/// - my-last-name (string): The last name of the sender, e.g., "岸田".
/// - my-first-name (string): The first name of the sender, e.g., "文雄".
/// - my-postal-code (string): The post code of the sender, e.g., "1008981".
/// - my-address (string): The address of the sender, e.g., "東京都千代田区永田町2-2-1 衆議院第1議員会館1222号室". Arabic numerals are automatically converted to kanji numerals.
/// - debug (boolean): Whether to show the debug image, e.g., true.
/// -> none
#let hagaki(last-name, first-name, postal-code, address, my-last-name, my-first-name, my-postal-code, my-address, debug: false) = {
let background = none
if debug {
background = image("hagaki.png")
}
set page(width: 100mm, height: 148mm, margin: 0mm, background: background)
// postCode

set text(size: 16pt)
for (i, c) in postal-code.clusters(
).filter(x => regex("[0-9]") in x).enumerate() {
place(
top + left,
block(
align(center + horizon)[#c],
width: 6mm,
height: 8mm,
),
dx: i * 7mm + 44mm,
dy: 12mm,
)
}

// myPostCode

set text(size: 10pt)
for (i, c) in my-postal-code.clusters(
).filter(x => regex("[0-9]") in x).enumerate() {
place(
top + left,
block(
align(center + horizon)[#c],
width: 4mm,
height: 6.5mm,
),
dx: i * 4.1mm + 5.7mm,
dy: 122.5mm,
)
}

// name

set text(size: 30pt)
place(
center + bottom,
block(
vw(last-name + " " + first-name + " 様"),
),
dy: -33mm,
)

// address

set text(size: 13pt)
place(
top + right,
block(
vw(format-address(address)),
width: 35mm,
height: 90mm,
),
dy: 30mm,
dx: -10mm,
)

// myAddress

place(
left + top,
block(
align(center + horizon)[
#set text(size: 10pt)
#vw(format-address(my-address))
],
width: 15mm,
height: 60mm,
),
dx: 15mm,
dy: 60mm,
)

// myName

place(
left + top,
block(
align(center + bottom)[
#set text(size: 16pt)
#vw(my-last-name + " " + my-first-name)
],
width: 10mm,
height: 60mm,
),
dx: 5mm,
dy: 60mm,
)
pagebreak(weak: true)
}

/// Generate a batch of address labels for Japanese postcards
/// with the given information from the CSV file.
///
/// - path (string): The path to the CSV file, e.g., "jyusyoroku.csv".
/// - lastNameColumn (integer): The column number for the last name, e.g., 0.
/// - firstNameColumn (integer): The column number for the first name, e.g., 1.
/// - postCodeColumn (integer): The column number for the post code, e.g., 2.
/// - addressColumn (integer): The column number for the address, e.g., 3.
/// - myLine (number): The line number for the sender, e.g., 1.
Comment on lines +161 to +166
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The names of the parameters here seem outdated.

/// - debug (boolean): Whether to show the debug image, e.g., true.
/// -> none
#let hagaki-from-csv(
path,
last-name-col,
first-name-col,
postal-code-col,
address-col,
my-line: 1,
debug: false,
) = {
let lines = csv(path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will probably not work as expected, since you can only access files from your package if you make the csv call here. Instead, you should ask the user of the package to pass a call to csv(path) instead of just path as a parameter.

for (i, line) in lines.slice(1).enumerate() {
if i + 1 == my-line {
continue
}
hagaki(
line.at(last-name-col),
line.at(first-name-col),
line.at(postal-code-col),
line.at(address-col),
lines.at(my-line).at(last-name-col),
lines.at(my-line).at(first-name-col),
lines.at(my-line).at(postal-code-col),
lines.at(my-line).at(address-col),
debug: debug,
)
}
}
Binary file added packages/preview/hagaki/0.1.0/tests/test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions packages/preview/hagaki/0.1.0/typst.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "hagaki"
version = "0.1.0"
entrypoint = "lib.typ"
authors = ["34j <@34j>"]
categories = ["office"]
keywords = ["postcard"]
license = "MIT"
repository = "https://github.com/34j/typst-hagaki"
description = "Print address labels on Japanese postcards."
exclude = ["tests/*", "*.png"]
Loading