SkPaint Reference


Paint controls options applied when drawing and measuring. Paint collects all options outside of the Canvas_Clip and Canvas_Matrix.

Various options apply to text, strokes and fills, and images.

Some options may not be implemented on all platforms; in these cases, setting the option has no effect. Some options are conveniences that duplicate Canvas functionality; for instance, text size is identical to matrix scale.

Paint options are rarely exclusive; each option modifies a stage of the drawing pipeline and multiple pipeline stages may be affected by a single Paint.

Paint collects effects and filters that describe single-pass and multiple-pass algorithms that alter the drawing geometry, color, and transparency. For instance, Paint does not directly implement dashing or blur, but contains the objects that do so.

The objects contained by Paint are opaque, and cannot be edited outside of the Paint to affect it. The implementation is free to defer computations associated with the Paint, or ignore them altogether. For instance, some GPU implementations draw all Path geometries with Anti_Aliasing, regardless of how SkPaint::kAntiAlias_Flag is set in Paint.

Paint describes a single color, a single font, a single image quality, and so on. Multiple colors are drawn either by using multiple paints or with objects like Shader attached to Paint.


Constructs Paint with default values.

attributedefault value
Anti_Aliasfalse
Blend_ModeSkBlendMode::kSrcOver
ColorSK_ColorBLACK
Color_Alpha255
Color_Filternullptr
Ditherfalse
Draw_Loopernullptr
Filter_QualitykNone_SkFilterQuality
Font_Force_Hintingfalse
Font_Embedded_Bitmapsfalse
Font_Emboldenfalse
Font_HintingSkFontHinting::kNormal
Font_Hinting_Spacingfalse
Font_Anti_Aliasfalse
Font_Linearfalse
Font_Scale_X1
Font_Size12
Font_Skew_X0
Font_Subpixelfalse
Image_Filternullptr
Miter_Limit4
Mask_Filternullptr
Path_Effectnullptr
Shadernullptr
StylekFill_Style
Text_EncodingkUTF8_SkTextEncoding
Typefacenullptr
Stroke_CapkButt_Cap
Stroke_JoinkMiter_Join
Stroke_Width0

The flags, text size, hinting, and miter limit may be overridden at compile time by defining paint default values. The overrides may be included in “SkUserConfig.h” or predefined by the build system.

Return Value

default initialized Paint

Example


Makes a shallow copy of SkPaint. SkTypeface, SkPathEffect, SkShader, SkMaskFilter, SkColorFilter, SkDrawLooper, and SkImageFilter are shared between the original paint and the copy. Objects containing SkRefCnt increment their references by one.

The referenced objects SkPathEffect, SkShader, SkMaskFilter, SkColorFilter, SkDrawLooper, and SkImageFilter cannot be modified after they are created. This prevents objects with SkRefCnt from being modified once SkPaint refers to them.

Parameters

Return Value

shallow copy of paint

Example

Example Output

SK_ColorRED == paint1.getColor()
SK_ColorBLUE == paint2.getColor()


Implements a move constructor to avoid increasing the reference counts of objects referenced by the paint.

After the call, paint is undefined, and can be safely destructed.

Parameters

Return Value

content of paint

Example

Example Output

path effect unique: true


Sets all SkPaint contents to their initial values. This is equivalent to replacing SkPaint with the result of SkPaint().

Example

Example Output

paint1 == paint2


Decreases SkPaint SkRefCnt of owned objects: SkTypeface, SkPathEffect, SkShader, SkMaskFilter, SkColorFilter, SkDrawLooper, and SkImageFilter. If the objects containing SkRefCnt go to zero, they are deleted.


Makes a shallow copy of SkPaint. SkTypeface, SkPathEffect, SkShader, SkMaskFilter, SkColorFilter, SkDrawLooper, and SkImageFilter are shared between the original paint and the copy. Objects containing SkRefCnt in the prior destination are decreased by one, and the referenced objects are deleted if the resulting count is zero. Objects containing SkRefCnt in the parameter paint are increased by one. paint is unmodified.

Parameters

Return Value

content of paint

Example

Example Output

SK_ColorRED == paint1.getColor()
SK_ColorRED == paint2.getColor()


Moves the paint to avoid increasing the reference counts of objects referenced by the paint parameter. Objects containing SkRefCnt in the prior destination are decreased by one; those objects are deleted if the resulting count is zero.

After the call, paint is undefined, and can be safely destructed.

Parameters

Return Value

content of paint

Example

Example Output

SK_ColorRED == paint2.getColor()


Compares a and b, and returns true if a and b are equivalent. May return false if SkTypeface, SkPathEffect, SkShader, SkMaskFilter, SkColorFilter, SkDrawLooper, or SkImageFilter have identical contents but different pointers.

Parameters

Return Value

true if SkPaint pair are equivalent

Example

Example Output

paint1 == paint2
paint1 != paint2

See Also

operator!=(const SkPaint& a, const SkPaint& b)


Compares a and b, and returns true if a and b are not equivalent. May return true if SkTypeface, SkPathEffect, SkShader, SkMaskFilter, SkColorFilter, SkDrawLooper, or SkImageFilter have identical contents but different pointers.

Parameters

Return Value

true if SkPaint pair are not equivalent

Example

Example Output

paint1 == paint2
paint1 == paint2

See Also

operator==(const SkPaint& a, const SkPaint& b)


Returns a hash generated from SkPaint values and pointers. Identical hashes guarantee that the paints are equivalent, but differing hashes do not guarantee that the paints have differing contents.

