Class Font

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class Font
    extends Managed
    • Field Detail

      • _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 default
        size - 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 default
        size - typographic size of the text
        scaleX - text horizonral scale
        skewX - 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:
        _nativeEquals in class Native
      • _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.
      • getTypeface

        @Nullable
        public @Nullable Typeface getTypeface()
        Returns:
        Typeface if set, or null
      • getTypefaceOrDefault

        @NotNull
        public @NotNull Typeface getTypefaceOrDefault()
        Returns:
        Typeface if 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, and PathEffect.
      • 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)