处理js将处理与Processing Java不同的字体。处理中Java字体从您的机器中提取。看到你的字体列表运行这个。
size(200, 200);
String[] fontList = PFont.list();
printArray(fontList);
作为一名设计师,我喜欢使用不是每个人都会安装的自定义字体。因此,您需要将一个字体版本上传到您的服务器,以便所有用户都能在网络上获得相同的体验。
首先将其添加到草图顶部,然后将字体添加到数据文件夹。根据您的项目设置,您可能需要将其添加到目录的顶部。
/* @pjs
crisp=true;
font=/yourfont.ttf;
*/
接下来,在你的设置参考字体。 (这是我遇到的一些问题)我正在加载lineto-brown-pro-bold.ttf
,并且必须在Brown
之下引用它,即使在我的字体列表中它也是Brown-bold
。将此行添加到您的设置中。
font_name = createFont("/yourfont.ttf", 32);
,并在你的画用
textFont(font_name);
因此,代码一起是
/* @pjs
crisp=true;
font=/yourfont.ttf;
*/
PFont font_name;
void setup() {
size (200, 330);
background (34);
font_name = createFont("/yourfont", 32);
smooth();
}
void draw() {
background (34);
textFont(font_name);
textSize(100);
fill(255);
text ("futura in pjs", 20, 310);
}
欲了解更多信息,请查阅处理。js文档http://processingjs.org/reference/font/ 也是一个很好的例子,写在http://alsoko.net/processing.js-custom-fonts/