6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

macOS Catalinaでサブセットフォントメーカーが使えなくなったのでPythonで日本語のWEBフォントを作成する

Posted at

はじめに

macOS Catalinaで、日本語のフォントをサブセット化する人気No.1ツール、サブセットフォントメーカーが使えなくなりました。サブセット化したフォントをwoff、woff2に変換するツール、WOFFコンバータも同様に使えなくなっています。ツールのアップデートを待ちつつ、Pythonのライブラリを使って日本語のWEBフォントを作ってみようと思います。

環境の確認

Pythonが入っているか確認

$ which python
/usr/local/bin/python

pipが入っているか確認

$ which pip
/usr/local/bin/pip

# ついでにpipをアップデート
$ pip install --upgrade pip

お好きな日本語フォントを準備

今回は、Hannari.otf (はんなり明朝)。

インストール

fontTools のインストール

https://github.com/fonttools/fonttools

$ pip install fonttools

Brotliのインストール

https://github.com/google/brotli

$ pip install brotli

変換コマンド

フォントをサブセット化しつつ、woffとwoff2をそれぞれ作成します。

pyftsubset Hannari.otf --text-file=web-font.txt --layout-features='*' --flavor=woff --output-file=public/stylesheets/Hannari.woff
pyftsubset Hannari.otf --text-file=web-font.txt --layout-features='*' --flavor=woff2 --output-file=public/stylesheets/Hannari.woff2

最初の引数: オリジナルのフォント
--text-file: WEBフォントに格納したい文字を書いたテキストファイル
--layout-features: '*'(すべて)
--flavor: woffかwoff2
--output-file: 出力ファイル名

上記のコマンドを.shファイルなどに書くことで、次回からは一発で日本語フォントのサブセット化、およびwoff、woff2の作成をすることができますね。

参考URL

6
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?