Webフォントは、
Webフォントとは
最近、
この

ローカルのソフトウェアであれば、
そこで、
@font-face {
font-family: "My font"
src: url("http://example.com/fonts/myfont.woff");
}
h1 {
font-family: "My Font", serif;
}
これにより、
モダンなWebブラウザーが一通り@font-faceルールに対応したのに合わせて、
Web Open Font Format(WOFF)
Webフォントはフォントファイルをダウンロードします。しかしながら従来のフォントファイルのサイズは大きく、
そんなフォーマットの1つが、
既存のフォントをWOFFに変換する
実は@font-faceルールは、
そうすると既存のフォントから必要なグリフのみを抽出したファイルを用意して、
なお、
Ubuntuのリポジトリには
woff-toolsを使う
OpenTypeやTrueTypeから一括してWOFFに変換するなら、
$ sudo apt install fonts-kouzan-mouhitsu $ dpkg -L fonts-kouzan-mouhitsu /. /usr /usr/share /usr/share/fonts /usr/share/fonts/truetype /usr/share/fonts/truetype/kouzan-mouhitsu /usr/share/fonts/truetype/kouzan-mouhitsu/kouzan-mouhitsu-gyosho.ttf /usr/share/fonts/truetype/kouzan-mouhitsu/kouzan-mouhitsu.ttf /usr/share/fonts/truetype/kouzan-mouhitsu/kouzan-mouhitsu-sosho.ttf /usr/share/doc /usr/share/doc/fonts-kouzan-mouhitsu /usr/share/doc/fonts-kouzan-mouhitsu/changelog.Debian.gz /usr/share/doc/fonts-kouzan-mouhitsu/copyright
woff-toolsもリポジトリからインストールします。
$ sudo apt install woff-tools
woff-toolsには、
$ cp /usr/share/fonts/truetype/kouzan-mouhitsu/kouzan-mouhitsu.ttf . $ sfnt2woff kouzan-mouhitsu.ttf $ file kouzan-mouhitsu.woff kouzan-mouhitsu.woff: Web Open Font Format, flavor 65536, length 5585588, version 0.0
作成したフォントを使うHTMLファイルを作成してみましょう。
<!DOCTYPE html>
<html><head>
<meta charset="utf-8" />
<title>Webフォント</title>
<style>
@font-face {
font-family: "衡山毛筆Webフォント";
src: url("kouzan-mouhitsu.woff");
}
p {
font-size: 200%;
font-family: "衡山毛筆Webフォント", serif;
}
</style>
</head>
<body>
<p>衡山毛筆フォントのテスト</p>
</body>
</html>
このHTMLファイルをWebブラウザーに読み込ませれば、

メタデータを埋め込む
Webフォントには、
<?xml version="1.0" encoding="UTF-8"?>
<metadata version="1.0">
<uniqueid id="com.example.KouzanMouhitsu"/>
<vendor name="青柳 衡山 (Kouzan Aoyagi)" url="http://opentype.jp/kouzanmouhitufont.htm"/>
<credits>
<credit name="青柳 衡山 (Kouzan Aoyagi)" role="design"/>
</credits>
<description>
<text lang="ja">衡山毛筆フォント for the Web</text>
</description>
<license url="http://opentype.jp/kouzanmouhitufont.htm">
<text lang="ja">
無料でご利用できます。
著作権放棄で完全フリーです。
改編も自由です。
雑誌・書籍への掲載・CD収録も自由です。
使用についての制限はありません。
無保証です。お客様の責任でご利用ください。
</text>
</license>
</metadata>
上記のような情報をmetadata.
$ sfnt2woff -m metadata.xml kouzan-mouhitsu.ttf
FontForgeでグリフを抽出する
woff-toolsはフォントファイルをそのままWOFFに変換します。このため、
古くから存在するフォントエディタであるFontForgeを使うと、
$ sudo apt install fontforge
起動するには端末からfontforgeコマンドを実行するか、


グリフは、
グリフを抽出するには、
FontForgeもWOFFに変更できる機能があるため、

Pythonでグリフを抽出する
FontForgeのUIで、
$ sudo apt install python-fontforge
さらに次のようなPythonスクリプト
#!/usr/bin/env python2
# -*- coding: utf-8; -*-
import sys
import fontforge
def pickup_glyphs(src, dst, strings):
glyphs = []
for c in unicode(strings, 'utf-8'):
glyphs.append(ord(c))
font = fontforge.open(src)
for glyph in glyphs:
font.selection.select(('more', 'unicode'), glyph)
try:
for ref in font[glyph].references:
font.selection.select(('more'), ref[0])
except:
sys.stderr.write("Error: not found for U+{:04x}\n".format(glyph))
font.selection.invert()
font.cut()
font.generate(dst)
font.close()
if __name__ == '__main__':
src = sys.argv[1]
dst = sys.argv[2]
strings = sys.argv[3]
pickup_glyphs(src, dst, strings)
第一引数が元データのフォントファイル、
$ python2 kouzan-mouhitsu.ttf kouzan-subset.woff "毛筆"
上記のように実行すると、
Webフォントを活用しよう
Webフォントを使用すればユーザーの環境に依存することなく、
たとえば和田研細丸ゴシックといった絵文字に対応したフォントをWebフォント化すると、
IPAmj明朝や花園フォントなどの広範囲の異体字に対応したフォントから必要なグリフのみを抽出すれば、
いわゆるWebアプリもレンダリングしているのはWebブラウザーそのものなので、