rtffont.java
来自「有关对pdf操作的代码」· Java 代码 · 共 737 行 · 第 1/2 页
JAVA
737 行
if((fontStyle & STYLE_OUTLINE) == STYLE_OUTLINE) { result.write(FONT_OUTLINE); } if((fontStyle & STYLE_EMBOSSED) == STYLE_EMBOSSED) { result.write(FONT_EMBOSSED); } if((fontStyle & STYLE_ENGRAVED) == STYLE_ENGRAVED) { result.write(FONT_ENGRAVED); } } if(color != null) { color.writeBegin(result); } } /** * Write the font end * * @param result The <code>OutputStream</code> to write to. * @throws IOException On i/o errors. */ public void writeEnd(final OutputStream result) throws IOException{ if(this.fontStyle != UNDEFINED) { if((fontStyle & STYLE_BOLD) == STYLE_BOLD) { result.write(FONT_BOLD); result.write(intToByteArray(0)); } if((fontStyle & STYLE_ITALIC) == STYLE_ITALIC) { result.write(FONT_ITALIC); result.write(intToByteArray(0)); } if((fontStyle & STYLE_UNDERLINE) == STYLE_UNDERLINE) { result.write(FONT_UNDERLINE); result.write(intToByteArray(0)); } if((fontStyle & STYLE_STRIKETHROUGH) == STYLE_STRIKETHROUGH) { result.write(FONT_STRIKETHROUGH); result.write(intToByteArray(0)); } if((fontStyle & STYLE_HIDDEN) == STYLE_HIDDEN) { result.write(FONT_HIDDEN); result.write(intToByteArray(0)); } if((fontStyle & STYLE_DOUBLE_STRIKETHROUGH) == STYLE_DOUBLE_STRIKETHROUGH) { result.write(FONT_DOUBLE_STRIKETHROUGH); result.write(intToByteArray(0)); } if((fontStyle & STYLE_SHADOW) == STYLE_SHADOW) { result.write(FONT_SHADOW); result.write(intToByteArray(0)); } if((fontStyle & STYLE_OUTLINE) == STYLE_OUTLINE) { result.write(FONT_OUTLINE); result.write(intToByteArray(0)); } if((fontStyle & STYLE_EMBOSSED) == STYLE_EMBOSSED) { result.write(FONT_EMBOSSED); result.write(intToByteArray(0)); } if((fontStyle & STYLE_ENGRAVED) == STYLE_ENGRAVED) { result.write(FONT_ENGRAVED); result.write(intToByteArray(0)); } } } /** * unused */ public void writeContent(OutputStream out) throws IOException { } /** * Tests for equality of RtfFonts. RtfFonts are equal if their fontName, * fontSize, fontStyle and fontSuperSubscript are equal * * @param obj The RtfFont to compare with this RtfFont * @return <code>True</code> if the RtfFonts are equal, <code>false</code> otherwise */ public boolean equals(Object obj) { if(!(obj instanceof RtfFont)) { return false; } RtfFont font = (RtfFont) obj; boolean result = true; result = result & this.fontName.equals(font.getFontName()); return result; } /** * Returns the hash code of this RtfFont. The hash code is the hash code of the * string containing the font name + font size + "-" + the font style + "-" + the * font super/supscript value. * * @return The hash code of this RtfFont */ public int hashCode() { return (this.fontName + this.fontSize + "-" + this.fontStyle).hashCode(); } /** * Gets the font name of this RtfFont * * @return The font name */ public String getFontName() { return this.fontName; } /** * Sets the font name of this RtfFont. * * @param fontName The font name to use */ protected void setFontName(String fontName) { this.fontName = fontName; if(document != null) { this.fontNumber = document.getDocumentHeader().getFontNumber(this); } } /** * @see com.lowagie.text.Font#getFamilyname() */ public String getFamilyname() { return this.fontName; } /** * @see com.lowagie.text.Font#setFamily(String) */ public void setFamily(String family){ super.setFamily(family); setToDefaultFamily(family); } /** * Sets the correct font name from the family name. * * @param familyname The family name to set the name to. */ private void setToDefaultFamily(String familyname){ switch (Font.getFamilyIndex(familyname)) { case Font.COURIER: this.fontName = "Courier"; break; case Font.HELVETICA: this.fontName = "Arial"; break; case Font.SYMBOL: this.fontName = "Symbol"; this.charset = 2; break; case Font.TIMES_ROMAN: this.fontName = "Times New Roman"; break; case Font.ZAPFDINGBATS: this.fontName = "Windings"; break; default: this.fontName = familyname; } } /** * Gets the font size of this RtfFont * * @return The font size */ public int getFontSize() { return this.fontSize; } /** * @see com.lowagie.text.Font#setSize(float) */ public void setSize(float size){ super.setSize(size); this.fontSize = (int) getSize(); } /** * Gets the font style of this RtfFont * * @return The font style */ public int getFontStyle() { return this.fontStyle; } /** * @see com.lowagie.text.Font#setStyle(int) */ public void setStyle(int style){ super.setStyle(style); this.fontStyle = getStyle(); } /** * @see com.lowagie.text.Font#setStyle(String) */ public void setStyle(String style) { super.setStyle(style); fontStyle = getStyle(); } /** * Gets the charset used for constructing this RtfFont. * * @return The charset of this RtfFont. */ public int getCharset() { return charset; } /** * Sets the charset used for constructing this RtfFont. * * @param charset The charset to use. */ public void setCharset(int charset) { this.charset = charset; } /** * Gets the font number of this RtfFont * * @return The font number */ public int getFontNumber() { return fontNumber; } /** * Sets the RtfDocument this RtfFont belongs to * * @param doc The RtfDocument to use */ public void setRtfDocument(RtfDocument doc) { this.document = doc; if(document != null) { this.fontNumber = document.getDocumentHeader().getFontNumber(this); } if(this.color != null) { this.color.setRtfDocument(this.document); } } /** * Unused * @param inTable */ public void setInTable(boolean inTable) { } /** * Unused * @param inHeader */ public void setInHeader(boolean inHeader) { } /** * @see com.lowagie.text.Font#setColor(Color) */ public void setColor(Color color) { super.setColor(color); if(color != null) { this.color = new RtfColor(document, color); } else { this.color = null; } } /** * @see com.lowagie.text.Font#setColor(int, int, int) */ public void setColor(int red, int green, int blue) { super.setColor(red,green,blue); this.color = new RtfColor(document, red, green, blue); } /** * Transforms an integer into its String representation and then returns the bytes * of that string. * * @param i The integer to convert * @return A byte array representing the integer */ protected byte[] intToByteArray(int i) { return Integer.toString(i).getBytes(); } /** * Replaces the attributes that are equal to <VAR>null</VAR> with * the attributes of a given font. * * @param font The surrounding font * @return A RtfFont */ public Font difference(Font font) { String dFamilyname = font.getFamilyname(); if(dFamilyname == null || dFamilyname.trim().equals("") || dFamilyname.trim().equalsIgnoreCase("unknown")) { dFamilyname = this.fontName; } float dSize = font.getSize(); if(dSize == Font.UNDEFINED) { dSize = this.getSize(); } int dStyle = Font.UNDEFINED; if(this.getStyle() != Font.UNDEFINED && font.getStyle() != Font.UNDEFINED) { dStyle = this.getStyle() | font.getStyle(); } else if(this.getStyle() != Font.UNDEFINED) { dStyle = this.getStyle(); } else if(font.getStyle() != Font.UNDEFINED) { dStyle = font.getStyle(); } Color dColor = font.getColor(); if(dColor == null) { dColor = this.getColor(); } int dCharset = this.charset; if(font instanceof RtfFont) { dCharset = ((RtfFont) font).getCharset(); } return new RtfFont(dFamilyname, dSize, dStyle, dColor, dCharset); } /** * The <code>RtfFont</code> is never a standard font. * * @since 2.1.0 */ public boolean isStandardFont() { return false; } /** * Compares this <code>RtfFont</code> to either a {@link com.lowagie.text.Font} or * an <code>RtfFont</code>. * * @since 2.1.0 */ public int compareTo(Object object) { if (object == null) { return -1; } if(object instanceof RtfFont) { if(this.getFontName().compareTo(((RtfFont) object).getFontName()) != 0) { return 1; } else { return super.compareTo(object); } } else if(object instanceof Font) { return super.compareTo(object); } else { return -3; } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?