Class AbstractFont

java.lang.Object
com.day.image.font.AbstractFont
Direct Known Subclasses:
Font

public abstract class AbstractFont extends Object
The AbstractFont class provides base class for font extensions with some static helper methods and access to the FontHelper and the system
invalid reference
Ticket
to access the ContentBus to its extensions.

This class cannot be initialized if the FontHelper and/or the system

invalid reference
Ticket
are not available.
Since:
degu
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The base line alignment constant.
    static final int
    The bottom alignment constant.
    static final int
    The center alignment constant.
    static final int
    The full justification alignment constant.
    static final int
    The vertical alignment flags mask.
    static final int
    The left alignment constant.
    static final int
    The right alignment constant.
    static final int
    The top alignment constant.
    static final int
    The vertical alignment flags mask.
    static final int
    Request bold font style
    static final int
    The draw the character outline constant instructs the font renderer to draw the texts outline and not fill it.
    static final int
    The strikeout style constant.
    static final int
    The underline style constant.
    static final int
    The text drawing style flags.
    static final int
    Request italic font style
    static final int
    Request plain font style (default)
    static final int
    The 180� (clockwise) rotation constant.
    static final int
    The 270� (clockwise) rotation constant.
    static final int
    The 90� (clockwise) rotation constant.
    static final int
    The rotation flags mask.
    static final int
    The odd (?) rotation constant.
    static final int
    The strikeout style constant.
    static final int
    The antialiased font rendering constant.
    static final int
    The TrueType flags mask
    static final int
    The old line spacing constant.
    static final int
    The old fonter scaling constant.
    static final int
    The hinting font rendering constant.
    static final int
    The oversampling font rendering constant.
    static final int
    Deprecated.
    since cq3
    static final int
    The underline style constant.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract boolean
    canDisplay(char c)
    Checks if this Font has a glyph for the specified character.
    abstract int
    canDisplayUpTo(char[] text, int start, int limit)
    Indicates whether or not this Font can display the characters in the specified text starting at start and ending at limit.
    abstract int
    Indicates whether or not this Font can display a specified String.
    abstract int
    canDisplayUpTo(CharacterIterator iter, int start, int limit)
    Indicates whether or not this Font can display the specified String.
    static String
    createFontFileName(String faceName, int size, int style)
    Constructs and returns a font file name from the font face name, size and style indication.
    abstract int
    drawText(Layer layer, int x, int y, int width, int height, String text, Paint paint, Stroke stroke, int align, double cs, int ls)
    Render the given text string in the given font to the Layer using the attributes given.
    abstract double
    Returns the ascent of this Font object, which is the maximal value any glyph of this font ascends above the base line.
    abstract Font
     
    abstract double
    Returns the descent of this Font object, which is the maximal value any glyph of this font descends below the base line.
    abstract double
    Returns the calculated font height in pixels.
    abstract Rectangle2D
    getTextExtent(int x, int y, int width, int height, String text, int align, double cs, int ls)
    Calculate the bounding box of the text, if it would be rendered with the rendering attributes given.
    static int
    Converts the font style code to a string.
    static String
    styleToDescription(int style)
    Converts the numeric font style code to a descriptive string.
    static String
    styleToString(int style)
    Converts the numeric font style code to a string usable for the font name identification.
    abstract String
    Returns a String representation of this object containing the font name, the size and style flags.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • PLAIN

      public static final int PLAIN
      Request plain font style (default)
      See Also:
    • BOLD

      public static final int BOLD
      Request bold font style
      See Also:
    • ITALIC

      public static final int ITALIC
      Request italic font style
      See Also:
    • UNDERLINE

      public static final int UNDERLINE
      The underline style constant. This can be combined with the other style constants (except PLAIN) for mixed styles.

      Underlining in Java2D is a property of drawing text and not a font style. Thus this constant is valid for any font you choose and takes effect when drawing text - and it works.

      See Also:
    • STRIKEOUT

      public static final int STRIKEOUT
      The strikeout style constant. This can be combined with the other style constants (except PLAIN) for mixed styles.

      Striekout in Java2D is a property of drawing text and not a font style. Thus this constant is valid for any font you choose and takes effect when drawing text - and it works.

      See Also:
    • TTFONTERSCALE

      public static final int TTFONTERSCALE
      The old fonter scaling constant. Set this constant to change the scaling of fonts from the old 72dpi to the default 96dpi.
      See Also:
    • TTFONTERLINESPACING

      public static final int TTFONTERLINESPACING
      The old line spacing constant. Set this constant to use the new line spacing values instead of the old line spacing values, which tend to be somewhat bigger, than what is intended in the TrueType standard.
      See Also:
    • ALIGN_VBASE

      public static final int ALIGN_VBASE
      The vertical alignment flags mask.
      See Also:
    • ALIGN_TOP

      public static final int ALIGN_TOP
      The top alignment constant. This can be combined with any one of the horizontal alignment and rotation constants to get mixed alignment/rotation style.
      See Also:
    • ALIGN_BASE

      public static final int ALIGN_BASE
      The base line alignment constant. This can be combined with any one of the horizontal alignment and rotation constants to get mixed alignment/rotation style.
      See Also:
    • ALIGN_BOTTOM

      public static final int ALIGN_BOTTOM
      The bottom alignment constant. This can be combined with any one of the horizontal alignment and rotation constants to get mixed alignment/rotation style.
      See Also:
    • ALIGN_HBASE

      public static final int ALIGN_HBASE
      The vertical alignment flags mask.
      See Also:
    • ALIGN_LEFT

      public static final int ALIGN_LEFT
      The left alignment constant. This can be combined with any one of the vertical alignment and rotation constants to get mixed alignment/rotation style.
      See Also:
    • ALIGN_CENTER

      public static final int ALIGN_CENTER
      The center alignment constant. This can be combined with any one of the vertical alignment and rotation constants to get mixed alignment/rotation style.
      See Also:
    • ALIGN_RIGHT

      public static final int ALIGN_RIGHT
      The right alignment constant. This can be combined with any one of the vertical alignment and rotation constants to get mixed alignment/rotation style.
      See Also:
    • ALIGN_FULL

      public static final int ALIGN_FULL
      The full justification alignment constant. This can be combined with any one of the vertical alignment and rotation constants to get mixed alignment/rotation style.
      See Also:
    • ROTBASE

      public static final int ROTBASE
      The rotation flags mask.
      See Also:
    • ROTODD

      public static final int ROTODD
      The odd (?) rotation constant. This can be combined with any one of the vertical and horizontal alignment constants to get mixed alignment/rotation style.
      See Also:
    • ROT90

      public static final int ROT90
      The 90� (clockwise) rotation constant. This can be combined with any one of the vertical and horizontal alignment constants to get mixed alignment/rotation style.
      See Also:
    • ROT270

      public static final int ROT270
      The 270� (clockwise) rotation constant. This can be combined with any one of the vertical and horizontal alignment constants to get mixed alignment/rotation style.
      See Also:
    • ROT180

      public static final int ROT180
      The 180� (clockwise) rotation constant. This can be combined with any one of the vertical and horizontal alignment constants to get mixed alignment/rotation style.
      See Also:
    • DRAWBASE

      public static final int DRAWBASE
      The text drawing style flags.
      See Also:
    • DRAW_UNDERLINE

      public static final int DRAW_UNDERLINE
      The underline style constant. This can be combined with the other style constants (except PLAIN) for mixed styles.

      Underlining in Java2D is a property of drawing text and not a font style. Thus this constant is valid for any font you choose and takes effect when drawing text - and it works.

      See Also:
    • DRAW_STRIKEOUT

      public static final int DRAW_STRIKEOUT
      The strikeout style constant. This can be combined with the other style constants (except PLAIN) for mixed styles.

      Striekout in Java2D is a property of drawing text and not a font style. Thus this constant is valid for any font you choose and takes effect when drawing text - and it works.

      See Also:
    • DRAW_OUTLINE

      public static final int DRAW_OUTLINE
      The draw the character outline constant instructs the font renderer to draw the texts outline and not fill it. Default is filling the outline. This can be combined with any one of the vertical and horizontal alignment and rotation constants to get mixed alignment/rotation style.
      See Also:
    • TTBASE

      public static final int TTBASE
      The TrueType flags mask
      See Also:
    • TTANTIALIASED

      public static final int TTANTIALIASED
      The antialiased font rendering constant. This can be combined with any one of the vertical and horizontal alignment and rotation constants to get mixed alignment/rotation style.
      See Also:
    • TTHINTED

      public static final int TTHINTED
      The hinting font rendering constant. This can be combined with any one of the vertical and horizontal alignment and rotation constants to get mixed alignment/rotation style.
      See Also:
    • TTOVERSAMPLING

      public static final int TTOVERSAMPLING
      The oversampling font rendering constant. This can be combined with any one of the vertical and horizontal alignment and rotation constants to get mixed alignment/rotation style.

      By popular demand font oversampling has been added again. For this reason this flag is not deprecated any more.

      The factor applied to the text being drawn is set by the

      invalid reference
      #setOversamplingFactor(int)
      method and has a default value of 16.
      See Also:
    • TTUNHINTED

      @Deprecated public static final int TTUNHINTED
      Deprecated.
      since cq3
      The 'do-not-hint' font rendering constant. This can be combined with any one of the vertical and horizontal alignment and rotation constants to get mixed alignment/rotation style.
      See Also:
  • Constructor Details

    • AbstractFont

      public AbstractFont()
  • Method Details

    • createFontFileName

      public static String createFontFileName(String faceName, int size, int style)
      Constructs and returns a font file name from the font face name, size and style indication. The file name consists of the face name converted to lower case and blanks replaced by underscores appending the size and style converted to a string with styleToString(int).

      Example : The font Times New Romain, size 12, style bold/italic has the font file name times_new_roman12bi.

      Parameters:
      faceName - The font face name
      size - The size of the font
      style - The style flags of the fon
      Returns:
      The valid font file name
    • styleToDescription

      public static String styleToDescription(int style)
      Converts the numeric font style code to a descriptive string.
      Parameters:
      style - The numeric font style
      Returns:
      The descriptive string representation of the font style
    • styleToString

      public static String styleToString(int style)
      Converts the numeric font style code to a string usable for the font name identification.
      Parameters:
      style - The numeric font style
      Returns:
      The string representation of the font style
    • stringToStyle

      public static int stringToStyle(String style)
      Converts the font style code to a string.
      Parameters:
      style - The string representation of the font style
      Returns:
      The numeric font style code.
    • getTextExtent

      public abstract Rectangle2D getTextExtent(int x, int y, int width, int height, String text, int align, double cs, int ls)
      Calculate the bounding box of the text, if it would be rendered with the rendering attributes given. The calculation will be done as if the text would be rendered in the current font object.

      If the width of the text box is set to some value other than zero, the text is broken to fit lines of the given length. The line breaking algorithm breaking algorithm breaks on whitespace (blank, tab), carriage return and linefeed (CR/LF) in any combination as well as on other characters such as hyphens.

      If the text contains carriage return and/or linefeed characters, the text is broken into several lines, regardless of whether the text would be broken because of the text box width setting.

      Parameters:
      x - left edge of the text box, required
      y - top edge of the text box, required
      width - maximum width of the textbox. If 0 (or negative) the width of the bounding box is dependent of the rendering attributes
      height - maximum height of the textbox. If 0 (or negative) the width of the bounding box is dependent of the rendering attributes
      text - the text string to calculate the bounding box for
      align - alignment, rotation and TrueType attributes for the text. Use ALIGN_LEFT as default value.
      cs - extra intercharacter spacing. Use 0 as default value to not add additional space.
      ls - extra line spacing. Use 0 as default value to not add additional space.
      Returns:
      returns a rectangle representing the bounding box, if the text would be rendered in this font using the given additional rendering attributes.
    • drawText

      public abstract int drawText(Layer layer, int x, int y, int width, int height, String text, Paint paint, Stroke stroke, int align, double cs, int ls)
      Render the given text string in the given font to the Layer using the attributes given. Use the default values given for unspecified values.

      If the width of the text box is set to some value other than zero, the text is broken to fit lines of the given length. The line breaking algorithm breaking algorithm breaks on whitespace (blank, tab), carriage return and linefeed (CR/LF) in any combination as well as on other characters such as hyphens.

      If the text contains carriage return and/or linefeed characters, the text is broken into several lines, regardless of whether the text would be broken because of the text box width setting.

      Parameters:
      layer - the layer to draw the text into
      x - left edge of the text box, required
      y - top edge of the text box, required
      width - maximum width of the textbox. If 0 (or negative) the width of the bounding box is dependent of the rendering attributes
      height - maximum height of the textbox. If 0 (or negative) the width of the bounding box is dependent of the rendering attributes
      text - the text string to calculate the bounding box for
      paint - The Paint to use for the text drawing.
      stroke - The Stroke to use for the text drawing.
      align - alignment, rotation and TrueType attributes for the text. Use
      invalid reference
      Font#ALIGN_LEFT
      as default value.
      cs - extra intercharacter spacing. Use 0 as default value to not add additional space.
      ls - extra line spacing. Use 0 as default value to not add additional space.
      Returns:
      the number of text lines drawn to the layer
    • getHeight

      public abstract double getHeight()
      Returns the calculated font height in pixels.
      Returns:
      the calculated font height in pixels.
    • getAscent

      public abstract double getAscent()
      Returns the ascent of this Font object, which is the maximal value any glyph of this font ascends above the base line.
      Returns:
      The ascent of this Font.
    • getDescent

      public abstract double getDescent()
      Returns the descent of this Font object, which is the maximal value any glyph of this font descends below the base line.
      Returns:
      The ascent of this Font.
    • canDisplay

      public abstract boolean canDisplay(char c)
      Checks if this Font has a glyph for the specified character.
      Parameters:
      c - a unicode character code
      Returns:
      true if this Font can display the character; false otherwise.
    • canDisplayUpTo

      public abstract int canDisplayUpTo(CharacterIterator iter, int start, int limit)
      Indicates whether or not this Font can display the specified String. For strings with Unicode encoding, it is important to know if a particular font can display the string. This method returns an offset into the String str which is the first character this Font cannot display without using the missing glyph code . If this Font can display all characters, -1 is returned.
      Parameters:
      iter - a CharacterIterator object
      start - the specified starting offset into the specified array of characters
      limit - the specified ending offset into the specified array of characters
      Returns:
      an offset into the String object that can be displayed by this Font.
    • canDisplayUpTo

      public abstract int canDisplayUpTo(String str)
      Indicates whether or not this Font can display a specified String. For strings with Unicode encoding, it is important to know if a particular font can display the string. This method returns an offset into the String str which is the first character this Font cannot display without using the missing glyph code. If the Font can display all characters, -1 is returned.
      Parameters:
      str - a String object
      Returns:
      an offset into str that points to the first character in str that this Font cannot display; or -1 if this Font can display all characters in str.
    • canDisplayUpTo

      public abstract int canDisplayUpTo(char[] text, int start, int limit)
      Indicates whether or not this Font can display the characters in the specified text starting at start and ending at limit. This method is a convenience overload.
      Parameters:
      text - the specified array of characters
      start - the specified starting offset into the specified array of characters
      limit - the specified ending offset into the specified array of characters
      Returns:
      an offset into text that points to the first character in text that this Font cannot display; or -1 if this Font can display all characters in text.
    • toString

      public abstract String toString()
      Returns a String representation of this object containing the font name, the size and style flags.
      Overrides:
      toString in class Object
      Returns:
      A String representation of this object.
    • getAwtFont

      public abstract Font getAwtFont()