Added in API level 1

Paint


open class Paint
kotlin.Any
   ↳ android.graphics.Paint

The Paint class holds the style and color information about how to draw geometries, text and bitmaps.

Summary

Nested classes

Align specifies how drawText aligns its text relative to the [x,y] coordinates.

The Cap specifies the treatment for the beginning and ending of stroked lines and paths.

open

Class that describes the various metrics for a font at a given text size.

open

Convenience method for callers that want to have FontMetrics values as integers.

The Join specifies the treatment where lines and curve segments join on a stroked path.

The Style specifies if the primitive being drawn is filled, stroked, or both (in the same color).

Constants
static Int

Paint flag that enables antialiasing when drawing.

static Int

Option for getTextRunCursor.

static Int

Option for getTextRunCursor.

static Int

Option for getTextRunCursor.

static Int

Option for getTextRunCursor.

static Int

Option for getTextRunCursor.

static Int

Legacy Paint flag, no longer used.

static Int

Paint flag that enables dithering when blitting.

static Int

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

static Int

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

static Int

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

static Int

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

static Int

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

static Int

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

static Int

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

static Int

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

static Int

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

static Int

Paint flag that enables bilinear sampling on scaled bitmaps.

static Int

Font hinter option that disables font hinting.

static Int

Font hinter option that enables font hinting.

static Int

Paint flag that enables smooth linear scaling of text.

static Int

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

static Int

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

static Int

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

static Int

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

static Int

Paint flag that enables subpixel positioning of text.

static Int

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

static Int

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

static Int

Paint flag that applies an underline decoration to drawn text.

Public constructors

Create a new paint with default settings.

Paint(paint: Paint!)

Create a new paint, initialized with the attributes in the specified paint parameter.

Paint(flags: Int)

Create a new paint with the specified flags.

Public methods
open Float

Return the distance above (negative) the baseline (ascent) based on the current typeface and text size.

open Int
breakText(text: CharArray!, index: Int, count: Int, maxWidth: Float, measuredWidth: FloatArray!)

Measure the text, stopping early if the measured width exceeds maxWidth.

open Int
breakText(text: CharSequence!, start: Int, end: Int, measureForwards: Boolean, maxWidth: Float, measuredWidth: FloatArray!)

Measure the text, stopping early if the measured width exceeds maxWidth.

open Int
breakText(text: String!, measureForwards: Boolean, maxWidth: Float, measuredWidth: FloatArray!)

Measure the text, stopping early if the measured width exceeds maxWidth.

open Unit

Clear the shadow layer.

open Float

Return the distance below (positive) the baseline (descent) based on the current typeface and text size.

open Boolean

Returns true of the passed Paint will have the same effect on text measurement

open Int

Helper to getColor() that just returns the color's alpha value.

open BlendMode?

Get the paint's blend mode object.

open Int

Return the paint's color in sRGB.

open ColorFilter!

Get the paint's colorfilter (maybe be null).

open Long

Return the paint's color.

open Int

Get the current value of end hyphen edit.

open Boolean
getFillPath(src: Path!, dst: Path!)

Applies any/all effects (patheffect, stroking) to src, returning the result in dst.

open Int

Return the paint's flags.

open String!

Returns the font feature settings.

open Paint.FontMetrics!

Allocates a new FontMetrics object, and then calls getFontMetrics(fm) with it, returning the object.

open Float

Return the font's recommended interline spacing, given the Paint's settings for typeface, textSize, etc.

open Unit

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

open Paint.FontMetricsInt!

open Int

Return the font's interline spacing, given the Paint's settings for typeface, textSize, etc.

open Unit
getFontMetricsInt(text: CharArray, start: Int, count: Int, contextStart: Int, contextCount: Int, isRtl: Boolean, outMetrics: Paint.FontMetricsInt)

Returns the font metrics value for the given text.

open Unit
getFontMetricsInt(text: CharSequence, start: Int, count: Int, contextStart: Int, contextCount: Int, isRtl: Boolean, outMetrics: Paint.FontMetricsInt)

Returns the font metrics value for the given text.

open Unit

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

open Float

Return the recommend line spacing based on the current typeface and text size.

open String!

Returns the font variation settings.

open Int

Return the paint's hinting mode.

open Float

Return the paint's letter-spacing for text.

open MaskFilter!

Get the paint's maskfilter object.

open Int
getOffsetForAdvance(text: CharArray!, start: Int, end: Int, contextStart: Int, contextEnd: Int, isRtl: Boolean, advance: Float)

Get the character offset within the string whose position is closest to the specified horizontal position.

open Int
getOffsetForAdvance(text: CharSequence!, start: Int, end: Int, contextStart: Int, contextEnd: Int, isRtl: Boolean, advance: Float)

open PathEffect!

Get the paint's patheffect object.

open Float
getRunAdvance(text: CharArray!, start: Int, end: Int, contextStart: Int, contextEnd: Int, isRtl: Boolean, offset: Int)

Measure cursor position within a run of text.

open Float
getRunAdvance(text: CharSequence!, start: Int, end: Int, contextStart: Int, contextEnd: Int, isRtl: Boolean, offset: Int)

open Float
getRunCharacterAdvance(text: CharArray, start: Int, end: Int, contextStart: Int, contextEnd: Int, isRtl: Boolean, offset: Int, advances: FloatArray?, advancesIndex: Int)

Measure the advance of each character within a run of text and also return the cursor position within the run.

open Float
getRunCharacterAdvance(text: CharSequence, start: Int, end: Int, contextStart: Int, contextEnd: Int, isRtl: Boolean, offset: Int, advances: FloatArray?, advancesIndex: Int)

open Shader!

Get the paint's shader object.

open Int

Returns the color of the shadow layer.

open Long

Returns the color of the shadow layer.

open Float

Returns the x offset of the shadow layer.

open Float

Returns the y offset of the shadow layer.

open Float

Returns the blur radius of the shadow layer.

open Int

Get the current value of start hyphen edit.

open Float

Distance from top of the strike-through line to the baseline in pixels.

open Float

Returns the thickness of the strike-through line in pixels.

open Paint.Cap!

Return the paint's Cap, controlling how the start and end of stroked lines and paths are treated.

open Paint.Join!

Return the paint's stroke join type.

open Float

Return the paint's stroke miter value.

open Float

Return the width for stroking.

open Paint.Style!

Return the paint's style, used for controlling how primitives' geometries are interpreted (except for drawBitmap, which always assumes FILL_STYLE).

open Paint.Align!

Return the paint's Align value for drawing text.

open Unit
getTextBounds(text: CharArray!, index: Int, count: Int, bounds: Rect!)

Return in bounds (allocated by the caller) the smallest rectangle that encloses all of the characters, with an implied origin at (0,0).

open Unit
getTextBounds(text: CharSequence, start: Int, end: Int, bounds: Rect)

Retrieve the text boundary box and store to bounds.

open Unit
getTextBounds(text: String!, start: Int, end: Int, bounds: Rect!)

Retrieve the text boundary box and store to bounds.

open Locale

Get the text's primary Locale.

open LocaleList

Get the text locale list.

open Unit
getTextPath(text: CharArray!, index: Int, count: Int, x: Float, y: Float, path: Path!)

Return the path (outline) for the specified text.

open Unit
getTextPath(text: String!, start: Int, end: Int, x: Float, y: Float, path: Path!)

Return the path (outline) for the specified text.

open Float
getTextRunAdvances(chars: CharArray, index: Int, count: Int, contextIndex: Int, contextCount: Int, isRtl: Boolean, advances: FloatArray?, advancesIndex: Int)

Retrieve the character advances of the text.

open Int
getTextRunCursor(text: CharArray, contextStart: Int, contextLength: Int, isRtl: Boolean, offset: Int, cursorOpt: Int)

Returns the next cursor position in the run.

open Int
getTextRunCursor(text: CharSequence, contextStart: Int, contextEnd: Int, isRtl: Boolean, offset: Int, cursorOpt: Int)

Returns the next cursor position in the run.

open Float

Return the paint's horizontal scale factor for text.

open Float

Return the paint's text size.

open Float

Return the paint's horizontal skew factor for text.

open Int
getTextWidths(text: CharArray!, index: Int, count: Int, widths: FloatArray!)

Return the advance widths for the characters in the string.

open Int
getTextWidths(text: CharSequence!, start: Int, end: Int, widths: FloatArray!)

Return the advance widths for the characters in the string.

open Int
getTextWidths(text: String!, widths: FloatArray!)

Return the advance widths for the characters in the string.

open Int
getTextWidths(text: String!, start: Int, end: Int, widths: FloatArray!)

Return the advance widths for the characters in the string.

open Typeface!

Get the paint's typeface object.

open Float

Returns the distance from top of the underline to the baseline in pixels.

open Float

Returns the thickness of the underline in pixels.

open Float

Return the paint's extra word-spacing for text.

open Xfermode!

Get the paint's transfer mode object.

open Boolean
hasGlyph(string: String!)

Determine whether the typeface set on the paint has a glyph supporting the string.

Boolean

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.

Boolean

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.

open Boolean

Get the elegant metrics flag.

Boolean

Helper for getFlags(), returning true if FAKE_BOLD_TEXT_FLAG bit is set

Boolean

Whether or not the bitmap filter is activated.

Boolean

Helper for getFlags(), returning true if LINEAR_TEXT_FLAG bit is set

Boolean

Helper for getFlags(), returning true if STRIKE_THRU_TEXT_FLAG bit is set

Boolean

Helper for getFlags(), returning true if SUBPIXEL_TEXT_FLAG bit is set

Boolean

Helper for getFlags(), returning true if UNDERLINE_TEXT_FLAG bit is set

open Float
measureText(text: CharArray!, index: Int, count: Int)

Return the width of the text.

open Float
measureText(text: CharSequence!, start: Int, end: Int)

Return the width of the text.

open Float

Return the width of the text.

open Float
measureText(text: String!, start: Int, end: Int)

