Top Description Inners Fields Constructors Methods
org.apache.fontbox.cmap

public Class CMapParser

extends Object
Class Inheritance
Imports
java.io.IOException, .InputStream, java.nio.charset.StandardCharsets, java.util.ArrayList, .Arrays, .HashMap, .List, .Map, org.apache.pdfbox.io.RandomAccessRead, .RandomAccessReadBuffer

Parses a CMap stream.
Author
Ben Litchfield

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
CMapParser.LiteralName

Internal class.

private static class
CMapParser.Operator

Internal class.

Field Summary

Modifier and TypeField and Description
private static final String
private static final String
private boolean
private final byte[]

Constructor Summary

AccessConstructor and Description
public
CMapParser()

Creates a new instance of CMapParser.

public
CMapParser(boolean
activates the strict mode used for inline CMaps
strictMode
)

Creates a new instance of CMapParser.

Method Summary

Modifier and TypeMethod and Description
private void
addMappingFrombfrange(CMap cmap, byte[] startCode, List<byte[]> tokenBytesList)

private void
addMappingFrombfrange(CMap cmap, byte[] startCode, int values, byte[] tokenBytes)

private void
checkExpectedOperator(CMapParser.Operator
Instance of operator
operator
,
String
Expected name of operator
expectedOperatorName
,
String
The name of the range in which the operator is expected (without a tilde character), to be used in the exception message.
rangeName
)

Throws an IOException if expectedOperatorName not equals operator.op

private static String
createStringFromBytes(byte[] bytes)

private RandomAccessRead
getExternalCMap(String
Name of the given "use" CMap resource.
name
)

Returns a RandomAccessRead containing the given "use" CMap.

private static boolean
increment(byte[] data, int position, boolean useStrictMode)

private static boolean
isDelimiter(int aByte)

Is this a standard PDF delimiter character?

private static boolean
isWhitespaceOrEOF(int aByte)

public CMap

Returns:

The parsed source as a java object, never null.
parse
(RandomAccessRead
the source of the CMap to be parsed.
randomAcccessRead
)

This will parse the stream and create a cmap object.

private void
parseBeginbfchar(Number cosCount, RandomAccessRead randomAcccessRead, CMap result)

private void
parseBeginbfrange(Number cosCount, RandomAccessRead randomAcccessRead, CMap result)

private void
parseBegincidchar(Number cosCount, RandomAccessRead randomAcccessRead, CMap result)

private void
parseBegincidrange(int numberOfLines, RandomAccessRead randomAcccessRead, CMap result)

private void
parseBegincodespacerange(Number cosCount, RandomAccessRead randomAcccessRead, CMap result)

private byte[]
parseByteArray(RandomAccessRead randomAcccessRead)

private Integer
parseInteger(RandomAccessRead randomAcccessRead)

private void
parseLiteralName(CMapParser.LiteralName literal, RandomAccessRead randomAcccessRead, CMap result)

private Object
parseNextToken(RandomAccessRead randomAcccessRead)

public CMap

Returns:

The parsed predefined CMap as a java object, never null.
parsePredefined
(String
CMap name.
name
)

Parses a predefined CMap.

private void
parseUsecmap(CMapParser.LiteralName useCmapName, CMap result)

private List<Object>
readArray(RandomAccessRead randomAcccessRead)

private Object
readDictionary(RandomAccessRead randomAcccessRead)

private String
readLine(RandomAccessRead randomAcccessRead, int firstByte)

private CMapParser.LiteralName
readLiteralName(RandomAccessRead randomAcccessRead)

private Number
readNumber(RandomAccessRead randomAcccessRead, int firstByte)

private CMapParser.Operator
readOperator(RandomAccessRead randomAcccessRead, int firstByte)

private String
readString(RandomAccessRead randomAcccessRead)

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

MARK_END_OF_ARRAYback to summary
private static final String MARK_END_OF_ARRAY
MARK_END_OF_DICTIONARYback to summary
private static final String MARK_END_OF_DICTIONARY
strictModeback to summary
private boolean strictMode
tokenParserByteBufferback to summary
private final byte[] tokenParserByteBuffer

Constructor Detail

CMapParserback to summary
public CMapParser()

Creates a new instance of CMapParser.

CMapParserback to summary
public CMapParser(boolean strictMode)

Creates a new instance of CMapParser.

Parameters
strictMode:boolean

activates the strict mode used for inline CMaps

Method Detail

addMappingFrombfrangeback to summary
private void addMappingFrombfrange(CMap cmap, byte[] startCode, List<byte[]> tokenBytesList)
addMappingFrombfrangeback to summary
private void addMappingFrombfrange(CMap cmap, byte[] startCode, int values, byte[] tokenBytes)
checkExpectedOperatorback to summary
private void checkExpectedOperator(CMapParser.Operator operator, String expectedOperatorName, String rangeName) throws IOException

