Constructor: |
public Font() {
this(UNDEFINED, UNDEFINED, UNDEFINED, null);
}
|
public Font(Font other) {
this.family = other.family;
this.size = other.size;
this.style = other.style;
this.color = other.color;
this.baseFont = other.baseFont;
}
Copy constructor of a Font Parameters:
other -
the font that has to be copied
|
public Font(BaseFont bf) {
this(bf, UNDEFINED, UNDEFINED, null);
}
Parameters:
bf -
the external font
|
public Font(int family) {
this(family, UNDEFINED, UNDEFINED, null);
}
Parameters:
family -
the family to which this font belongs
|
public Font(BaseFont bf,
float size) {
this(bf, size, UNDEFINED, null);
}
Parameters:
bf -
the external font
size -
the size of this font
|
public Font(int family,
float size) {
this(family, size, UNDEFINED, null);
}
Parameters:
family -
the family to which this font belongs
size -
the size of this font
|
public Font(BaseFont bf,
float size,
int style) {
this(bf, size, style, null);
}
Parameters:
bf -
the external font
size -
the size of this font
style -
the style of this font
|
public Font(int family,
float size,
int style) {
this(family, size, style, null);
}
Parameters:
family -
the family to which this font belongs
size -
the size of this font
style -
the style of this font
|
public Font(int family,
float size,
int style,
Color color) {
this.family = family;
this.size = size;
this.style = style;
this.color = color;
}
Parameters:
family -
the family to which this font belongs
size -
the size of this font
style -
the style of this font
color -
the Color of this font.
|
public Font(BaseFont bf,
float size,
int style,
Color color) {
this.baseFont = bf;
this.size = size;
this.style = style;
this.color = color;
}
Parameters:
bf -
the external font
size -
the size of this font
style -
the style of this font
color -
the Color of this font.
|
Method from com.lowagie.text.Font Detail: |
public int compareTo(Object object) {
if (object == null) {
return -1;
}
Font font;
try {
font = (Font) object;
if (baseFont != null && !baseFont.equals(font.getBaseFont())) {
return -2;
}
if (this.family != font.getFamily()) {
return 1;
}
if (this.size != font.getSize()) {
return 2;
}
if (this.style != font.getStyle()) {
return 3;
}
if (this.color == null) {
if (font.color == null) {
return 0;
}
return 4;
}
if (font.color == null) {
return 4;
}
if (this.color.equals(font.getColor())) {
return 0;
}
return 4;
} catch (ClassCastException cce) {
return -3;
}
}
Compares this Font with another |
public Font difference(Font font) {
if (font == null) return this;
// size
float dSize = font.size;
if (dSize == UNDEFINED) {
dSize = this.size;
}
// style
int dStyle = UNDEFINED;
int style1 = this.style;
int style2 = font.getStyle();
if (style1 != UNDEFINED || style2 != UNDEFINED) {
if (style1 == UNDEFINED)
style1 = 0;
if (style2 == UNDEFINED)
style2 = 0;
dStyle = style1 | style2;
}
// color
Color dColor = font.color;
if (dColor == null) {
dColor = this.color;
}
// family
if (font.baseFont != null) {
return new Font(font.baseFont, dSize, dStyle, dColor);
}
if (font.getFamily() != UNDEFINED) {
return new Font(font.family, dSize, dStyle, dColor);
}
if (this.baseFont != null) {
if (dStyle == style1) {
return new Font(this.baseFont, dSize, dStyle, dColor);
} else {
return FontFactory.getFont(this.getFamilyname(), dSize, dStyle,
dColor);
}
}
return new Font(this.family, dSize, dStyle, dColor);
}
Replaces the attributes that are equal to null with the
attributes of a given font. |
public BaseFont getBaseFont() {
return baseFont;
}
Gets the BaseFont inside this object. |
public BaseFont getCalculatedBaseFont(boolean specialEncoding) {
if (baseFont != null)
return baseFont;
int style = this.style;
if (style == UNDEFINED) {
style = NORMAL;
}
String fontName = BaseFont.HELVETICA;
String encoding = BaseFont.WINANSI;
BaseFont cfont = null;
switch (family) {
case COURIER:
switch (style & BOLDITALIC) {
case BOLD:
fontName = BaseFont.COURIER_BOLD;
break;
case ITALIC:
fontName = BaseFont.COURIER_OBLIQUE;
break;
case BOLDITALIC:
fontName = BaseFont.COURIER_BOLDOBLIQUE;
break;
default:
//case NORMAL:
fontName = BaseFont.COURIER;
break;
}
break;
case TIMES_ROMAN:
switch (style & BOLDITALIC) {
case BOLD:
fontName = BaseFont.TIMES_BOLD;
break;
case ITALIC:
fontName = BaseFont.TIMES_ITALIC;
break;
case BOLDITALIC:
fontName = BaseFont.TIMES_BOLDITALIC;
break;
default:
case NORMAL:
fontName = BaseFont.TIMES_ROMAN;
break;
}
break;
case SYMBOL:
fontName = BaseFont.SYMBOL;
if (specialEncoding)
encoding = BaseFont.SYMBOL;
break;
case ZAPFDINGBATS:
fontName = BaseFont.ZAPFDINGBATS;
if (specialEncoding)
encoding = BaseFont.ZAPFDINGBATS;
break;
default:
case Font.HELVETICA:
switch (style & BOLDITALIC) {
case BOLD:
fontName = BaseFont.HELVETICA_BOLD;
break;
case ITALIC:
fontName = BaseFont.HELVETICA_OBLIQUE;
break;
case BOLDITALIC:
fontName = BaseFont.HELVETICA_BOLDOBLIQUE;
break;
default:
case NORMAL:
fontName = BaseFont.HELVETICA;
break;
}
break;
}
try {
cfont = BaseFont.createFont(fontName, encoding, false);
} catch (Exception ee) {
throw new ExceptionConverter(ee);
}
return cfont;
}
Gets the BaseFont this class represents. For the built-in
fonts a BaseFont is calculated. |
public float getCalculatedLeading(float linespacing) {
return linespacing * getCalculatedSize();
}
Gets the leading that can be used with this font. |
public float getCalculatedSize() {
float s = this.size;
if (s == UNDEFINED) {
s = DEFAULTSIZE;
}
return s;
}
Gets the size that can be used with the calculated BaseFont
. |
public int getCalculatedStyle() {
int style = this.style;
if (style == UNDEFINED) {
style = NORMAL;
}
if (baseFont != null)
return style;
if (family == SYMBOL || family == ZAPFDINGBATS)
return style;
else
return style & (~BOLDITALIC);
}
Gets the style that can be used with the calculated BaseFont
. |
public Color getColor() {
return color;
}
Gets the color of this font. |
public int getFamily() {
return family;
}
Gets the family of this font. |
public static int getFamilyIndex(String family) {
if (family.equalsIgnoreCase(FontFactory.COURIER)) {
return COURIER;
}
if (family.equalsIgnoreCase(FontFactory.HELVETICA)) {
return HELVETICA;
}
if (family.equalsIgnoreCase(FontFactory.TIMES_ROMAN)) {
return TIMES_ROMAN;
}
if (family.equalsIgnoreCase(FontFactory.SYMBOL)) {
return SYMBOL;
}
if (family.equalsIgnoreCase(FontFactory.ZAPFDINGBATS)) {
return ZAPFDINGBATS;
}
return UNDEFINED;
}
Translates a String -value of a certain family into the
index that is used for this family in this class. |
public String getFamilyname() {
String tmp = "unknown";
switch (getFamily()) {
case Font.COURIER:
return FontFactory.COURIER;
case Font.HELVETICA:
return FontFactory.HELVETICA;
case Font.TIMES_ROMAN:
return FontFactory.TIMES_ROMAN;
case Font.SYMBOL:
return FontFactory.SYMBOL;
case Font.ZAPFDINGBATS:
return FontFactory.ZAPFDINGBATS;
default:
if (baseFont != null) {
String[][] names = baseFont.getFamilyFontName();
for (int i = 0; i < names.length; i++) {
if ("0".equals(names[i][2])) {
return names[i][3];
}
if ("1033".equals(names[i][2])) {
tmp = names[i][3];
}
if ("".equals(names[i][2])) {
tmp = names[i][3];
}
}
}
}
return tmp;
}
Gets the familyname as a String. |
public float getSize() {
return size;
}
Gets the size of this font. |
public int getStyle() {
return style;
}
Gets the style of this font. |
public static int getStyleValue(String style) {
int s = 0;
if (style.indexOf(Markup.CSS_VALUE_NORMAL) != -1) {
s |= NORMAL;
}
if (style.indexOf(Markup.CSS_VALUE_BOLD) != -1) {
s |= BOLD;
}
if (style.indexOf(Markup.CSS_VALUE_ITALIC) != -1) {
s |= ITALIC;
}
if (style.indexOf(Markup.CSS_VALUE_OBLIQUE) != -1) {
s |= ITALIC;
}
if (style.indexOf(Markup.CSS_VALUE_UNDERLINE) != -1) {
s |= UNDERLINE;
}
if (style.indexOf(Markup.CSS_VALUE_LINETHROUGH) != -1) {
s |= STRIKETHRU;
}
return s;
}
Translates a String -value of a certain style into the
index value is used for this style in this class. |
public boolean isBold() {
if (style == UNDEFINED) {
return false;
}
return (style & BOLD) == BOLD;
}
checks if this font is Bold. |
public boolean isItalic() {
if (style == UNDEFINED) {
return false;
}
return (style & ITALIC) == ITALIC;
}
checks if this font is Bold. |
public boolean isStandardFont() {
return (family == UNDEFINED && size == UNDEFINED && style == UNDEFINED
&& color == null && baseFont == null);
}
Checks if the properties of this font are undefined or null.
If so, the standard should be used. |
public boolean isStrikethru() {
if (style == UNDEFINED) {
return false;
}
return (style & STRIKETHRU) == STRIKETHRU;
}
checks if the style of this font is STRIKETHRU. |
public boolean isUnderlined() {
if (style == UNDEFINED) {
return false;
}
return (style & UNDERLINE) == UNDERLINE;
}
checks if this font is underlined. |
public void setColor(Color color) {
this.color = color;
}
|
public void setColor(int red,
int green,
int blue) {
this.color = new Color(red, green, blue);
}
|
public void setFamily(String family) {
this.family = getFamilyIndex(family);
}
Sets the family using a String ("Courier", "Helvetica",
"Times New Roman", "Symbol" or "ZapfDingbats"). |
public void setSize(float size) {
this.size = size;
}
|
public void setStyle(int style) {
this.style = style;
}
|
public void setStyle(String style) {
if (this.style == UNDEFINED)
this.style = NORMAL;
this.style |= getStyleValue(style);
}
Sets the style using a String containing one of more of
the following values: normal, bold, italic, underline, strike. |