Package com.mta.tehreer.graphics
Class Typeface
java.lang.Object
com.mta.tehreer.graphics.Typeface
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 Summary
ConstructorsConstructorDescriptionTypeface(AssetManager assetManager, String filePath) Constructs a typeface from the specified asset.Constructs a typeface from the specified file.Typeface(InputStream stream) Constructs a new typeface from the input stream by copying its data into a native memory buffer. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the typographic ascender of this typeface expressed in font units.int[]Returns the colors associated with this typeface if it supports OpenType color palettes.Returns the font bounding box expressed in font units.getColorInstance(int[] colors) Returns a color instance of this typeface with the specified colors array.intReturns the typographic descender of this typeface expressed in font units.Returns the family name of this typeface.Returns the full name of this typeface.floatgetGlyphAdvance(int glyphId, float typeSize, boolean vertical) Retrieves the advance for the specified glyph.intReturns the number of glyphs in this typeface.intgetGlyphId(int codePoint) Returns the glyph id for the specified code point.getGlyphPath(int glyphId, float typeSize, Matrix matrix) Generates the path for the specified glyph.intReturns the typographic leading of this typeface expressed in font units.Returns the named instance records of this typeface if it supports OpenType font variations.Returns the names associated with palette entries if this typeface supports OpenType color palettes.Returns the predefined palettes in this typeface if it supports OpenType color palettes.getSlope()Returns the typographic slope of this typeface.intReturns the position, in font units, of the strikeout for this typeface.intReturns the thickness, in font units, of the strikeout for this typeface.Returns the style name of this typeface.byte[]getTableData(int tableTag) Generates an array of bytes containing the data of the intended table.intReturns the position, in font units, of the underline for this typeface.intReturns the thickness, in font units, of the underline for this typeface.intReturns the number of font units per EM square for this typeface.Returns the variation axes of this typeface if it supports OpenType font variations.float[]Returns the design variation coordinates of this typeface if it supports OpenType font variations.getVariationInstance(float[] coordinates) Returns a variation instance of this typeface with the specified design coordinates.Returns the typographic weight of this typeface.getWidth()Returns the typographic width of this typeface.booleanReturnstrueif this typeface supports OpenType font variations.toString()
-
Constructor Details
-
Typeface
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- ifassetManagerorfilePathis null.RuntimeException- if an error occurred while initialization.
-
Typeface
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- iffileis null.RuntimeException- if an error occurred while initialization.
-
Typeface
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- ifstreamis null.RuntimeException- if an error occurred while initialization.
-
-
Method Details
-
isVariable
public boolean isVariable()Returnstrueif this typeface supports OpenType font variations.- Returns:
trueif this typeface supports OpenType font variations.
-
getVariationInstance
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- ifcoordinatesparameter is null.IllegalArgumentException- if the number of specified design coordinates does not match the number of variation axes.
-
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
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
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
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
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- ifcolorsparameter is null.IllegalArgumentException- if the number of specified colors does not match the number of colors in `CPAL` table.
-
getFamilyName
Returns the family name of this typeface.- Returns:
- The family name of this typeface.
-
getStyleName
Returns the style name of this typeface.- Returns:
- The style name of this typeface.
-
getFullName
Returns the full name of this typeface.- Returns:
- The full name of this typeface.
-
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
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
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 usingSfntTag.make(String)method.- Returns:
- An array of bytes containing the data of the table, or
nullif 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
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 benullif no transformation is required.- Returns:
- The path for the specified glyph.
-
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
-