blob: 85c2e3b2f78d6911c55b734cc8700be807ff376f [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 SkColorFilter;
joshualittfd450792015-03-13 08:38:43 -070019class SkData;
reed@android.com8a1c16f2008-12-17 15:59:43 +000020class SkDescriptor;
senorblanco0abdf762015-08-20 11:10:41 -070021class SkDrawLooper;
herbb69d0e02015-02-25 06:47:06 -080022class SkGlyph;
reed@android.com8a1c16f2008-12-17 15:59:43 +000023struct SkRect;
24class SkGlyphCache;
reed@google.com15356a62011-11-03 19:29:08 +000025class SkImageFilter;
reed@android.com8a1c16f2008-12-17 15:59:43 +000026class SkMaskFilter;
reed@android.com8a1c16f2008-12-17 15:59:43 +000027class SkPath;
28class SkPathEffect;
djsollen@google.comc73dd5c2012-08-07 15:54:32 +000029struct SkPoint;
reed@android.com8a1c16f2008-12-17 15:59:43 +000030class SkShader;
robertphillipsfcf78292015-06-19 11:49:52 -070031class SkSurfaceProps;
fmalitaeae6a912016-07-28 09:47:24 -070032class SkTextBlob;
reed@android.com8a1c16f2008-12-17 15:59:43 +000033class SkTypeface;
reed@android.com8a1c16f2008-12-17 15:59:43 +000034
reed@android.com8a1c16f2008-12-17 15:59:43 +000035/** \class SkPaint
Cary Clark50fa3ff2017-07-26 10:15:23 -040036 SkPaint controls options applied when drawing and measuring. SkPaint collects all
37 options outside of the SkCanvas clip and SkCanvas matrix.
reed@android.com8a1c16f2008-12-17 15:59:43 +000038
Cary Clark50fa3ff2017-07-26 10:15:23 -040039 Various options apply to text, strokes and fills, and images.
40
41 Some options may not be implemented on all platforms; in these cases, setting
42 the option has no effect. Some options are conveniences that duplicate SkCanvas
43 functionality; for instance, text size is identical to matrix scale.
44
45 SkPaint options are rarely exclusive; each option modifies a stage of the drawing
Cary Clark23890a92017-07-27 16:30:51 -040046 pipeline and multiple pipeline stages may be affected by a single SkPaint.
Cary Clark50fa3ff2017-07-26 10:15:23 -040047
Cary Clark23890a92017-07-27 16:30:51 -040048 SkPaint collects effects and filters that describe single-pass and multiple-pass
Cary Clark50fa3ff2017-07-26 10:15:23 -040049 algorithms that alter the drawing geometry, color, and transparency. For instance,
50 SkPaint does not directly implement dashing or blur, but contains the objects that do so.
51
52 The objects contained by SkPaint are opaque, and cannot be edited outside of the SkPaint
53 to affect it. The implementation is free to defer computations associated with the
54 SkPaint, or ignore them altogether. For instance, some GPU implementations draw all
Cary Clarkb7da7232017-09-01 13:49:54 -040055 SkPath geometries with anti-aliasing, regardless of how SkPaint::kAntiAlias_Flag
56 is set in SkPaint.
Cary Clark50fa3ff2017-07-26 10:15:23 -040057
58 SkPaint describes a single color, a single font, a single image quality, and so on.
59 Multiple colors are drawn either by using multiple paints or with objects like
60 SkShader attached to SkPaint.
reed@android.com8a1c16f2008-12-17 15:59:43 +000061*/
ctguil@chromium.org7ffb1b22011-03-15 21:27:08 +000062class SK_API SkPaint {
reed@android.com8a1c16f2008-12-17 15:59:43 +000063public:
Cary Clark50fa3ff2017-07-26 10:15:23 -040064
65 /** Constructs SkPaint with default values.
66
67 @return default initialized SkPaint
68 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000069 SkPaint();
Cary Clark50fa3ff2017-07-26 10:15:23 -040070
71 /** Makes a shallow copy of SkPaint. SkTypeface, SkPathEffect, SkShader,
Mike Reed8ad91a92018-01-19 19:09:32 -050072 SkMaskFilter, SkColorFilter, SkDrawLooper, and SkImageFilter are shared
Cary Clarkb7da7232017-09-01 13:49:54 -040073 between the original paint and the copy. Objects containing SkRefCnt increment
74 their references by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -040075
Mike Reed8ad91a92018-01-19 19:09:32 -050076 The referenced objects SkPathEffect, SkShader, SkMaskFilter, SkColorFilter,
Cary Clark50fa3ff2017-07-26 10:15:23 -040077 SkDrawLooper, and SkImageFilter cannot be modified after they are created.
78 This prevents objects with SkRefCnt from being modified once SkPaint refers to them.
79
80 @param paint original to copy
81 @return shallow copy of paint
82 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000083 SkPaint(const SkPaint& paint);
Cary Clark50fa3ff2017-07-26 10:15:23 -040084
Cary Clark8a02b0b2017-09-21 12:28:43 -040085 /** Implements a move constructor to avoid increasing the reference counts
Cary Clark50fa3ff2017-07-26 10:15:23 -040086 of objects referenced by the paint.
87
88 After the call, paint is undefined, and can be safely destructed.
89
90 @param paint original to move
91 @return content of paint
92 */
bungemanccce0e02016-02-07 14:37:23 -080093 SkPaint(SkPaint&& paint);
Cary Clark50fa3ff2017-07-26 10:15:23 -040094
95 /** Decreases SkPaint SkRefCnt of owned objects: SkTypeface, SkPathEffect, SkShader,
Mike Reed8ad91a92018-01-19 19:09:32 -050096 SkMaskFilter, SkColorFilter, SkDrawLooper, and SkImageFilter. If the
Cary Clarkb7da7232017-09-01 13:49:54 -040097 objects containing SkRefCnt go to zero, they are deleted.
Cary Clark50fa3ff2017-07-26 10:15:23 -040098 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000099 ~SkPaint();
100
Cary Clark50fa3ff2017-07-26 10:15:23 -0400101 /** Makes a shallow copy of SkPaint. SkTypeface, SkPathEffect, SkShader,
Mike Reed8ad91a92018-01-19 19:09:32 -0500102 SkMaskFilter, SkColorFilter, SkDrawLooper, and SkImageFilter are shared
Cary Clarkb7da7232017-09-01 13:49:54 -0400103 between the original paint and the copy. Objects containing SkRefCnt in the
Cary Clark50fa3ff2017-07-26 10:15:23 -0400104 prior destination are decreased by one, and the referenced objects are deleted if the
Cary Clarkb7da7232017-09-01 13:49:54 -0400105 resulting count is zero. Objects containing SkRefCnt in the parameter paint
106 are increased by one. paint is unmodified.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400107
108 @param paint original to copy
109 @return content of paint
110 */
Cary Clark0418a882017-05-10 09:07:42 -0400111 SkPaint& operator=(const SkPaint& paint);
Cary Clark50fa3ff2017-07-26 10:15:23 -0400112
Cary Clark8a02b0b2017-09-21 12:28:43 -0400113 /** Moves the paint to avoid increasing the reference counts
Cary Clarkb7da7232017-09-01 13:49:54 -0400114 of objects referenced by the paint parameter. Objects containing SkRefCnt in the
115 prior destination are decreased by one; those objects are deleted if the resulting count
116 is zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400117
118 After the call, paint is undefined, and can be safely destructed.
119
120 @param paint original to move
121 @return content of paint
122 */
Cary Clark0418a882017-05-10 09:07:42 -0400123 SkPaint& operator=(SkPaint&& paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000124
Cary Clark50fa3ff2017-07-26 10:15:23 -0400125 /** Compares a and b, and returns true if a and b are equivalent. May return false
Mike Reed8ad91a92018-01-19 19:09:32 -0500126 if SkTypeface, SkPathEffect, SkShader, SkMaskFilter, SkColorFilter,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400127 SkDrawLooper, or SkImageFilter have identical contents but different pointers.
128
129 @param a SkPaint to compare
130 @param b SkPaint to compare
131 @return true if SkPaint pair are equivalent
mtkleinbc97ef42014-08-25 10:10:47 -0700132 */
robertphillips@google.comb2657412013-08-07 22:36:29 +0000133 SK_API friend bool operator==(const SkPaint& a, const SkPaint& b);
Cary Clark50fa3ff2017-07-26 10:15:23 -0400134
135 /** Compares a and b, and returns true if a and b are not equivalent. May return true
Mike Reed8ad91a92018-01-19 19:09:32 -0500136 if SkTypeface, SkPathEffect, SkShader, SkMaskFilter, SkColorFilter,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400137 SkDrawLooper, or SkImageFilter have identical contents but different pointers.
138
139 @param a SkPaint to compare
140 @param b SkPaint to compare
141 @return true if SkPaint pair are not equivalent
142 */
robertphillips@google.comb2657412013-08-07 22:36:29 +0000143 friend bool operator!=(const SkPaint& a, const SkPaint& b) {
144 return !(a == b);
145 }
146
Cary Clark50fa3ff2017-07-26 10:15:23 -0400147 /** Returns a hash generated from SkPaint values and pointers.
148 Identical hashes guarantee that the paints are
149 equivalent, but differing hashes do not guarantee that the paints have differing
150 contents.
151
152 If operator==(const SkPaint& a, const SkPaint& b) returns true for two paints,
153 their hashes are also equal.
154
155 The hash returned is platform and implementation specific.
156
157 @return a shallow hash
158 */
mtkleinfb1fe4f2014-10-07 09:26:10 -0700159 uint32_t getHash() const;
160
Cary Clarkcc309eb2017-10-30 11:48:35 -0400161 /** Sets all SkPaint contents to their initial values. This is equivalent to replacing
162 SkPaint with the result of SkPaint().
reed@android.com8a1c16f2008-12-17 15:59:43 +0000163 */
164 void reset();
165
Cary Clark50fa3ff2017-07-26 10:15:23 -0400166 /** \enum SkPaint::Hinting
167 Hinting adjusts the glyph outlines so that the shape provides a uniform
168 look at a given point size on font engines that support it. Hinting may have a
169 muted effect or no effect at all depending on the platform.
170
171 The four levels roughly control corresponding features on platforms that use FreeType
172 as the font engine.
agl@chromium.org309485b2009-07-21 17:41:32 +0000173 */
174 enum Hinting {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400175 /** Leaves glyph outlines unchanged from their native representation.
176 With FreeType, this is equivalent to the FT_LOAD_NO_HINTING
177 bit-field constant supplied to FT_Load_Glyph, which indicates that the vector
178 outline being loaded should not be fitted to the pixel grid but simply scaled
179 to 26.6 fractional pixels.
180 */
181 kNo_Hinting = 0,
182
183 /** Modifies glyph outlines minimally to improve constrast.
184 With FreeType, this is equivalent in spirit to the
185 FT_LOAD_TARGET_LIGHT value supplied to FT_Load_Glyph. It chooses a
186 lighter hinting algorithm for non-monochrome modes.
187 Generated glyphs may be fuzzy but better resemble their original shape.
188 */
189 kSlight_Hinting = 1,
190
191 /** Modifies glyph outlines to improve constrast. This is the default.
192 With FreeType, this supplies FT_LOAD_TARGET_NORMAL to FT_Load_Glyph,
193 choosing the default hinting algorithm, which is optimized for standard
194 gray-level rendering.
195 */
196 kNormal_Hinting = 2,
197
198 /** Modifies glyph outlines for maxiumum constrast. With FreeType, this selects
199 FT_LOAD_TARGET_LCD or FT_LOAD_TARGET_LCD_V if kLCDRenderText_Flag is set.
200 FT_LOAD_TARGET_LCD is a variant of FT_LOAD_TARGET_NORMAL optimized for
201 horizontally decimated LCD displays; FT_LOAD_TARGET_LCD_V is a
202 variant of FT_LOAD_TARGET_NORMAL optimized for vertically decimated LCD displays.
203 */
204 kFull_Hinting = 3,
agl@chromium.org309485b2009-07-21 17:41:32 +0000205 };
206
Cary Clark50fa3ff2017-07-26 10:15:23 -0400207 /** Returns level of glyph outline adjustment.
208
209 @return one of: kNo_Hinting, kSlight_Hinting, kNormal_Hinting, kFull_Hinting
210 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000211 Hinting getHinting() const {
reedf59eab22014-07-14 14:39:15 -0700212 return static_cast<Hinting>(fBitfields.fHinting);
agl@chromium.org309485b2009-07-21 17:41:32 +0000213 }
214
Cary Clark50fa3ff2017-07-26 10:15:23 -0400215 /** Sets level of glyph outline adjustment.
216 Does not check for valid values of hintingLevel.
217
218 @param hintingLevel one of: kNo_Hinting, kSlight_Hinting, kNormal_Hinting, kFull_Hinting
219 */
djsollen@google.comf5dbe2f2011-04-15 13:41:26 +0000220 void setHinting(Hinting hintingLevel);
agl@chromium.org309485b2009-07-21 17:41:32 +0000221
Cary Clark50fa3ff2017-07-26 10:15:23 -0400222 /** \enum SkPaint::Flags
223 The bit values stored in Flags.
224 The default value for Flags, normally zero, can be changed at compile time
225 with a custom definition of SkPaintDefaults_Flags.
226 All flags can be read and written explicitly; Flags allows manipulating
227 multiple settings at once.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000228 */
229 enum Flags {
Cary Clark1eace2d2017-07-31 07:52:43 -0400230 kAntiAlias_Flag = 0x01, //!< mask for setting anti-alias
231 kDither_Flag = 0x04, //!< mask for setting dither
Cary Clark50fa3ff2017-07-26 10:15:23 -0400232 kFakeBoldText_Flag = 0x20, //!< mask for setting fake bold
233 kLinearText_Flag = 0x40, //!< mask for setting linear text
234 kSubpixelText_Flag = 0x80, //!< mask for setting subpixel text
Cary Clark75959392018-02-27 10:22:04 -0500235 kLCDRenderText_Flag = 0x200, //!< mask for setting LCD text
Cary Clark50fa3ff2017-07-26 10:15:23 -0400236 kEmbeddedBitmapText_Flag = 0x400, //!< mask for setting font embedded bitmaps
237 kAutoHinting_Flag = 0x800, //!< mask for setting auto-hinting
238 kVerticalText_Flag = 0x1000, //!< mask for setting vertical text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000239
Cary Clark50fa3ff2017-07-26 10:15:23 -0400240 /** mask of all Flags, including private flags and flags reserved for future use */
241 kAllFlags = 0xFFFF,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000242 };
243
Cary Clark50fa3ff2017-07-26 10:15:23 -0400244 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Mike Reedddbd37e2017-02-21 15:07:44 -0500245 enum ReserveFlags {
Cary Clark75959392018-02-27 10:22:04 -0500246 kUnderlineText_ReserveFlag = 0x08, //!< deprecated
247 kStrikeThruText_ReserveFlag = 0x10, //!< deprecated
Mike Reedddbd37e2017-02-21 15:07:44 -0500248 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400249 #endif
Mike Reedddbd37e2017-02-21 15:07:44 -0500250
Cary Clark50fa3ff2017-07-26 10:15:23 -0400251 /** Returns paint settings described by SkPaint::Flags. Each setting uses one
252 bit, and can be tested with SkPaint::Flags members.
253
254 @return zero, one, or more bits described by SkPaint::Flags
reed@android.com8a1c16f2008-12-17 15:59:43 +0000255 */
reedf59eab22014-07-14 14:39:15 -0700256 uint32_t getFlags() const { return fBitfields.fFlags; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000257
Cary Clark23890a92017-07-27 16:30:51 -0400258 /** Replaces SkPaint::Flags with flags, the union of the SkPaint::Flags members.
259 All SkPaint::Flags members may be cleared, or one or more may be set.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400260
261 @param flags union of SkPaint::Flags for SkPaint
reed@android.com8a1c16f2008-12-17 15:59:43 +0000262 */
263 void setFlags(uint32_t flags);
264
Cary Clark50fa3ff2017-07-26 10:15:23 -0400265 /** If true, pixels on the active edges of SkPath may be drawn with partial transparency.
266
Cary Clark579985c2017-07-31 11:48:27 -0400267 Equivalent to getFlags() masked with kAntiAlias_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400268
269 @return kAntiAlias_Flag state
270 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000271 bool isAntiAlias() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000272 return SkToBool(this->getFlags() & kAntiAlias_Flag);
273 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000274
Cary Clark50fa3ff2017-07-26 10:15:23 -0400275 /** Requests, but does not require, that SkPath edge pixels draw opaque or with
276 partial transparency.
277
278 Sets kAntiAlias_Flag if aa is true.
279 Clears kAntiAlias_Flag if aa is false.
280
281 @param aa setting for kAntiAlias_Flag
282 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000283 void setAntiAlias(bool aa);
reed@google.com9d07fec2011-03-16 20:02:59 +0000284
Cary Clark50fa3ff2017-07-26 10:15:23 -0400285 /** If true, color error may be distributed to smooth color transition.
286
Cary Clark579985c2017-07-31 11:48:27 -0400287 Equivalent to getFlags() masked with kDither_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400288
289 @return kDither_Flag state
290 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000291 bool isDither() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000292 return SkToBool(this->getFlags() & kDither_Flag);
293 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000294
Cary Clark50fa3ff2017-07-26 10:15:23 -0400295 /** Requests, but does not require, to distribute color error.
296
297 Sets kDither_Flag if dither is true.
298 Clears kDither_Flag if dither is false.
299
300 @param dither setting for kDither_Flag
301 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000302 void setDither(bool dither);
reed@google.com9d07fec2011-03-16 20:02:59 +0000303
Cary Clark50fa3ff2017-07-26 10:15:23 -0400304 /** If true, text is converted to SkPath before drawing and measuring.
305
Cary Clark579985c2017-07-31 11:48:27 -0400306 Equivalent to getFlags() masked with kLinearText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400307
308 @return kLinearText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000309 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000310 bool isLinearText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000311 return SkToBool(this->getFlags() & kLinearText_Flag);
312 }
313
Cary Clark50fa3ff2017-07-26 10:15:23 -0400314 /** If true, text is converted to SkPath before drawing and measuring.
315 By default, kLinearText_Flag is clear.
316
317 Sets kLinearText_Flag if linearText is true.
318 Clears kLinearText_Flag if linearText is false.
319
320 @param linearText setting for kLinearText_Flag
reed@android.com8a1c16f2008-12-17 15:59:43 +0000321 */
322 void setLinearText(bool linearText);
323
Cary Clark50fa3ff2017-07-26 10:15:23 -0400324 /** If true, glyphs at different sub-pixel positions may differ on pixel edge coverage.
325
Cary Clark579985c2017-07-31 11:48:27 -0400326 Equivalent to getFlags() masked with kSubpixelText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400327
328 @return kSubpixelText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000329 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000330 bool isSubpixelText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000331 return SkToBool(this->getFlags() & kSubpixelText_Flag);
332 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000333
Cary Clark50fa3ff2017-07-26 10:15:23 -0400334 /** Requests, but does not require, that glyphs respect sub-pixel positioning.
335
336 Sets kSubpixelText_Flag if subpixelText is true.
337 Clears kSubpixelText_Flag if subpixelText is false.
338
339 @param subpixelText setting for kSubpixelText_Flag
340 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000341 void setSubpixelText(bool subpixelText);
agl@chromium.org309485b2009-07-21 17:41:32 +0000342
Cary Clark50fa3ff2017-07-26 10:15:23 -0400343 /** If true, glyphs may use LCD striping to improve glyph edges.
344
345 Returns true if SkPaint::Flags kLCDRenderText_Flag is set.
346
347 @return kLCDRenderText_Flag state
348 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000349 bool isLCDRenderText() const {
agl@chromium.org309485b2009-07-21 17:41:32 +0000350 return SkToBool(this->getFlags() & kLCDRenderText_Flag);
351 }
352
Cary Clark50fa3ff2017-07-26 10:15:23 -0400353 /** Requests, but does not require, that glyphs use LCD striping for glyph edges.
354
355 Sets kLCDRenderText_Flag if lcdText is true.
356 Clears kLCDRenderText_Flag if lcdText is false.
357
358 @param lcdText setting for kLCDRenderText_Flag
359 */
reed@google.com84b437e2011-08-01 12:45:35 +0000360 void setLCDRenderText(bool lcdText);
agl@chromium.org309485b2009-07-21 17:41:32 +0000361
Cary Clark50fa3ff2017-07-26 10:15:23 -0400362 /** If true, font engine may return glyphs from font bitmaps instead of from outlines.
363
Cary Clark579985c2017-07-31 11:48:27 -0400364 Equivalent to getFlags() masked with kEmbeddedBitmapText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400365
366 @return kEmbeddedBitmapText_Flag state
367 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000368 bool isEmbeddedBitmapText() const {
agl@chromium.orge95c91e2010-01-04 18:27:55 +0000369 return SkToBool(this->getFlags() & kEmbeddedBitmapText_Flag);
370 }
371
Cary Clark50fa3ff2017-07-26 10:15:23 -0400372 /** Requests, but does not require, to use bitmaps in fonts instead of outlines.
373
374 Sets kEmbeddedBitmapText_Flag if useEmbeddedBitmapText is true.
375 Clears kEmbeddedBitmapText_Flag if useEmbeddedBitmapText is false.
376
377 @param useEmbeddedBitmapText setting for kEmbeddedBitmapText_Flag
agl@chromium.orge95c91e2010-01-04 18:27:55 +0000378 */
379 void setEmbeddedBitmapText(bool useEmbeddedBitmapText);
380
Cary Clark50fa3ff2017-07-26 10:15:23 -0400381 /** If true, and if SkPaint::Hinting is set to kNormal_Hinting or kFull_Hinting, and if
382 platform uses FreeType as the font manager, instruct the font manager to always hint
Cary Clark1eace2d2017-07-31 07:52:43 -0400383 glyphs.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400384
Cary Clark579985c2017-07-31 11:48:27 -0400385 Equivalent to getFlags() masked with kAutoHinting_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400386
387 @return kAutoHinting_Flag state
388 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000389 bool isAutohinted() const {
agl@chromium.orga2c71cb2010-06-17 20:49:17 +0000390 return SkToBool(this->getFlags() & kAutoHinting_Flag);
391 }
392
Cary Clark50fa3ff2017-07-26 10:15:23 -0400393 /** If SkPaint::Hinting is set to kNormal_Hinting or kFull_Hinting and useAutohinter is set,
Cary Clark1eace2d2017-07-31 07:52:43 -0400394 instruct the font manager to always hint glyphs.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400395 auto-hinting has no effect if SkPaint::Hinting is set to kNo_Hinting or
396 kSlight_Hinting.
397
Cary Clark579985c2017-07-31 11:48:27 -0400398 Only affects platforms that use FreeType as the font manager.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400399
400 Sets kAutoHinting_Flag if useAutohinter is true.
401 Clears kAutoHinting_Flag if useAutohinter is false.
402
403 @param useAutohinter setting for kAutoHinting_Flag
agl@chromium.orga2c71cb2010-06-17 20:49:17 +0000404 */
405 void setAutohinted(bool useAutohinter);
406
Cary Clark50fa3ff2017-07-26 10:15:23 -0400407 /** If true, glyphs are drawn top to bottom instead of left to right.
408
Cary Clark579985c2017-07-31 11:48:27 -0400409 Equivalent to getFlags() masked with kVerticalText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400410
411 @return kVerticalText_Flag state
412 */
reed@google.com830a23e2011-11-10 15:20:49 +0000413 bool isVerticalText() const {
414 return SkToBool(this->getFlags() & kVerticalText_Flag);
415 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000416
Cary Clark50fa3ff2017-07-26 10:15:23 -0400417 /** If true, text advance positions the next glyph below the previous glyph instead of to the
418 right of previous glyph.
419
420 Sets kVerticalText_Flag if vertical is true.
421 Clears kVerticalText_Flag if vertical is false.
422
423 @param verticalText setting for kVerticalText_Flag
424 */
Cary Clark0418a882017-05-10 09:07:42 -0400425 void setVerticalText(bool verticalText);
reed@google.com830a23e2011-11-10 15:20:49 +0000426
Cary Clark50fa3ff2017-07-26 10:15:23 -0400427 /** If true, approximate bold by increasing the stroke width when creating glyph bitmaps
428 from outlines.
429
Cary Clark579985c2017-07-31 11:48:27 -0400430 Equivalent to getFlags() masked with kFakeBoldText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400431
432 @return kFakeBoldText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000433 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000434 bool isFakeBoldText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000435 return SkToBool(this->getFlags() & kFakeBoldText_Flag);
436 }
437
Cary Clarkb7da7232017-09-01 13:49:54 -0400438 /** Use increased stroke width when creating glyph bitmaps to approximate a bold typeface.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400439
440 Sets kFakeBoldText_Flag if fakeBoldText is true.
441 Clears kFakeBoldText_Flag if fakeBoldText is false.
442
443 @param fakeBoldText setting for kFakeBoldText_Flag
reed@android.com8a1c16f2008-12-17 15:59:43 +0000444 */
445 void setFakeBoldText(bool fakeBoldText);
446
Cary Clark50fa3ff2017-07-26 10:15:23 -0400447 /** Returns if character spacing may be adjusted by the hinting difference.
448
Cary Clark579985c2017-07-31 11:48:27 -0400449 Equivalent to getFlags() masked with kDevKernText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400450
451 @return kDevKernText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000452 */
Herb Derbyfcac00f2018-05-01 11:57:56 -0400453 bool isDevKernText() const { return false; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000454
Cary Clark50fa3ff2017-07-26 10:15:23 -0400455 /** Requests, but does not require, to use hinting to adjust glyph spacing.
456
457 Sets kDevKernText_Flag if devKernText is true.
458 Clears kDevKernText_Flag if devKernText is false.
459
460 @param devKernText setting for devKernText
reed@android.com8a1c16f2008-12-17 15:59:43 +0000461 */
Herb Derbyfcac00f2018-05-01 11:57:56 -0400462 void setDevKernText(bool) { }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000463
Cary Clark50fa3ff2017-07-26 10:15:23 -0400464 /** Returns SkFilterQuality, the image filtering level. A lower setting
465 draws faster; a higher setting looks better when the image is scaled.
466
467 @return one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
468 kMedium_SkFilterQuality, kHigh_SkFilterQuality
469 */
reedf803da12015-01-23 05:58:07 -0800470 SkFilterQuality getFilterQuality() const {
471 return (SkFilterQuality)fBitfields.fFilterQuality;
472 }
mtkleinfe81e2d2015-09-09 07:35:42 -0700473
Cary Clark23890a92017-07-27 16:30:51 -0400474 /** Sets SkFilterQuality, the image filtering level. A lower setting
Cary Clark50fa3ff2017-07-26 10:15:23 -0400475 draws faster; a higher setting looks better when the image is scaled.
Cary Clark579985c2017-07-31 11:48:27 -0400476 Does not check to see if quality is valid.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400477
478 @param quality one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
479 kMedium_SkFilterQuality, kHigh_SkFilterQuality
480 */
reedf803da12015-01-23 05:58:07 -0800481 void setFilterQuality(SkFilterQuality quality);
reed@google.comc9683152013-07-18 13:47:01 +0000482
Cary Clark50fa3ff2017-07-26 10:15:23 -0400483 /** \enum SkPaint::Style
Cary Clark23890a92017-07-27 16:30:51 -0400484 Set Style to fill, stroke, or both fill and stroke geometry.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400485 The stroke and fill
486 share all paint attributes; for instance, they are drawn with the same color.
reed@google.com9d07fec2011-03-16 20:02:59 +0000487
Cary Clark50fa3ff2017-07-26 10:15:23 -0400488 Use kStrokeAndFill_Style to avoid hitting the same pixels twice with a stroke draw and
489 a fill draw.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000490 */
491 enum Style {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400492 /** Set to fill geometry.
Cary Clark1eace2d2017-07-31 07:52:43 -0400493 Applies to SkRect, SkRegion, SkRRect, circles, ovals, SkPath, and text.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400494 SkBitmap, SkImage, patches, SkRegion, sprites, and vertices are painted as if
495 kFill_Style is set, and ignore the set Style.
496 The FillType specifies additional rules to fill the area outside the path edge,
497 and to create an unfilled hole inside the shape.
498 Style is set to kFill_Style by default.
499 */
500 kFill_Style,
501
502 /** Set to stroke geometry.
Cary Clarkb7da7232017-09-01 13:49:54 -0400503 Applies to SkRect, SkRegion, SkRRect, arcs, circles, ovals, SkPath, and text.
Cary Clark2823f9f2018-01-03 10:00:34 -0500504 Arcs, lines, and points, are always drawn as if kStroke_Style is set,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400505 and ignore the set Style.
506 The stroke construction is unaffected by the FillType.
507 */
508 kStroke_Style,
509
510 /** Set to stroke and fill geometry.
Cary Clark1eace2d2017-07-31 07:52:43 -0400511 Applies to SkRect, SkRegion, SkRRect, circles, ovals, SkPath, and text.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400512 SkPath is treated as if it is set to SkPath::kWinding_FillType,
513 and the set FillType is ignored.
514 */
515 kStrokeAndFill_Style,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000516 };
517
Cary Clarkd98f78c2018-04-26 08:32:37 -0400518 /** The number of different Style values defined.
519 May be used to verify that Style is a legal value.
520 */
521 static constexpr int kStyleCount = kStrokeAndFill_Style + 1;
Cary Clark50fa3ff2017-07-26 10:15:23 -0400522
523 /** Whether the geometry is filled, stroked, or filled and stroked.
524
525 @return one of:kFill_Style, kStroke_Style, kStrokeAndFill_Style
reed@android.com8a1c16f2008-12-17 15:59:43 +0000526 */
reedf59eab22014-07-14 14:39:15 -0700527 Style getStyle() const { return (Style)fBitfields.fStyle; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000528
Cary Clark50fa3ff2017-07-26 10:15:23 -0400529 /** Sets whether the geometry is filled, stroked, or filled and stroked.
530 Has no effect if style is not a legal SkPaint::Style value.
531
532 @param style one of: kFill_Style, kStroke_Style, kStrokeAndFill_Style
reed@android.com8a1c16f2008-12-17 15:59:43 +0000533 */
534 void setStyle(Style style);
535
Cary Clark50fa3ff2017-07-26 10:15:23 -0400536 /** Retrieves alpha and RGB, unpremultiplied, packed into 32 bits.
537 Use helpers SkColorGetA(), SkColorGetR(), SkColorGetG(), and SkColorGetB() to extract
538 a color component.
539
Cary Clark8a02b0b2017-09-21 12:28:43 -0400540 @return unpremultiplied ARGB
reed@android.com8a1c16f2008-12-17 15:59:43 +0000541 */
542 SkColor getColor() const { return fColor; }
543
Cary Clark50fa3ff2017-07-26 10:15:23 -0400544 /** Sets alpha and RGB used when stroking and filling. The color is a 32-bit value,
Cary Clarkb7da7232017-09-01 13:49:54 -0400545 unpremultiplied, packing 8-bit components for alpha, red, blue, and green.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400546
Cary Clark8a02b0b2017-09-21 12:28:43 -0400547 @param color unpremultiplied ARGB
reed@android.com8a1c16f2008-12-17 15:59:43 +0000548 */
549 void setColor(SkColor color);
550
Cary Clark1eace2d2017-07-31 07:52:43 -0400551 /** Retrieves alpha from the color used when stroking and filling.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400552
Cary Clark8a02b0b2017-09-21 12:28:43 -0400553 @return alpha ranging from zero, fully transparent, to 255, fully opaque
Cary Clark50fa3ff2017-07-26 10:15:23 -0400554 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000555 uint8_t getAlpha() const { return SkToU8(SkColorGetA(fColor)); }
reed@google.com9d07fec2011-03-16 20:02:59 +0000556
Cary Clark50fa3ff2017-07-26 10:15:23 -0400557 /** Replaces alpha, leaving RGB
558 unchanged. An out of range value triggers an assert in the debug
559 build. a is a value from zero to 255.
Cary Clark1eace2d2017-07-31 07:52:43 -0400560 a set to zero makes color fully transparent; a set to 255 makes color
Cary Clark50fa3ff2017-07-26 10:15:23 -0400561 fully opaque.
562
Cary Clark8a02b0b2017-09-21 12:28:43 -0400563 @param a alpha component of color
reed@android.com8a1c16f2008-12-17 15:59:43 +0000564 */
565 void setAlpha(U8CPU a);
566
Cary Clark1eace2d2017-07-31 07:52:43 -0400567 /** Sets color used when drawing solid fills. The color components range from 0 to 255.
Cary Clarkb7da7232017-09-01 13:49:54 -0400568 The color is unpremultiplied; alpha sets the transparency independent of RGB.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400569
Cary Clarkb7da7232017-09-01 13:49:54 -0400570 @param a amount of color alpha, from fully transparent (0) to fully opaque (255)
571 @param r amount of color rgb red, from no red (0) to full red (255)
572 @param g amount of color rgb green, from no green (0) to full green (255)
573 @param b amount of color rgb blue, from no blue (0) to full blue (255)
reed@android.com8a1c16f2008-12-17 15:59:43 +0000574 */
575 void setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b);
576
Cary Clark50fa3ff2017-07-26 10:15:23 -0400577 /** Returns the thickness of the pen used by SkPaint to
578 outline the shape.
579
Cary Clark1eace2d2017-07-31 07:52:43 -0400580 @return zero for hairline, greater than zero for pen thickness
reed@android.com8a1c16f2008-12-17 15:59:43 +0000581 */
582 SkScalar getStrokeWidth() const { return fWidth; }
583
Cary Clark50fa3ff2017-07-26 10:15:23 -0400584 /** Sets the thickness of the pen used by the paint to
585 outline the shape.
586 Has no effect if width is less than zero.
587
Cary Clark1eace2d2017-07-31 07:52:43 -0400588 @param width zero thickness for hairline; greater than zero for pen thickness
reed@android.com8a1c16f2008-12-17 15:59:43 +0000589 */
590 void setStrokeWidth(SkScalar width);
591
Cary Clark50fa3ff2017-07-26 10:15:23 -0400592 /** The limit at which a sharp corner is drawn beveled.
593
594 @return zero and greater miter limit
reed@android.com8a1c16f2008-12-17 15:59:43 +0000595 */
596 SkScalar getStrokeMiter() const { return fMiterLimit; }
597
Cary Clark50fa3ff2017-07-26 10:15:23 -0400598 /** The limit at which a sharp corner is drawn beveled.
599 Valid values are zero and greater.
600 Has no effect if miter is less than zero.
601
602 @param miter zero and greater miter limit
reed@android.com8a1c16f2008-12-17 15:59:43 +0000603 */
604 void setStrokeMiter(SkScalar miter);
605
Cary Clark50fa3ff2017-07-26 10:15:23 -0400606 /** \enum SkPaint::Cap
607 Cap draws at the beginning and end of an open path contour.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000608 */
609 enum Cap {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400610 kButt_Cap, //!< Does not extend the stroke past the beginning or the end.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000611
Cary Clark50fa3ff2017-07-26 10:15:23 -0400612 /** Adds a circle with a diameter equal to stroke width at the beginning
613 and end.
614 */
615 kRound_Cap,
616
617 /** Adds a square with sides equal to stroke width at the beginning
618 and end. The square sides are parallel to the initial and final direction
619 of the stroke.
620 */
621 kSquare_Cap,
622 kLast_Cap = kSquare_Cap, //!< Equivalent to the largest value for Cap.
623
624 /** Equivalent to kButt_Cap.
625 Cap is set to kButt_Cap by default.
626 */
627 kDefault_Cap = kButt_Cap,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000628 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400629
Cary Clark75959392018-02-27 10:22:04 -0500630 /** The number of different SkPaint::Cap values defined.
631 May be used to verify that SkPaint::Cap is a legal value.*/
bsalomona7d85ba2016-07-06 11:54:59 -0700632 static constexpr int kCapCount = kLast_Cap + 1;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000633
Cary Clark50fa3ff2017-07-26 10:15:23 -0400634 /** \enum SkPaint::Join
Cary Clark1eace2d2017-07-31 07:52:43 -0400635 Join specifies how corners are drawn when a shape is stroked. Join
Cary Clark50fa3ff2017-07-26 10:15:23 -0400636 affects the four corners of a stroked rectangle, and the connected segments in a
637 stroked path.
638
639 Choose miter join to draw sharp corners. Choose round join to draw a circle with a
640 radius equal to the stroke width on top of the corner. Choose bevel join to minimally
641 connect the thick strokes.
642
643 The fill path constructed to describe the stroked path respects the join setting but may
644 not contain the actual join. For instance, a fill path constructed with round joins does
645 not necessarily include circles at each connected segment.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000646 */
647 enum Join {
Cary Clark23890a92017-07-27 16:30:51 -0400648 /** Extends the outside corner to the extent allowed by miter limit.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400649 If the extension exceeds miter limit, kBevel_Join is used instead.
650 */
651 kMiter_Join,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000652
Cary Clark50fa3ff2017-07-26 10:15:23 -0400653 /** Adds a circle with a diameter of stroke width at the sharp corner. */
654 kRound_Join,
655 kBevel_Join, //!< Connects the outside edges of the sharp corner.
656 kLast_Join = kBevel_Join, //!< Equivalent to the largest value for Join.
657
658 /** Equivalent to kMiter_Join.
659 Join is set to kMiter_Join by default.
660 */
661 kDefault_Join = kMiter_Join,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000662 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400663
Cary Clark75959392018-02-27 10:22:04 -0500664 /** The number of different SkPaint::Join values defined.
665 May be used to verify that SkPaint::Join is a legal value.*/
bsalomona7d85ba2016-07-06 11:54:59 -0700666 static constexpr int kJoinCount = kLast_Join + 1;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000667
Cary Clark50fa3ff2017-07-26 10:15:23 -0400668 /** The geometry drawn at the beginning and end of strokes.
669
670 @return one of: kButt_Cap, kRound_Cap, kSquare_Cap
reed@android.com8a1c16f2008-12-17 15:59:43 +0000671 */
reedf59eab22014-07-14 14:39:15 -0700672 Cap getStrokeCap() const { return (Cap)fBitfields.fCapType; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000673
Cary Clark50fa3ff2017-07-26 10:15:23 -0400674 /** The geometry drawn at the beginning and end of strokes.
675
676 @param cap one of: kButt_Cap, kRound_Cap, kSquare_Cap;
677 has no effect if cap is not valid
reed@android.com8a1c16f2008-12-17 15:59:43 +0000678 */
679 void setStrokeCap(Cap cap);
680
Cary Clark50fa3ff2017-07-26 10:15:23 -0400681 /** The geometry drawn at the corners of strokes.
682
683 @return one of: kMiter_Join, kRound_Join, kBevel_Join
reed@android.com8a1c16f2008-12-17 15:59:43 +0000684 */
reedf59eab22014-07-14 14:39:15 -0700685 Join getStrokeJoin() const { return (Join)fBitfields.fJoinType; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000686
Cary Clark50fa3ff2017-07-26 10:15:23 -0400687 /** The geometry drawn at the corners of strokes.
688
689 @param join one of: kMiter_Join, kRound_Join, kBevel_Join;
Cary Clark579985c2017-07-31 11:48:27 -0400690 otherwise, has no effect
reed@android.com8a1c16f2008-12-17 15:59:43 +0000691 */
692 void setStrokeJoin(Join join);
693
Cary Clark50fa3ff2017-07-26 10:15:23 -0400694 /** The filled equivalent of the stroked path.
695
696 @param src SkPath read to create a filled version
697 @param dst resulting SkPath; may be the same as src, but may not be nullptr
698 @param cullRect optional limit passed to SkPathEffect
699 @param resScale if > 1, increase precision, else if (0 < res < 1) reduce precision
700 to favor speed and size
Cary Clark1eace2d2017-07-31 07:52:43 -0400701 @return true if the path represents style fill, or false if it represents hairline
Cary Clark50fa3ff2017-07-26 10:15:23 -0400702 */
reed05d90442015-02-12 13:35:52 -0800703 bool getFillPath(const SkPath& src, SkPath* dst, const SkRect* cullRect,
704 SkScalar resScale = 1) const;
705
Cary Clark50fa3ff2017-07-26 10:15:23 -0400706 /** The filled equivalent of the stroked path.
707
Cary Clark23890a92017-07-27 16:30:51 -0400708 Replaces dst with the src path modified by SkPathEffect and style stroke.
709 SkPathEffect, if any, is not culled. stroke width is created with default precision.
710
711 @param src SkPath read to create a filled version
712 @param dst resulting SkPath dst may be the same as src, but may not be nullptr
Cary Clark1eace2d2017-07-31 07:52:43 -0400713 @return true if the path represents style fill, or false if it represents hairline
Cary Clark50fa3ff2017-07-26 10:15:23 -0400714 */
reed05d90442015-02-12 13:35:52 -0800715 bool getFillPath(const SkPath& src, SkPath* dst) const {
Ben Wagnera93a14a2017-08-28 10:34:05 -0400716 return this->getFillPath(src, dst, nullptr, 1);
reed05d90442015-02-12 13:35:52 -0800717 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000718
Cary Clark50fa3ff2017-07-26 10:15:23 -0400719 /** Optional colors used when filling a path, such as a gradient.
720
721 Does not alter SkShader SkRefCnt.
722
723 @return SkShader if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000724 */
reeda5ab9ec2016-03-06 18:10:48 -0800725 SkShader* getShader() const { return fShader.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400726
727 /** Optional colors used when filling a path, such as a gradient.
728
729 Increases SkShader SkRefCnt by one.
730
731 @return SkShader if previously set, nullptr otherwise
732 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500733 sk_sp<SkShader> refShader() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000734
Cary Clark50fa3ff2017-07-26 10:15:23 -0400735 /** Optional colors used when filling a path, such as a gradient.
736
Cary Clark8a02b0b2017-09-21 12:28:43 -0400737 Sets SkShader to shader, decreasing SkRefCnt of the previous SkShader.
738 Increments shader SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400739
Cary Clark1eace2d2017-07-31 07:52:43 -0400740 @param shader how geometry is filled with color; if nullptr, color is used instead
Cary Clark50fa3ff2017-07-26 10:15:23 -0400741 */
Cary Clark0418a882017-05-10 09:07:42 -0400742 void setShader(sk_sp<SkShader> shader);
reed@google.com9d07fec2011-03-16 20:02:59 +0000743
Cary Clark50fa3ff2017-07-26 10:15:23 -0400744 /** Returns SkColorFilter if set, or nullptr.
745 Does not alter SkColorFilter SkRefCnt.
746
747 @return SkColorFilter if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000748 */
reeda5ab9ec2016-03-06 18:10:48 -0800749 SkColorFilter* getColorFilter() const { return fColorFilter.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400750
751 /** Returns SkColorFilter if set, or nullptr.
752 Increases SkColorFilter SkRefCnt by one.
753
754 @return SkColorFilter if set, or nullptr
755 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500756 sk_sp<SkColorFilter> refColorFilter() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000757
Cary Clark8a02b0b2017-09-21 12:28:43 -0400758 /** Sets SkColorFilter to filter, decreasing SkRefCnt of the previous
759 SkColorFilter. Pass nullptr to clear SkColorFilter.
760
761 Increments filter SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400762
763 @param colorFilter SkColorFilter to apply to subsequent draw
reed@android.com8a1c16f2008-12-17 15:59:43 +0000764 */
Cary Clark0418a882017-05-10 09:07:42 -0400765 void setColorFilter(sk_sp<SkColorFilter> colorFilter);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000766
Cary Clark50fa3ff2017-07-26 10:15:23 -0400767 /** Returns SkBlendMode.
Cary Clark579985c2017-07-31 11:48:27 -0400768 By default, returns SkBlendMode::kSrcOver.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400769
770 @return mode used to combine source color with destination color
771 */
reed374772b2016-10-05 17:33:02 -0700772 SkBlendMode getBlendMode() const { return (SkBlendMode)fBlendMode; }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400773
774 /** Returns true if SkBlendMode is SkBlendMode::kSrcOver, the default.
775
776 @return true if SkBlendMode is SkBlendMode::kSrcOver
777 */
reed374772b2016-10-05 17:33:02 -0700778 bool isSrcOver() const { return (SkBlendMode)fBlendMode == SkBlendMode::kSrcOver; }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400779
780 /** Sets SkBlendMode to mode.
781 Does not check for valid input.
782
783 @param mode SkBlendMode used to combine source color and destination
784 */
reed374772b2016-10-05 17:33:02 -0700785 void setBlendMode(SkBlendMode mode) { fBlendMode = (unsigned)mode; }
reed@android.coma0f5d152009-06-22 17:38:10 +0000786
Cary Clark50fa3ff2017-07-26 10:15:23 -0400787 /** Returns SkPathEffect if set, or nullptr.
788 Does not alter SkPathEffect SkRefCnt.
789
790 @return SkPathEffect if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000791 */
reeda5ab9ec2016-03-06 18:10:48 -0800792 SkPathEffect* getPathEffect() const { return fPathEffect.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400793
794 /** Returns SkPathEffect if set, or nullptr.
795 Increases SkPathEffect SkRefCnt by one.
796
797 @return SkPathEffect if previously set, nullptr otherwise
798 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500799 sk_sp<SkPathEffect> refPathEffect() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000800
Cary Clark8a02b0b2017-09-21 12:28:43 -0400801 /** Sets SkPathEffect to pathEffect, decreasing SkRefCnt of the previous
802 SkPathEffect. Pass nullptr to leave the path geometry unaltered.
803
804 Increments pathEffect SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400805
806 @param pathEffect replace SkPath with a modification when drawn
reed@android.com8a1c16f2008-12-17 15:59:43 +0000807 */
Cary Clark0418a882017-05-10 09:07:42 -0400808 void setPathEffect(sk_sp<SkPathEffect> pathEffect);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000809
Cary Clark50fa3ff2017-07-26 10:15:23 -0400810 /** Returns SkMaskFilter if set, or nullptr.
811 Does not alter SkMaskFilter SkRefCnt.
812
813 @return SkMaskFilter if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000814 */
reeda5ab9ec2016-03-06 18:10:48 -0800815 SkMaskFilter* getMaskFilter() const { return fMaskFilter.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400816
817 /** Returns SkMaskFilter if set, or nullptr.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400818
Cary Clark50fa3ff2017-07-26 10:15:23 -0400819 Increases SkMaskFilter SkRefCnt by one.
820
821 @return SkMaskFilter if previously set, nullptr otherwise
822 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500823 sk_sp<SkMaskFilter> refMaskFilter() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000824
Cary Clark8a02b0b2017-09-21 12:28:43 -0400825 /** Sets SkMaskFilter to maskFilter, decreasing SkRefCnt of the previous
826 SkMaskFilter. Pass nullptr to clear SkMaskFilter and leave SkMaskFilter effect on
827 mask alpha unaltered.
828
Cary Clark75959392018-02-27 10:22:04 -0500829 Increments maskFilter SkRefCnt by one.
830
Cary Clark50fa3ff2017-07-26 10:15:23 -0400831 @param maskFilter modifies clipping mask generated from drawn geometry
reed@android.com8a1c16f2008-12-17 15:59:43 +0000832 */
Cary Clark0418a882017-05-10 09:07:42 -0400833 void setMaskFilter(sk_sp<SkMaskFilter> maskFilter);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000834
Cary Clark50fa3ff2017-07-26 10:15:23 -0400835 /** Returns SkTypeface if set, or nullptr.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400836 Increments SkTypeface SkRefCnt by one.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000837
Cary Clark50fa3ff2017-07-26 10:15:23 -0400838 @return SkTypeface if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000839 */
reeda5ab9ec2016-03-06 18:10:48 -0800840 SkTypeface* getTypeface() const { return fTypeface.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400841
842 /** Increases SkTypeface SkRefCnt by one.
843
844 @return SkTypeface if previously set, nullptr otherwise
845 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500846 sk_sp<SkTypeface> refTypeface() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000847
Cary Clark8a02b0b2017-09-21 12:28:43 -0400848 /** Sets SkTypeface to typeface, decreasing SkRefCnt of the previous SkTypeface.
849 Pass nullptr to clear SkTypeface and use the default typeface. Increments
850 typeface SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400851
852 @param typeface font and style used to draw text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000853 */
Cary Clark0418a882017-05-10 09:07:42 -0400854 void setTypeface(sk_sp<SkTypeface> typeface);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000855
Cary Clark50fa3ff2017-07-26 10:15:23 -0400856 /** Returns SkImageFilter if set, or nullptr.
857 Does not alter SkImageFilter SkRefCnt.
858
859 @return SkImageFilter if previously set, nullptr otherwise
860 */
reeda5ab9ec2016-03-06 18:10:48 -0800861 SkImageFilter* getImageFilter() const { return fImageFilter.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400862
863 /** Returns SkImageFilter if set, or nullptr.
864 Increases SkImageFilter SkRefCnt by one.
865
866 @return SkImageFilter if previously set, nullptr otherwise
867 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500868 sk_sp<SkImageFilter> refImageFilter() const;
Cary Clark50fa3ff2017-07-26 10:15:23 -0400869
Cary Clark8a02b0b2017-09-21 12:28:43 -0400870 /** Sets SkImageFilter to imageFilter, decreasing SkRefCnt of the previous
871 SkImageFilter. Pass nullptr to clear SkImageFilter, and remove SkImageFilter effect
Cary Clark50fa3ff2017-07-26 10:15:23 -0400872 on drawing.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400873
Cary Clark75959392018-02-27 10:22:04 -0500874 Increments imageFilter SkRefCnt by one.
875
Cary Clark50fa3ff2017-07-26 10:15:23 -0400876 @param imageFilter how SkImage is sampled when transformed
877 */
Cary Clark0418a882017-05-10 09:07:42 -0400878 void setImageFilter(sk_sp<SkImageFilter> imageFilter);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000879
Cary Clark50fa3ff2017-07-26 10:15:23 -0400880 /** Returns SkDrawLooper if set, or nullptr.
881 Does not alter SkDrawLooper SkRefCnt.
882
883 @return SkDrawLooper if previously set, nullptr otherwise
884 */
reed46f2d0a2016-09-11 05:40:31 -0700885 SkDrawLooper* getDrawLooper() const { return fDrawLooper.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400886
887 /** Returns SkDrawLooper if set, or nullptr.
888 Increases SkDrawLooper SkRefCnt by one.
889
890 @return SkDrawLooper if previously set, nullptr otherwise
891 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500892 sk_sp<SkDrawLooper> refDrawLooper() const;
893
Cary Clark23890a92017-07-27 16:30:51 -0400894 /** Deprecated.
Cary Clark75959392018-02-27 10:22:04 -0500895 (see skbug.com/6259)
Cary Clark50fa3ff2017-07-26 10:15:23 -0400896 */
reed46f2d0a2016-09-11 05:40:31 -0700897 SkDrawLooper* getLooper() const { return fDrawLooper.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400898
Cary Clark8a02b0b2017-09-21 12:28:43 -0400899 /** Sets SkDrawLooper to drawLooper, decreasing SkRefCnt of the previous
900 drawLooper. Pass nullptr to clear SkDrawLooper and leave SkDrawLooper effect on
901 drawing unaltered.
902
903 Increments drawLooper SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400904
Cary Clarkb7da7232017-09-01 13:49:54 -0400905 @param drawLooper iterates through drawing one or more time, altering SkPaint
Cary Clark50fa3ff2017-07-26 10:15:23 -0400906 */
Cary Clark0418a882017-05-10 09:07:42 -0400907 void setDrawLooper(sk_sp<SkDrawLooper> drawLooper);
Mike Reed09d94352016-10-31 15:11:04 -0400908
Cary Clark23890a92017-07-27 16:30:51 -0400909 /** Deprecated.
Cary Clark75959392018-02-27 10:22:04 -0500910 (see skbug.com/6259)
Cary Clark50fa3ff2017-07-26 10:15:23 -0400911 */
Cary Clark0418a882017-05-10 09:07:42 -0400912 void setLooper(sk_sp<SkDrawLooper> drawLooper);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000913
Cary Clark50fa3ff2017-07-26 10:15:23 -0400914 /** \enum SkPaint::Align
915 Align adjusts the text relative to the text position.
916 Align affects glyphs drawn with: SkCanvas::drawText, SkCanvas::drawPosText,
917 SkCanvas::drawPosTextH, SkCanvas::drawTextOnPath,
918 SkCanvas::drawTextOnPathHV, SkCanvas::drawTextRSXform, SkCanvas::drawTextBlob,
919 and SkCanvas::drawString;
Cary Clark579985c2017-07-31 11:48:27 -0400920 as well as calls that place text glyphs like getTextWidths() and getTextPath().
Cary Clark50fa3ff2017-07-26 10:15:23 -0400921
922 The text position is set by the font for both horizontal and vertical text.
923 Typically, for horizontal text, the position is to the left side of the glyph on the
Cary Clark23890a92017-07-27 16:30:51 -0400924 base line; and for vertical text, the position is the horizontal center of the glyph
Cary Clark50fa3ff2017-07-26 10:15:23 -0400925 at the caps height.
926
927 Align adjusts the glyph position to center it or move it to abut the position
928 using the metrics returned by the font.
929
930 Align defaults to kLeft_Align.
931 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000932 enum Align {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400933 /** Leaves the glyph at the position computed by the font offset by the text position. */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000934 kLeft_Align,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400935
936 /** Moves the glyph half its width if Flags has kVerticalText_Flag clear, and
937 half its height if Flags has kVerticalText_Flag set.
938 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000939 kCenter_Align,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400940
941 /** Moves the glyph by its width if Flags has kVerticalText_Flag clear,
942 and by its height if Flags has kVerticalText_Flag set.
943 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000944 kRight_Align,
mike@reedtribe.orgddc813b2013-06-08 12:58:19 +0000945 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400946
Cary Clarkd98f78c2018-04-26 08:32:37 -0400947 static constexpr int kAlignCount = 3; //!< The number of different Align values defined.
reed@google.com9d07fec2011-03-16 20:02:59 +0000948
Cary Clark50fa3ff2017-07-26 10:15:23 -0400949 /** Returns SkPaint::Align.
950 Returns kLeft_Align if SkPaint::Align has not been set.
951
952 @return text placement relative to position
reed@android.com8a1c16f2008-12-17 15:59:43 +0000953 */
reedf59eab22014-07-14 14:39:15 -0700954 Align getTextAlign() const { return (Align)fBitfields.fTextAlign; }
reed@google.com9d07fec2011-03-16 20:02:59 +0000955
Cary Clark50fa3ff2017-07-26 10:15:23 -0400956 /** Sets SkPaint::Align to align.
957 Has no effect if align is an invalid value.
958
959 @param align text placement relative to position
reed@android.com8a1c16f2008-12-17 15:59:43 +0000960 */
961 void setTextAlign(Align align);
962
Cary Clark50fa3ff2017-07-26 10:15:23 -0400963 /** Returns text size in points.
964
965 @return typographic height of text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000966 */
967 SkScalar getTextSize() const { return fTextSize; }
968
Cary Clark50fa3ff2017-07-26 10:15:23 -0400969 /** Sets text size in points.
970 Has no effect if textSize is not greater than or equal to zero.
971
972 @param textSize typographic height of text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000973 */
974 void setTextSize(SkScalar textSize);
975
Cary Clark50fa3ff2017-07-26 10:15:23 -0400976 /** Returns text scale x.
977 Default value is 1.
978
979 @return text horizontal scale
reed@android.com8a1c16f2008-12-17 15:59:43 +0000980 */
981 SkScalar getTextScaleX() const { return fTextScaleX; }
982
Cary Clark50fa3ff2017-07-26 10:15:23 -0400983 /** Sets text scale x.
984 Default value is 1.
985
986 @param scaleX text horizontal scale
reed@android.com8a1c16f2008-12-17 15:59:43 +0000987 */
988 void setTextScaleX(SkScalar scaleX);
989
Cary Clark50fa3ff2017-07-26 10:15:23 -0400990 /** Returns text skew x.
991 Default value is zero.
992
993 @return additional shear in x-axis relative to y-axis
reed@android.com8a1c16f2008-12-17 15:59:43 +0000994 */
995 SkScalar getTextSkewX() const { return fTextSkewX; }
996
Cary Clark50fa3ff2017-07-26 10:15:23 -0400997 /** Sets text skew x.
998 Default value is zero.
999
1000 @param skewX additional shear in x-axis relative to y-axis
reed@android.com8a1c16f2008-12-17 15:59:43 +00001001 */
1002 void setTextSkewX(SkScalar skewX);
1003
Cary Clark50fa3ff2017-07-26 10:15:23 -04001004 /** \enum SkPaint::TextEncoding
Cary Clark8a02b0b2017-09-21 12:28:43 -04001005 TextEncoding determines whether text specifies character codes and their encoded
Cary Clarkcc309eb2017-10-30 11:48:35 -04001006 size, or glyph indices. Characters are encoded as specified by the Unicode standard.
Cary Clark8a02b0b2017-09-21 12:28:43 -04001007
Cary Clark50fa3ff2017-07-26 10:15:23 -04001008 Character codes encoded size are specified by UTF-8, UTF-16, or UTF-32.
Cary Clarkcc309eb2017-10-30 11:48:35 -04001009 All character code formats are able to represent all of Unicode, differing only
1010 in the total storage required.
1011
1012 UTF-8 (RFC 3629) encodes each character as one or more 8-bit bytes.
1013
1014 UTF-16 (RFC 2781) encodes each character as one or two 16-bit words.
1015
1016 UTF-32 encodes each character as one 32-bit word.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001017
1018 font manager uses font data to convert character code points into glyph indices.
1019 A glyph index is a 16-bit word.
1020
1021 TextEncoding is set to kUTF8_TextEncoding by default.
reed@android.com8a1c16f2008-12-17 15:59:43 +00001022 */
1023 enum TextEncoding {
Cary Clark50fa3ff2017-07-26 10:15:23 -04001024 kUTF8_TextEncoding, //!< Uses bytes to represent UTF-8 or ASCII.
1025 kUTF16_TextEncoding, //!< Uses two byte words to represent most of Unicode.
1026 kUTF32_TextEncoding, //!< Uses four byte words to represent all of Unicode.
1027 kGlyphID_TextEncoding, //!< Uses two byte words to represent glyph indices.
reed@android.com8a1c16f2008-12-17 15:59:43 +00001028 };
reed@google.com9d07fec2011-03-16 20:02:59 +00001029
Cary Clark50fa3ff2017-07-26 10:15:23 -04001030 /** Returns SkPaint::TextEncoding.
1031 SkPaint::TextEncoding determines how character code points are mapped to font glyph indices.
1032
1033 @return one of: kUTF8_TextEncoding, kUTF16_TextEncoding, kUTF32_TextEncoding, or
1034 kGlyphID_TextEncoding
1035 */
reedf59eab22014-07-14 14:39:15 -07001036 TextEncoding getTextEncoding() const {
1037 return (TextEncoding)fBitfields.fTextEncoding;
1038 }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001039
Cary Clark50fa3ff2017-07-26 10:15:23 -04001040 /** Sets SkPaint::TextEncoding to encoding.
1041 SkPaint::TextEncoding determines how character code points are mapped to font glyph indices.
1042 Invalid values for encoding are ignored.
1043
1044 @param encoding one of: kUTF8_TextEncoding, kUTF16_TextEncoding, kUTF32_TextEncoding, or
Cary Clark579985c2017-07-31 11:48:27 -04001045 kGlyphID_TextEncoding
Cary Clark50fa3ff2017-07-26 10:15:23 -04001046 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001047 void setTextEncoding(TextEncoding encoding);
1048
Cary Clark50fa3ff2017-07-26 10:15:23 -04001049 /** \struct SkPaint::FontMetrics
Cary Clark579985c2017-07-31 11:48:27 -04001050 FontMetrics is filled out by getFontMetrics(). FontMetrics contents reflect the values
Cary Clark50fa3ff2017-07-26 10:15:23 -04001051 computed by font manager using SkTypeface. Values are set to zero if they are
Cary Clarkb7da7232017-09-01 13:49:54 -04001052 not available.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001053
Ben Wagnere5806492017-11-09 12:08:31 -05001054 All vertical values relative to the baseline are given y-down. As such, zero is on the
1055 baseline, negative values are above the baseline, and positive values are below the
1056 baseline.
1057
Cary Clark50fa3ff2017-07-26 10:15:23 -04001058 fUnderlineThickness and fUnderlinePosition have a bit set in fFlags if their values
1059 are valid, since their value may be zero.
1060
1061 fStrikeoutThickness and fStrikeoutPosition have a bit set in fFlags if their values
1062 are valid, since their value may be zero.
1063 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001064 struct FontMetrics {
Cary Clark50fa3ff2017-07-26 10:15:23 -04001065
Cary Clarkcc309eb2017-10-30 11:48:35 -04001066 /** \enum SkPaint::FontMetrics::FontMetricsFlags
1067 FontMetricsFlags are set in fFlags when underline and strikeout metrics are valid;
1068 the underline or strikeout metric may be valid and zero.
1069 Fonts with embedded bitmaps may not have valid underline or strikeout metrics.
1070 */
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001071 enum FontMetricsFlags {
Cary Clark50fa3ff2017-07-26 10:15:23 -04001072 kUnderlineThicknessIsValid_Flag = 1 << 0, //!< Set if fUnderlineThickness is valid.
1073 kUnderlinePositionIsValid_Flag = 1 << 1, //!< Set if fUnderlinePosition is valid.
1074 kStrikeoutThicknessIsValid_Flag = 1 << 2, //!< Set if fStrikeoutThickness is valid.
1075 kStrikeoutPositionIsValid_Flag = 1 << 3, //!< Set if fStrikeoutPosition is valid.
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001076 };
1077
Cary Clark50fa3ff2017-07-26 10:15:23 -04001078 uint32_t fFlags; //!< fFlags is set when underline metrics are valid.
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001079
Ben Wagnere5806492017-11-09 12:08:31 -05001080 /** Greatest extent above the baseline for any glyph.
1081 Typically less than zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001082 */
1083 SkScalar fTop;
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001084
Cary Clark50fa3ff2017-07-26 10:15:23 -04001085 /** Recommended distance above the baseline to reserve for a line of text.
Ben Wagnere5806492017-11-09 12:08:31 -05001086 Typically less than zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001087 */
1088 SkScalar fAscent;
Ben Wagner219f3622017-07-17 15:32:25 -04001089
Cary Clark50fa3ff2017-07-26 10:15:23 -04001090 /** Recommended distance below the baseline to reserve for a line of text.
Ben Wagnere5806492017-11-09 12:08:31 -05001091 Typically greater than zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001092 */
1093 SkScalar fDescent;
Ben Wagner219f3622017-07-17 15:32:25 -04001094
Cary Clark50fa3ff2017-07-26 10:15:23 -04001095 /** Greatest extent below the baseline for any glyph.
Ben Wagnere5806492017-11-09 12:08:31 -05001096 Typically greater than zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001097 */
1098 SkScalar fBottom;
1099
1100 /** Recommended distance to add between lines of text.
Ben Wagnere5806492017-11-09 12:08:31 -05001101 Typically greater than or equal to zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001102 */
1103 SkScalar fLeading;
1104
1105 /** Average character width, if it is available.
1106 Zero if no average width is stored in the font.
1107 */
1108 SkScalar fAvgCharWidth;
Cary Clarkcc309eb2017-10-30 11:48:35 -04001109
Cary Clark50fa3ff2017-07-26 10:15:23 -04001110 SkScalar fMaxCharWidth; //!< Maximum character width.
1111
1112 /** Minimum bounding box x value for all glyphs.
1113 Typically less than zero.
1114 */
1115 SkScalar fXMin;
1116
1117 /** Maximum bounding box x value for all glyphs.
1118 Typically greater than zero.
1119 */
1120 SkScalar fXMax;
1121
1122 /** Height of a lower-case 'x'.
1123 May be zero if no lower-case height is stored in the font.
1124 */
1125 SkScalar fXHeight;
1126
1127 /** Height of an upper-case letter.
1128 May be zero if no upper-case height is stored in the font.
1129 */
1130 SkScalar fCapHeight;
1131
Ben Wagnere5806492017-11-09 12:08:31 -05001132 /** Underline thickness.
1133
1134 If the metric is valid, the kUnderlineThicknessIsValid_Flag is set in fFlags.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001135 If kUnderlineThicknessIsValid_Flag is clear, fUnderlineThickness is zero.
1136 */
1137 SkScalar fUnderlineThickness;
1138
Ben Wagnere5806492017-11-09 12:08:31 -05001139 /** Position of the top of the underline stroke relative to the baseline.
1140 Typically positive when valid.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001141
1142 If the metric is valid, the kUnderlinePositionIsValid_Flag is set in fFlags.
1143 If kUnderlinePositionIsValid_Flag is clear, fUnderlinePosition is zero.
1144 */
1145 SkScalar fUnderlinePosition;
1146
Ben Wagnere5806492017-11-09 12:08:31 -05001147 /** Strikeout thickness.
1148
1149 If the metric is valid, the kStrikeoutThicknessIsValid_Flag is set in fFlags.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001150 If kStrikeoutThicknessIsValid_Flag is clear, fStrikeoutThickness is zero.
1151 */
1152 SkScalar fStrikeoutThickness;
1153
Ben Wagnere5806492017-11-09 12:08:31 -05001154 /** Position of the bottom of the strikeout stroke relative to the baseline.
1155 Typically negative when valid.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001156
1157 If the metric is valid, the kStrikeoutPositionIsValid_Flag is set in fFlags.
1158 If kStrikeoutPositionIsValid_Flag is clear, fStrikeoutPosition is zero.
1159 */
1160 SkScalar fStrikeoutPosition;
1161
1162 /** If SkPaint::FontMetrics has a valid underline thickness, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001163 thickness to that value. If the underline thickness is not valid,
1164 return false, and ignore thickness.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001165
1166 @param thickness storage for underline width
1167 @return true if font specifies underline width
1168 */
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001169 bool hasUnderlineThickness(SkScalar* thickness) const {
Ben Wagner3318da52017-03-23 14:01:22 -04001170 if (SkToBool(fFlags & kUnderlineThicknessIsValid_Flag)) {
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001171 *thickness = fUnderlineThickness;
1172 return true;
1173 }
1174 return false;
1175 }
1176
Cary Clark50fa3ff2017-07-26 10:15:23 -04001177 /** If SkPaint::FontMetrics has a valid underline position, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001178 position to that value. If the underline position is not valid,
1179 return false, and ignore position.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001180
1181 @param position storage for underline position
1182 @return true if font specifies underline position
1183 */
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001184 bool hasUnderlinePosition(SkScalar* position) const {
1185 if (SkToBool(fFlags & kUnderlinePositionIsValid_Flag)) {
1186 *position = fUnderlinePosition;
1187 return true;
1188 }
1189 return false;
1190 }
1191
Cary Clark50fa3ff2017-07-26 10:15:23 -04001192 /** If SkPaint::FontMetrics has a valid strikeout thickness, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001193 thickness to that value. If the underline thickness is not valid,
1194 return false, and ignore thickness.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001195
1196 @param thickness storage for strikeout width
1197 @return true if font specifies strikeout width
1198 */
Ben Wagner219f3622017-07-17 15:32:25 -04001199 bool hasStrikeoutThickness(SkScalar* thickness) const {
1200 if (SkToBool(fFlags & kStrikeoutThicknessIsValid_Flag)) {
1201 *thickness = fStrikeoutThickness;
1202 return true;
1203 }
1204 return false;
1205 }
1206
Cary Clark50fa3ff2017-07-26 10:15:23 -04001207 /** If SkPaint::FontMetrics has a valid strikeout position, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001208 position to that value. If the underline position is not valid,
1209 return false, and ignore position.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001210
1211 @param position storage for strikeout position
1212 @return true if font specifies strikeout position
1213 */
Ben Wagner219f3622017-07-17 15:32:25 -04001214 bool hasStrikeoutPosition(SkScalar* position) const {
1215 if (SkToBool(fFlags & kStrikeoutPositionIsValid_Flag)) {
1216 *position = fStrikeoutPosition;
1217 return true;
1218 }
1219 return false;
1220 }
Cary Clark50fa3ff2017-07-26 10:15:23 -04001221
reed@android.com8a1c16f2008-12-17 15:59:43 +00001222 };
reed@google.com9d07fec2011-03-16 20:02:59 +00001223
Cary Clark50fa3ff2017-07-26 10:15:23 -04001224 /** Returns SkPaint::FontMetrics associated with SkTypeface.
1225 The return value is the recommended spacing between lines: the sum of metrics
1226 descent, ascent, and leading.
1227 If metrics is not nullptr, SkPaint::FontMetrics is copied to metrics.
1228 Results are scaled by text size but does not take into account
1229 dimensions required by text scale x, text skew x, fake bold,
1230 style stroke, and SkPathEffect.
1231 Results can be additionally scaled by scale; a scale of zero
1232 is ignored.
1233
1234 @param metrics storage for SkPaint::FontMetrics from SkTypeface; may be nullptr
1235 @param scale additional multiplier for returned values
1236 @return recommended spacing between lines
reed@android.com8a1c16f2008-12-17 15:59:43 +00001237 */
1238 SkScalar getFontMetrics(FontMetrics* metrics, SkScalar scale = 0) const;
reed@google.com9d07fec2011-03-16 20:02:59 +00001239
Cary Clark50fa3ff2017-07-26 10:15:23 -04001240 /** Returns the recommended spacing between lines: the sum of metrics
1241 descent, ascent, and leading.
1242 Result is scaled by text size but does not take into account
1243 dimensions required by stroking and SkPathEffect.
Cary Clark579985c2017-07-31 11:48:27 -04001244 Returns the same result as getFontMetrics().
Cary Clark50fa3ff2017-07-26 10:15:23 -04001245
1246 @return recommended spacing between lines
reed@android.com8a1c16f2008-12-17 15:59:43 +00001247 */
Ben Wagnera93a14a2017-08-28 10:34:05 -04001248 SkScalar getFontSpacing() const { return this->getFontMetrics(nullptr, 0); }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001249
Cary Clark50fa3ff2017-07-26 10:15:23 -04001250 /** Converts text into glyph indices.
1251 Returns the number of glyph indices represented by text.
1252 SkPaint::TextEncoding specifies how text represents characters or glyphs.
1253 glyphs may be nullptr, to compute the glyph count.
1254
Cary Clarkcc309eb2017-10-30 11:48:35 -04001255 Does not check text for valid character codes or valid glyph indices.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001256
Cary Clark579985c2017-07-31 11:48:27 -04001257 If byteLength equals zero, returns zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001258 If byteLength includes a partial character, the partial character is ignored.
1259
1260 If SkPaint::TextEncoding is kUTF8_TextEncoding and
1261 text contains an invalid UTF-8 sequence, zero is returned.
1262
Cary Clarkb7da7232017-09-01 13:49:54 -04001263 @param text character storage encoded with SkPaint::TextEncoding
Cary Clark50fa3ff2017-07-26 10:15:23 -04001264 @param byteLength length of character storage in bytes
1265 @param glyphs storage for glyph indices; may be nullptr
1266 @return number of glyphs represented by text of length byteLength
reed@android.com8a1c16f2008-12-17 15:59:43 +00001267 */
1268 int textToGlyphs(const void* text, size_t byteLength,
halcanaryd0e95a52016-07-25 07:18:12 -07001269 SkGlyphID glyphs[]) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001270
Cary Clark50fa3ff2017-07-26 10:15:23 -04001271 /** Returns true if all text corresponds to a non-zero glyph index.
1272 Returns false if any characters in text are not supported in
1273 SkTypeface.
reed@android.coma5dcaf62010-02-05 17:12:32 +00001274
Cary Clark579985c2017-07-31 11:48:27 -04001275 If SkPaint::TextEncoding is kGlyphID_TextEncoding,
1276 returns true if all glyph indices in text are non-zero;
Cary Clark50fa3ff2017-07-26 10:15:23 -04001277 does not check to see if text contains valid glyph indices for SkTypeface.
1278
Cary Clarkb7da7232017-09-01 13:49:54 -04001279 Returns true if byteLength is zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001280
1281 @param text array of characters or glyphs
1282 @param byteLength number of bytes in text array
1283 @return true if all text corresponds to a non-zero glyph index
1284 */
reed@android.coma5dcaf62010-02-05 17:12:32 +00001285 bool containsText(const void* text, size_t byteLength) const;
1286
Cary Clark50fa3ff2017-07-26 10:15:23 -04001287 /** Converts glyphs into text if possible.
1288 Glyph values without direct Unicode equivalents are mapped to zero.
1289 Uses the SkTypeface, but is unaffected
1290 by SkPaint::TextEncoding; the text values returned are equivalent to kUTF32_TextEncoding.
1291
1292 Only supported on platforms that use FreeType as the font engine.
1293
1294 @param glyphs array of indices into font
1295 @param count length of glyph array
1296 @param text storage for character codes, one per glyph
reed@android.com9d3a9852010-01-08 14:07:42 +00001297 */
halcanaryd0e95a52016-07-25 07:18:12 -07001298 void glyphsToUnichars(const SkGlyphID glyphs[], int count, SkUnichar text[]) const;
reed@android.com9d3a9852010-01-08 14:07:42 +00001299
Cary Clark50fa3ff2017-07-26 10:15:23 -04001300 /** Returns the number of glyphs in text.
1301 Uses SkPaint::TextEncoding to count the glyphs.
Cary Clark579985c2017-07-31 11:48:27 -04001302 Returns the same result as textToGlyphs().
Cary Clark50fa3ff2017-07-26 10:15:23 -04001303
Cary Clarkb7da7232017-09-01 13:49:54 -04001304 @param text character storage encoded with SkPaint::TextEncoding
Cary Clark50fa3ff2017-07-26 10:15:23 -04001305 @param byteLength length of character storage in bytes
1306 @return number of glyphs represented by text of length byteLength
reed@android.com8a1c16f2008-12-17 15:59:43 +00001307 */
Herb Derby90864a22018-05-02 13:43:49 -04001308 int countText(const void* text, size_t byteLength) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001309
Cary Clark50fa3ff2017-07-26 10:15:23 -04001310 /** Returns the advance width of text if kVerticalText_Flag is clear,
1311 and the height of text if kVerticalText_Flag is set.
1312 The advance is the normal distance to move before drawing additional text.
1313 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
1314 and text size, text scale x, text skew x, stroke width, and
1315 SkPathEffect to scale the metrics and bounds.
1316 Returns the bounding box of text if bounds is not nullptr.
1317 The bounding box is computed as if the text was drawn at the origin.
1318
1319 @param text character codes or glyph indices to be measured
1320 @param length number of bytes of text to measure
1321 @param bounds returns bounding box relative to (0, 0) if not nullptr
1322 @return advance width or height
1323 */
reed99ae8812014-08-26 11:30:01 -07001324 SkScalar measureText(const void* text, size_t length, SkRect* bounds) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001325
Cary Clark50fa3ff2017-07-26 10:15:23 -04001326 /** Returns the advance width of text if kVerticalText_Flag is clear,
1327 and the height of text if kVerticalText_Flag is set.
1328 The advance is the normal distance to move before drawing additional text.
1329 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
Cary Clark23890a92017-07-27 16:30:51 -04001330 and text size to scale the metrics.
1331 Does not scale the advance or bounds by fake bold or SkPathEffect.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001332
1333 @param text character codes or glyph indices to be measured
1334 @param length number of bytes of text to measure
Cary Clark50fa3ff2017-07-26 10:15:23 -04001335 @return advance width or height
1336 */
reed@google.com9d07fec2011-03-16 20:02:59 +00001337 SkScalar measureText(const void* text, size_t length) const {
Ben Wagnera93a14a2017-08-28 10:34:05 -04001338 return this->measureText(text, length, nullptr);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001339 }
reed@google.com9d07fec2011-03-16 20:02:59 +00001340
Cary Clark50fa3ff2017-07-26 10:15:23 -04001341 /** Returns the bytes of text that fit within maxWidth.
1342 If kVerticalText_Flag is clear, the text fragment fits if its advance width is less than or
1343 equal to maxWidth.
1344 If kVerticalText_Flag is set, the text fragment fits if its advance height is less than or
1345 equal to maxWidth.
1346 Measures only while the advance is less than or equal to maxWidth.
1347 Returns the advance or the text fragment in measuredWidth if it not nullptr.
1348 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
1349 and text size to scale the metrics.
1350 Does not scale the advance or bounds by fake bold or SkPathEffect.
1351
1352 @param text character codes or glyph indices to be measured
1353 @param length number of bytes of text to measure
1354 @param maxWidth advance limit; text is measured while advance is less than maxWidth
1355 @param measuredWidth returns the width of the text less than or equal to maxWidth
1356 @return bytes of text that fit, always less than or equal to length
1357 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001358 size_t breakText(const void* text, size_t length, SkScalar maxWidth,
Ben Wagnera93a14a2017-08-28 10:34:05 -04001359 SkScalar* measuredWidth = nullptr) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001360
Cary Clark50fa3ff2017-07-26 10:15:23 -04001361 /** Retrieves the advance and bounds for each glyph in text, and returns
1362 the glyph count in text.
1363 Both widths and bounds may be nullptr.
1364 If widths is not nullptr, widths must be an array of glyph count entries.
1365 if bounds is not nullptr, bounds must be an array of glyph count entries.
1366 If kVerticalText_Flag is clear, widths returns the horizontal advance.
1367 If kVerticalText_Flag is set, widths returns the vertical advance.
1368 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
1369 and text size to scale the widths and bounds.
1370 Does not scale the advance by fake bold or SkPathEffect.
Cary Clark23890a92017-07-27 16:30:51 -04001371 Does include fake bold and SkPathEffect in the bounds.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001372
1373 @param text character codes or glyph indices to be measured
1374 @param byteLength number of bytes of text to measure
1375 @param widths returns text advances for each glyph; may be nullptr
1376 @param bounds returns bounds for each glyph relative to (0, 0); may be nullptr
1377 @return glyph count in text
1378 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001379 int getTextWidths(const void* text, size_t byteLength, SkScalar widths[],
Ben Wagnera93a14a2017-08-28 10:34:05 -04001380 SkRect bounds[] = nullptr) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001381
Cary Clark50fa3ff2017-07-26 10:15:23 -04001382 /** Returns the geometry as SkPath equivalent to the drawn text.
1383 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1384 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1385 All of the glyph paths are stored in path.
Cary Clark579985c2017-07-31 11:48:27 -04001386 Uses x, y, and SkPaint::Align to position path.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001387
1388 @param text character codes or glyph indices
1389 @param length number of bytes of text
1390 @param x x-coordinate of the origin of the text
1391 @param y y-coordinate of the origin of the text
1392 @param path geometry of the glyphs
1393 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001394 void getTextPath(const void* text, size_t length, SkScalar x, SkScalar y,
1395 SkPath* path) const;
1396
Cary Clark50fa3ff2017-07-26 10:15:23 -04001397 /** Returns the geometry as SkPath equivalent to the drawn text.
1398 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1399 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1400 All of the glyph paths are stored in path.
1401 Uses pos array and SkPaint::Align to position path.
1402 pos contains a position for each glyph.
1403
1404 @param text character codes or glyph indices
1405 @param length number of bytes of text
1406 @param pos positions of each glyph
1407 @param path geometry of the glyphs
1408 */
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001409 void getPosTextPath(const void* text, size_t length,
reed@google.comca0062e2012-07-20 11:20:32 +00001410 const SkPoint pos[], SkPath* path) const;
1411
Cary Clark50fa3ff2017-07-26 10:15:23 -04001412 /** Returns the number of intervals that intersect bounds.
1413 bounds describes a pair of lines parallel to the text advance.
1414 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1415 the string.
1416 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1417 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1418 Uses x, y, and SkPaint::Align to position intervals.
1419
1420 Pass nullptr for intervals to determine the size of the interval array.
1421
1422 intervals are cached to improve performance for multiple calls.
1423
1424 @param text character codes or glyph indices
1425 @param length number of bytes of text
1426 @param x x-coordinate of the origin of the text
1427 @param y y-coordinate of the origin of the text
1428 @param bounds lower and upper line parallel to the advance
1429 @param intervals returned intersections; may be nullptr
1430 @return number of intersections; may be zero
1431 */
caryclark0449bcf2016-02-09 13:25:45 -08001432 int getTextIntercepts(const void* text, size_t length, SkScalar x, SkScalar y,
1433 const SkScalar bounds[2], SkScalar* intervals) const;
1434
Cary Clark50fa3ff2017-07-26 10:15:23 -04001435 /** Returns the number of intervals that intersect bounds.
1436 bounds describes a pair of lines parallel to the text advance.
1437 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1438 the string.
1439 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1440 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1441 Uses pos array and SkPaint::Align to position intervals.
1442
1443 Pass nullptr for intervals to determine the size of the interval array.
1444
1445 intervals are cached to improve performance for multiple calls.
1446
1447 @param text character codes or glyph indices
1448 @param length number of bytes of text
1449 @param pos positions of each glyph
1450 @param bounds lower and upper line parallel to the advance
1451 @param intervals returned intersections; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -04001452 @return number of intersections; may be zero
Cary Clark50fa3ff2017-07-26 10:15:23 -04001453 */
caryclark0449bcf2016-02-09 13:25:45 -08001454 int getPosTextIntercepts(const void* text, size_t length, const SkPoint pos[],
1455 const SkScalar bounds[2], SkScalar* intervals) const;
1456
Cary Clark50fa3ff2017-07-26 10:15:23 -04001457 /** Returns the number of intervals that intersect bounds.
1458 bounds describes a pair of lines parallel to the text advance.
1459 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1460 the string.
1461 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1462 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1463 Uses xpos array, constY, and SkPaint::Align to position intervals.
1464
1465 Pass nullptr for intervals to determine the size of the interval array.
1466
1467 intervals are cached to improve performance for multiple calls.
1468
1469 @param text character codes or glyph indices
1470 @param length number of bytes of text
1471 @param xpos positions of each glyph in x
1472 @param constY position of each glyph in y
1473 @param bounds lower and upper line parallel to the advance
1474 @param intervals returned intersections; may be nullptr
1475 @return number of intersections; may be zero
1476 */
fmalitaeae6a912016-07-28 09:47:24 -07001477 int getPosTextHIntercepts(const void* text, size_t length, const SkScalar xpos[],
1478 SkScalar constY, const SkScalar bounds[2], SkScalar* intervals) const;
1479
Cary Clark50fa3ff2017-07-26 10:15:23 -04001480 /** Returns the number of intervals that intersect bounds.
1481 bounds describes a pair of lines parallel to the text advance.
1482 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1483 the string.
Cary Clark2823f9f2018-01-03 10:00:34 -05001484 Uses SkTypeface to get the glyph paths,
Cary Clark50fa3ff2017-07-26 10:15:23 -04001485 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
Cary Clarkb7da7232017-09-01 13:49:54 -04001486 Uses run array and SkPaint::Align to position intervals.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001487
Cary Clark2823f9f2018-01-03 10:00:34 -05001488 SkPaint::TextEncoding must be set to SkPaint::kGlyphID_TextEncoding.
1489
Cary Clark50fa3ff2017-07-26 10:15:23 -04001490 Pass nullptr for intervals to determine the size of the interval array.
1491
1492 intervals are cached to improve performance for multiple calls.
1493
Cary Clark8a02b0b2017-09-21 12:28:43 -04001494 @param blob glyphs, positions, and text paint attributes
Cary Clark50fa3ff2017-07-26 10:15:23 -04001495 @param bounds lower and upper line parallel to the advance
1496 @param intervals returned intersections; may be nullptr
1497 @return number of intersections; may be zero
1498 */
fmalitaeae6a912016-07-28 09:47:24 -07001499 int getTextBlobIntercepts(const SkTextBlob* blob, const SkScalar bounds[2],
1500 SkScalar* intervals) const;
1501
Cary Clark50fa3ff2017-07-26 10:15:23 -04001502 /** Returns the union of bounds of all glyphs.
1503 Returned dimensions are computed by font manager from font data,
Cary Clark579985c2017-07-31 11:48:27 -04001504 ignoring SkPaint::Hinting. Includes text size, text scale x,
Cary Clark50fa3ff2017-07-26 10:15:23 -04001505 and text skew x, but not fake bold or SkPathEffect.
1506
1507 If text size is large, text scale x is one, and text skew x is zero,
Cary Clark579985c2017-07-31 11:48:27 -04001508 returns the same bounds as SkPaint::FontMetrics { FontMetrics::fXMin,
Cary Clark50fa3ff2017-07-26 10:15:23 -04001509 FontMetrics::fTop, FontMetrics::fXMax, FontMetrics::fBottom }.
1510
1511 @return union of bounds of all glyphs
1512 */
reed8893e5f2014-12-15 13:27:26 -08001513 SkRect getFontBounds() const;
1514
Cary Clark579985c2017-07-31 11:48:27 -04001515 /** Returns true if SkPaint prevents all drawing;
1516 otherwise, the SkPaint may or may not allow drawing.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001517
Cary Clarkb7da7232017-09-01 13:49:54 -04001518 Returns true if, for example, SkBlendMode combined with color alpha computes a
1519 new alpha of zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001520
1521 @return true if SkPaint prevents all drawing
1522 */
reed@google.com632e1a22011-10-06 12:37:00 +00001523 bool nothingToDraw() const;
1524
Cary Clark2823f9f2018-01-03 10:00:34 -05001525 /** (to be made private)
Cary Clark50fa3ff2017-07-26 10:15:23 -04001526 Returns true if SkPaint does not include elements requiring extensive computation
1527 to compute SkBaseDevice bounds of drawn geometry. For instance, SkPaint with SkPathEffect
1528 always returns false.
reed@google.comd5f20792012-05-16 14:15:02 +00001529
Cary Clark50fa3ff2017-07-26 10:15:23 -04001530 @return true if SkPaint allows for fast computation of bounds
1531 */
senorblanco0abdf762015-08-20 11:10:41 -07001532 bool canComputeFastBounds() const;
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001533
Cary Clark2823f9f2018-01-03 10:00:34 -05001534 /** (to be made private)
Cary Clark579985c2017-07-31 11:48:27 -04001535 Only call this if canComputeFastBounds() returned true. This takes a
Cary Clark50fa3ff2017-07-26 10:15:23 -04001536 raw rectangle (the raw bounds of a shape), and adjusts it for stylistic
1537 effects in the paint (e.g. stroking). If needed, it uses the storage
Cary Clarkb7da7232017-09-01 13:49:54 -04001538 parameter. It returns the adjusted bounds that can then be used
Cary Clark50fa3ff2017-07-26 10:15:23 -04001539 for SkCanvas::quickReject tests.
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001540
Cary Clarkb7da7232017-09-01 13:49:54 -04001541 The returned SkRect will either be orig or storage, thus the caller
Cary Clark50fa3ff2017-07-26 10:15:23 -04001542 should not rely on storage being set to the result, but should always
Cary Clarkb7da7232017-09-01 13:49:54 -04001543 use the returned value. It is legal for orig and storage to be the same
1544 SkRect.
Cary Clark2823f9f2018-01-03 10:00:34 -05001545 e.g.
1546 if (paint.canComputeFastBounds()) {
1547 SkRect r, storage;
1548 path.computeBounds(&r, SkPath::kFast_BoundsType);
1549 const SkRect& fastR = paint.computeFastBounds(r, &storage);
1550 if (canvas->quickReject(fastR, ...)) {
1551 // don't draw the path
1552 }
1553 }
Cary Clark50fa3ff2017-07-26 10:15:23 -04001554
1555 @param orig geometry modified by SkPaint when drawn
1556 @param storage computed bounds of geometry; may not be nullptr
1557 @return fast computed bounds
1558 */
reed@google.coma584aed2012-05-16 14:06:02 +00001559 const SkRect& computeFastBounds(const SkRect& orig, SkRect* storage) const {
Brian Osman60751d72017-05-12 11:21:36 -04001560 // Things like stroking, etc... will do math on the bounds rect, assuming that it's sorted.
1561 SkASSERT(orig.isSorted());
reed@google.coma584aed2012-05-16 14:06:02 +00001562 SkPaint::Style style = this->getStyle();
1563 // ultra fast-case: filling with no effects that affect geometry
1564 if (kFill_Style == style) {
1565 uintptr_t effects = reinterpret_cast<uintptr_t>(this->getLooper());
1566 effects |= reinterpret_cast<uintptr_t>(this->getMaskFilter());
1567 effects |= reinterpret_cast<uintptr_t>(this->getPathEffect());
senorblanco@chromium.org336d1d72014-01-27 21:03:17 +00001568 effects |= reinterpret_cast<uintptr_t>(this->getImageFilter());
reed@google.coma584aed2012-05-16 14:06:02 +00001569 if (!effects) {
1570 return orig;
1571 }
1572 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001573
reed@google.coma584aed2012-05-16 14:06:02 +00001574 return this->doComputeFastBounds(orig, storage, style);
1575 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001576
Cary Clark2823f9f2018-01-03 10:00:34 -05001577 /** (to be made private)
Cary Clark50fa3ff2017-07-26 10:15:23 -04001578
1579 @param orig geometry modified by SkPaint when drawn
1580 @param storage computed bounds of geometry
1581 @return fast computed bounds
1582 */
reed@google.coma584aed2012-05-16 14:06:02 +00001583 const SkRect& computeFastStrokeBounds(const SkRect& orig,
1584 SkRect* storage) const {
reed@google.com73a02582012-05-16 19:21:12 +00001585 return this->doComputeFastBounds(orig, storage, kStroke_Style);
reed@google.coma584aed2012-05-16 14:06:02 +00001586 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001587
Cary Clark2823f9f2018-01-03 10:00:34 -05001588 /** (to be made private)
Cary Clarkb7da7232017-09-01 13:49:54 -04001589 Computes the bounds, overriding the SkPaint SkPaint::Style. This can be used to
1590 account for additional width required by stroking orig, without
1591 altering SkPaint::Style set to fill.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001592
1593 @param orig geometry modified by SkPaint when drawn
1594 @param storage computed bounds of geometry
1595 @param style overrides SkPaint::Style
1596 @return fast computed bounds
1597 */
reed@google.coma584aed2012-05-16 14:06:02 +00001598 const SkRect& doComputeFastBounds(const SkRect& orig, SkRect* storage,
Cary Clark0418a882017-05-10 09:07:42 -04001599 Style style) const;
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001600
Cary Clark99885412018-04-05 13:09:58 -04001601 /** Creates string representation of SkPaint. The representation is read by
1602 internal debugging tools.
Cary Clark0418a882017-05-10 09:07:42 -04001603
Cary Clarkb7da7232017-09-01 13:49:54 -04001604 @param str storage for string representation of SkPaint
Cary Clark50fa3ff2017-07-26 10:15:23 -04001605 */
Cary Clark99885412018-04-05 13:09:58 -04001606 void toString(SkString* str) const;
robertphillips@google.com791f12e2013-02-14 13:53:53 +00001607
reed@google.comd5f20792012-05-16 14:15:02 +00001608private:
Cary Clark0418a882017-05-10 09:07:42 -04001609 typedef const SkGlyph& (*GlyphCacheProc)(SkGlyphCache*, const char**);
1610
reeda5ab9ec2016-03-06 18:10:48 -08001611 sk_sp<SkTypeface> fTypeface;
1612 sk_sp<SkPathEffect> fPathEffect;
1613 sk_sp<SkShader> fShader;
reeda5ab9ec2016-03-06 18:10:48 -08001614 sk_sp<SkMaskFilter> fMaskFilter;
1615 sk_sp<SkColorFilter> fColorFilter;
reed46f2d0a2016-09-11 05:40:31 -07001616 sk_sp<SkDrawLooper> fDrawLooper;
reeda5ab9ec2016-03-06 18:10:48 -08001617 sk_sp<SkImageFilter> fImageFilter;
reed@google.comd5f20792012-05-16 14:15:02 +00001618
commit-bot@chromium.orge8807f42014-03-24 23:03:11 +00001619 SkScalar fTextSize;
1620 SkScalar fTextScaleX;
1621 SkScalar fTextSkewX;
reed@google.comd5f20792012-05-16 14:15:02 +00001622 SkColor fColor;
1623 SkScalar fWidth;
1624 SkScalar fMiterLimit;
Mike Reed71fecc32016-11-18 17:19:54 -05001625 uint32_t fBlendMode; // just need 5-6 bits
commit-bot@chromium.orgaca1c012014-02-21 18:18:05 +00001626 union {
1627 struct {
1628 // all of these bitfields should add up to 32
1629 unsigned fFlags : 16;
1630 unsigned fTextAlign : 2;
1631 unsigned fCapType : 2;
1632 unsigned fJoinType : 2;
1633 unsigned fStyle : 2;
1634 unsigned fTextEncoding : 2; // 3 values
1635 unsigned fHinting : 2;
reedf803da12015-01-23 05:58:07 -08001636 unsigned fFilterQuality : 2;
commit-bot@chromium.org85faf502014-04-16 12:58:02 +00001637 //unsigned fFreeBits : 2;
reedf59eab22014-07-14 14:39:15 -07001638 } fBitfields;
1639 uint32_t fBitfieldsUInt;
commit-bot@chromium.orgaca1c012014-02-21 18:18:05 +00001640 };
commit-bot@chromium.orge8807f42014-03-24 23:03:11 +00001641
robertphillipse34f17d2016-07-19 07:59:22 -07001642 static GlyphCacheProc GetGlyphCacheProc(TextEncoding encoding,
robertphillipse34f17d2016-07-19 07:59:22 -07001643 bool needFullMetrics);
reed@google.comd5f20792012-05-16 14:15:02 +00001644
1645 SkScalar measure_text(SkGlyphCache*, const char* text, size_t length,
1646 int* count, SkRect* bounds) const;
1647
joshualitt9e36c1a2015-04-14 12:17:27 -07001648 /*
1649 * The luminance color is used to determine which Gamma Canonical color to map to. This is
1650 * really only used by backends which want to cache glyph masks, and need some way to know if
1651 * they need to generate new masks based off a given color.
1652 */
1653 SkColor computeLuminanceColor() const;
1654
Cary Clarkd98f78c2018-04-26 08:32:37 -04001655 /* This is the size we use when we ask for a glyph's path. We then
1656 * post-transform it as we draw to match the request.
1657 * This is done to try to re-use cache entries for the path.
1658 *
1659 * This value is somewhat arbitrary. In theory, it could be 1, since
1660 * we store paths as floats. However, we get the path from the font
1661 * scaler, and it may represent its paths as fixed-point (or 26.6),
1662 * so we shouldn't ask for something too big (might overflow 16.16)
1663 * or too small (underflow 26.6).
1664 *
1665 * This value could track kMaxSizeForGlyphCache, assuming the above
1666 * constraints, but since we ask for unhinted paths, the two values
1667 * need not match per-se.
1668 */
1669 static constexpr int kCanonicalTextSizeForPaths = 64;
reed@google.comed43dff2013-06-04 16:56:27 +00001670
Jim Van Verthc65b65d2018-01-16 16:26:35 -05001671 static bool TooBigToUseCache(const SkMatrix& ctm, const SkMatrix& textM, SkScalar maxLimit);
reed@google.comed43dff2013-06-04 16:56:27 +00001672
reed@google.comed43dff2013-06-04 16:56:27 +00001673 // Set flags/hinting/textSize up to use for drawing text as paths.
1674 // Returns scale factor to restore the original textSize, since will will
1675 // have change it to kCanonicalTextSizeForPaths.
1676 SkScalar setupForAsPaths();
1677
Jim Van Verthc65b65d2018-01-16 16:26:35 -05001678 static SkScalar MaxCacheSize2(SkScalar maxLimit);
reed@google.comed43dff2013-06-04 16:56:27 +00001679
Herb Derby980a48d2018-01-23 13:39:21 -05001680 friend class GrAtlasTextBlob;
1681 friend class GrAtlasTextContext;
1682 friend class GrGLPathRendering;
1683 friend class GrPathRendering;
Herb Derby980a48d2018-01-23 13:39:21 -05001684 friend class GrTextUtils;
jvanverth2d2a68c2014-06-10 06:42:56 -07001685 friend class SkAutoGlyphCacheNoGamma;
Herb Derby980a48d2018-01-23 13:39:21 -05001686 friend class SkCanonicalizePaint;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001687 friend class SkCanvas;
1688 friend class SkDraw;
Cary Clark60ca8672018-03-06 15:09:27 -05001689 friend class SkPaintPriv;
vandebo@chromium.org28be72b2010-11-11 21:37:00 +00001690 friend class SkPDFDevice;
Herb Derby980a48d2018-01-23 13:39:21 -05001691 friend class SkScalerContext; // for computeLuminanceColor()
caryclark0449bcf2016-02-09 13:25:45 -08001692 friend class SkTextBaseIter;
Khushal51371a42018-05-17 10:41:40 -07001693 friend class SkTextBlobCacheDiffCanvas;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001694};
1695
reed@android.com8a1c16f2008-12-17 15:59:43 +00001696#endif