DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=25999>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=25999 [PATCH] Basic OpenType CFF Support for development branch: 3 Patches Summary: [PATCH] Basic OpenType CFF Support for development branch: 3 Patches Product: Fop Version: 1.0dev Platform: All OS/Version: Other Status: NEW Severity: Enhancement Priority: Other Component: general AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] Index: TTFFile.java =================================================================== RCS file: /home/cvspublic/xml- fop/src/java/org/apache/fop/fonts/truetype/TTFFile.java,v retrieving revision 1.4 diff -w -u -r1.4 TTFFile.java --- TTFFile.java 27 May 2003 14:03:34 -0000 1.4 +++ TTFFile.java 8 Jan 2004 19:52:11 -0000 @@ -132,6 +132,8 @@ private TTFDirTabEntry currentDirTab; + private boolean isCFF = false; + /** * Position inputstream to position indicated * in the dirtab offset + offset @@ -460,8 +462,10 @@ initAnsiWidths(); readPostScript(in); readOS2(in); + if (!isCFF) { readIndexToLocation(in); readGlyf(in); + } readName(in); readPCLT(in); // Read cmap table and fill in ansiwidths @@ -473,7 +477,11 @@ createCMaps(); // print_max_min(); + if (isCFF) { + // readGPOS(in); // GPOS is OpenType CFF analog of TrueType kerning table. + } else { readKerning(in); + } return true; } @@ -694,6 +702,15 @@ return isEmbeddable; } + /** + * Indicates whether or not the font is an OpenType + * CFF font (rather than a TrueType font). + * @return boolean True if the font is in OpenType CFF format. + */ + public boolean isCFF() { + return isCFF; + } + /** * Read Table Directory from the current position in the @@ -704,9 +721,26 @@ * @throws IOException in case of an I/O problem */ protected void readDirTabs(FontFileReader in) throws IOException { - in.skip(4); // TTF_FIXED_SIZE + + // Read the version value (first 4 bytes): + byte[] verBytes = new byte[4]; + verBytes[0] = in.readTTFByte(); + verBytes[1] = in.readTTFByte(); + verBytes[2] = in.readTTFByte(); + verBytes[3] = in.readTTFByte(); + String version = new String(verBytes, "ISO-8859-1"); + if (verBytes[1] == 0x01) { + getLogger().info("Font is TrueType TTF format"); + } else if (version.equals("OTTO")) { + getLogger().info("Font is OpenType CFF format"); + isCFF = true; + } else { + String msg = "Font does not appear to be either TrueType or OpenType"; + throw new IOException(msg); + } + int ntabs = in.readTTFUShort(); - in.skip(6); // 3xTTF_USHORT_SIZE + in.skip(6); // 3xTTF_USHORT_SIZE. searchRange, entrySelector, rangeShift dirTabs = new java.util.HashMap(); TTFDirTabEntry[] pd = new TTFDirTabEntry[ntabs]; @@ -715,6 +749,15 @@ pd[i] = new TTFDirTabEntry(); dirTabs.put(pd[i].read(in), pd[i]); } + if (getLogger().isDebugEnabled()) { + getLogger().debug("Font table entries:"); + Iterator iter = dirTabs.keySet().iterator(); + while (iter.hasNext()) { + String tag = (String)iter.next(); + TTFDirTabEntry tab = (TTFDirTabEntry)dirTabs.get (tag); + getLogger().debug(tab.getTagString() + ": offset=" + tab.getOffset() + ", length=" + tab.getLength()); + } + } } /** Index: TTFDirTabEntry.java =================================================================== RCS file: /home/cvspublic/xml- fop/src/java/org/apache/fop/fonts/truetype/TTFDirTabEntry.java,v retrieving revision 1.1 diff -w -u -r1.1 TTFDirTabEntry.java --- TTFDirTabEntry.java 11 Mar 2003 13:05:23 -0000 1.1 +++ TTFDirTabEntry.java 8 Jan 2004 19:59:08 -0000 @@ -51,6 +51,7 @@ package org.apache.fop.fonts.truetype; import java.io.IOException; +import java.io.UnsupportedEncodingException; /** @@ -76,9 +77,11 @@ offset = in.readTTFULong(); length = in.readTTFULong(); + String tagStr = new String(tag, "ISO-8859-1"); + // System.err.println("tag='" + tagStr + "'"); //System.out.println(this.toString()); - return new String(tag, "ISO-8859-1"); + return tagStr; } @@ -115,11 +118,23 @@ } /** - * Returns the tag. + * Returns the tag bytes. * @return byte[] */ public byte[] getTag() { return tag; } + + /** + * Returns the tag bytes. + * @return byte[] + */ + public String getTagString() { + try { + return new String(tag, "ISO-8859-1"); + } catch (UnsupportedEncodingException e) { + return this.toString(); // Should never happen. + } + } } Index: TTFReader.java =================================================================== RCS file: /home/cvspublic/xml- fop/src/java/org/apache/fop/fonts/apps/TTFReader.java,v retrieving revision 1.2 diff -w -u -r1.2 TTFReader.java --- TTFReader.java 27 May 2003 14:01:25 -0000 1.2 +++ TTFReader.java 8 Jan 2004 20:18:27 -0000 @@ -396,7 +396,11 @@ generateDOM4SingleByteExtras(root, ttf, isCid); } + // TODO: Need to get equivalent info from GPOS table for + // CFF fonts. + if (!ttf.isCFF()) { generateDOM4Kerning(root, ttf, isCid); + } return doc; } @@ -496,7 +500,6 @@ } else { h2 = (Map)ttf.getAnsiKerning().get(kpx1); } - Iterator enum2 = h2.keySet().iterator(); while (enum2.hasNext()) { Integer kpx2 = (Integer)enum2.next();