⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 font.java

📁 iText可以制作中文PDF文件的JAVA源程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        }        if (family.equalsIgnoreCase(FontFactory.HELVETICA)) {            return HELVETICA;        }        if (family.equalsIgnoreCase(FontFactory.TIMES_ROMAN) || family.equalsIgnoreCase(FontFactory.TIMES_NEW_ROMAN)) {            return TIMES_NEW_ROMAN;        }        if (family.equalsIgnoreCase(FontFactory.SYMBOL)) {            return SYMBOL;        }        if (family.equalsIgnoreCase(FontFactory.ZAPFDINGBATS)) {            return ZAPFDINGBATS;        }        return UNDEFINED;    }    /** * Gets the familyname as a String. * * @return  the familyname */        public String getFamilyname() {        String tmp = "unknown";        switch(family()) {            case Font.COURIER:                return FontFactory.COURIER;            case Font.HELVETICA:                return FontFactory.HELVETICA;            case Font.TIMES_NEW_ROMAN:                return FontFactory.TIMES_NEW_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;    }    /** * Sets the size. * * @param	size		The new size of the font. */        public void setSize(float size) {        this.size = size;    }    /** * 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(MarkupTags.CSS_NORMAL) != -1) {            s |= NORMAL;        }        if (style.indexOf(MarkupTags.CSS_BOLD) != -1) {            s |= BOLD;        }        if (style.indexOf(MarkupTags.CSS_ITALIC) != -1) {            s |= ITALIC;        }        if (style.indexOf(MarkupTags.CSS_OBLIQUE) != -1) {            s |= ITALIC;        }        if (style.indexOf(MarkupTags.CSS_UNDERLINE) != -1) {            s |= UNDERLINE;        }        if (style.indexOf(MarkupTags.CSS_LINETHROUGH) != -1) {            s |= STRIKETHRU;        }        return s;    }    /** * 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);    }    /** * Gets the leading that can be used with this font. * * @param	linespacing		a certain linespacing * @return	the height of a line */        public float leading(float linespacing) {        if (size == UNDEFINED) {            return linespacing * DEFAULTSIZE;        }        return linespacing * size;    }    /** * 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) {        // size        float dSize = font.size;        if (dSize == UNDEFINED) {            dSize = this.size;        }        // style        int dStyle = UNDEFINED;        int style1 = this.style;        int style2 = font.style();        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.family() != 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);    }        // methods to retrieve the membervariables    /** * Gets the family of this font. * * @return	the value of the family */        public int family() {        return family;    }    /** * Gets the size of this font. * * @return	a size */        public float size() {        return size;    }    /** * Gets the style of this font. * * @return	a size */        public int style() {        return style;    }    /** * 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;    }    /** * Gets the color of this font. * * @return	a color */        public Color color() {        return color;    }     /** Gets the <CODE>BaseFont</CODE> inside this object.  * @return the <CODE>BaseFont</CODE>  */        public BaseFont getBaseFont() {        return baseFont;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -