blob: 5cd05a2ddc470733db1baabe9fabcb8ef5b9377c [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00006 */
7
8#ifndef SkPaint_DEFINED
9#define SkPaint_DEFINED
10
reed374772b2016-10-05 17:33:02 -070011#include "SkBlendMode.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000012#include "SkColor.h"
reedf803da12015-01-23 05:58:07 -080013#include "SkFilterQuality.h"
reed@google.comed43dff2013-06-04 16:56:27 +000014#include "SkMatrix.h"
Mike Reed71fecc32016-11-18 17:19:54 -050015#include "SkRefCnt.h"
reed@android.coma0f5d152009-06-22 17:38:10 +000016
joshualitt2b6acb42015-04-01 11:30:27 -070017class SkAutoDescriptor;
reed@android.com8a1c16f2008-12-17 15:59:43 +000018class SkAutoGlyphCache;
19class SkColorFilter;
joshualittfd450792015-03-13 08:38:43 -070020class SkData;
reed@android.com8a1c16f2008-12-17 15:59:43 +000021class SkDescriptor;
senorblanco0abdf762015-08-20 11:10:41 -070022class SkDrawLooper;
herbb69d0e02015-02-25 06:47:06 -080023class SkGlyph;
reed@android.com8a1c16f2008-12-17 15:59:43 +000024struct SkRect;
25class SkGlyphCache;
reed@google.com15356a62011-11-03 19:29:08 +000026class SkImageFilter;
reed@android.com8a1c16f2008-12-17 15:59:43 +000027class SkMaskFilter;
reed@android.com8a1c16f2008-12-17 15:59:43 +000028class SkPath;
29class SkPathEffect;
djsollen@google.comc73dd5c2012-08-07 15:54:32 +000030struct SkPoint;
reed@android.com8a1c16f2008-12-17 15:59:43 +000031class SkShader;
robertphillipsfcf78292015-06-19 11:49:52 -070032class SkSurfaceProps;
fmalitaeae6a912016-07-28 09:47:24 -070033class SkTextBlob;
reed@android.com8a1c16f2008-12-17 15:59:43 +000034class SkTypeface;
reed@android.com8a1c16f2008-12-17 15:59:43 +000035
reed@android.com8a1c16f2008-12-17 15:59:43 +000036/** \class SkPaint
Cary Clark50fa3ff2017-07-26 10:15:23 -040037 SkPaint controls options applied when drawing and measuring. SkPaint collects all
38 options outside of the SkCanvas clip and SkCanvas matrix.
reed@android.com8a1c16f2008-12-17 15:59:43 +000039
Cary Clark50fa3ff2017-07-26 10:15:23 -040040 Various options apply to text, strokes and fills, and images.
41
42 Some options may not be implemented on all platforms; in these cases, setting
43 the option has no effect. Some options are conveniences that duplicate SkCanvas
44 functionality; for instance, text size is identical to matrix scale.
45
46 SkPaint options are rarely exclusive; each option modifies a stage of the drawing
Cary Clark23890a92017-07-27 16:30:51 -040047 pipeline and multiple pipeline stages may be affected by a single SkPaint.
Cary Clark50fa3ff2017-07-26 10:15:23 -040048
Cary Clark23890a92017-07-27 16:30:51 -040049 SkPaint collects effects and filters that describe single-pass and multiple-pass
Cary Clark50fa3ff2017-07-26 10:15:23 -040050 algorithms that alter the drawing geometry, color, and transparency. For instance,
51 SkPaint does not directly implement dashing or blur, but contains the objects that do so.
52
53 The objects contained by SkPaint are opaque, and cannot be edited outside of the SkPaint
54 to affect it. The implementation is free to defer computations associated with the
55 SkPaint, or ignore them altogether. For instance, some GPU implementations draw all
Cary Clarkb7da7232017-09-01 13:49:54 -040056 SkPath geometries with anti-aliasing, regardless of how SkPaint::kAntiAlias_Flag
57 is set in SkPaint.
Cary Clark50fa3ff2017-07-26 10:15:23 -040058
59 SkPaint describes a single color, a single font, a single image quality, and so on.
60 Multiple colors are drawn either by using multiple paints or with objects like
61 SkShader attached to SkPaint.
reed@android.com8a1c16f2008-12-17 15:59:43 +000062*/
ctguil@chromium.org7ffb1b22011-03-15 21:27:08 +000063class SK_API SkPaint {
reed@android.com8a1c16f2008-12-17 15:59:43 +000064public:
Cary Clark50fa3ff2017-07-26 10:15:23 -040065
66 /** Constructs SkPaint with default values.
67
68 @return default initialized SkPaint
69 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000070 SkPaint();
Cary Clark50fa3ff2017-07-26 10:15:23 -040071
72 /** Makes a shallow copy of SkPaint. SkTypeface, SkPathEffect, SkShader,
Mike Reed8ad91a92018-01-19 19:09:32 -050073 SkMaskFilter, SkColorFilter, SkDrawLooper, and SkImageFilter are shared
Cary Clarkb7da7232017-09-01 13:49:54 -040074 between the original paint and the copy. Objects containing SkRefCnt increment
75 their references by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -040076
Mike Reed8ad91a92018-01-19 19:09:32 -050077 The referenced objects SkPathEffect, SkShader, SkMaskFilter, SkColorFilter,
Cary Clark50fa3ff2017-07-26 10:15:23 -040078 SkDrawLooper, and SkImageFilter cannot be modified after they are created.
79 This prevents objects with SkRefCnt from being modified once SkPaint refers to them.
80
81 @param paint original to copy
82 @return shallow copy of paint
83 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000084 SkPaint(const SkPaint& paint);
Cary Clark50fa3ff2017-07-26 10:15:23 -040085
Cary Clark8a02b0b2017-09-21 12:28:43 -040086 /** Implements a move constructor to avoid increasing the reference counts
Cary Clark50fa3ff2017-07-26 10:15:23 -040087 of objects referenced by the paint.
88
89 After the call, paint is undefined, and can be safely destructed.
90
91 @param paint original to move
92 @return content of paint
93 */
bungemanccce0e02016-02-07 14:37:23 -080094 SkPaint(SkPaint&& paint);
Cary Clark50fa3ff2017-07-26 10:15:23 -040095
96 /** Decreases SkPaint SkRefCnt of owned objects: SkTypeface, SkPathEffect, SkShader,
Mike Reed8ad91a92018-01-19 19:09:32 -050097 SkMaskFilter, SkColorFilter, SkDrawLooper, and SkImageFilter. If the
Cary Clarkb7da7232017-09-01 13:49:54 -040098 objects containing SkRefCnt go to zero, they are deleted.
Cary Clark50fa3ff2017-07-26 10:15:23 -040099 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000100 ~SkPaint();
101
Cary Clark50fa3ff2017-07-26 10:15:23 -0400102 /** Makes a shallow copy of SkPaint. SkTypeface, SkPathEffect, SkShader,
Mike Reed8ad91a92018-01-19 19:09:32 -0500103 SkMaskFilter, SkColorFilter, SkDrawLooper, and SkImageFilter are shared
Cary Clarkb7da7232017-09-01 13:49:54 -0400104 between the original paint and the copy. Objects containing SkRefCnt in the
Cary Clark50fa3ff2017-07-26 10:15:23 -0400105 prior destination are decreased by one, and the referenced objects are deleted if the
Cary Clarkb7da7232017-09-01 13:49:54 -0400106 resulting count is zero. Objects containing SkRefCnt in the parameter paint
107 are increased by one. paint is unmodified.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400108
109 @param paint original to copy
110 @return content of paint
111 */
Cary Clark0418a882017-05-10 09:07:42 -0400112 SkPaint& operator=(const SkPaint& paint);
Cary Clark50fa3ff2017-07-26 10:15:23 -0400113
Cary Clark8a02b0b2017-09-21 12:28:43 -0400114 /** Moves the paint to avoid increasing the reference counts
Cary Clarkb7da7232017-09-01 13:49:54 -0400115 of objects referenced by the paint parameter. Objects containing SkRefCnt in the
116 prior destination are decreased by one; those objects are deleted if the resulting count
117 is zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400118
119 After the call, paint is undefined, and can be safely destructed.
120
121 @param paint original to move
122 @return content of paint
123 */
Cary Clark0418a882017-05-10 09:07:42 -0400124 SkPaint& operator=(SkPaint&& paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000125
Cary Clark50fa3ff2017-07-26 10:15:23 -0400126 /** Compares a and b, and returns true if a and b are equivalent. May return false
Mike Reed8ad91a92018-01-19 19:09:32 -0500127 if SkTypeface, SkPathEffect, SkShader, SkMaskFilter, SkColorFilter,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400128 SkDrawLooper, or SkImageFilter have identical contents but different pointers.
129
130 @param a SkPaint to compare
131 @param b SkPaint to compare
132 @return true if SkPaint pair are equivalent
mtkleinbc97ef42014-08-25 10:10:47 -0700133 */
robertphillips@google.comb2657412013-08-07 22:36:29 +0000134 SK_API friend bool operator==(const SkPaint& a, const SkPaint& b);
Cary Clark50fa3ff2017-07-26 10:15:23 -0400135
136 /** Compares a and b, and returns true if a and b are not equivalent. May return true
Mike Reed8ad91a92018-01-19 19:09:32 -0500137 if SkTypeface, SkPathEffect, SkShader, SkMaskFilter, SkColorFilter,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400138 SkDrawLooper, or SkImageFilter have identical contents but different pointers.
139
140 @param a SkPaint to compare
141 @param b SkPaint to compare
142 @return true if SkPaint pair are not equivalent
143 */
robertphillips@google.comb2657412013-08-07 22:36:29 +0000144 friend bool operator!=(const SkPaint& a, const SkPaint& b) {
145 return !(a == b);
146 }
147
Cary Clark50fa3ff2017-07-26 10:15:23 -0400148 /** Returns a hash generated from SkPaint values and pointers.
149 Identical hashes guarantee that the paints are
150 equivalent, but differing hashes do not guarantee that the paints have differing
151 contents.
152
153 If operator==(const SkPaint& a, const SkPaint& b) returns true for two paints,
154 their hashes are also equal.
155
156 The hash returned is platform and implementation specific.
157
158 @return a shallow hash
159 */
mtkleinfb1fe4f2014-10-07 09:26:10 -0700160 uint32_t getHash() const;
161
Cary Clarkcc309eb2017-10-30 11:48:35 -0400162 /** Sets all SkPaint contents to their initial values. This is equivalent to replacing
163 SkPaint with the result of SkPaint().
reed@android.com8a1c16f2008-12-17 15:59:43 +0000164 */
165 void reset();
166
Cary Clark50fa3ff2017-07-26 10:15:23 -0400167 /** \enum SkPaint::Hinting
168 Hinting adjusts the glyph outlines so that the shape provides a uniform
169 look at a given point size on font engines that support it. Hinting may have a
170 muted effect or no effect at all depending on the platform.
171
172 The four levels roughly control corresponding features on platforms that use FreeType
173 as the font engine.
agl@chromium.org309485b2009-07-21 17:41:32 +0000174 */
175 enum Hinting {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400176 /** Leaves glyph outlines unchanged from their native representation.
177 With FreeType, this is equivalent to the FT_LOAD_NO_HINTING
178 bit-field constant supplied to FT_Load_Glyph, which indicates that the vector
179 outline being loaded should not be fitted to the pixel grid but simply scaled
180 to 26.6 fractional pixels.
181 */
182 kNo_Hinting = 0,
183
184 /** Modifies glyph outlines minimally to improve constrast.
185 With FreeType, this is equivalent in spirit to the
186 FT_LOAD_TARGET_LIGHT value supplied to FT_Load_Glyph. It chooses a
187 lighter hinting algorithm for non-monochrome modes.
188 Generated glyphs may be fuzzy but better resemble their original shape.
189 */
190 kSlight_Hinting = 1,
191
192 /** Modifies glyph outlines to improve constrast. This is the default.
193 With FreeType, this supplies FT_LOAD_TARGET_NORMAL to FT_Load_Glyph,
194 choosing the default hinting algorithm, which is optimized for standard
195 gray-level rendering.
196 */
197 kNormal_Hinting = 2,
198
199 /** Modifies glyph outlines for maxiumum constrast. With FreeType, this selects
200 FT_LOAD_TARGET_LCD or FT_LOAD_TARGET_LCD_V if kLCDRenderText_Flag is set.
201 FT_LOAD_TARGET_LCD is a variant of FT_LOAD_TARGET_NORMAL optimized for
202 horizontally decimated LCD displays; FT_LOAD_TARGET_LCD_V is a
203 variant of FT_LOAD_TARGET_NORMAL optimized for vertically decimated LCD displays.
204 */
205 kFull_Hinting = 3,
agl@chromium.org309485b2009-07-21 17:41:32 +0000206 };
207
Cary Clark50fa3ff2017-07-26 10:15:23 -0400208 /** Returns level of glyph outline adjustment.
209
210 @return one of: kNo_Hinting, kSlight_Hinting, kNormal_Hinting, kFull_Hinting
211 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000212 Hinting getHinting() const {
reedf59eab22014-07-14 14:39:15 -0700213 return static_cast<Hinting>(fBitfields.fHinting);
agl@chromium.org309485b2009-07-21 17:41:32 +0000214 }
215
Cary Clark50fa3ff2017-07-26 10:15:23 -0400216 /** Sets level of glyph outline adjustment.
217 Does not check for valid values of hintingLevel.
218
219 @param hintingLevel one of: kNo_Hinting, kSlight_Hinting, kNormal_Hinting, kFull_Hinting
220 */
djsollen@google.comf5dbe2f2011-04-15 13:41:26 +0000221 void setHinting(Hinting hintingLevel);
agl@chromium.org309485b2009-07-21 17:41:32 +0000222
Cary Clark50fa3ff2017-07-26 10:15:23 -0400223 /** \enum SkPaint::Flags
224 The bit values stored in Flags.
225 The default value for Flags, normally zero, can be changed at compile time
226 with a custom definition of SkPaintDefaults_Flags.
227 All flags can be read and written explicitly; Flags allows manipulating
228 multiple settings at once.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000229 */
230 enum Flags {
Cary Clark1eace2d2017-07-31 07:52:43 -0400231 kAntiAlias_Flag = 0x01, //!< mask for setting anti-alias
232 kDither_Flag = 0x04, //!< mask for setting dither
Cary Clark50fa3ff2017-07-26 10:15:23 -0400233 kFakeBoldText_Flag = 0x20, //!< mask for setting fake bold
234 kLinearText_Flag = 0x40, //!< mask for setting linear text
235 kSubpixelText_Flag = 0x80, //!< mask for setting subpixel text
236 kDevKernText_Flag = 0x100, //!< mask for setting full hinting spacing
Cary Clark75959392018-02-27 10:22:04 -0500237 kLCDRenderText_Flag = 0x200, //!< mask for setting LCD text
Cary Clark50fa3ff2017-07-26 10:15:23 -0400238 kEmbeddedBitmapText_Flag = 0x400, //!< mask for setting font embedded bitmaps
239 kAutoHinting_Flag = 0x800, //!< mask for setting auto-hinting
240 kVerticalText_Flag = 0x1000, //!< mask for setting vertical text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000241
Cary Clark50fa3ff2017-07-26 10:15:23 -0400242 /** Hack for GDI -- do not use if you can help it */
243 kGenA8FromLCD_Flag = 0x2000,
244
245 /** mask of all Flags, including private flags and flags reserved for future use */
246 kAllFlags = 0xFFFF,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000247 };
248
Cary Clark50fa3ff2017-07-26 10:15:23 -0400249 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Mike Reedddbd37e2017-02-21 15:07:44 -0500250 enum ReserveFlags {
Cary Clark75959392018-02-27 10:22:04 -0500251 kUnderlineText_ReserveFlag = 0x08, //!< deprecated
252 kStrikeThruText_ReserveFlag = 0x10, //!< deprecated
Mike Reedddbd37e2017-02-21 15:07:44 -0500253 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400254 #endif
Mike Reedddbd37e2017-02-21 15:07:44 -0500255
Cary Clark50fa3ff2017-07-26 10:15:23 -0400256 /** Returns paint settings described by SkPaint::Flags. Each setting uses one
257 bit, and can be tested with SkPaint::Flags members.
258
259 @return zero, one, or more bits described by SkPaint::Flags
reed@android.com8a1c16f2008-12-17 15:59:43 +0000260 */
reedf59eab22014-07-14 14:39:15 -0700261 uint32_t getFlags() const { return fBitfields.fFlags; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000262
Cary Clark23890a92017-07-27 16:30:51 -0400263 /** Replaces SkPaint::Flags with flags, the union of the SkPaint::Flags members.
264 All SkPaint::Flags members may be cleared, or one or more may be set.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400265
266 @param flags union of SkPaint::Flags for SkPaint
reed@android.com8a1c16f2008-12-17 15:59:43 +0000267 */
268 void setFlags(uint32_t flags);
269
Cary Clark50fa3ff2017-07-26 10:15:23 -0400270 /** If true, pixels on the active edges of SkPath may be drawn with partial transparency.
271
Cary Clark579985c2017-07-31 11:48:27 -0400272 Equivalent to getFlags() masked with kAntiAlias_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400273
274 @return kAntiAlias_Flag state
275 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000276 bool isAntiAlias() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000277 return SkToBool(this->getFlags() & kAntiAlias_Flag);
278 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000279
Cary Clark50fa3ff2017-07-26 10:15:23 -0400280 /** Requests, but does not require, that SkPath edge pixels draw opaque or with
281 partial transparency.
282
283 Sets kAntiAlias_Flag if aa is true.
284 Clears kAntiAlias_Flag if aa is false.
285
286 @param aa setting for kAntiAlias_Flag
287 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000288 void setAntiAlias(bool aa);
reed@google.com9d07fec2011-03-16 20:02:59 +0000289
Cary Clark50fa3ff2017-07-26 10:15:23 -0400290 /** If true, color error may be distributed to smooth color transition.
291
Cary Clark579985c2017-07-31 11:48:27 -0400292 Equivalent to getFlags() masked with kDither_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400293
294 @return kDither_Flag state
295 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000296 bool isDither() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000297 return SkToBool(this->getFlags() & kDither_Flag);
298 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000299
Cary Clark50fa3ff2017-07-26 10:15:23 -0400300 /** Requests, but does not require, to distribute color error.
301
302 Sets kDither_Flag if dither is true.
303 Clears kDither_Flag if dither is false.
304
305 @param dither setting for kDither_Flag
306 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000307 void setDither(bool dither);
reed@google.com9d07fec2011-03-16 20:02:59 +0000308
Cary Clark50fa3ff2017-07-26 10:15:23 -0400309 /** If true, text is converted to SkPath before drawing and measuring.
310
Cary Clark579985c2017-07-31 11:48:27 -0400311 Equivalent to getFlags() masked with kLinearText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400312
313 @return kLinearText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000314 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000315 bool isLinearText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000316 return SkToBool(this->getFlags() & kLinearText_Flag);
317 }
318
Cary Clark50fa3ff2017-07-26 10:15:23 -0400319 /** If true, text is converted to SkPath before drawing and measuring.
320 By default, kLinearText_Flag is clear.
321
322 Sets kLinearText_Flag if linearText is true.
323 Clears kLinearText_Flag if linearText is false.
324
325 @param linearText setting for kLinearText_Flag
reed@android.com8a1c16f2008-12-17 15:59:43 +0000326 */
327 void setLinearText(bool linearText);
328
Cary Clark50fa3ff2017-07-26 10:15:23 -0400329 /** If true, glyphs at different sub-pixel positions may differ on pixel edge coverage.
330
Cary Clark579985c2017-07-31 11:48:27 -0400331 Equivalent to getFlags() masked with kSubpixelText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400332
333 @return kSubpixelText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000334 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000335 bool isSubpixelText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000336 return SkToBool(this->getFlags() & kSubpixelText_Flag);
337 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000338
Cary Clark50fa3ff2017-07-26 10:15:23 -0400339 /** Requests, but does not require, that glyphs respect sub-pixel positioning.
340
341 Sets kSubpixelText_Flag if subpixelText is true.
342 Clears kSubpixelText_Flag if subpixelText is false.
343
344 @param subpixelText setting for kSubpixelText_Flag
345 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000346 void setSubpixelText(bool subpixelText);
agl@chromium.org309485b2009-07-21 17:41:32 +0000347
Cary Clark50fa3ff2017-07-26 10:15:23 -0400348 /** If true, glyphs may use LCD striping to improve glyph edges.
349
350 Returns true if SkPaint::Flags kLCDRenderText_Flag is set.
351
352 @return kLCDRenderText_Flag state
353 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000354 bool isLCDRenderText() const {
agl@chromium.org309485b2009-07-21 17:41:32 +0000355 return SkToBool(this->getFlags() & kLCDRenderText_Flag);
356 }
357
Cary Clark50fa3ff2017-07-26 10:15:23 -0400358 /** Requests, but does not require, that glyphs use LCD striping for glyph edges.
359
360 Sets kLCDRenderText_Flag if lcdText is true.
361 Clears kLCDRenderText_Flag if lcdText is false.
362
363 @param lcdText setting for kLCDRenderText_Flag
364 */
reed@google.com84b437e2011-08-01 12:45:35 +0000365 void setLCDRenderText(bool lcdText);
agl@chromium.org309485b2009-07-21 17:41:32 +0000366
Cary Clark50fa3ff2017-07-26 10:15:23 -0400367 /** If true, font engine may return glyphs from font bitmaps instead of from outlines.
368
Cary Clark579985c2017-07-31 11:48:27 -0400369 Equivalent to getFlags() masked with kEmbeddedBitmapText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400370
371 @return kEmbeddedBitmapText_Flag state
372 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000373 bool isEmbeddedBitmapText() const {
agl@chromium.orge95c91e2010-01-04 18:27:55 +0000374 return SkToBool(this->getFlags() & kEmbeddedBitmapText_Flag);
375 }
376
Cary Clark50fa3ff2017-07-26 10:15:23 -0400377 /** Requests, but does not require, to use bitmaps in fonts instead of outlines.
378
379 Sets kEmbeddedBitmapText_Flag if useEmbeddedBitmapText is true.
380 Clears kEmbeddedBitmapText_Flag if useEmbeddedBitmapText is false.
381
382 @param useEmbeddedBitmapText setting for kEmbeddedBitmapText_Flag
agl@chromium.orge95c91e2010-01-04 18:27:55 +0000383 */
384 void setEmbeddedBitmapText(bool useEmbeddedBitmapText);
385
Cary Clark50fa3ff2017-07-26 10:15:23 -0400386 /** If true, and if SkPaint::Hinting is set to kNormal_Hinting or kFull_Hinting, and if
387 platform uses FreeType as the font manager, instruct the font manager to always hint
Cary Clark1eace2d2017-07-31 07:52:43 -0400388 glyphs.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400389
Cary Clark579985c2017-07-31 11:48:27 -0400390 Equivalent to getFlags() masked with kAutoHinting_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400391
392 @return kAutoHinting_Flag state
393 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000394 bool isAutohinted() const {
agl@chromium.orga2c71cb2010-06-17 20:49:17 +0000395 return SkToBool(this->getFlags() & kAutoHinting_Flag);
396 }
397
Cary Clark50fa3ff2017-07-26 10:15:23 -0400398 /** If SkPaint::Hinting is set to kNormal_Hinting or kFull_Hinting and useAutohinter is set,
Cary Clark1eace2d2017-07-31 07:52:43 -0400399 instruct the font manager to always hint glyphs.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400400 auto-hinting has no effect if SkPaint::Hinting is set to kNo_Hinting or
401 kSlight_Hinting.
402
Cary Clark579985c2017-07-31 11:48:27 -0400403 Only affects platforms that use FreeType as the font manager.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400404
405 Sets kAutoHinting_Flag if useAutohinter is true.
406 Clears kAutoHinting_Flag if useAutohinter is false.
407
408 @param useAutohinter setting for kAutoHinting_Flag
agl@chromium.orga2c71cb2010-06-17 20:49:17 +0000409 */
410 void setAutohinted(bool useAutohinter);
411
Cary Clark50fa3ff2017-07-26 10:15:23 -0400412 /** If true, glyphs are drawn top to bottom instead of left to right.
413
Cary Clark579985c2017-07-31 11:48:27 -0400414 Equivalent to getFlags() masked with kVerticalText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400415
416 @return kVerticalText_Flag state
417 */
reed@google.com830a23e2011-11-10 15:20:49 +0000418 bool isVerticalText() const {
419 return SkToBool(this->getFlags() & kVerticalText_Flag);
420 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000421
Cary Clark50fa3ff2017-07-26 10:15:23 -0400422 /** If true, text advance positions the next glyph below the previous glyph instead of to the
423 right of previous glyph.
424
425 Sets kVerticalText_Flag if vertical is true.
426 Clears kVerticalText_Flag if vertical is false.
427
428 @param verticalText setting for kVerticalText_Flag
429 */
Cary Clark0418a882017-05-10 09:07:42 -0400430 void setVerticalText(bool verticalText);
reed@google.com830a23e2011-11-10 15:20:49 +0000431
Cary Clark50fa3ff2017-07-26 10:15:23 -0400432 /** If true, approximate bold by increasing the stroke width when creating glyph bitmaps
433 from outlines.
434
Cary Clark579985c2017-07-31 11:48:27 -0400435 Equivalent to getFlags() masked with kFakeBoldText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400436
437 @return kFakeBoldText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000438 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000439 bool isFakeBoldText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000440 return SkToBool(this->getFlags() & kFakeBoldText_Flag);
441 }
442
Cary Clarkb7da7232017-09-01 13:49:54 -0400443 /** Use increased stroke width when creating glyph bitmaps to approximate a bold typeface.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400444
445 Sets kFakeBoldText_Flag if fakeBoldText is true.
446 Clears kFakeBoldText_Flag if fakeBoldText is false.
447
448 @param fakeBoldText setting for kFakeBoldText_Flag
reed@android.com8a1c16f2008-12-17 15:59:43 +0000449 */
450 void setFakeBoldText(bool fakeBoldText);
451
Cary Clark50fa3ff2017-07-26 10:15:23 -0400452 /** Returns if character spacing may be adjusted by the hinting difference.
453
Cary Clark579985c2017-07-31 11:48:27 -0400454 Equivalent to getFlags() masked with kDevKernText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400455
456 @return kDevKernText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000457 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000458 bool isDevKernText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000459 return SkToBool(this->getFlags() & kDevKernText_Flag);
460 }
461
Cary Clark50fa3ff2017-07-26 10:15:23 -0400462 /** Requests, but does not require, to use hinting to adjust glyph spacing.
463
464 Sets kDevKernText_Flag if devKernText is true.
465 Clears kDevKernText_Flag if devKernText is false.
466
467 @param devKernText setting for devKernText
reed@android.com8a1c16f2008-12-17 15:59:43 +0000468 */
469 void setDevKernText(bool devKernText);
470
Cary Clark50fa3ff2017-07-26 10:15:23 -0400471 /** Returns SkFilterQuality, the image filtering level. A lower setting
472 draws faster; a higher setting looks better when the image is scaled.
473
474 @return one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
475 kMedium_SkFilterQuality, kHigh_SkFilterQuality
476 */
reedf803da12015-01-23 05:58:07 -0800477 SkFilterQuality getFilterQuality() const {
478 return (SkFilterQuality)fBitfields.fFilterQuality;
479 }
mtkleinfe81e2d2015-09-09 07:35:42 -0700480
Cary Clark23890a92017-07-27 16:30:51 -0400481 /** Sets SkFilterQuality, the image filtering level. A lower setting
Cary Clark50fa3ff2017-07-26 10:15:23 -0400482 draws faster; a higher setting looks better when the image is scaled.
Cary Clark579985c2017-07-31 11:48:27 -0400483 Does not check to see if quality is valid.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400484
485 @param quality one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
486 kMedium_SkFilterQuality, kHigh_SkFilterQuality
487 */
reedf803da12015-01-23 05:58:07 -0800488 void setFilterQuality(SkFilterQuality quality);
reed@google.comc9683152013-07-18 13:47:01 +0000489
Cary Clark50fa3ff2017-07-26 10:15:23 -0400490 /** \enum SkPaint::Style
Cary Clark23890a92017-07-27 16:30:51 -0400491 Set Style to fill, stroke, or both fill and stroke geometry.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400492 The stroke and fill
493 share all paint attributes; for instance, they are drawn with the same color.
reed@google.com9d07fec2011-03-16 20:02:59 +0000494
Cary Clark50fa3ff2017-07-26 10:15:23 -0400495 Use kStrokeAndFill_Style to avoid hitting the same pixels twice with a stroke draw and
496 a fill draw.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000497 */
498 enum Style {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400499 /** Set to fill geometry.
Cary Clark1eace2d2017-07-31 07:52:43 -0400500 Applies to SkRect, SkRegion, SkRRect, circles, ovals, SkPath, and text.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400501 SkBitmap, SkImage, patches, SkRegion, sprites, and vertices are painted as if
502 kFill_Style is set, and ignore the set Style.
503 The FillType specifies additional rules to fill the area outside the path edge,
504 and to create an unfilled hole inside the shape.
505 Style is set to kFill_Style by default.
506 */
507 kFill_Style,
508
509 /** Set to stroke geometry.
Cary Clarkb7da7232017-09-01 13:49:54 -0400510 Applies to SkRect, SkRegion, SkRRect, arcs, circles, ovals, SkPath, and text.
Cary Clark2823f9f2018-01-03 10:00:34 -0500511 Arcs, lines, and points, are always drawn as if kStroke_Style is set,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400512 and ignore the set Style.
513 The stroke construction is unaffected by the FillType.
514 */
515 kStroke_Style,
516
517 /** Set to stroke and fill geometry.
Cary Clark1eace2d2017-07-31 07:52:43 -0400518 Applies to SkRect, SkRegion, SkRRect, circles, ovals, SkPath, and text.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400519 SkPath is treated as if it is set to SkPath::kWinding_FillType,
520 and the set FillType is ignored.
521 */
522 kStrokeAndFill_Style,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000523 };
524
Cary Clark50fa3ff2017-07-26 10:15:23 -0400525 enum {
526 /** The number of different Style values defined.
527 May be used to verify that Style is a legal value.
528 */
529 kStyleCount = kStrokeAndFill_Style + 1,
530 };
531
532 /** Whether the geometry is filled, stroked, or filled and stroked.
533
534 @return one of:kFill_Style, kStroke_Style, kStrokeAndFill_Style
reed@android.com8a1c16f2008-12-17 15:59:43 +0000535 */
reedf59eab22014-07-14 14:39:15 -0700536 Style getStyle() const { return (Style)fBitfields.fStyle; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000537
Cary Clark50fa3ff2017-07-26 10:15:23 -0400538 /** Sets whether the geometry is filled, stroked, or filled and stroked.
539 Has no effect if style is not a legal SkPaint::Style value.
540
541 @param style one of: kFill_Style, kStroke_Style, kStrokeAndFill_Style
reed@android.com8a1c16f2008-12-17 15:59:43 +0000542 */
543 void setStyle(Style style);
544
Cary Clark50fa3ff2017-07-26 10:15:23 -0400545 /** Retrieves alpha and RGB, unpremultiplied, packed into 32 bits.
546 Use helpers SkColorGetA(), SkColorGetR(), SkColorGetG(), and SkColorGetB() to extract
547 a color component.
548
Cary Clark8a02b0b2017-09-21 12:28:43 -0400549 @return unpremultiplied ARGB
reed@android.com8a1c16f2008-12-17 15:59:43 +0000550 */
551 SkColor getColor() const { return fColor; }
552
Cary Clark50fa3ff2017-07-26 10:15:23 -0400553 /** Sets alpha and RGB used when stroking and filling. The color is a 32-bit value,
Cary Clarkb7da7232017-09-01 13:49:54 -0400554 unpremultiplied, packing 8-bit components for alpha, red, blue, and green.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400555
Cary Clark8a02b0b2017-09-21 12:28:43 -0400556 @param color unpremultiplied ARGB
reed@android.com8a1c16f2008-12-17 15:59:43 +0000557 */
558 void setColor(SkColor color);
559
Cary Clark1eace2d2017-07-31 07:52:43 -0400560 /** Retrieves alpha from the color used when stroking and filling.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400561
Cary Clark8a02b0b2017-09-21 12:28:43 -0400562 @return alpha ranging from zero, fully transparent, to 255, fully opaque
Cary Clark50fa3ff2017-07-26 10:15:23 -0400563 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000564 uint8_t getAlpha() const { return SkToU8(SkColorGetA(fColor)); }
reed@google.com9d07fec2011-03-16 20:02:59 +0000565
Cary Clark50fa3ff2017-07-26 10:15:23 -0400566 /** Replaces alpha, leaving RGB
567 unchanged. An out of range value triggers an assert in the debug
568 build. a is a value from zero to 255.
Cary Clark1eace2d2017-07-31 07:52:43 -0400569 a set to zero makes color fully transparent; a set to 255 makes color
Cary Clark50fa3ff2017-07-26 10:15:23 -0400570 fully opaque.
571
Cary Clark8a02b0b2017-09-21 12:28:43 -0400572 @param a alpha component of color
reed@android.com8a1c16f2008-12-17 15:59:43 +0000573 */
574 void setAlpha(U8CPU a);
575
Cary Clark1eace2d2017-07-31 07:52:43 -0400576 /** Sets color used when drawing solid fills. The color components range from 0 to 255.
Cary Clarkb7da7232017-09-01 13:49:54 -0400577 The color is unpremultiplied; alpha sets the transparency independent of RGB.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400578
Cary Clarkb7da7232017-09-01 13:49:54 -0400579 @param a amount of color alpha, from fully transparent (0) to fully opaque (255)
580 @param r amount of color rgb red, from no red (0) to full red (255)
581 @param g amount of color rgb green, from no green (0) to full green (255)
582 @param b amount of color rgb blue, from no blue (0) to full blue (255)
reed@android.com8a1c16f2008-12-17 15:59:43 +0000583 */
584 void setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b);
585
Cary Clark50fa3ff2017-07-26 10:15:23 -0400586 /** Returns the thickness of the pen used by SkPaint to
587 outline the shape.
588
Cary Clark1eace2d2017-07-31 07:52:43 -0400589 @return zero for hairline, greater than zero for pen thickness
reed@android.com8a1c16f2008-12-17 15:59:43 +0000590 */
591 SkScalar getStrokeWidth() const { return fWidth; }
592
Cary Clark50fa3ff2017-07-26 10:15:23 -0400593 /** Sets the thickness of the pen used by the paint to
594 outline the shape.
595 Has no effect if width is less than zero.
596
Cary Clark1eace2d2017-07-31 07:52:43 -0400597 @param width zero thickness for hairline; greater than zero for pen thickness
reed@android.com8a1c16f2008-12-17 15:59:43 +0000598 */
599 void setStrokeWidth(SkScalar width);
600
Cary Clark50fa3ff2017-07-26 10:15:23 -0400601 /** The limit at which a sharp corner is drawn beveled.
602
603 @return zero and greater miter limit
reed@android.com8a1c16f2008-12-17 15:59:43 +0000604 */
605 SkScalar getStrokeMiter() const { return fMiterLimit; }
606
Cary Clark50fa3ff2017-07-26 10:15:23 -0400607 /** The limit at which a sharp corner is drawn beveled.
608 Valid values are zero and greater.
609 Has no effect if miter is less than zero.
610
611 @param miter zero and greater miter limit
reed@android.com8a1c16f2008-12-17 15:59:43 +0000612 */
613 void setStrokeMiter(SkScalar miter);
614
Cary Clark50fa3ff2017-07-26 10:15:23 -0400615 /** \enum SkPaint::Cap
616 Cap draws at the beginning and end of an open path contour.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000617 */
618 enum Cap {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400619 kButt_Cap, //!< Does not extend the stroke past the beginning or the end.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000620
Cary Clark50fa3ff2017-07-26 10:15:23 -0400621 /** Adds a circle with a diameter equal to stroke width at the beginning
622 and end.
623 */
624 kRound_Cap,
625
626 /** Adds a square with sides equal to stroke width at the beginning
627 and end. The square sides are parallel to the initial and final direction
628 of the stroke.
629 */
630 kSquare_Cap,
631 kLast_Cap = kSquare_Cap, //!< Equivalent to the largest value for Cap.
632
633 /** Equivalent to kButt_Cap.
634 Cap is set to kButt_Cap by default.
635 */
636 kDefault_Cap = kButt_Cap,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000637 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400638
Cary Clark75959392018-02-27 10:22:04 -0500639 /** The number of different SkPaint::Cap values defined.
640 May be used to verify that SkPaint::Cap is a legal value.*/
bsalomona7d85ba2016-07-06 11:54:59 -0700641 static constexpr int kCapCount = kLast_Cap + 1;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000642
Cary Clark50fa3ff2017-07-26 10:15:23 -0400643 /** \enum SkPaint::Join
Cary Clark1eace2d2017-07-31 07:52:43 -0400644 Join specifies how corners are drawn when a shape is stroked. Join
Cary Clark50fa3ff2017-07-26 10:15:23 -0400645 affects the four corners of a stroked rectangle, and the connected segments in a
646 stroked path.
647
648 Choose miter join to draw sharp corners. Choose round join to draw a circle with a
649 radius equal to the stroke width on top of the corner. Choose bevel join to minimally
650 connect the thick strokes.
651
652 The fill path constructed to describe the stroked path respects the join setting but may
653 not contain the actual join. For instance, a fill path constructed with round joins does
654 not necessarily include circles at each connected segment.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000655 */
656 enum Join {
Cary Clark23890a92017-07-27 16:30:51 -0400657 /** Extends the outside corner to the extent allowed by miter limit.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400658 If the extension exceeds miter limit, kBevel_Join is used instead.
659 */
660 kMiter_Join,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000661
Cary Clark50fa3ff2017-07-26 10:15:23 -0400662 /** Adds a circle with a diameter of stroke width at the sharp corner. */
663 kRound_Join,
664 kBevel_Join, //!< Connects the outside edges of the sharp corner.
665 kLast_Join = kBevel_Join, //!< Equivalent to the largest value for Join.
666
667 /** Equivalent to kMiter_Join.
668 Join is set to kMiter_Join by default.
669 */
670 kDefault_Join = kMiter_Join,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000671 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400672
Cary Clark75959392018-02-27 10:22:04 -0500673 /** The number of different SkPaint::Join values defined.
674 May be used to verify that SkPaint::Join is a legal value.*/
bsalomona7d85ba2016-07-06 11:54:59 -0700675 static constexpr int kJoinCount = kLast_Join + 1;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000676
Cary Clark50fa3ff2017-07-26 10:15:23 -0400677 /** The geometry drawn at the beginning and end of strokes.
678
679 @return one of: kButt_Cap, kRound_Cap, kSquare_Cap
reed@android.com8a1c16f2008-12-17 15:59:43 +0000680 */
reedf59eab22014-07-14 14:39:15 -0700681 Cap getStrokeCap() const { return (Cap)fBitfields.fCapType; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000682
Cary Clark50fa3ff2017-07-26 10:15:23 -0400683 /** The geometry drawn at the beginning and end of strokes.
684
685 @param cap one of: kButt_Cap, kRound_Cap, kSquare_Cap;
686 has no effect if cap is not valid
reed@android.com8a1c16f2008-12-17 15:59:43 +0000687 */
688 void setStrokeCap(Cap cap);
689
Cary Clark50fa3ff2017-07-26 10:15:23 -0400690 /** The geometry drawn at the corners of strokes.
691
692 @return one of: kMiter_Join, kRound_Join, kBevel_Join
reed@android.com8a1c16f2008-12-17 15:59:43 +0000693 */
reedf59eab22014-07-14 14:39:15 -0700694 Join getStrokeJoin() const { return (Join)fBitfields.fJoinType; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000695
Cary Clark50fa3ff2017-07-26 10:15:23 -0400696 /** The geometry drawn at the corners of strokes.
697
698 @param join one of: kMiter_Join, kRound_Join, kBevel_Join;
Cary Clark579985c2017-07-31 11:48:27 -0400699 otherwise, has no effect
reed@android.com8a1c16f2008-12-17 15:59:43 +0000700 */
701 void setStrokeJoin(Join join);
702
Cary Clark50fa3ff2017-07-26 10:15:23 -0400703 /** The filled equivalent of the stroked path.
704
705 @param src SkPath read to create a filled version
706 @param dst resulting SkPath; may be the same as src, but may not be nullptr
707 @param cullRect optional limit passed to SkPathEffect
708 @param resScale if > 1, increase precision, else if (0 < res < 1) reduce precision
709 to favor speed and size
Cary Clark1eace2d2017-07-31 07:52:43 -0400710 @return true if the path represents style fill, or false if it represents hairline
Cary Clark50fa3ff2017-07-26 10:15:23 -0400711 */
reed05d90442015-02-12 13:35:52 -0800712 bool getFillPath(const SkPath& src, SkPath* dst, const SkRect* cullRect,
713 SkScalar resScale = 1) const;
714
Cary Clark50fa3ff2017-07-26 10:15:23 -0400715 /** The filled equivalent of the stroked path.
716
Cary Clark23890a92017-07-27 16:30:51 -0400717 Replaces dst with the src path modified by SkPathEffect and style stroke.
718 SkPathEffect, if any, is not culled. stroke width is created with default precision.
719
720 @param src SkPath read to create a filled version
721 @param dst resulting SkPath dst may be the same as src, but may not be nullptr
Cary Clark1eace2d2017-07-31 07:52:43 -0400722 @return true if the path represents style fill, or false if it represents hairline
Cary Clark50fa3ff2017-07-26 10:15:23 -0400723 */
reed05d90442015-02-12 13:35:52 -0800724 bool getFillPath(const SkPath& src, SkPath* dst) const {
Ben Wagnera93a14a2017-08-28 10:34:05 -0400725 return this->getFillPath(src, dst, nullptr, 1);
reed05d90442015-02-12 13:35:52 -0800726 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000727
Cary Clark50fa3ff2017-07-26 10:15:23 -0400728 /** Optional colors used when filling a path, such as a gradient.
729
730 Does not alter SkShader SkRefCnt.
731
732 @return SkShader if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000733 */
reeda5ab9ec2016-03-06 18:10:48 -0800734 SkShader* getShader() const { return fShader.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400735
736 /** Optional colors used when filling a path, such as a gradient.
737
738 Increases SkShader SkRefCnt by one.
739
740 @return SkShader if previously set, nullptr otherwise
741 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500742 sk_sp<SkShader> refShader() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000743
Cary Clark50fa3ff2017-07-26 10:15:23 -0400744 /** Optional colors used when filling a path, such as a gradient.
745
Cary Clark8a02b0b2017-09-21 12:28:43 -0400746 Sets SkShader to shader, decreasing SkRefCnt of the previous SkShader.
747 Increments shader SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400748
Cary Clark1eace2d2017-07-31 07:52:43 -0400749 @param shader how geometry is filled with color; if nullptr, color is used instead
Cary Clark50fa3ff2017-07-26 10:15:23 -0400750 */
Cary Clark0418a882017-05-10 09:07:42 -0400751 void setShader(sk_sp<SkShader> shader);
reed@google.com9d07fec2011-03-16 20:02:59 +0000752
Cary Clark50fa3ff2017-07-26 10:15:23 -0400753 /** Returns SkColorFilter if set, or nullptr.
754 Does not alter SkColorFilter SkRefCnt.
755
756 @return SkColorFilter if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000757 */
reeda5ab9ec2016-03-06 18:10:48 -0800758 SkColorFilter* getColorFilter() const { return fColorFilter.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400759
760 /** Returns SkColorFilter if set, or nullptr.
761 Increases SkColorFilter SkRefCnt by one.
762
763 @return SkColorFilter if set, or nullptr
764 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500765 sk_sp<SkColorFilter> refColorFilter() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000766
Cary Clark8a02b0b2017-09-21 12:28:43 -0400767 /** Sets SkColorFilter to filter, decreasing SkRefCnt of the previous
768 SkColorFilter. Pass nullptr to clear SkColorFilter.
769
770 Increments filter SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400771
772 @param colorFilter SkColorFilter to apply to subsequent draw
reed@android.com8a1c16f2008-12-17 15:59:43 +0000773 */
Cary Clark0418a882017-05-10 09:07:42 -0400774 void setColorFilter(sk_sp<SkColorFilter> colorFilter);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000775
Cary Clark50fa3ff2017-07-26 10:15:23 -0400776 /** Returns SkBlendMode.
Cary Clark579985c2017-07-31 11:48:27 -0400777 By default, returns SkBlendMode::kSrcOver.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400778
779 @return mode used to combine source color with destination color
780 */
reed374772b2016-10-05 17:33:02 -0700781 SkBlendMode getBlendMode() const { return (SkBlendMode)fBlendMode; }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400782
783 /** Returns true if SkBlendMode is SkBlendMode::kSrcOver, the default.
784
785 @return true if SkBlendMode is SkBlendMode::kSrcOver
786 */
reed374772b2016-10-05 17:33:02 -0700787 bool isSrcOver() const { return (SkBlendMode)fBlendMode == SkBlendMode::kSrcOver; }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400788
789 /** Sets SkBlendMode to mode.
790 Does not check for valid input.
791
792 @param mode SkBlendMode used to combine source color and destination
793 */
reed374772b2016-10-05 17:33:02 -0700794 void setBlendMode(SkBlendMode mode) { fBlendMode = (unsigned)mode; }
reed@android.coma0f5d152009-06-22 17:38:10 +0000795
Cary Clark50fa3ff2017-07-26 10:15:23 -0400796 /** Returns SkPathEffect if set, or nullptr.
797 Does not alter SkPathEffect SkRefCnt.
798
799 @return SkPathEffect if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000800 */
reeda5ab9ec2016-03-06 18:10:48 -0800801 SkPathEffect* getPathEffect() const { return fPathEffect.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400802
803 /** Returns SkPathEffect if set, or nullptr.
804 Increases SkPathEffect SkRefCnt by one.
805
806 @return SkPathEffect if previously set, nullptr otherwise
807 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500808 sk_sp<SkPathEffect> refPathEffect() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000809
Cary Clark8a02b0b2017-09-21 12:28:43 -0400810 /** Sets SkPathEffect to pathEffect, decreasing SkRefCnt of the previous
811 SkPathEffect. Pass nullptr to leave the path geometry unaltered.
812
813 Increments pathEffect SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400814
815 @param pathEffect replace SkPath with a modification when drawn
reed@android.com8a1c16f2008-12-17 15:59:43 +0000816 */
Cary Clark0418a882017-05-10 09:07:42 -0400817 void setPathEffect(sk_sp<SkPathEffect> pathEffect);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000818
Cary Clark50fa3ff2017-07-26 10:15:23 -0400819 /** Returns SkMaskFilter if set, or nullptr.
820 Does not alter SkMaskFilter SkRefCnt.
821
822 @return SkMaskFilter if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000823 */
reeda5ab9ec2016-03-06 18:10:48 -0800824 SkMaskFilter* getMaskFilter() const { return fMaskFilter.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400825
826 /** Returns SkMaskFilter if set, or nullptr.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400827
Cary Clark50fa3ff2017-07-26 10:15:23 -0400828 Increases SkMaskFilter SkRefCnt by one.
829
830 @return SkMaskFilter if previously set, nullptr otherwise
831 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500832 sk_sp<SkMaskFilter> refMaskFilter() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000833
Cary Clark8a02b0b2017-09-21 12:28:43 -0400834 /** Sets SkMaskFilter to maskFilter, decreasing SkRefCnt of the previous
835 SkMaskFilter. Pass nullptr to clear SkMaskFilter and leave SkMaskFilter effect on
836 mask alpha unaltered.
837
Cary Clark75959392018-02-27 10:22:04 -0500838 Increments maskFilter SkRefCnt by one.
839
Cary Clark50fa3ff2017-07-26 10:15:23 -0400840 @param maskFilter modifies clipping mask generated from drawn geometry
reed@android.com8a1c16f2008-12-17 15:59:43 +0000841 */
Cary Clark0418a882017-05-10 09:07:42 -0400842 void setMaskFilter(sk_sp<SkMaskFilter> maskFilter);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000843
Cary Clark50fa3ff2017-07-26 10:15:23 -0400844 /** Returns SkTypeface if set, or nullptr.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400845 Increments SkTypeface SkRefCnt by one.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000846
Cary Clark50fa3ff2017-07-26 10:15:23 -0400847 @return SkTypeface if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000848 */
reeda5ab9ec2016-03-06 18:10:48 -0800849 SkTypeface* getTypeface() const { return fTypeface.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400850
851 /** Increases SkTypeface SkRefCnt by one.
852
853 @return SkTypeface if previously set, nullptr otherwise
854 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500855 sk_sp<SkTypeface> refTypeface() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000856
Cary Clark8a02b0b2017-09-21 12:28:43 -0400857 /** Sets SkTypeface to typeface, decreasing SkRefCnt of the previous SkTypeface.
858 Pass nullptr to clear SkTypeface and use the default typeface. Increments
859 typeface SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400860
861 @param typeface font and style used to draw text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000862 */
Cary Clark0418a882017-05-10 09:07:42 -0400863 void setTypeface(sk_sp<SkTypeface> typeface);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000864
Cary Clark50fa3ff2017-07-26 10:15:23 -0400865 /** Returns SkImageFilter if set, or nullptr.
866 Does not alter SkImageFilter SkRefCnt.
867
868 @return SkImageFilter if previously set, nullptr otherwise
869 */
reeda5ab9ec2016-03-06 18:10:48 -0800870 SkImageFilter* getImageFilter() const { return fImageFilter.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400871
872 /** Returns SkImageFilter if set, or nullptr.
873 Increases SkImageFilter SkRefCnt by one.
874
875 @return SkImageFilter if previously set, nullptr otherwise
876 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500877 sk_sp<SkImageFilter> refImageFilter() const;
Cary Clark50fa3ff2017-07-26 10:15:23 -0400878
Cary Clark8a02b0b2017-09-21 12:28:43 -0400879 /** Sets SkImageFilter to imageFilter, decreasing SkRefCnt of the previous
880 SkImageFilter. Pass nullptr to clear SkImageFilter, and remove SkImageFilter effect
Cary Clark50fa3ff2017-07-26 10:15:23 -0400881 on drawing.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400882
Cary Clark75959392018-02-27 10:22:04 -0500883 Increments imageFilter SkRefCnt by one.
884
Cary Clark50fa3ff2017-07-26 10:15:23 -0400885 @param imageFilter how SkImage is sampled when transformed
886 */
Cary Clark0418a882017-05-10 09:07:42 -0400887 void setImageFilter(sk_sp<SkImageFilter> imageFilter);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000888
Cary Clark50fa3ff2017-07-26 10:15:23 -0400889 /** Returns SkDrawLooper if set, or nullptr.
890 Does not alter SkDrawLooper SkRefCnt.
891
892 @return SkDrawLooper if previously set, nullptr otherwise
893 */
reed46f2d0a2016-09-11 05:40:31 -0700894 SkDrawLooper* getDrawLooper() const { return fDrawLooper.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400895
896 /** Returns SkDrawLooper if set, or nullptr.
897 Increases SkDrawLooper SkRefCnt by one.
898
899 @return SkDrawLooper if previously set, nullptr otherwise
900 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500901 sk_sp<SkDrawLooper> refDrawLooper() const;
902
Cary Clark23890a92017-07-27 16:30:51 -0400903 /** Deprecated.
Cary Clark75959392018-02-27 10:22:04 -0500904 (see skbug.com/6259)
Cary Clark50fa3ff2017-07-26 10:15:23 -0400905 */
reed46f2d0a2016-09-11 05:40:31 -0700906 SkDrawLooper* getLooper() const { return fDrawLooper.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400907
Cary Clark8a02b0b2017-09-21 12:28:43 -0400908 /** Sets SkDrawLooper to drawLooper, decreasing SkRefCnt of the previous
909 drawLooper. Pass nullptr to clear SkDrawLooper and leave SkDrawLooper effect on
910 drawing unaltered.
911
912 Increments drawLooper SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400913
Cary Clarkb7da7232017-09-01 13:49:54 -0400914 @param drawLooper iterates through drawing one or more time, altering SkPaint
Cary Clark50fa3ff2017-07-26 10:15:23 -0400915 */
Cary Clark0418a882017-05-10 09:07:42 -0400916 void setDrawLooper(sk_sp<SkDrawLooper> drawLooper);
Mike Reed09d94352016-10-31 15:11:04 -0400917
Cary Clark23890a92017-07-27 16:30:51 -0400918 /** Deprecated.
Cary Clark75959392018-02-27 10:22:04 -0500919 (see skbug.com/6259)
Cary Clark50fa3ff2017-07-26 10:15:23 -0400920 */
Cary Clark0418a882017-05-10 09:07:42 -0400921 void setLooper(sk_sp<SkDrawLooper> drawLooper);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000922
Cary Clark50fa3ff2017-07-26 10:15:23 -0400923 /** \enum SkPaint::Align
924 Align adjusts the text relative to the text position.
925 Align affects glyphs drawn with: SkCanvas::drawText, SkCanvas::drawPosText,
926 SkCanvas::drawPosTextH, SkCanvas::drawTextOnPath,
927 SkCanvas::drawTextOnPathHV, SkCanvas::drawTextRSXform, SkCanvas::drawTextBlob,
928 and SkCanvas::drawString;
Cary Clark579985c2017-07-31 11:48:27 -0400929 as well as calls that place text glyphs like getTextWidths() and getTextPath().
Cary Clark50fa3ff2017-07-26 10:15:23 -0400930
931 The text position is set by the font for both horizontal and vertical text.
932 Typically, for horizontal text, the position is to the left side of the glyph on the
Cary Clark23890a92017-07-27 16:30:51 -0400933 base line; and for vertical text, the position is the horizontal center of the glyph
Cary Clark50fa3ff2017-07-26 10:15:23 -0400934 at the caps height.
935
936 Align adjusts the glyph position to center it or move it to abut the position
937 using the metrics returned by the font.
938
939 Align defaults to kLeft_Align.
940 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000941 enum Align {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400942 /** Leaves the glyph at the position computed by the font offset by the text position. */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000943 kLeft_Align,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400944
945 /** Moves the glyph half its width if Flags has kVerticalText_Flag clear, and
946 half its height if Flags has kVerticalText_Flag set.
947 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000948 kCenter_Align,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400949
950 /** Moves the glyph by its width if Flags has kVerticalText_Flag clear,
951 and by its height if Flags has kVerticalText_Flag set.
952 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000953 kRight_Align,
mike@reedtribe.orgddc813b2013-06-08 12:58:19 +0000954 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400955
mike@reedtribe.orgddc813b2013-06-08 12:58:19 +0000956 enum {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400957 kAlignCount = 3, //!< The number of different Align values defined.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000958 };
reed@google.com9d07fec2011-03-16 20:02:59 +0000959
Cary Clark50fa3ff2017-07-26 10:15:23 -0400960 /** Returns SkPaint::Align.
961 Returns kLeft_Align if SkPaint::Align has not been set.
962
963 @return text placement relative to position
reed@android.com8a1c16f2008-12-17 15:59:43 +0000964 */
reedf59eab22014-07-14 14:39:15 -0700965 Align getTextAlign() const { return (Align)fBitfields.fTextAlign; }
reed@google.com9d07fec2011-03-16 20:02:59 +0000966
Cary Clark50fa3ff2017-07-26 10:15:23 -0400967 /** Sets SkPaint::Align to align.
968 Has no effect if align is an invalid value.
969
970 @param align text placement relative to position
reed@android.com8a1c16f2008-12-17 15:59:43 +0000971 */
972 void setTextAlign(Align align);
973
Cary Clark50fa3ff2017-07-26 10:15:23 -0400974 /** Returns text size in points.
975
976 @return typographic height of text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000977 */
978 SkScalar getTextSize() const { return fTextSize; }
979
Cary Clark50fa3ff2017-07-26 10:15:23 -0400980 /** Sets text size in points.
981 Has no effect if textSize is not greater than or equal to zero.
982
983 @param textSize typographic height of text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000984 */
985 void setTextSize(SkScalar textSize);
986
Cary Clark50fa3ff2017-07-26 10:15:23 -0400987 /** Returns text scale x.
988 Default value is 1.
989
990 @return text horizontal scale
reed@android.com8a1c16f2008-12-17 15:59:43 +0000991 */
992 SkScalar getTextScaleX() const { return fTextScaleX; }
993
Cary Clark50fa3ff2017-07-26 10:15:23 -0400994 /** Sets text scale x.
995 Default value is 1.
996
997 @param scaleX text horizontal scale
reed@android.com8a1c16f2008-12-17 15:59:43 +0000998 */
999 void setTextScaleX(SkScalar scaleX);
1000
Cary Clark50fa3ff2017-07-26 10:15:23 -04001001 /** Returns text skew x.
1002 Default value is zero.
1003
1004 @return additional shear in x-axis relative to y-axis
reed@android.com8a1c16f2008-12-17 15:59:43 +00001005 */
1006 SkScalar getTextSkewX() const { return fTextSkewX; }
1007
Cary Clark50fa3ff2017-07-26 10:15:23 -04001008 /** Sets text skew x.
1009 Default value is zero.
1010
1011 @param skewX additional shear in x-axis relative to y-axis
reed@android.com8a1c16f2008-12-17 15:59:43 +00001012 */
1013 void setTextSkewX(SkScalar skewX);
1014
Cary Clark50fa3ff2017-07-26 10:15:23 -04001015 /** \enum SkPaint::TextEncoding
Cary Clark8a02b0b2017-09-21 12:28:43 -04001016 TextEncoding determines whether text specifies character codes and their encoded
Cary Clarkcc309eb2017-10-30 11:48:35 -04001017 size, or glyph indices. Characters are encoded as specified by the Unicode standard.
Cary Clark8a02b0b2017-09-21 12:28:43 -04001018
Cary Clark50fa3ff2017-07-26 10:15:23 -04001019 Character codes encoded size are specified by UTF-8, UTF-16, or UTF-32.
Cary Clarkcc309eb2017-10-30 11:48:35 -04001020 All character code formats are able to represent all of Unicode, differing only
1021 in the total storage required.
1022
1023 UTF-8 (RFC 3629) encodes each character as one or more 8-bit bytes.
1024
1025 UTF-16 (RFC 2781) encodes each character as one or two 16-bit words.
1026
1027 UTF-32 encodes each character as one 32-bit word.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001028
1029 font manager uses font data to convert character code points into glyph indices.
1030 A glyph index is a 16-bit word.
1031
1032 TextEncoding is set to kUTF8_TextEncoding by default.
reed@android.com8a1c16f2008-12-17 15:59:43 +00001033 */
1034 enum TextEncoding {
Cary Clark50fa3ff2017-07-26 10:15:23 -04001035 kUTF8_TextEncoding, //!< Uses bytes to represent UTF-8 or ASCII.
1036 kUTF16_TextEncoding, //!< Uses two byte words to represent most of Unicode.
1037 kUTF32_TextEncoding, //!< Uses four byte words to represent all of Unicode.
1038 kGlyphID_TextEncoding, //!< Uses two byte words to represent glyph indices.
reed@android.com8a1c16f2008-12-17 15:59:43 +00001039 };
reed@google.com9d07fec2011-03-16 20:02:59 +00001040
Cary Clark50fa3ff2017-07-26 10:15:23 -04001041 /** Returns SkPaint::TextEncoding.
1042 SkPaint::TextEncoding determines how character code points are mapped to font glyph indices.
1043
1044 @return one of: kUTF8_TextEncoding, kUTF16_TextEncoding, kUTF32_TextEncoding, or
1045 kGlyphID_TextEncoding
1046 */
reedf59eab22014-07-14 14:39:15 -07001047 TextEncoding getTextEncoding() const {
1048 return (TextEncoding)fBitfields.fTextEncoding;
1049 }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001050
Cary Clark50fa3ff2017-07-26 10:15:23 -04001051 /** Sets SkPaint::TextEncoding to encoding.
1052 SkPaint::TextEncoding determines how character code points are mapped to font glyph indices.
1053 Invalid values for encoding are ignored.
1054
1055 @param encoding one of: kUTF8_TextEncoding, kUTF16_TextEncoding, kUTF32_TextEncoding, or
Cary Clark579985c2017-07-31 11:48:27 -04001056 kGlyphID_TextEncoding
Cary Clark50fa3ff2017-07-26 10:15:23 -04001057 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001058 void setTextEncoding(TextEncoding encoding);
1059
Cary Clark50fa3ff2017-07-26 10:15:23 -04001060 /** \struct SkPaint::FontMetrics
Cary Clark579985c2017-07-31 11:48:27 -04001061 FontMetrics is filled out by getFontMetrics(). FontMetrics contents reflect the values
Cary Clark50fa3ff2017-07-26 10:15:23 -04001062 computed by font manager using SkTypeface. Values are set to zero if they are
Cary Clarkb7da7232017-09-01 13:49:54 -04001063 not available.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001064
Ben Wagnere5806492017-11-09 12:08:31 -05001065 All vertical values relative to the baseline are given y-down. As such, zero is on the
1066 baseline, negative values are above the baseline, and positive values are below the
1067 baseline.
1068
Cary Clark50fa3ff2017-07-26 10:15:23 -04001069 fUnderlineThickness and fUnderlinePosition have a bit set in fFlags if their values
1070 are valid, since their value may be zero.
1071
1072 fStrikeoutThickness and fStrikeoutPosition have a bit set in fFlags if their values
1073 are valid, since their value may be zero.
1074 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001075 struct FontMetrics {
Cary Clark50fa3ff2017-07-26 10:15:23 -04001076
Cary Clarkcc309eb2017-10-30 11:48:35 -04001077 /** \enum SkPaint::FontMetrics::FontMetricsFlags
1078 FontMetricsFlags are set in fFlags when underline and strikeout metrics are valid;
1079 the underline or strikeout metric may be valid and zero.
1080 Fonts with embedded bitmaps may not have valid underline or strikeout metrics.
1081 */
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001082 enum FontMetricsFlags {
Cary Clark50fa3ff2017-07-26 10:15:23 -04001083 kUnderlineThicknessIsValid_Flag = 1 << 0, //!< Set if fUnderlineThickness is valid.
1084 kUnderlinePositionIsValid_Flag = 1 << 1, //!< Set if fUnderlinePosition is valid.
1085 kStrikeoutThicknessIsValid_Flag = 1 << 2, //!< Set if fStrikeoutThickness is valid.
1086 kStrikeoutPositionIsValid_Flag = 1 << 3, //!< Set if fStrikeoutPosition is valid.
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001087 };
1088
Cary Clark50fa3ff2017-07-26 10:15:23 -04001089 uint32_t fFlags; //!< fFlags is set when underline metrics are valid.
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001090
Ben Wagnere5806492017-11-09 12:08:31 -05001091 /** Greatest extent above the baseline for any glyph.
1092 Typically less than zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001093 */
1094 SkScalar fTop;
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001095
Cary Clark50fa3ff2017-07-26 10:15:23 -04001096 /** Recommended distance above the baseline to reserve for a line of text.
Ben Wagnere5806492017-11-09 12:08:31 -05001097 Typically less than zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001098 */
1099 SkScalar fAscent;
Ben Wagner219f3622017-07-17 15:32:25 -04001100
Cary Clark50fa3ff2017-07-26 10:15:23 -04001101 /** Recommended distance below the baseline to reserve for a line of text.
Ben Wagnere5806492017-11-09 12:08:31 -05001102 Typically greater than zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001103 */
1104 SkScalar fDescent;
Ben Wagner219f3622017-07-17 15:32:25 -04001105
Cary Clark50fa3ff2017-07-26 10:15:23 -04001106 /** Greatest extent below the baseline for any glyph.
Ben Wagnere5806492017-11-09 12:08:31 -05001107 Typically greater than zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001108 */
1109 SkScalar fBottom;
1110
1111 /** Recommended distance to add between lines of text.
Ben Wagnere5806492017-11-09 12:08:31 -05001112 Typically greater than or equal to zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001113 */
1114 SkScalar fLeading;
1115
1116 /** Average character width, if it is available.
1117 Zero if no average width is stored in the font.
1118 */
1119 SkScalar fAvgCharWidth;
Cary Clarkcc309eb2017-10-30 11:48:35 -04001120
Cary Clark50fa3ff2017-07-26 10:15:23 -04001121 SkScalar fMaxCharWidth; //!< Maximum character width.
1122
1123 /** Minimum bounding box x value for all glyphs.
1124 Typically less than zero.
1125 */
1126 SkScalar fXMin;
1127
1128 /** Maximum bounding box x value for all glyphs.
1129 Typically greater than zero.
1130 */
1131 SkScalar fXMax;
1132
1133 /** Height of a lower-case 'x'.
1134 May be zero if no lower-case height is stored in the font.
1135 */
1136 SkScalar fXHeight;
1137
1138 /** Height of an upper-case letter.
1139 May be zero if no upper-case height is stored in the font.
1140 */
1141 SkScalar fCapHeight;
1142
Ben Wagnere5806492017-11-09 12:08:31 -05001143 /** Underline thickness.
1144
1145 If the metric is valid, the kUnderlineThicknessIsValid_Flag is set in fFlags.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001146 If kUnderlineThicknessIsValid_Flag is clear, fUnderlineThickness is zero.
1147 */
1148 SkScalar fUnderlineThickness;
1149
Ben Wagnere5806492017-11-09 12:08:31 -05001150 /** Position of the top of the underline stroke relative to the baseline.
1151 Typically positive when valid.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001152
1153 If the metric is valid, the kUnderlinePositionIsValid_Flag is set in fFlags.
1154 If kUnderlinePositionIsValid_Flag is clear, fUnderlinePosition is zero.
1155 */
1156 SkScalar fUnderlinePosition;
1157
Ben Wagnere5806492017-11-09 12:08:31 -05001158 /** Strikeout thickness.
1159
1160 If the metric is valid, the kStrikeoutThicknessIsValid_Flag is set in fFlags.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001161 If kStrikeoutThicknessIsValid_Flag is clear, fStrikeoutThickness is zero.
1162 */
1163 SkScalar fStrikeoutThickness;
1164
Ben Wagnere5806492017-11-09 12:08:31 -05001165 /** Position of the bottom of the strikeout stroke relative to the baseline.
1166 Typically negative when valid.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001167
1168 If the metric is valid, the kStrikeoutPositionIsValid_Flag is set in fFlags.
1169 If kStrikeoutPositionIsValid_Flag is clear, fStrikeoutPosition is zero.
1170 */
1171 SkScalar fStrikeoutPosition;
1172
1173 /** If SkPaint::FontMetrics has a valid underline thickness, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001174 thickness to that value. If the underline thickness is not valid,
1175 return false, and ignore thickness.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001176
1177 @param thickness storage for underline width
1178 @return true if font specifies underline width
1179 */
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001180 bool hasUnderlineThickness(SkScalar* thickness) const {
Ben Wagner3318da52017-03-23 14:01:22 -04001181 if (SkToBool(fFlags & kUnderlineThicknessIsValid_Flag)) {
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001182 *thickness = fUnderlineThickness;
1183 return true;
1184 }
1185 return false;
1186 }
1187
Cary Clark50fa3ff2017-07-26 10:15:23 -04001188 /** If SkPaint::FontMetrics has a valid underline position, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001189 position to that value. If the underline position is not valid,
1190 return false, and ignore position.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001191
1192 @param position storage for underline position
1193 @return true if font specifies underline position
1194 */
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001195 bool hasUnderlinePosition(SkScalar* position) const {
1196 if (SkToBool(fFlags & kUnderlinePositionIsValid_Flag)) {
1197 *position = fUnderlinePosition;
1198 return true;
1199 }
1200 return false;
1201 }
1202
Cary Clark50fa3ff2017-07-26 10:15:23 -04001203 /** If SkPaint::FontMetrics has a valid strikeout thickness, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001204 thickness to that value. If the underline thickness is not valid,
1205 return false, and ignore thickness.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001206
1207 @param thickness storage for strikeout width
1208 @return true if font specifies strikeout width
1209 */
Ben Wagner219f3622017-07-17 15:32:25 -04001210 bool hasStrikeoutThickness(SkScalar* thickness) const {
1211 if (SkToBool(fFlags & kStrikeoutThicknessIsValid_Flag)) {
1212 *thickness = fStrikeoutThickness;
1213 return true;
1214 }
1215 return false;
1216 }
1217
Cary Clark50fa3ff2017-07-26 10:15:23 -04001218 /** If SkPaint::FontMetrics has a valid strikeout position, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001219 position to that value. If the underline position is not valid,
1220 return false, and ignore position.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001221
1222 @param position storage for strikeout position
1223 @return true if font specifies strikeout position
1224 */
Ben Wagner219f3622017-07-17 15:32:25 -04001225 bool hasStrikeoutPosition(SkScalar* position) const {
1226 if (SkToBool(fFlags & kStrikeoutPositionIsValid_Flag)) {
1227 *position = fStrikeoutPosition;
1228 return true;
1229 }
1230 return false;
1231 }
Cary Clark50fa3ff2017-07-26 10:15:23 -04001232
reed@android.com8a1c16f2008-12-17 15:59:43 +00001233 };
reed@google.com9d07fec2011-03-16 20:02:59 +00001234
Cary Clark50fa3ff2017-07-26 10:15:23 -04001235 /** Returns SkPaint::FontMetrics associated with SkTypeface.
1236 The return value is the recommended spacing between lines: the sum of metrics
1237 descent, ascent, and leading.
1238 If metrics is not nullptr, SkPaint::FontMetrics is copied to metrics.
1239 Results are scaled by text size but does not take into account
1240 dimensions required by text scale x, text skew x, fake bold,
1241 style stroke, and SkPathEffect.
1242 Results can be additionally scaled by scale; a scale of zero
1243 is ignored.
1244
1245 @param metrics storage for SkPaint::FontMetrics from SkTypeface; may be nullptr
1246 @param scale additional multiplier for returned values
1247 @return recommended spacing between lines
reed@android.com8a1c16f2008-12-17 15:59:43 +00001248 */
1249 SkScalar getFontMetrics(FontMetrics* metrics, SkScalar scale = 0) const;
reed@google.com9d07fec2011-03-16 20:02:59 +00001250
Cary Clark50fa3ff2017-07-26 10:15:23 -04001251 /** Returns the recommended spacing between lines: the sum of metrics
1252 descent, ascent, and leading.
1253 Result is scaled by text size but does not take into account
1254 dimensions required by stroking and SkPathEffect.
Cary Clark579985c2017-07-31 11:48:27 -04001255 Returns the same result as getFontMetrics().
Cary Clark50fa3ff2017-07-26 10:15:23 -04001256
1257 @return recommended spacing between lines
reed@android.com8a1c16f2008-12-17 15:59:43 +00001258 */
Ben Wagnera93a14a2017-08-28 10:34:05 -04001259 SkScalar getFontSpacing() const { return this->getFontMetrics(nullptr, 0); }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001260
Cary Clark50fa3ff2017-07-26 10:15:23 -04001261 /** Converts text into glyph indices.
1262 Returns the number of glyph indices represented by text.
1263 SkPaint::TextEncoding specifies how text represents characters or glyphs.
1264 glyphs may be nullptr, to compute the glyph count.
1265
Cary Clarkcc309eb2017-10-30 11:48:35 -04001266 Does not check text for valid character codes or valid glyph indices.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001267
Cary Clark579985c2017-07-31 11:48:27 -04001268 If byteLength equals zero, returns zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001269 If byteLength includes a partial character, the partial character is ignored.
1270
1271 If SkPaint::TextEncoding is kUTF8_TextEncoding and
1272 text contains an invalid UTF-8 sequence, zero is returned.
1273
Cary Clarkb7da7232017-09-01 13:49:54 -04001274 @param text character storage encoded with SkPaint::TextEncoding
Cary Clark50fa3ff2017-07-26 10:15:23 -04001275 @param byteLength length of character storage in bytes
1276 @param glyphs storage for glyph indices; may be nullptr
1277 @return number of glyphs represented by text of length byteLength
reed@android.com8a1c16f2008-12-17 15:59:43 +00001278 */
1279 int textToGlyphs(const void* text, size_t byteLength,
halcanaryd0e95a52016-07-25 07:18:12 -07001280 SkGlyphID glyphs[]) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001281
Cary Clark50fa3ff2017-07-26 10:15:23 -04001282 /** Returns true if all text corresponds to a non-zero glyph index.
1283 Returns false if any characters in text are not supported in
1284 SkTypeface.
reed@android.coma5dcaf62010-02-05 17:12:32 +00001285
Cary Clark579985c2017-07-31 11:48:27 -04001286 If SkPaint::TextEncoding is kGlyphID_TextEncoding,
1287 returns true if all glyph indices in text are non-zero;
Cary Clark50fa3ff2017-07-26 10:15:23 -04001288 does not check to see if text contains valid glyph indices for SkTypeface.
1289
Cary Clarkb7da7232017-09-01 13:49:54 -04001290 Returns true if byteLength is zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001291
1292 @param text array of characters or glyphs
1293 @param byteLength number of bytes in text array
1294 @return true if all text corresponds to a non-zero glyph index
1295 */
reed@android.coma5dcaf62010-02-05 17:12:32 +00001296 bool containsText(const void* text, size_t byteLength) const;
1297
Cary Clark50fa3ff2017-07-26 10:15:23 -04001298 /** Converts glyphs into text if possible.
1299 Glyph values without direct Unicode equivalents are mapped to zero.
1300 Uses the SkTypeface, but is unaffected
1301 by SkPaint::TextEncoding; the text values returned are equivalent to kUTF32_TextEncoding.
1302
1303 Only supported on platforms that use FreeType as the font engine.
1304
1305 @param glyphs array of indices into font
1306 @param count length of glyph array
1307 @param text storage for character codes, one per glyph
reed@android.com9d3a9852010-01-08 14:07:42 +00001308 */
halcanaryd0e95a52016-07-25 07:18:12 -07001309 void glyphsToUnichars(const SkGlyphID glyphs[], int count, SkUnichar text[]) const;
reed@android.com9d3a9852010-01-08 14:07:42 +00001310
Cary Clark50fa3ff2017-07-26 10:15:23 -04001311 /** Returns the number of glyphs in text.
1312 Uses SkPaint::TextEncoding to count the glyphs.
Cary Clark579985c2017-07-31 11:48:27 -04001313 Returns the same result as textToGlyphs().
Cary Clark50fa3ff2017-07-26 10:15:23 -04001314
Cary Clarkb7da7232017-09-01 13:49:54 -04001315 @param text character storage encoded with SkPaint::TextEncoding
Cary Clark50fa3ff2017-07-26 10:15:23 -04001316 @param byteLength length of character storage in bytes
1317 @return number of glyphs represented by text of length byteLength
reed@android.com8a1c16f2008-12-17 15:59:43 +00001318 */
reed@google.com9d07fec2011-03-16 20:02:59 +00001319 int countText(const void* text, size_t byteLength) const {
Ben Wagnera93a14a2017-08-28 10:34:05 -04001320 return this->textToGlyphs(text, byteLength, nullptr);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001321 }
1322
Cary Clark50fa3ff2017-07-26 10:15:23 -04001323 /** Returns the advance width of text if kVerticalText_Flag is clear,
1324 and the height of text if kVerticalText_Flag is set.
1325 The advance is the normal distance to move before drawing additional text.
1326 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
1327 and text size, text scale x, text skew x, stroke width, and
1328 SkPathEffect to scale the metrics and bounds.
1329 Returns the bounding box of text if bounds is not nullptr.
1330 The bounding box is computed as if the text was drawn at the origin.
1331
1332 @param text character codes or glyph indices to be measured
1333 @param length number of bytes of text to measure
1334 @param bounds returns bounding box relative to (0, 0) if not nullptr
1335 @return advance width or height
1336 */
reed99ae8812014-08-26 11:30:01 -07001337 SkScalar measureText(const void* text, size_t length, SkRect* bounds) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001338
Cary Clark50fa3ff2017-07-26 10:15:23 -04001339 /** Returns the advance width of text if kVerticalText_Flag is clear,
1340 and the height of text if kVerticalText_Flag is set.
1341 The advance is the normal distance to move before drawing additional text.
1342 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
Cary Clark23890a92017-07-27 16:30:51 -04001343 and text size to scale the metrics.
1344 Does not scale the advance or bounds by fake bold or SkPathEffect.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001345
1346 @param text character codes or glyph indices to be measured
1347 @param length number of bytes of text to measure
Cary Clark50fa3ff2017-07-26 10:15:23 -04001348 @return advance width or height
1349 */
reed@google.com9d07fec2011-03-16 20:02:59 +00001350 SkScalar measureText(const void* text, size_t length) const {
Ben Wagnera93a14a2017-08-28 10:34:05 -04001351 return this->measureText(text, length, nullptr);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001352 }
reed@google.com9d07fec2011-03-16 20:02:59 +00001353
Cary Clark50fa3ff2017-07-26 10:15:23 -04001354 /** Returns the bytes of text that fit within maxWidth.
1355 If kVerticalText_Flag is clear, the text fragment fits if its advance width is less than or
1356 equal to maxWidth.
1357 If kVerticalText_Flag is set, the text fragment fits if its advance height is less than or
1358 equal to maxWidth.
1359 Measures only while the advance is less than or equal to maxWidth.
1360 Returns the advance or the text fragment in measuredWidth if it not nullptr.
1361 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
1362 and text size to scale the metrics.
1363 Does not scale the advance or bounds by fake bold or SkPathEffect.
1364
1365 @param text character codes or glyph indices to be measured
1366 @param length number of bytes of text to measure
1367 @param maxWidth advance limit; text is measured while advance is less than maxWidth
1368 @param measuredWidth returns the width of the text less than or equal to maxWidth
1369 @return bytes of text that fit, always less than or equal to length
1370 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001371 size_t breakText(const void* text, size_t length, SkScalar maxWidth,
Ben Wagnera93a14a2017-08-28 10:34:05 -04001372 SkScalar* measuredWidth = nullptr) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001373
Cary Clark50fa3ff2017-07-26 10:15:23 -04001374 /** Retrieves the advance and bounds for each glyph in text, and returns
1375 the glyph count in text.
1376 Both widths and bounds may be nullptr.
1377 If widths is not nullptr, widths must be an array of glyph count entries.
1378 if bounds is not nullptr, bounds must be an array of glyph count entries.
1379 If kVerticalText_Flag is clear, widths returns the horizontal advance.
1380 If kVerticalText_Flag is set, widths returns the vertical advance.
1381 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
1382 and text size to scale the widths and bounds.
1383 Does not scale the advance by fake bold or SkPathEffect.
Cary Clark23890a92017-07-27 16:30:51 -04001384 Does include fake bold and SkPathEffect in the bounds.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001385
1386 @param text character codes or glyph indices to be measured
1387 @param byteLength number of bytes of text to measure
1388 @param widths returns text advances for each glyph; may be nullptr
1389 @param bounds returns bounds for each glyph relative to (0, 0); may be nullptr
1390 @return glyph count in text
1391 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001392 int getTextWidths(const void* text, size_t byteLength, SkScalar widths[],
Ben Wagnera93a14a2017-08-28 10:34:05 -04001393 SkRect bounds[] = nullptr) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001394
Cary Clark50fa3ff2017-07-26 10:15:23 -04001395 /** Returns the geometry as SkPath equivalent to the drawn text.
1396 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1397 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1398 All of the glyph paths are stored in path.
Cary Clark579985c2017-07-31 11:48:27 -04001399 Uses x, y, and SkPaint::Align to position path.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001400
1401 @param text character codes or glyph indices
1402 @param length number of bytes of text
1403 @param x x-coordinate of the origin of the text
1404 @param y y-coordinate of the origin of the text
1405 @param path geometry of the glyphs
1406 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001407 void getTextPath(const void* text, size_t length, SkScalar x, SkScalar y,
1408 SkPath* path) const;
1409
Cary Clark50fa3ff2017-07-26 10:15:23 -04001410 /** Returns the geometry as SkPath equivalent to the drawn text.
1411 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1412 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1413 All of the glyph paths are stored in path.
1414 Uses pos array and SkPaint::Align to position path.
1415 pos contains a position for each glyph.
1416
1417 @param text character codes or glyph indices
1418 @param length number of bytes of text
1419 @param pos positions of each glyph
1420 @param path geometry of the glyphs
1421 */
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001422 void getPosTextPath(const void* text, size_t length,
reed@google.comca0062e2012-07-20 11:20:32 +00001423 const SkPoint pos[], SkPath* path) const;
1424
Cary Clark50fa3ff2017-07-26 10:15:23 -04001425 /** Returns the number of intervals that intersect bounds.
1426 bounds describes a pair of lines parallel to the text advance.
1427 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1428 the string.
1429 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1430 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1431 Uses x, y, and SkPaint::Align to position intervals.
1432
1433 Pass nullptr for intervals to determine the size of the interval array.
1434
1435 intervals are cached to improve performance for multiple calls.
1436
1437 @param text character codes or glyph indices
1438 @param length number of bytes of text
1439 @param x x-coordinate of the origin of the text
1440 @param y y-coordinate of the origin of the text
1441 @param bounds lower and upper line parallel to the advance
1442 @param intervals returned intersections; may be nullptr
1443 @return number of intersections; may be zero
1444 */
caryclark0449bcf2016-02-09 13:25:45 -08001445 int getTextIntercepts(const void* text, size_t length, SkScalar x, SkScalar y,
1446 const SkScalar bounds[2], SkScalar* intervals) const;
1447
Cary Clark50fa3ff2017-07-26 10:15:23 -04001448 /** Returns the number of intervals that intersect bounds.
1449 bounds describes a pair of lines parallel to the text advance.
1450 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1451 the string.
1452 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1453 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1454 Uses pos array and SkPaint::Align to position intervals.
1455
1456 Pass nullptr for intervals to determine the size of the interval array.
1457
1458 intervals are cached to improve performance for multiple calls.
1459
1460 @param text character codes or glyph indices
1461 @param length number of bytes of text
1462 @param pos positions of each glyph
1463 @param bounds lower and upper line parallel to the advance
1464 @param intervals returned intersections; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -04001465 @return number of intersections; may be zero
Cary Clark50fa3ff2017-07-26 10:15:23 -04001466 */
caryclark0449bcf2016-02-09 13:25:45 -08001467 int getPosTextIntercepts(const void* text, size_t length, const SkPoint pos[],
1468 const SkScalar bounds[2], SkScalar* intervals) const;
1469
Cary Clark50fa3ff2017-07-26 10:15:23 -04001470 /** Returns the number of intervals that intersect bounds.
1471 bounds describes a pair of lines parallel to the text advance.
1472 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1473 the string.
1474 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1475 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1476 Uses xpos array, constY, and SkPaint::Align to position intervals.
1477
1478 Pass nullptr for intervals to determine the size of the interval array.
1479
1480 intervals are cached to improve performance for multiple calls.
1481
1482 @param text character codes or glyph indices
1483 @param length number of bytes of text
1484 @param xpos positions of each glyph in x
1485 @param constY position of each glyph in y
1486 @param bounds lower and upper line parallel to the advance
1487 @param intervals returned intersections; may be nullptr
1488 @return number of intersections; may be zero
1489 */
fmalitaeae6a912016-07-28 09:47:24 -07001490 int getPosTextHIntercepts(const void* text, size_t length, const SkScalar xpos[],
1491 SkScalar constY, const SkScalar bounds[2], SkScalar* intervals) const;
1492
Cary Clark50fa3ff2017-07-26 10:15:23 -04001493 /** Returns the number of intervals that intersect bounds.
1494 bounds describes a pair of lines parallel to the text advance.
1495 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1496 the string.
Cary Clark2823f9f2018-01-03 10:00:34 -05001497 Uses SkTypeface to get the glyph paths,
Cary Clark50fa3ff2017-07-26 10:15:23 -04001498 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
Cary Clarkb7da7232017-09-01 13:49:54 -04001499 Uses run array and SkPaint::Align to position intervals.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001500
Cary Clark2823f9f2018-01-03 10:00:34 -05001501 SkPaint::TextEncoding must be set to SkPaint::kGlyphID_TextEncoding.
1502
Cary Clark50fa3ff2017-07-26 10:15:23 -04001503 Pass nullptr for intervals to determine the size of the interval array.
1504
1505 intervals are cached to improve performance for multiple calls.
1506
Cary Clark8a02b0b2017-09-21 12:28:43 -04001507 @param blob glyphs, positions, and text paint attributes
Cary Clark50fa3ff2017-07-26 10:15:23 -04001508 @param bounds lower and upper line parallel to the advance
1509 @param intervals returned intersections; may be nullptr
1510 @return number of intersections; may be zero
1511 */
fmalitaeae6a912016-07-28 09:47:24 -07001512 int getTextBlobIntercepts(const SkTextBlob* blob, const SkScalar bounds[2],
1513 SkScalar* intervals) const;
1514
Cary Clark50fa3ff2017-07-26 10:15:23 -04001515 /** Returns the union of bounds of all glyphs.
1516 Returned dimensions are computed by font manager from font data,
Cary Clark579985c2017-07-31 11:48:27 -04001517 ignoring SkPaint::Hinting. Includes text size, text scale x,
Cary Clark50fa3ff2017-07-26 10:15:23 -04001518 and text skew x, but not fake bold or SkPathEffect.
1519
1520 If text size is large, text scale x is one, and text skew x is zero,
Cary Clark579985c2017-07-31 11:48:27 -04001521 returns the same bounds as SkPaint::FontMetrics { FontMetrics::fXMin,
Cary Clark50fa3ff2017-07-26 10:15:23 -04001522 FontMetrics::fTop, FontMetrics::fXMax, FontMetrics::fBottom }.
1523
1524 @return union of bounds of all glyphs
1525 */
reed8893e5f2014-12-15 13:27:26 -08001526 SkRect getFontBounds() const;
1527
Cary Clark579985c2017-07-31 11:48:27 -04001528 /** Returns true if SkPaint prevents all drawing;
1529 otherwise, the SkPaint may or may not allow drawing.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001530
Cary Clarkb7da7232017-09-01 13:49:54 -04001531 Returns true if, for example, SkBlendMode combined with color alpha computes a
1532 new alpha of zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001533
1534 @return true if SkPaint prevents all drawing
1535 */
reed@google.com632e1a22011-10-06 12:37:00 +00001536 bool nothingToDraw() const;
1537
Cary Clark2823f9f2018-01-03 10:00:34 -05001538 /** (to be made private)
Cary Clark50fa3ff2017-07-26 10:15:23 -04001539 Returns true if SkPaint does not include elements requiring extensive computation
1540 to compute SkBaseDevice bounds of drawn geometry. For instance, SkPaint with SkPathEffect
1541 always returns false.
reed@google.comd5f20792012-05-16 14:15:02 +00001542
Cary Clark50fa3ff2017-07-26 10:15:23 -04001543 @return true if SkPaint allows for fast computation of bounds
1544 */
senorblanco0abdf762015-08-20 11:10:41 -07001545 bool canComputeFastBounds() const;
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001546
Cary Clark2823f9f2018-01-03 10:00:34 -05001547 /** (to be made private)
Cary Clark579985c2017-07-31 11:48:27 -04001548 Only call this if canComputeFastBounds() returned true. This takes a
Cary Clark50fa3ff2017-07-26 10:15:23 -04001549 raw rectangle (the raw bounds of a shape), and adjusts it for stylistic
1550 effects in the paint (e.g. stroking). If needed, it uses the storage
Cary Clarkb7da7232017-09-01 13:49:54 -04001551 parameter. It returns the adjusted bounds that can then be used
Cary Clark50fa3ff2017-07-26 10:15:23 -04001552 for SkCanvas::quickReject tests.
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001553
Cary Clarkb7da7232017-09-01 13:49:54 -04001554 The returned SkRect will either be orig or storage, thus the caller
Cary Clark50fa3ff2017-07-26 10:15:23 -04001555 should not rely on storage being set to the result, but should always
Cary Clarkb7da7232017-09-01 13:49:54 -04001556 use the returned value. It is legal for orig and storage to be the same
1557 SkRect.
Cary Clark2823f9f2018-01-03 10:00:34 -05001558 e.g.
1559 if (paint.canComputeFastBounds()) {
1560 SkRect r, storage;
1561 path.computeBounds(&r, SkPath::kFast_BoundsType);
1562 const SkRect& fastR = paint.computeFastBounds(r, &storage);
1563 if (canvas->quickReject(fastR, ...)) {
1564 // don't draw the path
1565 }
1566 }
Cary Clark50fa3ff2017-07-26 10:15:23 -04001567
1568 @param orig geometry modified by SkPaint when drawn
1569 @param storage computed bounds of geometry; may not be nullptr
1570 @return fast computed bounds
1571 */
reed@google.coma584aed2012-05-16 14:06:02 +00001572 const SkRect& computeFastBounds(const SkRect& orig, SkRect* storage) const {
Brian Osman60751d72017-05-12 11:21:36 -04001573 // Things like stroking, etc... will do math on the bounds rect, assuming that it's sorted.
1574 SkASSERT(orig.isSorted());
reed@google.coma584aed2012-05-16 14:06:02 +00001575 SkPaint::Style style = this->getStyle();
1576 // ultra fast-case: filling with no effects that affect geometry
1577 if (kFill_Style == style) {
1578 uintptr_t effects = reinterpret_cast<uintptr_t>(this->getLooper());
1579 effects |= reinterpret_cast<uintptr_t>(this->getMaskFilter());
1580 effects |= reinterpret_cast<uintptr_t>(this->getPathEffect());
senorblanco@chromium.org336d1d72014-01-27 21:03:17 +00001581 effects |= reinterpret_cast<uintptr_t>(this->getImageFilter());
reed@google.coma584aed2012-05-16 14:06:02 +00001582 if (!effects) {
1583 return orig;
1584 }
1585 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001586
reed@google.coma584aed2012-05-16 14:06:02 +00001587 return this->doComputeFastBounds(orig, storage, style);
1588 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001589
Cary Clark2823f9f2018-01-03 10:00:34 -05001590 /** (to be made private)
Cary Clark50fa3ff2017-07-26 10:15:23 -04001591
1592 @param orig geometry modified by SkPaint when drawn
1593 @param storage computed bounds of geometry
1594 @return fast computed bounds
1595 */
reed@google.coma584aed2012-05-16 14:06:02 +00001596 const SkRect& computeFastStrokeBounds(const SkRect& orig,
1597 SkRect* storage) const {
reed@google.com73a02582012-05-16 19:21:12 +00001598 return this->doComputeFastBounds(orig, storage, kStroke_Style);
reed@google.coma584aed2012-05-16 14:06:02 +00001599 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001600
Cary Clark2823f9f2018-01-03 10:00:34 -05001601 /** (to be made private)
Cary Clarkb7da7232017-09-01 13:49:54 -04001602 Computes the bounds, overriding the SkPaint SkPaint::Style. This can be used to
1603 account for additional width required by stroking orig, without
1604 altering SkPaint::Style set to fill.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001605
1606 @param orig geometry modified by SkPaint when drawn
1607 @param storage computed bounds of geometry
1608 @param style overrides SkPaint::Style
1609 @return fast computed bounds
1610 */
reed@google.coma584aed2012-05-16 14:06:02 +00001611 const SkRect& doComputeFastBounds(const SkRect& orig, SkRect* storage,
Cary Clark0418a882017-05-10 09:07:42 -04001612 Style style) const;
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001613
Cary Clark23890a92017-07-27 16:30:51 -04001614 /** macro expands to: void toString(SkString* str) const;
Cary Clarkb7da7232017-09-01 13:49:54 -04001615 Creates string representation of SkPaint. The representation is read by
1616 internal debugging tools. The interface and implementation may be
1617 suppressed by defining SK_IGNORE_TO_STRING.
Cary Clark0418a882017-05-10 09:07:42 -04001618
Cary Clarkb7da7232017-09-01 13:49:54 -04001619 @param str storage for string representation of SkPaint
Cary Clark50fa3ff2017-07-26 10:15:23 -04001620 */
commit-bot@chromium.org0f10f7b2014-03-13 18:02:17 +00001621 SK_TO_STRING_NONVIRT()
robertphillips@google.com791f12e2013-02-14 13:53:53 +00001622
reed@google.comd5f20792012-05-16 14:15:02 +00001623private:
Cary Clark0418a882017-05-10 09:07:42 -04001624 typedef const SkGlyph& (*GlyphCacheProc)(SkGlyphCache*, const char**);
1625
reeda5ab9ec2016-03-06 18:10:48 -08001626 sk_sp<SkTypeface> fTypeface;
1627 sk_sp<SkPathEffect> fPathEffect;
1628 sk_sp<SkShader> fShader;
reeda5ab9ec2016-03-06 18:10:48 -08001629 sk_sp<SkMaskFilter> fMaskFilter;
1630 sk_sp<SkColorFilter> fColorFilter;
reed46f2d0a2016-09-11 05:40:31 -07001631 sk_sp<SkDrawLooper> fDrawLooper;
reeda5ab9ec2016-03-06 18:10:48 -08001632 sk_sp<SkImageFilter> fImageFilter;
reed@google.comd5f20792012-05-16 14:15:02 +00001633
commit-bot@chromium.orge8807f42014-03-24 23:03:11 +00001634 SkScalar fTextSize;
1635 SkScalar fTextScaleX;
1636 SkScalar fTextSkewX;
reed@google.comd5f20792012-05-16 14:15:02 +00001637 SkColor fColor;
1638 SkScalar fWidth;
1639 SkScalar fMiterLimit;
Mike Reed71fecc32016-11-18 17:19:54 -05001640 uint32_t fBlendMode; // just need 5-6 bits
commit-bot@chromium.orgaca1c012014-02-21 18:18:05 +00001641 union {
1642 struct {
1643 // all of these bitfields should add up to 32
1644 unsigned fFlags : 16;
1645 unsigned fTextAlign : 2;
1646 unsigned fCapType : 2;
1647 unsigned fJoinType : 2;
1648 unsigned fStyle : 2;
1649 unsigned fTextEncoding : 2; // 3 values
1650 unsigned fHinting : 2;
reedf803da12015-01-23 05:58:07 -08001651 unsigned fFilterQuality : 2;
commit-bot@chromium.org85faf502014-04-16 12:58:02 +00001652 //unsigned fFreeBits : 2;
reedf59eab22014-07-14 14:39:15 -07001653 } fBitfields;
1654 uint32_t fBitfieldsUInt;
commit-bot@chromium.orgaca1c012014-02-21 18:18:05 +00001655 };
commit-bot@chromium.orge8807f42014-03-24 23:03:11 +00001656
robertphillipse34f17d2016-07-19 07:59:22 -07001657 static GlyphCacheProc GetGlyphCacheProc(TextEncoding encoding,
1658 bool isDevKern,
1659 bool needFullMetrics);
reed@google.comd5f20792012-05-16 14:15:02 +00001660
1661 SkScalar measure_text(SkGlyphCache*, const char* text, size_t length,
1662 int* count, SkRect* bounds) const;
1663
joshualitt9e36c1a2015-04-14 12:17:27 -07001664 /*
1665 * The luminance color is used to determine which Gamma Canonical color to map to. This is
1666 * really only used by backends which want to cache glyph masks, and need some way to know if
1667 * they need to generate new masks based off a given color.
1668 */
1669 SkColor computeLuminanceColor() const;
1670
reed@android.com8a1c16f2008-12-17 15:59:43 +00001671 enum {
reed@google.comed43dff2013-06-04 16:56:27 +00001672 /* This is the size we use when we ask for a glyph's path. We then
1673 * post-transform it as we draw to match the request.
1674 * This is done to try to re-use cache entries for the path.
1675 *
1676 * This value is somewhat arbitrary. In theory, it could be 1, since
1677 * we store paths as floats. However, we get the path from the font
1678 * scaler, and it may represent its paths as fixed-point (or 26.6),
1679 * so we shouldn't ask for something too big (might overflow 16.16)
1680 * or too small (underflow 26.6).
1681 *
1682 * This value could track kMaxSizeForGlyphCache, assuming the above
1683 * constraints, but since we ask for unhinted paths, the two values
1684 * need not match per-se.
1685 */
1686 kCanonicalTextSizeForPaths = 64,
reed@android.com8a1c16f2008-12-17 15:59:43 +00001687 };
reed@google.comed43dff2013-06-04 16:56:27 +00001688
Jim Van Verthc65b65d2018-01-16 16:26:35 -05001689 static bool TooBigToUseCache(const SkMatrix& ctm, const SkMatrix& textM, SkScalar maxLimit);
reed@google.comed43dff2013-06-04 16:56:27 +00001690
reed@google.comed43dff2013-06-04 16:56:27 +00001691 // Set flags/hinting/textSize up to use for drawing text as paths.
1692 // Returns scale factor to restore the original textSize, since will will
1693 // have change it to kCanonicalTextSizeForPaths.
1694 SkScalar setupForAsPaths();
1695
Jim Van Verthc65b65d2018-01-16 16:26:35 -05001696 static SkScalar MaxCacheSize2(SkScalar maxLimit);
reed@google.comed43dff2013-06-04 16:56:27 +00001697
Herb Derby980a48d2018-01-23 13:39:21 -05001698 friend class GrAtlasTextBlob;
1699 friend class GrAtlasTextContext;
1700 friend class GrGLPathRendering;
1701 friend class GrPathRendering;
Herb Derby980a48d2018-01-23 13:39:21 -05001702 friend class GrTextUtils;
vandebo@chromium.org28be72b2010-11-11 21:37:00 +00001703 friend class SkAutoGlyphCache;
jvanverth2d2a68c2014-06-10 06:42:56 -07001704 friend class SkAutoGlyphCacheNoGamma;
Herb Derby980a48d2018-01-23 13:39:21 -05001705 friend class SkCanonicalizePaint;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001706 friend class SkCanvas;
1707 friend class SkDraw;
Cary Clark60ca8672018-03-06 15:09:27 -05001708 friend class SkPaintPriv;
vandebo@chromium.org28be72b2010-11-11 21:37:00 +00001709 friend class SkPDFDevice;
Herb Derby980a48d2018-01-23 13:39:21 -05001710 friend class SkScalerContext; // for computeLuminanceColor()
caryclark0449bcf2016-02-09 13:25:45 -08001711 friend class SkTextBaseIter;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001712};
1713
reed@android.com8a1c16f2008-12-17 15:59:43 +00001714#endif