If operator==(const SkPaint& a, const SkPaint& b) returns true for two paints, their hashes are also equal.

The hash returned is platform and implementation specific.

Return Value

a shallow hash

Example

Example Output

paint1 == paint2
paint1.getHash() == paint2.getHash()


Sets level of glyph outline adjustment. Does not check for valid values of hintingLevel.

Parameters

SkFontHinting::kNormal, SkFontHinting::kFull

Example

Example Output

paint1 == paint2


Returns level of glyph outline adjustment.

Return Value

one of: SkFontHinting::kNone, SkFontHinting::kSlight, SkFontHinting::kNormal,

SkFontHinting::kFull

Example

Example Output

SkFontHinting::kNormal == paint.getHinting()


The bit values stored in Flags. The default value for Flags, normally zero, can be changed at compile time with a custom definition of SkPaintDefaults_Flags. All flags can be read and written explicitly; Flags allows manipulating multiple settings at once.

Constants


Returns paint settings described by SkPaint::Flags. Each setting uses one bit, and can be tested with SkPaint::Flags members.

Return Value

zero, one, or more bits described by SkPaint::Flags

Example

Example Output

(SkPaint::kAntiAlias_Flag & paint.getFlags()) != 0


Replaces SkPaint::Flags with flags, the union of the SkPaint::Flags members. All SkPaint::Flags members may be cleared, or one or more may be set.

Parameters

Example

Example Output

paint.isAntiAlias()
paint.isDither()


Anti_Alias drawing approximates partial pixel coverage with transparency. If kAntiAlias_Flag is clear, pixel centers contained by the shape edge are drawn opaque. If kAntiAlias_Flag is set, pixels are drawn with Color_Alpha equal to their coverage.

The rule for Aliased pixels is inconsistent across platforms. A shape edge passing through the pixel center may, but is not required to, draw the pixel.

Raster_Engine draws Aliased pixels whose centers are on or to the right of the start of an active Path edge, and whose center is to the left of the end of the active Path edge.

A platform may only support Anti_Aliased drawing. Some GPU-backed platforms use Supersampling to Anti_Alias all drawing, and have no mechanism to selectively Alias.

The amount of coverage computed for Anti_Aliased pixels also varies across platforms.

Anti_Alias is disabled by default. Anti_Alias can be enabled by default by setting SkPaintDefaults_Flags to kAntiAlias_Flag at compile time.

Example


Returns true if pixels on the active edges of SkPath may be drawn with partial transparency.

Equivalent to getFlags() masked with kAntiAlias_Flag.

Return Value

kAntiAlias_Flag state

Example

Example Output

paint.isAntiAlias() == !!(paint.getFlags() & SkPaint::kAntiAlias_Flag)
paint.isAntiAlias() == !!(paint.getFlags() & SkPaint::kAntiAlias_Flag)


Requests, but does not require, that edge pixels draw opaque or with partial transparency.

Sets kAntiAlias_Flag if aa is true. Clears kAntiAlias_Flag if aa is false.

Parameters

Example

Example Output

paint1 == paint2


Dither increases fidelity by adjusting the color of adjacent pixels. This can help to smooth color transitions and reducing banding in gradients. Dithering lessens visible banding from kRGB_565_SkColorType and kRGBA_8888_SkColorType gradients, and improves rendering into a kRGB_565_SkColorType Surface.

Dithering is always enabled for linear gradients drawing into kRGB_565_SkColorType Surface and kRGBA_8888_SkColorType Surface. Dither cannot be enabled for kAlpha_8_SkColorType Surface and kRGBA_F16_SkColorType Surface.

Dither is disabled by default. Dither can be enabled by default by setting SkPaintDefaults_Flags to kDither_Flag at compile time.

Some platform implementations may ignore dithering. Set SK_IGNORE_GPU_DITHERto ignore Dither on GPU_Surface.

Example

Example

See Also

Gradient kRGB_565_SkColorType


Returns true if color error may be distributed to smooth color transition.

Equivalent to getFlags() masked with kDither_Flag.

Return Value

kDither_Flag state

Example

Example Output

paint.isDither() == !!(paint.getFlags() & SkPaint::kDither_Flag)
paint.isDither() == !!(paint.getFlags() & SkPaint::kDither_Flag)


Requests, but does not require, to distribute color error.

Sets kDither_Flag if dither is true. Clears kDither_Flag if dither is false.

Parameters

Example

Example Output

paint1 == paint2

See Also

kRGB_565_SkColorType


Font_Anti_Alias and Font_Subpixel increase the precision of glyph position.

When set, Flags kLCDRenderText_Flag takes advantage of the organization of RGB stripes that create a color, and relies on the small size of the stripe and visual perception to make the color fringing imperceptible. Font_Anti_Alias can be enabled on devices that orient stripes horizontally or vertically, and that order the color components as RGB or BGR.

Flags kSubpixelText_Flag uses the pixel transparency to represent a fractional offset. As the opaqueness of the color increases, the edge of the glyph appears to move towards the outside of the pixel.

Either or both techniques can be enabled. kLCDRenderText_Flag and kSubpixelText_Flag are clear by default. Font_Anti_Alias or Font_Subpixel can be enabled by default by setting SkPaintDefaults_Flags to kLCDRenderText_Flag or kSubpixelText_Flag (or both) at compile time.

Example

