Skia
2DGraphicsLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkPaint Class Reference

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

#include <SkPaint.h>

Classes

struct  FontMetrics
 

Public Types

enum  Hinting { kNo_Hinting = 0, kSlight_Hinting = 1, kNormal_Hinting = 2, kFull_Hinting = 3 }
 Specifies the level of hinting to be performed. More...
 
enum  Flags {
  kAntiAlias_Flag = 0x01, kDither_Flag = 0x04, kFakeBoldText_Flag = 0x20, kLinearText_Flag = 0x40,
  kSubpixelText_Flag = 0x80, kDevKernText_Flag = 0x100, kLCDRenderText_Flag = 0x200, kEmbeddedBitmapText_Flag = 0x400,
  kAutoHinting_Flag = 0x800, kVerticalText_Flag = 0x1000, kGenA8FromLCD_Flag = 0x2000, kAllFlags = 0xFFFF
}
 Specifies the bit values that are stored in the paint's flags. More...
 
enum  Style { kFill_Style, kStroke_Style, kStrokeAndFill_Style }
 Styles apply to rect, oval, path, and text. More...
 
enum  { kStyleCount = kStrokeAndFill_Style + 1 }
 
enum  Cap {
  kButt_Cap, kRound_Cap, kSquare_Cap, kLast_Cap = kSquare_Cap,
  kDefault_Cap = kButt_Cap
}
 Cap enum specifies the settings for the paint's strokecap. More...
 
enum  Join {
  kMiter_Join, kRound_Join, kBevel_Join, kLast_Join = kBevel_Join,
  kDefault_Join = kMiter_Join
}
 Join enum specifies the settings for the paint's strokejoin. More...
 
enum  Align { kLeft_Align, kCenter_Align, kRight_Align }
 
enum  { kAlignCount = 3 }
 
enum  TextEncoding { kUTF8_TextEncoding, kUTF16_TextEncoding, kUTF32_TextEncoding, kGlyphID_TextEncoding }
 Describes how to interpret the text parameters that are passed to paint methods like measureText() and getTextWidths(). More...
 

Public Member Functions

 SkPaint (const SkPaint &paint)
 
 SkPaint (SkPaint &&paint)
 
SkPaintoperator= (const SkPaint &paint)
 
SkPaintoperator= (SkPaint &&paint)
 
uint32_t getHash () const
 getHash() is a shallow hash, with the same limitations as operator==. More...
 
void flatten (SkWriteBuffer &buffer) const
 
void unflatten (SkReadBuffer &buffer)
 
void reset ()
 Restores the paint to its initial settings.
 
Hinting getHinting () const
 
void setHinting (Hinting hintingLevel)
 
uint32_t getFlags () const
 Return the paint's flags. More...
 
void setFlags (uint32_t flags)
 Set the paint's flags. More...
 
bool isAntiAlias () const
 Helper for getFlags(), returning true if kAntiAlias_Flag bit is set. More...
 
void setAntiAlias (bool aa)
 Helper for setFlags(), setting or clearing the kAntiAlias_Flag bit. More...
 
bool isDither () const
 Helper for getFlags(), returning true if kDither_Flag bit is set. More...
 
void setDither (bool dither)
 Helper for setFlags(), setting or clearing the kDither_Flag bit. More...
 
bool isLinearText () const
 Helper for getFlags(), returning true if kLinearText_Flag bit is set. More...
 
void setLinearText (bool linearText)
 Helper for setFlags(), setting or clearing the kLinearText_Flag bit. More...
 
bool isSubpixelText () const
 Helper for getFlags(), returning true if kSubpixelText_Flag bit is set. More...
 
void setSubpixelText (bool subpixelText)
 Helper for setFlags(), setting or clearing the kSubpixelText_Flag. More...
 
bool isLCDRenderText () const
 
void setLCDRenderText (bool lcdText)
 Helper for setFlags(), setting or clearing the kLCDRenderText_Flag. More...
 
bool isEmbeddedBitmapText () const
 
void setEmbeddedBitmapText (bool useEmbeddedBitmapText)
 Helper for setFlags(), setting or clearing the kEmbeddedBitmapText_Flag bit. More...
 
bool isAutohinted () const
 
void setAutohinted (bool useAutohinter)
 Helper for setFlags(), setting or clearing the kAutoHinting_Flag bit. More...
 
bool isVerticalText () const
 
void setVerticalText (bool verticalText)
 Helper for setting or clearing the kVerticalText_Flag bit in setFlags(...). More...
 
bool isFakeBoldText () const
 Helper for getFlags(), returns true if kFakeBoldText_Flag bit is set. More...
 
void setFakeBoldText (bool fakeBoldText)
 Helper for setFlags(), setting or clearing the kFakeBoldText_Flag bit. More...
 
bool isDevKernText () const
 Helper for getFlags(), returns true if kDevKernText_Flag bit is set. More...
 
void setDevKernText (bool devKernText)
 Helper for setFlags(), setting or clearing the kKernText_Flag bit. More...
 
SkFilterQuality getFilterQuality () const
 Return the filter level. More...
 
void setFilterQuality (SkFilterQuality quality)
 Set the filter quality. More...
 
Style getStyle () const
 Return the paint's style, used for controlling how primitives' geometries are interpreted (except for drawBitmap, which always assumes kFill_Style). More...
 
