// fos.write(fontdata);
// fos.close();
try {
// read the true type information
TrueTypeFont ttf = TrueTypeFont.parseFont (fontdata);
// System.out.println(ttf.toString());
// get the cmap, post, and hmtx tables for later use
this.cmapTable = (CmapTable) ttf.getTable ("cmap");
this.postTable = (PostTable) ttf.getTable ("post");
this.hmtxTable = (HmtxTable) ttf.getTable ("hmtx");
// read the units per em from the head table
HeadTable headTable = (HeadTable) ttf.getTable ("head");
this.unitsPerEm = headTable.getUnitsPerEm ();
/* Find out if we have the right info in our name table.
* This is a hack because Java can only deal with fonts that
* have a Microsoft encoded name in their name table (PlatformID 3).
* We'll 'adjust' the font to add it if not, and take our chances
* with our parsing, since it wasn't going to work anyway.
*/
NameTable nameTable = null;
try {
nameTable = (NameTable) ttf.getTable ("name");
} catch (Exception ex) {
System.out.println ("Error reading name table for font " +
getBaseFont () + ". Repairing!");
}
boolean nameFixed = fixNameTable (ttf, nameTable);
/* Figure out if we need to hack the CMap table. This might
* be the case if we use characters that Java considers control
* characters (0x9, 0xa and 0xd), that have to be re-mapped
*/
boolean cmapFixed = fixCMapTable (ttf, this.cmapTable);
// use the parsed font instead of the original
if (nameFixed || cmapFixed) {
// System.out.println("Using fixed font!");
// System.out.println(ttf.toString());
fontdata = ttf.writeFont ();
// FileOutputStream fos2 = new FileOutputStream("/tmp/" + getBaseFont() + ".fix");
// fos2.write(fontdata);
// fos2.close();
}