Font_Linear selects whether text is rendered as a Glyph or as a Path. If Font_Linear is set, it has the same effect as setting Hinting to SkFontHinting::kNormal. If Font_Linear is clear, it is the same as setting Hinting to SkFontHinting::kNone.


Returns true if text is converted to SkPath before drawing and measuring.

Equivalent to getFlags() masked with kLinearText_Flag.

Return Value

kLinearText_Flag state

Example

See Also

setLinearText Hinting


Requests, but does not require, that glyphs are converted to SkPath before drawing and measuring. By default, kLinearText_Flag is clear.

Sets kLinearText_Flag if linearText is true. Clears kLinearText_Flag if linearText is false.

Parameters

Example

See Also

isLinearText Hinting

Flags kSubpixelText_Flag uses the pixel transparency to represent a fractional offset. As the opaqueness of the color increases, the edge of the glyph appears to move towards the outside of the pixel.


Returns true if glyphs at different sub-pixel positions may differ on pixel edge coverage.

Equivalent to getFlags() masked with kSubpixelText_Flag.

Return Value

kSubpixelText_Flag state

Example

Example Output

paint.isSubpixelText() == !!(paint.getFlags() & SkPaint::kSubpixelText_Flag)
paint.isSubpixelText() == !!(paint.getFlags() & SkPaint::kSubpixelText_Flag)


Requests, but does not require, that glyphs respect sub-pixel positioning.

Sets kSubpixelText_Flag if subpixelText is true. Clears kSubpixelText_Flag if subpixelText is false.

Parameters

Example

Example Output

paint1 == paint2

When set, Font_Anti_Alias takes advantage of the organization of RGB stripes that create a color, and relies on the small size of the stripe and visual perception to make the color fringing imperceptible. Font_Anti_Alias can be enabled on devices that orient stripes horizontally or vertically, and that order the color components as RGB or BGR.


Returns true if glyphs may use LCD striping to improve glyph edges.

Returns true if SkPaint::Flags kLCDRenderText_Flag is set.

Return Value

kLCDRenderText_Flag state

Example

Example Output

paint.isLCDRenderText() == !!(paint.getFlags() & SkPaint::kLCDRenderText_Flag)
paint.isLCDRenderText() == !!(paint.getFlags() & SkPaint::kLCDRenderText_Flag)


Requests, but does not require, that glyphs use LCD striping for glyph edges.

Sets kLCDRenderText_Flag if lcdText is true. Clears kLCDRenderText_Flag if lcdText is false.

Parameters

Example

Example Output

paint1 == paint2


Font_Embedded_Bitmaps allows selecting custom sized bitmap Glyphs. Flags kEmbeddedBitmapText_Flag when set chooses an embedded bitmap glyph over an outline contained in a font if the platform supports this option.

FreeType selects the bitmap glyph if available when kEmbeddedBitmapText_Flag is set, and selects the outline glyph if kEmbeddedBitmapText_Flag is clear. Windows may select the bitmap glyph but is not required to do so. OS_X and iOS do not support this option.

Font_Embedded_Bitmaps is disabled by default. Font_Embedded_Bitmaps can be enabled by default by setting SkPaintDefaults_Flags to kEmbeddedBitmapText_Flag at compile time.

Example


Returns true if font engine may return glyphs from font bitmaps instead of from outlines.

Equivalent to getFlags() masked with kEmbeddedBitmapText_Flag.

Return Value

kEmbeddedBitmapText_Flag state

Example

Example Output

paint.isEmbeddedBitmapText() == !!(paint.getFlags() & SkPaint::kEmbeddedBitmapText_Flag)
paint.isEmbeddedBitmapText() == !!(paint.getFlags() & SkPaint::kEmbeddedBitmapText_Flag)


Requests, but does not require, to use bitmaps in fonts instead of outlines.

Sets kEmbeddedBitmapText_Flag if useEmbeddedBitmapText is true. Clears kEmbeddedBitmapText_Flag if useEmbeddedBitmapText is false.

Parameters

Example

Example Output

paint1 == paint2

If Hinting is set to SkFontHinting::kNormal or SkFontHinting::kFull, Font_Force_Hinting instructs the Font_Manager to always hint Glyphs. Font_Force_Hinting has no effect if Hinting is set to SkFontHinting::kNone or SkFontHinting::kSlight.

Font_Force_Hinting only affects platforms that use FreeType as the Font_Manager.


Returns true if SkPaint::Hinting is set to SkFontHinting::kNormal or SkFontHinting::kFull, and if platform uses FreeType as the font manager. If true, instructs the font manager to always hint glyphs.

Equivalent to getFlags() masked with kAutoHinting_Flag.

Return Value

kAutoHinting_Flag state

Example

Example Output

paint.isAutohinted() == !!(paint.getFlags() & SkPaint::kAutoHinting_Flag)
paint.isAutohinted() == !!(paint.getFlags() & SkPaint::kAutoHinting_Flag)

See Also

setAutohinted Hinting


Sets whether to always hint glyphs. If SkPaint::Hinting is set to SkFontHinting::kNormal or SkFontHinting::kFull and useAutohinter is set, instructs the font manager to always hint glyphs. useAutohinter has no effect if SkPaint::Hinting is set to SkFontHinting::kNone or SkFontHinting::kSlight.

Only affects platforms that use FreeType as the font manager.

Sets kAutoHinting_Flag if useAutohinter is true. Clears kAutoHinting_Flag if useAutohinter is false.

Parameters

Example

See Also

isAutohinted Hinting


