org.apache.fontbox.ttf.GlyphTable Java Examples
The following examples show how to use
org.apache.fontbox.ttf.GlyphTable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FontState.java From ttt with BSD 2-Clause "Simplified" License | 5 votes |
private String getGlyphsPathContours(FontKey key, String glyphsAsText, double[] advances, GlyphTable glyphs) { StringBuffer sb = new StringBuffer(); int[] retNext = new int[1]; for (int i = 0, n = glyphsAsText.length(); i < n; i = retNext[0]) { int gi = getGlyphId(glyphsAsText, i, false, null, retNext); if (gi > 0) { String p = getGlyphPath(key, gi, advances[i], glyphs); if (p != null) sb.append(p); } } return sb.toString(); }
Example #2
Source File: FontState.java From ttt with BSD 2-Clause "Simplified" License | 5 votes |
private String getGlyphPath(FontKey key, int gi, double advance, GlyphTable glyphs) { PathCacheKey pck = new PathCacheKey(key, gi, advance); if (hasCachedGlyphPath(pck)) return getCachedGlyphPath(pck); else return putCachedGlyphPath(pck, getGlyphPath(pck, glyphs)); }
Example #3
Source File: FontState.java From ttt with BSD 2-Clause "Simplified" License | 5 votes |
private String getGlyphPath(PathCacheKey pck, GlyphTable glyphs) { try { GlyphData gd = glyphs.getGlyph(pck.getGlyph()); if (gd != null) { GeneralPath p = gd.getPath(); if (p != null) return getGlyphPath(pck.getFontKey(), p, pck.getAdvance()); } } catch (IOException e) { } return null; }
Example #4
Source File: PDCIDFontType2Embedder.java From sambox with Apache License 2.0 | 4 votes |
/** * Builds vertical metrics with a custom CIDToGIDMap (for embedding font subset). */ private void buildVerticalMetrics(Map<Integer, Integer> cidToGid) throws IOException { // The "vhea" and "vmtx" tables that specify vertical metrics shall never be used by a conforming // reader. The only way to specify vertical metrics in PDF shall be by means of the DW2 and W2 // entries in a CIDFont dictionary. if (!buildVerticalHeader(cidFont)) { return; } float scaling = 1000f / ttf.getHeader().getUnitsPerEm(); VerticalHeaderTable vhea = ttf.getVerticalHeader(); VerticalMetricsTable vmtx = ttf.getVerticalMetrics(); GlyphTable glyf = ttf.getGlyph(); HorizontalMetricsTable hmtx = ttf.getHorizontalMetrics(); long v_y = Math.round(vhea.getAscender() * scaling); long w1 = Math.round(-vhea.getAdvanceHeightMax() * scaling); COSArray heights = new COSArray(); COSArray w2 = new COSArray(); int prev = Integer.MIN_VALUE; // Use a sorted list to get an optimal width array Set<Integer> keys = new TreeSet<Integer>(cidToGid.keySet()); for (int cid : keys) { // Unlike buildWidths, we look up with cid (not gid) here because this is // the original TTF, not the rebuilt one. GlyphData glyph = glyf.getGlyph(cid); if (glyph == null) { continue; } long height = Math.round((glyph.getYMaximum() + vmtx.getTopSideBearing(cid)) * scaling); long advance = Math.round(-vmtx.getAdvanceHeight(cid) * scaling); if (height == v_y && advance == w1) { // skip default metrics continue; } // c [w1_1y v_1x v_1y w1_2y v_2x v_2y ... w1_ny v_nx v_ny] if (prev != cid - 1) { w2 = new COSArray(); heights.add(COSInteger.get(cid)); // c heights.add(w2); } w2.add(COSInteger.get(advance)); // w1_iy long width = Math.round(hmtx.getAdvanceWidth(cid) * scaling); w2.add(COSInteger.get(width / 2)); // v_ix w2.add(COSInteger.get(height)); // v_iy prev = cid; } cidFont.setItem(COSName.W2, heights); }