package org.apache.fop.render.pdf.fonts; import org.apache.fop.render.pdf.Font; import org.apache.fop.layout.FontDescriptor; import org.apache.fop.fonts.Glyphs; import org.apache.fop.pdf.PDFStream; import org.apache.fop.pdf.PDFT1Stream; import java.io.InputStream; import java.io.FileInputStream; import java.io.BufferedInputStream; import java.util.HashMap; public class extends Font implements FontDescriptor { private final static String fontName = ""; private final static String encoding = ""; private final static int capHeight = ; private final static int xHeight = ; private final static int ascender = ; private final static int descender = ; private final static int[] fontBBox = { , , , }; private final static String embedFileName = ; private final static String embedResourceName = ; private static PDFT1Stream embeddedFont=null; private final static int flags = ; private final static int stemV = ; private final static int italicAngle = ; private final static int firstChar = ; private final static int lastChar = ; private final static int[] width; private final static HashMap kerning=new HashMap(); static { width = new int[256]; width[] = ; HashMap tmptable; tmptable=new HashMap(); tmptable.put(Glyphs.glyphToString(""), new Integer()); kerning.put(Glyphs.glyphToString(""), tmptable); } public final boolean hasKerningInfo() {return kerning.isEmpty();} public final java.util.HashMap getKerningInfo() {return kerning;} public byte getSubType() {return org.apache.fop.pdf.PDFFont.TYPE1;} public boolean isEmbeddable() { return (embedFileName==null && embedResourceName==null) ? false : true; } public PDFStream getFontFile(int i) { InputStream instream=null; // Get file first if (embedFileName!=null) try { instream=new FileInputStream(embedFileName); } catch (Exception e) { System.out.println("Failed to embed fontfile: "+embedFileName); } // Get resource if (instream==null && embedResourceName!=null) try { instream=new BufferedInputStream(this.getClass().getResourceAsStream(embedResourceName)); } catch (Exception e) { System.out.println("Failed to embed fontresource: "+embedResourceName); } if (instream==null) return (PDFStream)null; // Read fontdata byte[] file = new byte[128000]; int fsize = 0; try { int l = instream.read(file, 0, 128000); fsize += l; if (l==128000) { // More to read - needs to extend byte[] tmpbuf; while (l > 0) { tmpbuf = new byte[file.length + 64000]; System.arraycopy(file, 0, tmpbuf, 0, file.length); l=instream.read(tmpbuf, file.length, 64000); fsize += l; file = tmpbuf; if (l < 64000) // whole file read. No need to loop again l=0; } } embeddedFont=new PDFT1Stream(i, fsize); embeddedFont.addFilter("flate"); embeddedFont.addFilter("ascii-85"); embeddedFont.setData(file, fsize); instream.close(); } catch (Exception e) {} return (PDFStream) embeddedFont; } public String encoding() { return encoding; } public String fontName() { return fontName; } public int getAscender() { return ascender; } public int getCapHeight() { return capHeight; } public int getDescender() { return descender; } public int getAscender(int size) { return size * ascender; } public int getCapHeight(int size) { return size * capHeight; } public int getDescender(int size) { return size * descender; } public int getXHeight(int size) { return size * xHeight; } public int getFlags() { return flags; } public int[] getFontBBox() { return fontBBox; } public int getItalicAngle() { return italicAngle; } public int getStemV() { return stemV; } public int getFirstChar() { return firstChar; } public int getLastChar() { return lastChar; } public int width(int i, int size) { return size * width[i]; } public int[] getWidths(int size) { int[] arr = new int[getLastChar()-getFirstChar()+1]; System.arraycopy(width, getFirstChar(), arr, 0, getLastChar()-getFirstChar()+1); for( int i = 0; i < arr.length; i++) arr[i] *= size; return arr; } }