Font_Embolden approximates the bold font style accompanying a normal font when a bold font face is not available. Skia does not provide font substitution; it is up to the client to find the bold font face using the platform Font_Manager.

Use Text_Skew_X to approximate an italic font style when the italic font face is not available.

A FreeType based port may define SK_USE_FREETYPE_EMBOLDEN at compile time to direct the font engine to create the bold Glyphs. Otherwise, the extra bold is computed by increasing the stroke width and setting the Style to kStrokeAndFill_Style as needed.

Font_Embolden is disabled by default.

Example


Returns true if approximate bold by increasing the stroke width when creating glyph bitmaps from outlines.

Equivalent to getFlags() masked with kFakeBoldText_Flag.

Return Value

kFakeBoldText_Flag state

Example

Example Output

paint.isFakeBoldText() == !!(paint.getFlags() & SkPaint::kFakeBoldText_Flag)
paint.isFakeBoldText() == !!(paint.getFlags() & SkPaint::kFakeBoldText_Flag)


Increases stroke width when creating glyph bitmaps to approximate a bold typeface.

Sets kFakeBoldText_Flag if fakeBoldText is true. Clears kFakeBoldText_Flag if fakeBoldText is false.

Parameters

Example

Example Output

paint1 == paint2


Filter_Quality trades speed for image filtering when the image is scaled. A lower Filter_Quality draws faster, but has less fidelity. A higher Filter_Quality draws slower, but looks better. If the image is drawn without scaling, the Filter_Quality choice will not result in a noticeable difference.

Filter_Quality is used in Paint passed as a parameter to

and when Paint has a Shader specialization that uses Image or Bitmap.

Filter_Quality is kNone_SkFilterQuality by default.

Example


Returns SkFilterQuality, the image filtering level. A lower setting draws faster; a higher setting looks better when the image is scaled.

Return Value

one of: kNone_SkFilterQuality, kLow_SkFilterQuality,

kMedium_SkFilterQuality, kHigh_SkFilterQuality

Example

Example Output

kNone_SkFilterQuality == paint.getFilterQuality()


Sets SkFilterQuality, the image filtering level. A lower setting draws faster; a higher setting looks better when the image is scaled. Does not check to see if quality is valid.

Parameters

kMedium_SkFilterQuality, kHigh_SkFilterQuality

Example

Example Output

kHigh_SkFilterQuality == paint.getFilterQuality()

See Also

SkFilterQuality Image_Scaling


namedescription
getColorreturns Color_Alpha and RGB, one drawing color
setColorsets Color_Alpha and RGB, one drawing color

Color specifies the red, blue, green, and Color_Alpha values used to draw a filled or stroked shape in a 32-bit value. Each component occupies 8-bits, ranging from zero: no contribution; to 255: full intensity. All values in any combination are valid.

Color is not Premultiplied; Color_Alpha sets the transparency independent of RGB: red, blue, and green.

The bit positions of Color_Alpha and RGB are independent of the bit positions on the output device, which may have more or fewer bits, and may have a different arrangement.

bit positionsColor_Alpharedbluegreen
31 - 2423 - 1615 - 87 - 0

Example


Retrieves alpha and RGB, unpremultiplied, packed into 32 bits. Use helpers SkColorGetA(), SkColorGetR(), SkColorGetG(), and SkColorGetB() to extract a color component.

Return Value

unpremultiplied ARGB

Example

Example Output

Yellow is 100% red, 100% green, and 0% blue.

See Also

getColor4f SkColor


Retrieves alpha and RGB, unpremultiplied, as four floating point values. RGB are are extended sRGB values (sRGB gamut, and encoded with the sRGB transfer function).

Return Value

unpremultiplied RGBA

Example

Example Output

Yellow is 100% red, 100% green, and 0% blue.

See Also

getColor SkColor


Sets alpha and RGB used when stroking and filling. The color is a 32-bit value, unpremultiplied, packing 8-bit components for alpha, red, blue, and green.

Parameters

Example

Example Output

green1 == green2

See Also

SkColor setColor4f setARGB SkColorSetARGB


Sets alpha and RGB used when stroking and filling. The color is four floating point values, unpremultiplied. The color values are interpreted as being in the colorSpace. If colorSpace is nullptr, then color is assumed to be in the sRGB color space.

Parameters

Example

Example Output

green1 == green2

See Also

SkColor setColor setARGB SkColorSetARGB

Color_Alpha sets the transparency independent of RGB: red, blue, and green.


Retrieves alpha from the color used when stroking and filling.

Return Value

alpha ranging from zero, fully transparent, to 255, fully opaque

Example

Example Output

255 == paint.getAlpha()


Replaces alpha, leaving RGB unchanged. An out of range value triggers an assert in the debug build. a is a value from zero to 255. a set to zero makes color fully transparent; a set to 255 makes color fully opaque.

Parameters

Example

Example Output

0x44112233 == paint.getColor()


Sets color used when drawing solid fills. The color components range from 0 to 255. The color is unpremultiplied; alpha sets the transparency independent of RGB.

Parameters

Example

Example Output

transRed1 == transRed2

See Also

setColor SkColorSetARGB


Style specifies if the geometry is filled, stroked, or both filled and stroked. Some shapes ignore Style and are always drawn filled or stroked.

Set Style to kFill_Style to fill the shape. The fill covers the area inside the geometry for most shapes.

Set Style to kStroke_Style to stroke the shape.

