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

public Class CMap

extends Object
Class Inheritance
Imports
java.io.IOException, .InputStream, java.util.ArrayList, .HashMap, .List, .Map, org.apache.commons.logging.Log, .LogFactory

This class represents a CMap file.
Author
Ben Litchfield

Field Summary

Modifier and TypeField and Description
private final Map<Integer, String>
private final Map<Integer, String>
private String
private int
private String
private final List<CodespaceRange>
private final Map<Integer, Map<Integer, Integer>>
private final List<CIDRange>
private static final Log
private int
private int
private int
private int
private String
private String
private static final String
private int
private int
private final Map<String, byte[]>
private int

Constructor Summary

AccessConstructor and Description
pack-priv
CMap()

Creates a new instance of CMap.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
addCharMapping(byte[]
The character codes to map from.
codes
,
String
The Unicode characters to map to.
unicode
)

This will add a character code to Unicode character sequence mapping.

pack-priv void
addCIDMapping(byte[]
character code
code
,
int
CID
cid
)

This will add a CID mapping.

pack-priv void
addCIDRange(byte[]
starting character of the CID range.
from
,
byte[]
ending character of the CID range.
to
,
int
the cid to be started with.
cid
)

This will add a CID Range.

private void
addCIDRange(List<CIDRange> cidRanges, int from, int to, int cid, int length)

pack-priv void
addCodespaceRange(CodespaceRange
A single codespace range.
range
)

This will add a codespace range.

public byte[]

Returns:

the code bytes or null if there is none.
getCodesFromUnicode
(String
The unicode string.
unicode
)

Get the code bytes for an unicode string.

public String

Returns:

the CMap name.
getName
()

Returns the name of the CMap.

public String

Returns:

the ordering.
getOrdering
()

Returns the ordering of the CIDSystemInfo.

public String

Returns:

the registry.
getRegistry
()

Returns the registry of the CIDSystemInfo.

public int

Returns:

the mapped code for the space character
getSpaceMapping
()

Returns the mapping for the space character.

public int

Returns:

the supplement.
getSupplement
()

Returns the supplement of the CIDSystemInfo.

public int

Returns:

the CMap type.
getType
()

Returns the type of the CMap.

public String

Returns:

the CMap version.
getVersion
()

Returns the version of the CMap.

public int

Returns:

the wmode
getWMode
()

Returns the WMode of a CMap.

public boolean

Returns:

true If there are any CID mappings, false otherwise.
hasCIDMappings
()

This will tell if this cmap has any CID mappings.

public boolean

Returns:

true If there are any Unicode mappings, false otherwise.
hasUnicodeMappings
()

This will tell if this cmap has any Unicode mappings.

public int

Returns:

character code
readCode
(InputStream
string stream
in
)

Reads a character code from a string in the content stream.

public void
setName(String
the CMap name.
name
)

Sets the name of the CMap.

public void
setOrdering(String
the ordering.
newOrdering
)

Sets the ordering of the CIDSystemInfo.

public void
setRegistry(String
the registry.
newRegistry
)

Sets the registry of the CIDSystemInfo.

public void
setSupplement(int
the supplement.
newSupplement
)

Sets the supplement of the CIDSystemInfo.

public void
setType(int
the CMap type.
type
)

Sets the type of the CMap.

public void
setVersion(String
the CMap version.
version
)

Sets the version of the CMap.

public void
setWMode(int
the new WMode.
newWMode
)

Sets the WMode of a CMap.

public int

Returns:

CID
toCID
(byte[]
character code as byte array
code
)

Returns the CID for the given character code.

public int

Returns:

CID
toCID
(int
character code
code
)

Returns the CID for the given character code.

public int

Returns:

CID
toCID
(int
character code
code
,
int
the origin byte length of the code
length
)

Returns the CID for the given character code.

private int

Returns:

CID
toCIDFromRanges
(int
character code
code
,
int length)

Returns the CID for the given character code.

private int

Returns:

CID
toCIDFromRanges
(byte[]
character code
code
)

Returns the CID for the given character code.

pack-priv static int
toInt(byte[] data)

Returns an int for the given byte array

private static int
toInt(byte[] data, int dataLen)

