Package org.apache.fontbox.cmap
Class CMap
- java.lang.Object
-
- org.apache.fontbox.cmap.CMap
-
public class CMap extends java.lang.ObjectThis class represents a CMap file.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.Integer,java.lang.String>charToUnicodeMoreBytesprivate java.util.Map<java.lang.Integer,java.lang.String>charToUnicodeOneByteprivate java.util.Map<java.lang.Integer,java.lang.String>charToUnicodeTwoBytesprivate java.lang.StringcmapNameprivate intcmapTypeprivate java.lang.StringcmapVersionprivate java.util.List<CodespaceRange>codespaceRangesprivate java.util.Map<java.lang.Integer,java.util.Map<java.lang.Integer,java.lang.Integer>>codeToCidprivate java.util.List<CIDRange>codeToCidRangesprivate static org.apache.commons.logging.LogLOGprivate intmaxCidLengthprivate intmaxCodeLengthprivate intminCidLengthprivate intminCodeLengthprivate java.lang.Stringorderingprivate java.lang.Stringregistryprivate static java.lang.StringSPACEprivate intspaceMappingprivate intsupplementprivate java.util.Map<java.lang.String,byte[]>unicodeToByteCodesprivate intwmode
-
Constructor Summary
Constructors Constructor Description CMap()Creates a new instance of CMap.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidaddCharMapping(byte[] codes, java.lang.String unicode)This will add a character code to Unicode character sequence mapping.(package private) voidaddCIDMapping(byte[] code, int cid)This will add a CID mapping.(package private) voidaddCIDRange(byte[] from, byte[] to, int cid)This will add a CID Range.private voidaddCIDRange(java.util.List<CIDRange> cidRanges, int from, int to, int cid, int length)(package private) voidaddCodespaceRange(CodespaceRange range)This will add a codespace range.byte[]getCodesFromUnicode(java.lang.String unicode)Get the code bytes for an unicode string.java.lang.StringgetName()Returns the name of the CMap.java.lang.StringgetOrdering()Returns the ordering of the CIDSystemInfo.java.lang.StringgetRegistry()Returns the registry of the CIDSystemInfo.intgetSpaceMapping()Returns the mapping for the space character.intgetSupplement()Returns the supplement of the CIDSystemInfo.intgetType()Returns the type of the CMap.java.lang.StringgetVersion()Returns the version of the CMap.intgetWMode()Returns the WMode of a CMap.booleanhasCIDMappings()This will tell if this cmap has any CID mappings.booleanhasUnicodeMappings()This will tell if this cmap has any Unicode mappings.intreadCode(java.io.InputStream in)Reads a character code from a string in the content stream.voidsetName(java.lang.String name)Sets the name of the CMap.voidsetOrdering(java.lang.String newOrdering)Sets the ordering of the CIDSystemInfo.voidsetRegistry(java.lang.String newRegistry)Sets the registry of the CIDSystemInfo.voidsetSupplement(int newSupplement)Sets the supplement of the CIDSystemInfo.voidsetType(int type)Sets the type of the CMap.voidsetVersion(java.lang.String version)Sets the version of the CMap.voidsetWMode(int newWMode)Sets the WMode of a CMap.inttoCID(byte[] code)Returns the CID for the given character code.inttoCID(int code)Returns the CID for the given character code.inttoCID(int code, int length)Returns the CID for the given character code.private inttoCIDFromRanges(byte[] code)Returns the CID for the given character code.private inttoCIDFromRanges(int code, int length)Returns the CID for the given character code.(package private) static inttoInt(byte[] data)Returns an int for the given byte arrayprivate static inttoInt(byte[] data, int dataLen)Returns an int for the given byte arrayjava.lang.StringtoString()java.lang.StringtoUnicode(byte[] code)Returns the sequence of Unicode characters for the given character code.java.lang.StringtoUnicode(int code)Returns the sequence of Unicode characters for the given character code.java.lang.StringtoUnicode(int code, int length)Returns the sequence of Unicode characters for the given character code.(package private) voiduseCmap(CMap cmap)Implementation of the usecmap operator.
-
-
-
Field Detail
-
LOG
private static final org.apache.commons.logging.Log LOG
-
wmode
private int wmode
-
cmapName
private java.lang.String cmapName
-
cmapVersion
private java.lang.String cmapVersion
-
cmapType
private int cmapType
-
registry
private java.lang.String registry
-
ordering
private java.lang.String ordering
-
supplement
private int supplement
-
minCodeLength
private int minCodeLength
-
maxCodeLength
private int maxCodeLength
-
minCidLength
private int minCidLength
-
maxCidLength
private int maxCidLength
-
codespaceRanges
private final java.util.List<CodespaceRange> codespaceRanges
-
charToUnicodeOneByte
private final java.util.Map<java.lang.Integer,java.lang.String> charToUnicodeOneByte
-
charToUnicodeTwoBytes
private final java.util.Map<java.lang.Integer,java.lang.String> charToUnicodeTwoBytes
-
charToUnicodeMoreBytes
private final java.util.Map<java.lang.Integer,java.lang.String> charToUnicodeMoreBytes
-
codeToCid
private final java.util.Map<java.lang.Integer,java.util.Map<java.lang.Integer,java.lang.Integer>> codeToCid
-
codeToCidRanges
private final java.util.List<CIDRange> codeToCidRanges
-
unicodeToByteCodes
private final java.util.Map<java.lang.String,byte[]> unicodeToByteCodes
-
SPACE
private static final java.lang.String SPACE
- See Also:
- Constant Field Values
-
spaceMapping
private int spaceMapping
-
-
Method Detail
-
hasCIDMappings
public boolean hasCIDMappings()
This will tell if this cmap has any CID mappings.- Returns:
- true If there are any CID mappings, false otherwise.
-
hasUnicodeMappings
public boolean hasUnicodeMappings()
This will tell if this cmap has any Unicode mappings.- Returns:
- true If there are any Unicode mappings, false otherwise.
-
toUnicode
public java.lang.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- character code- Returns:
- Unicode characters (may be more than one, e.g "fi" ligature)
-
toUnicode
public java.lang.String toUnicode(int code, int length)Returns the sequence of Unicode characters for the given character code.- Parameters:
code- character codelength- code length- Returns:
- Unicode characters (may be more than one, e.g "fi" ligature)
-
toUnicode
public java.lang.String toUnicode(byte[] code)
Returns the sequence of Unicode characters for the given character code.- Parameters:
code- bytes of the character code- Returns:
- Unicode characters (may be more than one, e.g "fi" ligature)
-
readCode
public int readCode(java.io.InputStream in) throws java.io.IOExceptionReads a character code from a string in the content stream.See "CMap Mapping" and "Handling Undefined Characters" in PDF32000 for more details.
- Parameters:
in- string stream- Returns:
- character code
- Throws:
java.io.IOException- if there was an error reading the stream or CMap
-
toInt
static int toInt(byte[] data)
Returns an int for the given byte array
-
toInt
private static int toInt(byte[] data, int dataLen)Returns an int for the given byte array
-
toCID
public int toCID(byte[] code)
Returns the CID for the given character code.- Parameters:
code- character code as byte array- Returns:
- CID
-
toCID
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- character code- Returns:
- CID
-
toCID
public int toCID(int code, int length)Returns the CID for the given character code.- Parameters:
code- character codelength- the origin byte length of the code- Returns:
- CID
-
toCIDFromRanges
private int toCIDFromRanges(int code, int length)Returns the CID for the given character code.- Parameters:
code- character code- Returns:
- CID
-
toCIDFromRanges
private int toCIDFromRanges(byte[] code)
Returns the CID for the given character code.- Parameters:
code- character code- Returns:
- CID
-
addCharMapping
void addCharMapping(byte[] codes, java.lang.String unicode)This will add a character code to Unicode character sequence mapping.- Parameters:
codes- The character codes to map from.unicode- The Unicode characters to map to.
-
getCodesFromUnicode
public byte[] getCodesFromUnicode(java.lang.String unicode)
Get the code bytes for an unicode string.- Parameters:
unicode- The unicode string.- Returns:
- the code bytes or null if there is none.
-
addCIDMapping
void addCIDMapping(byte[] code, int cid)This will add a CID mapping.- Parameters:
code- character codecid- CID
-
addCIDRange
void addCIDRange(byte[] from, byte[] to, int cid)This will add a CID Range.- Parameters:
from- starting character of the CID range.to- ending character of the CID range.cid- the cid to be started with.
-
addCIDRange
private void addCIDRange(java.util.List<CIDRange> cidRanges, int from, int to, int cid, int length)
-
addCodespaceRange
void addCodespaceRange(CodespaceRange range)
This will add a codespace range.- Parameters:
range- A single codespace range.
-
useCmap
void useCmap(CMap cmap)
Implementation of the usecmap operator. This will copy all of the mappings from one cmap to another.- Parameters:
cmap- The cmap to load mappings from.
-
getWMode
public int getWMode()
Returns the WMode of a CMap. 0 represents a horizontal and 1 represents a vertical orientation.- Returns:
- the wmode
-
setWMode
public void setWMode(int newWMode)
Sets the WMode of a CMap.- Parameters:
newWMode- the new WMode.
-
getName
public java.lang.String getName()
Returns the name of the CMap.- Returns:
- the CMap name.
-
setName
public void setName(java.lang.String name)
Sets the name of the CMap.- Parameters:
name- the CMap name.
-
getVersion
public java.lang.String getVersion()
Returns the version of the CMap.- Returns:
- the CMap version.
-
setVersion
public void setVersion(java.lang.String version)
Sets the version of the CMap.- Parameters:
version- the CMap version.
-
getType
public int getType()
Returns the type of the CMap.- Returns:
- the CMap type.
-
setType
public void setType(int type)
Sets the type of the CMap.- Parameters:
type- the CMap type.
-
getRegistry
public java.lang.String getRegistry()
Returns the registry of the CIDSystemInfo.- Returns:
- the registry.
-
setRegistry
public void setRegistry(java.lang.String newRegistry)
Sets the registry of the CIDSystemInfo.- Parameters:
newRegistry- the registry.
-
getOrdering
public java.lang.String getOrdering()
Returns the ordering of the CIDSystemInfo.- Returns:
- the ordering.
-
setOrdering
public void setOrdering(java.lang.String newOrdering)
Sets the ordering of the CIDSystemInfo.- Parameters:
newOrdering- the ordering.
-
getSupplement
public int getSupplement()
Returns the supplement of the CIDSystemInfo.- Returns:
- the supplement.
-
setSupplement
public void setSupplement(int newSupplement)
Sets the supplement of the CIDSystemInfo.- Parameters:
newSupplement- the supplement.
-
getSpaceMapping
public int getSpaceMapping()
Returns the mapping for the space character.- Returns:
- the mapped code for the space character
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-