reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef SkPaint_DEFINED |
| 9 | #define SkPaint_DEFINED |
| 10 | |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 11 | #include "SkBlendMode.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 12 | #include "SkColor.h" |
reed | f803da1 | 2015-01-23 05:58:07 -0800 | [diff] [blame] | 13 | #include "SkFilterQuality.h" |
reed@google.com | ed43dff | 2013-06-04 16:56:27 +0000 | [diff] [blame] | 14 | #include "SkMatrix.h" |
Mike Reed | 71fecc3 | 2016-11-18 17:19:54 -0500 | [diff] [blame] | 15 | #include "SkRefCnt.h" |
reed@android.com | a0f5d15 | 2009-06-22 17:38:10 +0000 | [diff] [blame] | 16 | |
joshualitt | 2b6acb4 | 2015-04-01 11:30:27 -0700 | [diff] [blame] | 17 | class SkAutoDescriptor; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 18 | class SkAutoGlyphCache; |
| 19 | class SkColorFilter; |
joshualitt | fd45079 | 2015-03-13 08:38:43 -0700 | [diff] [blame] | 20 | class SkData; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 21 | class SkDescriptor; |
senorblanco | 0abdf76 | 2015-08-20 11:10:41 -0700 | [diff] [blame] | 22 | class SkDrawLooper; |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 23 | class SkReadBuffer; |
| 24 | class SkWriteBuffer; |
herb | b69d0e0 | 2015-02-25 06:47:06 -0800 | [diff] [blame] | 25 | class SkGlyph; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 26 | struct SkRect; |
| 27 | class SkGlyphCache; |
reed@google.com | 15356a6 | 2011-11-03 19:29:08 +0000 | [diff] [blame] | 28 | class SkImageFilter; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 29 | class SkMaskFilter; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 30 | class SkPath; |
| 31 | class SkPathEffect; |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 32 | struct SkPoint; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 33 | class SkRasterizer; |
reed | a9322c2 | 2016-04-12 06:47:05 -0700 | [diff] [blame] | 34 | struct SkScalerContextEffects; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 35 | class SkShader; |
robertphillips | fcf7829 | 2015-06-19 11:49:52 -0700 | [diff] [blame] | 36 | class SkSurfaceProps; |
fmalita | eae6a91 | 2016-07-28 09:47:24 -0700 | [diff] [blame] | 37 | class SkTextBlob; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 38 | class SkTypeface; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 39 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 40 | /** \class SkPaint |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 41 | SkPaint controls options applied when drawing and measuring. SkPaint collects all |
| 42 | options outside of the SkCanvas clip and SkCanvas matrix. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 43 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 44 | 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 |
| 51 | pipeline and multiple pipeline stages may be effected by a single SkPaint. |
| 52 | |
| 53 | SkPaint collects effect and filters that describe single-pass and multiple-pass |
| 54 | 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 |
| 60 | SkPath geometries with anti-aliasing, regardless of SkPaint::kAntiAlias_Flag setting. |
| 61 | |
| 62 | SkPaint describes a single color, a single font, a single image quality, and so on. |
| 63 | Multiple colors are drawn either by using multiple paints or with objects like |
| 64 | SkShader attached to SkPaint. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 65 | */ |
ctguil@chromium.org | 7ffb1b2 | 2011-03-15 21:27:08 +0000 | [diff] [blame] | 66 | class SK_API SkPaint { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 67 | public: |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 68 | |
| 69 | /** Constructs SkPaint with default values. |
| 70 | |
| 71 | @return default initialized SkPaint |
| 72 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 73 | SkPaint(); |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 74 | |
| 75 | /** Makes a shallow copy of SkPaint. SkTypeface, SkPathEffect, SkShader, |
| 76 | SkMaskFilter, SkColorFilter, SkRasterizer, SkDrawLooper, and SkImageFilter are shared |
| 77 | between the original paint and the copy. These objects' SkRefCnt are increased. |
| 78 | |
| 79 | The referenced objects SkPathEffect, SkShader, SkMaskFilter, SkColorFilter, SkRasterizer, |
| 80 | SkDrawLooper, and SkImageFilter cannot be modified after they are created. |
| 81 | This prevents objects with SkRefCnt from being modified once SkPaint refers to them. |
| 82 | |
| 83 | @param paint original to copy |
| 84 | @return shallow copy of paint |
| 85 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 86 | SkPaint(const SkPaint& paint); |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 87 | |
| 88 | /** Implements a move constructor to avoid incrementing the reference counts |
| 89 | of objects referenced by the paint. |
| 90 | |
| 91 | After the call, paint is undefined, and can be safely destructed. |
| 92 | |
| 93 | @param paint original to move |
| 94 | @return content of paint |
| 95 | */ |
bungeman | ccce0e0 | 2016-02-07 14:37:23 -0800 | [diff] [blame] | 96 | SkPaint(SkPaint&& paint); |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 97 | |
| 98 | /** Decreases SkPaint SkRefCnt of owned objects: SkTypeface, SkPathEffect, SkShader, |
| 99 | SkMaskFilter, SkColorFilter, SkRasterizer, SkDrawLooper, and SkImageFilter. If the |
| 100 | objects' reference count goes to zero, they are deleted. |
| 101 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 102 | ~SkPaint(); |
| 103 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 104 | /** Makes a shallow copy of SkPaint. SkTypeface, SkPathEffect, SkShader, |
| 105 | SkMaskFilter, SkColorFilter, SkRasterizer, SkDrawLooper, and SkImageFilter are shared |
| 106 | between the original paint and the copy. The objects' SkRefCnt are in the |
| 107 | prior destination are decreased by one, and the referenced objects are deleted if the |
| 108 | resulting count is zero. The objects' SkRefCnt in the parameter paint are increased |
| 109 | by one. paint is unmodified. |
| 110 | |
| 111 | @param paint original to copy |
| 112 | @return content of paint |
| 113 | */ |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 114 | SkPaint& operator=(const SkPaint& paint); |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 115 | |
| 116 | /** Moves the paint to avoid incrementing the reference counts |
| 117 | of objects referenced by the paint parameter. The objects' SkRefCnt are in the |
| 118 | prior destination are decreased by one, and the referenced objects are deleted if the |
| 119 | resulting count is zero. |
| 120 | |
| 121 | After the call, paint is undefined, and can be safely destructed. |
| 122 | |
| 123 | @param paint original to move |
| 124 | @return content of paint |
| 125 | */ |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 126 | SkPaint& operator=(SkPaint&& paint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 127 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 128 | /** Compares a and b, and returns true if a and b are equivalent. May return false |
| 129 | if SkTypeface, SkPathEffect, SkShader, SkMaskFilter, SkColorFilter, SkRasterizer, |
| 130 | SkDrawLooper, or SkImageFilter have identical contents but different pointers. |
| 131 | |
| 132 | @param a SkPaint to compare |
| 133 | @param b SkPaint to compare |
| 134 | @return true if SkPaint pair are equivalent |
mtklein | bc97ef4 | 2014-08-25 10:10:47 -0700 | [diff] [blame] | 135 | */ |
robertphillips@google.com | b265741 | 2013-08-07 22:36:29 +0000 | [diff] [blame] | 136 | SK_API friend bool operator==(const SkPaint& a, const SkPaint& b); |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 137 | |
| 138 | /** Compares a and b, and returns true if a and b are not equivalent. May return true |
| 139 | if SkTypeface, SkPathEffect, SkShader, SkMaskFilter, SkColorFilter, SkRasterizer, |
| 140 | SkDrawLooper, or SkImageFilter have identical contents but different pointers. |
| 141 | |
| 142 | @param a SkPaint to compare |
| 143 | @param b SkPaint to compare |
| 144 | @return true if SkPaint pair are not equivalent |
| 145 | */ |
robertphillips@google.com | b265741 | 2013-08-07 22:36:29 +0000 | [diff] [blame] | 146 | friend bool operator!=(const SkPaint& a, const SkPaint& b) { |
| 147 | return !(a == b); |
| 148 | } |
| 149 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 150 | /** Returns a hash generated from SkPaint values and pointers. |
| 151 | Identical hashes guarantee that the paints are |
| 152 | equivalent, but differing hashes do not guarantee that the paints have differing |
| 153 | contents. |
| 154 | |
| 155 | If operator==(const SkPaint& a, const SkPaint& b) returns true for two paints, |
| 156 | their hashes are also equal. |
| 157 | |
| 158 | The hash returned is platform and implementation specific. |
| 159 | |
| 160 | @return a shallow hash |
| 161 | */ |
mtklein | fb1fe4f | 2014-10-07 09:26:10 -0700 | [diff] [blame] | 162 | uint32_t getHash() const; |
| 163 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 164 | /** Serializes SkPaint into a buffer. A companion unflatten() call |
| 165 | can reconstitute the paint at a later time. |
| 166 | |
| 167 | @param buffer SkWriteBuffer receiving the flattened SkPaint data |
| 168 | */ |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 169 | void flatten(SkWriteBuffer& buffer) const; |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 170 | |
| 171 | /** Populates SkPaint, typically from a serialized stream, created by calling |
| 172 | flatten() at an earlier time. |
| 173 | |
| 174 | SkReadBuffer class is not public, so unflatten() cannot be meaningfully called |
| 175 | by the client. |
| 176 | |
| 177 | @param buffer serialized data to unflatten |
| 178 | */ |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 179 | void unflatten(SkReadBuffer& buffer); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 180 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 181 | /** Sets all paint's contents to their initial values. This is equivalent to replacing |
| 182 | the paint with the result of SkPaint(). |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 183 | */ |
| 184 | void reset(); |
| 185 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 186 | /** \enum SkPaint::Hinting |
| 187 | Hinting adjusts the glyph outlines so that the shape provides a uniform |
| 188 | look at a given point size on font engines that support it. Hinting may have a |
| 189 | muted effect or no effect at all depending on the platform. |
| 190 | |
| 191 | The four levels roughly control corresponding features on platforms that use FreeType |
| 192 | as the font engine. |
agl@chromium.org | 309485b | 2009-07-21 17:41:32 +0000 | [diff] [blame] | 193 | */ |
| 194 | enum Hinting { |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 195 | /** Leaves glyph outlines unchanged from their native representation. |
| 196 | With FreeType, this is equivalent to the FT_LOAD_NO_HINTING |
| 197 | bit-field constant supplied to FT_Load_Glyph, which indicates that the vector |
| 198 | outline being loaded should not be fitted to the pixel grid but simply scaled |
| 199 | to 26.6 fractional pixels. |
| 200 | */ |
| 201 | kNo_Hinting = 0, |
| 202 | |
| 203 | /** Modifies glyph outlines minimally to improve constrast. |
| 204 | With FreeType, this is equivalent in spirit to the |
| 205 | FT_LOAD_TARGET_LIGHT value supplied to FT_Load_Glyph. It chooses a |
| 206 | lighter hinting algorithm for non-monochrome modes. |
| 207 | Generated glyphs may be fuzzy but better resemble their original shape. |
| 208 | */ |
| 209 | kSlight_Hinting = 1, |
| 210 | |
| 211 | /** Modifies glyph outlines to improve constrast. This is the default. |
| 212 | With FreeType, this supplies FT_LOAD_TARGET_NORMAL to FT_Load_Glyph, |
| 213 | choosing the default hinting algorithm, which is optimized for standard |
| 214 | gray-level rendering. |
| 215 | */ |
| 216 | kNormal_Hinting = 2, |
| 217 | |
| 218 | /** Modifies glyph outlines for maxiumum constrast. With FreeType, this selects |
| 219 | FT_LOAD_TARGET_LCD or FT_LOAD_TARGET_LCD_V if kLCDRenderText_Flag is set. |
| 220 | FT_LOAD_TARGET_LCD is a variant of FT_LOAD_TARGET_NORMAL optimized for |
| 221 | horizontally decimated LCD displays; FT_LOAD_TARGET_LCD_V is a |
| 222 | variant of FT_LOAD_TARGET_NORMAL optimized for vertically decimated LCD displays. |
| 223 | */ |
| 224 | kFull_Hinting = 3, |
agl@chromium.org | 309485b | 2009-07-21 17:41:32 +0000 | [diff] [blame] | 225 | }; |
| 226 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 227 | /** Returns level of glyph outline adjustment. |
| 228 | |
| 229 | @return one of: kNo_Hinting, kSlight_Hinting, kNormal_Hinting, kFull_Hinting |
| 230 | */ |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 231 | Hinting getHinting() const { |
reed | f59eab2 | 2014-07-14 14:39:15 -0700 | [diff] [blame] | 232 | return static_cast<Hinting>(fBitfields.fHinting); |
agl@chromium.org | 309485b | 2009-07-21 17:41:32 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 235 | /** Sets level of glyph outline adjustment. |
| 236 | Does not check for valid values of hintingLevel. |
| 237 | |
| 238 | @param hintingLevel one of: kNo_Hinting, kSlight_Hinting, kNormal_Hinting, kFull_Hinting |
| 239 | */ |
djsollen@google.com | f5dbe2f | 2011-04-15 13:41:26 +0000 | [diff] [blame] | 240 | void setHinting(Hinting hintingLevel); |
agl@chromium.org | 309485b | 2009-07-21 17:41:32 +0000 | [diff] [blame] | 241 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 242 | /** \enum SkPaint::Flags |
| 243 | The bit values stored in Flags. |
| 244 | The default value for Flags, normally zero, can be changed at compile time |
| 245 | with a custom definition of SkPaintDefaults_Flags. |
| 246 | All flags can be read and written explicitly; Flags allows manipulating |
| 247 | multiple settings at once. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 248 | */ |
| 249 | enum Flags { |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 250 | kAntiAlias_Flag = 0x01, //!< mask for setting Anti-alias |
| 251 | kDither_Flag = 0x04, //!< mask for setting Dither |
| 252 | kFakeBoldText_Flag = 0x20, //!< mask for setting fake bold |
| 253 | kLinearText_Flag = 0x40, //!< mask for setting linear text |
| 254 | kSubpixelText_Flag = 0x80, //!< mask for setting subpixel text |
| 255 | kDevKernText_Flag = 0x100, //!< mask for setting full hinting spacing |
| 256 | kLCDRenderText_Flag = 0x200, //!< mask for setting lcd text |
| 257 | kEmbeddedBitmapText_Flag = 0x400, //!< mask for setting font embedded bitmaps |
| 258 | kAutoHinting_Flag = 0x800, //!< mask for setting auto-hinting |
| 259 | kVerticalText_Flag = 0x1000, //!< mask for setting vertical text |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 260 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 261 | /** Hack for GDI -- do not use if you can help it */ |
| 262 | kGenA8FromLCD_Flag = 0x2000, |
| 263 | |
| 264 | /** mask of all Flags, including private flags and flags reserved for future use */ |
| 265 | kAllFlags = 0xFFFF, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 266 | }; |
| 267 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 268 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
Mike Reed | ddbd37e | 2017-02-21 15:07:44 -0500 | [diff] [blame] | 269 | enum ReserveFlags { |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 270 | kUnderlineText_ReserveFlag = 0x08, //!< mask for underline text |
| 271 | kStrikeThruText_ReserveFlag = 0x10, //!< mask for strike-thru text |
Mike Reed | ddbd37e | 2017-02-21 15:07:44 -0500 | [diff] [blame] | 272 | }; |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 273 | #endif |
Mike Reed | ddbd37e | 2017-02-21 15:07:44 -0500 | [diff] [blame] | 274 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 275 | /** Returns paint settings described by SkPaint::Flags. Each setting uses one |
| 276 | bit, and can be tested with SkPaint::Flags members. |
| 277 | |
| 278 | @return zero, one, or more bits described by SkPaint::Flags |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 279 | */ |
reed | f59eab2 | 2014-07-14 14:39:15 -0700 | [diff] [blame] | 280 | uint32_t getFlags() const { return fBitfields.fFlags; } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 281 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 282 | /** Sets SkPaint::Flags to the union of the SkPaint::Flags members. |
| 283 | |
| 284 | @param flags union of SkPaint::Flags for SkPaint |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 285 | */ |
| 286 | void setFlags(uint32_t flags); |
| 287 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 288 | /** If true, pixels on the active edges of SkPath may be drawn with partial transparency. |
| 289 | |
| 290 | Equivalent to getFlags masked with kAntiAlias_Flag. |
| 291 | |
| 292 | @return kAntiAlias_Flag state |
| 293 | */ |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 294 | bool isAntiAlias() const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 295 | return SkToBool(this->getFlags() & kAntiAlias_Flag); |
| 296 | } |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 297 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 298 | /** Requests, but does not require, that SkPath edge pixels draw opaque or with |
| 299 | partial transparency. |
| 300 | |
| 301 | Sets kAntiAlias_Flag if aa is true. |
| 302 | Clears kAntiAlias_Flag if aa is false. |
| 303 | |
| 304 | @param aa setting for kAntiAlias_Flag |
| 305 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 306 | void setAntiAlias(bool aa); |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 307 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 308 | /** If true, color error may be distributed to smooth color transition. |
| 309 | |
| 310 | Equivalent to getFlags masked with kDither_Flag. |
| 311 | |
| 312 | @return kDither_Flag state |
| 313 | */ |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 314 | bool isDither() const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 315 | return SkToBool(this->getFlags() & kDither_Flag); |
| 316 | } |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 317 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 318 | /** Requests, but does not require, to distribute color error. |
| 319 | |
| 320 | Sets kDither_Flag if dither is true. |
| 321 | Clears kDither_Flag if dither is false. |
| 322 | |
| 323 | @param dither setting for kDither_Flag |
| 324 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 325 | void setDither(bool dither); |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 326 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 327 | /** If true, text is converted to SkPath before drawing and measuring. |
| 328 | |
| 329 | Equivalent to getFlags masked with kLinearText_Flag. |
| 330 | |
| 331 | @return kLinearText_Flag state |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 332 | */ |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 333 | bool isLinearText() const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 334 | return SkToBool(this->getFlags() & kLinearText_Flag); |
| 335 | } |
| 336 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 337 | /** If true, text is converted to SkPath before drawing and measuring. |
| 338 | By default, kLinearText_Flag is clear. |
| 339 | |
| 340 | Sets kLinearText_Flag if linearText is true. |
| 341 | Clears kLinearText_Flag if linearText is false. |
| 342 | |
| 343 | @param linearText setting for kLinearText_Flag |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 344 | */ |
| 345 | void setLinearText(bool linearText); |
| 346 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 347 | /** If true, glyphs at different sub-pixel positions may differ on pixel edge coverage. |
| 348 | |
| 349 | Equivalent to getFlags masked with kSubpixelText_Flag. |
| 350 | |
| 351 | @return kSubpixelText_Flag state |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 352 | */ |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 353 | bool isSubpixelText() const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 354 | return SkToBool(this->getFlags() & kSubpixelText_Flag); |
| 355 | } |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 356 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 357 | /** Requests, but does not require, that glyphs respect sub-pixel positioning. |
| 358 | |
| 359 | Sets kSubpixelText_Flag if subpixelText is true. |
| 360 | Clears kSubpixelText_Flag if subpixelText is false. |
| 361 | |
| 362 | @param subpixelText setting for kSubpixelText_Flag |
| 363 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 364 | void setSubpixelText(bool subpixelText); |
agl@chromium.org | 309485b | 2009-07-21 17:41:32 +0000 | [diff] [blame] | 365 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 366 | /** If true, glyphs may use LCD striping to improve glyph edges. |
| 367 | |
| 368 | Returns true if SkPaint::Flags kLCDRenderText_Flag is set. |
| 369 | |
| 370 | @return kLCDRenderText_Flag state |
| 371 | */ |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 372 | bool isLCDRenderText() const { |
agl@chromium.org | 309485b | 2009-07-21 17:41:32 +0000 | [diff] [blame] | 373 | return SkToBool(this->getFlags() & kLCDRenderText_Flag); |
| 374 | } |
| 375 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 376 | /** Requests, but does not require, that glyphs use LCD striping for glyph edges. |
| 377 | |
| 378 | Sets kLCDRenderText_Flag if lcdText is true. |
| 379 | Clears kLCDRenderText_Flag if lcdText is false. |
| 380 | |
| 381 | @param lcdText setting for kLCDRenderText_Flag |
| 382 | */ |
reed@google.com | 84b437e | 2011-08-01 12:45:35 +0000 | [diff] [blame] | 383 | void setLCDRenderText(bool lcdText); |
agl@chromium.org | 309485b | 2009-07-21 17:41:32 +0000 | [diff] [blame] | 384 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 385 | /** If true, font engine may return glyphs from font bitmaps instead of from outlines. |
| 386 | |
| 387 | Equivalent to getFlags masked with kEmbeddedBitmapText_Flag. |
| 388 | |
| 389 | @return kEmbeddedBitmapText_Flag state |
| 390 | */ |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 391 | bool isEmbeddedBitmapText() const { |
agl@chromium.org | e95c91e | 2010-01-04 18:27:55 +0000 | [diff] [blame] | 392 | return SkToBool(this->getFlags() & kEmbeddedBitmapText_Flag); |
| 393 | } |
| 394 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 395 | /** Requests, but does not require, to use bitmaps in fonts instead of outlines. |
| 396 | |
| 397 | Sets kEmbeddedBitmapText_Flag if useEmbeddedBitmapText is true. |
| 398 | Clears kEmbeddedBitmapText_Flag if useEmbeddedBitmapText is false. |
| 399 | |
| 400 | @param useEmbeddedBitmapText setting for kEmbeddedBitmapText_Flag |
agl@chromium.org | e95c91e | 2010-01-04 18:27:55 +0000 | [diff] [blame] | 401 | */ |
| 402 | void setEmbeddedBitmapText(bool useEmbeddedBitmapText); |
| 403 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 404 | /** If true, and if SkPaint::Hinting is set to kNormal_Hinting or kFull_Hinting, and if |
| 405 | platform uses FreeType as the font manager, instruct the font manager to always hint |
| 406 | Glyphs. |
| 407 | |
| 408 | Equivalent to getFlags masked with kAutoHinting_Flag. |
| 409 | |
| 410 | @return kAutoHinting_Flag state |
| 411 | */ |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 412 | bool isAutohinted() const { |
agl@chromium.org | a2c71cb | 2010-06-17 20:49:17 +0000 | [diff] [blame] | 413 | return SkToBool(this->getFlags() & kAutoHinting_Flag); |
| 414 | } |
| 415 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 416 | /** If SkPaint::Hinting is set to kNormal_Hinting or kFull_Hinting and useAutohinter is set, |
| 417 | instruct the font manager to always hint Glyphs. |
| 418 | auto-hinting has no effect if SkPaint::Hinting is set to kNo_Hinting or |
| 419 | kSlight_Hinting. |
| 420 | |
| 421 | setAutohinted only effects platforms that use FreeType as the font manager. |
| 422 | |
| 423 | Sets kAutoHinting_Flag if useAutohinter is true. |
| 424 | Clears kAutoHinting_Flag if useAutohinter is false. |
| 425 | |
| 426 | @param useAutohinter setting for kAutoHinting_Flag |
agl@chromium.org | a2c71cb | 2010-06-17 20:49:17 +0000 | [diff] [blame] | 427 | */ |
| 428 | void setAutohinted(bool useAutohinter); |
| 429 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 430 | /** If true, glyphs are drawn top to bottom instead of left to right. |
| 431 | |
| 432 | Equivalent to getFlags masked with kVerticalText_Flag. |
| 433 | |
| 434 | @return kVerticalText_Flag state |
| 435 | */ |
reed@google.com | 830a23e | 2011-11-10 15:20:49 +0000 | [diff] [blame] | 436 | bool isVerticalText() const { |
| 437 | return SkToBool(this->getFlags() & kVerticalText_Flag); |
| 438 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 439 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 440 | /** If true, text advance positions the next glyph below the previous glyph instead of to the |
| 441 | right of previous glyph. |
| 442 | |
| 443 | Sets kVerticalText_Flag if vertical is true. |
| 444 | Clears kVerticalText_Flag if vertical is false. |
| 445 | |
| 446 | @param verticalText setting for kVerticalText_Flag |
| 447 | */ |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 448 | void setVerticalText(bool verticalText); |
reed@google.com | 830a23e | 2011-11-10 15:20:49 +0000 | [diff] [blame] | 449 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 450 | /** If true, approximate bold by increasing the stroke width when creating glyph bitmaps |
| 451 | from outlines. |
| 452 | |
| 453 | Equivalent to getFlags masked with kFakeBoldText_Flag. |
| 454 | |
| 455 | @return kFakeBoldText_Flag state |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 456 | */ |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 457 | bool isFakeBoldText() const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 458 | return SkToBool(this->getFlags() & kFakeBoldText_Flag); |
| 459 | } |
| 460 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 461 | /** Use increased stroke width when creating glyph bitmaps to approximate bolding. |
| 462 | |
| 463 | Sets kFakeBoldText_Flag if fakeBoldText is true. |
| 464 | Clears kFakeBoldText_Flag if fakeBoldText is false. |
| 465 | |
| 466 | @param fakeBoldText setting for kFakeBoldText_Flag |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 467 | */ |
| 468 | void setFakeBoldText(bool fakeBoldText); |
| 469 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 470 | /** Returns if character spacing may be adjusted by the hinting difference. |
| 471 | |
| 472 | Equivalent to getFlags masked with kDevKernText_Flag. |
| 473 | |
| 474 | @return kDevKernText_Flag state |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 475 | */ |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 476 | bool isDevKernText() const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 477 | return SkToBool(this->getFlags() & kDevKernText_Flag); |
| 478 | } |
| 479 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 480 | /** Requests, but does not require, to use hinting to adjust glyph spacing. |
| 481 | |
| 482 | Sets kDevKernText_Flag if devKernText is true. |
| 483 | Clears kDevKernText_Flag if devKernText is false. |
| 484 | |
| 485 | @param devKernText setting for devKernText |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 486 | */ |
| 487 | void setDevKernText(bool devKernText); |
| 488 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 489 | /** Returns SkFilterQuality, the image filtering level. A lower setting |
| 490 | draws faster; a higher setting looks better when the image is scaled. |
| 491 | |
| 492 | @return one of: kNone_SkFilterQuality, kLow_SkFilterQuality, |
| 493 | kMedium_SkFilterQuality, kHigh_SkFilterQuality |
| 494 | */ |
reed | f803da1 | 2015-01-23 05:58:07 -0800 | [diff] [blame] | 495 | SkFilterQuality getFilterQuality() const { |
| 496 | return (SkFilterQuality)fBitfields.fFilterQuality; |
| 497 | } |
mtklein | fe81e2d | 2015-09-09 07:35:42 -0700 | [diff] [blame] | 498 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 499 | /** Sets or clears SkFilterQuality, the image filtering level. A lower setting |
| 500 | draws faster; a higher setting looks better when the image is scaled. |
| 501 | setFilterQuality does not check to see if quality is valid. |
| 502 | |
| 503 | @param quality one of: kNone_SkFilterQuality, kLow_SkFilterQuality, |
| 504 | kMedium_SkFilterQuality, kHigh_SkFilterQuality |
| 505 | */ |
reed | f803da1 | 2015-01-23 05:58:07 -0800 | [diff] [blame] | 506 | void setFilterQuality(SkFilterQuality quality); |
reed@google.com | c968315 | 2013-07-18 13:47:01 +0000 | [diff] [blame] | 507 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 508 | /** \enum SkPaint::Style |
| 509 | Set Style to kStrokeAndFill_Style to fill, stroke, or both fill and stroke geometry. |
| 510 | The stroke and fill |
| 511 | share all paint attributes; for instance, they are drawn with the same color. |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 512 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 513 | Use kStrokeAndFill_Style to avoid hitting the same pixels twice with a stroke draw and |
| 514 | a fill draw. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 515 | */ |
| 516 | enum Style { |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 517 | /** Set to fill geometry. |
| 518 | Applies to SkRect, SkRegion, SkRRect, circles, ovals, SkPath, and Text. |
| 519 | SkBitmap, SkImage, patches, SkRegion, sprites, and vertices are painted as if |
| 520 | kFill_Style is set, and ignore the set Style. |
| 521 | The FillType specifies additional rules to fill the area outside the path edge, |
| 522 | and to create an unfilled hole inside the shape. |
| 523 | Style is set to kFill_Style by default. |
| 524 | */ |
| 525 | kFill_Style, |
| 526 | |
| 527 | /** Set to stroke geometry. |
| 528 | Applies to SkRect, SkRegion, SkRRect, arcs, circles, ovals, |
| 529 | SkPath, and Text. |
| 530 | arcs, lines, SkPoint, and SkPoint arrays are always drawn as if kStroke_Style is set, |
| 531 | and ignore the set Style. |
| 532 | The stroke construction is unaffected by the FillType. |
| 533 | */ |
| 534 | kStroke_Style, |
| 535 | |
| 536 | /** Set to stroke and fill geometry. |
| 537 | Applies to SkRect, SkRegion, SkRRect, circles, ovals, SkPath, and Text. |
| 538 | SkPath is treated as if it is set to SkPath::kWinding_FillType, |
| 539 | and the set FillType is ignored. |
| 540 | */ |
| 541 | kStrokeAndFill_Style, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 542 | }; |
| 543 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 544 | enum { |
| 545 | /** The number of different Style values defined. |
| 546 | May be used to verify that Style is a legal value. |
| 547 | */ |
| 548 | kStyleCount = kStrokeAndFill_Style + 1, |
| 549 | }; |
| 550 | |
| 551 | /** Whether the geometry is filled, stroked, or filled and stroked. |
| 552 | |
| 553 | @return one of:kFill_Style, kStroke_Style, kStrokeAndFill_Style |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 554 | */ |
reed | f59eab2 | 2014-07-14 14:39:15 -0700 | [diff] [blame] | 555 | Style getStyle() const { return (Style)fBitfields.fStyle; } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 556 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 557 | /** Sets whether the geometry is filled, stroked, or filled and stroked. |
| 558 | Has no effect if style is not a legal SkPaint::Style value. |
| 559 | |
| 560 | @param style one of: kFill_Style, kStroke_Style, kStrokeAndFill_Style |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 561 | */ |
| 562 | void setStyle(Style style); |
| 563 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 564 | /** Retrieves alpha and RGB, unpremultiplied, packed into 32 bits. |
| 565 | Use helpers SkColorGetA(), SkColorGetR(), SkColorGetG(), and SkColorGetB() to extract |
| 566 | a color component. |
| 567 | |
| 568 | @return Unpremultiplied ARGB |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 569 | */ |
| 570 | SkColor getColor() const { return fColor; } |
| 571 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 572 | /** Sets alpha and RGB used when stroking and filling. The color is a 32-bit value, |
| 573 | unpremutiplied, packing 8-bit components for alpha, red, blue, and green. |
| 574 | |
| 575 | @param color Unpremultiplied ARGB |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 576 | */ |
| 577 | void setColor(SkColor color); |
| 578 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 579 | /** Retrieves alpha from the Color used when stroking and filling. |
| 580 | |
| 581 | @return alpha ranging from zero, fully transparent, to 255, fully opaque |
| 582 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 583 | uint8_t getAlpha() const { return SkToU8(SkColorGetA(fColor)); } |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 584 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 585 | /** Replaces alpha, leaving RGB |
| 586 | unchanged. An out of range value triggers an assert in the debug |
| 587 | build. a is a value from zero to 255. |
| 588 | a set to zero makes Color fully transparent; a set to 255 makes Color |
| 589 | fully opaque. |
| 590 | |
| 591 | @param a alpha component of Color |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 592 | */ |
| 593 | void setAlpha(U8CPU a); |
| 594 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 595 | /** Sets Color used when drawing solid fills. The color components range from 0 to 255. |
| 596 | The color is unpremultiplied; |
| 597 | alpha sets the transparency independent of RGB. |
| 598 | |
| 599 | @param a amount of alpha, from fully transparent (0) to fully opaque (255) |
| 600 | @param r amount of red, from no red (0) to full red (255) |
| 601 | @param g amount of green, from no green (0) to full green (255) |
| 602 | @param b amount of blue, from no blue (0) to full blue (255) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 603 | */ |
| 604 | void setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b); |
| 605 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 606 | /** Returns the thickness of the pen used by SkPaint to |
| 607 | outline the shape. |
| 608 | |
| 609 | @return zero for Hairline, greater than zero for pen thickness |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 610 | */ |
| 611 | SkScalar getStrokeWidth() const { return fWidth; } |
| 612 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 613 | /** Sets the thickness of the pen used by the paint to |
| 614 | outline the shape. |
| 615 | Has no effect if width is less than zero. |
| 616 | |
| 617 | @param width zero thickness for Hairline; greater than zero for pen thickness |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 618 | */ |
| 619 | void setStrokeWidth(SkScalar width); |
| 620 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 621 | /** The limit at which a sharp corner is drawn beveled. |
| 622 | |
| 623 | @return zero and greater miter limit |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 624 | */ |
| 625 | SkScalar getStrokeMiter() const { return fMiterLimit; } |
| 626 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 627 | /** The limit at which a sharp corner is drawn beveled. |
| 628 | Valid values are zero and greater. |
| 629 | Has no effect if miter is less than zero. |
| 630 | |
| 631 | @param miter zero and greater miter limit |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 632 | */ |
| 633 | void setStrokeMiter(SkScalar miter); |
| 634 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 635 | /** \enum SkPaint::Cap |
| 636 | Cap draws at the beginning and end of an open path contour. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 637 | */ |
| 638 | enum Cap { |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 639 | kButt_Cap, //!< Does not extend the stroke past the beginning or the end. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 640 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 641 | /** Adds a circle with a diameter equal to stroke width at the beginning |
| 642 | and end. |
| 643 | */ |
| 644 | kRound_Cap, |
| 645 | |
| 646 | /** Adds a square with sides equal to stroke width at the beginning |
| 647 | and end. The square sides are parallel to the initial and final direction |
| 648 | of the stroke. |
| 649 | */ |
| 650 | kSquare_Cap, |
| 651 | kLast_Cap = kSquare_Cap, //!< Equivalent to the largest value for Cap. |
| 652 | |
| 653 | /** Equivalent to kButt_Cap. |
| 654 | Cap is set to kButt_Cap by default. |
| 655 | */ |
| 656 | kDefault_Cap = kButt_Cap, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 657 | }; |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 658 | |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 659 | static constexpr int kCapCount = kLast_Cap + 1; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 660 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 661 | /** \enum SkPaint::Join |
| 662 | Join specifies how corners are drawn when a shape is stroked. The paint's Join setting |
| 663 | affects the four corners of a stroked rectangle, and the connected segments in a |
| 664 | stroked path. |
| 665 | |
| 666 | Choose miter join to draw sharp corners. Choose round join to draw a circle with a |
| 667 | radius equal to the stroke width on top of the corner. Choose bevel join to minimally |
| 668 | connect the thick strokes. |
| 669 | |
| 670 | The fill path constructed to describe the stroked path respects the join setting but may |
| 671 | not contain the actual join. For instance, a fill path constructed with round joins does |
| 672 | not necessarily include circles at each connected segment. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 673 | */ |
| 674 | enum Join { |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 675 | /** Extends the outside of the to the extent allowed by miter limit. |
| 676 | If the extension exceeds miter limit, kBevel_Join is used instead. |
| 677 | */ |
| 678 | kMiter_Join, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 679 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 680 | /** Adds a circle with a diameter of stroke width at the sharp corner. */ |
| 681 | kRound_Join, |
| 682 | kBevel_Join, //!< Connects the outside edges of the sharp corner. |
| 683 | kLast_Join = kBevel_Join, //!< Equivalent to the largest value for Join. |
| 684 | |
| 685 | /** Equivalent to kMiter_Join. |
| 686 | Join is set to kMiter_Join by default. |
| 687 | */ |
| 688 | kDefault_Join = kMiter_Join, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 689 | }; |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 690 | |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 691 | static constexpr int kJoinCount = kLast_Join + 1; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 692 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 693 | /** The geometry drawn at the beginning and end of strokes. |
| 694 | |
| 695 | @return one of: kButt_Cap, kRound_Cap, kSquare_Cap |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 696 | */ |
reed | f59eab2 | 2014-07-14 14:39:15 -0700 | [diff] [blame] | 697 | Cap getStrokeCap() const { return (Cap)fBitfields.fCapType; } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 698 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 699 | /** The geometry drawn at the beginning and end of strokes. |
| 700 | |
| 701 | @param cap one of: kButt_Cap, kRound_Cap, kSquare_Cap; |
| 702 | has no effect if cap is not valid |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 703 | */ |
| 704 | void setStrokeCap(Cap cap); |
| 705 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 706 | /** The geometry drawn at the corners of strokes. |
| 707 | |
| 708 | @return one of: kMiter_Join, kRound_Join, kBevel_Join |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 709 | */ |
reed | f59eab2 | 2014-07-14 14:39:15 -0700 | [diff] [blame] | 710 | Join getStrokeJoin() const { return (Join)fBitfields.fJoinType; } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 711 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 712 | /** The geometry drawn at the corners of strokes. |
| 713 | |
| 714 | @param join one of: kMiter_Join, kRound_Join, kBevel_Join; |
| 715 | otherwise, setStrokeJoin has no effect |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 716 | */ |
| 717 | void setStrokeJoin(Join join); |
| 718 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 719 | /** The filled equivalent of the stroked path. |
| 720 | |
| 721 | @param src SkPath read to create a filled version |
| 722 | @param dst resulting SkPath; may be the same as src, but may not be nullptr |
| 723 | @param cullRect optional limit passed to SkPathEffect |
| 724 | @param resScale if > 1, increase precision, else if (0 < res < 1) reduce precision |
| 725 | to favor speed and size |
| 726 | @return true if the path represents style fill, or false if it represents Hairline |
| 727 | */ |
reed | 05d9044 | 2015-02-12 13:35:52 -0800 | [diff] [blame] | 728 | bool getFillPath(const SkPath& src, SkPath* dst, const SkRect* cullRect, |
| 729 | SkScalar resScale = 1) const; |
| 730 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 731 | /** The filled equivalent of the stroked path. |
| 732 | |
| 733 | @param src SkPath read to create a filled version |
| 734 | @param dst resulting SkPath; may be the same as src, but may not be nullptr |
| 735 | @param cullRect optional limit passed to SkPathEffect |
| 736 | @param resScale if > 1, increase precision, else if (0 < res < 1) reduce precision |
| 737 | to favor speed and size |
| 738 | @return true if the path represents style fill, or false if it represents Hairline |
| 739 | */ |
reed | 05d9044 | 2015-02-12 13:35:52 -0800 | [diff] [blame] | 740 | bool getFillPath(const SkPath& src, SkPath* dst) const { |
| 741 | return this->getFillPath(src, dst, NULL, 1); |
| 742 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 743 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 744 | /** Optional colors used when filling a path, such as a gradient. |
| 745 | |
| 746 | Does not alter SkShader SkRefCnt. |
| 747 | |
| 748 | @return SkShader if previously set, nullptr otherwise |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 749 | */ |
reed | a5ab9ec | 2016-03-06 18:10:48 -0800 | [diff] [blame] | 750 | SkShader* getShader() const { return fShader.get(); } |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 751 | |
| 752 | /** Optional colors used when filling a path, such as a gradient. |
| 753 | |
| 754 | Increases SkShader SkRefCnt by one. |
| 755 | |
| 756 | @return SkShader if previously set, nullptr otherwise |
| 757 | */ |
Mike Reed | 693fdbd | 2017-01-12 10:13:40 -0500 | [diff] [blame] | 758 | sk_sp<SkShader> refShader() const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 759 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 760 | /** Optional colors used when filling a path, such as a gradient. |
| 761 | |
| 762 | Sets SkShader to shader, decrementing SkRefCnt of the previous SkShader. |
| 763 | Does not alter shader SkRefCnt. |
| 764 | |
| 765 | @param shader how geometry is filled with color; if nullptr, Color is used instead |
| 766 | */ |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 767 | void setShader(sk_sp<SkShader> shader); |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 768 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 769 | /** Returns SkColorFilter if set, or nullptr. |
| 770 | Does not alter SkColorFilter SkRefCnt. |
| 771 | |
| 772 | @return SkColorFilter if previously set, nullptr otherwise |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 773 | */ |
reed | a5ab9ec | 2016-03-06 18:10:48 -0800 | [diff] [blame] | 774 | SkColorFilter* getColorFilter() const { return fColorFilter.get(); } |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 775 | |
| 776 | /** Returns SkColorFilter if set, or nullptr. |
| 777 | Increases SkColorFilter SkRefCnt by one. |
| 778 | |
| 779 | @return SkColorFilter if set, or nullptr |
| 780 | */ |
Mike Reed | 693fdbd | 2017-01-12 10:13:40 -0500 | [diff] [blame] | 781 | sk_sp<SkColorFilter> refColorFilter() const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 782 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 783 | /** Sets SkColorFilter to filter, decrementing SkRefCnt of the previous SkColorFilter. |
| 784 | Pass nullptr to clear SkColorFilter. |
| 785 | Does not alter filter SkRefCnt. |
| 786 | |
| 787 | @param colorFilter SkColorFilter to apply to subsequent draw |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 788 | */ |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 789 | void setColorFilter(sk_sp<SkColorFilter> colorFilter); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 790 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 791 | /** Returns SkBlendMode. |
| 792 | By default, getBlendMode returns SkBlendMode::kSrcOver. |
| 793 | |
| 794 | @return mode used to combine source color with destination color |
| 795 | */ |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 796 | SkBlendMode getBlendMode() const { return (SkBlendMode)fBlendMode; } |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 797 | |
| 798 | /** Returns true if SkBlendMode is SkBlendMode::kSrcOver, the default. |
| 799 | |
| 800 | @return true if SkBlendMode is SkBlendMode::kSrcOver |
| 801 | */ |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 802 | bool isSrcOver() const { return (SkBlendMode)fBlendMode == SkBlendMode::kSrcOver; } |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 803 | |
| 804 | /** Sets SkBlendMode to mode. |
| 805 | Does not check for valid input. |
| 806 | |
| 807 | @param mode SkBlendMode used to combine source color and destination |
| 808 | */ |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 809 | void setBlendMode(SkBlendMode mode) { fBlendMode = (unsigned)mode; } |
reed@android.com | a0f5d15 | 2009-06-22 17:38:10 +0000 | [diff] [blame] | 810 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 811 | /** Returns SkPathEffect if set, or nullptr. |
| 812 | Does not alter SkPathEffect SkRefCnt. |
| 813 | |
| 814 | @return SkPathEffect if previously set, nullptr otherwise |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 815 | */ |
reed | a5ab9ec | 2016-03-06 18:10:48 -0800 | [diff] [blame] | 816 | SkPathEffect* getPathEffect() const { return fPathEffect.get(); } |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 817 | |
| 818 | /** Returns SkPathEffect if set, or nullptr. |
| 819 | Increases SkPathEffect SkRefCnt by one. |
| 820 | |
| 821 | @return SkPathEffect if previously set, nullptr otherwise |
| 822 | */ |
Mike Reed | 693fdbd | 2017-01-12 10:13:40 -0500 | [diff] [blame] | 823 | sk_sp<SkPathEffect> refPathEffect() const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 824 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 825 | /** Sets SkPathEffect to pathEffect, |
| 826 | decrementing SkRefCnt of the previous SkPathEffect. |
| 827 | Pass nullptr to leave the path geometry unaltered. |
| 828 | Does not alter pathEffect SkRefCnt. |
| 829 | |
| 830 | @param pathEffect replace SkPath with a modification when drawn |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 831 | */ |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 832 | void setPathEffect(sk_sp<SkPathEffect> pathEffect); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 833 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 834 | /** Returns SkMaskFilter if set, or nullptr. |
| 835 | Does not alter SkMaskFilter SkRefCnt. |
| 836 | |
| 837 | @return SkMaskFilter if previously set, nullptr otherwise |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 838 | */ |
reed | a5ab9ec | 2016-03-06 18:10:48 -0800 | [diff] [blame] | 839 | SkMaskFilter* getMaskFilter() const { return fMaskFilter.get(); } |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 840 | |
| 841 | /** Returns SkMaskFilter if set, or nullptr. |
| 842 | Increases SkMaskFilter SkRefCnt by one. |
| 843 | |
| 844 | @return SkMaskFilter if previously set, nullptr otherwise |
| 845 | */ |
Mike Reed | 693fdbd | 2017-01-12 10:13:40 -0500 | [diff] [blame] | 846 | sk_sp<SkMaskFilter> refMaskFilter() const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 847 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 848 | /** Sets SkMaskFilter to maskFilter, |
| 849 | decrementing SkRefCnt of the previous SkMaskFilter. |
| 850 | Pass nullptr to clear SkMaskFilter and leave SkMaskFilter effect on mask alpha unaltered. |
| 851 | Does not affect SkRasterizer. |
| 852 | Does not alter maskFilter SkRefCnt. |
| 853 | |
| 854 | @param maskFilter modifies clipping mask generated from drawn geometry |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 855 | */ |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 856 | void setMaskFilter(sk_sp<SkMaskFilter> maskFilter); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 857 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 858 | /** Returns SkTypeface if set, or nullptr. |
| 859 | Does not alter SkTypeface SkRefCnt. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 860 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 861 | @return SkTypeface if previously set, nullptr otherwise |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 862 | */ |
reed | a5ab9ec | 2016-03-06 18:10:48 -0800 | [diff] [blame] | 863 | SkTypeface* getTypeface() const { return fTypeface.get(); } |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 864 | |
| 865 | /** Increases SkTypeface SkRefCnt by one. |
| 866 | |
| 867 | @return SkTypeface if previously set, nullptr otherwise |
| 868 | */ |
Mike Reed | 693fdbd | 2017-01-12 10:13:40 -0500 | [diff] [blame] | 869 | sk_sp<SkTypeface> refTypeface() const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 870 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 871 | /** Sets SkTypeface to typeface, |
| 872 | decrementing SkRefCnt of the previous SkTypeface. |
| 873 | Pass nullptr to clear SkTypeface and use the default typeface. |
| 874 | Does not alter typeface SkRefCnt. |
| 875 | |
| 876 | @param typeface font and style used to draw text |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 877 | */ |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 878 | void setTypeface(sk_sp<SkTypeface> typeface); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 879 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 880 | /** Returns SkRasterizer if set, or nullptr. |
| 881 | Does not alter SkRasterizer SkRefCnt. |
| 882 | |
| 883 | @return SkRasterizer if previously set, nullptr otherwise |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 884 | */ |
reed | a5ab9ec | 2016-03-06 18:10:48 -0800 | [diff] [blame] | 885 | SkRasterizer* getRasterizer() const { return fRasterizer.get(); } |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 886 | |
| 887 | /** refRasterizer() returns SkRasterizer if set, or nullptr. |
| 888 | refRasterizer increases SkRasterizer SkRefCnt by one. |
| 889 | |
| 890 | @return SkRasterizer if previously set, nullptr otherwise |
| 891 | */ |
Mike Reed | 693fdbd | 2017-01-12 10:13:40 -0500 | [diff] [blame] | 892 | sk_sp<SkRasterizer> refRasterizer() const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 893 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 894 | /** Sets SkRasterizer to rasterizer, |
| 895 | decrementing SkRefCnt of the previous SkRasterizer. |
| 896 | Pass nullptr to clear SkRasterizer and leave SkRasterizer effect on mask alpha unaltered. |
| 897 | Does not affect SkMaskFilter. |
| 898 | Does not alter rasterizer SkRefCnt. |
| 899 | |
| 900 | @param rasterizer how geometry is converted to mask alpha |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 901 | */ |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 902 | void setRasterizer(sk_sp<SkRasterizer> rasterizer); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 903 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 904 | /** Returns SkImageFilter if set, or nullptr. |
| 905 | Does not alter SkImageFilter SkRefCnt. |
| 906 | |
| 907 | @return SkImageFilter if previously set, nullptr otherwise |
| 908 | */ |
reed | a5ab9ec | 2016-03-06 18:10:48 -0800 | [diff] [blame] | 909 | SkImageFilter* getImageFilter() const { return fImageFilter.get(); } |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 910 | |
| 911 | /** Returns SkImageFilter if set, or nullptr. |
| 912 | Increases SkImageFilter SkRefCnt by one. |
| 913 | |
| 914 | @return SkImageFilter if previously set, nullptr otherwise |
| 915 | */ |
Mike Reed | 693fdbd | 2017-01-12 10:13:40 -0500 | [diff] [blame] | 916 | sk_sp<SkImageFilter> refImageFilter() const; |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 917 | |
| 918 | /** Sets SkImageFilter to imageFilter, |
| 919 | decrementing SkRefCnt of the previous SkImageFilter. |
| 920 | Pass nullptr to clear SkImageFilter, and remove SkImageFilter effect |
| 921 | on drawing. |
| 922 | Does not affect SkRasterizer or SkMaskFilter. |
| 923 | Does not alter imageFilter SkRefCnt. |
| 924 | |
| 925 | @param imageFilter how SkImage is sampled when transformed |
| 926 | */ |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 927 | void setImageFilter(sk_sp<SkImageFilter> imageFilter); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 928 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 929 | /** Returns SkDrawLooper if set, or nullptr. |
| 930 | Does not alter SkDrawLooper SkRefCnt. |
| 931 | |
| 932 | @return SkDrawLooper if previously set, nullptr otherwise |
| 933 | */ |
reed | 46f2d0a | 2016-09-11 05:40:31 -0700 | [diff] [blame] | 934 | SkDrawLooper* getDrawLooper() const { return fDrawLooper.get(); } |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 935 | |
| 936 | /** Returns SkDrawLooper if set, or nullptr. |
| 937 | Increases SkDrawLooper SkRefCnt by one. |
| 938 | |
| 939 | @return SkDrawLooper if previously set, nullptr otherwise |
| 940 | */ |
Mike Reed | 693fdbd | 2017-01-12 10:13:40 -0500 | [diff] [blame] | 941 | sk_sp<SkDrawLooper> refDrawLooper() const; |
| 942 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 943 | /** (to be deprecated) |
| 944 | |
| 945 | @return SkDrawLooper if previously set, nullptr otherwise |
| 946 | */ |
reed | 46f2d0a | 2016-09-11 05:40:31 -0700 | [diff] [blame] | 947 | SkDrawLooper* getLooper() const { return fDrawLooper.get(); } |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 948 | |
| 949 | /** Sets SkDrawLooper to drawLooper, |
| 950 | decrementing SkRefCnt of the previous drawLooper. |
| 951 | Pass nullptr to clear SkDrawLooper and leave SkDrawLooper effect on drawing unaltered. |
| 952 | setDrawLooper does not alter drawLooper SkRefCnt. |
| 953 | |
| 954 | @param drawLooper Iterates through drawing one or more time, altering SkPaint |
| 955 | */ |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 956 | void setDrawLooper(sk_sp<SkDrawLooper> drawLooper); |
Mike Reed | 09d9435 | 2016-10-31 15:11:04 -0400 | [diff] [blame] | 957 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 958 | /** (to be deprecated) |
| 959 | |
| 960 | @param drawLooper sets SkDrawLooper to drawLooper |
| 961 | */ |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 962 | void setLooper(sk_sp<SkDrawLooper> drawLooper); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 963 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 964 | /** \enum SkPaint::Align |
| 965 | Align adjusts the text relative to the text position. |
| 966 | Align affects glyphs drawn with: SkCanvas::drawText, SkCanvas::drawPosText, |
| 967 | SkCanvas::drawPosTextH, SkCanvas::drawTextOnPath, |
| 968 | SkCanvas::drawTextOnPathHV, SkCanvas::drawTextRSXform, SkCanvas::drawTextBlob, |
| 969 | and SkCanvas::drawString; |
| 970 | as well as calls that place text glyphs like getTextWidths and getTextPath. |
| 971 | |
| 972 | The text position is set by the font for both horizontal and vertical text. |
| 973 | Typically, for horizontal text, the position is to the left side of the glyph on the |
| 974 | base line;and for vertical text, the position is the horizontal center at the glyph |
| 975 | at the caps height. |
| 976 | |
| 977 | Align adjusts the glyph position to center it or move it to abut the position |
| 978 | using the metrics returned by the font. |
| 979 | |
| 980 | Align defaults to kLeft_Align. |
| 981 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 982 | enum Align { |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 983 | /** Leaves the glyph at the position computed by the font offset by the text position. */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 984 | kLeft_Align, |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 985 | |
| 986 | /** Moves the glyph half its width if Flags has kVerticalText_Flag clear, and |
| 987 | half its height if Flags has kVerticalText_Flag set. |
| 988 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 989 | kCenter_Align, |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 990 | |
| 991 | /** Moves the glyph by its width if Flags has kVerticalText_Flag clear, |
| 992 | and by its height if Flags has kVerticalText_Flag set. |
| 993 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 994 | kRight_Align, |
mike@reedtribe.org | ddc813b | 2013-06-08 12:58:19 +0000 | [diff] [blame] | 995 | }; |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 996 | |
mike@reedtribe.org | ddc813b | 2013-06-08 12:58:19 +0000 | [diff] [blame] | 997 | enum { |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 998 | kAlignCount = 3, //!< The number of different Align values defined. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 999 | }; |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 1000 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1001 | /** Returns SkPaint::Align. |
| 1002 | Returns kLeft_Align if SkPaint::Align has not been set. |
| 1003 | |
| 1004 | @return text placement relative to position |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1005 | */ |
reed | f59eab2 | 2014-07-14 14:39:15 -0700 | [diff] [blame] | 1006 | Align getTextAlign() const { return (Align)fBitfields.fTextAlign; } |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 1007 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1008 | /** Sets SkPaint::Align to align. |
| 1009 | Has no effect if align is an invalid value. |
| 1010 | |
| 1011 | @param align text placement relative to position |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1012 | */ |
| 1013 | void setTextAlign(Align align); |
| 1014 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1015 | /** Returns text size in points. |
| 1016 | |
| 1017 | @return typographic height of text |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1018 | */ |
| 1019 | SkScalar getTextSize() const { return fTextSize; } |
| 1020 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1021 | /** Sets text size in points. |
| 1022 | Has no effect if textSize is not greater than or equal to zero. |
| 1023 | |
| 1024 | @param textSize typographic height of text |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1025 | */ |
| 1026 | void setTextSize(SkScalar textSize); |
| 1027 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1028 | /** Returns text scale x. |
| 1029 | Default value is 1. |
| 1030 | |
| 1031 | @return text horizontal scale |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1032 | */ |
| 1033 | SkScalar getTextScaleX() const { return fTextScaleX; } |
| 1034 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1035 | /** Sets text scale x. |
| 1036 | Default value is 1. |
| 1037 | |
| 1038 | @param scaleX text horizontal scale |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1039 | */ |
| 1040 | void setTextScaleX(SkScalar scaleX); |
| 1041 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1042 | /** Returns text skew x. |
| 1043 | Default value is zero. |
| 1044 | |
| 1045 | @return additional shear in x-axis relative to y-axis |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1046 | */ |
| 1047 | SkScalar getTextSkewX() const { return fTextSkewX; } |
| 1048 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1049 | /** Sets text skew x. |
| 1050 | Default value is zero. |
| 1051 | |
| 1052 | @param skewX additional shear in x-axis relative to y-axis |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1053 | */ |
| 1054 | void setTextSkewX(SkScalar skewX); |
| 1055 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1056 | /** \enum SkPaint::TextEncoding |
| 1057 | TextEncoding determines whether text specifies character codes and their encoded size, |
| 1058 | or glyph indices. Character codes use the encoding specified by the Unicode standard . |
| 1059 | Character codes encoded size are specified by UTF-8, UTF-16, or UTF-32. |
| 1060 | All character encoding are able to represent all of Unicode, differing only |
| 1061 | in the total storage required. UTF-8 (RFC 3629) is made up of 8-bit bytes, |
| 1062 | and is a superset of ASCII. UTF-16 (RFC 2781) is made up of 16-bit words, |
| 1063 | and is a superset of Unicode ranges 0x0000 to 0xD7FF and 0xE000 to 0xFFFF. UTF-32 is |
| 1064 | made up of 32-bit words, and is a superset of Unicode. |
| 1065 | |
| 1066 | font manager uses font data to convert character code points into glyph indices. |
| 1067 | A glyph index is a 16-bit word. |
| 1068 | |
| 1069 | TextEncoding is set to kUTF8_TextEncoding by default. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1070 | */ |
| 1071 | enum TextEncoding { |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1072 | kUTF8_TextEncoding, //!< Uses bytes to represent UTF-8 or ASCII. |
| 1073 | kUTF16_TextEncoding, //!< Uses two byte words to represent most of Unicode. |
| 1074 | kUTF32_TextEncoding, //!< Uses four byte words to represent all of Unicode. |
| 1075 | kGlyphID_TextEncoding, //!< Uses two byte words to represent glyph indices. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1076 | }; |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 1077 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1078 | /** Returns SkPaint::TextEncoding. |
| 1079 | SkPaint::TextEncoding determines how character code points are mapped to font glyph indices. |
| 1080 | |
| 1081 | @return one of: kUTF8_TextEncoding, kUTF16_TextEncoding, kUTF32_TextEncoding, or |
| 1082 | kGlyphID_TextEncoding |
| 1083 | */ |
reed | f59eab2 | 2014-07-14 14:39:15 -0700 | [diff] [blame] | 1084 | TextEncoding getTextEncoding() const { |
| 1085 | return (TextEncoding)fBitfields.fTextEncoding; |
| 1086 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1087 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1088 | /** Sets SkPaint::TextEncoding to encoding. |
| 1089 | SkPaint::TextEncoding determines how character code points are mapped to font glyph indices. |
| 1090 | Invalid values for encoding are ignored. |
| 1091 | |
| 1092 | @param encoding one of: kUTF8_TextEncoding, kUTF16_TextEncoding, kUTF32_TextEncoding, or |
| 1093 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1094 | void setTextEncoding(TextEncoding encoding); |
| 1095 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1096 | /** \struct SkPaint::FontMetrics |
| 1097 | FontMetrics is filled out by getFontMetrics. FontMetrics contents reflect the values |
| 1098 | computed by font manager using SkTypeface. Values are set to zero if they are |
| 1099 | not availble. |
| 1100 | |
| 1101 | fUnderlineThickness and fUnderlinePosition have a bit set in fFlags if their values |
| 1102 | are valid, since their value may be zero. |
| 1103 | |
| 1104 | fStrikeoutThickness and fStrikeoutPosition have a bit set in fFlags if their values |
| 1105 | are valid, since their value may be zero. |
| 1106 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1107 | struct FontMetrics { |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1108 | |
| 1109 | /** \enum SkPaint::FontMetrics::FontMetricsFlags |
| 1110 | FontMetricsFlags are set in fFlags when underline metrics are valid; |
| 1111 | the underline metric may be valid and zero. |
| 1112 | Fonts with embedded bitmaps may not have valid underline metrics. |
commit-bot@chromium.org | 0bc406d | 2014-03-01 20:12:26 +0000 | [diff] [blame] | 1113 | */ |
| 1114 | enum FontMetricsFlags { |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1115 | kUnderlineThicknessIsValid_Flag = 1 << 0, //!< Set if fUnderlineThickness is valid. |
| 1116 | kUnderlinePositionIsValid_Flag = 1 << 1, //!< Set if fUnderlinePosition is valid. |
| 1117 | kStrikeoutThicknessIsValid_Flag = 1 << 2, //!< Set if fStrikeoutThickness is valid. |
| 1118 | kStrikeoutPositionIsValid_Flag = 1 << 3, //!< Set if fStrikeoutPosition is valid. |
commit-bot@chromium.org | 0bc406d | 2014-03-01 20:12:26 +0000 | [diff] [blame] | 1119 | }; |
| 1120 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1121 | uint32_t fFlags; //!< fFlags is set when underline metrics are valid. |
commit-bot@chromium.org | 0bc406d | 2014-03-01 20:12:26 +0000 | [diff] [blame] | 1122 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1123 | /** Largest height for any glyph. |
| 1124 | A measure from the baseline, and is less than or equal to zero. |
| 1125 | */ |
| 1126 | SkScalar fTop; |
commit-bot@chromium.org | 0bc406d | 2014-03-01 20:12:26 +0000 | [diff] [blame] | 1127 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1128 | /** Recommended distance above the baseline to reserve for a line of text. |
| 1129 | A measure from the baseline, and is less than or equal to zero. |
| 1130 | */ |
| 1131 | SkScalar fAscent; |
Ben Wagner | 219f362 | 2017-07-17 15:32:25 -0400 | [diff] [blame] | 1132 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1133 | /** Recommended distance below the baseline to reserve for a line of text. |
| 1134 | A measure from the baseline, and is greater than or equal to zero. |
| 1135 | */ |
| 1136 | SkScalar fDescent; |
Ben Wagner | 219f362 | 2017-07-17 15:32:25 -0400 | [diff] [blame] | 1137 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1138 | /** Greatest extent below the baseline for any glyph. |
| 1139 | A measure from the baseline, and is greater than or equal to zero. |
| 1140 | */ |
| 1141 | SkScalar fBottom; |
| 1142 | |
| 1143 | /** Recommended distance to add between lines of text. |
| 1144 | Greater than or equal to zero. |
| 1145 | */ |
| 1146 | SkScalar fLeading; |
| 1147 | |
| 1148 | /** Average character width, if it is available. |
| 1149 | Zero if no average width is stored in the font. |
| 1150 | */ |
| 1151 | SkScalar fAvgCharWidth; |
| 1152 | SkScalar fMaxCharWidth; //!< Maximum character width. |
| 1153 | |
| 1154 | /** Minimum bounding box x value for all glyphs. |
| 1155 | Typically less than zero. |
| 1156 | */ |
| 1157 | SkScalar fXMin; |
| 1158 | |
| 1159 | /** Maximum bounding box x value for all glyphs. |
| 1160 | Typically greater than zero. |
| 1161 | */ |
| 1162 | SkScalar fXMax; |
| 1163 | |
| 1164 | /** Height of a lower-case 'x'. |
| 1165 | May be zero if no lower-case height is stored in the font. |
| 1166 | */ |
| 1167 | SkScalar fXHeight; |
| 1168 | |
| 1169 | /** Height of an upper-case letter. |
| 1170 | May be zero if no upper-case height is stored in the font. |
| 1171 | */ |
| 1172 | SkScalar fCapHeight; |
| 1173 | |
| 1174 | /** Underline thickness. If the metric |
| 1175 | is valid, the kUnderlineThicknessIsValid_Flag is set in fFlags. |
| 1176 | If kUnderlineThicknessIsValid_Flag is clear, fUnderlineThickness is zero. |
| 1177 | */ |
| 1178 | SkScalar fUnderlineThickness; |
| 1179 | |
| 1180 | /** Underline position relative to the baseline. |
| 1181 | It may be negative, to draw the underline above the baseline, zero |
| 1182 | to draw the underline on the baseline, or positive to draw the underline |
| 1183 | below the baseline. |
| 1184 | |
| 1185 | If the metric is valid, the kUnderlinePositionIsValid_Flag is set in fFlags. |
| 1186 | If kUnderlinePositionIsValid_Flag is clear, fUnderlinePosition is zero. |
| 1187 | */ |
| 1188 | SkScalar fUnderlinePosition; |
| 1189 | |
| 1190 | /** Strikeout thickness. If the metric |
| 1191 | is valid, the kStrikeoutThicknessIsValid_Flag is set in fFlags. |
| 1192 | If kStrikeoutThicknessIsValid_Flag is clear, fStrikeoutThickness is zero. |
| 1193 | */ |
| 1194 | SkScalar fStrikeoutThickness; |
| 1195 | |
| 1196 | /** Strikeout position relative to the baseline. |
| 1197 | It may be negative, to draw the strikeout above the baseline, zero |
| 1198 | to draw the strikeout on the baseline, or positive to draw the strikeout |
| 1199 | below the baseline. |
| 1200 | |
| 1201 | If the metric is valid, the kStrikeoutPositionIsValid_Flag is set in fFlags. |
| 1202 | If kStrikeoutPositionIsValid_Flag is clear, fStrikeoutPosition is zero. |
| 1203 | */ |
| 1204 | SkScalar fStrikeoutPosition; |
| 1205 | |
| 1206 | /** If SkPaint::FontMetrics has a valid underline thickness, return true, and set |
| 1207 | thickness to that value. If it doesn't, return false, and ignore |
| 1208 | thickness. |
| 1209 | |
| 1210 | @param thickness storage for underline width |
| 1211 | @return true if font specifies underline width |
| 1212 | */ |
commit-bot@chromium.org | 0bc406d | 2014-03-01 20:12:26 +0000 | [diff] [blame] | 1213 | bool hasUnderlineThickness(SkScalar* thickness) const { |
Ben Wagner | 3318da5 | 2017-03-23 14:01:22 -0400 | [diff] [blame] | 1214 | if (SkToBool(fFlags & kUnderlineThicknessIsValid_Flag)) { |
commit-bot@chromium.org | 0bc406d | 2014-03-01 20:12:26 +0000 | [diff] [blame] | 1215 | *thickness = fUnderlineThickness; |
| 1216 | return true; |
| 1217 | } |
| 1218 | return false; |
| 1219 | } |
| 1220 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1221 | /** If SkPaint::FontMetrics has a valid underline position, return true, and set |
| 1222 | position to that value. If it doesn't, return false, and ignore |
| 1223 | position. |
| 1224 | |
| 1225 | @param position storage for underline position |
| 1226 | @return true if font specifies underline position |
| 1227 | */ |
commit-bot@chromium.org | 0bc406d | 2014-03-01 20:12:26 +0000 | [diff] [blame] | 1228 | bool hasUnderlinePosition(SkScalar* position) const { |
| 1229 | if (SkToBool(fFlags & kUnderlinePositionIsValid_Flag)) { |
| 1230 | *position = fUnderlinePosition; |
| 1231 | return true; |
| 1232 | } |
| 1233 | return false; |
| 1234 | } |
| 1235 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1236 | /** If SkPaint::FontMetrics has a valid strikeout thickness, return true, and set |
| 1237 | thickness to that value. If it doesn't, return false, and ignore |
| 1238 | thickness. |
| 1239 | |
| 1240 | @param thickness storage for strikeout width |
| 1241 | @return true if font specifies strikeout width |
| 1242 | */ |
Ben Wagner | 219f362 | 2017-07-17 15:32:25 -0400 | [diff] [blame] | 1243 | bool hasStrikeoutThickness(SkScalar* thickness) const { |
| 1244 | if (SkToBool(fFlags & kStrikeoutThicknessIsValid_Flag)) { |
| 1245 | *thickness = fStrikeoutThickness; |
| 1246 | return true; |
| 1247 | } |
| 1248 | return false; |
| 1249 | } |
| 1250 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1251 | /** If SkPaint::FontMetrics has a valid strikeout position, return true, and set |
| 1252 | position to that value. If it doesn't, return false, and ignore |
| 1253 | position. |
| 1254 | |
| 1255 | @param position storage for strikeout position |
| 1256 | @return true if font specifies strikeout position |
| 1257 | */ |
Ben Wagner | 219f362 | 2017-07-17 15:32:25 -0400 | [diff] [blame] | 1258 | bool hasStrikeoutPosition(SkScalar* position) const { |
| 1259 | if (SkToBool(fFlags & kStrikeoutPositionIsValid_Flag)) { |
| 1260 | *position = fStrikeoutPosition; |
| 1261 | return true; |
| 1262 | } |
| 1263 | return false; |
| 1264 | } |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1265 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1266 | }; |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 1267 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1268 | /** Returns SkPaint::FontMetrics associated with SkTypeface. |
| 1269 | The return value is the recommended spacing between lines: the sum of metrics |
| 1270 | descent, ascent, and leading. |
| 1271 | If metrics is not nullptr, SkPaint::FontMetrics is copied to metrics. |
| 1272 | Results are scaled by text size but does not take into account |
| 1273 | dimensions required by text scale x, text skew x, fake bold, |
| 1274 | style stroke, and SkPathEffect. |
| 1275 | Results can be additionally scaled by scale; a scale of zero |
| 1276 | is ignored. |
| 1277 | |
| 1278 | @param metrics storage for SkPaint::FontMetrics from SkTypeface; may be nullptr |
| 1279 | @param scale additional multiplier for returned values |
| 1280 | @return recommended spacing between lines |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1281 | */ |
| 1282 | SkScalar getFontMetrics(FontMetrics* metrics, SkScalar scale = 0) const; |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 1283 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1284 | /** Returns the recommended spacing between lines: the sum of metrics |
| 1285 | descent, ascent, and leading. |
| 1286 | Result is scaled by text size but does not take into account |
| 1287 | dimensions required by stroking and SkPathEffect. |
| 1288 | getFontSpacing returns the same result as getFontMetrics. |
| 1289 | |
| 1290 | @return recommended spacing between lines |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1291 | */ |
| 1292 | SkScalar getFontSpacing() const { return this->getFontMetrics(NULL, 0); } |
| 1293 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1294 | /** Converts text into glyph indices. |
| 1295 | Returns the number of glyph indices represented by text. |
| 1296 | SkPaint::TextEncoding specifies how text represents characters or glyphs. |
| 1297 | glyphs may be nullptr, to compute the glyph count. |
| 1298 | |
| 1299 | Does not check text for valid character encoding or valid |
| 1300 | glyph indices. |
| 1301 | |
| 1302 | If byteLength equals zero, textToGlyphs returns zero. |
| 1303 | If byteLength includes a partial character, the partial character is ignored. |
| 1304 | |
| 1305 | If SkPaint::TextEncoding is kUTF8_TextEncoding and |
| 1306 | text contains an invalid UTF-8 sequence, zero is returned. |
| 1307 | |
| 1308 | @param text character stroage encoded with SkPaint::TextEncoding |
| 1309 | @param byteLength length of character storage in bytes |
| 1310 | @param glyphs storage for glyph indices; may be nullptr |
| 1311 | @return number of glyphs represented by text of length byteLength |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1312 | */ |
| 1313 | int textToGlyphs(const void* text, size_t byteLength, |
halcanary | d0e95a5 | 2016-07-25 07:18:12 -0700 | [diff] [blame] | 1314 | SkGlyphID glyphs[]) const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1315 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1316 | /** Returns true if all text corresponds to a non-zero glyph index. |
| 1317 | Returns false if any characters in text are not supported in |
| 1318 | SkTypeface. |
reed@android.com | a5dcaf6 | 2010-02-05 17:12:32 +0000 | [diff] [blame] | 1319 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1320 | If SkPaint::TextEncoding is kGlyphID_TextEncoding, containsText |
| 1321 | returns true if all glyph indices in text are non-zero; containsText |
| 1322 | does not check to see if text contains valid glyph indices for SkTypeface. |
| 1323 | |
| 1324 | Returns true if bytelength is zero. |
| 1325 | |
| 1326 | @param text array of characters or glyphs |
| 1327 | @param byteLength number of bytes in text array |
| 1328 | @return true if all text corresponds to a non-zero glyph index |
| 1329 | */ |
reed@android.com | a5dcaf6 | 2010-02-05 17:12:32 +0000 | [diff] [blame] | 1330 | bool containsText(const void* text, size_t byteLength) const; |
| 1331 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1332 | /** Converts glyphs into text if possible. |
| 1333 | Glyph values without direct Unicode equivalents are mapped to zero. |
| 1334 | Uses the SkTypeface, but is unaffected |
| 1335 | by SkPaint::TextEncoding; the text values returned are equivalent to kUTF32_TextEncoding. |
| 1336 | |
| 1337 | Only supported on platforms that use FreeType as the font engine. |
| 1338 | |
| 1339 | @param glyphs array of indices into font |
| 1340 | @param count length of glyph array |
| 1341 | @param text storage for character codes, one per glyph |
reed@android.com | 9d3a985 | 2010-01-08 14:07:42 +0000 | [diff] [blame] | 1342 | */ |
halcanary | d0e95a5 | 2016-07-25 07:18:12 -0700 | [diff] [blame] | 1343 | void glyphsToUnichars(const SkGlyphID glyphs[], int count, SkUnichar text[]) const; |
reed@android.com | 9d3a985 | 2010-01-08 14:07:42 +0000 | [diff] [blame] | 1344 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1345 | /** Returns the number of glyphs in text. |
| 1346 | Uses SkPaint::TextEncoding to count the glyphs. |
| 1347 | Returns the same result as textToGlyphs. |
| 1348 | |
| 1349 | @param text character stroage encoded with SkPaint::TextEncoding |
| 1350 | @param byteLength length of character storage in bytes |
| 1351 | @return number of glyphs represented by text of length byteLength |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1352 | */ |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 1353 | int countText(const void* text, size_t byteLength) const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1354 | return this->textToGlyphs(text, byteLength, NULL); |
| 1355 | } |
| 1356 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1357 | /** Returns the advance width of text if kVerticalText_Flag is clear, |
| 1358 | and the height of text if kVerticalText_Flag is set. |
| 1359 | The advance is the normal distance to move before drawing additional text. |
| 1360 | Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics, |
| 1361 | and text size, text scale x, text skew x, stroke width, and |
| 1362 | SkPathEffect to scale the metrics and bounds. |
| 1363 | Returns the bounding box of text if bounds is not nullptr. |
| 1364 | The bounding box is computed as if the text was drawn at the origin. |
| 1365 | |
| 1366 | @param text character codes or glyph indices to be measured |
| 1367 | @param length number of bytes of text to measure |
| 1368 | @param bounds returns bounding box relative to (0, 0) if not nullptr |
| 1369 | @return advance width or height |
| 1370 | */ |
reed | 99ae881 | 2014-08-26 11:30:01 -0700 | [diff] [blame] | 1371 | SkScalar measureText(const void* text, size_t length, SkRect* bounds) const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1372 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1373 | /** Returns the advance width of text if kVerticalText_Flag is clear, |
| 1374 | and the height of text if kVerticalText_Flag is set. |
| 1375 | The advance is the normal distance to move before drawing additional text. |
| 1376 | Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics, |
| 1377 | and text size, text scale x, text skew x, stroke width, and |
| 1378 | SkPathEffect to scale the metrics and bounds. |
| 1379 | Returns the bounding box of text if bounds is not nullptr. |
| 1380 | The bounding box is computed as if the text was drawn at the origin. |
| 1381 | |
| 1382 | @param text character codes or glyph indices to be measured |
| 1383 | @param length number of bytes of text to measure |
| 1384 | @param bounds returns bounding box relative to (0, 0) if not nullptr |
| 1385 | @return advance width or height |
| 1386 | */ |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 1387 | SkScalar measureText(const void* text, size_t length) const { |
reed | 99ae881 | 2014-08-26 11:30:01 -0700 | [diff] [blame] | 1388 | return this->measureText(text, length, NULL); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1389 | } |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 1390 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1391 | /** Returns the bytes of text that fit within maxWidth. |
| 1392 | If kVerticalText_Flag is clear, the text fragment fits if its advance width is less than or |
| 1393 | equal to maxWidth. |
| 1394 | If kVerticalText_Flag is set, the text fragment fits if its advance height is less than or |
| 1395 | equal to maxWidth. |
| 1396 | Measures only while the advance is less than or equal to maxWidth. |
| 1397 | Returns the advance or the text fragment in measuredWidth if it not nullptr. |
| 1398 | Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics, |
| 1399 | and text size to scale the metrics. |
| 1400 | Does not scale the advance or bounds by fake bold or SkPathEffect. |
| 1401 | |
| 1402 | @param text character codes or glyph indices to be measured |
| 1403 | @param length number of bytes of text to measure |
| 1404 | @param maxWidth advance limit; text is measured while advance is less than maxWidth |
| 1405 | @param measuredWidth returns the width of the text less than or equal to maxWidth |
| 1406 | @return bytes of text that fit, always less than or equal to length |
| 1407 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1408 | size_t breakText(const void* text, size_t length, SkScalar maxWidth, |
reed | 9e96aa0 | 2014-10-03 12:44:37 -0700 | [diff] [blame] | 1409 | SkScalar* measuredWidth = NULL) const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1410 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1411 | /** Retrieves the advance and bounds for each glyph in text, and returns |
| 1412 | the glyph count in text. |
| 1413 | Both widths and bounds may be nullptr. |
| 1414 | If widths is not nullptr, widths must be an array of glyph count entries. |
| 1415 | if bounds is not nullptr, bounds must be an array of glyph count entries. |
| 1416 | If kVerticalText_Flag is clear, widths returns the horizontal advance. |
| 1417 | If kVerticalText_Flag is set, widths returns the vertical advance. |
| 1418 | Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics, |
| 1419 | and text size to scale the widths and bounds. |
| 1420 | Does not scale the advance by fake bold or SkPathEffect. |
| 1421 | Does return include fake bold and SkPathEffect in the bounds. |
| 1422 | |
| 1423 | @param text character codes or glyph indices to be measured |
| 1424 | @param byteLength number of bytes of text to measure |
| 1425 | @param widths returns text advances for each glyph; may be nullptr |
| 1426 | @param bounds returns bounds for each glyph relative to (0, 0); may be nullptr |
| 1427 | @return glyph count in text |
| 1428 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1429 | int getTextWidths(const void* text, size_t byteLength, SkScalar widths[], |
| 1430 | SkRect bounds[] = NULL) const; |
| 1431 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1432 | /** Returns the geometry as SkPath equivalent to the drawn text. |
| 1433 | Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths, |
| 1434 | and text size, fake bold, and SkPathEffect to scale and modify the glyph paths. |
| 1435 | All of the glyph paths are stored in path. |
| 1436 | getTextPath uses x, y, and SkPaint::Align to position path. |
| 1437 | |
| 1438 | @param text character codes or glyph indices |
| 1439 | @param length number of bytes of text |
| 1440 | @param x x-coordinate of the origin of the text |
| 1441 | @param y y-coordinate of the origin of the text |
| 1442 | @param path geometry of the glyphs |
| 1443 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1444 | void getTextPath(const void* text, size_t length, SkScalar x, SkScalar y, |
| 1445 | SkPath* path) const; |
| 1446 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1447 | /** Returns the geometry as SkPath equivalent to the drawn text. |
| 1448 | Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths, |
| 1449 | and text size, fake bold, and SkPathEffect to scale and modify the glyph paths. |
| 1450 | All of the glyph paths are stored in path. |
| 1451 | Uses pos array and SkPaint::Align to position path. |
| 1452 | pos contains a position for each glyph. |
| 1453 | |
| 1454 | @param text character codes or glyph indices |
| 1455 | @param length number of bytes of text |
| 1456 | @param pos positions of each glyph |
| 1457 | @param path geometry of the glyphs |
| 1458 | */ |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1459 | void getPosTextPath(const void* text, size_t length, |
reed@google.com | ca0062e | 2012-07-20 11:20:32 +0000 | [diff] [blame] | 1460 | const SkPoint pos[], SkPath* path) const; |
| 1461 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1462 | /** Returns the number of intervals that intersect bounds. |
| 1463 | bounds describes a pair of lines parallel to the text advance. |
| 1464 | The return count is zero or a multiple of two, and is at most twice the number of glyphs in |
| 1465 | the string. |
| 1466 | Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths, |
| 1467 | and text size, fake bold, and SkPathEffect to scale and modify the glyph paths. |
| 1468 | Uses x, y, and SkPaint::Align to position intervals. |
| 1469 | |
| 1470 | Pass nullptr for intervals to determine the size of the interval array. |
| 1471 | |
| 1472 | intervals are cached to improve performance for multiple calls. |
| 1473 | |
| 1474 | @param text character codes or glyph indices |
| 1475 | @param length number of bytes of text |
| 1476 | @param x x-coordinate of the origin of the text |
| 1477 | @param y y-coordinate of the origin of the text |
| 1478 | @param bounds lower and upper line parallel to the advance |
| 1479 | @param intervals returned intersections; may be nullptr |
| 1480 | @return number of intersections; may be zero |
| 1481 | */ |
caryclark | 0449bcf | 2016-02-09 13:25:45 -0800 | [diff] [blame] | 1482 | int getTextIntercepts(const void* text, size_t length, SkScalar x, SkScalar y, |
| 1483 | const SkScalar bounds[2], SkScalar* intervals) const; |
| 1484 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1485 | /** Returns the number of intervals that intersect bounds. |
| 1486 | bounds describes a pair of lines parallel to the text advance. |
| 1487 | The return count is zero or a multiple of two, and is at most twice the number of glyphs in |
| 1488 | the string. |
| 1489 | Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths, |
| 1490 | and text size, fake bold, and SkPathEffect to scale and modify the glyph paths. |
| 1491 | Uses pos array and SkPaint::Align to position intervals. |
| 1492 | |
| 1493 | Pass nullptr for intervals to determine the size of the interval array. |
| 1494 | |
| 1495 | intervals are cached to improve performance for multiple calls. |
| 1496 | |
| 1497 | @param text character codes or glyph indices |
| 1498 | @param length number of bytes of text |
| 1499 | @param pos positions of each glyph |
| 1500 | @param bounds lower and upper line parallel to the advance |
| 1501 | @param intervals returned intersections; may be nullptr |
| 1502 | @return The number of intersections; may be zero |
| 1503 | */ |
caryclark | 0449bcf | 2016-02-09 13:25:45 -0800 | [diff] [blame] | 1504 | int getPosTextIntercepts(const void* text, size_t length, const SkPoint pos[], |
| 1505 | const SkScalar bounds[2], SkScalar* intervals) const; |
| 1506 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1507 | /** Returns the number of intervals that intersect bounds. |
| 1508 | bounds describes a pair of lines parallel to the text advance. |
| 1509 | The return count is zero or a multiple of two, and is at most twice the number of glyphs in |
| 1510 | the string. |
| 1511 | Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths, |
| 1512 | and text size, fake bold, and SkPathEffect to scale and modify the glyph paths. |
| 1513 | Uses xpos array, constY, and SkPaint::Align to position intervals. |
| 1514 | |
| 1515 | Pass nullptr for intervals to determine the size of the interval array. |
| 1516 | |
| 1517 | intervals are cached to improve performance for multiple calls. |
| 1518 | |
| 1519 | @param text character codes or glyph indices |
| 1520 | @param length number of bytes of text |
| 1521 | @param xpos positions of each glyph in x |
| 1522 | @param constY position of each glyph in y |
| 1523 | @param bounds lower and upper line parallel to the advance |
| 1524 | @param intervals returned intersections; may be nullptr |
| 1525 | @return number of intersections; may be zero |
| 1526 | */ |
fmalita | eae6a91 | 2016-07-28 09:47:24 -0700 | [diff] [blame] | 1527 | int getPosTextHIntercepts(const void* text, size_t length, const SkScalar xpos[], |
| 1528 | SkScalar constY, const SkScalar bounds[2], SkScalar* intervals) const; |
| 1529 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1530 | /** Returns the number of intervals that intersect bounds. |
| 1531 | bounds describes a pair of lines parallel to the text advance. |
| 1532 | The return count is zero or a multiple of two, and is at most twice the number of glyphs in |
| 1533 | the string. |
| 1534 | Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths, |
| 1535 | and text size, fake bold, and SkPathEffect to scale and modify the glyph paths. |
| 1536 | Uses pos array and SkPaint::Align to position intervals. |
| 1537 | |
| 1538 | Pass nullptr for intervals to determine the size of the interval array. |
| 1539 | |
| 1540 | intervals are cached to improve performance for multiple calls. |
| 1541 | |
| 1542 | @param blob glyphs, positions, and text paint attributes |
| 1543 | @param bounds lower and upper line parallel to the advance |
| 1544 | @param intervals returned intersections; may be nullptr |
| 1545 | @return number of intersections; may be zero |
| 1546 | */ |
fmalita | eae6a91 | 2016-07-28 09:47:24 -0700 | [diff] [blame] | 1547 | int getTextBlobIntercepts(const SkTextBlob* blob, const SkScalar bounds[2], |
| 1548 | SkScalar* intervals) const; |
| 1549 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1550 | /** Returns the union of bounds of all glyphs. |
| 1551 | Returned dimensions are computed by font manager from font data, |
| 1552 | ignoring SkPaint::Hinting. getFontBounds includes text size, text scale x, |
| 1553 | and text skew x, but not fake bold or SkPathEffect. |
| 1554 | |
| 1555 | If text size is large, text scale x is one, and text skew x is zero, |
| 1556 | getFontBounds returns the same bounds as SkPaint::FontMetrics { FontMetrics::fXMin, |
| 1557 | FontMetrics::fTop, FontMetrics::fXMax, FontMetrics::fBottom }. |
| 1558 | |
| 1559 | @return union of bounds of all glyphs |
| 1560 | */ |
reed | 8893e5f | 2014-12-15 13:27:26 -0800 | [diff] [blame] | 1561 | SkRect getFontBounds() const; |
| 1562 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1563 | /** Returns true if SkPaint prevents all drawing. |
| 1564 | If nothingToDraw returns false, the SkPaint may or may not allow drawing. |
| 1565 | |
| 1566 | Returns true if SkBlendMode and alpha are enabled, |
| 1567 | and computed alpha is zero. |
| 1568 | |
| 1569 | @return true if SkPaint prevents all drawing |
| 1570 | */ |
reed@google.com | 632e1a2 | 2011-10-06 12:37:00 +0000 | [diff] [blame] | 1571 | bool nothingToDraw() const; |
| 1572 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1573 | /** (to be made private) |
| 1574 | Returns true if SkPaint does not include elements requiring extensive computation |
| 1575 | to compute SkBaseDevice bounds of drawn geometry. For instance, SkPaint with SkPathEffect |
| 1576 | always returns false. |
reed@google.com | d5f2079 | 2012-05-16 14:15:02 +0000 | [diff] [blame] | 1577 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1578 | @return true if SkPaint allows for fast computation of bounds |
| 1579 | */ |
senorblanco | 0abdf76 | 2015-08-20 11:10:41 -0700 | [diff] [blame] | 1580 | bool canComputeFastBounds() const; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1581 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1582 | /** (to be made private) |
| 1583 | Only call this if canComputeFastBounds returned true. This takes a |
| 1584 | raw rectangle (the raw bounds of a shape), and adjusts it for stylistic |
| 1585 | effects in the paint (e.g. stroking). If needed, it uses the storage |
| 1586 | rect parameter. It returns the adjusted bounds that can then be used |
| 1587 | for SkCanvas::quickReject tests. |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1588 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1589 | The returned rect will either be orig or storage, thus the caller |
| 1590 | should not rely on storage being set to the result, but should always |
| 1591 | use the retured value. It is legal for orig and storage to be the same |
| 1592 | rect. |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1593 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1594 | e.g. |
| 1595 | if (paint.canComputeFastBounds()) { |
| 1596 | SkRect r, storage; |
| 1597 | path.computeBounds(&r, SkPath::kFast_BoundsType); |
| 1598 | const SkRect& fastR = paint.computeFastBounds(r, &storage); |
| 1599 | if (canvas->quickReject(fastR, ...)) { |
| 1600 | // don't draw the path |
| 1601 | } |
| 1602 | } |
| 1603 | |
| 1604 | @param orig geometry modified by SkPaint when drawn |
| 1605 | @param storage computed bounds of geometry; may not be nullptr |
| 1606 | @return fast computed bounds |
| 1607 | */ |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 1608 | const SkRect& computeFastBounds(const SkRect& orig, SkRect* storage) const { |
Brian Osman | 60751d7 | 2017-05-12 11:21:36 -0400 | [diff] [blame] | 1609 | // Things like stroking, etc... will do math on the bounds rect, assuming that it's sorted. |
| 1610 | SkASSERT(orig.isSorted()); |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 1611 | SkPaint::Style style = this->getStyle(); |
| 1612 | // ultra fast-case: filling with no effects that affect geometry |
| 1613 | if (kFill_Style == style) { |
| 1614 | uintptr_t effects = reinterpret_cast<uintptr_t>(this->getLooper()); |
| 1615 | effects |= reinterpret_cast<uintptr_t>(this->getMaskFilter()); |
| 1616 | effects |= reinterpret_cast<uintptr_t>(this->getPathEffect()); |
senorblanco@chromium.org | 336d1d7 | 2014-01-27 21:03:17 +0000 | [diff] [blame] | 1617 | effects |= reinterpret_cast<uintptr_t>(this->getImageFilter()); |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 1618 | if (!effects) { |
| 1619 | return orig; |
| 1620 | } |
| 1621 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1622 | |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 1623 | return this->doComputeFastBounds(orig, storage, style); |
| 1624 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1625 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1626 | /** (to be made private) |
| 1627 | |
| 1628 | @param orig geometry modified by SkPaint when drawn |
| 1629 | @param storage computed bounds of geometry |
| 1630 | @return fast computed bounds |
| 1631 | */ |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 1632 | const SkRect& computeFastStrokeBounds(const SkRect& orig, |
| 1633 | SkRect* storage) const { |
reed@google.com | 73a0258 | 2012-05-16 19:21:12 +0000 | [diff] [blame] | 1634 | return this->doComputeFastBounds(orig, storage, kStroke_Style); |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 1635 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1636 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1637 | /** (to be made private) |
| 1638 | Take the style explicitly, so the caller can force us to be stroked |
| 1639 | without having to make a copy of the paint just to change that field. |
| 1640 | |
| 1641 | @param orig geometry modified by SkPaint when drawn |
| 1642 | @param storage computed bounds of geometry |
| 1643 | @param style overrides SkPaint::Style |
| 1644 | @return fast computed bounds |
| 1645 | */ |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 1646 | const SkRect& doComputeFastBounds(const SkRect& orig, SkRect* storage, |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 1647 | Style style) const; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1648 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1649 | /** |
| 1650 | Converts SkPaint to machine parsable form in developer mode. |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 1651 | |
Cary Clark | 50fa3ff | 2017-07-26 10:15:23 -0400 | [diff] [blame^] | 1652 | @param str storage for string containing parsable SkPaint |
| 1653 | */ |
commit-bot@chromium.org | 0f10f7b | 2014-03-13 18:02:17 +0000 | [diff] [blame] | 1654 | SK_TO_STRING_NONVIRT() |
robertphillips@google.com | 791f12e | 2013-02-14 13:53:53 +0000 | [diff] [blame] | 1655 | |
reed@google.com | d5f2079 | 2012-05-16 14:15:02 +0000 | [diff] [blame] | 1656 | private: |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 1657 | typedef const SkGlyph& (*GlyphCacheProc)(SkGlyphCache*, const char**); |
| 1658 | |
reed | a5ab9ec | 2016-03-06 18:10:48 -0800 | [diff] [blame] | 1659 | sk_sp<SkTypeface> fTypeface; |
| 1660 | sk_sp<SkPathEffect> fPathEffect; |
| 1661 | sk_sp<SkShader> fShader; |
reed | a5ab9ec | 2016-03-06 18:10:48 -0800 | [diff] [blame] | 1662 | sk_sp<SkMaskFilter> fMaskFilter; |
| 1663 | sk_sp<SkColorFilter> fColorFilter; |
| 1664 | sk_sp<SkRasterizer> fRasterizer; |
reed | 46f2d0a | 2016-09-11 05:40:31 -0700 | [diff] [blame] | 1665 | sk_sp<SkDrawLooper> fDrawLooper; |
reed | a5ab9ec | 2016-03-06 18:10:48 -0800 | [diff] [blame] | 1666 | sk_sp<SkImageFilter> fImageFilter; |
reed@google.com | d5f2079 | 2012-05-16 14:15:02 +0000 | [diff] [blame] | 1667 | |
commit-bot@chromium.org | e8807f4 | 2014-03-24 23:03:11 +0000 | [diff] [blame] | 1668 | SkScalar fTextSize; |
| 1669 | SkScalar fTextScaleX; |
| 1670 | SkScalar fTextSkewX; |
reed@google.com | d5f2079 | 2012-05-16 14:15:02 +0000 | [diff] [blame] | 1671 | SkColor fColor; |
| 1672 | SkScalar fWidth; |
| 1673 | SkScalar fMiterLimit; |
Mike Reed | 71fecc3 | 2016-11-18 17:19:54 -0500 | [diff] [blame] | 1674 | uint32_t fBlendMode; // just need 5-6 bits |
commit-bot@chromium.org | aca1c01 | 2014-02-21 18:18:05 +0000 | [diff] [blame] | 1675 | union { |
| 1676 | struct { |
| 1677 | // all of these bitfields should add up to 32 |
| 1678 | unsigned fFlags : 16; |
| 1679 | unsigned fTextAlign : 2; |
| 1680 | unsigned fCapType : 2; |
| 1681 | unsigned fJoinType : 2; |
| 1682 | unsigned fStyle : 2; |
| 1683 | unsigned fTextEncoding : 2; // 3 values |
| 1684 | unsigned fHinting : 2; |
reed | f803da1 | 2015-01-23 05:58:07 -0800 | [diff] [blame] | 1685 | unsigned fFilterQuality : 2; |
commit-bot@chromium.org | 85faf50 | 2014-04-16 12:58:02 +0000 | [diff] [blame] | 1686 | //unsigned fFreeBits : 2; |
reed | f59eab2 | 2014-07-14 14:39:15 -0700 | [diff] [blame] | 1687 | } fBitfields; |
| 1688 | uint32_t fBitfieldsUInt; |
commit-bot@chromium.org | aca1c01 | 2014-02-21 18:18:05 +0000 | [diff] [blame] | 1689 | }; |
commit-bot@chromium.org | e8807f4 | 2014-03-24 23:03:11 +0000 | [diff] [blame] | 1690 | |
robertphillips | e34f17d | 2016-07-19 07:59:22 -0700 | [diff] [blame] | 1691 | static GlyphCacheProc GetGlyphCacheProc(TextEncoding encoding, |
| 1692 | bool isDevKern, |
| 1693 | bool needFullMetrics); |
reed@google.com | d5f2079 | 2012-05-16 14:15:02 +0000 | [diff] [blame] | 1694 | |
| 1695 | SkScalar measure_text(SkGlyphCache*, const char* text, size_t length, |
| 1696 | int* count, SkRect* bounds) const; |
| 1697 | |
brianosman | a1e8f8d | 2016-04-08 06:47:54 -0700 | [diff] [blame] | 1698 | enum ScalerContextFlags : uint32_t { |
| 1699 | kNone_ScalerContextFlags = 0, |
| 1700 | |
| 1701 | kFakeGamma_ScalerContextFlag = 1 << 0, |
| 1702 | kBoostContrast_ScalerContextFlag = 1 << 1, |
| 1703 | |
| 1704 | kFakeGammaAndBoostContrast_ScalerContextFlags = |
| 1705 | kFakeGamma_ScalerContextFlag | kBoostContrast_ScalerContextFlag, |
bungeman | f6d1e60 | 2016-02-22 13:20:28 -0800 | [diff] [blame] | 1706 | }; |
| 1707 | |
joshualitt | fd45079 | 2015-03-13 08:38:43 -0700 | [diff] [blame] | 1708 | /* |
| 1709 | * Allocs an SkDescriptor on the heap and return it to the caller as a refcnted |
| 1710 | * SkData. Caller is responsible for managing the lifetime of this object. |
| 1711 | */ |
reed | a9322c2 | 2016-04-12 06:47:05 -0700 | [diff] [blame] | 1712 | void getScalerContextDescriptor(SkScalerContextEffects*, SkAutoDescriptor*, |
| 1713 | const SkSurfaceProps& surfaceProps, |
brianosman | a1e8f8d | 2016-04-08 06:47:54 -0700 | [diff] [blame] | 1714 | uint32_t scalerContextFlags, const SkMatrix*) const; |
joshualitt | fd45079 | 2015-03-13 08:38:43 -0700 | [diff] [blame] | 1715 | |
brianosman | a1e8f8d | 2016-04-08 06:47:54 -0700 | [diff] [blame] | 1716 | SkGlyphCache* detachCache(const SkSurfaceProps* surfaceProps, uint32_t scalerContextFlags, |
bungeman | f6d1e60 | 2016-02-22 13:20:28 -0800 | [diff] [blame] | 1717 | const SkMatrix*) const; |
reed@google.com | d5f2079 | 2012-05-16 14:15:02 +0000 | [diff] [blame] | 1718 | |
brianosman | a1e8f8d | 2016-04-08 06:47:54 -0700 | [diff] [blame] | 1719 | void descriptorProc(const SkSurfaceProps* surfaceProps, uint32_t scalerContextFlags, |
bungeman | f6d1e60 | 2016-02-22 13:20:28 -0800 | [diff] [blame] | 1720 | const SkMatrix* deviceMatrix, |
reed | a9322c2 | 2016-04-12 06:47:05 -0700 | [diff] [blame] | 1721 | void (*proc)(SkTypeface*, const SkScalerContextEffects&, |
| 1722 | const SkDescriptor*, void*), |
bungeman | f6d1e60 | 2016-02-22 13:20:28 -0800 | [diff] [blame] | 1723 | void* context) const; |
reed@android.com | d252db0 | 2009-04-01 18:31:44 +0000 | [diff] [blame] | 1724 | |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 1725 | /* |
| 1726 | * The luminance color is used to determine which Gamma Canonical color to map to. This is |
| 1727 | * really only used by backends which want to cache glyph masks, and need some way to know if |
| 1728 | * they need to generate new masks based off a given color. |
| 1729 | */ |
| 1730 | SkColor computeLuminanceColor() const; |
| 1731 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1732 | enum { |
reed@google.com | ed43dff | 2013-06-04 16:56:27 +0000 | [diff] [blame] | 1733 | /* This is the size we use when we ask for a glyph's path. We then |
| 1734 | * post-transform it as we draw to match the request. |
| 1735 | * This is done to try to re-use cache entries for the path. |
| 1736 | * |
| 1737 | * This value is somewhat arbitrary. In theory, it could be 1, since |
| 1738 | * we store paths as floats. However, we get the path from the font |
| 1739 | * scaler, and it may represent its paths as fixed-point (or 26.6), |
| 1740 | * so we shouldn't ask for something too big (might overflow 16.16) |
| 1741 | * or too small (underflow 26.6). |
| 1742 | * |
| 1743 | * This value could track kMaxSizeForGlyphCache, assuming the above |
| 1744 | * constraints, but since we ask for unhinted paths, the two values |
| 1745 | * need not match per-se. |
| 1746 | */ |
| 1747 | kCanonicalTextSizeForPaths = 64, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1748 | }; |
reed@google.com | ed43dff | 2013-06-04 16:56:27 +0000 | [diff] [blame] | 1749 | |
| 1750 | static bool TooBigToUseCache(const SkMatrix& ctm, const SkMatrix& textM); |
| 1751 | |
reed@google.com | ed43dff | 2013-06-04 16:56:27 +0000 | [diff] [blame] | 1752 | // Set flags/hinting/textSize up to use for drawing text as paths. |
| 1753 | // Returns scale factor to restore the original textSize, since will will |
| 1754 | // have change it to kCanonicalTextSizeForPaths. |
| 1755 | SkScalar setupForAsPaths(); |
| 1756 | |
Mike Reed | d5bee5d | 2017-06-01 14:45:44 -0400 | [diff] [blame] | 1757 | static SkScalar MaxCacheSize2(); |
reed@google.com | ed43dff | 2013-06-04 16:56:27 +0000 | [diff] [blame] | 1758 | |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 1759 | friend class SkAutoGlyphCache; |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 1760 | friend class SkAutoGlyphCacheNoGamma; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1761 | friend class SkCanvas; |
| 1762 | friend class SkDraw; |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 1763 | friend class SkPDFDevice; |
joshualitt | e76b4bb | 2015-12-28 07:23:58 -0800 | [diff] [blame] | 1764 | friend class GrAtlasTextBlob; |
joshualitt | dbd3593 | 2015-04-02 09:19:04 -0700 | [diff] [blame] | 1765 | friend class GrAtlasTextContext; |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 1766 | friend class GrStencilAndCoverTextContext; |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 1767 | friend class GrPathRendering; |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 1768 | friend class GrTextUtils; |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 1769 | friend class GrGLPathRendering; |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 1770 | friend class SkScalerContext; |
caryclark | 0449bcf | 2016-02-09 13:25:45 -0800 | [diff] [blame] | 1771 | friend class SkTextBaseIter; |
reed@google.com | ed43dff | 2013-06-04 16:56:27 +0000 | [diff] [blame] | 1772 | friend class SkCanonicalizePaint; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1773 | }; |
| 1774 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1775 | #endif |