Return the width of the text.

open Unit

Restores the paint to its default settings.

open Unit
set(src: Paint!)

Copy the fields from src into this paint.

open Unit
setARGB(a: Int, r: Int, g: Int, b: Int)

Helper to setColor(), that takes a,r,g,b and constructs the color int

open Unit

Helper to setColor(), that only assigns the color's alpha value, leaving its r,g,b values unchanged.

open Unit

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.

open Unit
setBlendMode(blendmode: BlendMode?)

Set or clear the blend mode.

open Unit
setColor(color: Int)

Set the paint's color.

open Unit
setColor(color: Long)

Set the paint's color with a ColorLong.

open ColorFilter!

Set or clear the paint's colorfilter, returning the parameter.

open Unit
setDither(dither: Boolean)

Helper for setFlags(), setting or clearing the DITHER_FLAG bit Dithering affects how colors that are higher precision than the device are down-sampled.

open Unit

Set the paint's elegant height metrics flag.

open Unit
setEndHyphenEdit(endHyphen: Int)

Set a end hyphen edit on the paint.

open Unit
setFakeBoldText(fakeBoldText: Boolean)

Helper for setFlags(), setting or clearing the FAKE_BOLD_TEXT_FLAG bit

open Unit

Helper for setFlags(), setting or clearing the FILTER_BITMAP_FLAG bit.

open Unit
setFlags(flags: Int)

Set the paint's flags.

open Unit

Set font feature settings.

open Boolean
setFontVariationSettings(fontVariationSettings: String!)

Sets TrueType or OpenType font variation settings.

open Unit
setHinting(mode: Int)

Set the paint's hinting mode.

open Unit
setLetterSpacing(letterSpacing: Float)

Set the paint's letter-spacing for text.

open Unit
setLinearText(linearText: Boolean)

Helper for setFlags(), setting or clearing the LINEAR_TEXT_FLAG bit

open MaskFilter!
setMaskFilter(maskfilter: MaskFilter!)

Set or clear the maskfilter object.

open PathEffect!

Set or clear the patheffect object.

open Shader!
setShader(shader: Shader!)

Set or clear the shader object.

open Unit
setShadowLayer(radius: Float, dx: Float, dy: Float, shadowColor: Int)

This draws a shadow layer below the main layer, with the specified offset and color, and blur radius.

open Unit
setShadowLayer(radius: Float, dx: Float, dy: Float, shadowColor: Long)

This draws a shadow layer below the main layer, with the specified offset and color, and blur radius.

open Unit
setStartHyphenEdit(startHyphen: Int)

Set a start hyphen edit on the paint.

open Unit
setStrikeThruText(strikeThruText: Boolean)

Helper for setFlags(), setting or clearing the STRIKE_THRU_TEXT_FLAG bit

open Unit

Set the paint's Cap.

open Unit

Set the paint's Join.

open Unit

Set the paint's stroke miter value.

open Unit

Set the width for stroking.

open Unit

Set the paint's style, used for controlling how primitives' geometries are interpreted (except for drawBitmap, which always assumes Fill).

open Unit
setSubpixelText(subpixelText: Boolean)

Helper for setFlags(), setting or clearing the SUBPIXEL_TEXT_FLAG bit

open Unit

Set the paint's text alignment.

open Unit

Set the text locale list to a one-member list consisting of just the locale.

open Unit

Set the text locale list.

open Unit

Set the paint's horizontal scale factor for text.

open Unit
setTextSize(textSize: Float)

Set the paint's text size.

open Unit

Set the paint's horizontal skew factor for text.

open Typeface!
setTypeface(typeface: Typeface!)

Set or clear the typeface object.

open Unit
setUnderlineText(underlineText: Boolean)

Helper for setFlags(), setting or clearing the UNDERLINE_TEXT_FLAG bit

open Unit
setWordSpacing(wordSpacing: Float)

Set the paint's extra word-spacing for text.

open Xfermode!
setXfermode(xfermode: Xfermode!)

Set or clear the transfer mode object.

Constants

ANTI_ALIAS_FLAG

Added in API level 1
static val ANTI_ALIAS_FLAG: Int

Paint flag that enables antialiasing when drawing.

Enabling this flag will cause all draw operations that support antialiasing to use it.

Notable draw operations that do not support antialiasing include:

Value: 1

CURSOR_AFTER

Added in API level 29
static val CURSOR_AFTER: Int

Option for getTextRunCursor. Compute the valid cursor after offset or the limit of the context, whichever is less.

Value: 0

CURSOR_AT

Added in API level 29
static val CURSOR_AT: Int

Option for getTextRunCursor. Return offset if the cursor at offset is valid, or -1 if it isn't.

Value: 4

CURSOR_AT_OR_AFTER

Added in API level 29
static val CURSOR_AT_OR_AFTER: Int

Option for getTextRunCursor. Compute the valid cursor at or after the offset or the limit of the context, whichever is less.

Value: 1

CURSOR_AT_OR_BEFORE

Added in API level 29
static val CURSOR_AT_OR_BEFORE: Int

Option for getTextRunCursor. Compute the valid cursor at or before offset or the start of the context, whichever is greater.

Value: 3

CURSOR_BEFORE

Added in API level 29
static val CURSOR_BEFORE: Int

Option for getTextRunCursor. Compute the valid cursor before offset or the start of the context, whichever is greater.

Value: 2

DEV_KERN_TEXT_FLAG

Added in API level 1
static val DEV_KERN_TEXT_FLAG: Int

Legacy Paint flag, no longer used.

Value: 256

DITHER_FLAG

Added in API level 1
static val DITHER_FLAG: Int

Paint flag that enables dithering when blitting.

Enabling this flag applies a dither to any blit operation where the target's colour space is more constrained than the source.

Value: 4

EMBEDDED_BITMAP_TEXT_FLAG

Added in API level 19
static val EMBEDDED_BITMAP_TEXT_FLAG: Int

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

Disabling this flag will prevent text draw operations from using embedded bitmap strikes in fonts, causing fonts with both scalable outlines and bitmap strikes to draw only the scalable outlines, and fonts with only bitmap strikes to not draw at all.

Value: 1024

END_HYPHEN_EDIT_INSERT_ARMENIAN_HYPHEN

Added in API level 29
static val END_HYPHEN_EDIT_INSERT_ARMENIAN_HYPHEN: Int

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

Value: 3

END_HYPHEN_EDIT_INSERT_HYPHEN

Added in API level 29
static val END_HYPHEN_EDIT_INSERT_HYPHEN: Int

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

Value: 2

END_HYPHEN_EDIT_INSERT_MAQAF

Added in API level 29
static val END_HYPHEN_EDIT_INSERT_MAQAF: Int

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

Value: 4

END_HYPHEN_EDIT_INSERT_UCAS_HYPHEN

Added in API level 29
static val END_HYPHEN_EDIT_INSERT_UCAS_HYPHEN: Int

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

Value: 5

END_HYPHEN_EDIT_INSERT_ZWJ_AND_HYPHEN

Added in API level 29
static val END_HYPHEN_EDIT_INSERT_ZWJ_AND_HYPHEN: Int

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

Value: 6

END_HYPHEN_EDIT_NO_EDIT

Added in API level 29
static val END_HYPHEN_EDIT_NO_EDIT: Int

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

Value: 0

END_HYPHEN_EDIT_REPLACE_WITH_HYPHEN

Added in API level 29
static val END_HYPHEN_EDIT_REPLACE_WITH_HYPHEN: Int

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

Value: 1

FAKE_BOLD_TEXT_FLAG

Added in API level 1
static val FAKE_BOLD_TEXT_FLAG: Int

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

Enabling this flag will cause text draw operations to apply a simulated bold effect when drawing a Typeface that is not already bold.

Value: 32

FILTER_BITMAP_FLAG

Added in API level 1
static val FILTER_BITMAP_FLAG: Int

Paint flag that enables bilinear sampling on scaled bitmaps.

If cleared, scaled bitmaps will be drawn with nearest neighbor sampling, likely resulting in artifacts. This should generally be on when drawing bitmaps, unless performance-bound (rendering to software canvas) or preferring pixelation artifacts to blurriness when scaling significantly.

If bitmaps are scaled for device density at creation time (as resource bitmaps often are) the filtering will already have been done.

On devices running Build.VERSION_CODES.O and below, hardware accelerated drawing always uses bilinear sampling on scaled bitmaps, regardless of this flag. On devices running Build.VERSION_CODES.Q and above, this flag defaults to being set on a new Paint. It can be cleared with setFlags or setFilterBitmap.

Value: 2

HINTING_OFF

Added in API level 14
static val HINTING_OFF: Int

Font hinter option that disables font hinting.

Value: 0

See Also

HINTING_ON

Added in API level 14
static val HINTING_ON: Int

Font hinter option that enables font hinting.

Value: 1

See Also

LINEAR_TEXT_FLAG

Added in API level 1
static val LINEAR_TEXT_FLAG: Int

Paint flag that enables smooth linear scaling of text.

Enabling this flag does not actually scale text, but rather adjusts text draw operations to deal gracefully with smooth adjustment of scale. When this flag is enabled, font hinting is disabled to prevent shape deformation between scale factors, and glyph caching is disabled due to the large number of glyph images that will be generated.

SUBPIXEL_TEXT_FLAG should be used in conjunction with this flag to prevent glyph positions from snapping to whole pixel values as scale factor is adjusted.

Value: 64

START_HYPHEN_EDIT_INSERT_HYPHEN

Added in API level 29
static val START_HYPHEN_EDIT_INSERT_HYPHEN: Int

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

Value: 1

START_HYPHEN_EDIT_INSERT_ZWJ

Added in API level 29
static val START_HYPHEN_EDIT_INSERT_ZWJ: Int

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

Value: 2

START_HYPHEN_EDIT_NO_EDIT

Added in API level 29
static val START_HYPHEN_EDIT_NO_EDIT: Int

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

