我有一个 Canvas 。它要求用户从 A-Z、a-z 或 0-9 中绘制一个字符。一旦用户画了一个字符,比如 A,当前的 Canvas 对象就会保存在一个 Canvas 数组列表中。然后弹出另一个空白 Canvas ,要求用户绘制 B。等等。
程序运行良好。但我想创建一个 .ttf
文件,其中包含所有接受的字符。
我在最后一个显示的 Canvas 下方有一个按钮,单击该按钮时,将从 Canvas 的数组列表中提取所有字符并从中创建一个 .ttf
文件。但是怎么做?
最佳答案
我使用过这个库: fontastic font maker
这就是它的工作原理:
如何创建一个新的 Fontastic 对象:
Fontastic f = new Fontastic(this, "ExampleFont"); // Create a new Fontastic object
如何设置更多字体属性:
f.setAuthor("Andreas Koller"); // Set author name - will be saved in TTF file too
如何为字符 A 创建一个具有四个点的随机形状的字形(这里将是您之前从用户那里收集的点(或标准化点)):
PVector[] points = new PVector[4]; // Define a PVector array containing the points of the shape
points[0] = new PVector(0, 0); // Start at bottom left
points[1] = new PVector(random(512), 0); // The normal width is 512, the normal height 1024
points[2] = new PVector(random(512), random(1024)); // y coordinates are from bottom to top!
points[3] = new PVector(0, random(1024));
f.addGlyph('A').addContour(points); // Assign contour to character A
如何生成TrueType字体文件:
f.buildFont(); // Build the font resulting in .ttf and .woff files
// and a HTML template to preview the WOFF
关于java - 使用 javafx 创建 Truetype 字体文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26332766/