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