void setStyle (Style style)
 Set the paint's style, used for controlling how primitives' geometries are interpreted (except for drawBitmap, which always assumes Fill). More...
 
SkColor getColor () const
 Return the paint's color. More...
 
void setColor (SkColor color)
 Set the paint's color. More...
 
uint8_t getAlpha () const
 Helper to getColor() that just returns the color's alpha value. More...
 
void setAlpha (U8CPU a)
 Helper to setColor(), that only assigns the color's alpha value, leaving its r,g,b values unchanged. More...
 
void setARGB (U8CPU a, U8CPU r, U8CPU g, U8CPU b)
 Helper to setColor(), that takes a,r,g,b and constructs the color value using SkColorSetARGB() More...
 
SkScalar getStrokeWidth () const
 Return the width for stroking. More...
 
void setStrokeWidth (SkScalar width)
 Set the width for stroking. More...
 
SkScalar getStrokeMiter () const
 Return the paint's stroke miter value. More...
 
void setStrokeMiter (SkScalar miter)
 Set the paint's stroke miter value. More...
 
Cap getStrokeCap () const
 Return the paint's stroke cap type, controlling how the start and end of stroked lines and paths are treated. More...
 
void setStrokeCap (Cap cap)
 Set the paint's stroke cap type. More...
 
Join getStrokeJoin () const
 Return the paint's stroke join type. More...
 
void setStrokeJoin (Join join)
 Set the paint's stroke join type. More...
 
bool getFillPath (const SkPath &src, SkPath *dst, const SkRect *cullRect, SkScalar resScale=1) const
 Applies any/all effects (patheffect, stroking) to src, returning the result in dst. More...
 
bool getFillPath (const SkPath &src, SkPath *dst) const
 
SkShadergetShader () const
 Get the paint's shader object. More...
 
sk_sp< SkShaderrefShader () const
 
void setShader (sk_sp< SkShader > shader)
 Set or clear the shader object. More...
 
SkColorFiltergetColorFilter () const
 Get the paint's colorfilter. More...
 
sk_sp< SkColorFilterrefColorFilter () const
 
void setColorFilter (sk_sp< SkColorFilter > colorFilter)
 Set or clear the paint's colorfilter. More...
 
SkBlendMode getBlendMode () const
 
bool isSrcOver () const
 
void setBlendMode (SkBlendMode mode)
 
SkPathEffectgetPathEffect () const
 Get the paint's patheffect object. More...
 
sk_sp< SkPathEffectrefPathEffect () const
 
void setPathEffect (sk_sp< SkPathEffect > pathEffect)
 Set or clear the patheffect object. More...
 
SkMaskFiltergetMaskFilter () const
 Get the paint's maskfilter object. More...
 
sk_sp< SkMaskFilterrefMaskFilter () const
 
void setMaskFilter (sk_sp< SkMaskFilter > maskFilter)
 Set or clear the maskfilter object. More...
 
SkTypefacegetTypeface () const
 Get the paint's typeface object. More...
 
sk_sp< SkTypefacerefTypeface () const
 
void setTypeface (sk_sp< SkTypeface > typeface)
 Set or clear the typeface object. More...
 
SkRasterizergetRasterizer () const
 Get the paint's rasterizer (or NULL). More...
 
sk_sp< SkRasterizerrefRasterizer () const
 
void setRasterizer (sk_sp< SkRasterizer > rasterizer)
 Set or clear the rasterizer object. More...
 
SkImageFiltergetImageFilter () const
 
sk_sp< SkImageFilterrefImageFilter () const
 
void setImageFilter (sk_sp< SkImageFilter > imageFilter)
 
SkDrawLoopergetDrawLooper () const
 Return the paint's SkDrawLooper (if any). More...
 
sk_sp< SkDrawLooperrefDrawLooper () const
 
SkDrawLoopergetLooper () const
 
void setDrawLooper (sk_sp< SkDrawLooper > drawLooper)
 Set or clear the looper object. More...
 
void setLooper (sk_sp< SkDrawLooper > drawLooper)
 
Align getTextAlign () const
 Return the paint's Align value for drawing text. More...
 
void setTextAlign (Align align)
 Set the paint's text alignment. More...
 
SkScalar getTextSize () const
 Return the paint's text size. More...
 
void setTextSize (SkScalar textSize)
 Set the paint's text size. More...
 
SkScalar getTextScaleX () const
 Return the paint's horizontal scale factor for text. More...
 
void setTextScaleX (SkScalar scaleX)
 Set the paint's horizontal scale factor for text. More...
 
SkScalar getTextSkewX () const
 Return the paint's horizontal skew factor for text. More...
 
void setTextSkewX (SkScalar skewX)
 Set the paint's horizontal skew factor for text. More...
 
TextEncoding getTextEncoding () const
 
void setTextEncoding (TextEncoding encoding)
 
SkScalar getFontMetrics (FontMetrics *metrics, SkScalar scale=0) const
 Return the recommend spacing between lines (which will be fDescent - fAscent + fLeading). More...
 
SkScalar getFontSpacing () const
 Return the recommend line spacing. More...
 
int textToGlyphs (const void *text, size_t byteLength, SkGlyphID glyphs[]) const
 Convert the specified text into glyph IDs, returning the number of glyphs ID written. More...
 
bool containsText (const void *text, size_t byteLength) const
 Return true if all of the specified text has a corresponding non-zero glyph ID. More...
 
