ewe.fx
Class FontTools

java.lang.Object
  extended byewe.fx.FontTools

public class FontTools
extends Object

This class provides a set of static toolkit methods that work on Font and/or FontMetrics


Field Summary
static int METRIC_ASCENT
          A Metric value for getFontForMetric().
static int METRIC_DESCENT
          A Metric value for getFontForMetric().
static int METRIC_HEIGHT
          A Metric value for getFontForMetric().
static int METRIC_HEIGHT_OF_TEXT
          A Metric value for getFontForMetric().
static int METRIC_WIDTH_OF_TEXT
          A Metric value for getFontForMetric().
 
Constructor Summary
FontTools()
           
 
Method Summary
static Font fitInto(Dimension size, Object data, FontMetrics baseFont)
          Find the biggest Font such that the data provided fits within the size provided.
static Font getFontForHeight(int requiredHeight, FontMetrics baseFont)
          Find the biggest Font such that its height is less than or equal to the requiredHeight.
static Font getFontForMetric(int valueOfMetricInPixels, int whichMetric, Object data, FontMetrics baseFont)
          Retrieve the Font which is of the correct size, such that its metric is equal to, or just smaller than the specified metric in pixels, or for which the metrics of the supplied data is equal to or just smaller than the specified metric in pixels.
static int getMetricValue(int whichMetric, Object data, FontMetrics fm)
          Get the value of a particular Metric for a FontMetrics for a set of data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 

Field Detail

METRIC_HEIGHT

public static final int METRIC_HEIGHT
A Metric value for getFontForMetric().

See Also:
Constant Field Values

METRIC_ASCENT

public static final int METRIC_ASCENT
A Metric value for getFontForMetric().

See Also:
Constant Field Values

METRIC_DESCENT

public static final int METRIC_DESCENT
A Metric value for getFontForMetric().

See Also:
Constant Field Values

METRIC_WIDTH_OF_TEXT

public static final int METRIC_WIDTH_OF_TEXT
A Metric value for getFontForMetric().

See Also:
Constant Field Values

METRIC_HEIGHT_OF_TEXT

public static final int METRIC_HEIGHT_OF_TEXT
A Metric value for getFontForMetric().

See Also:
Constant Field Values
Constructor Detail

FontTools

public FontTools()
Method Detail

getMetricValue

public static int getMetricValue(int whichMetric,
                                 Object data,
                                 FontMetrics fm)
Get the value of a particular Metric for a FontMetrics for a set of data.

Parameters:
whichMetric - one of the METRIC_XXX values
data - This is only needed for METRIC_WIDTH_OF_TEXT or METRIC_HEIGHT_OF_TEXT. The data must be a String, an array of Strings (which is assumed will be placed one above the other) or a Character (for a single character).
fm - The FontMetrics to use.
Returns:
the value of the specified Metric.

getFontForMetric

public static Font getFontForMetric(int valueOfMetricInPixels,
                                    int whichMetric,
                                    Object data,
                                    FontMetrics baseFont)
Retrieve the Font which is of the correct size, such that its metric is equal to, or just smaller than the specified metric in pixels, or for which the metrics of the supplied data is equal to or just smaller than the specified metric in pixels.

Parameters:
valueOfMetricInPixels - The value of the metrics in Pixels.
whichMetric - one of the METRIC_XXX values
data - This is only needed for METRIC_WIDTH_OF_TEXT or METRIC_HEIGHT_OF_TEXT. The data must be a String, an array of Strings (which is assumed will be placed one above the other) or a Character (for a single character).
baseFont - The FontMetrics representing the base font to use. The returned Font will have the same name and style as the baseFont.
Returns:
the Font of the correct size so that it fits within the specified metric.

fitInto

public static Font fitInto(Dimension size,
                           Object data,
                           FontMetrics baseFont)
Find the biggest Font such that the data provided fits within the size provided.

Parameters:
size - The size in pixels.
data - This can be a Character or a String or an Array of Strings.
baseFont - The FontMetrics representing the base font to use. The returned Font will have the same name and style as the baseFont.
Returns:
the biggest Font such that the data provided fits within the size provided.

getFontForHeight

public static Font getFontForHeight(int requiredHeight,
                                    FontMetrics baseFont)
Find the biggest Font such that its height is less than or equal to the requiredHeight.

Parameters:
requiredHeight - The required height for the Font.
baseFont - The FontMetrics representing the base font to use. The returned Font will have the same name and style as the baseFont.
Returns:
the biggest Font such that its height is less than or equal to the requiredHeight.