Value: 0

STRIKE_THRU_TEXT_FLAG

Added in API level 1
static val STRIKE_THRU_TEXT_FLAG: Int

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

Value: 16

SUBPIXEL_TEXT_FLAG

Added in API level 1
static val SUBPIXEL_TEXT_FLAG: Int

Paint flag that enables subpixel positioning of text.

Enabling this flag causes glyph advances to be computed with subpixel accuracy.

This can be used with LINEAR_TEXT_FLAG to prevent text from jittering during smooth scale transitions.

Value: 128

TEXT_RUN_FLAG_LEFT_EDGE

Added in API level 35
static val TEXT_RUN_FLAG_LEFT_EDGE: Int

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

This flag is used for telling the underlying text layout engine that the text is located at the most left of the line. This flag is used for controlling the amount letter spacing added. If the text is in the middle of the line, the text layout engine assigns additional letter spacing to the both side of each letter. On the other hand, the letter spacing should not be added to the visually most left and right of the line. By setting this flag, text layout engine calculates the layout as it is located at the most visually left of the line and doesn't add letter spacing to the left of this run.

Note that the caller must resolve BiDi runs and reorder them visually and set this flag only if the target run is located visually most left position. This left does not always mean the beginning of the text.

If the run covers entire line, caller should set TEXT_RUN_FLAG_RIGHT_EDGE as well.

Note that this flag is only effective for run based APIs. For example, this flag works for Canvas.drawTextRun(CharSequence, int, int, int, int, float, float, boolean, Paint) and Paint.getRunCharacterAdvance(char[], int, int, int, int, boolean, int, float[], int). However, this doesn't work for Canvas.drawText(CharSequence, int, int, float, float, Paint) or Paint.measureText(CharSequence, int, int). The non-run based APIs works as both TEXT_RUN_FLAG_LEFT_EDGE and TEXT_RUN_FLAG_RIGHT_EDGE are specified.

Value: 8192

TEXT_RUN_FLAG_RIGHT_EDGE

Added in API level 35
static val TEXT_RUN_FLAG_RIGHT_EDGE: Int

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

This flag is used for telling the underlying text layout engine that the text is located at the most right of the line. This flag is used for controlling the amount letter spacing added. If the text is in the middle of the line, the text layout engine assigns additional letter spacing to the both side of each letter. On the other hand, the letter spacing should not be added to the visually most left and right of the line. By setting this flag, text layout engine calculates the layout as it is located at the most visually left of the line and doesn't add letter spacing to the left of this run.

Note that the caller must resolve BiDi runs and reorder them visually and set this flag only if the target run is located visually most right position. This right does not always mean the end of the text.

If the run covers entire line, caller should set TEXT_RUN_FLAG_LEFT_EDGE as well.

Note that this flag is only effective for run based APIs. For example, this flag works for Canvas.drawTextRun(CharSequence, int, int, int, int, float, float, boolean, Paint) and Paint.getRunCharacterAdvance(char[], int, int, int, int, boolean, int, float[], int). However, this doesn't work for Canvas.drawText(CharSequence, int, int, float, float, Paint) or Paint.measureText(CharSequence, int, int). The non-run based APIs works as both TEXT_RUN_FLAG_LEFT_EDGE and TEXT_RUN_FLAG_RIGHT_EDGE are specified.

Value: 16384

UNDERLINE_TEXT_FLAG

Added in API level 1
static val UNDERLINE_TEXT_FLAG: Int

Paint flag that applies an underline decoration to drawn text.

Value: 8

Public constructors

Paint

Added in API level 1
Paint()

Create a new paint with default settings.

On devices running Build.VERSION_CODES.O and below, hardware accelerated drawing always acts as if FILTER_BITMAP_FLAG is set. On devices running Build.VERSION_CODES.Q and above, FILTER_BITMAP_FLAG is set by this constructor, and it can be cleared with setFlags or setFilterBitmap. On devices running Build.VERSION_CODES.S and above, ANTI_ALIAS_FLAG is set by this constructor, and it can be cleared with setFlags or setAntiAlias.

Paint

Added in API level 1
Paint(paint: Paint!)

Create a new paint, initialized with the attributes in the specified paint parameter.

Parameters
paint Paint!: Existing paint used to initialized the attributes of the new paint.

Paint

Added in API level 1
Paint(flags: Int)

Create a new paint with the specified flags. Use setFlags() to change these after the paint is created.

On devices running Build.VERSION_CODES.O and below, hardware accelerated drawing always acts as if FILTER_BITMAP_FLAG is set. On devices running Build.VERSION_CODES.Q and above, FILTER_BITMAP_FLAG is always set by this constructor, regardless of the value of flags. It can be cleared with setFlags or setFilterBitmap.

Parameters
flags Int: initial flag bits, as if they were passed via setFlags().

Public methods

ascent

Added in API level 1
open fun ascent(): Float

Return the distance above (negative) the baseline (ascent) based on the current typeface and text size.

Note that this is the ascent of the main typeface, and actual text rendered may need a larger ascent because fallback fonts may get used in rendering the text.

Return
Float the distance above (negative) the baseline (ascent) based on the current typeface and text size.

breakText

Added in API level 1
open fun breakText(
    text: CharArray!,
    index: Int,
    count: Int,
    maxWidth: Float,
    measuredWidth: FloatArray!
): Int

Measure the text, stopping early if the measured width exceeds maxWidth. Return the number of chars that were measured, and if measuredWidth is not null, return in it the actual width measured.

Parameters
text CharArray!: The text to measure. Cannot be null.
index Int: The offset into text to begin measuring at
count Int: The number of maximum number of entries to measure. If count is negative, then the characters are measured in reverse order.
maxWidth Float: The maximum width to accumulate.
measuredWidth FloatArray!: Optional. If not null, returns the actual width measured.
Return
Int The number of chars that were measured. Will always be <= abs(count).

breakText

Added in API level 1
open fun breakText(
    text: CharSequence!,
    start: Int,
    end: Int,
    measureForwards: Boolean,
    maxWidth: Float,
    measuredWidth: FloatArray!
): Int

Measure the text, stopping early if the measured width exceeds maxWidth. Return the number of chars that were measured, and if measuredWidth is not null, return in it the actual width measured.

Parameters
text CharSequence!: The text to measure. Cannot be null.
start Int: The offset into text to begin measuring at
end Int: The end of the text slice to measure.
measureForwards Boolean: If true, measure forwards, starting at start. Otherwise, measure backwards, starting with end.
maxWidth Float: The maximum width to accumulate.
measuredWidth FloatArray!: Optional. If not null, returns the actual width measured.
Return
Int The number of chars that were measured. Will always be <= abs(end - start).

breakText

Added in API level 1
open fun breakText(
    text: String!,
    measureForwards: Boolean,
    maxWidth: Float,
    measuredWidth: FloatArray!
): Int

Measure the text, stopping early if the measured width exceeds maxWidth. Return the number of chars that were measured, and if measuredWidth is not null, return in it the actual width measured.

Parameters
text String!: The text to measure. Cannot be null.
measureForwards Boolean: If true, measure forwards, starting with the first character in the string. Otherwise, measure backwards, starting with the last character in the string.
maxWidth Float: The maximum width to accumulate.
measuredWidth FloatArray!: Optional. If not null, returns the actual width measured.
Return
Int The number of chars that were measured. Will always be <= abs(count).

clearShadowLayer

Added in API level 1
open fun clearShadowLayer(): Unit

Clear the shadow layer.

descent

Added in API level 1
open fun descent(): Float

Return the distance below (positive) the baseline (descent) based on the current typeface and text size.

Note that this is the descent of the main typeface, and actual text rendered may need a larger descent because fallback fonts may get used in rendering the text.

Return
Float the distance below (positive) the baseline (descent) based on the current typeface and text size.

equalsForTextMeasurement

Added in API level 28
open fun equalsForTextMeasurement(other: Paint): Boolean

Returns true of the passed Paint will have the same effect on text measurement

Parameters
other Paint: A Paint object. This value cannot be null.
Return
Boolean true if the other Paint has the same effect on text measurement.

getAlpha

Added in API level 1
open fun getAlpha(): Int

Helper to getColor() that just returns the color's alpha value. This is the same as calling getColor() >>> 24. It always returns a value between 0 (completely transparent) and 255 (completely opaque).

Return
Int the alpha component of the paint's color.

getBlendMode

Added in API level 29
open fun getBlendMode(): BlendMode?

Get the paint's blend mode object. Will return null if there is a Xfermode applied that cannot be represented by a blend mode (i.e. a custom RuntimeXfermode

Return
BlendMode? the paint's blend mode (or null)

getColor

Added in API level 1
open fun getColor(): Int

Return the paint's color in sRGB. Note that the color is a 32bit value containing alpha as well as r,g,b. This 32bit value is not premultiplied, meaning that its alpha can be any value, regardless of the values of r,g,b. See the Color class for more details.

Return
Int the paint's color (and alpha).

getColorFilter

Added in API level 1
open fun getColorFilter(): ColorFilter!

Get the paint's colorfilter (maybe be null).

Return
ColorFilter! the paint's colorfilter (maybe be null)

getColorLong

Added in API level 29
open fun getColorLong(): Long

Return the paint's color. Note that the color is a long with an encoded ColorSpace as well as alpha and r,g,b. These values are not premultiplied, meaning that alpha can be any value, regardless of the values of r,g,b. See the Color class for more details.

Return
Long the paint's color, alpha, and ColorSpace encoded as a ColorLong

getFillPath

Added in API level 1
open fun getFillPath(
    src: Path!,
    dst: Path!
): Boolean

Applies any/all effects (patheffect, stroking) to src, returning the result in dst. The result is that drawing src with this paint will be the same as drawing dst with a default paint (at least from the geometric perspective).

Parameters
src Path!: input path
dst Path!: output path (may be the same as src)
Return
Boolean true if the path should be filled, or false if it should be drawn with a hairline (width == 0)

