🖋️2020-05-27 🔄2020-05-27
by shibanyan_1

fontforgeでotfからttfに変換する

fontforge Noto ttf

fontforgeとは #

FontForgeは、Windows、Mac OS X、およびGNU + Linux向けの無料の(ライブラリ)GUIを持ったフォントエディタです。 OpenType、TrueType、UFO、CID-keyed、Multiple Master、およびその他の多くのフォーマットでフォントを作成、編集、変換するために使用します。

今回はOpenTypeフォントであるNoto Sans JPTrueTypeに変換する目的で、WSLのCLIから使用します。

fontforgeのインストール #

apt install fontforge

だとめちゃめちゃ古い(6年前?)のでソースからコンパイルします

fontforgeのビルド #

ここの通りです
fontforge/INSTALL.md at master · fontforge/fontforge

  1. git cloneまたはreleasesからソースコードをダウンロード
# [email protected]はお使いの環境(.ssh/configのHost)に合わせる
git clone [email protected]:fontforge/fontforge.git
  1. 依存関係をインストール
sudo apt install libjpeg-dev libtiff5-dev libpng-dev libfreetype6-dev libgif-dev libgtk-3-dev libxml2-dev libpango1.0-dev libcairo2-dev libspiro-dev libuninameslist-dev python3-dev ninja-build cmake build-essential
  1. ビルド
cd fontforge
mkdir build
cd build
cmake -GNinja ..
ninja
sudo ninja install
  1. 確認
    この時点でどの場所でもfontforgeが実行できるようになっています。
fontforge
Copyright (c) 2000-2020. See AUTHORS for Contributors.
 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
 with many parts BSD <http://fontforge.org/license.html>. Please read LICENSE.
 Version: 20200314
 Based on sources from 2020-05-27 03:04 UTC-ML-D-GDK3.
Unable to init server: Could not connect: Connection refused

(fontforge:9966): Gdk-WARNING **: 12:17:59.322: cannot open display:

fontforgeコマンド一覧 #

fontforge --help
Copyright (c) 2000-2020. See AUTHORS for Contributors.
 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
 with many parts BSD <http://fontforge.org/license.html>. Please read LICENSE.
 Version: 20200314
 Based on sources from 2020-05-27 03:04 UTC-ML-D-GDK3.
fontforge [options] [fontfiles]
        -new                     (creates a new font)
        -last                    (loads the last sfd file closed)
        -recover none|auto|inquire|clean (control error recovery)
        -allglyphs               (load all glyphs in the 'glyf' table
                         of a truetype collection)
        -nosplash                (no splash screen)
        -quiet                   (don't print non-essential information to stderr)
        -unique                  (if a fontforge is already running open
                         all arguments in it and have this process exit)
        -display display-name    (sets the X display)
        -depth val               (sets the display depth if possible)
        -vc val                  (sets the visual class if possible)
        -cmap current|copy|private       (sets the type of colormap)
        -dontopenxdevices        (in case that fails)
        -sync                    (syncs the display, debugging)
        -keyboard ibm|mac|sun|ppc  (generates appropriate hotkeys in menus)
        -usecairo=yes|no  Use (or not) the cairo library for drawing
        -help                    (displays this message, and exits)
        -docs                    (displays this message, invokes a browser)
                                 (Using the BROWSER environment variable)
        -version                 (prints the version of fontforge and exits)
        -library-status  (prints information about optional libraries
                                 and exits)
        -lang=py                 use python for scripts (may precede -script)
        -lang=ff                 use fontforge's legacy scripting language
        -script scriptfile       (executes scriptfile)
                must be the first option (or follow -lang).
                All others passed to scriptfile.
        -dry scriptfile          (syntax checks scriptfile)
                must be the first option. All others passed to scriptfile.
                Only for fontforge's own scripting language, not python.
        -c script-string         (executes argument as scripting cmds)
                must be the first option. All others passed to the script.

FontForge will read postscript (pfa, pfb, ps, cid), opentype (otf),
        truetype (ttf,ttc), macintosh resource fonts (dfont,bin,hqx),
        and bdf and pcf fonts. It will also read its own format --
        sfd files.
If no fontfiles are specified (and -new is not either and there's nothing
        to recover) then fontforge will produce an open font dlg.
If a scriptfile is specified then FontForge will not open the X display
        nor will it process any additional arguments. It will execute the
        scriptfile and give it any remaining arguments
If the first argument is an executable filename, and that file's first
        line contains "fontforge" then it will be treated as a scriptfile.

For more information see:
        http://fontforge.sourceforge.net/
Send bug reports to:    [email protected]

fontforge CLIでotfをttfに変換 #

fontforge Noto ttf
fontforge -lang=ff -c 'Open($1); CIDFlatten(); Generate($1:r+".ttf"); Quit(0);' NotoSansJP-Medium.otf NotoSansJP-Medium.ttf

-lang=ffをつけないとinvalid syntaxと怒られるよ

  File "<string>", line 1
    from sys import argv; from fontforge import *; Open($1); CIDFlatten(); Generate($1:r+".ttf"); Quit(0);
                                                        ^
SyntaxError: invalid syntax

fontforgeによるotf->ttf変換 - Qiita

fonts - Convert in command line an sfd file (fontforge) to ttf, otf, woff, svg - Unix & Linux Stack Exchange