Method from com.lowagie.text.pdf.BaseFont Detail: |
public void addSubsetRange(int[] range) {
if (subsetRanges == null)
subsetRanges = new ArrayList();
subsetRanges.add(range);
}
Adds a character range when subsetting. The range is an int array
where the first element is the start range inclusive and the second element is the
end range inclusive. Several ranges are allowed in the same array. |
public boolean charExists(int c) {
byte b[] = convertToBytes(c);
return b.length > 0;
}
Checks if a character exists in this font. |
byte[] convertToBytes(String text) {
if (directTextToByte)
return PdfEncodings.convertToBytes(text, null);
if (specialMap != null) {
byte[] b = new byte[text.length()];
int ptr = 0;
int length = text.length();
for (int k = 0; k < length; ++k) {
char c = text.charAt(k);
if (specialMap.containsKey(c))
b[ptr++] = (byte)specialMap.get(c);
}
if (ptr < length) {
byte[] b2 = new byte[ptr];
System.arraycopy(b, 0, b2, 0, ptr);
return b2;
}
else
return b;
}
return PdfEncodings.convertToBytes(text, encoding);
}
Converts a String to a byte array according
to the font's encoding. |
byte[] convertToBytes(int char1) {
if (directTextToByte)
return PdfEncodings.convertToBytes((char)char1, null);
if (specialMap != null) {
if (specialMap.containsKey(char1))
return new byte[]{(byte)specialMap.get(char1)};
else
return new byte[0];
}
return PdfEncodings.convertToBytes((char)char1, encoding);
}
Converts a char to a byte array according
to the font's encoding. |
public void correctArabicAdvance() {
for (char c = '\u064b'; c < = '\u0658'; ++c)
setCharAdvance(c, 0);
setCharAdvance('\u0670', 0);
for (char c = '\u06d6'; c < = '\u06dc'; ++c)
setCharAdvance(c, 0);
for (char c = '\u06df'; c < = '\u06e4'; ++c)
setCharAdvance(c, 0);
for (char c = '\u06e7'; c < = '\u06e8'; ++c)
setCharAdvance(c, 0);
for (char c = '\u06ea'; c < = '\u06ed'; ++c)
setCharAdvance(c, 0);
}
iText expects Arabic Diactrics (tashkeel) to have zero advance but some fonts,
most notably those that come with Windows, like times.ttf, have non-zero
advance for those characters. This method makes those character to have zero
width advance and work correctly in the iText Arabic shaping and reordering
context. |
protected void createEncoding() {
if (encoding.startsWith("#")) {
specialMap = new IntHashtable();
StringTokenizer tok = new StringTokenizer(encoding.substring(1), " ,\t\n\r\f");
if (tok.nextToken().equals("full")) {
while (tok.hasMoreTokens()) {
String order = tok.nextToken();
String name = tok.nextToken();
char uni = (char)Integer.parseInt(tok.nextToken(), 16);
int orderK;
if (order.startsWith("'"))
orderK = order.charAt(1);
else
orderK = Integer.parseInt(order);
orderK %= 256;
specialMap.put(uni, orderK);
differences[orderK] = name;
unicodeDifferences[orderK] = uni;
widths[orderK] = getRawWidth(uni, name);
charBBoxes[orderK] = getRawCharBBox(uni, name);
}
}
else {
int k = 0;
if (tok.hasMoreTokens())
k = Integer.parseInt(tok.nextToken());
while (tok.hasMoreTokens() && k < 256) {
String hex = tok.nextToken();
int uni = Integer.parseInt(hex, 16) % 0x10000;
String name = GlyphList.unicodeToName(uni);
if (name != null) {
specialMap.put(uni, k);
differences[k] = name;
unicodeDifferences[k] = (char)uni;
widths[k] = getRawWidth(uni, name);
charBBoxes[k] = getRawCharBBox(uni, name);
++k;
}
}
}
for (int k = 0; k < 256; ++k) {
if (differences[k] == null) {
differences[k] = notdef;
}
}
}
else if (fontSpecific) {
for (int k = 0; k < 256; ++k) {
widths[k] = getRawWidth(k, null);
charBBoxes[k] = getRawCharBBox(k, null);
}
}
else {
String s;
String name;
char c;
byte b[] = new byte[1];
for (int k = 0; k < 256; ++k) {
b[0] = (byte)k;
s = PdfEncodings.convertToString(b, encoding);
if (s.length() > 0) {
c = s.charAt(0);
}
else {
c = '?';
}
name = GlyphList.unicodeToName(c);
if (name == null)
name = notdef;
differences[k] = name;
unicodeDifferences[k] = c;
widths[k] = getRawWidth(c, name);
charBBoxes[k] = getRawCharBBox(c, name);
}
}
}
Creates the widths and the differences arrays |
public static BaseFont createFont() throws DocumentException, IOException {
return createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
}
Creates a new font. This will always be the default Helvetica font (not embedded).
This method is introduced because Helvetica is used in many examples. |
public static BaseFont createFont(PRIndirectReference fontRef) {
return new DocumentFont(fontRef);
}
Creates a font based on an existing document font. The created font font may not
behave as expected, depending on the encoding or subset. |
public static BaseFont createFont(String name,
String encoding,
boolean embedded) throws DocumentException, IOException {
return createFont(name, encoding, embedded, true, null, null, false);
}
Creates a new font. This font can be one of the 14 built in types,
a Type1 font referred to by an AFM or PFM file, a TrueType font (simple or collection) or a CJK font from the
Adobe Asian Font Pack. TrueType fonts and CJK fonts can have an optional style modifier
appended to the name. These modifiers are: Bold, Italic and BoldItalic. An
example would be "STSong-Light,Bold". Note that this modifiers do not work if
the font is embedded. Fonts in TrueType collections are addressed by index such as "msgothic.ttc,1".
This would get the second font (indexes start at 0), in this case "MS PGothic".
The fonts are cached and if they already exist they are extracted from the cache,
not parsed again.
Besides the common encodings described by name, custom encodings
can also be made. These encodings will only work for the single byte fonts
Type1 and TrueType. The encoding string starts with a '#'
followed by "simple" or "full". If "simple" there is a decimal for the first character position and then a list
of hex values representing the Unicode codes that compose that encoding.
The "simple" encoding is recommended for TrueType fonts
as the "full" encoding risks not matching the character with the right glyph
if not done with care.
The "full" encoding is specially aimed at Type1 fonts where the glyphs have to be
described by non standard names like the Tex math fonts. Each group of three elements
compose a code position: the one byte code order in decimal or as 'x' (x cannot be the space), the name and the Unicode character
used to access the glyph. The space must be assigned to character position 32 otherwise
text justification will not work.
Example for a "simple" encoding that includes the Unicode
character space, A, B and ecyrillic:
"# simple 32 0020 0041 0042 0454"
Example for a "full" encoding for a Type1 Tex font:
"# full 'A' nottriangeqlleft 0041 'B' dividemultiply 0042 32 space 0020"
This method calls:
createFont(name, encoding, embedded, true, null, null);
|
public static BaseFont createFont(String name,
String encoding,
boolean embedded,
boolean forceRead) throws DocumentException, IOException {
return createFont(name, encoding, embedded, true, null, null, forceRead);
}
Creates a new font. This font can be one of the 14 built in types,
a Type1 font referred to by an AFM or PFM file, a TrueType font (simple or collection) or a CJK font from the
Adobe Asian Font Pack. TrueType fonts and CJK fonts can have an optional style modifier
appended to the name. These modifiers are: Bold, Italic and BoldItalic. An
example would be "STSong-Light,Bold". Note that this modifiers do not work if
the font is embedded. Fonts in TrueType collections are addressed by index such as "msgothic.ttc,1".
This would get the second font (indexes start at 0), in this case "MS PGothic".
The fonts are cached and if they already exist they are extracted from the cache,
not parsed again.
Besides the common encodings described by name, custom encodings
can also be made. These encodings will only work for the single byte fonts
Type1 and TrueType. The encoding string starts with a '#'
followed by "simple" or "full". If "simple" there is a decimal for the first character position and then a list
of hex values representing the Unicode codes that compose that encoding.
The "simple" encoding is recommended for TrueType fonts
as the "full" encoding risks not matching the character with the right glyph
if not done with care.
The "full" encoding is specially aimed at Type1 fonts where the glyphs have to be
described by non standard names like the Tex math fonts. Each group of three elements
compose a code position: the one byte code order in decimal or as 'x' (x cannot be the space), the name and the Unicode character
used to access the glyph. The space must be assigned to character position 32 otherwise
text justification will not work.
Example for a "simple" encoding that includes the Unicode
character space, A, B and ecyrillic:
"# simple 32 0020 0041 0042 0454"
Example for a "full" encoding for a Type1 Tex font:
"# full 'A' nottriangeqlleft 0041 'B' dividemultiply 0042 32 space 0020"
This method calls:
createFont(name, encoding, embedded, true, null, null);
|
public static BaseFont createFont(String name,
String encoding,
boolean embedded,
boolean cached,
byte[] ttfAfm,
byte[] pfb) throws DocumentException, IOException {
return createFont(name, encoding, embedded, cached, ttfAfm, pfb, false);
}
Creates a new font. This font can be one of the 14 built in types,
a Type1 font referred to by an AFM or PFM file, a TrueType font (simple or collection) or a CJK font from the
Adobe Asian Font Pack. TrueType fonts and CJK fonts can have an optional style modifier
appended to the name. These modifiers are: Bold, Italic and BoldItalic. An
example would be "STSong-Light,Bold". Note that this modifiers do not work if
the font is embedded. Fonts in TrueType collections are addressed by index such as "msgothic.ttc,1".
This would get the second font (indexes start at 0), in this case "MS PGothic".
The fonts may or may not be cached depending on the flag cached .
If the byte arrays are present the font will be
read from them instead of the name. A name is still required to identify
the font type.
Besides the common encodings described by name, custom encodings
can also be made. These encodings will only work for the single byte fonts
Type1 and TrueType. The encoding string starts with a '#'
followed by "simple" or "full". If "simple" there is a decimal for the first character position and then a list
of hex values representing the Unicode codes that compose that encoding.
The "simple" encoding is recommended for TrueType fonts
as the "full" encoding risks not matching the character with the right glyph
if not done with care.
The "full" encoding is specially aimed at Type1 fonts where the glyphs have to be
described by non standard names like the Tex math fonts. Each group of three elements
compose a code position: the one byte code order in decimal or as 'x' (x cannot be the space), the name and the Unicode character
used to access the glyph. The space must be assigned to character position 32 otherwise
text justification will not work.
Example for a "simple" encoding that includes the Unicode
character space, A, B and ecyrillic:
"# simple 32 0020 0041 0042 0454"
Example for a "full" encoding for a Type1 Tex font:
"# full 'A' nottriangeqlleft 0041 'B' dividemultiply 0042 32 space 0020"
|
public static BaseFont createFont(String name,
String encoding,
boolean embedded,
boolean cached,
byte[] ttfAfm,
byte[] pfb,
boolean noThrow) throws DocumentException, IOException {
return createFont(name, encoding, embedded, cached, ttfAfm, pfb, false, false);
}
Creates a new font. This font can be one of the 14 built in types,
a Type1 font referred to by an AFM or PFM file, a TrueType font (simple or collection) or a CJK font from the
Adobe Asian Font Pack. TrueType fonts and CJK fonts can have an optional style modifier
appended to the name. These modifiers are: Bold, Italic and BoldItalic. An
example would be "STSong-Light,Bold". Note that this modifiers do not work if
the font is embedded. Fonts in TrueType collections are addressed by index such as "msgothic.ttc,1".
This would get the second font (indexes start at 0), in this case "MS PGothic".
The fonts may or may not be cached depending on the flag cached .
If the byte arrays are present the font will be
read from them instead of the name. A name is still required to identify
the font type.
Besides the common encodings described by name, custom encodings
can also be made. These encodings will only work for the single byte fonts
Type1 and TrueType. The encoding string starts with a '#'
followed by "simple" or "full". If "simple" there is a decimal for the first character position and then a list
of hex values representing the Unicode codes that compose that encoding.
The "simple" encoding is recommended for TrueType fonts
as the "full" encoding risks not matching the character with the right glyph
if not done with care.
The "full" encoding is specially aimed at Type1 fonts where the glyphs have to be
described by non standard names like the Tex math fonts. Each group of three elements
compose a code position: the one byte code order in decimal or as 'x' (x cannot be the space), the name and the Unicode character
used to access the glyph. The space must be assigned to character position 32 otherwise
text justification will not work.
Example for a "simple" encoding that includes the Unicode
character space, A, B and ecyrillic:
"# simple 32 0020 0041 0042 0454"
Example for a "full" encoding for a Type1 Tex font:
"# full 'A' nottriangeqlleft 0041 'B' dividemultiply 0042 32 space 0020"
|
public static BaseFont createFont(String name,
String encoding,
boolean embedded,
boolean cached,
byte[] ttfAfm,
byte[] pfb,
boolean noThrow,
boolean forceRead) throws DocumentException, IOException {
String nameBase = getBaseName(name);
encoding = normalizeEncoding(encoding);
boolean isBuiltinFonts14 = BuiltinFonts14.containsKey(name);
boolean isCJKFont = isBuiltinFonts14 ? false : CJKFont.isCJKFont(nameBase, encoding);
if (isBuiltinFonts14 || isCJKFont)
embedded = false;
else if (encoding.equals(IDENTITY_H) || encoding.equals(IDENTITY_V))
embedded = true;
BaseFont fontFound = null;
BaseFont fontBuilt = null;
String key = name + "\n" + encoding + "\n" + embedded;
if (cached) {
synchronized (fontCache) {
fontFound = (BaseFont)fontCache.get(key);
}
if (fontFound != null)
return fontFound;
}
if (isBuiltinFonts14 || name.toLowerCase().endsWith(".afm") || name.toLowerCase().endsWith(".pfm")) {
fontBuilt = new Type1Font(name, encoding, embedded, ttfAfm, pfb, forceRead);
fontBuilt.fastWinansi = encoding.equals(CP1252);
}
else if (nameBase.toLowerCase().endsWith(".ttf") || nameBase.toLowerCase().endsWith(".otf") || nameBase.toLowerCase().indexOf(".ttc,") > 0) {
if (encoding.equals(IDENTITY_H) || encoding.equals(IDENTITY_V))
fontBuilt = new TrueTypeFontUnicode(name, encoding, embedded, ttfAfm, forceRead);
else {
fontBuilt = new TrueTypeFont(name, encoding, embedded, ttfAfm, false, forceRead);
fontBuilt.fastWinansi = encoding.equals(CP1252);
}
}
else if (isCJKFont)
fontBuilt = new CJKFont(name, encoding, embedded);
else if (noThrow)
return null;
else
throw new DocumentException("Font '" + name + "' with '" + encoding + "' is not recognized.");
if (cached) {
synchronized (fontCache) {
fontFound = (BaseFont)fontCache.get(key);
if (fontFound != null)
return fontFound;
fontCache.put(key, fontBuilt);
}
}
return fontBuilt;
}
Creates a new font. This font can be one of the 14 built in types,
a Type1 font referred to by an AFM or PFM file, a TrueType font (simple or collection) or a CJK font from the
Adobe Asian Font Pack. TrueType fonts and CJK fonts can have an optional style modifier
appended to the name. These modifiers are: Bold, Italic and BoldItalic. An
example would be "STSong-Light,Bold". Note that this modifiers do not work if
the font is embedded. Fonts in TrueType collections are addressed by index such as "msgothic.ttc,1".
This would get the second font (indexes start at 0), in this case "MS PGothic".
The fonts may or may not be cached depending on the flag cached .
If the byte arrays are present the font will be
read from them instead of the name. A name is still required to identify
the font type.
Besides the common encodings described by name, custom encodings
can also be made. These encodings will only work for the single byte fonts
Type1 and TrueType. The encoding string starts with a '#'
followed by "simple" or "full". If "simple" there is a decimal for the first character position and then a list
of hex values representing the Unicode codes that compose that encoding.
The "simple" encoding is recommended for TrueType fonts
as the "full" encoding risks not matching the character with the right glyph
if not done with care.
The "full" encoding is specially aimed at Type1 fonts where the glyphs have to be
described by non standard names like the Tex math fonts. Each group of three elements
compose a code position: the one byte code order in decimal or as 'x' (x cannot be the space), the name and the Unicode character
used to access the glyph. The space must be assigned to character position 32 otherwise
text justification will not work.
Example for a "simple" encoding that includes the Unicode
character space, A, B and ecyrillic:
"# simple 32 0020 0041 0042 0454"
Example for a "full" encoding for a Type1 Tex font:
"# full 'A' nottriangeqlleft 0041 'B' dividemultiply 0042 32 space 0020"
|
public static String createSubsetPrefix() {
String s = "";
for (int k = 0; k < 6; ++k)
s += (char)(Math.random() * 26 + 'A');
return s + "+";
}
Creates a unique subset prefix to be added to the font name when the font is embedded and subset. |
public static String[] enumerateTTCNames(String ttcFile) throws DocumentException, IOException {
return new EnumerateTTC(ttcFile).getNames();
}
Enumerates the postscript font names present inside a
True Type Collection. |
public static String[] enumerateTTCNames(byte[] ttcArray) throws DocumentException, IOException {
return new EnumerateTTC(ttcArray).getNames();
}
Enumerates the postscript font names present inside a
True Type Collection. |
public static Object[] getAllFontNames(String name,
String encoding,
byte[] ttfAfm) throws DocumentException, IOException {
String nameBase = getBaseName(name);
BaseFont fontBuilt = null;
if (nameBase.toLowerCase().endsWith(".ttf") || nameBase.toLowerCase().endsWith(".otf") || nameBase.toLowerCase().indexOf(".ttc,") > 0)
fontBuilt = new TrueTypeFont(name, CP1252, false, ttfAfm, true, false);
else
fontBuilt = createFont(name, encoding, false, false, ttfAfm, null);
return new Object[]{fontBuilt.getPostscriptFontName(), fontBuilt.getFamilyFontName(), fontBuilt.getFullFontName()};
}
Gets all the names from the font. Only the required tables are read. |
abstract public 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}. |
public static String[][] getAllNameEntries(String name,
String encoding,
byte[] ttfAfm) throws DocumentException, IOException {
String nameBase = getBaseName(name);
BaseFont fontBuilt = null;
if (nameBase.toLowerCase().endsWith(".ttf") || nameBase.toLowerCase().endsWith(".otf") || nameBase.toLowerCase().indexOf(".ttc,") > 0)
fontBuilt = new TrueTypeFont(name, CP1252, false, ttfAfm, true, false);
else
fontBuilt = createFont(name, encoding, false, false, ttfAfm, null);
return fontBuilt.getAllNameEntries();
}
Gets all the entries of the namestable from the font. Only the required tables are read. |
public int getAscent(String text) {
int max = 0;
char chars[] = text.toCharArray();
for (int k = 0; k < chars.length; ++k) {
int bbox[] = getCharBBox(chars[k]);
if (bbox != null && bbox[3] > max)
max = bbox[3];
}
return max;
}
Gets the ascent of a String in normalized 1000 units. The ascent will always be
greater than or equal to zero even if all the characters have a lower ascent. |
public float getAscentPoint(String text,
float fontSize) {
return getAscent(text) * 0.001f * fontSize;
}
Gets the ascent of a String in points. The ascent will always be
greater than or equal to zero even if all the characters have a lower ascent. |
protected static String getBaseName(String name) {
if (name.endsWith(",Bold"))
return name.substring(0, name.length() - 5);
else if (name.endsWith(",Italic"))
return name.substring(0, name.length() - 7);
else if (name.endsWith(",BoldItalic"))
return name.substring(0, name.length() - 11);
else
return name;
}
Gets the name without the modifiers Bold, Italic or BoldItalic. |
public int[] getCharBBox(int c) {
byte b[] = convertToBytes(c);
if (b.length == 0)
return null;
else
return charBBoxes[b[0] & 0xff];
}
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]. |
public int getCidCode(int c) {
return c;
}
Gets the CID code given an Unicode.
It has only meaning with CJK fonts. |
public String[] getCodePagesSupported() {
return new String[0];
}
Gets the code pages supported by the font. This has only meaning
with True Type fonts. |
public int getCompressionLevel() {
return compressionLevel;
}
Returns the compression level used for the font streams. |
public int getDescent(String text) {
int min = 0;
char chars[] = text.toCharArray();
for (int k = 0; k < chars.length; ++k) {
int bbox[] = getCharBBox(chars[k]);
if (bbox != null && bbox[1] < min)
min = bbox[1];
}
return min;
}
Gets the descent of a String in normalized 1000 units. The descent will always be
less than or equal to zero even if all the characters have an higher descent. |
public float getDescentPoint(String text,
float fontSize) {
return getDescent(text) * 0.001f * fontSize;
}
Gets the descent of a String in points. The descent will always be
less than or equal to zero even if all the characters have an higher descent. |
public String[] getDifferences() {
return differences;
}
Gets the array with the names of the characters. |
public static ArrayList getDocumentFonts(PdfReader reader) {
IntHashtable hits = new IntHashtable();
ArrayList fonts = new ArrayList();
int npages = reader.getNumberOfPages();
for (int k = 1; k < = npages; ++k)
recourseFonts(reader.getPageN(k), hits, fonts, 1);
return fonts;
}
Gets a list of all document fonts. Each element of the ArrayList
contains a Object[]{String,PRIndirectReference} with the font name
and the indirect reference to it. |
public static ArrayList getDocumentFonts(PdfReader reader,
int page) {
IntHashtable hits = new IntHashtable();
ArrayList fonts = new ArrayList();
recourseFonts(reader.getPageN(page), hits, fonts, 1);
return fonts;
}
Gets a list of the document fonts in a particular page. Each element of the ArrayList
contains a Object[]{String,PRIndirectReference} with the font name
and the indirect reference to it. |
public String getEncoding() {
return encoding;
}
Gets the encoding used to convert String into byte[] . |
abstract 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}. |
abstract public float getFontDescriptor(int key,
float fontSize)
Gets the font parameter identified by key . Valid values
for key are ASCENT , AWT_ASCENT , CAPHEIGHT ,
DESCENT , AWT_DESCENT ,
ITALICANGLE , BBOXLLX , BBOXLLY , BBOXURX
and BBOXURY . |
public int getFontType() {
return fontType;
}
Gets the font type. The font types can be: FONT_TYPE_T1,
FONT_TYPE_TT, FONT_TYPE_CJK and FONT_TYPE_TTUNI. |
abstract 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}. |
public static String[][] getFullFontName(String name,
String encoding,
byte[] ttfAfm) throws DocumentException, IOException {
String nameBase = getBaseName(name);
BaseFont fontBuilt = null;
if (nameBase.toLowerCase().endsWith(".ttf") || nameBase.toLowerCase().endsWith(".otf") || nameBase.toLowerCase().indexOf(".ttc,") > 0)
fontBuilt = new TrueTypeFont(name, CP1252, false, ttfAfm, true, false);
else
fontBuilt = createFont(name, encoding, false, false, ttfAfm, null);
return fontBuilt.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}. |
abstract PdfStream getFullFontStream() throws IOException, DocumentException
Returns a PdfStream object with the full font program (if possible).
This method will return null for some types of fonts (CJKFont, Type3Font)
or if there is no font program available (standard Type 1 fonts). |
abstract public int getKerning(int char1,
int char2)
Gets the kerning between two Unicode chars. |
abstract public String getPostscriptFontName()
Gets the postscript font name. |
abstract protected int[] getRawCharBBox(int c,
String name)
|
abstract 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. |
public static InputStream getResourceStream(String key) {
return getResourceStream(key, null);
}
|
public static InputStream getResourceStream(String key,
ClassLoader loader) {
if (key.startsWith("/"))
key = key.substring(1);
InputStream is = null;
if (loader != null) {
is = loader.getResourceAsStream(key);
if (is != null)
return is;
}
// Try to use Context Class Loader to load the properties file.
try {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
if (contextClassLoader != null) {
is = contextClassLoader.getResourceAsStream(key);
}
} catch (Throwable e) {}
if (is == null) {
is = BaseFont.class.getResourceAsStream("/" + key);
}
if (is == null) {
is = ClassLoader.getSystemResourceAsStream(key);
}
return is;
}
|
public char[] getUnicodeDifferences() {
return unicodeDifferences;
}
Gets the array with the unicode characters. |
char getUnicodeDifferences(int index) {
return unicodeDifferences[index];
}
Gets the Unicode character corresponding to the byte output to the pdf stream. |
public int getUnicodeEquivalent(int c) {
return 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. |
public int getWidth(int char1) {
if (fastWinansi) {
if (char1 < 128 || (char1 >= 160 && char1 < = 255))
return widths[char1];
else
return widths[PdfEncodings.winansi.get(char1)];
}
else {
int total = 0;
byte mbytes[] = convertToBytes((char)char1);
for (int k = 0; k < mbytes.length; ++k)
total += widths[0xff & mbytes[k]];
return total;
}
}
Gets the width of a char in normalized 1000 units. |
public int getWidth(String text) {
int total = 0;
if (fastWinansi) {
int len = text.length();
for (int k = 0; k < len; ++k) {
char char1 = text.charAt(k);
if (char1 < 128 || (char1 >= 160 && char1 < = 255))
total += widths[char1];
else
total += widths[PdfEncodings.winansi.get(char1)];
}
return total;
}
else {
byte mbytes[] = convertToBytes(text);
for (int k = 0; k < mbytes.length; ++k)
total += widths[0xff & mbytes[k]];
}
return total;
}
Gets the width of a String in normalized 1000 units. |
public float getWidthPoint(String text,
float fontSize) {
return getWidth(text) * 0.001f * fontSize;
}
Gets the width of a String in points. |
public float getWidthPoint(int char1,
float fontSize) {
return getWidth(char1) * 0.001f * fontSize;
}
Gets the width of a char in points. |
public float getWidthPointKerned(String text,
float fontSize) {
float size = getWidth(text) * 0.001f * fontSize;
if (!hasKernPairs())
return size;
int len = text.length() - 1;
int kern = 0;
char c[] = text.toCharArray();
for (int k = 0; k < len; ++k) {
kern += getKerning(c[k], c[k + 1]);
}
return size + kern * 0.001f * fontSize;
}
Gets the width of a String in points taking kerning
into account. |
public int[] getWidths() {
return widths;
}
Gets the font width array. |
abstract public boolean hasKernPairs()
Checks if the font has any kerning pairs. |
public boolean isDirectTextToByte() {
return directTextToByte;
}
Gets the direct conversion of char to byte . |
public boolean isEmbedded() {
return embedded;
}
|
public boolean isFontSpecific() {
return fontSpecific;
}
Gets the symbolic flag of the font. |
public boolean isForceWidthsOutput() {
return forceWidthsOutput;
}
Gets the state of the property. |
public boolean isSubset() {
return subset;
}
Indicates if all the glyphs and widths for that particular
encoding should be included in the document. |
protected static String normalizeEncoding(String enc) {
if (enc.equals("winansi") || enc.equals(""))
return CP1252;
else if (enc.equals("macroman"))
return MACROMAN;
else
return enc;
}
Normalize the encoding names. "winansi" is changed to "Cp1252" and
"macroman" is changed to "MacRoman". |
public boolean setCharAdvance(int c,
int advance) {
byte b[] = convertToBytes(c);
if (b.length == 0)
return false;
widths[0xff & b[0]] = advance;
return true;
}
Sets the character advance. |
public void setCompressionLevel(int compressionLevel) {
if (compressionLevel < PdfStream.NO_COMPRESSION || compressionLevel > PdfStream.BEST_COMPRESSION)
this.compressionLevel = PdfStream.DEFAULT_COMPRESSION;
else
this.compressionLevel = compressionLevel;
}
Sets the compression level to be used for the font streams. |
public void setDirectTextToByte(boolean directTextToByte) {
this.directTextToByte = directTextToByte;
}
Sets the conversion of char directly to byte
by casting. This is a low level feature to put the bytes directly in
the content stream without passing through String.getBytes(). |
public void setForceWidthsOutput(boolean forceWidthsOutput) {
this.forceWidthsOutput = forceWidthsOutput;
}
Set to true to force the generation of the
widths array. |
abstract public boolean setKerning(int char1,
int char2,
int kern)
Sets the kerning between two Unicode chars. |
abstract 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. |
public void setSubset(boolean subset) {
this.subset = subset;
}
Indicates if all the glyphs and widths for that particular
encoding should be included in the document. When set to true
only the glyphs used will be included in the font. When set to false
and #addSubsetRange(int[]) was not called the full font will be included
otherwise just the characters ranges will be included. |
abstract void writeFont(PdfWriter writer,
PdfIndirectReference ref,
Object[] params) throws DocumentException, IOException
Outputs to the writer the font dictionaries and streams. |