| 限定符和类型 | 类 | 说明 |
|---|---|---|
static class |
Paint.FontMetrics |
Describes fonts of the same size in multiple metrics.
|
static class |
Paint.Join |
Enumerates line join styles of a paint.
|
static class |
Paint.MaskType |
Indicates the required shape for a mask.
|
static class |
Paint.ShaderType |
Indicates the shader type, which specifies how the colors in the paint are shaded.
|
static class |
Paint.StrokeCap |
Indicates the paint stroke cap, which specifies the shape of each drawing point of a paint stroke.
|
static class |
Paint.Style |
Indicates the paint style type.
|
| 限定符和类型 | 字段 | 说明 |
|---|---|---|
int |
baselineOffset |
Base line offset attributes of a Paint.
|
Color |
color |
Indicates the
Color attribute of the current Paint object. |
float[] |
dashPathEffectIntervals |
Indicates the
dashPathEffectIntervals attribute of this Paint. |
Color[] |
gradientShaderColor |
Indicates the gradient shader colors to be used by
Canvas#drawPolylineShadow. |
| 构造器 | 说明 |
|---|---|
Paint() |
Default constructor used to create a
Paint instance. |
Paint(Paint paint) |
A constructor used to create a
Paint instance by using an existing one. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
void |
addTextToPath(String text,
float xCoor,
float yCoor,
Path path) |
Adds a text to
Path. |
float |
ascent() |
Obtains the furthest distance of this text string above the baseline.
|
void |
clearBlurDrawLooper() |
Clears the shadow attributes of this
Paint. |
float |
descent() |
Obtains the furthest distance of this text string below the baseline.
|
int |
getAdvanceWidths(String text,
float[] widths) |
Obtains the text width in advance.
|
float |
getAlpha() |
Obtains the alpha value.
|
float |
getAngle() |
Obtains the stroke miter value of the
Paint object. |
BlendMode |
getBlendMode() |
Obtains the blend mode of this
Paint. |
Color |
getColor() |
Obtains the
Color attribute of a Paint object. |
ColorFilter |
getColorFilter() |
Obtains the color filter of this
Paint. |
ColorMatrix |
getColorMatrix() |
Obtains the color matrix of a
Paint object. |
float |
getCornerPathEffectRadius() |
Obtains the corner radius of this
CornerPathEffect. |
int |
getDashIntervalCount() |
Obtains the length of the
Paint#dashPathEffectIntervals value array of this Paint. |
float[] |
getDashPathEffectIntervals() |
Obtains the
Paint#dashPathEffectIntervals value array of this Paint. |
float |
getDashPathEffectPhase() |
Obtains the offset between each value pair in the
Paint#dashPathEffectIntervals value array of
this Paint. |
int |
getDisplayNumber(String text,
boolean isMeasuredForwards,
float maxWidth,
float[] measuredWidth) |
Calculates the number of characters that can be displayed within the specified width.
|
boolean |
getDither() |
Obtains the
Dither attribute of a Paint. |
boolean |
getFillPath(Path src,
Path dst) |
Obtains the actual contour of the source path and saves the obtained path to
dst. |
boolean |
getFilterBitmap() |
Obtains the
FilterBitmap attribute of a Paint. |
Font |
getFont() |
Obtains the text font.
|
String |
getFontFeatures() |
Obtains the font features.
|
Paint.FontMetrics |
getFontMetrics() |
Obtains the recommended line spacing for the font of a
Paint with attributes
such as font and textSize specified. |
Color[] |
getGradientShaderColor() |
Obtains the gradient shader colors to be used by
Canvas#drawPolylineShadow. |
float |
getLineHeightCoefficient() |
Obtains the line height coefficient of text.
|
float |
getLineHeightOffset() |
Obtains the line height's offset between lines in text.
|
LocaleProfile |
getLocales() |
Obtains the text locale profile.
|
MaskFilter |
getMaskFilter() |
Obtains the mask filter of this
Paint. |
int |
getMaxLines() |
Obtains the maximum number of lines that can be displayed.
|
PathEffect |
getPathEffect() |
Obtains the path effect of this
Paint. |
Point |
getPosition() |
已过时。
This change is effective since API version 8.
This method is deprecated together with
Paint#setPosition.
You need to manually record the position set by Canvas#drawText. |
Locale |
getPrimaryLocale() |
Obtains the primary locale.
|
float |
getRecommendedLineSpacing() |
Obtains the recommended line spacing.
|
Shader |
getShader() |
Obtains the shader attributes of a paint.
|
Paint.StrokeCap |
getStrokeCap() |
Obtains the stroke cap of this
Paint. |
Paint.Join |
getStrokeJoin() |
Obtains the stroke join of this
Paint. |
float |
getStrokeWidth() |
Obtains the stroke width of a
Paint object. |
Paint.Style |
getStyle() |
Obtains the style of a
Paint object, which can be Style#FILL_STYLE,
Style#STROKE_STYLE, or Style#FILLANDSTROKE_STYLE. |
int |
getTextAlign() |
Obtains the text alignment mode.
|
Rect |
getTextBounds(String text) |
Obtains the minimum rectangular bounds of the specified text.
|
int |
getTextSize() |
Obtains the font size of text.
|
void |
horizontalTilt(float tiltH) |
Sets the horizontal tilt factor for this text.
|
void |
horizontalZoom(float zoomH) |
Sets the horizontal zoom factor for this text.
|
boolean |
isAntiAlias() |
Checks if anti-aliasing is enabled for a
Paint object. |
boolean |
isFakeBoldText() |
Checks whether the
FakeBoldText attribute is set for this Paint. |
boolean |
isMultipleLine() |
Obtains whether text is displayed in multiple lines.
|
boolean |
isUnderLined() |
Checks whether the font in this
Paint is underlined. |
float |
measureText(String text) |
Obtains the width of text.
|
void |
reset() |
Resets all attributes for this
Paint. |
void |
set(Paint paint) |
Copies the attributes of a paint to this
Paint. |
void |
setAlpha(float alpha) |
Sets an alpha value.
|
void |
setAntiAlias(boolean flag) |
Sets the anti-aliasing for a
Paint object. |
BlendMode |
setBlendMode(BlendMode mode) |
Sets the blend mode for this
Paint. |
void |
setBlurDrawLooper(BlurDrawLooper looper) |
Sets shadow attributes for a
Paint. |
void |
setColor(Color newColor) |
Sets the color attribute of the
Paint object. |
void |
setColorFilter(ColorFilter colorFilter) |
Sets the color filter for this
Paint. |
void |
setColorMatrix(ColorMatrix matrix) |
Sets color matrix attributes for a
Paint object. |
void |
setCornerPathEffectRadius(float cornerRadius) |
Sets the corner radius for the
CornerPathEffect. |
void |
setDashPathEffectIntervals(float[] intervals) |
Sets the
Paint#dashPathEffectIntervals value array for a Paint. |
void |
setDashPathEffectPhase(float phase) |
Sets the offset for dash path effect intervals of a
Paint. |
void |
setDither(boolean dither) |
Sets the
Dither attribute for a Paint. |
void |
setFakeBoldText(boolean flag) |
Sets the
FakeBoldText attribute for a Paint. |
void |
setFilterBitmap(boolean filter) |
Sets the
FilterBitmap attribute for a Paint. |
void |
setFont(Font font) |
Sets text font.
|
void |
setFontFeatures(String fontFeatures) |
Sets the font features.
|
void |
setGradientShaderColor(Color[] newGradientShaderColor) |
Sets the gradient shader colors to be used by
Canvas#drawPolylineShadow. |
void |
setLetterSpacing(float spacing) |
Sets the letter spacing for this
Paint. |
void |
setLocales(LocaleProfile locales) |
Set the text locale profile.
|
void |
setMaskFilter(MaskFilter maskFilter) |
Sets the mask filter for this
Paint. |
void |
setMaxLines(int maxLines) |
Sets the maximum number of lines that can be displayed.
|
void |
setMultipleLine(boolean multiple) |
Sets whether text is displayed in multiple lines.
|
void |
setPathEffect(PathEffect pathEffect) |
Sets the path effect for a
Paint. |
void |
setPosition(Point point) |
已过时。
This change is effective since API version 8.
The position set by this method will be overwritten by that set by
Canvas#drawText.
Therefore, this API is deprecated. Use Canvas#drawText instead. |
void |
setPrimaryLocale(Locale locale) |
Sets the primary locale.
|
void |
setShader(Shader newShader,
Paint.ShaderType type) |
|
void |
setStrikeThrough(boolean isStrikeThrough) |
Sets whether to add a strikethrough for this text.
|
void |
setStrokeCap(Paint.StrokeCap cap) |
Sets the stroke cap for a
Paint. |
void |
setStrokeJoin(Paint.Join join) |
Sets the stroke join for this
Paint. |
void |
setStrokeMiter(float miter) |
Sets the stroke miter for this
Paint. |
void |
setStrokeWidth(float width) |
Sets the stroke width for a
Paint object. |
void |
setStyle(Paint.Style style) |
Sets the style attribute of a
Paint object. |
void |
setSubpixelAntiAlias(boolean isSubpixel) |
Sets whether to enable sub-pixel anti-aliasing for improving text legibility on an LCD screen.
|
void |
setTextAlign(int align) |
Sets the text alignment mode.
|
void |
setTextSize(int textSize) |
Sets the font size of text.
|
void |
setUnderLine(boolean isUnderLine) |
Sets whether to add an underline for this text.
|
public int baselineOffset
public float[] dashPathEffectIntervals
dashPathEffectIntervals attribute of this Paint.
Values in dashPathEffectIntervals are in pairs: The even and odd indices of these values specify
the number of pixels to draw and the number of blank pixels respectively.
public Color[] gradientShaderColor
Canvas#drawPolylineShadow.
The length is 2.public Paint()
Paint instance.public Paint(Paint paint)
Paint instance by using an existing one.paint - Indicates the existing paint.public void set(Paint paint)
Paint.paint - Indicates the paint whose attributes will be copied to the current paint.public void setStyle(Paint.Style style)
Paint object.style - Indicates the style that is set, which can be Style#FILL_STYLE, Style#STROKE_STYLE,
or Style#FILLANDSTROKE_STYLE.public Paint.Style getStyle()
Paint object, which can be Style#FILL_STYLE,
Style#STROKE_STYLE, or Style#FILLANDSTROKE_STYLE.Paint object.public void setDither(boolean dither)
Dither attribute for a Paint.dither - Indicates whether the Dither attribute is specified for the Paint.
true indicates specified; false indicates not specified.public boolean getDither()
Dither attribute of a Paint.Dither attribute of the Paint.public void setFilterBitmap(boolean filter)
FilterBitmap attribute for a Paint.
The FilterBitmap attribute is used to filter image bitmaps during transformation.
filter - Indicates whether to filter image bitmaps during transformation.
true indicates that the image bitmaps are filtered when being transformed;
false indicates that the image bitmaps are not filtered when being transformed.public boolean getFilterBitmap()
FilterBitmap attribute of a Paint.FilterBitmap attribute of the Paint.public void setStrokeCap(Paint.StrokeCap cap)
Paint.
The stroke cap represents the shape of each drawing point of a paint stroke, which is usually seen
at the start and end points of an open drawing path. The value can be StrokeCap#BUTT_CAP,
StrokeCap#ROUND_CAP, or StrokeCap#SQUARE_CAP.
cap - Indicates the stroke cap of the paint.public Paint.StrokeCap getStrokeCap()
Paint.Paint.public void setStrokeWidth(float width)
Paint object.
This method sets the stroke width of a Paint object when the style of the Paint
object is set to Style#STROKE_STYLE or Style#FILLANDSTROKE_STYLE.
width - Indicates the stroke width.public float getStrokeWidth()
Paint object.Paint object.public float getAngle()
Paint object.Paint object.public void setColor(Color newColor)
Paint object.
The new color is stored in Color.
newColor - Indicates the new color.public Color getColor()
Color attribute of a Paint object.Color attribute of the Paint object.public void setGradientShaderColor(Color[] newGradientShaderColor)
Canvas#drawPolylineShadow.
This method can be used to set two gradient shader colors,
which will only be used by Canvas#drawPolylineShadow.
If you want to implement the shader effect in other draw calls,
use setShader(ohos.agp.render.Shader,ohos.agp.render.Paint.ShaderType) to set the shader and set the required gradient shader color in Shader.
newGradientShaderColor - Indicates the gradient shader colors to set. The length is 2.public Color[] getGradientShaderColor()
Canvas#drawPolylineShadow.public void setDashPathEffectIntervals(float[] intervals)
Paint#dashPathEffectIntervals value array for a Paint.
Values saved in Paint#dashPathEffectIntervals members are in pairs: The even and odd indices of
these values specify the number of pixels to draw and the number of blank pixels, respectively.
intervals - Indicates the dashPathEffectIntervals value array to set.public float[] getDashPathEffectIntervals()
Paint#dashPathEffectIntervals value array of this Paint.Paint#dashPathEffectIntervals value array of the Paint.public int getDashIntervalCount()
Paint#dashPathEffectIntervals value array of this Paint.Paint#dashPathEffectIntervals value array of the Paint.public void setDashPathEffectPhase(float phase)
Paint.
After setting the Paint#dashPathEffectIntervals value array, you can use this method to set the offset
between each value pair in the array.
phase - Indicates the offset between each value pair in the Paint#dashPathEffectIntervals
value array.public float getDashPathEffectPhase()
Paint#dashPathEffectIntervals value array of
this Paint.Paint#dashPathEffectIntervals value array.public void setAntiAlias(boolean flag)
Paint object.
true indicates the anti-aliasing is enabled; false indicates anti-aliasing is disabled.
flag - Indicates the anti-aliasing state of the Paint object.public final boolean isAntiAlias()
Paint object.true if anti-aliasing is enabled; returns false otherwise.public void setFakeBoldText(boolean flag)
FakeBoldText attribute for a Paint.
FakeBoldText is used for faking the bold font.
flag - Specifies whether FakeBoldText is set to fake the bold font.
The value true indicates that the bold font will be faked, and false indicates that the bold
font will not be faked.public final boolean isFakeBoldText()
FakeBoldText attribute is set for this Paint.true if the FakeBoldText attribute is set; returns false otherwise.public Paint.FontMetrics getFontMetrics()
Paint with attributes
such as font and textSize specified.public void setAlpha(float alpha)
The alpha value ranges from 0.0f to 1.0f. The value 0.0f indicates completely transparent;
the value 1.0f indicates completely opaque.
alpha - Indicates the alpha value, which is a float value.public float getAlpha()
The alpha value ranges from 0.0f to 1.0f. The value 0.0f indicates completely transparent;
the value 1.0f indicates completely opaque.
public void setColorMatrix(ColorMatrix matrix)
Paint object.
The color and alpha of a Paint object can be changed by a color matrix.
matrix - Indicates the color matrix used as a filter.public ColorMatrix getColorMatrix()
Paint object.Paint object.public Rect getTextBounds(String text)
text - Indicates the specified text.public void setFont(Font font)
font - Indicates the text font to set.public Font getFont()
setFont(Font)public void setTextAlign(int align)
This method only supports text alignment in the horizontal direction.
align - Indicates the text alignment mode to set. The value can be LEFT, RIGHT,
or CENTER.TextAlignmentpublic int getTextAlign()
setTextAlign(int)public void setTextSize(int textSize)
textSize - Indicates the font size of text, which is an integer greater than 0.public int getTextSize()
public void setMaxLines(int maxLines)
maxLines - Indicates the maximum number of lines.public int getMaxLines()
public void setMultipleLine(boolean multiple)
By default, text is displayed in multiple lines.
multiple - Indicates the display of text. true indicates text is displayed in multiple lines;
false indicates text is displayed in a single line.public boolean isMultipleLine()
true if text is displayed in multiple lines; returns false otherwise.public float getLineHeightCoefficient()
LineHeight = LineHeightCoefficient * fontSize + LineHeightOffset.
public float getLineHeightOffset()
@Deprecated public void setPosition(Point point)
Canvas#drawText.
Therefore, this API is deprecated. Use Canvas#drawText instead.point - Indicates the starting position of the text to draw.@Deprecated public Point getPosition()
Paint#setPosition.
You need to manually record the position set by Canvas#drawText.public void setCornerPathEffectRadius(float cornerRadius)
CornerPathEffect.cornerRadius - Indicates the corner radius of the CornerPathEffect.public float getCornerPathEffectRadius()
CornerPathEffect.CornerPathEffect.public void setShader(Shader newShader, Paint.ShaderType type)
Shader and ShaderType for this Paint.
When drawing an object, the Paint obtains shading colors from the Shader.
If newShader is null, the shader is cleared from the paint.
newShader - Indicates the shader to set for the paint.type - Indicates the type of the new shader.public Shader getShader()
public float measureText(String text)
before use this method, use setTextSize(int)
text - Indicates the text to measure by the paint.public BlendMode setBlendMode(BlendMode mode)
Paint.mode - Indicates the blend mode to set, as enumerated in BlendMode.true if the setting is successful; returns false otherwise.public BlendMode getBlendMode()
Paint.public void setStrokeJoin(Paint.Join join)
Paint.join - Indicates the stroke join to set, as enumerated in Join.public Paint.Join getStrokeJoin()
Paint.public void setBlurDrawLooper(BlurDrawLooper looper)
Paint.looper - Indicates the shadow attributes to set. For details, see BlurDrawLooper.public void clearBlurDrawLooper()
Paint.public void setPathEffect(PathEffect pathEffect)
Paint.pathEffect - Indicates the path effect to set. For details, see PathEffect.public PathEffect getPathEffect()
Paint.public int getDisplayNumber(String text, boolean isMeasuredForwards, float maxWidth, float[] measuredWidth)
The text will be truncated if its width exceeds maxWidth. This method is usually used for text
typesetting.
text - Indicates the text to measure.isMeasuredForwards - Specifies how the text measurement should start. true indicates the measurement
starts from left to right, and false indicates the opposite case.maxWidth - Indicates the specified maximum width.measuredWidth - Indicates the width of each character displayed within the specified width.public int getAdvanceWidths(String text, float[] widths)
The text width can be used for text typesetting.
text - Indicates the text to measure.widths - Indicates the width of each character.public float ascent()
public float descent()
public void horizontalZoom(float zoomH)
The default value of zoomH is 1. If the value is greater than 1, the text is stretched
horizontally. Otherwise, the image is compressed horizontally.
zoomH - Indicates the horizontal zoom factor.public void horizontalTilt(float tiltH)
The parameter tiltH is not limited to a specific range. The default value is 0. A positive
value indicates that the text is tilted to the left, and a negative value indicates that the text is tilted to
the right.
tiltH - Indicates the horizontal tilt factor.public void setStrikeThrough(boolean isStrikeThrough)
isStrikeThrough - Specifies whether to add a strikethrough for this text. true indicates that a
strikethrough is added, and false (default value) indicates the opposite case.public void setUnderLine(boolean isUnderLine)
isUnderLine - Specifies whether to add an underline for this text. true indicates that an underline
is added, and false (default value) indicates the opposite case.public void setSubpixelAntiAlias(boolean isSubpixel)
isSubpixel - Specifies whether to enable sub-pixel anti-aliasing. true indicates that sub-pixel
anti-aliasing is enabled, and false indicates the opposite case.public void addTextToPath(String text, float xCoor, float yCoor, Path path)
Path.text - Indicates the text to add.xCoor - Indicates the x-coordinate of the text to add.yCoor - Indicates the y-coordinate of the text to add.path - Indicates the path for the text. After the text is added, it can be drawn along the path by calling
Canvas#drawPath.public void setStrokeMiter(float miter)
Paint.miter - Indicates the stroke miter to set.public void setMaskFilter(MaskFilter maskFilter)
Paint.maskFilter - Indicates the mask filter to set, as defined in MaskFilter.public MaskFilter getMaskFilter()
Paint.public void setColorFilter(ColorFilter colorFilter)
Paint.colorFilter - Indicates the color filter to set, as defined in ColorFilter.public ColorFilter getColorFilter()
Paint.public boolean getFillPath(Path src, Path dst)
dst.
The drawing effect of the destination path after it is filled with the default paint should be the same as that of the source path.
src - Indicates the source path.dst - Indicates the destination path.true if the operation is successful; returns false otherwise.public float getRecommendedLineSpacing()
public void setLetterSpacing(float spacing)
Paint.spacing - Indicates the letter spacing to set, in pixels.public final boolean isUnderLined()
Paint is underlined.true if the font is underlined; returns false otherwise.public void reset()
Paint.public void setFontFeatures(String fontFeatures)
fontFeatures - Indicates the font feature.public String getFontFeatures()
public void setLocales(LocaleProfile locales)
locales - Indicates the locale profile to set.public LocaleProfile getLocales()
public void setPrimaryLocale(Locale locale)
locale - Indicates the primary locale to set.public Locale getPrimaryLocale()