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