TextPaint | API reference | Android Developers
float
ascent()
Return the distance above (negative) the baseline (ascent) based on the current typeface and text size.
int
breakText(char[] text, int index, int count, float maxWidth, float[] measuredWidth)
Measure the text, stopping early if the measured width exceeds maxWidth.
int
breakText(String text, boolean measureForwards, float maxWidth, float[] measuredWidth)
Measure the text, stopping early if the measured width exceeds maxWidth.
int
breakText(CharSequence text, int start, int end, boolean measureForwards, float maxWidth, float[] measuredWidth)
Measure the text, stopping early if the measured width exceeds maxWidth.
void
clearShadowLayer()
Clear the shadow layer.
float
descent()
Return the distance below (positive) the baseline (descent) based on the current typeface and text size.
boolean
equalsForTextMeasurement(Paint other)
Returns true of the passed Paint will have the same effect on text measurement
int
getAlpha()
Helper to getColor() that just returns the color's alpha value.
BlendMode
getBlendMode()
Get the paint's blend mode object.
int
getColor()
Return the paint's color in sRGB.
ColorFilter
getColorFilter()
Get the paint's colorfilter (maybe be null).
long
getColorLong()
Return the paint's color.
int
getEndHyphenEdit()
Get the current value of end hyphen edit.
boolean
getFillPath(Path src, Path dst)
Applies any/all effects (patheffect, stroking) to src, returning the result in dst.
int
getFlags()
Return the paint's flags.
String
getFontFeatureSettings()
Returns the font feature settings.
float
getFontMetrics(Paint.FontMetrics metrics)
Return the font's recommended interline spacing, given the Paint's settings for typeface, textSize, etc.
Paint.FontMetrics
getFontMetrics()
Allocates a new FontMetrics object, and then calls getFontMetrics(fm) with it, returning the object.
void
getFontMetricsForLocale(Paint.FontMetrics metrics)
Get the font metrics used for the locale
Obtain the metrics of the font that is used for the specified locale by
setTextLocales(android.os.LocaleList).
void
getFontMetricsInt(char[] text, int start, int count, int contextStart, int contextCount, boolean isRtl, Paint.FontMetricsInt outMetrics)
Returns the font metrics value for the given text.
int
getFontMetricsInt(Paint.FontMetricsInt fmi)
Return the font's interline spacing, given the Paint's settings for typeface, textSize, etc.
Paint.FontMetricsInt
getFontMetricsInt()
void
getFontMetricsInt(CharSequence text, int start, int count, int contextStart, int contextCount, boolean isRtl, Paint.FontMetricsInt outMetrics)
Returns the font metrics value for the given text.
void
getFontMetricsIntForLocale(Paint.FontMetricsInt metrics)
Get the font metrics used for the locale
Obtain the metrics of the font that is used for the specified locale by
setTextLocales(android.os.LocaleList).
float
getFontSpacing()
Return the recommend line spacing based on the current typeface and text size.
String
getFontVariationOverride()
Gets the current font variation override value.
String
getFontVariationSettings()
Returns the font variation settings.
int
getHinting()
Return the paint's hinting mode.
float
getLetterSpacing()
Return the paint's letter-spacing for text.
MaskFilter
getMaskFilter()
Get the paint's maskfilter object.
int
getOffsetForAdvance(char[] text, int start, int end, int contextStart, int contextEnd, boolean isRtl, float advance)
Get the character offset within the string whose position is closest to the specified horizontal position.
int
getOffsetForAdvance(CharSequence text, int start, int end, int contextStart, int contextEnd, boolean isRtl, float advance)
PathEffect
getPathEffect()
Get the paint's patheffect object.
float
getRunAdvance(char[] text, int start, int end, int contextStart, int contextEnd, boolean isRtl, int offset)
Measure cursor position within a run of text.
float
getRunAdvance(CharSequence text, int start, int end, int contextStart, int contextEnd, boolean isRtl, int offset)
float
getRunCharacterAdvance(CharSequence text, int start, int end, int contextStart, int contextEnd, boolean isRtl, int offset, float[] advances, int advancesIndex)
float
getRunCharacterAdvance(char[] text, int start, int end, int contextStart, int contextEnd, boolean isRtl, int offset, float[] advances, int advancesIndex)
Measure the advance of each character within a run of text and also return the cursor position within the run.
Shader
getShader()
Get the paint's shader object.
int
getShadowLayerColor()
Returns the color of the shadow layer.
long
getShadowLayerColorLong()
Returns the color of the shadow layer.
float
getShadowLayerDx()
Returns the x offset of the shadow layer.
float
getShadowLayerDy()
Returns the y offset of the shadow layer.
float
getShadowLayerRadius()
Returns the blur radius of the shadow layer.
int
getStartHyphenEdit()
Get the current value of start hyphen edit.
float
getStrikeThruPosition()
Distance from top of the strike-through line to the baseline in pixels.
float
getStrikeThruThickness()
Returns the thickness of the strike-through line in pixels.
Paint.Cap
getStrokeCap()
Return the paint's Cap, controlling how the start and end of stroked lines and paths are treated.
Paint.Join
getStrokeJoin()
Return the paint's stroke join type.
float
getStrokeMiter()
Return the paint's stroke miter value.
float
getStrokeWidth()
Return the width for stroking.
Paint.Style
getStyle()
Return the paint's style, used for controlling how primitives' geometries are interpreted (except for drawBitmap, which always assumes FILL_STYLE).
Paint.Align
getTextAlign()
Return the paint's Align value for drawing text.
void
getTextBounds(String text, int start, int end, Rect bounds)
Retrieve the text boundary box and store to bounds.
void
getTextBounds(CharSequence text, int start, int end, Rect bounds)
Retrieve the text boundary box and store to bounds.
void
getTextBounds(char[] text, int index, int count, Rect bounds)
Return in bounds (allocated by the caller) the smallest rectangle that encloses all of the characters, with an implied origin at (0,0).
Locale
getTextLocale()
Get the text's primary Locale.
LocaleList
getTextLocales()
Get the text locale list.
void
getTextPath(char[] text, int index, int count, float x, float y, Path path)
Return the path (outline) for the specified text.
void
getTextPath(String text, int start, int end, float x, float y, Path path)
Return the path (outline) for the specified text.
float
getTextRunAdvances(char[] chars, int index, int count, int contextIndex, int contextCount, boolean isRtl, float[] advances, int advancesIndex)
Retrieve the character advances of the text.
int
getTextRunCursor(CharSequence text, int contextStart, int contextEnd, boolean isRtl, int offset, int cursorOpt)
Returns the next cursor position in the run.
int
getTextRunCursor(char[] text, int contextStart, int contextLength, boolean isRtl, int offset, int cursorOpt)
Returns the next cursor position in the run.
float
getTextScaleX()
Return the paint's horizontal scale factor for text.
float
getTextSize()
Return the paint's text size.
float
getTextSkewX()
Return the paint's horizontal skew factor for text.
int
getTextWidths(char[] text, int index, int count, float[] widths)
Return the advance widths for the characters in the string.
int
getTextWidths(String text, float[] widths)
Return the advance widths for the characters in the string.
int
getTextWidths(String text, int start, int end, float[] widths)
Return the advance widths for the characters in the string.
int
getTextWidths(CharSequence text, int start, int end, float[] widths)
Return the advance widths for the characters in the string.
Typeface
getTypeface()
Get the paint's typeface object.
float
getUnderlinePosition()
Returns the distance from top of the underline to the baseline in pixels.
float
getUnderlineThickness()
Returns the thickness of the underline in pixels.
float
getWordSpacing()
Return the paint's extra word-spacing for text.
Xfermode
getXfermode()
Get the paint's transfer mode object.
boolean
hasGlyph(String string)
Determine whether the typeface set on the paint has a glyph supporting the string.
final
boolean
isAntiAlias()
Helper for getFlags(), returning true if ANTI_ALIAS_FLAG bit is set AntiAliasing smooths out the edges of what is being drawn, but is has no impact on the interior of the shape.
final
boolean
isDither()
Helper for getFlags(), returning true if DITHER_FLAG bit is set Dithering affects how colors that are higher precision than the device are down-sampled.
boolean
isElegantTextHeight()
This method was deprecated in API level 36. The underlying UI fonts are deprecated and will be removed from the system image. Applications supporting scripts with large vertical metrics should adapt their UI by using fonts designed with corresponding vertical metrics.
final
boolean
isFakeBoldText()
Helper for getFlags(), returning true if FAKE_BOLD_TEXT_FLAG bit is set
final
boolean
isFilterBitmap()
Whether or not the bitmap filter is activated.
final
boolean
isLinearText()
Helper for getFlags(), returning true if LINEAR_TEXT_FLAG bit is set
final
boolean
isStrikeThruText()
Helper for getFlags(), returning true if STRIKE_THRU_TEXT_FLAG bit is set
final
boolean
isSubpixelText()
Helper for getFlags(), returning true if SUBPIXEL_TEXT_FLAG bit is set
final
boolean
isUnderlineText()
Helper for getFlags(), returning true if UNDERLINE_TEXT_FLAG bit is set
float
measureText(char[] text, int index, int count)
Return the width of the text.
float
measureText(CharSequence text, int start, int end)
Return the width of the text.
float
measureText(String text, int start, int end)
Return the width of the text.
float
measureText(String text)
Return the width of the text.
void
reset()
Restores the paint to its default settings.
void
set(Paint src)
Copy the fields from src into this paint.
void
setARGB(int a, int r, int g, int b)
Helper to setColor(), that takes a,r,g,b and constructs the color int
void
setAlpha(int a)
Helper to setColor(), that only assigns the color's alpha value, leaving its r,g,b values unchanged.
void
setAntiAlias(boolean aa)
Helper for setFlags(), setting or clearing the ANTI_ALIAS_FLAG bit AntiAliasing smooths out the edges of what is being drawn, but is has no impact on the interior of the shape.
void
setBlendMode(BlendMode blendmode)
Set or clear the blend mode.
void
setColor(long color)
Set the paint's color with a ColorLong.
void
setColor(int color)
Set the paint's color.
ColorFilter
setColorFilter(ColorFilter filter)
Set or clear the paint's colorfilter, returning the parameter.
void
setDither(boolean dither)
Helper for setFlags(), setting or clearing the DITHER_FLAG bit Dithering affects how colors that are higher precision than the device are down-sampled.
void
setElegantTextHeight(boolean elegant)
This method was deprecated in API level 36. This API will be no-op at some point in the future. The underlying UI fonts is deprecated and will be removed from the system image. Applications supporting scripts with large vertical metrics should adapt their UI by using fonts designed with corresponding vertical metrics.
void
setEndHyphenEdit(int endHyphen)
Set a end hyphen edit on the paint.
void
setFakeBoldText(boolean fakeBoldText)
Helper for setFlags(), setting or clearing the FAKE_BOLD_TEXT_FLAG bit
void
setFilterBitmap(boolean filter)
Helper for setFlags(), setting or clearing the FILTER_BITMAP_FLAG bit.
void
setFlags(int flags)
Set the paint's flags.
void
setFontFeatureSettings(String settings)
Set font feature settings.
void
setFontVariationOverride(String fontVariationOverride)
Sets TrueType or OpenType font variation settings for overriding.
boolean
setFontVariationSettings(String fontVariationSettings)
Sets TrueType or OpenType font variation settings.
void
setHinting(int mode)
Set the paint's hinting mode.
void
setLetterSpacing(float letterSpacing)
Set the paint's letter-spacing for text.
void
setLinearText(boolean linearText)
Helper for setFlags(), setting or clearing the LINEAR_TEXT_FLAG bit
MaskFilter
setMaskFilter(MaskFilter maskfilter)
Set or clear the maskfilter object.
PathEffect
setPathEffect(PathEffect effect)
Set or clear the patheffect object.
Shader
setShader(Shader shader)
Set or clear the shader object.
void
setShadowLayer(float radius, float dx, float dy, int shadowColor)
This draws a shadow layer below the main layer, with the specified offset and color, and blur radius.
void
setShadowLayer(float radius, float dx, float dy, long shadowColor)
This draws a shadow layer below the main layer, with the specified offset and color, and blur radius.
void
setStartHyphenEdit(int startHyphen)
Set a start hyphen edit on the paint.
void
setStrikeThruText(boolean strikeThruText)
Helper for setFlags(), setting or clearing the STRIKE_THRU_TEXT_FLAG bit
void
setStrokeCap(Paint.Cap cap)
Set the paint's Cap.
void
setStrokeJoin(Paint.Join join)
Set the paint's Join.
void
setStrokeMiter(float miter)
Set the paint's stroke miter value.
void
setStrokeWidth(float width)
Set the width for stroking.
void
setStyle(Paint.Style style)
Set the paint's style, used for controlling how primitives' geometries are interpreted (except for drawBitmap, which always assumes Fill).
void
setSubpixelText(boolean subpixelText)
Helper for setFlags(), setting or clearing the SUBPIXEL_TEXT_FLAG bit
void
setTextAlign(Paint.Align align)
Set the paint's text alignment.
void
setTextLocale(Locale locale)
Set the text locale list to a one-member list consisting of just the locale.
void
setTextLocales(LocaleList locales)
Set the text locale list.
void
setTextScaleX(float scaleX)
Set the paint's horizontal scale factor for text.
void
setTextSize(float textSize)
Set the paint's text size.
void
setTextSkewX(float skewX)
Set the paint's horizontal skew factor for text.
Typeface
setTypeface(Typeface typeface)
Set or clear the typeface object.
void
setUnderlineText(boolean underlineText)
Helper for setFlags(), setting or clearing the UNDERLINE_TEXT_FLAG bit
void
setWordSpacing(float wordSpacing)
Set the paint's extra word-spacing for text.
Xfermode
setXfermode(Xfermode xfermode)
Set or clear the transfer mode object.