Modifier and Type | Class and Description |
---|---|
static class |
Paint.Align
Align specifies how drawText aligns its text relative to the
[x,y] coordinates.
|
static class |
Paint.Cap
The Cap specifies the treatment for the beginning and ending of
stroked lines and paths.
|
static class |
Paint.FontMetrics
Class that describes the various metrics for a font at a given text size.
|
static class |
Paint.FontMetricsInt
Convenience method for callers that want to have FontMetrics values as
integers.
|
static class |
Paint.Join
The Join specifies the treatment where lines and curve segments
join on a stroked path.
|
static class |
Paint.Style
The Style specifies if the primitive being drawn is filled, stroked, or
both (in the same color).
|
Modifier and Type | Field and Description |
---|---|
static int |
ANTI_ALIAS_FLAG
Paint flag that enables antialiasing when drawing.
|
static int |
AUTO_HINTING_TEXT_FLAG |
static int |
BIDI_DEFAULT_LTR
Bidi flag to detect paragraph direction via heuristics, defaulting to
LTR.
|
static int |
BIDI_DEFAULT_RTL
Bidi flag to detect paragraph direction via heuristics, defaulting to
RTL.
|
static int |
BIDI_FORCE_LTR
Bidi flag to override direction to all LTR (ignore bidi).
|
static int |
BIDI_FORCE_RTL
Bidi flag to override direction to all RTL (ignore bidi).
|
static int |
BIDI_LTR
Bidi flag to set LTR paragraph direction.
|
static int |
BIDI_RTL
Bidi flag to set RTL paragraph direction.
|
static int |
CURSOR_AFTER
Option for getTextRunCursor to compute the valid cursor after
offset or the limit of the context, whichever is less.
|
static int |
CURSOR_AT
Option for getTextRunCursor to return offset if the cursor at offset
is valid, or -1 if it isn't.
|
static int |
CURSOR_AT_OR_AFTER
Option for getTextRunCursor to compute the valid cursor at or after
the offset or the limit of the context, whichever is less.
|
static int |
CURSOR_AT_OR_BEFORE
Option for getTextRunCursor to compute the valid cursor at or before
offset or the start of the context, whichever is greater.
|
static int |
CURSOR_BEFORE
Option for getTextRunCursor to compute the valid cursor before
offset or the start of the context, whichever is greater.
|
static int |
DEV_KERN_TEXT_FLAG
Legacy Paint flag, no longer used.
|
static int |
DIRECTION_LTR
Flag for getTextRunAdvances indicating left-to-right run direction.
|
static int |
DIRECTION_RTL
Flag for getTextRunAdvances indicating right-to-left run direction.
|
static int |
DITHER_FLAG
Paint flag that enables dithering when blitting.
|
static int |
EMBEDDED_BITMAP_TEXT_FLAG
Paint flag that enables the use of bitmap fonts when drawing text.
|
static int |
FAKE_BOLD_TEXT_FLAG
Paint flag that applies a synthetic bolding effect to drawn text.
|
static int |
FILTER_BITMAP_FLAG
Paint flag that enables bilinear sampling on scaled bitmaps.
|
static int |
HINTING_OFF
Font hinter option that disables font hinting.
|
static int |
HINTING_ON
Font hinter option that enables font hinting.
|
static int |
LCD_RENDER_TEXT_FLAG |
static int |
LINEAR_TEXT_FLAG
Paint flag that enables smooth linear scaling of text.
|
int |
mBidiFlags |
long |
mNativeTypeface |
static int |
STRIKE_THRU_TEXT_FLAG
Paint flag that applies a strike-through decoration to drawn text.
|
static int |
SUBPIXEL_TEXT_FLAG
Paint flag that enables subpixel positioning of text.
|
static int |
UNDERLINE_TEXT_FLAG
Paint flag that applies an underline decoration to drawn text.
|
static int |
VERTICAL_TEXT_FLAG |
Constructor and Description |
---|
Paint()
Create a new paint with default settings.
|
Paint(int flags)
Create a new paint with the specified flags.
|
Paint(Paint paint)
Create a new paint, initialized with the attributes in the specified
paint parameter.
|
Modifier and Type | Method and Description |
---|---|
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(CharSequence text,
int start,
int end,
boolean measureForwards,
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.
|
void |
clearShadowLayer()
Clear the shadow layer.
|
float |
descent()
Return the distance below (positive) the baseline (descent) based on the
current typeface and text size.
|
int |
getAlpha()
Helper to getColor() that just returns the color's alpha value.
|
int |
getBidiFlags()
Return the bidi flags on the paint.
|
int |
getColor()
Return the paint's color.
|
ColorFilter |
getColorFilter()
Get the paint's colorfilter (maybe be null).
|
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.
|
Paint.FontMetrics |
getFontMetrics()
Allocates a new FontMetrics object, and then calls getFontMetrics(fm)
with it, returning the object.
|
float |
getFontMetrics(Paint.FontMetrics metrics)
Return the font's recommended interline spacing, given the Paint's
settings for typeface, textSize, etc.
|
Paint.FontMetricsInt |
getFontMetricsInt() |
int |
getFontMetricsInt(Paint.FontMetricsInt fmi)
Return the font's interline spacing, given the Paint's settings for
typeface, textSize, etc.
|
float |
getFontSpacing()
Return the recommend line spacing based on the current typeface and
text size.
|
int |
getHinting()
Return the paint's hinting mode.
|
int |
getHyphenEdit()
Get the current value of hyphen edit.
|
float |
getLetterSpacing()
Return the paint's letter-spacing for text.
|
MaskFilter |
getMaskFilter()
Get the paint's maskfilter object.
|
long |
getNativeInstance()
Return the pointer to the native object while ensuring that any
mutable objects that are attached to the paint are also up-to-date.
|
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.
|
Rasterizer |
getRasterizer()
Deprecated.
Rasterizer is not supported by either the HW or PDF backends.
|
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) |
Shader |
getShader()
Get the paint's shader object.
|
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(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).
|
void |
getTextBounds(String text,
int start,
int end,
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)
Convenience overload that takes a char array instead of a
String.
|
float |
getTextRunAdvances(CharSequence text,
int start,
int end,
int contextStart,
int contextEnd,
boolean isRtl,
float[] advances,
int advancesIndex)
Convenience overload that takes a CharSequence instead of a
String.
|
float |
getTextRunAdvances(String text,
int start,
int end,
int contextStart,
int contextEnd,
boolean isRtl,
float[] advances,
int advancesIndex)
Returns the total advance width for the characters in the run
between start and end, and if advances is not null, the advance
assigned to each of these characters (java chars).
|
int |
getTextRunCursor(char[] text,
int contextStart,
int contextLength,
int dir,
int offset,
int cursorOpt)
Returns the next cursor position in the run.
|
int |
getTextRunCursor(CharSequence text,
int contextStart,
int contextEnd,
int dir,
int offset,
int cursorOpt)
Returns the next cursor position in the run.
|
int |
getTextRunCursor(String text,
int contextStart,
int contextEnd,
int dir,
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(CharSequence text,
int start,
int end,
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.
|
Typeface |
getTypeface()
Get the paint's typeface object.
|
Xfermode |
getXfermode()
Get the paint's xfermode object.
|
boolean |
hasGlyph(String string)
Determine whether the typeface set on the paint has a glyph supporting the string.
|
boolean |
hasShadowLayer()
Checks if the paint has a shadow layer attached
|
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.
|
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()
Get the elegant metrics flag.
|
boolean |
isFakeBoldText()
Helper for getFlags(), returning true if FAKE_BOLD_TEXT_FLAG bit is set
|
boolean |
isFilterBitmap()
Whether or not the bitmap filter is activated.
|
boolean |
isLinearText()
Helper for getFlags(), returning true if LINEAR_TEXT_FLAG bit is set
|
boolean |
isStrikeThruText()
Helper for getFlags(), returning true if STRIKE_THRU_TEXT_FLAG bit is set
|
boolean |
isSubpixelText()
Helper for getFlags(), returning true if SUBPIXEL_TEXT_FLAG bit is set
|
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)
Return the width of the text.
|
float |
measureText(String text,
int start,
int end)
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 |
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 |
setARGB(int a,
int r,
int g,
int b)
Helper to setColor(), that takes a,r,g,b and constructs the color int
|
void |
setBidiFlags(int flags)
Set the bidi flags on the paint.
|
void |
setColor(int color)
Set the paint's color.
|
ColorFilter |
setColorFilter(ColorFilter filter)
Set or clear the paint's colorfilter, returning the parameter.
|
void |
setCompatibilityScaling(float factor) |
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)
Set the paint's elegant height metrics flag.
|
void |
setFakeBoldText(boolean fakeBoldText)
Helper for setFlags(), setting or clearing the FAKE_BOLD_TEXT_FLAG bit
|
void |
setFilterBitmap(boolean filter)
Helper for setFlags(), setting or clearing the FILTER_BITMAP_FLAG bit.
|
void |
setFlags(int flags)
Set the paint's flags.
|
void |
setFontFeatureSettings(String settings)
Set font feature settings.
|
void |
setHinting(int mode)
Set the paint's hinting mode.
|
void |
setHyphenEdit(int hyphen)
Set a hyphen edit on the paint (causes a hyphen to be added to text when
measured or drawn).
|
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.
|
Rasterizer |
setRasterizer(Rasterizer rasterizer)
Deprecated.
Rasterizer is not supported by either the HW or PDF backends.
|
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 |
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
|
Xfermode |
setXfermode(Xfermode xfermode)
Set or clear the xfermode object.
|
public long mNativeTypeface
public int mBidiFlags
public static final int ANTI_ALIAS_FLAG
Enabling this flag will cause all draw operations that support antialiasing to use it.
Paint(int)
,
setFlags(int)
,
Constant Field Valuespublic static final int FILTER_BITMAP_FLAG
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.
Paint(int)
,
setFlags(int)
,
Constant Field Valuespublic static final int DITHER_FLAG
Enabling this flag applies a dither to any blit operation where the target's colour space is more constrained than the source.
Paint(int)
,
setFlags(int)
,
Constant Field Valuespublic static final int UNDERLINE_TEXT_FLAG
Paint(int)
,
setFlags(int)
,
Constant Field Valuespublic static final int STRIKE_THRU_TEXT_FLAG
Paint(int)
,
setFlags(int)
,
Constant Field Valuespublic static final int FAKE_BOLD_TEXT_FLAG
Enabling this flag will cause text draw operations to apply a
simulated bold effect when drawing a Typeface
that is not
already bold.
Paint(int)
,
setFlags(int)
,
Constant Field Valuespublic static final int LINEAR_TEXT_FLAG
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.
Paint(int)
,
setFlags(int)
,
Constant Field Valuespublic static final int SUBPIXEL_TEXT_FLAG
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.
Paint(int)
,
setFlags(int)
,
Constant Field Valuespublic static final int DEV_KERN_TEXT_FLAG
public static final int LCD_RENDER_TEXT_FLAG
public static final int EMBEDDED_BITMAP_TEXT_FLAG
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.
Paint(int)
,
setFlags(int)
,
Constant Field Valuespublic static final int AUTO_HINTING_TEXT_FLAG
public static final int VERTICAL_TEXT_FLAG
public static final int HINTING_OFF
setHinting(int)
,
Constant Field Valuespublic static final int HINTING_ON
setHinting(int)
,
Constant Field Valuespublic static final int BIDI_LTR
public static final int BIDI_RTL
public static final int BIDI_DEFAULT_LTR
public static final int BIDI_DEFAULT_RTL
public static final int BIDI_FORCE_LTR
public static final int BIDI_FORCE_RTL
public static final int DIRECTION_LTR
public static final int DIRECTION_RTL
public static final int CURSOR_AFTER
public static final int CURSOR_AT_OR_AFTER
public static final int CURSOR_BEFORE
public static final int CURSOR_AT_OR_BEFORE
public static final int CURSOR_AT
public Paint()
public Paint(int flags)
flags
- initial flag bits, as if they were passed via setFlags().public Paint(Paint paint)
paint
- Existing paint used to initialized the attributes of the
new paint.public void reset()
public void set(Paint src)
public void setCompatibilityScaling(float factor)
public long getNativeInstance()
public int getBidiFlags()
public void setBidiFlags(int flags)
public int getFlags()
public void setFlags(int flags)
flags
- The new flag bits for the paintpublic int getHinting()
HINTING_OFF
or HINTING_ON
.public void setHinting(int mode)
HINTING_OFF
or HINTING_ON
.public final boolean isAntiAlias()
public void setAntiAlias(boolean aa)
aa
- true to set the antialias bit in the flags, false to clear itpublic final boolean isDither()
public void setDither(boolean dither)
dither
- true to set the dithering bit in flags, false to clear itpublic final boolean isLinearText()
public void setLinearText(boolean linearText)
linearText
- true to set the linearText bit in the paint's flags,
false to clear it.public final boolean isSubpixelText()
public void setSubpixelText(boolean subpixelText)
subpixelText
- true to set the subpixelText bit in the paint's
flags, false to clear it.public final boolean isUnderlineText()
public void setUnderlineText(boolean underlineText)
underlineText
- true to set the underlineText bit in the paint's
flags, false to clear it.public final boolean isStrikeThruText()
public void setStrikeThruText(boolean strikeThruText)
strikeThruText
- true to set the strikeThruText bit in the paint's
flags, false to clear it.public final boolean isFakeBoldText()
public void setFakeBoldText(boolean fakeBoldText)
fakeBoldText
- true to set the fakeBoldText bit in the paint's
flags, false to clear it.public final boolean isFilterBitmap()
setFilterBitmap()
public void setFilterBitmap(boolean filter)
filter
- true to set the FILTER_BITMAP_FLAG bit in the paint's
flags, false to clear it.public Paint.Style getStyle()
public void setStyle(Paint.Style style)
style
- The new style to set in the paintpublic int getColor()
public void setColor(int color)
color
- The new color (including alpha) to set in the paint.public int getAlpha()
public void setAlpha(int a)
a
- set the alpha component [0..255] of the paint's color.public void setARGB(int a, int r, int g, int b)
a
- The new alpha component (0..255) of the paint's color.r
- The new red component (0..255) of the paint's color.g
- The new green component (0..255) of the paint's color.b
- The new blue component (0..255) of the paint's color.public float getStrokeWidth()
public void setStrokeWidth(float width)
width
- set the paint's stroke width, used whenever the paint's
style is Stroke or StrokeAndFill.public float getStrokeMiter()
public void setStrokeMiter(float miter)
miter
- set the miter limit on the paint, used whenever the paint's
style is Stroke or StrokeAndFill.public Paint.Cap getStrokeCap()
public void setStrokeCap(Paint.Cap cap)
cap
- set the paint's line cap style, used whenever the paint's
style is Stroke or StrokeAndFill.public Paint.Join getStrokeJoin()
public void setStrokeJoin(Paint.Join join)
join
- set the paint's Join, used whenever the paint's style is
Stroke or StrokeAndFill.public boolean getFillPath(Path src, Path dst)
src
- input pathdst
- output path (may be the same as src)public Shader getShader()
public Shader setShader(Shader shader)
shader
- May be null. the new shader to be installed in the paintpublic ColorFilter getColorFilter()
public ColorFilter setColorFilter(ColorFilter filter)
filter
- May be null. The new filter to be installed in the paintpublic Xfermode getXfermode()
public Xfermode setXfermode(Xfermode xfermode)
xfermode
- May be null. The xfermode to be installed in the paintpublic PathEffect getPathEffect()
public PathEffect setPathEffect(PathEffect effect)
effect
- May be null. The patheffect to be installed in the paintpublic MaskFilter getMaskFilter()
public MaskFilter setMaskFilter(MaskFilter maskfilter)
maskfilter
- May be null. The maskfilter to be installed in the
paintpublic Typeface getTypeface()
public Typeface setTypeface(Typeface typeface)
typeface
- May be null. The typeface to be installed in the paint@Deprecated public Rasterizer getRasterizer()
@Deprecated public Rasterizer setRasterizer(Rasterizer rasterizer)
rasterizer
- May be null. The new rasterizer to be installed in
the paint.public void setShadowLayer(float radius, float dx, float dy, int shadowColor)
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.
public void clearShadowLayer()
public boolean hasShadowLayer()
public Paint.Align getTextAlign()
public void setTextAlign(Paint.Align align)
align
- set the paint's Align value for drawing text.public Locale getTextLocale()
getTextLocales()
to get the complete list.public LocaleList getTextLocales()
public void setTextLocale(Locale locale)
setTextLocales(LocaleList)
for how the locale list affects
the way the text is drawn for some languages.locale
- the paint's locale value for drawing text, must not be null.public void setTextLocales(LocaleList locales)
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.locales
- the paint's locale list for drawing text, must not be null or empty.public boolean isElegantTextHeight()
public void setElegantTextHeight(boolean elegant)
elegant
- set the paint's elegant metrics flag for drawing text.public float getTextSize()
public void setTextSize(float textSize)
textSize
- set the paint's text size.public float getTextScaleX()
public void setTextScaleX(float scaleX)
scaleX
- set the paint's scale in X for drawing/measuring text.public float getTextSkewX()
public void setTextSkewX(float skewX)
skewX
- set the paint's skew factor in X for drawing text.public float getLetterSpacing()
public void setLetterSpacing(float letterSpacing)
letterSpacing
- set the paint's letter-spacing for drawing text.public String getFontFeatureSettings()
setFontFeatureSettings(String)
public void setFontFeatureSettings(String settings)
settings
- the font feature settings string to use, may be null.getFontFeatureSettings()
public int getHyphenEdit()
public void setHyphenEdit(int hyphen)
hyphen
- 0 for no edit, 1 for adding a hyphen (other values in future)public float ascent()
public float descent()
public float getFontMetrics(Paint.FontMetrics metrics)
metrics
- If this object is not null, its fields are filled with
the appropriate values given the paint's text attributes.public Paint.FontMetrics getFontMetrics()
public int getFontMetricsInt(Paint.FontMetricsInt fmi)
public Paint.FontMetricsInt getFontMetricsInt()
public float getFontSpacing()
public float measureText(char[] text, int index, int count)
text
- The text to measure. Cannot be null.index
- The index of the first character to start measuringcount
- THe number of characters to measure, beginning with startpublic float measureText(String text, int start, int end)
text
- The text to measure. Cannot be null.start
- The index of the first character to start measuringend
- 1 beyond the index of the last character to measurepublic float measureText(String text)
text
- The text to measure. Cannot be null.public float measureText(CharSequence text, int start, int end)
text
- The text to measurestart
- The index of the first character to start measuringend
- 1 beyond the index of the last character to measurepublic int breakText(char[] text, int index, int count, float maxWidth, float[] measuredWidth)
text
- The text to measure. Cannot be null.index
- The offset into text to begin measuring atcount
- The number of maximum number of entries to measure. If count
is negative, then the characters are measured in reverse order.maxWidth
- The maximum width to accumulate.measuredWidth
- Optional. If not null, returns the actual width
measured.public int breakText(CharSequence text, int start, int end, boolean measureForwards, float maxWidth, float[] measuredWidth)
text
- The text to measure. Cannot be null.start
- The offset into text to begin measuring atend
- The end of the text slice to measure.measureForwards
- If true, measure forwards, starting at start.
Otherwise, measure backwards, starting with end.maxWidth
- The maximum width to accumulate.measuredWidth
- Optional. If not null, returns the actual width
measured.public int breakText(String text, boolean measureForwards, float maxWidth, float[] measuredWidth)
text
- The text to measure. Cannot be null.measureForwards
- If true, measure forwards, starting with the
first character in the string. Otherwise,
measure backwards, starting with the
last character in the string.maxWidth
- The maximum width to accumulate.measuredWidth
- Optional. If not null, returns the actual width
measured.public int getTextWidths(char[] text, int index, int count, float[] widths)
text
- The text to measure. Cannot be null.index
- The index of the first char to to measurecount
- The number of chars starting with index to measurewidths
- array to receive the advance widths of the characters.
Must be at least a large as count.public int getTextWidths(CharSequence text, int start, int end, float[] widths)
text
- The text to measure. Cannot be null.start
- The index of the first char to to measureend
- The end of the text slice to measurewidths
- array to receive the advance widths of the characters.
Must be at least a large as (end - start).public int getTextWidths(String text, int start, int end, float[] widths)
text
- The text to measure. Cannot be null.start
- The index of the first char to to measureend
- The end of the text slice to measurewidths
- array to receive the advance widths of the characters.
Must be at least a large as the text.public int getTextWidths(String text, float[] widths)
text
- The text to measurewidths
- array to receive the advance widths of the characters.
Must be at least a large as the text.public float getTextRunAdvances(char[] chars, int index, int count, int contextIndex, int contextCount, boolean isRtl, float[] advances, int advancesIndex)
public float getTextRunAdvances(CharSequence text, int start, int end, int contextStart, int contextEnd, boolean isRtl, float[] advances, int advancesIndex)
public float getTextRunAdvances(String text, int start, int end, int contextStart, int contextEnd, boolean isRtl, float[] advances, int advancesIndex)
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.
text
- the text to measure. Cannot be null.start
- the index of the first character to measureend
- the index past the last character to measurecontextStart
- the index of the first character to use for shaping context,
must be <= startcontextEnd
- the index past the last character to use for shaping context,
must be >= endisRtl
- whether the run is in RTL directionadvances
- array to receive the advances, must have room for all advances,
can be null if only total advance is neededadvancesIndex
- the position in advances at which to put the
advance corresponding to the character at startpublic int getTextRunCursor(char[] text, int contextStart, int contextLength, int dir, int offset, int cursorOpt)
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.
text
- the textcontextStart
- the start of the contextcontextLength
- the length of the contextdir
- either DIRECTION_RTL
or DIRECTION_LTR
offset
- the cursor position to move fromcursorOpt
- how to move the cursor, one of CURSOR_AFTER
,
CURSOR_AT_OR_AFTER
, CURSOR_BEFORE
,
CURSOR_AT_OR_BEFORE
, or CURSOR_AT
public int getTextRunCursor(CharSequence text, int contextStart, int contextEnd, int dir, int offset, int cursorOpt)
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.
text
- the textcontextStart
- the start of the contextcontextEnd
- the end of the contextdir
- either DIRECTION_RTL
or DIRECTION_LTR
offset
- the cursor position to move fromcursorOpt
- how to move the cursor, one of CURSOR_AFTER
,
CURSOR_AT_OR_AFTER
, CURSOR_BEFORE
,
CURSOR_AT_OR_BEFORE
, or CURSOR_AT
public int getTextRunCursor(String text, int contextStart, int contextEnd, int dir, int offset, int cursorOpt)
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.
text
- the textcontextStart
- the start of the contextcontextEnd
- the end of the contextdir
- either DIRECTION_RTL
or DIRECTION_LTR
offset
- the cursor position to move fromcursorOpt
- how to move the cursor, one of CURSOR_AFTER
,
CURSOR_AT_OR_AFTER
, CURSOR_BEFORE
,
CURSOR_AT_OR_BEFORE
, or CURSOR_AT
public void getTextPath(char[] text, int index, int count, float x, float y, Path path)
text
- The text to retrieve the path fromindex
- The index of the first character in textcount
- The number of characterss starting with indexx
- The x coordinate of the text's originy
- The y coordinate of the text's originpath
- The path to receive the data describing the text. Must
be allocated by the caller.public void getTextPath(String text, int start, int end, float x, float y, Path path)
text
- The text to retrieve the path fromstart
- The first character in the textend
- 1 past the last charcter in the textx
- The x coordinate of the text's originy
- The y coordinate of the text's originpath
- The path to receive the data describing the text. Must
be allocated by the caller.public void getTextBounds(String text, int start, int end, Rect bounds)
text
- String to measure and return its boundsstart
- Index of the first char in the string to measureend
- 1 past the last char in the string measurebounds
- Returns the unioned bounds of all the text. Must be
allocated by the caller.public void getTextBounds(char[] text, int index, int count, Rect bounds)
text
- Array of chars to measure and return their unioned boundsindex
- Index of the first char in the array to measurecount
- The number of chars, beginning at index, to measurebounds
- Returns the unioned bounds of all the text. Must be
allocated by the caller.public boolean hasGlyph(String string)
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.
string
- the string to test whether there is glyph supportpublic float getRunAdvance(char[] text, int start, int end, int contextStart, int contextEnd, boolean isRtl, int offset)
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(char[], int, int, int, int, boolean, float)
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.
text
- the text to measure. Cannot be null.start
- the index of the start of the range to measureend
- the index + 1 of the end of the range to measurecontextStart
- the index of the start of the shaping contextcontextEnd
- the index + 1 of the end of the shaping contextisRtl
- whether the run is in RTL directionoffset
- index of caret positionpublic float getRunAdvance(CharSequence text, int start, int end, int contextStart, int contextEnd, boolean isRtl, int offset)
text
- the text to measure. Cannot be null.start
- the index of the start of the range to measureend
- the index + 1 of the end of the range to measurecontextStart
- the index of the start of the shaping contextcontextEnd
- the index + 1 of the end of the shaping contextisRtl
- whether the run is in RTL directionoffset
- index of caret positiongetRunAdvance(char[], int, int, int, int, boolean, int)
public int getOffsetForAdvance(char[] text, int start, int end, int contextStart, int contextEnd, boolean isRtl, float advance)
The returned value is generally the value of offset
for which
getRunAdvance(char[], int, int, int, int, boolean, int)
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.
text
- the text to measure. Cannot be null.start
- the index of the start of the range to measureend
- the index + 1 of the end of the range to measurecontextStart
- the index of the start of the shaping contextcontextEnd
- the index + 1 of the end of the range to measureisRtl
- whether the run is in RTL directionadvance
- width relative to start of runpublic int getOffsetForAdvance(CharSequence text, int start, int end, int contextStart, int contextEnd, boolean isRtl, float advance)
text
- the text to measure. Cannot be null.start
- the index of the start of the range to measureend
- the index + 1 of the end of the range to measurecontextStart
- the index of the start of the shaping contextcontextEnd
- the index + 1 of the end of the range to measureisRtl
- whether the run is in RTL directionadvance
- width relative to start of rungetOffsetForAdvance(char[], int, int, int, int, boolean, float)