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