blob: 83d5502742d393f340fc0671980271d0266ec420 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00006 */
7
8#ifndef SkPaint_DEFINED
9#define SkPaint_DEFINED
10
reed374772b2016-10-05 17:33:02 -070011#include "SkBlendMode.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000012#include "SkColor.h"
reedf803da12015-01-23 05:58:07 -080013#include "SkFilterQuality.h"
reed@google.comed43dff2013-06-04 16:56:27 +000014#include "SkMatrix.h"
Mike Reed71fecc32016-11-18 17:19:54 -050015#include "SkRefCnt.h"
reed@android.coma0f5d152009-06-22 17:38:10 +000016
joshualitt2b6acb42015-04-01 11:30:27 -070017class SkAutoDescriptor;
reed@android.com8a1c16f2008-12-17 15:59:43 +000018class SkAutoGlyphCache;
19class SkColorFilter;
joshualittfd450792015-03-13 08:38:43 -070020class SkData;
reed@android.com8a1c16f2008-12-17 15:59:43 +000021class SkDescriptor;
senorblanco0abdf762015-08-20 11:10:41 -070022class SkDrawLooper;
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +000023class SkReadBuffer;
24class SkWriteBuffer;
herbb69d0e02015-02-25 06:47:06 -080025class SkGlyph;
reed@android.com8a1c16f2008-12-17 15:59:43 +000026struct SkRect;
27class SkGlyphCache;
reed@google.com15356a62011-11-03 19:29:08 +000028class SkImageFilter;
reed@android.com8a1c16f2008-12-17 15:59:43 +000029class SkMaskFilter;
reed@android.com8a1c16f2008-12-17 15:59:43 +000030class SkPath;
31class SkPathEffect;
djsollen@google.comc73dd5c2012-08-07 15:54:32 +000032struct SkPoint;
reed@android.com8a1c16f2008-12-17 15:59:43 +000033class SkRasterizer;
reeda9322c22016-04-12 06:47:05 -070034struct SkScalerContextEffects;
reed@android.com8a1c16f2008-12-17 15:59:43 +000035class SkShader;
robertphillipsfcf78292015-06-19 11:49:52 -070036class SkSurfaceProps;
fmalitaeae6a912016-07-28 09:47:24 -070037class SkTextBlob;
reed@android.com8a1c16f2008-12-17 15:59:43 +000038class SkTypeface;
reed@android.com8a1c16f2008-12-17 15:59:43 +000039
reed@android.com8a1c16f2008-12-17 15:59:43 +000040/** \class SkPaint
Cary Clark50fa3ff2017-07-26 10:15:23 -040041 SkPaint controls options applied when drawing and measuring. SkPaint collects all
42 options outside of the SkCanvas clip and SkCanvas matrix.
reed@android.com8a1c16f2008-12-17 15:59:43 +000043
Cary Clark50fa3ff2017-07-26 10:15:23 -040044 Various options apply to text, strokes and fills, and images.
45
46 Some options may not be implemented on all platforms; in these cases, setting
47 the option has no effect. Some options are conveniences that duplicate SkCanvas
48 functionality; for instance, text size is identical to matrix scale.
49
50 SkPaint options are rarely exclusive; each option modifies a stage of the drawing
Cary Clark23890a92017-07-27 16:30:51 -040051 pipeline and multiple pipeline stages may be affected by a single SkPaint.
Cary Clark50fa3ff2017-07-26 10:15:23 -040052
Cary Clark23890a92017-07-27 16:30:51 -040053 SkPaint collects effects and filters that describe single-pass and multiple-pass
Cary Clark50fa3ff2017-07-26 10:15:23 -040054 algorithms that alter the drawing geometry, color, and transparency. For instance,
55 SkPaint does not directly implement dashing or blur, but contains the objects that do so.
56
57 The objects contained by SkPaint are opaque, and cannot be edited outside of the SkPaint
58 to affect it. The implementation is free to defer computations associated with the
59 SkPaint, or ignore them altogether. For instance, some GPU implementations draw all
Cary Clarkb7da7232017-09-01 13:49:54 -040060 SkPath geometries with anti-aliasing, regardless of how SkPaint::kAntiAlias_Flag
61 is set in SkPaint.
Cary Clark50fa3ff2017-07-26 10:15:23 -040062
63 SkPaint describes a single color, a single font, a single image quality, and so on.
64 Multiple colors are drawn either by using multiple paints or with objects like
65 SkShader attached to SkPaint.
reed@android.com8a1c16f2008-12-17 15:59:43 +000066*/
ctguil@chromium.org7ffb1b22011-03-15 21:27:08 +000067class SK_API SkPaint {
reed@android.com8a1c16f2008-12-17 15:59:43 +000068public:
Cary Clark50fa3ff2017-07-26 10:15:23 -040069
70 /** Constructs SkPaint with default values.
71
72 @return default initialized SkPaint
73 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000074 SkPaint();
Cary Clark50fa3ff2017-07-26 10:15:23 -040075
76 /** Makes a shallow copy of SkPaint. SkTypeface, SkPathEffect, SkShader,
77 SkMaskFilter, SkColorFilter, SkRasterizer, SkDrawLooper, and SkImageFilter are shared
Cary Clarkb7da7232017-09-01 13:49:54 -040078 between the original paint and the copy. Objects containing SkRefCnt increment
79 their references by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -040080
81 The referenced objects SkPathEffect, SkShader, SkMaskFilter, SkColorFilter, SkRasterizer,
82 SkDrawLooper, and SkImageFilter cannot be modified after they are created.
83 This prevents objects with SkRefCnt from being modified once SkPaint refers to them.
84
85 @param paint original to copy
86 @return shallow copy of paint
87 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000088 SkPaint(const SkPaint& paint);
Cary Clark50fa3ff2017-07-26 10:15:23 -040089
Cary Clark8a02b0b2017-09-21 12:28:43 -040090 /** Implements a move constructor to avoid increasing the reference counts
Cary Clark50fa3ff2017-07-26 10:15:23 -040091 of objects referenced by the paint.
92
93 After the call, paint is undefined, and can be safely destructed.
94
95 @param paint original to move
96 @return content of paint
97 */
bungemanccce0e02016-02-07 14:37:23 -080098 SkPaint(SkPaint&& paint);
Cary Clark50fa3ff2017-07-26 10:15:23 -040099
100 /** Decreases SkPaint SkRefCnt of owned objects: SkTypeface, SkPathEffect, SkShader,
101 SkMaskFilter, SkColorFilter, SkRasterizer, SkDrawLooper, and SkImageFilter. If the
Cary Clarkb7da7232017-09-01 13:49:54 -0400102 objects containing SkRefCnt go to zero, they are deleted.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400103 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000104 ~SkPaint();
105
Cary Clark50fa3ff2017-07-26 10:15:23 -0400106 /** Makes a shallow copy of SkPaint. SkTypeface, SkPathEffect, SkShader,
107 SkMaskFilter, SkColorFilter, SkRasterizer, SkDrawLooper, and SkImageFilter are shared
Cary Clarkb7da7232017-09-01 13:49:54 -0400108 between the original paint and the copy. Objects containing SkRefCnt in the
Cary Clark50fa3ff2017-07-26 10:15:23 -0400109 prior destination are decreased by one, and the referenced objects are deleted if the
Cary Clarkb7da7232017-09-01 13:49:54 -0400110 resulting count is zero. Objects containing SkRefCnt in the parameter paint
111 are increased by one. paint is unmodified.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400112
113 @param paint original to copy
114 @return content of paint
115 */
Cary Clark0418a882017-05-10 09:07:42 -0400116 SkPaint& operator=(const SkPaint& paint);
Cary Clark50fa3ff2017-07-26 10:15:23 -0400117
Cary Clark8a02b0b2017-09-21 12:28:43 -0400118 /** Moves the paint to avoid increasing the reference counts
Cary Clarkb7da7232017-09-01 13:49:54 -0400119 of objects referenced by the paint parameter. Objects containing SkRefCnt in the
120 prior destination are decreased by one; those objects are deleted if the resulting count
121 is zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400122
123 After the call, paint is undefined, and can be safely destructed.
124
125 @param paint original to move
126 @return content of paint
127 */
Cary Clark0418a882017-05-10 09:07:42 -0400128 SkPaint& operator=(SkPaint&& paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000129
Cary Clark50fa3ff2017-07-26 10:15:23 -0400130 /** Compares a and b, and returns true if a and b are equivalent. May return false
131 if SkTypeface, SkPathEffect, SkShader, SkMaskFilter, SkColorFilter, SkRasterizer,
132 SkDrawLooper, or SkImageFilter have identical contents but different pointers.
133
134 @param a SkPaint to compare
135 @param b SkPaint to compare
136 @return true if SkPaint pair are equivalent
mtkleinbc97ef42014-08-25 10:10:47 -0700137 */
robertphillips@google.comb2657412013-08-07 22:36:29 +0000138 SK_API friend bool operator==(const SkPaint& a, const SkPaint& b);
Cary Clark50fa3ff2017-07-26 10:15:23 -0400139
140 /** Compares a and b, and returns true if a and b are not equivalent. May return true
141 if SkTypeface, SkPathEffect, SkShader, SkMaskFilter, SkColorFilter, SkRasterizer,
142 SkDrawLooper, or SkImageFilter have identical contents but different pointers.
143
144 @param a SkPaint to compare
145 @param b SkPaint to compare
146 @return true if SkPaint pair are not equivalent
147 */
robertphillips@google.comb2657412013-08-07 22:36:29 +0000148 friend bool operator!=(const SkPaint& a, const SkPaint& b) {
149 return !(a == b);
150 }
151
Cary Clark50fa3ff2017-07-26 10:15:23 -0400152 /** Returns a hash generated from SkPaint values and pointers.
153 Identical hashes guarantee that the paints are
154 equivalent, but differing hashes do not guarantee that the paints have differing
155 contents.
156
157 If operator==(const SkPaint& a, const SkPaint& b) returns true for two paints,
158 their hashes are also equal.
159
160 The hash returned is platform and implementation specific.
161
162 @return a shallow hash
163 */
mtkleinfb1fe4f2014-10-07 09:26:10 -0700164 uint32_t getHash() const;
165
Cary Clark50fa3ff2017-07-26 10:15:23 -0400166 /** Serializes SkPaint into a buffer. A companion unflatten() call
167 can reconstitute the paint at a later time.
168
169 @param buffer SkWriteBuffer receiving the flattened SkPaint data
170 */
Cary Clark0418a882017-05-10 09:07:42 -0400171 void flatten(SkWriteBuffer& buffer) const;
Cary Clark50fa3ff2017-07-26 10:15:23 -0400172
173 /** Populates SkPaint, typically from a serialized stream, created by calling
174 flatten() at an earlier time.
175
176 SkReadBuffer class is not public, so unflatten() cannot be meaningfully called
177 by the client.
178
Cary Clarkb7da7232017-09-01 13:49:54 -0400179 @param buffer serialized data describing SkPaint content
Cary Clark50fa3ff2017-07-26 10:15:23 -0400180 */
Cary Clark0418a882017-05-10 09:07:42 -0400181 void unflatten(SkReadBuffer& buffer);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000182
Cary Clarkcc309eb2017-10-30 11:48:35 -0400183 /** Sets all SkPaint contents to their initial values. This is equivalent to replacing
184 SkPaint with the result of SkPaint().
reed@android.com8a1c16f2008-12-17 15:59:43 +0000185 */
186 void reset();
187
Cary Clark50fa3ff2017-07-26 10:15:23 -0400188 /** \enum SkPaint::Hinting
189 Hinting adjusts the glyph outlines so that the shape provides a uniform
190 look at a given point size on font engines that support it. Hinting may have a
191 muted effect or no effect at all depending on the platform.
192
193 The four levels roughly control corresponding features on platforms that use FreeType
194 as the font engine.
agl@chromium.org309485b2009-07-21 17:41:32 +0000195 */
196 enum Hinting {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400197 /** Leaves glyph outlines unchanged from their native representation.
198 With FreeType, this is equivalent to the FT_LOAD_NO_HINTING
199 bit-field constant supplied to FT_Load_Glyph, which indicates that the vector
200 outline being loaded should not be fitted to the pixel grid but simply scaled
201 to 26.6 fractional pixels.
202 */
203 kNo_Hinting = 0,
204
205 /** Modifies glyph outlines minimally to improve constrast.
206 With FreeType, this is equivalent in spirit to the
207 FT_LOAD_TARGET_LIGHT value supplied to FT_Load_Glyph. It chooses a
208 lighter hinting algorithm for non-monochrome modes.
209 Generated glyphs may be fuzzy but better resemble their original shape.
210 */
211 kSlight_Hinting = 1,
212
213 /** Modifies glyph outlines to improve constrast. This is the default.
214 With FreeType, this supplies FT_LOAD_TARGET_NORMAL to FT_Load_Glyph,
215 choosing the default hinting algorithm, which is optimized for standard
216 gray-level rendering.
217 */
218 kNormal_Hinting = 2,
219
220 /** Modifies glyph outlines for maxiumum constrast. With FreeType, this selects
221 FT_LOAD_TARGET_LCD or FT_LOAD_TARGET_LCD_V if kLCDRenderText_Flag is set.
222 FT_LOAD_TARGET_LCD is a variant of FT_LOAD_TARGET_NORMAL optimized for
223 horizontally decimated LCD displays; FT_LOAD_TARGET_LCD_V is a
224 variant of FT_LOAD_TARGET_NORMAL optimized for vertically decimated LCD displays.
225 */
226 kFull_Hinting = 3,
agl@chromium.org309485b2009-07-21 17:41:32 +0000227 };
228
Cary Clark50fa3ff2017-07-26 10:15:23 -0400229 /** Returns level of glyph outline adjustment.
230
231 @return one of: kNo_Hinting, kSlight_Hinting, kNormal_Hinting, kFull_Hinting
232 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000233 Hinting getHinting() const {
reedf59eab22014-07-14 14:39:15 -0700234 return static_cast<Hinting>(fBitfields.fHinting);
agl@chromium.org309485b2009-07-21 17:41:32 +0000235 }
236
Cary Clark50fa3ff2017-07-26 10:15:23 -0400237 /** Sets level of glyph outline adjustment.
238 Does not check for valid values of hintingLevel.
239
240 @param hintingLevel one of: kNo_Hinting, kSlight_Hinting, kNormal_Hinting, kFull_Hinting
241 */
djsollen@google.comf5dbe2f2011-04-15 13:41:26 +0000242 void setHinting(Hinting hintingLevel);
agl@chromium.org309485b2009-07-21 17:41:32 +0000243
Cary Clark50fa3ff2017-07-26 10:15:23 -0400244 /** \enum SkPaint::Flags
245 The bit values stored in Flags.
246 The default value for Flags, normally zero, can be changed at compile time
247 with a custom definition of SkPaintDefaults_Flags.
248 All flags can be read and written explicitly; Flags allows manipulating
249 multiple settings at once.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000250 */
251 enum Flags {
Cary Clark1eace2d2017-07-31 07:52:43 -0400252 kAntiAlias_Flag = 0x01, //!< mask for setting anti-alias
253 kDither_Flag = 0x04, //!< mask for setting dither
Cary Clark50fa3ff2017-07-26 10:15:23 -0400254 kFakeBoldText_Flag = 0x20, //!< mask for setting fake bold
255 kLinearText_Flag = 0x40, //!< mask for setting linear text
256 kSubpixelText_Flag = 0x80, //!< mask for setting subpixel text
257 kDevKernText_Flag = 0x100, //!< mask for setting full hinting spacing
258 kLCDRenderText_Flag = 0x200, //!< mask for setting lcd text
259 kEmbeddedBitmapText_Flag = 0x400, //!< mask for setting font embedded bitmaps
260 kAutoHinting_Flag = 0x800, //!< mask for setting auto-hinting
261 kVerticalText_Flag = 0x1000, //!< mask for setting vertical text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000262
Cary Clark50fa3ff2017-07-26 10:15:23 -0400263 /** Hack for GDI -- do not use if you can help it */
264 kGenA8FromLCD_Flag = 0x2000,
265
266 /** mask of all Flags, including private flags and flags reserved for future use */
267 kAllFlags = 0xFFFF,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000268 };
269
Cary Clark50fa3ff2017-07-26 10:15:23 -0400270 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Mike Reedddbd37e2017-02-21 15:07:44 -0500271 enum ReserveFlags {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400272 kUnderlineText_ReserveFlag = 0x08, //!< mask for underline text
273 kStrikeThruText_ReserveFlag = 0x10, //!< mask for strike-thru text
Mike Reedddbd37e2017-02-21 15:07:44 -0500274 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400275 #endif
Mike Reedddbd37e2017-02-21 15:07:44 -0500276
Cary Clark50fa3ff2017-07-26 10:15:23 -0400277 /** Returns paint settings described by SkPaint::Flags. Each setting uses one
278 bit, and can be tested with SkPaint::Flags members.
279
280 @return zero, one, or more bits described by SkPaint::Flags
reed@android.com8a1c16f2008-12-17 15:59:43 +0000281 */
reedf59eab22014-07-14 14:39:15 -0700282 uint32_t getFlags() const { return fBitfields.fFlags; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000283
Cary Clark23890a92017-07-27 16:30:51 -0400284 /** Replaces SkPaint::Flags with flags, the union of the SkPaint::Flags members.
285 All SkPaint::Flags members may be cleared, or one or more may be set.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400286
287 @param flags union of SkPaint::Flags for SkPaint
reed@android.com8a1c16f2008-12-17 15:59:43 +0000288 */
289 void setFlags(uint32_t flags);
290
Cary Clark50fa3ff2017-07-26 10:15:23 -0400291 /** If true, pixels on the active edges of SkPath may be drawn with partial transparency.
292
Cary Clark579985c2017-07-31 11:48:27 -0400293 Equivalent to getFlags() masked with kAntiAlias_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400294
295 @return kAntiAlias_Flag state
296 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000297 bool isAntiAlias() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000298 return SkToBool(this->getFlags() & kAntiAlias_Flag);
299 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000300
Cary Clark50fa3ff2017-07-26 10:15:23 -0400301 /** Requests, but does not require, that SkPath edge pixels draw opaque or with
302 partial transparency.
303
304 Sets kAntiAlias_Flag if aa is true.
305 Clears kAntiAlias_Flag if aa is false.
306
307 @param aa setting for kAntiAlias_Flag
308 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000309 void setAntiAlias(bool aa);
reed@google.com9d07fec2011-03-16 20:02:59 +0000310
Cary Clark50fa3ff2017-07-26 10:15:23 -0400311 /** If true, color error may be distributed to smooth color transition.
312
Cary Clark579985c2017-07-31 11:48:27 -0400313 Equivalent to getFlags() masked with kDither_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400314
315 @return kDither_Flag state
316 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000317 bool isDither() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000318 return SkToBool(this->getFlags() & kDither_Flag);
319 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000320
Cary Clark50fa3ff2017-07-26 10:15:23 -0400321 /** Requests, but does not require, to distribute color error.
322
323 Sets kDither_Flag if dither is true.
324 Clears kDither_Flag if dither is false.
325
326 @param dither setting for kDither_Flag
327 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000328 void setDither(bool dither);
reed@google.com9d07fec2011-03-16 20:02:59 +0000329
Cary Clark50fa3ff2017-07-26 10:15:23 -0400330 /** If true, text is converted to SkPath before drawing and measuring.
331
Cary Clark579985c2017-07-31 11:48:27 -0400332 Equivalent to getFlags() masked with kLinearText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400333
334 @return kLinearText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000335 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000336 bool isLinearText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000337 return SkToBool(this->getFlags() & kLinearText_Flag);
338 }
339
Cary Clark50fa3ff2017-07-26 10:15:23 -0400340 /** If true, text is converted to SkPath before drawing and measuring.
341 By default, kLinearText_Flag is clear.
342
343 Sets kLinearText_Flag if linearText is true.
344 Clears kLinearText_Flag if linearText is false.
345
346 @param linearText setting for kLinearText_Flag
reed@android.com8a1c16f2008-12-17 15:59:43 +0000347 */
348 void setLinearText(bool linearText);
349
Cary Clark50fa3ff2017-07-26 10:15:23 -0400350 /** If true, glyphs at different sub-pixel positions may differ on pixel edge coverage.
351
Cary Clark579985c2017-07-31 11:48:27 -0400352 Equivalent to getFlags() masked with kSubpixelText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400353
354 @return kSubpixelText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000355 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000356 bool isSubpixelText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000357 return SkToBool(this->getFlags() & kSubpixelText_Flag);
358 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000359
Cary Clark50fa3ff2017-07-26 10:15:23 -0400360 /** Requests, but does not require, that glyphs respect sub-pixel positioning.
361
362 Sets kSubpixelText_Flag if subpixelText is true.
363 Clears kSubpixelText_Flag if subpixelText is false.
364
365 @param subpixelText setting for kSubpixelText_Flag
366 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000367 void setSubpixelText(bool subpixelText);
agl@chromium.org309485b2009-07-21 17:41:32 +0000368
Cary Clark50fa3ff2017-07-26 10:15:23 -0400369 /** If true, glyphs may use LCD striping to improve glyph edges.
370
371 Returns true if SkPaint::Flags kLCDRenderText_Flag is set.
372
373 @return kLCDRenderText_Flag state
374 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000375 bool isLCDRenderText() const {
agl@chromium.org309485b2009-07-21 17:41:32 +0000376 return SkToBool(this->getFlags() & kLCDRenderText_Flag);
377 }
378
Cary Clark50fa3ff2017-07-26 10:15:23 -0400379 /** Requests, but does not require, that glyphs use LCD striping for glyph edges.
380
381 Sets kLCDRenderText_Flag if lcdText is true.
382 Clears kLCDRenderText_Flag if lcdText is false.
383
384 @param lcdText setting for kLCDRenderText_Flag
385 */
reed@google.com84b437e2011-08-01 12:45:35 +0000386 void setLCDRenderText(bool lcdText);
agl@chromium.org309485b2009-07-21 17:41:32 +0000387
Cary Clark50fa3ff2017-07-26 10:15:23 -0400388 /** If true, font engine may return glyphs from font bitmaps instead of from outlines.
389
Cary Clark579985c2017-07-31 11:48:27 -0400390 Equivalent to getFlags() masked with kEmbeddedBitmapText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400391
392 @return kEmbeddedBitmapText_Flag state
393 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000394 bool isEmbeddedBitmapText() const {
agl@chromium.orge95c91e2010-01-04 18:27:55 +0000395 return SkToBool(this->getFlags() & kEmbeddedBitmapText_Flag);
396 }
397
Cary Clark50fa3ff2017-07-26 10:15:23 -0400398 /** Requests, but does not require, to use bitmaps in fonts instead of outlines.
399
400 Sets kEmbeddedBitmapText_Flag if useEmbeddedBitmapText is true.
401 Clears kEmbeddedBitmapText_Flag if useEmbeddedBitmapText is false.
402
403 @param useEmbeddedBitmapText setting for kEmbeddedBitmapText_Flag
agl@chromium.orge95c91e2010-01-04 18:27:55 +0000404 */
405 void setEmbeddedBitmapText(bool useEmbeddedBitmapText);
406
Cary Clark50fa3ff2017-07-26 10:15:23 -0400407 /** If true, and if SkPaint::Hinting is set to kNormal_Hinting or kFull_Hinting, and if
408 platform uses FreeType as the font manager, instruct the font manager to always hint
Cary Clark1eace2d2017-07-31 07:52:43 -0400409 glyphs.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400410
Cary Clark579985c2017-07-31 11:48:27 -0400411 Equivalent to getFlags() masked with kAutoHinting_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400412
413 @return kAutoHinting_Flag state
414 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000415 bool isAutohinted() const {
agl@chromium.orga2c71cb2010-06-17 20:49:17 +0000416 return SkToBool(this->getFlags() & kAutoHinting_Flag);
417 }
418
Cary Clark50fa3ff2017-07-26 10:15:23 -0400419 /** If SkPaint::Hinting is set to kNormal_Hinting or kFull_Hinting and useAutohinter is set,
Cary Clark1eace2d2017-07-31 07:52:43 -0400420 instruct the font manager to always hint glyphs.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400421 auto-hinting has no effect if SkPaint::Hinting is set to kNo_Hinting or
422 kSlight_Hinting.
423
Cary Clark579985c2017-07-31 11:48:27 -0400424 Only affects platforms that use FreeType as the font manager.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400425
426 Sets kAutoHinting_Flag if useAutohinter is true.
427 Clears kAutoHinting_Flag if useAutohinter is false.
428
429 @param useAutohinter setting for kAutoHinting_Flag
agl@chromium.orga2c71cb2010-06-17 20:49:17 +0000430 */
431 void setAutohinted(bool useAutohinter);
432
Cary Clark50fa3ff2017-07-26 10:15:23 -0400433 /** If true, glyphs are drawn top to bottom instead of left to right.
434
Cary Clark579985c2017-07-31 11:48:27 -0400435 Equivalent to getFlags() masked with kVerticalText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400436
437 @return kVerticalText_Flag state
438 */
reed@google.com830a23e2011-11-10 15:20:49 +0000439 bool isVerticalText() const {
440 return SkToBool(this->getFlags() & kVerticalText_Flag);
441 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000442
Cary Clark50fa3ff2017-07-26 10:15:23 -0400443 /** If true, text advance positions the next glyph below the previous glyph instead of to the
444 right of previous glyph.
445
446 Sets kVerticalText_Flag if vertical is true.
447 Clears kVerticalText_Flag if vertical is false.
448
449 @param verticalText setting for kVerticalText_Flag
450 */
Cary Clark0418a882017-05-10 09:07:42 -0400451 void setVerticalText(bool verticalText);
reed@google.com830a23e2011-11-10 15:20:49 +0000452
Cary Clark50fa3ff2017-07-26 10:15:23 -0400453 /** If true, approximate bold by increasing the stroke width when creating glyph bitmaps
454 from outlines.
455
Cary Clark579985c2017-07-31 11:48:27 -0400456 Equivalent to getFlags() masked with kFakeBoldText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400457
458 @return kFakeBoldText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000459 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000460 bool isFakeBoldText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000461 return SkToBool(this->getFlags() & kFakeBoldText_Flag);
462 }
463
Cary Clarkb7da7232017-09-01 13:49:54 -0400464 /** Use increased stroke width when creating glyph bitmaps to approximate a bold typeface.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400465
466 Sets kFakeBoldText_Flag if fakeBoldText is true.
467 Clears kFakeBoldText_Flag if fakeBoldText is false.
468
469 @param fakeBoldText setting for kFakeBoldText_Flag
reed@android.com8a1c16f2008-12-17 15:59:43 +0000470 */
471 void setFakeBoldText(bool fakeBoldText);
472
Cary Clark50fa3ff2017-07-26 10:15:23 -0400473 /** Returns if character spacing may be adjusted by the hinting difference.
474
Cary Clark579985c2017-07-31 11:48:27 -0400475 Equivalent to getFlags() masked with kDevKernText_Flag.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400476
477 @return kDevKernText_Flag state
reed@android.com8a1c16f2008-12-17 15:59:43 +0000478 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000479 bool isDevKernText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000480 return SkToBool(this->getFlags() & kDevKernText_Flag);
481 }
482
Cary Clark50fa3ff2017-07-26 10:15:23 -0400483 /** Requests, but does not require, to use hinting to adjust glyph spacing.
484
485 Sets kDevKernText_Flag if devKernText is true.
486 Clears kDevKernText_Flag if devKernText is false.
487
488 @param devKernText setting for devKernText
reed@android.com8a1c16f2008-12-17 15:59:43 +0000489 */
490 void setDevKernText(bool devKernText);
491
Cary Clark50fa3ff2017-07-26 10:15:23 -0400492 /** Returns SkFilterQuality, the image filtering level. A lower setting
493 draws faster; a higher setting looks better when the image is scaled.
494
495 @return one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
496 kMedium_SkFilterQuality, kHigh_SkFilterQuality
497 */
reedf803da12015-01-23 05:58:07 -0800498 SkFilterQuality getFilterQuality() const {
499 return (SkFilterQuality)fBitfields.fFilterQuality;
500 }
mtkleinfe81e2d2015-09-09 07:35:42 -0700501
Cary Clark23890a92017-07-27 16:30:51 -0400502 /** Sets SkFilterQuality, the image filtering level. A lower setting
Cary Clark50fa3ff2017-07-26 10:15:23 -0400503 draws faster; a higher setting looks better when the image is scaled.
Cary Clark579985c2017-07-31 11:48:27 -0400504 Does not check to see if quality is valid.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400505
506 @param quality one of: kNone_SkFilterQuality, kLow_SkFilterQuality,
507 kMedium_SkFilterQuality, kHigh_SkFilterQuality
508 */
reedf803da12015-01-23 05:58:07 -0800509 void setFilterQuality(SkFilterQuality quality);
reed@google.comc9683152013-07-18 13:47:01 +0000510
Cary Clark50fa3ff2017-07-26 10:15:23 -0400511 /** \enum SkPaint::Style
Cary Clark23890a92017-07-27 16:30:51 -0400512 Set Style to fill, stroke, or both fill and stroke geometry.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400513 The stroke and fill
514 share all paint attributes; for instance, they are drawn with the same color.
reed@google.com9d07fec2011-03-16 20:02:59 +0000515
Cary Clark50fa3ff2017-07-26 10:15:23 -0400516 Use kStrokeAndFill_Style to avoid hitting the same pixels twice with a stroke draw and
517 a fill draw.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000518 */
519 enum Style {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400520 /** Set to fill geometry.
Cary Clark1eace2d2017-07-31 07:52:43 -0400521 Applies to SkRect, SkRegion, SkRRect, circles, ovals, SkPath, and text.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400522 SkBitmap, SkImage, patches, SkRegion, sprites, and vertices are painted as if
523 kFill_Style is set, and ignore the set Style.
524 The FillType specifies additional rules to fill the area outside the path edge,
525 and to create an unfilled hole inside the shape.
526 Style is set to kFill_Style by default.
527 */
528 kFill_Style,
529
530 /** Set to stroke geometry.
Cary Clarkb7da7232017-09-01 13:49:54 -0400531 Applies to SkRect, SkRegion, SkRRect, arcs, circles, ovals, SkPath, and text.
532 Arcs, lines, and SkPoint, are always drawn as if kStroke_Style is set,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400533 and ignore the set Style.
534 The stroke construction is unaffected by the FillType.
535 */
536 kStroke_Style,
537
538 /** Set to stroke and fill geometry.
Cary Clark1eace2d2017-07-31 07:52:43 -0400539 Applies to SkRect, SkRegion, SkRRect, circles, ovals, SkPath, and text.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400540 SkPath is treated as if it is set to SkPath::kWinding_FillType,
541 and the set FillType is ignored.
542 */
543 kStrokeAndFill_Style,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000544 };
545
Cary Clark50fa3ff2017-07-26 10:15:23 -0400546 enum {
547 /** The number of different Style values defined.
548 May be used to verify that Style is a legal value.
549 */
550 kStyleCount = kStrokeAndFill_Style + 1,
551 };
552
553 /** Whether the geometry is filled, stroked, or filled and stroked.
554
555 @return one of:kFill_Style, kStroke_Style, kStrokeAndFill_Style
reed@android.com8a1c16f2008-12-17 15:59:43 +0000556 */
reedf59eab22014-07-14 14:39:15 -0700557 Style getStyle() const { return (Style)fBitfields.fStyle; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000558
Cary Clark50fa3ff2017-07-26 10:15:23 -0400559 /** Sets whether the geometry is filled, stroked, or filled and stroked.
560 Has no effect if style is not a legal SkPaint::Style value.
561
562 @param style one of: kFill_Style, kStroke_Style, kStrokeAndFill_Style
reed@android.com8a1c16f2008-12-17 15:59:43 +0000563 */
564 void setStyle(Style style);
565
Cary Clark50fa3ff2017-07-26 10:15:23 -0400566 /** Retrieves alpha and RGB, unpremultiplied, packed into 32 bits.
567 Use helpers SkColorGetA(), SkColorGetR(), SkColorGetG(), and SkColorGetB() to extract
568 a color component.
569
Cary Clark8a02b0b2017-09-21 12:28:43 -0400570 @return unpremultiplied ARGB
reed@android.com8a1c16f2008-12-17 15:59:43 +0000571 */
572 SkColor getColor() const { return fColor; }
573
Cary Clark50fa3ff2017-07-26 10:15:23 -0400574 /** Sets alpha and RGB used when stroking and filling. The color is a 32-bit value,
Cary Clarkb7da7232017-09-01 13:49:54 -0400575 unpremultiplied, packing 8-bit components for alpha, red, blue, and green.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400576
Cary Clark8a02b0b2017-09-21 12:28:43 -0400577 @param color unpremultiplied ARGB
reed@android.com8a1c16f2008-12-17 15:59:43 +0000578 */
579 void setColor(SkColor color);
580
Cary Clark1eace2d2017-07-31 07:52:43 -0400581 /** Retrieves alpha from the color used when stroking and filling.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400582
Cary Clark8a02b0b2017-09-21 12:28:43 -0400583 @return alpha ranging from zero, fully transparent, to 255, fully opaque
Cary Clark50fa3ff2017-07-26 10:15:23 -0400584 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000585 uint8_t getAlpha() const { return SkToU8(SkColorGetA(fColor)); }
reed@google.com9d07fec2011-03-16 20:02:59 +0000586
Cary Clark50fa3ff2017-07-26 10:15:23 -0400587 /** Replaces alpha, leaving RGB
588 unchanged. An out of range value triggers an assert in the debug
589 build. a is a value from zero to 255.
Cary Clark1eace2d2017-07-31 07:52:43 -0400590 a set to zero makes color fully transparent; a set to 255 makes color
Cary Clark50fa3ff2017-07-26 10:15:23 -0400591 fully opaque.
592
Cary Clark8a02b0b2017-09-21 12:28:43 -0400593 @param a alpha component of color
reed@android.com8a1c16f2008-12-17 15:59:43 +0000594 */
595 void setAlpha(U8CPU a);
596
Cary Clark1eace2d2017-07-31 07:52:43 -0400597 /** Sets color used when drawing solid fills. The color components range from 0 to 255.
Cary Clarkb7da7232017-09-01 13:49:54 -0400598 The color is unpremultiplied; alpha sets the transparency independent of RGB.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400599
Cary Clarkb7da7232017-09-01 13:49:54 -0400600 @param a amount of color alpha, from fully transparent (0) to fully opaque (255)
601 @param r amount of color rgb red, from no red (0) to full red (255)
602 @param g amount of color rgb green, from no green (0) to full green (255)
603 @param b amount of color rgb blue, from no blue (0) to full blue (255)
reed@android.com8a1c16f2008-12-17 15:59:43 +0000604 */
605 void setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b);
606
Cary Clark50fa3ff2017-07-26 10:15:23 -0400607 /** Returns the thickness of the pen used by SkPaint to
608 outline the shape.
609
Cary Clark1eace2d2017-07-31 07:52:43 -0400610 @return zero for hairline, greater than zero for pen thickness
reed@android.com8a1c16f2008-12-17 15:59:43 +0000611 */
612 SkScalar getStrokeWidth() const { return fWidth; }
613
Cary Clark50fa3ff2017-07-26 10:15:23 -0400614 /** Sets the thickness of the pen used by the paint to
615 outline the shape.
616 Has no effect if width is less than zero.
617
Cary Clark1eace2d2017-07-31 07:52:43 -0400618 @param width zero thickness for hairline; greater than zero for pen thickness
reed@android.com8a1c16f2008-12-17 15:59:43 +0000619 */
620 void setStrokeWidth(SkScalar width);
621
Cary Clark50fa3ff2017-07-26 10:15:23 -0400622 /** The limit at which a sharp corner is drawn beveled.
623
624 @return zero and greater miter limit
reed@android.com8a1c16f2008-12-17 15:59:43 +0000625 */
626 SkScalar getStrokeMiter() const { return fMiterLimit; }
627
Cary Clark50fa3ff2017-07-26 10:15:23 -0400628 /** The limit at which a sharp corner is drawn beveled.
629 Valid values are zero and greater.
630 Has no effect if miter is less than zero.
631
632 @param miter zero and greater miter limit
reed@android.com8a1c16f2008-12-17 15:59:43 +0000633 */
634 void setStrokeMiter(SkScalar miter);
635
Cary Clark50fa3ff2017-07-26 10:15:23 -0400636 /** \enum SkPaint::Cap
637 Cap draws at the beginning and end of an open path contour.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000638 */
639 enum Cap {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400640 kButt_Cap, //!< Does not extend the stroke past the beginning or the end.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000641
Cary Clark50fa3ff2017-07-26 10:15:23 -0400642 /** Adds a circle with a diameter equal to stroke width at the beginning
643 and end.
644 */
645 kRound_Cap,
646
647 /** Adds a square with sides equal to stroke width at the beginning
648 and end. The square sides are parallel to the initial and final direction
649 of the stroke.
650 */
651 kSquare_Cap,
652 kLast_Cap = kSquare_Cap, //!< Equivalent to the largest value for Cap.
653
654 /** Equivalent to kButt_Cap.
655 Cap is set to kButt_Cap by default.
656 */
657 kDefault_Cap = kButt_Cap,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000658 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400659
bsalomona7d85ba2016-07-06 11:54:59 -0700660 static constexpr int kCapCount = kLast_Cap + 1;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000661
Cary Clark50fa3ff2017-07-26 10:15:23 -0400662 /** \enum SkPaint::Join
Cary Clark1eace2d2017-07-31 07:52:43 -0400663 Join specifies how corners are drawn when a shape is stroked. Join
Cary Clark50fa3ff2017-07-26 10:15:23 -0400664 affects the four corners of a stroked rectangle, and the connected segments in a
665 stroked path.
666
667 Choose miter join to draw sharp corners. Choose round join to draw a circle with a
668 radius equal to the stroke width on top of the corner. Choose bevel join to minimally
669 connect the thick strokes.
670
671 The fill path constructed to describe the stroked path respects the join setting but may
672 not contain the actual join. For instance, a fill path constructed with round joins does
673 not necessarily include circles at each connected segment.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000674 */
675 enum Join {
Cary Clark23890a92017-07-27 16:30:51 -0400676 /** Extends the outside corner to the extent allowed by miter limit.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400677 If the extension exceeds miter limit, kBevel_Join is used instead.
678 */
679 kMiter_Join,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000680
Cary Clark50fa3ff2017-07-26 10:15:23 -0400681 /** Adds a circle with a diameter of stroke width at the sharp corner. */
682 kRound_Join,
683 kBevel_Join, //!< Connects the outside edges of the sharp corner.
684 kLast_Join = kBevel_Join, //!< Equivalent to the largest value for Join.
685
686 /** Equivalent to kMiter_Join.
687 Join is set to kMiter_Join by default.
688 */
689 kDefault_Join = kMiter_Join,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000690 };
Cary Clark50fa3ff2017-07-26 10:15:23 -0400691
bsalomona7d85ba2016-07-06 11:54:59 -0700692 static constexpr int kJoinCount = kLast_Join + 1;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000693
Cary Clark50fa3ff2017-07-26 10:15:23 -0400694 /** The geometry drawn at the beginning and end of strokes.
695
696 @return one of: kButt_Cap, kRound_Cap, kSquare_Cap
reed@android.com8a1c16f2008-12-17 15:59:43 +0000697 */
reedf59eab22014-07-14 14:39:15 -0700698 Cap getStrokeCap() const { return (Cap)fBitfields.fCapType; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000699
Cary Clark50fa3ff2017-07-26 10:15:23 -0400700 /** The geometry drawn at the beginning and end of strokes.
701
702 @param cap one of: kButt_Cap, kRound_Cap, kSquare_Cap;
703 has no effect if cap is not valid
reed@android.com8a1c16f2008-12-17 15:59:43 +0000704 */
705 void setStrokeCap(Cap cap);
706
Cary Clark50fa3ff2017-07-26 10:15:23 -0400707 /** The geometry drawn at the corners of strokes.
708
709 @return one of: kMiter_Join, kRound_Join, kBevel_Join
reed@android.com8a1c16f2008-12-17 15:59:43 +0000710 */
reedf59eab22014-07-14 14:39:15 -0700711 Join getStrokeJoin() const { return (Join)fBitfields.fJoinType; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000712
Cary Clark50fa3ff2017-07-26 10:15:23 -0400713 /** The geometry drawn at the corners of strokes.
714
715 @param join one of: kMiter_Join, kRound_Join, kBevel_Join;
Cary Clark579985c2017-07-31 11:48:27 -0400716 otherwise, has no effect
reed@android.com8a1c16f2008-12-17 15:59:43 +0000717 */
718 void setStrokeJoin(Join join);
719
Cary Clark50fa3ff2017-07-26 10:15:23 -0400720 /** The filled equivalent of the stroked path.
721
722 @param src SkPath read to create a filled version
723 @param dst resulting SkPath; may be the same as src, but may not be nullptr
724 @param cullRect optional limit passed to SkPathEffect
725 @param resScale if > 1, increase precision, else if (0 < res < 1) reduce precision
726 to favor speed and size
Cary Clark1eace2d2017-07-31 07:52:43 -0400727 @return true if the path represents style fill, or false if it represents hairline
Cary Clark50fa3ff2017-07-26 10:15:23 -0400728 */
reed05d90442015-02-12 13:35:52 -0800729 bool getFillPath(const SkPath& src, SkPath* dst, const SkRect* cullRect,
730 SkScalar resScale = 1) const;
731
Cary Clark50fa3ff2017-07-26 10:15:23 -0400732 /** The filled equivalent of the stroked path.
733
Cary Clark23890a92017-07-27 16:30:51 -0400734 Replaces dst with the src path modified by SkPathEffect and style stroke.
735 SkPathEffect, if any, is not culled. stroke width is created with default precision.
736
737 @param src SkPath read to create a filled version
738 @param dst resulting SkPath dst may be the same as src, but may not be nullptr
Cary Clark1eace2d2017-07-31 07:52:43 -0400739 @return true if the path represents style fill, or false if it represents hairline
Cary Clark50fa3ff2017-07-26 10:15:23 -0400740 */
reed05d90442015-02-12 13:35:52 -0800741 bool getFillPath(const SkPath& src, SkPath* dst) const {
Ben Wagnera93a14a2017-08-28 10:34:05 -0400742 return this->getFillPath(src, dst, nullptr, 1);
reed05d90442015-02-12 13:35:52 -0800743 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000744
Cary Clark50fa3ff2017-07-26 10:15:23 -0400745 /** Optional colors used when filling a path, such as a gradient.
746
747 Does not alter SkShader SkRefCnt.
748
749 @return SkShader if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000750 */
reeda5ab9ec2016-03-06 18:10:48 -0800751 SkShader* getShader() const { return fShader.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400752
753 /** Optional colors used when filling a path, such as a gradient.
754
755 Increases SkShader SkRefCnt by one.
756
757 @return SkShader if previously set, nullptr otherwise
758 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500759 sk_sp<SkShader> refShader() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000760
Cary Clark50fa3ff2017-07-26 10:15:23 -0400761 /** Optional colors used when filling a path, such as a gradient.
762
Cary Clark8a02b0b2017-09-21 12:28:43 -0400763 Sets SkShader to shader, decreasing SkRefCnt of the previous SkShader.
764 Increments shader SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400765
Cary Clark1eace2d2017-07-31 07:52:43 -0400766 @param shader how geometry is filled with color; if nullptr, color is used instead
Cary Clark50fa3ff2017-07-26 10:15:23 -0400767 */
Cary Clark0418a882017-05-10 09:07:42 -0400768 void setShader(sk_sp<SkShader> shader);
reed@google.com9d07fec2011-03-16 20:02:59 +0000769
Cary Clark50fa3ff2017-07-26 10:15:23 -0400770 /** Returns SkColorFilter if set, or nullptr.
771 Does not alter SkColorFilter SkRefCnt.
772
773 @return SkColorFilter if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000774 */
reeda5ab9ec2016-03-06 18:10:48 -0800775 SkColorFilter* getColorFilter() const { return fColorFilter.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400776
777 /** Returns SkColorFilter if set, or nullptr.
778 Increases SkColorFilter SkRefCnt by one.
779
780 @return SkColorFilter if set, or nullptr
781 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500782 sk_sp<SkColorFilter> refColorFilter() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000783
Cary Clark8a02b0b2017-09-21 12:28:43 -0400784 /** Sets SkColorFilter to filter, decreasing SkRefCnt of the previous
785 SkColorFilter. Pass nullptr to clear SkColorFilter.
786
787 Increments filter SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400788
789 @param colorFilter SkColorFilter to apply to subsequent draw
reed@android.com8a1c16f2008-12-17 15:59:43 +0000790 */
Cary Clark0418a882017-05-10 09:07:42 -0400791 void setColorFilter(sk_sp<SkColorFilter> colorFilter);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000792
Cary Clark50fa3ff2017-07-26 10:15:23 -0400793 /** Returns SkBlendMode.
Cary Clark579985c2017-07-31 11:48:27 -0400794 By default, returns SkBlendMode::kSrcOver.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400795
796 @return mode used to combine source color with destination color
797 */
reed374772b2016-10-05 17:33:02 -0700798 SkBlendMode getBlendMode() const { return (SkBlendMode)fBlendMode; }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400799
800 /** Returns true if SkBlendMode is SkBlendMode::kSrcOver, the default.
801
802 @return true if SkBlendMode is SkBlendMode::kSrcOver
803 */
reed374772b2016-10-05 17:33:02 -0700804 bool isSrcOver() const { return (SkBlendMode)fBlendMode == SkBlendMode::kSrcOver; }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400805
806 /** Sets SkBlendMode to mode.
807 Does not check for valid input.
808
809 @param mode SkBlendMode used to combine source color and destination
810 */
reed374772b2016-10-05 17:33:02 -0700811 void setBlendMode(SkBlendMode mode) { fBlendMode = (unsigned)mode; }
reed@android.coma0f5d152009-06-22 17:38:10 +0000812
Cary Clark50fa3ff2017-07-26 10:15:23 -0400813 /** Returns SkPathEffect if set, or nullptr.
814 Does not alter SkPathEffect SkRefCnt.
815
816 @return SkPathEffect if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000817 */
reeda5ab9ec2016-03-06 18:10:48 -0800818 SkPathEffect* getPathEffect() const { return fPathEffect.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400819
820 /** Returns SkPathEffect if set, or nullptr.
821 Increases SkPathEffect SkRefCnt by one.
822
823 @return SkPathEffect if previously set, nullptr otherwise
824 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500825 sk_sp<SkPathEffect> refPathEffect() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000826
Cary Clark8a02b0b2017-09-21 12:28:43 -0400827 /** Sets SkPathEffect to pathEffect, decreasing SkRefCnt of the previous
828 SkPathEffect. Pass nullptr to leave the path geometry unaltered.
829
830 Increments pathEffect SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400831
832 @param pathEffect replace SkPath with a modification when drawn
reed@android.com8a1c16f2008-12-17 15:59:43 +0000833 */
Cary Clark0418a882017-05-10 09:07:42 -0400834 void setPathEffect(sk_sp<SkPathEffect> pathEffect);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000835
Cary Clark50fa3ff2017-07-26 10:15:23 -0400836 /** Returns SkMaskFilter if set, or nullptr.
837 Does not alter SkMaskFilter SkRefCnt.
838
839 @return SkMaskFilter if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000840 */
reeda5ab9ec2016-03-06 18:10:48 -0800841 SkMaskFilter* getMaskFilter() const { return fMaskFilter.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400842
843 /** Returns SkMaskFilter if set, or nullptr.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400844
Cary Clark50fa3ff2017-07-26 10:15:23 -0400845 Increases SkMaskFilter SkRefCnt by one.
846
847 @return SkMaskFilter if previously set, nullptr otherwise
848 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500849 sk_sp<SkMaskFilter> refMaskFilter() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000850
Cary Clark8a02b0b2017-09-21 12:28:43 -0400851 /** Sets SkMaskFilter to maskFilter, decreasing SkRefCnt of the previous
852 SkMaskFilter. Pass nullptr to clear SkMaskFilter and leave SkMaskFilter effect on
853 mask alpha unaltered.
854
Cary Clark50fa3ff2017-07-26 10:15:23 -0400855 Does not affect SkRasterizer.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400856 Increments maskFilter SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400857
858 @param maskFilter modifies clipping mask generated from drawn geometry
reed@android.com8a1c16f2008-12-17 15:59:43 +0000859 */
Cary Clark0418a882017-05-10 09:07:42 -0400860 void setMaskFilter(sk_sp<SkMaskFilter> maskFilter);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000861
Cary Clark50fa3ff2017-07-26 10:15:23 -0400862 /** Returns SkTypeface if set, or nullptr.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400863 Increments SkTypeface SkRefCnt by one.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000864
Cary Clark50fa3ff2017-07-26 10:15:23 -0400865 @return SkTypeface if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000866 */
reeda5ab9ec2016-03-06 18:10:48 -0800867 SkTypeface* getTypeface() const { return fTypeface.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400868
869 /** Increases SkTypeface SkRefCnt by one.
870
871 @return SkTypeface if previously set, nullptr otherwise
872 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500873 sk_sp<SkTypeface> refTypeface() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000874
Cary Clark8a02b0b2017-09-21 12:28:43 -0400875 /** Sets SkTypeface to typeface, decreasing SkRefCnt of the previous SkTypeface.
876 Pass nullptr to clear SkTypeface and use the default typeface. Increments
877 typeface SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400878
879 @param typeface font and style used to draw text
reed@android.com8a1c16f2008-12-17 15:59:43 +0000880 */
Cary Clark0418a882017-05-10 09:07:42 -0400881 void setTypeface(sk_sp<SkTypeface> typeface);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000882
Cary Clark50fa3ff2017-07-26 10:15:23 -0400883 /** Returns SkRasterizer if set, or nullptr.
884 Does not alter SkRasterizer SkRefCnt.
885
886 @return SkRasterizer if previously set, nullptr otherwise
reed@android.com8a1c16f2008-12-17 15:59:43 +0000887 */
reeda5ab9ec2016-03-06 18:10:48 -0800888 SkRasterizer* getRasterizer() const { return fRasterizer.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400889
Cary Clark23890a92017-07-27 16:30:51 -0400890 /** Returns SkRasterizer if set, or nullptr.
891 Increases SkRasterizer SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400892
893 @return SkRasterizer if previously set, nullptr otherwise
894 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500895 sk_sp<SkRasterizer> refRasterizer() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000896
Cary Clark8a02b0b2017-09-21 12:28:43 -0400897 /** Sets SkRasterizer to rasterizer, decreasing SkRefCnt of the previous
898 SkRasterizer. Pass nullptr to clear SkRasterizer and leave SkRasterizer effect on
899 mask alpha unaltered.
900
Cary Clark50fa3ff2017-07-26 10:15:23 -0400901 Does not affect SkMaskFilter.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400902 Increments rasterizer SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400903
904 @param rasterizer how geometry is converted to mask alpha
reed@android.com8a1c16f2008-12-17 15:59:43 +0000905 */
Cary Clark0418a882017-05-10 09:07:42 -0400906 void setRasterizer(sk_sp<SkRasterizer> rasterizer);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000907
Cary Clark50fa3ff2017-07-26 10:15:23 -0400908 /** Returns SkImageFilter if set, or nullptr.
909 Does not alter SkImageFilter SkRefCnt.
910
911 @return SkImageFilter if previously set, nullptr otherwise
912 */
reeda5ab9ec2016-03-06 18:10:48 -0800913 SkImageFilter* getImageFilter() const { return fImageFilter.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400914
915 /** Returns SkImageFilter if set, or nullptr.
916 Increases SkImageFilter SkRefCnt by one.
917
918 @return SkImageFilter if previously set, nullptr otherwise
919 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500920 sk_sp<SkImageFilter> refImageFilter() const;
Cary Clark50fa3ff2017-07-26 10:15:23 -0400921
Cary Clark8a02b0b2017-09-21 12:28:43 -0400922 /** Sets SkImageFilter to imageFilter, decreasing SkRefCnt of the previous
923 SkImageFilter. Pass nullptr to clear SkImageFilter, and remove SkImageFilter effect
Cary Clark50fa3ff2017-07-26 10:15:23 -0400924 on drawing.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400925
Cary Clark50fa3ff2017-07-26 10:15:23 -0400926 Does not affect SkRasterizer or SkMaskFilter.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400927 Increments imageFilter SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400928
929 @param imageFilter how SkImage is sampled when transformed
930 */
Cary Clark0418a882017-05-10 09:07:42 -0400931 void setImageFilter(sk_sp<SkImageFilter> imageFilter);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000932
Cary Clark50fa3ff2017-07-26 10:15:23 -0400933 /** Returns SkDrawLooper if set, or nullptr.
934 Does not alter SkDrawLooper SkRefCnt.
935
936 @return SkDrawLooper if previously set, nullptr otherwise
937 */
reed46f2d0a2016-09-11 05:40:31 -0700938 SkDrawLooper* getDrawLooper() const { return fDrawLooper.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400939
940 /** Returns SkDrawLooper if set, or nullptr.
941 Increases SkDrawLooper SkRefCnt by one.
942
943 @return SkDrawLooper if previously set, nullptr otherwise
944 */
Mike Reed693fdbd2017-01-12 10:13:40 -0500945 sk_sp<SkDrawLooper> refDrawLooper() const;
946
Cary Clark23890a92017-07-27 16:30:51 -0400947 /** Deprecated.
948 (see bug.skia.org/6259)
Cary Clark50fa3ff2017-07-26 10:15:23 -0400949
950 @return SkDrawLooper if previously set, nullptr otherwise
951 */
reed46f2d0a2016-09-11 05:40:31 -0700952 SkDrawLooper* getLooper() const { return fDrawLooper.get(); }
Cary Clark50fa3ff2017-07-26 10:15:23 -0400953
Cary Clark8a02b0b2017-09-21 12:28:43 -0400954 /** Sets SkDrawLooper to drawLooper, decreasing SkRefCnt of the previous
955 drawLooper. Pass nullptr to clear SkDrawLooper and leave SkDrawLooper effect on
956 drawing unaltered.
957
958 Increments drawLooper SkRefCnt by one.
Cary Clark50fa3ff2017-07-26 10:15:23 -0400959
Cary Clarkb7da7232017-09-01 13:49:54 -0400960 @param drawLooper iterates through drawing one or more time, altering SkPaint
Cary Clark50fa3ff2017-07-26 10:15:23 -0400961 */
Cary Clark0418a882017-05-10 09:07:42 -0400962 void setDrawLooper(sk_sp<SkDrawLooper> drawLooper);
Mike Reed09d94352016-10-31 15:11:04 -0400963
Cary Clark23890a92017-07-27 16:30:51 -0400964 /** Deprecated.
965 (see bug.skia.org/6259)
Cary Clark50fa3ff2017-07-26 10:15:23 -0400966
967 @param drawLooper sets SkDrawLooper to drawLooper
968 */
Cary Clark0418a882017-05-10 09:07:42 -0400969 void setLooper(sk_sp<SkDrawLooper> drawLooper);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000970
Cary Clark50fa3ff2017-07-26 10:15:23 -0400971 /** \enum SkPaint::Align
972 Align adjusts the text relative to the text position.
973 Align affects glyphs drawn with: SkCanvas::drawText, SkCanvas::drawPosText,
974 SkCanvas::drawPosTextH, SkCanvas::drawTextOnPath,
975 SkCanvas::drawTextOnPathHV, SkCanvas::drawTextRSXform, SkCanvas::drawTextBlob,
976 and SkCanvas::drawString;
Cary Clark579985c2017-07-31 11:48:27 -0400977 as well as calls that place text glyphs like getTextWidths() and getTextPath().
Cary Clark50fa3ff2017-07-26 10:15:23 -0400978
979 The text position is set by the font for both horizontal and vertical text.
980 Typically, for horizontal text, the position is to the left side of the glyph on the
Cary Clark23890a92017-07-27 16:30:51 -0400981 base line; and for vertical text, the position is the horizontal center of the glyph
Cary Clark50fa3ff2017-07-26 10:15:23 -0400982 at the caps height.
983
984 Align adjusts the glyph position to center it or move it to abut the position
985 using the metrics returned by the font.
986
987 Align defaults to kLeft_Align.
988 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000989 enum Align {
Cary Clark50fa3ff2017-07-26 10:15:23 -0400990 /** Leaves the glyph at the position computed by the font offset by the text position. */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000991 kLeft_Align,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400992
993 /** Moves the glyph half its width if Flags has kVerticalText_Flag clear, and
994 half its height if Flags has kVerticalText_Flag set.
995 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000996 kCenter_Align,
Cary Clark50fa3ff2017-07-26 10:15:23 -0400997
998 /** Moves the glyph by its width if Flags has kVerticalText_Flag clear,
999 and by its height if Flags has kVerticalText_Flag set.
1000 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001001 kRight_Align,
mike@reedtribe.orgddc813b2013-06-08 12:58:19 +00001002 };
Cary Clark50fa3ff2017-07-26 10:15:23 -04001003
mike@reedtribe.orgddc813b2013-06-08 12:58:19 +00001004 enum {
Cary Clark50fa3ff2017-07-26 10:15:23 -04001005 kAlignCount = 3, //!< The number of different Align values defined.
reed@android.com8a1c16f2008-12-17 15:59:43 +00001006 };
reed@google.com9d07fec2011-03-16 20:02:59 +00001007
Cary Clark50fa3ff2017-07-26 10:15:23 -04001008 /** Returns SkPaint::Align.
1009 Returns kLeft_Align if SkPaint::Align has not been set.
1010
1011 @return text placement relative to position
reed@android.com8a1c16f2008-12-17 15:59:43 +00001012 */
reedf59eab22014-07-14 14:39:15 -07001013 Align getTextAlign() const { return (Align)fBitfields.fTextAlign; }
reed@google.com9d07fec2011-03-16 20:02:59 +00001014
Cary Clark50fa3ff2017-07-26 10:15:23 -04001015 /** Sets SkPaint::Align to align.
1016 Has no effect if align is an invalid value.
1017
1018 @param align text placement relative to position
reed@android.com8a1c16f2008-12-17 15:59:43 +00001019 */
1020 void setTextAlign(Align align);
1021
Cary Clark50fa3ff2017-07-26 10:15:23 -04001022 /** Returns text size in points.
1023
1024 @return typographic height of text
reed@android.com8a1c16f2008-12-17 15:59:43 +00001025 */
1026 SkScalar getTextSize() const { return fTextSize; }
1027
Cary Clark50fa3ff2017-07-26 10:15:23 -04001028 /** Sets text size in points.
1029 Has no effect if textSize is not greater than or equal to zero.
1030
1031 @param textSize typographic height of text
reed@android.com8a1c16f2008-12-17 15:59:43 +00001032 */
1033 void setTextSize(SkScalar textSize);
1034
Cary Clark50fa3ff2017-07-26 10:15:23 -04001035 /** Returns text scale x.
1036 Default value is 1.
1037
1038 @return text horizontal scale
reed@android.com8a1c16f2008-12-17 15:59:43 +00001039 */
1040 SkScalar getTextScaleX() const { return fTextScaleX; }
1041
Cary Clark50fa3ff2017-07-26 10:15:23 -04001042 /** Sets text scale x.
1043 Default value is 1.
1044
1045 @param scaleX text horizontal scale
reed@android.com8a1c16f2008-12-17 15:59:43 +00001046 */
1047 void setTextScaleX(SkScalar scaleX);
1048
Cary Clark50fa3ff2017-07-26 10:15:23 -04001049 /** Returns text skew x.
1050 Default value is zero.
1051
1052 @return additional shear in x-axis relative to y-axis
reed@android.com8a1c16f2008-12-17 15:59:43 +00001053 */
1054 SkScalar getTextSkewX() const { return fTextSkewX; }
1055
Cary Clark50fa3ff2017-07-26 10:15:23 -04001056 /** Sets text skew x.
1057 Default value is zero.
1058
1059 @param skewX additional shear in x-axis relative to y-axis
reed@android.com8a1c16f2008-12-17 15:59:43 +00001060 */
1061 void setTextSkewX(SkScalar skewX);
1062
Cary Clark50fa3ff2017-07-26 10:15:23 -04001063 /** \enum SkPaint::TextEncoding
Cary Clark8a02b0b2017-09-21 12:28:43 -04001064 TextEncoding determines whether text specifies character codes and their encoded
Cary Clarkcc309eb2017-10-30 11:48:35 -04001065 size, or glyph indices. Characters are encoded as specified by the Unicode standard.
Cary Clark8a02b0b2017-09-21 12:28:43 -04001066
Cary Clark50fa3ff2017-07-26 10:15:23 -04001067 Character codes encoded size are specified by UTF-8, UTF-16, or UTF-32.
Cary Clarkcc309eb2017-10-30 11:48:35 -04001068 All character code formats are able to represent all of Unicode, differing only
1069 in the total storage required.
1070
1071 UTF-8 (RFC 3629) encodes each character as one or more 8-bit bytes.
1072
1073 UTF-16 (RFC 2781) encodes each character as one or two 16-bit words.
1074
1075 UTF-32 encodes each character as one 32-bit word.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001076
1077 font manager uses font data to convert character code points into glyph indices.
1078 A glyph index is a 16-bit word.
1079
1080 TextEncoding is set to kUTF8_TextEncoding by default.
reed@android.com8a1c16f2008-12-17 15:59:43 +00001081 */
1082 enum TextEncoding {
Cary Clark50fa3ff2017-07-26 10:15:23 -04001083 kUTF8_TextEncoding, //!< Uses bytes to represent UTF-8 or ASCII.
1084 kUTF16_TextEncoding, //!< Uses two byte words to represent most of Unicode.
1085 kUTF32_TextEncoding, //!< Uses four byte words to represent all of Unicode.
1086 kGlyphID_TextEncoding, //!< Uses two byte words to represent glyph indices.
reed@android.com8a1c16f2008-12-17 15:59:43 +00001087 };
reed@google.com9d07fec2011-03-16 20:02:59 +00001088
Cary Clark50fa3ff2017-07-26 10:15:23 -04001089 /** Returns SkPaint::TextEncoding.
1090 SkPaint::TextEncoding determines how character code points are mapped to font glyph indices.
1091
1092 @return one of: kUTF8_TextEncoding, kUTF16_TextEncoding, kUTF32_TextEncoding, or
1093 kGlyphID_TextEncoding
1094 */
reedf59eab22014-07-14 14:39:15 -07001095 TextEncoding getTextEncoding() const {
1096 return (TextEncoding)fBitfields.fTextEncoding;
1097 }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001098
Cary Clark50fa3ff2017-07-26 10:15:23 -04001099 /** Sets SkPaint::TextEncoding to encoding.
1100 SkPaint::TextEncoding determines how character code points are mapped to font glyph indices.
1101 Invalid values for encoding are ignored.
1102
1103 @param encoding one of: kUTF8_TextEncoding, kUTF16_TextEncoding, kUTF32_TextEncoding, or
Cary Clark579985c2017-07-31 11:48:27 -04001104 kGlyphID_TextEncoding
Cary Clark50fa3ff2017-07-26 10:15:23 -04001105 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001106 void setTextEncoding(TextEncoding encoding);
1107
Cary Clark50fa3ff2017-07-26 10:15:23 -04001108 /** \struct SkPaint::FontMetrics
Cary Clark579985c2017-07-31 11:48:27 -04001109 FontMetrics is filled out by getFontMetrics(). FontMetrics contents reflect the values
Cary Clark50fa3ff2017-07-26 10:15:23 -04001110 computed by font manager using SkTypeface. Values are set to zero if they are
Cary Clarkb7da7232017-09-01 13:49:54 -04001111 not available.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001112
1113 fUnderlineThickness and fUnderlinePosition have a bit set in fFlags if their values
1114 are valid, since their value may be zero.
1115
1116 fStrikeoutThickness and fStrikeoutPosition have a bit set in fFlags if their values
1117 are valid, since their value may be zero.
1118 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001119 struct FontMetrics {
Cary Clark50fa3ff2017-07-26 10:15:23 -04001120
Cary Clarkcc309eb2017-10-30 11:48:35 -04001121 /** \enum SkPaint::FontMetrics::FontMetricsFlags
1122 FontMetricsFlags are set in fFlags when underline and strikeout metrics are valid;
1123 the underline or strikeout metric may be valid and zero.
1124 Fonts with embedded bitmaps may not have valid underline or strikeout metrics.
1125 */
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001126 enum FontMetricsFlags {
Cary Clark50fa3ff2017-07-26 10:15:23 -04001127 kUnderlineThicknessIsValid_Flag = 1 << 0, //!< Set if fUnderlineThickness is valid.
1128 kUnderlinePositionIsValid_Flag = 1 << 1, //!< Set if fUnderlinePosition is valid.
1129 kStrikeoutThicknessIsValid_Flag = 1 << 2, //!< Set if fStrikeoutThickness is valid.
1130 kStrikeoutPositionIsValid_Flag = 1 << 3, //!< Set if fStrikeoutPosition is valid.
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001131 };
1132
Cary Clark50fa3ff2017-07-26 10:15:23 -04001133 uint32_t fFlags; //!< fFlags is set when underline metrics are valid.
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001134
Cary Clark50fa3ff2017-07-26 10:15:23 -04001135 /** Largest height for any glyph.
1136 A measure from the baseline, and is less than or equal to zero.
1137 */
1138 SkScalar fTop;
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001139
Cary Clark50fa3ff2017-07-26 10:15:23 -04001140 /** Recommended distance above the baseline to reserve for a line of text.
1141 A measure from the baseline, and is less than or equal to zero.
1142 */
1143 SkScalar fAscent;
Ben Wagner219f3622017-07-17 15:32:25 -04001144
Cary Clark50fa3ff2017-07-26 10:15:23 -04001145 /** Recommended distance below the baseline to reserve for a line of text.
1146 A measure from the baseline, and is greater than or equal to zero.
1147 */
1148 SkScalar fDescent;
Ben Wagner219f3622017-07-17 15:32:25 -04001149
Cary Clark50fa3ff2017-07-26 10:15:23 -04001150 /** Greatest extent below the baseline for any glyph.
1151 A measure from the baseline, and is greater than or equal to zero.
1152 */
1153 SkScalar fBottom;
1154
1155 /** Recommended distance to add between lines of text.
1156 Greater than or equal to zero.
1157 */
1158 SkScalar fLeading;
1159
1160 /** Average character width, if it is available.
1161 Zero if no average width is stored in the font.
1162 */
1163 SkScalar fAvgCharWidth;
Cary Clarkcc309eb2017-10-30 11:48:35 -04001164
Cary Clark50fa3ff2017-07-26 10:15:23 -04001165 SkScalar fMaxCharWidth; //!< Maximum character width.
1166
1167 /** Minimum bounding box x value for all glyphs.
1168 Typically less than zero.
1169 */
1170 SkScalar fXMin;
1171
1172 /** Maximum bounding box x value for all glyphs.
1173 Typically greater than zero.
1174 */
1175 SkScalar fXMax;
1176
1177 /** Height of a lower-case 'x'.
1178 May be zero if no lower-case height is stored in the font.
1179 */
1180 SkScalar fXHeight;
1181
1182 /** Height of an upper-case letter.
1183 May be zero if no upper-case height is stored in the font.
1184 */
1185 SkScalar fCapHeight;
1186
1187 /** Underline thickness. If the metric
1188 is valid, the kUnderlineThicknessIsValid_Flag is set in fFlags.
1189 If kUnderlineThicknessIsValid_Flag is clear, fUnderlineThickness is zero.
1190 */
1191 SkScalar fUnderlineThickness;
1192
1193 /** Underline position relative to the baseline.
1194 It may be negative, to draw the underline above the baseline, zero
1195 to draw the underline on the baseline, or positive to draw the underline
1196 below the baseline.
1197
1198 If the metric is valid, the kUnderlinePositionIsValid_Flag is set in fFlags.
1199 If kUnderlinePositionIsValid_Flag is clear, fUnderlinePosition is zero.
1200 */
1201 SkScalar fUnderlinePosition;
1202
1203 /** Strikeout thickness. If the metric
1204 is valid, the kStrikeoutThicknessIsValid_Flag is set in fFlags.
1205 If kStrikeoutThicknessIsValid_Flag is clear, fStrikeoutThickness is zero.
1206 */
1207 SkScalar fStrikeoutThickness;
1208
1209 /** Strikeout position relative to the baseline.
1210 It may be negative, to draw the strikeout above the baseline, zero
1211 to draw the strikeout on the baseline, or positive to draw the strikeout
1212 below the baseline.
1213
1214 If the metric is valid, the kStrikeoutPositionIsValid_Flag is set in fFlags.
1215 If kStrikeoutPositionIsValid_Flag is clear, fStrikeoutPosition is zero.
1216 */
1217 SkScalar fStrikeoutPosition;
1218
1219 /** If SkPaint::FontMetrics has a valid underline thickness, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001220 thickness to that value. If the underline thickness is not valid,
1221 return false, and ignore thickness.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001222
1223 @param thickness storage for underline width
1224 @return true if font specifies underline width
1225 */
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001226 bool hasUnderlineThickness(SkScalar* thickness) const {
Ben Wagner3318da52017-03-23 14:01:22 -04001227 if (SkToBool(fFlags & kUnderlineThicknessIsValid_Flag)) {
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001228 *thickness = fUnderlineThickness;
1229 return true;
1230 }
1231 return false;
1232 }
1233
Cary Clark50fa3ff2017-07-26 10:15:23 -04001234 /** If SkPaint::FontMetrics has a valid underline position, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001235 position to that value. If the underline position is not valid,
1236 return false, and ignore position.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001237
1238 @param position storage for underline position
1239 @return true if font specifies underline position
1240 */
commit-bot@chromium.org0bc406d2014-03-01 20:12:26 +00001241 bool hasUnderlinePosition(SkScalar* position) const {
1242 if (SkToBool(fFlags & kUnderlinePositionIsValid_Flag)) {
1243 *position = fUnderlinePosition;
1244 return true;
1245 }
1246 return false;
1247 }
1248
Cary Clark50fa3ff2017-07-26 10:15:23 -04001249 /** If SkPaint::FontMetrics has a valid strikeout thickness, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001250 thickness to that value. If the underline thickness is not valid,
1251 return false, and ignore thickness.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001252
1253 @param thickness storage for strikeout width
1254 @return true if font specifies strikeout width
1255 */
Ben Wagner219f3622017-07-17 15:32:25 -04001256 bool hasStrikeoutThickness(SkScalar* thickness) const {
1257 if (SkToBool(fFlags & kStrikeoutThicknessIsValid_Flag)) {
1258 *thickness = fStrikeoutThickness;
1259 return true;
1260 }
1261 return false;
1262 }
1263
Cary Clark50fa3ff2017-07-26 10:15:23 -04001264 /** If SkPaint::FontMetrics has a valid strikeout position, return true, and set
Cary Clarkb7da7232017-09-01 13:49:54 -04001265 position to that value. If the underline position is not valid,
1266 return false, and ignore position.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001267
1268 @param position storage for strikeout position
1269 @return true if font specifies strikeout position
1270 */
Ben Wagner219f3622017-07-17 15:32:25 -04001271 bool hasStrikeoutPosition(SkScalar* position) const {
1272 if (SkToBool(fFlags & kStrikeoutPositionIsValid_Flag)) {
1273 *position = fStrikeoutPosition;
1274 return true;
1275 }
1276 return false;
1277 }
Cary Clark50fa3ff2017-07-26 10:15:23 -04001278
reed@android.com8a1c16f2008-12-17 15:59:43 +00001279 };
reed@google.com9d07fec2011-03-16 20:02:59 +00001280
Cary Clark50fa3ff2017-07-26 10:15:23 -04001281 /** Returns SkPaint::FontMetrics associated with SkTypeface.
1282 The return value is the recommended spacing between lines: the sum of metrics
1283 descent, ascent, and leading.
1284 If metrics is not nullptr, SkPaint::FontMetrics is copied to metrics.
1285 Results are scaled by text size but does not take into account
1286 dimensions required by text scale x, text skew x, fake bold,
1287 style stroke, and SkPathEffect.
1288 Results can be additionally scaled by scale; a scale of zero
1289 is ignored.
1290
1291 @param metrics storage for SkPaint::FontMetrics from SkTypeface; may be nullptr
1292 @param scale additional multiplier for returned values
1293 @return recommended spacing between lines
reed@android.com8a1c16f2008-12-17 15:59:43 +00001294 */
1295 SkScalar getFontMetrics(FontMetrics* metrics, SkScalar scale = 0) const;
reed@google.com9d07fec2011-03-16 20:02:59 +00001296
Cary Clark50fa3ff2017-07-26 10:15:23 -04001297 /** Returns the recommended spacing between lines: the sum of metrics
1298 descent, ascent, and leading.
1299 Result is scaled by text size but does not take into account
1300 dimensions required by stroking and SkPathEffect.
Cary Clark579985c2017-07-31 11:48:27 -04001301 Returns the same result as getFontMetrics().
Cary Clark50fa3ff2017-07-26 10:15:23 -04001302
1303 @return recommended spacing between lines
reed@android.com8a1c16f2008-12-17 15:59:43 +00001304 */
Ben Wagnera93a14a2017-08-28 10:34:05 -04001305 SkScalar getFontSpacing() const { return this->getFontMetrics(nullptr, 0); }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001306
Cary Clark50fa3ff2017-07-26 10:15:23 -04001307 /** Converts text into glyph indices.
1308 Returns the number of glyph indices represented by text.
1309 SkPaint::TextEncoding specifies how text represents characters or glyphs.
1310 glyphs may be nullptr, to compute the glyph count.
1311
Cary Clarkcc309eb2017-10-30 11:48:35 -04001312 Does not check text for valid character codes or valid glyph indices.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001313
Cary Clark579985c2017-07-31 11:48:27 -04001314 If byteLength equals zero, returns zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001315 If byteLength includes a partial character, the partial character is ignored.
1316
1317 If SkPaint::TextEncoding is kUTF8_TextEncoding and
1318 text contains an invalid UTF-8 sequence, zero is returned.
1319
Cary Clarkb7da7232017-09-01 13:49:54 -04001320 @param text character storage encoded with SkPaint::TextEncoding
Cary Clark50fa3ff2017-07-26 10:15:23 -04001321 @param byteLength length of character storage in bytes
1322 @param glyphs storage for glyph indices; may be nullptr
1323 @return number of glyphs represented by text of length byteLength
reed@android.com8a1c16f2008-12-17 15:59:43 +00001324 */
1325 int textToGlyphs(const void* text, size_t byteLength,
halcanaryd0e95a52016-07-25 07:18:12 -07001326 SkGlyphID glyphs[]) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001327
Cary Clark50fa3ff2017-07-26 10:15:23 -04001328 /** Returns true if all text corresponds to a non-zero glyph index.
1329 Returns false if any characters in text are not supported in
1330 SkTypeface.
reed@android.coma5dcaf62010-02-05 17:12:32 +00001331
Cary Clark579985c2017-07-31 11:48:27 -04001332 If SkPaint::TextEncoding is kGlyphID_TextEncoding,
1333 returns true if all glyph indices in text are non-zero;
Cary Clark50fa3ff2017-07-26 10:15:23 -04001334 does not check to see if text contains valid glyph indices for SkTypeface.
1335
Cary Clarkb7da7232017-09-01 13:49:54 -04001336 Returns true if byteLength is zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001337
1338 @param text array of characters or glyphs
1339 @param byteLength number of bytes in text array
1340 @return true if all text corresponds to a non-zero glyph index
1341 */
reed@android.coma5dcaf62010-02-05 17:12:32 +00001342 bool containsText(const void* text, size_t byteLength) const;
1343
Cary Clark50fa3ff2017-07-26 10:15:23 -04001344 /** Converts glyphs into text if possible.
1345 Glyph values without direct Unicode equivalents are mapped to zero.
1346 Uses the SkTypeface, but is unaffected
1347 by SkPaint::TextEncoding; the text values returned are equivalent to kUTF32_TextEncoding.
1348
1349 Only supported on platforms that use FreeType as the font engine.
1350
1351 @param glyphs array of indices into font
1352 @param count length of glyph array
1353 @param text storage for character codes, one per glyph
reed@android.com9d3a9852010-01-08 14:07:42 +00001354 */
halcanaryd0e95a52016-07-25 07:18:12 -07001355 void glyphsToUnichars(const SkGlyphID glyphs[], int count, SkUnichar text[]) const;
reed@android.com9d3a9852010-01-08 14:07:42 +00001356
Cary Clark50fa3ff2017-07-26 10:15:23 -04001357 /** Returns the number of glyphs in text.
1358 Uses SkPaint::TextEncoding to count the glyphs.
Cary Clark579985c2017-07-31 11:48:27 -04001359 Returns the same result as textToGlyphs().
Cary Clark50fa3ff2017-07-26 10:15:23 -04001360
Cary Clarkb7da7232017-09-01 13:49:54 -04001361 @param text character storage encoded with SkPaint::TextEncoding
Cary Clark50fa3ff2017-07-26 10:15:23 -04001362 @param byteLength length of character storage in bytes
1363 @return number of glyphs represented by text of length byteLength
reed@android.com8a1c16f2008-12-17 15:59:43 +00001364 */
reed@google.com9d07fec2011-03-16 20:02:59 +00001365 int countText(const void* text, size_t byteLength) const {
Ben Wagnera93a14a2017-08-28 10:34:05 -04001366 return this->textToGlyphs(text, byteLength, nullptr);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001367 }
1368
Cary Clark50fa3ff2017-07-26 10:15:23 -04001369 /** Returns the advance width of text if kVerticalText_Flag is clear,
1370 and the height of text if kVerticalText_Flag is set.
1371 The advance is the normal distance to move before drawing additional text.
1372 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
1373 and text size, text scale x, text skew x, stroke width, and
1374 SkPathEffect to scale the metrics and bounds.
1375 Returns the bounding box of text if bounds is not nullptr.
1376 The bounding box is computed as if the text was drawn at the origin.
1377
1378 @param text character codes or glyph indices to be measured
1379 @param length number of bytes of text to measure
1380 @param bounds returns bounding box relative to (0, 0) if not nullptr
1381 @return advance width or height
1382 */
reed99ae8812014-08-26 11:30:01 -07001383 SkScalar measureText(const void* text, size_t length, SkRect* bounds) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001384
Cary Clark50fa3ff2017-07-26 10:15:23 -04001385 /** Returns the advance width of text if kVerticalText_Flag is clear,
1386 and the height of text if kVerticalText_Flag is set.
1387 The advance is the normal distance to move before drawing additional text.
1388 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
Cary Clark23890a92017-07-27 16:30:51 -04001389 and text size to scale the metrics.
1390 Does not scale the advance or bounds by fake bold or SkPathEffect.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001391
1392 @param text character codes or glyph indices to be measured
1393 @param length number of bytes of text to measure
Cary Clark50fa3ff2017-07-26 10:15:23 -04001394 @return advance width or height
1395 */
reed@google.com9d07fec2011-03-16 20:02:59 +00001396 SkScalar measureText(const void* text, size_t length) const {
Ben Wagnera93a14a2017-08-28 10:34:05 -04001397 return this->measureText(text, length, nullptr);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001398 }
reed@google.com9d07fec2011-03-16 20:02:59 +00001399
Cary Clark50fa3ff2017-07-26 10:15:23 -04001400 /** Returns the bytes of text that fit within maxWidth.
1401 If kVerticalText_Flag is clear, the text fragment fits if its advance width is less than or
1402 equal to maxWidth.
1403 If kVerticalText_Flag is set, the text fragment fits if its advance height is less than or
1404 equal to maxWidth.
1405 Measures only while the advance is less than or equal to maxWidth.
1406 Returns the advance or the text fragment in measuredWidth if it not nullptr.
1407 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
1408 and text size to scale the metrics.
1409 Does not scale the advance or bounds by fake bold or SkPathEffect.
1410
1411 @param text character codes or glyph indices to be measured
1412 @param length number of bytes of text to measure
1413 @param maxWidth advance limit; text is measured while advance is less than maxWidth
1414 @param measuredWidth returns the width of the text less than or equal to maxWidth
1415 @return bytes of text that fit, always less than or equal to length
1416 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001417 size_t breakText(const void* text, size_t length, SkScalar maxWidth,
Ben Wagnera93a14a2017-08-28 10:34:05 -04001418 SkScalar* measuredWidth = nullptr) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001419
Cary Clark50fa3ff2017-07-26 10:15:23 -04001420 /** Retrieves the advance and bounds for each glyph in text, and returns
1421 the glyph count in text.
1422 Both widths and bounds may be nullptr.
1423 If widths is not nullptr, widths must be an array of glyph count entries.
1424 if bounds is not nullptr, bounds must be an array of glyph count entries.
1425 If kVerticalText_Flag is clear, widths returns the horizontal advance.
1426 If kVerticalText_Flag is set, widths returns the vertical advance.
1427 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
1428 and text size to scale the widths and bounds.
1429 Does not scale the advance by fake bold or SkPathEffect.
Cary Clark23890a92017-07-27 16:30:51 -04001430 Does include fake bold and SkPathEffect in the bounds.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001431
1432 @param text character codes or glyph indices to be measured
1433 @param byteLength number of bytes of text to measure
1434 @param widths returns text advances for each glyph; may be nullptr
1435 @param bounds returns bounds for each glyph relative to (0, 0); may be nullptr
1436 @return glyph count in text
1437 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001438 int getTextWidths(const void* text, size_t byteLength, SkScalar widths[],
Ben Wagnera93a14a2017-08-28 10:34:05 -04001439 SkRect bounds[] = nullptr) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001440
Cary Clark50fa3ff2017-07-26 10:15:23 -04001441 /** Returns the geometry as SkPath equivalent to the drawn text.
1442 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1443 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1444 All of the glyph paths are stored in path.
Cary Clark579985c2017-07-31 11:48:27 -04001445 Uses x, y, and SkPaint::Align to position path.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001446
1447 @param text character codes or glyph indices
1448 @param length number of bytes of text
1449 @param x x-coordinate of the origin of the text
1450 @param y y-coordinate of the origin of the text
1451 @param path geometry of the glyphs
1452 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001453 void getTextPath(const void* text, size_t length, SkScalar x, SkScalar y,
1454 SkPath* path) const;
1455
Cary Clark50fa3ff2017-07-26 10:15:23 -04001456 /** Returns the geometry as SkPath equivalent to the drawn text.
1457 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1458 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1459 All of the glyph paths are stored in path.
1460 Uses pos array and SkPaint::Align to position path.
1461 pos contains a position for each glyph.
1462
1463 @param text character codes or glyph indices
1464 @param length number of bytes of text
1465 @param pos positions of each glyph
1466 @param path geometry of the glyphs
1467 */
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001468 void getPosTextPath(const void* text, size_t length,
reed@google.comca0062e2012-07-20 11:20:32 +00001469 const SkPoint pos[], SkPath* path) const;
1470
Cary Clark50fa3ff2017-07-26 10:15:23 -04001471 /** Returns the number of intervals that intersect bounds.
1472 bounds describes a pair of lines parallel to the text advance.
1473 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1474 the string.
1475 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1476 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1477 Uses x, y, and SkPaint::Align to position intervals.
1478
1479 Pass nullptr for intervals to determine the size of the interval array.
1480
1481 intervals are cached to improve performance for multiple calls.
1482
1483 @param text character codes or glyph indices
1484 @param length number of bytes of text
1485 @param x x-coordinate of the origin of the text
1486 @param y y-coordinate of the origin of the text
1487 @param bounds lower and upper line parallel to the advance
1488 @param intervals returned intersections; may be nullptr
1489 @return number of intersections; may be zero
1490 */
caryclark0449bcf2016-02-09 13:25:45 -08001491 int getTextIntercepts(const void* text, size_t length, SkScalar x, SkScalar y,
1492 const SkScalar bounds[2], SkScalar* intervals) const;
1493
Cary Clark50fa3ff2017-07-26 10:15:23 -04001494 /** Returns the number of intervals that intersect bounds.
1495 bounds describes a pair of lines parallel to the text advance.
1496 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1497 the string.
1498 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1499 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1500 Uses pos array and SkPaint::Align to position intervals.
1501
1502 Pass nullptr for intervals to determine the size of the interval array.
1503
1504 intervals are cached to improve performance for multiple calls.
1505
1506 @param text character codes or glyph indices
1507 @param length number of bytes of text
1508 @param pos positions of each glyph
1509 @param bounds lower and upper line parallel to the advance
1510 @param intervals returned intersections; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -04001511 @return number of intersections; may be zero
Cary Clark50fa3ff2017-07-26 10:15:23 -04001512 */
caryclark0449bcf2016-02-09 13:25:45 -08001513 int getPosTextIntercepts(const void* text, size_t length, const SkPoint pos[],
1514 const SkScalar bounds[2], SkScalar* intervals) const;
1515
Cary Clark50fa3ff2017-07-26 10:15:23 -04001516 /** Returns the number of intervals that intersect bounds.
1517 bounds describes a pair of lines parallel to the text advance.
1518 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1519 the string.
1520 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1521 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
1522 Uses xpos array, constY, and SkPaint::Align to position intervals.
1523
1524 Pass nullptr for intervals to determine the size of the interval array.
1525
1526 intervals are cached to improve performance for multiple calls.
1527
1528 @param text character codes or glyph indices
1529 @param length number of bytes of text
1530 @param xpos positions of each glyph in x
1531 @param constY position of each glyph in y
1532 @param bounds lower and upper line parallel to the advance
1533 @param intervals returned intersections; may be nullptr
1534 @return number of intersections; may be zero
1535 */
fmalitaeae6a912016-07-28 09:47:24 -07001536 int getPosTextHIntercepts(const void* text, size_t length, const SkScalar xpos[],
1537 SkScalar constY, const SkScalar bounds[2], SkScalar* intervals) const;
1538
Cary Clark50fa3ff2017-07-26 10:15:23 -04001539 /** Returns the number of intervals that intersect bounds.
1540 bounds describes a pair of lines parallel to the text advance.
1541 The return count is zero or a multiple of two, and is at most twice the number of glyphs in
1542 the string.
1543 Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
1544 and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
Cary Clarkb7da7232017-09-01 13:49:54 -04001545 Uses run array and SkPaint::Align to position intervals.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001546
1547 Pass nullptr for intervals to determine the size of the interval array.
1548
1549 intervals are cached to improve performance for multiple calls.
1550
Cary Clark8a02b0b2017-09-21 12:28:43 -04001551 @param blob glyphs, positions, and text paint attributes
Cary Clark50fa3ff2017-07-26 10:15:23 -04001552 @param bounds lower and upper line parallel to the advance
1553 @param intervals returned intersections; may be nullptr
1554 @return number of intersections; may be zero
1555 */
fmalitaeae6a912016-07-28 09:47:24 -07001556 int getTextBlobIntercepts(const SkTextBlob* blob, const SkScalar bounds[2],
1557 SkScalar* intervals) const;
1558
Cary Clark50fa3ff2017-07-26 10:15:23 -04001559 /** Returns the union of bounds of all glyphs.
1560 Returned dimensions are computed by font manager from font data,
Cary Clark579985c2017-07-31 11:48:27 -04001561 ignoring SkPaint::Hinting. Includes text size, text scale x,
Cary Clark50fa3ff2017-07-26 10:15:23 -04001562 and text skew x, but not fake bold or SkPathEffect.
1563
1564 If text size is large, text scale x is one, and text skew x is zero,
Cary Clark579985c2017-07-31 11:48:27 -04001565 returns the same bounds as SkPaint::FontMetrics { FontMetrics::fXMin,
Cary Clark50fa3ff2017-07-26 10:15:23 -04001566 FontMetrics::fTop, FontMetrics::fXMax, FontMetrics::fBottom }.
1567
1568 @return union of bounds of all glyphs
1569 */
reed8893e5f2014-12-15 13:27:26 -08001570 SkRect getFontBounds() const;
1571
Cary Clark579985c2017-07-31 11:48:27 -04001572 /** Returns true if SkPaint prevents all drawing;
1573 otherwise, the SkPaint may or may not allow drawing.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001574
Cary Clarkb7da7232017-09-01 13:49:54 -04001575 Returns true if, for example, SkBlendMode combined with color alpha computes a
1576 new alpha of zero.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001577
1578 @return true if SkPaint prevents all drawing
1579 */
reed@google.com632e1a22011-10-06 12:37:00 +00001580 bool nothingToDraw() const;
1581
Cary Clark50fa3ff2017-07-26 10:15:23 -04001582 /** (to be made private)
1583 Returns true if SkPaint does not include elements requiring extensive computation
1584 to compute SkBaseDevice bounds of drawn geometry. For instance, SkPaint with SkPathEffect
1585 always returns false.
reed@google.comd5f20792012-05-16 14:15:02 +00001586
Cary Clark50fa3ff2017-07-26 10:15:23 -04001587 @return true if SkPaint allows for fast computation of bounds
1588 */
senorblanco0abdf762015-08-20 11:10:41 -07001589 bool canComputeFastBounds() const;
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001590
Cary Clark50fa3ff2017-07-26 10:15:23 -04001591 /** (to be made private)
Cary Clark579985c2017-07-31 11:48:27 -04001592 Only call this if canComputeFastBounds() returned true. This takes a
Cary Clark50fa3ff2017-07-26 10:15:23 -04001593 raw rectangle (the raw bounds of a shape), and adjusts it for stylistic
1594 effects in the paint (e.g. stroking). If needed, it uses the storage
Cary Clarkb7da7232017-09-01 13:49:54 -04001595 parameter. It returns the adjusted bounds that can then be used
Cary Clark50fa3ff2017-07-26 10:15:23 -04001596 for SkCanvas::quickReject tests.
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001597
Cary Clarkb7da7232017-09-01 13:49:54 -04001598 The returned SkRect will either be orig or storage, thus the caller
Cary Clark50fa3ff2017-07-26 10:15:23 -04001599 should not rely on storage being set to the result, but should always
Cary Clarkb7da7232017-09-01 13:49:54 -04001600 use the returned value. It is legal for orig and storage to be the same
1601 SkRect.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001602 e.g.
1603 if (paint.canComputeFastBounds()) {
1604 SkRect r, storage;
1605 path.computeBounds(&r, SkPath::kFast_BoundsType);
1606 const SkRect& fastR = paint.computeFastBounds(r, &storage);
1607 if (canvas->quickReject(fastR, ...)) {
1608 // don't draw the path
1609 }
1610 }
1611
1612 @param orig geometry modified by SkPaint when drawn
1613 @param storage computed bounds of geometry; may not be nullptr
1614 @return fast computed bounds
1615 */
reed@google.coma584aed2012-05-16 14:06:02 +00001616 const SkRect& computeFastBounds(const SkRect& orig, SkRect* storage) const {
Brian Osman60751d72017-05-12 11:21:36 -04001617 // Things like stroking, etc... will do math on the bounds rect, assuming that it's sorted.
1618 SkASSERT(orig.isSorted());
reed@google.coma584aed2012-05-16 14:06:02 +00001619 SkPaint::Style style = this->getStyle();
1620 // ultra fast-case: filling with no effects that affect geometry
1621 if (kFill_Style == style) {
1622 uintptr_t effects = reinterpret_cast<uintptr_t>(this->getLooper());
1623 effects |= reinterpret_cast<uintptr_t>(this->getMaskFilter());
1624 effects |= reinterpret_cast<uintptr_t>(this->getPathEffect());
senorblanco@chromium.org336d1d72014-01-27 21:03:17 +00001625 effects |= reinterpret_cast<uintptr_t>(this->getImageFilter());
reed@google.coma584aed2012-05-16 14:06:02 +00001626 if (!effects) {
1627 return orig;
1628 }
1629 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001630
reed@google.coma584aed2012-05-16 14:06:02 +00001631 return this->doComputeFastBounds(orig, storage, style);
1632 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001633
Cary Clark50fa3ff2017-07-26 10:15:23 -04001634 /** (to be made private)
1635
1636 @param orig geometry modified by SkPaint when drawn
1637 @param storage computed bounds of geometry
1638 @return fast computed bounds
1639 */
reed@google.coma584aed2012-05-16 14:06:02 +00001640 const SkRect& computeFastStrokeBounds(const SkRect& orig,
1641 SkRect* storage) const {
reed@google.com73a02582012-05-16 19:21:12 +00001642 return this->doComputeFastBounds(orig, storage, kStroke_Style);
reed@google.coma584aed2012-05-16 14:06:02 +00001643 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001644
Cary Clark50fa3ff2017-07-26 10:15:23 -04001645 /** (to be made private)
Cary Clarkb7da7232017-09-01 13:49:54 -04001646 Computes the bounds, overriding the SkPaint SkPaint::Style. This can be used to
1647 account for additional width required by stroking orig, without
1648 altering SkPaint::Style set to fill.
Cary Clark50fa3ff2017-07-26 10:15:23 -04001649
1650 @param orig geometry modified by SkPaint when drawn
1651 @param storage computed bounds of geometry
1652 @param style overrides SkPaint::Style
1653 @return fast computed bounds
1654 */
reed@google.coma584aed2012-05-16 14:06:02 +00001655 const SkRect& doComputeFastBounds(const SkRect& orig, SkRect* storage,
Cary Clark0418a882017-05-10 09:07:42 -04001656 Style style) const;
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001657
Cary Clark23890a92017-07-27 16:30:51 -04001658 /** macro expands to: void toString(SkString* str) const;
Cary Clarkb7da7232017-09-01 13:49:54 -04001659 Creates string representation of SkPaint. The representation is read by
1660 internal debugging tools. The interface and implementation may be
1661 suppressed by defining SK_IGNORE_TO_STRING.
Cary Clark0418a882017-05-10 09:07:42 -04001662
Cary Clarkb7da7232017-09-01 13:49:54 -04001663 @param str storage for string representation of SkPaint
Cary Clark50fa3ff2017-07-26 10:15:23 -04001664 */
commit-bot@chromium.org0f10f7b2014-03-13 18:02:17 +00001665 SK_TO_STRING_NONVIRT()
robertphillips@google.com791f12e2013-02-14 13:53:53 +00001666
reed@google.comd5f20792012-05-16 14:15:02 +00001667private:
Cary Clark0418a882017-05-10 09:07:42 -04001668 typedef const SkGlyph& (*GlyphCacheProc)(SkGlyphCache*, const char**);
1669
reeda5ab9ec2016-03-06 18:10:48 -08001670 sk_sp<SkTypeface> fTypeface;
1671 sk_sp<SkPathEffect> fPathEffect;
1672 sk_sp<SkShader> fShader;
reeda5ab9ec2016-03-06 18:10:48 -08001673 sk_sp<SkMaskFilter> fMaskFilter;
1674 sk_sp<SkColorFilter> fColorFilter;
1675 sk_sp<SkRasterizer> fRasterizer;
reed46f2d0a2016-09-11 05:40:31 -07001676 sk_sp<SkDrawLooper> fDrawLooper;
reeda5ab9ec2016-03-06 18:10:48 -08001677 sk_sp<SkImageFilter> fImageFilter;
reed@google.comd5f20792012-05-16 14:15:02 +00001678
commit-bot@chromium.orge8807f42014-03-24 23:03:11 +00001679 SkScalar fTextSize;
1680 SkScalar fTextScaleX;
1681 SkScalar fTextSkewX;
reed@google.comd5f20792012-05-16 14:15:02 +00001682 SkColor fColor;
1683 SkScalar fWidth;
1684 SkScalar fMiterLimit;
Mike Reed71fecc32016-11-18 17:19:54 -05001685 uint32_t fBlendMode; // just need 5-6 bits
commit-bot@chromium.orgaca1c012014-02-21 18:18:05 +00001686 union {
1687 struct {
1688 // all of these bitfields should add up to 32
1689 unsigned fFlags : 16;
1690 unsigned fTextAlign : 2;
1691 unsigned fCapType : 2;
1692 unsigned fJoinType : 2;
1693 unsigned fStyle : 2;
1694 unsigned fTextEncoding : 2; // 3 values
1695 unsigned fHinting : 2;
reedf803da12015-01-23 05:58:07 -08001696 unsigned fFilterQuality : 2;
commit-bot@chromium.org85faf502014-04-16 12:58:02 +00001697 //unsigned fFreeBits : 2;
reedf59eab22014-07-14 14:39:15 -07001698 } fBitfields;
1699 uint32_t fBitfieldsUInt;
commit-bot@chromium.orgaca1c012014-02-21 18:18:05 +00001700 };
commit-bot@chromium.orge8807f42014-03-24 23:03:11 +00001701
robertphillipse34f17d2016-07-19 07:59:22 -07001702 static GlyphCacheProc GetGlyphCacheProc(TextEncoding encoding,
1703 bool isDevKern,
1704 bool needFullMetrics);
reed@google.comd5f20792012-05-16 14:15:02 +00001705
1706 SkScalar measure_text(SkGlyphCache*, const char* text, size_t length,
1707 int* count, SkRect* bounds) const;
1708
brianosmana1e8f8d2016-04-08 06:47:54 -07001709 enum ScalerContextFlags : uint32_t {
1710 kNone_ScalerContextFlags = 0,
1711
1712 kFakeGamma_ScalerContextFlag = 1 << 0,
1713 kBoostContrast_ScalerContextFlag = 1 << 1,
1714
1715 kFakeGammaAndBoostContrast_ScalerContextFlags =
1716 kFakeGamma_ScalerContextFlag | kBoostContrast_ScalerContextFlag,
bungemanf6d1e602016-02-22 13:20:28 -08001717 };
1718
joshualittfd450792015-03-13 08:38:43 -07001719 /*
1720 * Allocs an SkDescriptor on the heap and return it to the caller as a refcnted
1721 * SkData. Caller is responsible for managing the lifetime of this object.
1722 */
reeda9322c22016-04-12 06:47:05 -07001723 void getScalerContextDescriptor(SkScalerContextEffects*, SkAutoDescriptor*,
1724 const SkSurfaceProps& surfaceProps,
brianosmana1e8f8d2016-04-08 06:47:54 -07001725 uint32_t scalerContextFlags, const SkMatrix*) const;
joshualittfd450792015-03-13 08:38:43 -07001726
brianosmana1e8f8d2016-04-08 06:47:54 -07001727 SkGlyphCache* detachCache(const SkSurfaceProps* surfaceProps, uint32_t scalerContextFlags,
bungemanf6d1e602016-02-22 13:20:28 -08001728 const SkMatrix*) const;
reed@google.comd5f20792012-05-16 14:15:02 +00001729
brianosmana1e8f8d2016-04-08 06:47:54 -07001730 void descriptorProc(const SkSurfaceProps* surfaceProps, uint32_t scalerContextFlags,
bungemanf6d1e602016-02-22 13:20:28 -08001731 const SkMatrix* deviceMatrix,
reeda9322c22016-04-12 06:47:05 -07001732 void (*proc)(SkTypeface*, const SkScalerContextEffects&,
1733 const SkDescriptor*, void*),
bungemanf6d1e602016-02-22 13:20:28 -08001734 void* context) const;
reed@android.comd252db02009-04-01 18:31:44 +00001735
joshualitt9e36c1a2015-04-14 12:17:27 -07001736 /*
1737 * The luminance color is used to determine which Gamma Canonical color to map to. This is
1738 * really only used by backends which want to cache glyph masks, and need some way to know if
1739 * they need to generate new masks based off a given color.
1740 */
1741 SkColor computeLuminanceColor() const;
1742
reed@android.com8a1c16f2008-12-17 15:59:43 +00001743 enum {
reed@google.comed43dff2013-06-04 16:56:27 +00001744 /* This is the size we use when we ask for a glyph's path. We then
1745 * post-transform it as we draw to match the request.
1746 * This is done to try to re-use cache entries for the path.
1747 *
1748 * This value is somewhat arbitrary. In theory, it could be 1, since
1749 * we store paths as floats. However, we get the path from the font
1750 * scaler, and it may represent its paths as fixed-point (or 26.6),
1751 * so we shouldn't ask for something too big (might overflow 16.16)
1752 * or too small (underflow 26.6).
1753 *
1754 * This value could track kMaxSizeForGlyphCache, assuming the above
1755 * constraints, but since we ask for unhinted paths, the two values
1756 * need not match per-se.
1757 */
1758 kCanonicalTextSizeForPaths = 64,
reed@android.com8a1c16f2008-12-17 15:59:43 +00001759 };
reed@google.comed43dff2013-06-04 16:56:27 +00001760
1761 static bool TooBigToUseCache(const SkMatrix& ctm, const SkMatrix& textM);
1762
reed@google.comed43dff2013-06-04 16:56:27 +00001763 // Set flags/hinting/textSize up to use for drawing text as paths.
1764 // Returns scale factor to restore the original textSize, since will will
1765 // have change it to kCanonicalTextSizeForPaths.
1766 SkScalar setupForAsPaths();
1767
Mike Reedd5bee5d2017-06-01 14:45:44 -04001768 static SkScalar MaxCacheSize2();
reed@google.comed43dff2013-06-04 16:56:27 +00001769
vandebo@chromium.org28be72b2010-11-11 21:37:00 +00001770 friend class SkAutoGlyphCache;
jvanverth2d2a68c2014-06-10 06:42:56 -07001771 friend class SkAutoGlyphCacheNoGamma;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001772 friend class SkCanvas;
1773 friend class SkDraw;
vandebo@chromium.org28be72b2010-11-11 21:37:00 +00001774 friend class SkPDFDevice;
joshualitte76b4bb2015-12-28 07:23:58 -08001775 friend class GrAtlasTextBlob;
joshualittdbd35932015-04-02 09:19:04 -07001776 friend class GrAtlasTextContext;
kkinnunenc6cb56f2014-06-24 00:12:27 -07001777 friend class GrStencilAndCoverTextContext;
cdalton855d83f2014-09-18 13:51:53 -07001778 friend class GrPathRendering;
joshualitt0a42e682015-12-10 13:20:58 -08001779 friend class GrTextUtils;
cdalton855d83f2014-09-18 13:51:53 -07001780 friend class GrGLPathRendering;
joshualitt9e36c1a2015-04-14 12:17:27 -07001781 friend class SkScalerContext;
caryclark0449bcf2016-02-09 13:25:45 -08001782 friend class SkTextBaseIter;
reed@google.comed43dff2013-06-04 16:56:27 +00001783 friend class SkCanonicalizePaint;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001784};
1785
reed@android.com8a1c16f2008-12-17 15:59:43 +00001786#endif