com.lowagie.text.pdf

Class CJKFont


(package private) class CJKFont
extends BaseFont

Creates a CJK font compatible with the fonts in the Adobe Asian font Pack.
Author:
Paulo Soares (psoares@consiste.pt)

Nested Class Summary

Nested classes/interfaces inherited from class com.lowagie.text.pdf.BaseFont

BaseFont.StreamFont

Field Summary

private static int
BRACKET
(package private) static String
CJK_ENCODING
The encoding used in the PDF document for CJK fonts
private String
CMap
The CMap name associated with this font
private static int
FIRST
private static int
SERIAL
private static int
V1Y
(package private) static Hashtable
allCMaps
(package private) static Hashtable
allFonts
private boolean
cidDirect
(package private) static Properties
cjkEncodings
(package private) static Properties
cjkFonts
private HashMap
fontDesc
private String
fontName
The font name
private IntHashtable
hMetrics
private static boolean
propertiesLoaded
private String
style
The style modifier
private char[]
translationMap
private IntHashtable
vMetrics
private boolean
vertical

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, CID_NEWLINE, COURIER, COURIER_BOLD, COURIER_BOLDOBLIQUE, COURIER_OBLIQUE, CP1250, CP1252, CP1257, DESCENT, EMBEDDED, FONT_TYPE_CJK, FONT_TYPE_DOCUMENT, FONT_TYPE_T1, FONT_TYPE_TT, FONT_TYPE_TTUNI, HELVETICA, HELVETICA_BOLD, HELVETICA_BOLDOBLIQUE, HELVETICA_OBLIQUE, IDENTITY_H, IDENTITY_V, ITALICANGLE, MACROMAN, NOT_CACHED, NOT_EMBEDDED, RESOURCE_PATH, SYMBOL, TIMES_BOLD, TIMES_BOLDITALIC, TIMES_ITALIC, TIMES_ROMAN, WINANSI, ZAPFDINGBATS, charBBoxes, differences, directTextToByte, embedded, encoding, fastWinansi, fontCache, fontSpecific, fontType, forceWidthsOutput, notdef, subset, unicodeDifferences, widths

Constructor Summary

CJKFont(String fontName, String enc, boolean emb)
Creates a CJK font.

Method Summary

boolean
charExists(char c)
Checks if a character exists in this font.
(package private) static String
convertToHCIDMetrics(keys[] , IntHashtable h)
(package private) static String
convertToVCIDMetrics(keys[] , IntHashtable v, IntHashtable h)
(package private) static IntHashtable
createMetric(String s)
private float
getBBox(int idx)
private PdfDictionary
getCIDFont(PdfIndirectReference fontDescriptor, IntHashtable cjkTag)
int[]
getCharBBox(char c)
Gets the smallest box enclosing the character contours.
char
getCidCode(char c)
Gets the CID code given an Unicode.
private float
getDescNumber(String name)
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 by key.
String[][]
getFullFontName()
Gets the full name of the font.
int
getKerning(char char1, char char2)
Gets the kerning between two Unicode chars.
String
getPostscriptFontName()
Gets the postscript font name.
protected int[]
getRawCharBBox(int c, String name)
(package private) int
getRawWidth(int c, String name)
Gets the width from the font according to the Unicode char c or the name.
char
getUnicodeEquivalent(char c)
Gets the Unicode equivalent to a CID.
int
getWidth(String text)
Gets the width of a String in normalized 1000 units.
boolean
hasKernPairs()
Checks if the font has any kerning pairs.
static boolean
isCJKFont(String fontName, String enc)
Checks if its a valid CJK font.
private static void
loadProperties()
(package private) static char[]
readCMap(String name)
(package private) static HashMap
readFontProperties(String name)
boolean
setCharAdvance(char c, int advance)
Sets the character advance.
boolean
setKerning(char char1, char char2, int kern)
Sets the kerning between two Unicode chars.
void
setPostscriptFontName(String name)
Sets the font name that will appear in the pdf font dictionary.
(package private) void
writeFont(PdfWriter writer, PdfIndirectReference ref, params[] )
Outputs to the writer the font dictionaries and streams.

