Package io.github.humbleui.skija
Class Font
- java.lang.Object
-
- io.github.humbleui.skija.impl.Native
-
- io.github.humbleui.skija.impl.Managed
-
- io.github.humbleui.skija.Font
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class Font extends Managed
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFont._FinalizerHolder-
Nested classes/interfaces inherited from class io.github.humbleui.skija.impl.Managed
Managed.CleanerThunk
-
-
Field Summary
Fields Modifier and Type Field Description FontMetrics_metricsjava.lang.Float_spacing-
Fields inherited from class io.github.humbleui.skija.impl.Managed
_cleanable
-
-
Constructor Summary
Constructors Constructor Description Font()Returns Font initialized with default valuesFont(long ptr)Font(long ptr, boolean managed)Font(@Nullable Typeface typeface)Returns Font with Typeface and default sizeFont(@Nullable Typeface typeface, float size)Font(@Nullable Typeface typeface, float size, float scaleX, float skewX)Constructs Font with default values with Typeface and size in points, horizontal scale, and horizontal skew.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static boolean_nAreBitmapsEmbedded(long ptr)static boolean_nAreMetricsLinear(long ptr)boolean_nativeEquals(Native other)Compares fonts, and returns true if they are equivalent.static boolean_nEquals(long ptr, long otherPtr)static io.github.humbleui.types.Rect[]_nGetBounds(long ptr, short[] glyphs, long paintPtr)static int_nGetEdging(long ptr)static long_nGetFinalizer()static int_nGetHinting(long ptr)static FontMetrics_nGetMetrics(long ptr)static long_nGetPath(long ptr, short glyph)static Path[]_nGetPaths(long ptr, short[] glyphs)static io.github.humbleui.types.Point[]_nGetPositions(long ptr, short[] glyphs, float x, float y)static float_nGetScaleX(long ptr)static float_nGetSize(long ptr)static float_nGetSkewX(long ptr)static float_nGetSpacing(long ptr)static short[]_nGetStringGlyphs(long ptr, java.lang.String str)static int_nGetStringGlyphsCount(long ptr, java.lang.String str)static long_nGetTypeface(long ptr)static long_nGetTypefaceOrDefault(long ptr)static short_nGetUTF32Glyph(long ptr, int uni)static short[]_nGetUTF32Glyphs(long ptr, int[] uni)static float[]_nGetWidths(long ptr, short[] glyphs)static float[]_nGetXPositions(long ptr, short[] glyphs, float x)static boolean_nIsAutoHintingForced(long ptr)static boolean_nIsBaselineSnapped(long ptr)static boolean_nIsEmboldened(long ptr)static boolean_nIsSubpixel(long ptr)static long_nMakeClone(long ptr)static long_nMakeDefault()static long_nMakeTypeface(long typefacePtr)static long_nMakeTypefaceSize(long typefacePtr, float size)static long_nMakeTypefaceSizeScaleSkew(long typefacePtr, float size, float scaleX, float skewX)static io.github.humbleui.types.Rect_nMeasureText(long ptr, java.lang.String str, long paintPtr)static float_nMeasureTextWidth(long ptr, java.lang.String str, long paintPtr)static void_nSetAutoHintingForced(long ptr, boolean value)static void_nSetBaselineSnapped(long ptr, boolean value)static void_nSetBitmapsEmbedded(long ptr, boolean value)static void_nSetEdging(long ptr, int value)static void_nSetEmboldened(long ptr, boolean value)static void_nSetHinting(long ptr, int value)static void_nSetMetricsLinear(long ptr, boolean value)static void_nSetScaleX(long ptr, float value)static void_nSetSize(long ptr, float value)static void_nSetSkewX(long ptr, float value)static void_nSetSubpixel(long ptr, boolean value)static void_nSetTypeface(long ptr, long typefacePtr)void_resetMetrics()booleanareBitmapsEmbedded()booleanareMetricsLinear()io.github.humbleui.types.Rect[]getBounds(short[] glyphs)Retrieves the bounds for each glyphio.github.humbleui.types.Rect[]getBounds(short[] glyphs, Paint p)Retrieves the bounds for each glyphFontEdginggetEdging()Whether edge pixels draw opaque or with partial transparency.FontHintinggetHinting()@NotNull FontMetricsgetMetrics()Returns FontMetrics associated with Typeface.@Nullable PathgetPath(short glyph)If the glyph has an outline, returns it.Path[]getPaths(short[] glyphs)Return glyph outlines, some of which might be null.io.github.humbleui.types.Point[]getPositions(short[] glyphs)Retrieves the positions for each glyph.io.github.humbleui.types.Point[]getPositions(short[] glyphs, io.github.humbleui.types.Point offset)Retrieves the positions for each glyph, beginning at the specified origin.floatgetScaleX()floatgetSize()floatgetSkewX()floatgetSpacing()Returns the recommended spacing between lines: the sum of metrics descent, ascent, and leading.short[]getStringGlyphs(java.lang.String s)Converts text into glyph indices.intgetStringGlyphsCount(java.lang.String s)@Nullable TypefacegetTypeface()@NotNull TypefacegetTypefaceOrDefault()shortgetUTF32Glyph(int unichar)short[]getUTF32Glyphs(int[] uni)Given an array of UTF32 character codes, return their corresponding glyph IDs.float[]getWidths(short[] glyphs)Retrieves the advances for each glyphfloat[]getXPositions(short[] glyphs)Retrieves the x-positions for each glyph.float[]getXPositions(short[] glyphs, float offset)Retrieves the x-positions for each glyph, beginning at the specified origin.booleanisAutoHintingForced()If true, instructs the font manager to always hint glyphs.booleanisBaselineSnapped()Returns true if baselines will be snapped to pixel positions when the current transformation matrix is axis aligned.booleanisEmboldened()Returns true if bold is approximated by increasing the stroke width when creating glyph bitmaps from outlines.booleanisSubpixel()static FontmakeClone(long ptr)FontmakeWithSize(float size)Returns a font with the same attributes of this font, but with the specified size.io.github.humbleui.types.RectmeasureText(java.lang.String s)io.github.humbleui.types.RectmeasureText(java.lang.String s, Paint p)floatmeasureTextWidth(java.lang.String s)floatmeasureTextWidth(java.lang.String s, Paint p)FontsetAutoHintingForced(boolean value)Sets whether to always hint glyphs.FontsetBaselineSnapped(boolean value)Requests that baselines be snapped to pixels when the current transformation matrix is axis aligned.FontsetBitmapsEmbedded(boolean value)Requests, but does not require, to use bitmaps in fonts instead of outlines.FontsetEdging(FontEdging value)Requests, but does not require, that edge pixels draw opaque or with partial transparency.FontsetEmboldened(boolean value)Increases stroke width when creating glyph bitmaps to approximate a bold typeface.FontsetHinting(FontHinting value)Sets level of glyph outline adjustment.FontsetMetricsLinear(boolean value)Requests, but does not require, linearly scalable font and glyph metrics.FontsetScaleX(float value)Sets text scale on x-axis.FontsetSize(float value)Sets text size in points.FontsetSkewX(float value)Sets text skew on x-axis.FontsetSubpixel(boolean value)Requests, but does not require, that glyphs respect sub-pixel positioning.FontsetTypeface(@Nullable Typeface typeface)Sets Typeface to typeface.-
Methods inherited from class io.github.humbleui.skija.impl.Managed
_nInvokeFinalizer, close, isClosed
-
-
-
-
Field Detail
-
_metrics
@Internal public FontMetrics _metrics
-
_spacing
@Internal public java.lang.Float _spacing
-
-
Constructor Detail
-
Font
@Internal public Font(long ptr)
-
Font
@Internal public Font(long ptr, boolean managed)
-
Font
public Font()
Returns Font initialized with default values
-
Font
public Font(@Nullable @Nullable Typeface typeface)Returns Font with Typeface and default size- Parameters:
typeface- typeface and style used to draw and measure text. Pass null for default
-
Font
public Font(@Nullable @Nullable Typeface typeface, float size)- Parameters:
typeface- typeface and style used to draw and measure text. Pass null for defaultsize- typographic size of the text
-
Font
public Font(@Nullable @Nullable Typeface typeface, float size, float scaleX, float skewX)Constructs Font with default values with Typeface and size in points, horizontal scale, and horizontal skew. Horizontal scale emulates condensed and expanded fonts. Horizontal skew emulates oblique fonts.- Parameters:
typeface- typeface and style used to draw and measure text. Pass null for defaultsize- typographic size of the textscaleX- text horizonral scaleskewX- additional shear on x-axis relative to y-axis
-
-
Method Detail
-
_nativeEquals
@Internal public boolean _nativeEquals(Native other)
Compares fonts, and returns true if they are equivalent. May return false if Typeface has identical contents but different pointers.- Overrides:
_nativeEqualsin classNative
-
_resetMetrics
@Internal public void _resetMetrics()
-
makeClone
@Internal public static Font makeClone(long ptr)
-
isAutoHintingForced
public boolean isAutoHintingForced()
If true, instructs the font manager to always hint glyphs. Returned value is only meaningful if platform uses FreeType as the font manager.- Returns:
- true if all glyphs are hinted
-
areBitmapsEmbedded
public boolean areBitmapsEmbedded()
- Returns:
- true if font engine may return glyphs from font bitmaps instead of from outlines
-
isSubpixel
public boolean isSubpixel()
- Returns:
- true if glyphs may be drawn at sub-pixel offsets
-
areMetricsLinear
public boolean areMetricsLinear()
- Returns:
- true if font and glyph metrics are requested to be linearly scalable
-
isEmboldened
public boolean isEmboldened()
Returns true if bold is approximated by increasing the stroke width when creating glyph bitmaps from outlines.- Returns:
- true if bold is approximated through stroke width
-
isBaselineSnapped
public boolean isBaselineSnapped()
Returns true if baselines will be snapped to pixel positions when the current transformation matrix is axis aligned.- Returns:
- true if baselines may be snapped to pixels
-
setAutoHintingForced
public Font setAutoHintingForced(boolean value)
Sets whether to always hint glyphs. If forceAutoHinting is set, instructs the font manager to always hint glyphs. Only affects platforms that use FreeType as the font manager.- Parameters:
value- setting to always hint glyphs- Returns:
- this
-
setBitmapsEmbedded
public Font setBitmapsEmbedded(boolean value)
Requests, but does not require, to use bitmaps in fonts instead of outlines.- Parameters:
value- setting to use bitmaps in fonts- Returns:
- this
-
setSubpixel
public Font setSubpixel(boolean value)
Requests, but does not require, that glyphs respect sub-pixel positioning.- Parameters:
value- setting for sub-pixel positioning- Returns:
- this
-
setMetricsLinear
public Font setMetricsLinear(boolean value)
Requests, but does not require, linearly scalable font and glyph metrics. For outline fonts 'true' means font and glyph metrics should ignore hinting and rounding. Note that some bitmap formats may not be able to scale linearly and will ignore this flag.- Parameters:
value- setting for linearly scalable font and glyph metrics.- Returns:
- this
-
setEmboldened
public Font setEmboldened(boolean value)
Increases stroke width when creating glyph bitmaps to approximate a bold typeface.- Parameters:
value- setting for bold approximation- Returns:
- this
-
setBaselineSnapped
public Font setBaselineSnapped(boolean value)
Requests that baselines be snapped to pixels when the current transformation matrix is axis aligned.- Parameters:
value- setting for baseline snapping to pixels- Returns:
- this
-
getEdging
public FontEdging getEdging()
Whether edge pixels draw opaque or with partial transparency.
-
setEdging
public Font setEdging(FontEdging value)
Requests, but does not require, that edge pixels draw opaque or with partial transparency.
-
getHinting
public FontHinting getHinting()
- Returns:
- level of glyph outline adjustment
-
setHinting
public Font setHinting(FontHinting value)
Sets level of glyph outline adjustment. Does not check for valid values of hintingLevel.
-
makeWithSize
public Font makeWithSize(float size)
Returns a font with the same attributes of this font, but with the specified size.
-
getTypefaceOrDefault
@NotNull public @NotNull Typeface getTypefaceOrDefault()
- Returns:
Typefaceif set, or the default typeface.
-
getSize
public float getSize()
- Returns:
- text size in points
-
getScaleX
public float getScaleX()
- Returns:
- text scale on x-axis. Default value is 1
-
getSkewX
public float getSkewX()
- Returns:
- text skew on x-axis. Default value is 0
-
setTypeface
public Font setTypeface(@Nullable @Nullable Typeface typeface)
Sets Typeface to typeface. Pass null to use the default typeface.
-
setSize
public Font setSize(float value)
Sets text size in points. Has no effect if value is not greater than or equal to zero.
-
setScaleX
public Font setScaleX(float value)
Sets text scale on x-axis. Default value is 1.
-
setSkewX
public Font setSkewX(float value)
Sets text skew on x-axis. Default value is 0.
-
getStringGlyphs
public short[] getStringGlyphs(java.lang.String s)
Converts text into glyph indices.- Returns:
- the corresponding glyph ids for each character.
-
getUTF32Glyphs
public short[] getUTF32Glyphs(int[] uni)
Given an array of UTF32 character codes, return their corresponding glyph IDs.- Returns:
- the corresponding glyph IDs for each character.
-
getUTF32Glyph
public short getUTF32Glyph(int unichar)
- Returns:
- the glyph that corresponds to the specified unicode code-point (in UTF32 encoding). If the unichar is not supported, returns 0
-
getStringGlyphsCount
public int getStringGlyphsCount(java.lang.String s)
- Returns:
- number of glyphs represented by text
-
measureText
public io.github.humbleui.types.Rect measureText(java.lang.String s)
- Returns:
- the bounding box of text
-
measureText
public io.github.humbleui.types.Rect measureText(java.lang.String s, Paint p)- Parameters:
p- stroke width or PathEffect may modify the advance with- Returns:
- the bounding box of text
-
measureTextWidth
public float measureTextWidth(java.lang.String s)
-
measureTextWidth
public float measureTextWidth(java.lang.String s, Paint p)
-
getWidths
public float[] getWidths(short[] glyphs)
Retrieves the advances for each glyph
-
getBounds
public io.github.humbleui.types.Rect[] getBounds(short[] glyphs)
Retrieves the bounds for each glyph
-
getBounds
public io.github.humbleui.types.Rect[] getBounds(short[] glyphs, Paint p)Retrieves the bounds for each glyph
-
getPositions
public io.github.humbleui.types.Point[] getPositions(short[] glyphs)
Retrieves the positions for each glyph.
-
getPositions
public io.github.humbleui.types.Point[] getPositions(short[] glyphs, io.github.humbleui.types.Point offset)Retrieves the positions for each glyph, beginning at the specified origin.
-
getXPositions
public float[] getXPositions(short[] glyphs)
Retrieves the x-positions for each glyph.
-
getXPositions
public float[] getXPositions(short[] glyphs, float offset)Retrieves the x-positions for each glyph, beginning at the specified origin.
-
getPath
@Nullable public @Nullable Path getPath(short glyph)
If the glyph has an outline, returns it. The glyph outline may be empty. Degenerate contours in the glyph outline will be skipped. If glyph is described by a bitmap, returns null.
-
getPaths
public Path[] getPaths(short[] glyphs)
Return glyph outlines, some of which might be null.
-
getMetrics
@NotNull public @NotNull FontMetrics getMetrics()
Returns FontMetrics associated with Typeface. Results are scaled by text size but does not take into account dimensions required by text scale, text skew, fake bold, style stroke, andPathEffect.
-
getSpacing
public float getSpacing()
Returns the recommended spacing between lines: the sum of metrics descent, ascent, and leading. Result is scaled by text size but does not take into account dimensions required by stroking and SkPathEffect.
-
_nGetFinalizer
@Internal public static long _nGetFinalizer()
-
_nMakeDefault
@Internal public static long _nMakeDefault()
-
_nMakeTypeface
@Internal public static long _nMakeTypeface(long typefacePtr)
-
_nMakeTypefaceSize
@Internal public static long _nMakeTypefaceSize(long typefacePtr, float size)
-
_nMakeTypefaceSizeScaleSkew
@Internal public static long _nMakeTypefaceSizeScaleSkew(long typefacePtr, float size, float scaleX, float skewX)
-
_nMakeClone
@Internal public static long _nMakeClone(long ptr)
-
_nEquals
@Internal public static boolean _nEquals(long ptr, long otherPtr)
-
_nIsAutoHintingForced
@Internal public static boolean _nIsAutoHintingForced(long ptr)
-
_nAreBitmapsEmbedded
@Internal public static boolean _nAreBitmapsEmbedded(long ptr)
-
_nIsSubpixel
@Internal public static boolean _nIsSubpixel(long ptr)
-
_nAreMetricsLinear
@Internal public static boolean _nAreMetricsLinear(long ptr)
-
_nIsEmboldened
@Internal public static boolean _nIsEmboldened(long ptr)
-
_nIsBaselineSnapped
@Internal public static boolean _nIsBaselineSnapped(long ptr)
-
_nSetAutoHintingForced
@Internal public static void _nSetAutoHintingForced(long ptr, boolean value)
-
_nSetBitmapsEmbedded
@Internal public static void _nSetBitmapsEmbedded(long ptr, boolean value)
-
_nSetSubpixel
@Internal public static void _nSetSubpixel(long ptr, boolean value)
-
_nSetMetricsLinear
@Internal public static void _nSetMetricsLinear(long ptr, boolean value)
-
_nSetEmboldened
@Internal public static void _nSetEmboldened(long ptr, boolean value)
-
_nSetBaselineSnapped
@Internal public static void _nSetBaselineSnapped(long ptr, boolean value)
-
_nGetEdging
@Internal public static int _nGetEdging(long ptr)
-
_nSetEdging
@Internal public static void _nSetEdging(long ptr, int value)
-
_nGetHinting
@Internal public static int _nGetHinting(long ptr)
-
_nSetHinting
@Internal public static void _nSetHinting(long ptr, int value)
-
_nGetTypeface
@Internal public static long _nGetTypeface(long ptr)
-
_nGetTypefaceOrDefault
@Internal public static long _nGetTypefaceOrDefault(long ptr)
-
_nGetSize
@Internal public static float _nGetSize(long ptr)
-
_nGetScaleX
@Internal public static float _nGetScaleX(long ptr)
-
_nGetSkewX
@Internal public static float _nGetSkewX(long ptr)
-
_nSetTypeface
@Internal public static void _nSetTypeface(long ptr, long typefacePtr)
-
_nSetSize
@Internal public static void _nSetSize(long ptr, float value)
-
_nSetScaleX
@Internal public static void _nSetScaleX(long ptr, float value)
-
_nSetSkewX
@Internal public static void _nSetSkewX(long ptr, float value)
-
_nGetStringGlyphs
@Internal public static short[] _nGetStringGlyphs(long ptr, java.lang.String str)
-
_nGetUTF32Glyph
@Internal public static short _nGetUTF32Glyph(long ptr, int uni)
-
_nGetUTF32Glyphs
@Internal public static short[] _nGetUTF32Glyphs(long ptr, int[] uni)
-
_nGetStringGlyphsCount
@Internal public static int _nGetStringGlyphsCount(long ptr, java.lang.String str)
-
_nMeasureText
@Internal public static io.github.humbleui.types.Rect _nMeasureText(long ptr, java.lang.String str, long paintPtr)
-
_nMeasureTextWidth
@Internal public static float _nMeasureTextWidth(long ptr, java.lang.String str, long paintPtr)
-
_nGetWidths
@Internal public static float[] _nGetWidths(long ptr, short[] glyphs)
-
_nGetBounds
@Internal public static io.github.humbleui.types.Rect[] _nGetBounds(long ptr, short[] glyphs, long paintPtr)
-
_nGetPositions
@Internal public static io.github.humbleui.types.Point[] _nGetPositions(long ptr, short[] glyphs, float x, float y)
-
_nGetXPositions
@Internal public static float[] _nGetXPositions(long ptr, short[] glyphs, float x)
-
_nGetPath
@Internal public static long _nGetPath(long ptr, short glyph)
-
_nGetPaths
@Internal public static Path[] _nGetPaths(long ptr, short[] glyphs)
-
_nGetMetrics
@Internal public static FontMetrics _nGetMetrics(long ptr)
-
_nGetSpacing
@Internal public static float _nGetSpacing(long ptr)
-
-