public class Metrics extends Object implements GraphicsConstants, AlignmentConstants
Modifier and Type | Field and Description |
---|---|
static double |
adjustPixelGapDivisor
When converting gaps originally measured in pixels to large sized fonts, this is the fraction
of a Font height that the original pixel represents.
|
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_OPTION_MAKE_SMALLER_ONLY |
static int |
METRIC_WIDTH_OF_TEXT
A Metric value for getFontForMetric().
|
All, BDR_DOTTED, BDR_INNER, BDR_NOBORDER, BDR_OUTER, BDR_OUTLINE, BDR_RAISEDINNER, BDR_RAISEDOUTER, BDR_SUNKENINNER, BDR_SUNKENOUTER, BF_BOTTOM, BF_BOTTOMLEFT, BF_BOTTOMRIGHT, BF_BUTTON, BF_DIAGONAL, BF_DIAGONAL_ENDBOTTOMLEFT, BF_DIAGONAL_ENDBOTTOMRIGHT, BF_DIAGONAL_ENDTOPLEFT, BF_DIAGONAL_ENDTOPRIGHT, BF_EXACT, BF_FLAT, BF_LEFT, BF_MIDDLE, BF_MONO, BF_PALM, BF_RECT, BF_RIGHT, BF_SOFT, BF_SQUARE, BF_TOP, BF_TOPLEFT, BF_TOPRIGHT, Down, EDGE_BUMP, EDGE_ETCHED, EDGE_RAISED, EDGE_SUNKEN, Left, Right, Up
BOTTOM, CELLFLAG, CELLMASK, CENTER, CONTROLMASK, DONTCHANGE, DONTFILL, DONTSTRETCH, EAST, FILL, GROW, HCENTER, HCONTRACT, HEXPAND, HFILL, HGROW, HSHRINK, HSTRETCH, INITIALLY_CLOSED, INITIALLY_MINIMIZED, INITIALLY_PREFERRED_SIZE, LEFT, NORTH, NORTHEAST, NORTHWEST, RIGHT, SHRINK, SOUTH, SOUTHEAST, SOUTHWEST, STRETCH, TAG_BACKGROUND_IMAGE, TAG_BORDER, TAG_FIXEDSIZE, TAG_INSETS, TAG_MAXIMUMSIZE, TAG_MINIMUMSIZE, TAG_PREFERREDSIZE, TAG_RECT, TAG_SPAN, TAG_TEXTSIZE, TOP, VCENTER, VCONTRACT, VEXPAND, VFILL, VGROW, VSHRINK, VSTRETCH, WEST
Constructor and Description |
---|
Metrics() |
Modifier and Type | Method and Description |
---|---|
static boolean |
adjustForFont(FontMetrics fm) |
static int |
adjustGap(boolean shouldAdjust,
FontMetrics fm,
int gap) |
static void |
anchor(Rect subArea,
Rect largeArea,
int anchor)
Modify subArea so that it is anchored appropriately in largeArea.
|
static void |
anchorTextIn(FontMetrics fm,
Object[] lines,
Rect destination,
int anchor,
FormattedTextSpecs fts)
Find where the text would be given the full destination Rect.
|
static void |
anchorWithStretch(Rect subArea,
Rect largeArea,
int anchor) |
static Point |
centerText(FontMetrics fm,
String st,
int width,
int height,
Point destination) |
static Point |
centerText(FontMetrics fm,
SubString st,
int width,
int height,
Point destination) |
static void |
drawImage(Graphics g,
IImage image,
int imageDrawOptions,
Rect dest,
int anchor) |
static void |
drawText(Graphics g,
FontMetrics fm,
Object[] lines,
Rect where,
int alignment,
int anchor) |
static void |
drawText(Graphics g,
FontMetrics fm,
Object[] lines,
Rect where,
int alignment,
int anchor,
int startLine,
int endLine) |
static void |
drawText(Graphics g,
FontMetrics fm,
Object[] lines,
Rect where,
int alignment,
int anchor,
int startLine,
int endLine,
FormattedTextSpecs fts) |
protected static void |
drawTextIn(Graphics g,
FontMetrics fm,
Object[] lines,
Rect where,
int alignment,
int start,
int end,
FormattedTextSpecs fts) |
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 |
fitInto(int width,
int height,
Object data,
FontMetrics baseFont)
Find the biggest Font such that the data provided fits within the size provided.
|
static Dimension |
getAverageSize(FontMetrics fm,
int rows,
int columns,
int xGap,
int yGap,
Dimension destination)
Deprecated.
use getAverageSizeFor() which specifies the gap in fractions of font size.
|
static Dimension |
getAverageSizeFor(FontMetrics fm,
int rows,
int columns,
double hgap,
double vgap,
Dimension destination) |
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.
|
static Dimension |
getSize(FontMetrics fm,
String[] lines,
int xGap,
int yGap,
Dimension destination) |
static void |
getSize(FontMetrics fm,
String[] lines,
int start,
int end,
Dimension d,
FormattedTextSpecs fts) |
static void |
getSize(FontMetrics fm,
String line,
Dimension d) |
static void |
getSize(FontMetrics fm,
String line,
Dimension d,
FormattedTextSpecs fts) |
static Dimension |
getSize(FontMetrics fm,
String text,
int xGap,
int yGap,
Dimension destination)
Get the size of the text if placed within an imaginary box.
|
static void |
getSize(FontMetrics fm,
StringList lines,
int start,
int end,
Dimension d,
FormattedTextSpecs fts) |
static Dimension |
getSize(FontMetrics fm,
SubString[] lines,
int xGap,
int yGap,
Dimension destination) |
static void |
getSize(FontMetrics fm,
SubString[] lines,
int start,
int end,
Dimension d,
FormattedTextSpecs fts) |
static Dimension |
getSize(FontMetrics fm,
SubString text,
int xGap,
int yGap,
Dimension destination)
Deprecated.
use getSizeFor() which specifies the gaps in fractions of font size.
|
static Dimension |
getSizeFor(FontMetrics fm,
SubString text,
double hgap,
double vgap,
Dimension destination)
Get the size of the text if placed within an imaginary box.
|
static int |
getTextGapInPixels(FontMetrics fm,
double gap,
boolean isHorizontal) |
static void |
insetTextGap(FontMetrics fm,
PointInsets insets,
Dimension d)
Modify the dimension's width and height to add in the text insets.
|
static void |
offsetTextGap(FontMetrics fm,
PointInsets insets,
Point p)
Modify the Point x and y to add in the text insets top and left values.
|
static void |
offsetTextGap(FontMetrics fm,
PointInsets insets,
Rect r)
Modify the Rect x and y and width and height to add in the text insets top and left values
and remove the width and height.
|
static FontMetrics |
shrinkInto(int width,
int height,
Object data,
FontMetrics baseFont,
FontMetrics biggestSoFar) |
public static double adjustPixelGapDivisor
public static final int METRIC_HEIGHT
public static final int METRIC_ASCENT
public static final int METRIC_DESCENT
public static final int METRIC_WIDTH_OF_TEXT
public static final int METRIC_HEIGHT_OF_TEXT
public static final int METRIC_OPTION_MAKE_SMALLER_ONLY
public static Dimension getSize(FontMetrics fm, String text, int xGap, int yGap, Dimension destination)
fm
- the FontMetrics to use to measure.text
- a single line of text as a String, SubString, CharArray or char[]xGap
- the width at the left and right of the text.yGap
- the width at the top and bottom of the text.destination
- a destination rectangle.public static boolean adjustForFont(FontMetrics fm)
public static int adjustGap(boolean shouldAdjust, FontMetrics fm, int gap)
public static Dimension getSize(FontMetrics fm, SubString text, int xGap, int yGap, Dimension destination)
fm
- the FontMetrics to use to measure.text
- a single line of text as a String, SubString, CharArray or char[]xGap
- the width at the left and right of the text.yGap
- the width at the top and bottom of the text.destination
- a destination rectangle.public static int getTextGapInPixels(FontMetrics fm, double gap, boolean isHorizontal)
public static Dimension getSizeFor(FontMetrics fm, SubString text, double hgap, double vgap, Dimension destination)
fm
- the FontMetrics to use to measure.text
- a single line of text as a String, SubString, CharArray or char[]hgap
- the width of the gap at the left and right of the text as a fraction of the width of the 'X' character.vgap
- the height of the gap at the top and bottom of the text as a fraction of the height of the font.destination
- a destination rectangle.public static Dimension getSize(FontMetrics fm, String[] lines, int xGap, int yGap, Dimension destination)
public static Dimension getSize(FontMetrics fm, SubString[] lines, int xGap, int yGap, Dimension destination)
public static void insetTextGap(FontMetrics fm, PointInsets insets, Dimension d)
fm
- the FontMetrics to use. If it is null nothing is done.insets
- the insets to apply. If it is null nothing is done.d
- the Dimension to change.public static void offsetTextGap(FontMetrics fm, PointInsets insets, Point p)
fm
- the FontMetrics to use. If it is null nothing is done.insets
- the insets to apply. If it is null nothing is done.p
- the Point to modify.public static void offsetTextGap(FontMetrics fm, PointInsets insets, Rect r)
fm
- the FontMetrics to use. If it is null nothing is done.insets
- the insets to apply. If it is null nothing is done.r
- the Rect to modify.public static Dimension getAverageSize(FontMetrics fm, int rows, int columns, int xGap, int yGap, Dimension destination)
fm
- rows
- columns
- xGap
- yGap
- destination
- public static Dimension getAverageSizeFor(FontMetrics fm, int rows, int columns, double hgap, double vgap, Dimension destination)
public static Point centerText(FontMetrics fm, String st, int width, int height, Point destination)
public static Point centerText(FontMetrics fm, SubString st, int width, int height, Point destination)
public static void getSize(FontMetrics fm, String line, Dimension d)
public static void getSize(FontMetrics fm, String line, Dimension d, FormattedTextSpecs fts)
public static void getSize(FontMetrics fm, String[] lines, int start, int end, Dimension d, FormattedTextSpecs fts)
public static void getSize(FontMetrics fm, SubString[] lines, int start, int end, Dimension d, FormattedTextSpecs fts)
public static void getSize(FontMetrics fm, StringList lines, int start, int end, Dimension d, FormattedTextSpecs fts)
public static void anchor(Rect subArea, Rect largeArea, int anchor)
public static void drawImage(Graphics g, IImage image, int imageDrawOptions, Rect dest, int anchor)
public static void drawText(Graphics g, FontMetrics fm, Object[] lines, Rect where, int alignment, int anchor)
public static void drawText(Graphics g, FontMetrics fm, Object[] lines, Rect where, int alignment, int anchor, int startLine, int endLine)
public static void anchorTextIn(FontMetrics fm, Object[] lines, Rect destination, int anchor, FormattedTextSpecs fts)
fm
- The font metrics.lines
- the text.destination
- the destination area to hold the text which will be modified
to be the area that would hold the text exactly.anchor
- an anchor specifier (such as NORTH, SOUTH, etc).fts
- optional FormattedTextSpecs.public static void drawText(Graphics g, FontMetrics fm, Object[] lines, Rect where, int alignment, int anchor, int startLine, int endLine, FormattedTextSpecs fts)
protected static void drawTextIn(Graphics g, FontMetrics fm, Object[] lines, Rect where, int alignment, int start, int end, FormattedTextSpecs fts)
public static int getMetricValue(int whichMetric, Object data, FontMetrics fm)
whichMetric
- one of the METRIC_XXX valuesdata
- This is only needed for METRIC_WIDTH_OF_TEXT or METRIC_HEIGHT_OF_TEXT.
The data must be a String, a SubString or 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.public static Font getFontForMetric(int valueOfMetricInPixels, int whichMetric, Object data, FontMetrics baseFont)
valueOfMetricInPixels
- The value of the metrics in Pixels.whichMetric
- one of the METRIC_XXX valuesdata
- 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.public static Font fitInto(Dimension size, Object data, FontMetrics baseFont)
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.public static Font fitInto(int width, int height, Object data, FontMetrics baseFont)
width
- The width in pixels.height
- The height 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.public static FontMetrics shrinkInto(int width, int height, Object data, FontMetrics baseFont, FontMetrics biggestSoFar)
public static Font getFontForHeight(int requiredHeight, FontMetrics baseFont)
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.