blob: e2937c9ea50e0c8d18f1d6d5632f11a04dfabfd4 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00006 */
7
8#ifndef SkPaint_DEFINED
9#define SkPaint_DEFINED
10
reed374772b2016-10-05 17:33:02 -070011#include "SkBlendMode.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000012#include "SkColor.h"
reedf803da12015-01-23 05:58:07 -080013#include "SkFilterQuality.h"
reed@google.comed43dff2013-06-04 16:56:27 +000014#include "SkMatrix.h"
Mike Reed71fecc32016-11-18 17:19:54 -050015#include "SkRefCnt.h"
reed@android.coma0f5d152009-06-22 17:38:10 +000016
joshualitt2b6acb42015-04-01 11:30:27 -070017class SkAutoDescriptor;
reed@android.com8a1c16f2008-12-17 15:59:43 +000018class SkAutoGlyphCache;
19class SkColorFilter;
joshualittfd450792015-03-13 08:38:43 -070020class SkData;
reed@android.com8a1c16f2008-12-17 15:59:43 +000021class SkDescriptor;
senorblanco0abdf762015-08-20 11:10:41 -070022class SkDrawLooper;
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +000023class SkReadBuffer;
24class SkWriteBuffer;
herbb69d0e02015-02-25 06:47:06 -080025class SkGlyph;
reed@android.com8a1c16f2008-12-17 15:59:43 +000026struct SkRect;
27class SkGlyphCache;
reed@google.com15356a62011-11-03 19:29:08 +000028class SkImageFilter;
reed@android.com8a1c16f2008-12-17 15:59:43 +000029class SkMaskFilter;
reed@android.com8a1c16f2008-12-17 15:59:43 +000030class SkPath;
31class SkPathEffect;
djsollen@google.comc73dd5c2012-08-07 15:54:32 +000032struct SkPoint;
reed@android.com8a1c16f2008-12-17 15:59:43 +000033class SkRasterizer;
reeda9322c22016-04-12 06:47:05 -070034struct SkScalerContextEffects;
reed@android.com8a1c16f2008-12-17 15:59:43 +000035class SkShader;
robertphillipsfcf78292015-06-19 11:49:52 -070036class SkSurfaceProps;
fmalitaeae6a912016-07-28 09:47:24 -070037class SkTextBlob;
reed@android.com8a1c16f2008-12-17 15:59:43 +000038class SkTypeface;
reed@android.com8a1c16f2008-12-17 15:59:43 +000039
reed@android.com8a1c16f2008-12-17 15:59:43 +000040/** \class SkPaint
Cary Clark50fa3ff2017-07-26 10:15:23 -040041 SkPaint controls options applied when drawing and measuring. SkPaint collects all
42 options outside of the SkCanvas clip and SkCanvas matrix.
reed@android.com8a1c16f2008-12-17 15:59:43 +000043
Cary Clark50fa3ff2017-07-26 10:15:23 -040044 Various options apply to text, strokes and fills, and images.
45
46 Some options may not be implemented on all platforms; in these cases, setting
47 the option has no effect. Some options are conveniences that duplicate SkCanvas
48 functionality; for instance, text size is identical to matrix scale.
49
50 SkPaint options are rarely exclusive; each option modifies a stage of the drawing
Cary Clark23890a92017-07-27 16:30:51 -040051 pipeline and multiple pipeline stages may be affected by a single SkPaint.
Cary Clark50fa3ff2017-07-26 10:15:23 -040052
Cary Clark23890a92017-07-27 16:30:51 -040053 SkPaint collects effects and filters that describe single-pass and multiple-pass
Cary Clark50fa3ff2017-07-26 10:15:23 -040054 algorithms that alter the drawing geometry, color, and transparency. For instance,
55 SkPaint does not directly implement dashing or blur, but contains the objects that do so.
56
57 The objects contained by SkPaint are opaque, and cannot be edited outside of the SkPaint
58 to affect it. The implementation is free to defer computations associated with the
59 SkPaint, or ignore them altogether. For instance, some GPU implementations draw all
60 SkPath geometries with anti-aliasing, regardless of SkPaint::kAntiAlias_Flag setting.
61
62 SkPaint describes a single color, a single font, a single image quality, and so on.
63 Multiple colors are drawn either by using multiple paints or with objects like
64 SkShader attached to SkPaint.
reed@android.com8a1c16f2008-12-17 15:59:43 +000065*/
ctguil@chromium.org7ffb1b22011-03-15 21:27:08 +000066class SK_API SkPaint {
reed@android.com8a1c16f2008-12-17 15:59:43 +000067public:
Cary Clark50fa3ff2017-07-26 10:15:23 -040068
69 /** Constructs SkPaint with default values.
70
71 @return default initialized SkPaint
72 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000073 SkPaint();
Cary Clark50fa3ff2017-07-26 10:15:23 -040074
75 /** Makes a shallow copy of SkPaint. SkTypeface, SkPathEffect, SkShader,
76 SkMaskFilter, SkColorFilter, SkRasterizer, SkDrawLooper, and SkImageFilter are shared
77 between the original paint and the copy. These objects' SkRefCnt are increased.
78
79 The referenced objects SkPathEffect, SkShader, SkMaskFilter, SkColorFilter, SkRasterizer,
80 SkDrawLooper, and SkImageFilter cannot be modified after they are created.
81 This prevents objects with SkRefCnt from being modified once SkPaint refers to them.
82
83 @param paint original to copy
84 @return shallow copy of paint
85 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000086 SkPaint(const SkPaint& paint);
Cary Clark50fa3ff2017-07-26 10:15:23 -040087
88 /** Implements a move constructor to avoid incrementing the reference counts
89 of objects referenced by the paint.
90
91 After the call, paint is undefined, and can be safely destructed.
92
93 @param paint original to move
94 @return content of paint
95 */
bungemanccce0e02016-02-07 14:37:23 -080096 SkPaint(SkPaint&& paint);
Cary Clark50fa3ff2017-07-26 10:15:23 -040097
98 /** Decreases SkPaint SkRefCnt of owned objects: SkTypeface, SkPathEffect, SkShader,
99 SkMaskFilter, SkColorFilter, SkRasterizer, SkDrawLooper, and SkImageFilter. If the
100 objects' reference count goes to zero, they are deleted.
101 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000102 ~SkPaint();
103
Cary Clark50fa3ff2017-07-26 10:15:23 -0400104 /** Makes a shallow copy of SkPaint. SkTypeface, SkPathEffect, SkShader,
105 SkMaskFilter, SkColorFilter, SkRasterizer, SkDrawLooper, and SkImageFilter are shared
106 between the original paint and the copy. The objects' SkRefCnt are in the
107 prior destination are decreased by one, and the referenced objects are deleted if the
108 resulting count is zero. The objects' SkRefCnt in the parameter paint are increased
109 by one. paint is unmodified.
110
111 @param paint original to copy
112 @return content of paint
113 */
Cary Clark0418a882017-05-10 09:07:42 -0400114 SkPaint& operator=(const SkPaint& paint);
Cary Clark50fa3ff2017-07-26 10:15:23 -0400115
116 /** Moves the paint to avoid incrementing the reference counts
117 of objects referenced by the paint parameter. The objects' SkRefCnt are in the
118 prior destination are decreased by one, and the referenced objects are deleted if the
119 resulting count is zero.
120
121 After the call, paint is undefined, and can be safely destructed.
122
123 @param paint original to move
124 @return content of paint
125 */
Cary Clark0418a882017-05-10 09:07:42 -0400126 SkPaint& operator=(SkPaint&& paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000127
Cary Clark50fa3ff2017-07-26 10:15:23 -0400128 /** Compares a and b, and returns true if a and b are equivalent. May return false
129 if SkTypeface, SkPathEffect, SkShader, SkMaskFilter, SkColorFilter, SkRasterizer,
130 SkDrawLooper, or SkImageFilter have identical contents but different pointers.
131
132 @param a SkPaint to compare
133 @param b SkPaint to compare
134 @return true if SkPaint pair are equivalent
mtkleinbc97ef42014-08-25 10:10:47 -0700135 */
robertphillips@google.comb2657412013-08-07 22:36:29 +0000136 SK_API friend bool operator==(const SkPaint& a, const SkPaint& b);
Cary Clark50fa3ff2017-07-26 10:15:23 -0400137
138 /** Compares a and b, and returns true if a and b are not equivalent. May return true
139 if SkTypeface, SkPathEffect, SkShader, SkMaskFilter, SkColorFilter, SkRasterizer,
140 SkDrawLooper, or SkImageFilter have identical contents but different pointers.
141
142 @param a SkPaint to compare
143 @param b SkPaint to compare
144 @return true if SkPaint pair are not equivalent
145 */
robertphillips@google.comb2657412013-08-07 22:36:29 +0000146 friend bool operator!=(const SkPaint& a, const SkPaint& b) {
147 return !(a == b);
148 }
149
Cary Clark50fa3ff2017-07-26 10:15:23 -0400150 /** Returns a hash generated from SkPaint values and pointers.
151 Identical hashes guarantee that the paints are
152 equivalent, but differing hashes do not guarantee that the paints have differing
153 contents.
154
155 If operator==(const SkPaint& a, const SkPaint& b) returns true for two paints,
156 their hashes are also equal.
157
158 The hash returned is platform and implementation specific.
159
160 @return a shallow hash
161 */
mtkleinfb1fe4f2014-10-07 09:26:10 -0700162 uint32_t getHash() const;
163
Cary Clark50fa3ff2017-07-26 10:15:23 -0400164 /** Serializes SkPaint into a buffer. A companion unflatten() call
165 can reconstitute the paint at a later time.
166
167 @param buffer SkWriteBuffer receiving the flattened SkPaint data
168 */
Cary Clark0418a882017-05-10 09:07:42 -0400169 void flatten(SkWriteBuffer& buffer) const;
Cary Clark50fa3ff2017-07-26 10:15:23 -0400170
171 /** Populates SkPaint, typically from a serialized stream, created by calling
172 flatten() at an earlier time.
173
174 SkReadBuffer class is not public, so unflatten() cannot be meaningfully called
175 by the client.
176
177 @param buffer serialized data to unflatten
178 */
Cary Clark0418a882017-05-10 09:07:42 -0400179 void unflatten(SkReadBuffer& buffer);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000180
Cary Clark50fa3ff2017-07-26 10:15:23 -0400181 /** Sets all paint's contents to their initial values. This is equivalent to replacing
182 the paint with the result of SkPaint().
reed@android.com8a1c16f2008-12-17 15:59:43 +0000183 */
184 void reset();
185
Cary Clark50fa3ff2017-07-26 10:15:23 -0400186 /** \enum SkPaint::Hinting
187 Hinting adjusts the glyph outlines so that the shape provides a uniform
188 look at a given point size on font engines that support it. Hinting may have a
189 muted effect or no effect at all depending on the platform.
190
191 The four levels roughly control corresponding features on platforms that use FreeType
192 as the font engine.
agl@chromium.org309485b2009-07-21 17:41:32 +0000193 */
194 enum Hinting {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400195 /** Leaves glyph outlines unchanged from their native representation.
196 With FreeType, this is equivalent to the FT_LOAD_NO_HINTING
197 bit-field constant supplied to FT_Load_Glyph, which indicates that the vector
198 outline being loaded should not be fitted to the pixel grid but simply scaled
199 to 26.6 fractional pixels.
200 */
201 kNo_Hinting = 0,
202
203 /** Modifies glyph outlines minimally to improve constrast.
204 With FreeType, this is equivalent in spirit to the
205 FT_LOAD_TARGET_LIGHT value supplied to FT_Load_Glyph. It chooses a
206 lighter hinting algorithm for non-monochrome modes.
207 Generated glyphs may be fuzzy but better resemble their original shape.
208 */
209 kSlight_Hinting = 1,
210
211 /** Modifies glyph outlines to improve constrast. This is the default.
212 With FreeType, this supplies FT_LOAD_TARGET_NORMAL to FT_Load_Glyph,
213 choosing the default hinting algorithm, which is optimized for standard
214 gray-level rendering.
215 */
216 kNormal_Hinting = 2,
217
218 /** Modifies glyph outlines for maxiumum constrast. With FreeType, this selects
219 FT_LOAD_TARGET_LCD or FT_LOAD_TARGET_LCD_V if kLCDRenderText_Flag is set.
220 FT_LOAD_TARGET_LCD is a variant of FT_LOAD_TARGET_NORMAL optimized for
221 horizontally decimated LCD displays; FT_LOAD_TARGET_LCD_V is a
222 variant of FT_LOAD_TARGET_NORMAL optimized for vertically decimated LCD displays.
223 */
224 kFull_Hinting = 3,
agl@chromium.org309485b2009-07-21 17:41:32 +0000225 };
226
Cary Clark50fa3ff2017-07-26 10:15:23 -0400227 /** Returns level of glyph outline adjustment.
228
229 @return one of: kNo_Hinting, kSlight_Hinting, kNormal_Hinting, kFull_Hinting
230 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000231 Hinting getHinting() const {
reedf59eab22014-07-14 14:39:15 -0700232 return static_cast<Hinting>(fBitfields.fHinting);
agl@chromium.org309485b2009-07-21 17:41:32 +0000233 }
234
Cary Clark50fa3ff2017-07-26 10:15:23 -0400235 /** Sets level of glyph outline adjustment.
236 Does not check for valid values of hintingLevel.
237
238 @param hintingLevel one of: kNo_Hinting, kSlight_Hinting, kNormal_Hinting, kFull_Hinting
239 */
djsollen@google.comf5dbe2f2011-04-15 13:41:26 +0000240 void setHinting(Hinting hintingLevel);
agl@chromium.org309485b2009-07-21 17:41:32 +0000241
Cary Clark50fa3ff2017-07-26 10:15:23 -0400242 /** \enum SkPaint::Flags
243 The bit values stored in Flags.
244 The default value for Flags, normally zero, can be changed at compile time
245 with a custom definition of SkPaintDefaults_Flags.
246 All flags can be read and written explicitly; Flags allows manipulating
247 multiple settings at once.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000248 */
249 enum Flags {
Cary Clark1eace2d2017-07-31 07:52:43 -0400250 kAntiAlias_Flag = 0x01, //!< mask for setting anti-alias
251 kDither_Flag = 0x04, //!< mask for setting dither
Cary Clark50fa3ff2017-07-26 10:15:23 -0400252 kFakeBoldText_Flag = 0x20, //!< mask for setting fake bold
253 kLinearText_Flag = 0x40, //!< mask for setting linear text
254 kSubpixelText_Flag = 0x80, //!< mask for setting subpixel text
255 kDevKernText_Flag = 0x100, //!< mask for setting full hinting spacing
256 kLCDRenderText_Flag = 0x200, //!< mask for setting lcd text
257 kEmbeddedBitmapText_Flag = 0x400, //!< mask for setting font embedded bitmaps
258 kAutoHinting_Flag = 0x800, //!< mask for setting auto-hinting
259 kVerticalText_Flag = 0x1000, //!< mask for setting vertical text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000260
Cary Clark50fa3ff2017-07-26 10:15:23 -0400261 /** Hack for GDI -- do not use if you can help it */
262 kGenA8FromLCD_Flag = 0x2000,
263
264 /** mask of all Flags, including private flags and flags reserved for future use */
265 kAllFlags = 0xFFFF,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000266 };
267
Cary Clark50fa3ff2017-07-26 10:15:23 -0400268 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Mike Reedddbd37e2017-02-21 15:07:44 -0500269 enum ReserveFlags {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400270 kUnderlineText_ReserveFlag = 0x08, //!< mask for underline text
271 kStrikeThruText_ReserveFlag = 0x10, //!< mask for strike-thru text
Mike Reedddbd37e2017-02-21 15:07:44 -0500272 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400273 #endif
Mike Reedddbd37e2017-02-21 15:07:44 -0500274
Cary Clark50fa3ff2017-07-26 10:15:23 -0400275 /** Returns paint settings described by SkPaint::Flags. Each setting uses one
276 bit, and can be tested with SkPaint::Flags members.
277
278 @return zero, one, or more bits described by SkPaint::Flags
reed@android.com8a1c16f2008-12-17 15:59:43 +0000279 */
reedf59eab22014-07-14 14:39:15 -0700280 uint32_t getFlags() const { return fBitfields.fFlags; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000281
Cary Clark23890a92017-07-27 16:30:51 -0400282 /** Replaces SkPaint::Flags with flags, the union of the SkPaint::Flags members.
283 All SkPaint::Flags members may be cleared, or one or more may be set.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400284
285 @param flags union of SkPaint::Flags for SkPaint
reed@android.com8a1c16f2008-12-17 15:59:43 +0000286 */
287 void setFlags(uint32_t flags);
288
Cary Clark50fa3ff2017-07-26 10:15:23 -0400289 /** If true, pixels on the active edges of SkPath may be drawn with partial transparency.
290
Cary Clark579985c2017-07-31 11:48:27 -0400291 Equivalent to getFlags() masked with kAntiAlias_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400292
293 @return kAntiAlias_Flag state
294 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000295 bool isAntiAlias() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000296 return SkToBool(this->getFlags() & kAntiAlias_Flag);
297 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000298
Cary Clark50fa3ff2017-07-26 10:15:23 -0400299 /** Requests, but does not require, that SkPath edge pixels draw opaque or with
300 partial transparency.
301
302 Sets kAntiAlias_Flag if aa is true.
303 Clears kAntiAlias_Flag if aa is false.
304
305 @param aa setting for kAntiAlias_Flag
306 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000307 void setAntiAlias(bool aa);
reed@google.com9d07fec2011-03-16 20:02:59 +0000308
Cary Clark50fa3ff2017-07-26 10:15:23 -0400309 /** If true, color error may be distributed to smooth color transition.
310
Cary Clark579985c2017-07-31 11:48:27 -0400311 Equivalent to getFlags() masked with kDither_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400312
313 @return kDither_Flag state
314 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000315 bool isDither() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000316 return SkToBool(this->getFlags() & kDither_Flag);
317 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000318
Cary Clark50fa3ff2017-07-26 10:15:23 -0400319 /** Requests, but does not require, to distribute color error.
320
321 Sets kDither_Flag if dither is true.
322 Clears kDither_Flag if dither is false.
323
324 @param dither setting for kDither_Flag
325 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000326 void setDither(bool dither);
reed@google.com9d07fec2011-03-16 20:02:59 +0000327
Cary Clark50fa3ff2017-07-26 10:15:23 -0400328 /** If true, text is converted to SkPath before drawing and measuring.
329
Cary Clark579985c2017-07-31 11:48:27 -0400330 Equivalent to getFlags() masked with kLinearText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400331
332 @return kLinearText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000333 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000334 bool isLinearText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000335 return SkToBool(this->getFlags() & kLinearText_Flag);
336 }
337
Cary Clark50fa3ff2017-07-26 10:15:23 -0400338 /** If true, text is converted to SkPath before drawing and measuring.
339 By default, kLinearText_Flag is clear.
340
341 Sets kLinearText_Flag if linearText is true.
342 Clears kLinearText_Flag if linearText is false.
343
344 @param linearText setting for kLinearText_Flag
reed@android.com8a1c16f2008-12-17 15:59:43 +0000345 */
346 void setLinearText(bool linearText);
347
Cary Clark50fa3ff2017-07-26 10:15:23 -0400348 /** If true, glyphs at different sub-pixel positions may differ on pixel edge coverage.
349
Cary Clark579985c2017-07-31 11:48:27 -0400350 Equivalent to getFlags() masked with kSubpixelText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400351
352 @return kSubpixelText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000353 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000354 bool isSubpixelText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000355 return SkToBool(this->getFlags() & kSubpixelText_Flag);
356 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000357
Cary Clark50fa3ff2017-07-26 10:15:23 -0400358 /** Requests, but does not require, that glyphs respect sub-pixel positioning.
359
360 Sets kSubpixelText_Flag if subpixelText is true.
361 Clears kSubpixelText_Flag if subpixelText is false.
362
363 @param subpixelText setting for kSubpixelText_Flag
364 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000365 void setSubpixelText(bool subpixelText);
agl@chromium.org309485b2009-07-21 17:41:32 +0000366
Cary Clark50fa3ff2017-07-26 10:15:23 -0400367 /** If true, glyphs may use LCD striping to improve glyph edges.
368
369 Returns true if SkPaint::Flags kLCDRenderText_Flag is set.
370
371 @return kLCDRenderText_Flag state
372 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000373 bool isLCDRenderText() const {
agl@chromium.org309485b2009-07-21 17:41:32 +0000374 return SkToBool(this->getFlags() & kLCDRenderText_Flag);
375 }
376
Cary Clark50fa3ff2017-07-26 10:15:23 -0400377 /** Requests, but does not require, that glyphs use LCD striping for glyph edges.
378
379 Sets kLCDRenderText_Flag if lcdText is true.
380 Clears kLCDRenderText_Flag if lcdText is false.
381
382 @param lcdText setting for kLCDRenderText_Flag
383 */
reed@google.com84b437e2011-08-01 12:45:35 +0000384 void setLCDRenderText(bool lcdText);
agl@chromium.org309485b2009-07-21 17:41:32 +0000385
Cary Clark50fa3ff2017-07-26 10:15:23 -0400386 /** If true, font engine may return glyphs from font bitmaps instead of from outlines.
387
Cary Clark579985c2017-07-31 11:48:27 -0400388 Equivalent to getFlags() masked with kEmbeddedBitmapText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400389
390 @return kEmbeddedBitmapText_Flag state
391 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000392 bool isEmbeddedBitmapText() const {
agl@chromium.orge95c91e2010-01-04 18:27:55 +0000393 return SkToBool(this->getFlags() & kEmbeddedBitmapText_Flag);
394 }
395
Cary Clark50fa3ff2017-07-26 10:15:23 -0400396 /** Requests, but does not require, to use bitmaps in fonts instead of outlines.
397
398 Sets kEmbeddedBitmapText_Flag if useEmbeddedBitmapText is true.
399 Clears kEmbeddedBitmapText_Flag if useEmbeddedBitmapText is false.
400
401 @param useEmbeddedBitmapText setting for kEmbeddedBitmapText_Flag
agl@chromium.orge95c91e2010-01-04 18:27:55 +0000402 */
403 void setEmbeddedBitmapText(bool useEmbeddedBitmapText);
404
Cary Clark50fa3ff2017-07-26 10:15:23 -0400405 /** If true, and if SkPaint::Hinting is set to kNormal_Hinting or kFull_Hinting, and if
406 platform uses FreeType as the font manager, instruct the font manager to always hint
Cary Clark1eace2d2017-07-31 07:52:43 -0400407 glyphs.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400408
Cary Clark579985c2017-07-31 11:48:27 -0400409 Equivalent to getFlags() masked with kAutoHinting_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400410
411 @return kAutoHinting_Flag state
412 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000413 bool isAutohinted() const {
agl@chromium.orga2c71cb2010-06-17 20:49:17 +0000414 return SkToBool(this->getFlags() & kAutoHinting_Flag);
415 }
416
Cary Clark50fa3ff2017-07-26 10:15:23 -0400417 /** If SkPaint::Hinting is set to kNormal_Hinting or kFull_Hinting and useAutohinter is set,
Cary Clark1eace2d2017-07-31 07:52:43 -0400418 instruct the font manager to always hint glyphs.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400419 auto-hinting has no effect if SkPaint::Hinting is set to kNo_Hinting or
420 kSlight_Hinting.
421
Cary Clark579985c2017-07-31 11:48:27 -0400422 Only affects platforms that use FreeType as the font manager.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400423
424 Sets kAutoHinting_Flag if useAutohinter is true.
425 Clears kAutoHinting_Flag if useAutohinter is false.
426
427 @param useAutohinter setting for kAutoHinting_Flag
agl@chromium.orga2c71cb2010-06-17 20:49:17 +0000428 */
429 void setAutohinted(bool useAutohinter);
430
Cary Clark50fa3ff2017-07-26 10:15:23 -0400431 /** If true, glyphs are drawn top to bottom instead of left to right.
432
Cary Clark579985c2017-07-31 11:48:27 -0400433 Equivalent to getFlags() masked with kVerticalText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400434
435 @return kVerticalText_Flag state
436 */
reed@google.com830a23e2011-11-10 15:20:49 +0000437 bool isVerticalText() const {
438 return SkToBool(this->getFlags() & kVerticalText_Flag);
439 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000440
Cary Clark50fa3ff2017-07-26 10:15:23 -0400441 /** If true, text advance positions the next glyph below the previous glyph instead of to the
442 right of previous glyph.
443
444 Sets kVerticalText_Flag if vertical is true.
445 Clears kVerticalText_Flag if vertical is false.
446
447 @param verticalText setting for kVerticalText_Flag
448 */
Cary Clark0418a882017-05-10 09:07:42 -0400449 void setVerticalText(bool verticalText);
reed@google.com830a23e2011-11-10 15:20:49 +0000450
Cary Clark50fa3ff2017-07-26 10:15:23 -0400451 /** If true, approximate bold by increasing the stroke width when creating glyph bitmaps
452 from outlines.
453
Cary Clark579985c2017-07-31 11:48:27 -0400454 Equivalent to getFlags() masked with kFakeBoldText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400455
456 @return kFakeBoldText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000457 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000458 bool isFakeBoldText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000459 return SkToBool(this->getFlags() & kFakeBoldText_Flag);
460 }
461
Cary Clark50fa3ff2017-07-26 10:15:23 -0400462 /** Use increased stroke width when creating glyph bitmaps to approximate bolding.
463
464 Sets kFakeBoldText_Flag if fakeBoldText is true.
465 Clears kFakeBoldText_Flag if fakeBoldText is false.
466
467 @param fakeBoldText setting for kFakeBoldText_Flag
reed@android.com8a1c16f2008-12-17 15:59:43 +0000468 */
469 void setFakeBoldText(bool fakeBoldText);
470
Cary Clark50fa3ff2017-07-26 10:15:23 -0400471 /** Returns if character spacing may be adjusted by the hinting difference.
472
Cary Clark579985c2017-07-31 11:48:27 -0400473 Equivalent to getFlags() masked with kDevKernText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400474
475 @return kDevKernText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000476 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000477 bool isDevKernText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000478 return SkToBool(this->getFlags() & kDevKernText_Flag);
479 }
480
Cary Clark50fa3ff2017-07-26 10:15:23 -0400481 /** Requests, but does not require, to use hinting to adjust glyph spacing.
482
483 Sets kDevKernText_Flag if devKernText is true.
484 Clears kDevKernText_Flag if devKernText is false.
485
486 @param devKernText setting for devKernText
reed@android.com8a1c16f2008-12-17 15:59:43 +0000487 */
488 void setDevKernText(bool devKernText);
489
Cary Clark50fa3ff2017-07-26 10:15:23 -0400490 /** Returns SkFilterQuality, the image filtering level. A lower setting
491 draws faster; a higher setting looks better when the image is scaled.
492
493 @return one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
494 kMedium_SkFilterQuality, kHigh_SkFilterQuality
495 */
reedf803da12015-01-23 05:58:07 -0800496 SkFilterQuality getFilterQuality() const {
497 return (SkFilterQuality)fBitfields.fFilterQuality;
498 }
mtkleinfe81e2d2015-09-09 07:35:42 -0700499
Cary Clark23890a92017-07-27 16:30:51 -0400500 /** Sets SkFilterQuality, the image filtering level. A lower setting
Cary Clark50fa3ff2017-07-26 10:15:23 -0400501 draws faster; a higher setting looks better when the image is scaled.
Cary Clark579985c2017-07-31 11:48:27 -0400502 Does not check to see if quality is valid.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400503
504 @param quality one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
505 kMedium_SkFilterQuality, kHigh_SkFilterQuality
506 */
reedf803da12015-01-23 05:58:07 -0800507 void setFilterQuality(SkFilterQuality quality);
reed@google.comc9683152013-07-18 13:47:01 +0000508
Cary Clark50fa3ff2017-07-26 10:15:23 -0400509 /** \enum SkPaint::Style
Cary Clark23890a92017-07-27 16:30:51 -0400510 Set Style to fill, stroke, or both fill and stroke geometry.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400511 The stroke and fill
512 share all paint attributes; for instance, they are drawn with the same color.
reed@google.com9d07fec2011-03-16 20:02:59 +0000513
Cary Clark50fa3ff2017-07-26 10:15:23 -0400514 Use kStrokeAndFill_Style to avoid hitting the same pixels twice with a stroke draw and
515 a fill draw.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000516 */
517 enum Style {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400518 /** Set to fill geometry.
Cary Clark1eace2d2017-07-31 07:52:43 -0400519 Applies to SkRect, SkRegion, SkRRect, circles, ovals, SkPath, and text.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400520 SkBitmap, SkImage, patches, SkRegion, sprites, and vertices are painted as if
521 kFill_Style is set, and ignore the set Style.
522 The FillType specifies additional rules to fill the area outside the path edge,
523 and to create an unfilled hole inside the shape.
524 Style is set to kFill_Style by default.
525 */
526 kFill_Style,
527
528 /** Set to stroke geometry.
529 Applies to SkRect, SkRegion, SkRRect, arcs, circles, ovals,
Cary Clark1eace2d2017-07-31 07:52:43 -0400530 SkPath, and text.
531 Arcs, lines, SkPoint, and SkPoint arrays are always drawn as if kStroke_Style is set,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400532 and ignore the set Style.
533 The stroke construction is unaffected by the FillType.
534 */
535 kStroke_Style,
536
537 /** Set to stroke and fill geometry.
Cary Clark1eace2d2017-07-31 07:52:43 -0400538 Applies to SkRect, SkRegion, SkRRect, circles, ovals, SkPath, and text.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400539 SkPath is treated as if it is set to SkPath::kWinding_FillType,
540 and the set FillType is ignored.
541 */
542 kStrokeAndFill_Style,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000543 };
544
Cary Clark50fa3ff2017-07-26 10:15:23 -0400545 enum {
546 /** The number of different Style values defined.
547 May be used to verify that Style is a legal value.
548 */
549 kStyleCount = kStrokeAndFill_Style + 1,
550 };
551
552 /** Whether the geometry is filled, stroked, or filled and stroked.
553
554 @return one of:kFill_Style, kStroke_Style, kStrokeAndFill_Style
reed@android.com8a1c16f2008-12-17 15:59:43 +0000555 */
reedf59eab22014-07-14 14:39:15 -0700556 Style getStyle() const { return (Style)fBitfields.fStyle; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000557
Cary Clark50fa3ff2017-07-26 10:15:23 -0400558 /** Sets whether the geometry is filled, stroked, or filled and stroked.
559 Has no effect if style is not a legal SkPaint::Style value.
560
561 @param style one of: kFill_Style, kStroke_Style, kStrokeAndFill_Style
reed@android.com8a1c16f2008-12-17 15:59:43 +0000562 */
563 void setStyle(Style style);
564
Cary Clark50fa3ff2017-07-26 10:15:23 -0400565 /** Retrieves alpha and RGB, unpremultiplied, packed into 32 bits.
566 Use helpers SkColorGetA(), SkColorGetR(), SkColorGetG(), and SkColorGetB() to extract
567 a color component.
568
569 @return Unpremultiplied ARGB
reed@android.com8a1c16f2008-12-17 15:59:43 +0000570 */
571 SkColor getColor() const { return fColor; }
572
Cary Clark50fa3ff2017-07-26 10:15:23 -0400573 /** Sets alpha and RGB used when stroking and filling. The color is a 32-bit value,
574 unpremutiplied, packing 8-bit components for alpha, red, blue, and green.
575
576 @param color Unpremultiplied ARGB
reed@android.com8a1c16f2008-12-17 15:59:43 +0000577 */
578 void setColor(SkColor color);
579
Cary Clark1eace2d2017-07-31 07:52:43 -0400580 /** Retrieves alpha from the color used when stroking and filling.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400581
582 @return alpha ranging from zero, fully transparent, to 255, fully opaque
583 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000584 uint8_t getAlpha() const { return SkToU8(SkColorGetA(fColor)); }
reed@google.com9d07fec2011-03-16 20:02:59 +0000585
Cary Clark50fa3ff2017-07-26 10:15:23 -0400586 /** Replaces alpha, leaving RGB
587 unchanged. An out of range value triggers an assert in the debug
588 build. a is a value from zero to 255.
Cary Clark1eace2d2017-07-31 07:52:43 -0400589 a set to zero makes color fully transparent; a set to 255 makes color
Cary Clark50fa3ff2017-07-26 10:15:23 -0400590 fully opaque.
591
Cary Clark1eace2d2017-07-31 07:52:43 -0400592 @param a alpha component of color
reed@android.com8a1c16f2008-12-17 15:59:43 +0000593 */
594 void setAlpha(U8CPU a);
595
Cary Clark1eace2d2017-07-31 07:52:43 -0400596 /** Sets color used when drawing solid fills. The color components range from 0 to 255.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400597 The color is unpremultiplied;
598 alpha sets the transparency independent of RGB.
599
600 @param a amount of alpha, from fully transparent (0) to fully opaque (255)
601 @param r amount of red, from no red (0) to full red (255)
602 @param g amount of green, from no green (0) to full green (255)
603 @param b amount of blue, from no blue (0) to full blue (255)
reed@android.com8a1c16f2008-12-17 15:59:43 +0000604 */
605 void setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b);
606
Cary Clark50fa3ff2017-07-26 10:15:23 -0400607 /** Returns the thickness of the pen used by SkPaint to
608 outline the shape.
609
Cary Clark1eace2d2017-07-31 07:52:43 -0400610 @return zero for hairline, greater than zero for pen thickness
reed@android.com8a1c16f2008-12-17 15:59:43 +0000611 */
612 SkScalar getStrokeWidth() const { return fWidth; }
613
Cary Clark50fa3ff2017-07-26 10:15:23 -0400614 /** Sets the thickness of the pen used by the paint to
615 outline the shape.
616 Has no effect if width is less than zero.
617
Cary Clark1eace2d2017-07-31 07:52:43 -0400618 @param width zero thickness for hairline; greater than zero for pen thickness
reed@android.com8a1c16f2008-12-17 15:59:43 +0000619 */
620 void setStrokeWidth(SkScalar width);
621
Cary Clark50fa3ff2017-07-26 10:15:23 -0400622 /** The limit at which a sharp corner is drawn beveled.
623
624 @return zero and greater miter limit
reed@android.com8a1c16f2008-12-17 15:59:43 +0000625 */
626 SkScalar getStrokeMiter() const { return fMiterLimit; }
627
Cary Clark50fa3ff2017-07-26 10:15:23 -0400628 /** The limit at which a sharp corner is drawn beveled.
629 Valid values are zero and greater.
630 Has no effect if miter is less than zero.
631
632 @param miter zero and greater miter limit
reed@android.com8a1c16f2008-12-17 15:59:43 +0000633 */
634 void setStrokeMiter(SkScalar miter);
635
Cary Clark50fa3ff2017-07-26 10:15:23 -0400636 /** \enum SkPaint::Cap
637 Cap draws at the beginning and end of an open path contour.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000638 */
639 enum Cap {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400640 kButt_Cap, //!< Does not extend the stroke past the beginning or the end.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000641
Cary Clark50fa3ff2017-07-26 10:15:23 -0400642 /** Adds a circle with a diameter equal to stroke width at the beginning
643 and end.
644 */
645 kRound_Cap,
646
647 /** Adds a square with sides equal to stroke width at the beginning
648 and end. The square sides are parallel to the initial and final direction
649 of the stroke.
650 */
651 kSquare_Cap,
652 kLast_Cap = kSquare_Cap, //!< Equivalent to the largest value for Cap.
653
654 /** Equivalent to kButt_Cap.
655 Cap is set to kButt_Cap by default.
656 */
657 kDefault_Cap = kButt_Cap,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000658 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400659
bsalomona7d85ba2016-07-06 11:54:59 -0700660 static constexpr int kCapCount = kLast_Cap + 1;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000661
Cary Clark50fa3ff2017-07-26 10:15:23 -0400662 /** \enum SkPaint::Join
Cary Clark1eace2d2017-07-31 07:52:43 -0400663 Join specifies how corners are drawn when a shape is stroked. Join
Cary Clark50fa3ff2017-07-26 10:15:23 -0400664 affects the four corners of a stroked rectangle, and the connected segments in a
665 stroked path.
666
667 Choose miter join to draw sharp corners. Choose round join to draw a circle with a
668 radius equal to the stroke width on top of the corner. Choose bevel join to minimally
669 connect the thick strokes.
670
671 The fill path constructed to describe the stroked path respects the join setting but may
672 not contain the actual join. For instance, a fill path constructed with round joins does
673 not necessarily include circles at each connected segment.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000674 */
675 enum Join {
Cary Clark23890a92017-07-27 16:30:51 -0400676 /** Extends the outside corner to the extent allowed by miter limit.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400677 If the extension exceeds miter limit, kBevel_Join is used instead.
678 */
679 kMiter_Join,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000680
Cary Clark50fa3ff2017-07-26 10:15:23 -0400681 /** Adds a circle with a diameter of stroke width at the sharp corner. */
682 kRound_Join,
683 kBevel_Join, //!< Connects the outside edges of the sharp corner.
684 kLast_Join = kBevel_Join, //!< Equivalent to the largest value for Join.
685
686 /** Equivalent to kMiter_Join.
687 Join is set to kMiter_Join by default.
688 */
689 kDefault_Join = kMiter_Join,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000690 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400691
bsalomona7d85ba2016-07-06 11:54:59 -0700692 static constexpr int kJoinCount = kLast_Join + 1;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000693
Cary Clark50fa3ff2017-07-26 10:15:23 -0400694 /** The geometry drawn at the beginning and end of strokes.
695
696 @return one of: kButt_Cap, kRound_Cap, kSquare_Cap
reed@android.com8a1c16f2008-12-17 15:59:43 +0000697 */
reedf59eab22014-07-14 14:39:15 -0700698 Cap getStrokeCap() const { return (Cap)fBitfields.fCapType; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000699
Cary Clark50fa3ff2017-07-26 10:15:23 -0400700 /** The geometry drawn at the beginning and end of strokes.
701
702 @param cap one of: kButt_Cap, kRound_Cap, kSquare_Cap;
703 has no effect if cap is not valid
reed@android.com8a1c16f2008-12-17 15:59:43 +0000704 */
705 void setStrokeCap(Cap cap);
706
Cary Clark50fa3ff2017-07-26 10:15:23 -0400707 /** The geometry drawn at the corners of strokes.
708
709 @return one of: kMiter_Join, kRound_Join, kBevel_Join
reed@android.com8a1c16f2008-12-17 15:59:43 +0000710 */
reedf59eab22014-07-14 14:39:15 -0700711 Join getStrokeJoin() const { return (Join)fBitfields.fJoinType; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000712
Cary Clark50fa3ff2017-07-26 10:15:23 -0400713 /** The geometry drawn at the corners of strokes.
714
715 @param join one of: kMiter_Join, kRound_Join, kBevel_Join;
Cary Clark579985c2017-07-31 11:48:27 -0400716 otherwise, has no effect
reed@android.com8a1c16f2008-12-17 15:59:43 +0000717 */
718 void setStrokeJoin(Join join);
719
Cary Clark50fa3ff2017-07-26 10:15:23 -0400720 /** The filled equivalent of the stroked path.
721
722 @param src SkPath read to create a filled version
723 @param dst resulting SkPath; may be the same as src, but may not be nullptr
724 @param cullRect optional limit passed to SkPathEffect
725 @param resScale if > 1, increase precision, else if (0 < res < 1) reduce precision
726 to favor speed and size
Cary Clark1eace2d2017-07-31 07:52:43 -0400727 @return true if the path represents style fill, or false if it represents hairline
Cary Clark50fa3ff2017-07-26 10:15:23 -0400728 */
reed05d90442015-02-12 13:35:52 -0800729 bool getFillPath(const SkPath& src, SkPath* dst, const SkRect* cullRect,
730 SkScalar resScale = 1) const;
731
Cary Clark50fa3ff2017-07-26 10:15:23 -0400732 /** The filled equivalent of the stroked path.
733
Cary Clark23890a92017-07-27 16:30:51 -0400734 Replaces dst with the src path modified by SkPathEffect and style stroke.
735 SkPathEffect, if any, is not culled. stroke width is created with default precision.
736
737 @param src SkPath read to create a filled version
738 @param dst resulting SkPath dst may be the same as src, but may not be nullptr
Cary Clark1eace2d2017-07-31 07:52:43 -0400739 @return true if the path represents style fill, or false if it represents hairline
Cary Clark50fa3ff2017-07-26 10:15:23 -0400740 */
reed05d90442015-02-12 13:35:52 -0800741 bool getFillPath(const SkPath& src, SkPath* dst) const {
Ben Wagnera93a14a2017-08-28 10:34:05 -0400742 return this->getFillPath(src, dst, nullptr, 1);
reed05d90442015-02-12 13:35:52 -0800743 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000744
Cary Clark50fa3ff2017-07-26 10:15:23 -0400745 /** Optional colors used when filling a path, such as a gradient.
746
747 Does not alter SkShader SkRefCnt.
748
749 @return SkShader if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000750 */
reeda5ab9ec2016-03-06 18:10:48 -0800751 SkShader* getShader() const { return fShader.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400752
753 /** Optional colors used when filling a path, such as a gradient.
754
755 Increases SkShader SkRefCnt by one.
756
757 @return SkShader if previously set, nullptr otherwise
758 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500759 sk_sp<SkShader> refShader() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000760
Cary Clark50fa3ff2017-07-26 10:15:23 -0400761 /** Optional colors used when filling a path, such as a gradient.
762
763 Sets SkShader to shader, decrementing SkRefCnt of the previous SkShader.
764 Does not alter shader SkRefCnt.
765
Cary Clark1eace2d2017-07-31 07:52:43 -0400766 @param shader how geometry is filled with color; if nullptr, color is used instead
Cary Clark50fa3ff2017-07-26 10:15:23 -0400767 */
Cary Clark0418a882017-05-10 09:07:42 -0400768 void setShader(sk_sp<SkShader> shader);
reed@google.com9d07fec2011-03-16 20:02:59 +0000769
Cary Clark50fa3ff2017-07-26 10:15:23 -0400770 /** Returns SkColorFilter if set, or nullptr.
771 Does not alter SkColorFilter SkRefCnt.
772
773 @return SkColorFilter if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000774 */
reeda5ab9ec2016-03-06 18:10:48 -0800775 SkColorFilter* getColorFilter() const { return fColorFilter.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400776
777 /** Returns SkColorFilter if set, or nullptr.
778 Increases SkColorFilter SkRefCnt by one.
779
780 @return SkColorFilter if set, or nullptr
781 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500782 sk_sp<SkColorFilter> refColorFilter() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000783
Cary Clark50fa3ff2017-07-26 10:15:23 -0400784 /** Sets SkColorFilter to filter, decrementing SkRefCnt of the previous SkColorFilter.
785 Pass nullptr to clear SkColorFilter.
786 Does not alter filter SkRefCnt.
787
788 @param colorFilter SkColorFilter to apply to subsequent draw
reed@android.com8a1c16f2008-12-17 15:59:43 +0000789 */
Cary Clark0418a882017-05-10 09:07:42 -0400790 void setColorFilter(sk_sp<SkColorFilter> colorFilter);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000791
Cary Clark50fa3ff2017-07-26 10:15:23 -0400792 /** Returns SkBlendMode.
Cary Clark579985c2017-07-31 11:48:27 -0400793 By default, returns SkBlendMode::kSrcOver.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400794
795 @return mode used to combine source color with destination color
796 */
reed374772b2016-10-05 17:33:02 -0700797 SkBlendMode getBlendMode() const { return (SkBlendMode)fBlendMode; }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400798
799 /** Returns true if SkBlendMode is SkBlendMode::kSrcOver, the default.
800
801 @return true if SkBlendMode is SkBlendMode::kSrcOver
802 */
reed374772b2016-10-05 17:33:02 -0700803 bool isSrcOver() const { return (SkBlendMode)fBlendMode == SkBlendMode::kSrcOver; }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400804
805 /** Sets SkBlendMode to mode.
806 Does not check for valid input.
807
808 @param mode SkBlendMode used to combine source color and destination
809 */
reed374772b2016-10-05 17:33:02 -0700810 void setBlendMode(SkBlendMode mode) { fBlendMode = (unsigned)mode; }
reed@android.coma0f5d152009-06-22 17:38:10 +0000811
Cary Clark50fa3ff2017-07-26 10:15:23 -0400812 /** Returns SkPathEffect if set, or nullptr.
813 Does not alter SkPathEffect SkRefCnt.
814
815 @return SkPathEffect if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000816 */
reeda5ab9ec2016-03-06 18:10:48 -0800817 SkPathEffect* getPathEffect() const { return fPathEffect.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400818
819 /** Returns SkPathEffect if set, or nullptr.
820 Increases SkPathEffect SkRefCnt by one.
821
822 @return SkPathEffect if previously set, nullptr otherwise
823 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500824 sk_sp<SkPathEffect> refPathEffect() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000825
Cary Clark50fa3ff2017-07-26 10:15:23 -0400826 /** Sets SkPathEffect to pathEffect,
827 decrementing SkRefCnt of the previous SkPathEffect.
828 Pass nullptr to leave the path geometry unaltered.
829 Does not alter pathEffect SkRefCnt.
830
831 @param pathEffect replace SkPath with a modification when drawn
reed@android.com8a1c16f2008-12-17 15:59:43 +0000832 */
Cary Clark0418a882017-05-10 09:07:42 -0400833 void setPathEffect(sk_sp<SkPathEffect> pathEffect);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000834
Cary Clark50fa3ff2017-07-26 10:15:23 -0400835 /** Returns SkMaskFilter if set, or nullptr.
836 Does not alter SkMaskFilter SkRefCnt.
837
838 @return SkMaskFilter if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000839 */
reeda5ab9ec2016-03-06 18:10:48 -0800840 SkMaskFilter* getMaskFilter() const { return fMaskFilter.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400841
842 /** Returns SkMaskFilter if set, or nullptr.
843 Increases SkMaskFilter SkRefCnt by one.
844
845 @return SkMaskFilter if previously set, nullptr otherwise
846 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500847 sk_sp<SkMaskFilter> refMaskFilter() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000848
Cary Clark50fa3ff2017-07-26 10:15:23 -0400849 /** Sets SkMaskFilter to maskFilter,
850 decrementing SkRefCnt of the previous SkMaskFilter.
851 Pass nullptr to clear SkMaskFilter and leave SkMaskFilter effect on mask alpha unaltered.
852 Does not affect SkRasterizer.
853 Does not alter maskFilter SkRefCnt.
854
855 @param maskFilter modifies clipping mask generated from drawn geometry
reed@android.com8a1c16f2008-12-17 15:59:43 +0000856 */
Cary Clark0418a882017-05-10 09:07:42 -0400857 void setMaskFilter(sk_sp<SkMaskFilter> maskFilter);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000858
Cary Clark50fa3ff2017-07-26 10:15:23 -0400859 /** Returns SkTypeface if set, or nullptr.
860 Does not alter SkTypeface SkRefCnt.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000861
Cary Clark50fa3ff2017-07-26 10:15:23 -0400862 @return SkTypeface if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000863 */
reeda5ab9ec2016-03-06 18:10:48 -0800864 SkTypeface* getTypeface() const { return fTypeface.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400865
866 /** Increases SkTypeface SkRefCnt by one.
867
868 @return SkTypeface if previously set, nullptr otherwise
869 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500870 sk_sp<SkTypeface> refTypeface() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000871
Cary Clark50fa3ff2017-07-26 10:15:23 -0400872 /** Sets SkTypeface to typeface,
873 decrementing SkRefCnt of the previous SkTypeface.
874 Pass nullptr to clear SkTypeface and use the default typeface.
875 Does not alter typeface SkRefCnt.
876
877 @param typeface font and style used to draw text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000878 */
Cary Clark0418a882017-05-10 09:07:42 -0400879 void setTypeface(sk_sp<SkTypeface> typeface);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000880
Cary Clark50fa3ff2017-07-26 10:15:23 -0400881 /** Returns SkRasterizer if set, or nullptr.
882 Does not alter SkRasterizer SkRefCnt.
883
884 @return SkRasterizer if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000885 */
reeda5ab9ec2016-03-06 18:10:48 -0800886 SkRasterizer* getRasterizer() const { return fRasterizer.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400887
Cary Clark23890a92017-07-27 16:30:51 -0400888 /** Returns SkRasterizer if set, or nullptr.
889 Increases SkRasterizer SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400890
891 @return SkRasterizer if previously set, nullptr otherwise
892 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500893 sk_sp<SkRasterizer> refRasterizer() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000894
Cary Clark50fa3ff2017-07-26 10:15:23 -0400895 /** Sets SkRasterizer to rasterizer,
896 decrementing SkRefCnt of the previous SkRasterizer.
897 Pass nullptr to clear SkRasterizer and leave SkRasterizer effect on mask alpha unaltered.
898 Does not affect SkMaskFilter.
899 Does not alter rasterizer SkRefCnt.
900
901 @param rasterizer how geometry is converted to mask alpha
reed@android.com8a1c16f2008-12-17 15:59:43 +0000902 */
Cary Clark0418a882017-05-10 09:07:42 -0400903 void setRasterizer(sk_sp<SkRasterizer> rasterizer);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000904
Cary Clark50fa3ff2017-07-26 10:15:23 -0400905 /** Returns SkImageFilter if set, or nullptr.
906 Does not alter SkImageFilter SkRefCnt.
907
908 @return SkImageFilter if previously set, nullptr otherwise
909 */
reeda5ab9ec2016-03-06 18:10:48 -0800910 SkImageFilter* getImageFilter() const { return fImageFilter.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400911
912 /** Returns SkImageFilter if set, or nullptr.
913 Increases SkImageFilter SkRefCnt by one.
914
915 @return SkImageFilter if previously set, nullptr otherwise
916 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500917 sk_sp<SkImageFilter> refImageFilter() const;
Cary Clark50fa3ff2017-07-26 10:15:23 -0400918
919 /** Sets SkImageFilter to imageFilter,
920 decrementing SkRefCnt of the previous SkImageFilter.
921 Pass nullptr to clear SkImageFilter, and remove SkImageFilter effect
922 on drawing.
923 Does not affect SkRasterizer or SkMaskFilter.
924 Does not alter imageFilter SkRefCnt.
925
926 @param imageFilter how SkImage is sampled when transformed
927 */
Cary Clark0418a882017-05-10 09:07:42 -0400928 void setImageFilter(sk_sp<SkImageFilter> imageFilter);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000929
Cary Clark50fa3ff2017-07-26 10:15:23 -0400930 /** Returns SkDrawLooper if set, or nullptr.
931 Does not alter SkDrawLooper SkRefCnt.
932
933 @return SkDrawLooper if previously set, nullptr otherwise
934 */
reed46f2d0a2016-09-11 05:40:31 -0700935 SkDrawLooper* getDrawLooper() const { return fDrawLooper.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400936
937 /** Returns SkDrawLooper if set, or nullptr.
938 Increases SkDrawLooper SkRefCnt by one.
939
940 @return SkDrawLooper if previously set, nullptr otherwise
941 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500942 sk_sp<SkDrawLooper> refDrawLooper() const;
943
Cary Clark23890a92017-07-27 16:30:51 -0400944 /** Deprecated.
945 (see bug.skia.org/6259)
Cary Clark50fa3ff2017-07-26 10:15:23 -0400946
947 @return SkDrawLooper if previously set, nullptr otherwise
948 */
reed46f2d0a2016-09-11 05:40:31 -0700949 SkDrawLooper* getLooper() const { return fDrawLooper.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400950
951 /** Sets SkDrawLooper to drawLooper,
952 decrementing SkRefCnt of the previous drawLooper.
953 Pass nullptr to clear SkDrawLooper and leave SkDrawLooper effect on drawing unaltered.
Cary Clark579985c2017-07-31 11:48:27 -0400954 Does not alter drawLooper SkRefCnt.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400955
956 @param drawLooper Iterates through drawing one or more time, altering SkPaint
957 */
Cary Clark0418a882017-05-10 09:07:42 -0400958 void setDrawLooper(sk_sp<SkDrawLooper> drawLooper);
Mike Reed09d94352016-10-31 15:11:04 -0400959
Cary Clark23890a92017-07-27 16:30:51 -0400960 /** Deprecated.
961 (see bug.skia.org/6259)
Cary Clark50fa3ff2017-07-26 10:15:23 -0400962
963 @param drawLooper sets SkDrawLooper to drawLooper
964 */
Cary Clark0418a882017-05-10 09:07:42 -0400965 void setLooper(sk_sp<SkDrawLooper> drawLooper);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000966
Cary Clark50fa3ff2017-07-26 10:15:23 -0400967 /** \enum SkPaint::Align
968 Align adjusts the text relative to the text position.
969 Align affects glyphs drawn with: SkCanvas::drawText, SkCanvas::drawPosText,
970 SkCanvas::drawPosTextH, SkCanvas::drawTextOnPath,
971 SkCanvas::drawTextOnPathHV, SkCanvas::drawTextRSXform, SkCanvas::drawTextBlob,
972 and SkCanvas::drawString;
Cary Clark579985c2017-07-31 11:48:27 -0400973 as well as calls that place text glyphs like getTextWidths() and getTextPath().
Cary Clark50fa3ff2017-07-26 10:15:23 -0400974
975 The text position is set by the font for both horizontal and vertical text.
976 Typically, for horizontal text, the position is to the left side of the glyph on the
Cary Clark23890a92017-07-27 16:30:51 -0400977 base line; and for vertical text, the position is the horizontal center of the glyph
Cary Clark50fa3ff2017-07-26 10:15:23 -0400978 at the caps height.
979
980 Align adjusts the glyph position to center it or move it to abut the position
981 using the metrics returned by the font.
982
983 Align defaults to kLeft_Align.
984 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000985 enum Align {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400986 /** Leaves the glyph at the position computed by the font offset by the text position. */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000987 kLeft_Align,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400988
989 /** Moves the glyph half its width if Flags has kVerticalText_Flag clear, and
990 half its height if Flags has kVerticalText_Flag set.
991 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000992 kCenter_Align,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400993
994 /** Moves the glyph by its width if Flags has kVerticalText_Flag clear,
995 and by its height if Flags has kVerticalText_Flag set.
996 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000997 kRight_Align,
mike@reedtribe.orgddc813b2013-06-08 12:58:19 +0000998 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400999
mike@reedtribe.orgddc813b2013-06-08 12:58:19 +00001000 enum {
Cary Clark50fa3ff2017-07-26 10:15:23 -04001001 kAlignCount = 3, //!< The number of different Align values defined.
reed@android.com8a1c16f2008-12-17 15:59:43 +00001002 };
reed@google.com9d07fec2011-03-16 20:02:59 +00001003
Cary Clark50fa3ff2017-07-26 10:15:23 -04001004 /** Returns SkPaint::Align.
1005 Returns kLeft_Align if SkPaint::Align has not been set.
1006
1007 @return text placement relative to position
reed@android.com8a1c16f2008-12-17 15:59:43 +00001008 */
reedf59eab22014-07-14 14:39:15 -07001009 Align getTextAlign() const { return (Align)fBitfields.fTextAlign; }
reed@google.com9d07fec2011-03-16 20:02:59 +00001010
Cary Clark50fa3ff2017-07-26 10:15:23 -04001011 /** Sets SkPaint::Align to align.
1012 Has no effect if align is an invalid value.
1013
1014 @param align text placement relative to position
reed@android.com8a1c16f2008-12-17 15:59:43 +00001015 */
1016 void setTextAlign(Align align);
1017
Cary Clark50fa3ff2017-07-26 10:15:23 -04001018 /** Returns text size in points.
1019
1020 @return typographic height of text
reed@android.com8a1c16f2008-12-17 15:59:43 +00001021 */
1022 SkScalar getTextSize() const { return fTextSize; }
1023
Cary Clark50fa3ff2017-07-26 10:15:23 -04001024 /** Sets text size in points.
1025 Has no effect if textSize is not greater than or equal to zero.
1026
1027 @param textSize typographic height of text
reed@android.com8a1c16f2008-12-17 15:59:43 +00001028 */
1029 void setTextSize(SkScalar textSize);
1030
Cary Clark50fa3ff2017-07-26 10:15:23 -04001031 /** Returns text scale x.
1032 Default value is 1.
1033
1034 @return text horizontal scale
reed@android.com8a1c16f2008-12-17 15:59:43 +00001035 */
1036 SkScalar getTextScaleX() const { return fTextScaleX; }
1037
Cary Clark50fa3ff2017-07-26 10:15:23 -04001038 /** Sets text scale x.
1039 Default value is 1.
1040
1041 @param scaleX text horizontal scale
reed@android.com8a1c16f2008-12-17 15:59:43 +00001042 */
1043 void setTextScaleX(SkScalar scaleX);
1044
Cary Clark50fa3ff2017-07-26 10:15:23 -04001045 /** Returns text skew x.
1046 Default value is zero.
1047
1048 @return additional shear in x-axis relative to y-axis
reed@android.com8a1c16f2008-12-17 15:59:43 +00001049 */
1050 SkScalar getTextSkewX() const { return fTextSkewX; }
1051
Cary Clark50fa3ff2017-07-26 10:15:23 -04001052 /** Sets text skew x.
1053 Default value is zero.
1054
1055 @param skewX additional shear in x-axis relative to y-axis
reed@android.com8a1c16f2008-12-17 15:59:43 +00001056 */
1057 void setTextSkewX(SkScalar skewX);
1058
Cary Clark50fa3ff2017-07-26 10:15:23 -04001059 /** \enum SkPaint::TextEncoding
1060 TextEncoding determines whether text specifies character codes and their encoded size,
1061 or glyph indices. Character codes use the encoding specified by the Unicode standard .
1062 Character codes encoded size are specified by UTF-8, UTF-16, or UTF-32.
1063 All character encoding are able to represent all of Unicode, differing only
1064 in the total storage required. UTF-8 (RFC 3629) is made up of 8-bit bytes,
1065 and is a superset of ASCII. UTF-16 (RFC 2781) is made up of 16-bit words,
1066 and is a superset of Unicode ranges 0x0000 to 0xD7FF and 0xE000 to 0xFFFF. UTF-32 is
1067 made up of 32-bit words, and is a superset of Unicode.
1068
1069 font manager uses font data to convert character code points into glyph indices.
1070 A glyph index is a 16-bit word.
1071
1072 TextEncoding is set to kUTF8_TextEncoding by default.
reed@android.com8a1c16f2008-12-17 15:59:43 +00001073 */
1074 enum TextEncoding {
Cary Clark50fa3ff2017-07-26 10:15:23 -04001075 kUTF8_TextEncoding, //!< Uses bytes to represent UTF-8 or ASCII.
1076 kUTF16_TextEncoding, //!< Uses two byte words to represent most of Unicode.
1077 kUTF32_TextEncoding, //!< Uses four byte words to represent all of Unicode.
1078 kGlyphID_TextEncoding, //!< Uses two byte words to represent glyph indices.
reed@android.com8a1c16f2008-12-17 15:59:43 +00001079 };
reed@google.com9d07fec2011-03-16 20:02:59 +00001080
Cary Clark50fa3ff2017-07-26 10:15:23 -04001081 /** Returns SkPaint::TextEncoding.
1082 SkPaint::TextEncoding determines how character code points are mapped to font glyph indices.
1083
1084 @return one of: kUTF8_TextEncoding, kUTF16_TextEncoding, kUTF32_TextEncoding, or
1085 kGlyphID_TextEncoding
1086 */
reedf59eab22014-07-14 14:39:15 -07001087 TextEncoding getTextEncoding() const {
1088 return (TextEncoding)fBitfields.fTextEncoding;
1089 }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001090
Cary Clark50fa3ff2017-07-26 10:15:23 -04001091 /** Sets SkPaint::TextEncoding to encoding.
1092 SkPaint::TextEncoding determines how character code points are mapped to font glyph indices.
1093 Invalid values for encoding are ignored.
1094
1095 @param encoding one of: kUTF8_TextEncoding, kUTF16_TextEncoding, kUTF32_TextEncoding, or
Cary Clark579985c2017-07-31 11:48:27 -04001096 kGlyphID_TextEncoding
Cary Clark50fa3ff2017-07-26 10:15:23 -04001097 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001098 void setTextEncoding(TextEncoding encoding);
1099
Cary Clark50fa3ff2017-07-26 10:15:23 -04001100 /** \struct SkPaint::FontMetrics
Cary Clark579985c2017-07-31 11:48:27 -04001101 FontMetrics is filled out by getFontMetrics(). FontMetrics contents reflect the values
Cary Clark50fa3ff2017-07-26 10:15:23 -04001102 computed by font manager using SkTypeface. Values are set to zero if they are
1103 not availble.
1104
1105 fUnderlineThickness and fUnderlinePosition have a bit set in fFlags if their values
1106 are valid, since their value may be zero.
1107
1108 fStrikeoutThickness and fStrikeoutPosition have a bit set in fFlags if their values
1109 are valid, since their value may be zero.
1110 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001111 struct FontMetrics {
Cary Clark50fa3ff2017-07-26 10:15:23 -04001112
1113 /** \enum SkPaint::FontMetrics::FontMetricsFlags
Cary Clark23890a92017-07-27 16:30:51 -04001114 FontMetricsFlags are set in fFlags when underline and strikeout metrics are valid;
1115 the underline or strikeout metric may be valid and zero.
1116 Fonts with embedded bitmaps may not have valid underline or strikeout metrics.
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001117 */
1118 enum FontMetricsFlags {
Cary Clark50fa3ff2017-07-26 10:15:23 -04001119 kUnderlineThicknessIsValid_Flag = 1 << 0, //!< Set if fUnderlineThickness is valid.
1120 kUnderlinePositionIsValid_Flag = 1 << 1, //!< Set if fUnderlinePosition is valid.
1121 kStrikeoutThicknessIsValid_Flag = 1 << 2, //!< Set if fStrikeoutThickness is valid.
1122 kStrikeoutPositionIsValid_Flag = 1 << 3, //!< Set if fStrikeoutPosition is valid.
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001123 };
1124
Cary Clark50fa3ff2017-07-26 10:15:23 -04001125 uint32_t fFlags; //!< fFlags is set when underline metrics are valid.
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001126
Cary Clark50fa3ff2017-07-26 10:15:23 -04001127 /** Largest height for any glyph.
1128 A measure from the baseline, and is less than or equal to zero.
1129 */
1130 SkScalar fTop;
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001131
Cary Clark50fa3ff2017-07-26 10:15:23 -04001132 /** Recommended distance above the baseline to reserve for a line of text.
1133 A measure from the baseline, and is less than or equal to zero.
1134 */
1135 SkScalar fAscent;
Ben Wagner219f3622017-07-17 15:32:25 -04001136
Cary Clark50fa3ff2017-07-26 10:15:23 -04001137 /** Recommended distance below the baseline to reserve for a line of text.
1138 A measure from the baseline, and is greater than or equal to zero.
1139 */
1140 SkScalar fDescent;
Ben Wagner219f3622017-07-17 15:32:25 -04001141
Cary Clark50fa3ff2017-07-26 10:15:23 -04001142 /** Greatest extent below the baseline for any glyph.
1143 A measure from the baseline, and is greater than or equal to zero.
1144 */
1145 SkScalar fBottom;
1146
1147 /** Recommended distance to add between lines of text.
1148 Greater than or equal to zero.
1149 */
1150 SkScalar fLeading;
1151
1152 /** Average character width, if it is available.
1153 Zero if no average width is stored in the font.
1154 */
1155 SkScalar fAvgCharWidth;
1156 SkScalar fMaxCharWidth; //!< Maximum character width.
1157
1158 /** Minimum bounding box x value for all glyphs.
1159 Typically less than zero.
1160 */
1161 SkScalar fXMin;
1162
1163 /** Maximum bounding box x value for all glyphs.
1164 Typically greater than zero.
1165 */
1166 SkScalar fXMax;
1167
1168 /** Height of a lower-case 'x'.
1169 May be zero if no lower-case height is stored in the font.
1170 */
1171 SkScalar fXHeight;
1172
1173 /** Height of an upper-case letter.
1174 May be zero if no upper-case height is stored in the font.
1175 */
1176 SkScalar fCapHeight;
1177
1178 /** Underline thickness. If the metric
1179 is valid, the kUnderlineThicknessIsValid_Flag is set in fFlags.
1180 If kUnderlineThicknessIsValid_Flag is clear, fUnderlineThickness is zero.
1181 */
1182 SkScalar fUnderlineThickness;
1183
1184 /** Underline position relative to the baseline.
1185 It may be negative, to draw the underline above the baseline, zero
1186 to draw the underline on the baseline, or positive to draw the underline
1187 below the baseline.
1188
1189 If the metric is valid, the kUnderlinePositionIsValid_Flag is set in fFlags.
1190 If kUnderlinePositionIsValid_Flag is clear, fUnderlinePosition is zero.
1191 */
1192 SkScalar fUnderlinePosition;
1193
1194 /** Strikeout thickness. If the metric
1195 is valid, the kStrikeoutThicknessIsValid_Flag is set in fFlags.
1196 If kStrikeoutThicknessIsValid_Flag is clear, fStrikeoutThickness is zero.
1197 */
1198 SkScalar fStrikeoutThickness;
1199
1200 /** Strikeout position relative to the baseline.
1201 It may be negative, to draw the strikeout above the baseline, zero
1202 to draw the strikeout on the baseline, or positive to draw the strikeout
1203 below the baseline.
1204
1205 If the metric is valid, the kStrikeoutPositionIsValid_Flag is set in fFlags.
1206 If kStrikeoutPositionIsValid_Flag is clear, fStrikeoutPosition is zero.
1207 */
1208 SkScalar fStrikeoutPosition;
1209
1210 /** If SkPaint::FontMetrics has a valid underline thickness, return true, and set
1211 thickness to that value. If it doesn't, return false, and ignore
1212 thickness.
1213
1214 @param thickness storage for underline width
1215 @return true if font specifies underline width
1216 */
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001217 bool hasUnderlineThickness(SkScalar* thickness) const {
Ben Wagner3318da52017-03-23 14:01:22 -04001218 if (SkToBool(fFlags & kUnderlineThicknessIsValid_Flag)) {
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001219 *thickness = fUnderlineThickness;
1220 return true;
1221 }
1222 return false;
1223 }
1224
Cary Clark50fa3ff2017-07-26 10:15:23 -04001225 /** If SkPaint::FontMetrics has a valid underline position, return true, and set
1226 position to that value. If it doesn't, return false, and ignore
1227 position.
1228
1229 @param position storage for underline position
1230 @return true if font specifies underline position
1231 */
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001232 bool hasUnderlinePosition(SkScalar* position) const {
1233 if (SkToBool(fFlags & kUnderlinePositionIsValid_Flag)) {
1234 *position = fUnderlinePosition;
1235 return true;
1236 }
1237 return false;
1238 }
1239
Cary Clark50fa3ff2017-07-26 10:15:23 -04001240 /** If SkPaint::FontMetrics has a valid strikeout thickness, return true, and set
1241 thickness to that value. If it doesn't, return false, and ignore
1242 thickness.
1243
1244 @param thickness storage for strikeout width
1245 @return true if font specifies strikeout width
1246 */
Ben Wagner219f3622017-07-17 15:32:25 -04001247 bool hasStrikeoutThickness(SkScalar* thickness) const {
1248 if (SkToBool(fFlags & kStrikeoutThicknessIsValid_Flag)) {
1249 *thickness = fStrikeoutThickness;
1250 return true;
1251 }
1252 return false;
1253 }
1254
Cary Clark50fa3ff2017-07-26 10:15:23 -04001255 /** If SkPaint::FontMetrics has a valid strikeout position, return true, and set
1256 position to that value. If it doesn't, return false, and ignore
1257 position.
1258
1259 @param position storage for strikeout position
1260 @return true if font specifies strikeout position
1261 */
Ben Wagner219f3622017-07-17 15:32:25 -04001262 bool hasStrikeoutPosition(SkScalar* position) const {
1263 if (SkToBool(fFlags & kStrikeoutPositionIsValid_Flag)) {
1264 *position = fStrikeoutPosition;
1265 return true;
1266 }
1267 return false;
1268 }
Cary Clark50fa3ff2017-07-26 10:15:23 -04001269
reed@android.com8a1c16f2008-12-17 15:59:43 +00001270 };
reed@google.com9d07fec2011-03-16 20:02:59 +00001271
Cary Clark50fa3ff2017-07-26 10:15:23 -04001272 /** Returns SkPaint::FontMetrics associated with SkTypeface.
1273 The return value is the recommended spacing between lines: the sum of metrics
1274 descent, ascent, and leading.
1275 If metrics is not nullptr, SkPaint::FontMetrics is copied to metrics.
1276 Results are scaled by text size but does not take into account
1277 dimensions required by text scale x, text skew x, fake bold,
1278 style stroke, and SkPathEffect.
1279 Results can be additionally scaled by scale; a scale of zero
1280 is ignored.
1281
1282 @param metrics storage for SkPaint::FontMetrics from SkTypeface; may be nullptr
1283 @param scale additional multiplier for returned values
1284 @return recommended spacing between lines
reed@android.com8a1c16f2008-12-17 15:59:43 +00001285 */
1286 SkScalar getFontMetrics(FontMetrics* metrics, SkScalar scale = 0) const;
reed@google.com9d07fec2011-03-16 20:02:59 +00001287
Cary Clark50fa3ff2017-07-26 10:15:23 -04001288 /** Returns the recommended spacing between lines: the sum of metrics
1289 descent, ascent, and leading.
1290 Result is scaled by text size but does not take into account
1291 dimensions required by stroking and SkPathEffect.
Cary Clark579985c2017-07-31 11:48:27 -04001292 Returns the same result as getFontMetrics().
Cary Clark50fa3ff2017-07-26 10:15:23 -04001293
1294 @return recommended spacing between lines
reed@android.com8a1c16f2008-12-17 15:59:43 +00001295 */
Ben Wagnera93a14a2017-08-28 10:34:05 -04001296 SkScalar getFontSpacing() const { return this->getFontMetrics(nullptr, 0); }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001297
Cary Clark50fa3ff2017-07-26 10:15:23 -04001298 /** Converts text into glyph indices.
1299 Returns the number of glyph indices represented by text.
1300 SkPaint::TextEncoding specifies how text represents characters or glyphs.
1301 glyphs may be nullptr, to compute the glyph count.
1302
1303 Does not check text for valid character encoding or valid
1304 glyph indices.
1305
Cary Clark579985c2017-07-31 11:48:27 -04001306 If byteLength equals zero, returns zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001307 If byteLength includes a partial character, the partial character is ignored.
1308
1309 If SkPaint::TextEncoding is kUTF8_TextEncoding and
1310 text contains an invalid UTF-8 sequence, zero is returned.
1311
1312 @param text character stroage encoded with SkPaint::TextEncoding
1313 @param byteLength length of character storage in bytes
1314 @param glyphs storage for glyph indices; may be nullptr
1315 @return number of glyphs represented by text of length byteLength
reed@android.com8a1c16f2008-12-17 15:59:43 +00001316 */
1317 int textToGlyphs(const void* text, size_t byteLength,
halcanaryd0e95a52016-07-25 07:18:12 -07001318 SkGlyphID glyphs[]) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001319
Cary Clark50fa3ff2017-07-26 10:15:23 -04001320 /** Returns true if all text corresponds to a non-zero glyph index.
1321 Returns false if any characters in text are not supported in
1322 SkTypeface.
reed@android.coma5dcaf62010-02-05 17:12:32 +00001323
Cary Clark579985c2017-07-31 11:48:27 -04001324 If SkPaint::TextEncoding is kGlyphID_TextEncoding,
1325 returns true if all glyph indices in text are non-zero;
Cary Clark50fa3ff2017-07-26 10:15:23 -04001326 does not check to see if text contains valid glyph indices for SkTypeface.
1327
1328 Returns true if bytelength is zero.
1329
1330 @param text array of characters or glyphs
1331 @param byteLength number of bytes in text array
1332 @return true if all text corresponds to a non-zero glyph index
1333 */
reed@android.coma5dcaf62010-02-05 17:12:32 +00001334 bool containsText(const void* text, size_t byteLength) const;
1335
Cary Clark50fa3ff2017-07-26 10:15:23 -04001336 /** Converts glyphs into text if possible.
1337 Glyph values without direct Unicode equivalents are mapped to zero.
1338 Uses the SkTypeface, but is unaffected
1339 by SkPaint::TextEncoding; the text values returned are equivalent to kUTF32_TextEncoding.
1340
1341 Only supported on platforms that use FreeType as the font engine.
1342
1343 @param glyphs array of indices into font
1344 @param count length of glyph array
1345 @param text storage for character codes, one per glyph
reed@android.com9d3a9852010-01-08 14:07:42 +00001346 */
halcanaryd0e95a52016-07-25 07:18:12 -07001347 void glyphsToUnichars(const SkGlyphID glyphs[], int count, SkUnichar text[]) const;
reed@android.com9d3a9852010-01-08 14:07:42 +00001348
Cary Clark50fa3ff2017-07-26 10:15:23 -04001349 /** Returns the number of glyphs in text.
1350 Uses SkPaint::TextEncoding to count the glyphs.
Cary Clark579985c2017-07-31 11:48:27 -04001351 Returns the same result as textToGlyphs().
Cary Clark50fa3ff2017-07-26 10:15:23 -04001352
1353 @param text character stroage encoded with SkPaint::TextEncoding
1354 @param byteLength length of character storage in bytes
1355 @return number of glyphs represented by text of length byteLength
reed@android.com8a1c16f2008-12-17 15:59:43 +00001356 */
reed@google.com9d07fec2011-03-16 20:02:59 +00001357 int countText(const void* text, size_t byteLength) const {
Ben Wagnera93a14a2017-08-28 10:34:05 -04001358 return this->textToGlyphs(text, byteLength, nullptr);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001359 }
1360
Cary Clark50fa3ff2017-07-26 10:15:23 -04001361 /** Returns the advance width of text if kVerticalText_Flag is clear,
1362 and the height of text if kVerticalText_Flag is set.
1363 The advance is the normal distance to move before drawing additional text.
1364 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
1365 and text size, text scale x, text skew x, stroke width, and
1366 SkPathEffect to scale the metrics and bounds.
1367 Returns the bounding box of text if bounds is not nullptr.
1368 The bounding box is computed as if the text was drawn at the origin.
1369
1370 @param text character codes or glyph indices to be measured
1371 @param length number of bytes of text to measure
1372 @param bounds returns bounding box relative to (0, 0) if not nullptr
1373 @return advance width or height
1374 */
reed99ae8812014-08-26 11:30:01 -07001375 SkScalar measureText(const void* text, size_t length, SkRect* bounds) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001376
Cary Clark50fa3ff2017-07-26 10:15:23 -04001377 /** Returns the advance width of text if kVerticalText_Flag is clear,
1378 and the height of text if kVerticalText_Flag is set.
1379 The advance is the normal distance to move before drawing additional text.
1380 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
Cary Clark23890a92017-07-27 16:30:51 -04001381 and text size to scale the metrics.
1382 Does not scale the advance or bounds by fake bold or SkPathEffect.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001383
1384 @param text character codes or glyph indices to be measured
1385 @param length number of bytes of text to measure
Cary Clark50fa3ff2017-07-26 10:15:23 -04001386 @return advance width or height
1387 */
reed@google.com9d07fec2011-03-16 20:02:59 +00001388 SkScalar measureText(const void* text, size_t length) const {
Ben Wagnera93a14a2017-08-28 10:34:05 -04001389 return this->measureText(text, length, nullptr);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001390 }
reed@google.com9d07fec2011-03-16 20:02:59 +00001391
Cary Clark50fa3ff2017-07-26 10:15:23 -04001392 /** Returns the bytes of text that fit within maxWidth.
1393 If kVerticalText_Flag is clear, the text fragment fits if its advance width is less than or
1394 equal to maxWidth.
1395 If kVerticalText_Flag is set, the text fragment fits if its advance height is less than or
1396 equal to maxWidth.
1397 Measures only while the advance is less than or equal to maxWidth.
1398 Returns the advance or the text fragment in measuredWidth if it not nullptr.
1399 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
1400 and text size to scale the metrics.
1401 Does not scale the advance or bounds by fake bold or SkPathEffect.
1402
1403 @param text character codes or glyph indices to be measured
1404 @param length number of bytes of text to measure
1405 @param maxWidth advance limit; text is measured while advance is less than maxWidth
1406 @param measuredWidth returns the width of the text less than or equal to maxWidth
1407 @return bytes of text that fit, always less than or equal to length
1408 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001409 size_t breakText(const void* text, size_t length, SkScalar maxWidth,
Ben Wagnera93a14a2017-08-28 10:34:05 -04001410 SkScalar* measuredWidth = nullptr) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001411
Cary Clark50fa3ff2017-07-26 10:15:23 -04001412 /** Retrieves the advance and bounds for each glyph in text, and returns
1413 the glyph count in text.
1414 Both widths and bounds may be nullptr.
1415 If widths is not nullptr, widths must be an array of glyph count entries.
1416 if bounds is not nullptr, bounds must be an array of glyph count entries.
1417 If kVerticalText_Flag is clear, widths returns the horizontal advance.
1418 If kVerticalText_Flag is set, widths returns the vertical advance.
1419 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
1420 and text size to scale the widths and bounds.
1421 Does not scale the advance by fake bold or SkPathEffect.
Cary Clark23890a92017-07-27 16:30:51 -04001422 Does include fake bold and SkPathEffect in the bounds.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001423
1424 @param text character codes or glyph indices to be measured
1425 @param byteLength number of bytes of text to measure
1426 @param widths returns text advances for each glyph; may be nullptr
1427 @param bounds returns bounds for each glyph relative to (0, 0); may be nullptr
1428 @return glyph count in text
1429 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001430 int getTextWidths(const void* text, size_t byteLength, SkScalar widths[],
Ben Wagnera93a14a2017-08-28 10:34:05 -04001431 SkRect bounds[] = nullptr) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001432
Cary Clark50fa3ff2017-07-26 10:15:23 -04001433 /** Returns the geometry as SkPath equivalent to the drawn text.
1434 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1435 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1436 All of the glyph paths are stored in path.
Cary Clark579985c2017-07-31 11:48:27 -04001437 Uses x, y, and SkPaint::Align to position path.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001438
1439 @param text character codes or glyph indices
1440 @param length number of bytes of text
1441 @param x x-coordinate of the origin of the text
1442 @param y y-coordinate of the origin of the text
1443 @param path geometry of the glyphs
1444 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001445 void getTextPath(const void* text, size_t length, SkScalar x, SkScalar y,
1446 SkPath* path) const;
1447
Cary Clark50fa3ff2017-07-26 10:15:23 -04001448 /** Returns the geometry as SkPath equivalent to the drawn text.
1449 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1450 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1451 All of the glyph paths are stored in path.
1452 Uses pos array and SkPaint::Align to position path.
1453 pos contains a position for each glyph.
1454
1455 @param text character codes or glyph indices
1456 @param length number of bytes of text
1457 @param pos positions of each glyph
1458 @param path geometry of the glyphs
1459 */
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001460 void getPosTextPath(const void* text, size_t length,
reed@google.comca0062e2012-07-20 11:20:32 +00001461 const SkPoint pos[], SkPath* path) const;
1462
Cary Clark50fa3ff2017-07-26 10:15:23 -04001463 /** Returns the number of intervals that intersect bounds.
1464 bounds describes a pair of lines parallel to the text advance.
1465 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1466 the string.
1467 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1468 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1469 Uses x, y, and SkPaint::Align to position intervals.
1470
1471 Pass nullptr for intervals to determine the size of the interval array.
1472
1473 intervals are cached to improve performance for multiple calls.
1474
1475 @param text character codes or glyph indices
1476 @param length number of bytes of text
1477 @param x x-coordinate of the origin of the text
1478 @param y y-coordinate of the origin of the text
1479 @param bounds lower and upper line parallel to the advance
1480 @param intervals returned intersections; may be nullptr
1481 @return number of intersections; may be zero
1482 */
caryclark0449bcf2016-02-09 13:25:45 -08001483 int getTextIntercepts(const void* text, size_t length, SkScalar x, SkScalar y,
1484 const SkScalar bounds[2], SkScalar* intervals) const;
1485
Cary Clark50fa3ff2017-07-26 10:15:23 -04001486 /** Returns the number of intervals that intersect bounds.
1487 bounds describes a pair of lines parallel to the text advance.
1488 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1489 the string.
1490 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1491 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1492 Uses pos array and SkPaint::Align to position intervals.
1493
1494 Pass nullptr for intervals to determine the size of the interval array.
1495
1496 intervals are cached to improve performance for multiple calls.
1497
1498 @param text character codes or glyph indices
1499 @param length number of bytes of text
1500 @param pos positions of each glyph
1501 @param bounds lower and upper line parallel to the advance
1502 @param intervals returned intersections; may be nullptr
1503 @return The number of intersections; may be zero
1504 */
caryclark0449bcf2016-02-09 13:25:45 -08001505 int getPosTextIntercepts(const void* text, size_t length, const SkPoint pos[],
1506 const SkScalar bounds[2], SkScalar* intervals) const;
1507
Cary Clark50fa3ff2017-07-26 10:15:23 -04001508 /** Returns the number of intervals that intersect bounds.
1509 bounds describes a pair of lines parallel to the text advance.
1510 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1511 the string.
1512 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1513 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1514 Uses xpos array, constY, and SkPaint::Align to position intervals.
1515
1516 Pass nullptr for intervals to determine the size of the interval array.
1517
1518 intervals are cached to improve performance for multiple calls.
1519
1520 @param text character codes or glyph indices
1521 @param length number of bytes of text
1522 @param xpos positions of each glyph in x
1523 @param constY position of each glyph in y
1524 @param bounds lower and upper line parallel to the advance
1525 @param intervals returned intersections; may be nullptr
1526 @return number of intersections; may be zero
1527 */
fmalitaeae6a912016-07-28 09:47:24 -07001528 int getPosTextHIntercepts(const void* text, size_t length, const SkScalar xpos[],
1529 SkScalar constY, const SkScalar bounds[2], SkScalar* intervals) const;
1530
Cary Clark50fa3ff2017-07-26 10:15:23 -04001531 /** Returns the number of intervals that intersect bounds.
1532 bounds describes a pair of lines parallel to the text advance.
1533 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1534 the string.
1535 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1536 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1537 Uses pos array and SkPaint::Align to position intervals.
1538
1539 Pass nullptr for intervals to determine the size of the interval array.
1540
1541 intervals are cached to improve performance for multiple calls.
1542
1543 @param blob glyphs, positions, and text paint attributes
1544 @param bounds lower and upper line parallel to the advance
1545 @param intervals returned intersections; may be nullptr
1546 @return number of intersections; may be zero
1547 */
fmalitaeae6a912016-07-28 09:47:24 -07001548 int getTextBlobIntercepts(const SkTextBlob* blob, const SkScalar bounds[2],
1549 SkScalar* intervals) const;
1550
Cary Clark50fa3ff2017-07-26 10:15:23 -04001551 /** Returns the union of bounds of all glyphs.
1552 Returned dimensions are computed by font manager from font data,
Cary Clark579985c2017-07-31 11:48:27 -04001553 ignoring SkPaint::Hinting. Includes text size, text scale x,
Cary Clark50fa3ff2017-07-26 10:15:23 -04001554 and text skew x, but not fake bold or SkPathEffect.
1555
1556 If text size is large, text scale x is one, and text skew x is zero,
Cary Clark579985c2017-07-31 11:48:27 -04001557 returns the same bounds as SkPaint::FontMetrics { FontMetrics::fXMin,
Cary Clark50fa3ff2017-07-26 10:15:23 -04001558 FontMetrics::fTop, FontMetrics::fXMax, FontMetrics::fBottom }.
1559
1560 @return union of bounds of all glyphs
1561 */
reed8893e5f2014-12-15 13:27:26 -08001562 SkRect getFontBounds() const;
1563
Cary Clark579985c2017-07-31 11:48:27 -04001564 /** Returns true if SkPaint prevents all drawing;
1565 otherwise, the SkPaint may or may not allow drawing.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001566
1567 Returns true if SkBlendMode and alpha are enabled,
1568 and computed alpha is zero.
1569
1570 @return true if SkPaint prevents all drawing
1571 */
reed@google.com632e1a22011-10-06 12:37:00 +00001572 bool nothingToDraw() const;
1573
Cary Clark50fa3ff2017-07-26 10:15:23 -04001574 /** (to be made private)
1575 Returns true if SkPaint does not include elements requiring extensive computation
1576 to compute SkBaseDevice bounds of drawn geometry. For instance, SkPaint with SkPathEffect
1577 always returns false.
reed@google.comd5f20792012-05-16 14:15:02 +00001578
Cary Clark50fa3ff2017-07-26 10:15:23 -04001579 @return true if SkPaint allows for fast computation of bounds
1580 */
senorblanco0abdf762015-08-20 11:10:41 -07001581 bool canComputeFastBounds() const;
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001582
Cary Clark50fa3ff2017-07-26 10:15:23 -04001583 /** (to be made private)
Cary Clark579985c2017-07-31 11:48:27 -04001584 Only call this if canComputeFastBounds() returned true. This takes a
Cary Clark50fa3ff2017-07-26 10:15:23 -04001585 raw rectangle (the raw bounds of a shape), and adjusts it for stylistic
1586 effects in the paint (e.g. stroking). If needed, it uses the storage
1587 rect parameter. It returns the adjusted bounds that can then be used
1588 for SkCanvas::quickReject tests.
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001589
Cary Clark50fa3ff2017-07-26 10:15:23 -04001590 The returned rect will either be orig or storage, thus the caller
1591 should not rely on storage being set to the result, but should always
1592 use the retured value. It is legal for orig and storage to be the same
1593 rect.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001594 e.g.
1595 if (paint.canComputeFastBounds()) {
1596 SkRect r, storage;
1597 path.computeBounds(&r, SkPath::kFast_BoundsType);
1598 const SkRect& fastR = paint.computeFastBounds(r, &storage);
1599 if (canvas->quickReject(fastR, ...)) {
1600 // don't draw the path
1601 }
1602 }
1603
1604 @param orig geometry modified by SkPaint when drawn
1605 @param storage computed bounds of geometry; may not be nullptr
1606 @return fast computed bounds
1607 */
reed@google.coma584aed2012-05-16 14:06:02 +00001608 const SkRect& computeFastBounds(const SkRect& orig, SkRect* storage) const {
Brian Osman60751d72017-05-12 11:21:36 -04001609 // Things like stroking, etc... will do math on the bounds rect, assuming that it's sorted.
1610 SkASSERT(orig.isSorted());
reed@google.coma584aed2012-05-16 14:06:02 +00001611 SkPaint::Style style = this->getStyle();
1612 // ultra fast-case: filling with no effects that affect geometry
1613 if (kFill_Style == style) {
1614 uintptr_t effects = reinterpret_cast<uintptr_t>(this->getLooper());
1615 effects |= reinterpret_cast<uintptr_t>(this->getMaskFilter());
1616 effects |= reinterpret_cast<uintptr_t>(this->getPathEffect());
senorblanco@chromium.org336d1d72014-01-27 21:03:17 +00001617 effects |= reinterpret_cast<uintptr_t>(this->getImageFilter());
reed@google.coma584aed2012-05-16 14:06:02 +00001618 if (!effects) {
1619 return orig;
1620 }
1621 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001622
reed@google.coma584aed2012-05-16 14:06:02 +00001623 return this->doComputeFastBounds(orig, storage, style);
1624 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001625
Cary Clark50fa3ff2017-07-26 10:15:23 -04001626 /** (to be made private)
1627
1628 @param orig geometry modified by SkPaint when drawn
1629 @param storage computed bounds of geometry
1630 @return fast computed bounds
1631 */
reed@google.coma584aed2012-05-16 14:06:02 +00001632 const SkRect& computeFastStrokeBounds(const SkRect& orig,
1633 SkRect* storage) const {
reed@google.com73a02582012-05-16 19:21:12 +00001634 return this->doComputeFastBounds(orig, storage, kStroke_Style);
reed@google.coma584aed2012-05-16 14:06:02 +00001635 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001636
Cary Clark50fa3ff2017-07-26 10:15:23 -04001637 /** (to be made private)
1638 Take the style explicitly, so the caller can force us to be stroked
1639 without having to make a copy of the paint just to change that field.
1640
1641 @param orig geometry modified by SkPaint when drawn
1642 @param storage computed bounds of geometry
1643 @param style overrides SkPaint::Style
1644 @return fast computed bounds
1645 */
reed@google.coma584aed2012-05-16 14:06:02 +00001646 const SkRect& doComputeFastBounds(const SkRect& orig, SkRect* storage,
Cary Clark0418a882017-05-10 09:07:42 -04001647 Style style) const;
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001648
Cary Clark23890a92017-07-27 16:30:51 -04001649 /** macro expands to: void toString(SkString* str) const;
Cary Clark50fa3ff2017-07-26 10:15:23 -04001650 Converts SkPaint to machine parsable form in developer mode.
Cary Clark0418a882017-05-10 09:07:42 -04001651
Cary Clark50fa3ff2017-07-26 10:15:23 -04001652 @param str storage for string containing parsable SkPaint
1653 */
commit-bot@chromium.org0f10f7b2014-03-13 18:02:17 +00001654 SK_TO_STRING_NONVIRT()
robertphillips@google.com791f12e2013-02-14 13:53:53 +00001655
reed@google.comd5f20792012-05-16 14:15:02 +00001656private:
Cary Clark0418a882017-05-10 09:07:42 -04001657 typedef const SkGlyph& (*GlyphCacheProc)(SkGlyphCache*, const char**);
1658
reeda5ab9ec2016-03-06 18:10:48 -08001659 sk_sp<SkTypeface> fTypeface;
1660 sk_sp<SkPathEffect> fPathEffect;
1661 sk_sp<SkShader> fShader;
reeda5ab9ec2016-03-06 18:10:48 -08001662 sk_sp<SkMaskFilter> fMaskFilter;
1663 sk_sp<SkColorFilter> fColorFilter;
1664 sk_sp<SkRasterizer> fRasterizer;
reed46f2d0a2016-09-11 05:40:31 -07001665 sk_sp<SkDrawLooper> fDrawLooper;
reeda5ab9ec2016-03-06 18:10:48 -08001666 sk_sp<SkImageFilter> fImageFilter;
reed@google.comd5f20792012-05-16 14:15:02 +00001667
commit-bot@chromium.orge8807f42014-03-24 23:03:11 +00001668 SkScalar fTextSize;
1669 SkScalar fTextScaleX;
1670 SkScalar fTextSkewX;
reed@google.comd5f20792012-05-16 14:15:02 +00001671 SkColor fColor;
1672 SkScalar fWidth;
1673 SkScalar fMiterLimit;
Mike Reed71fecc32016-11-18 17:19:54 -05001674 uint32_t fBlendMode; // just need 5-6 bits
commit-bot@chromium.orgaca1c012014-02-21 18:18:05 +00001675 union {
1676 struct {
1677 // all of these bitfields should add up to 32
1678 unsigned fFlags : 16;
1679 unsigned fTextAlign : 2;
1680 unsigned fCapType : 2;
1681 unsigned fJoinType : 2;
1682 unsigned fStyle : 2;
1683 unsigned fTextEncoding : 2; // 3 values
1684 unsigned fHinting : 2;
reedf803da12015-01-23 05:58:07 -08001685 unsigned fFilterQuality : 2;
commit-bot@chromium.org85faf502014-04-16 12:58:02 +00001686 //unsigned fFreeBits : 2;
reedf59eab22014-07-14 14:39:15 -07001687 } fBitfields;
1688 uint32_t fBitfieldsUInt;
commit-bot@chromium.orgaca1c012014-02-21 18:18:05 +00001689 };
commit-bot@chromium.orge8807f42014-03-24 23:03:11 +00001690
robertphillipse34f17d2016-07-19 07:59:22 -07001691 static GlyphCacheProc GetGlyphCacheProc(TextEncoding encoding,
1692 bool isDevKern,
1693 bool needFullMetrics);
reed@google.comd5f20792012-05-16 14:15:02 +00001694
1695 SkScalar measure_text(SkGlyphCache*, const char* text, size_t length,
1696 int* count, SkRect* bounds) const;
1697
brianosmana1e8f8d2016-04-08 06:47:54 -07001698 enum ScalerContextFlags : uint32_t {
1699 kNone_ScalerContextFlags = 0,
1700
1701 kFakeGamma_ScalerContextFlag = 1 << 0,
1702 kBoostContrast_ScalerContextFlag = 1 << 1,
1703
1704 kFakeGammaAndBoostContrast_ScalerContextFlags =
1705 kFakeGamma_ScalerContextFlag | kBoostContrast_ScalerContextFlag,
bungemanf6d1e602016-02-22 13:20:28 -08001706 };
1707
joshualittfd450792015-03-13 08:38:43 -07001708 /*
1709 * Allocs an SkDescriptor on the heap and return it to the caller as a refcnted
1710 * SkData. Caller is responsible for managing the lifetime of this object.
1711 */
reeda9322c22016-04-12 06:47:05 -07001712 void getScalerContextDescriptor(SkScalerContextEffects*, SkAutoDescriptor*,
1713 const SkSurfaceProps& surfaceProps,
brianosmana1e8f8d2016-04-08 06:47:54 -07001714 uint32_t scalerContextFlags, const SkMatrix*) const;
joshualittfd450792015-03-13 08:38:43 -07001715
brianosmana1e8f8d2016-04-08 06:47:54 -07001716 SkGlyphCache* detachCache(const SkSurfaceProps* surfaceProps, uint32_t scalerContextFlags,
bungemanf6d1e602016-02-22 13:20:28 -08001717 const SkMatrix*) const;
reed@google.comd5f20792012-05-16 14:15:02 +00001718
brianosmana1e8f8d2016-04-08 06:47:54 -07001719 void descriptorProc(const SkSurfaceProps* surfaceProps, uint32_t scalerContextFlags,
bungemanf6d1e602016-02-22 13:20:28 -08001720 const SkMatrix* deviceMatrix,
reeda9322c22016-04-12 06:47:05 -07001721 void (*proc)(SkTypeface*, const SkScalerContextEffects&,
1722 const SkDescriptor*, void*),
bungemanf6d1e602016-02-22 13:20:28 -08001723 void* context) const;
reed@android.comd252db02009-04-01 18:31:44 +00001724
joshualitt9e36c1a2015-04-14 12:17:27 -07001725 /*
1726 * The luminance color is used to determine which Gamma Canonical color to map to. This is
1727 * really only used by backends which want to cache glyph masks, and need some way to know if
1728 * they need to generate new masks based off a given color.
1729 */
1730 SkColor computeLuminanceColor() const;
1731
reed@android.com8a1c16f2008-12-17 15:59:43 +00001732 enum {
reed@google.comed43dff2013-06-04 16:56:27 +00001733 /* This is the size we use when we ask for a glyph's path. We then
1734 * post-transform it as we draw to match the request.
1735 * This is done to try to re-use cache entries for the path.
1736 *
1737 * This value is somewhat arbitrary. In theory, it could be 1, since
1738 * we store paths as floats. However, we get the path from the font
1739 * scaler, and it may represent its paths as fixed-point (or 26.6),
1740 * so we shouldn't ask for something too big (might overflow 16.16)
1741 * or too small (underflow 26.6).
1742 *
1743 * This value could track kMaxSizeForGlyphCache, assuming the above
1744 * constraints, but since we ask for unhinted paths, the two values
1745 * need not match per-se.
1746 */
1747 kCanonicalTextSizeForPaths = 64,
reed@android.com8a1c16f2008-12-17 15:59:43 +00001748 };
reed@google.comed43dff2013-06-04 16:56:27 +00001749
1750 static bool TooBigToUseCache(const SkMatrix& ctm, const SkMatrix& textM);
1751
reed@google.comed43dff2013-06-04 16:56:27 +00001752 // Set flags/hinting/textSize up to use for drawing text as paths.
1753 // Returns scale factor to restore the original textSize, since will will
1754 // have change it to kCanonicalTextSizeForPaths.
1755 SkScalar setupForAsPaths();
1756
Mike Reedd5bee5d2017-06-01 14:45:44 -04001757 static SkScalar MaxCacheSize2();
reed@google.comed43dff2013-06-04 16:56:27 +00001758
vandebo@chromium.org28be72b2010-11-11 21:37:00 +00001759 friend class SkAutoGlyphCache;
jvanverth2d2a68c2014-06-10 06:42:56 -07001760 friend class SkAutoGlyphCacheNoGamma;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001761 friend class SkCanvas;
1762 friend class SkDraw;
vandebo@chromium.org28be72b2010-11-11 21:37:00 +00001763 friend class SkPDFDevice;
joshualitte76b4bb2015-12-28 07:23:58 -08001764 friend class GrAtlasTextBlob;
joshualittdbd35932015-04-02 09:19:04 -07001765 friend class GrAtlasTextContext;
kkinnunenc6cb56f2014-06-24 00:12:27 -07001766 friend class GrStencilAndCoverTextContext;
cdalton855d83f2014-09-18 13:51:53 -07001767 friend class GrPathRendering;
joshualitt0a42e682015-12-10 13:20:58 -08001768 friend class GrTextUtils;
cdalton855d83f2014-09-18 13:51:53 -07001769 friend class GrGLPathRendering;
joshualitt9e36c1a2015-04-14 12:17:27 -07001770 friend class SkScalerContext;
caryclark0449bcf2016-02-09 13:25:45 -08001771 friend class SkTextBaseIter;
reed@google.comed43dff2013-06-04 16:56:27 +00001772 friend class SkCanonicalizePaint;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001773};
1774
reed@android.com8a1c16f2008-12-17 15:59:43 +00001775#endif