Skip to content

Commit

Permalink
name table を設定した
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuya Maruyama committed Oct 31, 2020
1 parent 8b4ab52 commit d5bd36d
Show file tree
Hide file tree
Showing 7 changed files with 253 additions and 84 deletions.
1 change: 1 addition & 0 deletions NOTE.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
```
- lookup rclt は、読みのパターンごとにまとめる。 rclt0 は pattern one。 rclt1 は pattern two。 rclt2 は exception pattern.
- pattern.json はGraphs like
- 横書きのみ想定

# error:

Expand Down
Binary file modified outputs/output.otf
Binary file not shown.
1 change: 1 addition & 0 deletions src/GSUB_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class GSUBTable():

# マージ先のフォントのメインjson(フォントサイズを取得するため), ピンイン表示に使うためのglyfのjson, ピンインのグリフを追加したjson(出力ファイル)
def __init__(self, GSUB, PATTERN_ONE_TXT, PATTERN_TWO_JSON, EXCEPTION_PATTERN_JSON):
# TODO:
# 今は上書きするだけ
# calt も rclt も featute の数が多いと有効にならない。 feature には上限がある?ので、今は初期化して使う
# rclt は calt と似ていて、かつ無効にできないタグ [Tag:'rclt'](https://docs.microsoft.com/en-us/typography/opentype/spec/features_pt#-tag-rclt)
Expand Down
79 changes: 0 additions & 79 deletions src/dont_use_make_pinyin_glyph.py

This file was deleted.

42 changes: 38 additions & 4 deletions src/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import utility
import path as p
import GSUB_table as gt
import name_table as nt

class Font():
def __init__(self, TAMPLATE_MAIN_JSON, TAMPLATE_GLYF_JSON, ALPHABET_FOR_PINYIN_JSON, \
Expand Down Expand Up @@ -46,6 +47,11 @@ def get_advance_size_of_hanzi(self):
verticalOrigin = self.marged_font["glyf"][cid]["verticalOrigin"]
return (advanceWidth, advanceHeight, verticalOrigin)

def get_advance_size_of_pinyin_glyf(self):
# なんでもいいが、とりあえず「yi1」でサイズを取得する
advanceWidth = self.pinyin_glyf["arranged_yi1"]["advanceWidth"]
advanceHeight = self.pinyin_glyf["arranged_yi1"]["advanceHeight"]
return (advanceWidth, advanceHeight)

def add_cmap_uvs(self):
IVS = 0xE01E0 #917984
Expand Down Expand Up @@ -109,10 +115,11 @@ def add_glyph_order(self):
# print(self.marged_font["glyph_order"])

def generate_hanzi_glyf_with_normal_pinyin(self, cid):
(advanceWidth, advanceHeight, verticalOrigin) = self.get_advance_size_of_hanzi()
(advanceWidth, _, verticalOrigin) = self.get_advance_size_of_hanzi()
(_, advanceAddedPinyinHeight) = self.get_advance_size_of_pinyin_glyf()
hanzi_glyf = {
"advanceWidth": advanceWidth,
"advanceHeight": advanceHeight,
"advanceHeight": advanceAddedPinyinHeight,
"verticalOrigin": verticalOrigin,
"references": [
{"glyph":"{}.ss01".format(cid),"x":0, "y":0, "a":1, "b":0, "c":0, "d":1}
Expand All @@ -121,11 +128,12 @@ def generate_hanzi_glyf_with_normal_pinyin(self, cid):
return hanzi_glyf

def generate_hanzi_glyf_with_pinyin(self, cid, pronunciation):
(advanceWidth, advanceHeight, verticalOrigin) = self.get_advance_size_of_hanzi()
(advanceWidth, _, verticalOrigin) = self.get_advance_size_of_hanzi()
(_, advanceAddedPinyinHeight) = self.get_advance_size_of_pinyin_glyf()
simpled_pronunciation = utility.simplification_pronunciation( pronunciation )
hanzi_glyf = {
"advanceWidth": advanceWidth,
"advanceHeight": advanceHeight,
"advanceHeight": advanceAddedPinyinHeight,
"verticalOrigin": verticalOrigin,
"references": [
{"glyph":"arranged_{}".format(simpled_pronunciation),"x":0, "y":0, "a":1, "b":0, "c":0, "d":1},
Expand Down Expand Up @@ -225,6 +233,30 @@ def add_GSUB(self):
GSUB = gt.GSUBTable(self.marged_font["GSUB"], self.PATTERN_ONE_TXT, self.PATTERN_TWO_JSON, self.EXCEPTION_PATTERN_JSON)
self.marged_font["GSUB"] = GSUB.get_GSUB_table()

def set_about_size(self):
(_, advanceAddedPinyinHeight) = self.get_advance_size_of_pinyin_glyf()
if advanceAddedPinyinHeight > self.marged_font["head"]["yMax"]:
# すべてのグリフの輪郭を含む範囲
self.marged_font["head"]["yMax"] = advanceAddedPinyinHeight
if advanceAddedPinyinHeight > self.marged_font["hhea"]["ascender"]:
# 原点からグリフの上端までの距離
self.marged_font["hhea"]["ascender"] = advanceAddedPinyinHeight
# 特定の言語のベースライン
# self.marged_font["BASE"]["hani"]

def set_copyright(self):
# フォント製作者によるバージョン
self.marged_font["head"]["fontRevision"] = nt.VISION
# 作成日(基準日:1904/01/01 00:00 GMT)
from datetime import datetime
base_date = datetime.strptime("1904/01/01 00:00", "%Y/%m/%d %H:%M")
base_time = base_date.timestamp()
now_time = datetime.now().timestamp()
self.marged_font["head"]["created"] = round( now_time - base_time )
# フォント名等を設定
self.marged_font["name"] = nt.name_table


def load_json(self):
with open(self.TAMPLATE_MAIN_JSON, "rb") as read_file:
self.marged_font = orjson.loads(read_file.read())
Expand All @@ -250,6 +282,8 @@ def build(self, OUTPUT_FONT):
print("glyf table を追加完了")
self.add_GSUB()
print("GSUB table を追加完了")
self.set_about_size()
self.set_copyright()
TAMPLATE_MARGED_JSON = os.path.join(p.DIR_TEMP, "template.json")
self.save_as_json(TAMPLATE_MARGED_JSON)
self.convert_json2otf(TAMPLATE_MARGED_JSON, OUTPUT_FONT)
211 changes: 211 additions & 0 deletions src/name_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
# -*- coding: utf-8 -*-
#!/usr/bin/env python'


VISION = 1.0123

name_table = [
{
"platformID": 1,
"encodingID": 0,
"languageID": 0,
"nameID": 0,
"nameString": "Copyright � 2017 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'.\n\n[萌神PROJECT]\nCopyright(c) 2020 mengshen project"
},
{
"platformID": 1,
"encodingID": 0,
"languageID": 0,
"nameID": 1,
"nameString": "Mengshen"
},
{
"platformID": 1,
"encodingID": 0,
"languageID": 0,
"nameID": 2,
"nameString": "Regular"
},
{
"platformID": 1,
"encodingID": 0,
"languageID": 0,
"nameID": 3,
"nameString": "1.001;MENGSHEN;Mengshen-Regular;MENGSHEN"
},
{
"platformID": 1,
"encodingID": 0,
"languageID": 0,
"nameID": 4,
"nameString": "Mengshen"
},
{
"platformID": 1,
"encodingID": 0,
"languageID": 0,
"nameID": 5,
"nameString": "Version {}".format(VISION)
},
{
"platformID": 1,
"encodingID": 0,
"languageID": 0,
"nameID": 6,
"nameString": "Mengshen-Regular"
},
{
"platformID": 1,
"encodingID": 0,
"languageID": 0,
"nameID": 7,
"nameString": "Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries."
},
{
"platformID": 1,
"encodingID": 0,
"languageID": 0,
"nameID": 8,
"nameString": "Adobe Systems Incorporated"
},
{
"platformID": 1,
"encodingID": 0,
"languageID": 0,
"nameID": 9,
"nameString": "[Source Han Sans]\nRyoko NISHIZUKA (kana & ideographs); Frank Grie�hammer (Latin, Greek & Cyrillic); Wenlong ZHANG (bopomofo); Sandoll Communications , Soohyun PARK , Yejin WE & Donghoon HAN (hangul elements, letters & syllables)\n\n[mengshen project]"
},
{
"platformID": 1,
"encodingID": 0,
"languageID": 0,
"nameID": 10,
"nameString": "Dr. Ken Lunde (project architect, glyph set definition & overall production); Masataka HATTORI (production & ideograph elements)"
},
{
"platformID": 1,
"encodingID": 0,
"languageID": 0,
"nameID": 11,
"nameString": "http://www.mengshen-project.com/"
},
{
"platformID": 1,
"encodingID": 0,
"languageID": 0,
"nameID": 13,
"nameString": "This Font Software is licensed under the SIL Open Font License, Version 1.1. This Font Software is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the SIL Open Font License for the specific language, permissions and limitations governing your use of this Font Software."
},
{
"platformID": 1,
"encodingID": 0,
"languageID": 0,
"nameID": 14,
"nameString": "http://scripts.sil.org/OFL"
},
{
"platformID": 3,
"encodingID": 1,
"languageID": 1033,
"nameID": 0,
"nameString": "Copyright © 2017 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'.\n\n[萌神PROJECT]\nCopyright(c) 2020 mengshen project"
},
{
"platformID": 3,
"encodingID": 1,
"languageID": 1033,
"nameID": 1,
"nameString": "Mengshen-Regular"
},
{
"platformID": 3,
"encodingID": 1,
"languageID": 1033,
"nameID": 2,
"nameString": "Regular"
},
{
"platformID": 3,
"encodingID": 1,
"languageID": 1033,
"nameID": 3,
"nameString": "1.001;MENGSHEN;Mengshen-Regular;MENGSHEN"
},
{
"platformID": 3,
"encodingID": 1,
"languageID": 1033,
"nameID": 4,
"nameString": "Mengshen"
},
{
"platformID": 3,
"encodingID": 1,
"languageID": 1033,
"nameID": 5,
"nameString": "Version {}".format(VISION)
},
{
"platformID": 3,
"encodingID": 1,
"languageID": 1033,
"nameID": 6,
"nameString": "Mengshen-Regular"
},
{
"platformID": 3,
"encodingID": 1,
"languageID": 1033,
"nameID": 7,
"nameString": "Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries."
},
{
"platformID": 3,
"encodingID": 1,
"languageID": 1033,
"nameID": 9,
"nameString": "[Source Han Sans]\nRyoko NISHIZUKA 西塚涼子 (kana & ideographs); Paul D. Hunt (Latin, Greek & Cyrillic); Wenlong ZHANG 张文龙 (bopomofo); Sandoll Communication 산돌커뮤니케이션, Soo-young JANG 장수영 & Joo-yeon KANG 강주연 (hangul elements, letters & syllables)\n\n[mengshen project]\Yuya Maruyama 丸山裕也 (Tama)"
},
{
"platformID": 3,
"encodingID": 1,
"languageID": 1033,
"nameID": 10,
"nameString": "Dr. Ken Lunde (project architect, glyph set definition & overall production); Masataka HATTORI 服部正貴 (production & ideograph elements)"
},
{
"platformID": 3,
"encodingID": 1,
"languageID": 1033,
"nameID": 11,
"nameString": "http://www.mengshen-project.com/"
},
{
"platformID": 3,
"encodingID": 1,
"languageID": 1033,
"nameID": 13,
"nameString": "This Font Software is licensed under the SIL Open Font License, Version 1.1. This Font Software is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the SIL Open Font License for the specific language, permissions and limitations governing your use of this Font Software."
},
{
"platformID": 3,
"encodingID": 1,
"languageID": 1033,
"nameID": 14,
"nameString": "http://scripts.sil.org/OFL"
},
{
"platformID": 3,
"encodingID": 1,
"languageID": 1041,
"nameID": 1,
"nameString": "萌神"
},
{
"platformID": 3,
"encodingID": 1,
"languageID": 1041,
"nameID": 4,
"nameString": "萌神"
}
]
Loading

0 comments on commit d5bd36d

Please sign in to comment.