Example #1
0
  /**
   * 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) {
    String dFamilyname = font.getFamilyname();
    if (dFamilyname == null || dFamilyname.trim().equals("")) {
      dFamilyname = this.familyName;
    }

    float dSize = font.size();
    if (dSize == Font.UNDEFINED) {
      dSize = this.size();
    }

    int dStyle = Font.UNDEFINED;
    if (this.style() != Font.UNDEFINED && font.style() != Font.UNDEFINED) {
      dStyle = this.style() | font.style();
    } else if (this.style() != Font.UNDEFINED) {
      dStyle = this.style();
    } else if (font.style() != Font.UNDEFINED) {
      dStyle = font.style();
    }

    Color dColor = font.color();
    if (dColor == null) {
      dColor = this.color();
    }

    return new RtfFont(dFamilyname, dSize, dStyle, dColor);
  }
Example #2
0
 /**
  * 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);
 }
Example #3
0
 /**
  * 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;
   }
 }