getFontFeatureSettings

Added in API level 21
open fun getFontFeatureSettings(): String!

Returns the font feature settings. The format is the same as the CSS font-feature-settings attribute: https://www.w3.org/TR/css-fonts-3/#font-feature-settings-prop

Return
String! the paint's currently set font feature settings. Default is null.

getFontMetrics

Added in API level 1
open fun getFontMetrics(): Paint.FontMetrics!

Allocates a new FontMetrics object, and then calls getFontMetrics(fm) with it, returning the object.

getFontMetrics

Added in API level 1
open fun getFontMetrics(metrics: Paint.FontMetrics!): Float

Return the font's recommended interline spacing, given the Paint's settings for typeface, textSize, etc. If metrics is not null, return the fontmetric values in it.

Note that these are the values for the main typeface, and actual text rendered may need a larger set of values because fallback fonts may get used in rendering the text.

Parameters
metrics Paint.FontMetrics!: If this object is not null, its fields are filled with the appropriate values given the paint's text attributes.
Return
Float the font's recommended interline spacing.

getFontMetricsForLocale

Added in API level 35
open fun getFontMetricsForLocale(metrics: Paint.FontMetrics): Unit

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). If multiple locales are specified, the minimum ascent and maximum descent will be set. This API is useful for determining the default line height of the empty text field, e.g. android.widget.EditText. Note, if the android.graphics.Typeface is created from the custom font files, its metrics are reserved, i.e. the ascent will be the custom font's ascent or smaller, the descent will be the custom font's descent or larger. Note, if the android.graphics.Typeface is a system fallback, e.g. android.graphics.Typeface#SERIF, the default font's metrics are reserved, i.e. the ascent will be the serif font's ascent or smaller, the descent will be the serif font's descent or larger.

Parameters
metrics Paint.FontMetrics: an output parameter. All members will be set by calling this function. This value cannot be null.

getFontMetricsInt

Added in API level 1
open fun getFontMetricsInt(): Paint.FontMetricsInt!

getFontMetricsInt

Added in API level 1
open fun getFontMetricsInt(fmi: Paint.FontMetricsInt!): Int

Return the font's interline spacing, given the Paint's settings for typeface, textSize, etc. If metrics is not null, return the fontmetric values in it. Note: all values have been converted to integers from floats, in such a way has to make the answers useful for both spacing and clipping. If you want more control over the rounding, call getFontMetrics().

Note that these are the values for the main typeface, and actual text rendered may need a larger set of values because fallback fonts may get used in rendering the text.

Return
Int the font's interline spacing.

getFontMetricsInt

Added in API level 33
open fun getFontMetricsInt(
    text: CharArray,
    start: Int,
    count: Int,
    contextStart: Int,
    contextCount: Int,
    isRtl: Boolean,
    outMetrics: Paint.FontMetricsInt
): Unit

Returns the font metrics value for the given text. If the text is rendered with multiple font files, this function returns the large ascent and descent that are enough for drawing all font files. The context range is used for shaping context. Some script, e.g. Arabic or Devanagari, changes letter shape based on its location or surrounding characters.

Parameters
text CharArray: a text to be measured. This value cannot be null.
start Int: a starting offset in the text. Value is 0 or greater
count Int: a length of the text to be measured. Value is 0 or greater
contextStart Int: a context starting offset in the text. Value is 0 or greater
contextCount Int: a length of the context to be used. Value is 0 or greater
isRtl Boolean: true if measuring on RTL context, otherwise false.
outMetrics Paint.FontMetricsInt: the output font metrics. This value cannot be null.

getFontMetricsInt

Added in API level 33
open fun getFontMetricsInt(
    text: CharSequence,
    start: Int,
    count: Int,
    contextStart: Int,
    contextCount: Int,
    isRtl: Boolean,
    outMetrics: Paint.FontMetricsInt
): Unit

Returns the font metrics value for the given text. If the text is rendered with multiple font files, this function returns the large ascent and descent that are enough for drawing all font files. The context range is used for shaping context. Some script, e.g. Arabic or Devanagari, changes letter shape based on its location or surrounding characters.

Parameters
text CharSequence: a text to be measured. This value cannot be null.
start Int: a starting offset in the text. Value is 0 or greater
count Int: a length of the text to be measured. Value is 0 or greater
contextStart Int: a context starting offset in the text. Value is 0 or greater
contextCount Int: a length of the context to be used. Value is 0 or greater
isRtl Boolean: true if measuring on RTL context, otherwise false.
outMetrics Paint.FontMetricsInt: the output font metrics. This value cannot be null.

getFontMetricsIntForLocale

Added in API level 35
open fun getFontMetricsIntForLocale(metrics: Paint.FontMetricsInt): Unit

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). If multiple locales are specified, the minimum ascent and maximum descent will be set. This API is useful for determining the default line height of the empty text field, e.g. android.widget.EditText. Note, if the android.graphics.Typeface is created from the custom font files, its metrics are reserved, i.e. the ascent will be the custom font's ascent or smaller, the descent will be the custom font's descent or larger. Note, if the android.graphics.Typeface is a system fallback, e.g. android.graphics.Typeface#SERIF, the default font's metrics are reserved, i.e. the ascent will be the serif font's ascent or smaller, the descent will be the serif font's descent or larger.

Parameters
metrics Paint.FontMetricsInt: an output parameter. All members will be set by calling this function. This value cannot be null.

getFontSpacing

Added in API level 1
open fun getFontSpacing(): Float

Return the recommend line spacing based on the current typeface and text size.

Note that this is the value for the main typeface, and actual text rendered may need a larger value because fallback fonts may get used in rendering the text.

Return
Float recommend line spacing based on the current typeface and text size.

getFontVariationSettings

Added in API level 26
open fun getFontVariationSettings(): String!

Returns the font variation settings.

Return
String! the paint's currently set font variation settings. Default is null.

getHinting

Added in API level 14
open fun getHinting(): Int

Return the paint's hinting mode. Returns either HINTING_OFF or HINTING_ON.

getLetterSpacing

Added in API level 21
open fun getLetterSpacing(): Float

Return the paint's letter-spacing for text. The default value is 0.

Return
Float the paint's letter-spacing for drawing text.

getMaskFilter

Added in API level 1
open fun getMaskFilter(): MaskFilter!

Get the paint's maskfilter object.

Return
MaskFilter! the paint's maskfilter (or null)

getOffsetForAdvance

Added in API level 23
open fun getOffsetForAdvance(
    text: CharArray!,
    start: Int,
    end: Int,
    contextStart: Int,
    contextEnd: Int,
    isRtl: Boolean,
    advance: Float
): Int

Get the character offset within the string whose position is closest to the specified horizontal position.

The returned value is generally the value of offset for which #getRunAdvance yields a result most closely approximating advance, and which is also on a grapheme cluster boundary. As such, it is the preferred method for positioning a cursor in response to a touch or pointer event. The grapheme cluster boundaries are based on Unicode Standard Annex #29 but with some tailoring for better user experience.

Note that advance is a (generally positive) width measurement relative to the start of the run. Thus, for RTL runs it the distance from the point to the right edge.

All indices are relative to the start of text. Further, 0 <= contextStart <= start <= end <= contextEnd <= text.length must hold on entry, and start <= result <= end will hold on return.

Parameters
text CharArray!: the text to measure. Cannot be null.
start Int: the index of the start of the range to measure
end Int: the index + 1 of the end of the range to measure
contextStart Int: the index of the start of the shaping context
contextEnd Int: the index + 1 of the end of the range to measure
isRtl Boolean: whether the run is in RTL direction
advance Float: width relative to start of run
Return
Int index of offset

getOffsetForAdvance

Added in API level 23
open fun getOffsetForAdvance(
    text: CharSequence!,
    start: Int,
    end: Int,
    contextStart: Int,
    contextEnd: Int,
    isRtl: Boolean,
    advance: Float
): Int
Parameters
text CharSequence!: the text to measure. Cannot be null.
start Int: the index of the start of the range to measure
end Int: the index + 1 of the end of the range to measure
contextStart Int: the index of the start of the shaping context
contextEnd Int: the index + 1 of the end of the range to measure
isRtl Boolean: whether the run is in RTL direction
advance Float: width relative to start of run
Return
Int index of offset

getPathEffect

Added in API level 1
open fun getPathEffect(): PathEffect!

Get the paint's patheffect object.

Return
PathEffect! the paint's patheffect (or null)

getRunAdvance

Added in API level 23
open fun getRunAdvance(
    text: CharArray!,
    start: Int,
    end: Int,
    contextStart: Int,
    contextEnd: Int,
    isRtl: Boolean,
    offset: Int
): Float

Measure cursor position within a run of text.

The run of text includes the characters from start to end in the text. In addition, the range contextStart to contextEnd is used as context for the purpose of complex text shaping, such as Arabic text potentially shaped differently based on the text next to it.

All text outside the range contextStart..contextEnd is ignored. The text between start and end will be laid out to be measured.

The returned width measurement is the advance from start to offset. It is generally a positive value, no matter the direction of the run. If offset == end, the return value is simply the width of the whole run from start to end.

Ligatures are formed for characters in the range start..end (but not for start..contextStart or end..contextEnd). If offset points to a character in the middle of such a formed ligature, but at a grapheme cluster boundary, the return value will also reflect an advance in the middle of the ligature. See #getOffsetForAdvance for more discussion of grapheme cluster boundaries.

The direction of the run is explicitly specified by isRtl. Thus, this method is suitable only for runs of a single direction.

All indices are relative to the start of text. Further, 0 <= contextStart <= start <= offset <= end <= contextEnd <= text.length must hold on entry.

Parameters
text CharArray!: the text to measure. Cannot be null.
start Int: the index of the start of the range to measure
end Int: the index + 1 of the end of the range to measure
contextStart Int: the index of the start of the shaping context
contextEnd Int: the index + 1 of the end of the shaping context
isRtl Boolean: whether the run is in RTL direction
offset Int: index of caret position
Return
Float width measurement between start and offset

