Class Typeface

java.lang.Object
com.mta.tehreer.graphics.Typeface

public class Typeface extends Object
The Typeface class specifies the typeface and intrinsic style of a font. This is used in the renderer, along with optionally Renderer settings like typeSize, slantAngle, scaleX, to specify how text appears when drawn (and measured).
  • Constructor Details

    • Typeface

      public Typeface(@NonNull AssetManager assetManager, @NonNull String filePath)
      Constructs a typeface from the specified asset. The data of the asset is not copied into the memory. Rather, it is directly read from the stream when needed. So the performance of resulting typeface might be slower and should be used with caution.
      Parameters:
      assetManager - The application's asset manager.
      filePath - The path of the font file in the assets directory.
      Throws:
      NullPointerException - if assetManager or filePath is null.
      RuntimeException - if an error occurred while initialization.
    • Typeface

      public Typeface(@NonNull File file)
      Constructs a typeface from the specified file. The data for the font is directly read from the file when needed.
      Parameters:
      file - The font file.
      Throws:
      NullPointerException - if file is null.
      RuntimeException - if an error occurred while initialization.
    • Typeface

      public Typeface(@NonNull InputStream stream)
      Constructs a new typeface from the input stream by copying its data into a native memory buffer. It may take time to create the typeface if the stream holds larger data.
      Parameters:
      stream - The input stream that contains the data of the font.
      Throws:
      NullPointerException - if stream is null.
      RuntimeException - if an error occurred while initialization.
  • Method Details

    • isVariable

      public boolean isVariable()
      Returns true if this typeface supports OpenType font variations.
      Returns:
      true if this typeface supports OpenType font variations.
    • getVariationInstance

      @Nullable public Typeface getVariationInstance(@NonNull float[] coordinates)
      Returns a variation instance of this typeface with the specified design coordinates.
      Parameters:
      coordinates - The variation design coordinates.
      Returns:
      A variation instance of this typeface with the specified design coordinates.
      Throws:
      IllegalStateException - if this typeface does not support OpenType font variations.
      NullPointerException - if coordinates parameter is null.
      IllegalArgumentException - if the number of specified design coordinates does not match the number of variation axes.
    • getVariationAxes

      @Nullable public List<VariationAxis> getVariationAxes()
      Returns the variation axes of this typeface if it supports OpenType font variations.
      Returns:
      The variation axes of this typeface if it supports OpenType font variations.
    • getNamedStyles

      @Nullable public List<NamedStyle> getNamedStyles()
      Returns the named instance records of this typeface if it supports OpenType font variations.
      Returns:
      The named instance records of this typeface if it supports OpenType font variations.
    • getVariationCoordinates

      @Nullable public float[] getVariationCoordinates()
      Returns the design variation coordinates of this typeface if it supports OpenType font variations.
      Returns:
      The design variation coordinates of this typeface if it supports OpenType font variations.
    • getPaletteEntryNames

      @Nullable public List<String> getPaletteEntryNames()
      Returns the names associated with palette entries if this typeface supports OpenType color palettes.
      Returns:
      The names associated with palette entries if this typeface supports OpenType color palettes.
    • getPredefinedPalettes

      @Nullable public List<ColorPalette> getPredefinedPalettes()
      Returns the predefined palettes in this typeface if it supports OpenType color palettes.
      Returns:
      The predefined palettes in this typeface if it supports OpenType color palettes.
    • getAssociatedColors

      @Nullable public int[] getAssociatedColors()
      Returns the colors associated with this typeface if it supports OpenType color palettes.
      Returns:
      The colors associated with this typeface if it supports OpenType color palettes.
    • getColorInstance

      @Nullable public Typeface getColorInstance(@NonNull int[] colors)
      Returns a color instance of this typeface with the specified colors array.
      Parameters:
      colors - The colors array.
      Returns:
      A color instance of this typeface with the specified colors array.
      Throws:
      IllegalStateException - if this typeface does not support OpenType color palettes.
      NullPointerException - if colors parameter is null.
      IllegalArgumentException - if the number of specified colors does not match the number of colors in `CPAL` table.
    • getFamilyName

      public String getFamilyName()
      Returns the family name of this typeface.
      Returns:
      The family name of this typeface.
    • getStyleName

      public String getStyleName()
      Returns the style name of this typeface.
      Returns:
      The style name of this typeface.
    • getFullName

      public String getFullName()
      Returns the full name of this typeface.
      Returns:
      The full name of this typeface.
    • getWeight

      @NonNull public TypeWeight getWeight()
      Returns the typographic weight of this typeface. The weight value determines the thickness associated with a given character in a typeface.
      Returns:
      The typographic weight of this typeface.
    • getWidth

      @NonNull public TypeWidth getWidth()
      Returns the typographic width of this typeface. The width value determines whether a typeface is expanded or condensed when it is displayed.
      Returns:
      The typographic width of this typeface.
    • getSlope

      @NonNull public TypeSlope getSlope()
      Returns the typographic slope of this typeface. The slope value determines whether a typeface is plain or slanted when it is displayed.
      Returns:
      The typographic slope of this typeface.
    • getTableData

      @Nullable public byte[] getTableData(int tableTag)
      Generates an array of bytes containing the data of the intended table.
      Parameters:
      tableTag - The tag of the table as an integer. It can be created from string by using SfntTag.make(String) method.
      Returns:
      An array of bytes containing the data of the table, or null if no such table exists.
    • getUnitsPerEm

      public int getUnitsPerEm()
      Returns the number of font units per EM square for this typeface.
      Returns:
      The number of font units per EM square for this typeface.
    • getAscent

      public int getAscent()
      Returns the typographic ascender of this typeface expressed in font units.
      Returns:
      The typographic ascender of this typeface expressed in font units.
    • getDescent

      public int getDescent()
      Returns the typographic descender of this typeface expressed in font units.
      Returns:
      The typographic descender of this typeface expressed in font units.
    • getLeading

      public int getLeading()
      Returns the typographic leading of this typeface expressed in font units.
      Returns:
      The typographic leading of this typeface expressed in font units.
    • getGlyphCount

      public int getGlyphCount()
      Returns the number of glyphs in this typeface.
      Returns:
      The number of glyphs in this typeface.
    • getGlyphId

      public int getGlyphId(int codePoint)
      Returns the glyph id for the specified code point.
      Parameters:
      codePoint - The code point for which the glyph id is obtained.
      Returns:
      The glyph id for the specified code point.
    • getGlyphAdvance

      public float getGlyphAdvance(int glyphId, float typeSize, boolean vertical)
      Retrieves the advance for the specified glyph.
      Parameters:
      glyphId - The glyph id for which to retrieve the advance.
      typeSize - The size for which the advance is retrieved.
      vertical - The flag which indicates the type of advance, either horizontal or vertical.
      Returns:
      The advance for the specified glyph.
    • getGlyphPath

      @NonNull public Path getGlyphPath(int glyphId, float typeSize, @Nullable Matrix matrix)
      Generates the path for the specified glyph.
      Parameters:
      glyphId - The glyph id for which the path is generated.
      typeSize - The size for which the glyph path is required.
      matrix - The matrix applied to the path. Can be null if no transformation is required.
      Returns:
      The path for the specified glyph.
    • getBoundingBox

      @NonNull public Rect getBoundingBox()
      Returns the font bounding box expressed in font units. The box is large enough to contain any glyph from the font.
      Returns:
      The font bounding box expressed in font units.
    • getUnderlinePosition

      public int getUnderlinePosition()
      Returns the position, in font units, of the underline for this typeface.
      Returns:
      The position, in font units, of the underline for this typeface.
    • getUnderlineThickness

      public int getUnderlineThickness()
      Returns the thickness, in font units, of the underline for this typeface.
      Returns:
      The thickness, in font units, of the underline for this typeface.
    • getStrikeoutPosition

      public int getStrikeoutPosition()
      Returns the position, in font units, of the strikeout for this typeface.
      Returns:
      The position, in font units, of the strikeout for this typeface.
    • getStrikeoutThickness

      public int getStrikeoutThickness()
      Returns the thickness, in font units, of the strikeout for this typeface.
      Returns:
      The thickness, in font units, of the strikeout for this typeface.
    • toString

      public String toString()
      Overrides:
      toString in class Object