Methods inherited from class com.lowagie.text.pdf.BaseFont

addFont, charExists, convertToBytes, createEncoding, createFont, createFont, createFont, createSubsetPrefix, enumerateTTCNames, enumerateTTCNames, getAllFontNames, getAscent, getAscentPoint, getBaseName, getCharBBox, getCidCode, getCodePagesSupported, getDescent, getDescentPoint, getDifferences, getDocumentFonts, getDocumentFonts, getEncoding, getFamilyFontName, getFontDescriptor, getFontType, getFullFontName, getFullFontName, getKerning, getPostscriptFontName, getRawCharBBox, getRawWidth, getResourceStream, getResourceStream, getUnicodeDifferences, getUnicodeDifferences, getUnicodeEquivalent, getWidth, getWidth, getWidthPoint, getWidthPoint, getWidthPointKerned, getWidths, hasKernPairs, isDirectTextToByte, isEmbedded, isFontSpecific, isForceWidthsOutput, isSubset, normalizeEncoding, recourseFonts, setCharAdvance, setDirectTextToByte, setForceWidthsOutput, setKerning, setPostscriptFontName, setSubset, writeFont

Field Details

BRACKET

private static final int BRACKET
Field Value:
1

CJK_ENCODING

(package private) static final String CJK_ENCODING
The encoding used in the PDF document for CJK fonts

CMap

private String CMap
The CMap name associated with this font

FIRST

private static final int FIRST
Field Value:
0

SERIAL

private static final int SERIAL
Field Value:
2

V1Y

private static final int V1Y
Field Value:
880

allCMaps

(package private) static Hashtable allCMaps

allFonts

(package private) static Hashtable allFonts

cidDirect

private boolean cidDirect

cjkEncodings

(package private) static Properties cjkEncodings

cjkFonts

(package private) static Properties cjkFonts

fontDesc

private HashMap fontDesc

fontName

private String fontName
The font name

hMetrics

private IntHashtable hMetrics

propertiesLoaded

private static boolean propertiesLoaded

style

private String style
The style modifier

translationMap

private char[] translationMap

vMetrics

private IntHashtable vMetrics

vertical

private boolean vertical

Constructor Details

CJKFont

(package private)  CJKFont(String fontName,
                           String enc,
                           boolean emb)
            throws DocumentException,
                   IOException
Creates a CJK font.
Parameters:
fontName - the name of the font
enc - the encoding of the font
emb - always false. CJK font and not embedded
Throws:
DocumentException - on error

Method Details

charExists

public boolean charExists(char c)
Checks if a character exists in this font.
Overrides:
charExists in interface BaseFont
Parameters:
c - the character to check
Returns:
true if the character has a glyph, false otherwise

convertToHCIDMetrics

(package private) static String convertToHCIDMetrics(keys[] ,
                                                     IntHashtable h)

convertToVCIDMetrics

(package private) static String convertToVCIDMetrics(keys[] ,
                                                     IntHashtable v,
                                                     IntHashtable h)

createMetric

(package private) static IntHashtable createMetric(String s)

getBBox

private float getBBox(int idx)

getCIDFont

private PdfDictionary getCIDFont(PdfIndirectReference fontDescriptor,
                                 IntHashtable cjkTag)

getCharBBox

public int[] getCharBBox(char c)
Gets the smallest box enclosing the character contours. It will return null 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 interface BaseFont
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

getCidCode

public char getCidCode(char c)
Gets the CID code given an Unicode. It has only meaning with CJK fonts.
Overrides:
getCidCode in interface BaseFont
Parameters:
c - the Unicode
Returns:
the CID equivalent

getDescNumber

private float getDescNumber(String name)

getFamilyFontName