getRunAdvance

Added in API level 23
open fun getRunAdvance(
    text: CharSequence!,
    start: Int,
    end: Int,
    contextStart: Int,
    contextEnd: Int,
    isRtl: Boolean,
    offset: Int
): Float
Parameters
text CharSequence!: the text to measure. Cannot be null.
start Int: the index of the start of the range to measure
end Int: the index + 1 of the end of the range to measure
contextStart Int: the index of the start of the shaping context
contextEnd Int: the index + 1 of the end of the shaping context
isRtl Boolean: whether the run is in RTL direction
offset Int: index of caret position
Return
Float width measurement between start and offset

getRunCharacterAdvance

Added in API level 34
open fun getRunCharacterAdvance(
    text: CharArray,
    start: Int,
    end: Int,
    contextStart: Int,
    contextEnd: Int,
    isRtl: Boolean,
    offset: Int,
    advances: FloatArray?,
    advancesIndex: Int
): Float

Measure the advance of each character within a run of text and also return the cursor position within the run.

Parameters
text CharArray: the text to measure. Cannot be null.
start Int: the start index of the range to measure, inclusive
end Int: the end index of the range to measure, exclusive
contextStart Int: the start index of the shaping context, inclusive
contextEnd Int: the end index of the shaping context, exclusive
isRtl Boolean: whether the run is in RTL direction
offset Int: index of caret position
advances FloatArray?: the array that receives the computed character advances This value may be null.
advancesIndex Int: the start index from which the advances array is filled
Return
Float width measurement between start and offset
Exceptions
java.lang.IndexOutOfBoundsException if a) contextStart or contextEnd is out of array's range or contextStart is larger than contextEnd, b) start or end is not within the range [contextStart, contextEnd), or start is larger than end, c) offset is not within the range [start, end), d) advances.length - advanceIndex is smaller than the length of the run, which equals to end - start.

getRunCharacterAdvance

Added in API level 34
open fun getRunCharacterAdvance(
    text: CharSequence,
    start: Int,
    end: Int,
    contextStart: Int,
    contextEnd: Int,
    isRtl: Boolean,
    offset: Int,
    advances: FloatArray?,
    advancesIndex: Int
): Float
Parameters
text CharSequence: the text to measure. Cannot be null.
start Int: the index of the start of the range to measure
end Int: the index + 1 of the end of the range to measure
contextStart Int: the index of the start of the shaping context
contextEnd Int: the index + 1 of the end of the shaping context
isRtl Boolean: whether the run is in RTL direction
offset Int: index of caret position
advances FloatArray?: the array that receives the computed character advances This value may be null.
advancesIndex Int: the start index from which the advances array is filled
Return
Float width measurement between start and offset
Exceptions
java.lang.IndexOutOfBoundsException if a) contextStart or contextEnd is out of array's range or contextStart is larger than contextEnd, b) start or end is not within the range [contextStart, contextEnd), or end is larger than start, c) offset is not within the range [start, end), d) advances.length - advanceIndex is smaller than the run length, which equals to end - start.

getShader

Added in API level 1
open fun getShader(): Shader!

Get the paint's shader object.

Return
Shader! the paint's shader (or null)

getShadowLayerColor

Added in API level 29
open fun getShadowLayerColor(): Int

Returns the color of the shadow layer.

getShadowLayerColorLong

Added in API level 29
open fun getShadowLayerColorLong(): Long

Returns the color of the shadow layer.

Return
Long the shadow layer's color encoded as a ColorLong.

getShadowLayerDx

Added in API level 29
open fun getShadowLayerDx(): Float

Returns the x offset of the shadow layer.

getShadowLayerDy

Added in API level 29
open fun getShadowLayerDy(): Float

Returns the y offset of the shadow layer.

getShadowLayerRadius

Added in API level 29
open fun getShadowLayerRadius(): Float

Returns the blur radius of the shadow layer.

getStartHyphenEdit

Added in API level 29
open fun getStartHyphenEdit(): Int

Get the current value of start hyphen edit. The default value is 0 which is equivalent to START_HYPHEN_EDIT_NO_EDIT.

Return
Int the current starting hyphen edit value Value is android.graphics.Paint#START_HYPHEN_EDIT_NO_EDIT, android.graphics.Paint#START_HYPHEN_EDIT_INSERT_HYPHEN, or android.graphics.Paint#START_HYPHEN_EDIT_INSERT_ZWJ

getStrikeThruPosition

Added in API level 29
open fun getStrikeThruPosition(): Float

Distance from top of the strike-through line to the baseline in pixels. The result is negative for positions that are above the baseline. This method returns where the strike-through line should be drawn independent of if the STRIKE_THRU_TEXT_FLAG bit is set.
The units of this value are pixels.

Return
Float the position of the strike-through line in pixels The units of this value are pixels. {}

getStrikeThruThickness

Added in API level 29
open fun getStrikeThruThickness(): Float

Returns the thickness of the strike-through line in pixels.
The units of this value are pixels.

Return
Float the position of the strike-through line in pixels The units of this value are pixels. {}

getStrokeCap

Added in API level 1
open fun getStrokeCap(): Paint.Cap!

Return the paint's Cap, controlling how the start and end of stroked lines and paths are treated.

Return
Paint.Cap! the line cap style for the paint, used whenever the paint's style is Stroke or StrokeAndFill.

getStrokeJoin

Added in API level 1
open fun getStrokeJoin(): Paint.Join!

Return the paint's stroke join type.

Return
Paint.Join! the paint's Join.

getStrokeMiter

Added in API level 1
open fun getStrokeMiter(): Float

Return the paint's stroke miter value. Used to control the behavior of miter joins when the joins angle is sharp.

Return
Float the paint's miter limit, used whenever the paint's style is Stroke or StrokeAndFill.

getStrokeWidth

Added in API level 1
open fun getStrokeWidth(): Float

Return the width for stroking.

A value of 0 strokes in hairline mode. Hairlines always draws a single pixel independent of the canvas's matrix.
Return
Float the paint's stroke width, used whenever the paint's style is Stroke or StrokeAndFill.

getStyle

Added in API level 1
open fun getStyle(): Paint.Style!

Return the paint's style, used for controlling how primitives' geometries are interpreted (except for drawBitmap, which always assumes FILL_STYLE).

Return
Paint.Style! the paint's style setting (Fill, Stroke, StrokeAndFill)

getTextAlign

Added in API level 1
open fun getTextAlign(): Paint.Align!

Return the paint's Align value for drawing text. This controls how the text is positioned relative to its origin. LEFT align means that all of the text will be drawn to the right of its origin (i.e. the origin specifies the LEFT edge of the text) and so on.

Return
Paint.Align! the paint's Align value for drawing text.

getTextBounds

Added in API level 1
open fun getTextBounds(
    text: CharArray!,
    index: Int,
    count: Int,
    bounds: Rect!
): Unit

Return in bounds (allocated by the caller) the smallest rectangle that encloses all of the characters, with an implied origin at (0,0).

Parameters
text CharArray!: array of chars to measure and return their unioned bounds
index Int: index of the first char in the array to measure
count Int: the number of chars, beginning at index, to measure
bounds Rect!: returns the unioned bounds of all the text. Must be allocated by the caller

getTextBounds

Added in API level 29
open fun getTextBounds(
    text: CharSequence,
    start: Int,
    end: Int,
    bounds: Rect
): Unit

Retrieve the text boundary box and store to bounds. Return in bounds (allocated by the caller) the smallest rectangle that encloses all of the characters, with an implied origin at (0,0). Note that styles are ignored even if you pass android.text.Spanned instance. Use android.text.StaticLayout for measuring bounds of android.text.Spanned.

Parameters
text CharSequence: text to measure and return its bounds This value cannot be null.
start Int: index of the first char in the text to measure
end Int: 1 past the last char in the text to measure
bounds Rect: returns the unioned bounds of all the text. Must be allocated by the caller This value cannot be null.

getTextBounds

Added in API level 1
open fun getTextBounds(
    text: String!,
    start: Int,
    end: Int,
    bounds: Rect!
): Unit

Retrieve the text boundary box and store to bounds. Return in bounds (allocated by the caller) the smallest rectangle that encloses all of the characters, with an implied origin at (0,0).

Parameters
text String!: string to measure and return its bounds
start Int: index of the first char in the string to measure
end Int: 1 past the last char in the string to measure
bounds Rect!: returns the unioned bounds of all the text. Must be allocated by the caller

getTextLocale

Added in API level 17
open fun getTextLocale(): Locale

Get the text's primary Locale. Note that this is not all of the locale-related information Paint has. Use getTextLocales() to get the complete list.

Return
Locale the paint's primary Locale used for drawing text, never null.

getTextLocales

Added in API level 24
open fun getTextLocales(): LocaleList

Get the text locale list.

Return
LocaleList the paint's LocaleList used for drawing text, never null or empty.

getTextPath

Added in API level 1
open fun getTextPath(
    text: CharArray!,
    index: Int,
    count: Int,
    x: Float,
    y: Float,
    path: Path!
): Unit

Return the path (outline) for the specified text. Note: just like Canvas.drawText, this will respect the Align setting in the paint.

Parameters
text CharArray!: the text to retrieve the path from
index Int: the index of the first character in text
count Int: the number of characters starting with index
x Float: the x coordinate of the text's origin
y Float: the y coordinate of the text's origin
path Path!: the path to receive the data describing the text. Must be allocated by the caller

getTextPath

Added in API level 1
open fun getTextPath(
    text: String!,
    start: Int,
    end: Int,
    x: Float,
    y: Float,
    path: Path!
): Unit

Return the path (outline) for the specified text. Note: just like Canvas.drawText, this will respect the Align setting in the paint.

