org.pentaho.reporting.engine.classic.core.layout
Class DefaultSizeCalculator

java.lang.Object
  extended by org.pentaho.reporting.engine.classic.core.layout.DefaultSizeCalculator
All Implemented Interfaces:
SizeCalculator

public class DefaultSizeCalculator
extends Object
implements SizeCalculator

An AWT-Based default implementation of an SizeCalculator. This implementation tries to detect the currently used FontRendererContext; some JDKs are unable to return reasonable sizes for the given text.

Author:
Thomas Morgner
See Also:
DefaultSizeCalculator

Nested Class Summary
static class DefaultSizeCalculator.BuggyFontRendererDetector
          A helper class that is able to detect whether the implementation is considered buggy.
 
Field Summary
 
Fields inherited from interface org.pentaho.reporting.engine.classic.core.layout.SizeCalculator
CLIP_TEXT, USE_MAX_CHAR_SIZE
 
Constructor Summary
DefaultSizeCalculator(Font font, boolean maxLineHeightUsed)
          Creates a new size calculator.
DefaultSizeCalculator(FontDefinition font, boolean maxLineHeightUsed)
          Deprecated. Do not use the FontDefinition, use the Font-constructor instead.
 
Method Summary
static DefaultSizeCalculator getDefaultSizeCalculator(FontDefinition font, boolean maxLineHeightUsed)
          Deprecated. Do not use the FontDefinition, use the Font-constructor instead and instantiate the size-calculator directly.
static DefaultSizeCalculator.BuggyFontRendererDetector getFrcDetector()
          Returns a singleon instance of the FontRenderContext bug detector.
 float getLineHeight()
          Returns the height of the current font.
 float getStringWidth(String text, int lineStartPos, int endPos)
          Calculates the width of the specified String in the current Graphics context.
 String toString()
          Converts this object to a string.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultSizeCalculator

public DefaultSizeCalculator(FontDefinition font,
                             boolean maxLineHeightUsed)
Deprecated. Do not use the FontDefinition, use the Font-constructor instead.

Creates a new size calculator.

Parameters:
font - the font
maxLineHeightUsed - a flag indicating whether the maximum bounding box is used.

DefaultSizeCalculator

public DefaultSizeCalculator(Font font,
                             boolean maxLineHeightUsed)
Creates a new size calculator.

Parameters:
font - the font.
maxLineHeightUsed - a flag indicating whether the maximum bounding box is used.
Method Detail

getFrcDetector

public static DefaultSizeCalculator.BuggyFontRendererDetector getFrcDetector()
Returns a singleon instance of the FontRenderContext bug detector.

Returns:
the FontRenderContext-detector

getDefaultSizeCalculator

public static DefaultSizeCalculator getDefaultSizeCalculator(FontDefinition font,
                                                             boolean maxLineHeightUsed)
Deprecated. Do not use the FontDefinition, use the Font-constructor instead and instantiate the size-calculator directly.

Creates a new size calculator.

Parameters:
font - The font definition.
maxLineHeightUsed - a flag indicating whether the maximum bounding box is used.
Returns:
A default size calculator.

getLineHeight

public float getLineHeight()
Returns the height of the current font. The font height specifies the distance between 2 base lines.

Specified by:
getLineHeight in interface SizeCalculator
Returns:
the font height.

getStringWidth

public float getStringWidth(String text,
                            int lineStartPos,
                            int endPos)
Calculates the width of the specified String in the current Graphics context.

Specified by:
getStringWidth in interface SizeCalculator
Parameters:
text - the text to be weighted.
lineStartPos - the start position of the substring to be weighted.
endPos - the position of the last characterto be included in the weightening process.
Returns:
the width of the given string in 1/72" dpi.

toString

public String toString()
Converts this object to a string.

Overrides:
toString in class Object
Returns:
a string.