/** * Create a pretty String */ public String toString() { StringBuffer buf = new StringBuffer(); String indent = " "; buf.append(indent + "Glyf Table: (" + glyphs.length + " glyphs)\n"); buf.append(indent + " Glyf 0: " + getGlyph(0)); return buf.toString(); } }
/** get the data in this map as a ByteBuffer */ public ByteBuffer getData() { int size = getLength(); ByteBuffer buf = ByteBuffer.allocate(size); // write the offsets for (int i = 0; i < glyphs.length; i++) { Object o = glyphs[i]; if (o == null) { continue; } ByteBuffer glyfData = null; if (o instanceof ByteBuffer) { glyfData = (ByteBuffer) o; } else { glyfData = ((Glyf) o).getData(); } glyfData.rewind(); buf.put(glyfData); glyfData.flip(); } // reset the start pointer buf.flip(); return buf; }
break; case GLYF_TABLE: outTable = new GlyfTable(ttf); break; case HEAD_TABLE: // head table
break; case GLYF_TABLE: outTable = new GlyfTable(ttf); break; case HEAD_TABLE: // head table
/** * Create a pretty String */ public String toString() { StringBuffer buf = new StringBuffer(); String indent = " "; buf.append(indent + "Glyf Table: (" + glyphs.length + " glyphs)\n"); buf.append(indent + " Glyf 0: " + getGlyph(0)); return buf.toString(); } }
/** get the data in this map as a ByteBuffer */ public ByteBuffer getData() { int size = getLength(); ByteBuffer buf = ByteBuffer.allocate(size); // write the offsets for (int i = 0; i < glyphs.length; i++) { Object o = glyphs[i]; if (o == null) { continue; } ByteBuffer glyfData = null; if (o instanceof ByteBuffer) { glyfData = (ByteBuffer) o; } else { glyfData = ((Glyf) o).getData(); } glyfData.rewind(); buf.put(glyfData); glyfData.flip(); } // reset the start pointer buf.flip(); return buf; }
break; case GLYF_TABLE: outTable = new GlyfTable(ttf); break; case HEAD_TABLE: // head table
/** * Create a pretty String */ public String toString() { StringBuffer buf = new StringBuffer(); String indent = " "; buf.append(indent + "Glyf Table: (" + glyphs.length + " glyphs)\n"); buf.append(indent + " Glyf 0: " + getGlyph(0)); return buf.toString(); } }
/** get the data in this map as a ByteBuffer */ public ByteBuffer getData() { int size = getLength(); ByteBuffer buf = ByteBuffer.allocate(size); // write the offsets for (int i = 0; i < glyphs.length; i++) { Object o = glyphs[i]; if (o == null) { continue; } ByteBuffer glyfData = null; if (o instanceof ByteBuffer) { glyfData = (ByteBuffer) o; } else { glyfData = ((Glyf) o).getData(); } glyfData.rewind(); buf.put(glyfData); glyfData.flip(); } // reset the start pointer buf.flip(); return buf; }
/** * Render a compound glyf */ protected GeneralPath renderCompoundGlyph (GlyfTable glyf, GlyfCompound g) { GeneralPath gp = new GeneralPath (); for (int i = 0; i < g.getNumComponents (); i++) { // find and render the component glyf Glyf gl = glyf.getGlyph (g.getGlyphIndex (i)); GeneralPath path = null; if (gl instanceof GlyfSimple) { path = renderSimpleGlyph ((GlyfSimple) gl); } else if (gl instanceof GlyfCompound) { path = renderCompoundGlyph (glyf, (GlyfCompound) gl); } else { throw new RuntimeException ( "Unsupported glyph type " + gl.getClass ().getCanonicalName ()); } // multiply the translations by units per em double[] matrix = g.getTransform (i); // transform the path path.transform (new AffineTransform (matrix)); // add it to the global path gp.append (path, false); } return gp; }
/** * Get the outline of a character given the glyph id */ protected synchronized GeneralPath getOutline (int glyphId, float width) { // find the glyph itself GlyfTable glyf = (GlyfTable) font.getTable ("glyf"); Glyf g = glyf.getGlyph (glyphId); GeneralPath gp = null; if (g instanceof GlyfSimple) { gp = renderSimpleGlyph ((GlyfSimple) g); } else if (g instanceof GlyfCompound) { gp = renderCompoundGlyph (glyf, (GlyfCompound) g); } else { gp = new GeneralPath (); } // calculate the advance HmtxTable hmtx = (HmtxTable) font.getTable ("hmtx"); float advance = (float) hmtx.getAdvance (glyphId) / (float) unitsPerEm; // scale the glyph to match the desired advance float widthfactor = width / advance; // the base transform scales the glyph to 1x1 AffineTransform at = AffineTransform.getScaleInstance (1 / unitsPerEm, 1 / unitsPerEm); at.concatenate (AffineTransform.getScaleInstance (widthfactor, 1)); gp.transform (at); return gp; }
/** * Render a compound glyf */ protected GeneralPath renderCompoundGlyph (GlyfTable glyf, GlyfCompound g) { GeneralPath gp = new GeneralPath (); for (int i = 0; i < g.getNumComponents (); i++) { // find and render the component glyf Glyf gl = glyf.getGlyph (g.getGlyphIndex (i)); GeneralPath path = null; if (gl instanceof GlyfSimple) { path = renderSimpleGlyph ((GlyfSimple) gl); } else if (gl instanceof GlyfCompound) { path = renderCompoundGlyph (glyf, (GlyfCompound) gl); } else { throw new RuntimeException ( "Unsupported glyph type " + gl.getClass ().getCanonicalName ()); } // multiply the translations by units per em double[] matrix = g.getTransform (i); // transform the path path.transform (new AffineTransform (matrix)); // add it to the global path gp.append (path, false); } return gp; }
/** * Get the outline of a character given the glyph id */ protected synchronized GeneralPath getOutline (int glyphId, float width) { // find the glyph itself GlyfTable glyf = (GlyfTable) font.getTable ("glyf"); Glyf g = glyf.getGlyph (glyphId); GeneralPath gp = null; if (g instanceof GlyfSimple) { gp = renderSimpleGlyph ((GlyfSimple) g); } else if (g instanceof GlyfCompound) { gp = renderCompoundGlyph (glyf, (GlyfCompound) g); } else { gp = new GeneralPath (); } // calculate the advance HmtxTable hmtx = (HmtxTable) font.getTable ("hmtx"); float advance = (float) hmtx.getAdvance (glyphId) / (float) unitsPerEm; // scale the glyph to match the desired advance float widthfactor = width / advance; // the base transform scales the glyph to 1x1 AffineTransform at = AffineTransform.getScaleInstance (1 / unitsPerEm, 1 / unitsPerEm); at.concatenate (AffineTransform.getScaleInstance (widthfactor, 1)); gp.transform (at); return gp; }
/** * Get the outline of a character given the glyph id */ protected synchronized GeneralPath getOutline (int glyphId, float width) { // find the glyph itself GlyfTable glyf = (GlyfTable) font.getTable ("glyf"); Glyf g = glyf.getGlyph (glyphId); GeneralPath gp = null; if (g instanceof GlyfSimple) { gp = renderSimpleGlyph ((GlyfSimple) g); } else if (g instanceof GlyfCompound) { gp = renderCompoundGlyph (glyf, (GlyfCompound) g); } else { gp = new GeneralPath (); } // calculate the advance HmtxTable hmtx = (HmtxTable) font.getTable ("hmtx"); float advance = (float) hmtx.getAdvance (glyphId) / (float) unitsPerEm; // scale the glyph to match the desired advance float widthfactor = width / advance; // the base transform scales the glyph to 1x1 AffineTransform at = AffineTransform.getScaleInstance (1 / unitsPerEm, 1 / unitsPerEm); at.concatenate (AffineTransform.getScaleInstance (widthfactor, 1)); gp.transform (at); return gp; }
/** * Render a compound glyf */ protected GeneralPath renderCompoundGlyph (GlyfTable glyf, GlyfCompound g) { GeneralPath gp = new GeneralPath (); for (int i = 0; i < g.getNumComponents (); i++) { // find and render the component glyf Glyf gl = glyf.getGlyph (g.getGlyphIndex (i)); GeneralPath path = null; if (gl instanceof GlyfSimple) { path = renderSimpleGlyph ((GlyfSimple) gl); } else if (gl instanceof GlyfCompound) { path = renderCompoundGlyph (glyf, (GlyfCompound) gl); } else { throw new RuntimeException ( "Unsupported glyph type " + gl.getClass ().getCanonicalName ()); } // multiply the translations by units per em double[] matrix = g.getTransform (i); // transform the path path.transform (new AffineTransform (matrix)); // add it to the global path gp.append (path, false); } return gp; }