Parameters
text String!: the text to retrieve the path from
start Int: the first character in the text
end Int: 1 past the last character in the text
x Float: the x coordinate of the text's origin
y Float: the y coordinate of the text's origin
path Path!: the path to receive the data describing the text. Must be allocated by the caller

getTextRunAdvances

Added in API level 29
open fun getTextRunAdvances(
    chars: CharArray,
    index: Int,
    count: Int,
    contextIndex: Int,
    contextCount: Int,
    isRtl: Boolean,
    advances: FloatArray?,
    advancesIndex: Int
): Float

Retrieve the character advances of the text. Returns the total advance width for the characters in the run from index for count of chars, and if advances is not null, the advance assigned to each of these characters (java chars).

The trailing surrogate in a valid surrogate pair is assigned an advance of 0. Thus the number of returned advances is always equal to count, not to the number of unicode codepoints represented by the run.

In the case of conjuncts or combining marks, the total advance is assigned to the first logical character, and the following characters are assigned an advance of 0.

This generates the sum of the advances of glyphs for characters in a reordered cluster as the width of the first logical character in the cluster, and 0 for the widths of all other characters in the cluster. In effect, such clusters are treated like conjuncts.

The shaping bounds limit the amount of context available outside start and end that can be used for shaping analysis. These bounds typically reflect changes in bidi level or font metrics across which shaping does not occur.

Parameters
chars CharArray: the text to measure. This value cannot be null.
index Int: the index of the first character to measure Value is 0 or greater
count Int: the number of characters to measure Value is 0 or greater
contextIndex Int: the index of the first character to use for shaping context. Context must cover the measureing target. Value is 0 or greater
contextCount Int: the number of character to use for shaping context. Context must cover the measureing target. Value is 0 or greater
isRtl Boolean: whether the run is in RTL direction
advances FloatArray?: array to receive the advances, must have room for all advances. This can be null if only total advance is needed
advancesIndex Int: the position in advances at which to put the advance corresponding to the character at start Value is 0 or greater
Return
Float the total advance in pixels

getTextRunCursor

Added in API level 29
open fun getTextRunCursor(
    text: CharArray,
    contextStart: Int,
    contextLength: Int,
    isRtl: Boolean,
    offset: Int,
    cursorOpt: Int
): Int

Returns the next cursor position in the run. This avoids placing the cursor between surrogates, between characters that form conjuncts, between base characters and combining marks, or within a reordering cluster.

ContextStart and offset are relative to the start of text. The context is the shaping context for cursor movement, generally the bounds of the metric span enclosing the cursor in the direction of movement.

If cursorOpt is CURSOR_AT and the offset is not a valid cursor position, this returns -1. Otherwise this will never return a value before contextStart or after contextStart + contextLength.

Parameters
text CharArray: the text This value cannot be null.
contextStart Int: the start of the context Value is 0 or greater
contextLength Int: the length of the context Value is 0 or greater
isRtl Boolean: true if the paragraph context is RTL, otherwise false
offset Int: the cursor position to move from Value is 0 or greater
cursorOpt Int: how to move the cursor Value is android.graphics.Paint#CURSOR_AFTER, android.graphics.Paint#CURSOR_AT_OR_AFTER, android.graphics.Paint#CURSOR_BEFORE, or android.graphics.Paint#CURSOR_AT_OR_BEFORE
Return
Int the offset of the next position, or -1

getTextRunCursor

Added in API level 29
open fun getTextRunCursor(
    text: CharSequence,
    contextStart: Int,
    contextEnd: Int,
    isRtl: Boolean,
    offset: Int,
    cursorOpt: Int
): Int

Returns the next cursor position in the run. This avoids placing the cursor between surrogates, between characters that form conjuncts, between base characters and combining marks, or within a reordering cluster.

ContextStart, contextEnd, and offset are relative to the start of text. The context is the shaping context for cursor movement, generally the bounds of the metric span enclosing the cursor in the direction of movement.

If cursorOpt is CURSOR_AT and the offset is not a valid cursor position, this returns -1. Otherwise this will never return a value before contextStart or after contextEnd.

Parameters
text CharSequence: the text This value cannot be null.
contextStart Int: the start of the context Value is 0 or greater
contextEnd Int: the end of the context Value is 0 or greater
isRtl Boolean: true if the paragraph context is RTL, otherwise false
offset Int: the cursor position to move from Value is 0 or greater
cursorOpt Int: how to move the cursor Value is android.graphics.Paint#CURSOR_AFTER, android.graphics.Paint#CURSOR_AT_OR_AFTER, android.graphics.Paint#CURSOR_BEFORE, or android.graphics.Paint#CURSOR_AT_OR_BEFORE
Return
Int the offset of the next position, or -1

getTextScaleX

Added in API level 1
open fun getTextScaleX(): Float

Return the paint's horizontal scale factor for text. The default value is 1.0.

Return
Float the paint's scale factor in X for drawing/measuring text

getTextSize

Added in API level 1
open fun getTextSize(): Float

Return the paint's text size.

Return
Float the paint's text size in pixel units.

getTextSkewX

Added in API level 1
open fun getTextSkewX(): Float

Return the paint's horizontal skew factor for text. The default value is 0.

Return
Float the paint's skew factor in X for drawing text.

getTextWidths

Added in API level 1
open fun getTextWidths(
    text: CharArray!,
    index: Int,
    count: Int,
    widths: FloatArray!
): Int

Return the advance widths for the characters in the string.

Parameters
text CharArray!: The text to measure. Cannot be null.
index Int: The index of the first char to to measure
count Int: The number of chars starting with index to measure
widths FloatArray!: array to receive the advance widths of the characters. Must be at least a large as count.
Return
Int the actual number of widths returned.

getTextWidths

Added in API level 1
open fun getTextWidths(
    text: CharSequence!,
    start: Int,
    end: Int,
    widths: FloatArray!
): Int

Return the advance widths for the characters in the string.

Parameters
text CharSequence!: The text to measure. Cannot be null.
start Int: The index of the first char to to measure
end Int: The end of the text slice to measure
widths FloatArray!: array to receive the advance widths of the characters. Must be at least a large as (end - start).
Return
Int the actual number of widths returned.

getTextWidths

Added in API level 1
open fun getTextWidths(
    text: String!,
    widths: FloatArray!
): Int

Return the advance widths for the characters in the string.

Parameters
text String!: The text to measure
widths FloatArray!: array to receive the advance widths of the characters. Must be at least a large as the text.
Return
Int the number of code units in the specified text.

getTextWidths

Added in API level 1
open fun getTextWidths(
    text: String!,
    start: Int,
    end: Int,
    widths: FloatArray!
): Int

Return the advance widths for the characters in the string.

Parameters
text String!: The text to measure. Cannot be null.
start Int: The index of the first char to to measure
end Int: The end of the text slice to measure
widths FloatArray!: array to receive the advance widths of the characters. Must be at least a large as the text.
Return
Int the number of code units in the specified text.

getTypeface

Added in API level 1
open fun getTypeface(): Typeface!

Get the paint's typeface object.

The typeface object identifies which font to use when drawing or measuring text.
Return
Typeface! the paint's typeface (or null)

getUnderlinePosition

Added in API level 29
open fun getUnderlinePosition(): Float

Returns the distance from top of the underline to the baseline in pixels. The result is positive for positions that are below the baseline. This method returns where the underline should be drawn independent of if the UNDERLINE_TEXT_FLAG bit is set.
The units of this value are pixels.

Return
Float the position of the underline in pixels The units of this value are pixels. {}

getUnderlineThickness

Added in API level 29
open fun getUnderlineThickness(): Float

Returns the thickness of the underline in pixels.
The units of this value are pixels.

Return
Float the thickness of the underline in pixels The units of this value are pixels. {}

getWordSpacing

Added in API level 29
open fun getWordSpacing(): Float

Return the paint's extra word-spacing for text. The default value is 0.
The units of this value are pixels.

Return
Float the paint's extra word-spacing for drawing text in pixels. The units of this value are pixels. {}

getXfermode

Added in API level 1
open fun getXfermode(): Xfermode!

Get the paint's transfer mode object.

Return
Xfermode! the paint's transfer mode (or null)

hasGlyph

Added in API level 23
open fun hasGlyph(string: String!): Boolean

Determine whether the typeface set on the paint has a glyph supporting the string. The simplest case is when the string contains a single character, in which this method determines whether the font has the character. In the case of multiple characters, the method returns true if there is a single glyph representing the ligature. For example, if the input is a pair of regional indicator symbols, determine whether there is an emoji flag for the pair.

Finally, if the string contains a variation selector, the method only returns true if the fonts contains a glyph specific to that variation.

Checking is done on the entire fallback chain, not just the immediate font referenced.

Parameters
string String!: the string to test whether there is glyph support
Return
Boolean true if the typeface has a glyph for the string

isAntiAlias

Added in API level 1
fun isAntiAlias(): Boolean

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. See setDither() and setFilterBitmap() to affect how colors are treated.

Return
Boolean true if the antialias bit is set in the paint's flags.

isDither

Added in API level 1
fun isDither(): Boolean

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. No dithering is generally faster, but higher precision colors are just truncated down (e.g. 8888 -> 565). Dithering tries to distribute the error inherent in this process, to reduce the visual artifacts.

Return
Boolean true if the dithering bit is set in the paint's flags.

isElegantTextHeight

open fun isElegantTextHeight(): Boolean

Get the elegant metrics flag. Note: For applications target API 35 or later, this function returns true by default. For applications target API 36 or later, the function call will be ignored and the elegant text height is always enabled.

Return
Boolean true if elegant metrics are enabled for text drawing.

isFakeBoldText

Added in API level 1
fun isFakeBoldText(): Boolean

Helper for getFlags(), returning true if FAKE_BOLD_TEXT_FLAG bit is set

Return
Boolean true if the fakeBoldText bit is set in the paint's flags.

isFilterBitmap

Added in API level 1
fun isFilterBitmap(): Boolean

