Source Han Sans / 源ノ角ゴシック をビルドする
Source Han Sans、源ノ角ゴシック。すてきなフォントがApache License 2.0というオープンなライセンスでリリースされた。すばらしい。
Source Han Sansは、7つのウエイトが利用可能で、日本語と韓国語で用いる文字および中国語で用いる繁体字と簡体字のグリフのバリエーションすべてに完全に対応する 書体ファミリーです。
- The Typekit Blog | Source Han Sansの紹介:オープンソースのPan-CJK書体
- オープンソースの美しい Noto フォントファミリーに日本語、中国語、韓国語が加わりました。 - Google Developer Relations Japan Blog
- Source Han Sans / Home / Home
- adobe-fonts/source-han-sans
Adobeからは Source Han Sans Japanese / 源ノ角ゴシックとして、Googleからは Noto Sans Japanese としてリリースされている。
普通に使うぶんには、こちらからダウンロードすればいい。
GitHubのリポジトリでは、Source Han Sansのソースが公開され、ビルド方法も書いてあった。なのでやってみた。
READMEを読むと、Adobe Font Development Kit for OpenType (AFDKO) が必要で、AFDKOに含まれるmakeotfを使うことがわかる。細かいことはCOMMANDS.txtを読んでねって感じ。
Adobe Font Development Kit for OpenType (AFDKO)のインストール
AFDKOがなんだかさっぱりわからないけど、インストールする。下のほうのリンクから、使用許諾に同意して、ダウンロードして適当なディレクトリに解凍する。Macでビルドするので、Mac版をダウンロードした。
FDKってディレクトリにRead_Me_First.htmlがあるのでまず読む。こんなことが書いてある。
- Download the AFDKO archive file and decompress it.
- You should now have a folder named "FDK". Move it to where you want.
- Open a Terminal window (Terminal is located in /Applications/Utilities/Terminal).
- Open the "FDK" folder and locate the file named "FinishInstallOSX".
- Select the "FinishInstallOSX" file, drag & drop it on the Terminal window, and press the "Return" key.
- If FinishInstallOSX complains that it does not have permission to make the changes, type "sudo " (no quotes and keep the final space) before doing step 5. The results in the command line "sudo FinishInstallOSX". This command will prompt you for the system administrator password, which will allow FinishInstallOSX to complete its work.
- Close the Terminal window.
FinishInstallOSXというファイルがあるから、それをターミナルにドラッグアンドドロップして、実行してね、と。個人的には、これは実行しないほうがいいと思う。あれこれいけてない。実行するとこんなメッセージが表示される。
Adding a symbolic link from '/Users/sada/bin' to the FDK directory /Users/sada/Downloads/FDK.
そんな変なシンボリックリンク、勝手に張らないでくれよ…。そして .profile と .bash_profile と .zprofile にパスを追加したぜってメッセージがでてくる。
というわけで、シンボリックリンク消して、追加されたパスを削除して、自分で適当になんとかする。
mv ~/Downloads/FDK ~/Library
zshを使っているので、.zshrcをこんな感じに修正。このあたりは、それぞれの環境によって設定が変わってくると思う。そのままコピペするとあれこれ動かなくなったりするので注意が必要。
export FDK_EXE=$HOME/Library/FDK/Tools/osx export PATH=$FDK_EXE:$PATH
.zshrcを再読込する。
source ~/.zshrc
autohint -h
でなにか出てくれば、OKみたい。
autohint -h
やれやれ。
Source Han Sansのビルド
COMMANDS.txtにはこんなことが書いてある。ふうむ。
Command line for building the multilingual Japanese-default OTFs
makeotf -f cidfont.ps -ff features -fi cidfontinfo -mf ../FontMenuNameDB -r -nS -cs 1 -ch ../UniSourceHanSansJP-UTF32-H -ci ../SourceHanSans_JP_sequences.txt
Command lines for building the region-specific subset OTFs
Japanese
makeotf -f cidfont.ps.JP -ff features.JP -fi cidfontinfo.JP -mf ../FontMenuNameDB.SUBSET -r -nS -cs 1 -ch ../UniSourceHanSansJP-UTF32-H -ci ../SourceHanSans_JP_sequences.txt
まずはソースをとってくる。リポジトリをクローンしてもいいし、右下の Download Zip でもいい。
適当なディレクトリで git clone
する。1.4GBくらいあるので、心してcloneする。
git clone https://github.com/adobe-fonts/source-han-sans.git
あとはそれぞれのウェイトのディレクトリで、さっきのコマンドを実行すればいいみたい。multilingual Japanese-default OTFs と region-specific subset OTFs の違いは、あんまりよくわからないけど、なんとなくわかる気もするので、日本語の region-specific subset OTFs を作ってみる。
cloneしたsource-han-sansのディレクトリに移動して、さらにウェイトごとのディレクトリに移動する。今回はExtraLightのフォントをビルドする。
cd source-han-sans cd ExtraLight
COMMAND.txtの通りにmakeotfする。
makeotf -f cidfont.ps.JP -ff features.JP -fi cidfontinfo.JP -mf ../FontMenuNameDB.SUBSET -r -nS -cs 1 -ch ../UniSourceHanSansJP-UTF32-H -ci ../SourceHanSans_JP_sequences.txt
なんかいろいろでてくる。
makeotf [Warning] Could not find an Adobe CMAP Mac encoding mapping file. If you want a Mac cmap subtable, please specify the Mac CMAP encoding file with the '-cm' option. makeotf [Note] setting the DONT_USE_WIN_LINE_METRICS OS/2 fsSelection bit 7 from fontinfo keyword. makeotf [Note] setting the WEIGHT_WIDTH_SLOPE_ONLY OS/2 fsSelection bit 8 from fontinfo keyword. makeotf [Note] setting the OBLIQUE OS/2 fsSelection bit 9 from fontinfo keyword. makeotf [Note] Writing options file ./current.fpr makeotf [Note] Running makeotfexe with commands: cd "/Users/sada/Documents/source-han-sans/ExtraLight" makeotfexe "-f" "cidfont.ps.JP" "-o" "SourceHanSansJP-ExtraLight.otf" -ff "features.JP" -mf "../FontMenuNameDB.SUBSET" -r -nS -cs "1" -ch "../UniSourceHanSansJP-UTF32-H" -ci "../SourceHanSans_JP_sequences.txt" -lic "ADOBE" -osv "4" -osbOn "7" -osbOn "8" makeotfexe [WARNING] <SourceHanSansJP-ExtraLight> cmap{plat=1,script=1,lang=0}: empty encoding makeotfexe [WARNING] <SourceHanSansJP-ExtraLight> Macintosh Adobe CMap not seen makeotfexe [NOTE] <SourceHanSansJP-ExtraLight> cmap{plat=0,script=5,lang=0}: Number of default Unicode Variation Sequence values 13307 makeotfexe [NOTE] <SourceHanSansJP-ExtraLight> cmap{plat=0,script=5,lang=0}: Number of non-default UVS values 1460 makeotfexe [NOTE] Wrote new font file 'SourceHanSansJP-ExtraLight.otf'. Built release mode font 'SourceHanSansJP-ExtraLight.otf' Revision 1.000 Done.
SourceHanSansJP-ExtraLight.otf ができた!これをダブルクリックすると、ちゃんとインストールできる。
まとめ
フォントをビルドしたのは初めてだった。こんなふうにオープンソースなフォントがリリースされなければ、フォントをビルドすることなんてなかったと思う。
ほんとうは使いたいグリフのみを含んだサブセット化されたフォントを作りたかったんだけど、あれこれ調べてみても方法がわからなかった…。AFDKOのドキュメントをちゃんと読んで、フォントの作り方をもうちょっと勉強しないと無理そう。また頑張ろう。
これまでもオープンソースの恩恵をたくさん頂いている。こういったフォントがオープンソースになっているというのは、ほんとうにすごい。
例えばLeanPubとかで源ノ角ゴシックがサポートされれば、きれいな日本語フォントの電子書籍が読めるようになるかもしれない。
こちらを読んでみると、実際に組み込んでもらうこともできそうな気がする。
日本に限らず、WebFontsのサービスが源ノ角ゴシックをサポートしてくれれば、より手軽に日本語のWebFontsを利用できる。
GitHubのissuesにはバグ報告や質問が集まって、いろいろなやりとりが行われている。オープンソースのエコシステムが動いてる。すてきだ。
源ノ角ゴシックの、角がちょっとぴんっとしているところがエレガントですてき。これから、いろいろたのしみ。