In Method: | getFont(String, String, boolean, float, int, BaseColor, boolean) |
Code with Finding: |
class FontFactoryImp {
/**
* Constructs a <CODE>Font</CODE>-object.
*
* @param fontname the name of the font
* @param encoding the encoding of the font
* @param embedded true if the font is to be embedded in the PDF
* @param size the size of this font
* @param style the style of this font
* @param color the <CODE>BaseColor</CODE> of this font.
* @param cached true if the font comes from the cache or is added to
* the cache if new, false if the font is always created new
* @return the Font constructed based on the parameters
*/
public Font getFont(String fontname, final String encoding, final boolean embedded, final float size, int style, final BaseColor color, final boolean cached) {
if (fontname == null) return new Font(FontFamily.UNDEFINED, size, style, color);
String lowercasefontname = fontname.toLowerCase();
ArrayList<String> tmp = fontFamilies.get(lowercasefontname);
if (tmp != null) {
// some bugs were fixed here by Daniel Marczisovszky
int s = style == Font.UNDEFINED ? Font.NORMAL : style;
int fs = Font.NORMAL;
boolean found = false;
for (String string : tmp) {
String f = string;
String lcf = f.toLowerCase();
fs = Font.NORMAL;
if (lcf.toLowerCase().indexOf("bold") != -1) fs |= Font.BOLD;
if (lcf.toLowerCase().indexOf("italic") != -1 || lcf.toLowerCase().indexOf("oblique") != -1) fs |= Font.ITALIC;
if ((s & Font.BOLDITALIC) == fs) {
fontname = f;
found = true;
break;
}
}
if (style != Font.UNDEFINED && found) {
style &= ~fs;
}
}
BaseFont basefont = null;
try {
try {
// the font is a type 1 font or CJK font
basefont = BaseFont.createFont(fontname, encoding, embedded, cached, null, null, true);
}
catch(DocumentException de) {
}
if (basefont == null) {
// the font is a true type font or an unknown font
fontname = trueTypeFonts.get(fontname.toLowerCase());
// the font is not registered as truetype font
if (fontname == null) return new Font(FontFamily.UNDEFINED, size, style, color);
// the font is registered as truetype font
basefont = BaseFont.createFont(fontname, encoding, embedded, cached, null, null);
}
}
catch(DocumentException de) {
// this shouldn't happen
throw new ExceptionConverter(de);
}
catch(IOException ioe) {
// the font is registered as a true type font, but the path was wrong
return new Font(FontFamily.UNDEFINED, size, style, color);
}
catch(NullPointerException npe) {
// null was entered as fontname and/or encoding
return new Font(FontFamily.UNDEFINED, size, style, color);
}
return new Font(basefont, size, style, color);
}
}
|