📄 font.java
字号:
if (family.equalsIgnoreCase(FontFactory.SYMBOL)) { return SYMBOL; } if (family.equalsIgnoreCase(FontFactory.ZAPFDINGBATS)) { return ZAPFDINGBATS; } return UNDEFINED; } // SIZE /** * Gets the size of this font. * * @return a size */ public float getSize() { return size; } /** * Gets the size that can be used with the calculated <CODE>BaseFont * </CODE>. * * @return the size that can be used with the calculated <CODE>BaseFont * </CODE> */ public float getCalculatedSize() { float s = this.size; if (s == UNDEFINED) { s = DEFAULTSIZE; } return s; } /** * Gets the leading that can be used with this font. * * @param linespacing * a certain linespacing * @return the height of a line */ public float getCalculatedLeading(float linespacing) { return linespacing * getCalculatedSize(); } /** * Sets the size. * * @param size * The new size of the font. */ public void setSize(float size) { this.size = size; } // STYLE /** * Gets the style of this font. * * @return a size */ public int getStyle() { return style; } /** * Gets the style that can be used with the calculated <CODE>BaseFont * </CODE>. * * @return the style that can be used with the calculated <CODE>BaseFont * </CODE> */ 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); } /** * checks if this font is Bold. * * @return a <CODE>boolean</CODE> */ public boolean isBold() { if (style == UNDEFINED) { return false; } return (style & BOLD) == BOLD; } /** * checks if this font is Bold. * * @return a <CODE>boolean</CODE> */ public boolean isItalic() { if (style == UNDEFINED) { return false; } return (style & ITALIC) == ITALIC; } /** * checks if this font is underlined. * * @return a <CODE>boolean</CODE> */ public boolean isUnderlined() { if (style == UNDEFINED) { return false; } return (style & UNDERLINE) == UNDERLINE; } /** * checks if the style of this font is STRIKETHRU. * * @return a <CODE>boolean</CODE> */ public boolean isStrikethru() { if (style == UNDEFINED) { return false; } return (style & STRIKETHRU) == STRIKETHRU; } /** * Sets the style. * * @param style * the style. */ public void setStyle(int style) { if (this.style == UNDEFINED) this.style = NORMAL; this.style |= style; } /** * Sets the style using a <CODE>String</CODE> containing one of more of * the following values: normal, bold, italic, underline, strike. * * @param style * A <CODE>String</CODE> representing a certain style. */ public void setStyle(String style) { if (this.style == UNDEFINED) this.style = NORMAL; this.style |= getStyleValue(style); } /** * Translates a <CODE>String</CODE> -value of a certain style into the * index value is used for this style in this class. * * @param style * A <CODE>String</CODE> * @return the corresponding value */ 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; } // COLOR /** * Gets the color of this font. * * @return a color */ public Color getColor() { return color; } /** * Sets the color. * * @param color * the new color of the font */ public void setColor(Color color) { this.color = color; } /** * Sets the color. * * @param red * the red-value of the new color * @param green * the green-value of the new color * @param blue * the blue-value of the new color */ public void setColor(int red, int green, int blue) { this.color = new Color(red, green, blue); } // BASEFONT /** * Gets the <CODE>BaseFont</CODE> inside this object. * * @return the <CODE>BaseFont</CODE> */ public BaseFont getBaseFont() { return baseFont; } /** * Gets the <CODE>BaseFont</CODE> this class represents. For the built-in * fonts a <CODE>BaseFont</CODE> is calculated. * * @param specialEncoding * <CODE>true</CODE> to use the special encoding for Symbol and * ZapfDingbats, <CODE>false</CODE> to always use <CODE>Cp1252 * </CODE> * @return the <CODE>BaseFont</CODE> this class represents */ 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; } // Helper methods /** * Checks if the properties of this font are undefined or null. * <P> * If so, the standard should be used. * * @return a <CODE>boolean</CODE> */ public boolean isStandardFont() { return (family == UNDEFINED && size == UNDEFINED && style == UNDEFINED && color == null && baseFont == null); } /** * Replaces the attributes that are equal to <VAR>null</VAR> with the * attributes of a given font. * * @param font * the font of a bigger element class * @return a <CODE>Font</CODE> */ 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); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -