From 6025b6016517c6d898d8957d1d7e03ba71431912 Mon Sep 17 00:00:00 2001 From: tknall Date: Fri, 1 Dec 2006 12:20:24 +0000 Subject: Initial import of release 2.2. git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@4 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../java/org/pdfbox/ttf/CMAPEncodingEntry.java | 219 +++++++ src/main/java/org/pdfbox/ttf/CMAPTable.java | 122 ++++ .../java/org/pdfbox/ttf/DigitalSignatureTable.java | 45 ++ src/main/java/org/pdfbox/ttf/GlyphData.java | 125 ++++ src/main/java/org/pdfbox/ttf/GlyphTable.java | 88 +++ src/main/java/org/pdfbox/ttf/HeaderTable.java | 332 ++++++++++ .../java/org/pdfbox/ttf/HorizontalHeaderTable.java | 332 ++++++++++ .../org/pdfbox/ttf/HorizontalMetricsTable.java | 95 +++ .../java/org/pdfbox/ttf/IndexToLocationTable.java | 96 +++ .../java/org/pdfbox/ttf/MaximumProfileTable.java | 300 +++++++++ .../java/org/pdfbox/ttf/MemoryTTFDataStream.java | 231 +++++++ src/main/java/org/pdfbox/ttf/NameRecord.java | 242 +++++++ src/main/java/org/pdfbox/ttf/NamingTable.java | 112 ++++ .../org/pdfbox/ttf/OS2WindowsMetricsTable.java | 694 +++++++++++++++++++++ src/main/java/org/pdfbox/ttf/PostScriptTable.java | 304 +++++++++ src/main/java/org/pdfbox/ttf/RAFDataStream.java | 193 ++++++ src/main/java/org/pdfbox/ttf/TTFDataStream.java | 253 ++++++++ src/main/java/org/pdfbox/ttf/TTFParser.java | 219 +++++++ src/main/java/org/pdfbox/ttf/TTFTable.java | 115 ++++ src/main/java/org/pdfbox/ttf/TrueTypeFont.java | 221 +++++++ src/main/java/org/pdfbox/ttf/package.html | 9 + 21 files changed, 4347 insertions(+) create mode 100644 src/main/java/org/pdfbox/ttf/CMAPEncodingEntry.java create mode 100644 src/main/java/org/pdfbox/ttf/CMAPTable.java create mode 100644 src/main/java/org/pdfbox/ttf/DigitalSignatureTable.java create mode 100644 src/main/java/org/pdfbox/ttf/GlyphData.java create mode 100644 src/main/java/org/pdfbox/ttf/GlyphTable.java create mode 100644 src/main/java/org/pdfbox/ttf/HeaderTable.java create mode 100644 src/main/java/org/pdfbox/ttf/HorizontalHeaderTable.java create mode 100644 src/main/java/org/pdfbox/ttf/HorizontalMetricsTable.java create mode 100644 src/main/java/org/pdfbox/ttf/IndexToLocationTable.java create mode 100644 src/main/java/org/pdfbox/ttf/MaximumProfileTable.java create mode 100644 src/main/java/org/pdfbox/ttf/MemoryTTFDataStream.java create mode 100644 src/main/java/org/pdfbox/ttf/NameRecord.java create mode 100644 src/main/java/org/pdfbox/ttf/NamingTable.java create mode 100644 src/main/java/org/pdfbox/ttf/OS2WindowsMetricsTable.java create mode 100644 src/main/java/org/pdfbox/ttf/PostScriptTable.java create mode 100644 src/main/java/org/pdfbox/ttf/RAFDataStream.java create mode 100644 src/main/java/org/pdfbox/ttf/TTFDataStream.java create mode 100644 src/main/java/org/pdfbox/ttf/TTFParser.java create mode 100644 src/main/java/org/pdfbox/ttf/TTFTable.java create mode 100644 src/main/java/org/pdfbox/ttf/TrueTypeFont.java create mode 100644 src/main/java/org/pdfbox/ttf/package.html (limited to 'src/main/java/org/pdfbox/ttf') diff --git a/src/main/java/org/pdfbox/ttf/CMAPEncodingEntry.java b/src/main/java/org/pdfbox/ttf/CMAPEncodingEntry.java new file mode 100644 index 0000000..a740203 --- /dev/null +++ b/src/main/java/org/pdfbox/ttf/CMAPEncodingEntry.java @@ -0,0 +1,219 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.ttf; + +import java.io.IOException; + +/** + * An encoding entry for a cmap. + * + * @author Ben Litchfield (ben@csh.rit.edu) + * @version $Revision: 1.1 $ + */ +public class CMAPEncodingEntry +{ + + private int platformId; + private int platformEncodingId; + private long subTableOffset; + private int[] glyphIdToCharacterCode; + /** + * This will read the required data from the stream. + * + * @param ttf The font that is being read. + * @param data The stream to read the data from. + * @throws IOException If there is an error reading the data. + */ + public void initData( TrueTypeFont ttf, TTFDataStream data ) throws IOException + { + platformId = data.readUnsignedShort(); + platformEncodingId = data.readUnsignedShort(); + subTableOffset = data.readUnsignedInt(); + } + + /** + * This will read the required data from the stream. + * + * @param ttf The font that is being read. + * @param data The stream to read the data from. + * @throws IOException If there is an error reading the data. + */ + public void initSubtable( TrueTypeFont ttf, TTFDataStream data ) throws IOException + { + data.seek( ttf.getCMAP().getOffset() + subTableOffset ); + int subtableFormat = data.readUnsignedShort(); + int length = data.readUnsignedShort(); + int version = data.readUnsignedShort(); + int numGlyphs = ttf.getMaximumProfile().getNumGlyphs(); + if( subtableFormat == 0 ) + { + byte[] glyphMapping = data.read( 256 ); + glyphIdToCharacterCode = new int[256]; + for( int i=0;i 0 ) + { + endPointsOfContours = new int[ numberOfContours ]; + for( int i=0; i= 1 ) + { + codePageRange1 = data.readUnsignedInt(); + codePageRange2 = data.readUnsignedInt(); + } + } +} diff --git a/src/main/java/org/pdfbox/ttf/PostScriptTable.java b/src/main/java/org/pdfbox/ttf/PostScriptTable.java new file mode 100644 index 0000000..e7b7822 --- /dev/null +++ b/src/main/java/org/pdfbox/ttf/PostScriptTable.java @@ -0,0 +1,304 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.ttf; + +import java.io.IOException; + +import org.pdfbox.cos.COSName; + +import org.pdfbox.encoding.MacRomanEncoding; + +/** + * A table in a true type font. + * + * @author Ben Litchfield (ben@csh.rit.edu) + * @version $Revision: 1.1 $ + */ +public class PostScriptTable extends TTFTable +{ + private float formatType; + private float italicAngle; + private short underlinePosition; + private short underlineThickness; + private long isFixedPitch; + private long minMemType42; + private long maxMemType42; + private long mimMemType1; + private long maxMemType1; + private String[] glyphNames = null; + + /** + * A tag that identifies this table type. + */ + public static final String TAG = "post"; + + /** + * This will read the required data from the stream. + * + * @param ttf The font that is being read. + * @param data The stream to read the data from. + * @throws IOException If there is an error reading the data. + */ + public void initData( TrueTypeFont ttf, TTFDataStream data ) throws IOException + { + MaximumProfileTable maxp = ttf.getMaximumProfile(); + formatType = data.read32Fixed(); + italicAngle = data.read32Fixed(); + underlinePosition = data.readSignedShort(); + underlineThickness = data.readSignedShort(); + isFixedPitch = data.readUnsignedInt(); + minMemType42 = data.readUnsignedInt(); + maxMemType42 = data.readUnsignedInt(); + mimMemType1 = data.readUnsignedInt(); + maxMemType1 = data.readUnsignedInt(); + MacRomanEncoding encoding = new MacRomanEncoding(); + + + if( formatType == 1.0f ) + { + /* + * This TrueType font file contains exactly the 258 glyphs in the standard + * Macintosh TrueType. + */ + glyphNames = new String[258]; + for( int i=0; i= 258 ) + { + nameArray = new String[ maxIndex-258 +1 ]; + for( int i=0; i= 258 && index <= 32767 ) + { + glyphNames[i] = nameArray[index-258]; + } + else + { + throw new IOException( "Unknown glyph name index:" + index ); + } + } + } + else if( formatType == 2.5f ) + { + int[] glyphNameIndex = new int[maxp.getNumGlyphs()]; + for( int i=0; i + * usage: java org.pdfbox.ttf.TTFParser <ttf-file> + * + * @param args The command line arguments. + * + * @throws IOException If there is an error while parsing the font file. + */ + public static void main( String[] args ) throws IOException + { + if( args.length != 1 ) + { + System.err.println( "usage: java org.pdfbox.ttf.TTFParser " ); + System.exit( -1 ); + } + TTFParser parser = new TTFParser(); + TrueTypeFont font = parser.parseTTF( args[0] ); + System.out.println( "Font:" + font ); + } + + /** + * Parse a file and get a true type font. + * @param ttfFile The TTF file. + * @return A true type font. + * @throws IOException If there is an error parsing the true type font. + */ + public TrueTypeFont parseTTF( String ttfFile ) throws IOException + { + RAFDataStream raf = new RAFDataStream( ttfFile, "r" ); + return parseTTF( raf ); + } + + /** + * Parse a file and get a true type font. + * @param ttfFile The TTF file. + * @return A true type font. + * @throws IOException If there is an error parsing the true type font. + */ + public TrueTypeFont parseTTF( File ttfFile ) throws IOException + { + RAFDataStream raf = new RAFDataStream( ttfFile, "r" ); + return parseTTF( raf ); + } + + /** + * Parse a file and get a true type font. + * @param raf The TTF file. + * @return A true type font. + * @throws IOException If there is an error parsing the true type font. + */ + public TrueTypeFont parseTTF( TTFDataStream raf ) throws IOException + { + TrueTypeFont font = new TrueTypeFont( raf ); + font.setVersion( raf.read32Fixed() ); + int numberOfTables = raf.readUnsignedShort(); + int searchRange = raf.readUnsignedShort(); + int entrySelector = raf.readUnsignedShort(); + int rangeShift = raf.readUnsignedShort(); + for( int i=0; i + + + + + +This package contains classes to parse a TTF file. + + -- cgit v1.2.3