Package com.lowagie.text.pdf
Class CMapAwareDocumentFont
java.lang.Object
com.lowagie.text.pdf.BaseFont
com.lowagie.text.pdf.DocumentFont
com.lowagie.text.pdf.CMapAwareDocumentFont
Implementation of DocumentFont used while parsing PDF streams.
- Since:
- 2.1.4
-
Nested Class Summary
Nested classes/interfaces inherited from class com.lowagie.text.pdf.BaseFont
BaseFont.StreamFont
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate char[]
Mapping between CID code (single byte only for now) and unicode equivalent as derived by the font's encoding.private PdfDictionary
The font dictionary.private int
the width of a space for this font, in normalized 1000 point unitsprivate CMap
The CMap constructed from the ToUnicode map from the font's dictionary, if present.Fields inherited from class com.lowagie.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, 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, fontCache, fontSpecific, fontType, forceWidthsOutput, HELVETICA, HELVETICA_BOLD, HELVETICA_BOLDOBLIQUE, HELVETICA_OBLIQUE, IDENTITY_H, IDENTITY_V, includeCidSet, ITALICANGLE, MACROMAN, NOT_CACHED, NOT_EMBEDDED, notdef, RESOURCE_PATH, secureRandom, 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, widths, WINANSI, ZAPFDINGBATS
-
Constructor Summary
ConstructorsConstructorDescriptionCMapAwareDocumentFont
(PRIndirectReference refFont) Creates an instance of a CMapAwareFont based on an indirect reference to a font. -
Method Summary
Modifier and TypeMethodDescriptionprivate int
For all widths of all glyphs, compute the average width in normalized 1000 point units.decode
(byte[] cidbytes, int offset, int len) Decodes a string of bytes (encoded in the font's encoding) into a unicode string.decode
(char c) Decode single character whose value represents a code point in this font.Decodes a string.private String
decodeSingleCID
(byte[] bytes, int offset, int len) Decodes a single CID (represented by one or two bytes) to a unicode String.int
getWidth
(int char1) Gets the width of achar
in normalized 1000 units.boolean
boolean
private void
Parses the ToUnicode entry, if present, and constructs a CMap for itprivate void
Inverts DocumentFont's uni2byte mapping to obtain a cid-to-unicode mapping based on the font's encodingMethods inherited from class com.lowagie.text.pdf.DocumentFont
charExists, convertToBytes, convertToBytes, getAllNameEntries, getCharBBox, getFamilyFontName, getFontDescriptor, getFontDescriptor, getFullFontName, getFullFontStream, getIndirectReference, getKerning, getPostscriptFontName, getRawCharBBox, getRawWidth, getUni2Byte, getWidth, hasKernPairs, setKerning, setPostscriptFontName, toString, writeFont
Methods inherited from class com.lowagie.text.pdf.BaseFont
addSubsetRange, correctArabicAdvance, 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, getResourceStream, getResourceStream, getSecureRandom, getUnicodeDifferences, getUnicodeDifferences, getUnicodeEquivalent, getWidthPoint, getWidthPoint, getWidthPointKerned, getWidths, isDirectTextToByte, isEmbedded, isFontSpecific, isForceWidthsOutput, isIncludeCidSet, isSubset, normalizeEncoding, setCharAdvance, setCompressionLevel, setDirectTextToByte, setForceWidthsOutput, setIncludeCidSet, setSecureRandom, setSubset
-
Field Details
-
fontDic
The font dictionary. -
spaceWidth
private int spaceWidththe width of a space for this font, in normalized 1000 point units -
toUnicodeCmap
The CMap constructed from the ToUnicode map from the font's dictionary, if present. This CMap transforms CID values into unicode equivalent -
cidbyte2uni
private char[] cidbyte2uniMapping 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.
-
-
Constructor Details
-
CMapAwareDocumentFont
Creates an instance of a CMapAwareFont based on an indirect reference to a font.- Parameters:
refFont
- the indirect reference to a font
-
-
Method Details
-
processToUnicode
private void processToUnicode()Parses the ToUnicode entry, if present, and constructs a CMap for it- Since:
- 2.1.7
-
processUni2Byte
private void processUni2Byte()Inverts DocumentFont's uni2byte mapping to obtain a cid-to-unicode mapping based on the font's encoding- 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:
-
decodeSingleCID
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.
-
hasUnicodeCMAP
public boolean hasUnicodeCMAP()- Returns:
- true if this font has unicode information available.
-
hasTwoByteUnicodeCMAP
public boolean hasTwoByteUnicodeCMAP()- Returns:
- true if this font has unicode information available and if it is two bytes.
-
decode
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 decodedoffset
- offsetlen
- length- Returns:
- the unicode String that results from decoding
- Since:
- 2.1.7
-
decode
Decodes a string. This is a normal Java string, but if the range of character values exceeds the range of the encoding for the font, this will fail. Required since we need to process the characters of strings, and we can't determine the character boundaries in advance, especially because of Identity-H encoded fonts which have two-byte character indexes.PdfString is used to hold character code points, even though the bytes may not map 1-1. It's not possible to change the encoding once a string is in place.
- Parameters:
chars
- the Characters that need to be decoded- Returns:
- the unicode String that results from decoding
- Since:
- 2.1.
-
decode
Decode single character whose value represents a code point in this font. Will fail if the characters do not have values that correspond to valid code points for the font.- Parameters:
c
- character to decode- Returns:
- Unicode character corresponding to the remapped code according to the font's current encoding.
- Throws:
Error
- if the the character is out of range
-