Skip to content

Commit

Permalink
Use BIZUDGothic
Browse files Browse the repository at this point in the history
  • Loading branch information
okenakt committed Feb 5, 2025
1 parent 29e0015 commit c5dfe8a
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 100 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
VERSION=v0.1.0
HACK_VERSION=v3.003
MGENPLUS_VERSION=20150602
BIZUD_VERSION=v1.051
NERD_VERSION=v3.3.0
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ include .env
tmp_dir := ./tmp
params := $(wildcard ./parameters/*.json)
hack := ${tmp_dir}/Hack-Regular.ttf ${tmp_dir}/Hack-Bold.ttf
mgenplus := ${tmp_dir}/mgenplus-1m-regular.ttf ${tmp_dir}/mgenplus-1m-bold.ttf
bizud := ${tmp_dir}/BIZUDGothic-Regular.ttf ${tmp_dir}/BIZUDGothic-Bold.ttf
nerd_font_patcher := ${tmp_dir}/FontPatcher.zip
nerd := ${tmp_dir}/NerdFont.ttf

Expand All @@ -26,11 +26,11 @@ ${hack}: .env
@cp ${tmp_dir}/hack/ttf/Hack-Regular.ttf ${tmp_dir}
@cp ${tmp_dir}/hack/ttf/Hack-Bold.ttf ${tmp_dir}

${mgenplus}: .env
@curl -fsL https://ftp.iij.ad.jp/pub/osdn.jp/users/8/8597/mgenplus-${MGENPLUS_VERSION}.7z -o ${tmp_dir}/mgenplus.7z
@unar -f ${tmp_dir}/mgenplus.7z -o ${tmp_dir}
@cp ${tmp_dir}/mgenplus/mgenplus-1m-regular.ttf ${tmp_dir}
@cp ${tmp_dir}/mgenplus/mgenplus-1m-bold.ttf ${tmp_dir}
${bizud}: .env
@curl -fsL https://github.com/googlefonts/morisawa-biz-ud-gothic/releases/download/${BIZUD_VERSION}/BIZUDGothic.zip -o ${tmp_dir}/bizud.zip
@unar -f ${tmp_dir}/bizud.zip -o ${tmp_dir}
@cp ${tmp_dir}/bizud/BIZUDGothic-Regular.ttf ${tmp_dir}
@cp ${tmp_dir}/bizud/BIZUDGothic-Bold.ttf ${tmp_dir}

${nerd_font_patcher}: .env
@curl -fsL https://github.com/ryanoasis/nerd-fonts/releases/download/${NERD_VERSION}/FontPatcher.zip -o ${tmp_dir}/FontPatcher.zip
Expand All @@ -46,7 +46,7 @@ nerd:
@make ${nerd}

.PHONY: build
build: ${hack} ${mgenplus} ${nerd}
build: ${hack} ${bizud} ${nerd}
@$(foreach param, ${params}, \
python3 -m src.build_pennywort --src-dir ${tmp_dir} ${param}; \
)
Expand Down
19 changes: 4 additions & 15 deletions parameters/bold.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,17 @@
"dot_zero": true,
"broken_vline": true
},
"mgenplus": {
"source": "mgenplus-1m-bold.ttf",
"shape_as": {
"ascent": 876,
"descent": 97,
"half_width": 374,
"full_width": 748
},
"visualize_zenkaku_space": true,
"baseline_shift": 41,
"weight": 12
},
"bizud": {
"source": "BIZUDGothic-Bold.ttf",
"shape_as": {
"ascent": 1800,
"ascent": 1900,
"descent": 195,
"half_width": 819,
"full_width": 1638
},
"baseline_shift": 49,
"weight": 16
"visualize_zenkaku_space": true,
"baseline_shift": 98,
"weight": 28
},
"nerd": {
"source": "NerdFont.ttf",
Expand Down
19 changes: 4 additions & 15 deletions parameters/bold_italic.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,17 @@
"dot_zero": true,
"broken_vline": true
},
"mgenplus": {
"source": "mgenplus-1m-bold.ttf",
"shape_as": {
"ascent": 876,
"descent": 97,
"half_width": 374,
"full_width": 748
},
"visualize_zenkaku_space": true,
"baseline_shift": 41,
"weight": 12
},
"bizud": {
"source": "BIZUDGothic-Bold.ttf",
"shape_as": {
"ascent": 1800,
"ascent": 1900,
"descent": 195,
"half_width": 819,
"full_width": 1638
},
"baseline_shift": 49,
"weight": 16
"visualize_zenkaku_space": true,
"baseline_shift": 98,
"weight": 28
},
"nerd": {
"source": "NerdFont.ttf",
Expand Down
19 changes: 4 additions & 15 deletions parameters/italic.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,17 @@
"dot_zero": true,
"broken_vline": true
},
"mgenplus": {
"source": "mgenplus-1m-regular.ttf",
"shape_as": {
"ascent": 876,
"descent": 97,
"half_width": 374,
"full_width": 748
},
"visualize_zenkaku_space": true,
"baseline_shift": 41,
"weight": 12
},
"bizud": {
"source": "BIZUDGothic-Regular.ttf",
"shape_as": {
"ascent": 1800,
"ascent": 1900,
"descent": 195,
"half_width": 819,
"full_width": 1638
},
"baseline_shift": 49,
"weight": 16
"visualize_zenkaku_space": true,
"baseline_shift": 98,
"weight": 20
},
"nerd": {
"source": "NerdFont.ttf",
Expand Down
19 changes: 4 additions & 15 deletions parameters/regular.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,17 @@
"dot_zero": true,
"broken_vline": true
},
"mgenplus": {
"source": "mgenplus-1m-regular.ttf",
"shape_as": {
"ascent": 876,
"descent": 97,
"half_width": 374,
"full_width": 748
},
"visualize_zenkaku_space": true,
"baseline_shift": 41,
"weight": 12
},
"bizud": {
"source": "BIZUDGothic-Regular.ttf",
"shape_as": {
"ascent": 1800,
"ascent": 1900,
"descent": 195,
"half_width": 819,
"full_width": 1638
},
"baseline_shift": 49,
"weight": 16
"visualize_zenkaku_space": true,
"baseline_shift": 98,
"weight": 20
},
"nerd": {
"source": "NerdFont.ttf",
Expand Down
Empty file removed source_fonts/.gitkeep
Empty file.
4 changes: 2 additions & 2 deletions src/build_nerd.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
from .utils import (
align_center,
copy_glyph,
get_box_mode,
get_max_box,
get_max_height,
get_max_width,
get_mode_box,
log,
)

Expand Down Expand Up @@ -232,7 +232,7 @@ def modify(
scale = width / fit_target

if valign == "mode_bottom":
_, mode_bottom, _, _ = get_box_mode(glyphs)
_, mode_bottom, _, _ = get_mode_box(glyphs)
shift = (0, -mode_bottom * scale)
else:
_, _, _, max_top = get_max_box(glyphs)
Expand Down
24 changes: 12 additions & 12 deletions src/build_pennywort.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import fontforge
from fontforge import font as Font

from .modify_bizud import modify_bizud
from .modify_hack import modify_hack
from .modify_mgenplus import modify_mgenplus
from .parameter import Parameter
from .utils import log, set_os2_table

Expand All @@ -30,16 +30,16 @@ def open_font(file_name: str) -> Font:
parameter.hack.broken_vline,
)

log("Modify Mgen+")
mgenplus = open_font(parameter.mgenplus.source)
modify_mgenplus(
mgenplus,
parameter.mgenplus.shape_as,
log("Modify BIZUD")
bizud = open_font(parameter.bizud.source)
modify_bizud(
bizud,
parameter.bizud.shape_as,
parameter.shape_to,
parameter.skew,
parameter.mgenplus.visualize_zenkaku_space,
parameter.mgenplus.baseline_shift,
parameter.mgenplus.weight,
parameter.bizud.visualize_zenkaku_space,
parameter.bizud.baseline_shift,
parameter.bizud.weight,
)

log("Load Nerd Font")
Expand All @@ -48,11 +48,11 @@ def open_font(file_name: str) -> Font:
log("Merge fonts")
pennywort = Font()
pennywort.mergeFonts(hack)
pennywort.mergeFonts(mgenplus)
pennywort.mergeFonts(bizud)
pennywort.mergeFonts(nerd)

hack.close()
mgenplus.close()
bizud.close()
nerd.close()

log("Set attributes")
Expand Down Expand Up @@ -111,6 +111,6 @@ def parse_args() -> argparse.Namespace:
log(f"Build {parameter.family_name}-{parameter.style_name}:{VERSION}")
pennywort = build_pennywort(parameter, source_fonts_dir)

output_path = str(Path(args.dst_dir) / f"{pennywort.fullname.replace(' ', '')}.ttf")
output_path = str(Path(args.dst_dir) / f"{pennywort.fullname}.ttf")
log(f"Generate {output_path}")
pennywort.generate(output_path)
32 changes: 16 additions & 16 deletions src/modify_mgenplus.py → src/modify_bizud.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
from .utils import copy_glyph, fit, resize_width


def modify_zenkaku_space(mgenplus: Font) -> None:
def modify_zenkaku_space(bizud: Font) -> None:
space_unicode = 0x3000 # ideographic space

copy_glyph(
(mgenplus, 0x2610), # ballot box
(mgenplus, space_unicode),
(bizud, 0x25A1), # white square
(bizud, space_unicode),
replace=True,
)
copy_glyph(
(mgenplus, 0x271A), # heavy greek cross
(mgenplus, space_unicode),
(bizud, 0x25C6), # black diamond
(bizud, space_unicode),
)

mgenplus.selection.select(space_unicode)
mgenplus.intersect()
mgenplus.selection.none()
bizud.selection.select(space_unicode)
bizud.intersect()
bizud.selection.none()


def modify_mgenplus(
mgenplus: Font,
def modify_bizud(
bizud: Font,
shape_as: GlyphShape,
shape_to: GlyphShape,
skew: float = 0,
Expand All @@ -33,13 +33,13 @@ def modify_mgenplus(
weight: float = 0,
) -> None:
if visualize_zenkaku_space:
modify_zenkaku_space(mgenplus)
modify_zenkaku_space(bizud)

# reshape
original_em = mgenplus.em
mgenplus.ascent = shape_as.ascent
mgenplus.descent = shape_as.descent
for glyph in mgenplus.glyphs():
original_em = bizud.em
bizud.ascent = shape_as.ascent
bizud.descent = shape_as.descent
for glyph in bizud.glyphs():
if glyph.width > original_em / 2:
source_width = shape_as.full_width
target_width = shape_to.full_width
Expand All @@ -61,6 +61,6 @@ def modify_mgenplus(

# italic
if skew:
for glyph in mgenplus.glyphs():
for glyph in bizud.glyphs():
if glyph.isWorthOutputting:
glyph.transform(psMat.skew(skew))
4 changes: 2 additions & 2 deletions src/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class HackConfig(BaseConfig):


@dataclass(frozen=True)
class MgenplusConfig(BaseConfig):
class BizudConfig(BaseConfig):
visualize_zenkaku_space: bool
baseline_shift: float
weight: float
Expand All @@ -46,5 +46,5 @@ class Parameter(DataClassJsonMixin):
upos: int
os2_table: dict
hack: HackConfig
mgenplus: MgenplusConfig
bizud: BizudConfig
nerd: NerdConfig
7 changes: 6 additions & 1 deletion src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ def round_half_up(f: float, e: str = "0") -> Decimal:
return Decimal(str(f)).quantize(Decimal(e), ROUND_HALF_UP)


def calc_actual_size(glyph: Glyph) -> tuple[float, float]:
left, bottom, right, top = glyph.boundingBox()
return (right - left, top - bottom)


def get_max_width(glyphs: list[Glyph]) -> float:
max_width = 0
for glyph in glyphs:
Expand Down Expand Up @@ -48,7 +53,7 @@ def get_max_box(glyphs: list[Glyph]) -> tuple[int, ...]:
return xmin, ymin, xmax, ymax


def get_box_mode(glyphs: list[Glyph]) -> tuple[int, ...]:
def get_mode_box(glyphs: list[Glyph]) -> tuple[int, ...]:
coords: list[tuple[int, ...]] = []
for glyph in glyphs:
coord = glyph.boundingBox()
Expand Down

0 comments on commit c5dfe8a

Please sign in to comment.