Package com.itextpdf.io.font
Class FontEncoding
java.lang.Object
com.itextpdf.io.font.FontEncoding
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringBase font encoding.protected int[]Unicode values indexed by unsigned one-byte font code;-1marks an unmapped code.protected String[]Encoding names.static final Stringprotected booleantrueif the font must use its built in encoding.static final StringA not defined character in a custom PDF encoding.protected com.itextpdf.io.util.IntHashtableEncodings unicode differencesprotected com.itextpdf.io.util.IntHashtableMapping map from unicode to simple code according to the encoding. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates an empty encoding with 256 code slots and no base encoding. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddSymbol(int code, int unicode) booleancanDecode(int code) Check whether abytecode can be converted to unicode symbol according to the encoding.booleancanEncode(int unicode) Check whether a unicode symbol or font specific code can be converted tobyteaccording to the encoding.intconvertToByte(int unicode) Converts a unicode symbol or font specific code tobyteaccording to the encoding.byte[]convertToBytes(String text) Converts aStringto abytearray according to the encoding.static FontEncodingCreates an empty font encoding.static FontEncodingcreateFontEncoding(String baseEncoding) Creates an encoding from a named encoding or custom encoding description.static FontEncodingThis encoding will base on font encoding (FontSpecific encoding in Type 1 terminology)protected voidParses the custom#-prefixed base encoding specification.static voidfillFontEncoding(FontEncoding encoding) FillFontEncodingobject with default data.protected voidParses the named encoding.protected voidFills mappings from the PDF StandardEncoding table.Gets the normalized base encoding name.getDifference(int index) intgetUnicode(int index) Gets unicode value for corresponding font's char code.intgetUnicodeDifference(int index) booleanbooleanisBuiltWith(String encoding) Checks whether theFontEncodingwas built with corresponding encoding.booleanChecks whether codes are interpreted using the font's built-in encoding.protected static StringnormalizeEncoding(String enc) Normalize the encoding names.voidsetDifference(int index, String difference) Sets a new value in the differences array.
-
Field Details
-
FONT_SPECIFIC
- See Also:
-
NOTDEF
A not defined character in a custom PDF encoding.- See Also:
-
baseEncoding
Base font encoding. -
fontSpecific
protected boolean fontSpecifictrueif the font must use its built in encoding. In that case theencodingis only used to map a char to the position inside the font, not to the expected char name. -
unicodeToCode
protected com.itextpdf.io.util.IntHashtable unicodeToCodeMapping map from unicode to simple code according to the encoding. -
codeToUnicode
protected int[] codeToUnicodeUnicode values indexed by unsigned one-byte font code;-1marks an unmapped code. -
differences
Encoding names. -
unicodeDifferences
protected com.itextpdf.io.util.IntHashtable unicodeDifferencesEncodings unicode differences
-
-
Constructor Details
-
FontEncoding
protected FontEncoding()Creates an empty encoding with 256 code slots and no base encoding.
-
-
Method Details
-
createFontEncoding
Creates an encoding from a named encoding or custom encoding description.- Parameters:
-
baseEncoding- encoding name or custom specification beginning with# - Returns:
- created encoding
-
createEmptyFontEncoding
Creates an empty font encoding.- Returns:
- empty non-font-specific encoding
-
createFontSpecificEncoding
This encoding will base on font encoding (FontSpecific encoding in Type 1 terminology)- Returns:
- created font specific encoding
-
fillFontEncoding
FillFontEncodingobject with default data.- Parameters:
-
encoding-FontEncodingto fill.
-
getBaseEncoding
Gets the normalized base encoding name.- Returns:
-
base encoding name, or
nullfor an empty encoding
-
isFontSpecific
public boolean isFontSpecific()Checks whether codes are interpreted using the font's built-in encoding.- Returns:
-
truefor a font-specific encoding
-
addSymbol
public boolean addSymbol(int code, int unicode) -
getUnicode
public int getUnicode(int index) Gets unicode value for corresponding font's char code.- Parameters:
-
index- font's char code - Returns:
- -1, if the char code unsupported or valid unicode.
-
getUnicodeDifference
public int getUnicodeDifference(int index) -
hasDifferences
public boolean hasDifferences() -
getDifference
-
setDifference
Sets a new value in the differences array. Seedifferences.- Parameters:
-
index- position to replace -
difference- new difference value
-
convertToBytes
Converts aStringto abytearray according to the encoding. String could contain a unicode symbols or font specific codes.- Parameters:
-
text- theStringto be converted. - Returns:
-
an array of
byterepresenting the conversion according to the encoding
-
convertToByte
public int convertToByte(int unicode) Converts a unicode symbol or font specific code tobyteaccording to the encoding.- Parameters:
-
unicode- a unicode symbol or FontSpecif code to be converted. - Returns:
-
a
byterepresenting the conversion according to the encoding
-
canEncode
public boolean canEncode(int unicode) Check whether a unicode symbol or font specific code can be converted tobyteaccording to the encoding.- Parameters:
-
unicode- a unicode symbol or font specific code to be checked. - Returns:
-
trueifchcould be encoded.
-
canDecode
public boolean canDecode(int code) Check whether abytecode can be converted to unicode symbol according to the encoding.- Parameters:
-
code- a byte code to be checked. - Returns:
-
trueifcodecould be decoded.
-
isBuiltWith
Checks whether theFontEncodingwas built with corresponding encoding.- Parameters:
-
encoding- an encoding - Returns:
- true, if the FontEncoding was built with the encoding. Otherwise false.
-
fillCustomEncoding
protected void fillCustomEncoding()Parses the custom#-prefixed base encoding specification. -
fillNamedEncoding
protected void fillNamedEncoding()Parses the named encoding. -
fillStandardEncoding
protected void fillStandardEncoding()Fills mappings from the PDF StandardEncoding table. -
normalizeEncoding
Normalize the encoding names. "winansi" is changed to "Cp1252" and "macroman" is changed to "MacRoman".- Parameters:
-
enc- the encoding to be normalized - Returns:
- the normalized encoding
-