Returns an int for the given byte array

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public String

Returns:

Unicode characters (may be more than one, e.g "fi" ligature)
toUnicode
(int
character code
code
)

Returns the sequence of Unicode characters for the given character code.

public String

Returns:

Unicode characters (may be more than one, e.g "fi" ligature)
toUnicode
(int
character code
code
,
int
code length
length
)

Returns the sequence of Unicode characters for the given character code.

public String

Returns:

Unicode characters (may be more than one, e.g "fi" ligature)
toUnicode
(byte[]
bytes of the character code
code
)

Returns the sequence of Unicode characters for the given character code.

pack-priv void
useCmap(CMap
The cmap to load mappings from.
cmap
)

Implementation of the usecmap operator.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

charToUnicodeOneByteback to summary
private final Map<Integer, String> charToUnicodeOneByte
charToUnicodeTwoBytesback to summary
private final Map<Integer, String> charToUnicodeTwoBytes
cmapNameback to summary
private String cmapName
cmapTypeback to summary
private int cmapType
cmapVersionback to summary
private String cmapVersion
codespaceRangesback to summary
private final List<CodespaceRange> codespaceRanges
codeToCidback to summary
private final Map<Integer, Map<Integer, Integer>> codeToCid
codeToCidRangesback to summary
private final List<CIDRange> codeToCidRanges
LOGback to summary
private static final Log LOG
maxCidLengthback to summary
private int maxCidLength
maxCodeLengthback to summary
private int maxCodeLength
minCidLengthback to summary
private int minCidLength
minCodeLengthback to summary
private int minCodeLength
orderingback to summary
private String ordering
registryback to summary
private String registry
SPACEback to summary
private static final String SPACE
spaceMappingback to summary
private int spaceMapping
supplementback to summary
private int supplement
unicodeToByteCodesback to summary
private final Map<String, byte[]> unicodeToByteCodes
wmodeback to summary
private int wmode

Constructor Detail

CMapback to summary
pack-priv CMap()

Creates a new instance of CMap.

Method Detail

addCharMappingback to summary
pack-priv void addCharMapping(byte[] codes, String unicode)

This will add a character code to Unicode character sequence mapping.

Parameters
codes:byte[]

The character codes to map from.

unicode:String

The Unicode characters to map to.

addCIDMappingback to summary
pack-priv void addCIDMapping(byte[] code, int cid)

This will add a CID mapping.

Parameters
code:byte[]

character code

cid:int

CID

addCIDRangeback to summary
pack-priv void addCIDRange(byte[] from, byte[] to, int cid)

This will add a CID Range.

Parameters
from:byte[]

starting character of the CID range.

to:byte[]

ending character of the CID range.

cid:int

the cid to be started with.

addCIDRangeback to summary
private void addCIDRange(List<CIDRange> cidRanges, int from, int to, int cid, int length)
addCodespaceRangeback to summary
pack-priv void addCodespaceRange(CodespaceRange range)

This will add a codespace range.

Parameters
range:CodespaceRange

A single codespace range.

getCodesFromUnicodeback to summary
public byte[] getCodesFromUnicode(String unicode)

Get the code bytes for an unicode string.

Parameters
unicode:String

The unicode string.

Returns:byte[]

the code bytes or null if there is none.

getNameback to summary
public String getName()

Returns the name of the CMap.

Returns:String

the CMap name.

getOrderingback to summary
public String getOrdering()

Returns the ordering of the CIDSystemInfo.

Returns:String

the ordering.

getRegistryback to summary
public String getRegistry()

Returns the registry of the CIDSystemInfo.

Returns:String

the registry.

getSpaceMappingback to summary
public int getSpaceMapping()

Returns the mapping for the space character.

Returns:int

the mapped code for the space character

getSupplementback to summary
public int getSupplement()

Returns the supplement of the CIDSystemInfo.

Returns:int

the supplement.

getTypeback to summary
public int getType()

Returns the type of the CMap.

Returns:int

the CMap type.

getVersionback to summary
public String getVersion()

Returns the version of the CMap.

Returns:String

the CMap version.

getWModeback to summary
public int getWMode()

Returns the WMode of a CMap. 0 represents a horizontal and 1 represents a vertical orientation.