Throws an IOException if expectedOperatorName not equals operator.op

Parameters
operator:CMapParser.Operator

Instance of operator

expectedOperatorName:String

Expected name of operator

rangeName:String

The name of the range in which the operator is expected (without a tilde character), to be used in the exception message.

Exceptions
IOException:
if expectedOperatorName not equals operator.op
createStringFromBytesback to summary
private static String createStringFromBytes(byte[] bytes)
getExternalCMapback to summary
private RandomAccessRead getExternalCMap(String name) throws IOException

Returns a RandomAccessRead containing the given "use" CMap.

Parameters
name:String

Name of the given "use" CMap resource.

Exceptions
IOException:
if the CMap resource doesn't exist or if there is an error opening it.
incrementback to summary
private static boolean increment(byte[] data, int position, boolean useStrictMode)
isDelimiterback to summary
private static boolean isDelimiter(int aByte)

Is this a standard PDF delimiter character?

isWhitespaceOrEOFback to summary
private static boolean isWhitespaceOrEOF(int aByte)
parseback to summary
public CMap parse(RandomAccessRead randomAcccessRead) throws IOException

This will parse the stream and create a cmap object.

Parameters
randomAcccessRead:RandomAccessRead

the source of the CMap to be parsed.

Returns:CMap

The parsed source as a java object, never null.

Exceptions
IOException:
If there is an error parsing the data.
parseBeginbfcharback to summary
private void parseBeginbfchar(Number cosCount, RandomAccessRead randomAcccessRead, CMap result) throws IOException
parseBeginbfrangeback to summary
private void parseBeginbfrange(Number cosCount, RandomAccessRead randomAcccessRead, CMap result) throws IOException
parseBegincidcharback to summary
private void parseBegincidchar(Number cosCount, RandomAccessRead randomAcccessRead, CMap result) throws IOException
parseBegincidrangeback to summary
private void parseBegincidrange(int numberOfLines, RandomAccessRead randomAcccessRead, CMap result) throws IOException
parseBegincodespacerangeback to summary
private void parseBegincodespacerange(Number cosCount, RandomAccessRead randomAcccessRead, CMap result) throws IOException
parseByteArrayback to summary
private byte[] parseByteArray(RandomAccessRead randomAcccessRead) throws IOException
parseIntegerback to summary
private Integer parseInteger(RandomAccessRead randomAcccessRead) throws IOException
parseLiteralNameback to summary
private void parseLiteralName(CMapParser.LiteralName literal, RandomAccessRead randomAcccessRead, CMap result) throws IOException
parseNextTokenback to summary
private Object parseNextToken(RandomAccessRead randomAcccessRead) throws IOException
parsePredefinedback to summary
public CMap parsePredefined(String name) throws IOException

Parses a predefined CMap.

Parameters
name:String

CMap name.

Returns:CMap

The parsed predefined CMap as a java object, never null.

Exceptions
IOException:
If the CMap could not be parsed.
parseUsecmapback to summary
private void parseUsecmap(CMapParser.LiteralName useCmapName, CMap result) throws IOException
readArrayback to summary
private List<Object> readArray(RandomAccessRead randomAcccessRead) throws IOException
readDictionaryback to summary
private Object readDictionary(RandomAccessRead randomAcccessRead) throws IOException
readLineback to summary
private String readLine(RandomAccessRead randomAcccessRead, int firstByte) throws IOException
readLiteralNameback to summary
private CMapParser.LiteralName readLiteralName(RandomAccessRead randomAcccessRead) throws IOException
readNumberback to summary
private Number readNumber(RandomAccessRead randomAcccessRead, int firstByte) throws IOException
readOperatorback to summary
private CMapParser.Operator readOperator(RandomAccessRead randomAcccessRead, int firstByte) throws IOException
readStringback to summary
private String readString(RandomAccessRead randomAcccessRead) throws IOException
readUntilEndOfLineback to summary
private void readUntilEndOfLine(RandomAccessRead randomAcccessRead, StringBuilder buf) throws IOException
org.apache.fontbox.cmap back to summary

private final Class CMapParser.LiteralName

extends Object
Class Inheritance

Internal class.

Field Summary

Modifier and TypeField and Description
private final String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

nameback to summary
private final String name

Constructor Detail

LiteralNameback to summary
private LiteralName(String theName)
org.apache.fontbox.cmap back to summary

private final Class CMapParser.Operator

extends Object
Class Inheritance

Internal class.

Field Summary

Modifier and TypeField and Description
private final String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

opback to summary
private final String op

Constructor Detail

Operatorback to summary
private Operator(String theOp)