for (TTFTable table : font.getTables()) font.readTable(table); HeaderTable head = font.getHeader(); if (head == null) HorizontalHeaderTable hh = font.getHorizontalHeader(); if (hh == null) MaximumProfileTable maxp = font.getMaximumProfile(); if (maxp == null) PostScriptTable post = font.getPostScript(); if (post == null && !isEmbedded) IndexToLocationTable loc = font.getIndexToLocation(); if (loc == null) if (font.getGlyph() == null) if (font.getNaming() == null && !isEmbedded) if (font.getHorizontalMetrics() == null) if (!isEmbedded && font.getCmap() == null)
@Override public float getWidthFromFont(int code) throws IOException { int gid = codeToGID(code); int width = ttf.getAdvanceWidth(gid); int unitsPerEM = ttf.getUnitsPerEm(); if (unitsPerEM != 1000) { width *= 1000f / unitsPerEM; } return width; }
if (ttf.getName() != null && ttf.getName().contains("|")) LOG.warn("Skipping font with '|' in name " + ttf.getName() + " in file " + file); else if (ttf.getName() != null) if (ttf.getHeader() == null) fontInfoList.add(new FSIgnored(file, FontFormat.TTF, ttf.getName())); return; int macStyle = ttf.getHeader().getMacStyle(); if (ttf.getOS2Windows() != null) sFamilyClass = ttf.getOS2Windows().getFamilyClass(); usWeightClass = ttf.getOS2Windows().getWeightClass(); ulCodePageRange1 = (int)ttf.getOS2Windows().getCodePageRange1(); ulCodePageRange2 = (int)ttf.getOS2Windows().getCodePageRange2(); panose = ttf.getOS2Windows().getPanose(); fontInfoList.add(new FSFontInfo(file, FontFormat.OTF, ttf.getName(), ros, usWeightClass, sFamilyClass, ulCodePageRange1, ulCodePageRange2, macStyle, panose, this)); if (ttf.getTableMap().containsKey("gcid")) byte[] bytes = ttf.getTableBytes(ttf.getTableMap().get("gcid")); String reg = new String(bytes, 10, 64, Charsets.US_ASCII);
@Override public float getWidth(String name) throws IOException { Integer gid = nameToGID(name); return getAdvanceWidth(gid); }
@Override public float getHeight(int code) throws IOException { // todo: really we want the BBox, (for text extraction:) return (ttf.getHorizontalHeader().getAscender() + -ttf.getHorizontalHeader().getDescender()) / ttf.getUnitsPerEm(); // todo: shouldn't this be the yMax/yMin? }
/** * Creates a new TrueType font for embedding. */ TrueTypeEmbedder(PDDocument document, COSDictionary dict, TrueTypeFont ttf, boolean embedSubset) throws IOException { this.document = document; this.embedSubset = embedSubset; this.ttf = ttf; fontDescriptor = createFontDescriptor(ttf); if (!isEmbeddingPermitted(ttf)) { throw new IOException("This font does not permit embedding"); } if (!embedSubset) { // full embedding PDStream stream = new PDStream(document, ttf.getOriginalData(), COSName.FLATE_DECODE); stream.getCOSObject().setLong(COSName.LENGTH1, ttf.getOriginalDataSize()); fontDescriptor.setFontFile2(stream); } dict.setName(COSName.BASE_FONT, ttf.getName()); // choose a Unicode "cmap" cmap = ttf.getUnicodeCmap(); cmapLookup = ttf.getUnicodeCmapLookup(); }
fd.setFontName(ttf.getName()); OS2WindowsMetricsTable os2 = ttf.getOS2Windows(); PostScriptTable post = ttf.getPostScript(); ttf.getHorizontalHeader().getNumberOfHMetrics() == 1); HeaderTable header = ttf.getHeader(); PDRectangle rect = new PDRectangle(); float scaling = 1000f / header.getUnitsPerEm(); HorizontalHeaderTable hHeader = ttf.getHorizontalHeader(); fd.setAscent(hHeader.getAscender() * scaling); fd.setDescent(hHeader.getDescender() * scaling); GeneralPath capHPath = ttf.getPath("H"); if (capHPath != null) GeneralPath xPath = ttf.getPath("x"); if (xPath != null)
font.getHeader().getCreated()); metadata.set(TikaCoreProperties.MODIFIED, font.getHeader().getModified()); metadata.set(AdobeFontMetricParser.MET_DOC_VERSION, Float.toString(font.getHeader().getVersion())); NamingTable fontNaming = font.getNaming(); for (NameRecord nr : fontNaming.getNameRecords()) { if (nr.getNameId() == NameRecord.NAME_FONT_FAMILY_NAME) { font.close();
float scaling = 1000f / ttf.getHeader().getUnitsPerEm(); VerticalHeaderTable vhea = ttf.getVerticalHeader(); VerticalMetricsTable vmtx = ttf.getVerticalMetrics(); GlyphTable glyf = ttf.getGlyph(); HorizontalMetricsTable hmtx = ttf.getHorizontalMetrics();
HorizontalHeaderTable h = ttf.getHorizontalHeader(); HorizontalMetricsTable hm = ttf.getHorizontalMetrics(); InputStream is = ttf.getOriginalData();
do GlyphTable g = ttf.getGlyph(); long[] offsets = ttf.getIndexToLocation().getOffsets(); InputStream is = ttf.getOriginalData(); Set<Integer> glyphIdsToAdd = null; try
@Override public BoundingBox getFontBBox() throws IOException { short xMin = getHeader().getXMin(); short xMax = getHeader().getXMax(); short yMin = getHeader().getYMin(); short yMax = getHeader().getYMax(); float scale = 1000f / getUnitsPerEm(); return new BoundingBox(xMin * scale, yMin * scale, xMax * scale, yMax * scale); }
private byte[] buildCmapTable() throws IOException if (ttf.getCmap() == null || uniToGID.isEmpty() || keepTables != null && !keepTables.contains("cmap"))
LOG.debug("Fallback font available on the system: {} (for {})", mappedFont.getName(), fontName); } else { LOG.debug("Original font available on the system: {}", fontName); return PDType0Font.load(document, mappedFont.getOriginalData()); } catch (IOException ioe) { LOG.warn("Failed to load font from system", ioe); try { mappedFont.close(); } catch (Exception e) { LOG.warn("Failed closing font", e);
/** * Build vertical metrics with Identity CIDToGIDMap (for embedding full font). */ private void buildVerticalMetrics(COSDictionary cidFont) throws IOException { if (!buildVerticalHeader(cidFont)) { return; } int cidMax = ttf.getNumberOfGlyphs(); int[] gidMetrics = new int[cidMax * 4]; for (int cid = 0; cid < cidMax; cid++) { GlyphData glyph = ttf.getGlyph().getGlyph(cid); if (glyph == null) { gidMetrics[cid * 4] = Integer.MIN_VALUE; } else { gidMetrics[cid * 4] = cid; gidMetrics[cid * 4 + 1] = ttf.getVerticalMetrics().getAdvanceHeight(cid); gidMetrics[cid * 4 + 2] = ttf.getHorizontalMetrics().getAdvanceWidth(cid); gidMetrics[cid * 4 + 3] = glyph.getYMaximum() + ttf.getVerticalMetrics().getTopSideBearing(cid); } } cidFont.setItem(COSName.W2, getVerticalMetrics(gidMetrics)); }
float scaling = 1000f / ttf.getHeader().getUnitsPerEm(); HorizontalMetricsTable hmtx = ttf.getHorizontalMetrics();
int gid = ttf.nameToGID(name); if (gid == 0) if (gid > ttf.getNumberOfGlyphs()) GlyphData glyph = ttf.getGlyph().getGlyph(gid); if (glyph != null)
/** * Returns the units per EM (Header.unitsPerEm). * * @return units per EM * @throws IOException if there was an error reading the table. */ public int getUnitsPerEm() throws IOException { if (unitsPerEm == -1) { HeaderTable header = getHeader(); if (header != null) { unitsPerEm = header.getUnitsPerEm(); } else { // this should never happen unitsPerEm = 0; } } return unitsPerEm; }