The stroke covers the area described by following the shape edge with a pen or brush of Stroke_Width. The area covered where the shape starts and stops is described by Stroke_Cap. The area covered where the shape turns a corner is described by Stroke_Join. The stroke is centered on the shape; it extends equally on either side of the shape edge.As Stroke_Width gets smaller, the drawn path frame is thinner. Stroke_Width less than one may have gaps, and if kAntiAlias_Flag is set, Color_Alpha will increase to visually decrease coverage.

See Also

Path_Fill_Type Path_Effect Style_Fill Style_Stroke


Stroke_Width of zero has a special meaning and switches drawing to use Hairline. Hairline draws the thinnest continuous frame. If kAntiAlias_Flag is clear, adjacent pixels flow horizontally, vertically,or diagonally.

Path drawing with Hairline may hit the same pixel more than once. For instance, Path containing two lines in one Path_Contour will draw the corner point once, but may both lines may draw the adjacent pixel. If kAntiAlias_Flag is set, transparency is applied twice, resulting in a darker pixel. Some GPU-backed implementations apply transparency at a later drawing stage, avoiding double hit pixels while stroking.

See Also

Path_Fill_Type Path_Effect Style_Fill Style_Stroke


Set Style to fill, stroke, or both fill and stroke geometry. The stroke and fill share all paint attributes; for instance, they are drawn with the same color.

Use kStrokeAndFill_Style to avoid hitting the same pixels twice with a stroke draw and a fill draw.

Constants


Returns whether the geometry is filled, stroked, or filled and stroked.

Return Value

one of:kFill_Style, kStroke_Style, kStrokeAndFill_Style

Example

Example Output

SkPaint::kFill_Style == paint.getStyle()

See Also

Style setStyle


Sets whether the geometry is filled, stroked, or filled and stroked. Has no effect if style is not a legal SkPaint::Style value.

Parameters

Example

See Also

Style getStyle


Stroke_Width sets the width for stroking. The width is the thickness of the stroke perpendicular to the path direction when the paint style is set to kStroke_Style or kStrokeAndFill_Style.

When width is greater than zero, the stroke encompasses as many pixels partially or fully as needed. When the width equals zero, the paint enables hairlines; the stroke is always one pixel wide.

The stroke dimensions are scaled by the canvas matrix, but Hairline stroke remains one pixel wide regardless of scaling.

The default width for the paint is zero.

Example


Returns the thickness of the pen used by SkPaint to outline the shape.

Return Value

zero for hairline, greater than zero for pen thickness

Example

Example Output

0 == paint.getStrokeWidth()


Sets the thickness of the pen used by the paint to outline the shape. Has no effect if width is less than zero.

Parameters

Example

Example Output

5 == paint.getStrokeWidth()


Miter_Limit specifies the maximum miter length, relative to the stroke width.

Miter_Limit is used when the Stroke_Join is set to kMiter_Join, and the Style is either kStroke_Style or kStrokeAndFill_Style.

If the miter at a corner exceeds this limit, kMiter_Join is replaced with kBevel_Join.

Miter_Limit can be computed from the corner angle using: miter limit = 1 / sin ( angle / 2 ).

Miter_Limit default value is 4. The default may be changed at compile time by setting SkPaintDefaults_MiterLimit in “SkUserConfig.h” or as a define supplied by the build environment.

Here are some miter limits and the angles that triggers them.

miter limitangle in degrees
1011.48
912.76
814.36
716.43
619.19
523.07
428.96
338.94
260
1180

Example


Returns the limit at which a sharp corner is drawn beveled.

Return Value

zero and greater miter limit

Example

Example Output

default miter limit == 4

See Also

Miter_Limit setStrokeMiter Join


Sets the limit at which a sharp corner is drawn beveled. Valid values are zero and greater. Has no effect if miter is less than zero.

Parameters

Example

Example Output

default miter limit == 8

See Also

Miter_Limit getStrokeMiter Join


Stroke_Cap draws at the beginning and end of an open Path_Contour.

Constants

Stroke describes the area covered by a pen of Stroke_Width as it follows the Path_Contour, moving parallel to the contour direction.

If the Path_Contour is not terminated by SkPath::kClose_Verb, the contour has a visible beginning and end.

Path_Contour may start and end at the same point; defining Zero_Length_Contour.

kButt_Cap and Zero_Length_Contour is not drawn. kRound_Cap and Zero_Length_Contour draws a circle of diameter Stroke_Width at the contour point. kSquare_Cap and Zero_Length_Contour draws an upright square with a side of Stroke_Width at the contour point.

Stroke_Cap is kButt_Cap by default.

Example


Returns the geometry drawn at the beginning and end of strokes.

Return Value

one of: kButt_Cap, kRound_Cap, kSquare_Cap

Example

Example Output

kButt_Cap == default stroke cap

See Also

Stroke_Cap setStrokeCap


Sets the geometry drawn at the beginning and end of strokes.

Parameters

has no effect if cap is not valid

Example

Example Output

kRound_Cap == paint.getStrokeCap()

See Also

Stroke_Cap getStrokeCap

Stroke_Join draws at the sharp corners of an open or closed Path_Contour.

Stroke describes the area covered by a pen of Stroke_Width as it follows the Path_Contour, moving parallel to the contour direction.

If the contour direction changes abruptly, because the tangent direction leading to the end of a curve within the contour does not match the tangent direction of the following curve, the pair of curves meet at Stroke_Join.

Example


Join specifies how corners are drawn when a shape is stroked. Join affects the four corners of a stroked rectangle, and the connected segments in a stroked path.

