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