8 #ifndef SkPaint_DEFINED
9 #define SkPaint_DEFINED
12 #include "SkFilterQuality.h"
14 #include "SkXfermode.h"
16 class SkAutoDescriptor;
17 class SkAutoGlyphCache;
33 struct SkScalerContextEffects;
39 #define kBicubicFilterBitmap_Flag kHighQualityFilterBitmap_Flag
68 uint32_t getHash()
const;
71 void unflatten(SkReadBuffer&);
94 Hinting getHinting()
const {
95 return static_cast<Hinting
>(fBitfields.fHinting);
98 void setHinting(Hinting hintingLevel);
103 kAntiAlias_Flag = 0x01,
105 kUnderlineText_Flag = 0x08,
106 kStrikeThruText_Flag = 0x10,
107 kFakeBoldText_Flag = 0x20,
108 kLinearText_Flag = 0x40,
109 kSubpixelText_Flag = 0x80,
110 kDevKernText_Flag = 0x100,
111 kLCDRenderText_Flag = 0x200,
112 kEmbeddedBitmapText_Flag = 0x400,
113 kAutoHinting_Flag = 0x800,
114 kVerticalText_Flag = 0x1000,
115 kGenA8FromLCD_Flag = 0x2000,
125 uint32_t
getFlags()
const {
return fBitfields.fFlags; }
130 void setFlags(uint32_t flags);
136 return SkToBool(this->getFlags() & kAntiAlias_Flag);
142 void setAntiAlias(
bool aa);
148 return SkToBool(this->getFlags() & kDither_Flag);
154 void setDither(
bool dither);
160 return SkToBool(this->getFlags() & kLinearText_Flag);
167 void setLinearText(
bool linearText);
173 return SkToBool(this->getFlags() & kSubpixelText_Flag);
181 void setSubpixelText(
bool subpixelText);
183 bool isLCDRenderText()
const {
184 return SkToBool(this->getFlags() & kLCDRenderText_Flag);
193 void setLCDRenderText(
bool lcdText);
195 bool isEmbeddedBitmapText()
const {
196 return SkToBool(this->getFlags() & kEmbeddedBitmapText_Flag);
203 void setEmbeddedBitmapText(
bool useEmbeddedBitmapText);
205 bool isAutohinted()
const {
206 return SkToBool(this->getFlags() & kAutoHinting_Flag);
214 void setAutohinted(
bool useAutohinter);
216 bool isVerticalText()
const {
217 return SkToBool(this->getFlags() & kVerticalText_Flag);
228 void setVerticalText(
bool);
234 return SkToBool(this->getFlags() & kUnderlineText_Flag);
241 void setUnderlineText(
bool underlineText);
247 return SkToBool(this->getFlags() & kStrikeThruText_Flag);
254 void setStrikeThruText(
bool strikeThruText);
260 return SkToBool(this->getFlags() & kFakeBoldText_Flag);
267 void setFakeBoldText(
bool fakeBoldText);
273 return SkToBool(this->getFlags() & kDevKernText_Flag);
280 void setDevKernText(
bool devKernText);
287 return (SkFilterQuality)fBitfields.fFilterQuality;
294 void setFilterQuality(SkFilterQuality quality);
311 kStyleCount = kStrokeAndFill_Style + 1
326 void setStyle(Style style);
352 void setAlpha(
U8CPU a);
378 void setStrokeWidth(SkScalar width);
393 void setStrokeMiter(SkScalar miter);
413 kLast_Cap = kSquare_Cap,
414 kDefault_Cap = kButt_Cap
416 static constexpr
int kCapCount = kLast_Cap + 1;
426 kLast_Join = kBevel_Join,
427 kDefault_Join = kMiter_Join
429 static constexpr
int kJoinCount = kLast_Join + 1;
442 void setStrokeCap(Cap cap);
454 void setStrokeJoin(Join join);
471 SkScalar resScale = 1)
const;
473 bool getFillPath(
const SkPath& src,
SkPath* dst)
const {
474 return this->getFillPath(src, dst, NULL, 1);
506 #ifdef SK_SUPPORT_LEGACY_CREATESHADER_PTR
523 #ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR
546 #ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR
574 #ifdef SK_SUPPORT_LEGACY_PATHEFFECT_PTR
595 #ifdef SK_SUPPORT_LEGACY_MASKFILTER_PTR
621 #ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
643 #ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR
648 SkImageFilter* getImageFilter()
const {
return fImageFilter.get(); }
669 #ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR
691 void setTextAlign(Align align);
701 void setTextSize(SkScalar textSize);
715 void setTextScaleX(SkScalar scaleX);
727 void setTextSkewX(SkScalar skewX);
736 kGlyphID_TextEncoding
739 TextEncoding getTextEncoding()
const {
740 return (TextEncoding)fBitfields.fTextEncoding;
743 void setTextEncoding(TextEncoding encoding);
750 kUnderlineThinknessIsValid_Flag = 1 << 0,
751 kUnderlinePositionIsValid_Flag = 1 << 1,
781 if (
SkToBool(fFlags & kUnderlineThinknessIsValid_Flag)) {
782 *thickness = fUnderlineThickness;
793 if (
SkToBool(fFlags & kUnderlinePositionIsValid_Flag)) {
794 *position = fUnderlinePosition;
813 SkScalar getFontMetrics(FontMetrics* metrics, SkScalar scale = 0)
const;
824 int textToGlyphs(
const void* text,
size_t byteLength,
834 bool containsText(
const void* text,
size_t byteLength)
const;
847 int countText(
const void* text,
size_t byteLength)
const {
848 return this->textToGlyphs(text, byteLength, NULL);
861 SkScalar measureText(
const void* text,
size_t length,
SkRect* bounds)
const;
872 return this->measureText(text, length, NULL);
888 size_t breakText(
const void* text,
size_t length, SkScalar maxWidth,
889 SkScalar* measuredWidth = NULL)
const;
903 int getTextWidths(
const void* text,
size_t byteLength, SkScalar widths[],
904 SkRect bounds[] = NULL)
const;
916 void getTextPath(
const void* text,
size_t length, SkScalar x, SkScalar y,
928 void getPosTextPath(
const void* text,
size_t length,
947 int getTextIntercepts(
const void* text,
size_t length, SkScalar x, SkScalar y,
948 const SkScalar bounds[2], SkScalar* intervals)
const;
965 int getPosTextIntercepts(
const void* text,
size_t length,
const SkPoint pos[],
966 const SkScalar bounds[2], SkScalar* intervals)
const;
984 int getPosTextHIntercepts(
const void* text,
size_t length,
const SkScalar xpos[],
985 SkScalar constY,
const SkScalar bounds[2], SkScalar* intervals)
const;
999 int getTextBlobIntercepts(
const SkTextBlob* blob,
const SkScalar bounds[2],
1000 SkScalar* intervals)
const;
1008 SkRect getFontBounds()
const;
1012 bool nothingToDraw()
const;
1021 bool canComputeFastBounds()
const;
1047 if (kFill_Style == style) {
1048 uintptr_t effects =
reinterpret_cast<uintptr_t
>(this->getLooper());
1049 effects |=
reinterpret_cast<uintptr_t
>(this->getMaskFilter());
1050 effects |=
reinterpret_cast<uintptr_t
>(this->getPathEffect());
1051 effects |=
reinterpret_cast<uintptr_t
>(this->getImageFilter());
1057 return this->doComputeFastBounds(orig, storage, style);
1060 const SkRect& computeFastStrokeBounds(
const SkRect& orig,
1062 return this->doComputeFastBounds(orig, storage, kStroke_Style);
1074 SkScalar scaleX, SkScalar skewX) {
1075 matrix->
setScale(size * scaleX, size);
1083 return SetTextMatrix(matrix, fTextSize, fTextScaleX, fTextSkewX);
1086 typedef const SkGlyph& (*GlyphCacheProc)(SkGlyphCache*,
const char**);
1088 SK_TO_STRING_NONVIRT()
1102 SkScalar fTextScaleX;
1103 SkScalar fTextSkewX;
1106 SkScalar fMiterLimit;
1110 unsigned fFlags : 16;
1111 unsigned fTextAlign : 2;
1112 unsigned fCapType : 2;
1113 unsigned fJoinType : 2;
1114 unsigned fStyle : 2;
1115 unsigned fTextEncoding : 2;
1116 unsigned fHinting : 2;
1117 unsigned fFilterQuality : 2;
1120 uint32_t fBitfieldsUInt;
1123 static GlyphCacheProc GetGlyphCacheProc(TextEncoding encoding,
1125 bool needFullMetrics);
1127 SkScalar measure_text(SkGlyphCache*,
const char* text,
size_t length,
1128 int* count,
SkRect* bounds)
const;
1130 enum ScalerContextFlags : uint32_t {
1131 kNone_ScalerContextFlags = 0,
1133 kFakeGamma_ScalerContextFlag = 1 << 0,
1134 kBoostContrast_ScalerContextFlag = 1 << 1,
1136 kFakeGammaAndBoostContrast_ScalerContextFlags =
1137 kFakeGamma_ScalerContextFlag | kBoostContrast_ScalerContextFlag,
1144 void getScalerContextDescriptor(SkScalerContextEffects*, SkAutoDescriptor*,
1146 uint32_t scalerContextFlags,
const SkMatrix*)
const;
1148 SkGlyphCache* detachCache(
const SkSurfaceProps* surfaceProps, uint32_t scalerContextFlags,
1151 void descriptorProc(
const SkSurfaceProps* surfaceProps, uint32_t scalerContextFlags,
1153 void (*proc)(
SkTypeface*,
const SkScalerContextEffects&,
1154 const SkDescriptor*,
void*),
1155 void* context)
const;
1162 SkColor computeLuminanceColor()
const;
1179 kCanonicalTextSizeForPaths = 64,
1186 kMaxSizeForGlyphCache = 256,
1194 SkScalar setupForAsPaths();
1196 static SkScalar MaxCacheSize2() {
1197 static const SkScalar kMaxSize = SkIntToScalar(kMaxSizeForGlyphCache);
1198 static const SkScalar kMag2Max = kMaxSize * kMaxSize;
1202 friend class SkAutoGlyphCache;
1203 friend class SkAutoGlyphCacheNoGamma;
1206 friend class SkPDFDevice;
1207 friend class GrAtlasTextBlob;
1208 friend class GrAtlasTextContext;
1209 friend class GrStencilAndCoverTextContext;
1210 friend class GrPathRendering;
1211 friend class GrTextUtils;
1212 friend class GrGLPathRendering;
1213 friend class SkScalerContext;
1214 friend class SkTextBaseIter;
1215 friend class SkCanonicalizePaint;
SkScalar fTop
The greatest distance above the baseline for any glyph (will be <= 0)
Definition: SkPaint.h:755
bool isDevKernText() const
Helper for getFlags(), returns true if kDevKernText_Flag bit is set.
Definition: SkPaint.h:272
bool hasUnderlineThickness(SkScalar *thickness) const
If the fontmetrics has a valid underlinethickness, return true, and set the thickness param to that v...
Definition: SkPaint.h:780
A Canvas encapsulates all of the state about drawing into a device (bitmap).
Definition: SkCanvas.h:58
begin/end contours with a semi-circle extension
Definition: SkPaint.h:410
connect path segments with a round join
Definition: SkPaint.h:423
SkPathEffect * getPathEffect() const
Get the paint's patheffect object.
Definition: SkPaint.h:561
The SkPath class encapsulates compound (multiple contour) geometric paths consisting of straight line...
Definition: SkPath.h:27
SkTextBlob combines multiple text runs into an immutable, ref-counted structure.
Definition: SkTextBlob.h:22
SkScalar fDescent
The recommended distance below the baseline (will be >= 0)
Definition: SkPaint.h:757
Mode
List of predefined xfermodes.
Definition: SkXfermode.h:71
Shaders specify the source color(s) for what is being drawn.
Definition: SkShader.h:38
SkPathEffect is the base class for objects in the SkPaint that affect the geometry of a drawing primi...
Definition: SkPathEffect.h:29
Style getStyle() const
Return the paint's style, used for controlling how primitives' geometries are interpreted (except for...
Definition: SkPaint.h:319
SkScalar getStrokeMiter() const
Return the paint's stroke miter value.
Definition: SkPaint.h:385
ColorFilters are optional objects in the drawing pipeline.
Definition: SkColorFilter.h:29
uint16_t SkGlyphID
16 bit unsigned integer to hold a glyph index
Definition: SkTypes.h:359
bool hasUnderlinePosition(SkScalar *position) const
If the fontmetrics has a valid underlineposition, return true, and set the thickness param to that va...
Definition: SkPaint.h:792
void setScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Set the matrix to scale by sx and sy, with a pivot point at (px, py).
bool isFakeBoldText() const
Helper for getFlags(), returns true if kFakeBoldText_Flag bit is set.
Definition: SkPaint.h:259
SkScalar getStrokeWidth() const
Return the width for stroking.
Definition: SkPaint.h:370
the text parameters are UTF8
Definition: SkPaint.h:733
SkScalar fMaxCharWidth
the max character width (>= 0)
Definition: SkPaint.h:761
Describes properties and constraints of a given SkSurface.
Definition: SkSurfaceProps.h:51
Definition: SkPoint.h:156
SkMaskFilter * getMaskFilter() const
Get the paint's maskfilter object.
Definition: SkPaint.h:583
Cap
Cap enum specifies the settings for the paint's strokecap.
Definition: SkPaint.h:408
the text parameters are UTF16
Definition: SkPaint.h:734
TextEncoding
Describes how to interpret the text parameters that are passed to paint methods like measureText() an...
Definition: SkPaint.h:732
connect path segments with a flat bevel join
Definition: SkPaint.h:424
Align getTextAlign() const
Return the paint's Align value for drawing text.
Definition: SkPaint.h:686
The SkMatrix class holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:26
Hinting
Specifies the level of hinting to be performed.
Definition: SkPaint.h:87
SkScalar measureText(const void *text, size_t length) const
Return the width of the text.
Definition: SkPaint.h:871
The SkPaint class holds the style and color information about how to draw geometries, text and bitmaps.
Definition: SkPaint.h:46
SkScalar fXMin
The minimum bounding box x value for all glyphs.
Definition: SkPaint.h:762
stroke the geometry
Definition: SkPaint.h:307
SkDrawLooper * getLooper() const
Return the paint's SkDrawLooper (if any).
Definition: SkPaint.h:656
uint8_t getAlpha() const
Helper to getColor() that just returns the color's alpha value.
Definition: SkPaint.h:346
bool isAntiAlias() const
Helper for getFlags(), returning true if kAntiAlias_Flag bit is set.
Definition: SkPaint.h:135
fill the geometry
Definition: SkPaint.h:306
Definition: SkRasterizer.h:21
SkXfermode is the base class for objects that are called to implement custom "transfer-modes" in the ...
Definition: SkXfermode.h:34
Definition: SkPaint.h:745
SkData holds an immutable data buffer.
Definition: SkData.h:22
Join
Join enum specifies the settings for the paint's strokejoin.
Definition: SkPaint.h:421
#define SkToBool(cond)
Returns 0 or 1 based on the condition.
Definition: SkTypes.h:287
Cap getStrokeCap() const
Return the paint's stroke cap type, controlling how the start and end of stroked lines and paths are ...
Definition: SkPaint.h:436
SkScalar getTextScaleX() const
Return the paint's horizontal scale factor for text.
Definition: SkPaint.h:707
The SkTypeface class specifies the typeface and intrinsic style of a font.
Definition: SkTypeface.h:42
Base class for image filters.
Definition: SkImageFilter.h:35
SkScalar fLeading
The recommended distance to add between lines of text (will be >= 0)
Definition: SkPaint.h:759
connect path segments with a sharp join
Definition: SkPaint.h:422
uint32_t getFlags() const
Return the paint's flags.
Definition: SkPaint.h:125
the text parameters are UTF32
Definition: SkPaint.h:735
SkScalar getFontSpacing() const
Return the recommend line spacing.
Definition: SkPaint.h:818
SkMaskFilter is the base class for object that perform transformations on an alpha-channel mask befor...
Definition: SkMaskFilter.h:44
void postSkew(SkScalar kx, SkScalar ky, SkScalar px, SkScalar py)
Postconcats the matrix with the specified skew.
bool isSubpixelText() const
Helper for getFlags(), returning true if kSubpixelText_Flag bit is set.
Definition: SkPaint.h:172
Style
Styles apply to rect, oval, path, and text.
Definition: SkPaint.h:305
int32_t SkUnichar
32 bit integer to hold a unicode value
Definition: SkTypes.h:355
SkRasterizer * getRasterizer() const
Get the paint's rasterizer (or NULL).
Definition: SkPaint.h:630
SkTypeface * getTypeface() const
Get the paint's typeface object.
Definition: SkPaint.h:608
uint32_t SkColor
32 bit ARGB color value, not premultiplied.
Definition: SkColor.h:28
SkScalar fAvgCharWidth
the average character width (>= 0)
Definition: SkPaint.h:760
static SkMatrix * SetTextMatrix(SkMatrix *matrix, SkScalar size, SkScalar scaleX, SkScalar skewX)
Return a matrix that applies the paint's text values: size, scale, skew.
Definition: SkPaint.h:1073
SkScalar fXMax
The maximum bounding box x value for all glyphs.
Definition: SkPaint.h:763
SkScalar fUnderlinePosition
Underline Position - position of the top of the Underline stroke relative to the baseline, this can have following values.
Definition: SkPaint.h:774
Subclasses of SkDrawLooper can be attached to a SkPaint.
Definition: SkDrawLooper.h:31
Definition: SkWriteBuffer.h:26
const SkRect & computeFastBounds(const SkRect &orig, SkRect *storage) const
Only call this if canComputeFastBounds() returned true.
Definition: SkPaint.h:1044
SkScalar getTextSize() const
Return the paint's text size.
Definition: SkPaint.h:696
Flags
Specifies the bit values that are stored in the paint's flags.
Definition: SkPaint.h:102
#define SkColorGetA(color)
return the alpha byte from a SkColor value
Definition: SkColor.h:62
SkFilterQuality getFilterQuality() const
Return the filter level.
Definition: SkPaint.h:286
fill and stroke the geometry
Definition: SkPaint.h:308
SkXfermode * getXfermode() const
Get the paint's xfermode object.
Definition: SkPaint.h:533
SkScalar fAscent
The recommended distance above the baseline (will be <= 0)
Definition: SkPaint.h:756
begin/end contours with no extension
Definition: SkPaint.h:409
SkShader * getShader() const
Get the paint's shader object.
Definition: SkPaint.h:482
bool isUnderlineText() const
Helper for getFlags(), returning true if kUnderlineText_Flag bit is set.
Definition: SkPaint.h:233
SkScalar getTextSkewX() const
Return the paint's horizontal skew factor for text.
Definition: SkPaint.h:721
SkScalar fCapHeight
The cap height (> 0), or 0 if cannot be determined.
Definition: SkPaint.h:765
uint32_t fFlags
Bit field to identify which values are unknown.
Definition: SkPaint.h:754
bool isLinearText() const
Helper for getFlags(), returning true if kLinearText_Flag bit is set.
Definition: SkPaint.h:159
int countText(const void *text, size_t byteLength) const
Return the number of drawable units in the specified text buffer.
Definition: SkPaint.h:847
unsigned U8CPU
Fast type for unsigned 8 bits.
Definition: SkTypes.h:251
begin/end contours with a half square extension
Definition: SkPaint.h:411
Join getStrokeJoin() const
Return the paint's stroke join type.
Definition: SkPaint.h:448
bool isDither() const
Helper for getFlags(), returning true if kDither_Flag bit is set.
Definition: SkPaint.h:147
SkColorFilter * getColorFilter() const
Get the paint's colorfilter.
Definition: SkPaint.h:514
SkScalar fBottom
The greatest distance below the baseline for any glyph (will be >= 0)
Definition: SkPaint.h:758
FontMetricsFlags
Flags which indicate the confidence level of various metrics.
Definition: SkPaint.h:749
SkScalar fXHeight
The height of an 'x' in px, or 0 if no 'x' in face.
Definition: SkPaint.h:764
SkColor getColor() const
Return the paint's color.
Definition: SkPaint.h:334
Types and macros for colors.
SkScalar fUnderlineThickness
underline thickness, or 0 if cannot be determined
Definition: SkPaint.h:766
bool isStrikeThruText() const
Helper for getFlags(), returns true if kStrikeThruText_Flag bit is set.
Definition: SkPaint.h:246