Choose miter join to draw sharp corners. Choose round join to draw a circle with a radius equal to the stroke width on top of the corner. Choose bevel join to minimally connect the thick strokes.

The fill path constructed to describe the stroked path respects the join setting but may not contain the actual join. For instance, a fill path constructed with round joins does not necessarily include circles at each connected segment.

Constants

Example

See Also

setStrokeJoin getStrokeJoin setStrokeMiter getStrokeMiter


Returns the geometry drawn at the corners of strokes.

Return Value

one of: kMiter_Join, kRound_Join, kBevel_Join

Example

Example Output

kMiter_Join == default stroke join

See Also

Stroke_Join setStrokeJoin


Sets the geometry drawn at the corners of strokes.

Parameters

otherwise, has no effect

Example

Example Output

kMiter_Join == paint.getStrokeJoin()

See Also

Stroke_Join getStrokeJoin

See Also

Miter_Limit


Fill_Path creates a Path by applying the Path_Effect, followed by the Style_Stroke.

If Paint contains Path_Effect, Path_Effect operates on the source Path; the result replaces the destination Path. Otherwise, the source Path is replaces the destination Path.

Fill Path can request the Path_Effect to restrict to a culling rectangle, but the Path_Effect is not required to do so.

If Style is kStroke_Style or kStrokeAndFill_Style, and Stroke_Width is greater than zero, the Stroke_Width, Stroke_Cap, Stroke_Join, and Miter_Limit operate on the destination Path, replacing it.

Fill Path can specify the precision used by Stroke_Width to approximate the stroke geometry.

If the Style is kStroke_Style and the Stroke_Width is zero, getFillPath returns false since Hairline has no filled equivalent.

See Also

Style_Stroke Stroke_Width Path_Effect


Returns the filled equivalent of the stroked path.

Parameters

to favor speed and size

Return Value

true if the path represents style fill, or false if it represents hairline

Example


Returns the filled equivalent of the stroked path.

Replaces dst with the src path modified by SkPathEffect and style stroke. SkPathEffect, if any, is not culled. stroke width is created with default precision.

Parameters

Return Value

true if the path represents style fill, or false if it represents hairline

Example


Shader defines the colors used when drawing a shape. Shader may be an image, a gradient, or a computed fill. If Paint has no Shader, then Color fills the shape.

Shader is modulated by Color_Alpha component of Color. If Shader object defines only Color_Alpha, then Color modulated by Color_Alpha describes the fill.

The drawn transparency can be modified without altering Shader, by changing Color_Alpha.

Example

If Shader generates only Color_Alpha then all components of Color modulate the output.

Example


Returns optional colors used when filling a path, such as a gradient.

Does not alter SkShader SkRefCnt.

Return Value

SkShader if previously set, nullptr otherwise

Example

Example Output

nullptr == shader
nullptr != shader


Returns optional colors used when filling a path, such as a gradient.

Increases SkShader SkRefCnt by one.

Return Value

SkShader if previously set, nullptr otherwise

Example

Example Output

shader unique: true
shader unique: false


Sets optional colors used when filling a path, such as a gradient.

Sets SkShader to shader, decreasing SkRefCnt of the previous SkShader. Increments shader SkRefCnt by one.

Parameters

Example


Color_Filter alters the color used when drawing a shape. Color_Filter may apply Blend_Mode, transform the color through a matrix, or composite multiple filters. If Paint has no Color_Filter, the color is unaltered.

The drawn transparency can be modified without altering Color_Filter, by changing Color_Alpha.

Example


Returns SkColorFilter if set, or nullptr. Does not alter SkColorFilter SkRefCnt.

Return Value

SkColorFilter if previously set, nullptr otherwise

Example

Example Output

nullptr == color filter
nullptr != color filter


Returns SkColorFilter if set, or nullptr. Increases SkColorFilter SkRefCnt by one.

Return Value

SkColorFilter if set, or nullptr

Example

Example Output

color filter unique: true
color filter unique: false


Sets SkColorFilter to filter, decreasing SkRefCnt of the previous SkColorFilter. Pass nullptr to clear SkColorFilter.

Increments filter SkRefCnt by one.

Parameters

Example


Blend_Mode describes how Color combines with the destination color. The default setting, SkBlendMode::kSrcOver, draws the source color over the destination color.

Example

See Also

Blend_Mode


Returns SkBlendMode. By default, returns SkBlendMode::kSrcOver.

Return Value

mode used to combine source color with destination color

Example

Example Output

kSrcOver == getBlendMode
kSrcOver != getBlendMode


Returns true if SkBlendMode is SkBlendMode::kSrcOver, the default.

Return Value

true if SkBlendMode is SkBlendMode::kSrcOver

Example

Example Output

isSrcOver == true
isSrcOver != true


Sets SkBlendMode to mode. Does not check for valid input.

Parameters

Example

Example Output

isSrcOver == true
isSrcOver != true


Path_Effect modifies the path geometry before drawing it. Path_Effect may implement dashing, custom fill effects and custom stroke effects. If Paint has no Path_Effect, the path geometry is unaltered when filled or stroked.

Example

See Also

Path_Effect


Returns SkPathEffect if set, or nullptr. Does not alter SkPathEffect SkRefCnt.

Return Value

SkPathEffect if previously set, nullptr otherwise

Example

Example Output

nullptr == path effect
nullptr != path effect


