TrueTypeFont(String ttcPath, int ttcIndex) throws java.io.IOException { fontParser = new OpenTypeParser(ttcPath, ttcIndex); fontParser.loadTables(true); initializeFontProperties(); }
/** * Reads the font data. * @param all if true, all tables will be read, otherwise only 'head', 'name', and 'os/2'. */ protected void loadTables(boolean all) throws java.io.IOException { readNameTable(); readHeadTable(); readOs_2Table(); readPostTable(); if (all) { checkCff(); readHheaTable(); readGlyphWidths(); readCmapTable(); } }
public void close() throws java.io.IOException { if (fontParser != null) { fontParser.close(); } fontParser = null; } }
private static FontProgramDescriptor fetchOpenTypeFontDescriptor(OpenTypeParser fontParser) throws java.io.IOException { fontParser.loadTables(false); return new FontProgramDescriptor(fontParser.getFontNames(), fontParser.getPostTable().italicAngle, fontParser.getPostTable().isFixedPitch); }
private void initializeFontProperties() throws java.io.IOException { OpenTypeParser.HeaderTable head = fontParser.getHeadTable(); OpenTypeParser.HorizontalHeader hhea = fontParser.getHheaTable(); OpenTypeParser.WindowsMetrics os_2 = fontParser.getOs_2Table(); OpenTypeParser.PostTable post = fontParser.getPostTable(); isFontSpecific = fontParser.getCmapTable().fontSpecific; kerning = fontParser.readKerning(head.unitsPerEm); bBoxes = fontParser.readBbox(head.unitsPerEm); fontNames = fontParser.getFontNames(); fontMetrics.setNumberOfGlyphs(fontParser.readNumGlyphs()); fontMetrics.setGlyphWidths(fontParser.getGlyphWidthsByIndex()); fontMetrics.setTypoAscender(os_2.sTypoAscender); fontMetrics.setTypoDescender(os_2.sTypoDescender); int[] glyphWidths = fontParser.getGlyphWidthsByIndex(); int numOfGlyphs = fontMetrics.getNumberOfGlyphs(); unicodeToGlyph = new LinkedHashMap<>(cmap.size());
public byte[] getFontStreamBytes() { if (fontStreamBytes != null) return fontStreamBytes; try { if (fontParser.isCff()) { fontStreamBytes = fontParser.readCffFont(); } else { fontStreamBytes = fontParser.getFullFont(); } } catch (java.io.IOException e) { fontStreamBytes = null; throw new IOException(IOException.IoException, e); } return fontStreamBytes; }
private static FontProgramDescriptor fetchTTCDescriptor(String baseName) throws java.io.IOException { int ttcSplit = baseName.toLowerCase().indexOf(".ttc,"); if (ttcSplit > 0) { String ttcName; int ttcIndex; try { ttcName = baseName.substring(0, ttcSplit + 4); // count(.ttc) = 4 ttcIndex = Integer.parseInt(baseName.substring(ttcSplit + 5)); // count(.ttc,) = 5) } catch (NumberFormatException nfe) { throw new IOException(nfe.getMessage(), nfe); } OpenTypeParser parser = new OpenTypeParser(ttcName, ttcIndex); FontProgramDescriptor descriptor = fetchOpenTypeFontDescriptor(parser); parser.close(); return descriptor; } else { return null; } }
/** * The information in the maps of the table 'cmap' is coded in several formats. * Format 0 is the Apple standard character to glyph index mapping table. * * @return a <CODE>HashMap</CODE> representing this map * @throws java.io.IOException the font file could not be read */ private Map<Integer, int[]> readFormat0() throws java.io.IOException { Map<Integer, int[]> h = new LinkedHashMap<>(); raf.skipBytes(4); for (int k = 0; k < 256; ++k) { int[] r = new int[2]; r[0] = raf.readUnsignedByte(); r[1] = getGlyphWidth(r[0]); h.put(k, r); } return h; }
public FontNames getFontNames() { FontNames fontNames = new FontNames(); fontNames.setAllNames(getAllNameEntries()); fontNames.setFontName(getPsFontName()); fontNames.setFullName(fontNames.getNames(4)); String[][] otfFamilyName = fontNames.getNames(16);
private static FontProgramDescriptor fetchTrueTypeFontDescriptor(String fontName) throws java.io.IOException { try (OpenTypeParser parser = new OpenTypeParser(fontName)) { return fetchOpenTypeFontDescriptor(parser); } }
public Map<Integer, int[]> getActiveCmap() { OpenTypeParser.CmapTable cmaps = fontParser.getCmapTable(); if (cmaps.cmapExt != null) { return cmaps.cmapExt; } else if (!cmaps.fontSpecific && cmaps.cmap31 != null) { return cmaps.cmap31; } else if (cmaps.fontSpecific && cmaps.cmap10 != null) { return cmaps.cmap10; } else if (cmaps.cmap31 != null) { return cmaps.cmap31; } else { return cmaps.cmap10; } }
private void initializeFontProperties() throws java.io.IOException { OpenTypeParser.HeaderTable head = fontParser.getHeadTable(); OpenTypeParser.HorizontalHeader hhea = fontParser.getHheaTable(); OpenTypeParser.WindowsMetrics os_2 = fontParser.getOs_2Table(); OpenTypeParser.PostTable post = fontParser.getPostTable(); isFontSpecific = fontParser.getCmapTable().fontSpecific; kerning = fontParser.readKerning(head.unitsPerEm); bBoxes = fontParser.readBbox(head.unitsPerEm); fontNames = fontParser.getFontNames(); fontMetrics.setNumberOfGlyphs(fontParser.readNumGlyphs()); fontMetrics.setGlyphWidths(fontParser.getGlyphWidthsByIndex()); fontMetrics.setTypoAscender(os_2.sTypoAscender); fontMetrics.setTypoDescender(os_2.sTypoDescender); int[] glyphWidths = fontParser.getGlyphWidthsByIndex(); int numOfGlyphs = fontMetrics.getNumberOfGlyphs(); unicodeToGlyph = new LinkedHashMap<>(cmap.size());
private static FontProgramDescriptor fetchOpenTypeFontDescriptor(OpenTypeParser fontParser) throws java.io.IOException { fontParser.loadTables(false); return new FontProgramDescriptor(fontParser.getFontNames(), fontParser.getPostTable().italicAngle, fontParser.getPostTable().isFixedPitch); }
public byte[] getFontStreamBytes() { if (fontStreamBytes != null) return fontStreamBytes; try { if (fontParser.isCff()) { fontStreamBytes = fontParser.readCffFont(); } else { fontStreamBytes = fontParser.getFullFont(); } } catch (java.io.IOException e) { fontStreamBytes = null; throw new IOException(IOException.IoException, e); } return fontStreamBytes; }
private static FontProgramDescriptor fetchTTCDescriptor(String baseName) throws java.io.IOException { int ttcSplit = baseName.toLowerCase().indexOf(".ttc,"); if (ttcSplit > 0) { String ttcName; int ttcIndex; try { ttcName = baseName.substring(0, ttcSplit + 4); // count(.ttc) = 4 ttcIndex = Integer.parseInt(baseName.substring(ttcSplit + 5)); // count(.ttc,) = 5) } catch (NumberFormatException nfe) { throw new IOException(nfe.getMessage(), nfe); } OpenTypeParser parser = new OpenTypeParser(ttcName, ttcIndex); FontProgramDescriptor descriptor = fetchOpenTypeFontDescriptor(parser); parser.close(); return descriptor; } else { return null; } }
/** * The information in the maps of the table 'cmap' is coded in several formats. * Format 0 is the Apple standard character to glyph index mapping table. * * @return a <CODE>HashMap</CODE> representing this map * @throws java.io.IOException the font file could not be read */ private Map<Integer, int[]> readFormat0() throws java.io.IOException { Map<Integer, int[]> h = new LinkedHashMap<>(); raf.skipBytes(4); for (int k = 0; k < 256; ++k) { int[] r = new int[2]; r[0] = raf.readUnsignedByte(); r[1] = getGlyphWidth(r[0]); h.put(k, r); } return h; }
public FontNames getFontNames() { FontNames fontNames = new FontNames(); fontNames.setAllNames(getAllNameEntries()); fontNames.setFontName(getPsFontName()); fontNames.setFullName(fontNames.getNames(4)); String[][] otfFamilyName = fontNames.getNames(16);
private static FontProgramDescriptor fetchTrueTypeFontDescriptor(String fontName) throws java.io.IOException { try (OpenTypeParser parser = new OpenTypeParser(fontName)) { return fetchOpenTypeFontDescriptor(parser); } }
public Map<Integer, int[]> getActiveCmap() { OpenTypeParser.CmapTable cmaps = fontParser.getCmapTable(); if (cmaps.cmapExt != null) { return cmaps.cmapExt; } else if (!cmaps.fontSpecific && cmaps.cmap31 != null) { return cmaps.cmap31; } else if (cmaps.fontSpecific && cmaps.cmap10 != null) { return cmaps.cmap10; } else if (cmaps.cmap31 != null) { return cmaps.cmap31; } else { return cmaps.cmap10; } }
/** * Reads the font data. * @param all if true, all tables will be read, otherwise only 'head', 'name', and 'os/2'. */ protected void loadTables(boolean all) throws java.io.IOException { readNameTable(); readHeadTable(); readOs_2Table(); readPostTable(); if (all) { checkCff(); readHheaTable(); readGlyphWidths(); readCmapTable(); } }