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