Package com.itextpdf.text.pdf
Class CJKFont
- java.lang.Object
-
- com.itextpdf.text.pdf.BaseFont
-
- com.itextpdf.text.pdf.CJKFont
-
class CJKFont extends BaseFont
Creates a CJK font compatible with the fonts in the Adobe Asian font Pack.
-
-
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 static java.util.HashMap<java.lang.String,java.util.HashMap<java.lang.String,java.lang.Object>>
allFonts
private static int
BRACKET
private CMapCidByte
cidByte
private boolean
cidDirect
private CMapCidUni
cidUni
(package private) static java.lang.String
CJK_ENCODING
The encoding used in the PDF document for CJK fonts(package private) static java.util.Properties
cjkEncodings
(package private) static java.util.Properties
cjkFonts
private java.lang.String
CMap
The CMap name associated with this fontprivate static int
FIRST
private java.util.HashMap<java.lang.String,java.lang.Object>
fontDesc
private java.lang.String
fontName
The font nameprivate IntHashtable
hMetrics
private static boolean
propertiesLoaded
private static java.util.HashMap<java.lang.String,java.util.Set<java.lang.String>>
registryNames
static java.lang.String
RESOURCE_PATH_CMAP
The path to the font resources.private static int
SERIAL
private java.lang.String
style
The style modifierprivate CMapUniCid
uniCid
private java.lang.String
uniMap
private static int
V1Y
private IntHashtable
vMetrics
-
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 CJKFont(java.lang.String fontName, java.lang.String enc, boolean emb)
Creates a CJK font.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
charExists(int c)
Checks if a character exists in this font.(package private) byte[]
convertToBytes(int char1)
Converts achar
to a byte array according to the font's encoding.byte[]
convertToBytes(java.lang.String text)
Converts aString
to a byte array according to the font's encoding.(package private) static java.lang.String
convertToHCIDMetrics(int[] keys, IntHashtable h)
(package private) static java.lang.String
convertToVCIDMetrics(int[] keys, IntHashtable v, IntHashtable h)
(package private) static IntHashtable
createMetric(java.lang.String s)
java.lang.String[][]
getAllNameEntries()
Gets all the entries of the names-table.private float
getBBox(int idx)
int[]
getCharBBox(int c)
Gets the smallest box enclosing the character contours.int
getCidCode(int c)
Gets the CID code given an Unicode.private PdfDictionary
getCIDFont(PdfIndirectReference fontDescriptor, IntHashtable cjkTag)
static java.lang.String
GetCompatibleFont(java.lang.String enc)
Returns a font compatible with a CJK encoding or null if not found.private float
getDescNumber(java.lang.String name)
java.lang.String[][]
getFamilyFontName()
Gets the family name of the font.private PdfDictionary
getFontBaseType(PdfIndirectReference CIDFont)
private PdfDictionary
getFontDescriptor()
float
getFontDescriptor(int key, float fontSize)
Gets the font parameter identified bykey
.java.lang.String[][]
getFullFontName()
Gets the full name of the font.PdfStream
getFullFontStream()
You can't get the FontStream of a CJK font (CJK fonts are never embedded), so this method always returns null.int
getKerning(int char1, int char2)
Gets the kerning between two Unicode chars.java.lang.String
getPostscriptFontName()
Gets the postscript font name.protected int[]
getRawCharBBox(int c, java.lang.String name)
(package private) int
getRawWidth(int c, java.lang.String name)
Gets the width from the font according to the Unicode charc
or thename
.int
getUnicodeEquivalent(int c)
Gets the Unicode equivalent to a CID.(package private) java.lang.String
getUniMap()
int
getWidth(int char1)
Gets the width of achar
in normalized 1000 units.int
getWidth(java.lang.String text)
Gets the width of aString
in normalized 1000 units.boolean
hasKernPairs()
Checks if the font has any kerning pairs.static boolean
isCJKFont(java.lang.String fontName, java.lang.String enc)
Checks if its a valid CJK font.boolean
isIdentity()
private void
loadCMaps()
private static void
loadProperties()
private static void
loadRegistry()
private static java.util.HashMap<java.lang.String,java.lang.Object>
readFontProperties(java.lang.String name)
boolean
setCharAdvance(int c, int advance)
Sets the character advance.boolean
setKerning(int char1, int char2, int kern)
Sets the kerning between two Unicode chars.void
setPostscriptFontName(java.lang.String name)
Sets the font name that will appear in the pdf font dictionary.(package private) void
writeFont(PdfWriter writer, PdfIndirectReference ref, java.lang.Object[] params)
Outputs to the writer the font dictionaries and streams.-
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, getCodePagesSupported, getCompressionLevel, getDescent, getDescentPoint, getDifferences, getDocumentFonts, getDocumentFonts, getEncoding, getFontMatrix, getFontType, getFullFontName, getSubfamily, getUnicodeDifferences, getUnicodeDifferences, getWidthPoint, getWidthPoint, getWidthPointKerned, getWidths, isDirectTextToByte, isEmbedded, isFontSpecific, isForceWidthsOutput, isSubset, isVertical, normalizeEncoding, setCompressionLevel, setDirectTextToByte, setFontDescriptor, setForceWidthsOutput, setSubset
-
-
-
-
Field Detail
-
CJK_ENCODING
static final java.lang.String CJK_ENCODING
The encoding used in the PDF document for CJK fonts- See Also:
- Constant Field Values
-
FIRST
private static final int FIRST
- See Also:
- Constant Field Values
-
BRACKET
private static final int BRACKET
- See Also:
- Constant Field Values
-
SERIAL
private static final int SERIAL
- See Also:
- Constant Field Values
-
V1Y
private static final int V1Y
- See Also:
- Constant Field Values
-
cjkFonts
static java.util.Properties cjkFonts
-
cjkEncodings
static java.util.Properties cjkEncodings
-
allFonts
private static final java.util.HashMap<java.lang.String,java.util.HashMap<java.lang.String,java.lang.Object>> allFonts
-
propertiesLoaded
private static boolean propertiesLoaded
-
RESOURCE_PATH_CMAP
public static final java.lang.String RESOURCE_PATH_CMAP
The path to the font resources.- See Also:
- Constant Field Values
-
registryNames
private static final java.util.HashMap<java.lang.String,java.util.Set<java.lang.String>> registryNames
-
cidByte
private CMapCidByte cidByte
-
uniCid
private CMapUniCid uniCid
-
cidUni
private CMapCidUni cidUni
-
uniMap
private java.lang.String uniMap
-
fontName
private java.lang.String fontName
The font name
-
style
private java.lang.String style
The style modifier
-
CMap
private java.lang.String CMap
The CMap name associated with this font
-
cidDirect
private boolean cidDirect
-
vMetrics
private IntHashtable vMetrics
-
hMetrics
private IntHashtable hMetrics
-
fontDesc
private java.util.HashMap<java.lang.String,java.lang.Object> fontDesc
-
-
Constructor Detail
-
CJKFont
CJKFont(java.lang.String fontName, java.lang.String enc, boolean emb) throws DocumentException
Creates a CJK font.- Parameters:
fontName
- the name of the fontenc
- the encoding of the fontemb
- alwaysfalse
. CJK font and not embedded- Throws:
DocumentException
- on error
-
-
Method Detail
-
loadProperties
private static void loadProperties()
-
loadRegistry
private static void loadRegistry() throws java.io.IOException
- Throws:
java.io.IOException
-
getUniMap
java.lang.String getUniMap()
-
loadCMaps
private void loadCMaps() throws DocumentException
- Throws:
DocumentException
-
GetCompatibleFont
public static java.lang.String GetCompatibleFont(java.lang.String enc)
Returns a font compatible with a CJK encoding or null if not found.- Parameters:
enc
-- Returns:
-
isCJKFont
public static boolean isCJKFont(java.lang.String fontName, java.lang.String enc)
Checks if its a valid CJK font.- Parameters:
fontName
- the font nameenc
- the encoding- Returns:
true
if it is CJK font
-
getWidth
public int getWidth(int char1)
Gets the width of achar
in normalized 1000 units.
-
getWidth
public int getWidth(java.lang.String text)
Description copied from class:BaseFont
Gets the width of aString
in normalized 1000 units.
-
getRawWidth
int getRawWidth(int c, java.lang.String name)
Description copied from class:BaseFont
Gets the width from the font according to the Unicode charc
or thename
. If thename
is null it's a symbolic font.- Specified by:
getRawWidth
in classBaseFont
- Parameters:
c
- the unicode charname
- the glyph name- Returns:
- the width of the char
-
getKerning
public int getKerning(int char1, int char2)
Description copied from class:BaseFont
Gets the kerning between two Unicode chars.- Specified by:
getKerning
in classBaseFont
- Parameters:
char1
- the first charchar2
- the second char- Returns:
- the kerning to be applied in normalized 1000 units
-
getFontDescriptor
private PdfDictionary getFontDescriptor()
-
getCIDFont
private PdfDictionary getCIDFont(PdfIndirectReference fontDescriptor, IntHashtable cjkTag)
-
getFontBaseType
private PdfDictionary getFontBaseType(PdfIndirectReference CIDFont)
-
writeFont
void writeFont(PdfWriter writer, PdfIndirectReference ref, java.lang.Object[] params) throws DocumentException, java.io.IOException
Description copied from class:BaseFont
Outputs to the writer the font dictionaries and streams.- Specified by:
writeFont
in classBaseFont
- Parameters:
writer
- the writer for this documentref
- the font indirect referenceparams
- several parameters that depend on the font type- Throws:
DocumentException
- error in generating the objectjava.io.IOException
- on error
-
getFullFontStream
public PdfStream getFullFontStream()
You can't get the FontStream of a CJK font (CJK fonts are never embedded), so this method always returns null.- Specified by:
getFullFontStream
in classBaseFont
- Returns:
- null
- Since:
- 2.1.3
-
getDescNumber
private float getDescNumber(java.lang.String name)
-
getBBox
private float getBBox(int idx)
-
getFontDescriptor
public float getFontDescriptor(int key, float fontSize)
Gets the font parameter identified bykey
. Valid values forkey
areASCENT
,CAPHEIGHT
,DESCENT
andITALICANGLE
.- Specified by:
getFontDescriptor
in classBaseFont
- Parameters:
key
- the parameter to be extractedfontSize
- the font size in points- Returns:
- the parameter in points
-
getPostscriptFontName
public java.lang.String getPostscriptFontName()
Description copied from class:BaseFont
Gets the postscript font name.- Specified by:
getPostscriptFontName
in classBaseFont
- Returns:
- the postscript font name
-
getFullFontName
public java.lang.String[][] getFullFontName()
Gets the full name of the font. If it is a True Type font each array element will have {Platform ID, Platform Encoding ID, Language ID, font name}. The interpretation of this values can be found in the Open Type specification, chapter 2, in the 'name' table.
For the other fonts the array has a single element with {"", "", "", font name}.- Specified by:
getFullFontName
in classBaseFont
- Returns:
- the full name of the font
-
getAllNameEntries
public java.lang.String[][] getAllNameEntries()
Gets all the entries of the names-table. If it is a True Type font each array element will have {Name ID, Platform ID, Platform Encoding ID, Language ID, font name}. The interpretation of this values can be found in the Open Type specification, chapter 2, in the 'name' table.
For the other fonts the array has a single element with {"4", "", "", "", font name}.- Specified by:
getAllNameEntries
in classBaseFont
- Returns:
- the full name of the font
-
getFamilyFontName
public java.lang.String[][] getFamilyFontName()
Gets the family name of the font. If it is a True Type font each array element will have {Platform ID, Platform Encoding ID, Language ID, font name}. The interpretation of this values can be found in the Open Type specification, chapter 2, in the 'name' table.
For the other fonts the array has a single element with {"", "", "", font name}.- Specified by:
getFamilyFontName
in classBaseFont
- Returns:
- the family name of the font
-
createMetric
static IntHashtable createMetric(java.lang.String s)
-
convertToHCIDMetrics
static java.lang.String convertToHCIDMetrics(int[] keys, IntHashtable h)
-
convertToVCIDMetrics
static java.lang.String convertToVCIDMetrics(int[] keys, IntHashtable v, IntHashtable h)
-
readFontProperties
private static java.util.HashMap<java.lang.String,java.lang.Object> readFontProperties(java.lang.String name) throws java.io.IOException
- Throws:
java.io.IOException
-
getUnicodeEquivalent
public int getUnicodeEquivalent(int c)
Description copied from class:BaseFont
Gets the Unicode equivalent to a CID. The (inexistent) CIDis translated as '\n'. It has only meaning with CJK fonts with Identity encoding. - Overrides:
getUnicodeEquivalent
in classBaseFont
- Parameters:
c
- the CID code- Returns:
- the Unicode equivalent
-
getCidCode
public int getCidCode(int c)
Description copied from class:BaseFont
Gets the CID code given an Unicode. It has only meaning with CJK fonts.- Overrides:
getCidCode
in classBaseFont
- Parameters:
c
- the Unicode- Returns:
- the CID equivalent
-
hasKernPairs
public boolean hasKernPairs()
Checks if the font has any kerning pairs.- Specified by:
hasKernPairs
in classBaseFont
- Returns:
- always
false
-
charExists
public boolean charExists(int c)
Checks if a character exists in this font.- Overrides:
charExists
in classBaseFont
- Parameters:
c
- the character to check- Returns:
true
if the character has a glyph,false
otherwise
-
setCharAdvance
public boolean setCharAdvance(int c, int advance)
Sets the character advance.- Overrides:
setCharAdvance
in classBaseFont
- Parameters:
c
- the characteradvance
- the character advance normalized to 1000 units- Returns:
true
if the advance was set,false
otherwise. Will always returnfalse
-
setPostscriptFontName
public void setPostscriptFontName(java.lang.String name)
Sets the font name that will appear in the pdf font dictionary. Use with care as it can easily make a font unreadable if not embedded.- Specified by:
setPostscriptFontName
in classBaseFont
- Parameters:
name
- the new font name
-
setKerning
public boolean setKerning(int char1, int char2, int kern)
Description copied from class:BaseFont
Sets the kerning between two Unicode chars.- Specified by:
setKerning
in classBaseFont
- Parameters:
char1
- the first charchar2
- the second charkern
- the kerning to apply in normalized 1000 units- Returns:
true
if the kerning was applied,false
otherwise
-
getCharBBox
public int[] getCharBBox(int c)
Description copied from class:BaseFont
Gets the smallest box enclosing the character contours. It will returnnull
if the font has not the information or the character has no contours, as in the case of the space, for example. Characters with no contours may also return [0,0,0,0].- Overrides:
getCharBBox
in classBaseFont
- Parameters:
c
- the character to get the contour bounding box from- Returns:
- an array of four floats with the bounding box in the format [llx,lly,urx,ury] or
null
-
getRawCharBBox
protected int[] getRawCharBBox(int c, java.lang.String name)
- Specified by:
getRawCharBBox
in classBaseFont
-
convertToBytes
public byte[] convertToBytes(java.lang.String text)
Converts aString
to a byte array according to the font's encoding.- Overrides:
convertToBytes
in classBaseFont
- Parameters:
text
- theString
to be converted- Returns:
- an array of
byte
representing the conversion according to the font's encoding
-
convertToBytes
byte[] convertToBytes(int char1)
Converts achar
to a byte array according to the font's encoding.- Overrides:
convertToBytes
in classBaseFont
- Parameters:
char1
- thechar
to be converted- Returns:
- an array of
byte
representing the conversion according to the font's encoding
-
isIdentity
public boolean isIdentity()
-
-