void glyphsToUnichars (const SkGlyphID glyphs[], int count, SkUnichar text[]) const
 Convert the glyph array into Unichars. More...
 
int countText (const void *text, size_t byteLength) const
 Return the number of drawable units in the specified text buffer. More...
 
SkScalar measureText (const void *text, size_t length, SkRect *bounds) const
 Return the width of the text. More...
 
SkScalar measureText (const void *text, size_t length) const
 Return the width of the text. More...
 
size_t breakText (const void *text, size_t length, SkScalar maxWidth, SkScalar *measuredWidth=NULL) const
 Return the number of bytes of text that were measured. More...
 
int getTextWidths (const void *text, size_t byteLength, SkScalar widths[], SkRect bounds[]=NULL) const
 Return the advances for the text. More...
 
void getTextPath (const void *text, size_t length, SkScalar x, SkScalar y, SkPath *path) const
 Return the path (outline) for the specified text. More...
 
void getPosTextPath (const void *text, size_t length, const SkPoint pos[], SkPath *path) const
 Return the path (outline) for the specified text. More...
 
int getTextIntercepts (const void *text, size_t length, SkScalar x, SkScalar y, const SkScalar bounds[2], SkScalar *intervals) const
 Return the number of intervals that intersect the intercept along the axis of the advance. More...
 
int getPosTextIntercepts (const void *text, size_t length, const SkPoint pos[], const SkScalar bounds[2], SkScalar *intervals) const
 Return the number of intervals that intersect the intercept along the axis of the advance. More...
 
int getPosTextHIntercepts (const void *text, size_t length, const SkScalar xpos[], SkScalar constY, const SkScalar bounds[2], SkScalar *intervals) const
 Return the number of intervals that intersect the intercept along the axis of the advance. More...
 
int getTextBlobIntercepts (const SkTextBlob *blob, const SkScalar bounds[2], SkScalar *intervals) const
 Return the number of intervals that intersect the intercept along the axis of the advance. More...
 
SkRect getFontBounds () const
 Return a rectangle that represents the union of the bounds of all of the glyphs, but each one positioned at (0,0). More...
 
bool nothingToDraw () const
 