public 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}.
Overrides:
getFamilyFontName in interface BaseFont
Returns:
the family name of the font

getFontBaseType

private PdfDictionary getFontBaseType(PdfIndirectReference CIDFont)

getFontDescriptor

private PdfDictionary getFontDescriptor()

getFontDescriptor

public float getFontDescriptor(int key,
                               float fontSize)
Gets the font parameter identified by key. Valid values for key are ASCENT, CAPHEIGHT, DESCENT and ITALICANGLE.
Overrides:
getFontDescriptor in interface BaseFont
Parameters:
key - the parameter to be extracted
fontSize - the font size in points
Returns:
the parameter in points

getFullFontName

public 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}.
Overrides:
getFullFontName in interface BaseFont
Returns:
the full name of the font

getKerning

public int getKerning(char char1,
                      char char2)
Gets the kerning between two Unicode chars.
Overrides:
getKerning in interface BaseFont
Parameters:
char1 - the first char
char2 - the second char
Returns:
the kerning to be applied in normalized 1000 units

getPostscriptFontName

public String getPostscriptFontName()
Gets the postscript font name.
Overrides:
getPostscriptFontName in interface BaseFont
Returns:
the postscript font name

getRawCharBBox

protected int[] getRawCharBBox(int c,
                               String name)
Overrides:
getRawCharBBox in interface BaseFont

getRawWidth

(package private)  int getRawWidth(int c,
                                   String name)
Gets the width from the font according to the Unicode char c or the name. If the name is null it's a symbolic font.
Overrides:
getRawWidth in interface BaseFont
Parameters:
c - the unicode char
name - the glyph name
Returns:
the width of the char

getUnicodeEquivalent

public char getUnicodeEquivalent(char c)
Gets the Unicode equivalent to a CID. The (inexistent) CID is translated as '\n'. It has only meaning with CJK fonts with Identity encoding.
Overrides:
getUnicodeEquivalent in interface BaseFont
Parameters:
c - the CID code
Returns:
the Unicode equivalent

getWidth

public int getWidth(String text)
Gets the width of a String in normalized 1000 units.
Overrides:
getWidth in interface BaseFont
Parameters:
text - the String to get the witdth of
Returns:
the width in normalized 1000 units

hasKernPairs

public boolean hasKernPairs()
Checks if the font has any kerning pairs.
Overrides:
hasKernPairs in interface BaseFont
Returns:
always false

isCJKFont

public static boolean isCJKFont(String fontName,
                                String enc)
Checks if its a valid CJK font.
Parameters:
fontName - the font name
enc - the encoding
Returns:
true if it is CJK font

loadProperties

private static void loadProperties()

readCMap

(package private) static char[] readCMap(String name)

readFontProperties

(package private) static HashMap readFontProperties(String name)

setCharAdvance

public boolean setCharAdvance(char c,
                              int advance)
Sets the character advance.
Overrides:
setCharAdvance in interface BaseFont
Parameters:
c - the character
advance - the character advance normalized to 1000 units
Returns:
true if the advance was set, false otherwise. Will always return false

setKerning

public boolean setKerning(char char1,
                          char char2,
                          int kern)
Sets the kerning between two Unicode chars.
Overrides:
setKerning in interface BaseFont
Parameters:
char1 - the first char
char2 - the second char
kern - the kerning to apply in normalized 1000 units
Returns:
true if the kerning was applied, false otherwise

setPostscriptFontName

public void setPostscriptFontName(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.
Overrides:
setPostscriptFontName in interface BaseFont
Parameters:
name - the new font name

writeFont

(package private)  void writeFont(PdfWriter writer,
                                  PdfIndirectReference ref,
                                  params[] )
            throws DocumentException,
                   IOException
Outputs to the writer the font dictionaries and streams.
Overrides:
writeFont in interface BaseFont
Parameters:
writer - the writer for this document
ref - the font indirect reference
Throws:
DocumentException - error in generating the object