blob: 883e5c610e0552d7985d2f9e2aa961eb5de9f43e [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00006 */
7
8#ifndef SkPaint_DEFINED
9#define SkPaint_DEFINED
10
reed374772b2016-10-05 17:33:02 -070011#include "SkBlendMode.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000012#include "SkColor.h"
reedf803da12015-01-23 05:58:07 -080013#include "SkFilterQuality.h"
reed@google.comed43dff2013-06-04 16:56:27 +000014#include "SkMatrix.h"
Mike Reed71fecc32016-11-18 17:19:54 -050015#include "SkRefCnt.h"
reed@android.coma0f5d152009-06-22 17:38:10 +000016
joshualitt2b6acb42015-04-01 11:30:27 -070017class SkAutoDescriptor;
reed@android.com8a1c16f2008-12-17 15:59:43 +000018class SkColorFilter;
joshualittfd450792015-03-13 08:38:43 -070019class SkData;
reed@android.com8a1c16f2008-12-17 15:59:43 +000020class SkDescriptor;
senorblanco0abdf762015-08-20 11:10:41 -070021class SkDrawLooper;
herbb69d0e02015-02-25 06:47:06 -080022class SkGlyph;
reed@android.com8a1c16f2008-12-17 15:59:43 +000023struct SkRect;
24class SkGlyphCache;
reed@google.com15356a62011-11-03 19:29:08 +000025class SkImageFilter;
reed@android.com8a1c16f2008-12-17 15:59:43 +000026class SkMaskFilter;
reed@android.com8a1c16f2008-12-17 15:59:43 +000027class SkPath;
28class SkPathEffect;
djsollen@google.comc73dd5c2012-08-07 15:54:32 +000029struct SkPoint;
reed@android.com8a1c16f2008-12-17 15:59:43 +000030class SkShader;
robertphillipsfcf78292015-06-19 11:49:52 -070031class SkSurfaceProps;
fmalitaeae6a912016-07-28 09:47:24 -070032class SkTextBlob;
reed@android.com8a1c16f2008-12-17 15:59:43 +000033class SkTypeface;
reed@android.com8a1c16f2008-12-17 15:59:43 +000034
reed@android.com8a1c16f2008-12-17 15:59:43 +000035/** \class SkPaint
Cary Clark50fa3ff2017-07-26 10:15:23 -040036 SkPaint controls options applied when drawing and measuring. SkPaint collects all
37 options outside of the SkCanvas clip and SkCanvas matrix.
reed@android.com8a1c16f2008-12-17 15:59:43 +000038
Cary Clark50fa3ff2017-07-26 10:15:23 -040039 Various options apply to text, strokes and fills, and images.
40
41 Some options may not be implemented on all platforms; in these cases, setting
42 the option has no effect. Some options are conveniences that duplicate SkCanvas
43 functionality; for instance, text size is identical to matrix scale.
44
45 SkPaint options are rarely exclusive; each option modifies a stage of the drawing
Cary Clark23890a92017-07-27 16:30:51 -040046 pipeline and multiple pipeline stages may be affected by a single SkPaint.
Cary Clark50fa3ff2017-07-26 10:15:23 -040047
Cary Clark23890a92017-07-27 16:30:51 -040048 SkPaint collects effects and filters that describe single-pass and multiple-pass
Cary Clark50fa3ff2017-07-26 10:15:23 -040049 algorithms that alter the drawing geometry, color, and transparency. For instance,
50 SkPaint does not directly implement dashing or blur, but contains the objects that do so.
51
52 The objects contained by SkPaint are opaque, and cannot be edited outside of the SkPaint
53 to affect it. The implementation is free to defer computations associated with the
54 SkPaint, or ignore them altogether. For instance, some GPU implementations draw all
Cary Clarkb7da7232017-09-01 13:49:54 -040055 SkPath geometries with anti-aliasing, regardless of how SkPaint::kAntiAlias_Flag
56 is set in SkPaint.
Cary Clark50fa3ff2017-07-26 10:15:23 -040057
58 SkPaint describes a single color, a single font, a single image quality, and so on.
59 Multiple colors are drawn either by using multiple paints or with objects like
60 SkShader attached to SkPaint.
reed@android.com8a1c16f2008-12-17 15:59:43 +000061*/
ctguil@chromium.org7ffb1b22011-03-15 21:27:08 +000062class SK_API SkPaint {
reed@android.com8a1c16f2008-12-17 15:59:43 +000063public:
Cary Clark50fa3ff2017-07-26 10:15:23 -040064
65 /** Constructs SkPaint with default values.
66
67 @return default initialized SkPaint
68 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000069 SkPaint();
Cary Clark50fa3ff2017-07-26 10:15:23 -040070
71 /** Makes a shallow copy of SkPaint. SkTypeface, SkPathEffect, SkShader,
Mike Reed8ad91a92018-01-19 19:09:32 -050072 SkMaskFilter, SkColorFilter, SkDrawLooper, and SkImageFilter are shared
Cary Clarkb7da7232017-09-01 13:49:54 -040073 between the original paint and the copy. Objects containing SkRefCnt increment
74 their references by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -040075
Mike Reed8ad91a92018-01-19 19:09:32 -050076 The referenced objects SkPathEffect, SkShader, SkMaskFilter, SkColorFilter,
Cary Clark50fa3ff2017-07-26 10:15:23 -040077 SkDrawLooper, and SkImageFilter cannot be modified after they are created.
78 This prevents objects with SkRefCnt from being modified once SkPaint refers to them.
79
80 @param paint original to copy
81 @return shallow copy of paint
82 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000083 SkPaint(const SkPaint& paint);
Cary Clark50fa3ff2017-07-26 10:15:23 -040084
Cary Clark8a02b0b2017-09-21 12:28:43 -040085 /** Implements a move constructor to avoid increasing the reference counts
Cary Clark50fa3ff2017-07-26 10:15:23 -040086 of objects referenced by the paint.
87
88 After the call, paint is undefined, and can be safely destructed.
89
90 @param paint original to move
91 @return content of paint
92 */
bungemanccce0e02016-02-07 14:37:23 -080093 SkPaint(SkPaint&& paint);
Cary Clark50fa3ff2017-07-26 10:15:23 -040094
95 /** Decreases SkPaint SkRefCnt of owned objects: SkTypeface, SkPathEffect, SkShader,
Mike Reed8ad91a92018-01-19 19:09:32 -050096 SkMaskFilter, SkColorFilter, SkDrawLooper, and SkImageFilter. If the
Cary Clarkb7da7232017-09-01 13:49:54 -040097 objects containing SkRefCnt go to zero, they are deleted.
Cary Clark50fa3ff2017-07-26 10:15:23 -040098 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000099 ~SkPaint();
100
Cary Clark50fa3ff2017-07-26 10:15:23 -0400101 /** Makes a shallow copy of SkPaint. SkTypeface, SkPathEffect, SkShader,
Mike Reed8ad91a92018-01-19 19:09:32 -0500102 SkMaskFilter, SkColorFilter, SkDrawLooper, and SkImageFilter are shared
Cary Clarkb7da7232017-09-01 13:49:54 -0400103 between the original paint and the copy. Objects containing SkRefCnt in the
Cary Clark50fa3ff2017-07-26 10:15:23 -0400104 prior destination are decreased by one, and the referenced objects are deleted if the
Cary Clarkb7da7232017-09-01 13:49:54 -0400105 resulting count is zero. Objects containing SkRefCnt in the parameter paint
106 are increased by one. paint is unmodified.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400107
108 @param paint original to copy
109 @return content of paint
110 */
Cary Clark0418a882017-05-10 09:07:42 -0400111 SkPaint& operator=(const SkPaint& paint);
Cary Clark50fa3ff2017-07-26 10:15:23 -0400112
Cary Clark8a02b0b2017-09-21 12:28:43 -0400113 /** Moves the paint to avoid increasing the reference counts
Cary Clarkb7da7232017-09-01 13:49:54 -0400114 of objects referenced by the paint parameter. Objects containing SkRefCnt in the
115 prior destination are decreased by one; those objects are deleted if the resulting count
116 is zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400117
118 After the call, paint is undefined, and can be safely destructed.
119
120 @param paint original to move
121 @return content of paint
122 */
Cary Clark0418a882017-05-10 09:07:42 -0400123 SkPaint& operator=(SkPaint&& paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000124
Cary Clark50fa3ff2017-07-26 10:15:23 -0400125 /** Compares a and b, and returns true if a and b are equivalent. May return false
Mike Reed8ad91a92018-01-19 19:09:32 -0500126 if SkTypeface, SkPathEffect, SkShader, SkMaskFilter, SkColorFilter,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400127 SkDrawLooper, or SkImageFilter have identical contents but different pointers.
128
129 @param a SkPaint to compare
130 @param b SkPaint to compare
131 @return true if SkPaint pair are equivalent
mtkleinbc97ef42014-08-25 10:10:47 -0700132 */
robertphillips@google.comb2657412013-08-07 22:36:29 +0000133 SK_API friend bool operator==(const SkPaint& a, const SkPaint& b);
Cary Clark50fa3ff2017-07-26 10:15:23 -0400134
135 /** Compares a and b, and returns true if a and b are not equivalent. May return true
Mike Reed8ad91a92018-01-19 19:09:32 -0500136 if SkTypeface, SkPathEffect, SkShader, SkMaskFilter, SkColorFilter,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400137 SkDrawLooper, or SkImageFilter have identical contents but different pointers.
138
139 @param a SkPaint to compare
140 @param b SkPaint to compare
141 @return true if SkPaint pair are not equivalent
142 */
robertphillips@google.comb2657412013-08-07 22:36:29 +0000143 friend bool operator!=(const SkPaint& a, const SkPaint& b) {
144 return !(a == b);
145 }
146
Cary Clark50fa3ff2017-07-26 10:15:23 -0400147 /** Returns a hash generated from SkPaint values and pointers.
148 Identical hashes guarantee that the paints are
149 equivalent, but differing hashes do not guarantee that the paints have differing
150 contents.
151
152 If operator==(const SkPaint& a, const SkPaint& b) returns true for two paints,
153 their hashes are also equal.
154
155 The hash returned is platform and implementation specific.
156
157 @return a shallow hash
158 */
mtkleinfb1fe4f2014-10-07 09:26:10 -0700159 uint32_t getHash() const;
160
Cary Clarkcc309eb2017-10-30 11:48:35 -0400161 /** Sets all SkPaint contents to their initial values. This is equivalent to replacing
162 SkPaint with the result of SkPaint().
reed@android.com8a1c16f2008-12-17 15:59:43 +0000163 */
164 void reset();
165
Cary Clark50fa3ff2017-07-26 10:15:23 -0400166 /** \enum SkPaint::Hinting
167 Hinting adjusts the glyph outlines so that the shape provides a uniform
168 look at a given point size on font engines that support it. Hinting may have a
169 muted effect or no effect at all depending on the platform.
170
171 The four levels roughly control corresponding features on platforms that use FreeType
172 as the font engine.
agl@chromium.org309485b2009-07-21 17:41:32 +0000173 */
174 enum Hinting {
Cary Clark462505f2018-05-30 09:20:29 -0400175 kNo_Hinting = 0, //!< glyph outlines unchanged
176 kSlight_Hinting = 1, //!< minimal modification to improve constrast
177 kNormal_Hinting = 2, //!< glyph outlines modified to improve constrast
178 kFull_Hinting = 3, //!< modifies glyph outlines for maximum constrast
agl@chromium.org309485b2009-07-21 17:41:32 +0000179 };
180
Cary Clark50fa3ff2017-07-26 10:15:23 -0400181 /** Returns level of glyph outline adjustment.
182
183 @return one of: kNo_Hinting, kSlight_Hinting, kNormal_Hinting, kFull_Hinting
184 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000185 Hinting getHinting() const {
reedf59eab22014-07-14 14:39:15 -0700186 return static_cast<Hinting>(fBitfields.fHinting);
agl@chromium.org309485b2009-07-21 17:41:32 +0000187 }
188
Cary Clark50fa3ff2017-07-26 10:15:23 -0400189 /** Sets level of glyph outline adjustment.
190 Does not check for valid values of hintingLevel.
191
192 @param hintingLevel one of: kNo_Hinting, kSlight_Hinting, kNormal_Hinting, kFull_Hinting
193 */
djsollen@google.comf5dbe2f2011-04-15 13:41:26 +0000194 void setHinting(Hinting hintingLevel);
agl@chromium.org309485b2009-07-21 17:41:32 +0000195
Cary Clark50fa3ff2017-07-26 10:15:23 -0400196 /** \enum SkPaint::Flags
197 The bit values stored in Flags.
198 The default value for Flags, normally zero, can be changed at compile time
199 with a custom definition of SkPaintDefaults_Flags.
200 All flags can be read and written explicitly; Flags allows manipulating
201 multiple settings at once.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000202 */
203 enum Flags {
Cary Clark1eace2d2017-07-31 07:52:43 -0400204 kAntiAlias_Flag = 0x01, //!< mask for setting anti-alias
205 kDither_Flag = 0x04, //!< mask for setting dither
Cary Clark50fa3ff2017-07-26 10:15:23 -0400206 kFakeBoldText_Flag = 0x20, //!< mask for setting fake bold
207 kLinearText_Flag = 0x40, //!< mask for setting linear text
208 kSubpixelText_Flag = 0x80, //!< mask for setting subpixel text
Cary Clark75959392018-02-27 10:22:04 -0500209 kLCDRenderText_Flag = 0x200, //!< mask for setting LCD text
Cary Clark50fa3ff2017-07-26 10:15:23 -0400210 kEmbeddedBitmapText_Flag = 0x400, //!< mask for setting font embedded bitmaps
211 kAutoHinting_Flag = 0x800, //!< mask for setting auto-hinting
212 kVerticalText_Flag = 0x1000, //!< mask for setting vertical text
Cary Clark462505f2018-05-30 09:20:29 -0400213 kAllFlags = 0xFFFF, //!< mask of all Flags
reed@android.com8a1c16f2008-12-17 15:59:43 +0000214 };
215
Cary Clark50fa3ff2017-07-26 10:15:23 -0400216 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Mike Reedddbd37e2017-02-21 15:07:44 -0500217 enum ReserveFlags {
Cary Clark462505f2018-05-30 09:20:29 -0400218 kUnderlineText_ReserveFlag = 0x08, //!< to be deprecated soon
219 kStrikeThruText_ReserveFlag = 0x10, //!< to be deprecated soon
Mike Reedddbd37e2017-02-21 15:07:44 -0500220 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400221 #endif
Mike Reedddbd37e2017-02-21 15:07:44 -0500222
Cary Clark50fa3ff2017-07-26 10:15:23 -0400223 /** Returns paint settings described by SkPaint::Flags. Each setting uses one
224 bit, and can be tested with SkPaint::Flags members.
225
226 @return zero, one, or more bits described by SkPaint::Flags
reed@android.com8a1c16f2008-12-17 15:59:43 +0000227 */
reedf59eab22014-07-14 14:39:15 -0700228 uint32_t getFlags() const { return fBitfields.fFlags; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000229
Cary Clark23890a92017-07-27 16:30:51 -0400230 /** Replaces SkPaint::Flags with flags, the union of the SkPaint::Flags members.
231 All SkPaint::Flags members may be cleared, or one or more may be set.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400232
233 @param flags union of SkPaint::Flags for SkPaint
reed@android.com8a1c16f2008-12-17 15:59:43 +0000234 */
235 void setFlags(uint32_t flags);
236
Cary Clark50fa3ff2017-07-26 10:15:23 -0400237 /** If true, pixels on the active edges of SkPath may be drawn with partial transparency.
238
Cary Clark579985c2017-07-31 11:48:27 -0400239 Equivalent to getFlags() masked with kAntiAlias_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400240
241 @return kAntiAlias_Flag state
242 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000243 bool isAntiAlias() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000244 return SkToBool(this->getFlags() & kAntiAlias_Flag);
245 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000246
Cary Clark50fa3ff2017-07-26 10:15:23 -0400247 /** Requests, but does not require, that SkPath edge pixels draw opaque or with
248 partial transparency.
249
250 Sets kAntiAlias_Flag if aa is true.
251 Clears kAntiAlias_Flag if aa is false.
252
253 @param aa setting for kAntiAlias_Flag
254 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000255 void setAntiAlias(bool aa);
reed@google.com9d07fec2011-03-16 20:02:59 +0000256
Cary Clark50fa3ff2017-07-26 10:15:23 -0400257 /** If true, color error may be distributed to smooth color transition.
258
Cary Clark579985c2017-07-31 11:48:27 -0400259 Equivalent to getFlags() masked with kDither_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400260
261 @return kDither_Flag state
262 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000263 bool isDither() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000264 return SkToBool(this->getFlags() & kDither_Flag);
265 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000266
Cary Clark50fa3ff2017-07-26 10:15:23 -0400267 /** Requests, but does not require, to distribute color error.
268
269 Sets kDither_Flag if dither is true.
270 Clears kDither_Flag if dither is false.
271
272 @param dither setting for kDither_Flag
273 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000274 void setDither(bool dither);
reed@google.com9d07fec2011-03-16 20:02:59 +0000275
Cary Clark50fa3ff2017-07-26 10:15:23 -0400276 /** If true, text is converted to SkPath before drawing and measuring.
277
Cary Clark579985c2017-07-31 11:48:27 -0400278 Equivalent to getFlags() masked with kLinearText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400279
280 @return kLinearText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000281 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000282 bool isLinearText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000283 return SkToBool(this->getFlags() & kLinearText_Flag);
284 }
285
Cary Clark50fa3ff2017-07-26 10:15:23 -0400286 /** If true, text is converted to SkPath before drawing and measuring.
287 By default, kLinearText_Flag is clear.
288
289 Sets kLinearText_Flag if linearText is true.
290 Clears kLinearText_Flag if linearText is false.
291
292 @param linearText setting for kLinearText_Flag
reed@android.com8a1c16f2008-12-17 15:59:43 +0000293 */
294 void setLinearText(bool linearText);
295
Cary Clark50fa3ff2017-07-26 10:15:23 -0400296 /** If true, glyphs at different sub-pixel positions may differ on pixel edge coverage.
297
Cary Clark579985c2017-07-31 11:48:27 -0400298 Equivalent to getFlags() masked with kSubpixelText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400299
300 @return kSubpixelText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000301 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000302 bool isSubpixelText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000303 return SkToBool(this->getFlags() & kSubpixelText_Flag);
304 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000305
Cary Clark50fa3ff2017-07-26 10:15:23 -0400306 /** Requests, but does not require, that glyphs respect sub-pixel positioning.
307
308 Sets kSubpixelText_Flag if subpixelText is true.
309 Clears kSubpixelText_Flag if subpixelText is false.
310
311 @param subpixelText setting for kSubpixelText_Flag
312 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000313 void setSubpixelText(bool subpixelText);
agl@chromium.org309485b2009-07-21 17:41:32 +0000314
Cary Clark50fa3ff2017-07-26 10:15:23 -0400315 /** If true, glyphs may use LCD striping to improve glyph edges.
316
317 Returns true if SkPaint::Flags kLCDRenderText_Flag is set.
318
319 @return kLCDRenderText_Flag state
320 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000321 bool isLCDRenderText() const {
agl@chromium.org309485b2009-07-21 17:41:32 +0000322 return SkToBool(this->getFlags() & kLCDRenderText_Flag);
323 }
324
Cary Clark50fa3ff2017-07-26 10:15:23 -0400325 /** Requests, but does not require, that glyphs use LCD striping for glyph edges.
326
327 Sets kLCDRenderText_Flag if lcdText is true.
328 Clears kLCDRenderText_Flag if lcdText is false.
329
330 @param lcdText setting for kLCDRenderText_Flag
331 */
reed@google.com84b437e2011-08-01 12:45:35 +0000332 void setLCDRenderText(bool lcdText);
agl@chromium.org309485b2009-07-21 17:41:32 +0000333
Cary Clark50fa3ff2017-07-26 10:15:23 -0400334 /** If true, font engine may return glyphs from font bitmaps instead of from outlines.
335
Cary Clark579985c2017-07-31 11:48:27 -0400336 Equivalent to getFlags() masked with kEmbeddedBitmapText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400337
338 @return kEmbeddedBitmapText_Flag state
339 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000340 bool isEmbeddedBitmapText() const {
agl@chromium.orge95c91e2010-01-04 18:27:55 +0000341 return SkToBool(this->getFlags() & kEmbeddedBitmapText_Flag);
342 }
343
Cary Clark50fa3ff2017-07-26 10:15:23 -0400344 /** Requests, but does not require, to use bitmaps in fonts instead of outlines.
345
346 Sets kEmbeddedBitmapText_Flag if useEmbeddedBitmapText is true.
347 Clears kEmbeddedBitmapText_Flag if useEmbeddedBitmapText is false.
348
349 @param useEmbeddedBitmapText setting for kEmbeddedBitmapText_Flag
agl@chromium.orge95c91e2010-01-04 18:27:55 +0000350 */
351 void setEmbeddedBitmapText(bool useEmbeddedBitmapText);
352
Cary Clark50fa3ff2017-07-26 10:15:23 -0400353 /** If true, and if SkPaint::Hinting is set to kNormal_Hinting or kFull_Hinting, and if
354 platform uses FreeType as the font manager, instruct the font manager to always hint
Cary Clark1eace2d2017-07-31 07:52:43 -0400355 glyphs.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400356
Cary Clark579985c2017-07-31 11:48:27 -0400357 Equivalent to getFlags() masked with kAutoHinting_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400358
359 @return kAutoHinting_Flag state
360 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000361 bool isAutohinted() const {
agl@chromium.orga2c71cb2010-06-17 20:49:17 +0000362 return SkToBool(this->getFlags() & kAutoHinting_Flag);
363 }
364
Cary Clark50fa3ff2017-07-26 10:15:23 -0400365 /** If SkPaint::Hinting is set to kNormal_Hinting or kFull_Hinting and useAutohinter is set,
Cary Clark1eace2d2017-07-31 07:52:43 -0400366 instruct the font manager to always hint glyphs.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400367 auto-hinting has no effect if SkPaint::Hinting is set to kNo_Hinting or
368 kSlight_Hinting.
369
Cary Clark579985c2017-07-31 11:48:27 -0400370 Only affects platforms that use FreeType as the font manager.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400371
372 Sets kAutoHinting_Flag if useAutohinter is true.
373 Clears kAutoHinting_Flag if useAutohinter is false.
374
375 @param useAutohinter setting for kAutoHinting_Flag
agl@chromium.orga2c71cb2010-06-17 20:49:17 +0000376 */
377 void setAutohinted(bool useAutohinter);
378
Cary Clark50fa3ff2017-07-26 10:15:23 -0400379 /** If true, glyphs are drawn top to bottom instead of left to right.
380
Cary Clark579985c2017-07-31 11:48:27 -0400381 Equivalent to getFlags() masked with kVerticalText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400382
383 @return kVerticalText_Flag state
384 */
reed@google.com830a23e2011-11-10 15:20:49 +0000385 bool isVerticalText() const {
386 return SkToBool(this->getFlags() & kVerticalText_Flag);
387 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000388
Cary Clark50fa3ff2017-07-26 10:15:23 -0400389 /** If true, text advance positions the next glyph below the previous glyph instead of to the
390 right of previous glyph.
391
392 Sets kVerticalText_Flag if vertical is true.
393 Clears kVerticalText_Flag if vertical is false.
394
395 @param verticalText setting for kVerticalText_Flag
396 */
Cary Clark0418a882017-05-10 09:07:42 -0400397 void setVerticalText(bool verticalText);
reed@google.com830a23e2011-11-10 15:20:49 +0000398
Cary Clark50fa3ff2017-07-26 10:15:23 -0400399 /** If true, approximate bold by increasing the stroke width when creating glyph bitmaps
400 from outlines.
401
Cary Clark579985c2017-07-31 11:48:27 -0400402 Equivalent to getFlags() masked with kFakeBoldText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400403
404 @return kFakeBoldText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000405 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000406 bool isFakeBoldText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000407 return SkToBool(this->getFlags() & kFakeBoldText_Flag);
408 }
409
Cary Clarkb7da7232017-09-01 13:49:54 -0400410 /** Use increased stroke width when creating glyph bitmaps to approximate a bold typeface.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400411
412 Sets kFakeBoldText_Flag if fakeBoldText is true.
413 Clears kFakeBoldText_Flag if fakeBoldText is false.
414
415 @param fakeBoldText setting for kFakeBoldText_Flag
reed@android.com8a1c16f2008-12-17 15:59:43 +0000416 */
417 void setFakeBoldText(bool fakeBoldText);
418
Cary Clark462505f2018-05-30 09:20:29 -0400419 /** Deprecated.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000420 */
Herb Derbyfcac00f2018-05-01 11:57:56 -0400421 bool isDevKernText() const { return false; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000422
Cary Clark462505f2018-05-30 09:20:29 -0400423 /** Deprecated.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000424 */
Herb Derbyfcac00f2018-05-01 11:57:56 -0400425 void setDevKernText(bool) { }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000426
Cary Clark50fa3ff2017-07-26 10:15:23 -0400427 /** Returns SkFilterQuality, the image filtering level. A lower setting
428 draws faster; a higher setting looks better when the image is scaled.
429
430 @return one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
431 kMedium_SkFilterQuality, kHigh_SkFilterQuality
432 */
reedf803da12015-01-23 05:58:07 -0800433 SkFilterQuality getFilterQuality() const {
434 return (SkFilterQuality)fBitfields.fFilterQuality;
435 }
mtkleinfe81e2d2015-09-09 07:35:42 -0700436
Cary Clark23890a92017-07-27 16:30:51 -0400437 /** Sets SkFilterQuality, the image filtering level. A lower setting
Cary Clark50fa3ff2017-07-26 10:15:23 -0400438 draws faster; a higher setting looks better when the image is scaled.
Cary Clark579985c2017-07-31 11:48:27 -0400439 Does not check to see if quality is valid.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400440
441 @param quality one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
442 kMedium_SkFilterQuality, kHigh_SkFilterQuality
443 */
reedf803da12015-01-23 05:58:07 -0800444 void setFilterQuality(SkFilterQuality quality);
reed@google.comc9683152013-07-18 13:47:01 +0000445
Cary Clark50fa3ff2017-07-26 10:15:23 -0400446 /** \enum SkPaint::Style
Cary Clark23890a92017-07-27 16:30:51 -0400447 Set Style to fill, stroke, or both fill and stroke geometry.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400448 The stroke and fill
449 share all paint attributes; for instance, they are drawn with the same color.
reed@google.com9d07fec2011-03-16 20:02:59 +0000450
Cary Clark50fa3ff2017-07-26 10:15:23 -0400451 Use kStrokeAndFill_Style to avoid hitting the same pixels twice with a stroke draw and
452 a fill draw.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000453 */
454 enum Style {
Cary Clark462505f2018-05-30 09:20:29 -0400455 kFill_Style, //!< set to fill geometry
456 kStroke_Style, //!< set to stroke geometry
457 kStrokeAndFill_Style, //!< sets to stroke and fill geometry
reed@android.com8a1c16f2008-12-17 15:59:43 +0000458 };
459
Cary Clark462505f2018-05-30 09:20:29 -0400460 /** May be used to verify that SkPaint::Style is a legal value.
Cary Clarkd98f78c2018-04-26 08:32:37 -0400461 */
462 static constexpr int kStyleCount = kStrokeAndFill_Style + 1;
Cary Clark50fa3ff2017-07-26 10:15:23 -0400463
464 /** Whether the geometry is filled, stroked, or filled and stroked.
465
466 @return one of:kFill_Style, kStroke_Style, kStrokeAndFill_Style
reed@android.com8a1c16f2008-12-17 15:59:43 +0000467 */
reedf59eab22014-07-14 14:39:15 -0700468 Style getStyle() const { return (Style)fBitfields.fStyle; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000469
Cary Clark50fa3ff2017-07-26 10:15:23 -0400470 /** Sets whether the geometry is filled, stroked, or filled and stroked.
471 Has no effect if style is not a legal SkPaint::Style value.
472
473 @param style one of: kFill_Style, kStroke_Style, kStrokeAndFill_Style
reed@android.com8a1c16f2008-12-17 15:59:43 +0000474 */
475 void setStyle(Style style);
476
Cary Clark50fa3ff2017-07-26 10:15:23 -0400477 /** Retrieves alpha and RGB, unpremultiplied, packed into 32 bits.
478 Use helpers SkColorGetA(), SkColorGetR(), SkColorGetG(), and SkColorGetB() to extract
479 a color component.
480
Cary Clark8a02b0b2017-09-21 12:28:43 -0400481 @return unpremultiplied ARGB
reed@android.com8a1c16f2008-12-17 15:59:43 +0000482 */
483 SkColor getColor() const { return fColor; }
484
Cary Clark50fa3ff2017-07-26 10:15:23 -0400485 /** Sets alpha and RGB used when stroking and filling. The color is a 32-bit value,
Cary Clarkb7da7232017-09-01 13:49:54 -0400486 unpremultiplied, packing 8-bit components for alpha, red, blue, and green.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400487
Cary Clark8a02b0b2017-09-21 12:28:43 -0400488 @param color unpremultiplied ARGB
reed@android.com8a1c16f2008-12-17 15:59:43 +0000489 */
490 void setColor(SkColor color);
491
Cary Clark1eace2d2017-07-31 07:52:43 -0400492 /** Retrieves alpha from the color used when stroking and filling.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400493
Cary Clark8a02b0b2017-09-21 12:28:43 -0400494 @return alpha ranging from zero, fully transparent, to 255, fully opaque
Cary Clark50fa3ff2017-07-26 10:15:23 -0400495 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000496 uint8_t getAlpha() const { return SkToU8(SkColorGetA(fColor)); }
reed@google.com9d07fec2011-03-16 20:02:59 +0000497
Cary Clark50fa3ff2017-07-26 10:15:23 -0400498 /** Replaces alpha, leaving RGB
499 unchanged. An out of range value triggers an assert in the debug
500 build. a is a value from zero to 255.
Cary Clark1eace2d2017-07-31 07:52:43 -0400501 a set to zero makes color fully transparent; a set to 255 makes color
Cary Clark50fa3ff2017-07-26 10:15:23 -0400502 fully opaque.
503
Cary Clark8a02b0b2017-09-21 12:28:43 -0400504 @param a alpha component of color
reed@android.com8a1c16f2008-12-17 15:59:43 +0000505 */
506 void setAlpha(U8CPU a);
507
Cary Clark1eace2d2017-07-31 07:52:43 -0400508 /** Sets color used when drawing solid fills. The color components range from 0 to 255.
Cary Clarkb7da7232017-09-01 13:49:54 -0400509 The color is unpremultiplied; alpha sets the transparency independent of RGB.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400510
Cary Clark462505f2018-05-30 09:20:29 -0400511 @param a amount of alpha, from fully transparent (0) to fully opaque (255)
512 @param r amount of red, from no red (0) to full red (255)
513 @param g amount of green, from no green (0) to full green (255)
514 @param b amount of blue, from no blue (0) to full blue (255)
reed@android.com8a1c16f2008-12-17 15:59:43 +0000515 */
516 void setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b);
517
Cary Clark50fa3ff2017-07-26 10:15:23 -0400518 /** Returns the thickness of the pen used by SkPaint to
519 outline the shape.
520
Cary Clark1eace2d2017-07-31 07:52:43 -0400521 @return zero for hairline, greater than zero for pen thickness
reed@android.com8a1c16f2008-12-17 15:59:43 +0000522 */
523 SkScalar getStrokeWidth() const { return fWidth; }
524
Cary Clark50fa3ff2017-07-26 10:15:23 -0400525 /** Sets the thickness of the pen used by the paint to
526 outline the shape.
527 Has no effect if width is less than zero.
528
Cary Clark1eace2d2017-07-31 07:52:43 -0400529 @param width zero thickness for hairline; greater than zero for pen thickness
reed@android.com8a1c16f2008-12-17 15:59:43 +0000530 */
531 void setStrokeWidth(SkScalar width);
532
Cary Clark50fa3ff2017-07-26 10:15:23 -0400533 /** The limit at which a sharp corner is drawn beveled.
534
535 @return zero and greater miter limit
reed@android.com8a1c16f2008-12-17 15:59:43 +0000536 */
537 SkScalar getStrokeMiter() const { return fMiterLimit; }
538
Cary Clark50fa3ff2017-07-26 10:15:23 -0400539 /** The limit at which a sharp corner is drawn beveled.
540 Valid values are zero and greater.
541 Has no effect if miter is less than zero.
542
543 @param miter zero and greater miter limit
reed@android.com8a1c16f2008-12-17 15:59:43 +0000544 */
545 void setStrokeMiter(SkScalar miter);
546
Cary Clark50fa3ff2017-07-26 10:15:23 -0400547 /** \enum SkPaint::Cap
548 Cap draws at the beginning and end of an open path contour.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000549 */
550 enum Cap {
Cary Clark462505f2018-05-30 09:20:29 -0400551 kButt_Cap, //!< no stroke extension
552 kRound_Cap, //!< adds circle
553 kSquare_Cap, //!< adds square
554 kLast_Cap = kSquare_Cap, //!< largest Cap value
555 kDefault_Cap = kButt_Cap, //!< equivalent to kButt_Cap
reed@android.com8a1c16f2008-12-17 15:59:43 +0000556 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400557
Cary Clark462505f2018-05-30 09:20:29 -0400558 /** May be used to verify that SkPaint::Cap is a legal value.
559 */
bsalomona7d85ba2016-07-06 11:54:59 -0700560 static constexpr int kCapCount = kLast_Cap + 1;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000561
Cary Clark50fa3ff2017-07-26 10:15:23 -0400562 /** \enum SkPaint::Join
Cary Clark1eace2d2017-07-31 07:52:43 -0400563 Join specifies how corners are drawn when a shape is stroked. Join
Cary Clark50fa3ff2017-07-26 10:15:23 -0400564 affects the four corners of a stroked rectangle, and the connected segments in a
565 stroked path.
566
567 Choose miter join to draw sharp corners. Choose round join to draw a circle with a
568 radius equal to the stroke width on top of the corner. Choose bevel join to minimally
569 connect the thick strokes.
570
571 The fill path constructed to describe the stroked path respects the join setting but may
572 not contain the actual join. For instance, a fill path constructed with round joins does
573 not necessarily include circles at each connected segment.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000574 */
575 enum Join {
Cary Clark462505f2018-05-30 09:20:29 -0400576 kMiter_Join, //!< extends to miter limit
577 kRound_Join, //!< adds circle
578 kBevel_Join, //!< connects outside edges
579 kLast_Join = kBevel_Join, //!< equivalent to the largest value for Join
580 kDefault_Join = kMiter_Join, //!< equivalent to kMiter_Join
reed@android.com8a1c16f2008-12-17 15:59:43 +0000581 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400582
Cary Clark462505f2018-05-30 09:20:29 -0400583 /** May be used to verify that SkPaint::Join is a legal value.
584 */
bsalomona7d85ba2016-07-06 11:54:59 -0700585 static constexpr int kJoinCount = kLast_Join + 1;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000586
Cary Clark50fa3ff2017-07-26 10:15:23 -0400587 /** The geometry drawn at the beginning and end of strokes.
588
589 @return one of: kButt_Cap, kRound_Cap, kSquare_Cap
reed@android.com8a1c16f2008-12-17 15:59:43 +0000590 */
reedf59eab22014-07-14 14:39:15 -0700591 Cap getStrokeCap() const { return (Cap)fBitfields.fCapType; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000592
Cary Clark50fa3ff2017-07-26 10:15:23 -0400593 /** The geometry drawn at the beginning and end of strokes.
594
595 @param cap one of: kButt_Cap, kRound_Cap, kSquare_Cap;
596 has no effect if cap is not valid
reed@android.com8a1c16f2008-12-17 15:59:43 +0000597 */
598 void setStrokeCap(Cap cap);
599
Cary Clark50fa3ff2017-07-26 10:15:23 -0400600 /** The geometry drawn at the corners of strokes.
601
602 @return one of: kMiter_Join, kRound_Join, kBevel_Join
reed@android.com8a1c16f2008-12-17 15:59:43 +0000603 */
reedf59eab22014-07-14 14:39:15 -0700604 Join getStrokeJoin() const { return (Join)fBitfields.fJoinType; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000605
Cary Clark50fa3ff2017-07-26 10:15:23 -0400606 /** The geometry drawn at the corners of strokes.
607
608 @param join one of: kMiter_Join, kRound_Join, kBevel_Join;
Cary Clark579985c2017-07-31 11:48:27 -0400609 otherwise, has no effect
reed@android.com8a1c16f2008-12-17 15:59:43 +0000610 */
611 void setStrokeJoin(Join join);
612
Cary Clark50fa3ff2017-07-26 10:15:23 -0400613 /** The filled equivalent of the stroked path.
614
615 @param src SkPath read to create a filled version
616 @param dst resulting SkPath; may be the same as src, but may not be nullptr
617 @param cullRect optional limit passed to SkPathEffect
618 @param resScale if > 1, increase precision, else if (0 < res < 1) reduce precision
619 to favor speed and size
Cary Clark1eace2d2017-07-31 07:52:43 -0400620 @return true if the path represents style fill, or false if it represents hairline
Cary Clark50fa3ff2017-07-26 10:15:23 -0400621 */
reed05d90442015-02-12 13:35:52 -0800622 bool getFillPath(const SkPath& src, SkPath* dst, const SkRect* cullRect,
623 SkScalar resScale = 1) const;
624
Cary Clark50fa3ff2017-07-26 10:15:23 -0400625 /** The filled equivalent of the stroked path.
626
Cary Clark23890a92017-07-27 16:30:51 -0400627 Replaces dst with the src path modified by SkPathEffect and style stroke.
628 SkPathEffect, if any, is not culled. stroke width is created with default precision.
629
630 @param src SkPath read to create a filled version
631 @param dst resulting SkPath dst may be the same as src, but may not be nullptr
Cary Clark1eace2d2017-07-31 07:52:43 -0400632 @return true if the path represents style fill, or false if it represents hairline
Cary Clark50fa3ff2017-07-26 10:15:23 -0400633 */
reed05d90442015-02-12 13:35:52 -0800634 bool getFillPath(const SkPath& src, SkPath* dst) const {
Ben Wagnera93a14a2017-08-28 10:34:05 -0400635 return this->getFillPath(src, dst, nullptr, 1);
reed05d90442015-02-12 13:35:52 -0800636 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000637
Cary Clark50fa3ff2017-07-26 10:15:23 -0400638 /** Optional colors used when filling a path, such as a gradient.
639
640 Does not alter SkShader SkRefCnt.
641
642 @return SkShader if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000643 */
reeda5ab9ec2016-03-06 18:10:48 -0800644 SkShader* getShader() const { return fShader.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400645
646 /** Optional colors used when filling a path, such as a gradient.
647
648 Increases SkShader SkRefCnt by one.
649
650 @return SkShader if previously set, nullptr otherwise
651 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500652 sk_sp<SkShader> refShader() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000653
Cary Clark50fa3ff2017-07-26 10:15:23 -0400654 /** Optional colors used when filling a path, such as a gradient.
655
Cary Clark8a02b0b2017-09-21 12:28:43 -0400656 Sets SkShader to shader, decreasing SkRefCnt of the previous SkShader.
657 Increments shader SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400658
Cary Clark1eace2d2017-07-31 07:52:43 -0400659 @param shader how geometry is filled with color; if nullptr, color is used instead
Cary Clark50fa3ff2017-07-26 10:15:23 -0400660 */
Cary Clark0418a882017-05-10 09:07:42 -0400661 void setShader(sk_sp<SkShader> shader);
reed@google.com9d07fec2011-03-16 20:02:59 +0000662
Cary Clark50fa3ff2017-07-26 10:15:23 -0400663 /** Returns SkColorFilter if set, or nullptr.
664 Does not alter SkColorFilter SkRefCnt.
665
666 @return SkColorFilter if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000667 */
reeda5ab9ec2016-03-06 18:10:48 -0800668 SkColorFilter* getColorFilter() const { return fColorFilter.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400669
670 /** Returns SkColorFilter if set, or nullptr.
671 Increases SkColorFilter SkRefCnt by one.
672
673 @return SkColorFilter if set, or nullptr
674 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500675 sk_sp<SkColorFilter> refColorFilter() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000676
Cary Clark8a02b0b2017-09-21 12:28:43 -0400677 /** Sets SkColorFilter to filter, decreasing SkRefCnt of the previous
678 SkColorFilter. Pass nullptr to clear SkColorFilter.
679
680 Increments filter SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400681
682 @param colorFilter SkColorFilter to apply to subsequent draw
reed@android.com8a1c16f2008-12-17 15:59:43 +0000683 */
Cary Clark0418a882017-05-10 09:07:42 -0400684 void setColorFilter(sk_sp<SkColorFilter> colorFilter);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000685
Cary Clark50fa3ff2017-07-26 10:15:23 -0400686 /** Returns SkBlendMode.
Cary Clark579985c2017-07-31 11:48:27 -0400687 By default, returns SkBlendMode::kSrcOver.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400688
689 @return mode used to combine source color with destination color
690 */
reed374772b2016-10-05 17:33:02 -0700691 SkBlendMode getBlendMode() const { return (SkBlendMode)fBlendMode; }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400692
693 /** Returns true if SkBlendMode is SkBlendMode::kSrcOver, the default.
694
695 @return true if SkBlendMode is SkBlendMode::kSrcOver
696 */
reed374772b2016-10-05 17:33:02 -0700697 bool isSrcOver() const { return (SkBlendMode)fBlendMode == SkBlendMode::kSrcOver; }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400698
699 /** Sets SkBlendMode to mode.
700 Does not check for valid input.
701
702 @param mode SkBlendMode used to combine source color and destination
703 */
reed374772b2016-10-05 17:33:02 -0700704 void setBlendMode(SkBlendMode mode) { fBlendMode = (unsigned)mode; }
reed@android.coma0f5d152009-06-22 17:38:10 +0000705
Cary Clark50fa3ff2017-07-26 10:15:23 -0400706 /** Returns SkPathEffect if set, or nullptr.
707 Does not alter SkPathEffect SkRefCnt.
708
709 @return SkPathEffect if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000710 */
reeda5ab9ec2016-03-06 18:10:48 -0800711 SkPathEffect* getPathEffect() const { return fPathEffect.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400712
713 /** Returns SkPathEffect if set, or nullptr.
714 Increases SkPathEffect SkRefCnt by one.
715
716 @return SkPathEffect if previously set, nullptr otherwise
717 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500718 sk_sp<SkPathEffect> refPathEffect() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000719
Cary Clark8a02b0b2017-09-21 12:28:43 -0400720 /** Sets SkPathEffect to pathEffect, decreasing SkRefCnt of the previous
721 SkPathEffect. Pass nullptr to leave the path geometry unaltered.
722
723 Increments pathEffect SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400724
725 @param pathEffect replace SkPath with a modification when drawn
reed@android.com8a1c16f2008-12-17 15:59:43 +0000726 */
Cary Clark0418a882017-05-10 09:07:42 -0400727 void setPathEffect(sk_sp<SkPathEffect> pathEffect);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000728
Cary Clark50fa3ff2017-07-26 10:15:23 -0400729 /** Returns SkMaskFilter if set, or nullptr.
730 Does not alter SkMaskFilter SkRefCnt.
731
732 @return SkMaskFilter if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000733 */
reeda5ab9ec2016-03-06 18:10:48 -0800734 SkMaskFilter* getMaskFilter() const { return fMaskFilter.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400735
736 /** Returns SkMaskFilter if set, or nullptr.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400737
Cary Clark50fa3ff2017-07-26 10:15:23 -0400738 Increases SkMaskFilter SkRefCnt by one.
739
740 @return SkMaskFilter if previously set, nullptr otherwise
741 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500742 sk_sp<SkMaskFilter> refMaskFilter() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000743
Cary Clark8a02b0b2017-09-21 12:28:43 -0400744 /** Sets SkMaskFilter to maskFilter, decreasing SkRefCnt of the previous
745 SkMaskFilter. Pass nullptr to clear SkMaskFilter and leave SkMaskFilter effect on
746 mask alpha unaltered.
747
Cary Clark75959392018-02-27 10:22:04 -0500748 Increments maskFilter SkRefCnt by one.
749
Cary Clark50fa3ff2017-07-26 10:15:23 -0400750 @param maskFilter modifies clipping mask generated from drawn geometry
reed@android.com8a1c16f2008-12-17 15:59:43 +0000751 */
Cary Clark0418a882017-05-10 09:07:42 -0400752 void setMaskFilter(sk_sp<SkMaskFilter> maskFilter);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000753
Cary Clark50fa3ff2017-07-26 10:15:23 -0400754 /** Returns SkTypeface if set, or nullptr.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400755 Increments SkTypeface SkRefCnt by one.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000756
Cary Clark50fa3ff2017-07-26 10:15:23 -0400757 @return SkTypeface if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000758 */
reeda5ab9ec2016-03-06 18:10:48 -0800759 SkTypeface* getTypeface() const { return fTypeface.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400760
761 /** Increases SkTypeface SkRefCnt by one.
762
763 @return SkTypeface if previously set, nullptr otherwise
764 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500765 sk_sp<SkTypeface> refTypeface() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000766
Cary Clark8a02b0b2017-09-21 12:28:43 -0400767 /** Sets SkTypeface to typeface, decreasing SkRefCnt of the previous SkTypeface.
768 Pass nullptr to clear SkTypeface and use the default typeface. Increments
769 typeface SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400770
771 @param typeface font and style used to draw text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000772 */
Cary Clark0418a882017-05-10 09:07:42 -0400773 void setTypeface(sk_sp<SkTypeface> typeface);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000774
Cary Clark50fa3ff2017-07-26 10:15:23 -0400775 /** Returns SkImageFilter if set, or nullptr.
776 Does not alter SkImageFilter SkRefCnt.
777
778 @return SkImageFilter if previously set, nullptr otherwise
779 */
reeda5ab9ec2016-03-06 18:10:48 -0800780 SkImageFilter* getImageFilter() const { return fImageFilter.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400781
782 /** Returns SkImageFilter if set, or nullptr.
783 Increases SkImageFilter SkRefCnt by one.
784
785 @return SkImageFilter if previously set, nullptr otherwise
786 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500787 sk_sp<SkImageFilter> refImageFilter() const;
Cary Clark50fa3ff2017-07-26 10:15:23 -0400788
Cary Clark8a02b0b2017-09-21 12:28:43 -0400789 /** Sets SkImageFilter to imageFilter, decreasing SkRefCnt of the previous
790 SkImageFilter. Pass nullptr to clear SkImageFilter, and remove SkImageFilter effect
Cary Clark50fa3ff2017-07-26 10:15:23 -0400791 on drawing.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400792
Cary Clark75959392018-02-27 10:22:04 -0500793 Increments imageFilter SkRefCnt by one.
794
Cary Clark50fa3ff2017-07-26 10:15:23 -0400795 @param imageFilter how SkImage is sampled when transformed
796 */
Cary Clark0418a882017-05-10 09:07:42 -0400797 void setImageFilter(sk_sp<SkImageFilter> imageFilter);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000798
Cary Clark50fa3ff2017-07-26 10:15:23 -0400799 /** Returns SkDrawLooper if set, or nullptr.
800 Does not alter SkDrawLooper SkRefCnt.
801
802 @return SkDrawLooper if previously set, nullptr otherwise
803 */
reed46f2d0a2016-09-11 05:40:31 -0700804 SkDrawLooper* getDrawLooper() const { return fDrawLooper.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400805
806 /** Returns SkDrawLooper if set, or nullptr.
807 Increases SkDrawLooper SkRefCnt by one.
808
809 @return SkDrawLooper if previously set, nullptr otherwise
810 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500811 sk_sp<SkDrawLooper> refDrawLooper() const;
812
Cary Clark23890a92017-07-27 16:30:51 -0400813 /** Deprecated.
Cary Clark75959392018-02-27 10:22:04 -0500814 (see skbug.com/6259)
Cary Clark50fa3ff2017-07-26 10:15:23 -0400815 */
reed46f2d0a2016-09-11 05:40:31 -0700816 SkDrawLooper* getLooper() const { return fDrawLooper.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400817
Cary Clark8a02b0b2017-09-21 12:28:43 -0400818 /** Sets SkDrawLooper to drawLooper, decreasing SkRefCnt of the previous
819 drawLooper. Pass nullptr to clear SkDrawLooper and leave SkDrawLooper effect on
820 drawing unaltered.
821
822 Increments drawLooper SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400823
Cary Clarkb7da7232017-09-01 13:49:54 -0400824 @param drawLooper iterates through drawing one or more time, altering SkPaint
Cary Clark50fa3ff2017-07-26 10:15:23 -0400825 */
Cary Clark0418a882017-05-10 09:07:42 -0400826 void setDrawLooper(sk_sp<SkDrawLooper> drawLooper);
Mike Reed09d94352016-10-31 15:11:04 -0400827
Cary Clark23890a92017-07-27 16:30:51 -0400828 /** Deprecated.
Cary Clark75959392018-02-27 10:22:04 -0500829 (see skbug.com/6259)
Cary Clark50fa3ff2017-07-26 10:15:23 -0400830 */
Cary Clark0418a882017-05-10 09:07:42 -0400831 void setLooper(sk_sp<SkDrawLooper> drawLooper);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000832
Cary Clark50fa3ff2017-07-26 10:15:23 -0400833 /** \enum SkPaint::Align
834 Align adjusts the text relative to the text position.
835 Align affects glyphs drawn with: SkCanvas::drawText, SkCanvas::drawPosText,
836 SkCanvas::drawPosTextH, SkCanvas::drawTextOnPath,
837 SkCanvas::drawTextOnPathHV, SkCanvas::drawTextRSXform, SkCanvas::drawTextBlob,
838 and SkCanvas::drawString;
Cary Clark579985c2017-07-31 11:48:27 -0400839 as well as calls that place text glyphs like getTextWidths() and getTextPath().
Cary Clark50fa3ff2017-07-26 10:15:23 -0400840
841 The text position is set by the font for both horizontal and vertical text.
842 Typically, for horizontal text, the position is to the left side of the glyph on the
Cary Clark23890a92017-07-27 16:30:51 -0400843 base line; and for vertical text, the position is the horizontal center of the glyph
Cary Clark50fa3ff2017-07-26 10:15:23 -0400844 at the caps height.
845
846 Align adjusts the glyph position to center it or move it to abut the position
847 using the metrics returned by the font.
848
849 Align defaults to kLeft_Align.
850 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000851 enum Align {
Cary Clark462505f2018-05-30 09:20:29 -0400852 kLeft_Align, //!< positions glyph by computed font offset
853 kCenter_Align, //!< centers line of glyphs by its width or height
854 kRight_Align, //!< moves lines of glyphs by its width or height
mike@reedtribe.orgddc813b2013-06-08 12:58:19 +0000855 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400856
Cary Clark462505f2018-05-30 09:20:29 -0400857 /** May be used to verify that align is a legal value.
858 */
859 static constexpr int kAlignCount = 3;
reed@google.com9d07fec2011-03-16 20:02:59 +0000860
Cary Clark50fa3ff2017-07-26 10:15:23 -0400861 /** Returns SkPaint::Align.
862 Returns kLeft_Align if SkPaint::Align has not been set.
863
864 @return text placement relative to position
reed@android.com8a1c16f2008-12-17 15:59:43 +0000865 */
reedf59eab22014-07-14 14:39:15 -0700866 Align getTextAlign() const { return (Align)fBitfields.fTextAlign; }
reed@google.com9d07fec2011-03-16 20:02:59 +0000867
Cary Clark50fa3ff2017-07-26 10:15:23 -0400868 /** Sets SkPaint::Align to align.
869 Has no effect if align is an invalid value.
870
871 @param align text placement relative to position
reed@android.com8a1c16f2008-12-17 15:59:43 +0000872 */
873 void setTextAlign(Align align);
874
Cary Clark50fa3ff2017-07-26 10:15:23 -0400875 /** Returns text size in points.
876
877 @return typographic height of text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000878 */
879 SkScalar getTextSize() const { return fTextSize; }
880
Cary Clark50fa3ff2017-07-26 10:15:23 -0400881 /** Sets text size in points.
882 Has no effect if textSize is not greater than or equal to zero.
883
884 @param textSize typographic height of text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000885 */
886 void setTextSize(SkScalar textSize);
887
Cary Clark50fa3ff2017-07-26 10:15:23 -0400888 /** Returns text scale x.
889 Default value is 1.
890
891 @return text horizontal scale
reed@android.com8a1c16f2008-12-17 15:59:43 +0000892 */
893 SkScalar getTextScaleX() const { return fTextScaleX; }
894
Cary Clark50fa3ff2017-07-26 10:15:23 -0400895 /** Sets text scale x.
896 Default value is 1.
897
898 @param scaleX text horizontal scale
reed@android.com8a1c16f2008-12-17 15:59:43 +0000899 */
900 void setTextScaleX(SkScalar scaleX);
901
Cary Clark50fa3ff2017-07-26 10:15:23 -0400902 /** Returns text skew x.
903 Default value is zero.
904
905 @return additional shear in x-axis relative to y-axis
reed@android.com8a1c16f2008-12-17 15:59:43 +0000906 */
907 SkScalar getTextSkewX() const { return fTextSkewX; }
908
Cary Clark50fa3ff2017-07-26 10:15:23 -0400909 /** Sets text skew x.
910 Default value is zero.
911
912 @param skewX additional shear in x-axis relative to y-axis
reed@android.com8a1c16f2008-12-17 15:59:43 +0000913 */
914 void setTextSkewX(SkScalar skewX);
915
Cary Clark50fa3ff2017-07-26 10:15:23 -0400916 /** \enum SkPaint::TextEncoding
Cary Clark8a02b0b2017-09-21 12:28:43 -0400917 TextEncoding determines whether text specifies character codes and their encoded
Cary Clarkcc309eb2017-10-30 11:48:35 -0400918 size, or glyph indices. Characters are encoded as specified by the Unicode standard.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400919
Cary Clark50fa3ff2017-07-26 10:15:23 -0400920 Character codes encoded size are specified by UTF-8, UTF-16, or UTF-32.
Cary Clarkcc309eb2017-10-30 11:48:35 -0400921 All character code formats are able to represent all of Unicode, differing only
922 in the total storage required.
923
924 UTF-8 (RFC 3629) encodes each character as one or more 8-bit bytes.
925
926 UTF-16 (RFC 2781) encodes each character as one or two 16-bit words.
927
928 UTF-32 encodes each character as one 32-bit word.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400929
930 font manager uses font data to convert character code points into glyph indices.
931 A glyph index is a 16-bit word.
932
933 TextEncoding is set to kUTF8_TextEncoding by default.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000934 */
935 enum TextEncoding {
Cary Clark462505f2018-05-30 09:20:29 -0400936 kUTF8_TextEncoding, //!< uses bytes to represent UTF-8 or ASCII
937 kUTF16_TextEncoding, //!< uses two byte words to represent most of Unicode
938 kUTF32_TextEncoding, //!< uses four byte words to represent all of Unicode
939 kGlyphID_TextEncoding, //!< uses two byte words to represent glyph indices
reed@android.com8a1c16f2008-12-17 15:59:43 +0000940 };
reed@google.com9d07fec2011-03-16 20:02:59 +0000941
Cary Clark50fa3ff2017-07-26 10:15:23 -0400942 /** Returns SkPaint::TextEncoding.
943 SkPaint::TextEncoding determines how character code points are mapped to font glyph indices.
944
945 @return one of: kUTF8_TextEncoding, kUTF16_TextEncoding, kUTF32_TextEncoding, or
946 kGlyphID_TextEncoding
947 */
reedf59eab22014-07-14 14:39:15 -0700948 TextEncoding getTextEncoding() const {
949 return (TextEncoding)fBitfields.fTextEncoding;
950 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000951
Cary Clark50fa3ff2017-07-26 10:15:23 -0400952 /** Sets SkPaint::TextEncoding to encoding.
953 SkPaint::TextEncoding determines how character code points are mapped to font glyph indices.
954 Invalid values for encoding are ignored.
955
956 @param encoding one of: kUTF8_TextEncoding, kUTF16_TextEncoding, kUTF32_TextEncoding, or
Cary Clark579985c2017-07-31 11:48:27 -0400957 kGlyphID_TextEncoding
Cary Clark50fa3ff2017-07-26 10:15:23 -0400958 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000959 void setTextEncoding(TextEncoding encoding);
960
Cary Clark50fa3ff2017-07-26 10:15:23 -0400961 /** \struct SkPaint::FontMetrics
Cary Clark579985c2017-07-31 11:48:27 -0400962 FontMetrics is filled out by getFontMetrics(). FontMetrics contents reflect the values
Cary Clark50fa3ff2017-07-26 10:15:23 -0400963 computed by font manager using SkTypeface. Values are set to zero if they are
Cary Clarkb7da7232017-09-01 13:49:54 -0400964 not available.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400965
Ben Wagnere5806492017-11-09 12:08:31 -0500966 All vertical values relative to the baseline are given y-down. As such, zero is on the
967 baseline, negative values are above the baseline, and positive values are below the
968 baseline.
969
Cary Clark50fa3ff2017-07-26 10:15:23 -0400970 fUnderlineThickness and fUnderlinePosition have a bit set in fFlags if their values
971 are valid, since their value may be zero.
972
973 fStrikeoutThickness and fStrikeoutPosition have a bit set in fFlags if their values
974 are valid, since their value may be zero.
975 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000976 struct FontMetrics {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400977
Cary Clarkcc309eb2017-10-30 11:48:35 -0400978 /** \enum SkPaint::FontMetrics::FontMetricsFlags
979 FontMetricsFlags are set in fFlags when underline and strikeout metrics are valid;
980 the underline or strikeout metric may be valid and zero.
981 Fonts with embedded bitmaps may not have valid underline or strikeout metrics.
982 */
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +0000983 enum FontMetricsFlags {
Cary Clark462505f2018-05-30 09:20:29 -0400984 kUnderlineThicknessIsValid_Flag = 1 << 0, //!< set if fUnderlineThickness is valid
985 kUnderlinePositionIsValid_Flag = 1 << 1, //!< set if fUnderlinePosition is valid
986 kStrikeoutThicknessIsValid_Flag = 1 << 2, //!< set if fStrikeoutThickness is valid
987 kStrikeoutPositionIsValid_Flag = 1 << 3, //!< set if fStrikeoutPosition is valid
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +0000988 };
989
Cary Clark462505f2018-05-30 09:20:29 -0400990 uint32_t fFlags; //!< is set to FontMetricsFlags when metrics are valid
991 SkScalar fTop; //!< extent above baseline
992 SkScalar fAscent; //!< distance to reserve above baseline
993 SkScalar fDescent; //!< distance to reserve below baseline
994 SkScalar fBottom; //!< extent below baseline
995 SkScalar fLeading; //!< distance to add between lines
996 SkScalar fAvgCharWidth; //!< average character width
997 SkScalar fMaxCharWidth; //!< maximum character width
998 SkScalar fXMin; //!< minimum x
999 SkScalar fXMax; //!< maximum x
1000 SkScalar fXHeight; //!< height of lower-case 'x'
1001 SkScalar fCapHeight; //!< height of an upper-case letter
1002 SkScalar fUnderlineThickness; //!< underline thickness
1003 SkScalar fUnderlinePosition; //!< underline position relative to baseline
1004 SkScalar fStrikeoutThickness; //!< strikeout thickness
1005 SkScalar fStrikeoutPosition; //!< strikeout position relative to baseline
Cary Clark50fa3ff2017-07-26 10:15:23 -04001006
1007 /** If SkPaint::FontMetrics has a valid underline thickness, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001008 thickness to that value. If the underline thickness is not valid,
1009 return false, and ignore thickness.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001010
1011 @param thickness storage for underline width
1012 @return true if font specifies underline width
1013 */
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001014 bool hasUnderlineThickness(SkScalar* thickness) const {
Ben Wagner3318da52017-03-23 14:01:22 -04001015 if (SkToBool(fFlags & kUnderlineThicknessIsValid_Flag)) {
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001016 *thickness = fUnderlineThickness;
1017 return true;
1018 }
1019 return false;
1020 }
1021
Cary Clark50fa3ff2017-07-26 10:15:23 -04001022 /** If SkPaint::FontMetrics has a valid underline position, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001023 position to that value. If the underline position is not valid,
1024 return false, and ignore position.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001025
1026 @param position storage for underline position
1027 @return true if font specifies underline position
1028 */
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001029 bool hasUnderlinePosition(SkScalar* position) const {
1030 if (SkToBool(fFlags & kUnderlinePositionIsValid_Flag)) {
1031 *position = fUnderlinePosition;
1032 return true;
1033 }
1034 return false;
1035 }
1036
Cary Clark50fa3ff2017-07-26 10:15:23 -04001037 /** If SkPaint::FontMetrics has a valid strikeout thickness, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001038 thickness to that value. If the underline thickness is not valid,
1039 return false, and ignore thickness.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001040
1041 @param thickness storage for strikeout width
1042 @return true if font specifies strikeout width
1043 */
Ben Wagner219f3622017-07-17 15:32:25 -04001044 bool hasStrikeoutThickness(SkScalar* thickness) const {
1045 if (SkToBool(fFlags & kStrikeoutThicknessIsValid_Flag)) {
1046 *thickness = fStrikeoutThickness;
1047 return true;
1048 }
1049 return false;
1050 }
1051
Cary Clark50fa3ff2017-07-26 10:15:23 -04001052 /** If SkPaint::FontMetrics has a valid strikeout position, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001053 position to that value. If the underline position is not valid,
1054 return false, and ignore position.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001055
1056 @param position storage for strikeout position
1057 @return true if font specifies strikeout position
1058 */
Ben Wagner219f3622017-07-17 15:32:25 -04001059 bool hasStrikeoutPosition(SkScalar* position) const {
1060 if (SkToBool(fFlags & kStrikeoutPositionIsValid_Flag)) {
1061 *position = fStrikeoutPosition;
1062 return true;
1063 }
1064 return false;
1065 }
Cary Clark50fa3ff2017-07-26 10:15:23 -04001066
reed@android.com8a1c16f2008-12-17 15:59:43 +00001067 };
reed@google.com9d07fec2011-03-16 20:02:59 +00001068
Cary Clark50fa3ff2017-07-26 10:15:23 -04001069 /** Returns SkPaint::FontMetrics associated with SkTypeface.
1070 The return value is the recommended spacing between lines: the sum of metrics
1071 descent, ascent, and leading.
1072 If metrics is not nullptr, SkPaint::FontMetrics is copied to metrics.
1073 Results are scaled by text size but does not take into account
1074 dimensions required by text scale x, text skew x, fake bold,
1075 style stroke, and SkPathEffect.
1076 Results can be additionally scaled by scale; a scale of zero
1077 is ignored.
1078
1079 @param metrics storage for SkPaint::FontMetrics from SkTypeface; may be nullptr
1080 @param scale additional multiplier for returned values
1081 @return recommended spacing between lines
reed@android.com8a1c16f2008-12-17 15:59:43 +00001082 */
1083 SkScalar getFontMetrics(FontMetrics* metrics, SkScalar scale = 0) const;
reed@google.com9d07fec2011-03-16 20:02:59 +00001084
Cary Clark50fa3ff2017-07-26 10:15:23 -04001085 /** Returns the recommended spacing between lines: the sum of metrics
1086 descent, ascent, and leading.
1087 Result is scaled by text size but does not take into account
1088 dimensions required by stroking and SkPathEffect.
Cary Clark579985c2017-07-31 11:48:27 -04001089 Returns the same result as getFontMetrics().
Cary Clark50fa3ff2017-07-26 10:15:23 -04001090
1091 @return recommended spacing between lines
reed@android.com8a1c16f2008-12-17 15:59:43 +00001092 */
Ben Wagnera93a14a2017-08-28 10:34:05 -04001093 SkScalar getFontSpacing() const { return this->getFontMetrics(nullptr, 0); }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001094
Cary Clark50fa3ff2017-07-26 10:15:23 -04001095 /** Converts text into glyph indices.
1096 Returns the number of glyph indices represented by text.
1097 SkPaint::TextEncoding specifies how text represents characters or glyphs.
1098 glyphs may be nullptr, to compute the glyph count.
1099
Cary Clarkcc309eb2017-10-30 11:48:35 -04001100 Does not check text for valid character codes or valid glyph indices.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001101
Cary Clark579985c2017-07-31 11:48:27 -04001102 If byteLength equals zero, returns zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001103 If byteLength includes a partial character, the partial character is ignored.
1104
1105 If SkPaint::TextEncoding is kUTF8_TextEncoding and
1106 text contains an invalid UTF-8 sequence, zero is returned.
1107
Cary Clarkb7da7232017-09-01 13:49:54 -04001108 @param text character storage encoded with SkPaint::TextEncoding
Cary Clark50fa3ff2017-07-26 10:15:23 -04001109 @param byteLength length of character storage in bytes
1110 @param glyphs storage for glyph indices; may be nullptr
1111 @return number of glyphs represented by text of length byteLength
reed@android.com8a1c16f2008-12-17 15:59:43 +00001112 */
1113 int textToGlyphs(const void* text, size_t byteLength,
halcanaryd0e95a52016-07-25 07:18:12 -07001114 SkGlyphID glyphs[]) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001115
Cary Clark50fa3ff2017-07-26 10:15:23 -04001116 /** Returns true if all text corresponds to a non-zero glyph index.
1117 Returns false if any characters in text are not supported in
1118 SkTypeface.
reed@android.coma5dcaf62010-02-05 17:12:32 +00001119
Cary Clark579985c2017-07-31 11:48:27 -04001120 If SkPaint::TextEncoding is kGlyphID_TextEncoding,
1121 returns true if all glyph indices in text are non-zero;
Cary Clark50fa3ff2017-07-26 10:15:23 -04001122 does not check to see if text contains valid glyph indices for SkTypeface.
1123
Cary Clarkb7da7232017-09-01 13:49:54 -04001124 Returns true if byteLength is zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001125
1126 @param text array of characters or glyphs
1127 @param byteLength number of bytes in text array
1128 @return true if all text corresponds to a non-zero glyph index
1129 */
reed@android.coma5dcaf62010-02-05 17:12:32 +00001130 bool containsText(const void* text, size_t byteLength) const;
1131
Cary Clark50fa3ff2017-07-26 10:15:23 -04001132 /** Converts glyphs into text if possible.
1133 Glyph values without direct Unicode equivalents are mapped to zero.
1134 Uses the SkTypeface, but is unaffected
1135 by SkPaint::TextEncoding; the text values returned are equivalent to kUTF32_TextEncoding.
1136
1137 Only supported on platforms that use FreeType as the font engine.
1138
1139 @param glyphs array of indices into font
1140 @param count length of glyph array
1141 @param text storage for character codes, one per glyph
reed@android.com9d3a9852010-01-08 14:07:42 +00001142 */
halcanaryd0e95a52016-07-25 07:18:12 -07001143 void glyphsToUnichars(const SkGlyphID glyphs[], int count, SkUnichar text[]) const;
reed@android.com9d3a9852010-01-08 14:07:42 +00001144
Cary Clark50fa3ff2017-07-26 10:15:23 -04001145 /** Returns the number of glyphs in text.
1146 Uses SkPaint::TextEncoding to count the glyphs.
Cary Clark579985c2017-07-31 11:48:27 -04001147 Returns the same result as textToGlyphs().
Cary Clark50fa3ff2017-07-26 10:15:23 -04001148
Cary Clarkb7da7232017-09-01 13:49:54 -04001149 @param text character storage encoded with SkPaint::TextEncoding
Cary Clark50fa3ff2017-07-26 10:15:23 -04001150 @param byteLength length of character storage in bytes
1151 @return number of glyphs represented by text of length byteLength
reed@android.com8a1c16f2008-12-17 15:59:43 +00001152 */
Herb Derby90864a22018-05-02 13:43:49 -04001153 int countText(const void* text, size_t byteLength) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001154
Cary Clark50fa3ff2017-07-26 10:15:23 -04001155 /** Returns the advance width of text if kVerticalText_Flag is clear,
1156 and the height of text if kVerticalText_Flag is set.
1157 The advance is the normal distance to move before drawing additional text.
1158 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
1159 and text size, text scale x, text skew x, stroke width, and
1160 SkPathEffect to scale the metrics and bounds.
1161 Returns the bounding box of text if bounds is not nullptr.
1162 The bounding box is computed as if the text was drawn at the origin.
1163
1164 @param text character codes or glyph indices to be measured
1165 @param length number of bytes of text to measure
1166 @param bounds returns bounding box relative to (0, 0) if not nullptr
1167 @return advance width or height
1168 */
reed99ae8812014-08-26 11:30:01 -07001169 SkScalar measureText(const void* text, size_t length, SkRect* bounds) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001170
Cary Clark50fa3ff2017-07-26 10:15:23 -04001171 /** Returns the advance width of text if kVerticalText_Flag is clear,
1172 and the height of text if kVerticalText_Flag is set.
1173 The advance is the normal distance to move before drawing additional text.
1174 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
Cary Clark23890a92017-07-27 16:30:51 -04001175 and text size to scale the metrics.
1176 Does not scale the advance or bounds by fake bold or SkPathEffect.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001177
1178 @param text character codes or glyph indices to be measured
1179 @param length number of bytes of text to measure
Cary Clark50fa3ff2017-07-26 10:15:23 -04001180 @return advance width or height
1181 */
reed@google.com9d07fec2011-03-16 20:02:59 +00001182 SkScalar measureText(const void* text, size_t length) const {
Ben Wagnera93a14a2017-08-28 10:34:05 -04001183 return this->measureText(text, length, nullptr);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001184 }
reed@google.com9d07fec2011-03-16 20:02:59 +00001185
Cary Clark50fa3ff2017-07-26 10:15:23 -04001186 /** Returns the bytes of text that fit within maxWidth.
1187 If kVerticalText_Flag is clear, the text fragment fits if its advance width is less than or
1188 equal to maxWidth.
1189 If kVerticalText_Flag is set, the text fragment fits if its advance height is less than or
1190 equal to maxWidth.
1191 Measures only while the advance is less than or equal to maxWidth.
1192 Returns the advance or the text fragment in measuredWidth if it not nullptr.
1193 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
1194 and text size to scale the metrics.
1195 Does not scale the advance or bounds by fake bold or SkPathEffect.
1196
1197 @param text character codes or glyph indices to be measured
1198 @param length number of bytes of text to measure
1199 @param maxWidth advance limit; text is measured while advance is less than maxWidth
1200 @param measuredWidth returns the width of the text less than or equal to maxWidth
1201 @return bytes of text that fit, always less than or equal to length
1202 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001203 size_t breakText(const void* text, size_t length, SkScalar maxWidth,
Ben Wagnera93a14a2017-08-28 10:34:05 -04001204 SkScalar* measuredWidth = nullptr) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001205
Cary Clark50fa3ff2017-07-26 10:15:23 -04001206 /** Retrieves the advance and bounds for each glyph in text, and returns
1207 the glyph count in text.
1208 Both widths and bounds may be nullptr.
1209 If widths is not nullptr, widths must be an array of glyph count entries.
1210 if bounds is not nullptr, bounds must be an array of glyph count entries.
1211 If kVerticalText_Flag is clear, widths returns the horizontal advance.
1212 If kVerticalText_Flag is set, widths returns the vertical advance.
1213 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
1214 and text size to scale the widths and bounds.
1215 Does not scale the advance by fake bold or SkPathEffect.
Cary Clark23890a92017-07-27 16:30:51 -04001216 Does include fake bold and SkPathEffect in the bounds.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001217
1218 @param text character codes or glyph indices to be measured
1219 @param byteLength number of bytes of text to measure
1220 @param widths returns text advances for each glyph; may be nullptr
1221 @param bounds returns bounds for each glyph relative to (0, 0); may be nullptr
1222 @return glyph count in text
1223 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001224 int getTextWidths(const void* text, size_t byteLength, SkScalar widths[],
Ben Wagnera93a14a2017-08-28 10:34:05 -04001225 SkRect bounds[] = nullptr) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001226
Cary Clark50fa3ff2017-07-26 10:15:23 -04001227 /** Returns the geometry as SkPath equivalent to the drawn text.
1228 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1229 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1230 All of the glyph paths are stored in path.
Cary Clark579985c2017-07-31 11:48:27 -04001231 Uses x, y, and SkPaint::Align to position path.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001232
1233 @param text character codes or glyph indices
1234 @param length number of bytes of text
1235 @param x x-coordinate of the origin of the text
1236 @param y y-coordinate of the origin of the text
1237 @param path geometry of the glyphs
1238 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001239 void getTextPath(const void* text, size_t length, SkScalar x, SkScalar y,
1240 SkPath* path) const;
1241
Cary Clark50fa3ff2017-07-26 10:15:23 -04001242 /** Returns the geometry as SkPath equivalent to the drawn text.
1243 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1244 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1245 All of the glyph paths are stored in path.
1246 Uses pos array and SkPaint::Align to position path.
1247 pos contains a position for each glyph.
1248
1249 @param text character codes or glyph indices
1250 @param length number of bytes of text
1251 @param pos positions of each glyph
1252 @param path geometry of the glyphs
1253 */
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001254 void getPosTextPath(const void* text, size_t length,
reed@google.comca0062e2012-07-20 11:20:32 +00001255 const SkPoint pos[], SkPath* path) const;
1256
Cary Clark50fa3ff2017-07-26 10:15:23 -04001257 /** Returns the number of intervals that intersect bounds.
1258 bounds describes a pair of lines parallel to the text advance.
1259 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1260 the string.
1261 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1262 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1263 Uses x, y, and SkPaint::Align to position intervals.
1264
1265 Pass nullptr for intervals to determine the size of the interval array.
1266
1267 intervals are cached to improve performance for multiple calls.
1268
1269 @param text character codes or glyph indices
1270 @param length number of bytes of text
1271 @param x x-coordinate of the origin of the text
1272 @param y y-coordinate of the origin of the text
1273 @param bounds lower and upper line parallel to the advance
1274 @param intervals returned intersections; may be nullptr
1275 @return number of intersections; may be zero
1276 */
caryclark0449bcf2016-02-09 13:25:45 -08001277 int getTextIntercepts(const void* text, size_t length, SkScalar x, SkScalar y,
1278 const SkScalar bounds[2], SkScalar* intervals) const;
1279
Cary Clark50fa3ff2017-07-26 10:15:23 -04001280 /** Returns the number of intervals that intersect bounds.
1281 bounds describes a pair of lines parallel to the text advance.
1282 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1283 the string.
1284 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1285 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1286 Uses pos array and SkPaint::Align to position intervals.
1287
1288 Pass nullptr for intervals to determine the size of the interval array.
1289
1290 intervals are cached to improve performance for multiple calls.
1291
1292 @param text character codes or glyph indices
1293 @param length number of bytes of text
1294 @param pos positions of each glyph
1295 @param bounds lower and upper line parallel to the advance
1296 @param intervals returned intersections; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -04001297 @return number of intersections; may be zero
Cary Clark50fa3ff2017-07-26 10:15:23 -04001298 */
caryclark0449bcf2016-02-09 13:25:45 -08001299 int getPosTextIntercepts(const void* text, size_t length, const SkPoint pos[],
1300 const SkScalar bounds[2], SkScalar* intervals) const;
1301
Cary Clark50fa3ff2017-07-26 10:15:23 -04001302 /** Returns the number of intervals that intersect bounds.
1303 bounds describes a pair of lines parallel to the text advance.
1304 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1305 the string.
1306 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1307 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1308 Uses xpos array, constY, and SkPaint::Align to position intervals.
1309
1310 Pass nullptr for intervals to determine the size of the interval array.
1311
1312 intervals are cached to improve performance for multiple calls.
1313
1314 @param text character codes or glyph indices
1315 @param length number of bytes of text
1316 @param xpos positions of each glyph in x
1317 @param constY position of each glyph in y
1318 @param bounds lower and upper line parallel to the advance
1319 @param intervals returned intersections; may be nullptr
1320 @return number of intersections; may be zero
1321 */
fmalitaeae6a912016-07-28 09:47:24 -07001322 int getPosTextHIntercepts(const void* text, size_t length, const SkScalar xpos[],
1323 SkScalar constY, const SkScalar bounds[2], SkScalar* intervals) const;
1324
Cary Clark50fa3ff2017-07-26 10:15:23 -04001325 /** Returns the number of intervals that intersect bounds.
1326 bounds describes a pair of lines parallel to the text advance.
1327 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1328 the string.
Cary Clark2823f9f2018-01-03 10:00:34 -05001329 Uses SkTypeface to get the glyph paths,
Cary Clark50fa3ff2017-07-26 10:15:23 -04001330 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
Cary Clarkb7da7232017-09-01 13:49:54 -04001331 Uses run array and SkPaint::Align to position intervals.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001332
Cary Clark2823f9f2018-01-03 10:00:34 -05001333 SkPaint::TextEncoding must be set to SkPaint::kGlyphID_TextEncoding.
1334
Cary Clark50fa3ff2017-07-26 10:15:23 -04001335 Pass nullptr for intervals to determine the size of the interval array.
1336
1337 intervals are cached to improve performance for multiple calls.
1338
Cary Clark8a02b0b2017-09-21 12:28:43 -04001339 @param blob glyphs, positions, and text paint attributes
Cary Clark50fa3ff2017-07-26 10:15:23 -04001340 @param bounds lower and upper line parallel to the advance
1341 @param intervals returned intersections; may be nullptr
1342 @return number of intersections; may be zero
1343 */
fmalitaeae6a912016-07-28 09:47:24 -07001344 int getTextBlobIntercepts(const SkTextBlob* blob, const SkScalar bounds[2],
1345 SkScalar* intervals) const;
1346
Cary Clark50fa3ff2017-07-26 10:15:23 -04001347 /** Returns the union of bounds of all glyphs.
1348 Returned dimensions are computed by font manager from font data,
Cary Clark579985c2017-07-31 11:48:27 -04001349 ignoring SkPaint::Hinting. Includes text size, text scale x,
Cary Clark50fa3ff2017-07-26 10:15:23 -04001350 and text skew x, but not fake bold or SkPathEffect.
1351
1352 If text size is large, text scale x is one, and text skew x is zero,
Cary Clark579985c2017-07-31 11:48:27 -04001353 returns the same bounds as SkPaint::FontMetrics { FontMetrics::fXMin,
Cary Clark50fa3ff2017-07-26 10:15:23 -04001354 FontMetrics::fTop, FontMetrics::fXMax, FontMetrics::fBottom }.
1355
1356 @return union of bounds of all glyphs
1357 */
reed8893e5f2014-12-15 13:27:26 -08001358 SkRect getFontBounds() const;
1359
Cary Clark579985c2017-07-31 11:48:27 -04001360 /** Returns true if SkPaint prevents all drawing;
1361 otherwise, the SkPaint may or may not allow drawing.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001362
Cary Clark462505f2018-05-30 09:20:29 -04001363 Returns true if, for example, SkBlendMode combined with alpha computes a
Cary Clarkb7da7232017-09-01 13:49:54 -04001364 new alpha of zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001365
1366 @return true if SkPaint prevents all drawing
1367 */
reed@google.com632e1a22011-10-06 12:37:00 +00001368 bool nothingToDraw() const;
1369
Cary Clark2823f9f2018-01-03 10:00:34 -05001370 /** (to be made private)
Cary Clark50fa3ff2017-07-26 10:15:23 -04001371 Returns true if SkPaint does not include elements requiring extensive computation
1372 to compute SkBaseDevice bounds of drawn geometry. For instance, SkPaint with SkPathEffect
1373 always returns false.
reed@google.comd5f20792012-05-16 14:15:02 +00001374
Cary Clark50fa3ff2017-07-26 10:15:23 -04001375 @return true if SkPaint allows for fast computation of bounds
1376 */
senorblanco0abdf762015-08-20 11:10:41 -07001377 bool canComputeFastBounds() const;
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001378
Cary Clark2823f9f2018-01-03 10:00:34 -05001379 /** (to be made private)
Cary Clark579985c2017-07-31 11:48:27 -04001380 Only call this if canComputeFastBounds() returned true. This takes a
Cary Clark50fa3ff2017-07-26 10:15:23 -04001381 raw rectangle (the raw bounds of a shape), and adjusts it for stylistic
1382 effects in the paint (e.g. stroking). If needed, it uses the storage
Cary Clarkb7da7232017-09-01 13:49:54 -04001383 parameter. It returns the adjusted bounds that can then be used
Cary Clark50fa3ff2017-07-26 10:15:23 -04001384 for SkCanvas::quickReject tests.
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001385
Cary Clarkb7da7232017-09-01 13:49:54 -04001386 The returned SkRect will either be orig or storage, thus the caller
Cary Clark50fa3ff2017-07-26 10:15:23 -04001387 should not rely on storage being set to the result, but should always
Cary Clarkb7da7232017-09-01 13:49:54 -04001388 use the returned value. It is legal for orig and storage to be the same
1389 SkRect.
Cary Clark462505f2018-05-30 09:20:29 -04001390 For example:
1391 if (!path.isInverseFillType() && paint.canComputeFastBounds()) {
1392 SkRect storage;
1393 if (canvas->quickReject(paint.computeFastBounds(path.getBounds(), &storage))) {
1394 return; // do not draw the path
1395 }
Cary Clark2823f9f2018-01-03 10:00:34 -05001396 }
Cary Clark462505f2018-05-30 09:20:29 -04001397 // draw the path
Cary Clark50fa3ff2017-07-26 10:15:23 -04001398
1399 @param orig geometry modified by SkPaint when drawn
1400 @param storage computed bounds of geometry; may not be nullptr
1401 @return fast computed bounds
1402 */
reed@google.coma584aed2012-05-16 14:06:02 +00001403 const SkRect& computeFastBounds(const SkRect& orig, SkRect* storage) const {
Brian Osman60751d72017-05-12 11:21:36 -04001404 // Things like stroking, etc... will do math on the bounds rect, assuming that it's sorted.
1405 SkASSERT(orig.isSorted());
reed@google.coma584aed2012-05-16 14:06:02 +00001406 SkPaint::Style style = this->getStyle();
1407 // ultra fast-case: filling with no effects that affect geometry
1408 if (kFill_Style == style) {
1409 uintptr_t effects = reinterpret_cast<uintptr_t>(this->getLooper());
1410 effects |= reinterpret_cast<uintptr_t>(this->getMaskFilter());
1411 effects |= reinterpret_cast<uintptr_t>(this->getPathEffect());
senorblanco@chromium.org336d1d72014-01-27 21:03:17 +00001412 effects |= reinterpret_cast<uintptr_t>(this->getImageFilter());
reed@google.coma584aed2012-05-16 14:06:02 +00001413 if (!effects) {
1414 return orig;
1415 }
1416 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001417
reed@google.coma584aed2012-05-16 14:06:02 +00001418 return this->doComputeFastBounds(orig, storage, style);
1419 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001420
Cary Clark2823f9f2018-01-03 10:00:34 -05001421 /** (to be made private)
Cary Clark50fa3ff2017-07-26 10:15:23 -04001422
1423 @param orig geometry modified by SkPaint when drawn
1424 @param storage computed bounds of geometry
1425 @return fast computed bounds
1426 */
reed@google.coma584aed2012-05-16 14:06:02 +00001427 const SkRect& computeFastStrokeBounds(const SkRect& orig,
1428 SkRect* storage) const {
reed@google.com73a02582012-05-16 19:21:12 +00001429 return this->doComputeFastBounds(orig, storage, kStroke_Style);
reed@google.coma584aed2012-05-16 14:06:02 +00001430 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001431
Cary Clark2823f9f2018-01-03 10:00:34 -05001432 /** (to be made private)
Cary Clarkb7da7232017-09-01 13:49:54 -04001433 Computes the bounds, overriding the SkPaint SkPaint::Style. This can be used to
1434 account for additional width required by stroking orig, without
1435 altering SkPaint::Style set to fill.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001436
1437 @param orig geometry modified by SkPaint when drawn
1438 @param storage computed bounds of geometry
1439 @param style overrides SkPaint::Style
1440 @return fast computed bounds
1441 */
reed@google.coma584aed2012-05-16 14:06:02 +00001442 const SkRect& doComputeFastBounds(const SkRect& orig, SkRect* storage,
Cary Clark0418a882017-05-10 09:07:42 -04001443 Style style) const;
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001444
Cary Clark32a49102018-05-20 23:15:43 +00001445 /** Creates string representation of SkPaint. The representation is read by
1446 internal debugging tools.
1447
1448 @param str storage for string representation of SkPaint
1449 */
1450 void toString(SkString* str) const;
1451
reed@google.comd5f20792012-05-16 14:15:02 +00001452private:
Cary Clark0418a882017-05-10 09:07:42 -04001453 typedef const SkGlyph& (*GlyphCacheProc)(SkGlyphCache*, const char**);
1454
reeda5ab9ec2016-03-06 18:10:48 -08001455 sk_sp<SkTypeface> fTypeface;
1456 sk_sp<SkPathEffect> fPathEffect;
1457 sk_sp<SkShader> fShader;
reeda5ab9ec2016-03-06 18:10:48 -08001458 sk_sp<SkMaskFilter> fMaskFilter;
1459 sk_sp<SkColorFilter> fColorFilter;
reed46f2d0a2016-09-11 05:40:31 -07001460 sk_sp<SkDrawLooper> fDrawLooper;
reeda5ab9ec2016-03-06 18:10:48 -08001461 sk_sp<SkImageFilter> fImageFilter;
reed@google.comd5f20792012-05-16 14:15:02 +00001462
commit-bot@chromium.orge8807f42014-03-24 23:03:11 +00001463 SkScalar fTextSize;
1464 SkScalar fTextScaleX;
1465 SkScalar fTextSkewX;
reed@google.comd5f20792012-05-16 14:15:02 +00001466 SkColor fColor;
1467 SkScalar fWidth;
1468 SkScalar fMiterLimit;
Mike Reed71fecc32016-11-18 17:19:54 -05001469 uint32_t fBlendMode; // just need 5-6 bits
commit-bot@chromium.orgaca1c012014-02-21 18:18:05 +00001470 union {
1471 struct {
1472 // all of these bitfields should add up to 32
1473 unsigned fFlags : 16;
1474 unsigned fTextAlign : 2;
1475 unsigned fCapType : 2;
1476 unsigned fJoinType : 2;
1477 unsigned fStyle : 2;
1478 unsigned fTextEncoding : 2; // 3 values
1479 unsigned fHinting : 2;
reedf803da12015-01-23 05:58:07 -08001480 unsigned fFilterQuality : 2;
commit-bot@chromium.org85faf502014-04-16 12:58:02 +00001481 //unsigned fFreeBits : 2;
reedf59eab22014-07-14 14:39:15 -07001482 } fBitfields;
1483 uint32_t fBitfieldsUInt;
commit-bot@chromium.orgaca1c012014-02-21 18:18:05 +00001484 };
commit-bot@chromium.orge8807f42014-03-24 23:03:11 +00001485
robertphillipse34f17d2016-07-19 07:59:22 -07001486 static GlyphCacheProc GetGlyphCacheProc(TextEncoding encoding,
robertphillipse34f17d2016-07-19 07:59:22 -07001487 bool needFullMetrics);
reed@google.comd5f20792012-05-16 14:15:02 +00001488
1489 SkScalar measure_text(SkGlyphCache*, const char* text, size_t length,
1490 int* count, SkRect* bounds) const;
1491
joshualitt9e36c1a2015-04-14 12:17:27 -07001492 /*
1493 * The luminance color is used to determine which Gamma Canonical color to map to. This is
1494 * really only used by backends which want to cache glyph masks, and need some way to know if
1495 * they need to generate new masks based off a given color.
1496 */
1497 SkColor computeLuminanceColor() const;
1498
Cary Clarkd98f78c2018-04-26 08:32:37 -04001499 /* This is the size we use when we ask for a glyph's path. We then
1500 * post-transform it as we draw to match the request.
1501 * This is done to try to re-use cache entries for the path.
1502 *
1503 * This value is somewhat arbitrary. In theory, it could be 1, since
1504 * we store paths as floats. However, we get the path from the font
1505 * scaler, and it may represent its paths as fixed-point (or 26.6),
1506 * so we shouldn't ask for something too big (might overflow 16.16)
1507 * or too small (underflow 26.6).
1508 *
1509 * This value could track kMaxSizeForGlyphCache, assuming the above
1510 * constraints, but since we ask for unhinted paths, the two values
1511 * need not match per-se.
1512 */
1513 static constexpr int kCanonicalTextSizeForPaths = 64;
reed@google.comed43dff2013-06-04 16:56:27 +00001514
Jim Van Verthc65b65d2018-01-16 16:26:35 -05001515 static bool TooBigToUseCache(const SkMatrix& ctm, const SkMatrix& textM, SkScalar maxLimit);
reed@google.comed43dff2013-06-04 16:56:27 +00001516
reed@google.comed43dff2013-06-04 16:56:27 +00001517 // Set flags/hinting/textSize up to use for drawing text as paths.
1518 // Returns scale factor to restore the original textSize, since will will
1519 // have change it to kCanonicalTextSizeForPaths.
1520 SkScalar setupForAsPaths();
1521
Jim Van Verthc65b65d2018-01-16 16:26:35 -05001522 static SkScalar MaxCacheSize2(SkScalar maxLimit);
reed@google.comed43dff2013-06-04 16:56:27 +00001523
Herb Derby980a48d2018-01-23 13:39:21 -05001524 friend class GrAtlasTextBlob;
Herb Derby26cbe512018-05-24 14:39:01 -04001525 friend class GrTextContext;
Herb Derby980a48d2018-01-23 13:39:21 -05001526 friend class GrGLPathRendering;
1527 friend class GrPathRendering;
Herb Derby980a48d2018-01-23 13:39:21 -05001528 friend class GrTextUtils;
jvanverth2d2a68c2014-06-10 06:42:56 -07001529 friend class SkAutoGlyphCacheNoGamma;
Herb Derby980a48d2018-01-23 13:39:21 -05001530 friend class SkCanonicalizePaint;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001531 friend class SkCanvas;
1532 friend class SkDraw;
Cary Clark60ca8672018-03-06 15:09:27 -05001533 friend class SkPaintPriv;
vandebo@chromium.org28be72b2010-11-11 21:37:00 +00001534 friend class SkPDFDevice;
Herb Derby980a48d2018-01-23 13:39:21 -05001535 friend class SkScalerContext; // for computeLuminanceColor()
caryclark0449bcf2016-02-09 13:25:45 -08001536 friend class SkTextBaseIter;
Khushal51371a42018-05-17 10:41:40 -07001537 friend class SkTextBlobCacheDiffCanvas;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001538};
1539
reed@android.com8a1c16f2008-12-17 15:59:43 +00001540#endif