Class VulkanTextMetrics
java.lang.Object
org.inspirenxe.strata.vulkan.VulkanTextMetrics
- All Implemented Interfaces:
org.inspirenxe.strata.api.text.TextMetrics
public final class VulkanTextMetrics
extends Object
implements org.inspirenxe.strata.api.text.TextMetrics
Measures text the way the Vulkan canvas draws it, with a
VulkanFont for ordinary text, another for
monospaced text, and the families the application registers under a FontId.
A style's font picks a registered family, which wins over monospace; a
family that is not registered, or no font at all, picks the monospaced font for a monospaced style when there is
one and the ordinary font otherwise. A style's size scales the chosen font from its
own size, and a size of 0 is the default size, the ordinary font's. Widths, line heights
and ascents scale alike, and the canvas draws the glyphs at the scaled size rather than stretching them.
Registering, replacing or removing a family changes version(), so open screens lay out again. The
metrics never close a registered font: close it after removing it, or after the views that draw with it.
Use it on the UI thread only.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final floatThe sizedefaults()uses, in UI units, the same as the Swing adapter's default font. -
Constructor Summary
ConstructorsConstructorDescriptionVulkanTextMetrics(VulkanFont text) Creates metrics with one font for every style; monospaced spans use it too.VulkanTextMetrics(VulkanFont text, VulkanFont monospace) Creates metrics with a font for monospaced spans. -
Method Summary
Modifier and TypeMethodDescriptionfloatascent(org.inspirenxe.strata.api.text.TextStyle style) static VulkanTextMetricsdefaults()Returns metrics for the operating system's sans-serif and monospaced fonts at 9.0f units, asFreeTypeFont.system(float)andFreeTypeFont.systemMonospace(float)find them.floatReturns the size text of size 0 measures and draws at: the ordinary font's own size.font(org.inspirenxe.strata.api.text.TextStyle style) Returns the font a style is measured and drawn with, at the font's own size.booleanReturns whether these metrics have a monospaced font, which the platform reports asCapabilities.monospaceFont().floatlineHeight(org.inspirenxe.strata.api.text.TextStyle style) register(org.inspirenxe.strata.api.text.FontId id, VulkanFont font) Registers a family under an id, replacing any family registered under it before, so styles that name the id draw with it.registered(org.inspirenxe.strata.api.text.FontId id) Returns the family registered under an id.unregister(org.inspirenxe.strata.api.text.FontId id) Removes the family registered under an id, so styles that name it draw with the default font again.longversion()floatwidth(org.inspirenxe.strata.api.text.TextSpan span)
-
Field Details
-
DEFAULT_SIZE
public static final float DEFAULT_SIZEThe sizedefaults()uses, in UI units, the same as the Swing adapter's default font.- See Also:
-
-
Constructor Details
-
VulkanTextMetrics
Creates metrics with one font for every style; monospaced spans use it too.- Parameters:
text- the font
-
VulkanTextMetrics
Creates metrics with a font for monospaced spans.- Parameters:
text- the font for ordinary spansmonospace- the font for spans whose style asks for monospace
-
-
Method Details
-
defaults
Returns metrics for the operating system's sans-serif and monospaced fonts at 9.0f units, asFreeTypeFont.system(float)andFreeTypeFont.systemMonospace(float)find them. The fonts are read once per call; keep the result.- Returns:
- the metrics, without a monospaced font if the system has none of the ones looked for
- Throws:
IllegalStateException- if no sans-serif font is found; give the metrics a font file instead
-
register
Registers a family under an id, replacing any family registered under it before, so styles that name the id draw with it.- Parameters:
id- the id styles namefont- the family- Returns:
- the family registered under the id before, if any, which the caller closes when nothing draws with it
-
unregister
Removes the family registered under an id, so styles that name it draw with the default font again.- Parameters:
id- the id- Returns:
- the family that was registered, if any, which the caller closes when nothing draws with it
-
registered
Returns the family registered under an id.- Parameters:
id- the id- Returns:
- the family, or empty if none is registered under it
-
defaultSize
public float defaultSize()Returns the size text of size 0 measures and draws at: the ordinary font's own size.- Returns:
- the size in UI units
-
font
Returns the font a style is measured and drawn with, at the font's own size.- Parameters:
style- the style; its font and monospace choose between the fonts- Returns:
- the font
-
hasMonospace
public boolean hasMonospace()Returns whether these metrics have a monospaced font, which the platform reports asCapabilities.monospaceFont().- Returns:
- true when a monospaced font was given
-
width
public float width(org.inspirenxe.strata.api.text.TextSpan span) - Specified by:
widthin interfaceorg.inspirenxe.strata.api.text.TextMetrics
-
lineHeight
public float lineHeight(org.inspirenxe.strata.api.text.TextStyle style) - Specified by:
lineHeightin interfaceorg.inspirenxe.strata.api.text.TextMetrics
-
ascent
public float ascent(org.inspirenxe.strata.api.text.TextStyle style) - Specified by:
ascentin interfaceorg.inspirenxe.strata.api.text.TextMetrics
-
version
public long version()- Specified by:
versionin interfaceorg.inspirenxe.strata.api.text.TextMetrics
-