Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a Truetype Font file with javafx

I have a canvas. It asks the user to draw a character from A-Z, a-z or 0-9. once the user draws a character say A, the current canvas object is saved in an arraylist of canvases. and another blank canvas pops up that asks the user to draw B. and so on.

The programs works fine. But I want to create a .ttf file with all the accepted characters drawn.

I have a button below the last displayed canvas which when clicked, will extract all chars from the arraylist of canvases and create a .ttf file from it. But how?

like image 454
Aditya Singh Avatar asked Oct 13 '14 04:10

Aditya Singh


People also ask

Is it better to install OTF or TTF?

OTF is more likely to be a “better” font, as it supports more advanced typesetting features (smallcaps, alternates, ligatures and so on actually inside the font rather than in fiddly separate expert set fonts).

Are TTF files binary?

A TrueType font file is a binary file that consists of a sequence of concatenated tables. Each table is a sequence of words and has a name known as Tag .

What does a TTF file contain?

A TrueType font is a binary file containing a number of tables. There is a directory of tables at the start of the file. The file may contain only one table of each type, and the type is indicated by a case-sensitive four letter tag. Each table and the whole font have checksums.


1 Answers

I have used this library: fontastic font maker

And that is how it works:

How to create a new Fontastic object:

Fontastic f = new Fontastic(this, "ExampleFont");  // Create a new Fontastic object 

How to set further font properties:

f.setAuthor("Andreas Koller");                  // Set author name - will be saved in TTF file too 

How to create a glyph for the character A with a random shape of four points(so here would be the points(or normalized points), which you have gathered before from user):

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 

How to generate the TrueType font file:

f.buildFont();                                  // Build the font resulting in .ttf and .woff files                                                 // and a HTML template to preview the WOFF 
like image 78
Oleksii Kyslytsyn Avatar answered Oct 05 '22 23:10

Oleksii Kyslytsyn