Skip to content

Instantly share code, notes, and snippets.

@h20y6m
Last active January 4, 2024 08:29
Show Gist options
  • Save h20y6m/2dbeb4c901385443b7e06f6927a9c432 to your computer and use it in GitHub Desktop.
Save h20y6m/2dbeb4c901385443b7e06f6927a9c432 to your computer and use it in GitHub Desktop.
IPAmj明朝VF作成

ref. https://h20y6m.github.io/posts/2023-12-02-texadvent2023/

使い方

  1. zrotfdump.pl を入手
  2. zrotfdump.pl を使用して ipamjm.ttf からグリフ一覧を取得
$ perl zrotfdump.pl name ipamjm.ttf > ipamjm-name.txt
  1. この ipamjm.py を使って ZVP ファイルを作成
$ python3 ipamjm.py
  1. ZVP から VF/JFM を作成
$ jfmutil zvp2vf ipamjmm--h
$ jfmutil zvp2vf ipamjmm--v

メモ

Windows の TeX Live に同梱されている perl を使うときは zrotfdump.pl の 41 行目をコメントアウトする。

#use Data::Dump 'dump';
#!/usr/bin/env python3
import re
IPAmjMinchoVersion = '006.01'
mjn2gid = {}
with open('ipamjm-name.txt') as f:
for line in f:
m = re.match(r'^(\d+)\tmj(\d+)$', line)
if m:
gid = int(m.group(1))
mjn = int(m.group(2))
mjn2gid[mjn] = gid
mjns = sorted(mjn2gid.keys())
mjnr = []
for mjn in mjns:
if len(mjnr) > 0 and mjnr[len(mjnr)-1][1] == mjn - 1:
mjnr[len(mjnr)-1][1] = mjn
else:
mjnr.append([mjn, mjn])
for dir in ['h', 'v']:
with open(f'ipamjmm--{dir}.zvp', 'w') as f:
def outvp(s):
f.write(s)
f.write('\n')
charht = '0.88'
chardp = '0.12'
if dir == 'v':
charht = '0.5'
chardp = '0.5'
outvp( '(DIRECTION TATE)')
outvp(f'(VTITLE IPAmjMincho{IPAmjMinchoVersion})')
outvp( '(FAMILY IPAMJM KANJI)')
outvp( '(FACE F MRR)')
outvp( '(CODINGSCHEME TEX KANJI TEXT)')
outvp( '(DESIGNSIZE R 10.0)')
outvp( '(CHECKSUM O 0)')
outvp( '(FONTDIMEN')
outvp( ' (SLANT R 0.0)')
outvp( ' (SPACE R 0.0)')
outvp( ' (STRETCH R 0.1)')
outvp( ' (SHRINK R 0.0)')
outvp( ' (XHEIGHT R 1.0)')
outvp( ' (QUAD R 1.0)')
outvp( ' (EXTRASPACE R 0.25)')
outvp( ' (EXTRASTRETCH R 0.2)')
outvp( ' (EXTRASHRINK R 0.125)')
outvp( ' )')
outvp( '(MAPFONT D 0')
outvp(f' (FONTNAME ipamjm-mzm-{dir})')
outvp( ' (FONTCHECKSUM O 0)')
outvp( ' (FONTAT R 1.0)')
outvp( ' (FONTDSIZE R 10.0)')
outvp( ' )')
outvp( '(CODESPACE')
for [mjn1, mjn2] in mjnr:
if mjn1 == mjn2:
outvp(f' X{mjn1:X}')
else:
outvp(f' (CTRANGE H {mjn1:X} H {mjn2:X})')
outvp( ' )')
outvp( '(TYPE D 0')
outvp( ' (CHARWD R 1.0)')
outvp(f' (CHARHT R {charht})')
outvp(f' (CHARDP R {chardp})')
outvp( ' (MAP)')
outvp( ' )')
for mjn in mjns:
gid = mjn2gid[mjn]
outvp(f'(CHARACTER H {mjn:X}')
outvp( ' (MAP')
outvp(f' (SETCHAR H {gid:X})')
outvp( ' )')
outvp( ' )')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment