-
Notifications
You must be signed in to change notification settings - Fork 575
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
Closed
hagaki:0.1.0 #1505
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
/// - 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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, | ||
) | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.