net.sf.jasperreports.engine.util
Class JdkGlyphFixTextMeasurer

java.lang.Object
  extended by net.sf.jasperreports.engine.fill.TextMeasurer
      extended by net.sf.jasperreports.engine.util.JdkGlyphFixTextMeasurer
All Implemented Interfaces:
JRTextMeasurer

public class JdkGlyphFixTextMeasurer
extends TextMeasurer

A text measurer implementation that extends the default text measurer and adds a workaround for Sun JDK bug 6367148/ 6611637.

The workaround consists of simply reattempting the text measuring when a java.lang.NullPointer exception is thrown from sun.font.GlyphLayout.

Version:
$Id: JdkGlyphFixTextMeasurer.java 5089 2012-03-15 12:46:09Z teodord $
Author:
Lucian Chirita (lucianc@users.sourceforge.net)
See Also:
JdkGlyphFixTextMeasurerFactory

Nested Class Summary
 
Nested classes/interfaces inherited from class net.sf.jasperreports.engine.fill.TextMeasurer
TextMeasurer.FontInfo, TextMeasurer.FontKey, TextMeasurer.TextMeasuredState
 
Field Summary
static int DEFAULT_ATTEMPT_SLEEP
          The default between attempts sleep time.
static int DEFAULT_ATTEMPTS
          The default attempt count.
protected static java.lang.String JDK_EXCEPTION_CLASS_PREFIX
           
static java.lang.String PROPERTY_ATTEMPT_SLEEP
          A property that specifies the number of milliseconds to sleep between measuring reattempts.
static java.lang.String PROPERTY_ATTEMPTS
          A property that specifies the number of times the measurer should attempt to measure a single text element before giving up.
static java.lang.String PROPERTY_CATCH_EMPTY_STACKTRACE
          Whether java.lang.NullPointer exceptions with empty stacktraces should be caught.
 
Fields inherited from class net.sf.jasperreports.engine.fill.TextMeasurer
jasperReportsContext, leftPadding, maxHeight, measuredState, prevMeasuredState, PROPERTY_MEASURE_SIMPLE_TEXTS, rightPadding, textElement, width
 
Constructor Summary
JdkGlyphFixTextMeasurer(JasperReportsContext jasperReportsContext, JRCommonText textElement)
          Create a text measurer for a text element.
JdkGlyphFixTextMeasurer(JRCommonText textElement)
          Deprecated. Replaced by JdkGlyphFixTextMeasurer(JasperReportsContext, JRCommonText).
 
Method Summary
protected  boolean isJdkGlyphError(java.lang.NullPointerException e)
           
 JRMeasuredText measure(JRStyledText styledText, int remainingTextStart, int availableStretchHeight, boolean canOverflow)
          Calls super.measure, catches sun.font.GlyphLayout NPEs and reattempts the call.
 
Methods inherited from class net.sf.jasperreports.engine.fill.TextMeasurer
appendTruncateSuffix, getFontRenderContext, getTextPropertiesHolder, getTruncateSuffix, hasParagraphIndents, initialize, isLeftToRight, isToTruncateAtChar, measureSimpleText, processLastTruncatedRow, renderNextLine, renderParagraph, setAttributes, setAttributes, truncateLastLineAtChar
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JDK_EXCEPTION_CLASS_PREFIX

protected static final java.lang.String JDK_EXCEPTION_CLASS_PREFIX
See Also:
Constant Field Values

DEFAULT_ATTEMPTS

public static final int DEFAULT_ATTEMPTS
The default attempt count.

See Also:
Constant Field Values

DEFAULT_ATTEMPT_SLEEP

public static final int DEFAULT_ATTEMPT_SLEEP
The default between attempts sleep time.

See Also:
Constant Field Values

PROPERTY_ATTEMPTS

public static final java.lang.String PROPERTY_ATTEMPTS
A property that specifies the number of times the measurer should attempt to measure a single text element before giving up. The default value is 20.

See Also:
DEFAULT_ATTEMPTS, Constant Field Values

PROPERTY_ATTEMPT_SLEEP

public static final java.lang.String PROPERTY_ATTEMPT_SLEEP
A property that specifies the number of milliseconds to sleep between measuring reattempts. The default value is 0, which means that the measurer will not pause between reattempts.

See Also:
DEFAULT_ATTEMPT_SLEEP, Constant Field Values

PROPERTY_CATCH_EMPTY_STACKTRACE

public static final java.lang.String PROPERTY_CATCH_EMPTY_STACKTRACE
Whether java.lang.NullPointer exceptions with empty stacktraces should be caught. This is useful when running on a Sun server JVM (java -server), which might omit exception stacktraces in some cases.

See Also:
Constant Field Values
Constructor Detail

JdkGlyphFixTextMeasurer

public JdkGlyphFixTextMeasurer(JasperReportsContext jasperReportsContext,
                               JRCommonText textElement)
Create a text measurer for a text element.

Parameters:
textElement - the text element

JdkGlyphFixTextMeasurer

public JdkGlyphFixTextMeasurer(JRCommonText textElement)
Deprecated. Replaced by JdkGlyphFixTextMeasurer(JasperReportsContext, JRCommonText).

Method Detail

measure

public JRMeasuredText measure(JRStyledText styledText,
                              int remainingTextStart,
                              int availableStretchHeight,
                              boolean canOverflow)
Calls super.measure, catches sun.font.GlyphLayout NPEs and reattempts the call.

Specified by:
measure in interface JRTextMeasurer
Overrides:
measure in class TextMeasurer
Parameters:
styledText - the full text
remainingTextStart - the start index of the remaining text
availableStretchHeight - the available stretch height
canOverflow - whether the text element is able to overflow
Returns:
text measuring information

isJdkGlyphError

protected boolean isJdkGlyphError(java.lang.NullPointerException e)


© 2001-2010 Jaspersoft Corporation www.jaspersoft.com