Skip to content

Commit

Permalink
fixed some kanji glyphs
Browse files Browse the repository at this point in the history
  • Loading branch information
mshioda committed May 23, 2021
1 parent 08479d1 commit d550465
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 25 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Changelog
==========

1.03 (2021-05-23)
-----------------

- Fixed for `python3-fontforge` library
- Add conversion script of resource fonts from OTF to TTF
- Fixed segmentation fault when open otf
- Fixed some Kanji glyphs from old style to modern style
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ You can get the fonts from [here](https://github.com/mshioda/relaxed-typing-mono
## How to Generate
1. Download Source Code Pro (TTF) and Noto Sans JP (OTF)
2. Put them in `resources` directory
3. Execute `script.py` (required `fontforge` Python library)
3. Execute `conv-ttf.sh` (required `otf2ttf`)
4. Execute `script.py` (required `fontforge` Python library)
3 changes: 2 additions & 1 deletion README_jp.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ Relaxed Typing Mono JP は、Source Code Pro と Noto Sans JP の派生フォン
## 生成の仕方
1. Source Code Pro(TTF)と Noto Sans JP(OTF)をダウンロードしてください
2. それらを `resources` ディレクトリに入れます
3. `script.py` を実行します(`fontforge` Python ライブラリが必要です)
3. `conv-ttf.sh` を実行します(`otf2ttf` が必要です)
4. `script.py` を実行します(`fontforge` Python ライブラリが必要です)
6 changes: 6 additions & 0 deletions conv-ttf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
for otf in ./resources/NotoSansJP-*.otf; do
ttf=${otf%.otf}.ttf
if [ ! -f ${ttf} ]; then
otf2ttf ${otf} ${ttf}
fi
done
44 changes: 22 additions & 22 deletions script.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import fontforge
import psMat
from sys import stderr, argv
from os import path, system
from compat_map import compat_map
from glyph_filter import ranges as filter_ranges
from os2_weights import os2_weights
from version import version

weight = "Regular" if len(argv) == 1 else argv[1]

if not os2_weights.has_key(weight):
raise Exception("Unknown weight: {}".format(weight))
if weight not in os2_weights:
raise Exception(f"Unknown weight: {weight}")

latin = fontforge.open("./resources/SourceCodePro-{}.ttf".format(weight))
hans = fontforge.open("./resources/NotoSansJP-{}.otf".format(weight))
if not path.exists(f"./resources/NotoSansJP-{weight}.ttf"):
system("bash ./conv-ttf.sh")

latin = fontforge.open(f"./resources/SourceCodePro-{weight}.ttf")
han = fontforge.open(f"./resources/NotoSansJP-{weight}.ttf")

filters = [range(x[0], x[1]) for x in filter_ranges]

Expand All @@ -23,11 +27,10 @@ def is_halfwidth(codepoint):
return 0xFF61 <= codepoint <= 0xFFDC or 0xFFE8 <= codepoint <= 0xFFEE

def do_paste(glyph):
hans.selection.select(glyph.glyphname)
hans.copy()
han.selection.select(glyph.unicode)
han.copy()

code = compat_map.get(glyph.unicode)
if code is None: code = glyph.unicode
code = compat_map.get(glyph.unicode) or glyph.unicode

latin.selection.select(code)
latin.paste()
Expand All @@ -41,17 +44,15 @@ def do_paste(glyph):
else:
latin[code].width = 1024
except Exception as err:
stderr.write("E: {}\n".format(hex(code)))
stderr.write(f"E: {hex(code)}\n")
print(err)

hans.selection.none()
han.selection.none()
latin.selection.none()


def do_merge(cid_number):
hans.cidsubfont = cid_number

for g in hans.glyphs():
def do_merge():
for g in han.glyphs():
if any([g.unicode in x for x in filters]):
do_paste(g)

Expand All @@ -63,25 +64,24 @@ def do_merge(cid_number):

latin.selection.none()

for n in range(1, 17):
do_merge(n)
do_merge()

latin.fontname = "RelaxedTypingMonoJP-{}".format(weight)
latin.fontname = f"RelaxedTypingMonoJP-{weight}"
latin.familyname = "Relaxed Typing Mono JP"
latin.fullname = "Relaxed Typing Mono JP-{}".format(weight)
latin.fullname = f"Relaxed Typing Mono JP-{weight}"
latin.os2_weight = os2_weights[weight]
latin.os2_vendor = "MSHD"
latin.sfntRevision = float(version)
latin.version = version
latin.copyright = """Source Code Pro:
{}
latin.copyright = f"""Source Code Pro:
{sfnt_find_first("Copyright")[2]}
Noto Sans JP:
Copyright -2020 Adobe (http://www.adobe.com/), with Reserved Font Name 'Source'.
Relaxed Typing Mono JP:
Copyright 2020 SHIODA Masaharu, with Reserved Font Name 'Relaxed Typing Mono'.
""".format(sfnt_find_first("Copyright")[2])
"""
latin.sfnt_names = ()

latin.generate("RelaxedTypingMonoJP-{}.ttf".format(weight))
latin.generate(f"RelaxedTypingMonoJP-{weight}.ttf")
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "1.02"
version = "1.03"

0 comments on commit d550465

Please sign in to comment.