Whether or not the bitmap filter is activated. Filtering affects the sampling of bitmaps when they are transformed. Filtering does not affect how the colors in the bitmap are converted into device pixels. That is dependent on dithering and xfermodes.

isLinearText

Added in API level 1
fun isLinearText(): Boolean

Helper for getFlags(), returning true if LINEAR_TEXT_FLAG bit is set

Return
Boolean true if the lineartext bit is set in the paint's flags

isStrikeThruText

Added in API level 1
fun isStrikeThruText(): Boolean

Helper for getFlags(), returning true if STRIKE_THRU_TEXT_FLAG bit is set

Return
Boolean true if the STRIKE_THRU_TEXT_FLAG bit is set in the paint's flags.

isSubpixelText

Added in API level 1
fun isSubpixelText(): Boolean

Helper for getFlags(), returning true if SUBPIXEL_TEXT_FLAG bit is set

Return
Boolean true if the subpixel bit is set in the paint's flags

isUnderlineText

Added in API level 1
fun isUnderlineText(): Boolean

Helper for getFlags(), returning true if UNDERLINE_TEXT_FLAG bit is set

Return
Boolean true if the underlineText bit is set in the paint's flags.

measureText

Added in API level 1
open fun measureText(
    text: CharArray!,
    index: Int,
    count: Int
): Float

Return the width of the text.

Parameters
text CharArray!: The text to measure. Cannot be null.
index Int: The index of the first character to start measuring
count Int: THe number of characters to measure, beginning with start
Return
Float The width of the text

measureText

Added in API level 1
open fun measureText(
    text: CharSequence!,
    start: Int,
    end: Int
): Float

Return the width of the text.

Parameters
text CharSequence!: The text to measure
start Int: The index of the first character to start measuring
end Int: 1 beyond the index of the last character to measure
Return
Float The width of the text

measureText

Added in API level 1
open fun measureText(text: String!): Float

Return the width of the text.

Parameters
text String!: The text to measure. Cannot be null.
Return
Float The width of the text

measureText

Added in API level 1
open fun measureText(
    text: String!,
    start: Int,
    end: Int
): Float

Return the width of the text.

Parameters
text String!: The text to measure. Cannot be null.
start Int: The index of the first character to start measuring
end Int: 1 beyond the index of the last character to measure
Return
Float The width of the text

reset

Added in API level 1
open fun reset(): Unit

Restores the paint to its default settings.

set

Added in API level 1
open fun set(src: Paint!): Unit

Copy the fields from src into this paint. This is equivalent to calling get() on all of the src fields, and calling the corresponding set() methods on this.

setARGB

Added in API level 1
open fun setARGB(
    a: Int,
    r: Int,
    g: Int,
    b: Int
): Unit

Helper to setColor(), that takes a,r,g,b and constructs the color int

Parameters
a Int: The new alpha component (0..255) of the paint's color.
r Int: The new red component (0..255) of the paint's color.
g Int: The new green component (0..255) of the paint's color.
b Int: The new blue component (0..255) of the paint's color.

setAlpha

Added in API level 1
open fun setAlpha(a: Int): Unit

Helper to setColor(), that only assigns the color's alpha value, leaving its r,g,b values unchanged. Results are undefined if the alpha value is outside of the range [0..255]

Parameters
a Int: set the alpha component [0..255] of the paint's color.

setAntiAlias

Added in API level 1
open fun setAntiAlias(aa: Boolean): Unit

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. See setDither() and setFilterBitmap() to affect how colors are treated.

Parameters
aa Boolean: true to set the antialias bit in the flags, false to clear it

setBlendMode

Added in API level 29
open fun setBlendMode(blendmode: BlendMode?): Unit

Set or clear the blend mode. A blend mode defines how source pixels (generated by a drawing command) are composited with the destination pixels (content of the render target).

Pass null to clear any previous blend mode.

Parameters
blendmode BlendMode?: May be null. The blend mode to be installed in the paint

setColor

Added in API level 1
open fun setColor(color: Int): Unit

Set the paint's color. Note that the color is an int containing alpha as well as r,g,b. This 32bit value is not premultiplied, meaning that its alpha can be any value, regardless of the values of r,g,b. See the Color class for more details.

Parameters
color Int: The new color (including alpha) to set in the paint.

setColor

Added in API level 29
open fun setColor(color: Long): Unit

Set the paint's color with a ColorLong. Note that the color is a long with an encoded ColorSpace as well as alpha and r,g,b. These values are not premultiplied, meaning that alpha can be any value, regardless of the values of r,g,b. See the Color class for more details.

Parameters
color Long: The new color (including alpha and ColorSpace) to set in the paint.
Exceptions
java.lang.IllegalArgumentException if the color space encoded in the ColorLong is invalid or unknown.

setColorFilter

Added in API level 1
open fun setColorFilter(filter: ColorFilter!): ColorFilter!

Set or clear the paint's colorfilter, returning the parameter.

Parameters
filter ColorFilter!: May be null. The new filter to be installed in the paint
Return
ColorFilter! filter

setDither

Added in API level 1
open fun setDither(dither: Boolean): Unit

Helper for setFlags(), setting or clearing the DITHER_FLAG bit Dithering affects how colors that are higher precision than the device are down-sampled. No dithering is generally faster, but higher precision colors are just truncated down (e.g. 8888 -> 565). Dithering tries to distribute the error inherent in this process, to reduce the visual artifacts.

Parameters
dither Boolean: true to set the dithering bit in flags, false to clear it

setElegantTextHeight

open fun setElegantTextHeight(elegant: Boolean): Unit

Set the paint's elegant height metrics flag. This setting selects font variants that have not been compacted to fit Latin-based vertical metrics, and also increases top and bottom bounds to provide more space.

Note: For applications target API 35 or later, the default value will be true by default. For applications target API 36 or later, the function call will be ignored and the elegant text height is always enabled.

Parameters
elegant Boolean: set the paint's elegant metrics flag for drawing text.

setEndHyphenEdit

Added in API level 29
open fun setEndHyphenEdit(endHyphen: Int): Unit

Set a end hyphen edit on the paint. By setting end hyphen edit, the measurement and drawing is performed with modifying hyphenation at the end of line. For example, by passing END_HYPHEN_EDIT_INSERT_HYPHEN like as follows, HYPHEN(U+2010) character is appended at the end of line.

<code>
    Paint paint = new Paint();
    paint.setEndHyphenEdit(Paint.END_HYPHEN_EDIT_INSERT_HYPHEN);
    paint.measureText("abc", 0, 3);  // Returns the width of "abc-"
    Canvas.drawText("abc", 0, 3, 0f, 0f, paint);  // Draws "abc-"
  </code>
The default value is 0 which is equivalent to END_HYPHEN_EDIT_NO_EDIT.

Parameters
endHyphen Int: a end hyphen edit value. Value is android.graphics.Paint#END_HYPHEN_EDIT_NO_EDIT, android.graphics.Paint#END_HYPHEN_EDIT_REPLACE_WITH_HYPHEN, android.graphics.Paint#END_HYPHEN_EDIT_INSERT_HYPHEN, android.graphics.Paint#END_HYPHEN_EDIT_INSERT_ARMENIAN_HYPHEN, android.graphics.Paint#END_HYPHEN_EDIT_INSERT_MAQAF, android.graphics.Paint#END_HYPHEN_EDIT_INSERT_UCAS_HYPHEN, or android.graphics.Paint#END_HYPHEN_EDIT_INSERT_ZWJ_AND_HYPHEN

setFakeBoldText

Added in API level 1
open fun setFakeBoldText(fakeBoldText: Boolean): Unit

Helper for setFlags(), setting or clearing the FAKE_BOLD_TEXT_FLAG bit

Parameters
fakeBoldText Boolean: true to set the fakeBoldText bit in the paint's flags, false to clear it.

setFilterBitmap

Added in API level 1
open fun setFilterBitmap(filter: Boolean): Unit

Helper for setFlags(), setting or clearing the FILTER_BITMAP_FLAG bit. Filtering affects the sampling of bitmaps when they are transformed. Filtering does not affect how the colors in the bitmap are converted into device pixels. That is dependent on dithering and xfermodes.

Parameters
filter Boolean: true to set the FILTER_BITMAP_FLAG bit in the paint's flags, false to clear it.

setFontFeatureSettings

Added in API level 21
open fun setFontFeatureSettings(settings: String!): Unit

Set font feature settings. The format is the same as the CSS font-feature-settings attribute: https://www.w3.org/TR/css-fonts-3/#font-feature-settings-prop

Parameters
settings String!: the font feature settings string to use, may be null.

setFontVariationSettings

Added in API level 26
open fun setFontVariationSettings(fontVariationSettings: String!): Boolean

Sets TrueType or OpenType font variation settings. The settings string is constructed from multiple pairs of axis tag and style values. The axis tag must contain four ASCII characters and must be wrapped with single quotes (U+0027) or double quotes (U+0022). Axis strings that are longer or shorter than four characters, or contain characters outside of U+0020..U+007E are invalid. If a specified axis name is not defined in the font, the settings will be ignored. Examples,

  • Set font width to 150.
    <code>
        Paint paint = new Paint();
        paint.setFontVariationSettings("'wdth' 150");
      </code>
  • Set the font slant to 20 degrees and ask for italic style.
    <code>
        Paint paint = new Paint();
        paint.setFontVariationSettings("'slnt' 20, 'ital' 1");
      </code>

Note: If the application that targets API 35 or before, this function mutates the underlying typeface instance.

Parameters
fontVariationSettings String!: font variation settings. You can pass null or empty string as no variation settings.
Return
Boolean If the application that targets API 36 or later and is running on devices API 36 or later, this function always returns true. Otherwise, this function returns true if the given settings is effective to at least one font file underlying this typeface. This function also returns true for empty settings string. Otherwise returns false.
Exceptions
java.lang.IllegalArgumentException If given string is not a valid font variation settings format

setHinting

Added in API level 14
open fun setHinting(mode: Int): Unit

