You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ju...@apache.org on 2008/07/22 19:20:56 UTC
svn commit: r678810 [3/6] - in /incubator/pdfbox/trunk/fontbox: ./
Resources/ lib/ licenses/ licenses/checkstyle/ licenses/fontbox/
licenses/junit/ src/ src/org/ src/org/fontbox/ src/org/fontbox/afm/
src/org/fontbox/cmap/ src/org/fontbox/encoding/ src/...
Added: incubator/pdfbox/trunk/fontbox/src/org/fontbox/cmap/CMap.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/fontbox/src/org/fontbox/cmap/CMap.java?rev=678810&view=auto
==============================================================================
--- incubator/pdfbox/trunk/fontbox/src/org/fontbox/cmap/CMap.java (added)
+++ incubator/pdfbox/trunk/fontbox/src/org/fontbox/cmap/CMap.java Tue Jul 22 10:20:54 2008
@@ -0,0 +1,173 @@
+/**
+ * Copyright (c) 2005, www.fontbox.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 fontbox; 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.fontbox.org
+ *
+ */
+package org.fontbox.cmap;
+
+import java.io.IOException;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * This class represents a CMap file.
+ *
+ * @author Ben Litchfield (ben@benlitchfield.com)
+ * @version $Revision: 1.3 $
+ */
+public class CMap
+{
+ private List codeSpaceRanges = new ArrayList();
+ private Map singleByteMappings = new HashMap();
+ private Map doubleByteMappings = new HashMap();
+
+ /**
+ * Creates a new instance of CMap.
+ */
+ public CMap()
+ {
+ //default constructor
+ }
+
+ /**
+ * This will tell if this cmap has any one byte mappings.
+ *
+ * @return true If there are any one byte mappings, false otherwise.
+ */
+ public boolean hasOneByteMappings()
+ {
+ return singleByteMappings.size() > 0;
+ }
+
+ /**
+ * This will tell if this cmap has any two byte mappings.
+ *
+ * @return true If there are any two byte mappings, false otherwise.
+ */
+ public boolean hasTwoByteMappings()
+ {
+ return doubleByteMappings.size() > 0;
+ }
+
+ /**
+ * This will perform a lookup into the map.
+ *
+ * @param code The code used to lookup.
+ * @param offset The offset into the byte array.
+ * @param length The length of the data we are getting.
+ *
+ * @return The string that matches the lookup.
+ */
+ public String lookup( byte[] code, int offset, int length )
+ {
+ String result = null;
+ Integer key = null;
+ if( length == 1 )
+ {
+
+ key = new Integer( (code[offset]+256)%256 );
+ result = (String)singleByteMappings.get( key );
+ }
+ else if( length == 2 )
+ {
+ int intKey = (code[offset]+256)%256;
+ intKey <<= 8;
+ intKey += (code[offset+1]+256)%256;
+ key = new Integer( intKey );
+
+ result = (String)doubleByteMappings.get( key );
+ }
+
+ return result;
+ }
+
+ /**
+ * This will add a mapping.
+ *
+ * @param src The src to the mapping.
+ * @param dest The dest to the mapping.
+ *
+ * @throws IOException if the src is invalid.
+ */
+ public void addMapping( byte[] src, String dest ) throws IOException
+ {
+ if( src.length == 1 )
+ {
+ singleByteMappings.put( new Integer( src[0] ), dest );
+ }
+ else if( src.length == 2 )
+ {
+ int intSrc = src[0]&0xFF;
+ intSrc <<= 8;
+ intSrc |= (src[1]&0xFF);
+ doubleByteMappings.put( new Integer( intSrc ), dest );
+ }
+ else
+ {
+ throw new IOException( "Mapping code should be 1 or two bytes and not " + src.length );
+ }
+ }
+
+
+ /**
+ * This will add a codespace range.
+ *
+ * @param range A single codespace range.
+ */
+ public void addCodespaceRange( CodespaceRange range )
+ {
+ codeSpaceRanges.add( range );
+ }
+
+ /**
+ * Getter for property codeSpaceRanges.
+ *
+ * @return Value of property codeSpaceRanges.
+ */
+ public List getCodeSpaceRanges()
+ {
+ return codeSpaceRanges;
+ }
+
+ /**
+ * Implementation of the usecmap operator. This will
+ * copy all of the mappings from one cmap to another.
+ *
+ * @param cmap The cmap to load mappings from.
+ */
+ public void useCmap( CMap cmap )
+ {
+ this.codeSpaceRanges.addAll( cmap.codeSpaceRanges );
+ this.singleByteMappings.putAll( cmap.singleByteMappings );
+ this.doubleByteMappings.putAll( cmap.doubleByteMappings );
+ }
+
+}
\ No newline at end of file
Added: incubator/pdfbox/trunk/fontbox/src/org/fontbox/cmap/CMapParser.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/fontbox/src/org/fontbox/cmap/CMapParser.java?rev=678810&view=auto
==============================================================================
--- incubator/pdfbox/trunk/fontbox/src/org/fontbox/cmap/CMapParser.java (added)
+++ incubator/pdfbox/trunk/fontbox/src/org/fontbox/cmap/CMapParser.java Tue Jul 22 10:20:54 2008
@@ -0,0 +1,539 @@
+/**
+ * Copyright (c) 2005-2006, www.fontbox.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 fontbox; 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.fontbox.org
+ *
+ */
+package org.fontbox.cmap;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.PushbackInputStream;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.fontbox.util.ResourceLoader;
+
+/**
+ * This will parser a CMap stream.
+ *
+ * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
+ * @version $Revision: 1.9 $
+ */
+public class CMapParser
+{
+ private static final String BEGIN_CODESPACE_RANGE = "begincodespacerange";
+ private static final String BEGIN_BASE_FONT_CHAR = "beginbfchar";
+ private static final String BEGIN_BASE_FONT_RANGE = "beginbfrange";
+ private static final String USECMAP = "usecmap";
+
+ private static final String MARK_END_OF_DICTIONARY = ">>";
+ private static final String MARK_END_OF_ARRAY = "]";
+
+
+ private byte[] tokenParserByteBuffer = new byte[512];
+
+ /**
+ * Creates a new instance of CMapParser.
+ */
+ public CMapParser()
+ {
+ }
+
+ /**
+ * Parse a CMAP file on the file system.
+ *
+ * @param file The file to parse.
+ *
+ * @return A parsed CMAP file.
+ *
+ * @throws IOException If there is an issue while parsing the CMAP.
+ */
+ public CMap parse( File file ) throws IOException
+ {
+ String rootDir = file.getParent() + File.separator;
+ FileInputStream input = null;
+ try
+ {
+ input = new FileInputStream( file );
+ return parse( rootDir, input );
+ }
+ finally
+ {
+ if( input != null )
+ {
+ input.close();
+ }
+ }
+
+ }
+
+ /**
+ * This will parse the stream and create a cmap object.
+ *
+ * @param resourceRoot The root path to the cmap file. This will be used
+ * to find referenced cmap files. It can be null.
+ * @param input The CMAP stream to parse.
+ *
+ * @return The parsed stream as a java object.
+ *
+ * @throws IOException If there is an error parsing the stream.
+ */
+ public CMap parse( String resourceRoot, InputStream input ) throws IOException
+ {
+ PushbackInputStream cmapStream = new PushbackInputStream( input );
+ CMap result = new CMap();
+ Object previousToken = null;
+ Object token = null;
+ while( (token = parseNextToken( cmapStream )) != null )
+ {
+ if( token instanceof Operator )
+ {
+ Operator op = (Operator)token;
+ if( op.op.equals( USECMAP ) )
+ {
+ LiteralName useCmapName = (LiteralName)previousToken;
+ InputStream useStream = ResourceLoader.loadResource( resourceRoot + useCmapName.name );
+ if( useStream == null )
+ {
+ throw new IOException( "Error: Could not find referenced cmap stream " + useCmapName.name );
+ }
+ CMap useCMap = parse( resourceRoot, useStream );
+ result.useCmap( useCMap );
+ }
+ else if( op.op.equals( BEGIN_CODESPACE_RANGE ) )
+ {
+ Number cosCount = (Number)previousToken;
+ for( int j=0; j<cosCount.intValue(); j++ )
+ {
+ byte[] startRange = (byte[])parseNextToken( cmapStream );
+ byte[] endRange = (byte[])parseNextToken( cmapStream );
+ CodespaceRange range = new CodespaceRange();
+ range.setStart( startRange );
+ range.setEnd( endRange );
+ result.addCodespaceRange( range );
+ }
+ }
+ else if( op.op.equals( BEGIN_BASE_FONT_CHAR ) )
+ {
+ Number cosCount = (Number)previousToken;
+ for( int j=0; j<cosCount.intValue(); j++ )
+ {
+ byte[] inputCode = (byte[])parseNextToken( cmapStream );
+ Object nextToken = parseNextToken( cmapStream );
+ if( nextToken instanceof byte[] )
+ {
+ byte[] bytes = (byte[])nextToken;
+ String value = createStringFromBytes( bytes );
+ result.addMapping( inputCode, value );
+ }
+ else if( nextToken instanceof LiteralName )
+ {
+ result.addMapping( inputCode, ((LiteralName)nextToken).name );
+ }
+ else
+ {
+ throw new IOException( "Error parsing CMap beginbfchar, expected{COSString " +
+ "or COSName} and not " + nextToken );
+ }
+ }
+ }
+ else if( op.op.equals( BEGIN_BASE_FONT_RANGE ) )
+ {
+ Number cosCount = (Number)previousToken;
+
+ for( int j=0; j<cosCount.intValue(); j++ )
+ {
+ byte[] startCode = (byte[])parseNextToken( cmapStream );
+ byte[] endCode = (byte[])parseNextToken( cmapStream );
+ Object nextToken = parseNextToken( cmapStream );
+ List array = null;
+ byte[] tokenBytes = null;
+ if( nextToken instanceof List )
+ {
+ array = (List)nextToken;
+ tokenBytes = (byte[])array.get( 0 );
+ }
+ else
+ {
+ tokenBytes = (byte[])nextToken;
+ }
+
+ String value = null;
+
+ int arrayIndex = 0;
+ boolean done = false;
+ while( !done )
+ {
+ if( compare( startCode, endCode ) >= 0 )
+ {
+ done = true;
+ }
+ value = createStringFromBytes( tokenBytes );
+ result.addMapping( startCode, value );
+ increment( startCode );
+
+ if( array == null )
+ {
+ increment( tokenBytes );
+ }
+ else
+ {
+ arrayIndex++;
+ if( arrayIndex < array.size() )
+ {
+ tokenBytes = (byte[])array.get( arrayIndex );
+ }
+ }
+ }
+ }
+ }
+ }
+ previousToken = token;
+ }
+ return result;
+ }
+
+ private Object parseNextToken( PushbackInputStream is ) throws IOException
+ {
+ Object retval = null;
+ int nextByte = is.read();
+ //skip whitespace
+ while( nextByte == 0x09 || nextByte == 0x20 || nextByte == 0x0D || nextByte == 0x0A )
+ {
+ nextByte = is.read();
+ }
+ switch( nextByte )
+ {
+ case '%':
+ {
+ //header operations, for now return the entire line
+ //may need to smarter in the future
+ StringBuffer buffer = new StringBuffer();
+ buffer.append( (char)nextByte );
+ readUntilEndOfLine( is, buffer );
+ retval = buffer.toString();
+ break;
+ }
+ case '(':
+ {
+ StringBuffer buffer = new StringBuffer();
+ int stringByte = is.read();
+
+ while( stringByte != -1 && stringByte != ')' )
+ {
+ buffer.append( (char)stringByte );
+ stringByte = is.read();
+ }
+ retval = buffer.toString();
+ break;
+ }
+ case '>':
+ {
+ int secondCloseBrace = is.read();
+ if( secondCloseBrace == '>' )
+ {
+ retval = MARK_END_OF_DICTIONARY;
+ }
+ else
+ {
+ throw new IOException( "Error: expected the end of a dictionary.");
+ }
+ break;
+ }
+ case ']':
+ {
+ retval = MARK_END_OF_ARRAY;
+ break;
+ }
+ case '[':
+ {
+ List list = new ArrayList();
+
+ Object nextToken = parseNextToken( is );
+ while( nextToken != null && nextToken != MARK_END_OF_ARRAY )
+ {
+ list.add( nextToken );
+ nextToken = parseNextToken( is );
+ }
+ retval = list;
+ break;
+ }
+ case '<':
+ {
+ int theNextByte = is.read();
+ if( theNextByte == '<' )
+ {
+ Map result = new HashMap();
+ //we are reading a dictionary
+ Object key = parseNextToken( is );
+ while( key instanceof LiteralName && key != MARK_END_OF_DICTIONARY )
+ {
+ Object value = parseNextToken( is );
+ result.put( ((LiteralName)key).name, value );
+ key = parseNextToken( is );
+ }
+ retval = result;
+ }
+ else
+ {
+ //won't read more than 512 bytes
+
+ int multiplyer = 16;
+ int bufferIndex = -1;
+ while( theNextByte != -1 && theNextByte != '>' )
+ {
+ int intValue = 0;
+ if( theNextByte >= '0' && theNextByte <= '9' )
+ {
+ intValue = theNextByte - '0';
+ }
+ else if( theNextByte >= 'A' && theNextByte <= 'F' )
+ {
+ intValue = 10 + theNextByte - 'A';
+ }
+ else if( theNextByte >= 'a' && theNextByte <= 'f' )
+ {
+ intValue = 10 + theNextByte - 'a';
+ }
+ else
+ {
+ throw new IOException( "Error: expected hex character and not " +
+ (char)theNextByte + ":" + theNextByte );
+ }
+ intValue *= multiplyer;
+ if( multiplyer == 16 )
+ {
+ bufferIndex++;
+ tokenParserByteBuffer[bufferIndex] = 0;
+ multiplyer = 1;
+ }
+ else
+ {
+ multiplyer = 16;
+ }
+ tokenParserByteBuffer[bufferIndex]+= intValue;
+ theNextByte = is.read();
+ }
+ byte[] finalResult = new byte[bufferIndex+1];
+ System.arraycopy(tokenParserByteBuffer,0,finalResult, 0, bufferIndex+1);
+ retval = finalResult;
+ }
+ break;
+ }
+ case '/':
+ {
+ StringBuffer buffer = new StringBuffer();
+ int stringByte = is.read();
+
+ while( !isWhitespaceOrEOF( stringByte ) )
+ {
+ buffer.append( (char)stringByte );
+ stringByte = is.read();
+ }
+ retval = new LiteralName( buffer.toString() );
+ break;
+ }
+ case -1:
+ {
+ //EOF return null;
+ break;
+ }
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append( (char)nextByte );
+ nextByte = is.read();
+
+ while( !isWhitespaceOrEOF( nextByte ) &&
+ (Character.isDigit( (char)nextByte )||
+ nextByte == '.' ) )
+ {
+ buffer.append( (char)nextByte );
+ nextByte = is.read();
+ }
+ is.unread( nextByte );
+ String value = buffer.toString();
+ if( value.indexOf( '.' ) >=0 )
+ {
+ retval = new Double( value );
+ }
+ else
+ {
+ retval = new Integer( buffer.toString() );
+ }
+ break;
+ }
+ default:
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append( (char)nextByte );
+ nextByte = is.read();
+
+ while( !isWhitespaceOrEOF( nextByte ) )
+ {
+ buffer.append( (char)nextByte );
+ nextByte = is.read();
+ }
+ retval = new Operator( buffer.toString() );
+
+ break;
+ }
+ }
+ return retval;
+ }
+
+ private void readUntilEndOfLine( InputStream is, StringBuffer buf ) throws IOException
+ {
+ int nextByte = is.read();
+ while( nextByte != -1 && nextByte != 0x0D && nextByte != 0x0A )
+ {
+ buf.append( (char)nextByte );
+ nextByte = is.read();
+ }
+ }
+
+ private boolean isWhitespaceOrEOF( int aByte )
+ {
+ return aByte == -1 || aByte == 0x20 || aByte == 0x0D || aByte == 0x0A;
+ }
+
+
+ private void increment( byte[] data )
+ {
+ increment( data, data.length-1 );
+ }
+
+ private void increment( byte[] data, int position )
+ {
+ if( position > 0 && (data[position]+256)%256 == 255 )
+ {
+ data[position]=0;
+ increment( data, position-1);
+ }
+ else
+ {
+ data[position] = (byte)(data[position]+1);
+ }
+ }
+
+ private String createStringFromBytes( byte[] bytes ) throws IOException
+ {
+ String retval = null;
+ if( bytes.length == 1 )
+ {
+ retval = new String( bytes );
+ }
+ else
+ {
+ retval = new String( bytes, "UTF-16BE" );
+ }
+ return retval;
+ }
+
+ private int compare( byte[] first, byte[] second )
+ {
+ int retval = 1;
+ boolean done = false;
+ for( int i=0; i<first.length && !done; i++ )
+ {
+ if( first[i] == second[i] )
+ {
+ //move to next position
+ }
+ else if( ((first[i]+256)%256) < ((second[i]+256)%256) )
+ {
+ done = true;
+ retval = -1;
+ }
+ else
+ {
+ done = true;
+ retval = 1;
+ }
+ }
+ return retval;
+ }
+
+ /**
+ * Internal class.
+ */
+ private class LiteralName
+ {
+ private String name;
+ private LiteralName( String theName )
+ {
+ name = theName;
+ }
+ }
+
+ /**
+ * Internal class.
+ */
+ private class Operator
+ {
+ private String op;
+ private Operator( String theOp )
+ {
+ op = theOp;
+ }
+ }
+
+ /**
+ * A simple class to test parsing of cmap files.
+ *
+ * @param args Some command line arguments.
+ *
+ * @throws Exception If there is an error parsing the file.
+ */
+ public static void main( String[] args ) throws Exception
+ {
+ if( args.length != 1 )
+ {
+ System.err.println( "usage: java org.pdfbox.cmapparser.CMapParser <CMAP File>" );
+ System.exit( -1 );
+ }
+ CMapParser parser = new CMapParser( );
+ File cmapFile = new File( args[0] );
+ CMap result = parser.parse( cmapFile );
+ System.out.println( "Result:" + result );
+ }
+}
\ No newline at end of file
Added: incubator/pdfbox/trunk/fontbox/src/org/fontbox/cmap/CodespaceRange.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/fontbox/src/org/fontbox/cmap/CodespaceRange.java?rev=678810&view=auto
==============================================================================
--- incubator/pdfbox/trunk/fontbox/src/org/fontbox/cmap/CodespaceRange.java (added)
+++ incubator/pdfbox/trunk/fontbox/src/org/fontbox/cmap/CodespaceRange.java Tue Jul 22 10:20:54 2008
@@ -0,0 +1,88 @@
+/**
+ * Copyright (c) 2005, www.fontbox.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 fontbox; 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.fontbox.org
+ *
+ */
+package org.fontbox.cmap;
+
+/**
+ * This represents a single entry in the codespace range.
+ *
+ * @author Ben Litchfield (ben@benlitchfield.com)
+ * @version $Revision: 1.1 $
+ */
+public class CodespaceRange
+{
+
+ private byte[] start;
+ private byte[] end;
+
+ /**
+ * Creates a new instance of CodespaceRange.
+ */
+ public CodespaceRange()
+ {
+ }
+
+ /** Getter for property end.
+ * @return Value of property end.
+ *
+ */
+ public byte[] getEnd()
+ {
+ return this.end;
+ }
+
+ /** Setter for property end.
+ * @param endBytes New value of property end.
+ *
+ */
+ public void setEnd(byte[] endBytes)
+ {
+ end = endBytes;
+ }
+
+ /** Getter for property start.
+ * @return Value of property start.
+ *
+ */
+ public byte[] getStart()
+ {
+ return this.start;
+ }
+
+ /** Setter for property start.
+ * @param startBytes New value of property start.
+ *
+ */
+ public void setStart(byte[] startBytes)
+ {
+ start = startBytes;
+ }
+
+}
\ No newline at end of file
Added: incubator/pdfbox/trunk/fontbox/src/org/fontbox/cmap/package.html
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/fontbox/src/org/fontbox/cmap/package.html?rev=678810&view=auto
==============================================================================
--- incubator/pdfbox/trunk/fontbox/src/org/fontbox/cmap/package.html (added)
+++ incubator/pdfbox/trunk/fontbox/src/org/fontbox/cmap/package.html Tue Jul 22 10:20:54 2008
@@ -0,0 +1,9 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+
+</head>
+<body>
+This package holds classes that are necessary to parse cmap files.
+</body>
+</html>
Added: incubator/pdfbox/trunk/fontbox/src/org/fontbox/encoding/Encoding.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/fontbox/src/org/fontbox/encoding/Encoding.java?rev=678810&view=auto
==============================================================================
--- incubator/pdfbox/trunk/fontbox/src/org/fontbox/encoding/Encoding.java (added)
+++ incubator/pdfbox/trunk/fontbox/src/org/fontbox/encoding/Encoding.java Tue Jul 22 10:20:54 2008
@@ -0,0 +1,169 @@
+/**
+ * Copyright (c) 2003-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.fontbox.encoding;
+
+import java.io.IOException;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * This is an interface to a text encoder.
+ *
+ * @author Ben Litchfield
+ * @version $Revision: 1.1 $
+ */
+public abstract class Encoding
+{
+
+
+ /**
+ * This is a mapping from a character code to a character name.
+ */
+ protected Map codeToName = new HashMap();
+ /**
+ * This is a mapping from a character name to a character code.
+ */
+ protected Map nameToCode = new HashMap();
+
+ private static final Map NAME_TO_CHARACTER = new HashMap();
+ private static final Map CHARACTER_TO_NAME = new HashMap();
+
+ static
+ {
+ }
+
+
+ /**
+ * This will add a character encoding.
+ *
+ * @param code The character code that matches the character.
+ * @param name The name of the character.
+ */
+ protected void addCharacterEncoding( int code, String name )
+ {
+ Integer intCode = new Integer( code );
+ codeToName.put( intCode, name );
+ nameToCode.put( name, intCode );
+ }
+
+ /**
+ * This will get the character code for the name.
+ *
+ * @param name The name of the character.
+ *
+ * @return The code for the character.
+ *
+ * @throws IOException If there is no character code for the name.
+ */
+ public int getCode( String name ) throws IOException
+ {
+ Integer code = (Integer)nameToCode.get( name );
+ if( code == null )
+ {
+ throw new IOException( "No character code for character name '" + name + "'" );
+ }
+ return code.intValue();
+ }
+
+ /**
+ * This will take a character code and get the name from the code.
+ *
+ * @param code The character code.
+ *
+ * @return The name of the character.
+ *
+ * @throws IOException If there is no name for the code.
+ */
+ public String getName( int code ) throws IOException
+ {
+ String name = (String)codeToName.get( new Integer( code ) );
+ if( name == null )
+ {
+ //lets be forgiving for now
+ name = "space";
+ //throw new IOException( getClass().getName() +
+ // ": No name for character code '" + code + "'" );
+ }
+ return name;
+ }
+
+ /**
+ * This will take a character code and get the name from the code.
+ *
+ * @param c The character.
+ *
+ * @return The name of the character.
+ *
+ * @throws IOException If there is no name for the character.
+ */
+ public String getNameFromCharacter( char c ) throws IOException
+ {
+ String name = (String)CHARACTER_TO_NAME.get( "" + c );
+ if( name == null )
+ {
+ throw new IOException( "No name for character '" + c + "'" );
+ }
+ return name;
+ }
+
+ /**
+ * This will get the character from the code.
+ *
+ * @param code The character code.
+ *
+ * @return The printable character for the code.
+ *
+ * @throws IOException If there is not name for the character.
+ */
+ public String getCharacter( int code ) throws IOException
+ {
+ String character = getCharacter( getName( code ) );
+ return character;
+ }
+
+ /**
+ * This will get the character from the name.
+ *
+ * @param name The name of the character.
+ *
+ * @return The printable character for the code.
+ */
+ public static String getCharacter( String name )
+ {
+ String character = (String)NAME_TO_CHARACTER.get( name );
+ if( character == null )
+ {
+ character = name;
+ }
+ return character;
+ }
+}
\ No newline at end of file
Added: incubator/pdfbox/trunk/fontbox/src/org/fontbox/encoding/MacRomanEncoding.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/fontbox/src/org/fontbox/encoding/MacRomanEncoding.java?rev=678810&view=auto
==============================================================================
--- incubator/pdfbox/trunk/fontbox/src/org/fontbox/encoding/MacRomanEncoding.java (added)
+++ incubator/pdfbox/trunk/fontbox/src/org/fontbox/encoding/MacRomanEncoding.java Tue Jul 22 10:20:54 2008
@@ -0,0 +1,254 @@
+/**
+ * Copyright (c) 2003, 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.fontbox.encoding;
+
+/**
+ * This is an interface to a text encoder.
+ *
+ * @author Ben Litchfield
+ * @version $Revision: 1.1 $
+ */
+public class MacRomanEncoding extends Encoding
+{
+ /**
+ * Constructor.
+ */
+ public MacRomanEncoding()
+ {
+ addCharacterEncoding( 0101, "A" );
+ addCharacterEncoding( 0256, "AE" );
+ addCharacterEncoding( 0347, "Aacute" );
+ addCharacterEncoding( 0345, "Acircumflex" );
+ addCharacterEncoding( 0200, "Adieresis" );
+ addCharacterEncoding( 0313, "Agrave" );
+ addCharacterEncoding( 0201, "Aring" );
+ addCharacterEncoding( 0314, "Atilde" );
+ addCharacterEncoding( 0102, "B" );
+ addCharacterEncoding( 0103, "C" );
+ addCharacterEncoding( 0202, "Ccedilla" );
+ addCharacterEncoding( 0104, "D" );
+ addCharacterEncoding( 0105, "E" );
+ addCharacterEncoding( 0203, "Eacute" );
+ addCharacterEncoding( 0346, "Ecircumflex" );
+ addCharacterEncoding( 0350, "Edieresis" );
+ addCharacterEncoding( 0351, "Egrave" );
+ addCharacterEncoding( 0106, "F" );
+ addCharacterEncoding( 0107, "G" );
+ addCharacterEncoding( 0110, "H" );
+ addCharacterEncoding( 0111, "I" );
+ addCharacterEncoding( 0352, "Iacute" );
+ addCharacterEncoding( 0353, "Icircumflex" );
+ addCharacterEncoding( 0354, "Idieresis" );
+ addCharacterEncoding( 0355, "Igrave" );
+ addCharacterEncoding( 0112, "J" );
+ addCharacterEncoding( 0113, "K" );
+ addCharacterEncoding( 0114, "L" );
+ addCharacterEncoding( 0115, "M" );
+ addCharacterEncoding( 0116, "N" );
+ addCharacterEncoding( 0204, "Ntilde" );
+ addCharacterEncoding( 0117, "O" );
+ addCharacterEncoding( 0316, "OE" );
+ addCharacterEncoding( 0356, "Oacute" );
+ addCharacterEncoding( 0357, "Ocircumflex" );
+ addCharacterEncoding( 0205, "Odieresis" );
+ addCharacterEncoding( 0361, "Ograve" );
+ addCharacterEncoding( 0257, "Oslash" );
+ addCharacterEncoding( 0315, "Otilde" );
+ addCharacterEncoding( 0120, "P" );
+ addCharacterEncoding( 0121, "Q" );
+ addCharacterEncoding( 0122, "R" );
+ addCharacterEncoding( 0123, "S" );
+ addCharacterEncoding( 0124, "T" );
+ addCharacterEncoding( 0125, "U" );
+ addCharacterEncoding( 0362, "Uacute" );
+ addCharacterEncoding( 0363, "Ucircumflex" );
+ addCharacterEncoding( 0206, "Udieresis" );
+ addCharacterEncoding( 0364, "Ugrave" );
+ addCharacterEncoding( 0126, "V" );
+ addCharacterEncoding( 0127, "W" );
+ addCharacterEncoding( 0130, "X" );
+ addCharacterEncoding( 0131, "Y" );
+ addCharacterEncoding( 0331, "Ydieresis" );
+ addCharacterEncoding( 0132, "Z" );
+ addCharacterEncoding( 0141, "a" );
+ addCharacterEncoding( 0207, "aacute" );
+ addCharacterEncoding( 0211, "acircumflex" );
+ addCharacterEncoding( 0253, "acute" );
+ addCharacterEncoding( 0212, "adieresis" );
+ addCharacterEncoding( 0276, "ae" );
+ addCharacterEncoding( 0210, "agrave" );
+ addCharacterEncoding( 046, "ampersand" );
+ addCharacterEncoding( 0214, "aring" );
+ addCharacterEncoding( 0136, "asciicircum" );
+ addCharacterEncoding( 0176, "asciitilde" );
+ addCharacterEncoding( 052, "asterisk" );
+ addCharacterEncoding( 0100, "at" );
+ addCharacterEncoding( 0213, "atilde" );
+ addCharacterEncoding( 0142, "b" );
+ addCharacterEncoding( 0134, "backslash" );
+ addCharacterEncoding( 0174, "bar" );
+ addCharacterEncoding( 0173, "braceleft" );
+ addCharacterEncoding( 0175, "braceright" );
+ addCharacterEncoding( 0133, "bracketleft" );
+ addCharacterEncoding( 0135, "bracketright" );
+ addCharacterEncoding( 0371, "breve" );
+ addCharacterEncoding( 0245, "bullet" );
+ addCharacterEncoding( 0143, "c" );
+ addCharacterEncoding( 0377, "caron" );
+ addCharacterEncoding( 0215, "ccedilla" );
+ addCharacterEncoding( 0374, "cedilla" );
+ addCharacterEncoding( 0242, "cent" );
+ addCharacterEncoding( 0366, "circumflex" );
+ addCharacterEncoding( 072, "colon" );
+ addCharacterEncoding( 054, "comma" );
+ addCharacterEncoding( 0251, "copyright" );
+ addCharacterEncoding( 0333, "currency1" );
+ addCharacterEncoding( 0144, "d" );
+ addCharacterEncoding( 0240, "dagger" );
+ addCharacterEncoding( 0340, "daggerdbl" );
+ addCharacterEncoding( 0241, "degree" );
+ addCharacterEncoding( 0254, "dieresis" );
+ addCharacterEncoding( 0326, "divide" );
+ addCharacterEncoding( 044, "dollar" );
+ addCharacterEncoding( 0372, "dotaccent" );
+ addCharacterEncoding( 0365, "dotlessi" );
+ addCharacterEncoding( 0145, "e" );
+ addCharacterEncoding( 0216, "eacute" );
+ addCharacterEncoding( 0220, "ecircumflex" );
+ addCharacterEncoding( 0221, "edieresis" );
+ addCharacterEncoding( 0217, "egrave" );
+ addCharacterEncoding( 070, "eight" );
+ addCharacterEncoding( 0311, "ellipsis" );
+ addCharacterEncoding( 0321, "emdash" );
+ addCharacterEncoding( 0320, "endash" );
+ addCharacterEncoding( 075, "equal" );
+ addCharacterEncoding( 041, "exclam" );
+ addCharacterEncoding( 0301, "exclamdown" );
+ addCharacterEncoding( 0146, "f" );
+ addCharacterEncoding( 0336, "fi" );
+ addCharacterEncoding( 065, "five" );
+ addCharacterEncoding( 0337, "fl" );
+ addCharacterEncoding( 0304, "florin" );
+ addCharacterEncoding( 064, "four" );
+ addCharacterEncoding( 0332, "fraction" );
+ addCharacterEncoding( 0147, "g" );
+ addCharacterEncoding( 0247, "germandbls" );
+ addCharacterEncoding( 0140, "grave" );
+ addCharacterEncoding( 076, "greater" );
+ addCharacterEncoding( 0307, "guillemotleft" );
+ addCharacterEncoding( 0310, "guillemotright" );
+ addCharacterEncoding( 0334, "guilsinglleft" );
+ addCharacterEncoding( 0335, "guilsinglright" );
+ addCharacterEncoding( 0150, "h" );
+ addCharacterEncoding( 0375, "hungarumlaut" );
+ addCharacterEncoding( 055, "hyphen" );
+ addCharacterEncoding( 0151, "i" );
+ addCharacterEncoding( 0222, "iacute" );
+ addCharacterEncoding( 0224, "icircumflex" );
+ addCharacterEncoding( 0225, "idieresis" );
+ addCharacterEncoding( 0223, "igrave" );
+ addCharacterEncoding( 0152, "j" );
+ addCharacterEncoding( 0153, "k" );
+ addCharacterEncoding( 0154, "l" );
+ addCharacterEncoding( 074, "less" );
+ addCharacterEncoding( 0302, "logicalnot" );
+ addCharacterEncoding( 0155, "m" );
+ addCharacterEncoding( 0370, "macron" );
+ addCharacterEncoding( 0265, "mu" );
+ addCharacterEncoding( 0156, "n" );
+ addCharacterEncoding( 071, "nine" );
+ addCharacterEncoding( 0226, "ntilde" );
+ addCharacterEncoding( 043, "numbersign" );
+ addCharacterEncoding( 0157, "o" );
+ addCharacterEncoding( 0227, "oacute" );
+ addCharacterEncoding( 0231, "ocircumflex" );
+ addCharacterEncoding( 0232, "odieresis" );
+ addCharacterEncoding( 0317, "oe" );
+ addCharacterEncoding( 0376, "ogonek" );
+ addCharacterEncoding( 0230, "ograve" );
+ addCharacterEncoding( 061, "one" );
+ addCharacterEncoding( 0273, "ordfeminine" );
+ addCharacterEncoding( 0274, "ordmasculine" );
+ addCharacterEncoding( 0277, "oslash" );
+ addCharacterEncoding( 0233, "otilde" );
+ addCharacterEncoding( 0160, "p" );
+ addCharacterEncoding( 0246, "paragraph" );
+ addCharacterEncoding( 050, "parenleft" );
+ addCharacterEncoding( 051, "parenright" );
+ addCharacterEncoding( 045, "percent" );
+ addCharacterEncoding( 056, "period" );
+ addCharacterEncoding( 0341, "periodcentered" );
+ addCharacterEncoding( 0344, "perthousand" );
+ addCharacterEncoding( 053, "plus" );
+ addCharacterEncoding( 0261, "plusminus" );
+ addCharacterEncoding( 0161, "q" );
+ addCharacterEncoding( 077, "question" );
+ addCharacterEncoding( 0300, "questiondown" );
+ addCharacterEncoding( 042, "quotedbl" );
+ addCharacterEncoding( 0343, "quotedblbase" );
+ addCharacterEncoding( 0322, "quotedblleft" );
+ addCharacterEncoding( 0323, "quotedblright" );
+ addCharacterEncoding( 0324, "quoteleft" );
+ addCharacterEncoding( 0325, "quoteright" );
+ addCharacterEncoding( 0342, "quotesinglbase" );
+ addCharacterEncoding( 047, "quotesingle" );
+ addCharacterEncoding( 0162, "r" );
+ addCharacterEncoding( 0250, "registered" );
+ addCharacterEncoding( 0373, "ring" );
+ addCharacterEncoding( 0163, "s" );
+ addCharacterEncoding( 0244, "section" );
+ addCharacterEncoding( 073, "semicolon" );
+ addCharacterEncoding( 067, "seven" );
+ addCharacterEncoding( 066, "six" );
+ addCharacterEncoding( 057, "slash" );
+ addCharacterEncoding( 040, "space" );
+ addCharacterEncoding( 0243, "sterling" );
+ addCharacterEncoding( 0164, "t" );
+ addCharacterEncoding( 063, "three" );
+ addCharacterEncoding( 0367, "tilde" );
+ addCharacterEncoding( 0252, "trademark" );
+ addCharacterEncoding( 062, "two" );
+ addCharacterEncoding( 0165, "u" );
+ addCharacterEncoding( 0234, "uacute" );
+ addCharacterEncoding( 0236, "ucircumflex" );
+ addCharacterEncoding( 0237, "udieresis" );
+ addCharacterEncoding( 0235, "ugrave" );
+ addCharacterEncoding( 0137, "underscore" );
+ addCharacterEncoding( 0166, "v" );
+ addCharacterEncoding( 0167, "w" );
+ addCharacterEncoding( 0170, "x" );
+ addCharacterEncoding( 0171, "y" );
+ addCharacterEncoding( 0330, "ydieresis" );
+ addCharacterEncoding( 0264, "yen" );
+ addCharacterEncoding( 0172, "z" );
+ addCharacterEncoding( 060, "zero" );
+ }
+}
\ No newline at end of file
Added: incubator/pdfbox/trunk/fontbox/src/org/fontbox/encoding/package.html
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/fontbox/src/org/fontbox/encoding/package.html?rev=678810&view=auto
==============================================================================
--- incubator/pdfbox/trunk/fontbox/src/org/fontbox/encoding/package.html (added)
+++ incubator/pdfbox/trunk/fontbox/src/org/fontbox/encoding/package.html Tue Jul 22 10:20:54 2008
@@ -0,0 +1,9 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+
+</head>
+<body>
+This package contains the implementations for all of the encodings that are used in PDF documents.
+</body>
+</html>
Added: incubator/pdfbox/trunk/fontbox/src/org/fontbox/pfb/PfbParser.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/fontbox/src/org/fontbox/pfb/PfbParser.java?rev=678810&view=auto
==============================================================================
--- incubator/pdfbox/trunk/fontbox/src/org/fontbox/pfb/PfbParser.java (added)
+++ incubator/pdfbox/trunk/fontbox/src/org/fontbox/pfb/PfbParser.java Tue Jul 22 10:20:54 2008
@@ -0,0 +1,211 @@
+/**
+ * Copyright (c) 2005, www.fontbox.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 fontbox; 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.fontbox.org
+ *
+ */
+package org.fontbox.pfb;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.EOFException;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Parser for a pfb-file.
+ *
+ * @author Ben Litchfield (ben@benlitchfield.com)
+ * @author <a href="mailto:m.g.n@gmx.de">Michael Niedermair</a>
+ * @version $Revision: 1.1 $
+ */
+public class PfbParser
+{
+ /**
+ * the pdf header length.
+ * (start-marker (1 byte), ascii-/binary-marker (1 byte), size (4 byte))
+ * 3*6 == 18
+ */
+ private static final int PFB_HEADER_LENGTH = 18;
+
+ /**
+ * the start marker.
+ */
+ private static final int START_MARKER = 0x80;
+
+ /**
+ * the ascii marker.
+ */
+ private static final int ASCII_MARKER = 0x01;
+
+ /**
+ * the binary marker.
+ */
+ private static final int BINARY_MARKER = 0x02;
+
+ /**
+ * The record types in the pfb-file.
+ */
+ private static final int[] PFB_RECORDS = {ASCII_MARKER, BINARY_MARKER,
+ ASCII_MARKER};
+
+ /**
+ * buffersize.
+ */
+ private static final int BUFFER_SIZE = 0xffff;
+
+ /**
+ * the parsed pfb-data.
+ */
+ private byte[] pfbdata;
+
+ /**
+ * the lengths of the records.
+ */
+ private int[] lengths;
+
+ // sample (pfb-file)
+ // 00000000 80 01 8b 15 00 00 25 21 50 53 2d 41 64 6f 62 65
+ // ......%!PS-Adobe
+
+
+ /**
+ * Create a new object.
+ * @param filename the file name
+ * @throws IOException if an IO-error occurs.
+ */
+ public PfbParser(final String filename) throws IOException
+ {
+ this( new BufferedInputStream(new FileInputStream(filename),BUFFER_SIZE) );
+ }
+
+ /**
+ * Create a new object.
+ * @param in The input.
+ * @throws IOException if an IO-error occurs.
+ */
+ public PfbParser(final InputStream in) throws IOException
+ {
+ byte[] pfb = readPfbInput(in);
+ parsePfb(pfb);
+ }
+
+ /**
+ * Parse the pfb-array.
+ * @param pfb The pfb-Array
+ * @throws IOException in an IO-error occurs.
+ */
+ private void parsePfb(final byte[] pfb) throws IOException
+ {
+
+ ByteArrayInputStream in = new ByteArrayInputStream(pfb);
+ pfbdata = new byte[pfb.length - PFB_HEADER_LENGTH];
+ lengths = new int[PFB_RECORDS.length];
+ int pointer = 0;
+ for (int records = 0; records < PFB_RECORDS.length; records++)
+ {
+ if (in.read() != START_MARKER)
+ {
+ throw new IOException("Start marker missing");
+ }
+
+ if (in.read() != PFB_RECORDS[records])
+ {
+ throw new IOException("Incorrect record type");
+ }
+
+ int size = in.read();
+ size += in.read() << 8;
+ size += in.read() << 16;
+ size += in.read() << 24;
+ lengths[records] = size;
+ int got = in.read(pfbdata, pointer, size);
+ if (got < 0)
+ {
+ throw new EOFException();
+ }
+ pointer += got;
+ }
+ }
+
+ /**
+ * Read the pdf input.
+ * @param in The input.
+ * @return Returns the pdf-array.
+ * @throws IOException if an IO-error occurs.
+ */
+ private byte[] readPfbInput(final InputStream in) throws IOException
+ {
+ // copy into an array
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ byte[] tmpbuf = new byte[BUFFER_SIZE];
+ int amountRead = -1;
+ while ((amountRead = in.read(tmpbuf)) != -1)
+ {
+ out.write(tmpbuf, 0, amountRead);
+ }
+ return out.toByteArray();
+ }
+
+ /**
+ * Returns the lengths.
+ * @return Returns the lengths.
+ */
+ public int[] getLengths()
+ {
+ return lengths;
+ }
+
+ /**
+ * Returns the pfbdata.
+ * @return Returns the pfbdata.
+ */
+ public byte[] getPfbdata()
+ {
+ return pfbdata;
+ }
+
+ /**
+ * Returns the pfb data as stream.
+ * @return Returns the pfb data as stream.
+ */
+ public InputStream getInputStream()
+ {
+ return new ByteArrayInputStream(pfbdata);
+ }
+
+ /**
+ * Returns the size of the pfb-data.
+ * @return Returns the size of the pfb-data.
+ */
+ public int size()
+ {
+ return pfbdata.length;
+ }
+}
Added: incubator/pdfbox/trunk/fontbox/src/org/fontbox/pfb/package.html
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/fontbox/src/org/fontbox/pfb/package.html?rev=678810&view=auto
==============================================================================
--- incubator/pdfbox/trunk/fontbox/src/org/fontbox/pfb/package.html (added)
+++ incubator/pdfbox/trunk/fontbox/src/org/fontbox/pfb/package.html Tue Jul 22 10:20:54 2008
@@ -0,0 +1,9 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+
+</head>
+<body>
+Classes that are used to parse pfb files.
+</body>
+</html>
Added: incubator/pdfbox/trunk/fontbox/src/org/fontbox/ttf/CMAPEncodingEntry.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/fontbox/src/org/fontbox/ttf/CMAPEncodingEntry.java?rev=678810&view=auto
==============================================================================
--- incubator/pdfbox/trunk/fontbox/src/org/fontbox/ttf/CMAPEncodingEntry.java (added)
+++ incubator/pdfbox/trunk/fontbox/src/org/fontbox/ttf/CMAPEncodingEntry.java Tue Jul 22 10:20:54 2008
@@ -0,0 +1,219 @@
+/**
+ * Copyright (c) 2005-2006, www.fontbox.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 fontbox; 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.fontbox.org
+ *
+ */
+package org.fontbox.ttf;
+
+import java.io.IOException;
+
+/**
+ * An encoding entry for a cmap.
+ *
+ * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
+ * @version $Revision: 1.2 $
+ */
+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<glyphMapping.length; i++ )
+ {
+ glyphIdToCharacterCode[i]=(glyphMapping[i]+256)%256;
+ }
+ }
+ else if( subtableFormat == 2 )
+ {
+ int[] subHeaderKeys = new int[256];
+ for( int i=0; i<256; i++)
+ {
+ subHeaderKeys[i] = data.readUnsignedShort();
+ }
+ int firstCode = data.readUnsignedShort();
+ int entryCount = data.readUnsignedShort();
+ short idDelta = data.readSignedShort();
+ int idRangeOffset = data.readUnsignedShort();
+ //BJL
+ //HMM the TTF spec is not very clear about what is suppose to
+ //happen here. If you know please submit a patch or point
+ //me to some better documentation.
+ throw new IOException( "Not yet implemented:" + subtableFormat );
+ }
+ else if( subtableFormat == 4 )
+ {
+ int segCountX2 = data.readUnsignedShort();
+ int segCount = segCountX2/2;
+ int searchRange = data.readUnsignedShort();
+ int entrySelector = data.readUnsignedShort();
+ int rangeShift = data.readUnsignedShort();
+ int[] endCount = data.readUnsignedShortArray( segCount );
+ int reservedPad = data.readUnsignedShort();
+ int[] startCount = data.readUnsignedShortArray( segCount );
+ int[] idDelta = data.readUnsignedShortArray( segCount );
+ int[] idRangeOffset = data.readUnsignedShortArray( segCount );
+
+ //this is the final result
+ //key=glyphId, value is character codes
+ glyphIdToCharacterCode = new int[numGlyphs];
+
+ long currentPosition = data.getCurrentPosition();
+
+ for( int i=0; i<segCount; i++ )
+ {
+ int start = startCount[i];
+ int end = endCount[i];
+ int delta = idDelta[i];
+ int rangeOffset = idRangeOffset[i];
+ if( start != 65535 && end != 65535 )
+ {
+ for( int j=start; j<=end; j++ )
+ {
+ if( rangeOffset == 0 )
+ {
+ glyphIdToCharacterCode[ ((j+delta)%65536) ]=j;
+ }
+ else
+ {
+ long glyphOffset = currentPosition +
+ ((rangeOffset/2) + //idRangeOffset[i]/2
+ (j-start) + //(c - startCount[i])
+ (i-segCount))*2; //&idRangeOffset[i]);
+ data.seek( glyphOffset );
+ int glyphIndex = data.readUnsignedShort();
+ if( glyphIndex != 0 )
+ {
+ glyphIndex += delta;
+ glyphIndex = glyphIndex % 65536;
+ if( glyphIdToCharacterCode[glyphIndex] == 0 )
+ {
+ glyphIdToCharacterCode[glyphIndex] = j;
+ }
+ }
+
+ }
+ }
+ }
+ }
+ }
+ else if( subtableFormat == 6 )
+ {
+ int firstCode = data.readUnsignedShort();
+ int entryCount = data.readUnsignedShort();
+ glyphIdToCharacterCode = new int[numGlyphs];
+ int[] glyphIdArray = data.readUnsignedShortArray( entryCount );
+ for( int i=0; i<entryCount; i++)
+ {
+ glyphIdToCharacterCode[glyphIdArray[i]] = firstCode+i;
+ }
+ }
+ else
+ {
+ throw new IOException( "Unknown cmap format:" + subtableFormat );
+ }
+ }
+
+
+ /**
+ * @return Returns the glyphIdToCharacterCode.
+ */
+ public int[] getGlyphIdToCharacterCode()
+ {
+ return glyphIdToCharacterCode;
+ }
+ /**
+ * @param glyphIdToCharacterCodeValue The glyphIdToCharacterCode to set.
+ */
+ public void setGlyphIdToCharacterCode(int[] glyphIdToCharacterCodeValue)
+ {
+ this.glyphIdToCharacterCode = glyphIdToCharacterCodeValue;
+ }
+
+ /**
+ * @return Returns the platformEncodingId.
+ */
+ public int getPlatformEncodingId()
+ {
+ return platformEncodingId;
+ }
+ /**
+ * @param platformEncodingIdValue The platformEncodingId to set.
+ */
+ public void setPlatformEncodingId(int platformEncodingIdValue)
+ {
+ this.platformEncodingId = platformEncodingIdValue;
+ }
+ /**
+ * @return Returns the platformId.
+ */
+ public int getPlatformId()
+ {
+ return platformId;
+ }
+ /**
+ * @param platformIdValue The platformId to set.
+ */
+ public void setPlatformId(int platformIdValue)
+ {
+ this.platformId = platformIdValue;
+ }
+}
Added: incubator/pdfbox/trunk/fontbox/src/org/fontbox/ttf/CMAPTable.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/fontbox/src/org/fontbox/ttf/CMAPTable.java?rev=678810&view=auto
==============================================================================
--- incubator/pdfbox/trunk/fontbox/src/org/fontbox/ttf/CMAPTable.java (added)
+++ incubator/pdfbox/trunk/fontbox/src/org/fontbox/ttf/CMAPTable.java Tue Jul 22 10:20:54 2008
@@ -0,0 +1,122 @@
+/**
+ * Copyright (c) 2005, www.fontbox.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 fontbox; 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.fontbox.org
+ *
+ */
+package org.fontbox.ttf;
+
+import java.io.IOException;
+
+/**
+ * A table in a true type font.
+ *
+ * @author Ben Litchfield (ben@benlitchfield.com)
+ * @version $Revision: 1.1 $
+ */
+public class CMAPTable extends TTFTable
+{
+ /**
+ * A tag used to identify this table.
+ */
+ public static final String TAG = "cmap";
+
+ /**
+ * A constant for the platform.
+ */
+ public static final int PLATFORM_WINDOWS = 3;
+
+ /**
+ * An encoding constant.
+ */
+ public static final int ENCODING_SYMBOL = 0;
+ /**
+ * An encoding constant.
+ */
+ public static final int ENCODING_UNICODE = 1;
+ /**
+ * An encoding constant.
+ */
+ public static final int ENCODING_SHIFT_JIS = 2;
+ /**
+ * An encoding constant.
+ */
+ public static final int ENCODING_BIG5 = 3;
+ /**
+ * An encoding constant.
+ */
+ public static final int ENCODING_PRC = 4;
+ /**
+ * An encoding constant.
+ */
+ public static final int ENCODING_WANSUNG = 5;
+ /**
+ * An encoding constant.
+ */
+ public static final int ENCODING_JOHAB = 6;
+
+ private CMAPEncodingEntry[] cmaps;
+
+ /**
+ * 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
+ {
+ int version = data.readUnsignedShort();
+ int numberOfTables = data.readUnsignedShort();
+ cmaps = new CMAPEncodingEntry[ numberOfTables ];
+ for( int i=0; i< numberOfTables; i++ )
+ {
+ CMAPEncodingEntry cmap = new CMAPEncodingEntry();
+ cmap.initData( ttf, data );
+ cmaps[i]=cmap;
+ }
+ for( int i=0; i< numberOfTables; i++ )
+ {
+ cmaps[i].initSubtable( ttf, data );
+ }
+
+ }
+ /**
+ * @return Returns the cmaps.
+ */
+ public CMAPEncodingEntry[] getCmaps()
+ {
+ return cmaps;
+ }
+ /**
+ * @param cmapsValue The cmaps to set.
+ */
+ public void setCmaps(CMAPEncodingEntry[] cmapsValue)
+ {
+ this.cmaps = cmapsValue;
+ }
+}
Added: incubator/pdfbox/trunk/fontbox/src/org/fontbox/ttf/DigitalSignatureTable.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/fontbox/src/org/fontbox/ttf/DigitalSignatureTable.java?rev=678810&view=auto
==============================================================================
--- incubator/pdfbox/trunk/fontbox/src/org/fontbox/ttf/DigitalSignatureTable.java (added)
+++ incubator/pdfbox/trunk/fontbox/src/org/fontbox/ttf/DigitalSignatureTable.java Tue Jul 22 10:20:54 2008
@@ -0,0 +1,45 @@
+/**
+ * Copyright (c) 2005, www.fontbox.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 fontbox; 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.fontbox.org
+ *
+ */
+package org.fontbox.ttf;
+
+/**
+ * A table in a true type font.
+ *
+ * @author Ben Litchfield (ben@benlitchfield.com)
+ * @version $Revision: 1.1 $
+ */
+public class DigitalSignatureTable extends TTFTable
+{
+ /**
+ * Tag to identify this table.
+ */
+ public static final String TAG = "DSIG";
+}
Added: incubator/pdfbox/trunk/fontbox/src/org/fontbox/ttf/GlyphData.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/fontbox/src/org/fontbox/ttf/GlyphData.java?rev=678810&view=auto
==============================================================================
--- incubator/pdfbox/trunk/fontbox/src/org/fontbox/ttf/GlyphData.java (added)
+++ incubator/pdfbox/trunk/fontbox/src/org/fontbox/ttf/GlyphData.java Tue Jul 22 10:20:54 2008
@@ -0,0 +1,125 @@
+/**
+ * Copyright (c) 2005, www.fontbox.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 fontbox; 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.fontbox.org
+ *
+ */
+package org.fontbox.ttf;
+
+import java.io.IOException;
+
+import org.fontbox.util.BoundingBox;
+
+/**
+ * A glyph data record in the glyf table.
+ *
+ * @author Ben Litchfield (ben@benlitchfield.com)
+ * @version $Revision: 1.1 $
+ */
+public class GlyphData
+{
+ private static final int FLAG_ON_CURVE = 1;
+ private static final int FLAG_SHORT_X = 1<<1;
+ private static final int FLAG_SHORT_Y = 1<<2;
+ private static final int FLAG_X_MAGIC = 1<<3;
+ private static final int FLAG_Y_MAGIC = 1<<4;
+
+ private BoundingBox boundingBox = new BoundingBox();
+ private short numberOfContours;
+ private int[] endPointsOfContours;
+ private byte[] instructions;
+ private int[] flags;
+ private short[] xCoordinates;
+ private short[] yCoordinates;
+
+ /**
+ * 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
+ {
+ numberOfContours = data.readSignedShort();
+ boundingBox.setLowerLeftX( data.readSignedShort() );
+ boundingBox.setLowerLeftY( data.readSignedShort() );
+ boundingBox.setUpperRightX( data.readSignedShort() );
+ boundingBox.setUpperRightY( data.readSignedShort() );
+ /**if( numberOfContours > 0 )
+ {
+ endPointsOfContours = new int[ numberOfContours ];
+ for( int i=0; i<numberOfContours; i++ )
+ {
+ endPointsOfContours[i] = data.readUnsignedShort();
+ }
+ int instructionLength = data.readUnsignedShort();
+ instructions = data.read( instructionLength );
+
+ //BJL It is possible to read some more information here but PDFBox
+ //does not need it at this time so just ignore it.
+
+ //not sure if the length of the flags is the number of contours??
+ //flags = new int[numberOfContours];
+ //first read the flags, and just so the TTF can save a couples bytes
+ //we need to check some bit masks to see if there are more bytes or not.
+ //int currentFlagIndex = 0;
+ //int currentFlag =
+
+
+ }*/
+ }
+
+ /**
+ * @return Returns the boundingBox.
+ */
+ public BoundingBox getBoundingBox()
+ {
+ return boundingBox;
+ }
+ /**
+ * @param boundingBoxValue The boundingBox to set.
+ */
+ public void setBoundingBox(BoundingBox boundingBoxValue)
+ {
+ this.boundingBox = boundingBoxValue;
+ }
+ /**
+ * @return Returns the numberOfContours.
+ */
+ public short getNumberOfContours()
+ {
+ return numberOfContours;
+ }
+ /**
+ * @param numberOfContoursValue The numberOfContours to set.
+ */
+ public void setNumberOfContours(short numberOfContoursValue)
+ {
+ this.numberOfContours = numberOfContoursValue;
+ }
+}
Added: incubator/pdfbox/trunk/fontbox/src/org/fontbox/ttf/GlyphTable.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/fontbox/src/org/fontbox/ttf/GlyphTable.java?rev=678810&view=auto
==============================================================================
--- incubator/pdfbox/trunk/fontbox/src/org/fontbox/ttf/GlyphTable.java (added)
+++ incubator/pdfbox/trunk/fontbox/src/org/fontbox/ttf/GlyphTable.java Tue Jul 22 10:20:54 2008
@@ -0,0 +1,88 @@
+/**
+ * Copyright (c) 2005, www.fontbox.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 fontbox; 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.fontbox.org
+ *
+ */
+package org.fontbox.ttf;
+
+import java.io.IOException;
+
+/**
+ * A table in a true type font.
+ *
+ * @author Ben Litchfield (ben@benlitchfield.com)
+ * @version $Revision: 1.1 $
+ */
+public class GlyphTable extends TTFTable
+{
+ /**
+ * Tag to identify this table.
+ */
+ public static final String TAG = "glyf";
+
+ private GlyphData[] glyphs;
+
+ /**
+ * 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();
+ IndexToLocationTable loc = ttf.getIndexToLocation();
+ PostScriptTable post = ttf.getPostScript();
+ long[] offsets = loc.getOffsets();
+ int numGlyphs = maxp.getNumGlyphs();
+ glyphs = new GlyphData[numGlyphs];
+ String[] glyphNames = post.getGlyphNames();
+ for( int i=0; i<numGlyphs-1; i++ )
+ {
+ GlyphData glyph = new GlyphData();
+ data.seek( getOffset() + offsets[i] );
+ glyph.initData( ttf, data );
+ glyphs[i] = glyph;
+ }
+ }
+ /**
+ * @return Returns the glyphs.
+ */
+ public GlyphData[] getGlyphs()
+ {
+ return glyphs;
+ }
+ /**
+ * @param glyphsValue The glyphs to set.
+ */
+ public void setGlyphs(GlyphData[] glyphsValue)
+ {
+ this.glyphs = glyphsValue;
+ }
+}