public class VectorFont extends Object implements Closeable
Font metrics:
Important note: The font size should not be confused with the actual font height:
getHeight(float)
.
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this font and its associated resources.
|
float |
getBaselinePosition(float size)
Returns the position of the baseline for this font, at given font size.
|
float |
getHeight(float size)
Returns the height of this font, at given font size.
|
boolean |
isClosed()
Returns whether this font has been closed or not.
|
static VectorFont |
loadFont(String resourcePath)
Loads a vector font from a path using a simple text layout.
|
static VectorFont |
loadFont(String resourcePath,
boolean complexText)
Loads a vector font from a path using the specified text layout(simple or complex).
|
float |
measureStringHeight(String string,
float size)
Returns the height of a string when it is drawn with this font and the given size.
|
float |
measureStringWidth(String string,
float size)
Returns the width of a string when it is drawn with this font and the given size.
|
float |
measureStringWidth(String string,
float size,
float letterSpacing)
Returns the width of a string when it is drawn with this font and the given size.
|
public void close()
Calling this method on a font which has already been closed has no effect.
close
in interface Closeable
close
in interface AutoCloseable
public float getBaselinePosition(float size)
The returned value is the distance between the line of maximum ascent and the baseline (see VectorFont
).
The specified font size must be positive. If it is less than or equal to 0, the method will return 0.
size
- the font size, in pixelsVectorGraphicsException
- if the measure could not be obtained for any reason (see
VectorGraphicsException.getErrorCode()
)public float getHeight(float size)
The returned value is the distance between the line of maximum ascent and the line of maximum descent (see
VectorFont
).
This method can be used to size a text area. Since all the glyphs of a font are located between these two lines,
any text will fit in an area of that height when drawn with VectorGraphicsPainter
methods. If, instead,
you prefer to adjust the size of your area to be the exact size of a specific text, refer to the method
measureStringHeight(String, float)
.
The specified font size must be positive. If it is less than or equal to 0, the method will return 0.
size
- the font size, in pixelsVectorGraphicsException
- if the measure could not be obtained for any reason (see
VectorGraphicsException.getErrorCode()
)measureStringHeight(String, float)
,
VectorGraphicsPainter.drawString(ej.microui.display.GraphicsContext, String, VectorFont, float, float,
float)
public boolean isClosed()
true
if the font has been closed, false
otherwisepublic static VectorFont loadFont(String resourcePath)
loadFont(resourcePath, false)
.resourcePath
- the path to get the font fromVectorGraphicsException
- if the font could not be loaded (see VectorGraphicsException.getErrorCode()
for the error
cause)public static VectorFont loadFont(String resourcePath, boolean complexText)
resourcePath
- the path to get the font fromcomplexText
- if true the font layouter considers complex text layout features like contextual glyph substitution or
positioning.
Arabic and Thai scripts are examples of scripts that need complex text layout features.
The vector font file should contain the tables needed by the selected text layout.
VectorGraphicsException
- if the font could not be loaded or if complexText is true and no complex layouter is available(see
VectorGraphicsException.getErrorCode()
for the error cause)public float measureStringHeight(String string, float size)
The returned value is the height of the smallest rectangle that encloses all the glyphs.
This method can be used to size a text area. The given text will fit perfectly in an area of that height when
drawn with VectorGraphicsPainter
methods. If, instead, you prefer to adjust the size of your area to fit
any kind of text, refer to the method getHeight(float)
.
The specified font size must be positive. If it is less than or equal to 0, the method will return 0.
string
- the string to measuresize
- the font size, in pixelsVectorGraphicsException
- if the measure could not be obtained for any reason (see
VectorGraphicsException.getErrorCode()
)getHeight(float)
,
VectorGraphicsPainter.drawString(ej.microui.display.GraphicsContext, String, VectorFont, float, float,
float)
public float measureStringWidth(String string, float size)
The returned value is the width of the smallest rectangle that encloses all the glyphs.
This method can be used to size a text area. The given text will fit perfectly in an area of that width when
drawn with VectorGraphicsPainter
methods.
Note that the measure includes the gaps between the glyphs (also known as side bearings). For this reason, the measurement for a given string is not equal to the sum of the measurements for each glyph of that string.
The specified font size must be positive. If it is less than or equal to 0, the method will return 0.
Equivalent to calling measureStringWidth(String, float, float)
with a letter spacing of 0.
string
- the string to measuresize
- the font size, in pixelsVectorGraphicsException
- if the measure could not be obtained for any reason (see
VectorGraphicsException.getErrorCode()
)measureStringWidth(String, float, float)
,
VectorGraphicsPainter.drawString(ej.microui.display.GraphicsContext, String, VectorFont, float, float,
float)
public float measureStringWidth(String string, float size, float letterSpacing)
The returned value is the width of the smallest rectangle that encloses all the glyphs, taking into account the given extra letter spacing.
This method can be used to size a text area. The given text will fit perfectly in an area of that width when
drawn with VectorGraphicsPainter
methods.
Note that the measure includes the gaps between the glyphs (side bearings and extra letter spacing). For this reason, the measurement for a given string is not equal to the sum of the measurements for each glyph of that string.
The letter spacing argument specifies the extra space to add between the characters. A positive value will move the characters apart, a negative value will move them together. The default value is 0.
The specified font size must be positive. If it is less than or equal to 0, the method will return 0.
string
- the string to measuresize
- the font size, in pixelsletterSpacing
- the extra letter spacing to use, in pixelsVectorGraphicsException
- if the measure could not be obtained for any reason (see
VectorGraphicsException.getErrorCode()
)measureStringWidth(String, float)
,
VectorGraphicsPainter.drawString(ej.microui.display.GraphicsContext, String, VectorFont, float, Matrix, int,
BlendMode, float)