blob: 4c82e50f0068e5d855f04a75e25bfcf8cb5cb747 [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
Cary Clark91499542018-06-08 11:49:19 -04008/* Generated by tools/bookmaker from include/core/SkPaint.h and docs/SkPaint_Reference.bmh
9 on 2018-06-08 11:48:28. Additional documentation and examples can be found at:
10 https://skia.org/user/api/SkPaint_Reference
11
12 You may edit either file directly. Structural changes to public interfaces require
13 editing both files. After editing docs/SkPaint_Reference.bmh, run:
14 bookmaker -b docs -i include/core/SkPaint.h -p
15 to create an updated version of this file.
16 */
17
reed@android.com8a1c16f2008-12-17 15:59:43 +000018#ifndef SkPaint_DEFINED
19#define SkPaint_DEFINED
20
reed374772b2016-10-05 17:33:02 -070021#include "SkBlendMode.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000022#include "SkColor.h"
reedf803da12015-01-23 05:58:07 -080023#include "SkFilterQuality.h"
reed@google.comed43dff2013-06-04 16:56:27 +000024#include "SkMatrix.h"
Mike Reed71fecc32016-11-18 17:19:54 -050025#include "SkRefCnt.h"
reed@android.coma0f5d152009-06-22 17:38:10 +000026
joshualitt2b6acb42015-04-01 11:30:27 -070027class SkAutoDescriptor;
reed@android.com8a1c16f2008-12-17 15:59:43 +000028class SkColorFilter;
joshualittfd450792015-03-13 08:38:43 -070029class SkData;
reed@android.com8a1c16f2008-12-17 15:59:43 +000030class SkDescriptor;
senorblanco0abdf762015-08-20 11:10:41 -070031class SkDrawLooper;
herbb69d0e02015-02-25 06:47:06 -080032class SkGlyph;
reed@android.com8a1c16f2008-12-17 15:59:43 +000033struct SkRect;
34class SkGlyphCache;
reed@google.com15356a62011-11-03 19:29:08 +000035class SkImageFilter;
reed@android.com8a1c16f2008-12-17 15:59:43 +000036class SkMaskFilter;
reed@android.com8a1c16f2008-12-17 15:59:43 +000037class SkPath;
38class SkPathEffect;
djsollen@google.comc73dd5c2012-08-07 15:54:32 +000039struct SkPoint;
reed@android.com8a1c16f2008-12-17 15:59:43 +000040class SkShader;
robertphillipsfcf78292015-06-19 11:49:52 -070041class SkSurfaceProps;
fmalitaeae6a912016-07-28 09:47:24 -070042class SkTextBlob;
reed@android.com8a1c16f2008-12-17 15:59:43 +000043class SkTypeface;
reed@android.com8a1c16f2008-12-17 15:59:43 +000044
reed@android.com8a1c16f2008-12-17 15:59:43 +000045/** \class SkPaint
Cary Clark50fa3ff2017-07-26 10:15:23 -040046 SkPaint controls options applied when drawing and measuring. SkPaint collects all
47 options outside of the SkCanvas clip and SkCanvas matrix.
reed@android.com8a1c16f2008-12-17 15:59:43 +000048
Cary Clark50fa3ff2017-07-26 10:15:23 -040049 Various options apply to text, strokes and fills, and images.
50
51 Some options may not be implemented on all platforms; in these cases, setting
52 the option has no effect. Some options are conveniences that duplicate SkCanvas
53 functionality; for instance, text size is identical to matrix scale.
54
55 SkPaint options are rarely exclusive; each option modifies a stage of the drawing
Cary Clark23890a92017-07-27 16:30:51 -040056 pipeline and multiple pipeline stages may be affected by a single SkPaint.
Cary Clark50fa3ff2017-07-26 10:15:23 -040057
Cary Clark23890a92017-07-27 16:30:51 -040058 SkPaint collects effects and filters that describe single-pass and multiple-pass
Cary Clark50fa3ff2017-07-26 10:15:23 -040059 algorithms that alter the drawing geometry, color, and transparency. For instance,
60 SkPaint does not directly implement dashing or blur, but contains the objects that do so.
61
62 The objects contained by SkPaint are opaque, and cannot be edited outside of the SkPaint
63 to affect it. The implementation is free to defer computations associated with the
64 SkPaint, or ignore them altogether. For instance, some GPU implementations draw all
Cary Clarkb7da7232017-09-01 13:49:54 -040065 SkPath geometries with anti-aliasing, regardless of how SkPaint::kAntiAlias_Flag
66 is set in SkPaint.
Cary Clark50fa3ff2017-07-26 10:15:23 -040067
68 SkPaint describes a single color, a single font, a single image quality, and so on.
69 Multiple colors are drawn either by using multiple paints or with objects like
70 SkShader attached to SkPaint.
reed@android.com8a1c16f2008-12-17 15:59:43 +000071*/
ctguil@chromium.org7ffb1b22011-03-15 21:27:08 +000072class SK_API SkPaint {
reed@android.com8a1c16f2008-12-17 15:59:43 +000073public:
Cary Clark50fa3ff2017-07-26 10:15:23 -040074
75 /** Constructs SkPaint with default values.
76
77 @return default initialized SkPaint
78 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000079 SkPaint();
Cary Clark50fa3ff2017-07-26 10:15:23 -040080
81 /** Makes a shallow copy of SkPaint. SkTypeface, SkPathEffect, SkShader,
Mike Reed8ad91a92018-01-19 19:09:32 -050082 SkMaskFilter, SkColorFilter, SkDrawLooper, and SkImageFilter are shared
Cary Clarkb7da7232017-09-01 13:49:54 -040083 between the original paint and the copy. Objects containing SkRefCnt increment
84 their references by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -040085
Mike Reed8ad91a92018-01-19 19:09:32 -050086 The referenced objects SkPathEffect, SkShader, SkMaskFilter, SkColorFilter,
Cary Clark50fa3ff2017-07-26 10:15:23 -040087 SkDrawLooper, and SkImageFilter cannot be modified after they are created.
88 This prevents objects with SkRefCnt from being modified once SkPaint refers to them.
89
90 @param paint original to copy
91 @return shallow copy of paint
92 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000093 SkPaint(const SkPaint& paint);
Cary Clark50fa3ff2017-07-26 10:15:23 -040094
Cary Clark8a02b0b2017-09-21 12:28:43 -040095 /** Implements a move constructor to avoid increasing the reference counts
Cary Clark50fa3ff2017-07-26 10:15:23 -040096 of objects referenced by the paint.
97
98 After the call, paint is undefined, and can be safely destructed.
99
100 @param paint original to move
101 @return content of paint
102 */
bungemanccce0e02016-02-07 14:37:23 -0800103 SkPaint(SkPaint&& paint);
Cary Clark50fa3ff2017-07-26 10:15:23 -0400104
105 /** Decreases SkPaint SkRefCnt of owned objects: SkTypeface, SkPathEffect, SkShader,
Mike Reed8ad91a92018-01-19 19:09:32 -0500106 SkMaskFilter, SkColorFilter, SkDrawLooper, and SkImageFilter. If the
Cary Clarkb7da7232017-09-01 13:49:54 -0400107 objects containing SkRefCnt go to zero, they are deleted.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400108 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000109 ~SkPaint();
110
Cary Clark50fa3ff2017-07-26 10:15:23 -0400111 /** Makes a shallow copy of SkPaint. SkTypeface, SkPathEffect, SkShader,
Mike Reed8ad91a92018-01-19 19:09:32 -0500112 SkMaskFilter, SkColorFilter, SkDrawLooper, and SkImageFilter are shared
Cary Clarkb7da7232017-09-01 13:49:54 -0400113 between the original paint and the copy. Objects containing SkRefCnt in the
Cary Clark50fa3ff2017-07-26 10:15:23 -0400114 prior destination are decreased by one, and the referenced objects are deleted if the
Cary Clarkb7da7232017-09-01 13:49:54 -0400115 resulting count is zero. Objects containing SkRefCnt in the parameter paint
116 are increased by one. paint is unmodified.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400117
118 @param paint original to copy
119 @return content of paint
120 */
Cary Clark0418a882017-05-10 09:07:42 -0400121 SkPaint& operator=(const SkPaint& paint);
Cary Clark50fa3ff2017-07-26 10:15:23 -0400122
Cary Clark8a02b0b2017-09-21 12:28:43 -0400123 /** Moves the paint to avoid increasing the reference counts
Cary Clarkb7da7232017-09-01 13:49:54 -0400124 of objects referenced by the paint parameter. Objects containing SkRefCnt in the
125 prior destination are decreased by one; those objects are deleted if the resulting count
126 is zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400127
128 After the call, paint is undefined, and can be safely destructed.
129
130 @param paint original to move
131 @return content of paint
132 */
Cary Clark0418a882017-05-10 09:07:42 -0400133 SkPaint& operator=(SkPaint&& paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000134
Cary Clark50fa3ff2017-07-26 10:15:23 -0400135 /** Compares a and b, and returns true if a and b are equivalent. May return false
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 equivalent
mtkleinbc97ef42014-08-25 10:10:47 -0700142 */
robertphillips@google.comb2657412013-08-07 22:36:29 +0000143 SK_API friend bool operator==(const SkPaint& a, const SkPaint& b);
Cary Clark50fa3ff2017-07-26 10:15:23 -0400144
145 /** Compares a and b, and returns true if a and b are not equivalent. May return true
Mike Reed8ad91a92018-01-19 19:09:32 -0500146 if SkTypeface, SkPathEffect, SkShader, SkMaskFilter, SkColorFilter,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400147 SkDrawLooper, or SkImageFilter have identical contents but different pointers.
148
149 @param a SkPaint to compare
150 @param b SkPaint to compare
151 @return true if SkPaint pair are not equivalent
152 */
robertphillips@google.comb2657412013-08-07 22:36:29 +0000153 friend bool operator!=(const SkPaint& a, const SkPaint& b) {
154 return !(a == b);
155 }
156
Cary Clark50fa3ff2017-07-26 10:15:23 -0400157 /** Returns a hash generated from SkPaint values and pointers.
158 Identical hashes guarantee that the paints are
159 equivalent, but differing hashes do not guarantee that the paints have differing
160 contents.
161
162 If operator==(const SkPaint& a, const SkPaint& b) returns true for two paints,
163 their hashes are also equal.
164
165 The hash returned is platform and implementation specific.
166
167 @return a shallow hash
168 */
mtkleinfb1fe4f2014-10-07 09:26:10 -0700169 uint32_t getHash() const;
170
Cary Clarkcc309eb2017-10-30 11:48:35 -0400171 /** Sets all SkPaint contents to their initial values. This is equivalent to replacing
172 SkPaint with the result of SkPaint().
reed@android.com8a1c16f2008-12-17 15:59:43 +0000173 */
174 void reset();
175
Cary Clark50fa3ff2017-07-26 10:15:23 -0400176 /** \enum SkPaint::Hinting
177 Hinting adjusts the glyph outlines so that the shape provides a uniform
178 look at a given point size on font engines that support it. Hinting may have a
179 muted effect or no effect at all depending on the platform.
180
181 The four levels roughly control corresponding features on platforms that use FreeType
182 as the font engine.
agl@chromium.org309485b2009-07-21 17:41:32 +0000183 */
184 enum Hinting {
Cary Clark462505f2018-05-30 09:20:29 -0400185 kNo_Hinting = 0, //!< glyph outlines unchanged
186 kSlight_Hinting = 1, //!< minimal modification to improve constrast
187 kNormal_Hinting = 2, //!< glyph outlines modified to improve constrast
188 kFull_Hinting = 3, //!< modifies glyph outlines for maximum constrast
agl@chromium.org309485b2009-07-21 17:41:32 +0000189 };
190
Cary Clark50fa3ff2017-07-26 10:15:23 -0400191 /** Returns level of glyph outline adjustment.
192
193 @return one of: kNo_Hinting, kSlight_Hinting, kNormal_Hinting, kFull_Hinting
194 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000195 Hinting getHinting() const {
reedf59eab22014-07-14 14:39:15 -0700196 return static_cast<Hinting>(fBitfields.fHinting);
agl@chromium.org309485b2009-07-21 17:41:32 +0000197 }
198
Cary Clark50fa3ff2017-07-26 10:15:23 -0400199 /** Sets level of glyph outline adjustment.
200 Does not check for valid values of hintingLevel.
201
202 @param hintingLevel one of: kNo_Hinting, kSlight_Hinting, kNormal_Hinting, kFull_Hinting
203 */
djsollen@google.comf5dbe2f2011-04-15 13:41:26 +0000204 void setHinting(Hinting hintingLevel);
agl@chromium.org309485b2009-07-21 17:41:32 +0000205
Cary Clark50fa3ff2017-07-26 10:15:23 -0400206 /** \enum SkPaint::Flags
207 The bit values stored in Flags.
208 The default value for Flags, normally zero, can be changed at compile time
209 with a custom definition of SkPaintDefaults_Flags.
210 All flags can be read and written explicitly; Flags allows manipulating
211 multiple settings at once.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000212 */
213 enum Flags {
Cary Clark1eace2d2017-07-31 07:52:43 -0400214 kAntiAlias_Flag = 0x01, //!< mask for setting anti-alias
215 kDither_Flag = 0x04, //!< mask for setting dither
Cary Clark50fa3ff2017-07-26 10:15:23 -0400216 kFakeBoldText_Flag = 0x20, //!< mask for setting fake bold
217 kLinearText_Flag = 0x40, //!< mask for setting linear text
218 kSubpixelText_Flag = 0x80, //!< mask for setting subpixel text
Cary Clark75959392018-02-27 10:22:04 -0500219 kLCDRenderText_Flag = 0x200, //!< mask for setting LCD text
Cary Clark50fa3ff2017-07-26 10:15:23 -0400220 kEmbeddedBitmapText_Flag = 0x400, //!< mask for setting font embedded bitmaps
221 kAutoHinting_Flag = 0x800, //!< mask for setting auto-hinting
222 kVerticalText_Flag = 0x1000, //!< mask for setting vertical text
Cary Clark462505f2018-05-30 09:20:29 -0400223 kAllFlags = 0xFFFF, //!< mask of all Flags
reed@android.com8a1c16f2008-12-17 15:59:43 +0000224 };
225
Cary Clark50fa3ff2017-07-26 10:15:23 -0400226 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Mike Reedddbd37e2017-02-21 15:07:44 -0500227 enum ReserveFlags {
Cary Clark462505f2018-05-30 09:20:29 -0400228 kUnderlineText_ReserveFlag = 0x08, //!< to be deprecated soon
229 kStrikeThruText_ReserveFlag = 0x10, //!< to be deprecated soon
Mike Reedddbd37e2017-02-21 15:07:44 -0500230 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400231 #endif
Mike Reedddbd37e2017-02-21 15:07:44 -0500232
Cary Clark50fa3ff2017-07-26 10:15:23 -0400233 /** Returns paint settings described by SkPaint::Flags. Each setting uses one
234 bit, and can be tested with SkPaint::Flags members.
235
236 @return zero, one, or more bits described by SkPaint::Flags
reed@android.com8a1c16f2008-12-17 15:59:43 +0000237 */
reedf59eab22014-07-14 14:39:15 -0700238 uint32_t getFlags() const { return fBitfields.fFlags; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000239
Cary Clark23890a92017-07-27 16:30:51 -0400240 /** Replaces SkPaint::Flags with flags, the union of the SkPaint::Flags members.
241 All SkPaint::Flags members may be cleared, or one or more may be set.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400242
243 @param flags union of SkPaint::Flags for SkPaint
reed@android.com8a1c16f2008-12-17 15:59:43 +0000244 */
245 void setFlags(uint32_t flags);
246
Cary Clark50fa3ff2017-07-26 10:15:23 -0400247 /** If true, pixels on the active edges of SkPath may be drawn with partial transparency.
248
Cary Clark579985c2017-07-31 11:48:27 -0400249 Equivalent to getFlags() masked with kAntiAlias_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400250
251 @return kAntiAlias_Flag state
252 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000253 bool isAntiAlias() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000254 return SkToBool(this->getFlags() & kAntiAlias_Flag);
255 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000256
Cary Clark50fa3ff2017-07-26 10:15:23 -0400257 /** Requests, but does not require, that SkPath edge pixels draw opaque or with
258 partial transparency.
259
260 Sets kAntiAlias_Flag if aa is true.
261 Clears kAntiAlias_Flag if aa is false.
262
263 @param aa setting for kAntiAlias_Flag
264 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000265 void setAntiAlias(bool aa);
reed@google.com9d07fec2011-03-16 20:02:59 +0000266
Cary Clark50fa3ff2017-07-26 10:15:23 -0400267 /** If true, color error may be distributed to smooth color transition.
268
Cary Clark579985c2017-07-31 11:48:27 -0400269 Equivalent to getFlags() masked with kDither_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400270
271 @return kDither_Flag state
272 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000273 bool isDither() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000274 return SkToBool(this->getFlags() & kDither_Flag);
275 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000276
Cary Clark50fa3ff2017-07-26 10:15:23 -0400277 /** Requests, but does not require, to distribute color error.
278
279 Sets kDither_Flag if dither is true.
280 Clears kDither_Flag if dither is false.
281
282 @param dither setting for kDither_Flag
283 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000284 void setDither(bool dither);
reed@google.com9d07fec2011-03-16 20:02:59 +0000285
Cary Clark50fa3ff2017-07-26 10:15:23 -0400286 /** If true, text is converted to SkPath before drawing and measuring.
287
Cary Clark579985c2017-07-31 11:48:27 -0400288 Equivalent to getFlags() masked with kLinearText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400289
290 @return kLinearText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000291 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000292 bool isLinearText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000293 return SkToBool(this->getFlags() & kLinearText_Flag);
294 }
295
Cary Clark50fa3ff2017-07-26 10:15:23 -0400296 /** If true, text is converted to SkPath before drawing and measuring.
297 By default, kLinearText_Flag is clear.
298
299 Sets kLinearText_Flag if linearText is true.
300 Clears kLinearText_Flag if linearText is false.
301
302 @param linearText setting for kLinearText_Flag
reed@android.com8a1c16f2008-12-17 15:59:43 +0000303 */
304 void setLinearText(bool linearText);
305
Cary Clark50fa3ff2017-07-26 10:15:23 -0400306 /** If true, glyphs at different sub-pixel positions may differ on pixel edge coverage.
307
Cary Clark579985c2017-07-31 11:48:27 -0400308 Equivalent to getFlags() masked with kSubpixelText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400309
310 @return kSubpixelText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000311 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000312 bool isSubpixelText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000313 return SkToBool(this->getFlags() & kSubpixelText_Flag);
314 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000315
Cary Clark50fa3ff2017-07-26 10:15:23 -0400316 /** Requests, but does not require, that glyphs respect sub-pixel positioning.
317
318 Sets kSubpixelText_Flag if subpixelText is true.
319 Clears kSubpixelText_Flag if subpixelText is false.
320
321 @param subpixelText setting for kSubpixelText_Flag
322 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000323 void setSubpixelText(bool subpixelText);
agl@chromium.org309485b2009-07-21 17:41:32 +0000324
Cary Clark50fa3ff2017-07-26 10:15:23 -0400325 /** If true, glyphs may use LCD striping to improve glyph edges.
326
327 Returns true if SkPaint::Flags kLCDRenderText_Flag is set.
328
329 @return kLCDRenderText_Flag state
330 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000331 bool isLCDRenderText() const {
agl@chromium.org309485b2009-07-21 17:41:32 +0000332 return SkToBool(this->getFlags() & kLCDRenderText_Flag);
333 }
334
Cary Clark50fa3ff2017-07-26 10:15:23 -0400335 /** Requests, but does not require, that glyphs use LCD striping for glyph edges.
336
337 Sets kLCDRenderText_Flag if lcdText is true.
338 Clears kLCDRenderText_Flag if lcdText is false.
339
340 @param lcdText setting for kLCDRenderText_Flag
341 */
reed@google.com84b437e2011-08-01 12:45:35 +0000342 void setLCDRenderText(bool lcdText);
agl@chromium.org309485b2009-07-21 17:41:32 +0000343
Cary Clark50fa3ff2017-07-26 10:15:23 -0400344 /** If true, font engine may return glyphs from font bitmaps instead of from outlines.
345
Cary Clark579985c2017-07-31 11:48:27 -0400346 Equivalent to getFlags() masked with kEmbeddedBitmapText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400347
348 @return kEmbeddedBitmapText_Flag state
349 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000350 bool isEmbeddedBitmapText() const {
agl@chromium.orge95c91e2010-01-04 18:27:55 +0000351 return SkToBool(this->getFlags() & kEmbeddedBitmapText_Flag);
352 }
353
Cary Clark50fa3ff2017-07-26 10:15:23 -0400354 /** Requests, but does not require, to use bitmaps in fonts instead of outlines.
355
356 Sets kEmbeddedBitmapText_Flag if useEmbeddedBitmapText is true.
357 Clears kEmbeddedBitmapText_Flag if useEmbeddedBitmapText is false.
358
359 @param useEmbeddedBitmapText setting for kEmbeddedBitmapText_Flag
agl@chromium.orge95c91e2010-01-04 18:27:55 +0000360 */
361 void setEmbeddedBitmapText(bool useEmbeddedBitmapText);
362
Cary Clark50fa3ff2017-07-26 10:15:23 -0400363 /** If true, and if SkPaint::Hinting is set to kNormal_Hinting or kFull_Hinting, and if
364 platform uses FreeType as the font manager, instruct the font manager to always hint
Cary Clark1eace2d2017-07-31 07:52:43 -0400365 glyphs.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400366
Cary Clark579985c2017-07-31 11:48:27 -0400367 Equivalent to getFlags() masked with kAutoHinting_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400368
369 @return kAutoHinting_Flag state
370 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000371 bool isAutohinted() const {
agl@chromium.orga2c71cb2010-06-17 20:49:17 +0000372 return SkToBool(this->getFlags() & kAutoHinting_Flag);
373 }
374
Cary Clark50fa3ff2017-07-26 10:15:23 -0400375 /** If SkPaint::Hinting is set to kNormal_Hinting or kFull_Hinting and useAutohinter is set,
Cary Clark1eace2d2017-07-31 07:52:43 -0400376 instruct the font manager to always hint glyphs.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400377 auto-hinting has no effect if SkPaint::Hinting is set to kNo_Hinting or
378 kSlight_Hinting.
379
Cary Clark579985c2017-07-31 11:48:27 -0400380 Only affects platforms that use FreeType as the font manager.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400381
382 Sets kAutoHinting_Flag if useAutohinter is true.
383 Clears kAutoHinting_Flag if useAutohinter is false.
384
385 @param useAutohinter setting for kAutoHinting_Flag
agl@chromium.orga2c71cb2010-06-17 20:49:17 +0000386 */
387 void setAutohinted(bool useAutohinter);
388
Cary Clark50fa3ff2017-07-26 10:15:23 -0400389 /** If true, glyphs are drawn top to bottom instead of left to right.
390
Cary Clark579985c2017-07-31 11:48:27 -0400391 Equivalent to getFlags() masked with kVerticalText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400392
393 @return kVerticalText_Flag state
394 */
reed@google.com830a23e2011-11-10 15:20:49 +0000395 bool isVerticalText() const {
396 return SkToBool(this->getFlags() & kVerticalText_Flag);
397 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000398
Cary Clark50fa3ff2017-07-26 10:15:23 -0400399 /** If true, text advance positions the next glyph below the previous glyph instead of to the
400 right of previous glyph.
401
402 Sets kVerticalText_Flag if vertical is true.
403 Clears kVerticalText_Flag if vertical is false.
404
405 @param verticalText setting for kVerticalText_Flag
406 */
Cary Clark0418a882017-05-10 09:07:42 -0400407 void setVerticalText(bool verticalText);
reed@google.com830a23e2011-11-10 15:20:49 +0000408
Cary Clark50fa3ff2017-07-26 10:15:23 -0400409 /** If true, approximate bold by increasing the stroke width when creating glyph bitmaps
410 from outlines.
411
Cary Clark579985c2017-07-31 11:48:27 -0400412 Equivalent to getFlags() masked with kFakeBoldText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400413
414 @return kFakeBoldText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000415 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000416 bool isFakeBoldText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000417 return SkToBool(this->getFlags() & kFakeBoldText_Flag);
418 }
419
Cary Clarkb7da7232017-09-01 13:49:54 -0400420 /** Use increased stroke width when creating glyph bitmaps to approximate a bold typeface.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400421
422 Sets kFakeBoldText_Flag if fakeBoldText is true.
423 Clears kFakeBoldText_Flag if fakeBoldText is false.
424
425 @param fakeBoldText setting for kFakeBoldText_Flag
reed@android.com8a1c16f2008-12-17 15:59:43 +0000426 */
427 void setFakeBoldText(bool fakeBoldText);
428
Cary Clark462505f2018-05-30 09:20:29 -0400429 /** Deprecated.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000430 */
Herb Derbyfcac00f2018-05-01 11:57:56 -0400431 bool isDevKernText() const { return false; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000432
Cary Clark462505f2018-05-30 09:20:29 -0400433 /** Deprecated.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000434 */
Herb Derbyfcac00f2018-05-01 11:57:56 -0400435 void setDevKernText(bool) { }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000436
Cary Clark50fa3ff2017-07-26 10:15:23 -0400437 /** Returns SkFilterQuality, the image filtering level. A lower setting
438 draws faster; a higher setting looks better when the image is scaled.
439
440 @return one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
441 kMedium_SkFilterQuality, kHigh_SkFilterQuality
442 */
reedf803da12015-01-23 05:58:07 -0800443 SkFilterQuality getFilterQuality() const {
444 return (SkFilterQuality)fBitfields.fFilterQuality;
445 }
mtkleinfe81e2d2015-09-09 07:35:42 -0700446
Cary Clark23890a92017-07-27 16:30:51 -0400447 /** Sets SkFilterQuality, the image filtering level. A lower setting
Cary Clark50fa3ff2017-07-26 10:15:23 -0400448 draws faster; a higher setting looks better when the image is scaled.
Cary Clark579985c2017-07-31 11:48:27 -0400449 Does not check to see if quality is valid.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400450
451 @param quality one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
452 kMedium_SkFilterQuality, kHigh_SkFilterQuality
453 */
reedf803da12015-01-23 05:58:07 -0800454 void setFilterQuality(SkFilterQuality quality);
reed@google.comc9683152013-07-18 13:47:01 +0000455
Cary Clark50fa3ff2017-07-26 10:15:23 -0400456 /** \enum SkPaint::Style
Cary Clark23890a92017-07-27 16:30:51 -0400457 Set Style to fill, stroke, or both fill and stroke geometry.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400458 The stroke and fill
459 share all paint attributes; for instance, they are drawn with the same color.
reed@google.com9d07fec2011-03-16 20:02:59 +0000460
Cary Clark50fa3ff2017-07-26 10:15:23 -0400461 Use kStrokeAndFill_Style to avoid hitting the same pixels twice with a stroke draw and
462 a fill draw.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000463 */
464 enum Style {
Cary Clark462505f2018-05-30 09:20:29 -0400465 kFill_Style, //!< set to fill geometry
466 kStroke_Style, //!< set to stroke geometry
467 kStrokeAndFill_Style, //!< sets to stroke and fill geometry
reed@android.com8a1c16f2008-12-17 15:59:43 +0000468 };
469
Cary Clark462505f2018-05-30 09:20:29 -0400470 /** May be used to verify that SkPaint::Style is a legal value.
Cary Clarkd98f78c2018-04-26 08:32:37 -0400471 */
472 static constexpr int kStyleCount = kStrokeAndFill_Style + 1;
Cary Clark50fa3ff2017-07-26 10:15:23 -0400473
474 /** Whether the geometry is filled, stroked, or filled and stroked.
475
476 @return one of:kFill_Style, kStroke_Style, kStrokeAndFill_Style
reed@android.com8a1c16f2008-12-17 15:59:43 +0000477 */
reedf59eab22014-07-14 14:39:15 -0700478 Style getStyle() const { return (Style)fBitfields.fStyle; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000479
Cary Clark50fa3ff2017-07-26 10:15:23 -0400480 /** Sets whether the geometry is filled, stroked, or filled and stroked.
481 Has no effect if style is not a legal SkPaint::Style value.
482
483 @param style one of: kFill_Style, kStroke_Style, kStrokeAndFill_Style
reed@android.com8a1c16f2008-12-17 15:59:43 +0000484 */
485 void setStyle(Style style);
486
Cary Clark50fa3ff2017-07-26 10:15:23 -0400487 /** Retrieves alpha and RGB, unpremultiplied, packed into 32 bits.
488 Use helpers SkColorGetA(), SkColorGetR(), SkColorGetG(), and SkColorGetB() to extract
489 a color component.
490
Cary Clark8a02b0b2017-09-21 12:28:43 -0400491 @return unpremultiplied ARGB
reed@android.com8a1c16f2008-12-17 15:59:43 +0000492 */
493 SkColor getColor() const { return fColor; }
494
Cary Clark50fa3ff2017-07-26 10:15:23 -0400495 /** Sets alpha and RGB used when stroking and filling. The color is a 32-bit value,
Cary Clarkb7da7232017-09-01 13:49:54 -0400496 unpremultiplied, packing 8-bit components for alpha, red, blue, and green.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400497
Cary Clark8a02b0b2017-09-21 12:28:43 -0400498 @param color unpremultiplied ARGB
reed@android.com8a1c16f2008-12-17 15:59:43 +0000499 */
500 void setColor(SkColor color);
501
Cary Clark1eace2d2017-07-31 07:52:43 -0400502 /** Retrieves alpha from the color used when stroking and filling.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400503
Cary Clark8a02b0b2017-09-21 12:28:43 -0400504 @return alpha ranging from zero, fully transparent, to 255, fully opaque
Cary Clark50fa3ff2017-07-26 10:15:23 -0400505 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000506 uint8_t getAlpha() const { return SkToU8(SkColorGetA(fColor)); }
reed@google.com9d07fec2011-03-16 20:02:59 +0000507
Cary Clark50fa3ff2017-07-26 10:15:23 -0400508 /** Replaces alpha, leaving RGB
509 unchanged. An out of range value triggers an assert in the debug
510 build. a is a value from zero to 255.
Cary Clark1eace2d2017-07-31 07:52:43 -0400511 a set to zero makes color fully transparent; a set to 255 makes color
Cary Clark50fa3ff2017-07-26 10:15:23 -0400512 fully opaque.
513
Cary Clark8a02b0b2017-09-21 12:28:43 -0400514 @param a alpha component of color
reed@android.com8a1c16f2008-12-17 15:59:43 +0000515 */
516 void setAlpha(U8CPU a);
517
Cary Clark1eace2d2017-07-31 07:52:43 -0400518 /** Sets color used when drawing solid fills. The color components range from 0 to 255.
Cary Clarkb7da7232017-09-01 13:49:54 -0400519 The color is unpremultiplied; alpha sets the transparency independent of RGB.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400520
Cary Clark462505f2018-05-30 09:20:29 -0400521 @param a amount of alpha, from fully transparent (0) to fully opaque (255)
522 @param r amount of red, from no red (0) to full red (255)
523 @param g amount of green, from no green (0) to full green (255)
524 @param b amount of blue, from no blue (0) to full blue (255)
reed@android.com8a1c16f2008-12-17 15:59:43 +0000525 */
526 void setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b);
527
Cary Clark50fa3ff2017-07-26 10:15:23 -0400528 /** Returns the thickness of the pen used by SkPaint to
529 outline the shape.
530
Cary Clark1eace2d2017-07-31 07:52:43 -0400531 @return zero for hairline, greater than zero for pen thickness
reed@android.com8a1c16f2008-12-17 15:59:43 +0000532 */
533 SkScalar getStrokeWidth() const { return fWidth; }
534
Cary Clark50fa3ff2017-07-26 10:15:23 -0400535 /** Sets the thickness of the pen used by the paint to
536 outline the shape.
537 Has no effect if width is less than zero.
538
Cary Clark1eace2d2017-07-31 07:52:43 -0400539 @param width zero thickness for hairline; greater than zero for pen thickness
reed@android.com8a1c16f2008-12-17 15:59:43 +0000540 */
541 void setStrokeWidth(SkScalar width);
542
Cary Clark50fa3ff2017-07-26 10:15:23 -0400543 /** The limit at which a sharp corner is drawn beveled.
544
545 @return zero and greater miter limit
reed@android.com8a1c16f2008-12-17 15:59:43 +0000546 */
547 SkScalar getStrokeMiter() const { return fMiterLimit; }
548
Cary Clark50fa3ff2017-07-26 10:15:23 -0400549 /** The limit at which a sharp corner is drawn beveled.
550 Valid values are zero and greater.
551 Has no effect if miter is less than zero.
552
553 @param miter zero and greater miter limit
reed@android.com8a1c16f2008-12-17 15:59:43 +0000554 */
555 void setStrokeMiter(SkScalar miter);
556
Cary Clark50fa3ff2017-07-26 10:15:23 -0400557 /** \enum SkPaint::Cap
558 Cap draws at the beginning and end of an open path contour.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000559 */
560 enum Cap {
Cary Clark462505f2018-05-30 09:20:29 -0400561 kButt_Cap, //!< no stroke extension
562 kRound_Cap, //!< adds circle
563 kSquare_Cap, //!< adds square
564 kLast_Cap = kSquare_Cap, //!< largest Cap value
565 kDefault_Cap = kButt_Cap, //!< equivalent to kButt_Cap
reed@android.com8a1c16f2008-12-17 15:59:43 +0000566 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400567
Cary Clark462505f2018-05-30 09:20:29 -0400568 /** May be used to verify that SkPaint::Cap is a legal value.
569 */
bsalomona7d85ba2016-07-06 11:54:59 -0700570 static constexpr int kCapCount = kLast_Cap + 1;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000571
Cary Clark50fa3ff2017-07-26 10:15:23 -0400572 /** \enum SkPaint::Join
Cary Clark1eace2d2017-07-31 07:52:43 -0400573 Join specifies how corners are drawn when a shape is stroked. Join
Cary Clark50fa3ff2017-07-26 10:15:23 -0400574 affects the four corners of a stroked rectangle, and the connected segments in a
575 stroked path.
576
577 Choose miter join to draw sharp corners. Choose round join to draw a circle with a
578 radius equal to the stroke width on top of the corner. Choose bevel join to minimally
579 connect the thick strokes.
580
581 The fill path constructed to describe the stroked path respects the join setting but may
582 not contain the actual join. For instance, a fill path constructed with round joins does
583 not necessarily include circles at each connected segment.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000584 */
585 enum Join {
Cary Clark462505f2018-05-30 09:20:29 -0400586 kMiter_Join, //!< extends to miter limit
587 kRound_Join, //!< adds circle
588 kBevel_Join, //!< connects outside edges
589 kLast_Join = kBevel_Join, //!< equivalent to the largest value for Join
590 kDefault_Join = kMiter_Join, //!< equivalent to kMiter_Join
reed@android.com8a1c16f2008-12-17 15:59:43 +0000591 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400592
Cary Clark462505f2018-05-30 09:20:29 -0400593 /** May be used to verify that SkPaint::Join is a legal value.
594 */
bsalomona7d85ba2016-07-06 11:54:59 -0700595 static constexpr int kJoinCount = kLast_Join + 1;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000596
Cary Clark50fa3ff2017-07-26 10:15:23 -0400597 /** The geometry drawn at the beginning and end of strokes.
598
599 @return one of: kButt_Cap, kRound_Cap, kSquare_Cap
reed@android.com8a1c16f2008-12-17 15:59:43 +0000600 */
reedf59eab22014-07-14 14:39:15 -0700601 Cap getStrokeCap() const { return (Cap)fBitfields.fCapType; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000602
Cary Clark50fa3ff2017-07-26 10:15:23 -0400603 /** The geometry drawn at the beginning and end of strokes.
604
605 @param cap one of: kButt_Cap, kRound_Cap, kSquare_Cap;
606 has no effect if cap is not valid
reed@android.com8a1c16f2008-12-17 15:59:43 +0000607 */
608 void setStrokeCap(Cap cap);
609
Cary Clark50fa3ff2017-07-26 10:15:23 -0400610 /** The geometry drawn at the corners of strokes.
611
612 @return one of: kMiter_Join, kRound_Join, kBevel_Join
reed@android.com8a1c16f2008-12-17 15:59:43 +0000613 */
reedf59eab22014-07-14 14:39:15 -0700614 Join getStrokeJoin() const { return (Join)fBitfields.fJoinType; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000615
Cary Clark50fa3ff2017-07-26 10:15:23 -0400616 /** The geometry drawn at the corners of strokes.
617
618 @param join one of: kMiter_Join, kRound_Join, kBevel_Join;
Cary Clark579985c2017-07-31 11:48:27 -0400619 otherwise, has no effect
reed@android.com8a1c16f2008-12-17 15:59:43 +0000620 */
621 void setStrokeJoin(Join join);
622
Cary Clark50fa3ff2017-07-26 10:15:23 -0400623 /** The filled equivalent of the stroked path.
624
625 @param src SkPath read to create a filled version
626 @param dst resulting SkPath; may be the same as src, but may not be nullptr
627 @param cullRect optional limit passed to SkPathEffect
628 @param resScale if > 1, increase precision, else if (0 < res < 1) reduce precision
629 to favor speed and size
Cary Clark1eace2d2017-07-31 07:52:43 -0400630 @return true if the path represents style fill, or false if it represents hairline
Cary Clark50fa3ff2017-07-26 10:15:23 -0400631 */
reed05d90442015-02-12 13:35:52 -0800632 bool getFillPath(const SkPath& src, SkPath* dst, const SkRect* cullRect,
633 SkScalar resScale = 1) const;
634
Cary Clark50fa3ff2017-07-26 10:15:23 -0400635 /** The filled equivalent of the stroked path.
636
Cary Clark23890a92017-07-27 16:30:51 -0400637 Replaces dst with the src path modified by SkPathEffect and style stroke.
638 SkPathEffect, if any, is not culled. stroke width is created with default precision.
639
640 @param src SkPath read to create a filled version
641 @param dst resulting SkPath dst may be the same as src, but may not be nullptr
Cary Clark1eace2d2017-07-31 07:52:43 -0400642 @return true if the path represents style fill, or false if it represents hairline
Cary Clark50fa3ff2017-07-26 10:15:23 -0400643 */
reed05d90442015-02-12 13:35:52 -0800644 bool getFillPath(const SkPath& src, SkPath* dst) const {
Ben Wagnera93a14a2017-08-28 10:34:05 -0400645 return this->getFillPath(src, dst, nullptr, 1);
reed05d90442015-02-12 13:35:52 -0800646 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000647
Cary Clark50fa3ff2017-07-26 10:15:23 -0400648 /** Optional colors used when filling a path, such as a gradient.
649
650 Does not alter SkShader SkRefCnt.
651
652 @return SkShader if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000653 */
reeda5ab9ec2016-03-06 18:10:48 -0800654 SkShader* getShader() const { return fShader.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400655
656 /** Optional colors used when filling a path, such as a gradient.
657
658 Increases SkShader SkRefCnt by one.
659
660 @return SkShader if previously set, nullptr otherwise
661 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500662 sk_sp<SkShader> refShader() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000663
Cary Clark50fa3ff2017-07-26 10:15:23 -0400664 /** Optional colors used when filling a path, such as a gradient.
665
Cary Clark8a02b0b2017-09-21 12:28:43 -0400666 Sets SkShader to shader, decreasing SkRefCnt of the previous SkShader.
667 Increments shader SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400668
Cary Clark1eace2d2017-07-31 07:52:43 -0400669 @param shader how geometry is filled with color; if nullptr, color is used instead
Cary Clark50fa3ff2017-07-26 10:15:23 -0400670 */
Cary Clark0418a882017-05-10 09:07:42 -0400671 void setShader(sk_sp<SkShader> shader);
reed@google.com9d07fec2011-03-16 20:02:59 +0000672
Cary Clark50fa3ff2017-07-26 10:15:23 -0400673 /** Returns SkColorFilter if set, or nullptr.
674 Does not alter SkColorFilter SkRefCnt.
675
676 @return SkColorFilter if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000677 */
reeda5ab9ec2016-03-06 18:10:48 -0800678 SkColorFilter* getColorFilter() const { return fColorFilter.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400679
680 /** Returns SkColorFilter if set, or nullptr.
681 Increases SkColorFilter SkRefCnt by one.
682
683 @return SkColorFilter if set, or nullptr
684 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500685 sk_sp<SkColorFilter> refColorFilter() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000686
Cary Clark8a02b0b2017-09-21 12:28:43 -0400687 /** Sets SkColorFilter to filter, decreasing SkRefCnt of the previous
688 SkColorFilter. Pass nullptr to clear SkColorFilter.
689
690 Increments filter SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400691
692 @param colorFilter SkColorFilter to apply to subsequent draw
reed@android.com8a1c16f2008-12-17 15:59:43 +0000693 */
Cary Clark0418a882017-05-10 09:07:42 -0400694 void setColorFilter(sk_sp<SkColorFilter> colorFilter);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000695
Cary Clark50fa3ff2017-07-26 10:15:23 -0400696 /** Returns SkBlendMode.
Cary Clark579985c2017-07-31 11:48:27 -0400697 By default, returns SkBlendMode::kSrcOver.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400698
699 @return mode used to combine source color with destination color
700 */
reed374772b2016-10-05 17:33:02 -0700701 SkBlendMode getBlendMode() const { return (SkBlendMode)fBlendMode; }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400702
703 /** Returns true if SkBlendMode is SkBlendMode::kSrcOver, the default.
704
705 @return true if SkBlendMode is SkBlendMode::kSrcOver
706 */
reed374772b2016-10-05 17:33:02 -0700707 bool isSrcOver() const { return (SkBlendMode)fBlendMode == SkBlendMode::kSrcOver; }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400708
709 /** Sets SkBlendMode to mode.
710 Does not check for valid input.
711
712 @param mode SkBlendMode used to combine source color and destination
713 */
reed374772b2016-10-05 17:33:02 -0700714 void setBlendMode(SkBlendMode mode) { fBlendMode = (unsigned)mode; }
reed@android.coma0f5d152009-06-22 17:38:10 +0000715
Cary Clark50fa3ff2017-07-26 10:15:23 -0400716 /** Returns SkPathEffect if set, or nullptr.
717 Does not alter SkPathEffect SkRefCnt.
718
719 @return SkPathEffect if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000720 */
reeda5ab9ec2016-03-06 18:10:48 -0800721 SkPathEffect* getPathEffect() const { return fPathEffect.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400722
723 /** Returns SkPathEffect if set, or nullptr.
724 Increases SkPathEffect SkRefCnt by one.
725
726 @return SkPathEffect if previously set, nullptr otherwise
727 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500728 sk_sp<SkPathEffect> refPathEffect() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000729
Cary Clark8a02b0b2017-09-21 12:28:43 -0400730 /** Sets SkPathEffect to pathEffect, decreasing SkRefCnt of the previous
731 SkPathEffect. Pass nullptr to leave the path geometry unaltered.
732
733 Increments pathEffect SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400734
735 @param pathEffect replace SkPath with a modification when drawn
reed@android.com8a1c16f2008-12-17 15:59:43 +0000736 */
Cary Clark0418a882017-05-10 09:07:42 -0400737 void setPathEffect(sk_sp<SkPathEffect> pathEffect);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000738
Cary Clark50fa3ff2017-07-26 10:15:23 -0400739 /** Returns SkMaskFilter if set, or nullptr.
740 Does not alter SkMaskFilter SkRefCnt.
741
742 @return SkMaskFilter if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000743 */
reeda5ab9ec2016-03-06 18:10:48 -0800744 SkMaskFilter* getMaskFilter() const { return fMaskFilter.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400745
746 /** Returns SkMaskFilter if set, or nullptr.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400747
Cary Clark50fa3ff2017-07-26 10:15:23 -0400748 Increases SkMaskFilter SkRefCnt by one.
749
750 @return SkMaskFilter if previously set, nullptr otherwise
751 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500752 sk_sp<SkMaskFilter> refMaskFilter() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000753
Cary Clark8a02b0b2017-09-21 12:28:43 -0400754 /** Sets SkMaskFilter to maskFilter, decreasing SkRefCnt of the previous
755 SkMaskFilter. Pass nullptr to clear SkMaskFilter and leave SkMaskFilter effect on
756 mask alpha unaltered.
757
Cary Clark75959392018-02-27 10:22:04 -0500758 Increments maskFilter SkRefCnt by one.
759
Cary Clark50fa3ff2017-07-26 10:15:23 -0400760 @param maskFilter modifies clipping mask generated from drawn geometry
reed@android.com8a1c16f2008-12-17 15:59:43 +0000761 */
Cary Clark0418a882017-05-10 09:07:42 -0400762 void setMaskFilter(sk_sp<SkMaskFilter> maskFilter);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000763
Cary Clark50fa3ff2017-07-26 10:15:23 -0400764 /** Returns SkTypeface if set, or nullptr.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400765 Increments SkTypeface SkRefCnt by one.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000766
Cary Clark50fa3ff2017-07-26 10:15:23 -0400767 @return SkTypeface if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000768 */
reeda5ab9ec2016-03-06 18:10:48 -0800769 SkTypeface* getTypeface() const { return fTypeface.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400770
771 /** Increases SkTypeface SkRefCnt by one.
772
773 @return SkTypeface if previously set, nullptr otherwise
774 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500775 sk_sp<SkTypeface> refTypeface() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000776
Cary Clark8a02b0b2017-09-21 12:28:43 -0400777 /** Sets SkTypeface to typeface, decreasing SkRefCnt of the previous SkTypeface.
778 Pass nullptr to clear SkTypeface and use the default typeface. Increments
779 typeface SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400780
781 @param typeface font and style used to draw text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000782 */
Cary Clark0418a882017-05-10 09:07:42 -0400783 void setTypeface(sk_sp<SkTypeface> typeface);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000784
Cary Clark50fa3ff2017-07-26 10:15:23 -0400785 /** Returns SkImageFilter if set, or nullptr.
786 Does not alter SkImageFilter SkRefCnt.
787
788 @return SkImageFilter if previously set, nullptr otherwise
789 */
reeda5ab9ec2016-03-06 18:10:48 -0800790 SkImageFilter* getImageFilter() const { return fImageFilter.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400791
792 /** Returns SkImageFilter if set, or nullptr.
793 Increases SkImageFilter SkRefCnt by one.
794
795 @return SkImageFilter if previously set, nullptr otherwise
796 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500797 sk_sp<SkImageFilter> refImageFilter() const;
Cary Clark50fa3ff2017-07-26 10:15:23 -0400798
Cary Clark8a02b0b2017-09-21 12:28:43 -0400799 /** Sets SkImageFilter to imageFilter, decreasing SkRefCnt of the previous
800 SkImageFilter. Pass nullptr to clear SkImageFilter, and remove SkImageFilter effect
Cary Clark50fa3ff2017-07-26 10:15:23 -0400801 on drawing.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400802
Cary Clark75959392018-02-27 10:22:04 -0500803 Increments imageFilter SkRefCnt by one.
804
Cary Clark50fa3ff2017-07-26 10:15:23 -0400805 @param imageFilter how SkImage is sampled when transformed
806 */
Cary Clark0418a882017-05-10 09:07:42 -0400807 void setImageFilter(sk_sp<SkImageFilter> imageFilter);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000808
Cary Clark50fa3ff2017-07-26 10:15:23 -0400809 /** Returns SkDrawLooper if set, or nullptr.
810 Does not alter SkDrawLooper SkRefCnt.
811
812 @return SkDrawLooper if previously set, nullptr otherwise
813 */
reed46f2d0a2016-09-11 05:40:31 -0700814 SkDrawLooper* getDrawLooper() const { return fDrawLooper.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400815
816 /** Returns SkDrawLooper if set, or nullptr.
817 Increases SkDrawLooper SkRefCnt by one.
818
819 @return SkDrawLooper if previously set, nullptr otherwise
820 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500821 sk_sp<SkDrawLooper> refDrawLooper() const;
822
Cary Clark23890a92017-07-27 16:30:51 -0400823 /** Deprecated.
Cary Clark75959392018-02-27 10:22:04 -0500824 (see skbug.com/6259)
Cary Clark50fa3ff2017-07-26 10:15:23 -0400825 */
reed46f2d0a2016-09-11 05:40:31 -0700826 SkDrawLooper* getLooper() const { return fDrawLooper.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400827
Cary Clark8a02b0b2017-09-21 12:28:43 -0400828 /** Sets SkDrawLooper to drawLooper, decreasing SkRefCnt of the previous
829 drawLooper. Pass nullptr to clear SkDrawLooper and leave SkDrawLooper effect on
830 drawing unaltered.
831
832 Increments drawLooper SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400833
Cary Clarkb7da7232017-09-01 13:49:54 -0400834 @param drawLooper iterates through drawing one or more time, altering SkPaint
Cary Clark50fa3ff2017-07-26 10:15:23 -0400835 */
Cary Clark0418a882017-05-10 09:07:42 -0400836 void setDrawLooper(sk_sp<SkDrawLooper> drawLooper);
Mike Reed09d94352016-10-31 15:11:04 -0400837
Cary Clark23890a92017-07-27 16:30:51 -0400838 /** Deprecated.
Cary Clark75959392018-02-27 10:22:04 -0500839 (see skbug.com/6259)
Cary Clark50fa3ff2017-07-26 10:15:23 -0400840 */
Cary Clark0418a882017-05-10 09:07:42 -0400841 void setLooper(sk_sp<SkDrawLooper> drawLooper);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000842
Cary Clark50fa3ff2017-07-26 10:15:23 -0400843 /** \enum SkPaint::Align
844 Align adjusts the text relative to the text position.
845 Align affects glyphs drawn with: SkCanvas::drawText, SkCanvas::drawPosText,
846 SkCanvas::drawPosTextH, SkCanvas::drawTextOnPath,
847 SkCanvas::drawTextOnPathHV, SkCanvas::drawTextRSXform, SkCanvas::drawTextBlob,
848 and SkCanvas::drawString;
Cary Clark579985c2017-07-31 11:48:27 -0400849 as well as calls that place text glyphs like getTextWidths() and getTextPath().
Cary Clark50fa3ff2017-07-26 10:15:23 -0400850
851 The text position is set by the font for both horizontal and vertical text.
852 Typically, for horizontal text, the position is to the left side of the glyph on the
Cary Clark23890a92017-07-27 16:30:51 -0400853 base line; and for vertical text, the position is the horizontal center of the glyph
Cary Clark50fa3ff2017-07-26 10:15:23 -0400854 at the caps height.
855
856 Align adjusts the glyph position to center it or move it to abut the position
857 using the metrics returned by the font.
858
859 Align defaults to kLeft_Align.
860 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000861 enum Align {
Cary Clark462505f2018-05-30 09:20:29 -0400862 kLeft_Align, //!< positions glyph by computed font offset
863 kCenter_Align, //!< centers line of glyphs by its width or height
864 kRight_Align, //!< moves lines of glyphs by its width or height
mike@reedtribe.orgddc813b2013-06-08 12:58:19 +0000865 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400866
Cary Clark462505f2018-05-30 09:20:29 -0400867 /** May be used to verify that align is a legal value.
868 */
869 static constexpr int kAlignCount = 3;
reed@google.com9d07fec2011-03-16 20:02:59 +0000870
Cary Clark50fa3ff2017-07-26 10:15:23 -0400871 /** Returns SkPaint::Align.
872 Returns kLeft_Align if SkPaint::Align has not been set.
873
874 @return text placement relative to position
reed@android.com8a1c16f2008-12-17 15:59:43 +0000875 */
reedf59eab22014-07-14 14:39:15 -0700876 Align getTextAlign() const { return (Align)fBitfields.fTextAlign; }
reed@google.com9d07fec2011-03-16 20:02:59 +0000877
Cary Clark50fa3ff2017-07-26 10:15:23 -0400878 /** Sets SkPaint::Align to align.
879 Has no effect if align is an invalid value.
880
881 @param align text placement relative to position
reed@android.com8a1c16f2008-12-17 15:59:43 +0000882 */
883 void setTextAlign(Align align);
884
Cary Clark50fa3ff2017-07-26 10:15:23 -0400885 /** Returns text size in points.
886
887 @return typographic height of text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000888 */
889 SkScalar getTextSize() const { return fTextSize; }
890
Cary Clark50fa3ff2017-07-26 10:15:23 -0400891 /** Sets text size in points.
892 Has no effect if textSize is not greater than or equal to zero.
893
894 @param textSize typographic height of text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000895 */
896 void setTextSize(SkScalar textSize);
897
Cary Clark50fa3ff2017-07-26 10:15:23 -0400898 /** Returns text scale x.
899 Default value is 1.
900
901 @return text horizontal scale
reed@android.com8a1c16f2008-12-17 15:59:43 +0000902 */
903 SkScalar getTextScaleX() const { return fTextScaleX; }
904
Cary Clark50fa3ff2017-07-26 10:15:23 -0400905 /** Sets text scale x.
906 Default value is 1.
907
908 @param scaleX text horizontal scale
reed@android.com8a1c16f2008-12-17 15:59:43 +0000909 */
910 void setTextScaleX(SkScalar scaleX);
911
Cary Clark50fa3ff2017-07-26 10:15:23 -0400912 /** Returns text skew x.
913 Default value is zero.
914
915 @return additional shear in x-axis relative to y-axis
reed@android.com8a1c16f2008-12-17 15:59:43 +0000916 */
917 SkScalar getTextSkewX() const { return fTextSkewX; }
918
Cary Clark50fa3ff2017-07-26 10:15:23 -0400919 /** Sets text skew x.
920 Default value is zero.
921
922 @param skewX additional shear in x-axis relative to y-axis
reed@android.com8a1c16f2008-12-17 15:59:43 +0000923 */
924 void setTextSkewX(SkScalar skewX);
925
Cary Clark50fa3ff2017-07-26 10:15:23 -0400926 /** \enum SkPaint::TextEncoding
Cary Clark8a02b0b2017-09-21 12:28:43 -0400927 TextEncoding determines whether text specifies character codes and their encoded
Cary Clarkcc309eb2017-10-30 11:48:35 -0400928 size, or glyph indices. Characters are encoded as specified by the Unicode standard.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400929
Cary Clark50fa3ff2017-07-26 10:15:23 -0400930 Character codes encoded size are specified by UTF-8, UTF-16, or UTF-32.
Cary Clarkcc309eb2017-10-30 11:48:35 -0400931 All character code formats are able to represent all of Unicode, differing only
932 in the total storage required.
933
934 UTF-8 (RFC 3629) encodes each character as one or more 8-bit bytes.
935
936 UTF-16 (RFC 2781) encodes each character as one or two 16-bit words.
937
938 UTF-32 encodes each character as one 32-bit word.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400939
940 font manager uses font data to convert character code points into glyph indices.
941 A glyph index is a 16-bit word.
942
943 TextEncoding is set to kUTF8_TextEncoding by default.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000944 */
945 enum TextEncoding {
Cary Clark462505f2018-05-30 09:20:29 -0400946 kUTF8_TextEncoding, //!< uses bytes to represent UTF-8 or ASCII
947 kUTF16_TextEncoding, //!< uses two byte words to represent most of Unicode
948 kUTF32_TextEncoding, //!< uses four byte words to represent all of Unicode
949 kGlyphID_TextEncoding, //!< uses two byte words to represent glyph indices
reed@android.com8a1c16f2008-12-17 15:59:43 +0000950 };
reed@google.com9d07fec2011-03-16 20:02:59 +0000951
Cary Clark50fa3ff2017-07-26 10:15:23 -0400952 /** Returns SkPaint::TextEncoding.
953 SkPaint::TextEncoding determines how character code points are mapped to font glyph indices.
954
955 @return one of: kUTF8_TextEncoding, kUTF16_TextEncoding, kUTF32_TextEncoding, or
956 kGlyphID_TextEncoding
957 */
reedf59eab22014-07-14 14:39:15 -0700958 TextEncoding getTextEncoding() const {
959 return (TextEncoding)fBitfields.fTextEncoding;
960 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000961
Cary Clark50fa3ff2017-07-26 10:15:23 -0400962 /** Sets SkPaint::TextEncoding to encoding.
963 SkPaint::TextEncoding determines how character code points are mapped to font glyph indices.
964 Invalid values for encoding are ignored.
965
966 @param encoding one of: kUTF8_TextEncoding, kUTF16_TextEncoding, kUTF32_TextEncoding, or
Cary Clark579985c2017-07-31 11:48:27 -0400967 kGlyphID_TextEncoding
Cary Clark50fa3ff2017-07-26 10:15:23 -0400968 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000969 void setTextEncoding(TextEncoding encoding);
970
Cary Clark50fa3ff2017-07-26 10:15:23 -0400971 /** \struct SkPaint::FontMetrics
Cary Clark579985c2017-07-31 11:48:27 -0400972 FontMetrics is filled out by getFontMetrics(). FontMetrics contents reflect the values
Cary Clark50fa3ff2017-07-26 10:15:23 -0400973 computed by font manager using SkTypeface. Values are set to zero if they are
Cary Clarkb7da7232017-09-01 13:49:54 -0400974 not available.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400975
Ben Wagnere5806492017-11-09 12:08:31 -0500976 All vertical values relative to the baseline are given y-down. As such, zero is on the
977 baseline, negative values are above the baseline, and positive values are below the
978 baseline.
979
Cary Clark50fa3ff2017-07-26 10:15:23 -0400980 fUnderlineThickness and fUnderlinePosition have a bit set in fFlags if their values
981 are valid, since their value may be zero.
982
983 fStrikeoutThickness and fStrikeoutPosition have a bit set in fFlags if their values
984 are valid, since their value may be zero.
985 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000986 struct FontMetrics {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400987
Cary Clarkcc309eb2017-10-30 11:48:35 -0400988 /** \enum SkPaint::FontMetrics::FontMetricsFlags
989 FontMetricsFlags are set in fFlags when underline and strikeout metrics are valid;
990 the underline or strikeout metric may be valid and zero.
991 Fonts with embedded bitmaps may not have valid underline or strikeout metrics.
992 */
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +0000993 enum FontMetricsFlags {
Cary Clark462505f2018-05-30 09:20:29 -0400994 kUnderlineThicknessIsValid_Flag = 1 << 0, //!< set if fUnderlineThickness is valid
995 kUnderlinePositionIsValid_Flag = 1 << 1, //!< set if fUnderlinePosition is valid
996 kStrikeoutThicknessIsValid_Flag = 1 << 2, //!< set if fStrikeoutThickness is valid
997 kStrikeoutPositionIsValid_Flag = 1 << 3, //!< set if fStrikeoutPosition is valid
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +0000998 };
999
Cary Clark462505f2018-05-30 09:20:29 -04001000 uint32_t fFlags; //!< is set to FontMetricsFlags when metrics are valid
1001 SkScalar fTop; //!< extent above baseline
1002 SkScalar fAscent; //!< distance to reserve above baseline
1003 SkScalar fDescent; //!< distance to reserve below baseline
1004 SkScalar fBottom; //!< extent below baseline
1005 SkScalar fLeading; //!< distance to add between lines
1006 SkScalar fAvgCharWidth; //!< average character width
1007 SkScalar fMaxCharWidth; //!< maximum character width
1008 SkScalar fXMin; //!< minimum x
1009 SkScalar fXMax; //!< maximum x
1010 SkScalar fXHeight; //!< height of lower-case 'x'
1011 SkScalar fCapHeight; //!< height of an upper-case letter
1012 SkScalar fUnderlineThickness; //!< underline thickness
1013 SkScalar fUnderlinePosition; //!< underline position relative to baseline
1014 SkScalar fStrikeoutThickness; //!< strikeout thickness
1015 SkScalar fStrikeoutPosition; //!< strikeout position relative to baseline
Cary Clark50fa3ff2017-07-26 10:15:23 -04001016
1017 /** If SkPaint::FontMetrics has a valid underline thickness, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001018 thickness to that value. If the underline thickness is not valid,
1019 return false, and ignore thickness.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001020
1021 @param thickness storage for underline width
1022 @return true if font specifies underline width
1023 */
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001024 bool hasUnderlineThickness(SkScalar* thickness) const {
Ben Wagner3318da52017-03-23 14:01:22 -04001025 if (SkToBool(fFlags & kUnderlineThicknessIsValid_Flag)) {
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001026 *thickness = fUnderlineThickness;
1027 return true;
1028 }
1029 return false;
1030 }
1031
Cary Clark50fa3ff2017-07-26 10:15:23 -04001032 /** If SkPaint::FontMetrics has a valid underline position, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001033 position to that value. If the underline position is not valid,
1034 return false, and ignore position.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001035
1036 @param position storage for underline position
1037 @return true if font specifies underline position
1038 */
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001039 bool hasUnderlinePosition(SkScalar* position) const {
1040 if (SkToBool(fFlags & kUnderlinePositionIsValid_Flag)) {
1041 *position = fUnderlinePosition;
1042 return true;
1043 }
1044 return false;
1045 }
1046
Cary Clark50fa3ff2017-07-26 10:15:23 -04001047 /** If SkPaint::FontMetrics has a valid strikeout thickness, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001048 thickness to that value. If the underline thickness is not valid,
1049 return false, and ignore thickness.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001050
1051 @param thickness storage for strikeout width
1052 @return true if font specifies strikeout width
1053 */
Ben Wagner219f3622017-07-17 15:32:25 -04001054 bool hasStrikeoutThickness(SkScalar* thickness) const {
1055 if (SkToBool(fFlags & kStrikeoutThicknessIsValid_Flag)) {
1056 *thickness = fStrikeoutThickness;
1057 return true;
1058 }
1059 return false;
1060 }
1061
Cary Clark50fa3ff2017-07-26 10:15:23 -04001062 /** If SkPaint::FontMetrics has a valid strikeout position, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001063 position to that value. If the underline position is not valid,
1064 return false, and ignore position.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001065
1066 @param position storage for strikeout position
1067 @return true if font specifies strikeout position
1068 */
Ben Wagner219f3622017-07-17 15:32:25 -04001069 bool hasStrikeoutPosition(SkScalar* position) const {
1070 if (SkToBool(fFlags & kStrikeoutPositionIsValid_Flag)) {
1071 *position = fStrikeoutPosition;
1072 return true;
1073 }
1074 return false;
1075 }
Cary Clark50fa3ff2017-07-26 10:15:23 -04001076
reed@android.com8a1c16f2008-12-17 15:59:43 +00001077 };
reed@google.com9d07fec2011-03-16 20:02:59 +00001078
Cary Clark50fa3ff2017-07-26 10:15:23 -04001079 /** Returns SkPaint::FontMetrics associated with SkTypeface.
1080 The return value is the recommended spacing between lines: the sum of metrics
1081 descent, ascent, and leading.
1082 If metrics is not nullptr, SkPaint::FontMetrics is copied to metrics.
1083 Results are scaled by text size but does not take into account
1084 dimensions required by text scale x, text skew x, fake bold,
1085 style stroke, and SkPathEffect.
1086 Results can be additionally scaled by scale; a scale of zero
1087 is ignored.
1088
1089 @param metrics storage for SkPaint::FontMetrics from SkTypeface; may be nullptr
1090 @param scale additional multiplier for returned values
1091 @return recommended spacing between lines
reed@android.com8a1c16f2008-12-17 15:59:43 +00001092 */
1093 SkScalar getFontMetrics(FontMetrics* metrics, SkScalar scale = 0) const;
reed@google.com9d07fec2011-03-16 20:02:59 +00001094
Cary Clark50fa3ff2017-07-26 10:15:23 -04001095 /** Returns the recommended spacing between lines: the sum of metrics
1096 descent, ascent, and leading.
1097 Result is scaled by text size but does not take into account
1098 dimensions required by stroking and SkPathEffect.
Cary Clark579985c2017-07-31 11:48:27 -04001099 Returns the same result as getFontMetrics().
Cary Clark50fa3ff2017-07-26 10:15:23 -04001100
1101 @return recommended spacing between lines
reed@android.com8a1c16f2008-12-17 15:59:43 +00001102 */
Ben Wagnera93a14a2017-08-28 10:34:05 -04001103 SkScalar getFontSpacing() const { return this->getFontMetrics(nullptr, 0); }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001104
Cary Clark50fa3ff2017-07-26 10:15:23 -04001105 /** Converts text into glyph indices.
1106 Returns the number of glyph indices represented by text.
1107 SkPaint::TextEncoding specifies how text represents characters or glyphs.
1108 glyphs may be nullptr, to compute the glyph count.
1109
Cary Clarkcc309eb2017-10-30 11:48:35 -04001110 Does not check text for valid character codes or valid glyph indices.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001111
Cary Clark579985c2017-07-31 11:48:27 -04001112 If byteLength equals zero, returns zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001113 If byteLength includes a partial character, the partial character is ignored.
1114
1115 If SkPaint::TextEncoding is kUTF8_TextEncoding and
1116 text contains an invalid UTF-8 sequence, zero is returned.
1117
Cary Clarkb7da7232017-09-01 13:49:54 -04001118 @param text character storage encoded with SkPaint::TextEncoding
Cary Clark50fa3ff2017-07-26 10:15:23 -04001119 @param byteLength length of character storage in bytes
1120 @param glyphs storage for glyph indices; may be nullptr
1121 @return number of glyphs represented by text of length byteLength
reed@android.com8a1c16f2008-12-17 15:59:43 +00001122 */
1123 int textToGlyphs(const void* text, size_t byteLength,
halcanaryd0e95a52016-07-25 07:18:12 -07001124 SkGlyphID glyphs[]) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001125
Cary Clark50fa3ff2017-07-26 10:15:23 -04001126 /** Returns true if all text corresponds to a non-zero glyph index.
1127 Returns false if any characters in text are not supported in
1128 SkTypeface.
reed@android.coma5dcaf62010-02-05 17:12:32 +00001129
Cary Clark579985c2017-07-31 11:48:27 -04001130 If SkPaint::TextEncoding is kGlyphID_TextEncoding,
1131 returns true if all glyph indices in text are non-zero;
Cary Clark50fa3ff2017-07-26 10:15:23 -04001132 does not check to see if text contains valid glyph indices for SkTypeface.
1133
Cary Clarkb7da7232017-09-01 13:49:54 -04001134 Returns true if byteLength is zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001135
1136 @param text array of characters or glyphs
1137 @param byteLength number of bytes in text array
1138 @return true if all text corresponds to a non-zero glyph index
1139 */
reed@android.coma5dcaf62010-02-05 17:12:32 +00001140 bool containsText(const void* text, size_t byteLength) const;
1141
Cary Clark50fa3ff2017-07-26 10:15:23 -04001142 /** Converts glyphs into text if possible.
1143 Glyph values without direct Unicode equivalents are mapped to zero.
1144 Uses the SkTypeface, but is unaffected
1145 by SkPaint::TextEncoding; the text values returned are equivalent to kUTF32_TextEncoding.
1146
1147 Only supported on platforms that use FreeType as the font engine.
1148
1149 @param glyphs array of indices into font
1150 @param count length of glyph array
1151 @param text storage for character codes, one per glyph
reed@android.com9d3a9852010-01-08 14:07:42 +00001152 */
halcanaryd0e95a52016-07-25 07:18:12 -07001153 void glyphsToUnichars(const SkGlyphID glyphs[], int count, SkUnichar text[]) const;
reed@android.com9d3a9852010-01-08 14:07:42 +00001154
Cary Clark50fa3ff2017-07-26 10:15:23 -04001155 /** Returns the number of glyphs in text.
1156 Uses SkPaint::TextEncoding to count the glyphs.
Cary Clark579985c2017-07-31 11:48:27 -04001157 Returns the same result as textToGlyphs().
Cary Clark50fa3ff2017-07-26 10:15:23 -04001158
Cary Clarkb7da7232017-09-01 13:49:54 -04001159 @param text character storage encoded with SkPaint::TextEncoding
Cary Clark50fa3ff2017-07-26 10:15:23 -04001160 @param byteLength length of character storage in bytes
1161 @return number of glyphs represented by text of length byteLength
reed@android.com8a1c16f2008-12-17 15:59:43 +00001162 */
Herb Derby90864a22018-05-02 13:43:49 -04001163 int countText(const void* text, size_t byteLength) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001164
Cary Clark50fa3ff2017-07-26 10:15:23 -04001165 /** Returns the advance width of text if kVerticalText_Flag is clear,
1166 and the height of text if kVerticalText_Flag is set.
1167 The advance is the normal distance to move before drawing additional text.
1168 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
1169 and text size, text scale x, text skew x, stroke width, and
1170 SkPathEffect to scale the metrics and bounds.
1171 Returns the bounding box of text if bounds is not nullptr.
1172 The bounding box is computed as if the text was drawn at the origin.
1173
1174 @param text character codes or glyph indices to be measured
1175 @param length number of bytes of text to measure
1176 @param bounds returns bounding box relative to (0, 0) if not nullptr
1177 @return advance width or height
1178 */
reed99ae8812014-08-26 11:30:01 -07001179 SkScalar measureText(const void* text, size_t length, SkRect* bounds) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001180
Cary Clark50fa3ff2017-07-26 10:15:23 -04001181 /** Returns the advance width of text if kVerticalText_Flag is clear,
1182 and the height of text if kVerticalText_Flag is set.
1183 The advance is the normal distance to move before drawing additional text.
1184 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
Cary Clark23890a92017-07-27 16:30:51 -04001185 and text size to scale the metrics.
1186 Does not scale the advance or bounds by fake bold or SkPathEffect.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001187
1188 @param text character codes or glyph indices to be measured
1189 @param length number of bytes of text to measure
Cary Clark50fa3ff2017-07-26 10:15:23 -04001190 @return advance width or height
1191 */
reed@google.com9d07fec2011-03-16 20:02:59 +00001192 SkScalar measureText(const void* text, size_t length) const {
Ben Wagnera93a14a2017-08-28 10:34:05 -04001193 return this->measureText(text, length, nullptr);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001194 }
reed@google.com9d07fec2011-03-16 20:02:59 +00001195
Cary Clark50fa3ff2017-07-26 10:15:23 -04001196 /** Returns the bytes of text that fit within maxWidth.
1197 If kVerticalText_Flag is clear, the text fragment fits if its advance width is less than or
1198 equal to maxWidth.
1199 If kVerticalText_Flag is set, the text fragment fits if its advance height is less than or
1200 equal to maxWidth.
1201 Measures only while the advance is less than or equal to maxWidth.
1202 Returns the advance or the text fragment in measuredWidth if it not nullptr.
1203 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
1204 and text size to scale the metrics.
1205 Does not scale the advance or bounds by fake bold or SkPathEffect.
1206
1207 @param text character codes or glyph indices to be measured
1208 @param length number of bytes of text to measure
1209 @param maxWidth advance limit; text is measured while advance is less than maxWidth
1210 @param measuredWidth returns the width of the text less than or equal to maxWidth
1211 @return bytes of text that fit, always less than or equal to length
1212 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001213 size_t breakText(const void* text, size_t length, SkScalar maxWidth,
Ben Wagnera93a14a2017-08-28 10:34:05 -04001214 SkScalar* measuredWidth = nullptr) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001215
Cary Clark50fa3ff2017-07-26 10:15:23 -04001216 /** Retrieves the advance and bounds for each glyph in text, and returns
1217 the glyph count in text.
1218 Both widths and bounds may be nullptr.
1219 If widths is not nullptr, widths must be an array of glyph count entries.
1220 if bounds is not nullptr, bounds must be an array of glyph count entries.
1221 If kVerticalText_Flag is clear, widths returns the horizontal advance.
1222 If kVerticalText_Flag is set, widths returns the vertical advance.
1223 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
1224 and text size to scale the widths and bounds.
1225 Does not scale the advance by fake bold or SkPathEffect.
Cary Clark23890a92017-07-27 16:30:51 -04001226 Does include fake bold and SkPathEffect in the bounds.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001227
1228 @param text character codes or glyph indices to be measured
1229 @param byteLength number of bytes of text to measure
1230 @param widths returns text advances for each glyph; may be nullptr
1231 @param bounds returns bounds for each glyph relative to (0, 0); may be nullptr
1232 @return glyph count in text
1233 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001234 int getTextWidths(const void* text, size_t byteLength, SkScalar widths[],
Ben Wagnera93a14a2017-08-28 10:34:05 -04001235 SkRect bounds[] = nullptr) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001236
Cary Clark50fa3ff2017-07-26 10:15:23 -04001237 /** Returns the geometry as SkPath equivalent to the drawn text.
1238 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1239 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1240 All of the glyph paths are stored in path.
Cary Clark579985c2017-07-31 11:48:27 -04001241 Uses x, y, and SkPaint::Align to position path.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001242
1243 @param text character codes or glyph indices
1244 @param length number of bytes of text
1245 @param x x-coordinate of the origin of the text
1246 @param y y-coordinate of the origin of the text
1247 @param path geometry of the glyphs
1248 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001249 void getTextPath(const void* text, size_t length, SkScalar x, SkScalar y,
1250 SkPath* path) const;
1251
Cary Clark50fa3ff2017-07-26 10:15:23 -04001252 /** Returns the geometry as SkPath equivalent to the drawn text.
1253 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1254 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1255 All of the glyph paths are stored in path.
1256 Uses pos array and SkPaint::Align to position path.
1257 pos contains a position for each glyph.
1258
1259 @param text character codes or glyph indices
1260 @param length number of bytes of text
1261 @param pos positions of each glyph
1262 @param path geometry of the glyphs
1263 */
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001264 void getPosTextPath(const void* text, size_t length,
reed@google.comca0062e2012-07-20 11:20:32 +00001265 const SkPoint pos[], SkPath* path) const;
1266
Cary Clark50fa3ff2017-07-26 10:15:23 -04001267 /** Returns the number of intervals that intersect bounds.
1268 bounds describes a pair of lines parallel to the text advance.
1269 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1270 the string.
1271 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1272 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1273 Uses x, y, and SkPaint::Align to position intervals.
1274
1275 Pass nullptr for intervals to determine the size of the interval array.
1276
1277 intervals are cached to improve performance for multiple calls.
1278
1279 @param text character codes or glyph indices
1280 @param length number of bytes of text
1281 @param x x-coordinate of the origin of the text
1282 @param y y-coordinate of the origin of the text
1283 @param bounds lower and upper line parallel to the advance
1284 @param intervals returned intersections; may be nullptr
1285 @return number of intersections; may be zero
1286 */
caryclark0449bcf2016-02-09 13:25:45 -08001287 int getTextIntercepts(const void* text, size_t length, SkScalar x, SkScalar y,
1288 const SkScalar bounds[2], SkScalar* intervals) const;
1289
Cary Clark50fa3ff2017-07-26 10:15:23 -04001290 /** Returns the number of intervals that intersect bounds.
1291 bounds describes a pair of lines parallel to the text advance.
1292 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1293 the string.
1294 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1295 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1296 Uses pos array and SkPaint::Align to position intervals.
1297
1298 Pass nullptr for intervals to determine the size of the interval array.
1299
1300 intervals are cached to improve performance for multiple calls.
1301
1302 @param text character codes or glyph indices
1303 @param length number of bytes of text
1304 @param pos positions of each glyph
1305 @param bounds lower and upper line parallel to the advance
1306 @param intervals returned intersections; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -04001307 @return number of intersections; may be zero
Cary Clark50fa3ff2017-07-26 10:15:23 -04001308 */
caryclark0449bcf2016-02-09 13:25:45 -08001309 int getPosTextIntercepts(const void* text, size_t length, const SkPoint pos[],
1310 const SkScalar bounds[2], SkScalar* intervals) const;
1311
Cary Clark50fa3ff2017-07-26 10:15:23 -04001312 /** Returns the number of intervals that intersect bounds.
1313 bounds describes a pair of lines parallel to the text advance.
1314 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1315 the string.
1316 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1317 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1318 Uses xpos array, constY, and SkPaint::Align to position intervals.
1319
1320 Pass nullptr for intervals to determine the size of the interval array.
1321
1322 intervals are cached to improve performance for multiple calls.
1323
1324 @param text character codes or glyph indices
1325 @param length number of bytes of text
1326 @param xpos positions of each glyph in x
1327 @param constY position of each glyph in y
1328 @param bounds lower and upper line parallel to the advance
1329 @param intervals returned intersections; may be nullptr
1330 @return number of intersections; may be zero
1331 */
fmalitaeae6a912016-07-28 09:47:24 -07001332 int getPosTextHIntercepts(const void* text, size_t length, const SkScalar xpos[],
1333 SkScalar constY, const SkScalar bounds[2], SkScalar* intervals) const;
1334
Cary Clark50fa3ff2017-07-26 10:15:23 -04001335 /** Returns the number of intervals that intersect bounds.
1336 bounds describes a pair of lines parallel to the text advance.
1337 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1338 the string.
Cary Clark2823f9f2018-01-03 10:00:34 -05001339 Uses SkTypeface to get the glyph paths,
Cary Clark50fa3ff2017-07-26 10:15:23 -04001340 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
Cary Clarkb7da7232017-09-01 13:49:54 -04001341 Uses run array and SkPaint::Align to position intervals.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001342
Cary Clark2823f9f2018-01-03 10:00:34 -05001343 SkPaint::TextEncoding must be set to SkPaint::kGlyphID_TextEncoding.
1344
Cary Clark50fa3ff2017-07-26 10:15:23 -04001345 Pass nullptr for intervals to determine the size of the interval array.
1346
1347 intervals are cached to improve performance for multiple calls.
1348
Cary Clark8a02b0b2017-09-21 12:28:43 -04001349 @param blob glyphs, positions, and text paint attributes
Cary Clark50fa3ff2017-07-26 10:15:23 -04001350 @param bounds lower and upper line parallel to the advance
1351 @param intervals returned intersections; may be nullptr
1352 @return number of intersections; may be zero
1353 */
fmalitaeae6a912016-07-28 09:47:24 -07001354 int getTextBlobIntercepts(const SkTextBlob* blob, const SkScalar bounds[2],
1355 SkScalar* intervals) const;
1356
Cary Clark50fa3ff2017-07-26 10:15:23 -04001357 /** Returns the union of bounds of all glyphs.
1358 Returned dimensions are computed by font manager from font data,
Cary Clark579985c2017-07-31 11:48:27 -04001359 ignoring SkPaint::Hinting. Includes text size, text scale x,
Cary Clark50fa3ff2017-07-26 10:15:23 -04001360 and text skew x, but not fake bold or SkPathEffect.
1361
1362 If text size is large, text scale x is one, and text skew x is zero,
Cary Clark579985c2017-07-31 11:48:27 -04001363 returns the same bounds as SkPaint::FontMetrics { FontMetrics::fXMin,
Cary Clark50fa3ff2017-07-26 10:15:23 -04001364 FontMetrics::fTop, FontMetrics::fXMax, FontMetrics::fBottom }.
1365
1366 @return union of bounds of all glyphs
1367 */
reed8893e5f2014-12-15 13:27:26 -08001368 SkRect getFontBounds() const;
1369
Cary Clark579985c2017-07-31 11:48:27 -04001370 /** Returns true if SkPaint prevents all drawing;
1371 otherwise, the SkPaint may or may not allow drawing.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001372
Cary Clark462505f2018-05-30 09:20:29 -04001373 Returns true if, for example, SkBlendMode combined with alpha computes a
Cary Clarkb7da7232017-09-01 13:49:54 -04001374 new alpha of zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001375
1376 @return true if SkPaint prevents all drawing
1377 */
reed@google.com632e1a22011-10-06 12:37:00 +00001378 bool nothingToDraw() const;
1379
Cary Clark2823f9f2018-01-03 10:00:34 -05001380 /** (to be made private)
Cary Clark50fa3ff2017-07-26 10:15:23 -04001381 Returns true if SkPaint does not include elements requiring extensive computation
1382 to compute SkBaseDevice bounds of drawn geometry. For instance, SkPaint with SkPathEffect
1383 always returns false.
reed@google.comd5f20792012-05-16 14:15:02 +00001384
Cary Clark50fa3ff2017-07-26 10:15:23 -04001385 @return true if SkPaint allows for fast computation of bounds
1386 */
senorblanco0abdf762015-08-20 11:10:41 -07001387 bool canComputeFastBounds() const;
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001388
Cary Clark2823f9f2018-01-03 10:00:34 -05001389 /** (to be made private)
Cary Clark579985c2017-07-31 11:48:27 -04001390 Only call this if canComputeFastBounds() returned true. This takes a
Cary Clark50fa3ff2017-07-26 10:15:23 -04001391 raw rectangle (the raw bounds of a shape), and adjusts it for stylistic
1392 effects in the paint (e.g. stroking). If needed, it uses the storage
Cary Clarkb7da7232017-09-01 13:49:54 -04001393 parameter. It returns the adjusted bounds that can then be used
Cary Clark50fa3ff2017-07-26 10:15:23 -04001394 for SkCanvas::quickReject tests.
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001395
Cary Clarkb7da7232017-09-01 13:49:54 -04001396 The returned SkRect will either be orig or storage, thus the caller
Cary Clark50fa3ff2017-07-26 10:15:23 -04001397 should not rely on storage being set to the result, but should always
Cary Clarkb7da7232017-09-01 13:49:54 -04001398 use the returned value. It is legal for orig and storage to be the same
1399 SkRect.
Cary Clark462505f2018-05-30 09:20:29 -04001400 For example:
1401 if (!path.isInverseFillType() && paint.canComputeFastBounds()) {
1402 SkRect storage;
1403 if (canvas->quickReject(paint.computeFastBounds(path.getBounds(), &storage))) {
1404 return; // do not draw the path
1405 }
Cary Clark2823f9f2018-01-03 10:00:34 -05001406 }
Cary Clark462505f2018-05-30 09:20:29 -04001407 // draw the path
Cary Clark50fa3ff2017-07-26 10:15:23 -04001408
1409 @param orig geometry modified by SkPaint when drawn
1410 @param storage computed bounds of geometry; may not be nullptr
1411 @return fast computed bounds
1412 */
reed@google.coma584aed2012-05-16 14:06:02 +00001413 const SkRect& computeFastBounds(const SkRect& orig, SkRect* storage) const {
Brian Osman60751d72017-05-12 11:21:36 -04001414 // Things like stroking, etc... will do math on the bounds rect, assuming that it's sorted.
1415 SkASSERT(orig.isSorted());
reed@google.coma584aed2012-05-16 14:06:02 +00001416 SkPaint::Style style = this->getStyle();
1417 // ultra fast-case: filling with no effects that affect geometry
1418 if (kFill_Style == style) {
1419 uintptr_t effects = reinterpret_cast<uintptr_t>(this->getLooper());
1420 effects |= reinterpret_cast<uintptr_t>(this->getMaskFilter());
1421 effects |= reinterpret_cast<uintptr_t>(this->getPathEffect());
senorblanco@chromium.org336d1d72014-01-27 21:03:17 +00001422 effects |= reinterpret_cast<uintptr_t>(this->getImageFilter());
reed@google.coma584aed2012-05-16 14:06:02 +00001423 if (!effects) {
1424 return orig;
1425 }
1426 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001427
reed@google.coma584aed2012-05-16 14:06:02 +00001428 return this->doComputeFastBounds(orig, storage, style);
1429 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001430
Cary Clark2823f9f2018-01-03 10:00:34 -05001431 /** (to be made private)
Cary Clark50fa3ff2017-07-26 10:15:23 -04001432
1433 @param orig geometry modified by SkPaint when drawn
1434 @param storage computed bounds of geometry
1435 @return fast computed bounds
1436 */
reed@google.coma584aed2012-05-16 14:06:02 +00001437 const SkRect& computeFastStrokeBounds(const SkRect& orig,
1438 SkRect* storage) const {
reed@google.com73a02582012-05-16 19:21:12 +00001439 return this->doComputeFastBounds(orig, storage, kStroke_Style);
reed@google.coma584aed2012-05-16 14:06:02 +00001440 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001441
Cary Clark2823f9f2018-01-03 10:00:34 -05001442 /** (to be made private)
Cary Clarkb7da7232017-09-01 13:49:54 -04001443 Computes the bounds, overriding the SkPaint SkPaint::Style. This can be used to
1444 account for additional width required by stroking orig, without
1445 altering SkPaint::Style set to fill.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001446
1447 @param orig geometry modified by SkPaint when drawn
1448 @param storage computed bounds of geometry
1449 @param style overrides SkPaint::Style
1450 @return fast computed bounds
1451 */
reed@google.coma584aed2012-05-16 14:06:02 +00001452 const SkRect& doComputeFastBounds(const SkRect& orig, SkRect* storage,
Cary Clark0418a882017-05-10 09:07:42 -04001453 Style style) const;
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001454
reed@google.comd5f20792012-05-16 14:15:02 +00001455private:
Cary Clark0418a882017-05-10 09:07:42 -04001456 typedef const SkGlyph& (*GlyphCacheProc)(SkGlyphCache*, const char**);
1457
reeda5ab9ec2016-03-06 18:10:48 -08001458 sk_sp<SkTypeface> fTypeface;
1459 sk_sp<SkPathEffect> fPathEffect;
1460 sk_sp<SkShader> fShader;
reeda5ab9ec2016-03-06 18:10:48 -08001461 sk_sp<SkMaskFilter> fMaskFilter;
1462 sk_sp<SkColorFilter> fColorFilter;
reed46f2d0a2016-09-11 05:40:31 -07001463 sk_sp<SkDrawLooper> fDrawLooper;
reeda5ab9ec2016-03-06 18:10:48 -08001464 sk_sp<SkImageFilter> fImageFilter;
reed@google.comd5f20792012-05-16 14:15:02 +00001465
commit-bot@chromium.orge8807f42014-03-24 23:03:11 +00001466 SkScalar fTextSize;
1467 SkScalar fTextScaleX;
1468 SkScalar fTextSkewX;
reed@google.comd5f20792012-05-16 14:15:02 +00001469 SkColor fColor;
1470 SkScalar fWidth;
1471 SkScalar fMiterLimit;
Mike Reed71fecc32016-11-18 17:19:54 -05001472 uint32_t fBlendMode; // just need 5-6 bits
commit-bot@chromium.orgaca1c012014-02-21 18:18:05 +00001473 union {
1474 struct {
1475 // all of these bitfields should add up to 32
1476 unsigned fFlags : 16;
1477 unsigned fTextAlign : 2;
1478 unsigned fCapType : 2;
1479 unsigned fJoinType : 2;
1480 unsigned fStyle : 2;
1481 unsigned fTextEncoding : 2; // 3 values
1482 unsigned fHinting : 2;
reedf803da12015-01-23 05:58:07 -08001483 unsigned fFilterQuality : 2;
commit-bot@chromium.org85faf502014-04-16 12:58:02 +00001484 //unsigned fFreeBits : 2;
reedf59eab22014-07-14 14:39:15 -07001485 } fBitfields;
1486 uint32_t fBitfieldsUInt;
commit-bot@chromium.orgaca1c012014-02-21 18:18:05 +00001487 };
commit-bot@chromium.orge8807f42014-03-24 23:03:11 +00001488
robertphillipse34f17d2016-07-19 07:59:22 -07001489 static GlyphCacheProc GetGlyphCacheProc(TextEncoding encoding,
robertphillipse34f17d2016-07-19 07:59:22 -07001490 bool needFullMetrics);
reed@google.comd5f20792012-05-16 14:15:02 +00001491
1492 SkScalar measure_text(SkGlyphCache*, const char* text, size_t length,
1493 int* count, SkRect* bounds) const;
1494
joshualitt9e36c1a2015-04-14 12:17:27 -07001495 /*
1496 * The luminance color is used to determine which Gamma Canonical color to map to. This is
1497 * really only used by backends which want to cache glyph masks, and need some way to know if
1498 * they need to generate new masks based off a given color.
1499 */
1500 SkColor computeLuminanceColor() const;
1501
Cary Clarkd98f78c2018-04-26 08:32:37 -04001502 /* This is the size we use when we ask for a glyph's path. We then
1503 * post-transform it as we draw to match the request.
1504 * This is done to try to re-use cache entries for the path.
1505 *
1506 * This value is somewhat arbitrary. In theory, it could be 1, since
1507 * we store paths as floats. However, we get the path from the font
1508 * scaler, and it may represent its paths as fixed-point (or 26.6),
1509 * so we shouldn't ask for something too big (might overflow 16.16)
1510 * or too small (underflow 26.6).
1511 *
1512 * This value could track kMaxSizeForGlyphCache, assuming the above
1513 * constraints, but since we ask for unhinted paths, the two values
1514 * need not match per-se.
1515 */
1516 static constexpr int kCanonicalTextSizeForPaths = 64;
reed@google.comed43dff2013-06-04 16:56:27 +00001517
Jim Van Verthc65b65d2018-01-16 16:26:35 -05001518 static bool TooBigToUseCache(const SkMatrix& ctm, const SkMatrix& textM, SkScalar maxLimit);
reed@google.comed43dff2013-06-04 16:56:27 +00001519
reed@google.comed43dff2013-06-04 16:56:27 +00001520 // Set flags/hinting/textSize up to use for drawing text as paths.
1521 // Returns scale factor to restore the original textSize, since will will
1522 // have change it to kCanonicalTextSizeForPaths.
1523 SkScalar setupForAsPaths();
1524
Jim Van Verthc65b65d2018-01-16 16:26:35 -05001525 static SkScalar MaxCacheSize2(SkScalar maxLimit);
reed@google.comed43dff2013-06-04 16:56:27 +00001526
Herb Derby980a48d2018-01-23 13:39:21 -05001527 friend class GrAtlasTextBlob;
Herb Derby26cbe512018-05-24 14:39:01 -04001528 friend class GrTextContext;
Herb Derby980a48d2018-01-23 13:39:21 -05001529 friend class GrGLPathRendering;
1530 friend class GrPathRendering;
Herb Derby980a48d2018-01-23 13:39:21 -05001531 friend class GrTextUtils;
jvanverth2d2a68c2014-06-10 06:42:56 -07001532 friend class SkAutoGlyphCacheNoGamma;
Herb Derby980a48d2018-01-23 13:39:21 -05001533 friend class SkCanonicalizePaint;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001534 friend class SkCanvas;
1535 friend class SkDraw;
Cary Clark60ca8672018-03-06 15:09:27 -05001536 friend class SkPaintPriv;
vandebo@chromium.org28be72b2010-11-11 21:37:00 +00001537 friend class SkPDFDevice;
Herb Derby980a48d2018-01-23 13:39:21 -05001538 friend class SkScalerContext; // for computeLuminanceColor()
caryclark0449bcf2016-02-09 13:25:45 -08001539 friend class SkTextBaseIter;
Khushal51371a42018-05-17 10:41:40 -07001540 friend class SkTextBlobCacheDiffCanvas;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001541};
1542
reed@android.com8a1c16f2008-12-17 15:59:43 +00001543#endif