blob: 3d471d15ff942a514f5c014f22856090b8d8f04f [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
Hal Canaryc640d0d2018-06-13 09:59:02 -040021#include "../private/SkTo.h"
reed374772b2016-10-05 17:33:02 -070022#include "SkBlendMode.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000023#include "SkColor.h"
reedf803da12015-01-23 05:58:07 -080024#include "SkFilterQuality.h"
reed@google.comed43dff2013-06-04 16:56:27 +000025#include "SkMatrix.h"
Mike Reed71fecc32016-11-18 17:19:54 -050026#include "SkRefCnt.h"
reed@android.coma0f5d152009-06-22 17:38:10 +000027
joshualitt2b6acb42015-04-01 11:30:27 -070028class SkAutoDescriptor;
reed@android.com8a1c16f2008-12-17 15:59:43 +000029class SkColorFilter;
joshualittfd450792015-03-13 08:38:43 -070030class SkData;
reed@android.com8a1c16f2008-12-17 15:59:43 +000031class SkDescriptor;
senorblanco0abdf762015-08-20 11:10:41 -070032class SkDrawLooper;
herbb69d0e02015-02-25 06:47:06 -080033class SkGlyph;
reed@android.com8a1c16f2008-12-17 15:59:43 +000034struct SkRect;
35class SkGlyphCache;
reed@google.com15356a62011-11-03 19:29:08 +000036class SkImageFilter;
reed@android.com8a1c16f2008-12-17 15:59:43 +000037class SkMaskFilter;
reed@android.com8a1c16f2008-12-17 15:59:43 +000038class SkPath;
39class SkPathEffect;
djsollen@google.comc73dd5c2012-08-07 15:54:32 +000040struct SkPoint;
reed@android.com8a1c16f2008-12-17 15:59:43 +000041class SkShader;
robertphillipsfcf78292015-06-19 11:49:52 -070042class SkSurfaceProps;
fmalitaeae6a912016-07-28 09:47:24 -070043class SkTextBlob;
reed@android.com8a1c16f2008-12-17 15:59:43 +000044class SkTypeface;
reed@android.com8a1c16f2008-12-17 15:59:43 +000045
reed@android.com8a1c16f2008-12-17 15:59:43 +000046/** \class SkPaint
Cary Clark50fa3ff2017-07-26 10:15:23 -040047 SkPaint controls options applied when drawing and measuring. SkPaint collects all
48 options outside of the SkCanvas clip and SkCanvas matrix.
reed@android.com8a1c16f2008-12-17 15:59:43 +000049
Cary Clark50fa3ff2017-07-26 10:15:23 -040050 Various options apply to text, strokes and fills, and images.
51
52 Some options may not be implemented on all platforms; in these cases, setting
53 the option has no effect. Some options are conveniences that duplicate SkCanvas
54 functionality; for instance, text size is identical to matrix scale.
55
56 SkPaint options are rarely exclusive; each option modifies a stage of the drawing
Cary Clark23890a92017-07-27 16:30:51 -040057 pipeline and multiple pipeline stages may be affected by a single SkPaint.
Cary Clark50fa3ff2017-07-26 10:15:23 -040058
Cary Clark23890a92017-07-27 16:30:51 -040059 SkPaint collects effects and filters that describe single-pass and multiple-pass
Cary Clark50fa3ff2017-07-26 10:15:23 -040060 algorithms that alter the drawing geometry, color, and transparency. For instance,
61 SkPaint does not directly implement dashing or blur, but contains the objects that do so.
62
63 The objects contained by SkPaint are opaque, and cannot be edited outside of the SkPaint
64 to affect it. The implementation is free to defer computations associated with the
65 SkPaint, or ignore them altogether. For instance, some GPU implementations draw all
Cary Clarkb7da7232017-09-01 13:49:54 -040066 SkPath geometries with anti-aliasing, regardless of how SkPaint::kAntiAlias_Flag
67 is set in SkPaint.
Cary Clark50fa3ff2017-07-26 10:15:23 -040068
69 SkPaint describes a single color, a single font, a single image quality, and so on.
70 Multiple colors are drawn either by using multiple paints or with objects like
71 SkShader attached to SkPaint.
reed@android.com8a1c16f2008-12-17 15:59:43 +000072*/
ctguil@chromium.org7ffb1b22011-03-15 21:27:08 +000073class SK_API SkPaint {
reed@android.com8a1c16f2008-12-17 15:59:43 +000074public:
Cary Clark50fa3ff2017-07-26 10:15:23 -040075
76 /** Constructs SkPaint with default values.
77
78 @return default initialized SkPaint
79 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000080 SkPaint();
Cary Clark50fa3ff2017-07-26 10:15:23 -040081
82 /** Makes a shallow copy of SkPaint. SkTypeface, SkPathEffect, SkShader,
Mike Reed8ad91a92018-01-19 19:09:32 -050083 SkMaskFilter, SkColorFilter, SkDrawLooper, and SkImageFilter are shared
Cary Clarkb7da7232017-09-01 13:49:54 -040084 between the original paint and the copy. Objects containing SkRefCnt increment
85 their references by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -040086
Mike Reed8ad91a92018-01-19 19:09:32 -050087 The referenced objects SkPathEffect, SkShader, SkMaskFilter, SkColorFilter,
Cary Clark50fa3ff2017-07-26 10:15:23 -040088 SkDrawLooper, and SkImageFilter cannot be modified after they are created.
89 This prevents objects with SkRefCnt from being modified once SkPaint refers to them.
90
91 @param paint original to copy
92 @return shallow copy of paint
93 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000094 SkPaint(const SkPaint& paint);
Cary Clark50fa3ff2017-07-26 10:15:23 -040095
Cary Clark8a02b0b2017-09-21 12:28:43 -040096 /** Implements a move constructor to avoid increasing the reference counts
Cary Clark50fa3ff2017-07-26 10:15:23 -040097 of objects referenced by the paint.
98
99 After the call, paint is undefined, and can be safely destructed.
100
101 @param paint original to move
102 @return content of paint
103 */
bungemanccce0e02016-02-07 14:37:23 -0800104 SkPaint(SkPaint&& paint);
Cary Clark50fa3ff2017-07-26 10:15:23 -0400105
106 /** Decreases SkPaint SkRefCnt of owned objects: SkTypeface, SkPathEffect, SkShader,
Mike Reed8ad91a92018-01-19 19:09:32 -0500107 SkMaskFilter, SkColorFilter, SkDrawLooper, and SkImageFilter. If the
Cary Clarkb7da7232017-09-01 13:49:54 -0400108 objects containing SkRefCnt go to zero, they are deleted.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400109 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000110 ~SkPaint();
111
Cary Clark50fa3ff2017-07-26 10:15:23 -0400112 /** Makes a shallow copy of SkPaint. SkTypeface, SkPathEffect, SkShader,
Mike Reed8ad91a92018-01-19 19:09:32 -0500113 SkMaskFilter, SkColorFilter, SkDrawLooper, and SkImageFilter are shared
Cary Clarkb7da7232017-09-01 13:49:54 -0400114 between the original paint and the copy. Objects containing SkRefCnt in the
Cary Clark50fa3ff2017-07-26 10:15:23 -0400115 prior destination are decreased by one, and the referenced objects are deleted if the
Cary Clarkb7da7232017-09-01 13:49:54 -0400116 resulting count is zero. Objects containing SkRefCnt in the parameter paint
117 are increased by one. paint is unmodified.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400118
119 @param paint original to copy
120 @return content of paint
121 */
Cary Clark0418a882017-05-10 09:07:42 -0400122 SkPaint& operator=(const SkPaint& paint);
Cary Clark50fa3ff2017-07-26 10:15:23 -0400123
Cary Clark8a02b0b2017-09-21 12:28:43 -0400124 /** Moves the paint to avoid increasing the reference counts
Cary Clarkb7da7232017-09-01 13:49:54 -0400125 of objects referenced by the paint parameter. Objects containing SkRefCnt in the
126 prior destination are decreased by one; those objects are deleted if the resulting count
127 is zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400128
129 After the call, paint is undefined, and can be safely destructed.
130
131 @param paint original to move
132 @return content of paint
133 */
Cary Clark0418a882017-05-10 09:07:42 -0400134 SkPaint& operator=(SkPaint&& paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000135
Cary Clark50fa3ff2017-07-26 10:15:23 -0400136 /** Compares a and b, and returns true if a and b are equivalent. May return false
Mike Reed8ad91a92018-01-19 19:09:32 -0500137 if SkTypeface, SkPathEffect, SkShader, SkMaskFilter, SkColorFilter,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400138 SkDrawLooper, or SkImageFilter have identical contents but different pointers.
139
140 @param a SkPaint to compare
141 @param b SkPaint to compare
142 @return true if SkPaint pair are equivalent
mtkleinbc97ef42014-08-25 10:10:47 -0700143 */
robertphillips@google.comb2657412013-08-07 22:36:29 +0000144 SK_API friend bool operator==(const SkPaint& a, const SkPaint& b);
Cary Clark50fa3ff2017-07-26 10:15:23 -0400145
146 /** Compares a and b, and returns true if a and b are not equivalent. May return true
Mike Reed8ad91a92018-01-19 19:09:32 -0500147 if SkTypeface, SkPathEffect, SkShader, SkMaskFilter, SkColorFilter,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400148 SkDrawLooper, or SkImageFilter have identical contents but different pointers.
149
150 @param a SkPaint to compare
151 @param b SkPaint to compare
152 @return true if SkPaint pair are not equivalent
153 */
robertphillips@google.comb2657412013-08-07 22:36:29 +0000154 friend bool operator!=(const SkPaint& a, const SkPaint& b) {
155 return !(a == b);
156 }
157
Cary Clark50fa3ff2017-07-26 10:15:23 -0400158 /** Returns a hash generated from SkPaint values and pointers.
159 Identical hashes guarantee that the paints are
160 equivalent, but differing hashes do not guarantee that the paints have differing
161 contents.
162
163 If operator==(const SkPaint& a, const SkPaint& b) returns true for two paints,
164 their hashes are also equal.
165
166 The hash returned is platform and implementation specific.
167
168 @return a shallow hash
169 */
mtkleinfb1fe4f2014-10-07 09:26:10 -0700170 uint32_t getHash() const;
171
Cary Clarkcc309eb2017-10-30 11:48:35 -0400172 /** Sets all SkPaint contents to their initial values. This is equivalent to replacing
173 SkPaint with the result of SkPaint().
reed@android.com8a1c16f2008-12-17 15:59:43 +0000174 */
175 void reset();
176
Cary Clark50fa3ff2017-07-26 10:15:23 -0400177 /** \enum SkPaint::Hinting
178 Hinting adjusts the glyph outlines so that the shape provides a uniform
179 look at a given point size on font engines that support it. Hinting may have a
180 muted effect or no effect at all depending on the platform.
181
182 The four levels roughly control corresponding features on platforms that use FreeType
183 as the font engine.
agl@chromium.org309485b2009-07-21 17:41:32 +0000184 */
185 enum Hinting {
Cary Clark462505f2018-05-30 09:20:29 -0400186 kNo_Hinting = 0, //!< glyph outlines unchanged
187 kSlight_Hinting = 1, //!< minimal modification to improve constrast
188 kNormal_Hinting = 2, //!< glyph outlines modified to improve constrast
189 kFull_Hinting = 3, //!< modifies glyph outlines for maximum constrast
agl@chromium.org309485b2009-07-21 17:41:32 +0000190 };
191
Cary Clark50fa3ff2017-07-26 10:15:23 -0400192 /** Returns level of glyph outline adjustment.
193
194 @return one of: kNo_Hinting, kSlight_Hinting, kNormal_Hinting, kFull_Hinting
195 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000196 Hinting getHinting() const {
reedf59eab22014-07-14 14:39:15 -0700197 return static_cast<Hinting>(fBitfields.fHinting);
agl@chromium.org309485b2009-07-21 17:41:32 +0000198 }
199
Cary Clark50fa3ff2017-07-26 10:15:23 -0400200 /** Sets level of glyph outline adjustment.
201 Does not check for valid values of hintingLevel.
202
203 @param hintingLevel one of: kNo_Hinting, kSlight_Hinting, kNormal_Hinting, kFull_Hinting
204 */
djsollen@google.comf5dbe2f2011-04-15 13:41:26 +0000205 void setHinting(Hinting hintingLevel);
agl@chromium.org309485b2009-07-21 17:41:32 +0000206
Cary Clark50fa3ff2017-07-26 10:15:23 -0400207 /** \enum SkPaint::Flags
208 The bit values stored in Flags.
209 The default value for Flags, normally zero, can be changed at compile time
210 with a custom definition of SkPaintDefaults_Flags.
211 All flags can be read and written explicitly; Flags allows manipulating
212 multiple settings at once.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000213 */
214 enum Flags {
Cary Clark1eace2d2017-07-31 07:52:43 -0400215 kAntiAlias_Flag = 0x01, //!< mask for setting anti-alias
216 kDither_Flag = 0x04, //!< mask for setting dither
Cary Clark50fa3ff2017-07-26 10:15:23 -0400217 kFakeBoldText_Flag = 0x20, //!< mask for setting fake bold
218 kLinearText_Flag = 0x40, //!< mask for setting linear text
219 kSubpixelText_Flag = 0x80, //!< mask for setting subpixel text
Cary Clark75959392018-02-27 10:22:04 -0500220 kLCDRenderText_Flag = 0x200, //!< mask for setting LCD text
Cary Clark50fa3ff2017-07-26 10:15:23 -0400221 kEmbeddedBitmapText_Flag = 0x400, //!< mask for setting font embedded bitmaps
222 kAutoHinting_Flag = 0x800, //!< mask for setting auto-hinting
223 kVerticalText_Flag = 0x1000, //!< mask for setting vertical text
Cary Clark462505f2018-05-30 09:20:29 -0400224 kAllFlags = 0xFFFF, //!< mask of all Flags
reed@android.com8a1c16f2008-12-17 15:59:43 +0000225 };
226
Cary Clark50fa3ff2017-07-26 10:15:23 -0400227 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Mike Reedddbd37e2017-02-21 15:07:44 -0500228 enum ReserveFlags {
Cary Clark462505f2018-05-30 09:20:29 -0400229 kUnderlineText_ReserveFlag = 0x08, //!< to be deprecated soon
230 kStrikeThruText_ReserveFlag = 0x10, //!< to be deprecated soon
Mike Reedddbd37e2017-02-21 15:07:44 -0500231 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400232 #endif
Mike Reedddbd37e2017-02-21 15:07:44 -0500233
Cary Clark50fa3ff2017-07-26 10:15:23 -0400234 /** Returns paint settings described by SkPaint::Flags. Each setting uses one
235 bit, and can be tested with SkPaint::Flags members.
236
237 @return zero, one, or more bits described by SkPaint::Flags
reed@android.com8a1c16f2008-12-17 15:59:43 +0000238 */
reedf59eab22014-07-14 14:39:15 -0700239 uint32_t getFlags() const { return fBitfields.fFlags; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000240
Cary Clark23890a92017-07-27 16:30:51 -0400241 /** Replaces SkPaint::Flags with flags, the union of the SkPaint::Flags members.
242 All SkPaint::Flags members may be cleared, or one or more may be set.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400243
244 @param flags union of SkPaint::Flags for SkPaint
reed@android.com8a1c16f2008-12-17 15:59:43 +0000245 */
246 void setFlags(uint32_t flags);
247
Cary Clark50fa3ff2017-07-26 10:15:23 -0400248 /** If true, pixels on the active edges of SkPath may be drawn with partial transparency.
249
Cary Clark579985c2017-07-31 11:48:27 -0400250 Equivalent to getFlags() masked with kAntiAlias_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400251
252 @return kAntiAlias_Flag state
253 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000254 bool isAntiAlias() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000255 return SkToBool(this->getFlags() & kAntiAlias_Flag);
256 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000257
Cary Clark50fa3ff2017-07-26 10:15:23 -0400258 /** Requests, but does not require, that SkPath edge pixels draw opaque or with
259 partial transparency.
260
261 Sets kAntiAlias_Flag if aa is true.
262 Clears kAntiAlias_Flag if aa is false.
263
264 @param aa setting for kAntiAlias_Flag
265 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000266 void setAntiAlias(bool aa);
reed@google.com9d07fec2011-03-16 20:02:59 +0000267
Cary Clark50fa3ff2017-07-26 10:15:23 -0400268 /** If true, color error may be distributed to smooth color transition.
269
Cary Clark579985c2017-07-31 11:48:27 -0400270 Equivalent to getFlags() masked with kDither_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400271
272 @return kDither_Flag state
273 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000274 bool isDither() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000275 return SkToBool(this->getFlags() & kDither_Flag);
276 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000277
Cary Clark50fa3ff2017-07-26 10:15:23 -0400278 /** Requests, but does not require, to distribute color error.
279
280 Sets kDither_Flag if dither is true.
281 Clears kDither_Flag if dither is false.
282
283 @param dither setting for kDither_Flag
284 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000285 void setDither(bool dither);
reed@google.com9d07fec2011-03-16 20:02:59 +0000286
Cary Clark50fa3ff2017-07-26 10:15:23 -0400287 /** If true, text is converted to SkPath before drawing and measuring.
288
Cary Clark579985c2017-07-31 11:48:27 -0400289 Equivalent to getFlags() masked with kLinearText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400290
291 @return kLinearText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000292 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000293 bool isLinearText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000294 return SkToBool(this->getFlags() & kLinearText_Flag);
295 }
296
Cary Clark50fa3ff2017-07-26 10:15:23 -0400297 /** If true, text is converted to SkPath before drawing and measuring.
298 By default, kLinearText_Flag is clear.
299
300 Sets kLinearText_Flag if linearText is true.
301 Clears kLinearText_Flag if linearText is false.
302
303 @param linearText setting for kLinearText_Flag
reed@android.com8a1c16f2008-12-17 15:59:43 +0000304 */
305 void setLinearText(bool linearText);
306
Cary Clark50fa3ff2017-07-26 10:15:23 -0400307 /** If true, glyphs at different sub-pixel positions may differ on pixel edge coverage.
308
Cary Clark579985c2017-07-31 11:48:27 -0400309 Equivalent to getFlags() masked with kSubpixelText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400310
311 @return kSubpixelText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000312 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000313 bool isSubpixelText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000314 return SkToBool(this->getFlags() & kSubpixelText_Flag);
315 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000316
Cary Clark50fa3ff2017-07-26 10:15:23 -0400317 /** Requests, but does not require, that glyphs respect sub-pixel positioning.
318
319 Sets kSubpixelText_Flag if subpixelText is true.
320 Clears kSubpixelText_Flag if subpixelText is false.
321
322 @param subpixelText setting for kSubpixelText_Flag
323 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000324 void setSubpixelText(bool subpixelText);
agl@chromium.org309485b2009-07-21 17:41:32 +0000325
Cary Clark50fa3ff2017-07-26 10:15:23 -0400326 /** If true, glyphs may use LCD striping to improve glyph edges.
327
328 Returns true if SkPaint::Flags kLCDRenderText_Flag is set.
329
330 @return kLCDRenderText_Flag state
331 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000332 bool isLCDRenderText() const {
agl@chromium.org309485b2009-07-21 17:41:32 +0000333 return SkToBool(this->getFlags() & kLCDRenderText_Flag);
334 }
335
Cary Clark50fa3ff2017-07-26 10:15:23 -0400336 /** Requests, but does not require, that glyphs use LCD striping for glyph edges.
337
338 Sets kLCDRenderText_Flag if lcdText is true.
339 Clears kLCDRenderText_Flag if lcdText is false.
340
341 @param lcdText setting for kLCDRenderText_Flag
342 */
reed@google.com84b437e2011-08-01 12:45:35 +0000343 void setLCDRenderText(bool lcdText);
agl@chromium.org309485b2009-07-21 17:41:32 +0000344
Cary Clark50fa3ff2017-07-26 10:15:23 -0400345 /** If true, font engine may return glyphs from font bitmaps instead of from outlines.
346
Cary Clark579985c2017-07-31 11:48:27 -0400347 Equivalent to getFlags() masked with kEmbeddedBitmapText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400348
349 @return kEmbeddedBitmapText_Flag state
350 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000351 bool isEmbeddedBitmapText() const {
agl@chromium.orge95c91e2010-01-04 18:27:55 +0000352 return SkToBool(this->getFlags() & kEmbeddedBitmapText_Flag);
353 }
354
Cary Clark50fa3ff2017-07-26 10:15:23 -0400355 /** Requests, but does not require, to use bitmaps in fonts instead of outlines.
356
357 Sets kEmbeddedBitmapText_Flag if useEmbeddedBitmapText is true.
358 Clears kEmbeddedBitmapText_Flag if useEmbeddedBitmapText is false.
359
360 @param useEmbeddedBitmapText setting for kEmbeddedBitmapText_Flag
agl@chromium.orge95c91e2010-01-04 18:27:55 +0000361 */
362 void setEmbeddedBitmapText(bool useEmbeddedBitmapText);
363
Cary Clark50fa3ff2017-07-26 10:15:23 -0400364 /** If true, and if SkPaint::Hinting is set to kNormal_Hinting or kFull_Hinting, and if
365 platform uses FreeType as the font manager, instruct the font manager to always hint
Cary Clark1eace2d2017-07-31 07:52:43 -0400366 glyphs.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400367
Cary Clark579985c2017-07-31 11:48:27 -0400368 Equivalent to getFlags() masked with kAutoHinting_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400369
370 @return kAutoHinting_Flag state
371 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000372 bool isAutohinted() const {
agl@chromium.orga2c71cb2010-06-17 20:49:17 +0000373 return SkToBool(this->getFlags() & kAutoHinting_Flag);
374 }
375
Cary Clark50fa3ff2017-07-26 10:15:23 -0400376 /** If SkPaint::Hinting is set to kNormal_Hinting or kFull_Hinting and useAutohinter is set,
Cary Clark1eace2d2017-07-31 07:52:43 -0400377 instruct the font manager to always hint glyphs.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400378 auto-hinting has no effect if SkPaint::Hinting is set to kNo_Hinting or
379 kSlight_Hinting.
380
Cary Clark579985c2017-07-31 11:48:27 -0400381 Only affects platforms that use FreeType as the font manager.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400382
383 Sets kAutoHinting_Flag if useAutohinter is true.
384 Clears kAutoHinting_Flag if useAutohinter is false.
385
386 @param useAutohinter setting for kAutoHinting_Flag
agl@chromium.orga2c71cb2010-06-17 20:49:17 +0000387 */
388 void setAutohinted(bool useAutohinter);
389
Cary Clark50fa3ff2017-07-26 10:15:23 -0400390 /** If true, glyphs are drawn top to bottom instead of left to right.
391
Cary Clark579985c2017-07-31 11:48:27 -0400392 Equivalent to getFlags() masked with kVerticalText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400393
394 @return kVerticalText_Flag state
395 */
reed@google.com830a23e2011-11-10 15:20:49 +0000396 bool isVerticalText() const {
397 return SkToBool(this->getFlags() & kVerticalText_Flag);
398 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000399
Cary Clark50fa3ff2017-07-26 10:15:23 -0400400 /** If true, text advance positions the next glyph below the previous glyph instead of to the
401 right of previous glyph.
402
403 Sets kVerticalText_Flag if vertical is true.
404 Clears kVerticalText_Flag if vertical is false.
405
406 @param verticalText setting for kVerticalText_Flag
407 */
Cary Clark0418a882017-05-10 09:07:42 -0400408 void setVerticalText(bool verticalText);
reed@google.com830a23e2011-11-10 15:20:49 +0000409
Cary Clark50fa3ff2017-07-26 10:15:23 -0400410 /** If true, approximate bold by increasing the stroke width when creating glyph bitmaps
411 from outlines.
412
Cary Clark579985c2017-07-31 11:48:27 -0400413 Equivalent to getFlags() masked with kFakeBoldText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400414
415 @return kFakeBoldText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000416 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000417 bool isFakeBoldText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000418 return SkToBool(this->getFlags() & kFakeBoldText_Flag);
419 }
420
Cary Clarkb7da7232017-09-01 13:49:54 -0400421 /** Use increased stroke width when creating glyph bitmaps to approximate a bold typeface.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400422
423 Sets kFakeBoldText_Flag if fakeBoldText is true.
424 Clears kFakeBoldText_Flag if fakeBoldText is false.
425
426 @param fakeBoldText setting for kFakeBoldText_Flag
reed@android.com8a1c16f2008-12-17 15:59:43 +0000427 */
428 void setFakeBoldText(bool fakeBoldText);
429
Cary Clark462505f2018-05-30 09:20:29 -0400430 /** Deprecated.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000431 */
Herb Derbyfcac00f2018-05-01 11:57:56 -0400432 bool isDevKernText() const { return false; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000433
Cary Clark462505f2018-05-30 09:20:29 -0400434 /** Deprecated.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000435 */
Herb Derbyfcac00f2018-05-01 11:57:56 -0400436 void setDevKernText(bool) { }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000437
Cary Clark50fa3ff2017-07-26 10:15:23 -0400438 /** Returns SkFilterQuality, the image filtering level. A lower setting
439 draws faster; a higher setting looks better when the image is scaled.
440
441 @return one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
442 kMedium_SkFilterQuality, kHigh_SkFilterQuality
443 */
reedf803da12015-01-23 05:58:07 -0800444 SkFilterQuality getFilterQuality() const {
445 return (SkFilterQuality)fBitfields.fFilterQuality;
446 }
mtkleinfe81e2d2015-09-09 07:35:42 -0700447
Cary Clark23890a92017-07-27 16:30:51 -0400448 /** Sets SkFilterQuality, the image filtering level. A lower setting
Cary Clark50fa3ff2017-07-26 10:15:23 -0400449 draws faster; a higher setting looks better when the image is scaled.
Cary Clark579985c2017-07-31 11:48:27 -0400450 Does not check to see if quality is valid.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400451
452 @param quality one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
453 kMedium_SkFilterQuality, kHigh_SkFilterQuality
454 */
reedf803da12015-01-23 05:58:07 -0800455 void setFilterQuality(SkFilterQuality quality);
reed@google.comc9683152013-07-18 13:47:01 +0000456
Cary Clark50fa3ff2017-07-26 10:15:23 -0400457 /** \enum SkPaint::Style
Cary Clark23890a92017-07-27 16:30:51 -0400458 Set Style to fill, stroke, or both fill and stroke geometry.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400459 The stroke and fill
460 share all paint attributes; for instance, they are drawn with the same color.
reed@google.com9d07fec2011-03-16 20:02:59 +0000461
Cary Clark50fa3ff2017-07-26 10:15:23 -0400462 Use kStrokeAndFill_Style to avoid hitting the same pixels twice with a stroke draw and
463 a fill draw.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000464 */
465 enum Style {
Cary Clark462505f2018-05-30 09:20:29 -0400466 kFill_Style, //!< set to fill geometry
467 kStroke_Style, //!< set to stroke geometry
468 kStrokeAndFill_Style, //!< sets to stroke and fill geometry
reed@android.com8a1c16f2008-12-17 15:59:43 +0000469 };
470
Cary Clark462505f2018-05-30 09:20:29 -0400471 /** May be used to verify that SkPaint::Style is a legal value.
Cary Clarkd98f78c2018-04-26 08:32:37 -0400472 */
473 static constexpr int kStyleCount = kStrokeAndFill_Style + 1;
Cary Clark50fa3ff2017-07-26 10:15:23 -0400474
475 /** Whether the geometry is filled, stroked, or filled and stroked.
476
477 @return one of:kFill_Style, kStroke_Style, kStrokeAndFill_Style
reed@android.com8a1c16f2008-12-17 15:59:43 +0000478 */
reedf59eab22014-07-14 14:39:15 -0700479 Style getStyle() const { return (Style)fBitfields.fStyle; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000480
Cary Clark50fa3ff2017-07-26 10:15:23 -0400481 /** Sets whether the geometry is filled, stroked, or filled and stroked.
482 Has no effect if style is not a legal SkPaint::Style value.
483
484 @param style one of: kFill_Style, kStroke_Style, kStrokeAndFill_Style
reed@android.com8a1c16f2008-12-17 15:59:43 +0000485 */
486 void setStyle(Style style);
487
Cary Clark50fa3ff2017-07-26 10:15:23 -0400488 /** Retrieves alpha and RGB, unpremultiplied, packed into 32 bits.
489 Use helpers SkColorGetA(), SkColorGetR(), SkColorGetG(), and SkColorGetB() to extract
490 a color component.
491
Cary Clark8a02b0b2017-09-21 12:28:43 -0400492 @return unpremultiplied ARGB
reed@android.com8a1c16f2008-12-17 15:59:43 +0000493 */
494 SkColor getColor() const { return fColor; }
495
Cary Clark50fa3ff2017-07-26 10:15:23 -0400496 /** Sets alpha and RGB used when stroking and filling. The color is a 32-bit value,
Cary Clarkb7da7232017-09-01 13:49:54 -0400497 unpremultiplied, packing 8-bit components for alpha, red, blue, and green.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400498
Cary Clark8a02b0b2017-09-21 12:28:43 -0400499 @param color unpremultiplied ARGB
reed@android.com8a1c16f2008-12-17 15:59:43 +0000500 */
501 void setColor(SkColor color);
502
Cary Clark1eace2d2017-07-31 07:52:43 -0400503 /** Retrieves alpha from the color used when stroking and filling.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400504
Cary Clark8a02b0b2017-09-21 12:28:43 -0400505 @return alpha ranging from zero, fully transparent, to 255, fully opaque
Cary Clark50fa3ff2017-07-26 10:15:23 -0400506 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000507 uint8_t getAlpha() const { return SkToU8(SkColorGetA(fColor)); }
reed@google.com9d07fec2011-03-16 20:02:59 +0000508
Cary Clark50fa3ff2017-07-26 10:15:23 -0400509 /** Replaces alpha, leaving RGB
510 unchanged. An out of range value triggers an assert in the debug
511 build. a is a value from zero to 255.
Cary Clark1eace2d2017-07-31 07:52:43 -0400512 a set to zero makes color fully transparent; a set to 255 makes color
Cary Clark50fa3ff2017-07-26 10:15:23 -0400513 fully opaque.
514
Cary Clark8a02b0b2017-09-21 12:28:43 -0400515 @param a alpha component of color
reed@android.com8a1c16f2008-12-17 15:59:43 +0000516 */
517 void setAlpha(U8CPU a);
518
Cary Clark1eace2d2017-07-31 07:52:43 -0400519 /** Sets color used when drawing solid fills. The color components range from 0 to 255.
Cary Clarkb7da7232017-09-01 13:49:54 -0400520 The color is unpremultiplied; alpha sets the transparency independent of RGB.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400521
Cary Clark462505f2018-05-30 09:20:29 -0400522 @param a amount of alpha, from fully transparent (0) to fully opaque (255)
523 @param r amount of red, from no red (0) to full red (255)
524 @param g amount of green, from no green (0) to full green (255)
525 @param b amount of blue, from no blue (0) to full blue (255)
reed@android.com8a1c16f2008-12-17 15:59:43 +0000526 */
527 void setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b);
528
Cary Clark50fa3ff2017-07-26 10:15:23 -0400529 /** Returns the thickness of the pen used by SkPaint to
530 outline the shape.
531
Cary Clark1eace2d2017-07-31 07:52:43 -0400532 @return zero for hairline, greater than zero for pen thickness
reed@android.com8a1c16f2008-12-17 15:59:43 +0000533 */
534 SkScalar getStrokeWidth() const { return fWidth; }
535
Cary Clark50fa3ff2017-07-26 10:15:23 -0400536 /** Sets the thickness of the pen used by the paint to
537 outline the shape.
538 Has no effect if width is less than zero.
539
Cary Clark1eace2d2017-07-31 07:52:43 -0400540 @param width zero thickness for hairline; greater than zero for pen thickness
reed@android.com8a1c16f2008-12-17 15:59:43 +0000541 */
542 void setStrokeWidth(SkScalar width);
543
Cary Clark50fa3ff2017-07-26 10:15:23 -0400544 /** The limit at which a sharp corner is drawn beveled.
545
546 @return zero and greater miter limit
reed@android.com8a1c16f2008-12-17 15:59:43 +0000547 */
548 SkScalar getStrokeMiter() const { return fMiterLimit; }
549
Cary Clark50fa3ff2017-07-26 10:15:23 -0400550 /** The limit at which a sharp corner is drawn beveled.
551 Valid values are zero and greater.
552 Has no effect if miter is less than zero.
553
554 @param miter zero and greater miter limit
reed@android.com8a1c16f2008-12-17 15:59:43 +0000555 */
556 void setStrokeMiter(SkScalar miter);
557
Cary Clark50fa3ff2017-07-26 10:15:23 -0400558 /** \enum SkPaint::Cap
559 Cap draws at the beginning and end of an open path contour.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000560 */
561 enum Cap {
Cary Clark462505f2018-05-30 09:20:29 -0400562 kButt_Cap, //!< no stroke extension
563 kRound_Cap, //!< adds circle
564 kSquare_Cap, //!< adds square
565 kLast_Cap = kSquare_Cap, //!< largest Cap value
566 kDefault_Cap = kButt_Cap, //!< equivalent to kButt_Cap
reed@android.com8a1c16f2008-12-17 15:59:43 +0000567 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400568
Cary Clark462505f2018-05-30 09:20:29 -0400569 /** May be used to verify that SkPaint::Cap is a legal value.
570 */
bsalomona7d85ba2016-07-06 11:54:59 -0700571 static constexpr int kCapCount = kLast_Cap + 1;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000572
Cary Clark50fa3ff2017-07-26 10:15:23 -0400573 /** \enum SkPaint::Join
Cary Clark1eace2d2017-07-31 07:52:43 -0400574 Join specifies how corners are drawn when a shape is stroked. Join
Cary Clark50fa3ff2017-07-26 10:15:23 -0400575 affects the four corners of a stroked rectangle, and the connected segments in a
576 stroked path.
577
578 Choose miter join to draw sharp corners. Choose round join to draw a circle with a
579 radius equal to the stroke width on top of the corner. Choose bevel join to minimally
580 connect the thick strokes.
581
582 The fill path constructed to describe the stroked path respects the join setting but may
583 not contain the actual join. For instance, a fill path constructed with round joins does
584 not necessarily include circles at each connected segment.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000585 */
586 enum Join {
Cary Clark462505f2018-05-30 09:20:29 -0400587 kMiter_Join, //!< extends to miter limit
588 kRound_Join, //!< adds circle
589 kBevel_Join, //!< connects outside edges
590 kLast_Join = kBevel_Join, //!< equivalent to the largest value for Join
591 kDefault_Join = kMiter_Join, //!< equivalent to kMiter_Join
reed@android.com8a1c16f2008-12-17 15:59:43 +0000592 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400593
Cary Clark462505f2018-05-30 09:20:29 -0400594 /** May be used to verify that SkPaint::Join is a legal value.
595 */
bsalomona7d85ba2016-07-06 11:54:59 -0700596 static constexpr int kJoinCount = kLast_Join + 1;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000597
Cary Clark50fa3ff2017-07-26 10:15:23 -0400598 /** The geometry drawn at the beginning and end of strokes.
599
600 @return one of: kButt_Cap, kRound_Cap, kSquare_Cap
reed@android.com8a1c16f2008-12-17 15:59:43 +0000601 */
reedf59eab22014-07-14 14:39:15 -0700602 Cap getStrokeCap() const { return (Cap)fBitfields.fCapType; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000603
Cary Clark50fa3ff2017-07-26 10:15:23 -0400604 /** The geometry drawn at the beginning and end of strokes.
605
606 @param cap one of: kButt_Cap, kRound_Cap, kSquare_Cap;
607 has no effect if cap is not valid
reed@android.com8a1c16f2008-12-17 15:59:43 +0000608 */
609 void setStrokeCap(Cap cap);
610
Cary Clark50fa3ff2017-07-26 10:15:23 -0400611 /** The geometry drawn at the corners of strokes.
612
613 @return one of: kMiter_Join, kRound_Join, kBevel_Join
reed@android.com8a1c16f2008-12-17 15:59:43 +0000614 */
reedf59eab22014-07-14 14:39:15 -0700615 Join getStrokeJoin() const { return (Join)fBitfields.fJoinType; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000616
Cary Clark50fa3ff2017-07-26 10:15:23 -0400617 /** The geometry drawn at the corners of strokes.
618
619 @param join one of: kMiter_Join, kRound_Join, kBevel_Join;
Cary Clark579985c2017-07-31 11:48:27 -0400620 otherwise, has no effect
reed@android.com8a1c16f2008-12-17 15:59:43 +0000621 */
622 void setStrokeJoin(Join join);
623
Cary Clark50fa3ff2017-07-26 10:15:23 -0400624 /** The filled equivalent of the stroked path.
625
626 @param src SkPath read to create a filled version
627 @param dst resulting SkPath; may be the same as src, but may not be nullptr
628 @param cullRect optional limit passed to SkPathEffect
629 @param resScale if > 1, increase precision, else if (0 < res < 1) reduce precision
630 to favor speed and size
Cary Clark1eace2d2017-07-31 07:52:43 -0400631 @return true if the path represents style fill, or false if it represents hairline
Cary Clark50fa3ff2017-07-26 10:15:23 -0400632 */
reed05d90442015-02-12 13:35:52 -0800633 bool getFillPath(const SkPath& src, SkPath* dst, const SkRect* cullRect,
634 SkScalar resScale = 1) const;
635
Cary Clark50fa3ff2017-07-26 10:15:23 -0400636 /** The filled equivalent of the stroked path.
637
Cary Clark23890a92017-07-27 16:30:51 -0400638 Replaces dst with the src path modified by SkPathEffect and style stroke.
639 SkPathEffect, if any, is not culled. stroke width is created with default precision.
640
641 @param src SkPath read to create a filled version
642 @param dst resulting SkPath dst may be the same as src, but may not be nullptr
Cary Clark1eace2d2017-07-31 07:52:43 -0400643 @return true if the path represents style fill, or false if it represents hairline
Cary Clark50fa3ff2017-07-26 10:15:23 -0400644 */
reed05d90442015-02-12 13:35:52 -0800645 bool getFillPath(const SkPath& src, SkPath* dst) const {
Ben Wagnera93a14a2017-08-28 10:34:05 -0400646 return this->getFillPath(src, dst, nullptr, 1);
reed05d90442015-02-12 13:35:52 -0800647 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000648
Cary Clark50fa3ff2017-07-26 10:15:23 -0400649 /** Optional colors used when filling a path, such as a gradient.
650
651 Does not alter SkShader SkRefCnt.
652
653 @return SkShader if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000654 */
reeda5ab9ec2016-03-06 18:10:48 -0800655 SkShader* getShader() const { return fShader.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400656
657 /** Optional colors used when filling a path, such as a gradient.
658
659 Increases SkShader SkRefCnt by one.
660
661 @return SkShader if previously set, nullptr otherwise
662 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500663 sk_sp<SkShader> refShader() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000664
Cary Clark50fa3ff2017-07-26 10:15:23 -0400665 /** Optional colors used when filling a path, such as a gradient.
666
Cary Clark8a02b0b2017-09-21 12:28:43 -0400667 Sets SkShader to shader, decreasing SkRefCnt of the previous SkShader.
668 Increments shader SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400669
Cary Clark1eace2d2017-07-31 07:52:43 -0400670 @param shader how geometry is filled with color; if nullptr, color is used instead
Cary Clark50fa3ff2017-07-26 10:15:23 -0400671 */
Cary Clark0418a882017-05-10 09:07:42 -0400672 void setShader(sk_sp<SkShader> shader);
reed@google.com9d07fec2011-03-16 20:02:59 +0000673
Cary Clark50fa3ff2017-07-26 10:15:23 -0400674 /** Returns SkColorFilter if set, or nullptr.
675 Does not alter SkColorFilter SkRefCnt.
676
677 @return SkColorFilter if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000678 */
reeda5ab9ec2016-03-06 18:10:48 -0800679 SkColorFilter* getColorFilter() const { return fColorFilter.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400680
681 /** Returns SkColorFilter if set, or nullptr.
682 Increases SkColorFilter SkRefCnt by one.
683
684 @return SkColorFilter if set, or nullptr
685 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500686 sk_sp<SkColorFilter> refColorFilter() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000687
Cary Clark8a02b0b2017-09-21 12:28:43 -0400688 /** Sets SkColorFilter to filter, decreasing SkRefCnt of the previous
689 SkColorFilter. Pass nullptr to clear SkColorFilter.
690
691 Increments filter SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400692
693 @param colorFilter SkColorFilter to apply to subsequent draw
reed@android.com8a1c16f2008-12-17 15:59:43 +0000694 */
Cary Clark0418a882017-05-10 09:07:42 -0400695 void setColorFilter(sk_sp<SkColorFilter> colorFilter);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000696
Cary Clark50fa3ff2017-07-26 10:15:23 -0400697 /** Returns SkBlendMode.
Cary Clark579985c2017-07-31 11:48:27 -0400698 By default, returns SkBlendMode::kSrcOver.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400699
700 @return mode used to combine source color with destination color
701 */
reed374772b2016-10-05 17:33:02 -0700702 SkBlendMode getBlendMode() const { return (SkBlendMode)fBlendMode; }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400703
704 /** Returns true if SkBlendMode is SkBlendMode::kSrcOver, the default.
705
706 @return true if SkBlendMode is SkBlendMode::kSrcOver
707 */
reed374772b2016-10-05 17:33:02 -0700708 bool isSrcOver() const { return (SkBlendMode)fBlendMode == SkBlendMode::kSrcOver; }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400709
710 /** Sets SkBlendMode to mode.
711 Does not check for valid input.
712
713 @param mode SkBlendMode used to combine source color and destination
714 */
reed374772b2016-10-05 17:33:02 -0700715 void setBlendMode(SkBlendMode mode) { fBlendMode = (unsigned)mode; }
reed@android.coma0f5d152009-06-22 17:38:10 +0000716
Cary Clark50fa3ff2017-07-26 10:15:23 -0400717 /** Returns SkPathEffect if set, or nullptr.
718 Does not alter SkPathEffect SkRefCnt.
719
720 @return SkPathEffect if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000721 */
reeda5ab9ec2016-03-06 18:10:48 -0800722 SkPathEffect* getPathEffect() const { return fPathEffect.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400723
724 /** Returns SkPathEffect if set, or nullptr.
725 Increases SkPathEffect SkRefCnt by one.
726
727 @return SkPathEffect if previously set, nullptr otherwise
728 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500729 sk_sp<SkPathEffect> refPathEffect() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000730
Cary Clark8a02b0b2017-09-21 12:28:43 -0400731 /** Sets SkPathEffect to pathEffect, decreasing SkRefCnt of the previous
732 SkPathEffect. Pass nullptr to leave the path geometry unaltered.
733
734 Increments pathEffect SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400735
736 @param pathEffect replace SkPath with a modification when drawn
reed@android.com8a1c16f2008-12-17 15:59:43 +0000737 */
Cary Clark0418a882017-05-10 09:07:42 -0400738 void setPathEffect(sk_sp<SkPathEffect> pathEffect);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000739
Cary Clark50fa3ff2017-07-26 10:15:23 -0400740 /** Returns SkMaskFilter if set, or nullptr.
741 Does not alter SkMaskFilter SkRefCnt.
742
743 @return SkMaskFilter if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000744 */
reeda5ab9ec2016-03-06 18:10:48 -0800745 SkMaskFilter* getMaskFilter() const { return fMaskFilter.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400746
747 /** Returns SkMaskFilter if set, or nullptr.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400748
Cary Clark50fa3ff2017-07-26 10:15:23 -0400749 Increases SkMaskFilter SkRefCnt by one.
750
751 @return SkMaskFilter if previously set, nullptr otherwise
752 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500753 sk_sp<SkMaskFilter> refMaskFilter() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000754
Cary Clark8a02b0b2017-09-21 12:28:43 -0400755 /** Sets SkMaskFilter to maskFilter, decreasing SkRefCnt of the previous
756 SkMaskFilter. Pass nullptr to clear SkMaskFilter and leave SkMaskFilter effect on
757 mask alpha unaltered.
758
Cary Clark75959392018-02-27 10:22:04 -0500759 Increments maskFilter SkRefCnt by one.
760
Cary Clark50fa3ff2017-07-26 10:15:23 -0400761 @param maskFilter modifies clipping mask generated from drawn geometry
reed@android.com8a1c16f2008-12-17 15:59:43 +0000762 */
Cary Clark0418a882017-05-10 09:07:42 -0400763 void setMaskFilter(sk_sp<SkMaskFilter> maskFilter);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000764
Cary Clark50fa3ff2017-07-26 10:15:23 -0400765 /** Returns SkTypeface if set, or nullptr.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400766 Increments SkTypeface SkRefCnt by one.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000767
Cary Clark50fa3ff2017-07-26 10:15:23 -0400768 @return SkTypeface if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000769 */
reeda5ab9ec2016-03-06 18:10:48 -0800770 SkTypeface* getTypeface() const { return fTypeface.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400771
772 /** Increases SkTypeface SkRefCnt by one.
773
774 @return SkTypeface if previously set, nullptr otherwise
775 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500776 sk_sp<SkTypeface> refTypeface() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000777
Cary Clark8a02b0b2017-09-21 12:28:43 -0400778 /** Sets SkTypeface to typeface, decreasing SkRefCnt of the previous SkTypeface.
779 Pass nullptr to clear SkTypeface and use the default typeface. Increments
780 typeface SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400781
782 @param typeface font and style used to draw text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000783 */
Cary Clark0418a882017-05-10 09:07:42 -0400784 void setTypeface(sk_sp<SkTypeface> typeface);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000785
Cary Clark50fa3ff2017-07-26 10:15:23 -0400786 /** Returns SkImageFilter if set, or nullptr.
787 Does not alter SkImageFilter SkRefCnt.
788
789 @return SkImageFilter if previously set, nullptr otherwise
790 */
reeda5ab9ec2016-03-06 18:10:48 -0800791 SkImageFilter* getImageFilter() const { return fImageFilter.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400792
793 /** Returns SkImageFilter if set, or nullptr.
794 Increases SkImageFilter SkRefCnt by one.
795
796 @return SkImageFilter if previously set, nullptr otherwise
797 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500798 sk_sp<SkImageFilter> refImageFilter() const;
Cary Clark50fa3ff2017-07-26 10:15:23 -0400799
Cary Clark8a02b0b2017-09-21 12:28:43 -0400800 /** Sets SkImageFilter to imageFilter, decreasing SkRefCnt of the previous
801 SkImageFilter. Pass nullptr to clear SkImageFilter, and remove SkImageFilter effect
Cary Clark50fa3ff2017-07-26 10:15:23 -0400802 on drawing.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400803
Cary Clark75959392018-02-27 10:22:04 -0500804 Increments imageFilter SkRefCnt by one.
805
Cary Clark50fa3ff2017-07-26 10:15:23 -0400806 @param imageFilter how SkImage is sampled when transformed
807 */
Cary Clark0418a882017-05-10 09:07:42 -0400808 void setImageFilter(sk_sp<SkImageFilter> imageFilter);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000809
Cary Clark50fa3ff2017-07-26 10:15:23 -0400810 /** Returns SkDrawLooper if set, or nullptr.
811 Does not alter SkDrawLooper SkRefCnt.
812
813 @return SkDrawLooper if previously set, nullptr otherwise
814 */
reed46f2d0a2016-09-11 05:40:31 -0700815 SkDrawLooper* getDrawLooper() const { return fDrawLooper.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400816
817 /** Returns SkDrawLooper if set, or nullptr.
818 Increases SkDrawLooper SkRefCnt by one.
819
820 @return SkDrawLooper if previously set, nullptr otherwise
821 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500822 sk_sp<SkDrawLooper> refDrawLooper() const;
823
Cary Clark23890a92017-07-27 16:30:51 -0400824 /** Deprecated.
Cary Clark75959392018-02-27 10:22:04 -0500825 (see skbug.com/6259)
Cary Clark50fa3ff2017-07-26 10:15:23 -0400826 */
reed46f2d0a2016-09-11 05:40:31 -0700827 SkDrawLooper* getLooper() const { return fDrawLooper.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400828
Cary Clark8a02b0b2017-09-21 12:28:43 -0400829 /** Sets SkDrawLooper to drawLooper, decreasing SkRefCnt of the previous
830 drawLooper. Pass nullptr to clear SkDrawLooper and leave SkDrawLooper effect on
831 drawing unaltered.
832
833 Increments drawLooper SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400834
Cary Clarkb7da7232017-09-01 13:49:54 -0400835 @param drawLooper iterates through drawing one or more time, altering SkPaint
Cary Clark50fa3ff2017-07-26 10:15:23 -0400836 */
Cary Clark0418a882017-05-10 09:07:42 -0400837 void setDrawLooper(sk_sp<SkDrawLooper> drawLooper);
Mike Reed09d94352016-10-31 15:11:04 -0400838
Cary Clark23890a92017-07-27 16:30:51 -0400839 /** Deprecated.
Cary Clark75959392018-02-27 10:22:04 -0500840 (see skbug.com/6259)
Cary Clark50fa3ff2017-07-26 10:15:23 -0400841 */
Cary Clark0418a882017-05-10 09:07:42 -0400842 void setLooper(sk_sp<SkDrawLooper> drawLooper);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000843
Cary Clark50fa3ff2017-07-26 10:15:23 -0400844 /** \enum SkPaint::Align
845 Align adjusts the text relative to the text position.
846 Align affects glyphs drawn with: SkCanvas::drawText, SkCanvas::drawPosText,
847 SkCanvas::drawPosTextH, SkCanvas::drawTextOnPath,
848 SkCanvas::drawTextOnPathHV, SkCanvas::drawTextRSXform, SkCanvas::drawTextBlob,
849 and SkCanvas::drawString;
Cary Clark579985c2017-07-31 11:48:27 -0400850 as well as calls that place text glyphs like getTextWidths() and getTextPath().
Cary Clark50fa3ff2017-07-26 10:15:23 -0400851
852 The text position is set by the font for both horizontal and vertical text.
853 Typically, for horizontal text, the position is to the left side of the glyph on the
Cary Clark23890a92017-07-27 16:30:51 -0400854 base line; and for vertical text, the position is the horizontal center of the glyph
Cary Clark50fa3ff2017-07-26 10:15:23 -0400855 at the caps height.
856
857 Align adjusts the glyph position to center it or move it to abut the position
858 using the metrics returned by the font.
859
860 Align defaults to kLeft_Align.
861 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000862 enum Align {
Cary Clark462505f2018-05-30 09:20:29 -0400863 kLeft_Align, //!< positions glyph by computed font offset
864 kCenter_Align, //!< centers line of glyphs by its width or height
865 kRight_Align, //!< moves lines of glyphs by its width or height
mike@reedtribe.orgddc813b2013-06-08 12:58:19 +0000866 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400867
Cary Clark462505f2018-05-30 09:20:29 -0400868 /** May be used to verify that align is a legal value.
869 */
870 static constexpr int kAlignCount = 3;
reed@google.com9d07fec2011-03-16 20:02:59 +0000871
Cary Clark50fa3ff2017-07-26 10:15:23 -0400872 /** Returns SkPaint::Align.
873 Returns kLeft_Align if SkPaint::Align has not been set.
874
875 @return text placement relative to position
reed@android.com8a1c16f2008-12-17 15:59:43 +0000876 */
reedf59eab22014-07-14 14:39:15 -0700877 Align getTextAlign() const { return (Align)fBitfields.fTextAlign; }
reed@google.com9d07fec2011-03-16 20:02:59 +0000878
Cary Clark50fa3ff2017-07-26 10:15:23 -0400879 /** Sets SkPaint::Align to align.
880 Has no effect if align is an invalid value.
881
882 @param align text placement relative to position
reed@android.com8a1c16f2008-12-17 15:59:43 +0000883 */
884 void setTextAlign(Align align);
885
Cary Clark50fa3ff2017-07-26 10:15:23 -0400886 /** Returns text size in points.
887
888 @return typographic height of text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000889 */
890 SkScalar getTextSize() const { return fTextSize; }
891
Cary Clark50fa3ff2017-07-26 10:15:23 -0400892 /** Sets text size in points.
893 Has no effect if textSize is not greater than or equal to zero.
894
895 @param textSize typographic height of text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000896 */
897 void setTextSize(SkScalar textSize);
898
Cary Clark50fa3ff2017-07-26 10:15:23 -0400899 /** Returns text scale x.
900 Default value is 1.
901
902 @return text horizontal scale
reed@android.com8a1c16f2008-12-17 15:59:43 +0000903 */
904 SkScalar getTextScaleX() const { return fTextScaleX; }
905
Cary Clark50fa3ff2017-07-26 10:15:23 -0400906 /** Sets text scale x.
907 Default value is 1.
908
909 @param scaleX text horizontal scale
reed@android.com8a1c16f2008-12-17 15:59:43 +0000910 */
911 void setTextScaleX(SkScalar scaleX);
912
Cary Clark50fa3ff2017-07-26 10:15:23 -0400913 /** Returns text skew x.
914 Default value is zero.
915
916 @return additional shear in x-axis relative to y-axis
reed@android.com8a1c16f2008-12-17 15:59:43 +0000917 */
918 SkScalar getTextSkewX() const { return fTextSkewX; }
919
Cary Clark50fa3ff2017-07-26 10:15:23 -0400920 /** Sets text skew x.
921 Default value is zero.
922
923 @param skewX additional shear in x-axis relative to y-axis
reed@android.com8a1c16f2008-12-17 15:59:43 +0000924 */
925 void setTextSkewX(SkScalar skewX);
926
Cary Clark50fa3ff2017-07-26 10:15:23 -0400927 /** \enum SkPaint::TextEncoding
Cary Clark8a02b0b2017-09-21 12:28:43 -0400928 TextEncoding determines whether text specifies character codes and their encoded
Cary Clarkcc309eb2017-10-30 11:48:35 -0400929 size, or glyph indices. Characters are encoded as specified by the Unicode standard.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400930
Cary Clark50fa3ff2017-07-26 10:15:23 -0400931 Character codes encoded size are specified by UTF-8, UTF-16, or UTF-32.
Cary Clarkcc309eb2017-10-30 11:48:35 -0400932 All character code formats are able to represent all of Unicode, differing only
933 in the total storage required.
934
935 UTF-8 (RFC 3629) encodes each character as one or more 8-bit bytes.
936
937 UTF-16 (RFC 2781) encodes each character as one or two 16-bit words.
938
939 UTF-32 encodes each character as one 32-bit word.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400940
941 font manager uses font data to convert character code points into glyph indices.
942 A glyph index is a 16-bit word.
943
944 TextEncoding is set to kUTF8_TextEncoding by default.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000945 */
946 enum TextEncoding {
Cary Clark462505f2018-05-30 09:20:29 -0400947 kUTF8_TextEncoding, //!< uses bytes to represent UTF-8 or ASCII
948 kUTF16_TextEncoding, //!< uses two byte words to represent most of Unicode
949 kUTF32_TextEncoding, //!< uses four byte words to represent all of Unicode
950 kGlyphID_TextEncoding, //!< uses two byte words to represent glyph indices
reed@android.com8a1c16f2008-12-17 15:59:43 +0000951 };
reed@google.com9d07fec2011-03-16 20:02:59 +0000952
Cary Clark50fa3ff2017-07-26 10:15:23 -0400953 /** Returns SkPaint::TextEncoding.
954 SkPaint::TextEncoding determines how character code points are mapped to font glyph indices.
955
956 @return one of: kUTF8_TextEncoding, kUTF16_TextEncoding, kUTF32_TextEncoding, or
957 kGlyphID_TextEncoding
958 */
reedf59eab22014-07-14 14:39:15 -0700959 TextEncoding getTextEncoding() const {
960 return (TextEncoding)fBitfields.fTextEncoding;
961 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000962
Cary Clark50fa3ff2017-07-26 10:15:23 -0400963 /** Sets SkPaint::TextEncoding to encoding.
964 SkPaint::TextEncoding determines how character code points are mapped to font glyph indices.
965 Invalid values for encoding are ignored.
966
967 @param encoding one of: kUTF8_TextEncoding, kUTF16_TextEncoding, kUTF32_TextEncoding, or
Cary Clark579985c2017-07-31 11:48:27 -0400968 kGlyphID_TextEncoding
Cary Clark50fa3ff2017-07-26 10:15:23 -0400969 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000970 void setTextEncoding(TextEncoding encoding);
971
Cary Clark50fa3ff2017-07-26 10:15:23 -0400972 /** \struct SkPaint::FontMetrics
Cary Clark579985c2017-07-31 11:48:27 -0400973 FontMetrics is filled out by getFontMetrics(). FontMetrics contents reflect the values
Cary Clark50fa3ff2017-07-26 10:15:23 -0400974 computed by font manager using SkTypeface. Values are set to zero if they are
Cary Clarkb7da7232017-09-01 13:49:54 -0400975 not available.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400976
Ben Wagnere5806492017-11-09 12:08:31 -0500977 All vertical values relative to the baseline are given y-down. As such, zero is on the
978 baseline, negative values are above the baseline, and positive values are below the
979 baseline.
980
Cary Clark50fa3ff2017-07-26 10:15:23 -0400981 fUnderlineThickness and fUnderlinePosition have a bit set in fFlags if their values
982 are valid, since their value may be zero.
983
984 fStrikeoutThickness and fStrikeoutPosition have a bit set in fFlags if their values
985 are valid, since their value may be zero.
986 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000987 struct FontMetrics {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400988
Cary Clarkcc309eb2017-10-30 11:48:35 -0400989 /** \enum SkPaint::FontMetrics::FontMetricsFlags
990 FontMetricsFlags are set in fFlags when underline and strikeout metrics are valid;
991 the underline or strikeout metric may be valid and zero.
992 Fonts with embedded bitmaps may not have valid underline or strikeout metrics.
993 */
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +0000994 enum FontMetricsFlags {
Cary Clark462505f2018-05-30 09:20:29 -0400995 kUnderlineThicknessIsValid_Flag = 1 << 0, //!< set if fUnderlineThickness is valid
996 kUnderlinePositionIsValid_Flag = 1 << 1, //!< set if fUnderlinePosition is valid
997 kStrikeoutThicknessIsValid_Flag = 1 << 2, //!< set if fStrikeoutThickness is valid
998 kStrikeoutPositionIsValid_Flag = 1 << 3, //!< set if fStrikeoutPosition is valid
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +0000999 };
1000
Cary Clark462505f2018-05-30 09:20:29 -04001001 uint32_t fFlags; //!< is set to FontMetricsFlags when metrics are valid
1002 SkScalar fTop; //!< extent above baseline
1003 SkScalar fAscent; //!< distance to reserve above baseline
1004 SkScalar fDescent; //!< distance to reserve below baseline
1005 SkScalar fBottom; //!< extent below baseline
1006 SkScalar fLeading; //!< distance to add between lines
1007 SkScalar fAvgCharWidth; //!< average character width
1008 SkScalar fMaxCharWidth; //!< maximum character width
1009 SkScalar fXMin; //!< minimum x
1010 SkScalar fXMax; //!< maximum x
1011 SkScalar fXHeight; //!< height of lower-case 'x'
1012 SkScalar fCapHeight; //!< height of an upper-case letter
1013 SkScalar fUnderlineThickness; //!< underline thickness
1014 SkScalar fUnderlinePosition; //!< underline position relative to baseline
1015 SkScalar fStrikeoutThickness; //!< strikeout thickness
1016 SkScalar fStrikeoutPosition; //!< strikeout position relative to baseline
Cary Clark50fa3ff2017-07-26 10:15:23 -04001017
1018 /** If SkPaint::FontMetrics has a valid underline thickness, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001019 thickness to that value. If the underline thickness is not valid,
1020 return false, and ignore thickness.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001021
1022 @param thickness storage for underline width
1023 @return true if font specifies underline width
1024 */
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001025 bool hasUnderlineThickness(SkScalar* thickness) const {
Ben Wagner3318da52017-03-23 14:01:22 -04001026 if (SkToBool(fFlags & kUnderlineThicknessIsValid_Flag)) {
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001027 *thickness = fUnderlineThickness;
1028 return true;
1029 }
1030 return false;
1031 }
1032
Cary Clark50fa3ff2017-07-26 10:15:23 -04001033 /** If SkPaint::FontMetrics has a valid underline position, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001034 position to that value. If the underline position is not valid,
1035 return false, and ignore position.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001036
1037 @param position storage for underline position
1038 @return true if font specifies underline position
1039 */
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001040 bool hasUnderlinePosition(SkScalar* position) const {
1041 if (SkToBool(fFlags & kUnderlinePositionIsValid_Flag)) {
1042 *position = fUnderlinePosition;
1043 return true;
1044 }
1045 return false;
1046 }
1047
Cary Clark50fa3ff2017-07-26 10:15:23 -04001048 /** If SkPaint::FontMetrics has a valid strikeout thickness, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001049 thickness to that value. If the underline thickness is not valid,
1050 return false, and ignore thickness.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001051
1052 @param thickness storage for strikeout width
1053 @return true if font specifies strikeout width
1054 */
Ben Wagner219f3622017-07-17 15:32:25 -04001055 bool hasStrikeoutThickness(SkScalar* thickness) const {
1056 if (SkToBool(fFlags & kStrikeoutThicknessIsValid_Flag)) {
1057 *thickness = fStrikeoutThickness;
1058 return true;
1059 }
1060 return false;
1061 }
1062
Cary Clark50fa3ff2017-07-26 10:15:23 -04001063 /** If SkPaint::FontMetrics has a valid strikeout position, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001064 position to that value. If the underline position is not valid,
1065 return false, and ignore position.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001066
1067 @param position storage for strikeout position
1068 @return true if font specifies strikeout position
1069 */
Ben Wagner219f3622017-07-17 15:32:25 -04001070 bool hasStrikeoutPosition(SkScalar* position) const {
1071 if (SkToBool(fFlags & kStrikeoutPositionIsValid_Flag)) {
1072 *position = fStrikeoutPosition;
1073 return true;
1074 }
1075 return false;
1076 }
Cary Clark50fa3ff2017-07-26 10:15:23 -04001077
reed@android.com8a1c16f2008-12-17 15:59:43 +00001078 };
reed@google.com9d07fec2011-03-16 20:02:59 +00001079
Cary Clark50fa3ff2017-07-26 10:15:23 -04001080 /** Returns SkPaint::FontMetrics associated with SkTypeface.
1081 The return value is the recommended spacing between lines: the sum of metrics
1082 descent, ascent, and leading.
1083 If metrics is not nullptr, SkPaint::FontMetrics is copied to metrics.
1084 Results are scaled by text size but does not take into account
1085 dimensions required by text scale x, text skew x, fake bold,
1086 style stroke, and SkPathEffect.
1087 Results can be additionally scaled by scale; a scale of zero
1088 is ignored.
1089
1090 @param metrics storage for SkPaint::FontMetrics from SkTypeface; may be nullptr
1091 @param scale additional multiplier for returned values
1092 @return recommended spacing between lines
reed@android.com8a1c16f2008-12-17 15:59:43 +00001093 */
1094 SkScalar getFontMetrics(FontMetrics* metrics, SkScalar scale = 0) const;
reed@google.com9d07fec2011-03-16 20:02:59 +00001095
Cary Clark50fa3ff2017-07-26 10:15:23 -04001096 /** Returns the recommended spacing between lines: the sum of metrics
1097 descent, ascent, and leading.
1098 Result is scaled by text size but does not take into account
1099 dimensions required by stroking and SkPathEffect.
Cary Clark579985c2017-07-31 11:48:27 -04001100 Returns the same result as getFontMetrics().
Cary Clark50fa3ff2017-07-26 10:15:23 -04001101
1102 @return recommended spacing between lines
reed@android.com8a1c16f2008-12-17 15:59:43 +00001103 */
Ben Wagnera93a14a2017-08-28 10:34:05 -04001104 SkScalar getFontSpacing() const { return this->getFontMetrics(nullptr, 0); }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001105
Cary Clark50fa3ff2017-07-26 10:15:23 -04001106 /** Converts text into glyph indices.
1107 Returns the number of glyph indices represented by text.
1108 SkPaint::TextEncoding specifies how text represents characters or glyphs.
1109 glyphs may be nullptr, to compute the glyph count.
1110
Cary Clarkcc309eb2017-10-30 11:48:35 -04001111 Does not check text for valid character codes or valid glyph indices.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001112
Cary Clark579985c2017-07-31 11:48:27 -04001113 If byteLength equals zero, returns zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001114 If byteLength includes a partial character, the partial character is ignored.
1115
1116 If SkPaint::TextEncoding is kUTF8_TextEncoding and
1117 text contains an invalid UTF-8 sequence, zero is returned.
1118
Cary Clarkb7da7232017-09-01 13:49:54 -04001119 @param text character storage encoded with SkPaint::TextEncoding
Cary Clark50fa3ff2017-07-26 10:15:23 -04001120 @param byteLength length of character storage in bytes
1121 @param glyphs storage for glyph indices; may be nullptr
1122 @return number of glyphs represented by text of length byteLength
reed@android.com8a1c16f2008-12-17 15:59:43 +00001123 */
1124 int textToGlyphs(const void* text, size_t byteLength,
halcanaryd0e95a52016-07-25 07:18:12 -07001125 SkGlyphID glyphs[]) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001126
Cary Clark50fa3ff2017-07-26 10:15:23 -04001127 /** Returns true if all text corresponds to a non-zero glyph index.
1128 Returns false if any characters in text are not supported in
1129 SkTypeface.
reed@android.coma5dcaf62010-02-05 17:12:32 +00001130
Cary Clark579985c2017-07-31 11:48:27 -04001131 If SkPaint::TextEncoding is kGlyphID_TextEncoding,
1132 returns true if all glyph indices in text are non-zero;
Cary Clark50fa3ff2017-07-26 10:15:23 -04001133 does not check to see if text contains valid glyph indices for SkTypeface.
1134
Cary Clarkb7da7232017-09-01 13:49:54 -04001135 Returns true if byteLength is zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001136
1137 @param text array of characters or glyphs
1138 @param byteLength number of bytes in text array
1139 @return true if all text corresponds to a non-zero glyph index
1140 */
reed@android.coma5dcaf62010-02-05 17:12:32 +00001141 bool containsText(const void* text, size_t byteLength) const;
1142
Cary Clark50fa3ff2017-07-26 10:15:23 -04001143 /** Converts glyphs into text if possible.
1144 Glyph values without direct Unicode equivalents are mapped to zero.
1145 Uses the SkTypeface, but is unaffected
1146 by SkPaint::TextEncoding; the text values returned are equivalent to kUTF32_TextEncoding.
1147
1148 Only supported on platforms that use FreeType as the font engine.
1149
1150 @param glyphs array of indices into font
1151 @param count length of glyph array
1152 @param text storage for character codes, one per glyph
reed@android.com9d3a9852010-01-08 14:07:42 +00001153 */
halcanaryd0e95a52016-07-25 07:18:12 -07001154 void glyphsToUnichars(const SkGlyphID glyphs[], int count, SkUnichar text[]) const;
reed@android.com9d3a9852010-01-08 14:07:42 +00001155
Cary Clark50fa3ff2017-07-26 10:15:23 -04001156 /** Returns the number of glyphs in text.
1157 Uses SkPaint::TextEncoding to count the glyphs.
Cary Clark579985c2017-07-31 11:48:27 -04001158 Returns the same result as textToGlyphs().
Cary Clark50fa3ff2017-07-26 10:15:23 -04001159
Cary Clarkb7da7232017-09-01 13:49:54 -04001160 @param text character storage encoded with SkPaint::TextEncoding
Cary Clark50fa3ff2017-07-26 10:15:23 -04001161 @param byteLength length of character storage in bytes
1162 @return number of glyphs represented by text of length byteLength
reed@android.com8a1c16f2008-12-17 15:59:43 +00001163 */
Herb Derby90864a22018-05-02 13:43:49 -04001164 int countText(const void* text, size_t byteLength) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001165
Cary Clark50fa3ff2017-07-26 10:15:23 -04001166 /** Returns the advance width of text if kVerticalText_Flag is clear,
1167 and the height of text if kVerticalText_Flag is set.
1168 The advance is the normal distance to move before drawing additional text.
1169 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
1170 and text size, text scale x, text skew x, stroke width, and
1171 SkPathEffect to scale the metrics and bounds.
1172 Returns the bounding box of text if bounds is not nullptr.
1173 The bounding box is computed as if the text was drawn at the origin.
1174
1175 @param text character codes or glyph indices to be measured
1176 @param length number of bytes of text to measure
1177 @param bounds returns bounding box relative to (0, 0) if not nullptr
1178 @return advance width or height
1179 */
reed99ae8812014-08-26 11:30:01 -07001180 SkScalar measureText(const void* text, size_t length, SkRect* bounds) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001181
Cary Clark50fa3ff2017-07-26 10:15:23 -04001182 /** Returns the advance width of text if kVerticalText_Flag is clear,
1183 and the height of text if kVerticalText_Flag is set.
1184 The advance is the normal distance to move before drawing additional text.
1185 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
Cary Clark23890a92017-07-27 16:30:51 -04001186 and text size to scale the metrics.
1187 Does not scale the advance or bounds by fake bold or SkPathEffect.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001188
1189 @param text character codes or glyph indices to be measured
1190 @param length number of bytes of text to measure
Cary Clark50fa3ff2017-07-26 10:15:23 -04001191 @return advance width or height
1192 */
reed@google.com9d07fec2011-03-16 20:02:59 +00001193 SkScalar measureText(const void* text, size_t length) const {
Ben Wagnera93a14a2017-08-28 10:34:05 -04001194 return this->measureText(text, length, nullptr);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001195 }
reed@google.com9d07fec2011-03-16 20:02:59 +00001196
Cary Clark50fa3ff2017-07-26 10:15:23 -04001197 /** Returns the bytes of text that fit within maxWidth.
1198 If kVerticalText_Flag is clear, the text fragment fits if its advance width is less than or
1199 equal to maxWidth.
1200 If kVerticalText_Flag is set, the text fragment fits if its advance height is less than or
1201 equal to maxWidth.
1202 Measures only while the advance is less than or equal to maxWidth.
1203 Returns the advance or the text fragment in measuredWidth if it not nullptr.
1204 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
1205 and text size to scale the metrics.
1206 Does not scale the advance or bounds by fake bold or SkPathEffect.
1207
1208 @param text character codes or glyph indices to be measured
1209 @param length number of bytes of text to measure
1210 @param maxWidth advance limit; text is measured while advance is less than maxWidth
1211 @param measuredWidth returns the width of the text less than or equal to maxWidth
1212 @return bytes of text that fit, always less than or equal to length
1213 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001214 size_t breakText(const void* text, size_t length, SkScalar maxWidth,
Ben Wagnera93a14a2017-08-28 10:34:05 -04001215 SkScalar* measuredWidth = nullptr) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001216
Cary Clark50fa3ff2017-07-26 10:15:23 -04001217 /** Retrieves the advance and bounds for each glyph in text, and returns
1218 the glyph count in text.
1219 Both widths and bounds may be nullptr.
1220 If widths is not nullptr, widths must be an array of glyph count entries.
1221 if bounds is not nullptr, bounds must be an array of glyph count entries.
1222 If kVerticalText_Flag is clear, widths returns the horizontal advance.
1223 If kVerticalText_Flag is set, widths returns the vertical advance.
1224 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
1225 and text size to scale the widths and bounds.
1226 Does not scale the advance by fake bold or SkPathEffect.
Cary Clark23890a92017-07-27 16:30:51 -04001227 Does include fake bold and SkPathEffect in the bounds.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001228
1229 @param text character codes or glyph indices to be measured
1230 @param byteLength number of bytes of text to measure
1231 @param widths returns text advances for each glyph; may be nullptr
1232 @param bounds returns bounds for each glyph relative to (0, 0); may be nullptr
1233 @return glyph count in text
1234 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001235 int getTextWidths(const void* text, size_t byteLength, SkScalar widths[],
Ben Wagnera93a14a2017-08-28 10:34:05 -04001236 SkRect bounds[] = nullptr) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001237
Cary Clark50fa3ff2017-07-26 10:15:23 -04001238 /** Returns the geometry as SkPath equivalent to the drawn text.
1239 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1240 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1241 All of the glyph paths are stored in path.
Cary Clark579985c2017-07-31 11:48:27 -04001242 Uses x, y, and SkPaint::Align to position path.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001243
1244 @param text character codes or glyph indices
1245 @param length number of bytes of text
1246 @param x x-coordinate of the origin of the text
1247 @param y y-coordinate of the origin of the text
1248 @param path geometry of the glyphs
1249 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001250 void getTextPath(const void* text, size_t length, SkScalar x, SkScalar y,
1251 SkPath* path) const;
1252
Cary Clark50fa3ff2017-07-26 10:15:23 -04001253 /** Returns the geometry as SkPath equivalent to the drawn text.
1254 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1255 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1256 All of the glyph paths are stored in path.
1257 Uses pos array and SkPaint::Align to position path.
1258 pos contains a position for each glyph.
1259
1260 @param text character codes or glyph indices
1261 @param length number of bytes of text
1262 @param pos positions of each glyph
1263 @param path geometry of the glyphs
1264 */
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001265 void getPosTextPath(const void* text, size_t length,
reed@google.comca0062e2012-07-20 11:20:32 +00001266 const SkPoint pos[], SkPath* path) const;
1267
Cary Clark50fa3ff2017-07-26 10:15:23 -04001268 /** Returns the number of intervals that intersect bounds.
1269 bounds describes a pair of lines parallel to the text advance.
1270 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1271 the string.
1272 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1273 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1274 Uses x, y, and SkPaint::Align to position intervals.
1275
1276 Pass nullptr for intervals to determine the size of the interval array.
1277
1278 intervals are cached to improve performance for multiple calls.
1279
1280 @param text character codes or glyph indices
1281 @param length number of bytes of text
1282 @param x x-coordinate of the origin of the text
1283 @param y y-coordinate of the origin of the text
1284 @param bounds lower and upper line parallel to the advance
1285 @param intervals returned intersections; may be nullptr
1286 @return number of intersections; may be zero
1287 */
caryclark0449bcf2016-02-09 13:25:45 -08001288 int getTextIntercepts(const void* text, size_t length, SkScalar x, SkScalar y,
1289 const SkScalar bounds[2], SkScalar* intervals) const;
1290
Cary Clark50fa3ff2017-07-26 10:15:23 -04001291 /** Returns the number of intervals that intersect bounds.
1292 bounds describes a pair of lines parallel to the text advance.
1293 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1294 the string.
1295 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1296 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1297 Uses pos array and SkPaint::Align to position intervals.
1298
1299 Pass nullptr for intervals to determine the size of the interval array.
1300
1301 intervals are cached to improve performance for multiple calls.
1302
1303 @param text character codes or glyph indices
1304 @param length number of bytes of text
1305 @param pos positions of each glyph
1306 @param bounds lower and upper line parallel to the advance
1307 @param intervals returned intersections; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -04001308 @return number of intersections; may be zero
Cary Clark50fa3ff2017-07-26 10:15:23 -04001309 */
caryclark0449bcf2016-02-09 13:25:45 -08001310 int getPosTextIntercepts(const void* text, size_t length, const SkPoint pos[],
1311 const SkScalar bounds[2], SkScalar* intervals) const;
1312
Cary Clark50fa3ff2017-07-26 10:15:23 -04001313 /** Returns the number of intervals that intersect bounds.
1314 bounds describes a pair of lines parallel to the text advance.
1315 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1316 the string.
1317 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1318 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1319 Uses xpos array, constY, and SkPaint::Align to position intervals.
1320
1321 Pass nullptr for intervals to determine the size of the interval array.
1322
1323 intervals are cached to improve performance for multiple calls.
1324
1325 @param text character codes or glyph indices
1326 @param length number of bytes of text
1327 @param xpos positions of each glyph in x
1328 @param constY position of each glyph in y
1329 @param bounds lower and upper line parallel to the advance
1330 @param intervals returned intersections; may be nullptr
1331 @return number of intersections; may be zero
1332 */
fmalitaeae6a912016-07-28 09:47:24 -07001333 int getPosTextHIntercepts(const void* text, size_t length, const SkScalar xpos[],
1334 SkScalar constY, const SkScalar bounds[2], SkScalar* intervals) const;
1335
Cary Clark50fa3ff2017-07-26 10:15:23 -04001336 /** Returns the number of intervals that intersect bounds.
1337 bounds describes a pair of lines parallel to the text advance.
1338 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1339 the string.
Cary Clark2823f9f2018-01-03 10:00:34 -05001340 Uses SkTypeface to get the glyph paths,
Cary Clark50fa3ff2017-07-26 10:15:23 -04001341 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
Cary Clarkb7da7232017-09-01 13:49:54 -04001342 Uses run array and SkPaint::Align to position intervals.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001343
Cary Clark2823f9f2018-01-03 10:00:34 -05001344 SkPaint::TextEncoding must be set to SkPaint::kGlyphID_TextEncoding.
1345
Cary Clark50fa3ff2017-07-26 10:15:23 -04001346 Pass nullptr for intervals to determine the size of the interval array.
1347
1348 intervals are cached to improve performance for multiple calls.
1349
Cary Clark8a02b0b2017-09-21 12:28:43 -04001350 @param blob glyphs, positions, and text paint attributes
Cary Clark50fa3ff2017-07-26 10:15:23 -04001351 @param bounds lower and upper line parallel to the advance
1352 @param intervals returned intersections; may be nullptr
1353 @return number of intersections; may be zero
1354 */
fmalitaeae6a912016-07-28 09:47:24 -07001355 int getTextBlobIntercepts(const SkTextBlob* blob, const SkScalar bounds[2],
1356 SkScalar* intervals) const;
1357
Cary Clark50fa3ff2017-07-26 10:15:23 -04001358 /** Returns the union of bounds of all glyphs.
1359 Returned dimensions are computed by font manager from font data,
Cary Clark579985c2017-07-31 11:48:27 -04001360 ignoring SkPaint::Hinting. Includes text size, text scale x,
Cary Clark50fa3ff2017-07-26 10:15:23 -04001361 and text skew x, but not fake bold or SkPathEffect.
1362
1363 If text size is large, text scale x is one, and text skew x is zero,
Cary Clark579985c2017-07-31 11:48:27 -04001364 returns the same bounds as SkPaint::FontMetrics { FontMetrics::fXMin,
Cary Clark50fa3ff2017-07-26 10:15:23 -04001365 FontMetrics::fTop, FontMetrics::fXMax, FontMetrics::fBottom }.
1366
1367 @return union of bounds of all glyphs
1368 */
reed8893e5f2014-12-15 13:27:26 -08001369 SkRect getFontBounds() const;
1370
Cary Clark579985c2017-07-31 11:48:27 -04001371 /** Returns true if SkPaint prevents all drawing;
1372 otherwise, the SkPaint may or may not allow drawing.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001373
Cary Clark462505f2018-05-30 09:20:29 -04001374 Returns true if, for example, SkBlendMode combined with alpha computes a
Cary Clarkb7da7232017-09-01 13:49:54 -04001375 new alpha of zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001376
1377 @return true if SkPaint prevents all drawing
1378 */
reed@google.com632e1a22011-10-06 12:37:00 +00001379 bool nothingToDraw() const;
1380
Cary Clark2823f9f2018-01-03 10:00:34 -05001381 /** (to be made private)
Cary Clark50fa3ff2017-07-26 10:15:23 -04001382 Returns true if SkPaint does not include elements requiring extensive computation
1383 to compute SkBaseDevice bounds of drawn geometry. For instance, SkPaint with SkPathEffect
1384 always returns false.
reed@google.comd5f20792012-05-16 14:15:02 +00001385
Cary Clark50fa3ff2017-07-26 10:15:23 -04001386 @return true if SkPaint allows for fast computation of bounds
1387 */
senorblanco0abdf762015-08-20 11:10:41 -07001388 bool canComputeFastBounds() const;
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001389
Cary Clark2823f9f2018-01-03 10:00:34 -05001390 /** (to be made private)
Cary Clark579985c2017-07-31 11:48:27 -04001391 Only call this if canComputeFastBounds() returned true. This takes a
Cary Clark50fa3ff2017-07-26 10:15:23 -04001392 raw rectangle (the raw bounds of a shape), and adjusts it for stylistic
1393 effects in the paint (e.g. stroking). If needed, it uses the storage
Cary Clarkb7da7232017-09-01 13:49:54 -04001394 parameter. It returns the adjusted bounds that can then be used
Cary Clark50fa3ff2017-07-26 10:15:23 -04001395 for SkCanvas::quickReject tests.
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001396
Cary Clarkb7da7232017-09-01 13:49:54 -04001397 The returned SkRect will either be orig or storage, thus the caller
Cary Clark50fa3ff2017-07-26 10:15:23 -04001398 should not rely on storage being set to the result, but should always
Cary Clarkb7da7232017-09-01 13:49:54 -04001399 use the returned value. It is legal for orig and storage to be the same
1400 SkRect.
Cary Clark462505f2018-05-30 09:20:29 -04001401 For example:
1402 if (!path.isInverseFillType() && paint.canComputeFastBounds()) {
1403 SkRect storage;
1404 if (canvas->quickReject(paint.computeFastBounds(path.getBounds(), &storage))) {
1405 return; // do not draw the path
1406 }
Cary Clark2823f9f2018-01-03 10:00:34 -05001407 }
Cary Clark462505f2018-05-30 09:20:29 -04001408 // draw the path
Cary Clark50fa3ff2017-07-26 10:15:23 -04001409
1410 @param orig geometry modified by SkPaint when drawn
1411 @param storage computed bounds of geometry; may not be nullptr
1412 @return fast computed bounds
1413 */
reed@google.coma584aed2012-05-16 14:06:02 +00001414 const SkRect& computeFastBounds(const SkRect& orig, SkRect* storage) const {
Brian Osman60751d72017-05-12 11:21:36 -04001415 // Things like stroking, etc... will do math on the bounds rect, assuming that it's sorted.
1416 SkASSERT(orig.isSorted());
reed@google.coma584aed2012-05-16 14:06:02 +00001417 SkPaint::Style style = this->getStyle();
1418 // ultra fast-case: filling with no effects that affect geometry
1419 if (kFill_Style == style) {
1420 uintptr_t effects = reinterpret_cast<uintptr_t>(this->getLooper());
1421 effects |= reinterpret_cast<uintptr_t>(this->getMaskFilter());
1422 effects |= reinterpret_cast<uintptr_t>(this->getPathEffect());
senorblanco@chromium.org336d1d72014-01-27 21:03:17 +00001423 effects |= reinterpret_cast<uintptr_t>(this->getImageFilter());
reed@google.coma584aed2012-05-16 14:06:02 +00001424 if (!effects) {
1425 return orig;
1426 }
1427 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001428
reed@google.coma584aed2012-05-16 14:06:02 +00001429 return this->doComputeFastBounds(orig, storage, style);
1430 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001431
Cary Clark2823f9f2018-01-03 10:00:34 -05001432 /** (to be made private)
Cary Clark50fa3ff2017-07-26 10:15:23 -04001433
1434 @param orig geometry modified by SkPaint when drawn
1435 @param storage computed bounds of geometry
1436 @return fast computed bounds
1437 */
reed@google.coma584aed2012-05-16 14:06:02 +00001438 const SkRect& computeFastStrokeBounds(const SkRect& orig,
1439 SkRect* storage) const {
reed@google.com73a02582012-05-16 19:21:12 +00001440 return this->doComputeFastBounds(orig, storage, kStroke_Style);
reed@google.coma584aed2012-05-16 14:06:02 +00001441 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001442
Cary Clark2823f9f2018-01-03 10:00:34 -05001443 /** (to be made private)
Cary Clarkb7da7232017-09-01 13:49:54 -04001444 Computes the bounds, overriding the SkPaint SkPaint::Style. This can be used to
1445 account for additional width required by stroking orig, without
1446 altering SkPaint::Style set to fill.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001447
1448 @param orig geometry modified by SkPaint when drawn
1449 @param storage computed bounds of geometry
1450 @param style overrides SkPaint::Style
1451 @return fast computed bounds
1452 */
reed@google.coma584aed2012-05-16 14:06:02 +00001453 const SkRect& doComputeFastBounds(const SkRect& orig, SkRect* storage,
Cary Clark0418a882017-05-10 09:07:42 -04001454 Style style) const;
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001455
reed@google.comd5f20792012-05-16 14:15:02 +00001456private:
Cary Clark0418a882017-05-10 09:07:42 -04001457 typedef const SkGlyph& (*GlyphCacheProc)(SkGlyphCache*, const char**);
1458
reeda5ab9ec2016-03-06 18:10:48 -08001459 sk_sp<SkTypeface> fTypeface;
1460 sk_sp<SkPathEffect> fPathEffect;
1461 sk_sp<SkShader> fShader;
reeda5ab9ec2016-03-06 18:10:48 -08001462 sk_sp<SkMaskFilter> fMaskFilter;
1463 sk_sp<SkColorFilter> fColorFilter;
reed46f2d0a2016-09-11 05:40:31 -07001464 sk_sp<SkDrawLooper> fDrawLooper;
reeda5ab9ec2016-03-06 18:10:48 -08001465 sk_sp<SkImageFilter> fImageFilter;
reed@google.comd5f20792012-05-16 14:15:02 +00001466
commit-bot@chromium.orge8807f42014-03-24 23:03:11 +00001467 SkScalar fTextSize;
1468 SkScalar fTextScaleX;
1469 SkScalar fTextSkewX;
reed@google.comd5f20792012-05-16 14:15:02 +00001470 SkColor fColor;
1471 SkScalar fWidth;
1472 SkScalar fMiterLimit;
Mike Reed71fecc32016-11-18 17:19:54 -05001473 uint32_t fBlendMode; // just need 5-6 bits
commit-bot@chromium.orgaca1c012014-02-21 18:18:05 +00001474 union {
1475 struct {
1476 // all of these bitfields should add up to 32
1477 unsigned fFlags : 16;
1478 unsigned fTextAlign : 2;
1479 unsigned fCapType : 2;
1480 unsigned fJoinType : 2;
1481 unsigned fStyle : 2;
1482 unsigned fTextEncoding : 2; // 3 values
1483 unsigned fHinting : 2;
reedf803da12015-01-23 05:58:07 -08001484 unsigned fFilterQuality : 2;
commit-bot@chromium.org85faf502014-04-16 12:58:02 +00001485 //unsigned fFreeBits : 2;
reedf59eab22014-07-14 14:39:15 -07001486 } fBitfields;
1487 uint32_t fBitfieldsUInt;
commit-bot@chromium.orgaca1c012014-02-21 18:18:05 +00001488 };
commit-bot@chromium.orge8807f42014-03-24 23:03:11 +00001489
robertphillipse34f17d2016-07-19 07:59:22 -07001490 static GlyphCacheProc GetGlyphCacheProc(TextEncoding encoding,
robertphillipse34f17d2016-07-19 07:59:22 -07001491 bool needFullMetrics);
reed@google.comd5f20792012-05-16 14:15:02 +00001492
1493 SkScalar measure_text(SkGlyphCache*, const char* text, size_t length,
1494 int* count, SkRect* bounds) const;
1495
joshualitt9e36c1a2015-04-14 12:17:27 -07001496 /*
1497 * The luminance color is used to determine which Gamma Canonical color to map to. This is
1498 * really only used by backends which want to cache glyph masks, and need some way to know if
1499 * they need to generate new masks based off a given color.
1500 */
1501 SkColor computeLuminanceColor() const;
1502
Cary Clarkd98f78c2018-04-26 08:32:37 -04001503 /* This is the size we use when we ask for a glyph's path. We then
1504 * post-transform it as we draw to match the request.
1505 * This is done to try to re-use cache entries for the path.
1506 *
1507 * This value is somewhat arbitrary. In theory, it could be 1, since
1508 * we store paths as floats. However, we get the path from the font
1509 * scaler, and it may represent its paths as fixed-point (or 26.6),
1510 * so we shouldn't ask for something too big (might overflow 16.16)
1511 * or too small (underflow 26.6).
1512 *
1513 * This value could track kMaxSizeForGlyphCache, assuming the above
1514 * constraints, but since we ask for unhinted paths, the two values
1515 * need not match per-se.
1516 */
1517 static constexpr int kCanonicalTextSizeForPaths = 64;
reed@google.comed43dff2013-06-04 16:56:27 +00001518
Jim Van Verthc65b65d2018-01-16 16:26:35 -05001519 static bool TooBigToUseCache(const SkMatrix& ctm, const SkMatrix& textM, SkScalar maxLimit);
reed@google.comed43dff2013-06-04 16:56:27 +00001520
reed@google.comed43dff2013-06-04 16:56:27 +00001521 // Set flags/hinting/textSize up to use for drawing text as paths.
1522 // Returns scale factor to restore the original textSize, since will will
1523 // have change it to kCanonicalTextSizeForPaths.
1524 SkScalar setupForAsPaths();
1525
Jim Van Verthc65b65d2018-01-16 16:26:35 -05001526 static SkScalar MaxCacheSize2(SkScalar maxLimit);
reed@google.comed43dff2013-06-04 16:56:27 +00001527
Herb Derby980a48d2018-01-23 13:39:21 -05001528 friend class GrAtlasTextBlob;
Herb Derby26cbe512018-05-24 14:39:01 -04001529 friend class GrTextContext;
Herb Derby980a48d2018-01-23 13:39:21 -05001530 friend class GrGLPathRendering;
1531 friend class GrPathRendering;
Herb Derby980a48d2018-01-23 13:39:21 -05001532 friend class GrTextUtils;
jvanverth2d2a68c2014-06-10 06:42:56 -07001533 friend class SkAutoGlyphCacheNoGamma;
Herb Derby980a48d2018-01-23 13:39:21 -05001534 friend class SkCanonicalizePaint;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001535 friend class SkCanvas;
1536 friend class SkDraw;
Cary Clark60ca8672018-03-06 15:09:27 -05001537 friend class SkPaintPriv;
vandebo@chromium.org28be72b2010-11-11 21:37:00 +00001538 friend class SkPDFDevice;
Herb Derby980a48d2018-01-23 13:39:21 -05001539 friend class SkScalerContext; // for computeLuminanceColor()
caryclark0449bcf2016-02-09 13:25:45 -08001540 friend class SkTextBaseIter;
Khushal51371a42018-05-17 10:41:40 -07001541 friend class SkTextBlobCacheDiffCanvas;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001542};
1543
reed@android.com8a1c16f2008-12-17 15:59:43 +00001544#endif