Class GlyphRun

java.lang.Object
com.mta.tehreer.layout.GlyphRun

public class GlyphRun extends Object
A GlyphRun object is a collection of consecutive glyphs sharing the same attributes and direction.
  • Method Details

    • getCharStart

      public int getCharStart()
      Returns the index to the first character of this run in source text.
      Returns:
      The index to the first character of this run in source text.
    • getCharEnd

      public int getCharEnd()
      Returns the index after the last character of this run in source text.
      Returns:
      The index after the last character of this run in source text.
    • getStartExtraLength

      public int getStartExtraLength()
      Returns the extra excluded length at the start of the cluster map. If the first cluster of this run begins within the extra range, then its rendering will be clipped from the start. The amount of clipping would be equal to the perceived trailing caret position of last excluded character.

      For example, consider three characters `f`, `i` and another `i` form a cluster having a single ligature, `fii` and the run starts from the second `i` with `f` and `i` being extra characters. In this case, the ligature would be divided into three equal parts and the first two parts would be clipped.

      Returns:
      The extra excluded length at the start of the cluster map.
      See Also:
    • getEndExtraLength

      public int getEndExtraLength()
      Returns the extra excluded length at the end of the cluster map. If the last cluster of this run finishes within the excluded range, then its rendering will be clipped from the end. The amount of clipping would be equal to the perceived leading caret position of first excluded character.

      For example, consider three characters `f`, `i` and another `i` form a cluster having a single ligature, `fii` and the run consists of just `f` with both `i` being extra characters. In this case, the ligature would be divided into three equal parts and the last two parts would be clipped.

      Returns:
      The extra excluded length at the end of the cluster map.
      See Also:
    • getBidiLevel

      public byte getBidiLevel()
      Returns the bidirectional level of this run.
      Returns:
      The bidirectional level of this run.
    • getTypeface

      @NonNull public Typeface getTypeface()
      Returns the typeface of this run.
      Returns:
      The typeface of this run.
    • getTypeSize

      public float getTypeSize()
      Returns the type size of this run.
      Returns:
      The type size of this run.
    • getWritingDirection

      @NonNull public WritingDirection getWritingDirection()
      Returns the writing direction of this run.
      Returns:
      The writing direction of this run.
    • getGlyphCount

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

      @NonNull public IntList getGlyphIds()
      Returns a list of glyph IDs in this run.
      Returns:
      A list of glyph IDs in this run.
    • getGlyphOffsets

      @NonNull public PointList getGlyphOffsets()
      Returns a list of glyph offsets in this run.
      Returns:
      A list of glyph offsets in this run.
    • getGlyphAdvances

      @NonNull public FloatList getGlyphAdvances()
      Returns a list of glyph advances in this run.
      Returns:
      A list of glyph advances in this run.
    • getClusterMap

      @NonNull public IntList getClusterMap()
      Returns a list of indexes, mapping each character in this run to corresponding glyph.
      Returns:
      A list of indexes, mapping each character in this run to corresponding glyph.
    • getOriginX

      public float getOriginX()
      Returns the x- origin of this run in parent line.
      Returns:
      The x- origin of this run in parent line.
    • getOriginY

      public float getOriginY()
      Returns the y- origin of this run in parent line.
      Returns:
      The y- origin of this run in parent line.
    • getAscent

      public float getAscent()
      Returns the ascent of this run. The ascent is the distance from the top of the GlyphRun to the baseline. It is always either positive or zero.
      Returns:
      The ascent of this run.
    • getDescent

      public float getDescent()
      Returns the descent of this run. The descent is the distance from the baseline to the bottom of the GlyphRun. It is always either positive or zero.
      Returns:
      The descent of this run.
    • getLeading

      public float getLeading()
      Returns the leading of this run. The leading is the distance that should be placed between two lines.
      Returns:
      The leading of this run.
    • getWidth

      public float getWidth()
      Returns the typographic width of this run.
      Returns:
      The typographic width of this run.
    • getHeight

      public float getHeight()
      Returns the typographic height of this run.
      Returns:
      The typographic height of this run.
    • getActualClusterStart

      public int getActualClusterStart(int charIndex)
      Returns the index to the first character of specified cluster in source string. In most cases, it would be the same index as the specified one. But if the character occurs within a cluster, then a previous index would be returned; whether the run logically flows forward or backward.
      Parameters:
      charIndex - The index of a character in source string.
      Returns:
      The index to the first character of specified cluster in source string.
      Throws:
      IllegalArgumentException - if charIndex is less than run start or greater than or equal to run end.
    • getActualClusterEnd

      public int getActualClusterEnd(int charIndex)
      Returns the index after the last character of specified cluster in source string. In most cases, it would be an index after the specified one. But if the character occurs within a cluster, then a farther index would be returned; whether the run logically flows forward or backward.
      Parameters:
      charIndex - The index of a character in source string.
      Returns:
      The index after the last character of specified cluster in source string.
      Throws:
      IllegalArgumentException - if charIndex is less than run start or greater than or equal to run end.
    • getLeadingGlyphIndex

      public int getLeadingGlyphIndex(int charIndex)
      Returns the index of leading glyph related to the specified cluster. It will come after the trailing glyph, if the characters of this run logically flow backward.
      Parameters:
      charIndex - The index of a character in source string.
      Returns:
      The index of leading glyph related to the specified cluster.
      Throws:
      IllegalArgumentException - if charIndex is less than run start or greater than or equal to run end.
      See Also:
    • getTrailingGlyphIndex

      public int getTrailingGlyphIndex(int charIndex)
      Returns the index of trailing glyph related to the specified cluster. It will come before the leading glyph, if the characters of this run logically flow backward.
      Parameters:
      charIndex - The index of a character in source string.
      Returns:
      The index of trailing glyph related to the specified cluster.
      Throws:
      IllegalArgumentException - if charIndex is less than run start or greater than or equal to run end.
      See Also:
    • computeCharDistance

      public float computeCharDistance(int charIndex)
      Determines the distance of specified character from the start of the run assumed at zero.
      Parameters:
      charIndex - The index of a character in source string.
      Returns:
      The distance of specified character from the start of the run assumed at zero.
      Throws:
      IllegalArgumentException - if charIndex is less than run start or greater than run end.
    • computeNearestCharIndex

      public int computeNearestCharIndex(float distance)
      Determines the index of character nearest to the specified distance.

      The process involves iterating over the clusters of this glyph run. If a cluster consists of multiple characters, its total advance is evenly distributed among the number of characters it contains. The advance of each character is added to track the covered distance. This way leading and trailing characters are determined close to the specified distance. Afterwards, the index of nearer character is returned.

      If distance is negative, then run's starting index is returned. If it is beyond run's extent, then ending index is returned. The indices will be reversed in case of right-to-left run.

      Parameters:
      distance - The distance for which to determine the character index. It should be offset from zero origin.
      Returns:
      The index of character nearest to the specified distance. It will be an absolute index in source string.
      See Also:
    • computeBoundingBox

      @NonNull public RectF computeBoundingBox(@NonNull Renderer renderer, int glyphStart, int glyphEnd)
      Calculates the bounding box for the given glyph range in this run. The bounding box is a rectangle that encloses the paths of this run's glyphs in the given range, as tightly as possible.
      Parameters:
      renderer - The renderer to use for calculating the bounding box. This is required because the renderer could have settings in it that would cause changes in the bounding box.
      glyphStart - The index to the first glyph being measured.
      glyphEnd - The index after the last glyph being measured.
      Returns:
      A rectangle that tightly encloses the paths of this run's glyphs in the given range.
      Throws:
      IllegalArgumentException - if glyphStart is negative, or glyphEnd is greater than total number of glyphs in the run, or glyphStart is greater than glyphEnd.
    • draw

      public void draw(@NonNull Renderer renderer, @NonNull Canvas canvas)
      Draws this run completely onto the given canvas using the given renderer.
      Parameters:
      renderer - The renderer to use for drawing this run.
      canvas - The canvas onto which to draw this run.
    • toString

      public String toString()
      Overrides:
      toString in class Object