Package com.mta.tehreer.graphics
Class Renderer
java.lang.Object
com.mta.tehreer.graphics.Renderer
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptioncomputeBoundingBox
(int glyphId) Calculates the bounding box of specified glyph.computeBoundingBox
(IntList glyphIds, PointList offsets, FloatList advances) Calculates the bounding box of specified glyphs.void
drawGlyphs
(Canvas canvas, IntList glyphIds, PointList offsets, FloatList advances) Draws specified glyphs onto the given canvas.generatePath
(int glyphId) Generates the path of the specified glyph.generatePath
(IntList glyphIds, PointList offsets, FloatList advances) Generates a cumulative path of specified glyphs.int
Returns this renderer's fill color for glyphs.Returns this renderer's style, used for controlling how glyphs should appear while drawing.float
Returns this renderer's horizontal scale factor for glyphs.float
Returns this renderer's vertical scale factor for glyphs.int
Returns this renderer's shadow color.float
Returns this renderer's horizontal shadow offset.float
Returns this renderer's vertical shadow offset.float
Returns this renderer's shadow radius, used when drawing glyphs.float
Returns this renderer's slant angle for glyphs.Returns this renderer's cap, controlling how the start and end of stroked lines and paths are treated.int
Returns this renderer's stroke color for glyphs.Returns this renderer's stroke join type.float
Returns this renderer's stroke miter value.float
Returns this renderer's width for stroking glyphs.Returns this renderer's typeface, used for drawing glyphs.float
Returns this renderer's type size, applied on glyphs while drawing.Returns the direction in which the pen will advance after drawing a glyph.void
setFillColor
(int fillColor) Sets this renderer's fill color for glyphs.void
setRenderingStyle
(RenderingStyle renderingStyle) Sets this renderer's style, used for controlling how glyphs should appear while drawing.void
setScaleX
(float scaleX) Sets this renderer's horizontal scale factor for glyphs.void
setScaleY
(float scaleY) Sets this renderer's vertical scale factor for glyphs.void
setShadowColor
(int shadowColor) Sets this renderer's shadow color.void
setShadowDx
(float shadowDx) Sets this renderer's horizontal shadow offset.void
setShadowDy
(float shadowDy) Sets this renderer's vertical shadow offset.void
setShadowRadius
(float shadowRadius) Sets this renderer's shadow radius.void
setSlantAngle
(float slantAngle) Sets this renderer's slant angle for glyphs.void
setStrokeCap
(StrokeCap strokeCap) Sets this renderer's cap, controlling how the start and end of stroked lines and paths are treated.void
setStrokeColor
(int strokeColor) Sets this renderer's stroke color for glyphs.void
setStrokeJoin
(StrokeJoin strokeJoin) Sets this renderer's stroke join type.void
setStrokeMiter
(float strokeMiter) Sets this renderer's stroke miter value.void
setStrokeWidth
(float strokeWidth) Sets this renderer's width for stroking glyphs.void
setTypeface
(Typeface typeface) Sets this renderer's typeface, used for drawing glyphs.void
setTypeSize
(float typeSize) Sets this renderer's type size, applied on glyphs while drawing.void
setWritingDirection
(WritingDirection writingDirection) Sets the direction in which the pen will advance after drawing a glyph.
-
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 isColor.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 isColor.BLACK
.- Parameters:
fillColor
- The 32-bit value of color expressed as ARGB.
-
getRenderingStyle
Returns this renderer's style, used for controlling how glyphs should appear while drawing. The default value isRenderingStyle.FILL
.- Returns:
- The style setting of this renderer.
-
setRenderingStyle
Sets this renderer's style, used for controlling how glyphs should appear while drawing. The default value isRenderingStyle.FILL
.- Parameters:
renderingStyle
- The new style setting for the renderer.
-
getWritingDirection
Returns the direction in which the pen will advance after drawing a glyph. The default value isWritingDirection.LEFT_TO_RIGHT
.- Returns:
- The current writing direction.
-
setWritingDirection
Sets the direction in which the pen will advance after drawing a glyph. The default value isWritingDirection.LEFT_TO_RIGHT
.- Parameters:
writingDirection
- The new writing direction.
-
getTypeface
Returns this renderer's typeface, used for drawing glyphs.- Returns:
- The typeface of this renderer.
-
setTypeface
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
- iftypeSize
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 isColor.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 isColor.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
Returns this renderer's cap, controlling how the start and end of stroked lines and paths are treated. The default value isStrokeCap.BUTT
.- Returns:
- The stroke cap style of this renderer.
-
setStrokeCap
Sets this renderer's cap, controlling how the start and end of stroked lines and paths are treated. The default value isStrokeCap.BUTT
.- Parameters:
strokeCap
- The new stroke cap style.
-
getStrokeJoin
Returns this renderer's stroke join type. The default value isStrokeJoin.ROUND
.- Returns:
- The stroke join type of this renderer.
-
setStrokeJoin
Sets this renderer's stroke join type. The default value isStrokeJoin.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
- ifstrokeMiter
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
- ifshadowRadius
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
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
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.
-