bool canComputeFastBounds () const
 Returns true if the current paint settings allow for fast computation of bounds (i.e. More...
 
const SkRectcomputeFastBounds (const SkRect &orig, SkRect *storage) const
 Only call this if canComputeFastBounds() returned true. More...
 
const SkRectcomputeFastStrokeBounds (const SkRect &orig, SkRect *storage) const
 
const SkRectdoComputeFastBounds (const SkRect &orig, SkRect *storage, Style style) const
 

Static Public Attributes

static constexpr int kCapCount = kLast_Cap + 1
 
static constexpr int kJoinCount = kLast_Join + 1
 

Private Types

enum  ScalerContextFlags : uint32_t { kNone_ScalerContextFlags = 0, kFakeGamma_ScalerContextFlag = 1 << 0, kBoostContrast_ScalerContextFlag = 1 << 1, kFakeGammaAndBoostContrast_ScalerContextFlags }
 
enum  { kCanonicalTextSizeForPaths = 64 }
 
typedef const SkGlyph &(* GlyphCacheProc )(SkGlyphCache *, const char **)
 

Private Member Functions

SkScalar measure_text (SkGlyphCache *, const char *text, size_t length, int *count, SkRect *bounds) const
 
void getScalerContextDescriptor (SkScalerContextEffects *, SkAutoDescriptor *, const SkSurfaceProps &surfaceProps, uint32_t scalerContextFlags, const SkMatrix *) const
 
SkGlyphCache * detachCache (const SkSurfaceProps *surfaceProps, uint32_t scalerContextFlags, const SkMatrix *) const
 
void descriptorProc (const SkSurfaceProps *surfaceProps, uint32_t scalerContextFlags, const SkMatrix *deviceMatrix, void(*proc)(SkTypeface *, const SkScalerContextEffects &, const SkDescriptor *, void *), void *context) const
 
SkColor computeLuminanceColor () const
 
SkScalar setupForAsPaths ()
 

Static Private Member Functions

static GlyphCacheProc GetGlyphCacheProc (TextEncoding encoding, bool isDevKern, bool needFullMetrics)
 
static bool TooBigToUseCache (const SkMatrix &ctm, const SkMatrix &textM)
 
static SkScalar MaxCacheSize2 ()
 

Private Attributes

sk_sp< SkTypefacefTypeface
 
sk_sp< SkPathEffectfPathEffect
 
sk_sp< SkShaderfShader
 
sk_sp< SkMaskFilterfMaskFilter
 
sk_sp< SkColorFilterfColorFilter
 
sk_sp< SkRasterizerfRasterizer
 
sk_sp< SkDrawLooperfDrawLooper
 
sk_sp< SkImageFilterfImageFilter
 
SkScalar fTextSize
 
SkScalar fTextScaleX
 
SkScalar fTextSkewX
 
SkColor fColor
 
SkScalar fWidth
 
SkScalar fMiterLimit
 
uint32_t fBlendMode
 
union {
   struct {
      unsigned   fFlags: 16
 
      unsigned   fTextAlign: 2
 
      unsigned   fCapType: 2
 
      unsigned   fJoinType: 2
 
      unsigned   fStyle: 2
 
      unsigned   fTextEncoding: 2
 
      unsigned   fHinting: 2
 
      unsigned   fFilterQuality: 2
 
   }   fBitfields
 
   uint32_t   fBitfieldsUInt
 
}; 
 

Friends

class SkAutoGlyphCache
 
class SkAutoGlyphCacheNoGamma
 
class SkCanvas
 
class SkDraw
 
class SkPDFDevice
 
class GrAtlasTextBlob
 
class GrAtlasTextContext
 
class GrStencilAndCoverTextContext
 
class GrPathRendering
 
class GrTextUtils
 
class GrGLPathRendering
 
class SkScalerContext
 
class SkTextBaseIter
 
class SkCanonicalizePaint
 
SK_API friend bool operator== (const SkPaint &a, const SkPaint &b)
 operator== may give false negatives: two paints that draw equivalently may return false. More...
 
bool operator!= (const SkPaint &a, const SkPaint &b)
 

Detailed Description

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

Member Enumeration Documentation

Cap enum specifies the settings for the paint's strokecap.

This is the treatment that is applied to the beginning and end of each non-closed contour (e.g. lines).

If the cap is round or square, the caps are drawn when the contour has a zero length. Zero length contours can be created by following moveTo with a lineTo at the same point, or a moveTo followed by a close.

A dash with an on interval of zero also creates a zero length contour.

The zero length contour draws the square cap without rotation, since the no direction can be inferred.

Enumerator
kButt_Cap 

begin/end contours with no extension

kRound_Cap 

begin/end contours with a semi-circle extension

kSquare_Cap 

begin/end contours with a half square extension

Specifies the bit values that are stored in the paint's flags.

Enumerator
kAntiAlias_Flag 

mask to enable antialiasing

kDither_Flag 

mask to enable dithering. see setDither()

kFakeBoldText_Flag 

mask to enable fake-bold text

kLinearText_Flag 

mask to enable linear-text

kSubpixelText_Flag 

mask to enable subpixel text positioning

kDevKernText_Flag 

mask to enable device kerning text

kLCDRenderText_Flag 

mask to enable subpixel glyph renderering

kEmbeddedBitmapText_Flag 

mask to enable embedded bitmap strikes

kAutoHinting_Flag 

mask to force Freetype's autohinter

Specifies the level of hinting to be performed.

These names are taken from the Gnome/Cairo names for the same. They are translated into Freetype concepts the same as in cairo-ft-font.c: kNo_Hinting -> FT_LOAD_NO_HINTING kSlight_Hinting -> FT_LOAD_TARGET_LIGHT kNormal_Hinting -> <default, no option> kFull_Hinting -> <same as kNormalHinting, unless we are rendering subpixel glyphs, in which case TARGET_LCD or TARGET_LCD_V is used>

Enumerator
kNormal_Hinting 

this is the default

Join enum specifies the settings for the paint's strokejoin.

This is the treatment that is applied to corners in paths and rectangles.

Enumerator
kMiter_Join 

connect path segments with a sharp join

kRound_Join 

connect path segments with a round join

kBevel_Join 

connect path segments with a flat bevel join

Styles apply to rect, oval, path, and text.

Bitmaps are always drawn in "fill", and lines are always drawn in "stroke".

Note: strokeandfill implicitly draws the result with SkPath::kWinding_FillType, so if the original path is even-odd, the results may not appear the same as if it was drawn twice, filled and then stroked.

Enumerator
kFill_Style 

fill the geometry

kStroke_Style 

stroke the geometry

kStrokeAndFill_Style 

fill and stroke the geometry

Describes how to interpret the text parameters that are passed to paint methods like measureText() and getTextWidths().

Enumerator
kUTF8_TextEncoding 

the text parameters are UTF8

kUTF16_TextEncoding 

the text parameters are UTF16

kUTF32_TextEncoding 

the text parameters are UTF32

kGlyphID_TextEncoding 

the text parameters are glyph indices

Member Function Documentation

size_t SkPaint::breakText ( const void *  text,
size_t  length,
SkScalar  maxWidth,
SkScalar *  measuredWidth = NULL 
) const

Return the number of bytes of text that were measured.

If isVerticalText() is true, then the vertical advances are used for the measurement.

Parameters
textThe text to be measured
lengthNumber of bytes of text to measure
maxWidthMaximum width. Only the subset of text whose accumulated widths are <= maxWidth are measured.
measuredWidthOptional. If non-null, this returns the actual width of the measured text.
Returns
The number of bytes of text that were measured. Will be <= length.
bool SkPaint::canComputeFastBounds ( ) const

Returns true if the current paint settings allow for fast computation of bounds (i.e.

there is nothing complex like a patheffect that would make the bounds computation expensive.

const SkRect& SkPaint::computeFastBounds ( const SkRect orig,
SkRect storage 
) const
inline

Only call this if canComputeFastBounds() returned true.

This takes a raw rectangle (the raw bounds of a shape), and adjusts it for stylistic effects in the paint (e.g. stroking). If needed, it uses the storage rect parameter. It returns the adjusted bounds that can then be used for quickReject tests.

The returned rect will either be orig or storage, thus the caller should not rely on storage being set to the result, but should always use the retured value. It is legal for orig and storage to be the same rect.

e.g. if (paint.canComputeFastBounds()) { SkRect r, storage; path.computeBounds(&r, SkPath::kFast_BoundsType); const SkRect& fastR = paint.computeFastBounds(r, &storage); if (canvas->quickReject(fastR, ...)) { don't draw the path } }

bool SkPaint::containsText ( const void *  text,
size_t  byteLength 
) const

Return true if all of the specified text has a corresponding non-zero glyph ID.

If any of the code-points in the text are not supported in the typeface (i.e. the glyph ID would be zero), then return false.

If the text encoding for the paint is kGlyph_TextEncoding, then this returns true if all of the specified glyph IDs are non-zero.

int SkPaint::countText ( const void *  text,
size_t  byteLength 
) const
inline

Return the number of drawable units in the specified text buffer.

This looks at the current TextEncoding field of the paint. If you also want to have the text converted into glyph IDs, call textToGlyphs instead.

uint8_t SkPaint::getAlpha ( ) const
inline

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

Returns
the alpha component of the paint's color.
SkColor SkPaint::getColor ( ) const
inline

Return the paint's color.

Note that the color is a 32bit value containing alpha as well as r,g,b. This 32bit value is not premultiplied, meaning that its alpha can be any value, regardless of the values of r,g,b.

Returns
the paint's color (and alpha).
SkColorFilter* SkPaint::getColorFilter ( ) const
inline

Get the paint's colorfilter.

If there is a colorfilter, its reference count is not changed.

Returns
the paint's colorfilter (or NULL)
SkDrawLooper* SkPaint::getDrawLooper ( ) const
inline

Return the paint's SkDrawLooper (if any).

Does not affect the looper's reference count.

bool SkPaint::getFillPath ( const SkPath src,
SkPath dst,
const SkRect cullRect,
SkScalar  resScale = 1 
) const

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

The result is that drawing src with this paint will be the same as drawing dst with a default paint (at least from the geometric perspective).

Parameters
srcinput path
dstoutput path (may be the same as src)
cullRectIf not null, the dst path may be culled to this rect.
resScaleIf > 1, increase precision, else if (0 < res < 1) reduce precision in favor of speed/size.
Returns
true if the path should be filled, or false if it should be drawn with a hairline (width == 0)
SkFilterQuality SkPaint::getFilterQuality ( ) const
inline

Return the filter level.

This affects the quality (and performance) of drawing scaled images.

uint32_t SkPaint::getFlags ( ) const
inline

Return the paint's flags.

Use the Flag enum to test flag values.

Returns
the paint's flags (see enums ending in _Flag for bit masks)
SkRect SkPaint::getFontBounds ( ) const

Return a rectangle that represents the union of the bounds of all of the glyphs, but each one positioned at (0,0).

This may be conservatively large, and will not take into account any hinting, but will respect any text-scale-x or text-skew-x on this paint.

SkScalar SkPaint::getFontMetrics ( FontMetrics metrics,
SkScalar  scale = 0 
) const

Return the recommend spacing between lines (which will be fDescent - fAscent + fLeading).

If metrics is not null, return in it the font metrics for the typeface/pointsize/etc. currently set in the paint.

Parameters
metricsIf not null, returns the font metrics for the current typeface/pointsize/etc setting in this paint.
scaleIf not 0, return width as if the canvas were scaled by this value
returnthe recommended spacing between lines
SkScalar SkPaint::getFontSpacing ( ) const
inline

Return the recommend line spacing.

This will be fDescent - fAscent + fLeading

uint32_t SkPaint::getHash ( ) const

getHash() is a shallow hash, with the same limitations as operator==.

If operator== returns true for two paints, getHash() returns the same value for each.

SkMaskFilter* SkPaint::getMaskFilter ( ) const
inline

Get the paint's maskfilter object.

The maskfilter reference count is not affected.

Returns
the paint's maskfilter (or NULL)
SkPathEffect* SkPaint::getPathEffect ( ) const
inline

Get the paint's patheffect object.

The patheffect reference count is not affected.

Returns
the paint's patheffect (or NULL)
int SkPaint::getPosTextHIntercepts ( const void *  text,
size_t  length,
const SkScalar  xpos[],
SkScalar  constY,
const SkScalar  bounds[2],
SkScalar *  intervals 
) const

Return the number of intervals that intersect the intercept along the axis of the advance.

The return count is zero or a multiple of two, and is at most the number of glyphs * 2 in string. The caller may pass nullptr for intervals to determine the size of the interval array, or may conservatively pre-allocate an array with length * 2 entries. The computed intervals are cached by glyph to improve performance for multiple calls. This permits constructing an underline that skips the descenders.

Parameters
textThe text.
lengthNumber of bytes of text.
xposArray of x-positions, used to position each character.
constYThe shared Y coordinate for all of the positions.
boundsThe lower and upper line parallel to the advance.
arrayIf not null, the glyph bounds contained by the advance parallel lines.
Returns
The number of intersections, which may be zero.
int SkPaint::getPosTextIntercepts ( const void *  text,
size_t  length,
const SkPoint  pos[],
const SkScalar  bounds[2],
SkScalar *  intervals 
) const

Return the number of intervals that intersect the intercept along the axis of the advance.

The return count is zero or a multiple of two, and is at most the number of glyphs * 2 in string. The caller may pass nullptr for intervals to determine the size of the interval array, or may conservatively pre-allocate an array with length * 2 entries. The computed intervals are cached by glyph to improve performance for multiple calls. This permits constructing an underline that skips the descenders.

Parameters
textthe text
lengthnumber of bytes of text
posarray of positions, used to position each character
boundsThe lower and upper line parallel to the advance.
arrayIf not null, the glyph bounds contained by the advance parallel lines.
Returns
The number of intersections, which may be zero.
void SkPaint::getPosTextPath ( const void *  text,
size_t  length,
const SkPoint  pos[],
SkPath path 
) const

Return the path (outline) for the specified text.

Note: just like SkCanvas::drawText, this will respect the Align setting in the paint.

Parameters
textthe text
lengthnumber of bytes of text
posarray of positions, used to position each character
pathThe outline of the text.
SkRasterizer* SkPaint::getRasterizer ( ) const
inline

Get the paint's rasterizer (or NULL).

The raster controls how paths/text are turned into alpha masks.

Returns
the paint's rasterizer (or NULL)
SkShader* SkPaint::getShader ( ) const
inline

Get the paint's shader object.

The shader's reference count is not affected.

Returns
the paint's shader (or NULL)
Cap SkPaint::getStrokeCap ( ) const
inline

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

Returns
the line cap style for the paint, used whenever the paint's style is Stroke or StrokeAndFill.
Join SkPaint::getStrokeJoin ( ) const
inline

Return the paint's stroke join type.

Returns
the paint's line join style, used whenever the paint's style is Stroke or StrokeAndFill.
SkScalar SkPaint::getStrokeMiter ( ) const
inline

Return the paint's stroke miter value.

This is used to control the behavior of miter joins when the joins angle is sharp.

Returns
the paint's miter limit, used whenever the paint's style is Stroke or StrokeAndFill.
SkScalar SkPaint::getStrokeWidth ( ) const
inline

Return the width for stroking.

A value of 0 strokes in hairline mode. Hairlines always draw 1-pixel wide, regardless of the matrix.

Returns
the paint's stroke width, used whenever the paint's style is Stroke or StrokeAndFill.
Style SkPaint::getStyle ( ) const
inline

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

Returns
the paint's Style
Align SkPaint::getTextAlign ( ) const
inline

Return the paint's Align value for drawing text.

Returns
the paint's Align value for drawing text.
int SkPaint::getTextBlobIntercepts ( const SkTextBlob blob,
const SkScalar  bounds[2],
SkScalar *  intervals 
) const

Return the number of intervals that intersect the intercept along the axis of the advance.

The return count is zero or a multiple of two, and is at most the number of glyphs * 2 in text blob. The caller may pass nullptr for intervals to determine the size of the interval array. The computed intervals are cached by glyph to improve performance for multiple calls. This permits constructing an underline that skips the descenders.

Parameters
blobThe text blob.
boundsThe lower and upper line parallel to the advance.
arrayIf not null, the glyph bounds contained by the advance parallel lines.
Returns
The number of intersections, which may be zero.
int SkPaint::getTextIntercepts ( const void *  text,
size_t  length,
SkScalar  x,
SkScalar  y,
const SkScalar  bounds[2],
SkScalar *  intervals 
) const

Return the number of intervals that intersect the intercept along the axis of the advance.

The return count is zero or a multiple of two, and is at most the number of glyphs * 2 in the string. The caller may pass nullptr for intervals to determine the size of the interval array, or may conservatively pre-allocate an array with length * 2 entries. The computed intervals are cached by glyph to improve performance for multiple calls. This permits constructing an underline that skips the descenders.

Parameters
textthe text
lengthnumber of bytes of text
xThe x-coordinate of the origin of the text.
yThe y-coordinate of the origin of the text.
boundsThe lower and upper line parallel to the advance.
arrayIf not null, the found intersections.
Returns
The number of intersections, which may be zero.
void SkPaint::getTextPath ( const void *  text,
size_t  length,
SkScalar  x,
SkScalar  y,
SkPath path 
) const

Return the path (outline) for the specified text.

Note: just like SkCanvas::drawText, this will respect the Align setting in the paint.

Parameters
textthe text
lengthnumber of bytes of text
xThe x-coordinate of the origin of the text.
yThe y-coordinate of the origin of the text.
pathThe outline of the text.
SkScalar SkPaint::getTextScaleX ( ) const
inline

Return the paint's horizontal scale factor for text.

The default value is 1.0.

Returns
the paint's scale factor in X for drawing/measuring text
SkScalar SkPaint::getTextSize ( ) const
inline

Return the paint's text size.

Returns
the paint's text size.
SkScalar SkPaint::getTextSkewX ( ) const
inline

Return the paint's horizontal skew factor for text.

The default value is 0.

Returns
the paint's skew factor in X for drawing text.
int SkPaint::getTextWidths ( const void *  text,
size_t  byteLength,
SkScalar  widths[],
SkRect  bounds[] = NULL 
) const

Return the advances for the text.

These will be vertical advances if isVerticalText() returns true.

Parameters
textthe text
byteLengthnumber of bytes to of text
widthsIf not null, returns the array of advances for the glyphs. If not NULL, must be at least a large as the number of unichars in the specified text.
boundsIf not null, returns the bounds for each of character, relative to (0, 0)
Returns
the number of unichars in the specified text.
SkTypeface* SkPaint::getTypeface ( ) const
inline

Get the paint's typeface object.

The typeface object identifies which font to use when drawing or measuring text. The typeface reference count is not affected.

Returns
the paint's typeface (or NULL)
void SkPaint::glyphsToUnichars ( const SkGlyphID  glyphs[],
int  count,
SkUnichar  text[] 
) const

Convert the glyph array into Unichars.

Unconvertable glyphs are mapped to zero. Note: this does not look at the text-encoding setting in the paint, only at the typeface.

bool SkPaint::isAntiAlias ( ) const
inline

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

Returns
true if the antialias bit is set in the paint's flags.
bool SkPaint::isDevKernText ( ) const
inline

Helper for getFlags(), returns true if kDevKernText_Flag bit is set.

Returns
true if the kernText bit is set in the paint's flags.
bool SkPaint::isDither ( ) const
inline

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

Returns
true if the dithering bit is set in the paint's flags.
bool SkPaint::isFakeBoldText ( ) const
inline

Helper for getFlags(), returns true if kFakeBoldText_Flag bit is set.

Returns
true if the kFakeBoldText_Flag bit is set in the paint's flags.
bool SkPaint::isLinearText ( ) const
inline

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

Returns
true if the lineartext bit is set in the paint's flags
bool SkPaint::isSubpixelText ( ) const
inline

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

Returns
true if the lineartext bit is set in the paint's flags
SkScalar SkPaint::measureText ( const void *  text,
size_t  length,
SkRect bounds 
) const

Return the width of the text.

This will return the vertical measure if isVerticalText() is true, in which case the returned value should be treated has a height instead of a width.

Parameters
textThe text to be measured
lengthNumber of bytes of text to measure
boundsIf not NULL, returns the bounds of the text, relative to (0, 0).
Returns
The advance width of the text
SkScalar SkPaint::measureText ( const void *  text,
size_t  length 
) const
inline

Return the width of the text.

This will return the vertical measure if isVerticalText() is true, in which case the returned value should be treated has a height instead of a width.

Parameters
textAddress of the text
lengthNumber of bytes of text to measure
Returns
The advance width of the text
void SkPaint::setAlpha ( U8CPU  a)

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

Parameters
aset the alpha component (0..255) of the paint's color.
void SkPaint::setAntiAlias ( bool  aa)

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

Parameters
aatrue to enable antialiasing, false to disable it
void SkPaint::setARGB ( U8CPU  a,
U8CPU  r,
U8CPU  g,
U8CPU  b 
)

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

Parameters
aThe new alpha component (0..255) of the paint's color.
rThe new red component (0..255) of the paint's color.
gThe new green component (0..255) of the paint's color.
bThe new blue component (0..255) of the paint's color.
void SkPaint::setAutohinted ( bool  useAutohinter)

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

Parameters
useAutohintertrue to set the kEmbeddedBitmapText bit in the paint's flags, false to clear it.
void SkPaint::setColor ( SkColor  color)

Set the paint's color.

Note that the color is a 32bit value containing alpha as well as r,g,b. This 32bit value is not premultiplied, meaning that its alpha can be any value, regardless of the values of r,g,b.

Parameters
colorThe new color (including alpha) to set in the paint.
void SkPaint::setColorFilter ( sk_sp< SkColorFilter colorFilter)

Set or clear the paint's colorfilter.

If the paint already has a filter, its reference count is decremented. If filter is not NULL, its reference count is incremented.

Parameters
filterMay be NULL. The filter to be installed in the paint
void SkPaint::setDevKernText ( bool  devKernText)

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

Parameters
kernTexttrue to set the kKernText_Flag bit in the paint's flags, false to clear it.
void SkPaint::setDither ( bool  dither)

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

Parameters
dithertrue to enable dithering, false to disable it

Note: gradients ignore this setting and always dither.

void SkPaint::setDrawLooper ( sk_sp< SkDrawLooper drawLooper)

Set or clear the looper object.

Pass NULL to clear any previous looper. If a previous looper exists in the paint, its reference count is decremented. If looper is not NULL, its reference count is incremented.

Parameters
looperMay be NULL. The new looper to be installed in the paint.
void SkPaint::setEmbeddedBitmapText ( bool  useEmbeddedBitmapText)

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

Parameters
useEmbeddedBitmapTexttrue to set the kEmbeddedBitmapText bit in the paint's flags, false to clear it.
void SkPaint::setFakeBoldText ( bool  fakeBoldText)

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

Parameters
fakeBoldTexttrue to set the kFakeBoldText_Flag bit in the paint's flags, false to clear it.
void SkPaint::setFilterQuality ( SkFilterQuality  quality)

Set the filter quality.

This affects the quality (and performance) of drawing scaled images.

void SkPaint::setFlags ( uint32_t  flags)

Set the paint's flags.

Use the Flag enum to specific flag values.

Parameters
flagsThe new flag bits for the paint (see Flags enum)
void SkPaint::setLCDRenderText ( bool  lcdText)

Helper for setFlags(), setting or clearing the kLCDRenderText_Flag.

Note: antialiasing must also be on for lcd rendering

Parameters
lcdTexttrue to set the LCDRenderText bit in the paint's flags, false to clear it.
void SkPaint::setLinearText ( bool  linearText)

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

Parameters
linearTexttrue to set the linearText bit in the paint's flags, false to clear it.
void SkPaint::setMaskFilter ( sk_sp< SkMaskFilter maskFilter)

Set or clear the maskfilter object.

Pass NULL to clear any previous maskfilter. As a convenience, the parameter passed is also returned. If a previous maskfilter exists, its reference count is decremented. If maskfilter is not NULL, its reference count is incremented.

Parameters
maskfilterMay be NULL. The new maskfilter to be installed in the paint
Returns
maskfilter
void SkPaint::setPathEffect ( sk_sp< SkPathEffect pathEffect)

Set or clear the patheffect object.

Pass NULL to clear any previous patheffect. As a convenience, the parameter passed is also returned. If a previous patheffect exists, its reference count is decremented. If patheffect is not NULL, its reference count is incremented.

Parameters
effectMay be NULL. The new patheffect to be installed in the paint
Returns
effect
void SkPaint::setRasterizer ( sk_sp< SkRasterizer rasterizer)

Set or clear the rasterizer object.

Pass NULL to clear any previous rasterizer. As a convenience, the parameter passed is also returned. If a previous rasterizer exists in the paint, its reference count is decremented. If rasterizer is not NULL, its reference count is incremented.

Parameters
rasterizerMay be NULL. The new rasterizer to be installed in the paint.
Returns
rasterizer
void SkPaint::setShader ( sk_sp< SkShader shader)

Set or clear the shader object.

Shaders specify the source color(s) for what is being drawn. If a paint has no shader, then the paint's color is used. If the paint has a shader, then the shader's color(s) are use instead, but they are modulated by the paint's alpha. This makes it easy to create a shader once (e.g. bitmap tiling or gradient) and then change its transparency w/o having to modify the original shader... only the paint's alpha needs to be modified.

There is an exception to this only-respect-paint's-alpha rule: If the shader only generates alpha (e.g. SkShader::CreateBitmapShader(bitmap, ...) where bitmap's colortype is kAlpha_8) then the shader will use the paint's entire color to "colorize" its output (modulating the bitmap's alpha with the paint's color+alpha).

Pass NULL to clear any previous shader. As a convenience, the parameter passed is also returned. If a previous shader exists, its reference count is decremented. If shader is not NULL, its reference count is incremented.

Parameters
shaderMay be NULL. The shader to be installed in the paint
void SkPaint::setStrokeCap ( Cap  cap)

Set the paint's stroke cap type.

Parameters
capset the paint's line cap style, used whenever the paint's style is Stroke or StrokeAndFill.
void SkPaint::setStrokeJoin ( Join  join)

Set the paint's stroke join type.

Parameters
joinset the paint's line join style, used whenever the paint's style is Stroke or StrokeAndFill.
void SkPaint::setStrokeMiter ( SkScalar  miter)

Set the paint's stroke miter value.

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

Parameters
miterset the miter limit on the paint, used whenever the paint's style is Stroke or StrokeAndFill.
void SkPaint::setStrokeWidth ( SkScalar  width)

Set the width for stroking.

Pass 0 to stroke in hairline mode. Hairlines always draw 1-pixel wide, regardless of the matrix.

Parameters
widthset the paint's stroke width, used whenever the paint's style is Stroke or StrokeAndFill.
void SkPaint::setStyle ( Style  style)

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

Parameters
styleThe new style to set in the paint
void SkPaint::setSubpixelText ( bool  subpixelText)

Helper for setFlags(), setting or clearing the kSubpixelText_Flag.

Parameters
subpixelTexttrue to set the subpixelText bit in the paint's flags, false to clear it.
void SkPaint::setTextAlign ( Align  align)

Set the paint's text alignment.

Parameters
alignset the paint's Align value for drawing text.
void SkPaint::setTextScaleX ( SkScalar  scaleX)

Set the paint's horizontal scale factor for text.

The default value is 1.0. Values > 1.0 will stretch the text wider. Values < 1.0 will stretch the text narrower.

Parameters
scaleXset the paint's scale factor in X for drawing/measuring text.
void SkPaint::setTextSize ( SkScalar  textSize)

Set the paint's text size.

This value must be > 0

Parameters
textSizeset the paint's text size.
void SkPaint::setTextSkewX ( SkScalar  skewX)

Set the paint's horizontal skew factor for text.

The default value is 0. For approximating oblique text, use values around -0.25.

Parameters
skewXset the paint's skew factor in X for drawing text.
void SkPaint::setTypeface ( sk_sp< SkTypeface typeface)

Set or clear the typeface object.

Pass NULL to clear any previous typeface. As a convenience, the parameter passed is also returned. If a previous typeface exists, its reference count is decremented. If typeface is not NULL, its reference count is incremented.

Parameters
typefaceMay be NULL. The new typeface to be installed in the paint
Returns
typeface
void SkPaint::setVerticalText ( bool  verticalText)

Helper for setting or clearing the kVerticalText_Flag bit in setFlags(...).

If this bit is set, then advances are treated as Y values rather than X values, and drawText will places its glyphs vertically rather than horizontally.

int SkPaint::textToGlyphs ( const void *  text,
size_t  byteLength,
SkGlyphID  glyphs[] 
) const

Convert the specified text into glyph IDs, returning the number of glyphs ID written.

If glyphs is NULL, it is ignore and only the count is returned.

Friends And Related Function Documentation

SK_API friend bool operator== ( const SkPaint a,
const SkPaint b 
)
friend

operator== may give false negatives: two paints that draw equivalently may return false.

It will never give false positives: two paints that are not equivalent always return false.


The documentation for this class was generated from the following file: