TextPaint


public class TextPaint
extends Paint

java.lang.Object
   ↳ android.graphics.Paint
     ↳ android.text.TextPaint


TextPaint is an extension of Paint that leaves room for some extra data used during text measuring and drawing.

Summary

Inherited constants

int ANTI_ALIAS_FLAG

Paint flag that enables antialiasing when drawing.

int CURSOR_AFTER

Option for getTextRunCursor.

int CURSOR_AT

Option for getTextRunCursor.

int CURSOR_AT_OR_AFTER

Option for getTextRunCursor.

int CURSOR_AT_OR_BEFORE

Option for getTextRunCursor.

int CURSOR_BEFORE

Option for getTextRunCursor.

int DEV_KERN_TEXT_FLAG

Legacy Paint flag, no longer used.

int DITHER_FLAG

Paint flag that enables dithering when blitting.

int EMBEDDED_BITMAP_TEXT_FLAG

Paint flag that enables the use of bitmap fonts when drawing text.

int END_HYPHEN_EDIT_INSERT_ARMENIAN_HYPHEN

An integer representing the end of the line has Armentian hyphen (U+058A).

int END_HYPHEN_EDIT_INSERT_HYPHEN

An integer representing the end of the line has normal hyphen character (U+002D).

int END_HYPHEN_EDIT_INSERT_MAQAF

An integer representing the end of the line has maqaf (Hebrew hyphen, U+05BE).

int END_HYPHEN_EDIT_INSERT_UCAS_HYPHEN

An integer representing the end of the line has Canadian Syllabics hyphen (U+1400).

int END_HYPHEN_EDIT_INSERT_ZWJ_AND_HYPHEN

An integer representing the end of the line has Zero-Width-Joiner (U+200D) followed by normal hyphen character (U+002D).

int END_HYPHEN_EDIT_NO_EDIT

An integer representing the end of the line has no modification for hyphenation.

int END_HYPHEN_EDIT_REPLACE_WITH_HYPHEN

An integer representing the character at the end of the line is replaced with hyphen character (U+002D).

int FAKE_BOLD_TEXT_FLAG

Paint flag that applies a synthetic bolding effect to drawn text.

int FILTER_BITMAP_FLAG

Paint flag that enables bilinear sampling on scaled bitmaps.

int HINTING_OFF

Font hinter option that disables font hinting.

int HINTING_ON

Font hinter option that enables font hinting.

int LINEAR_TEXT_FLAG

Paint flag that enables smooth linear scaling of text.

int START_HYPHEN_EDIT_INSERT_HYPHEN

An integer representing the starting of the line has normal hyphen character (U+002D).

int START_HYPHEN_EDIT_INSERT_ZWJ

An integer representing the starting of the line has Zero-Width-Joiner (U+200D).

int START_HYPHEN_EDIT_NO_EDIT

An integer representing the starting of the line has no modification for hyphenation.

int STRIKE_THRU_TEXT_FLAG

Paint flag that applies a strike-through decoration to drawn text.

int SUBPIXEL_TEXT_FLAG

Paint flag that enables subpixel positioning of text.

int TEXT_RUN_FLAG_LEFT_EDGE

A text run flag that indicates the run is located the visually most left segment of the line.

int TEXT_RUN_FLAG_RIGHT_EDGE

A text run flag that indicates the run is located the visually most right segment of the line.

int UNDERLINE_TEXT_FLAG

Paint flag that applies an underline decoration to drawn text.

int VERTICAL_TEXT_FLAG

A flat that controls text to be written in vertical orientation

This flag is used for telling the underlying text layout engine that the text is for vertical direction.

Fields

public int baselineShift

public int bgColor

public float density

public int[] drawableState

public int linkColor

public int underlineColor

Special value 0 means no custom underline

public float underlineThickness

Thickness of the underline, in pixels.

Public constructors

TextPaint()
TextPaint(Paint p)
TextPaint(int flags)

Public methods

void set(TextPaint tp)

Copy the fields from tp into this TextPaint, including the fields inherited from Paint.

Inherited methods

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 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 Baklava. 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 Baklava. 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.

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.

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(long timeoutMillis, int nanos)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait(long timeoutMillis)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait()

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

Fields

baselineShift

Added in API level 1
public int baselineShift

bgColor

Added in API level 1
public int bgColor

density

Added in API level 5
public float density

drawableState

Added in API level 1
public int[] drawableState

linkColor

Added in API level 1
public int linkColor

underlineColor

Added in API level 29
public int underlineColor

Special value 0 means no custom underline

underlineThickness

Added in API level 29
public float underlineThickness

Thickness of the underline, in pixels.
The units of this value are pixels.

Public constructors

TextPaint

Added in API level 1
public TextPaint ()

TextPaint

Added in API level 1
public TextPaint (Paint p)

Parameters
p Paint

TextPaint

Added in API level 1
public TextPaint (int flags)

Parameters
flags int

Public methods

set

Added in API level 1
public void set (TextPaint tp)

Copy the fields from tp into this TextPaint, including the fields inherited from Paint.

Parameters
tp TextPaint