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