blob: 7a65e2ca476060caee33c363e6eaf54ebeaff7f8 [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 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000454 bool isDevKernText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000455 return SkToBool(this->getFlags() & kDevKernText_Flag);
456 }
457
Cary Clark50fa3ff2017-07-26 10:15:23 -0400458 /** Requests, but does not require, to use hinting to adjust glyph spacing.
459
460 Sets kDevKernText_Flag if devKernText is true.
461 Clears kDevKernText_Flag if devKernText is false.
462
463 @param devKernText setting for devKernText
reed@android.com8a1c16f2008-12-17 15:59:43 +0000464 */
465 void setDevKernText(bool devKernText);
466
Cary Clark50fa3ff2017-07-26 10:15:23 -0400467 /** Returns SkFilterQuality, the image filtering level. A lower setting
468 draws faster; a higher setting looks better when the image is scaled.
469
470 @return one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
471 kMedium_SkFilterQuality, kHigh_SkFilterQuality
472 */
reedf803da12015-01-23 05:58:07 -0800473 SkFilterQuality getFilterQuality() const {
474 return (SkFilterQuality)fBitfields.fFilterQuality;
475 }
mtkleinfe81e2d2015-09-09 07:35:42 -0700476
Cary Clark23890a92017-07-27 16:30:51 -0400477 /** Sets SkFilterQuality, the image filtering level. A lower setting
Cary Clark50fa3ff2017-07-26 10:15:23 -0400478 draws faster; a higher setting looks better when the image is scaled.
Cary Clark579985c2017-07-31 11:48:27 -0400479 Does not check to see if quality is valid.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400480
481 @param quality one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
482 kMedium_SkFilterQuality, kHigh_SkFilterQuality
483 */
reedf803da12015-01-23 05:58:07 -0800484 void setFilterQuality(SkFilterQuality quality);
reed@google.comc9683152013-07-18 13:47:01 +0000485
Cary Clark50fa3ff2017-07-26 10:15:23 -0400486 /** \enum SkPaint::Style
Cary Clark23890a92017-07-27 16:30:51 -0400487 Set Style to fill, stroke, or both fill and stroke geometry.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400488 The stroke and fill
489 share all paint attributes; for instance, they are drawn with the same color.
reed@google.com9d07fec2011-03-16 20:02:59 +0000490
Cary Clark50fa3ff2017-07-26 10:15:23 -0400491 Use kStrokeAndFill_Style to avoid hitting the same pixels twice with a stroke draw and
492 a fill draw.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000493 */
494 enum Style {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400495 /** Set to fill geometry.
Cary Clark1eace2d2017-07-31 07:52:43 -0400496 Applies to SkRect, SkRegion, SkRRect, circles, ovals, SkPath, and text.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400497 SkBitmap, SkImage, patches, SkRegion, sprites, and vertices are painted as if
498 kFill_Style is set, and ignore the set Style.
499 The FillType specifies additional rules to fill the area outside the path edge,
500 and to create an unfilled hole inside the shape.
501 Style is set to kFill_Style by default.
502 */
503 kFill_Style,
504
505 /** Set to stroke geometry.
Cary Clarkb7da7232017-09-01 13:49:54 -0400506 Applies to SkRect, SkRegion, SkRRect, arcs, circles, ovals, SkPath, and text.
Cary Clark2823f9f2018-01-03 10:00:34 -0500507 Arcs, lines, and points, are always drawn as if kStroke_Style is set,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400508 and ignore the set Style.
509 The stroke construction is unaffected by the FillType.
510 */
511 kStroke_Style,
512
513 /** Set to stroke and fill geometry.
Cary Clark1eace2d2017-07-31 07:52:43 -0400514 Applies to SkRect, SkRegion, SkRRect, circles, ovals, SkPath, and text.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400515 SkPath is treated as if it is set to SkPath::kWinding_FillType,
516 and the set FillType is ignored.
517 */
518 kStrokeAndFill_Style,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000519 };
520
Cary Clarkd98f78c2018-04-26 08:32:37 -0400521 /** The number of different Style values defined.
522 May be used to verify that Style is a legal value.
523 */
524 static constexpr int kStyleCount = kStrokeAndFill_Style + 1;
Cary Clark50fa3ff2017-07-26 10:15:23 -0400525
526 /** Whether the geometry is filled, stroked, or filled and stroked.
527
528 @return one of:kFill_Style, kStroke_Style, kStrokeAndFill_Style
reed@android.com8a1c16f2008-12-17 15:59:43 +0000529 */
reedf59eab22014-07-14 14:39:15 -0700530 Style getStyle() const { return (Style)fBitfields.fStyle; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000531
Cary Clark50fa3ff2017-07-26 10:15:23 -0400532 /** Sets whether the geometry is filled, stroked, or filled and stroked.
533 Has no effect if style is not a legal SkPaint::Style value.
534
535 @param style one of: kFill_Style, kStroke_Style, kStrokeAndFill_Style
reed@android.com8a1c16f2008-12-17 15:59:43 +0000536 */
537 void setStyle(Style style);
538
Cary Clark50fa3ff2017-07-26 10:15:23 -0400539 /** Retrieves alpha and RGB, unpremultiplied, packed into 32 bits.
540 Use helpers SkColorGetA(), SkColorGetR(), SkColorGetG(), and SkColorGetB() to extract
541 a color component.
542
Cary Clark8a02b0b2017-09-21 12:28:43 -0400543 @return unpremultiplied ARGB
reed@android.com8a1c16f2008-12-17 15:59:43 +0000544 */
545 SkColor getColor() const { return fColor; }
546
Cary Clark50fa3ff2017-07-26 10:15:23 -0400547 /** Sets alpha and RGB used when stroking and filling. The color is a 32-bit value,
Cary Clarkb7da7232017-09-01 13:49:54 -0400548 unpremultiplied, packing 8-bit components for alpha, red, blue, and green.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400549
Cary Clark8a02b0b2017-09-21 12:28:43 -0400550 @param color unpremultiplied ARGB
reed@android.com8a1c16f2008-12-17 15:59:43 +0000551 */
552 void setColor(SkColor color);
553
Cary Clark1eace2d2017-07-31 07:52:43 -0400554 /** Retrieves alpha from the color used when stroking and filling.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400555
Cary Clark8a02b0b2017-09-21 12:28:43 -0400556 @return alpha ranging from zero, fully transparent, to 255, fully opaque
Cary Clark50fa3ff2017-07-26 10:15:23 -0400557 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000558 uint8_t getAlpha() const { return SkToU8(SkColorGetA(fColor)); }
reed@google.com9d07fec2011-03-16 20:02:59 +0000559
Cary Clark50fa3ff2017-07-26 10:15:23 -0400560 /** Replaces alpha, leaving RGB
561 unchanged. An out of range value triggers an assert in the debug
562 build. a is a value from zero to 255.
Cary Clark1eace2d2017-07-31 07:52:43 -0400563 a set to zero makes color fully transparent; a set to 255 makes color
Cary Clark50fa3ff2017-07-26 10:15:23 -0400564 fully opaque.
565
Cary Clark8a02b0b2017-09-21 12:28:43 -0400566 @param a alpha component of color
reed@android.com8a1c16f2008-12-17 15:59:43 +0000567 */
568 void setAlpha(U8CPU a);
569
Cary Clark1eace2d2017-07-31 07:52:43 -0400570 /** Sets color used when drawing solid fills. The color components range from 0 to 255.
Cary Clarkb7da7232017-09-01 13:49:54 -0400571 The color is unpremultiplied; alpha sets the transparency independent of RGB.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400572
Cary Clarkb7da7232017-09-01 13:49:54 -0400573 @param a amount of color alpha, from fully transparent (0) to fully opaque (255)
574 @param r amount of color rgb red, from no red (0) to full red (255)
575 @param g amount of color rgb green, from no green (0) to full green (255)
576 @param b amount of color rgb blue, from no blue (0) to full blue (255)
reed@android.com8a1c16f2008-12-17 15:59:43 +0000577 */
578 void setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b);
579
Cary Clark50fa3ff2017-07-26 10:15:23 -0400580 /** Returns the thickness of the pen used by SkPaint to
581 outline the shape.
582
Cary Clark1eace2d2017-07-31 07:52:43 -0400583 @return zero for hairline, greater than zero for pen thickness
reed@android.com8a1c16f2008-12-17 15:59:43 +0000584 */
585 SkScalar getStrokeWidth() const { return fWidth; }
586
Cary Clark50fa3ff2017-07-26 10:15:23 -0400587 /** Sets the thickness of the pen used by the paint to
588 outline the shape.
589 Has no effect if width is less than zero.
590
Cary Clark1eace2d2017-07-31 07:52:43 -0400591 @param width zero thickness for hairline; greater than zero for pen thickness
reed@android.com8a1c16f2008-12-17 15:59:43 +0000592 */
593 void setStrokeWidth(SkScalar width);
594
Cary Clark50fa3ff2017-07-26 10:15:23 -0400595 /** The limit at which a sharp corner is drawn beveled.
596
597 @return zero and greater miter limit
reed@android.com8a1c16f2008-12-17 15:59:43 +0000598 */
599 SkScalar getStrokeMiter() const { return fMiterLimit; }
600
Cary Clark50fa3ff2017-07-26 10:15:23 -0400601 /** The limit at which a sharp corner is drawn beveled.
602 Valid values are zero and greater.
603 Has no effect if miter is less than zero.
604
605 @param miter zero and greater miter limit
reed@android.com8a1c16f2008-12-17 15:59:43 +0000606 */
607 void setStrokeMiter(SkScalar miter);
608
Cary Clark50fa3ff2017-07-26 10:15:23 -0400609 /** \enum SkPaint::Cap
610 Cap draws at the beginning and end of an open path contour.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000611 */
612 enum Cap {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400613 kButt_Cap, //!< Does not extend the stroke past the beginning or the end.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000614
Cary Clark50fa3ff2017-07-26 10:15:23 -0400615 /** Adds a circle with a diameter equal to stroke width at the beginning
616 and end.
617 */
618 kRound_Cap,
619
620 /** Adds a square with sides equal to stroke width at the beginning
621 and end. The square sides are parallel to the initial and final direction
622 of the stroke.
623 */
624 kSquare_Cap,
625 kLast_Cap = kSquare_Cap, //!< Equivalent to the largest value for Cap.
626
627 /** Equivalent to kButt_Cap.
628 Cap is set to kButt_Cap by default.
629 */
630 kDefault_Cap = kButt_Cap,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000631 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400632
Cary Clark75959392018-02-27 10:22:04 -0500633 /** The number of different SkPaint::Cap values defined.
634 May be used to verify that SkPaint::Cap is a legal value.*/
bsalomona7d85ba2016-07-06 11:54:59 -0700635 static constexpr int kCapCount = kLast_Cap + 1;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000636
Cary Clark50fa3ff2017-07-26 10:15:23 -0400637 /** \enum SkPaint::Join
Cary Clark1eace2d2017-07-31 07:52:43 -0400638 Join specifies how corners are drawn when a shape is stroked. Join
Cary Clark50fa3ff2017-07-26 10:15:23 -0400639 affects the four corners of a stroked rectangle, and the connected segments in a
640 stroked path.
641
642 Choose miter join to draw sharp corners. Choose round join to draw a circle with a
643 radius equal to the stroke width on top of the corner. Choose bevel join to minimally
644 connect the thick strokes.
645
646 The fill path constructed to describe the stroked path respects the join setting but may
647 not contain the actual join. For instance, a fill path constructed with round joins does
648 not necessarily include circles at each connected segment.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000649 */
650 enum Join {
Cary Clark23890a92017-07-27 16:30:51 -0400651 /** Extends the outside corner to the extent allowed by miter limit.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400652 If the extension exceeds miter limit, kBevel_Join is used instead.
653 */
654 kMiter_Join,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000655
Cary Clark50fa3ff2017-07-26 10:15:23 -0400656 /** Adds a circle with a diameter of stroke width at the sharp corner. */
657 kRound_Join,
658 kBevel_Join, //!< Connects the outside edges of the sharp corner.
659 kLast_Join = kBevel_Join, //!< Equivalent to the largest value for Join.
660
661 /** Equivalent to kMiter_Join.
662 Join is set to kMiter_Join by default.
663 */
664 kDefault_Join = kMiter_Join,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000665 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400666
Cary Clark75959392018-02-27 10:22:04 -0500667 /** The number of different SkPaint::Join values defined.
668 May be used to verify that SkPaint::Join is a legal value.*/
bsalomona7d85ba2016-07-06 11:54:59 -0700669 static constexpr int kJoinCount = kLast_Join + 1;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000670
Cary Clark50fa3ff2017-07-26 10:15:23 -0400671 /** The geometry drawn at the beginning and end of strokes.
672
673 @return one of: kButt_Cap, kRound_Cap, kSquare_Cap
reed@android.com8a1c16f2008-12-17 15:59:43 +0000674 */
reedf59eab22014-07-14 14:39:15 -0700675 Cap getStrokeCap() const { return (Cap)fBitfields.fCapType; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000676
Cary Clark50fa3ff2017-07-26 10:15:23 -0400677 /** The geometry drawn at the beginning and end of strokes.
678
679 @param cap one of: kButt_Cap, kRound_Cap, kSquare_Cap;
680 has no effect if cap is not valid
reed@android.com8a1c16f2008-12-17 15:59:43 +0000681 */
682 void setStrokeCap(Cap cap);
683
Cary Clark50fa3ff2017-07-26 10:15:23 -0400684 /** The geometry drawn at the corners of strokes.
685
686 @return one of: kMiter_Join, kRound_Join, kBevel_Join
reed@android.com8a1c16f2008-12-17 15:59:43 +0000687 */
reedf59eab22014-07-14 14:39:15 -0700688 Join getStrokeJoin() const { return (Join)fBitfields.fJoinType; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000689
Cary Clark50fa3ff2017-07-26 10:15:23 -0400690 /** The geometry drawn at the corners of strokes.
691
692 @param join one of: kMiter_Join, kRound_Join, kBevel_Join;
Cary Clark579985c2017-07-31 11:48:27 -0400693 otherwise, has no effect
reed@android.com8a1c16f2008-12-17 15:59:43 +0000694 */
695 void setStrokeJoin(Join join);
696
Cary Clark50fa3ff2017-07-26 10:15:23 -0400697 /** The filled equivalent of the stroked path.
698
699 @param src SkPath read to create a filled version
700 @param dst resulting SkPath; may be the same as src, but may not be nullptr
701 @param cullRect optional limit passed to SkPathEffect
702 @param resScale if > 1, increase precision, else if (0 < res < 1) reduce precision
703 to favor speed and size
Cary Clark1eace2d2017-07-31 07:52:43 -0400704 @return true if the path represents style fill, or false if it represents hairline
Cary Clark50fa3ff2017-07-26 10:15:23 -0400705 */
reed05d90442015-02-12 13:35:52 -0800706 bool getFillPath(const SkPath& src, SkPath* dst, const SkRect* cullRect,
707 SkScalar resScale = 1) const;
708
Cary Clark50fa3ff2017-07-26 10:15:23 -0400709 /** The filled equivalent of the stroked path.
710
Cary Clark23890a92017-07-27 16:30:51 -0400711 Replaces dst with the src path modified by SkPathEffect and style stroke.
712 SkPathEffect, if any, is not culled. stroke width is created with default precision.
713
714 @param src SkPath read to create a filled version
715 @param dst resulting SkPath dst may be the same as src, but may not be nullptr
Cary Clark1eace2d2017-07-31 07:52:43 -0400716 @return true if the path represents style fill, or false if it represents hairline
Cary Clark50fa3ff2017-07-26 10:15:23 -0400717 */
reed05d90442015-02-12 13:35:52 -0800718 bool getFillPath(const SkPath& src, SkPath* dst) const {
Ben Wagnera93a14a2017-08-28 10:34:05 -0400719 return this->getFillPath(src, dst, nullptr, 1);
reed05d90442015-02-12 13:35:52 -0800720 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000721
Cary Clark50fa3ff2017-07-26 10:15:23 -0400722 /** Optional colors used when filling a path, such as a gradient.
723
724 Does not alter SkShader SkRefCnt.
725
726 @return SkShader if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000727 */
reeda5ab9ec2016-03-06 18:10:48 -0800728 SkShader* getShader() const { return fShader.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400729
730 /** Optional colors used when filling a path, such as a gradient.
731
732 Increases SkShader SkRefCnt by one.
733
734 @return SkShader if previously set, nullptr otherwise
735 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500736 sk_sp<SkShader> refShader() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000737
Cary Clark50fa3ff2017-07-26 10:15:23 -0400738 /** Optional colors used when filling a path, such as a gradient.
739
Cary Clark8a02b0b2017-09-21 12:28:43 -0400740 Sets SkShader to shader, decreasing SkRefCnt of the previous SkShader.
741 Increments shader SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400742
Cary Clark1eace2d2017-07-31 07:52:43 -0400743 @param shader how geometry is filled with color; if nullptr, color is used instead
Cary Clark50fa3ff2017-07-26 10:15:23 -0400744 */
Cary Clark0418a882017-05-10 09:07:42 -0400745 void setShader(sk_sp<SkShader> shader);
reed@google.com9d07fec2011-03-16 20:02:59 +0000746
Cary Clark50fa3ff2017-07-26 10:15:23 -0400747 /** Returns SkColorFilter if set, or nullptr.
748 Does not alter SkColorFilter SkRefCnt.
749
750 @return SkColorFilter if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000751 */
reeda5ab9ec2016-03-06 18:10:48 -0800752 SkColorFilter* getColorFilter() const { return fColorFilter.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400753
754 /** Returns SkColorFilter if set, or nullptr.
755 Increases SkColorFilter SkRefCnt by one.
756
757 @return SkColorFilter if set, or nullptr
758 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500759 sk_sp<SkColorFilter> refColorFilter() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000760
Cary Clark8a02b0b2017-09-21 12:28:43 -0400761 /** Sets SkColorFilter to filter, decreasing SkRefCnt of the previous
762 SkColorFilter. Pass nullptr to clear SkColorFilter.
763
764 Increments filter SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400765
766 @param colorFilter SkColorFilter to apply to subsequent draw
reed@android.com8a1c16f2008-12-17 15:59:43 +0000767 */
Cary Clark0418a882017-05-10 09:07:42 -0400768 void setColorFilter(sk_sp<SkColorFilter> colorFilter);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000769
Cary Clark50fa3ff2017-07-26 10:15:23 -0400770 /** Returns SkBlendMode.
Cary Clark579985c2017-07-31 11:48:27 -0400771 By default, returns SkBlendMode::kSrcOver.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400772
773 @return mode used to combine source color with destination color
774 */
reed374772b2016-10-05 17:33:02 -0700775 SkBlendMode getBlendMode() const { return (SkBlendMode)fBlendMode; }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400776
777 /** Returns true if SkBlendMode is SkBlendMode::kSrcOver, the default.
778
779 @return true if SkBlendMode is SkBlendMode::kSrcOver
780 */
reed374772b2016-10-05 17:33:02 -0700781 bool isSrcOver() const { return (SkBlendMode)fBlendMode == SkBlendMode::kSrcOver; }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400782
783 /** Sets SkBlendMode to mode.
784 Does not check for valid input.
785
786 @param mode SkBlendMode used to combine source color and destination
787 */
reed374772b2016-10-05 17:33:02 -0700788 void setBlendMode(SkBlendMode mode) { fBlendMode = (unsigned)mode; }
reed@android.coma0f5d152009-06-22 17:38:10 +0000789
Cary Clark50fa3ff2017-07-26 10:15:23 -0400790 /** Returns SkPathEffect if set, or nullptr.
791 Does not alter SkPathEffect SkRefCnt.
792
793 @return SkPathEffect if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000794 */
reeda5ab9ec2016-03-06 18:10:48 -0800795 SkPathEffect* getPathEffect() const { return fPathEffect.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400796
797 /** Returns SkPathEffect if set, or nullptr.
798 Increases SkPathEffect SkRefCnt by one.
799
800 @return SkPathEffect if previously set, nullptr otherwise
801 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500802 sk_sp<SkPathEffect> refPathEffect() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000803
Cary Clark8a02b0b2017-09-21 12:28:43 -0400804 /** Sets SkPathEffect to pathEffect, decreasing SkRefCnt of the previous
805 SkPathEffect. Pass nullptr to leave the path geometry unaltered.
806
807 Increments pathEffect SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400808
809 @param pathEffect replace SkPath with a modification when drawn
reed@android.com8a1c16f2008-12-17 15:59:43 +0000810 */
Cary Clark0418a882017-05-10 09:07:42 -0400811 void setPathEffect(sk_sp<SkPathEffect> pathEffect);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000812
Cary Clark50fa3ff2017-07-26 10:15:23 -0400813 /** Returns SkMaskFilter if set, or nullptr.
814 Does not alter SkMaskFilter SkRefCnt.
815
816 @return SkMaskFilter if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000817 */
reeda5ab9ec2016-03-06 18:10:48 -0800818 SkMaskFilter* getMaskFilter() const { return fMaskFilter.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400819
820 /** Returns SkMaskFilter if set, or nullptr.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400821
Cary Clark50fa3ff2017-07-26 10:15:23 -0400822 Increases SkMaskFilter SkRefCnt by one.
823
824 @return SkMaskFilter if previously set, nullptr otherwise
825 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500826 sk_sp<SkMaskFilter> refMaskFilter() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000827
Cary Clark8a02b0b2017-09-21 12:28:43 -0400828 /** Sets SkMaskFilter to maskFilter, decreasing SkRefCnt of the previous
829 SkMaskFilter. Pass nullptr to clear SkMaskFilter and leave SkMaskFilter effect on
830 mask alpha unaltered.
831
Cary Clark75959392018-02-27 10:22:04 -0500832 Increments maskFilter SkRefCnt by one.
833
Cary Clark50fa3ff2017-07-26 10:15:23 -0400834 @param maskFilter modifies clipping mask generated from drawn geometry
reed@android.com8a1c16f2008-12-17 15:59:43 +0000835 */
Cary Clark0418a882017-05-10 09:07:42 -0400836 void setMaskFilter(sk_sp<SkMaskFilter> maskFilter);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000837
Cary Clark50fa3ff2017-07-26 10:15:23 -0400838 /** Returns SkTypeface if set, or nullptr.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400839 Increments SkTypeface SkRefCnt by one.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000840
Cary Clark50fa3ff2017-07-26 10:15:23 -0400841 @return SkTypeface if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000842 */
reeda5ab9ec2016-03-06 18:10:48 -0800843 SkTypeface* getTypeface() const { return fTypeface.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400844
845 /** Increases SkTypeface SkRefCnt by one.
846
847 @return SkTypeface if previously set, nullptr otherwise
848 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500849 sk_sp<SkTypeface> refTypeface() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000850
Cary Clark8a02b0b2017-09-21 12:28:43 -0400851 /** Sets SkTypeface to typeface, decreasing SkRefCnt of the previous SkTypeface.
852 Pass nullptr to clear SkTypeface and use the default typeface. Increments
853 typeface SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400854
855 @param typeface font and style used to draw text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000856 */
Cary Clark0418a882017-05-10 09:07:42 -0400857 void setTypeface(sk_sp<SkTypeface> typeface);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000858
Cary Clark50fa3ff2017-07-26 10:15:23 -0400859 /** Returns SkImageFilter if set, or nullptr.
860 Does not alter SkImageFilter SkRefCnt.
861
862 @return SkImageFilter if previously set, nullptr otherwise
863 */
reeda5ab9ec2016-03-06 18:10:48 -0800864 SkImageFilter* getImageFilter() const { return fImageFilter.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400865
866 /** Returns SkImageFilter if set, or nullptr.
867 Increases SkImageFilter SkRefCnt by one.
868
869 @return SkImageFilter if previously set, nullptr otherwise
870 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500871 sk_sp<SkImageFilter> refImageFilter() const;
Cary Clark50fa3ff2017-07-26 10:15:23 -0400872
Cary Clark8a02b0b2017-09-21 12:28:43 -0400873 /** Sets SkImageFilter to imageFilter, decreasing SkRefCnt of the previous
874 SkImageFilter. Pass nullptr to clear SkImageFilter, and remove SkImageFilter effect
Cary Clark50fa3ff2017-07-26 10:15:23 -0400875 on drawing.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400876
Cary Clark75959392018-02-27 10:22:04 -0500877 Increments imageFilter SkRefCnt by one.
878
Cary Clark50fa3ff2017-07-26 10:15:23 -0400879 @param imageFilter how SkImage is sampled when transformed
880 */
Cary Clark0418a882017-05-10 09:07:42 -0400881 void setImageFilter(sk_sp<SkImageFilter> imageFilter);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000882
Cary Clark50fa3ff2017-07-26 10:15:23 -0400883 /** Returns SkDrawLooper if set, or nullptr.
884 Does not alter SkDrawLooper SkRefCnt.
885
886 @return SkDrawLooper if previously set, nullptr otherwise
887 */
reed46f2d0a2016-09-11 05:40:31 -0700888 SkDrawLooper* getDrawLooper() const { return fDrawLooper.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400889
890 /** Returns SkDrawLooper if set, or nullptr.
891 Increases SkDrawLooper SkRefCnt by one.
892
893 @return SkDrawLooper if previously set, nullptr otherwise
894 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500895 sk_sp<SkDrawLooper> refDrawLooper() const;
896
Cary Clark23890a92017-07-27 16:30:51 -0400897 /** Deprecated.
Cary Clark75959392018-02-27 10:22:04 -0500898 (see skbug.com/6259)
Cary Clark50fa3ff2017-07-26 10:15:23 -0400899 */
reed46f2d0a2016-09-11 05:40:31 -0700900 SkDrawLooper* getLooper() const { return fDrawLooper.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400901
Cary Clark8a02b0b2017-09-21 12:28:43 -0400902 /** Sets SkDrawLooper to drawLooper, decreasing SkRefCnt of the previous
903 drawLooper. Pass nullptr to clear SkDrawLooper and leave SkDrawLooper effect on
904 drawing unaltered.
905
906 Increments drawLooper SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400907
Cary Clarkb7da7232017-09-01 13:49:54 -0400908 @param drawLooper iterates through drawing one or more time, altering SkPaint
Cary Clark50fa3ff2017-07-26 10:15:23 -0400909 */
Cary Clark0418a882017-05-10 09:07:42 -0400910 void setDrawLooper(sk_sp<SkDrawLooper> drawLooper);
Mike Reed09d94352016-10-31 15:11:04 -0400911
Cary Clark23890a92017-07-27 16:30:51 -0400912 /** Deprecated.
Cary Clark75959392018-02-27 10:22:04 -0500913 (see skbug.com/6259)
Cary Clark50fa3ff2017-07-26 10:15:23 -0400914 */
Cary Clark0418a882017-05-10 09:07:42 -0400915 void setLooper(sk_sp<SkDrawLooper> drawLooper);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000916
Cary Clark50fa3ff2017-07-26 10:15:23 -0400917 /** \enum SkPaint::Align
918 Align adjusts the text relative to the text position.
919 Align affects glyphs drawn with: SkCanvas::drawText, SkCanvas::drawPosText,
920 SkCanvas::drawPosTextH, SkCanvas::drawTextOnPath,
921 SkCanvas::drawTextOnPathHV, SkCanvas::drawTextRSXform, SkCanvas::drawTextBlob,
922 and SkCanvas::drawString;
Cary Clark579985c2017-07-31 11:48:27 -0400923 as well as calls that place text glyphs like getTextWidths() and getTextPath().
Cary Clark50fa3ff2017-07-26 10:15:23 -0400924
925 The text position is set by the font for both horizontal and vertical text.
926 Typically, for horizontal text, the position is to the left side of the glyph on the
Cary Clark23890a92017-07-27 16:30:51 -0400927 base line; and for vertical text, the position is the horizontal center of the glyph
Cary Clark50fa3ff2017-07-26 10:15:23 -0400928 at the caps height.
929
930 Align adjusts the glyph position to center it or move it to abut the position
931 using the metrics returned by the font.
932
933 Align defaults to kLeft_Align.
934 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000935 enum Align {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400936 /** Leaves the glyph at the position computed by the font offset by the text position. */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000937 kLeft_Align,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400938
939 /** Moves the glyph half its width if Flags has kVerticalText_Flag clear, and
940 half its height if Flags has kVerticalText_Flag set.
941 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000942 kCenter_Align,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400943
944 /** Moves the glyph by its width if Flags has kVerticalText_Flag clear,
945 and by its height if Flags has kVerticalText_Flag set.
946 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000947 kRight_Align,
mike@reedtribe.orgddc813b2013-06-08 12:58:19 +0000948 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400949
Cary Clarkd98f78c2018-04-26 08:32:37 -0400950 static constexpr int kAlignCount = 3; //!< The number of different Align values defined.
reed@google.com9d07fec2011-03-16 20:02:59 +0000951
Cary Clark50fa3ff2017-07-26 10:15:23 -0400952 /** Returns SkPaint::Align.
953 Returns kLeft_Align if SkPaint::Align has not been set.
954
955 @return text placement relative to position
reed@android.com8a1c16f2008-12-17 15:59:43 +0000956 */
reedf59eab22014-07-14 14:39:15 -0700957 Align getTextAlign() const { return (Align)fBitfields.fTextAlign; }
reed@google.com9d07fec2011-03-16 20:02:59 +0000958
Cary Clark50fa3ff2017-07-26 10:15:23 -0400959 /** Sets SkPaint::Align to align.
960 Has no effect if align is an invalid value.
961
962 @param align text placement relative to position
reed@android.com8a1c16f2008-12-17 15:59:43 +0000963 */
964 void setTextAlign(Align align);
965
Cary Clark50fa3ff2017-07-26 10:15:23 -0400966 /** Returns text size in points.
967
968 @return typographic height of text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000969 */
970 SkScalar getTextSize() const { return fTextSize; }
971
Cary Clark50fa3ff2017-07-26 10:15:23 -0400972 /** Sets text size in points.
973 Has no effect if textSize is not greater than or equal to zero.
974
975 @param textSize typographic height of text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000976 */
977 void setTextSize(SkScalar textSize);
978
Cary Clark50fa3ff2017-07-26 10:15:23 -0400979 /** Returns text scale x.
980 Default value is 1.
981
982 @return text horizontal scale
reed@android.com8a1c16f2008-12-17 15:59:43 +0000983 */
984 SkScalar getTextScaleX() const { return fTextScaleX; }
985
Cary Clark50fa3ff2017-07-26 10:15:23 -0400986 /** Sets text scale x.
987 Default value is 1.
988
989 @param scaleX text horizontal scale
reed@android.com8a1c16f2008-12-17 15:59:43 +0000990 */
991 void setTextScaleX(SkScalar scaleX);
992
Cary Clark50fa3ff2017-07-26 10:15:23 -0400993 /** Returns text skew x.
994 Default value is zero.
995
996 @return additional shear in x-axis relative to y-axis
reed@android.com8a1c16f2008-12-17 15:59:43 +0000997 */
998 SkScalar getTextSkewX() const { return fTextSkewX; }
999
Cary Clark50fa3ff2017-07-26 10:15:23 -04001000 /** Sets text skew x.
1001 Default value is zero.
1002
1003 @param skewX additional shear in x-axis relative to y-axis
reed@android.com8a1c16f2008-12-17 15:59:43 +00001004 */
1005 void setTextSkewX(SkScalar skewX);
1006
Cary Clark50fa3ff2017-07-26 10:15:23 -04001007 /** \enum SkPaint::TextEncoding
Cary Clark8a02b0b2017-09-21 12:28:43 -04001008 TextEncoding determines whether text specifies character codes and their encoded
Cary Clarkcc309eb2017-10-30 11:48:35 -04001009 size, or glyph indices. Characters are encoded as specified by the Unicode standard.
Cary Clark8a02b0b2017-09-21 12:28:43 -04001010
Cary Clark50fa3ff2017-07-26 10:15:23 -04001011 Character codes encoded size are specified by UTF-8, UTF-16, or UTF-32.
Cary Clarkcc309eb2017-10-30 11:48:35 -04001012 All character code formats are able to represent all of Unicode, differing only
1013 in the total storage required.
1014
1015 UTF-8 (RFC 3629) encodes each character as one or more 8-bit bytes.
1016
1017 UTF-16 (RFC 2781) encodes each character as one or two 16-bit words.
1018
1019 UTF-32 encodes each character as one 32-bit word.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001020
1021 font manager uses font data to convert character code points into glyph indices.
1022 A glyph index is a 16-bit word.
1023
1024 TextEncoding is set to kUTF8_TextEncoding by default.
reed@android.com8a1c16f2008-12-17 15:59:43 +00001025 */
1026 enum TextEncoding {
Cary Clark50fa3ff2017-07-26 10:15:23 -04001027 kUTF8_TextEncoding, //!< Uses bytes to represent UTF-8 or ASCII.
1028 kUTF16_TextEncoding, //!< Uses two byte words to represent most of Unicode.
1029 kUTF32_TextEncoding, //!< Uses four byte words to represent all of Unicode.
1030 kGlyphID_TextEncoding, //!< Uses two byte words to represent glyph indices.
reed@android.com8a1c16f2008-12-17 15:59:43 +00001031 };
reed@google.com9d07fec2011-03-16 20:02:59 +00001032
Cary Clark50fa3ff2017-07-26 10:15:23 -04001033 /** Returns SkPaint::TextEncoding.
1034 SkPaint::TextEncoding determines how character code points are mapped to font glyph indices.
1035
1036 @return one of: kUTF8_TextEncoding, kUTF16_TextEncoding, kUTF32_TextEncoding, or
1037 kGlyphID_TextEncoding
1038 */
reedf59eab22014-07-14 14:39:15 -07001039 TextEncoding getTextEncoding() const {
1040 return (TextEncoding)fBitfields.fTextEncoding;
1041 }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001042
Cary Clark50fa3ff2017-07-26 10:15:23 -04001043 /** Sets SkPaint::TextEncoding to encoding.
1044 SkPaint::TextEncoding determines how character code points are mapped to font glyph indices.
1045 Invalid values for encoding are ignored.
1046
1047 @param encoding one of: kUTF8_TextEncoding, kUTF16_TextEncoding, kUTF32_TextEncoding, or
Cary Clark579985c2017-07-31 11:48:27 -04001048 kGlyphID_TextEncoding
Cary Clark50fa3ff2017-07-26 10:15:23 -04001049 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001050 void setTextEncoding(TextEncoding encoding);
1051
Cary Clark50fa3ff2017-07-26 10:15:23 -04001052 /** \struct SkPaint::FontMetrics
Cary Clark579985c2017-07-31 11:48:27 -04001053 FontMetrics is filled out by getFontMetrics(). FontMetrics contents reflect the values
Cary Clark50fa3ff2017-07-26 10:15:23 -04001054 computed by font manager using SkTypeface. Values are set to zero if they are
Cary Clarkb7da7232017-09-01 13:49:54 -04001055 not available.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001056
Ben Wagnere5806492017-11-09 12:08:31 -05001057 All vertical values relative to the baseline are given y-down. As such, zero is on the
1058 baseline, negative values are above the baseline, and positive values are below the
1059 baseline.
1060
Cary Clark50fa3ff2017-07-26 10:15:23 -04001061 fUnderlineThickness and fUnderlinePosition have a bit set in fFlags if their values
1062 are valid, since their value may be zero.
1063
1064 fStrikeoutThickness and fStrikeoutPosition have a bit set in fFlags if their values
1065 are valid, since their value may be zero.
1066 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001067 struct FontMetrics {
Cary Clark50fa3ff2017-07-26 10:15:23 -04001068
Cary Clarkcc309eb2017-10-30 11:48:35 -04001069 /** \enum SkPaint::FontMetrics::FontMetricsFlags
1070 FontMetricsFlags are set in fFlags when underline and strikeout metrics are valid;
1071 the underline or strikeout metric may be valid and zero.
1072 Fonts with embedded bitmaps may not have valid underline or strikeout metrics.
1073 */
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001074 enum FontMetricsFlags {
Cary Clark50fa3ff2017-07-26 10:15:23 -04001075 kUnderlineThicknessIsValid_Flag = 1 << 0, //!< Set if fUnderlineThickness is valid.
1076 kUnderlinePositionIsValid_Flag = 1 << 1, //!< Set if fUnderlinePosition is valid.
1077 kStrikeoutThicknessIsValid_Flag = 1 << 2, //!< Set if fStrikeoutThickness is valid.
1078 kStrikeoutPositionIsValid_Flag = 1 << 3, //!< Set if fStrikeoutPosition is valid.
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001079 };
1080
Cary Clark50fa3ff2017-07-26 10:15:23 -04001081 uint32_t fFlags; //!< fFlags is set when underline metrics are valid.
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001082
Ben Wagnere5806492017-11-09 12:08:31 -05001083 /** Greatest extent above the baseline for any glyph.
1084 Typically less than zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001085 */
1086 SkScalar fTop;
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001087
Cary Clark50fa3ff2017-07-26 10:15:23 -04001088 /** Recommended distance above the baseline to reserve for a line of text.
Ben Wagnere5806492017-11-09 12:08:31 -05001089 Typically less than zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001090 */
1091 SkScalar fAscent;
Ben Wagner219f3622017-07-17 15:32:25 -04001092
Cary Clark50fa3ff2017-07-26 10:15:23 -04001093 /** Recommended distance below the baseline to reserve for a line of text.
Ben Wagnere5806492017-11-09 12:08:31 -05001094 Typically greater than zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001095 */
1096 SkScalar fDescent;
Ben Wagner219f3622017-07-17 15:32:25 -04001097
Cary Clark50fa3ff2017-07-26 10:15:23 -04001098 /** Greatest extent below the baseline for any glyph.
Ben Wagnere5806492017-11-09 12:08:31 -05001099 Typically greater than zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001100 */
1101 SkScalar fBottom;
1102
1103 /** Recommended distance to add between lines of text.
Ben Wagnere5806492017-11-09 12:08:31 -05001104 Typically greater than or equal to zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001105 */
1106 SkScalar fLeading;
1107
1108 /** Average character width, if it is available.
1109 Zero if no average width is stored in the font.
1110 */
1111 SkScalar fAvgCharWidth;
Cary Clarkcc309eb2017-10-30 11:48:35 -04001112
Cary Clark50fa3ff2017-07-26 10:15:23 -04001113 SkScalar fMaxCharWidth; //!< Maximum character width.
1114
1115 /** Minimum bounding box x value for all glyphs.
1116 Typically less than zero.
1117 */
1118 SkScalar fXMin;
1119
1120 /** Maximum bounding box x value for all glyphs.
1121 Typically greater than zero.
1122 */
1123 SkScalar fXMax;
1124
1125 /** Height of a lower-case 'x'.
1126 May be zero if no lower-case height is stored in the font.
1127 */
1128 SkScalar fXHeight;
1129
1130 /** Height of an upper-case letter.
1131 May be zero if no upper-case height is stored in the font.
1132 */
1133 SkScalar fCapHeight;
1134
Ben Wagnere5806492017-11-09 12:08:31 -05001135 /** Underline thickness.
1136
1137 If the metric is valid, the kUnderlineThicknessIsValid_Flag is set in fFlags.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001138 If kUnderlineThicknessIsValid_Flag is clear, fUnderlineThickness is zero.
1139 */
1140 SkScalar fUnderlineThickness;
1141
Ben Wagnere5806492017-11-09 12:08:31 -05001142 /** Position of the top of the underline stroke relative to the baseline.
1143 Typically positive when valid.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001144
1145 If the metric is valid, the kUnderlinePositionIsValid_Flag is set in fFlags.
1146 If kUnderlinePositionIsValid_Flag is clear, fUnderlinePosition is zero.
1147 */
1148 SkScalar fUnderlinePosition;
1149
Ben Wagnere5806492017-11-09 12:08:31 -05001150 /** Strikeout thickness.
1151
1152 If the metric is valid, the kStrikeoutThicknessIsValid_Flag is set in fFlags.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001153 If kStrikeoutThicknessIsValid_Flag is clear, fStrikeoutThickness is zero.
1154 */
1155 SkScalar fStrikeoutThickness;
1156
Ben Wagnere5806492017-11-09 12:08:31 -05001157 /** Position of the bottom of the strikeout stroke relative to the baseline.
1158 Typically negative when valid.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001159
1160 If the metric is valid, the kStrikeoutPositionIsValid_Flag is set in fFlags.
1161 If kStrikeoutPositionIsValid_Flag is clear, fStrikeoutPosition is zero.
1162 */
1163 SkScalar fStrikeoutPosition;
1164
1165 /** If SkPaint::FontMetrics has a valid underline thickness, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001166 thickness to that value. If the underline thickness is not valid,
1167 return false, and ignore thickness.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001168
1169 @param thickness storage for underline width
1170 @return true if font specifies underline width
1171 */
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001172 bool hasUnderlineThickness(SkScalar* thickness) const {
Ben Wagner3318da52017-03-23 14:01:22 -04001173 if (SkToBool(fFlags & kUnderlineThicknessIsValid_Flag)) {
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001174 *thickness = fUnderlineThickness;
1175 return true;
1176 }
1177 return false;
1178 }
1179
Cary Clark50fa3ff2017-07-26 10:15:23 -04001180 /** If SkPaint::FontMetrics has a valid underline position, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001181 position to that value. If the underline position is not valid,
1182 return false, and ignore position.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001183
1184 @param position storage for underline position
1185 @return true if font specifies underline position
1186 */
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001187 bool hasUnderlinePosition(SkScalar* position) const {
1188 if (SkToBool(fFlags & kUnderlinePositionIsValid_Flag)) {
1189 *position = fUnderlinePosition;
1190 return true;
1191 }
1192 return false;
1193 }
1194
Cary Clark50fa3ff2017-07-26 10:15:23 -04001195 /** If SkPaint::FontMetrics has a valid strikeout thickness, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001196 thickness to that value. If the underline thickness is not valid,
1197 return false, and ignore thickness.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001198
1199 @param thickness storage for strikeout width
1200 @return true if font specifies strikeout width
1201 */
Ben Wagner219f3622017-07-17 15:32:25 -04001202 bool hasStrikeoutThickness(SkScalar* thickness) const {
1203 if (SkToBool(fFlags & kStrikeoutThicknessIsValid_Flag)) {
1204 *thickness = fStrikeoutThickness;
1205 return true;
1206 }
1207 return false;
1208 }
1209
Cary Clark50fa3ff2017-07-26 10:15:23 -04001210 /** If SkPaint::FontMetrics has a valid strikeout position, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001211 position to that value. If the underline position is not valid,
1212 return false, and ignore position.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001213
1214 @param position storage for strikeout position
1215 @return true if font specifies strikeout position
1216 */
Ben Wagner219f3622017-07-17 15:32:25 -04001217 bool hasStrikeoutPosition(SkScalar* position) const {
1218 if (SkToBool(fFlags & kStrikeoutPositionIsValid_Flag)) {
1219 *position = fStrikeoutPosition;
1220 return true;
1221 }
1222 return false;
1223 }
Cary Clark50fa3ff2017-07-26 10:15:23 -04001224
reed@android.com8a1c16f2008-12-17 15:59:43 +00001225 };
reed@google.com9d07fec2011-03-16 20:02:59 +00001226
Cary Clark50fa3ff2017-07-26 10:15:23 -04001227 /** Returns SkPaint::FontMetrics associated with SkTypeface.
1228 The return value is the recommended spacing between lines: the sum of metrics
1229 descent, ascent, and leading.
1230 If metrics is not nullptr, SkPaint::FontMetrics is copied to metrics.
1231 Results are scaled by text size but does not take into account
1232 dimensions required by text scale x, text skew x, fake bold,
1233 style stroke, and SkPathEffect.
1234 Results can be additionally scaled by scale; a scale of zero
1235 is ignored.
1236
1237 @param metrics storage for SkPaint::FontMetrics from SkTypeface; may be nullptr
1238 @param scale additional multiplier for returned values
1239 @return recommended spacing between lines
reed@android.com8a1c16f2008-12-17 15:59:43 +00001240 */
1241 SkScalar getFontMetrics(FontMetrics* metrics, SkScalar scale = 0) const;
reed@google.com9d07fec2011-03-16 20:02:59 +00001242
Cary Clark50fa3ff2017-07-26 10:15:23 -04001243 /** Returns the recommended spacing between lines: the sum of metrics
1244 descent, ascent, and leading.
1245 Result is scaled by text size but does not take into account
1246 dimensions required by stroking and SkPathEffect.
Cary Clark579985c2017-07-31 11:48:27 -04001247 Returns the same result as getFontMetrics().
Cary Clark50fa3ff2017-07-26 10:15:23 -04001248
1249 @return recommended spacing between lines
reed@android.com8a1c16f2008-12-17 15:59:43 +00001250 */
Ben Wagnera93a14a2017-08-28 10:34:05 -04001251 SkScalar getFontSpacing() const { return this->getFontMetrics(nullptr, 0); }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001252
Cary Clark50fa3ff2017-07-26 10:15:23 -04001253 /** Converts text into glyph indices.
1254 Returns the number of glyph indices represented by text.
1255 SkPaint::TextEncoding specifies how text represents characters or glyphs.
1256 glyphs may be nullptr, to compute the glyph count.
1257
Cary Clarkcc309eb2017-10-30 11:48:35 -04001258 Does not check text for valid character codes or valid glyph indices.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001259
Cary Clark579985c2017-07-31 11:48:27 -04001260 If byteLength equals zero, returns zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001261 If byteLength includes a partial character, the partial character is ignored.
1262
1263 If SkPaint::TextEncoding is kUTF8_TextEncoding and
1264 text contains an invalid UTF-8 sequence, zero is returned.
1265
Cary Clarkb7da7232017-09-01 13:49:54 -04001266 @param text character storage encoded with SkPaint::TextEncoding
Cary Clark50fa3ff2017-07-26 10:15:23 -04001267 @param byteLength length of character storage in bytes
1268 @param glyphs storage for glyph indices; may be nullptr
1269 @return number of glyphs represented by text of length byteLength
reed@android.com8a1c16f2008-12-17 15:59:43 +00001270 */
1271 int textToGlyphs(const void* text, size_t byteLength,
halcanaryd0e95a52016-07-25 07:18:12 -07001272 SkGlyphID glyphs[]) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001273
Cary Clark50fa3ff2017-07-26 10:15:23 -04001274 /** Returns true if all text corresponds to a non-zero glyph index.
1275 Returns false if any characters in text are not supported in
1276 SkTypeface.
reed@android.coma5dcaf62010-02-05 17:12:32 +00001277
Cary Clark579985c2017-07-31 11:48:27 -04001278 If SkPaint::TextEncoding is kGlyphID_TextEncoding,
1279 returns true if all glyph indices in text are non-zero;
Cary Clark50fa3ff2017-07-26 10:15:23 -04001280 does not check to see if text contains valid glyph indices for SkTypeface.
1281
Cary Clarkb7da7232017-09-01 13:49:54 -04001282 Returns true if byteLength is zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001283
1284 @param text array of characters or glyphs
1285 @param byteLength number of bytes in text array
1286 @return true if all text corresponds to a non-zero glyph index
1287 */
reed@android.coma5dcaf62010-02-05 17:12:32 +00001288 bool containsText(const void* text, size_t byteLength) const;
1289
Cary Clark50fa3ff2017-07-26 10:15:23 -04001290 /** Converts glyphs into text if possible.
1291 Glyph values without direct Unicode equivalents are mapped to zero.
1292 Uses the SkTypeface, but is unaffected
1293 by SkPaint::TextEncoding; the text values returned are equivalent to kUTF32_TextEncoding.
1294
1295 Only supported on platforms that use FreeType as the font engine.
1296
1297 @param glyphs array of indices into font
1298 @param count length of glyph array
1299 @param text storage for character codes, one per glyph
reed@android.com9d3a9852010-01-08 14:07:42 +00001300 */
halcanaryd0e95a52016-07-25 07:18:12 -07001301 void glyphsToUnichars(const SkGlyphID glyphs[], int count, SkUnichar text[]) const;
reed@android.com9d3a9852010-01-08 14:07:42 +00001302
Cary Clark50fa3ff2017-07-26 10:15:23 -04001303 /** Returns the number of glyphs in text.
1304 Uses SkPaint::TextEncoding to count the glyphs.
Cary Clark579985c2017-07-31 11:48:27 -04001305 Returns the same result as textToGlyphs().
Cary Clark50fa3ff2017-07-26 10:15:23 -04001306
Cary Clarkb7da7232017-09-01 13:49:54 -04001307 @param text character storage encoded with SkPaint::TextEncoding
Cary Clark50fa3ff2017-07-26 10:15:23 -04001308 @param byteLength length of character storage in bytes
1309 @return number of glyphs represented by text of length byteLength
reed@android.com8a1c16f2008-12-17 15:59:43 +00001310 */
reed@google.com9d07fec2011-03-16 20:02:59 +00001311 int countText(const void* text, size_t byteLength) const {
Ben Wagnera93a14a2017-08-28 10:34:05 -04001312 return this->textToGlyphs(text, byteLength, nullptr);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001313 }
1314
Cary Clark50fa3ff2017-07-26 10:15:23 -04001315 /** Returns the advance width of text if kVerticalText_Flag is clear,
1316 and the height of text if kVerticalText_Flag is set.
1317 The advance is the normal distance to move before drawing additional text.
1318 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
1319 and text size, text scale x, text skew x, stroke width, and
1320 SkPathEffect to scale the metrics and bounds.
1321 Returns the bounding box of text if bounds is not nullptr.
1322 The bounding box is computed as if the text was drawn at the origin.
1323
1324 @param text character codes or glyph indices to be measured
1325 @param length number of bytes of text to measure
1326 @param bounds returns bounding box relative to (0, 0) if not nullptr
1327 @return advance width or height
1328 */
reed99ae8812014-08-26 11:30:01 -07001329 SkScalar measureText(const void* text, size_t length, SkRect* bounds) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001330
Cary Clark50fa3ff2017-07-26 10:15:23 -04001331 /** Returns the advance width of text if kVerticalText_Flag is clear,
1332 and the height of text if kVerticalText_Flag is set.
1333 The advance is the normal distance to move before drawing additional text.
1334 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
Cary Clark23890a92017-07-27 16:30:51 -04001335 and text size to scale the metrics.
1336 Does not scale the advance or bounds by fake bold or SkPathEffect.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001337
1338 @param text character codes or glyph indices to be measured
1339 @param length number of bytes of text to measure
Cary Clark50fa3ff2017-07-26 10:15:23 -04001340 @return advance width or height
1341 */
reed@google.com9d07fec2011-03-16 20:02:59 +00001342 SkScalar measureText(const void* text, size_t length) const {
Ben Wagnera93a14a2017-08-28 10:34:05 -04001343 return this->measureText(text, length, nullptr);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001344 }
reed@google.com9d07fec2011-03-16 20:02:59 +00001345
Cary Clark50fa3ff2017-07-26 10:15:23 -04001346 /** Returns the bytes of text that fit within maxWidth.
1347 If kVerticalText_Flag is clear, the text fragment fits if its advance width is less than or
1348 equal to maxWidth.
1349 If kVerticalText_Flag is set, the text fragment fits if its advance height is less than or
1350 equal to maxWidth.
1351 Measures only while the advance is less than or equal to maxWidth.
1352 Returns the advance or the text fragment in measuredWidth if it not nullptr.
1353 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
1354 and text size to scale the metrics.
1355 Does not scale the advance or bounds by fake bold or SkPathEffect.
1356
1357 @param text character codes or glyph indices to be measured
1358 @param length number of bytes of text to measure
1359 @param maxWidth advance limit; text is measured while advance is less than maxWidth
1360 @param measuredWidth returns the width of the text less than or equal to maxWidth
1361 @return bytes of text that fit, always less than or equal to length
1362 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001363 size_t breakText(const void* text, size_t length, SkScalar maxWidth,
Ben Wagnera93a14a2017-08-28 10:34:05 -04001364 SkScalar* measuredWidth = nullptr) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001365
Cary Clark50fa3ff2017-07-26 10:15:23 -04001366 /** Retrieves the advance and bounds for each glyph in text, and returns
1367 the glyph count in text.
1368 Both widths and bounds may be nullptr.
1369 If widths is not nullptr, widths must be an array of glyph count entries.
1370 if bounds is not nullptr, bounds must be an array of glyph count entries.
1371 If kVerticalText_Flag is clear, widths returns the horizontal advance.
1372 If kVerticalText_Flag is set, widths returns the vertical advance.
1373 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
1374 and text size to scale the widths and bounds.
1375 Does not scale the advance by fake bold or SkPathEffect.
Cary Clark23890a92017-07-27 16:30:51 -04001376 Does include fake bold and SkPathEffect in the bounds.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001377
1378 @param text character codes or glyph indices to be measured
1379 @param byteLength number of bytes of text to measure
1380 @param widths returns text advances for each glyph; may be nullptr
1381 @param bounds returns bounds for each glyph relative to (0, 0); may be nullptr
1382 @return glyph count in text
1383 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001384 int getTextWidths(const void* text, size_t byteLength, SkScalar widths[],
Ben Wagnera93a14a2017-08-28 10:34:05 -04001385 SkRect bounds[] = nullptr) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001386
Cary Clark50fa3ff2017-07-26 10:15:23 -04001387 /** Returns the geometry as SkPath equivalent to the drawn text.
1388 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1389 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1390 All of the glyph paths are stored in path.
Cary Clark579985c2017-07-31 11:48:27 -04001391 Uses x, y, and SkPaint::Align to position path.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001392
1393 @param text character codes or glyph indices
1394 @param length number of bytes of text
1395 @param x x-coordinate of the origin of the text
1396 @param y y-coordinate of the origin of the text
1397 @param path geometry of the glyphs
1398 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001399 void getTextPath(const void* text, size_t length, SkScalar x, SkScalar y,
1400 SkPath* path) const;
1401
Cary Clark50fa3ff2017-07-26 10:15:23 -04001402 /** Returns the geometry as SkPath equivalent to the drawn text.
1403 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1404 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1405 All of the glyph paths are stored in path.
1406 Uses pos array and SkPaint::Align to position path.
1407 pos contains a position for each glyph.
1408
1409 @param text character codes or glyph indices
1410 @param length number of bytes of text
1411 @param pos positions of each glyph
1412 @param path geometry of the glyphs
1413 */
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001414 void getPosTextPath(const void* text, size_t length,
reed@google.comca0062e2012-07-20 11:20:32 +00001415 const SkPoint pos[], SkPath* path) const;
1416
Cary Clark50fa3ff2017-07-26 10:15:23 -04001417 /** Returns the number of intervals that intersect bounds.
1418 bounds describes a pair of lines parallel to the text advance.
1419 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1420 the string.
1421 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1422 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1423 Uses x, y, and SkPaint::Align to position intervals.
1424
1425 Pass nullptr for intervals to determine the size of the interval array.
1426
1427 intervals are cached to improve performance for multiple calls.
1428
1429 @param text character codes or glyph indices
1430 @param length number of bytes of text
1431 @param x x-coordinate of the origin of the text
1432 @param y y-coordinate of the origin of the text
1433 @param bounds lower and upper line parallel to the advance
1434 @param intervals returned intersections; may be nullptr
1435 @return number of intersections; may be zero
1436 */
caryclark0449bcf2016-02-09 13:25:45 -08001437 int getTextIntercepts(const void* text, size_t length, SkScalar x, SkScalar y,
1438 const SkScalar bounds[2], SkScalar* intervals) const;
1439
Cary Clark50fa3ff2017-07-26 10:15:23 -04001440 /** Returns the number of intervals that intersect bounds.
1441 bounds describes a pair of lines parallel to the text advance.
1442 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1443 the string.
1444 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1445 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1446 Uses pos array and SkPaint::Align to position intervals.
1447
1448 Pass nullptr for intervals to determine the size of the interval array.
1449
1450 intervals are cached to improve performance for multiple calls.
1451
1452 @param text character codes or glyph indices
1453 @param length number of bytes of text
1454 @param pos positions of each glyph
1455 @param bounds lower and upper line parallel to the advance
1456 @param intervals returned intersections; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -04001457 @return number of intersections; may be zero
Cary Clark50fa3ff2017-07-26 10:15:23 -04001458 */
caryclark0449bcf2016-02-09 13:25:45 -08001459 int getPosTextIntercepts(const void* text, size_t length, const SkPoint pos[],
1460 const SkScalar bounds[2], SkScalar* intervals) const;
1461
Cary Clark50fa3ff2017-07-26 10:15:23 -04001462 /** Returns the number of intervals that intersect bounds.
1463 bounds describes a pair of lines parallel to the text advance.
1464 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1465 the string.
1466 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1467 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1468 Uses xpos array, constY, and SkPaint::Align to position intervals.
1469
1470 Pass nullptr for intervals to determine the size of the interval array.
1471
1472 intervals are cached to improve performance for multiple calls.
1473
1474 @param text character codes or glyph indices
1475 @param length number of bytes of text
1476 @param xpos positions of each glyph in x
1477 @param constY position of each glyph in y
1478 @param bounds lower and upper line parallel to the advance
1479 @param intervals returned intersections; may be nullptr
1480 @return number of intersections; may be zero
1481 */
fmalitaeae6a912016-07-28 09:47:24 -07001482 int getPosTextHIntercepts(const void* text, size_t length, const SkScalar xpos[],
1483 SkScalar constY, const SkScalar bounds[2], SkScalar* intervals) const;
1484
Cary Clark50fa3ff2017-07-26 10:15:23 -04001485 /** Returns the number of intervals that intersect bounds.
1486 bounds describes a pair of lines parallel to the text advance.
1487 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1488 the string.
Cary Clark2823f9f2018-01-03 10:00:34 -05001489 Uses SkTypeface to get the glyph paths,
Cary Clark50fa3ff2017-07-26 10:15:23 -04001490 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
Cary Clarkb7da7232017-09-01 13:49:54 -04001491 Uses run array and SkPaint::Align to position intervals.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001492
Cary Clark2823f9f2018-01-03 10:00:34 -05001493 SkPaint::TextEncoding must be set to SkPaint::kGlyphID_TextEncoding.
1494
Cary Clark50fa3ff2017-07-26 10:15:23 -04001495 Pass nullptr for intervals to determine the size of the interval array.
1496
1497 intervals are cached to improve performance for multiple calls.
1498
Cary Clark8a02b0b2017-09-21 12:28:43 -04001499 @param blob glyphs, positions, and text paint attributes
Cary Clark50fa3ff2017-07-26 10:15:23 -04001500 @param bounds lower and upper line parallel to the advance
1501 @param intervals returned intersections; may be nullptr
1502 @return number of intersections; may be zero
1503 */
fmalitaeae6a912016-07-28 09:47:24 -07001504 int getTextBlobIntercepts(const SkTextBlob* blob, const SkScalar bounds[2],
1505 SkScalar* intervals) const;
1506
Cary Clark50fa3ff2017-07-26 10:15:23 -04001507 /** Returns the union of bounds of all glyphs.
1508 Returned dimensions are computed by font manager from font data,
Cary Clark579985c2017-07-31 11:48:27 -04001509 ignoring SkPaint::Hinting. Includes text size, text scale x,
Cary Clark50fa3ff2017-07-26 10:15:23 -04001510 and text skew x, but not fake bold or SkPathEffect.
1511
1512 If text size is large, text scale x is one, and text skew x is zero,
Cary Clark579985c2017-07-31 11:48:27 -04001513 returns the same bounds as SkPaint::FontMetrics { FontMetrics::fXMin,
Cary Clark50fa3ff2017-07-26 10:15:23 -04001514 FontMetrics::fTop, FontMetrics::fXMax, FontMetrics::fBottom }.
1515
1516 @return union of bounds of all glyphs
1517 */
reed8893e5f2014-12-15 13:27:26 -08001518 SkRect getFontBounds() const;
1519
Cary Clark579985c2017-07-31 11:48:27 -04001520 /** Returns true if SkPaint prevents all drawing;
1521 otherwise, the SkPaint may or may not allow drawing.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001522
Cary Clarkb7da7232017-09-01 13:49:54 -04001523 Returns true if, for example, SkBlendMode combined with color alpha computes a
1524 new alpha of zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001525
1526 @return true if SkPaint prevents all drawing
1527 */
reed@google.com632e1a22011-10-06 12:37:00 +00001528 bool nothingToDraw() const;
1529
Cary Clark2823f9f2018-01-03 10:00:34 -05001530 /** (to be made private)
Cary Clark50fa3ff2017-07-26 10:15:23 -04001531 Returns true if SkPaint does not include elements requiring extensive computation
1532 to compute SkBaseDevice bounds of drawn geometry. For instance, SkPaint with SkPathEffect
1533 always returns false.
reed@google.comd5f20792012-05-16 14:15:02 +00001534
Cary Clark50fa3ff2017-07-26 10:15:23 -04001535 @return true if SkPaint allows for fast computation of bounds
1536 */
senorblanco0abdf762015-08-20 11:10:41 -07001537 bool canComputeFastBounds() const;
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001538
Cary Clark2823f9f2018-01-03 10:00:34 -05001539 /** (to be made private)
Cary Clark579985c2017-07-31 11:48:27 -04001540 Only call this if canComputeFastBounds() returned true. This takes a
Cary Clark50fa3ff2017-07-26 10:15:23 -04001541 raw rectangle (the raw bounds of a shape), and adjusts it for stylistic
1542 effects in the paint (e.g. stroking). If needed, it uses the storage
Cary Clarkb7da7232017-09-01 13:49:54 -04001543 parameter. It returns the adjusted bounds that can then be used
Cary Clark50fa3ff2017-07-26 10:15:23 -04001544 for SkCanvas::quickReject tests.
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001545
Cary Clarkb7da7232017-09-01 13:49:54 -04001546 The returned SkRect will either be orig or storage, thus the caller
Cary Clark50fa3ff2017-07-26 10:15:23 -04001547 should not rely on storage being set to the result, but should always
Cary Clarkb7da7232017-09-01 13:49:54 -04001548 use the returned value. It is legal for orig and storage to be the same
1549 SkRect.
Cary Clark2823f9f2018-01-03 10:00:34 -05001550 e.g.
1551 if (paint.canComputeFastBounds()) {
1552 SkRect r, storage;
1553 path.computeBounds(&r, SkPath::kFast_BoundsType);
1554 const SkRect& fastR = paint.computeFastBounds(r, &storage);
1555 if (canvas->quickReject(fastR, ...)) {
1556 // don't draw the path
1557 }
1558 }
Cary Clark50fa3ff2017-07-26 10:15:23 -04001559
1560 @param orig geometry modified by SkPaint when drawn
1561 @param storage computed bounds of geometry; may not be nullptr
1562 @return fast computed bounds
1563 */
reed@google.coma584aed2012-05-16 14:06:02 +00001564 const SkRect& computeFastBounds(const SkRect& orig, SkRect* storage) const {
Brian Osman60751d72017-05-12 11:21:36 -04001565 // Things like stroking, etc... will do math on the bounds rect, assuming that it's sorted.
1566 SkASSERT(orig.isSorted());
reed@google.coma584aed2012-05-16 14:06:02 +00001567 SkPaint::Style style = this->getStyle();
1568 // ultra fast-case: filling with no effects that affect geometry
1569 if (kFill_Style == style) {
1570 uintptr_t effects = reinterpret_cast<uintptr_t>(this->getLooper());
1571 effects |= reinterpret_cast<uintptr_t>(this->getMaskFilter());
1572 effects |= reinterpret_cast<uintptr_t>(this->getPathEffect());
senorblanco@chromium.org336d1d72014-01-27 21:03:17 +00001573 effects |= reinterpret_cast<uintptr_t>(this->getImageFilter());
reed@google.coma584aed2012-05-16 14:06:02 +00001574 if (!effects) {
1575 return orig;
1576 }
1577 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001578
reed@google.coma584aed2012-05-16 14:06:02 +00001579 return this->doComputeFastBounds(orig, storage, style);
1580 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001581
Cary Clark2823f9f2018-01-03 10:00:34 -05001582 /** (to be made private)
Cary Clark50fa3ff2017-07-26 10:15:23 -04001583
1584 @param orig geometry modified by SkPaint when drawn
1585 @param storage computed bounds of geometry
1586 @return fast computed bounds
1587 */
reed@google.coma584aed2012-05-16 14:06:02 +00001588 const SkRect& computeFastStrokeBounds(const SkRect& orig,
1589 SkRect* storage) const {
reed@google.com73a02582012-05-16 19:21:12 +00001590 return this->doComputeFastBounds(orig, storage, kStroke_Style);
reed@google.coma584aed2012-05-16 14:06:02 +00001591 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001592
Cary Clark2823f9f2018-01-03 10:00:34 -05001593 /** (to be made private)
Cary Clarkb7da7232017-09-01 13:49:54 -04001594 Computes the bounds, overriding the SkPaint SkPaint::Style. This can be used to
1595 account for additional width required by stroking orig, without
1596 altering SkPaint::Style set to fill.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001597
1598 @param orig geometry modified by SkPaint when drawn
1599 @param storage computed bounds of geometry
1600 @param style overrides SkPaint::Style
1601 @return fast computed bounds
1602 */
reed@google.coma584aed2012-05-16 14:06:02 +00001603 const SkRect& doComputeFastBounds(const SkRect& orig, SkRect* storage,
Cary Clark0418a882017-05-10 09:07:42 -04001604 Style style) const;
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001605
Cary Clark99885412018-04-05 13:09:58 -04001606 /** Creates string representation of SkPaint. The representation is read by
1607 internal debugging tools.
Cary Clark0418a882017-05-10 09:07:42 -04001608
Cary Clarkb7da7232017-09-01 13:49:54 -04001609 @param str storage for string representation of SkPaint
Cary Clark50fa3ff2017-07-26 10:15:23 -04001610 */
Cary Clark99885412018-04-05 13:09:58 -04001611 void toString(SkString* str) const;
robertphillips@google.com791f12e2013-02-14 13:53:53 +00001612
reed@google.comd5f20792012-05-16 14:15:02 +00001613private:
Cary Clark0418a882017-05-10 09:07:42 -04001614 typedef const SkGlyph& (*GlyphCacheProc)(SkGlyphCache*, const char**);
1615
reeda5ab9ec2016-03-06 18:10:48 -08001616 sk_sp<SkTypeface> fTypeface;
1617 sk_sp<SkPathEffect> fPathEffect;
1618 sk_sp<SkShader> fShader;
reeda5ab9ec2016-03-06 18:10:48 -08001619 sk_sp<SkMaskFilter> fMaskFilter;
1620 sk_sp<SkColorFilter> fColorFilter;
reed46f2d0a2016-09-11 05:40:31 -07001621 sk_sp<SkDrawLooper> fDrawLooper;
reeda5ab9ec2016-03-06 18:10:48 -08001622 sk_sp<SkImageFilter> fImageFilter;
reed@google.comd5f20792012-05-16 14:15:02 +00001623
commit-bot@chromium.orge8807f42014-03-24 23:03:11 +00001624 SkScalar fTextSize;
1625 SkScalar fTextScaleX;
1626 SkScalar fTextSkewX;
reed@google.comd5f20792012-05-16 14:15:02 +00001627 SkColor fColor;
1628 SkScalar fWidth;
1629 SkScalar fMiterLimit;
Mike Reed71fecc32016-11-18 17:19:54 -05001630 uint32_t fBlendMode; // just need 5-6 bits
commit-bot@chromium.orgaca1c012014-02-21 18:18:05 +00001631 union {
1632 struct {
1633 // all of these bitfields should add up to 32
1634 unsigned fFlags : 16;
1635 unsigned fTextAlign : 2;
1636 unsigned fCapType : 2;
1637 unsigned fJoinType : 2;
1638 unsigned fStyle : 2;
1639 unsigned fTextEncoding : 2; // 3 values
1640 unsigned fHinting : 2;
reedf803da12015-01-23 05:58:07 -08001641 unsigned fFilterQuality : 2;
commit-bot@chromium.org85faf502014-04-16 12:58:02 +00001642 //unsigned fFreeBits : 2;
reedf59eab22014-07-14 14:39:15 -07001643 } fBitfields;
1644 uint32_t fBitfieldsUInt;
commit-bot@chromium.orgaca1c012014-02-21 18:18:05 +00001645 };
commit-bot@chromium.orge8807f42014-03-24 23:03:11 +00001646
robertphillipse34f17d2016-07-19 07:59:22 -07001647 static GlyphCacheProc GetGlyphCacheProc(TextEncoding encoding,
1648 bool isDevKern,
1649 bool needFullMetrics);
reed@google.comd5f20792012-05-16 14:15:02 +00001650
1651 SkScalar measure_text(SkGlyphCache*, const char* text, size_t length,
1652 int* count, SkRect* bounds) const;
1653
joshualitt9e36c1a2015-04-14 12:17:27 -07001654 /*
1655 * The luminance color is used to determine which Gamma Canonical color to map to. This is
1656 * really only used by backends which want to cache glyph masks, and need some way to know if
1657 * they need to generate new masks based off a given color.
1658 */
1659 SkColor computeLuminanceColor() const;
1660
Cary Clarkd98f78c2018-04-26 08:32:37 -04001661 /* This is the size we use when we ask for a glyph's path. We then
1662 * post-transform it as we draw to match the request.
1663 * This is done to try to re-use cache entries for the path.
1664 *
1665 * This value is somewhat arbitrary. In theory, it could be 1, since
1666 * we store paths as floats. However, we get the path from the font
1667 * scaler, and it may represent its paths as fixed-point (or 26.6),
1668 * so we shouldn't ask for something too big (might overflow 16.16)
1669 * or too small (underflow 26.6).
1670 *
1671 * This value could track kMaxSizeForGlyphCache, assuming the above
1672 * constraints, but since we ask for unhinted paths, the two values
1673 * need not match per-se.
1674 */
1675 static constexpr int kCanonicalTextSizeForPaths = 64;
reed@google.comed43dff2013-06-04 16:56:27 +00001676
Jim Van Verthc65b65d2018-01-16 16:26:35 -05001677 static bool TooBigToUseCache(const SkMatrix& ctm, const SkMatrix& textM, SkScalar maxLimit);
reed@google.comed43dff2013-06-04 16:56:27 +00001678
reed@google.comed43dff2013-06-04 16:56:27 +00001679 // Set flags/hinting/textSize up to use for drawing text as paths.
1680 // Returns scale factor to restore the original textSize, since will will
1681 // have change it to kCanonicalTextSizeForPaths.
1682 SkScalar setupForAsPaths();
1683
Jim Van Verthc65b65d2018-01-16 16:26:35 -05001684 static SkScalar MaxCacheSize2(SkScalar maxLimit);
reed@google.comed43dff2013-06-04 16:56:27 +00001685
Herb Derby980a48d2018-01-23 13:39:21 -05001686 friend class GrAtlasTextBlob;
1687 friend class GrAtlasTextContext;
1688 friend class GrGLPathRendering;
1689 friend class GrPathRendering;
Herb Derby980a48d2018-01-23 13:39:21 -05001690 friend class GrTextUtils;
jvanverth2d2a68c2014-06-10 06:42:56 -07001691 friend class SkAutoGlyphCacheNoGamma;
Herb Derby980a48d2018-01-23 13:39:21 -05001692 friend class SkCanonicalizePaint;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001693 friend class SkCanvas;
1694 friend class SkDraw;
Cary Clark60ca8672018-03-06 15:09:27 -05001695 friend class SkPaintPriv;
vandebo@chromium.org28be72b2010-11-11 21:37:00 +00001696 friend class SkPDFDevice;
Herb Derby980a48d2018-01-23 13:39:21 -05001697 friend class SkScalerContext; // for computeLuminanceColor()
caryclark0449bcf2016-02-09 13:25:45 -08001698 friend class SkTextBaseIter;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001699};
1700
reed@android.com8a1c16f2008-12-17 15:59:43 +00001701#endif