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