com.jrefinery.report.targets.base.layout
Class DefaultSizeCalculator

java.lang.Object
  extended bycom.jrefinery.report.targets.base.layout.DefaultSizeCalculator
All Implemented Interfaces:
SizeCalculator

public class DefaultSizeCalculator
extends java.lang.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.
 
Constructor Summary
DefaultSizeCalculator(FontDefinition font)
          Creates a new size calculator.
 
Method Summary
static DefaultSizeCalculator getDefaultSizeCalculator(FontDefinition font)
          Returns an instance.
static DefaultSizeCalculator.BuggyFontRendererDetector getFrcDetector()
          Returns a singleon instance of the FontRenderContext bug detector.
 float getLineHeight()
          Returns the height of the current font.
 float getStringWidth(java.lang.String text, int lineStartPos, int endPos)
          Calculates the width of the specified String in the current Graphics context.
 java.lang.String toString()
          Converts this object to a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultSizeCalculator

public DefaultSizeCalculator(FontDefinition font)
Creates a new size calculator.

Parameters:
font - the font.
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)
Returns an instance.

Parameters:
font - The font definition.
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(java.lang.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 java.lang.String toString()
Converts this object to a string.

Returns:
a string.