Package org.apache.fop.render.java2d
Class Java2DFontMetrics
- java.lang.Object
-
- org.apache.fop.render.java2d.Java2DFontMetrics
-
public class Java2DFontMetrics extends java.lang.Object
This is a FontMetrics to be used for AWT rendering. It instanciates a font, depening on family and style values. The java.awt.FontMetrics for this font is then created to be used for the actual measurement. Since layout is word by word and since it is expected that two subsequent words often share the same style, the Font and FontMetrics is buffered and only changed if needed.Since FontState and FontInfo multiply all factors by size, we assume a "standard" font of FONT_SIZE.
-
-
Field Summary
Fields Modifier and Type Field Description private int
ascender
The highest point of the font above the baseline (usually derived from "d", value in mpt)private int
descender
The lowest point of the font under the baseline (usually derived from "p", value in mpt)private java.awt.Font
f1
Buffered font.private java.lang.String
family
The family type of the font last usedprivate java.awt.FontMetrics
fmt
The FontMetrics object used to calculate character width etc.static int
FONT_FACTOR
This factor multiplies the calculated values to scale to FOP internal measurementsstatic int
FONT_SIZE
Font size standard used for metric measurementsprivate java.awt.Graphics2D
graphics
Temp graphics object needed to get the font metricsprivate java.awt.font.LineMetrics
lineMetrics
A LineMetrics to access high-resolution metrics information.private float
size
The size of the font last usedprivate int
style
The style of the font last usedprivate int[]
width
The width of all 256 character, if requestedprivate int
xHeight
The typical height of a small cap latter (often derived from "x", value in mpt)
-
Constructor Summary
Constructors Constructor Description Java2DFontMetrics()
Constructs a new Font-metrics.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.awt.Graphics2D
createFontMetricsGraphics2D()
Creates a Graphics2D object for the sole purpose of getting font metrics.int
getAscender(java.lang.String family, int style, int size)
Determines the font ascent of the Font described by this FontMetrics objectprivate java.awt.Font
getBaseFont(java.lang.String family, int style, float size)
int
getCapHeight(java.lang.String family, int style, int size)
The size of a capital letter measured from the font's baselineint
getDescender(java.lang.String family, int style, int size)
Determines the font descent of the Font described by this FontMetrics objectjava.awt.Font
getFont(java.lang.String family, int style, int size)
Returns a java.awt.Font instance for the desired family, style and size type.int
getMaxAscent(java.lang.String family, int style, int size)
Determines the font's maximum ascent of the Font described by the current FontMetrics objectint
getStrikeoutPosition(java.lang.String family, int style, int size)
int
getStrikeoutThickness(java.lang.String family, int style, int size)
int
getUnderlinePosition(java.lang.String family, int style, int size)
int
getUnderlineThickness(java.lang.String family, int style, int size)
int[]
getWidths(java.lang.String family, int style, int size)
Return widths (in 1/1000ths of point size) of all charactersint
getXHeight(java.lang.String family, int style, int size)
Determines the typical font height of a small cap letter FontMetrics objectboolean
hasChar(java.lang.String family, int style, int size, char c)
Indicates whether the font contains a particular character/glyph.private int
internalCharWidth(int i)
private boolean
setFont(java.lang.String family, int style, int size)
Checks whether the font for which values are requested is the one used immediately before or whether it is a new oneint
width(int i, java.lang.String family, int style, int size)
Returns width (in 1/1000ths of point size) of character at code point i
-
-
-
Field Detail
-
FONT_SIZE
public static final int FONT_SIZE
Font size standard used for metric measurements- See Also:
- Constant Field Values
-
FONT_FACTOR
public static final int FONT_FACTOR
This factor multiplies the calculated values to scale to FOP internal measurements- See Also:
- Constant Field Values
-
width
private int[] width
The width of all 256 character, if requested
-
xHeight
private int xHeight
The typical height of a small cap latter (often derived from "x", value in mpt)
-
ascender
private int ascender
The highest point of the font above the baseline (usually derived from "d", value in mpt)
-
descender
private int descender
The lowest point of the font under the baseline (usually derived from "p", value in mpt)
-
f1
private java.awt.Font f1
Buffered font. f1 is bufferd for metric measurements during layout. fSized is buffered for display purposes
-
family
private java.lang.String family
The family type of the font last used
-
style
private int style
The style of the font last used
-
size
private float size
The size of the font last used
-
fmt
private java.awt.FontMetrics fmt
The FontMetrics object used to calculate character width etc.
-
lineMetrics
private java.awt.font.LineMetrics lineMetrics
A LineMetrics to access high-resolution metrics information.
-
graphics
private final java.awt.Graphics2D graphics
Temp graphics object needed to get the font metrics
-
-
Method Detail
-
createFontMetricsGraphics2D
private static java.awt.Graphics2D createFontMetricsGraphics2D()
Creates a Graphics2D object for the sole purpose of getting font metrics.- Returns:
- a Graphics2D object
-
getMaxAscent
public int getMaxAscent(java.lang.String family, int style, int size)
Determines the font's maximum ascent of the Font described by the current FontMetrics object- Parameters:
family
- font family (java name) to usestyle
- font style (java def.) to usesize
- font size- Returns:
- ascent in milliponts
-
getAscender
public int getAscender(java.lang.String family, int style, int size)
Determines the font ascent of the Font described by this FontMetrics object- Parameters:
family
- font family (java name) to usestyle
- font style (java def.) to usesize
- font size- Returns:
- ascent in milliponts
-
getCapHeight
public int getCapHeight(java.lang.String family, int style, int size)
The size of a capital letter measured from the font's baseline- Parameters:
family
- font familystyle
- font stylesize
- font size- Returns:
- capital height in millipoints
-
getDescender
public int getDescender(java.lang.String family, int style, int size)
Determines the font descent of the Font described by this FontMetrics object- Parameters:
family
- font family (jave name) to usestyle
- font style (jave def.) to usesize
- font size- Returns:
- descent in milliponts
-
getXHeight
public int getXHeight(java.lang.String family, int style, int size)
Determines the typical font height of a small cap letter FontMetrics object- Parameters:
family
- font family (jave name) to usestyle
- font style (jave def.) to usesize
- font size- Returns:
- font height in milliponts
-
getUnderlinePosition
public int getUnderlinePosition(java.lang.String family, int style, int size)
-
getUnderlineThickness
public int getUnderlineThickness(java.lang.String family, int style, int size)
-
getStrikeoutPosition
public int getStrikeoutPosition(java.lang.String family, int style, int size)
-
getStrikeoutThickness
public int getStrikeoutThickness(java.lang.String family, int style, int size)
-
width
public int width(int i, java.lang.String family, int style, int size)
Returns width (in 1/1000ths of point size) of character at code point i- Parameters:
i
- the character for which to get the widthfamily
- font family (jave name) to usestyle
- font style (jave def.) to usesize
- font size- Returns:
- character width in millipoints
-
internalCharWidth
private int internalCharWidth(int i)
-
getWidths
public int[] getWidths(java.lang.String family, int style, int size)
Return widths (in 1/1000ths of point size) of all characters- Parameters:
family
- font family (jave name) to usestyle
- font style (jave def.) to usesize
- font size- Returns:
- array of character widths in millipoints
-
getBaseFont
private java.awt.Font getBaseFont(java.lang.String family, int style, float size)
-
setFont
private boolean setFont(java.lang.String family, int style, int size)
Checks whether the font for which values are requested is the one used immediately before or whether it is a new one- Parameters:
family
- font family (jave name) to usestyle
- font style (jave def.) to usesize
- font size- Returns:
- true if the font was changed, false otherwise
-
getFont
public java.awt.Font getFont(java.lang.String family, int style, int size)
Returns a java.awt.Font instance for the desired family, style and size type. This is here, so that the font-mapping of FOP-defined fonts to java-fonts can be done in one place and does not need to occur in AWTFontRenderer.- Parameters:
family
- font family (jave name) to usestyle
- font style (jave def.) to usesize
- font size- Returns:
- font with the desired characeristics.
-
hasChar
public boolean hasChar(java.lang.String family, int style, int size, char c)
Indicates whether the font contains a particular character/glyph.- Parameters:
family
- font family (jave name) to usestyle
- font style (jave def.) to usesize
- font sizec
- the glyph to check- Returns:
- true if the character is supported
-
-