Returns:int

the wmode

hasCIDMappingsback to summary
public boolean hasCIDMappings()

This will tell if this cmap has any CID mappings.

Returns:boolean

true If there are any CID mappings, false otherwise.

hasUnicodeMappingsback to summary
public boolean hasUnicodeMappings()

This will tell if this cmap has any Unicode mappings.

Returns:boolean

true If there are any Unicode mappings, false otherwise.

readCodeback to summary
public int readCode(InputStream in) throws IOException

Reads a character code from a string in the content stream.

See "CMap Mapping" and "Handling Undefined Characters" in PDF32000 for more details.

Parameters
in:InputStream

string stream

Returns:int

character code

Exceptions
IOException:
if there was an error reading the stream or CMap
setNameback to summary
public void setName(String name)

Sets the name of the CMap.

Parameters
name:String

the CMap name.

setOrderingback to summary
public void setOrdering(String newOrdering)

Sets the ordering of the CIDSystemInfo.

Parameters
newOrdering:String

the ordering.

setRegistryback to summary
public void setRegistry(String newRegistry)

Sets the registry of the CIDSystemInfo.

Parameters
newRegistry:String

the registry.

setSupplementback to summary
public void setSupplement(int newSupplement)

Sets the supplement of the CIDSystemInfo.

Parameters
newSupplement:int

the supplement.

setTypeback to summary
public void setType(int type)

Sets the type of the CMap.

Parameters
type:int

the CMap type.

setVersionback to summary
public void setVersion(String version)

Sets the version of the CMap.

Parameters
version:String

the CMap version.

setWModeback to summary
public void setWMode(int newWMode)

Sets the WMode of a CMap.

Parameters
newWMode:int

the new WMode.

toCIDback to summary
public int toCID(byte[] code)

Returns the CID for the given character code.

Parameters
code:byte[]

character code as byte array

Returns:int

CID

toCIDback to summary
public int toCID(int code)

Returns the CID for the given character code. This method exists for convenience. It may return false values as the origin byte length of the input value is unknown and the mapping for some input values aren't unique.
Example:
The two byte value 0x00, 0x65 maps to 0x20
An input value of 0x65 always returns 0x20 even if the value has an origin byte length of 1.

Parameters
code:int

character code

Returns:int

CID

toCIDback to summary
public int toCID(int code, int length)

Returns the CID for the given character code.

Parameters
code:int

character code

length:int

the origin byte length of the code

Returns:int

CID

toCIDFromRangesback to summary
private int toCIDFromRanges(int code, int length)

Returns the CID for the given character code.

Parameters
code:int

character code

Returns:int

CID

toCIDFromRangesback to summary
private int toCIDFromRanges(byte[] code)

Returns the CID for the given character code.

Parameters
code:byte[]

character code

Returns:int

CID

toIntback to summary
pack-priv static int toInt(byte[] data)

Returns an int for the given byte array

toIntback to summary
private static int toInt(byte[] data, int dataLen)

Returns an int for the given byte array

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
toUnicodeback to summary
public String toUnicode(int code)

Returns the sequence of Unicode characters for the given character code. This method exists for convenience. It may return false values as the origin byte length of the input value is unknown and the mapping for some input values aren't unique.
Example:
The two byte value 0x00, 0x65 maps to 0x20
An input value of 0x65 always returns 0x20 even if the value has an origin byte length of 1.

Parameters
code:int

character code

Returns:String

Unicode characters (may be more than one, e.g "fi" ligature)

toUnicodeback to summary
public String toUnicode(int code, int length)

Returns the sequence of Unicode characters for the given character code.

Parameters
code:int

character code

length:int

code length

Returns:String

Unicode characters (may be more than one, e.g "fi" ligature)

toUnicodeback to summary
public String toUnicode(byte[] code)

Returns the sequence of Unicode characters for the given character code.

Parameters
code:byte[]

bytes of the character code

Returns:String

Unicode characters (may be more than one, e.g "fi" ligature)

useCmapback to summary
pack-priv void useCmap(CMap cmap)

Implementation of the usecmap operator. This will copy all of the mappings from one cmap to another.

Parameters
cmap:CMap

The cmap to load mappings from.