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
Constructors -
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.voiddrawGlyphs(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.intReturns this renderer's fill color for glyphs.Returns this renderer's style, used for controlling how glyphs should appear while drawing.floatReturns this renderer's horizontal scale factor for glyphs.floatReturns this renderer's vertical scale factor for glyphs.intReturns this renderer's shadow color.floatReturns this renderer's horizontal shadow offset.floatReturns this renderer's vertical shadow offset.floatReturns this renderer's shadow radius, used when drawing glyphs.floatReturns 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.intReturns this renderer's stroke color for glyphs.Returns this renderer's stroke join type.floatReturns this renderer's stroke miter value.floatReturns this renderer's width for stroking glyphs.Returns this renderer's typeface, used for drawing glyphs.floatReturns this renderer's type size, applied on glyphs while drawing.Returns the direction in which the pen will advance after drawing a glyph.voidsetFillColor(int fillColor) Sets this renderer's fill color for glyphs.voidsetRenderingStyle(RenderingStyle renderingStyle) Sets this renderer's style, used for controlling how glyphs should appear while drawing.voidsetScaleX(float scaleX) Sets this renderer's horizontal scale factor for glyphs.voidsetScaleY(float scaleY) Sets this renderer's vertical scale factor for glyphs.voidsetShadowColor(int shadowColor) Sets this renderer's shadow color.voidsetShadowDx(float shadowDx) Sets this renderer's horizontal shadow offset.voidsetShadowDy(float shadowDy) Sets this renderer's vertical shadow offset.voidsetShadowRadius(float shadowRadius) Sets this renderer's shadow radius.voidsetSlantAngle(float slantAngle) Sets this renderer's slant angle for glyphs.voidsetStrokeCap(StrokeCap strokeCap) Sets this renderer's cap, controlling how the start and end of stroked lines and paths are treated.voidsetStrokeColor(int strokeColor) Sets this renderer's stroke color for glyphs.voidsetStrokeJoin(StrokeJoin strokeJoin) Sets this renderer's stroke join type.voidsetStrokeMiter(float strokeMiter) Sets this renderer's stroke miter value.voidsetStrokeWidth(float strokeWidth) Sets this renderer's width for stroking glyphs.voidsetTypeface(Typeface typeface) Sets this renderer's typeface, used for drawing glyphs.voidsetTypeSize(float typeSize) Sets this renderer's type size, applied on glyphs while drawing.voidsetWritingDirection(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- iftypeSizeis 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- ifstrokeMiteris 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- ifshadowRadiusis 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.
-