結論
dataフォルダーのなかにttfファイルなどを置き、それをcreateFont()でPFontを取得できる
それをtextFont()で設定する
例
textFont(createFont("font.ttf", 64));
過程
先週、あのフォントを使いたい!と思ったのですが、
void setup()
{
textFont(createFont("KHドット秋葉原16", 32, true));
}
void draw()
{
text("abcあいう", 0, height);
}
このコードを実行すると、
"KHドット秋葉原16" is not available, so another font will be used. Use PFont.list() to show available fonts.
というエラーを吐いた
コンピュータにインストールしてあるフォントなのですが、ダメらしい
試しにPFont.list()を確認する
String[] list = PFont.list();
for (int i = 0; i < list.length; i++)
{
println(i + ":" + list[i]);
}
0:Agency FB
1:Agency FB Bold
2:Algerian
(省略)
258:KHドット秋葉原16
(後略)
KHドット秋葉原16が存在していた
String[] list = PFont.list();
for (int i = 0; i < list.length; i++)
{
textFont(createFont(list[i],64, true));
}
"Bahnschrift Bold" is not available, so another font will be used. Use PFont.list() to show available fonts.
"Bahnschrift Bold Condensed" is not available, so another font will be used. Use PFont.list() to show available fonts.
(省略)
"KHドット秋葉原16" is not available, so another font will be used. Use PFont.list() to show available fonts.
(後略)
やはり、PFont.list()の中に書いてあるフォント全てが使えるわけではなさそうだ
また、Processingの開発ツールの「ツール」の「フォント作成」では、選べるフォントが全て英語だった(私の環境だけ?
公式リファレンスを見てみると、
https://processing.org/reference/createFont_.html
When sharing a sketch with other people or posting it on the web, you may need to include a .ttf or .otf version of your font in the data directory of the sketch because other people might not have the font installed on their computer.
他の人とスケッチを共有したり、Webに投稿したりする場合、他の人がフォントをコンピューターにインストールしていない可能性があるため、スケッチのデータディレクトリにフォントの.ttfまたは.otfバージョンを含める必要があります。(グーグル翻訳より)
dataフォルダーの中にttfファイルなどを置き、それをロードすることができるらしい
textFont(createFont("KH-Dot-Akihabara-16.ttf", 64, true));
これで無事に好きなフォントを使うことができた