Class Renderer

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

public class Renderer extends Object
The Renderer class represents a generic glyph renderer. It can be used to generate glyph paths, measure their bounding boxes and draw them on a Canvas object.
  • Constructor Details

    • Renderer

      public Renderer()
      Constructs a renderer object.
  • Method Details

    • getFillColor

      @ColorInt public int getFillColor()
      Returns this renderer's fill color for glyphs. The default value is Color.BLACK.
      Returns:
      The fill color of this renderer expressed as ARGB integer.
    • setFillColor

      public void setFillColor(@ColorInt int fillColor)
      Sets this renderer's fill color for glyphs. The default value is Color.BLACK.
      Parameters:
      fillColor - The 32-bit value of color expressed as ARGB.
    • getRenderingStyle

      @NonNull public RenderingStyle getRenderingStyle()
      Returns this renderer's style, used for controlling how glyphs should appear while drawing. The default value is RenderingStyle.FILL.
      Returns:
      The style setting of this renderer.
    • setRenderingStyle

      public void setRenderingStyle(@NonNull RenderingStyle renderingStyle)
      Sets this renderer's style, used for controlling how glyphs should appear while drawing. The default value is RenderingStyle.FILL.
      Parameters:
      renderingStyle - The new style setting for the renderer.
    • getWritingDirection

      @NonNull public WritingDirection getWritingDirection()
      Returns the direction in which the pen will advance after drawing a glyph. The default value is WritingDirection.LEFT_TO_RIGHT.
      Returns:
      The current writing direction.
    • setWritingDirection

      public void setWritingDirection(@NonNull WritingDirection writingDirection)
      Sets the direction in which the pen will advance after drawing a glyph. The default value is WritingDirection.LEFT_TO_RIGHT.
      Parameters:
      writingDirection - The new writing direction.
    • getTypeface

      public Typeface getTypeface()
      Returns this renderer's typeface, used for drawing glyphs.
      Returns:
      The typeface of this renderer.
    • setTypeface

      public void setTypeface(Typeface typeface)
      Sets this renderer's typeface, used for drawing glyphs.
      Parameters:
      typeface - The typeface to use for drawing glyphs.
    • getTypeSize

      public float getTypeSize()
      Returns this renderer's type size, applied on glyphs while drawing.
      Returns:
      The type size of this renderer in pixels.
    • setTypeSize

      public void setTypeSize(float typeSize)
      Sets this renderer's type size, applied on glyphs while drawing.
      Parameters:
      typeSize - The new type size in pixels.
      Throws:
      IllegalArgumentException - if typeSize is negative.
    • getSlantAngle

      public float getSlantAngle()
      Returns this renderer's slant angle for glyphs. The default value is 0.
      Returns:
      The slant angle of this renderer for drawing glyphs.
    • setSlantAngle

      public void setSlantAngle(float slantAngle)
      Sets this renderer's slant angle for glyphs. The default value is 0.
      Parameters:
      slantAngle - The slant angle for drawing glyphs.
    • getScaleX

      public float getScaleX()
      Returns this renderer's horizontal scale factor for glyphs. The default value is 1.0.
      Returns:
      The horizontal scale factor of this renderer for drawing/measuring glyphs.
    • setScaleX

      public void setScaleX(float scaleX)
      Sets this renderer's horizontal scale factor for glyphs. The default value is 1.0. Values greater than 1.0 will stretch the glyphs wider. Values less than 1.0 will stretch the glyphs narrower.
      Parameters:
      scaleX - The horizontal scale factor for drawing/measuring glyphs.
    • getScaleY

      public float getScaleY()
      Returns this renderer's vertical scale factor for glyphs. The default value is 1.0.
      Returns:
      The vertical scale factor of this renderer for drawing/measuring glyphs.
    • setScaleY

      public void setScaleY(float scaleY)
      Sets this renderer's vertical scale factor for glyphs. The default value is 1.0. Values greater than 1.0 will stretch the glyphs wider. Values less than 1.0 will stretch the glyphs narrower.
      Parameters:
      scaleY - The vertical scale factor for drawing/measuring glyphs.
    • getStrokeColor

      @ColorInt public int getStrokeColor()
      Returns this renderer's stroke color for glyphs. The default value is Color.BLACK.
      Returns:
      The stroke color of this renderer expressed as ARGB integer.
    • setStrokeColor

      public void setStrokeColor(@ColorInt int strokeColor)
      Sets this renderer's stroke color for glyphs. The default value is Color.BLACK.
      Parameters:
      strokeColor - The 32-bit value of color expressed as ARGB.
    • getStrokeWidth

      public float getStrokeWidth()
      Returns this renderer's width for stroking glyphs.
      Returns:
      The stroke width of this renderer in pixels.
    • setStrokeWidth

      public void setStrokeWidth(float strokeWidth)
      Sets this renderer's width for stroking glyphs.
      Parameters:
      strokeWidth - The stroke width in pixels.
    • getStrokeCap

      @NonNull public StrokeCap getStrokeCap()
      Returns this renderer's cap, controlling how the start and end of stroked lines and paths are treated. The default value is StrokeCap.BUTT.
      Returns:
      The stroke cap style of this renderer.
    • setStrokeCap

      public void setStrokeCap(@NonNull StrokeCap strokeCap)
      Sets this renderer's cap, controlling how the start and end of stroked lines and paths are treated. The default value is StrokeCap.BUTT.
      Parameters:
      strokeCap - The new stroke cap style.
    • getStrokeJoin

      @NonNull public StrokeJoin getStrokeJoin()
      Returns this renderer's stroke join type. The default value is StrokeJoin.ROUND.
      Returns:
      The stroke join type of this renderer.
    • setStrokeJoin

      public void setStrokeJoin(@NonNull StrokeJoin strokeJoin)
      Sets this renderer's stroke join type. The default value is StrokeJoin.ROUND.
      Parameters:
      strokeJoin - The new stroke join type.
    • getStrokeMiter

      public float getStrokeMiter()
      Returns this renderer's stroke miter value. Used to control the behavior of miter joins when the joins angle is sharp.
      Returns:
      The miter limit of this renderer in pixels.
    • setStrokeMiter

      public void setStrokeMiter(float strokeMiter)
      Sets this renderer's stroke miter value. This is used to control the behavior of miter joins when the joins angle is sharp.
      Parameters:
      strokeMiter - The value of miter limit in pixels.
      Throws:
      IllegalArgumentException - if strokeMiter is less than one.
    • getShadowRadius

      public float getShadowRadius()
      Returns this renderer's shadow radius, used when drawing glyphs. The default value is zero.
      Returns:
      The shadow radius of this renderer in pixels.
    • setShadowRadius

      public void setShadowRadius(float shadowRadius)
      Sets this renderer's shadow radius. The default value is zero. The shadow is disabled if the radius is set to zero.
      Parameters:
      shadowRadius - The value of shadow radius in pixels.
      Throws:
      IllegalArgumentException - if shadowRadius is negative.
    • getShadowDx

      public float getShadowDx()
      Returns this renderer's horizontal shadow offset.
      Returns:
      The horizontal shadow offset of this renderer in pixels.
    • setShadowDx

      public void setShadowDx(float shadowDx)
      Sets this renderer's horizontal shadow offset.
      Parameters:
      shadowDx - The value of horizontal shadow offset in pixels.
    • getShadowDy

      public float getShadowDy()
      Returns this renderer's vertical shadow offset.
      Returns:
      The vertical shadow offset of this renderer in pixels.
    • setShadowDy

      public void setShadowDy(float shadowDy)
      Sets this renderer's vertical shadow offset.
      Parameters:
      shadowDy - The value of vertical shadow offset in pixels.
    • getShadowColor

      @ColorInt public int getShadowColor()
      Returns this renderer's shadow color.
      Returns:
      The shadow color of this renderer expressed as ARGB integer.
    • setShadowColor

      public void setShadowColor(@ColorInt int shadowColor)
      Sets this renderer's shadow color.
      Parameters:
      shadowColor - The 32-bit value of color expressed as ARGB.
    • generatePath

      @NonNull public Path generatePath(int glyphId)
      Generates the path of the specified glyph.
      Parameters:
      glyphId - The ID of glyph whose path is generated.
      Returns:
      The path of the glyph specified by glyphId.
    • generatePath

      @NonNull public Path generatePath(@NonNull IntList glyphIds, @NonNull PointList offsets, @NonNull FloatList advances)
      Generates a cumulative path of specified glyphs.
      Parameters:
      glyphIds - The list containing the glyph IDs.
      offsets - The list containing the glyph offsets.
      advances - The list containing the glyph advances.
      Returns:
      The cumulative path of specified glyphs.
    • computeBoundingBox

      @NonNull public RectF computeBoundingBox(int glyphId)
      Calculates the bounding box of specified glyph.
      Parameters:
      glyphId - The ID of glyph whose bounding box is calculated.
      Returns:
      A rectangle that tightly encloses the path of the specified glyph.
    • computeBoundingBox

      @NonNull public RectF computeBoundingBox(@NonNull IntList glyphIds, @NonNull PointList offsets, @NonNull FloatList advances)
      Calculates the bounding box of specified glyphs.
      Parameters:
      glyphIds - The list containing the glyph IDs.
      offsets - The list containing the glyph offsets.
      advances - The list containing the glyph advances.
      Returns:
      A rectangle that tightly encloses the paths of specified glyphs.
    • drawGlyphs

      public void drawGlyphs(@NonNull Canvas canvas, @NonNull IntList glyphIds, @NonNull PointList offsets, @NonNull FloatList advances)
      Draws specified glyphs onto the given canvas. The shadow will not be drawn if the canvas is hardware accelerated.
      Parameters:
      canvas - The canvas onto which to draw the glyphs.
      glyphIds - The list containing the glyph IDs.
      offsets - The list containing the glyph offsets.
      advances - The list containing the glyph advances.