Returns SkPathEffect if set, or nullptr. Increases SkPathEffect SkRefCnt by one.

Return Value

SkPathEffect if previously set, nullptr otherwise

Example

Example Output

path effect unique: true
path effect unique: false


Sets SkPathEffect to pathEffect, decreasing SkRefCnt of the previous SkPathEffect. Pass nullptr to leave the path geometry unaltered.

Increments pathEffect SkRefCnt by one.

Parameters

Example


Mask_Filter uses coverage of the shape drawn to create Mask_Alpha. Mask_Filter takes a Mask, and returns a Mask.

Mask_Filter may change the geometry and transparency of the shape, such as creating a blur effect. Set Mask_Filter to nullptr to prevent Mask_Filter from modifying the draw.

Example


Returns SkMaskFilter if set, or nullptr. Does not alter SkMaskFilter SkRefCnt.

Return Value

SkMaskFilter if previously set, nullptr otherwise

Example

Example Output

nullptr == mask filter
nullptr != mask filter


Returns SkMaskFilter if set, or nullptr.

Increases SkMaskFilter SkRefCnt by one.

Return Value

SkMaskFilter if previously set, nullptr otherwise

Example

Example Output

mask filter unique: true
mask filter unique: false


Sets SkMaskFilter to maskFilter, decreasing SkRefCnt of the previous SkMaskFilter. Pass nullptr to clear SkMaskFilter and leave SkMaskFilter effect on mask alpha unaltered.

Increments maskFilter SkRefCnt by one.

Parameters

Example


Typeface identifies the font used when drawing and measuring text. Typeface may be specified by name, from a file, or from a data stream. The default Typeface defers to the platform-specific default font implementation.

Example


Returns SkTypeface if set, or nullptr. Does not alter SkTypeface SkRefCnt.

Return Value

SkTypeface if previously set, nullptr otherwise

Example

Example Output

nullptr == typeface
nullptr != typeface


Increases SkTypeface SkRefCnt by one.

Return Value

SkTypeface if previously set, nullptr otherwise

Example

Example Output

typeface1 != typeface2
typeface1 == typeface2


Sets SkTypeface to typeface, decreasing SkRefCnt of the previous SkTypeface. Pass nullptr to clear SkTypeface and use the default typeface. Increments typeface SkRefCnt by one.

Parameters

Example


Image_Filter operates on the pixel representation of the shape, as modified by Paint with Blend_Mode set to SkBlendMode::kSrcOver. Image_Filter creates a new bitmap, which is drawn to the device using the set Blend_Mode.

Image_Filter is higher level than Mask_Filter; for instance, an Image_Filter can operate on all channels of Color, while Mask_Filter generates Alpha only. Image_Filter operates independently of and can be used in combination with Mask_Filter.

Example


Returns SkImageFilter if set, or nullptr. Does not alter SkImageFilter SkRefCnt.

Return Value

SkImageFilter if previously set, nullptr otherwise

Example

Example Output

nullptr == image filter
nullptr != image filter


Returns SkImageFilter if set, or nullptr. Increases SkImageFilter SkRefCnt by one.

Return Value

SkImageFilter if previously set, nullptr otherwise

Example

Example Output

image filter unique: true
image filter unique: false


Sets SkImageFilter to imageFilter, decreasing SkRefCnt of the previous SkImageFilter. Pass nullptr to clear SkImageFilter, and remove SkImageFilter effect on drawing.

Increments imageFilter SkRefCnt by one.

Parameters

Example


Draw_Looper sets a modifier that communicates state from one Draw_Layer to another to construct the draw.

Draw_Looper draws one or more times, modifying the canvas and paint each time. Draw_Looper may be used to draw multiple colors or create a colored shadow. Set Draw_Looper to nullptr to prevent Draw_Looper from modifying the draw.

Example


Returns SkDrawLooper if set, or nullptr. Does not alter SkDrawLooper SkRefCnt.

Return Value

SkDrawLooper if previously set, nullptr otherwise

Example

Example Output

nullptr == draw looper
nullptr != draw looper


Returns SkDrawLooper if set, or nullptr. Increases SkDrawLooper SkRefCnt by one.

Return Value

SkDrawLooper if previously set, nullptr otherwise

Example

Example Output

draw looper unique: true
draw looper unique: false


Sets SkDrawLooper to drawLooper, decreasing SkRefCnt of the previous drawLooper. Pass nullptr to clear SkDrawLooper and leave SkDrawLooper effect on drawing unaltered.

Increments drawLooper SkRefCnt by one.

Parameters

Example


Text_Size adjusts the overall text size in points. Text_Size can be set to any positive value or zero. Text_Size defaults to 12. Set SkPaintDefaults_TextSize at compile time to change the default setting.

Example


Returns text size in points.

Return Value

typographic height of text

Example


Sets text size in points. Has no effect if textSize is not greater than or equal to zero.

Parameters

Example


Text_Scale_X adjusts the text horizontal scale. Text scaling approximates condensed and expanded type faces when the actual face is not available. Text_Scale_X can be set to any value. Text_Scale_X defaults to 1.

Example


Returns text scale on x-axis. Default value is 1.

Return Value

text horizontal scale

Example


Sets text scale on x-axis. Default value is 1.

Parameters

Example


Text_Skew_X adjusts the text horizontal slant. Text skewing approximates italic and oblique type faces when the actual face is not available. Text_Skew_X can be set to any value. Text_Skew_X defaults to 0.

Example


Returns text skew on x-axis. Default value is zero.

