Package com.itextpdf.text.pdf
Class CMapAwareDocumentFont
- java.lang.Object
-
- com.itextpdf.text.pdf.BaseFont
-
- com.itextpdf.text.pdf.DocumentFont
-
- com.itextpdf.text.pdf.CMapAwareDocumentFont
-
public class CMapAwareDocumentFont extends DocumentFont
Implementation of DocumentFont used while parsing PDF streams.- Since:
- 2.1.4
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.itextpdf.text.pdf.BaseFont
BaseFont.StreamFont
-
-
Field Summary
Fields Modifier and Type Field Description private CMapByteCid
byteCid
private char[]
cidbyte2uni
Mapping between CID code (single byte only for now) and unicode equivalent as derived by the font's encoding.private CMapCidUni
cidUni
private PdfDictionary
fontDic
The font dictionary.private static Logger
LOGGER
private int
spaceWidth
the width of a space for this font, in normalized 1000 point unitsprivate CMapToUnicode
toUnicodeCmap
The CMap constructed from the ToUnicode map from the font's dictionary, if present.private java.util.Map<java.lang.Integer,java.lang.Integer>
uni2cid
-
Fields inherited from class com.itextpdf.text.pdf.DocumentFont
cjkEncoding, defaultWidth, isType0, uniMap
-
Fields inherited from class com.itextpdf.text.pdf.BaseFont
ASCENT, AWT_ASCENT, AWT_DESCENT, AWT_LEADING, AWT_MAXADVANCE, BBOXLLX, BBOXLLY, BBOXURX, BBOXURY, BuiltinFonts14, CACHED, CAPHEIGHT, CHAR_RANGE_ARABIC, CHAR_RANGE_CYRILLIC, CHAR_RANGE_HEBREW, CHAR_RANGE_LATIN, charBBoxes, CID_NEWLINE, compressionLevel, COURIER, COURIER_BOLD, COURIER_BOLDOBLIQUE, COURIER_OBLIQUE, CP1250, CP1252, CP1257, DEFAULT_FONT_MATRIX, DESCENT, differences, directTextToByte, embedded, EMBEDDED, encoding, fastWinansi, FONT_TYPE_CJK, FONT_TYPE_DOCUMENT, FONT_TYPE_T1, FONT_TYPE_T3, FONT_TYPE_TT, FONT_TYPE_TTUNI, FONT_WEIGHT, fontCache, fontSpecific, fontType, forceWidthsOutput, HELVETICA, HELVETICA_BOLD, HELVETICA_BOLDOBLIQUE, HELVETICA_OBLIQUE, IDENTITY_H, IDENTITY_V, ITALICANGLE, MACROMAN, NOT_CACHED, NOT_EMBEDDED, notdef, PARAGRAPH_SEPARATOR, RESOURCE_PATH, specialMap, STRIKETHROUGH_POSITION, STRIKETHROUGH_THICKNESS, SUBSCRIPT_OFFSET, SUBSCRIPT_SIZE, subset, subsetRanges, SUPERSCRIPT_OFFSET, SUPERSCRIPT_SIZE, SYMBOL, TIMES_BOLD, TIMES_BOLDITALIC, TIMES_ITALIC, TIMES_ROMAN, UNDERLINE_POSITION, UNDERLINE_THICKNESS, unicodeDifferences, vertical, WEIGHT_CLASS, WIDTH_CLASS, widths, WINANSI, ZAPFDINGBATS
-
-
Constructor Summary
Constructors Constructor Description CMapAwareDocumentFont(PdfDictionary font)
CMapAwareDocumentFont(PRIndirectReference refFont)
Creates an instance of a CMapAwareFont based on an indirect reference to a font.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private int
computeAverageWidth()
For all widths of all glyphs, compute the average width in normalized 1000 point units.java.lang.String
decode(byte[] cidbytes, int offset, int len)
Decodes a string of bytes (encoded in the font's encoding) into a unicode string This will use the ToUnicode map of the font, if available, otherwise it uses the font's encodingprivate java.lang.String
decodeSingleCID(byte[] bytes, int offset, int len)
Decodes a single CID (represented by one or two bytes) to a unicode String.java.lang.String
encode(byte[] bytes, int offset, int len)
Deprecated.method name is not indicative of what it does.int
getWidth(int char1)
Gets the width of achar
in normalized 1000 units.private void
initFont()
private void
processToUnicode()
Parses the ToUnicode entry, if present, and constructs a CMap for itprivate void
processUni2Byte()
Inverts DocumentFont's uni2byte mapping to obtain a cid-to-unicode mapping based on the font's encoding-
Methods inherited from class com.itextpdf.text.pdf.DocumentFont
charExists, convertToBytes, convertToBytes, getAllNameEntries, getByte2Uni, getCharBBox, getDiffmap, getFamilyFontName, getFontDescriptor, getFontDictionary, getFontMatrix, getFullFontName, getFullFontStream, getIndirectReference, getKerning, getPostscriptFontName, getRawCharBBox, getRawWidth, getUni2Byte, getWidth, hasKernPairs, isSymbolic, isVertical, setKerning, setPostscriptFontName, writeFont
-
Methods inherited from class com.itextpdf.text.pdf.BaseFont
addSubsetRange, correctArabicAdvance, createBuiltInFontDictionary, createEncoding, createFont, createFont, createFont, createFont, createFont, createFont, createFont, createSubsetPrefix, enumerateTTCNames, enumerateTTCNames, getAllFontNames, getAllNameEntries, getAscent, getAscentPoint, getBaseName, getCidCode, getCodePagesSupported, getCompressionLevel, getDescent, getDescentPoint, getDifferences, getDocumentFonts, getDocumentFonts, getEncoding, getFontType, getFullFontName, getSubfamily, getUnicodeDifferences, getUnicodeDifferences, getUnicodeEquivalent, getWidthPoint, getWidthPoint, getWidthPointKerned, getWidths, isDirectTextToByte, isEmbedded, isFontSpecific, isForceWidthsOutput, isSubset, normalizeEncoding, setCharAdvance, setCompressionLevel, setDirectTextToByte, setFontDescriptor, setForceWidthsOutput, setSubset
-
-
-
-
Field Detail
-
LOGGER
private static final Logger LOGGER
-
fontDic
private PdfDictionary fontDic
The font dictionary.
-
spaceWidth
private int spaceWidth
the width of a space for this font, in normalized 1000 point units
-
toUnicodeCmap
private CMapToUnicode toUnicodeCmap
The CMap constructed from the ToUnicode map from the font's dictionary, if present. This CMap transforms CID values into unicode equivalent
-
byteCid
private CMapByteCid byteCid
-
cidUni
private CMapCidUni cidUni
-
cidbyte2uni
private char[] cidbyte2uni
Mapping between CID code (single byte only for now) and unicode equivalent as derived by the font's encoding. Only needed if the ToUnicode CMap is not provided.
-
uni2cid
private java.util.Map<java.lang.Integer,java.lang.Integer> uni2cid
-
-
Constructor Detail
-
CMapAwareDocumentFont
public CMapAwareDocumentFont(PdfDictionary font)
-
CMapAwareDocumentFont
public CMapAwareDocumentFont(PRIndirectReference refFont)
Creates an instance of a CMapAwareFont based on an indirect reference to a font.- Parameters:
refFont
- the indirect reference to a font
-
-
Method Detail
-
initFont
private void initFont()
-
processToUnicode
private void processToUnicode()
Parses the ToUnicode entry, if present, and constructs a CMap for it- Since:
- 2.1.7
-
processUni2Byte
private void processUni2Byte() throws java.io.IOException
Inverts DocumentFont's uni2byte mapping to obtain a cid-to-unicode mapping based on the font's encoding- Throws:
java.io.IOException
- Since:
- 2.1.7
-
computeAverageWidth
private int computeAverageWidth()
For all widths of all glyphs, compute the average width in normalized 1000 point units. This is used to give some meaningful width in cases where we need an average font width (such as if the width of a space isn't specified by a given font)- Returns:
- the average width of all non-zero width glyphs in the font
-
getWidth
public int getWidth(int char1)
Description copied from class:DocumentFont
Gets the width of achar
in normalized 1000 units.- Overrides:
getWidth
in classDocumentFont
- Parameters:
char1
- the unicodechar
to get the width of- Returns:
- the width in normalized 1000 units
- Since:
- 2.1.5 Override to allow special handling for fonts that don't specify width of space character
- See Also:
DocumentFont.getWidth(int)
-
decodeSingleCID
private java.lang.String decodeSingleCID(byte[] bytes, int offset, int len)
Decodes a single CID (represented by one or two bytes) to a unicode String.- Parameters:
bytes
- the bytes making up the character code to convertoffset
- an offsetlen
- a length- Returns:
- a String containing the encoded form of the input bytes using the font's encoding.
-
decode
public java.lang.String decode(byte[] cidbytes, int offset, int len)
Decodes a string of bytes (encoded in the font's encoding) into a unicode string This will use the ToUnicode map of the font, if available, otherwise it uses the font's encoding- Parameters:
cidbytes
- the bytes that need to be decoded- Returns:
- the unicode String that results from decoding
- Since:
- 2.1.7
-
encode
public java.lang.String encode(byte[] bytes, int offset, int len)
Deprecated.method name is not indicative of what it does. Usedecode
instead.Encodes bytes to a String.- Parameters:
bytes
- the bytes from a streamoffset
- an offsetlen
- a length- Returns:
- a String encoded taking into account if the bytes are in unicode or not.
-
-