org.writersforge.catalan.layout.style
Class FontStyleMetrics

java.lang.Object
  extended byorg.writersforge.catalan.layout.style.FontStyleMetrics
All Implemented Interfaces:
FontStyle

public class FontStyleMetrics
extends java.lang.Object
implements FontStyle

Wrapper class to calculate font metrics based on a FontStyle object. Echoes the critical methods from FontMetrics.

Author:
jsheets

Field Summary
static double FIXED_CHAR_MULT
          Default multiplier for converting font point size into character width.
 
Fields inherited from interface org.writersforge.catalan.layout.style.FontStyle
FONT_STYLE_BOLD, FONT_STYLE_ITALIC, FONT_STYLE_PLAIN, STYLE_ENUM
 
Constructor Summary
FontStyleMetrics(FontStyle fontStyle)
          Creates a new instance of FontStyleMetrics from the FontStyle.
FontStyleMetrics(java.lang.String fontName, int fontStyle, int fontSize)
          Creates a new instance of FontStyleMetrics with the explicit font parameters and a calculated font height.
FontStyleMetrics(java.lang.String fontName, int fontStyle, int fontSize, int fontHeight)
          Creates a new instance of FontStyleMetrics with the explicit font parameters.
 
Method Summary
 int charWidth(char ch)
          Estimates the width of the given character in this style.
 int getAscent()
          Returns the ascent for this font.
 int getDescent()
          Returns the descent for this font.
 java.awt.Color getFontColor()
          Returns the color of this run of text.
 int getFontHeight()
          Estimates the height of the font in point size.
 java.lang.String getFontName()
          Getter for property name, the name of the font.
 int getFontSize()
          Getter for property size, the point size of the font.
 int getFontStyle()
          Getter for property style: plain, bold, or italic.
 int getLeading()
          Returns the leading for this font.
 int stringWidth(java.lang.String str)
          Estimates the width of the given string if rendered in this style.
 java.lang.String toString()
          Returns this object as a String
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FIXED_CHAR_MULT

public static final double FIXED_CHAR_MULT
Default multiplier for converting font point size into character width.

See Also:
Constant Field Values
Constructor Detail

FontStyleMetrics

public FontStyleMetrics(FontStyle fontStyle)
Creates a new instance of FontStyleMetrics from the FontStyle.

Parameters:
fontStyle - FontStyle to wrap

FontStyleMetrics

public FontStyleMetrics(java.lang.String fontName,
                        int fontStyle,
                        int fontSize)
Creates a new instance of FontStyleMetrics with the explicit font parameters and a calculated font height. Any parameters with DefaultStyle.NOT_FOUND will carry default values.

Parameters:
fontName - the name of the font
fontStyle - the plain/italic/bold style of the font
fontSize - the point size of the font

FontStyleMetrics

public FontStyleMetrics(java.lang.String fontName,
                        int fontStyle,
                        int fontSize,
                        int fontHeight)
Creates a new instance of FontStyleMetrics with the explicit font parameters. Any parameters with DefaultStyle.NOT_FOUND will carry default values.

Parameters:
fontName - the name of the font
fontStyle - the plain/italic/bold style of the font
fontSize - the point size of the font
fontHeight - the height of the font in points
Method Detail

getFontName

public java.lang.String getFontName()
Getter for property name, the name of the font.

Specified by:
getFontName in interface FontStyle
Returns:
Value of property name.

getFontStyle

public int getFontStyle()
Getter for property style: plain, bold, or italic.

Specified by:
getFontStyle in interface FontStyle
Returns:
Value of property style.

getFontSize

public int getFontSize()
Getter for property size, the point size of the font.

Specified by:
getFontSize in interface FontStyle
Returns:
Value of property size.

getFontHeight

public int getFontHeight()
Estimates the height of the font in point size. Not a true measure of the font height, but can be used for rough estimates. If the font height is declared explicitly, use that instead.

Specified by:
getFontHeight in interface FontStyle
Returns:
the height of the font in point size

getAscent

public int getAscent()
Returns the ascent for this font. The ascent is the amount by which the character ascends above the baseline.

Returns:
the ascent in font points

getDescent

public int getDescent()
Returns the descent for this font. The descent is the amount by which the character descends below the baseline.

Returns:
the descent in font points

getLeading

public int getLeading()
Returns the leading for this font. The standard leading, or interline spacing, is the logical amount of space to be reserved between the descent of one line of text and the ascent of the next line.

Returns:
the leading in font points

charWidth

public int charWidth(char ch)
Estimates the width of the given character in this style. Not a true measure of the character width, but can be used for rough estimates.

Parameters:
ch - the character to check
Returns:
the width of the single given character in this style

stringWidth

public int stringWidth(java.lang.String str)
Estimates the width of the given string if rendered in this style. Not a true measure of the string's width in the matching font, but can be used for rough estimates.

Parameters:
str - the String to check
Returns:
the width of the given string in this style

toString

public java.lang.String toString()
Returns this object as a String

Returns:
a String representation of this object
See Also:
Object.toString()

getFontColor

public java.awt.Color getFontColor()
Returns the color of this run of text. If this instance was created with the FontStyle constructor, it will get the color from the FontStyle reference; otherwise, it will return the default color.

Specified by:
getFontColor in interface FontStyle
Returns:
the text color