/** * 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); }
/** * Compares this <CODE>Font</CODE> with another * * @param object the other <CODE>Font</CODE> * @return a value */ 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.family()) { return 1; } if (this.size != font.size()) { return 2; } if (this.style != font.style()) { 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.color())) { return 0; } return 4; } catch (ClassCastException cce) { return -3; } }