Set the paint's hinting mode. May be either HINTING_OFF or HINTING_ON.

setLetterSpacing

Added in API level 21
open fun setLetterSpacing(letterSpacing: Float): Unit

Set the paint's letter-spacing for text. The default value is 0. The value is in 'EM' units. Typical values for slight expansion will be around 0.05. Negative values tighten text.

Parameters
letterSpacing Float: set the paint's letter-spacing for drawing text.

setLinearText

Added in API level 1
open fun setLinearText(linearText: Boolean): Unit

Helper for setFlags(), setting or clearing the LINEAR_TEXT_FLAG bit

Parameters
linearText Boolean: true to set the linearText bit in the paint's flags, false to clear it.

setMaskFilter

Added in API level 1
open fun setMaskFilter(maskfilter: MaskFilter!): MaskFilter!

Set or clear the maskfilter object.

Pass null to clear any previous maskfilter. As a convenience, the parameter passed is also returned.
Parameters
maskfilter MaskFilter!: May be null. The maskfilter to be installed in the paint
Return
MaskFilter! maskfilter

setPathEffect

Added in API level 1
open fun setPathEffect(effect: PathEffect!): PathEffect!

Set or clear the patheffect object.

Pass null to clear any previous patheffect. As a convenience, the parameter passed is also returned.
Parameters
effect PathEffect!: May be null. The patheffect to be installed in the paint
Return
PathEffect! effect

setShader

Added in API level 1
open fun setShader(shader: Shader!): Shader!

Set or clear the shader object.

Pass null to clear any previous shader. As a convenience, the parameter passed is also returned.
Parameters
shader Shader!: May be null. the new shader to be installed in the paint
Return
Shader! shader

setShadowLayer

Added in API level 1
open fun setShadowLayer(
    radius: Float,
    dx: Float,
    dy: Float,
    shadowColor: Int
): Unit

This draws a shadow layer below the main layer, with the specified offset and color, and blur radius. If radius is 0, then the shadow layer is removed.

Can be used to create a blurred shadow underneath text. Support for use with other drawing operations is constrained to the software rendering pipeline.

The alpha of the shadow will be the paint's alpha if the shadow color is opaque, or the alpha from the shadow color if not.

setShadowLayer

Added in API level 29
open fun setShadowLayer(
    radius: Float,
    dx: Float,
    dy: Float,
    shadowColor: Long
): Unit

This draws a shadow layer below the main layer, with the specified offset and color, and blur radius. If radius is 0, then the shadow layer is removed.

Can be used to create a blurred shadow underneath text. Support for use with other drawing operations is constrained to the software rendering pipeline.

The alpha of the shadow will be the paint's alpha if the shadow color is opaque, or the alpha from the shadow color if not.

Exceptions
java.lang.IllegalArgumentException if the color space encoded in the ColorLong is invalid or unknown.

setStartHyphenEdit

Added in API level 29
open fun setStartHyphenEdit(startHyphen: Int): Unit

Set a start hyphen edit on the paint. By setting start hyphen edit, the measurement and drawing is performed with modifying hyphenation at the start of line. For example, by passing START_HYPHEN_EDIT_INSERT_HYPHEN like as follows, HYPHEN(U+2010) character is appended at the start of line.

<code>
    Paint paint = new Paint();
    paint.setStartHyphenEdit(Paint.START_HYPHEN_EDIT_INSERT_HYPHEN);
    paint.measureText("abc", 0, 3);  // Returns the width of "-abc"
    Canvas.drawText("abc", 0, 3, 0f, 0f, paint);  // Draws "-abc"
  </code>
The default value is 0 which is equivalent to START_HYPHEN_EDIT_NO_EDIT.

Parameters
startHyphen Int: a start hyphen edit value. Value is android.graphics.Paint#START_HYPHEN_EDIT_NO_EDIT, android.graphics.Paint#START_HYPHEN_EDIT_INSERT_HYPHEN, or android.graphics.Paint#START_HYPHEN_EDIT_INSERT_ZWJ

setStrikeThruText

Added in API level 1
open fun setStrikeThruText(strikeThruText: Boolean): Unit

Helper for setFlags(), setting or clearing the STRIKE_THRU_TEXT_FLAG bit

Parameters
strikeThruText Boolean: true to set the strikeThruText bit in the paint's flags, false to clear it.

setStrokeCap

Added in API level 1
open fun setStrokeCap(cap: Paint.Cap!): Unit

Set the paint's Cap.

Parameters
cap Paint.Cap!: set the paint's line cap style, used whenever the paint's style is Stroke or StrokeAndFill.

setStrokeJoin

Added in API level 1
open fun setStrokeJoin(join: Paint.Join!): Unit

Set the paint's Join.

Parameters
join Paint.Join!: set the paint's Join, used whenever the paint's style is Stroke or StrokeAndFill.

setStrokeMiter

Added in API level 1
open fun setStrokeMiter(miter: Float): Unit

Set the paint's stroke miter value. This is used to control the behavior of miter joins when the joins angle is sharp. This value must be >= 0.

Parameters
miter Float: set the miter limit on the paint, used whenever the paint's style is Stroke or StrokeAndFill.

setStrokeWidth

Added in API level 1
open fun setStrokeWidth(width: Float): Unit

Set the width for stroking. Pass 0 to stroke in hairline mode. Hairlines always draws a single pixel independent of the canvas's matrix.

Parameters
width Float: set the paint's stroke width, used whenever the paint's style is Stroke or StrokeAndFill.

setStyle

Added in API level 1
open fun setStyle(style: Paint.Style!): Unit

Set the paint's style, used for controlling how primitives' geometries are interpreted (except for drawBitmap, which always assumes Fill).

Parameters
style Paint.Style!: The new style to set in the paint

setSubpixelText

Added in API level 1
open fun setSubpixelText(subpixelText: Boolean): Unit

Helper for setFlags(), setting or clearing the SUBPIXEL_TEXT_FLAG bit

Parameters
subpixelText Boolean: true to set the subpixelText bit in the paint's flags, false to clear it.

setTextAlign

Added in API level 1
open fun setTextAlign(align: Paint.Align!): Unit

Set the paint's text alignment. This controls how the text is positioned relative to its origin. LEFT align means that all of the text will be drawn to the right of its origin (i.e. the origin specifies the LEFT edge of the text) and so on.

Parameters
align Paint.Align!: set the paint's Align value for drawing text.

setTextLocale

Added in API level 17
open fun setTextLocale(locale: Locale): Unit

Set the text locale list to a one-member list consisting of just the locale. See setTextLocales(android.os.LocaleList) for how the locale list affects the way the text is drawn for some languages.

Parameters
locale Locale: the paint's locale value for drawing text, must not be null.

setTextLocales

Added in API level 24
open fun setTextLocales(locales: LocaleList): Unit

Set the text locale list. The text locale list affects how the text is drawn for some languages. For example, if the locale list contains Locale.CHINESE or Locale.CHINA, then the text renderer will prefer to draw text using a Chinese font. Likewise, if the locale list contains Locale.JAPANESE or Locale.JAPAN, then the text renderer will prefer to draw text using a Japanese font. If the locale list contains both, the order those locales appear in the list is considered for deciding the font. This distinction is important because Chinese and Japanese text both use many of the same Unicode code points but their appearance is subtly different for each language. By default, the text locale list is initialized to a one-member list just containing the system locales. This assumes that the text to be rendered will most likely be in the user's preferred language. If the actual language or languages of the text is/are known, then they can be provided to the text renderer using this method. The text renderer may attempt to guess the language script based on the contents of the text to be drawn independent of the text locale here. Specifying the text locales just helps it do a better job in certain ambiguous cases.

Parameters
locales LocaleList: the paint's locale list for drawing text, must not be null or empty.

setTextScaleX

Added in API level 1
open fun setTextScaleX(scaleX: Float): Unit

Set the paint's horizontal scale factor for text. The default value is 1.0. Values > 1.0 will stretch the text wider. Values < 1.0 will stretch the text narrower.

Parameters
scaleX Float: set the paint's scale in X for drawing/measuring text.

setTextSize

Added in API level 1
open fun setTextSize(textSize: Float): Unit

Set the paint's text size. This value must be > 0

Parameters
textSize Float: set the paint's text size in pixel units.

setTextSkewX

Added in API level 1
open fun setTextSkewX(skewX: Float): Unit

Set the paint's horizontal skew factor for text. The default value is 0. For approximating oblique text, use values around -0.25.

Parameters
skewX Float: set the paint's skew factor in X for drawing text.

setTypeface

Added in API level 1
open fun setTypeface(typeface: Typeface!): Typeface!

Set or clear the typeface object.

Pass null to clear any previous typeface. As a convenience, the parameter passed is also returned.
Parameters
typeface Typeface!: May be null. The typeface to be installed in the paint
Return
Typeface! typeface

setUnderlineText

Added in API level 1
open fun setUnderlineText(underlineText: Boolean): Unit

Helper for setFlags(), setting or clearing the UNDERLINE_TEXT_FLAG bit

Parameters
underlineText Boolean: true to set the underlineText bit in the paint's flags, false to clear it.

setWordSpacing

Added in API level 29
open fun setWordSpacing(wordSpacing: Float): Unit

Set the paint's extra word-spacing for text. Increases the white space width between words with the given amount of pixels. The default value is 0.

Parameters
wordSpacing Float: set the paint's extra word-spacing for drawing text in pixels. The units of this value are pixels.

setXfermode

Added in API level 1
open fun setXfermode(xfermode: Xfermode!): Xfermode!

Set or clear the transfer mode object. A transfer mode defines how source pixels (generate by a drawing command) are composited with the destination pixels (content of the render target).

Pass null to clear any previous transfer mode. As a convenience, the parameter passed is also returned.

PorterDuffXfermode is the most common transfer mode.
Parameters
xfermode Xfermode!: May be null. The xfermode to be installed in the paint
Return
Xfermode! xfermode