Return Value

additional shear on x-axis relative to y-axis

Example


Sets text skew on x-axis. Default value is zero.

Parameters

Example


Example


Returns the text encoding. Text encoding describes how to interpret the text bytes pass to methods like measureText() and SkCanvas::drawText().

Return Value

the text encoding

Example

Example Output

kUTF8_SkTextEncoding == text encoding
kGlyphID_SkTextEncoding == text encoding


Sets the text encoding. Text encoding describes how to interpret the text bytes pass to methods like measureText() and SkCanvas::drawText().

Parameters

Example

Example Output

4 != text encoding



Returns SkFontMetrics associated with SkTypeface. The return value is the recommended spacing between lines: the sum of metrics descent, ascent, and leading. If metrics is not nullptr, SkFontMetrics is copied to metrics. Results are scaled by text size but does not take into account dimensions required by text scale x, text skew x, fake bold, style stroke, and SkPathEffect.

Parameters

Return Value

recommended spacing between lines

Example

See Also

Font_Size Typeface Typeface_Methods


Returns the recommended spacing between lines: the sum of metrics descent, ascent, and leading. Result is scaled by text size but does not take into account dimensions required by stroking and SkPathEffect. Returns the same result as getFontMetrics().

Return Value

recommended spacing between lines

Example

Example Output

textSize: 12 fontSpacing: 13.9688
textSize: 18 fontSpacing: 20.9531
textSize: 24 fontSpacing: 27.9375
textSize: 32 fontSpacing: 37.25


Converts text into glyph indices. Returns the number of glyph indices represented by text. SkTextEncoding specifies how text represents characters or glyphs. glyphs may be nullptr, to compute the glyph count.

Does not check text for valid character codes or valid glyph indices.

If byteLength equals zero, returns zero. If byteLength includes a partial character, the partial character is ignored.

If SkTextEncoding is kUTF8_SkTextEncoding and text contains an invalid UTF-8 sequence, zero is returned.

Parameters

Return Value

number of glyphs represented by text of length byteLength

Example


Returns the number of glyphs in text. Uses SkTextEncoding to count the glyphs. Returns the same result as textToGlyphs().

Parameters

Return Value

number of glyphs represented by text of length byteLength

Example

Example Output

count = 5


Returns true if all text corresponds to a non-zero glyph index. Returns false if any characters in text are not supported in SkTypeface.

If SkTextEncoding is kGlyphID_SkTextEncoding, returns true if all glyph indices in text are non-zero; does not check to see if text contains valid glyph indices for SkTypeface.

Returns true if byteLength is zero.

Parameters

Return Value

true if all text corresponds to a non-zero glyph index

Example Output

0x00b0 == has char
0xd800 != has char

Example

Example Output

0x01ff == has glyph
0x0000 != has glyph
0xffff == has glyph

See Also

setTextEncoding Typeface


Converts glyphs into text if possible. Glyph values without direct Unicode equivalents are mapped to zero. Uses the SkTypeface, but is unaffected by SkTextEncoding; the text values returned are equivalent to kUTF32_SkTextEncoding.

Only supported on platforms that use FreeType as the font engine.

Parameters


Returns the advance width of text. The advance is the normal distance to move before drawing additional text. Uses SkTextEncoding to decode text, SkTypeface to get the font metrics, and text size, text scale x, text skew x, stroke width, and SkPathEffect to scale the metrics and bounds. Returns the bounding box of text if bounds is not nullptr. The bounding box is computed as if the text was drawn at the origin.

Parameters

Return Value

advance width or height

Example


Returns the advance width of text. The advance is the normal distance to move before drawing additional text. Uses SkTextEncoding to decode text, SkTypeface to get the font metrics, and text size to scale the metrics. Does not scale the advance or bounds by fake bold or SkPathEffect.

Parameters

Return Value

advance width or height

Example

Example Output

default width = 5
double width = 10


Retrieves the advance and bounds for each glyph in text, and returns the glyph count in text. Both widths and bounds may be nullptr. If widths is not nullptr, widths must be an array of glyph count entries. if bounds is not nullptr, bounds must be an array of glyph count entries. Uses SkTextEncoding to decode text, SkTypeface to get the font metrics, and text size to scale the widths and bounds. Does not scale the advance by fake bold or SkPathEffect. Does include fake bold and SkPathEffect in the bounds.

Parameters

Return Value

glyph count in text

Example

Text_Path describes the geometry of Glyphs used to draw text.


Returns the geometry as SkPath equivalent to the drawn text. Uses SkTextEncoding to decode text, SkTypeface to get the glyph paths, and text size, fake bold, and SkPathEffect to scale and modify the glyph paths. All of the glyph paths are stored in path. Uses x, y, to position path.

Parameters

Example


Returns the geometry as SkPath equivalent to the drawn text. Uses SkTextEncoding to decode text, SkTypeface to get the glyph paths, and text size, fake bold, and SkPathEffect to scale and modify the glyph paths. All of the glyph paths are stored in path. Uses pos array to position path. pos contains a position for each glyph.

Parameters

Example


Returns true if SkPaint prevents all drawing; otherwise, the SkPaint may or may not allow drawing.

Returns true if, for example, SkBlendMode combined with alpha computes a new alpha of zero.

Return Value

true if SkPaint prevents all drawing

Example

Example Output

initial nothing to draw: false
blend dst nothing to draw: true
blend src over nothing to draw: false
alpha 0 nothing to draw: true