sfntly as font generator

202 views
Skip to first unread message

andreas...@network.rca.ac.uk

unread,
Dec 18, 2012, 3:03:48 PM12/18/12
to sfntly...@googlegroups.com
I am new to this group, and I am not a Java developer or programmer. Some very basic stuff ahead...

For a project at uni, I would like to generate a font (ttf or otf) with a basic set of 26 characters (A-Z), which are generated based on various inputs (camera, live data,...), which are not based on any previously loaded font.

However, I run into problems to define a simple glyph table. I guess it is an easy task, but my programming skills are very limited. That's how far I've got:

  FontFactory fontFactory = FontFactory.getInstance();
  Font.Builder fontBuilder = fontFactory.newFontBuilder();
  CMapTable.Builder cmapTableBuilder = (CMapTable.Builder) fontBuilder.newTableBuilder(Tag.cmap);
  CMap.Builder cmapBuilder = cmapTableBuilder.newCMapBuilder(CMapId.MAC_ROMAN, CMapFormat.Format0);
  CMapFormat0.Builder cmapFormat0Builder = (CMapFormat0.Builder) cmapBuilder;   
  
  LocaTable.Builder locaBuilder = (LocaTable.Builder) fontBuilder.newTableBuilder(Tag.loca);
  GlyphTable.Builder glyphTableBuilder = (GlyphTable.Builder) fontBuilder.newTableBuilder(Tag.glyf);
  
 // define glyphs here 
 
   Font newFont = fontBuilder.build(); 
   File dstFontFile = TestFontUtils.serializeFont(newFont, ".ttf");
   System.out.println(dstFontFile);  
 
I don't know how the glyph definition could work and I couldn't find any example code. Also, saving the .ttf file is not working with this code yet... hope someone can help me.

Thanks in advance for looking into the topic!
Andreas

Stuart Gill

unread,
Jan 25, 2013, 7:55:59 PM1/25/13
to sfntly...@googlegroups.com
sfntly could be used a font generator but that wasn't the original purpose it was written for. As such, it probably lacks all of the necessary methods and builders for various sub-tables elements such as for glyphs. Building a font from scratch can be a pretty involved process that will require getting the right entries into a lot of various tables.

For the glyph building issue you could use the Glyph.Builder.setData() method (inherited from FontDataTable.Builder) to set the raw data. You would need to pack the data into the WritableFontData object in your code using the spec for glyphs in the OpenType spec - http://www.microsoft.com/typography/otspec/glyf.htm

Of course, it would be better to extend the SimpleGlyph.Builder class to have methods for editing a glyph. If you do write up the code for this then if you put it in the form of methods on the builder I would be happy to consider it for contribution to the sfntly library.

Stuart

andreas...@network.rca.ac.uk

unread,
Feb 27, 2013, 2:13:54 PM2/27/13
to sfntly...@googlegroups.com
Hi Stuart,

thanks for your answer. Finally I decided to use a Java library called doubletype to create a ttf file and from there create a woff with sfntly. It would be great to do all of this with sfntly, but I think I can't do it myself as you explained, as I'm not a programmer. I'll check back regularly and hope that these functions will be added sometime soon. Thanks again.

Andreas
Reply all
Reply to author
Forward
0 new messages