blob: 8cc8733c274b320a26347c47ff651f4fd36c52c2 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00006 */
7
8#ifndef SkPaint_DEFINED
9#define SkPaint_DEFINED
10
reed374772b2016-10-05 17:33:02 -070011#include "SkBlendMode.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000012#include "SkColor.h"
reedf803da12015-01-23 05:58:07 -080013#include "SkFilterQuality.h"
reed@google.comed43dff2013-06-04 16:56:27 +000014#include "SkMatrix.h"
Mike Reed71fecc32016-11-18 17:19:54 -050015#include "SkRefCnt.h"
reed@android.coma0f5d152009-06-22 17:38:10 +000016
joshualitt2b6acb42015-04-01 11:30:27 -070017class SkAutoDescriptor;
reed@android.com8a1c16f2008-12-17 15:59:43 +000018class SkColorFilter;
joshualittfd450792015-03-13 08:38:43 -070019class SkData;
reed@android.com8a1c16f2008-12-17 15:59:43 +000020class SkDescriptor;
senorblanco0abdf762015-08-20 11:10:41 -070021class SkDrawLooper;
herbb69d0e02015-02-25 06:47:06 -080022class SkGlyph;
reed@android.com8a1c16f2008-12-17 15:59:43 +000023struct SkRect;
24class SkGlyphCache;
reed@google.com15356a62011-11-03 19:29:08 +000025class SkImageFilter;
reed@android.com8a1c16f2008-12-17 15:59:43 +000026class SkMaskFilter;
reed@android.com8a1c16f2008-12-17 15:59:43 +000027class SkPath;
28class SkPathEffect;
djsollen@google.comc73dd5c2012-08-07 15:54:32 +000029struct SkPoint;
reed@android.com8a1c16f2008-12-17 15:59:43 +000030class SkShader;
robertphillipsfcf78292015-06-19 11:49:52 -070031class SkSurfaceProps;
fmalitaeae6a912016-07-28 09:47:24 -070032class SkTextBlob;
reed@android.com8a1c16f2008-12-17 15:59:43 +000033class SkTypeface;
reed@android.com8a1c16f2008-12-17 15:59:43 +000034
reed@android.com8a1c16f2008-12-17 15:59:43 +000035/** \class SkPaint
Cary Clark50fa3ff2017-07-26 10:15:23 -040036 SkPaint controls options applied when drawing and measuring. SkPaint collects all
37 options outside of the SkCanvas clip and SkCanvas matrix.
reed@android.com8a1c16f2008-12-17 15:59:43 +000038
Cary Clark50fa3ff2017-07-26 10:15:23 -040039 Various options apply to text, strokes and fills, and images.
40
41 Some options may not be implemented on all platforms; in these cases, setting
42 the option has no effect. Some options are conveniences that duplicate SkCanvas
43 functionality; for instance, text size is identical to matrix scale.
44
45 SkPaint options are rarely exclusive; each option modifies a stage of the drawing
Cary Clark23890a92017-07-27 16:30:51 -040046 pipeline and multiple pipeline stages may be affected by a single SkPaint.
Cary Clark50fa3ff2017-07-26 10:15:23 -040047
Cary Clark23890a92017-07-27 16:30:51 -040048 SkPaint collects effects and filters that describe single-pass and multiple-pass
Cary Clark50fa3ff2017-07-26 10:15:23 -040049 algorithms that alter the drawing geometry, color, and transparency. For instance,
50 SkPaint does not directly implement dashing or blur, but contains the objects that do so.
51
52 The objects contained by SkPaint are opaque, and cannot be edited outside of the SkPaint
53 to affect it. The implementation is free to defer computations associated with the
54 SkPaint, or ignore them altogether. For instance, some GPU implementations draw all
Cary Clarkb7da7232017-09-01 13:49:54 -040055 SkPath geometries with anti-aliasing, regardless of how SkPaint::kAntiAlias_Flag
56 is set in SkPaint.
Cary Clark50fa3ff2017-07-26 10:15:23 -040057
58 SkPaint describes a single color, a single font, a single image quality, and so on.
59 Multiple colors are drawn either by using multiple paints or with objects like
60 SkShader attached to SkPaint.
reed@android.com8a1c16f2008-12-17 15:59:43 +000061*/
ctguil@chromium.org7ffb1b22011-03-15 21:27:08 +000062class SK_API SkPaint {
reed@android.com8a1c16f2008-12-17 15:59:43 +000063public:
Cary Clark50fa3ff2017-07-26 10:15:23 -040064
65 /** Constructs SkPaint with default values.
66
67 @return default initialized SkPaint
68 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000069 SkPaint();
Cary Clark50fa3ff2017-07-26 10:15:23 -040070
71 /** Makes a shallow copy of SkPaint. SkTypeface, SkPathEffect, SkShader,
Mike Reed8ad91a92018-01-19 19:09:32 -050072 SkMaskFilter, SkColorFilter, SkDrawLooper, and SkImageFilter are shared
Cary Clarkb7da7232017-09-01 13:49:54 -040073 between the original paint and the copy. Objects containing SkRefCnt increment
74 their references by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -040075
Mike Reed8ad91a92018-01-19 19:09:32 -050076 The referenced objects SkPathEffect, SkShader, SkMaskFilter, SkColorFilter,
Cary Clark50fa3ff2017-07-26 10:15:23 -040077 SkDrawLooper, and SkImageFilter cannot be modified after they are created.
78 This prevents objects with SkRefCnt from being modified once SkPaint refers to them.
79
80 @param paint original to copy
81 @return shallow copy of paint
82 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000083 SkPaint(const SkPaint& paint);
Cary Clark50fa3ff2017-07-26 10:15:23 -040084
Cary Clark8a02b0b2017-09-21 12:28:43 -040085 /** Implements a move constructor to avoid increasing the reference counts
Cary Clark50fa3ff2017-07-26 10:15:23 -040086 of objects referenced by the paint.
87
88 After the call, paint is undefined, and can be safely destructed.
89
90 @param paint original to move
91 @return content of paint
92 */
bungemanccce0e02016-02-07 14:37:23 -080093 SkPaint(SkPaint&& paint);
Cary Clark50fa3ff2017-07-26 10:15:23 -040094
95 /** Decreases SkPaint SkRefCnt of owned objects: SkTypeface, SkPathEffect, SkShader,
Mike Reed8ad91a92018-01-19 19:09:32 -050096 SkMaskFilter, SkColorFilter, SkDrawLooper, and SkImageFilter. If the
Cary Clarkb7da7232017-09-01 13:49:54 -040097 objects containing SkRefCnt go to zero, they are deleted.
Cary Clark50fa3ff2017-07-26 10:15:23 -040098 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000099 ~SkPaint();
100
Cary Clark50fa3ff2017-07-26 10:15:23 -0400101 /** Makes a shallow copy of SkPaint. SkTypeface, SkPathEffect, SkShader,
Mike Reed8ad91a92018-01-19 19:09:32 -0500102 SkMaskFilter, SkColorFilter, SkDrawLooper, and SkImageFilter are shared
Cary Clarkb7da7232017-09-01 13:49:54 -0400103 between the original paint and the copy. Objects containing SkRefCnt in the
Cary Clark50fa3ff2017-07-26 10:15:23 -0400104 prior destination are decreased by one, and the referenced objects are deleted if the
Cary Clarkb7da7232017-09-01 13:49:54 -0400105 resulting count is zero. Objects containing SkRefCnt in the parameter paint
106 are increased by one. paint is unmodified.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400107
108 @param paint original to copy
109 @return content of paint
110 */
Cary Clark0418a882017-05-10 09:07:42 -0400111 SkPaint& operator=(const SkPaint& paint);
Cary Clark50fa3ff2017-07-26 10:15:23 -0400112
Cary Clark8a02b0b2017-09-21 12:28:43 -0400113 /** Moves the paint to avoid increasing the reference counts
Cary Clarkb7da7232017-09-01 13:49:54 -0400114 of objects referenced by the paint parameter. Objects containing SkRefCnt in the
115 prior destination are decreased by one; those objects are deleted if the resulting count
116 is zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400117
118 After the call, paint is undefined, and can be safely destructed.
119
120 @param paint original to move
121 @return content of paint
122 */
Cary Clark0418a882017-05-10 09:07:42 -0400123 SkPaint& operator=(SkPaint&& paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000124
Cary Clark50fa3ff2017-07-26 10:15:23 -0400125 /** Compares a and b, and returns true if a and b are equivalent. May return false
Mike Reed8ad91a92018-01-19 19:09:32 -0500126 if SkTypeface, SkPathEffect, SkShader, SkMaskFilter, SkColorFilter,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400127 SkDrawLooper, or SkImageFilter have identical contents but different pointers.
128
129 @param a SkPaint to compare
130 @param b SkPaint to compare
131 @return true if SkPaint pair are equivalent
mtkleinbc97ef42014-08-25 10:10:47 -0700132 */
robertphillips@google.comb2657412013-08-07 22:36:29 +0000133 SK_API friend bool operator==(const SkPaint& a, const SkPaint& b);
Cary Clark50fa3ff2017-07-26 10:15:23 -0400134
135 /** Compares a and b, and returns true if a and b are not equivalent. May return true
Mike Reed8ad91a92018-01-19 19:09:32 -0500136 if SkTypeface, SkPathEffect, SkShader, SkMaskFilter, SkColorFilter,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400137 SkDrawLooper, or SkImageFilter have identical contents but different pointers.
138
139 @param a SkPaint to compare
140 @param b SkPaint to compare
141 @return true if SkPaint pair are not equivalent
142 */
robertphillips@google.comb2657412013-08-07 22:36:29 +0000143 friend bool operator!=(const SkPaint& a, const SkPaint& b) {
144 return !(a == b);
145 }
146
Cary Clark50fa3ff2017-07-26 10:15:23 -0400147 /** Returns a hash generated from SkPaint values and pointers.
148 Identical hashes guarantee that the paints are
149 equivalent, but differing hashes do not guarantee that the paints have differing
150 contents.
151
152 If operator==(const SkPaint& a, const SkPaint& b) returns true for two paints,
153 their hashes are also equal.
154
155 The hash returned is platform and implementation specific.
156
157 @return a shallow hash
158 */
mtkleinfb1fe4f2014-10-07 09:26:10 -0700159 uint32_t getHash() const;
160
Cary Clarkcc309eb2017-10-30 11:48:35 -0400161 /** Sets all SkPaint contents to their initial values. This is equivalent to replacing
162 SkPaint with the result of SkPaint().
reed@android.com8a1c16f2008-12-17 15:59:43 +0000163 */
164 void reset();
165
Cary Clark50fa3ff2017-07-26 10:15:23 -0400166 /** \enum SkPaint::Hinting
167 Hinting adjusts the glyph outlines so that the shape provides a uniform
168 look at a given point size on font engines that support it. Hinting may have a
169 muted effect or no effect at all depending on the platform.
170
171 The four levels roughly control corresponding features on platforms that use FreeType
172 as the font engine.
agl@chromium.org309485b2009-07-21 17:41:32 +0000173 */
174 enum Hinting {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400175 /** Leaves glyph outlines unchanged from their native representation.
176 With FreeType, this is equivalent to the FT_LOAD_NO_HINTING
177 bit-field constant supplied to FT_Load_Glyph, which indicates that the vector
178 outline being loaded should not be fitted to the pixel grid but simply scaled
179 to 26.6 fractional pixels.
180 */
181 kNo_Hinting = 0,
182
183 /** Modifies glyph outlines minimally to improve constrast.
184 With FreeType, this is equivalent in spirit to the
185 FT_LOAD_TARGET_LIGHT value supplied to FT_Load_Glyph. It chooses a
186 lighter hinting algorithm for non-monochrome modes.
187 Generated glyphs may be fuzzy but better resemble their original shape.
188 */
189 kSlight_Hinting = 1,
190
191 /** Modifies glyph outlines to improve constrast. This is the default.
192 With FreeType, this supplies FT_LOAD_TARGET_NORMAL to FT_Load_Glyph,
193 choosing the default hinting algorithm, which is optimized for standard
194 gray-level rendering.
195 */
196 kNormal_Hinting = 2,
197
198 /** Modifies glyph outlines for maxiumum constrast. With FreeType, this selects
199 FT_LOAD_TARGET_LCD or FT_LOAD_TARGET_LCD_V if kLCDRenderText_Flag is set.
200 FT_LOAD_TARGET_LCD is a variant of FT_LOAD_TARGET_NORMAL optimized for
201 horizontally decimated LCD displays; FT_LOAD_TARGET_LCD_V is a
202 variant of FT_LOAD_TARGET_NORMAL optimized for vertically decimated LCD displays.
203 */
204 kFull_Hinting = 3,
agl@chromium.org309485b2009-07-21 17:41:32 +0000205 };
206
Cary Clark50fa3ff2017-07-26 10:15:23 -0400207 /** Returns level of glyph outline adjustment.
208
209 @return one of: kNo_Hinting, kSlight_Hinting, kNormal_Hinting, kFull_Hinting
210 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000211 Hinting getHinting() const {
reedf59eab22014-07-14 14:39:15 -0700212 return static_cast<Hinting>(fBitfields.fHinting);
agl@chromium.org309485b2009-07-21 17:41:32 +0000213 }
214
Cary Clark50fa3ff2017-07-26 10:15:23 -0400215 /** Sets level of glyph outline adjustment.
216 Does not check for valid values of hintingLevel.
217
218 @param hintingLevel one of: kNo_Hinting, kSlight_Hinting, kNormal_Hinting, kFull_Hinting
219 */
djsollen@google.comf5dbe2f2011-04-15 13:41:26 +0000220 void setHinting(Hinting hintingLevel);
agl@chromium.org309485b2009-07-21 17:41:32 +0000221
Cary Clark50fa3ff2017-07-26 10:15:23 -0400222 /** \enum SkPaint::Flags
223 The bit values stored in Flags.
224 The default value for Flags, normally zero, can be changed at compile time
225 with a custom definition of SkPaintDefaults_Flags.
226 All flags can be read and written explicitly; Flags allows manipulating
227 multiple settings at once.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000228 */
229 enum Flags {
Cary Clark1eace2d2017-07-31 07:52:43 -0400230 kAntiAlias_Flag = 0x01, //!< mask for setting anti-alias
231 kDither_Flag = 0x04, //!< mask for setting dither
Cary Clark50fa3ff2017-07-26 10:15:23 -0400232 kFakeBoldText_Flag = 0x20, //!< mask for setting fake bold
233 kLinearText_Flag = 0x40, //!< mask for setting linear text
234 kSubpixelText_Flag = 0x80, //!< mask for setting subpixel text
235 kDevKernText_Flag = 0x100, //!< mask for setting full hinting spacing
Cary Clark75959392018-02-27 10:22:04 -0500236 kLCDRenderText_Flag = 0x200, //!< mask for setting LCD text
Cary Clark50fa3ff2017-07-26 10:15:23 -0400237 kEmbeddedBitmapText_Flag = 0x400, //!< mask for setting font embedded bitmaps
238 kAutoHinting_Flag = 0x800, //!< mask for setting auto-hinting
239 kVerticalText_Flag = 0x1000, //!< mask for setting vertical text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000240
Cary Clark50fa3ff2017-07-26 10:15:23 -0400241 /** mask of all Flags, including private flags and flags reserved for future use */
242 kAllFlags = 0xFFFF,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000243 };
244
Cary Clark50fa3ff2017-07-26 10:15:23 -0400245 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Mike Reedddbd37e2017-02-21 15:07:44 -0500246 enum ReserveFlags {
Cary Clark75959392018-02-27 10:22:04 -0500247 kUnderlineText_ReserveFlag = 0x08, //!< deprecated
248 kStrikeThruText_ReserveFlag = 0x10, //!< deprecated
Mike Reedddbd37e2017-02-21 15:07:44 -0500249 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400250 #endif
Mike Reedddbd37e2017-02-21 15:07:44 -0500251
Cary Clark50fa3ff2017-07-26 10:15:23 -0400252 /** Returns paint settings described by SkPaint::Flags. Each setting uses one
253 bit, and can be tested with SkPaint::Flags members.
254
255 @return zero, one, or more bits described by SkPaint::Flags
reed@android.com8a1c16f2008-12-17 15:59:43 +0000256 */
reedf59eab22014-07-14 14:39:15 -0700257 uint32_t getFlags() const { return fBitfields.fFlags; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000258
Cary Clark23890a92017-07-27 16:30:51 -0400259 /** Replaces SkPaint::Flags with flags, the union of the SkPaint::Flags members.
260 All SkPaint::Flags members may be cleared, or one or more may be set.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400261
262 @param flags union of SkPaint::Flags for SkPaint
reed@android.com8a1c16f2008-12-17 15:59:43 +0000263 */
264 void setFlags(uint32_t flags);
265
Cary Clark50fa3ff2017-07-26 10:15:23 -0400266 /** If true, pixels on the active edges of SkPath may be drawn with partial transparency.
267
Cary Clark579985c2017-07-31 11:48:27 -0400268 Equivalent to getFlags() masked with kAntiAlias_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400269
270 @return kAntiAlias_Flag state
271 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000272 bool isAntiAlias() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000273 return SkToBool(this->getFlags() & kAntiAlias_Flag);
274 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000275
Cary Clark50fa3ff2017-07-26 10:15:23 -0400276 /** Requests, but does not require, that SkPath edge pixels draw opaque or with
277 partial transparency.
278
279 Sets kAntiAlias_Flag if aa is true.
280 Clears kAntiAlias_Flag if aa is false.
281
282 @param aa setting for kAntiAlias_Flag
283 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000284 void setAntiAlias(bool aa);
reed@google.com9d07fec2011-03-16 20:02:59 +0000285
Cary Clark50fa3ff2017-07-26 10:15:23 -0400286 /** If true, color error may be distributed to smooth color transition.
287
Cary Clark579985c2017-07-31 11:48:27 -0400288 Equivalent to getFlags() masked with kDither_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400289
290 @return kDither_Flag state
291 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000292 bool isDither() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000293 return SkToBool(this->getFlags() & kDither_Flag);
294 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000295
Cary Clark50fa3ff2017-07-26 10:15:23 -0400296 /** Requests, but does not require, to distribute color error.
297
298 Sets kDither_Flag if dither is true.
299 Clears kDither_Flag if dither is false.
300
301 @param dither setting for kDither_Flag
302 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000303 void setDither(bool dither);
reed@google.com9d07fec2011-03-16 20:02:59 +0000304
Cary Clark50fa3ff2017-07-26 10:15:23 -0400305 /** If true, text is converted to SkPath before drawing and measuring.
306
Cary Clark579985c2017-07-31 11:48:27 -0400307 Equivalent to getFlags() masked with kLinearText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400308
309 @return kLinearText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000310 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000311 bool isLinearText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000312 return SkToBool(this->getFlags() & kLinearText_Flag);
313 }
314
Cary Clark50fa3ff2017-07-26 10:15:23 -0400315 /** If true, text is converted to SkPath before drawing and measuring.
316 By default, kLinearText_Flag is clear.
317
318 Sets kLinearText_Flag if linearText is true.
319 Clears kLinearText_Flag if linearText is false.
320
321 @param linearText setting for kLinearText_Flag
reed@android.com8a1c16f2008-12-17 15:59:43 +0000322 */
323 void setLinearText(bool linearText);
324
Cary Clark50fa3ff2017-07-26 10:15:23 -0400325 /** If true, glyphs at different sub-pixel positions may differ on pixel edge coverage.
326
Cary Clark579985c2017-07-31 11:48:27 -0400327 Equivalent to getFlags() masked with kSubpixelText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400328
329 @return kSubpixelText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000330 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000331 bool isSubpixelText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000332 return SkToBool(this->getFlags() & kSubpixelText_Flag);
333 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000334
Cary Clark50fa3ff2017-07-26 10:15:23 -0400335 /** Requests, but does not require, that glyphs respect sub-pixel positioning.
336
337 Sets kSubpixelText_Flag if subpixelText is true.
338 Clears kSubpixelText_Flag if subpixelText is false.
339
340 @param subpixelText setting for kSubpixelText_Flag
341 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000342 void setSubpixelText(bool subpixelText);
agl@chromium.org309485b2009-07-21 17:41:32 +0000343
Cary Clark50fa3ff2017-07-26 10:15:23 -0400344 /** If true, glyphs may use LCD striping to improve glyph edges.
345
346 Returns true if SkPaint::Flags kLCDRenderText_Flag is set.
347
348 @return kLCDRenderText_Flag state
349 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000350 bool isLCDRenderText() const {
agl@chromium.org309485b2009-07-21 17:41:32 +0000351 return SkToBool(this->getFlags() & kLCDRenderText_Flag);
352 }
353
Cary Clark50fa3ff2017-07-26 10:15:23 -0400354 /** Requests, but does not require, that glyphs use LCD striping for glyph edges.
355
356 Sets kLCDRenderText_Flag if lcdText is true.
357 Clears kLCDRenderText_Flag if lcdText is false.
358
359 @param lcdText setting for kLCDRenderText_Flag
360 */
reed@google.com84b437e2011-08-01 12:45:35 +0000361 void setLCDRenderText(bool lcdText);
agl@chromium.org309485b2009-07-21 17:41:32 +0000362
Cary Clark50fa3ff2017-07-26 10:15:23 -0400363 /** If true, font engine may return glyphs from font bitmaps instead of from outlines.
364
Cary Clark579985c2017-07-31 11:48:27 -0400365 Equivalent to getFlags() masked with kEmbeddedBitmapText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400366
367 @return kEmbeddedBitmapText_Flag state
368 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000369 bool isEmbeddedBitmapText() const {
agl@chromium.orge95c91e2010-01-04 18:27:55 +0000370 return SkToBool(this->getFlags() & kEmbeddedBitmapText_Flag);
371 }
372
Cary Clark50fa3ff2017-07-26 10:15:23 -0400373 /** Requests, but does not require, to use bitmaps in fonts instead of outlines.
374
375 Sets kEmbeddedBitmapText_Flag if useEmbeddedBitmapText is true.
376 Clears kEmbeddedBitmapText_Flag if useEmbeddedBitmapText is false.
377
378 @param useEmbeddedBitmapText setting for kEmbeddedBitmapText_Flag
agl@chromium.orge95c91e2010-01-04 18:27:55 +0000379 */
380 void setEmbeddedBitmapText(bool useEmbeddedBitmapText);
381
Cary Clark50fa3ff2017-07-26 10:15:23 -0400382 /** If true, and if SkPaint::Hinting is set to kNormal_Hinting or kFull_Hinting, and if
383 platform uses FreeType as the font manager, instruct the font manager to always hint
Cary Clark1eace2d2017-07-31 07:52:43 -0400384 glyphs.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400385
Cary Clark579985c2017-07-31 11:48:27 -0400386 Equivalent to getFlags() masked with kAutoHinting_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400387
388 @return kAutoHinting_Flag state
389 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000390 bool isAutohinted() const {
agl@chromium.orga2c71cb2010-06-17 20:49:17 +0000391 return SkToBool(this->getFlags() & kAutoHinting_Flag);
392 }
393
Cary Clark50fa3ff2017-07-26 10:15:23 -0400394 /** If SkPaint::Hinting is set to kNormal_Hinting or kFull_Hinting and useAutohinter is set,
Cary Clark1eace2d2017-07-31 07:52:43 -0400395 instruct the font manager to always hint glyphs.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400396 auto-hinting has no effect if SkPaint::Hinting is set to kNo_Hinting or
397 kSlight_Hinting.
398
Cary Clark579985c2017-07-31 11:48:27 -0400399 Only affects platforms that use FreeType as the font manager.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400400
401 Sets kAutoHinting_Flag if useAutohinter is true.
402 Clears kAutoHinting_Flag if useAutohinter is false.
403
404 @param useAutohinter setting for kAutoHinting_Flag
agl@chromium.orga2c71cb2010-06-17 20:49:17 +0000405 */
406 void setAutohinted(bool useAutohinter);
407
Cary Clark50fa3ff2017-07-26 10:15:23 -0400408 /** If true, glyphs are drawn top to bottom instead of left to right.
409
Cary Clark579985c2017-07-31 11:48:27 -0400410 Equivalent to getFlags() masked with kVerticalText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400411
412 @return kVerticalText_Flag state
413 */
reed@google.com830a23e2011-11-10 15:20:49 +0000414 bool isVerticalText() const {
415 return SkToBool(this->getFlags() & kVerticalText_Flag);
416 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000417
Cary Clark50fa3ff2017-07-26 10:15:23 -0400418 /** If true, text advance positions the next glyph below the previous glyph instead of to the
419 right of previous glyph.
420
421 Sets kVerticalText_Flag if vertical is true.
422 Clears kVerticalText_Flag if vertical is false.
423
424 @param verticalText setting for kVerticalText_Flag
425 */
Cary Clark0418a882017-05-10 09:07:42 -0400426 void setVerticalText(bool verticalText);
reed@google.com830a23e2011-11-10 15:20:49 +0000427
Cary Clark50fa3ff2017-07-26 10:15:23 -0400428 /** If true, approximate bold by increasing the stroke width when creating glyph bitmaps
429 from outlines.
430
Cary Clark579985c2017-07-31 11:48:27 -0400431 Equivalent to getFlags() masked with kFakeBoldText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400432
433 @return kFakeBoldText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000434 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000435 bool isFakeBoldText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000436 return SkToBool(this->getFlags() & kFakeBoldText_Flag);
437 }
438
Cary Clarkb7da7232017-09-01 13:49:54 -0400439 /** Use increased stroke width when creating glyph bitmaps to approximate a bold typeface.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400440
441 Sets kFakeBoldText_Flag if fakeBoldText is true.
442 Clears kFakeBoldText_Flag if fakeBoldText is false.
443
444 @param fakeBoldText setting for kFakeBoldText_Flag
reed@android.com8a1c16f2008-12-17 15:59:43 +0000445 */
446 void setFakeBoldText(bool fakeBoldText);
447
Cary Clark50fa3ff2017-07-26 10:15:23 -0400448 /** Returns if character spacing may be adjusted by the hinting difference.
449
Cary Clark579985c2017-07-31 11:48:27 -0400450 Equivalent to getFlags() masked with kDevKernText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400451
452 @return kDevKernText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000453 */
Herb Derbyfcac00f2018-05-01 11:57:56 -0400454 bool isDevKernText() const { return false; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000455
Cary Clark50fa3ff2017-07-26 10:15:23 -0400456 /** Requests, but does not require, to use hinting to adjust glyph spacing.
457
458 Sets kDevKernText_Flag if devKernText is true.
459 Clears kDevKernText_Flag if devKernText is false.
460
461 @param devKernText setting for devKernText
reed@android.com8a1c16f2008-12-17 15:59:43 +0000462 */
Herb Derbyfcac00f2018-05-01 11:57:56 -0400463 void setDevKernText(bool) { }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000464
Cary Clark50fa3ff2017-07-26 10:15:23 -0400465 /** Returns SkFilterQuality, the image filtering level. A lower setting
466 draws faster; a higher setting looks better when the image is scaled.
467
468 @return one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
469 kMedium_SkFilterQuality, kHigh_SkFilterQuality
470 */
reedf803da12015-01-23 05:58:07 -0800471 SkFilterQuality getFilterQuality() const {
472 return (SkFilterQuality)fBitfields.fFilterQuality;
473 }
mtkleinfe81e2d2015-09-09 07:35:42 -0700474
Cary Clark23890a92017-07-27 16:30:51 -0400475 /** Sets SkFilterQuality, the image filtering level. A lower setting
Cary Clark50fa3ff2017-07-26 10:15:23 -0400476 draws faster; a higher setting looks better when the image is scaled.
Cary Clark579985c2017-07-31 11:48:27 -0400477 Does not check to see if quality is valid.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400478
479 @param quality one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
480 kMedium_SkFilterQuality, kHigh_SkFilterQuality
481 */
reedf803da12015-01-23 05:58:07 -0800482 void setFilterQuality(SkFilterQuality quality);
reed@google.comc9683152013-07-18 13:47:01 +0000483
Cary Clark50fa3ff2017-07-26 10:15:23 -0400484 /** \enum SkPaint::Style
Cary Clark23890a92017-07-27 16:30:51 -0400485 Set Style to fill, stroke, or both fill and stroke geometry.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400486 The stroke and fill
487 share all paint attributes; for instance, they are drawn with the same color.
reed@google.com9d07fec2011-03-16 20:02:59 +0000488
Cary Clark50fa3ff2017-07-26 10:15:23 -0400489 Use kStrokeAndFill_Style to avoid hitting the same pixels twice with a stroke draw and
490 a fill draw.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000491 */
492 enum Style {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400493 /** Set to fill geometry.
Cary Clark1eace2d2017-07-31 07:52:43 -0400494 Applies to SkRect, SkRegion, SkRRect, circles, ovals, SkPath, and text.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400495 SkBitmap, SkImage, patches, SkRegion, sprites, and vertices are painted as if
496 kFill_Style is set, and ignore the set Style.
497 The FillType specifies additional rules to fill the area outside the path edge,
498 and to create an unfilled hole inside the shape.
499 Style is set to kFill_Style by default.
500 */
501 kFill_Style,
502
503 /** Set to stroke geometry.
Cary Clarkb7da7232017-09-01 13:49:54 -0400504 Applies to SkRect, SkRegion, SkRRect, arcs, circles, ovals, SkPath, and text.
Cary Clark2823f9f2018-01-03 10:00:34 -0500505 Arcs, lines, and points, are always drawn as if kStroke_Style is set,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400506 and ignore the set Style.
507 The stroke construction is unaffected by the FillType.
508 */
509 kStroke_Style,
510
511 /** Set to stroke and fill geometry.
Cary Clark1eace2d2017-07-31 07:52:43 -0400512 Applies to SkRect, SkRegion, SkRRect, circles, ovals, SkPath, and text.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400513 SkPath is treated as if it is set to SkPath::kWinding_FillType,
514 and the set FillType is ignored.
515 */
516 kStrokeAndFill_Style,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000517 };
518
Cary Clarkd98f78c2018-04-26 08:32:37 -0400519 /** The number of different Style values defined.
520 May be used to verify that Style is a legal value.
521 */
522 static constexpr int kStyleCount = kStrokeAndFill_Style + 1;
Cary Clark50fa3ff2017-07-26 10:15:23 -0400523
524 /** Whether the geometry is filled, stroked, or filled and stroked.
525
526 @return one of:kFill_Style, kStroke_Style, kStrokeAndFill_Style
reed@android.com8a1c16f2008-12-17 15:59:43 +0000527 */
reedf59eab22014-07-14 14:39:15 -0700528 Style getStyle() const { return (Style)fBitfields.fStyle; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000529
Cary Clark50fa3ff2017-07-26 10:15:23 -0400530 /** Sets whether the geometry is filled, stroked, or filled and stroked.
531 Has no effect if style is not a legal SkPaint::Style value.
532
533 @param style one of: kFill_Style, kStroke_Style, kStrokeAndFill_Style
reed@android.com8a1c16f2008-12-17 15:59:43 +0000534 */
535 void setStyle(Style style);
536
Cary Clark50fa3ff2017-07-26 10:15:23 -0400537 /** Retrieves alpha and RGB, unpremultiplied, packed into 32 bits.
538 Use helpers SkColorGetA(), SkColorGetR(), SkColorGetG(), and SkColorGetB() to extract
539 a color component.
540
Cary Clark8a02b0b2017-09-21 12:28:43 -0400541 @return unpremultiplied ARGB
reed@android.com8a1c16f2008-12-17 15:59:43 +0000542 */
543 SkColor getColor() const { return fColor; }
544
Cary Clark50fa3ff2017-07-26 10:15:23 -0400545 /** Sets alpha and RGB used when stroking and filling. The color is a 32-bit value,
Cary Clarkb7da7232017-09-01 13:49:54 -0400546 unpremultiplied, packing 8-bit components for alpha, red, blue, and green.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400547
Cary Clark8a02b0b2017-09-21 12:28:43 -0400548 @param color unpremultiplied ARGB
reed@android.com8a1c16f2008-12-17 15:59:43 +0000549 */
550 void setColor(SkColor color);
551
Cary Clark1eace2d2017-07-31 07:52:43 -0400552 /** Retrieves alpha from the color used when stroking and filling.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400553
Cary Clark8a02b0b2017-09-21 12:28:43 -0400554 @return alpha ranging from zero, fully transparent, to 255, fully opaque
Cary Clark50fa3ff2017-07-26 10:15:23 -0400555 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000556 uint8_t getAlpha() const { return SkToU8(SkColorGetA(fColor)); }
reed@google.com9d07fec2011-03-16 20:02:59 +0000557
Cary Clark50fa3ff2017-07-26 10:15:23 -0400558 /** Replaces alpha, leaving RGB
559 unchanged. An out of range value triggers an assert in the debug
560 build. a is a value from zero to 255.
Cary Clark1eace2d2017-07-31 07:52:43 -0400561 a set to zero makes color fully transparent; a set to 255 makes color
Cary Clark50fa3ff2017-07-26 10:15:23 -0400562 fully opaque.
563
Cary Clark8a02b0b2017-09-21 12:28:43 -0400564 @param a alpha component of color
reed@android.com8a1c16f2008-12-17 15:59:43 +0000565 */
566 void setAlpha(U8CPU a);
567
Cary Clark1eace2d2017-07-31 07:52:43 -0400568 /** Sets color used when drawing solid fills. The color components range from 0 to 255.
Cary Clarkb7da7232017-09-01 13:49:54 -0400569 The color is unpremultiplied; alpha sets the transparency independent of RGB.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400570
Cary Clarkb7da7232017-09-01 13:49:54 -0400571 @param a amount of color alpha, from fully transparent (0) to fully opaque (255)
572 @param r amount of color rgb red, from no red (0) to full red (255)
573 @param g amount of color rgb green, from no green (0) to full green (255)
574 @param b amount of color rgb blue, from no blue (0) to full blue (255)
reed@android.com8a1c16f2008-12-17 15:59:43 +0000575 */
576 void setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b);
577
Cary Clark50fa3ff2017-07-26 10:15:23 -0400578 /** Returns the thickness of the pen used by SkPaint to
579 outline the shape.
580
Cary Clark1eace2d2017-07-31 07:52:43 -0400581 @return zero for hairline, greater than zero for pen thickness
reed@android.com8a1c16f2008-12-17 15:59:43 +0000582 */
583 SkScalar getStrokeWidth() const { return fWidth; }
584
Cary Clark50fa3ff2017-07-26 10:15:23 -0400585 /** Sets the thickness of the pen used by the paint to
586 outline the shape.
587 Has no effect if width is less than zero.
588
Cary Clark1eace2d2017-07-31 07:52:43 -0400589 @param width zero thickness for hairline; greater than zero for pen thickness
reed@android.com8a1c16f2008-12-17 15:59:43 +0000590 */
591 void setStrokeWidth(SkScalar width);
592
Cary Clark50fa3ff2017-07-26 10:15:23 -0400593 /** The limit at which a sharp corner is drawn beveled.
594
595 @return zero and greater miter limit
reed@android.com8a1c16f2008-12-17 15:59:43 +0000596 */
597 SkScalar getStrokeMiter() const { return fMiterLimit; }
598
Cary Clark50fa3ff2017-07-26 10:15:23 -0400599 /** The limit at which a sharp corner is drawn beveled.
600 Valid values are zero and greater.
601 Has no effect if miter is less than zero.
602
603 @param miter zero and greater miter limit
reed@android.com8a1c16f2008-12-17 15:59:43 +0000604 */
605 void setStrokeMiter(SkScalar miter);
606
Cary Clark50fa3ff2017-07-26 10:15:23 -0400607 /** \enum SkPaint::Cap
608 Cap draws at the beginning and end of an open path contour.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000609 */
610 enum Cap {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400611 kButt_Cap, //!< Does not extend the stroke past the beginning or the end.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000612
Cary Clark50fa3ff2017-07-26 10:15:23 -0400613 /** Adds a circle with a diameter equal to stroke width at the beginning
614 and end.
615 */
616 kRound_Cap,
617
618 /** Adds a square with sides equal to stroke width at the beginning
619 and end. The square sides are parallel to the initial and final direction
620 of the stroke.
621 */
622 kSquare_Cap,
623 kLast_Cap = kSquare_Cap, //!< Equivalent to the largest value for Cap.
624
625 /** Equivalent to kButt_Cap.
626 Cap is set to kButt_Cap by default.
627 */
628 kDefault_Cap = kButt_Cap,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000629 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400630
Cary Clark75959392018-02-27 10:22:04 -0500631 /** The number of different SkPaint::Cap values defined.
632 May be used to verify that SkPaint::Cap is a legal value.*/
bsalomona7d85ba2016-07-06 11:54:59 -0700633 static constexpr int kCapCount = kLast_Cap + 1;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000634
Cary Clark50fa3ff2017-07-26 10:15:23 -0400635 /** \enum SkPaint::Join
Cary Clark1eace2d2017-07-31 07:52:43 -0400636 Join specifies how corners are drawn when a shape is stroked. Join
Cary Clark50fa3ff2017-07-26 10:15:23 -0400637 affects the four corners of a stroked rectangle, and the connected segments in a
638 stroked path.
639
640 Choose miter join to draw sharp corners. Choose round join to draw a circle with a
641 radius equal to the stroke width on top of the corner. Choose bevel join to minimally
642 connect the thick strokes.
643
644 The fill path constructed to describe the stroked path respects the join setting but may
645 not contain the actual join. For instance, a fill path constructed with round joins does
646 not necessarily include circles at each connected segment.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000647 */
648 enum Join {
Cary Clark23890a92017-07-27 16:30:51 -0400649 /** Extends the outside corner to the extent allowed by miter limit.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400650 If the extension exceeds miter limit, kBevel_Join is used instead.
651 */
652 kMiter_Join,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000653
Cary Clark50fa3ff2017-07-26 10:15:23 -0400654 /** Adds a circle with a diameter of stroke width at the sharp corner. */
655 kRound_Join,
656 kBevel_Join, //!< Connects the outside edges of the sharp corner.
657 kLast_Join = kBevel_Join, //!< Equivalent to the largest value for Join.
658
659 /** Equivalent to kMiter_Join.
660 Join is set to kMiter_Join by default.
661 */
662 kDefault_Join = kMiter_Join,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000663 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400664
Cary Clark75959392018-02-27 10:22:04 -0500665 /** The number of different SkPaint::Join values defined.
666 May be used to verify that SkPaint::Join is a legal value.*/
bsalomona7d85ba2016-07-06 11:54:59 -0700667 static constexpr int kJoinCount = kLast_Join + 1;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000668
Cary Clark50fa3ff2017-07-26 10:15:23 -0400669 /** The geometry drawn at the beginning and end of strokes.
670
671 @return one of: kButt_Cap, kRound_Cap, kSquare_Cap
reed@android.com8a1c16f2008-12-17 15:59:43 +0000672 */
reedf59eab22014-07-14 14:39:15 -0700673 Cap getStrokeCap() const { return (Cap)fBitfields.fCapType; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000674
Cary Clark50fa3ff2017-07-26 10:15:23 -0400675 /** The geometry drawn at the beginning and end of strokes.
676
677 @param cap one of: kButt_Cap, kRound_Cap, kSquare_Cap;
678 has no effect if cap is not valid
reed@android.com8a1c16f2008-12-17 15:59:43 +0000679 */
680 void setStrokeCap(Cap cap);
681
Cary Clark50fa3ff2017-07-26 10:15:23 -0400682 /** The geometry drawn at the corners of strokes.
683
684 @return one of: kMiter_Join, kRound_Join, kBevel_Join
reed@android.com8a1c16f2008-12-17 15:59:43 +0000685 */
reedf59eab22014-07-14 14:39:15 -0700686 Join getStrokeJoin() const { return (Join)fBitfields.fJoinType; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000687
Cary Clark50fa3ff2017-07-26 10:15:23 -0400688 /** The geometry drawn at the corners of strokes.
689
690 @param join one of: kMiter_Join, kRound_Join, kBevel_Join;
Cary Clark579985c2017-07-31 11:48:27 -0400691 otherwise, has no effect
reed@android.com8a1c16f2008-12-17 15:59:43 +0000692 */
693 void setStrokeJoin(Join join);
694
Cary Clark50fa3ff2017-07-26 10:15:23 -0400695 /** The filled equivalent of the stroked path.
696
697 @param src SkPath read to create a filled version
698 @param dst resulting SkPath; may be the same as src, but may not be nullptr
699 @param cullRect optional limit passed to SkPathEffect
700 @param resScale if > 1, increase precision, else if (0 < res < 1) reduce precision
701 to favor speed and size
Cary Clark1eace2d2017-07-31 07:52:43 -0400702 @return true if the path represents style fill, or false if it represents hairline
Cary Clark50fa3ff2017-07-26 10:15:23 -0400703 */
reed05d90442015-02-12 13:35:52 -0800704 bool getFillPath(const SkPath& src, SkPath* dst, const SkRect* cullRect,
705 SkScalar resScale = 1) const;
706
Cary Clark50fa3ff2017-07-26 10:15:23 -0400707 /** The filled equivalent of the stroked path.
708
Cary Clark23890a92017-07-27 16:30:51 -0400709 Replaces dst with the src path modified by SkPathEffect and style stroke.
710 SkPathEffect, if any, is not culled. stroke width is created with default precision.
711
712 @param src SkPath read to create a filled version
713 @param dst resulting SkPath dst may be the same as src, but may not be nullptr
Cary Clark1eace2d2017-07-31 07:52:43 -0400714 @return true if the path represents style fill, or false if it represents hairline
Cary Clark50fa3ff2017-07-26 10:15:23 -0400715 */
reed05d90442015-02-12 13:35:52 -0800716 bool getFillPath(const SkPath& src, SkPath* dst) const {
Ben Wagnera93a14a2017-08-28 10:34:05 -0400717 return this->getFillPath(src, dst, nullptr, 1);
reed05d90442015-02-12 13:35:52 -0800718 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000719
Cary Clark50fa3ff2017-07-26 10:15:23 -0400720 /** Optional colors used when filling a path, such as a gradient.
721
722 Does not alter SkShader SkRefCnt.
723
724 @return SkShader if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000725 */
reeda5ab9ec2016-03-06 18:10:48 -0800726 SkShader* getShader() const { return fShader.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400727
728 /** Optional colors used when filling a path, such as a gradient.
729
730 Increases SkShader SkRefCnt by one.
731
732 @return SkShader if previously set, nullptr otherwise
733 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500734 sk_sp<SkShader> refShader() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000735
Cary Clark50fa3ff2017-07-26 10:15:23 -0400736 /** Optional colors used when filling a path, such as a gradient.
737
Cary Clark8a02b0b2017-09-21 12:28:43 -0400738 Sets SkShader to shader, decreasing SkRefCnt of the previous SkShader.
739 Increments shader SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400740
Cary Clark1eace2d2017-07-31 07:52:43 -0400741 @param shader how geometry is filled with color; if nullptr, color is used instead
Cary Clark50fa3ff2017-07-26 10:15:23 -0400742 */
Cary Clark0418a882017-05-10 09:07:42 -0400743 void setShader(sk_sp<SkShader> shader);
reed@google.com9d07fec2011-03-16 20:02:59 +0000744
Cary Clark50fa3ff2017-07-26 10:15:23 -0400745 /** Returns SkColorFilter if set, or nullptr.
746 Does not alter SkColorFilter SkRefCnt.
747
748 @return SkColorFilter if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000749 */
reeda5ab9ec2016-03-06 18:10:48 -0800750 SkColorFilter* getColorFilter() const { return fColorFilter.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400751
752 /** Returns SkColorFilter if set, or nullptr.
753 Increases SkColorFilter SkRefCnt by one.
754
755 @return SkColorFilter if set, or nullptr
756 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500757 sk_sp<SkColorFilter> refColorFilter() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000758
Cary Clark8a02b0b2017-09-21 12:28:43 -0400759 /** Sets SkColorFilter to filter, decreasing SkRefCnt of the previous
760 SkColorFilter. Pass nullptr to clear SkColorFilter.
761
762 Increments filter SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400763
764 @param colorFilter SkColorFilter to apply to subsequent draw
reed@android.com8a1c16f2008-12-17 15:59:43 +0000765 */
Cary Clark0418a882017-05-10 09:07:42 -0400766 void setColorFilter(sk_sp<SkColorFilter> colorFilter);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000767
Cary Clark50fa3ff2017-07-26 10:15:23 -0400768 /** Returns SkBlendMode.
Cary Clark579985c2017-07-31 11:48:27 -0400769 By default, returns SkBlendMode::kSrcOver.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400770
771 @return mode used to combine source color with destination color
772 */
reed374772b2016-10-05 17:33:02 -0700773 SkBlendMode getBlendMode() const { return (SkBlendMode)fBlendMode; }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400774
775 /** Returns true if SkBlendMode is SkBlendMode::kSrcOver, the default.
776
777 @return true if SkBlendMode is SkBlendMode::kSrcOver
778 */
reed374772b2016-10-05 17:33:02 -0700779 bool isSrcOver() const { return (SkBlendMode)fBlendMode == SkBlendMode::kSrcOver; }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400780
781 /** Sets SkBlendMode to mode.
782 Does not check for valid input.
783
784 @param mode SkBlendMode used to combine source color and destination
785 */
reed374772b2016-10-05 17:33:02 -0700786 void setBlendMode(SkBlendMode mode) { fBlendMode = (unsigned)mode; }
reed@android.coma0f5d152009-06-22 17:38:10 +0000787
Cary Clark50fa3ff2017-07-26 10:15:23 -0400788 /** Returns SkPathEffect if set, or nullptr.
789 Does not alter SkPathEffect SkRefCnt.
790
791 @return SkPathEffect if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000792 */
reeda5ab9ec2016-03-06 18:10:48 -0800793 SkPathEffect* getPathEffect() const { return fPathEffect.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400794
795 /** Returns SkPathEffect if set, or nullptr.
796 Increases SkPathEffect SkRefCnt by one.
797
798 @return SkPathEffect if previously set, nullptr otherwise
799 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500800 sk_sp<SkPathEffect> refPathEffect() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000801
Cary Clark8a02b0b2017-09-21 12:28:43 -0400802 /** Sets SkPathEffect to pathEffect, decreasing SkRefCnt of the previous
803 SkPathEffect. Pass nullptr to leave the path geometry unaltered.
804
805 Increments pathEffect SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400806
807 @param pathEffect replace SkPath with a modification when drawn
reed@android.com8a1c16f2008-12-17 15:59:43 +0000808 */
Cary Clark0418a882017-05-10 09:07:42 -0400809 void setPathEffect(sk_sp<SkPathEffect> pathEffect);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000810
Cary Clark50fa3ff2017-07-26 10:15:23 -0400811 /** Returns SkMaskFilter if set, or nullptr.
812 Does not alter SkMaskFilter SkRefCnt.
813
814 @return SkMaskFilter if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000815 */
reeda5ab9ec2016-03-06 18:10:48 -0800816 SkMaskFilter* getMaskFilter() const { return fMaskFilter.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400817
818 /** Returns SkMaskFilter if set, or nullptr.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400819
Cary Clark50fa3ff2017-07-26 10:15:23 -0400820 Increases SkMaskFilter SkRefCnt by one.
821
822 @return SkMaskFilter if previously set, nullptr otherwise
823 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500824 sk_sp<SkMaskFilter> refMaskFilter() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000825
Cary Clark8a02b0b2017-09-21 12:28:43 -0400826 /** Sets SkMaskFilter to maskFilter, decreasing SkRefCnt of the previous
827 SkMaskFilter. Pass nullptr to clear SkMaskFilter and leave SkMaskFilter effect on
828 mask alpha unaltered.
829
Cary Clark75959392018-02-27 10:22:04 -0500830 Increments maskFilter SkRefCnt by one.
831
Cary Clark50fa3ff2017-07-26 10:15:23 -0400832 @param maskFilter modifies clipping mask generated from drawn geometry
reed@android.com8a1c16f2008-12-17 15:59:43 +0000833 */
Cary Clark0418a882017-05-10 09:07:42 -0400834 void setMaskFilter(sk_sp<SkMaskFilter> maskFilter);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000835
Cary Clark50fa3ff2017-07-26 10:15:23 -0400836 /** Returns SkTypeface if set, or nullptr.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400837 Increments SkTypeface SkRefCnt by one.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000838
Cary Clark50fa3ff2017-07-26 10:15:23 -0400839 @return SkTypeface if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000840 */
reeda5ab9ec2016-03-06 18:10:48 -0800841 SkTypeface* getTypeface() const { return fTypeface.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400842
843 /** Increases SkTypeface SkRefCnt by one.
844
845 @return SkTypeface if previously set, nullptr otherwise
846 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500847 sk_sp<SkTypeface> refTypeface() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000848
Cary Clark8a02b0b2017-09-21 12:28:43 -0400849 /** Sets SkTypeface to typeface, decreasing SkRefCnt of the previous SkTypeface.
850 Pass nullptr to clear SkTypeface and use the default typeface. Increments
851 typeface SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400852
853 @param typeface font and style used to draw text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000854 */
Cary Clark0418a882017-05-10 09:07:42 -0400855 void setTypeface(sk_sp<SkTypeface> typeface);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000856
Cary Clark50fa3ff2017-07-26 10:15:23 -0400857 /** Returns SkImageFilter if set, or nullptr.
858 Does not alter SkImageFilter SkRefCnt.
859
860 @return SkImageFilter if previously set, nullptr otherwise
861 */
reeda5ab9ec2016-03-06 18:10:48 -0800862 SkImageFilter* getImageFilter() const { return fImageFilter.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400863
864 /** Returns SkImageFilter if set, or nullptr.
865 Increases SkImageFilter SkRefCnt by one.
866
867 @return SkImageFilter if previously set, nullptr otherwise
868 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500869 sk_sp<SkImageFilter> refImageFilter() const;
Cary Clark50fa3ff2017-07-26 10:15:23 -0400870
Cary Clark8a02b0b2017-09-21 12:28:43 -0400871 /** Sets SkImageFilter to imageFilter, decreasing SkRefCnt of the previous
872 SkImageFilter. Pass nullptr to clear SkImageFilter, and remove SkImageFilter effect
Cary Clark50fa3ff2017-07-26 10:15:23 -0400873 on drawing.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400874
Cary Clark75959392018-02-27 10:22:04 -0500875 Increments imageFilter SkRefCnt by one.
876
Cary Clark50fa3ff2017-07-26 10:15:23 -0400877 @param imageFilter how SkImage is sampled when transformed
878 */
Cary Clark0418a882017-05-10 09:07:42 -0400879 void setImageFilter(sk_sp<SkImageFilter> imageFilter);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000880
Cary Clark50fa3ff2017-07-26 10:15:23 -0400881 /** Returns SkDrawLooper if set, or nullptr.
882 Does not alter SkDrawLooper SkRefCnt.
883
884 @return SkDrawLooper if previously set, nullptr otherwise
885 */
reed46f2d0a2016-09-11 05:40:31 -0700886 SkDrawLooper* getDrawLooper() const { return fDrawLooper.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400887
888 /** Returns SkDrawLooper if set, or nullptr.
889 Increases SkDrawLooper SkRefCnt by one.
890
891 @return SkDrawLooper if previously set, nullptr otherwise
892 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500893 sk_sp<SkDrawLooper> refDrawLooper() const;
894
Cary Clark23890a92017-07-27 16:30:51 -0400895 /** Deprecated.
Cary Clark75959392018-02-27 10:22:04 -0500896 (see skbug.com/6259)
Cary Clark50fa3ff2017-07-26 10:15:23 -0400897 */
reed46f2d0a2016-09-11 05:40:31 -0700898 SkDrawLooper* getLooper() const { return fDrawLooper.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400899
Cary Clark8a02b0b2017-09-21 12:28:43 -0400900 /** Sets SkDrawLooper to drawLooper, decreasing SkRefCnt of the previous
901 drawLooper. Pass nullptr to clear SkDrawLooper and leave SkDrawLooper effect on
902 drawing unaltered.
903
904 Increments drawLooper SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400905
Cary Clarkb7da7232017-09-01 13:49:54 -0400906 @param drawLooper iterates through drawing one or more time, altering SkPaint
Cary Clark50fa3ff2017-07-26 10:15:23 -0400907 */
Cary Clark0418a882017-05-10 09:07:42 -0400908 void setDrawLooper(sk_sp<SkDrawLooper> drawLooper);
Mike Reed09d94352016-10-31 15:11:04 -0400909
Cary Clark23890a92017-07-27 16:30:51 -0400910 /** Deprecated.
Cary Clark75959392018-02-27 10:22:04 -0500911 (see skbug.com/6259)
Cary Clark50fa3ff2017-07-26 10:15:23 -0400912 */
Cary Clark0418a882017-05-10 09:07:42 -0400913 void setLooper(sk_sp<SkDrawLooper> drawLooper);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000914
Cary Clark50fa3ff2017-07-26 10:15:23 -0400915 /** \enum SkPaint::Align
916 Align adjusts the text relative to the text position.
917 Align affects glyphs drawn with: SkCanvas::drawText, SkCanvas::drawPosText,
918 SkCanvas::drawPosTextH, SkCanvas::drawTextOnPath,
919 SkCanvas::drawTextOnPathHV, SkCanvas::drawTextRSXform, SkCanvas::drawTextBlob,
920 and SkCanvas::drawString;
Cary Clark579985c2017-07-31 11:48:27 -0400921 as well as calls that place text glyphs like getTextWidths() and getTextPath().
Cary Clark50fa3ff2017-07-26 10:15:23 -0400922
923 The text position is set by the font for both horizontal and vertical text.
924 Typically, for horizontal text, the position is to the left side of the glyph on the
Cary Clark23890a92017-07-27 16:30:51 -0400925 base line; and for vertical text, the position is the horizontal center of the glyph
Cary Clark50fa3ff2017-07-26 10:15:23 -0400926 at the caps height.
927
928 Align adjusts the glyph position to center it or move it to abut the position
929 using the metrics returned by the font.
930
931 Align defaults to kLeft_Align.
932 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000933 enum Align {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400934 /** Leaves the glyph at the position computed by the font offset by the text position. */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000935 kLeft_Align,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400936
937 /** Moves the glyph half its width if Flags has kVerticalText_Flag clear, and
938 half its height if Flags has kVerticalText_Flag set.
939 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000940 kCenter_Align,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400941
942 /** Moves the glyph by its width if Flags has kVerticalText_Flag clear,
943 and by its height if Flags has kVerticalText_Flag set.
944 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000945 kRight_Align,
mike@reedtribe.orgddc813b2013-06-08 12:58:19 +0000946 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400947
Cary Clarkd98f78c2018-04-26 08:32:37 -0400948 static constexpr int kAlignCount = 3; //!< The number of different Align values defined.
reed@google.com9d07fec2011-03-16 20:02:59 +0000949
Cary Clark50fa3ff2017-07-26 10:15:23 -0400950 /** Returns SkPaint::Align.
951 Returns kLeft_Align if SkPaint::Align has not been set.
952
953 @return text placement relative to position
reed@android.com8a1c16f2008-12-17 15:59:43 +0000954 */
reedf59eab22014-07-14 14:39:15 -0700955 Align getTextAlign() const { return (Align)fBitfields.fTextAlign; }
reed@google.com9d07fec2011-03-16 20:02:59 +0000956
Cary Clark50fa3ff2017-07-26 10:15:23 -0400957 /** Sets SkPaint::Align to align.
958 Has no effect if align is an invalid value.
959
960 @param align text placement relative to position
reed@android.com8a1c16f2008-12-17 15:59:43 +0000961 */
962 void setTextAlign(Align align);
963
Cary Clark50fa3ff2017-07-26 10:15:23 -0400964 /** Returns text size in points.
965
966 @return typographic height of text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000967 */
968 SkScalar getTextSize() const { return fTextSize; }
969
Cary Clark50fa3ff2017-07-26 10:15:23 -0400970 /** Sets text size in points.
971 Has no effect if textSize is not greater than or equal to zero.
972
973 @param textSize typographic height of text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000974 */
975 void setTextSize(SkScalar textSize);
976
Cary Clark50fa3ff2017-07-26 10:15:23 -0400977 /** Returns text scale x.
978 Default value is 1.
979
980 @return text horizontal scale
reed@android.com8a1c16f2008-12-17 15:59:43 +0000981 */
982 SkScalar getTextScaleX() const { return fTextScaleX; }
983
Cary Clark50fa3ff2017-07-26 10:15:23 -0400984 /** Sets text scale x.
985 Default value is 1.
986
987 @param scaleX text horizontal scale
reed@android.com8a1c16f2008-12-17 15:59:43 +0000988 */
989 void setTextScaleX(SkScalar scaleX);
990
Cary Clark50fa3ff2017-07-26 10:15:23 -0400991 /** Returns text skew x.
992 Default value is zero.
993
994 @return additional shear in x-axis relative to y-axis
reed@android.com8a1c16f2008-12-17 15:59:43 +0000995 */
996 SkScalar getTextSkewX() const { return fTextSkewX; }
997
Cary Clark50fa3ff2017-07-26 10:15:23 -0400998 /** Sets text skew x.
999 Default value is zero.
1000
1001 @param skewX additional shear in x-axis relative to y-axis
reed@android.com8a1c16f2008-12-17 15:59:43 +00001002 */
1003 void setTextSkewX(SkScalar skewX);
1004
Cary Clark50fa3ff2017-07-26 10:15:23 -04001005 /** \enum SkPaint::TextEncoding
Cary Clark8a02b0b2017-09-21 12:28:43 -04001006 TextEncoding determines whether text specifies character codes and their encoded
Cary Clarkcc309eb2017-10-30 11:48:35 -04001007 size, or glyph indices. Characters are encoded as specified by the Unicode standard.
Cary Clark8a02b0b2017-09-21 12:28:43 -04001008
Cary Clark50fa3ff2017-07-26 10:15:23 -04001009 Character codes encoded size are specified by UTF-8, UTF-16, or UTF-32.
Cary Clarkcc309eb2017-10-30 11:48:35 -04001010 All character code formats are able to represent all of Unicode, differing only
1011 in the total storage required.
1012
1013 UTF-8 (RFC 3629) encodes each character as one or more 8-bit bytes.
1014
1015 UTF-16 (RFC 2781) encodes each character as one or two 16-bit words.
1016
1017 UTF-32 encodes each character as one 32-bit word.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001018
1019 font manager uses font data to convert character code points into glyph indices.
1020 A glyph index is a 16-bit word.
1021
1022 TextEncoding is set to kUTF8_TextEncoding by default.
reed@android.com8a1c16f2008-12-17 15:59:43 +00001023 */
1024 enum TextEncoding {
Cary Clark50fa3ff2017-07-26 10:15:23 -04001025 kUTF8_TextEncoding, //!< Uses bytes to represent UTF-8 or ASCII.
1026 kUTF16_TextEncoding, //!< Uses two byte words to represent most of Unicode.
1027 kUTF32_TextEncoding, //!< Uses four byte words to represent all of Unicode.
1028 kGlyphID_TextEncoding, //!< Uses two byte words to represent glyph indices.
reed@android.com8a1c16f2008-12-17 15:59:43 +00001029 };
reed@google.com9d07fec2011-03-16 20:02:59 +00001030
Cary Clark50fa3ff2017-07-26 10:15:23 -04001031 /** Returns SkPaint::TextEncoding.
1032 SkPaint::TextEncoding determines how character code points are mapped to font glyph indices.
1033
1034 @return one of: kUTF8_TextEncoding, kUTF16_TextEncoding, kUTF32_TextEncoding, or
1035 kGlyphID_TextEncoding
1036 */
reedf59eab22014-07-14 14:39:15 -07001037 TextEncoding getTextEncoding() const {
1038 return (TextEncoding)fBitfields.fTextEncoding;
1039 }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001040
Cary Clark50fa3ff2017-07-26 10:15:23 -04001041 /** Sets SkPaint::TextEncoding to encoding.
1042 SkPaint::TextEncoding determines how character code points are mapped to font glyph indices.
1043 Invalid values for encoding are ignored.
1044
1045 @param encoding one of: kUTF8_TextEncoding, kUTF16_TextEncoding, kUTF32_TextEncoding, or
Cary Clark579985c2017-07-31 11:48:27 -04001046 kGlyphID_TextEncoding
Cary Clark50fa3ff2017-07-26 10:15:23 -04001047 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001048 void setTextEncoding(TextEncoding encoding);
1049
Cary Clark50fa3ff2017-07-26 10:15:23 -04001050 /** \struct SkPaint::FontMetrics
Cary Clark579985c2017-07-31 11:48:27 -04001051 FontMetrics is filled out by getFontMetrics(). FontMetrics contents reflect the values
Cary Clark50fa3ff2017-07-26 10:15:23 -04001052 computed by font manager using SkTypeface. Values are set to zero if they are
Cary Clarkb7da7232017-09-01 13:49:54 -04001053 not available.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001054
Ben Wagnere5806492017-11-09 12:08:31 -05001055 All vertical values relative to the baseline are given y-down. As such, zero is on the
1056 baseline, negative values are above the baseline, and positive values are below the
1057 baseline.
1058
Cary Clark50fa3ff2017-07-26 10:15:23 -04001059 fUnderlineThickness and fUnderlinePosition have a bit set in fFlags if their values
1060 are valid, since their value may be zero.
1061
1062 fStrikeoutThickness and fStrikeoutPosition have a bit set in fFlags if their values
1063 are valid, since their value may be zero.
1064 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001065 struct FontMetrics {
Cary Clark50fa3ff2017-07-26 10:15:23 -04001066
Cary Clarkcc309eb2017-10-30 11:48:35 -04001067 /** \enum SkPaint::FontMetrics::FontMetricsFlags
1068 FontMetricsFlags are set in fFlags when underline and strikeout metrics are valid;
1069 the underline or strikeout metric may be valid and zero.
1070 Fonts with embedded bitmaps may not have valid underline or strikeout metrics.
1071 */
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001072 enum FontMetricsFlags {
Cary Clark50fa3ff2017-07-26 10:15:23 -04001073 kUnderlineThicknessIsValid_Flag = 1 << 0, //!< Set if fUnderlineThickness is valid.
1074 kUnderlinePositionIsValid_Flag = 1 << 1, //!< Set if fUnderlinePosition is valid.
1075 kStrikeoutThicknessIsValid_Flag = 1 << 2, //!< Set if fStrikeoutThickness is valid.
1076 kStrikeoutPositionIsValid_Flag = 1 << 3, //!< Set if fStrikeoutPosition is valid.
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001077 };
1078
Cary Clark50fa3ff2017-07-26 10:15:23 -04001079 uint32_t fFlags; //!< fFlags is set when underline metrics are valid.
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001080
Ben Wagnere5806492017-11-09 12:08:31 -05001081 /** Greatest extent above the baseline for any glyph.
1082 Typically less than zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001083 */
1084 SkScalar fTop;
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001085
Cary Clark50fa3ff2017-07-26 10:15:23 -04001086 /** Recommended distance above the baseline to reserve for a line of text.
Ben Wagnere5806492017-11-09 12:08:31 -05001087 Typically less than zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001088 */
1089 SkScalar fAscent;
Ben Wagner219f3622017-07-17 15:32:25 -04001090
Cary Clark50fa3ff2017-07-26 10:15:23 -04001091 /** Recommended distance below the baseline to reserve for a line of text.
Ben Wagnere5806492017-11-09 12:08:31 -05001092 Typically greater than zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001093 */
1094 SkScalar fDescent;
Ben Wagner219f3622017-07-17 15:32:25 -04001095
Cary Clark50fa3ff2017-07-26 10:15:23 -04001096 /** Greatest extent below the baseline for any glyph.
Ben Wagnere5806492017-11-09 12:08:31 -05001097 Typically greater than zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001098 */
1099 SkScalar fBottom;
1100
1101 /** Recommended distance to add between lines of text.
Ben Wagnere5806492017-11-09 12:08:31 -05001102 Typically greater than or equal to zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001103 */
1104 SkScalar fLeading;
1105
1106 /** Average character width, if it is available.
1107 Zero if no average width is stored in the font.
1108 */
1109 SkScalar fAvgCharWidth;
Cary Clarkcc309eb2017-10-30 11:48:35 -04001110
Cary Clark50fa3ff2017-07-26 10:15:23 -04001111 SkScalar fMaxCharWidth; //!< Maximum character width.
1112
1113 /** Minimum bounding box x value for all glyphs.
1114 Typically less than zero.
1115 */
1116 SkScalar fXMin;
1117
1118 /** Maximum bounding box x value for all glyphs.
1119 Typically greater than zero.
1120 */
1121 SkScalar fXMax;
1122
1123 /** Height of a lower-case 'x'.
1124 May be zero if no lower-case height is stored in the font.
1125 */
1126 SkScalar fXHeight;
1127
1128 /** Height of an upper-case letter.
1129 May be zero if no upper-case height is stored in the font.
1130 */
1131 SkScalar fCapHeight;
1132
Ben Wagnere5806492017-11-09 12:08:31 -05001133 /** Underline thickness.
1134
1135 If the metric is valid, the kUnderlineThicknessIsValid_Flag is set in fFlags.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001136 If kUnderlineThicknessIsValid_Flag is clear, fUnderlineThickness is zero.
1137 */
1138 SkScalar fUnderlineThickness;
1139
Ben Wagnere5806492017-11-09 12:08:31 -05001140 /** Position of the top of the underline stroke relative to the baseline.
1141 Typically positive when valid.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001142
1143 If the metric is valid, the kUnderlinePositionIsValid_Flag is set in fFlags.
1144 If kUnderlinePositionIsValid_Flag is clear, fUnderlinePosition is zero.
1145 */
1146 SkScalar fUnderlinePosition;
1147
Ben Wagnere5806492017-11-09 12:08:31 -05001148 /** Strikeout thickness.
1149
1150 If the metric is valid, the kStrikeoutThicknessIsValid_Flag is set in fFlags.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001151 If kStrikeoutThicknessIsValid_Flag is clear, fStrikeoutThickness is zero.
1152 */
1153 SkScalar fStrikeoutThickness;
1154
Ben Wagnere5806492017-11-09 12:08:31 -05001155 /** Position of the bottom of the strikeout stroke relative to the baseline.
1156 Typically negative when valid.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001157
1158 If the metric is valid, the kStrikeoutPositionIsValid_Flag is set in fFlags.
1159 If kStrikeoutPositionIsValid_Flag is clear, fStrikeoutPosition is zero.
1160 */
1161 SkScalar fStrikeoutPosition;
1162
1163 /** If SkPaint::FontMetrics has a valid underline thickness, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001164 thickness to that value. If the underline thickness is not valid,
1165 return false, and ignore thickness.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001166
1167 @param thickness storage for underline width
1168 @return true if font specifies underline width
1169 */
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001170 bool hasUnderlineThickness(SkScalar* thickness) const {
Ben Wagner3318da52017-03-23 14:01:22 -04001171 if (SkToBool(fFlags & kUnderlineThicknessIsValid_Flag)) {
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001172 *thickness = fUnderlineThickness;
1173 return true;
1174 }
1175 return false;
1176 }
1177
Cary Clark50fa3ff2017-07-26 10:15:23 -04001178 /** If SkPaint::FontMetrics has a valid underline position, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001179 position to that value. If the underline position is not valid,
1180 return false, and ignore position.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001181
1182 @param position storage for underline position
1183 @return true if font specifies underline position
1184 */
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001185 bool hasUnderlinePosition(SkScalar* position) const {
1186 if (SkToBool(fFlags & kUnderlinePositionIsValid_Flag)) {
1187 *position = fUnderlinePosition;
1188 return true;
1189 }
1190 return false;
1191 }
1192
Cary Clark50fa3ff2017-07-26 10:15:23 -04001193 /** If SkPaint::FontMetrics has a valid strikeout thickness, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001194 thickness to that value. If the underline thickness is not valid,
1195 return false, and ignore thickness.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001196
1197 @param thickness storage for strikeout width
1198 @return true if font specifies strikeout width
1199 */
Ben Wagner219f3622017-07-17 15:32:25 -04001200 bool hasStrikeoutThickness(SkScalar* thickness) const {
1201 if (SkToBool(fFlags & kStrikeoutThicknessIsValid_Flag)) {
1202 *thickness = fStrikeoutThickness;
1203 return true;
1204 }
1205 return false;
1206 }
1207
Cary Clark50fa3ff2017-07-26 10:15:23 -04001208 /** If SkPaint::FontMetrics has a valid strikeout position, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001209 position to that value. If the underline position is not valid,
1210 return false, and ignore position.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001211
1212 @param position storage for strikeout position
1213 @return true if font specifies strikeout position
1214 */
Ben Wagner219f3622017-07-17 15:32:25 -04001215 bool hasStrikeoutPosition(SkScalar* position) const {
1216 if (SkToBool(fFlags & kStrikeoutPositionIsValid_Flag)) {
1217 *position = fStrikeoutPosition;
1218 return true;
1219 }
1220 return false;
1221 }
Cary Clark50fa3ff2017-07-26 10:15:23 -04001222
reed@android.com8a1c16f2008-12-17 15:59:43 +00001223 };
reed@google.com9d07fec2011-03-16 20:02:59 +00001224
Cary Clark50fa3ff2017-07-26 10:15:23 -04001225 /** Returns SkPaint::FontMetrics associated with SkTypeface.
1226 The return value is the recommended spacing between lines: the sum of metrics
1227 descent, ascent, and leading.
1228 If metrics is not nullptr, SkPaint::FontMetrics is copied to metrics.
1229 Results are scaled by text size but does not take into account
1230 dimensions required by text scale x, text skew x, fake bold,
1231 style stroke, and SkPathEffect.
1232 Results can be additionally scaled by scale; a scale of zero
1233 is ignored.
1234
1235 @param metrics storage for SkPaint::FontMetrics from SkTypeface; may be nullptr
1236 @param scale additional multiplier for returned values
1237 @return recommended spacing between lines
reed@android.com8a1c16f2008-12-17 15:59:43 +00001238 */
1239 SkScalar getFontMetrics(FontMetrics* metrics, SkScalar scale = 0) const;
reed@google.com9d07fec2011-03-16 20:02:59 +00001240
Cary Clark50fa3ff2017-07-26 10:15:23 -04001241 /** Returns the recommended spacing between lines: the sum of metrics
1242 descent, ascent, and leading.
1243 Result is scaled by text size but does not take into account
1244 dimensions required by stroking and SkPathEffect.
Cary Clark579985c2017-07-31 11:48:27 -04001245 Returns the same result as getFontMetrics().
Cary Clark50fa3ff2017-07-26 10:15:23 -04001246
1247 @return recommended spacing between lines
reed@android.com8a1c16f2008-12-17 15:59:43 +00001248 */
Ben Wagnera93a14a2017-08-28 10:34:05 -04001249 SkScalar getFontSpacing() const { return this->getFontMetrics(nullptr, 0); }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001250
Cary Clark50fa3ff2017-07-26 10:15:23 -04001251 /** Converts text into glyph indices.
1252 Returns the number of glyph indices represented by text.
1253 SkPaint::TextEncoding specifies how text represents characters or glyphs.
1254 glyphs may be nullptr, to compute the glyph count.
1255
Cary Clarkcc309eb2017-10-30 11:48:35 -04001256 Does not check text for valid character codes or valid glyph indices.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001257
Cary Clark579985c2017-07-31 11:48:27 -04001258 If byteLength equals zero, returns zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001259 If byteLength includes a partial character, the partial character is ignored.
1260
1261 If SkPaint::TextEncoding is kUTF8_TextEncoding and
1262 text contains an invalid UTF-8 sequence, zero is returned.
1263
Cary Clarkb7da7232017-09-01 13:49:54 -04001264 @param text character storage encoded with SkPaint::TextEncoding
Cary Clark50fa3ff2017-07-26 10:15:23 -04001265 @param byteLength length of character storage in bytes
1266 @param glyphs storage for glyph indices; may be nullptr
1267 @return number of glyphs represented by text of length byteLength
reed@android.com8a1c16f2008-12-17 15:59:43 +00001268 */
1269 int textToGlyphs(const void* text, size_t byteLength,
halcanaryd0e95a52016-07-25 07:18:12 -07001270 SkGlyphID glyphs[]) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001271
Cary Clark50fa3ff2017-07-26 10:15:23 -04001272 /** Returns true if all text corresponds to a non-zero glyph index.
1273 Returns false if any characters in text are not supported in
1274 SkTypeface.
reed@android.coma5dcaf62010-02-05 17:12:32 +00001275
Cary Clark579985c2017-07-31 11:48:27 -04001276 If SkPaint::TextEncoding is kGlyphID_TextEncoding,
1277 returns true if all glyph indices in text are non-zero;
Cary Clark50fa3ff2017-07-26 10:15:23 -04001278 does not check to see if text contains valid glyph indices for SkTypeface.
1279
Cary Clarkb7da7232017-09-01 13:49:54 -04001280 Returns true if byteLength is zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001281
1282 @param text array of characters or glyphs
1283 @param byteLength number of bytes in text array
1284 @return true if all text corresponds to a non-zero glyph index
1285 */
reed@android.coma5dcaf62010-02-05 17:12:32 +00001286 bool containsText(const void* text, size_t byteLength) const;
1287
Cary Clark50fa3ff2017-07-26 10:15:23 -04001288 /** Converts glyphs into text if possible.
1289 Glyph values without direct Unicode equivalents are mapped to zero.
1290 Uses the SkTypeface, but is unaffected
1291 by SkPaint::TextEncoding; the text values returned are equivalent to kUTF32_TextEncoding.
1292
1293 Only supported on platforms that use FreeType as the font engine.
1294
1295 @param glyphs array of indices into font
1296 @param count length of glyph array
1297 @param text storage for character codes, one per glyph
reed@android.com9d3a9852010-01-08 14:07:42 +00001298 */
halcanaryd0e95a52016-07-25 07:18:12 -07001299 void glyphsToUnichars(const SkGlyphID glyphs[], int count, SkUnichar text[]) const;
reed@android.com9d3a9852010-01-08 14:07:42 +00001300
Cary Clark50fa3ff2017-07-26 10:15:23 -04001301 /** Returns the number of glyphs in text.
1302 Uses SkPaint::TextEncoding to count the glyphs.
Cary Clark579985c2017-07-31 11:48:27 -04001303 Returns the same result as textToGlyphs().
Cary Clark50fa3ff2017-07-26 10:15:23 -04001304
Cary Clarkb7da7232017-09-01 13:49:54 -04001305 @param text character storage encoded with SkPaint::TextEncoding
Cary Clark50fa3ff2017-07-26 10:15:23 -04001306 @param byteLength length of character storage in bytes
1307 @return number of glyphs represented by text of length byteLength
reed@android.com8a1c16f2008-12-17 15:59:43 +00001308 */
Herb Derby90864a22018-05-02 13:43:49 -04001309 int countText(const void* text, size_t byteLength) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001310
Cary Clark50fa3ff2017-07-26 10:15:23 -04001311 /** Returns the advance width of text if kVerticalText_Flag is clear,
1312 and the height of text if kVerticalText_Flag is set.
1313 The advance is the normal distance to move before drawing additional text.
1314 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
1315 and text size, text scale x, text skew x, stroke width, and
1316 SkPathEffect to scale the metrics and bounds.
1317 Returns the bounding box of text if bounds is not nullptr.
1318 The bounding box is computed as if the text was drawn at the origin.
1319
1320 @param text character codes or glyph indices to be measured
1321 @param length number of bytes of text to measure
1322 @param bounds returns bounding box relative to (0, 0) if not nullptr
1323 @return advance width or height
1324 */
reed99ae8812014-08-26 11:30:01 -07001325 SkScalar measureText(const void* text, size_t length, SkRect* bounds) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001326
Cary Clark50fa3ff2017-07-26 10:15:23 -04001327 /** Returns the advance width of text if kVerticalText_Flag is clear,
1328 and the height of text if kVerticalText_Flag is set.
1329 The advance is the normal distance to move before drawing additional text.
1330 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
Cary Clark23890a92017-07-27 16:30:51 -04001331 and text size to scale the metrics.
1332 Does not scale the advance or bounds by fake bold or SkPathEffect.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001333
1334 @param text character codes or glyph indices to be measured
1335 @param length number of bytes of text to measure
Cary Clark50fa3ff2017-07-26 10:15:23 -04001336 @return advance width or height
1337 */
reed@google.com9d07fec2011-03-16 20:02:59 +00001338 SkScalar measureText(const void* text, size_t length) const {
Ben Wagnera93a14a2017-08-28 10:34:05 -04001339 return this->measureText(text, length, nullptr);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001340 }
reed@google.com9d07fec2011-03-16 20:02:59 +00001341
Cary Clark50fa3ff2017-07-26 10:15:23 -04001342 /** Returns the bytes of text that fit within maxWidth.
1343 If kVerticalText_Flag is clear, the text fragment fits if its advance width is less than or
1344 equal to maxWidth.
1345 If kVerticalText_Flag is set, the text fragment fits if its advance height is less than or
1346 equal to maxWidth.
1347 Measures only while the advance is less than or equal to maxWidth.
1348 Returns the advance or the text fragment in measuredWidth if it not nullptr.
1349 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
1350 and text size to scale the metrics.
1351 Does not scale the advance or bounds by fake bold or SkPathEffect.
1352
1353 @param text character codes or glyph indices to be measured
1354 @param length number of bytes of text to measure
1355 @param maxWidth advance limit; text is measured while advance is less than maxWidth
1356 @param measuredWidth returns the width of the text less than or equal to maxWidth
1357 @return bytes of text that fit, always less than or equal to length
1358 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001359 size_t breakText(const void* text, size_t length, SkScalar maxWidth,
Ben Wagnera93a14a2017-08-28 10:34:05 -04001360 SkScalar* measuredWidth = nullptr) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001361
Cary Clark50fa3ff2017-07-26 10:15:23 -04001362 /** Retrieves the advance and bounds for each glyph in text, and returns
1363 the glyph count in text.
1364 Both widths and bounds may be nullptr.
1365 If widths is not nullptr, widths must be an array of glyph count entries.
1366 if bounds is not nullptr, bounds must be an array of glyph count entries.
1367 If kVerticalText_Flag is clear, widths returns the horizontal advance.
1368 If kVerticalText_Flag is set, widths returns the vertical advance.
1369 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
1370 and text size to scale the widths and bounds.
1371 Does not scale the advance by fake bold or SkPathEffect.
Cary Clark23890a92017-07-27 16:30:51 -04001372 Does include fake bold and SkPathEffect in the bounds.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001373
1374 @param text character codes or glyph indices to be measured
1375 @param byteLength number of bytes of text to measure
1376 @param widths returns text advances for each glyph; may be nullptr
1377 @param bounds returns bounds for each glyph relative to (0, 0); may be nullptr
1378 @return glyph count in text
1379 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001380 int getTextWidths(const void* text, size_t byteLength, SkScalar widths[],
Ben Wagnera93a14a2017-08-28 10:34:05 -04001381 SkRect bounds[] = nullptr) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001382
Cary Clark50fa3ff2017-07-26 10:15:23 -04001383 /** Returns the geometry as SkPath equivalent to the drawn text.
1384 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1385 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1386 All of the glyph paths are stored in path.
Cary Clark579985c2017-07-31 11:48:27 -04001387 Uses x, y, and SkPaint::Align to position path.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001388
1389 @param text character codes or glyph indices
1390 @param length number of bytes of text
1391 @param x x-coordinate of the origin of the text
1392 @param y y-coordinate of the origin of the text
1393 @param path geometry of the glyphs
1394 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001395 void getTextPath(const void* text, size_t length, SkScalar x, SkScalar y,
1396 SkPath* path) const;
1397
Cary Clark50fa3ff2017-07-26 10:15:23 -04001398 /** Returns the geometry as SkPath equivalent to the drawn text.
1399 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1400 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1401 All of the glyph paths are stored in path.
1402 Uses pos array and SkPaint::Align to position path.
1403 pos contains a position for each glyph.
1404
1405 @param text character codes or glyph indices
1406 @param length number of bytes of text
1407 @param pos positions of each glyph
1408 @param path geometry of the glyphs
1409 */
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001410 void getPosTextPath(const void* text, size_t length,
reed@google.comca0062e2012-07-20 11:20:32 +00001411 const SkPoint pos[], SkPath* path) const;
1412
Cary Clark50fa3ff2017-07-26 10:15:23 -04001413 /** Returns the number of intervals that intersect bounds.
1414 bounds describes a pair of lines parallel to the text advance.
1415 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1416 the string.
1417 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1418 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1419 Uses x, y, and SkPaint::Align to position intervals.
1420
1421 Pass nullptr for intervals to determine the size of the interval array.
1422
1423 intervals are cached to improve performance for multiple calls.
1424
1425 @param text character codes or glyph indices
1426 @param length number of bytes of text
1427 @param x x-coordinate of the origin of the text
1428 @param y y-coordinate of the origin of the text
1429 @param bounds lower and upper line parallel to the advance
1430 @param intervals returned intersections; may be nullptr
1431 @return number of intersections; may be zero
1432 */
caryclark0449bcf2016-02-09 13:25:45 -08001433 int getTextIntercepts(const void* text, size_t length, SkScalar x, SkScalar y,
1434 const SkScalar bounds[2], SkScalar* intervals) const;
1435
Cary Clark50fa3ff2017-07-26 10:15:23 -04001436 /** Returns the number of intervals that intersect bounds.
1437 bounds describes a pair of lines parallel to the text advance.
1438 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1439 the string.
1440 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1441 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1442 Uses pos array and SkPaint::Align to position intervals.
1443
1444 Pass nullptr for intervals to determine the size of the interval array.
1445
1446 intervals are cached to improve performance for multiple calls.
1447
1448 @param text character codes or glyph indices
1449 @param length number of bytes of text
1450 @param pos positions of each glyph
1451 @param bounds lower and upper line parallel to the advance
1452 @param intervals returned intersections; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -04001453 @return number of intersections; may be zero
Cary Clark50fa3ff2017-07-26 10:15:23 -04001454 */
caryclark0449bcf2016-02-09 13:25:45 -08001455 int getPosTextIntercepts(const void* text, size_t length, const SkPoint pos[],
1456 const SkScalar bounds[2], SkScalar* intervals) const;
1457
Cary Clark50fa3ff2017-07-26 10:15:23 -04001458 /** Returns the number of intervals that intersect bounds.
1459 bounds describes a pair of lines parallel to the text advance.
1460 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1461 the string.
1462 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1463 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1464 Uses xpos array, constY, and SkPaint::Align to position intervals.
1465
1466 Pass nullptr for intervals to determine the size of the interval array.
1467
1468 intervals are cached to improve performance for multiple calls.
1469
1470 @param text character codes or glyph indices
1471 @param length number of bytes of text
1472 @param xpos positions of each glyph in x
1473 @param constY position of each glyph in y
1474 @param bounds lower and upper line parallel to the advance
1475 @param intervals returned intersections; may be nullptr
1476 @return number of intersections; may be zero
1477 */
fmalitaeae6a912016-07-28 09:47:24 -07001478 int getPosTextHIntercepts(const void* text, size_t length, const SkScalar xpos[],
1479 SkScalar constY, const SkScalar bounds[2], SkScalar* intervals) const;
1480
Cary Clark50fa3ff2017-07-26 10:15:23 -04001481 /** Returns the number of intervals that intersect bounds.
1482 bounds describes a pair of lines parallel to the text advance.
1483 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1484 the string.
Cary Clark2823f9f2018-01-03 10:00:34 -05001485 Uses SkTypeface to get the glyph paths,
Cary Clark50fa3ff2017-07-26 10:15:23 -04001486 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
Cary Clarkb7da7232017-09-01 13:49:54 -04001487 Uses run array and SkPaint::Align to position intervals.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001488
Cary Clark2823f9f2018-01-03 10:00:34 -05001489 SkPaint::TextEncoding must be set to SkPaint::kGlyphID_TextEncoding.
1490
Cary Clark50fa3ff2017-07-26 10:15:23 -04001491 Pass nullptr for intervals to determine the size of the interval array.
1492
1493 intervals are cached to improve performance for multiple calls.
1494
Cary Clark8a02b0b2017-09-21 12:28:43 -04001495 @param blob glyphs, positions, and text paint attributes
Cary Clark50fa3ff2017-07-26 10:15:23 -04001496 @param bounds lower and upper line parallel to the advance
1497 @param intervals returned intersections; may be nullptr
1498 @return number of intersections; may be zero
1499 */
fmalitaeae6a912016-07-28 09:47:24 -07001500 int getTextBlobIntercepts(const SkTextBlob* blob, const SkScalar bounds[2],
1501 SkScalar* intervals) const;
1502
Cary Clark50fa3ff2017-07-26 10:15:23 -04001503 /** Returns the union of bounds of all glyphs.
1504 Returned dimensions are computed by font manager from font data,
Cary Clark579985c2017-07-31 11:48:27 -04001505 ignoring SkPaint::Hinting. Includes text size, text scale x,
Cary Clark50fa3ff2017-07-26 10:15:23 -04001506 and text skew x, but not fake bold or SkPathEffect.
1507
1508 If text size is large, text scale x is one, and text skew x is zero,
Cary Clark579985c2017-07-31 11:48:27 -04001509 returns the same bounds as SkPaint::FontMetrics { FontMetrics::fXMin,
Cary Clark50fa3ff2017-07-26 10:15:23 -04001510 FontMetrics::fTop, FontMetrics::fXMax, FontMetrics::fBottom }.
1511
1512 @return union of bounds of all glyphs
1513 */
reed8893e5f2014-12-15 13:27:26 -08001514 SkRect getFontBounds() const;
1515
Cary Clark579985c2017-07-31 11:48:27 -04001516 /** Returns true if SkPaint prevents all drawing;
1517 otherwise, the SkPaint may or may not allow drawing.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001518
Cary Clarkb7da7232017-09-01 13:49:54 -04001519 Returns true if, for example, SkBlendMode combined with color alpha computes a
1520 new alpha of zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001521
1522 @return true if SkPaint prevents all drawing
1523 */
reed@google.com632e1a22011-10-06 12:37:00 +00001524 bool nothingToDraw() const;
1525
Cary Clark2823f9f2018-01-03 10:00:34 -05001526 /** (to be made private)
Cary Clark50fa3ff2017-07-26 10:15:23 -04001527 Returns true if SkPaint does not include elements requiring extensive computation
1528 to compute SkBaseDevice bounds of drawn geometry. For instance, SkPaint with SkPathEffect
1529 always returns false.
reed@google.comd5f20792012-05-16 14:15:02 +00001530
Cary Clark50fa3ff2017-07-26 10:15:23 -04001531 @return true if SkPaint allows for fast computation of bounds
1532 */
senorblanco0abdf762015-08-20 11:10:41 -07001533 bool canComputeFastBounds() const;
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001534
Cary Clark2823f9f2018-01-03 10:00:34 -05001535 /** (to be made private)
Cary Clark579985c2017-07-31 11:48:27 -04001536 Only call this if canComputeFastBounds() returned true. This takes a
Cary Clark50fa3ff2017-07-26 10:15:23 -04001537 raw rectangle (the raw bounds of a shape), and adjusts it for stylistic
1538 effects in the paint (e.g. stroking). If needed, it uses the storage
Cary Clarkb7da7232017-09-01 13:49:54 -04001539 parameter. It returns the adjusted bounds that can then be used
Cary Clark50fa3ff2017-07-26 10:15:23 -04001540 for SkCanvas::quickReject tests.
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001541
Cary Clarkb7da7232017-09-01 13:49:54 -04001542 The returned SkRect will either be orig or storage, thus the caller
Cary Clark50fa3ff2017-07-26 10:15:23 -04001543 should not rely on storage being set to the result, but should always
Cary Clarkb7da7232017-09-01 13:49:54 -04001544 use the returned value. It is legal for orig and storage to be the same
1545 SkRect.
Cary Clark2823f9f2018-01-03 10:00:34 -05001546 e.g.
1547 if (paint.canComputeFastBounds()) {
1548 SkRect r, storage;
1549 path.computeBounds(&r, SkPath::kFast_BoundsType);
1550 const SkRect& fastR = paint.computeFastBounds(r, &storage);
1551 if (canvas->quickReject(fastR, ...)) {
1552 // don't draw the path
1553 }
1554 }
Cary Clark50fa3ff2017-07-26 10:15:23 -04001555
1556 @param orig geometry modified by SkPaint when drawn
1557 @param storage computed bounds of geometry; may not be nullptr
1558 @return fast computed bounds
1559 */
reed@google.coma584aed2012-05-16 14:06:02 +00001560 const SkRect& computeFastBounds(const SkRect& orig, SkRect* storage) const {
Brian Osman60751d72017-05-12 11:21:36 -04001561 // Things like stroking, etc... will do math on the bounds rect, assuming that it's sorted.
1562 SkASSERT(orig.isSorted());
reed@google.coma584aed2012-05-16 14:06:02 +00001563 SkPaint::Style style = this->getStyle();
1564 // ultra fast-case: filling with no effects that affect geometry
1565 if (kFill_Style == style) {
1566 uintptr_t effects = reinterpret_cast<uintptr_t>(this->getLooper());
1567 effects |= reinterpret_cast<uintptr_t>(this->getMaskFilter());
1568 effects |= reinterpret_cast<uintptr_t>(this->getPathEffect());
senorblanco@chromium.org336d1d72014-01-27 21:03:17 +00001569 effects |= reinterpret_cast<uintptr_t>(this->getImageFilter());
reed@google.coma584aed2012-05-16 14:06:02 +00001570 if (!effects) {
1571 return orig;
1572 }
1573 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001574
reed@google.coma584aed2012-05-16 14:06:02 +00001575 return this->doComputeFastBounds(orig, storage, style);
1576 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001577
Cary Clark2823f9f2018-01-03 10:00:34 -05001578 /** (to be made private)
Cary Clark50fa3ff2017-07-26 10:15:23 -04001579
1580 @param orig geometry modified by SkPaint when drawn
1581 @param storage computed bounds of geometry
1582 @return fast computed bounds
1583 */
reed@google.coma584aed2012-05-16 14:06:02 +00001584 const SkRect& computeFastStrokeBounds(const SkRect& orig,
1585 SkRect* storage) const {
reed@google.com73a02582012-05-16 19:21:12 +00001586 return this->doComputeFastBounds(orig, storage, kStroke_Style);
reed@google.coma584aed2012-05-16 14:06:02 +00001587 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001588
Cary Clark2823f9f2018-01-03 10:00:34 -05001589 /** (to be made private)
Cary Clarkb7da7232017-09-01 13:49:54 -04001590 Computes the bounds, overriding the SkPaint SkPaint::Style. This can be used to
1591 account for additional width required by stroking orig, without
1592 altering SkPaint::Style set to fill.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001593
1594 @param orig geometry modified by SkPaint when drawn
1595 @param storage computed bounds of geometry
1596 @param style overrides SkPaint::Style
1597 @return fast computed bounds
1598 */
reed@google.coma584aed2012-05-16 14:06:02 +00001599 const SkRect& doComputeFastBounds(const SkRect& orig, SkRect* storage,
Cary Clark0418a882017-05-10 09:07:42 -04001600 Style style) const;
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001601
Cary Clark99885412018-04-05 13:09:58 -04001602 /** Creates string representation of SkPaint. The representation is read by
1603 internal debugging tools.
Cary Clark0418a882017-05-10 09:07:42 -04001604
Cary Clarkb7da7232017-09-01 13:49:54 -04001605 @param str storage for string representation of SkPaint
Cary Clark50fa3ff2017-07-26 10:15:23 -04001606 */
Cary Clark99885412018-04-05 13:09:58 -04001607 void toString(SkString* str) const;
robertphillips@google.com791f12e2013-02-14 13:53:53 +00001608
reed@google.comd5f20792012-05-16 14:15:02 +00001609private:
Cary Clark0418a882017-05-10 09:07:42 -04001610 typedef const SkGlyph& (*GlyphCacheProc)(SkGlyphCache*, const char**);
1611
reeda5ab9ec2016-03-06 18:10:48 -08001612 sk_sp<SkTypeface> fTypeface;
1613 sk_sp<SkPathEffect> fPathEffect;
1614 sk_sp<SkShader> fShader;
reeda5ab9ec2016-03-06 18:10:48 -08001615 sk_sp<SkMaskFilter> fMaskFilter;
1616 sk_sp<SkColorFilter> fColorFilter;
reed46f2d0a2016-09-11 05:40:31 -07001617 sk_sp<SkDrawLooper> fDrawLooper;
reeda5ab9ec2016-03-06 18:10:48 -08001618 sk_sp<SkImageFilter> fImageFilter;
reed@google.comd5f20792012-05-16 14:15:02 +00001619
commit-bot@chromium.orge8807f42014-03-24 23:03:11 +00001620 SkScalar fTextSize;
1621 SkScalar fTextScaleX;
1622 SkScalar fTextSkewX;
reed@google.comd5f20792012-05-16 14:15:02 +00001623 SkColor fColor;
1624 SkScalar fWidth;
1625 SkScalar fMiterLimit;
Mike Reed71fecc32016-11-18 17:19:54 -05001626 uint32_t fBlendMode; // just need 5-6 bits
commit-bot@chromium.orgaca1c012014-02-21 18:18:05 +00001627 union {
1628 struct {
1629 // all of these bitfields should add up to 32
1630 unsigned fFlags : 16;
1631 unsigned fTextAlign : 2;
1632 unsigned fCapType : 2;
1633 unsigned fJoinType : 2;
1634 unsigned fStyle : 2;
1635 unsigned fTextEncoding : 2; // 3 values
1636 unsigned fHinting : 2;
reedf803da12015-01-23 05:58:07 -08001637 unsigned fFilterQuality : 2;
commit-bot@chromium.org85faf502014-04-16 12:58:02 +00001638 //unsigned fFreeBits : 2;
reedf59eab22014-07-14 14:39:15 -07001639 } fBitfields;
1640 uint32_t fBitfieldsUInt;
commit-bot@chromium.orgaca1c012014-02-21 18:18:05 +00001641 };
commit-bot@chromium.orge8807f42014-03-24 23:03:11 +00001642
robertphillipse34f17d2016-07-19 07:59:22 -07001643 static GlyphCacheProc GetGlyphCacheProc(TextEncoding encoding,
robertphillipse34f17d2016-07-19 07:59:22 -07001644 bool needFullMetrics);
reed@google.comd5f20792012-05-16 14:15:02 +00001645
1646 SkScalar measure_text(SkGlyphCache*, const char* text, size_t length,
1647 int* count, SkRect* bounds) const;
1648
joshualitt9e36c1a2015-04-14 12:17:27 -07001649 /*
1650 * The luminance color is used to determine which Gamma Canonical color to map to. This is
1651 * really only used by backends which want to cache glyph masks, and need some way to know if
1652 * they need to generate new masks based off a given color.
1653 */
1654 SkColor computeLuminanceColor() const;
1655
Cary Clarkd98f78c2018-04-26 08:32:37 -04001656 /* This is the size we use when we ask for a glyph's path. We then
1657 * post-transform it as we draw to match the request.
1658 * This is done to try to re-use cache entries for the path.
1659 *
1660 * This value is somewhat arbitrary. In theory, it could be 1, since
1661 * we store paths as floats. However, we get the path from the font
1662 * scaler, and it may represent its paths as fixed-point (or 26.6),
1663 * so we shouldn't ask for something too big (might overflow 16.16)
1664 * or too small (underflow 26.6).
1665 *
1666 * This value could track kMaxSizeForGlyphCache, assuming the above
1667 * constraints, but since we ask for unhinted paths, the two values
1668 * need not match per-se.
1669 */
1670 static constexpr int kCanonicalTextSizeForPaths = 64;
reed@google.comed43dff2013-06-04 16:56:27 +00001671
Jim Van Verthc65b65d2018-01-16 16:26:35 -05001672 static bool TooBigToUseCache(const SkMatrix& ctm, const SkMatrix& textM, SkScalar maxLimit);
reed@google.comed43dff2013-06-04 16:56:27 +00001673
reed@google.comed43dff2013-06-04 16:56:27 +00001674 // Set flags/hinting/textSize up to use for drawing text as paths.
1675 // Returns scale factor to restore the original textSize, since will will
1676 // have change it to kCanonicalTextSizeForPaths.
1677 SkScalar setupForAsPaths();
1678
Jim Van Verthc65b65d2018-01-16 16:26:35 -05001679 static SkScalar MaxCacheSize2(SkScalar maxLimit);
reed@google.comed43dff2013-06-04 16:56:27 +00001680
Herb Derby980a48d2018-01-23 13:39:21 -05001681 friend class GrAtlasTextBlob;
1682 friend class GrAtlasTextContext;
1683 friend class GrGLPathRendering;
1684 friend class GrPathRendering;
Herb Derby980a48d2018-01-23 13:39:21 -05001685 friend class GrTextUtils;
jvanverth2d2a68c2014-06-10 06:42:56 -07001686 friend class SkAutoGlyphCacheNoGamma;
Herb Derby980a48d2018-01-23 13:39:21 -05001687 friend class SkCanonicalizePaint;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001688 friend class SkCanvas;
1689 friend class SkDraw;
Cary Clark60ca8672018-03-06 15:09:27 -05001690 friend class SkPaintPriv;
vandebo@chromium.org28be72b2010-11-11 21:37:00 +00001691 friend class SkPDFDevice;
Herb Derby980a48d2018-01-23 13:39:21 -05001692 friend class SkScalerContext; // for computeLuminanceColor()
caryclark0449bcf2016-02-09 13:25:45 -08001693 friend class SkTextBaseIter;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001694};
1695
reed@android.com8a1c16f2008-12-17 15:59:43 +00001696#endif