reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef SkPaint_DEFINED |
| 9 | #define SkPaint_DEFINED |
| 10 | |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 11 | #include "SkBlendMode.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 12 | #include "SkColor.h" |
reed | f803da1 | 2015-01-23 05:58:07 -0800 | [diff] [blame] | 13 | #include "SkFilterQuality.h" |
reed@google.com | ed43dff | 2013-06-04 16:56:27 +0000 | [diff] [blame] | 14 | #include "SkMatrix.h" |
Mike Reed | 71fecc3 | 2016-11-18 17:19:54 -0500 | [diff] [blame] | 15 | #include "SkRefCnt.h" |
reed@android.com | a0f5d15 | 2009-06-22 17:38:10 +0000 | [diff] [blame] | 16 | |
joshualitt | 2b6acb4 | 2015-04-01 11:30:27 -0700 | [diff] [blame] | 17 | class SkAutoDescriptor; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 18 | class SkAutoGlyphCache; |
| 19 | class SkColorFilter; |
joshualitt | fd45079 | 2015-03-13 08:38:43 -0700 | [diff] [blame] | 20 | class SkData; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 21 | class SkDescriptor; |
senorblanco | 0abdf76 | 2015-08-20 11:10:41 -0700 | [diff] [blame] | 22 | class SkDrawLooper; |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 23 | class SkReadBuffer; |
| 24 | class SkWriteBuffer; |
herb | b69d0e0 | 2015-02-25 06:47:06 -0800 | [diff] [blame] | 25 | class SkGlyph; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 26 | struct SkRect; |
| 27 | class SkGlyphCache; |
reed@google.com | 15356a6 | 2011-11-03 19:29:08 +0000 | [diff] [blame] | 28 | class SkImageFilter; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 29 | class SkMaskFilter; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 30 | class SkPath; |
| 31 | class SkPathEffect; |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 32 | struct SkPoint; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 33 | class SkRasterizer; |
reed | a9322c2 | 2016-04-12 06:47:05 -0700 | [diff] [blame] | 34 | struct SkScalerContextEffects; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 35 | class SkShader; |
robertphillips | fcf7829 | 2015-06-19 11:49:52 -0700 | [diff] [blame] | 36 | class SkSurfaceProps; |
fmalita | eae6a91 | 2016-07-28 09:47:24 -0700 | [diff] [blame] | 37 | class SkTextBlob; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 38 | class SkTypeface; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 39 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 40 | /** \class SkPaint |
| 41 | |
| 42 | The SkPaint class holds the style and color information about how to draw |
| 43 | geometries, text and bitmaps. |
| 44 | */ |
ctguil@chromium.org | 7ffb1b2 | 2011-03-15 21:27:08 +0000 | [diff] [blame] | 45 | class SK_API SkPaint { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 46 | public: |
| 47 | SkPaint(); |
| 48 | SkPaint(const SkPaint& paint); |
bungeman | ccce0e0 | 2016-02-07 14:37:23 -0800 | [diff] [blame] | 49 | SkPaint(SkPaint&& paint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 50 | ~SkPaint(); |
| 51 | |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 52 | SkPaint& operator=(const SkPaint& paint); |
| 53 | SkPaint& operator=(SkPaint&& paint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 54 | |
mtklein | bc97ef4 | 2014-08-25 10:10:47 -0700 | [diff] [blame] | 55 | /** operator== may give false negatives: two paints that draw equivalently |
| 56 | may return false. It will never give false positives: two paints that |
| 57 | are not equivalent always return false. |
| 58 | */ |
Cary Clark | 0e616cf | 2017-05-18 15:27:57 -0400 | [diff] [blame] | 59 | // cc_unittests requires SK_API to make operator== visible |
robertphillips@google.com | b265741 | 2013-08-07 22:36:29 +0000 | [diff] [blame] | 60 | SK_API friend bool operator==(const SkPaint& a, const SkPaint& b); |
| 61 | friend bool operator!=(const SkPaint& a, const SkPaint& b) { |
| 62 | return !(a == b); |
| 63 | } |
| 64 | |
mtklein | fb1fe4f | 2014-10-07 09:26:10 -0700 | [diff] [blame] | 65 | /** getHash() is a shallow hash, with the same limitations as operator==. |
| 66 | * If operator== returns true for two paints, getHash() returns the same value for each. |
| 67 | */ |
| 68 | uint32_t getHash() const; |
| 69 | |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 70 | void flatten(SkWriteBuffer& buffer) const; |
| 71 | void unflatten(SkReadBuffer& buffer); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 72 | |
| 73 | /** Restores the paint to its initial settings. |
| 74 | */ |
| 75 | void reset(); |
| 76 | |
agl@chromium.org | 309485b | 2009-07-21 17:41:32 +0000 | [diff] [blame] | 77 | /** Specifies the level of hinting to be performed. These names are taken |
| 78 | from the Gnome/Cairo names for the same. They are translated into |
| 79 | Freetype concepts the same as in cairo-ft-font.c: |
| 80 | kNo_Hinting -> FT_LOAD_NO_HINTING |
| 81 | kSlight_Hinting -> FT_LOAD_TARGET_LIGHT |
| 82 | kNormal_Hinting -> <default, no option> |
| 83 | kFull_Hinting -> <same as kNormalHinting, unless we are rendering |
| 84 | subpixel glyphs, in which case TARGET_LCD or |
| 85 | TARGET_LCD_V is used> |
| 86 | */ |
| 87 | enum Hinting { |
| 88 | kNo_Hinting = 0, |
| 89 | kSlight_Hinting = 1, |
| 90 | kNormal_Hinting = 2, //!< this is the default |
tomhudson@google.com | 1f90287 | 2012-06-01 13:15:47 +0000 | [diff] [blame] | 91 | kFull_Hinting = 3 |
agl@chromium.org | 309485b | 2009-07-21 17:41:32 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 94 | Hinting getHinting() const { |
reed | f59eab2 | 2014-07-14 14:39:15 -0700 | [diff] [blame] | 95 | return static_cast<Hinting>(fBitfields.fHinting); |
agl@chromium.org | 309485b | 2009-07-21 17:41:32 +0000 | [diff] [blame] | 96 | } |
| 97 | |
djsollen@google.com | f5dbe2f | 2011-04-15 13:41:26 +0000 | [diff] [blame] | 98 | void setHinting(Hinting hintingLevel); |
agl@chromium.org | 309485b | 2009-07-21 17:41:32 +0000 | [diff] [blame] | 99 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 100 | /** Specifies the bit values that are stored in the paint's flags. |
| 101 | */ |
| 102 | enum Flags { |
| 103 | kAntiAlias_Flag = 0x01, //!< mask to enable antialiasing |
Mike Reed | 4435311 | 2017-05-09 12:20:02 -0400 | [diff] [blame] | 104 | kDither_Flag = 0x04, //!< mask to enable dithering. see setDither() |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 105 | kFakeBoldText_Flag = 0x20, //!< mask to enable fake-bold text |
| 106 | kLinearText_Flag = 0x40, //!< mask to enable linear-text |
agl@chromium.org | 309485b | 2009-07-21 17:41:32 +0000 | [diff] [blame] | 107 | kSubpixelText_Flag = 0x80, //!< mask to enable subpixel text positioning |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 108 | kDevKernText_Flag = 0x100, //!< mask to enable device kerning text |
agl@chromium.org | 309485b | 2009-07-21 17:41:32 +0000 | [diff] [blame] | 109 | kLCDRenderText_Flag = 0x200, //!< mask to enable subpixel glyph renderering |
agl@chromium.org | e95c91e | 2010-01-04 18:27:55 +0000 | [diff] [blame] | 110 | kEmbeddedBitmapText_Flag = 0x400, //!< mask to enable embedded bitmap strikes |
agl@chromium.org | a2c71cb | 2010-06-17 20:49:17 +0000 | [diff] [blame] | 111 | kAutoHinting_Flag = 0x800, //!< mask to force Freetype's autohinter |
reed@google.com | 830a23e | 2011-11-10 15:20:49 +0000 | [diff] [blame] | 112 | kVerticalText_Flag = 0x1000, |
reed@google.com | 8351aab | 2012-01-18 17:06:35 +0000 | [diff] [blame] | 113 | kGenA8FromLCD_Flag = 0x2000, // hack for GDI -- do not use if you can help it |
agl@chromium.org | 309485b | 2009-07-21 17:41:32 +0000 | [diff] [blame] | 114 | // when adding extra flags, note that the fFlags member is specified |
| 115 | // with a bit-width and you'll have to expand it. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 116 | |
Mike Reed | bcfb8f6 | 2017-02-23 14:19:35 +0000 | [diff] [blame] | 117 | kAllFlags = 0xFFFF, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 118 | }; |
| 119 | |
Mike Reed | ddbd37e | 2017-02-21 15:07:44 -0500 | [diff] [blame] | 120 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 121 | enum ReserveFlags { |
| 122 | // These are not used by paint, but the bits are reserved for private use by the |
| 123 | // android framework. |
| 124 | kUnderlineText_ReserveFlag = 0x08, //!< mask to enable underline text |
| 125 | kStrikeThruText_ReserveFlag = 0x10, //!< mask to enable strike-thru text |
| 126 | }; |
| 127 | #endif |
| 128 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 129 | /** Return the paint's flags. Use the Flag enum to test flag values. |
| 130 | @return the paint's flags (see enums ending in _Flag for bit masks) |
| 131 | */ |
reed | f59eab2 | 2014-07-14 14:39:15 -0700 | [diff] [blame] | 132 | uint32_t getFlags() const { return fBitfields.fFlags; } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 133 | |
| 134 | /** Set the paint's flags. Use the Flag enum to specific flag values. |
| 135 | @param flags The new flag bits for the paint (see Flags enum) |
| 136 | */ |
| 137 | void setFlags(uint32_t flags); |
| 138 | |
| 139 | /** Helper for getFlags(), returning true if kAntiAlias_Flag bit is set |
| 140 | @return true if the antialias bit is set in the paint's flags. |
| 141 | */ |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 142 | bool isAntiAlias() const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 143 | return SkToBool(this->getFlags() & kAntiAlias_Flag); |
| 144 | } |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 145 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 146 | /** Helper for setFlags(), setting or clearing the kAntiAlias_Flag bit |
| 147 | @param aa true to enable antialiasing, false to disable it |
| 148 | */ |
| 149 | void setAntiAlias(bool aa); |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 150 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 151 | /** Helper for getFlags(), returning true if kDither_Flag bit is set |
| 152 | @return true if the dithering bit is set in the paint's flags. |
| 153 | */ |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 154 | bool isDither() const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 155 | return SkToBool(this->getFlags() & kDither_Flag); |
| 156 | } |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 157 | |
Mike Reed | 4435311 | 2017-05-09 12:20:02 -0400 | [diff] [blame] | 158 | /** |
| 159 | * Helper for setFlags(), setting or clearing the kDither_Flag bit |
| 160 | * @param dither true to enable dithering, false to disable it |
| 161 | * |
| 162 | * Note: gradients ignore this setting and always dither. |
| 163 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 164 | void setDither(bool dither); |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 165 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 166 | /** Helper for getFlags(), returning true if kLinearText_Flag bit is set |
| 167 | @return true if the lineartext bit is set in the paint's flags |
| 168 | */ |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 169 | bool isLinearText() const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 170 | return SkToBool(this->getFlags() & kLinearText_Flag); |
| 171 | } |
| 172 | |
| 173 | /** Helper for setFlags(), setting or clearing the kLinearText_Flag bit |
| 174 | @param linearText true to set the linearText bit in the paint's flags, |
| 175 | false to clear it. |
| 176 | */ |
| 177 | void setLinearText(bool linearText); |
| 178 | |
| 179 | /** Helper for getFlags(), returning true if kSubpixelText_Flag bit is set |
| 180 | @return true if the lineartext bit is set in the paint's flags |
| 181 | */ |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 182 | bool isSubpixelText() const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 183 | return SkToBool(this->getFlags() & kSubpixelText_Flag); |
| 184 | } |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 185 | |
reed@google.com | 84b437e | 2011-08-01 12:45:35 +0000 | [diff] [blame] | 186 | /** |
| 187 | * Helper for setFlags(), setting or clearing the kSubpixelText_Flag. |
| 188 | * @param subpixelText true to set the subpixelText bit in the paint's |
| 189 | * flags, false to clear it. |
| 190 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 191 | void setSubpixelText(bool subpixelText); |
agl@chromium.org | 309485b | 2009-07-21 17:41:32 +0000 | [diff] [blame] | 192 | |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 193 | bool isLCDRenderText() const { |
agl@chromium.org | 309485b | 2009-07-21 17:41:32 +0000 | [diff] [blame] | 194 | return SkToBool(this->getFlags() & kLCDRenderText_Flag); |
| 195 | } |
| 196 | |
reed@google.com | 84b437e | 2011-08-01 12:45:35 +0000 | [diff] [blame] | 197 | /** |
| 198 | * Helper for setFlags(), setting or clearing the kLCDRenderText_Flag. |
| 199 | * Note: antialiasing must also be on for lcd rendering |
| 200 | * @param lcdText true to set the LCDRenderText bit in the paint's flags, |
| 201 | * false to clear it. |
| 202 | */ |
| 203 | void setLCDRenderText(bool lcdText); |
agl@chromium.org | 309485b | 2009-07-21 17:41:32 +0000 | [diff] [blame] | 204 | |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 205 | bool isEmbeddedBitmapText() const { |
agl@chromium.org | e95c91e | 2010-01-04 18:27:55 +0000 | [diff] [blame] | 206 | return SkToBool(this->getFlags() & kEmbeddedBitmapText_Flag); |
| 207 | } |
| 208 | |
| 209 | /** Helper for setFlags(), setting or clearing the kEmbeddedBitmapText_Flag bit |
| 210 | @param useEmbeddedBitmapText true to set the kEmbeddedBitmapText bit in the paint's flags, |
| 211 | false to clear it. |
| 212 | */ |
| 213 | void setEmbeddedBitmapText(bool useEmbeddedBitmapText); |
| 214 | |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 215 | bool isAutohinted() const { |
agl@chromium.org | a2c71cb | 2010-06-17 20:49:17 +0000 | [diff] [blame] | 216 | return SkToBool(this->getFlags() & kAutoHinting_Flag); |
| 217 | } |
| 218 | |
| 219 | /** Helper for setFlags(), setting or clearing the kAutoHinting_Flag bit |
| 220 | @param useAutohinter true to set the kEmbeddedBitmapText bit in the |
| 221 | paint's flags, |
| 222 | false to clear it. |
| 223 | */ |
| 224 | void setAutohinted(bool useAutohinter); |
| 225 | |
reed@google.com | 830a23e | 2011-11-10 15:20:49 +0000 | [diff] [blame] | 226 | bool isVerticalText() const { |
| 227 | return SkToBool(this->getFlags() & kVerticalText_Flag); |
| 228 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 229 | |
reed@google.com | 830a23e | 2011-11-10 15:20:49 +0000 | [diff] [blame] | 230 | /** |
| 231 | * Helper for setting or clearing the kVerticalText_Flag bit in |
| 232 | * setFlags(...). |
| 233 | * |
| 234 | * If this bit is set, then advances are treated as Y values rather than |
| 235 | * X values, and drawText will places its glyphs vertically rather than |
| 236 | * horizontally. |
| 237 | */ |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 238 | void setVerticalText(bool verticalText); |
reed@google.com | 830a23e | 2011-11-10 15:20:49 +0000 | [diff] [blame] | 239 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 240 | /** Helper for getFlags(), returns true if kFakeBoldText_Flag bit is set |
| 241 | @return true if the kFakeBoldText_Flag bit is set in the paint's flags. |
| 242 | */ |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 243 | bool isFakeBoldText() const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 244 | return SkToBool(this->getFlags() & kFakeBoldText_Flag); |
| 245 | } |
| 246 | |
| 247 | /** Helper for setFlags(), setting or clearing the kFakeBoldText_Flag bit |
| 248 | @param fakeBoldText true to set the kFakeBoldText_Flag bit in the paint's |
| 249 | flags, false to clear it. |
| 250 | */ |
| 251 | void setFakeBoldText(bool fakeBoldText); |
| 252 | |
| 253 | /** Helper for getFlags(), returns true if kDevKernText_Flag bit is set |
| 254 | @return true if the kernText bit is set in the paint's flags. |
| 255 | */ |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 256 | bool isDevKernText() const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 257 | return SkToBool(this->getFlags() & kDevKernText_Flag); |
| 258 | } |
| 259 | |
| 260 | /** Helper for setFlags(), setting or clearing the kKernText_Flag bit |
| 261 | @param kernText true to set the kKernText_Flag bit in the paint's |
| 262 | flags, false to clear it. |
| 263 | */ |
| 264 | void setDevKernText(bool devKernText); |
| 265 | |
reed | f803da1 | 2015-01-23 05:58:07 -0800 | [diff] [blame] | 266 | /** |
| 267 | * Return the filter level. This affects the quality (and performance) of |
| 268 | * drawing scaled images. |
| 269 | */ |
| 270 | SkFilterQuality getFilterQuality() const { |
| 271 | return (SkFilterQuality)fBitfields.fFilterQuality; |
| 272 | } |
mtklein | fe81e2d | 2015-09-09 07:35:42 -0700 | [diff] [blame] | 273 | |
reed | f803da1 | 2015-01-23 05:58:07 -0800 | [diff] [blame] | 274 | /** |
| 275 | * Set the filter quality. This affects the quality (and performance) of |
| 276 | * drawing scaled images. |
| 277 | */ |
| 278 | void setFilterQuality(SkFilterQuality quality); |
reed@google.com | c968315 | 2013-07-18 13:47:01 +0000 | [diff] [blame] | 279 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 280 | /** Styles apply to rect, oval, path, and text. |
| 281 | Bitmaps are always drawn in "fill", and lines are always drawn in |
| 282 | "stroke". |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 283 | |
reed@android.com | ed881c2 | 2009-09-15 14:10:42 +0000 | [diff] [blame] | 284 | Note: strokeandfill implicitly draws the result with |
| 285 | SkPath::kWinding_FillType, so if the original path is even-odd, the |
| 286 | results may not appear the same as if it was drawn twice, filled and |
| 287 | then stroked. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 288 | */ |
| 289 | enum Style { |
reed@android.com | ed881c2 | 2009-09-15 14:10:42 +0000 | [diff] [blame] | 290 | kFill_Style, //!< fill the geometry |
| 291 | kStroke_Style, //!< stroke the geometry |
| 292 | kStrokeAndFill_Style, //!< fill and stroke the geometry |
mike@reedtribe.org | aac2fb8 | 2013-02-04 05:17:10 +0000 | [diff] [blame] | 293 | }; |
| 294 | enum { |
| 295 | kStyleCount = kStrokeAndFill_Style + 1 |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 296 | }; |
| 297 | |
| 298 | /** Return the paint's style, used for controlling how primitives' |
| 299 | geometries are interpreted (except for drawBitmap, which always assumes |
| 300 | kFill_Style). |
| 301 | @return the paint's Style |
| 302 | */ |
reed | f59eab2 | 2014-07-14 14:39:15 -0700 | [diff] [blame] | 303 | Style getStyle() const { return (Style)fBitfields.fStyle; } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 304 | |
| 305 | /** Set the paint's style, used for controlling how primitives' |
| 306 | geometries are interpreted (except for drawBitmap, which always assumes |
| 307 | Fill). |
| 308 | @param style The new style to set in the paint |
| 309 | */ |
| 310 | void setStyle(Style style); |
| 311 | |
| 312 | /** Return the paint's color. Note that the color is a 32bit value |
| 313 | containing alpha as well as r,g,b. This 32bit value is not |
| 314 | premultiplied, meaning that its alpha can be any value, regardless of |
| 315 | the values of r,g,b. |
| 316 | @return the paint's color (and alpha). |
| 317 | */ |
| 318 | SkColor getColor() const { return fColor; } |
| 319 | |
| 320 | /** Set the paint's color. Note that the color is a 32bit value containing |
| 321 | alpha as well as r,g,b. This 32bit value is not premultiplied, meaning |
| 322 | that its alpha can be any value, regardless of the values of r,g,b. |
| 323 | @param color The new color (including alpha) to set in the paint. |
| 324 | */ |
| 325 | void setColor(SkColor color); |
| 326 | |
| 327 | /** Helper to getColor() that just returns the color's alpha value. |
| 328 | @return the alpha component of the paint's color. |
| 329 | */ |
| 330 | uint8_t getAlpha() const { return SkToU8(SkColorGetA(fColor)); } |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 331 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 332 | /** Helper to setColor(), that only assigns the color's alpha value, |
| 333 | leaving its r,g,b values unchanged. |
| 334 | @param a set the alpha component (0..255) of the paint's color. |
| 335 | */ |
| 336 | void setAlpha(U8CPU a); |
| 337 | |
| 338 | /** Helper to setColor(), that takes a,r,g,b and constructs the color value |
| 339 | using SkColorSetARGB() |
| 340 | @param a The new alpha component (0..255) of the paint's color. |
| 341 | @param r The new red component (0..255) of the paint's color. |
| 342 | @param g The new green component (0..255) of the paint's color. |
| 343 | @param b The new blue component (0..255) of the paint's color. |
| 344 | */ |
| 345 | void setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b); |
| 346 | |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 347 | /** Return the width for stroking. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 348 | <p /> |
| 349 | A value of 0 strokes in hairline mode. |
| 350 | Hairlines always draw 1-pixel wide, regardless of the matrix. |
| 351 | @return the paint's stroke width, used whenever the paint's style is |
| 352 | Stroke or StrokeAndFill. |
| 353 | */ |
| 354 | SkScalar getStrokeWidth() const { return fWidth; } |
| 355 | |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 356 | /** Set the width for stroking. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 357 | Pass 0 to stroke in hairline mode. |
| 358 | Hairlines always draw 1-pixel wide, regardless of the matrix. |
| 359 | @param width set the paint's stroke width, used whenever the paint's |
| 360 | style is Stroke or StrokeAndFill. |
| 361 | */ |
| 362 | void setStrokeWidth(SkScalar width); |
| 363 | |
| 364 | /** Return the paint's stroke miter value. This is used to control the |
| 365 | behavior of miter joins when the joins angle is sharp. |
| 366 | @return the paint's miter limit, used whenever the paint's style is |
| 367 | Stroke or StrokeAndFill. |
| 368 | */ |
| 369 | SkScalar getStrokeMiter() const { return fMiterLimit; } |
| 370 | |
| 371 | /** Set the paint's stroke miter value. This is used to control the |
| 372 | behavior of miter joins when the joins angle is sharp. This value must |
| 373 | be >= 0. |
| 374 | @param miter set the miter limit on the paint, used whenever the |
| 375 | paint's style is Stroke or StrokeAndFill. |
| 376 | */ |
| 377 | void setStrokeMiter(SkScalar miter); |
| 378 | |
| 379 | /** Cap enum specifies the settings for the paint's strokecap. This is the |
| 380 | treatment that is applied to the beginning and end of each non-closed |
| 381 | contour (e.g. lines). |
caryclark | 5cb00a9 | 2015-08-26 09:04:55 -0700 | [diff] [blame] | 382 | |
| 383 | If the cap is round or square, the caps are drawn when the contour has |
| 384 | a zero length. Zero length contours can be created by following moveTo |
| 385 | with a lineTo at the same point, or a moveTo followed by a close. |
| 386 | |
| 387 | A dash with an on interval of zero also creates a zero length contour. |
| 388 | |
| 389 | The zero length contour draws the square cap without rotation, since |
| 390 | the no direction can be inferred. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 391 | */ |
| 392 | enum Cap { |
| 393 | kButt_Cap, //!< begin/end contours with no extension |
| 394 | kRound_Cap, //!< begin/end contours with a semi-circle extension |
| 395 | kSquare_Cap, //!< begin/end contours with a half square extension |
| 396 | |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 397 | kLast_Cap = kSquare_Cap, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 398 | kDefault_Cap = kButt_Cap |
| 399 | }; |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 400 | static constexpr int kCapCount = kLast_Cap + 1; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 401 | |
| 402 | /** Join enum specifies the settings for the paint's strokejoin. This is |
| 403 | the treatment that is applied to corners in paths and rectangles. |
| 404 | */ |
| 405 | enum Join { |
| 406 | kMiter_Join, //!< connect path segments with a sharp join |
| 407 | kRound_Join, //!< connect path segments with a round join |
| 408 | kBevel_Join, //!< connect path segments with a flat bevel join |
| 409 | |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 410 | kLast_Join = kBevel_Join, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 411 | kDefault_Join = kMiter_Join |
| 412 | }; |
bsalomon | a7d85ba | 2016-07-06 11:54:59 -0700 | [diff] [blame] | 413 | static constexpr int kJoinCount = kLast_Join + 1; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 414 | |
| 415 | /** Return the paint's stroke cap type, controlling how the start and end |
| 416 | of stroked lines and paths are treated. |
| 417 | @return the line cap style for the paint, used whenever the paint's |
| 418 | style is Stroke or StrokeAndFill. |
| 419 | */ |
reed | f59eab2 | 2014-07-14 14:39:15 -0700 | [diff] [blame] | 420 | Cap getStrokeCap() const { return (Cap)fBitfields.fCapType; } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 421 | |
| 422 | /** Set the paint's stroke cap type. |
| 423 | @param cap set the paint's line cap style, used whenever the paint's |
| 424 | style is Stroke or StrokeAndFill. |
| 425 | */ |
| 426 | void setStrokeCap(Cap cap); |
| 427 | |
| 428 | /** Return the paint's stroke join type. |
| 429 | @return the paint's line join style, used whenever the paint's style is |
| 430 | Stroke or StrokeAndFill. |
| 431 | */ |
reed | f59eab2 | 2014-07-14 14:39:15 -0700 | [diff] [blame] | 432 | Join getStrokeJoin() const { return (Join)fBitfields.fJoinType; } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 433 | |
| 434 | /** Set the paint's stroke join type. |
| 435 | @param join set the paint's line join style, used whenever the paint's |
| 436 | style is Stroke or StrokeAndFill. |
| 437 | */ |
| 438 | void setStrokeJoin(Join join); |
| 439 | |
reed@google.com | 4bbdeac | 2013-01-24 21:03:11 +0000 | [diff] [blame] | 440 | /** |
| 441 | * Applies any/all effects (patheffect, stroking) to src, returning the |
| 442 | * result in dst. The result is that drawing src with this paint will be |
| 443 | * the same as drawing dst with a default paint (at least from the |
| 444 | * geometric perspective). |
| 445 | * |
| 446 | * @param src input path |
| 447 | * @param dst output path (may be the same as src) |
| 448 | * @param cullRect If not null, the dst path may be culled to this rect. |
reed | 05d9044 | 2015-02-12 13:35:52 -0800 | [diff] [blame] | 449 | * @param resScale If > 1, increase precision, else if (0 < res < 1) reduce precision |
| 450 | * in favor of speed/size. |
reed@google.com | 4bbdeac | 2013-01-24 21:03:11 +0000 | [diff] [blame] | 451 | * @return true if the path should be filled, or false if it should be |
| 452 | * drawn with a hairline (width == 0) |
| 453 | */ |
reed | 05d9044 | 2015-02-12 13:35:52 -0800 | [diff] [blame] | 454 | bool getFillPath(const SkPath& src, SkPath* dst, const SkRect* cullRect, |
| 455 | SkScalar resScale = 1) const; |
| 456 | |
| 457 | bool getFillPath(const SkPath& src, SkPath* dst) const { |
| 458 | return this->getFillPath(src, dst, NULL, 1); |
| 459 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 460 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 461 | /** Get the paint's shader object. |
| 462 | <p /> |
| 463 | The shader's reference count is not affected. |
| 464 | @return the paint's shader (or NULL) |
| 465 | */ |
reed | a5ab9ec | 2016-03-06 18:10:48 -0800 | [diff] [blame] | 466 | SkShader* getShader() const { return fShader.get(); } |
Mike Reed | 693fdbd | 2017-01-12 10:13:40 -0500 | [diff] [blame] | 467 | sk_sp<SkShader> refShader() const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 468 | |
| 469 | /** Set or clear the shader object. |
reed@google.com | 880dc47 | 2012-05-11 14:47:03 +0000 | [diff] [blame] | 470 | * Shaders specify the source color(s) for what is being drawn. If a paint |
| 471 | * has no shader, then the paint's color is used. If the paint has a |
| 472 | * shader, then the shader's color(s) are use instead, but they are |
| 473 | * modulated by the paint's alpha. This makes it easy to create a shader |
| 474 | * once (e.g. bitmap tiling or gradient) and then change its transparency |
| 475 | * w/o having to modify the original shader... only the paint's alpha needs |
| 476 | * to be modified. |
commit-bot@chromium.org | e5957f6 | 2014-03-18 16:28:12 +0000 | [diff] [blame] | 477 | * |
| 478 | * There is an exception to this only-respect-paint's-alpha rule: If the shader only generates |
| 479 | * alpha (e.g. SkShader::CreateBitmapShader(bitmap, ...) where bitmap's colortype is kAlpha_8) |
| 480 | * then the shader will use the paint's entire color to "colorize" its output (modulating the |
| 481 | * bitmap's alpha with the paint's color+alpha). |
| 482 | * |
reed@google.com | 880dc47 | 2012-05-11 14:47:03 +0000 | [diff] [blame] | 483 | * Pass NULL to clear any previous shader. |
| 484 | * As a convenience, the parameter passed is also returned. |
| 485 | * If a previous shader exists, its reference count is decremented. |
| 486 | * If shader is not NULL, its reference count is incremented. |
| 487 | * @param shader May be NULL. The shader to be installed in the paint |
reed@google.com | 880dc47 | 2012-05-11 14:47:03 +0000 | [diff] [blame] | 488 | */ |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 489 | void setShader(sk_sp<SkShader> shader); |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 490 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 491 | /** Get the paint's colorfilter. If there is a colorfilter, its reference |
| 492 | count is not changed. |
| 493 | @return the paint's colorfilter (or NULL) |
| 494 | */ |
reed | a5ab9ec | 2016-03-06 18:10:48 -0800 | [diff] [blame] | 495 | SkColorFilter* getColorFilter() const { return fColorFilter.get(); } |
Mike Reed | 693fdbd | 2017-01-12 10:13:40 -0500 | [diff] [blame] | 496 | sk_sp<SkColorFilter> refColorFilter() const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 497 | |
Mike Reed | 958788a | 2016-10-20 16:40:26 -0400 | [diff] [blame] | 498 | /** Set or clear the paint's colorfilter. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 499 | <p /> |
| 500 | If the paint already has a filter, its reference count is decremented. |
| 501 | If filter is not NULL, its reference count is incremented. |
| 502 | @param filter May be NULL. The filter to be installed in the paint |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 503 | */ |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 504 | void setColorFilter(sk_sp<SkColorFilter> colorFilter); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 505 | |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 506 | SkBlendMode getBlendMode() const { return (SkBlendMode)fBlendMode; } |
| 507 | bool isSrcOver() const { return (SkBlendMode)fBlendMode == SkBlendMode::kSrcOver; } |
| 508 | void setBlendMode(SkBlendMode mode) { fBlendMode = (unsigned)mode; } |
reed@android.com | a0f5d15 | 2009-06-22 17:38:10 +0000 | [diff] [blame] | 509 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 510 | /** Get the paint's patheffect object. |
| 511 | <p /> |
| 512 | The patheffect reference count is not affected. |
| 513 | @return the paint's patheffect (or NULL) |
| 514 | */ |
reed | a5ab9ec | 2016-03-06 18:10:48 -0800 | [diff] [blame] | 515 | SkPathEffect* getPathEffect() const { return fPathEffect.get(); } |
Mike Reed | 693fdbd | 2017-01-12 10:13:40 -0500 | [diff] [blame] | 516 | sk_sp<SkPathEffect> refPathEffect() const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 517 | |
| 518 | /** Set or clear the patheffect object. |
| 519 | <p /> |
| 520 | Pass NULL to clear any previous patheffect. |
| 521 | As a convenience, the parameter passed is also returned. |
| 522 | If a previous patheffect exists, its reference count is decremented. |
| 523 | If patheffect is not NULL, its reference count is incremented. |
| 524 | @param effect May be NULL. The new patheffect to be installed in the |
| 525 | paint |
| 526 | @return effect |
| 527 | */ |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 528 | void setPathEffect(sk_sp<SkPathEffect> pathEffect); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 529 | |
| 530 | /** Get the paint's maskfilter object. |
| 531 | <p /> |
| 532 | The maskfilter reference count is not affected. |
| 533 | @return the paint's maskfilter (or NULL) |
| 534 | */ |
reed | a5ab9ec | 2016-03-06 18:10:48 -0800 | [diff] [blame] | 535 | SkMaskFilter* getMaskFilter() const { return fMaskFilter.get(); } |
Mike Reed | 693fdbd | 2017-01-12 10:13:40 -0500 | [diff] [blame] | 536 | sk_sp<SkMaskFilter> refMaskFilter() const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 537 | |
| 538 | /** Set or clear the maskfilter object. |
| 539 | <p /> |
| 540 | Pass NULL to clear any previous maskfilter. |
| 541 | As a convenience, the parameter passed is also returned. |
| 542 | If a previous maskfilter exists, its reference count is decremented. |
| 543 | If maskfilter is not NULL, its reference count is incremented. |
| 544 | @param maskfilter May be NULL. The new maskfilter to be installed in |
| 545 | the paint |
| 546 | @return maskfilter |
| 547 | */ |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 548 | void setMaskFilter(sk_sp<SkMaskFilter> maskFilter); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 549 | |
| 550 | // These attributes are for text/fonts |
| 551 | |
| 552 | /** Get the paint's typeface object. |
| 553 | <p /> |
| 554 | The typeface object identifies which font to use when drawing or |
| 555 | measuring text. The typeface reference count is not affected. |
| 556 | @return the paint's typeface (or NULL) |
| 557 | */ |
reed | a5ab9ec | 2016-03-06 18:10:48 -0800 | [diff] [blame] | 558 | SkTypeface* getTypeface() const { return fTypeface.get(); } |
Mike Reed | 693fdbd | 2017-01-12 10:13:40 -0500 | [diff] [blame] | 559 | sk_sp<SkTypeface> refTypeface() const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 560 | |
| 561 | /** Set or clear the typeface object. |
| 562 | <p /> |
| 563 | Pass NULL to clear any previous typeface. |
| 564 | As a convenience, the parameter passed is also returned. |
| 565 | If a previous typeface exists, its reference count is decremented. |
| 566 | If typeface is not NULL, its reference count is incremented. |
| 567 | @param typeface May be NULL. The new typeface to be installed in the |
| 568 | paint |
| 569 | @return typeface |
| 570 | */ |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 571 | void setTypeface(sk_sp<SkTypeface> typeface); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 572 | |
| 573 | /** Get the paint's rasterizer (or NULL). |
| 574 | <p /> |
| 575 | The raster controls how paths/text are turned into alpha masks. |
| 576 | @return the paint's rasterizer (or NULL) |
| 577 | */ |
reed | a5ab9ec | 2016-03-06 18:10:48 -0800 | [diff] [blame] | 578 | SkRasterizer* getRasterizer() const { return fRasterizer.get(); } |
Mike Reed | 693fdbd | 2017-01-12 10:13:40 -0500 | [diff] [blame] | 579 | sk_sp<SkRasterizer> refRasterizer() const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 580 | |
| 581 | /** Set or clear the rasterizer object. |
| 582 | <p /> |
| 583 | Pass NULL to clear any previous rasterizer. |
| 584 | As a convenience, the parameter passed is also returned. |
| 585 | If a previous rasterizer exists in the paint, its reference count is |
| 586 | decremented. If rasterizer is not NULL, its reference count is |
| 587 | incremented. |
| 588 | @param rasterizer May be NULL. The new rasterizer to be installed in |
| 589 | the paint. |
| 590 | @return rasterizer |
| 591 | */ |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 592 | void setRasterizer(sk_sp<SkRasterizer> rasterizer); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 593 | |
reed | a5ab9ec | 2016-03-06 18:10:48 -0800 | [diff] [blame] | 594 | SkImageFilter* getImageFilter() const { return fImageFilter.get(); } |
Mike Reed | 693fdbd | 2017-01-12 10:13:40 -0500 | [diff] [blame] | 595 | sk_sp<SkImageFilter> refImageFilter() const; |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 596 | void setImageFilter(sk_sp<SkImageFilter> imageFilter); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 597 | |
reed@google.com | b0a34d8 | 2012-07-11 19:57:55 +0000 | [diff] [blame] | 598 | /** |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 599 | * Return the paint's SkDrawLooper (if any). Does not affect the looper's |
| 600 | * reference count. |
| 601 | */ |
reed | 46f2d0a | 2016-09-11 05:40:31 -0700 | [diff] [blame] | 602 | SkDrawLooper* getDrawLooper() const { return fDrawLooper.get(); } |
Mike Reed | 693fdbd | 2017-01-12 10:13:40 -0500 | [diff] [blame] | 603 | sk_sp<SkDrawLooper> refDrawLooper() const; |
| 604 | |
reed | 46f2d0a | 2016-09-11 05:40:31 -0700 | [diff] [blame] | 605 | SkDrawLooper* getLooper() const { return fDrawLooper.get(); } |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 606 | /** |
| 607 | * Set or clear the looper object. |
| 608 | * <p /> |
| 609 | * Pass NULL to clear any previous looper. |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 610 | * If a previous looper exists in the paint, its reference count is |
| 611 | * decremented. If looper is not NULL, its reference count is |
| 612 | * incremented. |
| 613 | * @param looper May be NULL. The new looper to be installed in the paint. |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 614 | */ |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 615 | void setDrawLooper(sk_sp<SkDrawLooper> drawLooper); |
Mike Reed | 09d9435 | 2016-10-31 15:11:04 -0400 | [diff] [blame] | 616 | |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 617 | void setLooper(sk_sp<SkDrawLooper> drawLooper); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 618 | |
| 619 | enum Align { |
| 620 | kLeft_Align, |
| 621 | kCenter_Align, |
| 622 | kRight_Align, |
mike@reedtribe.org | ddc813b | 2013-06-08 12:58:19 +0000 | [diff] [blame] | 623 | }; |
| 624 | enum { |
| 625 | kAlignCount = 3 |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 626 | }; |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 627 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 628 | /** Return the paint's Align value for drawing text. |
| 629 | @return the paint's Align value for drawing text. |
| 630 | */ |
reed | f59eab2 | 2014-07-14 14:39:15 -0700 | [diff] [blame] | 631 | Align getTextAlign() const { return (Align)fBitfields.fTextAlign; } |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 632 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 633 | /** Set the paint's text alignment. |
| 634 | @param align set the paint's Align value for drawing text. |
| 635 | */ |
| 636 | void setTextAlign(Align align); |
| 637 | |
| 638 | /** Return the paint's text size. |
| 639 | @return the paint's text size. |
| 640 | */ |
| 641 | SkScalar getTextSize() const { return fTextSize; } |
| 642 | |
| 643 | /** Set the paint's text size. This value must be > 0 |
| 644 | @param textSize set the paint's text size. |
| 645 | */ |
| 646 | void setTextSize(SkScalar textSize); |
| 647 | |
| 648 | /** Return the paint's horizontal scale factor for text. The default value |
| 649 | is 1.0. |
| 650 | @return the paint's scale factor in X for drawing/measuring text |
| 651 | */ |
| 652 | SkScalar getTextScaleX() const { return fTextScaleX; } |
| 653 | |
| 654 | /** Set the paint's horizontal scale factor for text. The default value |
| 655 | is 1.0. Values > 1.0 will stretch the text wider. Values < 1.0 will |
| 656 | stretch the text narrower. |
| 657 | @param scaleX set the paint's scale factor in X for drawing/measuring |
| 658 | text. |
| 659 | */ |
| 660 | void setTextScaleX(SkScalar scaleX); |
| 661 | |
| 662 | /** Return the paint's horizontal skew factor for text. The default value |
| 663 | is 0. |
| 664 | @return the paint's skew factor in X for drawing text. |
| 665 | */ |
| 666 | SkScalar getTextSkewX() const { return fTextSkewX; } |
| 667 | |
| 668 | /** Set the paint's horizontal skew factor for text. The default value |
| 669 | is 0. For approximating oblique text, use values around -0.25. |
| 670 | @param skewX set the paint's skew factor in X for drawing text. |
| 671 | */ |
| 672 | void setTextSkewX(SkScalar skewX); |
| 673 | |
| 674 | /** Describes how to interpret the text parameters that are passed to paint |
| 675 | methods like measureText() and getTextWidths(). |
| 676 | */ |
| 677 | enum TextEncoding { |
| 678 | kUTF8_TextEncoding, //!< the text parameters are UTF8 |
| 679 | kUTF16_TextEncoding, //!< the text parameters are UTF16 |
robertphillips@google.com | 6970557 | 2012-03-21 19:46:50 +0000 | [diff] [blame] | 680 | kUTF32_TextEncoding, //!< the text parameters are UTF32 |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 681 | kGlyphID_TextEncoding //!< the text parameters are glyph indices |
| 682 | }; |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 683 | |
reed | f59eab2 | 2014-07-14 14:39:15 -0700 | [diff] [blame] | 684 | TextEncoding getTextEncoding() const { |
| 685 | return (TextEncoding)fBitfields.fTextEncoding; |
| 686 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 687 | |
| 688 | void setTextEncoding(TextEncoding encoding); |
| 689 | |
| 690 | struct FontMetrics { |
commit-bot@chromium.org | 0bc406d | 2014-03-01 20:12:26 +0000 | [diff] [blame] | 691 | /** Flags which indicate the confidence level of various metrics. |
| 692 | A set flag indicates that the metric may be trusted. |
| 693 | */ |
| 694 | enum FontMetricsFlags { |
Ben Wagner | 3318da5 | 2017-03-23 14:01:22 -0400 | [diff] [blame] | 695 | kUnderlineThicknessIsValid_Flag = 1 << 0, |
commit-bot@chromium.org | 0bc406d | 2014-03-01 20:12:26 +0000 | [diff] [blame] | 696 | kUnderlinePositionIsValid_Flag = 1 << 1, |
Ben Wagner | 219f362 | 2017-07-17 15:32:25 -0400 | [diff] [blame^] | 697 | kStrikeoutThicknessIsValid_Flag = 1 << 2, |
| 698 | kStrikeoutPositionIsValid_Flag = 1 << 3, |
commit-bot@chromium.org | 0bc406d | 2014-03-01 20:12:26 +0000 | [diff] [blame] | 699 | }; |
| 700 | |
| 701 | uint32_t fFlags; //!< Bit field to identify which values are unknown |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 702 | SkScalar fTop; //!< The greatest distance above the baseline for any glyph (will be <= 0) |
| 703 | SkScalar fAscent; //!< The recommended distance above the baseline (will be <= 0) |
| 704 | SkScalar fDescent; //!< The recommended distance below the baseline (will be >= 0) |
| 705 | SkScalar fBottom; //!< The greatest distance below the baseline for any glyph (will be >= 0) |
| 706 | SkScalar fLeading; //!< The recommended distance to add between lines of text (will be >= 0) |
commit-bot@chromium.org | 0bc406d | 2014-03-01 20:12:26 +0000 | [diff] [blame] | 707 | SkScalar fAvgCharWidth; //!< the average character width (>= 0) |
| 708 | SkScalar fMaxCharWidth; //!< the max character width (>= 0) |
agl@chromium.org | cc3096b | 2009-04-22 22:09:04 +0000 | [diff] [blame] | 709 | SkScalar fXMin; //!< The minimum bounding box x value for all glyphs |
| 710 | SkScalar fXMax; //!< The maximum bounding box x value for all glyphs |
bungeman@google.com | cbe1b54 | 2013-12-16 17:02:39 +0000 | [diff] [blame] | 711 | SkScalar fXHeight; //!< The height of an 'x' in px, or 0 if no 'x' in face |
| 712 | SkScalar fCapHeight; //!< The cap height (> 0), or 0 if cannot be determined. |
commit-bot@chromium.org | 0bc406d | 2014-03-01 20:12:26 +0000 | [diff] [blame] | 713 | SkScalar fUnderlineThickness; //!< underline thickness, or 0 if cannot be determined |
| 714 | |
Ben Wagner | 219f362 | 2017-07-17 15:32:25 -0400 | [diff] [blame^] | 715 | /** Position of the top of the underline stroke relative to the baseline. |
| 716 | * A positive value means draw below the baseline; negative values above. |
commit-bot@chromium.org | 0bc406d | 2014-03-01 20:12:26 +0000 | [diff] [blame] | 717 | */ |
Ben Wagner | 219f362 | 2017-07-17 15:32:25 -0400 | [diff] [blame^] | 718 | SkScalar fUnderlinePosition; |
commit-bot@chromium.org | 0bc406d | 2014-03-01 20:12:26 +0000 | [diff] [blame] | 719 | |
Ben Wagner | 219f362 | 2017-07-17 15:32:25 -0400 | [diff] [blame^] | 720 | SkScalar fStrikeoutThickness; //!< strikeout thickness, or 0 if cannot be determined |
| 721 | |
| 722 | /** Position of the bottom of the strikeout stroke relative to the baseline. |
| 723 | * A positive value means draw below the baseline; negative values above. |
| 724 | */ |
| 725 | SkScalar fStrikeoutPosition; |
| 726 | |
| 727 | /** If the underline thickness is valid return true and set thickness. |
| 728 | * Otherwise return false and ignore the thickness param. |
| 729 | */ |
commit-bot@chromium.org | 0bc406d | 2014-03-01 20:12:26 +0000 | [diff] [blame] | 730 | bool hasUnderlineThickness(SkScalar* thickness) const { |
Ben Wagner | 3318da5 | 2017-03-23 14:01:22 -0400 | [diff] [blame] | 731 | if (SkToBool(fFlags & kUnderlineThicknessIsValid_Flag)) { |
commit-bot@chromium.org | 0bc406d | 2014-03-01 20:12:26 +0000 | [diff] [blame] | 732 | *thickness = fUnderlineThickness; |
| 733 | return true; |
| 734 | } |
| 735 | return false; |
| 736 | } |
| 737 | |
Ben Wagner | 219f362 | 2017-07-17 15:32:25 -0400 | [diff] [blame^] | 738 | /** If the underline position is valid return true and set position. |
| 739 | * Otherwise return false and ignore the position param. |
| 740 | */ |
commit-bot@chromium.org | 0bc406d | 2014-03-01 20:12:26 +0000 | [diff] [blame] | 741 | bool hasUnderlinePosition(SkScalar* position) const { |
| 742 | if (SkToBool(fFlags & kUnderlinePositionIsValid_Flag)) { |
| 743 | *position = fUnderlinePosition; |
| 744 | return true; |
| 745 | } |
| 746 | return false; |
| 747 | } |
| 748 | |
Ben Wagner | 219f362 | 2017-07-17 15:32:25 -0400 | [diff] [blame^] | 749 | /** If the strikeout thickness is valid return true and set thickness. |
| 750 | * Otherwise return false and ignore the thickness param. |
| 751 | */ |
| 752 | bool hasStrikeoutThickness(SkScalar* thickness) const { |
| 753 | if (SkToBool(fFlags & kStrikeoutThicknessIsValid_Flag)) { |
| 754 | *thickness = fStrikeoutThickness; |
| 755 | return true; |
| 756 | } |
| 757 | return false; |
| 758 | } |
| 759 | |
| 760 | /** If the strikeout position is valid return true and set position. |
| 761 | * Otherwise return false and ignore the position param. |
| 762 | */ |
| 763 | bool hasStrikeoutPosition(SkScalar* position) const { |
| 764 | if (SkToBool(fFlags & kStrikeoutPositionIsValid_Flag)) { |
| 765 | *position = fStrikeoutPosition; |
| 766 | return true; |
| 767 | } |
| 768 | return false; |
| 769 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 770 | }; |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 771 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 772 | /** Return the recommend spacing between lines (which will be |
| 773 | fDescent - fAscent + fLeading). |
| 774 | If metrics is not null, return in it the font metrics for the |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 775 | typeface/pointsize/etc. currently set in the paint. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 776 | @param metrics If not null, returns the font metrics for the |
| 777 | current typeface/pointsize/etc setting in this |
| 778 | paint. |
| 779 | @param scale If not 0, return width as if the canvas were scaled |
| 780 | by this value |
| 781 | @param return the recommended spacing between lines |
| 782 | */ |
| 783 | SkScalar getFontMetrics(FontMetrics* metrics, SkScalar scale = 0) const; |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 784 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 785 | /** Return the recommend line spacing. This will be |
| 786 | fDescent - fAscent + fLeading |
| 787 | */ |
| 788 | SkScalar getFontSpacing() const { return this->getFontMetrics(NULL, 0); } |
| 789 | |
| 790 | /** Convert the specified text into glyph IDs, returning the number of |
| 791 | glyphs ID written. If glyphs is NULL, it is ignore and only the count |
| 792 | is returned. |
| 793 | */ |
| 794 | int textToGlyphs(const void* text, size_t byteLength, |
halcanary | d0e95a5 | 2016-07-25 07:18:12 -0700 | [diff] [blame] | 795 | SkGlyphID glyphs[]) const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 796 | |
reed@android.com | a5dcaf6 | 2010-02-05 17:12:32 +0000 | [diff] [blame] | 797 | /** Return true if all of the specified text has a corresponding non-zero |
| 798 | glyph ID. If any of the code-points in the text are not supported in |
| 799 | the typeface (i.e. the glyph ID would be zero), then return false. |
| 800 | |
| 801 | If the text encoding for the paint is kGlyph_TextEncoding, then this |
| 802 | returns true if all of the specified glyph IDs are non-zero. |
| 803 | */ |
| 804 | bool containsText(const void* text, size_t byteLength) const; |
| 805 | |
reed@android.com | 9d3a985 | 2010-01-08 14:07:42 +0000 | [diff] [blame] | 806 | /** Convert the glyph array into Unichars. Unconvertable glyphs are mapped |
| 807 | to zero. Note: this does not look at the text-encoding setting in the |
| 808 | paint, only at the typeface. |
| 809 | */ |
halcanary | d0e95a5 | 2016-07-25 07:18:12 -0700 | [diff] [blame] | 810 | void glyphsToUnichars(const SkGlyphID glyphs[], int count, SkUnichar text[]) const; |
reed@android.com | 9d3a985 | 2010-01-08 14:07:42 +0000 | [diff] [blame] | 811 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 812 | /** Return the number of drawable units in the specified text buffer. |
| 813 | This looks at the current TextEncoding field of the paint. If you also |
| 814 | want to have the text converted into glyph IDs, call textToGlyphs |
| 815 | instead. |
| 816 | */ |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 817 | int countText(const void* text, size_t byteLength) const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 818 | return this->textToGlyphs(text, byteLength, NULL); |
| 819 | } |
| 820 | |
reed@google.com | 44da42e | 2011-11-10 20:04:47 +0000 | [diff] [blame] | 821 | /** Return the width of the text. This will return the vertical measure |
| 822 | * if isVerticalText() is true, in which case the returned value should |
| 823 | * be treated has a height instead of a width. |
| 824 | * |
| 825 | * @param text The text to be measured |
| 826 | * @param length Number of bytes of text to measure |
| 827 | * @param bounds If not NULL, returns the bounds of the text, |
| 828 | * relative to (0, 0). |
reed@google.com | 44da42e | 2011-11-10 20:04:47 +0000 | [diff] [blame] | 829 | * @return The advance width of the text |
| 830 | */ |
reed | 99ae881 | 2014-08-26 11:30:01 -0700 | [diff] [blame] | 831 | SkScalar measureText(const void* text, size_t length, SkRect* bounds) const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 832 | |
reed@google.com | 44da42e | 2011-11-10 20:04:47 +0000 | [diff] [blame] | 833 | /** Return the width of the text. This will return the vertical measure |
| 834 | * if isVerticalText() is true, in which case the returned value should |
| 835 | * be treated has a height instead of a width. |
| 836 | * |
| 837 | * @param text Address of the text |
| 838 | * @param length Number of bytes of text to measure |
reed@google.com | 97ecd1d | 2012-05-15 19:25:17 +0000 | [diff] [blame] | 839 | * @return The advance width of the text |
reed@google.com | 44da42e | 2011-11-10 20:04:47 +0000 | [diff] [blame] | 840 | */ |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 841 | SkScalar measureText(const void* text, size_t length) const { |
reed | 99ae881 | 2014-08-26 11:30:01 -0700 | [diff] [blame] | 842 | return this->measureText(text, length, NULL); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 843 | } |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 844 | |
reed@google.com | 44da42e | 2011-11-10 20:04:47 +0000 | [diff] [blame] | 845 | /** Return the number of bytes of text that were measured. If |
| 846 | * isVerticalText() is true, then the vertical advances are used for |
| 847 | * the measurement. |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 848 | * |
reed@google.com | 44da42e | 2011-11-10 20:04:47 +0000 | [diff] [blame] | 849 | * @param text The text to be measured |
| 850 | * @param length Number of bytes of text to measure |
| 851 | * @param maxWidth Maximum width. Only the subset of text whose accumulated |
| 852 | * widths are <= maxWidth are measured. |
| 853 | * @param measuredWidth Optional. If non-null, this returns the actual |
| 854 | * width of the measured text. |
reed@google.com | 44da42e | 2011-11-10 20:04:47 +0000 | [diff] [blame] | 855 | * @return The number of bytes of text that were measured. Will be |
| 856 | * <= length. |
| 857 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 858 | size_t breakText(const void* text, size_t length, SkScalar maxWidth, |
reed | 9e96aa0 | 2014-10-03 12:44:37 -0700 | [diff] [blame] | 859 | SkScalar* measuredWidth = NULL) const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 860 | |
reed@google.com | 44da42e | 2011-11-10 20:04:47 +0000 | [diff] [blame] | 861 | /** Return the advances for the text. These will be vertical advances if |
| 862 | * isVerticalText() returns true. |
| 863 | * |
| 864 | * @param text the text |
| 865 | * @param byteLength number of bytes to of text |
| 866 | * @param widths If not null, returns the array of advances for |
| 867 | * the glyphs. If not NULL, must be at least a large |
| 868 | * as the number of unichars in the specified text. |
| 869 | * @param bounds If not null, returns the bounds for each of |
| 870 | * character, relative to (0, 0) |
| 871 | * @return the number of unichars in the specified text. |
| 872 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 873 | int getTextWidths(const void* text, size_t byteLength, SkScalar widths[], |
| 874 | SkRect bounds[] = NULL) const; |
| 875 | |
| 876 | /** Return the path (outline) for the specified text. |
caryclark | 0449bcf | 2016-02-09 13:25:45 -0800 | [diff] [blame] | 877 | * Note: just like SkCanvas::drawText, this will respect the Align setting |
| 878 | * in the paint. |
| 879 | * |
| 880 | * @param text the text |
| 881 | * @param length number of bytes of text |
| 882 | * @param x The x-coordinate of the origin of the text. |
| 883 | * @param y The y-coordinate of the origin of the text. |
| 884 | * @param path The outline of the text. |
| 885 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 886 | void getTextPath(const void* text, size_t length, SkScalar x, SkScalar y, |
| 887 | SkPath* path) const; |
| 888 | |
caryclark | 0449bcf | 2016-02-09 13:25:45 -0800 | [diff] [blame] | 889 | /** Return the path (outline) for the specified text. |
| 890 | * Note: just like SkCanvas::drawText, this will respect the Align setting |
| 891 | * in the paint. |
| 892 | * |
| 893 | * @param text the text |
| 894 | * @param length number of bytes of text |
| 895 | * @param pos array of positions, used to position each character |
| 896 | * @param path The outline of the text. |
| 897 | */ |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 898 | void getPosTextPath(const void* text, size_t length, |
reed@google.com | ca0062e | 2012-07-20 11:20:32 +0000 | [diff] [blame] | 899 | const SkPoint pos[], SkPath* path) const; |
| 900 | |
caryclark | 0449bcf | 2016-02-09 13:25:45 -0800 | [diff] [blame] | 901 | /** Return the number of intervals that intersect the intercept along the axis of the advance. |
| 902 | * The return count is zero or a multiple of two, and is at most the number of glyphs * 2 in |
| 903 | * the string. The caller may pass nullptr for intervals to determine the size of the interval |
| 904 | * array, or may conservatively pre-allocate an array with length * 2 entries. The computed |
| 905 | * intervals are cached by glyph to improve performance for multiple calls. |
| 906 | * This permits constructing an underline that skips the descenders. |
| 907 | * |
| 908 | * @param text the text |
| 909 | * @param length number of bytes of text |
| 910 | * @param x The x-coordinate of the origin of the text. |
| 911 | * @param y The y-coordinate of the origin of the text. |
| 912 | * @param bounds The lower and upper line parallel to the advance. |
| 913 | * @param array If not null, the found intersections. |
| 914 | * |
| 915 | * @return The number of intersections, which may be zero. |
| 916 | */ |
| 917 | int getTextIntercepts(const void* text, size_t length, SkScalar x, SkScalar y, |
| 918 | const SkScalar bounds[2], SkScalar* intervals) const; |
| 919 | |
| 920 | /** Return the number of intervals that intersect the intercept along the axis of the advance. |
| 921 | * The return count is zero or a multiple of two, and is at most the number of glyphs * 2 in |
| 922 | * string. The caller may pass nullptr for intervals to determine the size of the interval |
| 923 | * array, or may conservatively pre-allocate an array with length * 2 entries. The computed |
| 924 | * intervals are cached by glyph to improve performance for multiple calls. |
| 925 | * This permits constructing an underline that skips the descenders. |
| 926 | * |
| 927 | * @param text the text |
| 928 | * @param length number of bytes of text |
| 929 | * @param pos array of positions, used to position each character |
| 930 | * @param bounds The lower and upper line parallel to the advance. |
| 931 | * @param array If not null, the glyph bounds contained by the advance parallel lines. |
| 932 | * |
| 933 | * @return The number of intersections, which may be zero. |
| 934 | */ |
| 935 | int getPosTextIntercepts(const void* text, size_t length, const SkPoint pos[], |
| 936 | const SkScalar bounds[2], SkScalar* intervals) const; |
| 937 | |
fmalita | eae6a91 | 2016-07-28 09:47:24 -0700 | [diff] [blame] | 938 | /** Return the number of intervals that intersect the intercept along the axis of the advance. |
| 939 | * The return count is zero or a multiple of two, and is at most the number of glyphs * 2 in |
| 940 | * string. The caller may pass nullptr for intervals to determine the size of the interval |
| 941 | * array, or may conservatively pre-allocate an array with length * 2 entries. The computed |
| 942 | * intervals are cached by glyph to improve performance for multiple calls. |
| 943 | * This permits constructing an underline that skips the descenders. |
| 944 | * |
| 945 | * @param text The text. |
| 946 | * @param length Number of bytes of text. |
| 947 | * @param xpos Array of x-positions, used to position each character. |
| 948 | * @param constY The shared Y coordinate for all of the positions. |
| 949 | * @param bounds The lower and upper line parallel to the advance. |
| 950 | * @param array If not null, the glyph bounds contained by the advance parallel lines. |
| 951 | * |
| 952 | * @return The number of intersections, which may be zero. |
| 953 | */ |
| 954 | int getPosTextHIntercepts(const void* text, size_t length, const SkScalar xpos[], |
| 955 | SkScalar constY, const SkScalar bounds[2], SkScalar* intervals) const; |
| 956 | |
| 957 | /** Return the number of intervals that intersect the intercept along the axis of the advance. |
| 958 | * The return count is zero or a multiple of two, and is at most the number of glyphs * 2 in |
| 959 | * text blob. The caller may pass nullptr for intervals to determine the size of the interval |
| 960 | * array. The computed intervals are cached by glyph to improve performance for multiple calls. |
| 961 | * This permits constructing an underline that skips the descenders. |
| 962 | * |
| 963 | * @param blob The text blob. |
| 964 | * @param bounds The lower and upper line parallel to the advance. |
| 965 | * @param array If not null, the glyph bounds contained by the advance parallel lines. |
| 966 | * |
| 967 | * @return The number of intersections, which may be zero. |
| 968 | */ |
| 969 | int getTextBlobIntercepts(const SkTextBlob* blob, const SkScalar bounds[2], |
| 970 | SkScalar* intervals) const; |
| 971 | |
reed | 8893e5f | 2014-12-15 13:27:26 -0800 | [diff] [blame] | 972 | /** |
| 973 | * Return a rectangle that represents the union of the bounds of all |
| 974 | * of the glyphs, but each one positioned at (0,0). This may be conservatively large, and |
| 975 | * will not take into account any hinting, but will respect any text-scale-x or text-skew-x |
| 976 | * on this paint. |
| 977 | */ |
| 978 | SkRect getFontBounds() const; |
| 979 | |
reed@google.com | 632e1a2 | 2011-10-06 12:37:00 +0000 | [diff] [blame] | 980 | // returns true if the paint's settings (e.g. xfermode + alpha) resolve to |
| 981 | // mean that we need not draw at all (e.g. SrcOver + 0-alpha) |
| 982 | bool nothingToDraw() const; |
| 983 | |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 984 | /////////////////////////////////////////////////////////////////////////// |
reed@google.com | d5f2079 | 2012-05-16 14:15:02 +0000 | [diff] [blame] | 985 | // would prefer to make these private... |
| 986 | |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 987 | /** Returns true if the current paint settings allow for fast computation of |
| 988 | bounds (i.e. there is nothing complex like a patheffect that would make |
| 989 | the bounds computation expensive. |
| 990 | */ |
senorblanco | 0abdf76 | 2015-08-20 11:10:41 -0700 | [diff] [blame] | 991 | bool canComputeFastBounds() const; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 992 | |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 993 | /** Only call this if canComputeFastBounds() returned true. This takes a |
| 994 | raw rectangle (the raw bounds of a shape), and adjusts it for stylistic |
| 995 | effects in the paint (e.g. stroking). If needed, it uses the storage |
| 996 | rect parameter. It returns the adjusted bounds that can then be used |
| 997 | for quickReject tests. |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 998 | |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 999 | The returned rect will either be orig or storage, thus the caller |
| 1000 | should not rely on storage being set to the result, but should always |
| 1001 | use the retured value. It is legal for orig and storage to be the same |
| 1002 | rect. |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1003 | |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 1004 | e.g. |
| 1005 | if (paint.canComputeFastBounds()) { |
| 1006 | SkRect r, storage; |
| 1007 | path.computeBounds(&r, SkPath::kFast_BoundsType); |
| 1008 | const SkRect& fastR = paint.computeFastBounds(r, &storage); |
| 1009 | if (canvas->quickReject(fastR, ...)) { |
| 1010 | // don't draw the path |
| 1011 | } |
| 1012 | } |
| 1013 | */ |
| 1014 | const SkRect& computeFastBounds(const SkRect& orig, SkRect* storage) const { |
Brian Osman | 60751d7 | 2017-05-12 11:21:36 -0400 | [diff] [blame] | 1015 | // Things like stroking, etc... will do math on the bounds rect, assuming that it's sorted. |
| 1016 | SkASSERT(orig.isSorted()); |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 1017 | SkPaint::Style style = this->getStyle(); |
| 1018 | // ultra fast-case: filling with no effects that affect geometry |
| 1019 | if (kFill_Style == style) { |
| 1020 | uintptr_t effects = reinterpret_cast<uintptr_t>(this->getLooper()); |
| 1021 | effects |= reinterpret_cast<uintptr_t>(this->getMaskFilter()); |
| 1022 | effects |= reinterpret_cast<uintptr_t>(this->getPathEffect()); |
senorblanco@chromium.org | 336d1d7 | 2014-01-27 21:03:17 +0000 | [diff] [blame] | 1023 | effects |= reinterpret_cast<uintptr_t>(this->getImageFilter()); |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 1024 | if (!effects) { |
| 1025 | return orig; |
| 1026 | } |
| 1027 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1028 | |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 1029 | return this->doComputeFastBounds(orig, storage, style); |
| 1030 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1031 | |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 1032 | const SkRect& computeFastStrokeBounds(const SkRect& orig, |
| 1033 | SkRect* storage) const { |
reed@google.com | 73a0258 | 2012-05-16 19:21:12 +0000 | [diff] [blame] | 1034 | return this->doComputeFastBounds(orig, storage, kStroke_Style); |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 1035 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1036 | |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 1037 | // Take the style explicitly, so the caller can force us to be stroked |
| 1038 | // without having to make a copy of the paint just to change that field. |
| 1039 | const SkRect& doComputeFastBounds(const SkRect& orig, SkRect* storage, |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 1040 | Style style) const; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1041 | |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 1042 | |
benjaminwagner | d936f63 | 2016-02-23 10:44:31 -0800 | [diff] [blame] | 1043 | |
commit-bot@chromium.org | 0f10f7b | 2014-03-13 18:02:17 +0000 | [diff] [blame] | 1044 | SK_TO_STRING_NONVIRT() |
robertphillips@google.com | 791f12e | 2013-02-14 13:53:53 +0000 | [diff] [blame] | 1045 | |
reed@google.com | d5f2079 | 2012-05-16 14:15:02 +0000 | [diff] [blame] | 1046 | private: |
Cary Clark | 0418a88 | 2017-05-10 09:07:42 -0400 | [diff] [blame] | 1047 | typedef const SkGlyph& (*GlyphCacheProc)(SkGlyphCache*, const char**); |
| 1048 | |
reed | a5ab9ec | 2016-03-06 18:10:48 -0800 | [diff] [blame] | 1049 | sk_sp<SkTypeface> fTypeface; |
| 1050 | sk_sp<SkPathEffect> fPathEffect; |
| 1051 | sk_sp<SkShader> fShader; |
reed | a5ab9ec | 2016-03-06 18:10:48 -0800 | [diff] [blame] | 1052 | sk_sp<SkMaskFilter> fMaskFilter; |
| 1053 | sk_sp<SkColorFilter> fColorFilter; |
| 1054 | sk_sp<SkRasterizer> fRasterizer; |
reed | 46f2d0a | 2016-09-11 05:40:31 -0700 | [diff] [blame] | 1055 | sk_sp<SkDrawLooper> fDrawLooper; |
reed | a5ab9ec | 2016-03-06 18:10:48 -0800 | [diff] [blame] | 1056 | sk_sp<SkImageFilter> fImageFilter; |
reed@google.com | d5f2079 | 2012-05-16 14:15:02 +0000 | [diff] [blame] | 1057 | |
commit-bot@chromium.org | e8807f4 | 2014-03-24 23:03:11 +0000 | [diff] [blame] | 1058 | SkScalar fTextSize; |
| 1059 | SkScalar fTextScaleX; |
| 1060 | SkScalar fTextSkewX; |
reed@google.com | d5f2079 | 2012-05-16 14:15:02 +0000 | [diff] [blame] | 1061 | SkColor fColor; |
| 1062 | SkScalar fWidth; |
| 1063 | SkScalar fMiterLimit; |
Mike Reed | 71fecc3 | 2016-11-18 17:19:54 -0500 | [diff] [blame] | 1064 | uint32_t fBlendMode; // just need 5-6 bits |
commit-bot@chromium.org | aca1c01 | 2014-02-21 18:18:05 +0000 | [diff] [blame] | 1065 | union { |
| 1066 | struct { |
| 1067 | // all of these bitfields should add up to 32 |
| 1068 | unsigned fFlags : 16; |
| 1069 | unsigned fTextAlign : 2; |
| 1070 | unsigned fCapType : 2; |
| 1071 | unsigned fJoinType : 2; |
| 1072 | unsigned fStyle : 2; |
| 1073 | unsigned fTextEncoding : 2; // 3 values |
| 1074 | unsigned fHinting : 2; |
reed | f803da1 | 2015-01-23 05:58:07 -0800 | [diff] [blame] | 1075 | unsigned fFilterQuality : 2; |
commit-bot@chromium.org | 85faf50 | 2014-04-16 12:58:02 +0000 | [diff] [blame] | 1076 | //unsigned fFreeBits : 2; |
reed | f59eab2 | 2014-07-14 14:39:15 -0700 | [diff] [blame] | 1077 | } fBitfields; |
| 1078 | uint32_t fBitfieldsUInt; |
commit-bot@chromium.org | aca1c01 | 2014-02-21 18:18:05 +0000 | [diff] [blame] | 1079 | }; |
commit-bot@chromium.org | e8807f4 | 2014-03-24 23:03:11 +0000 | [diff] [blame] | 1080 | |
robertphillips | e34f17d | 2016-07-19 07:59:22 -0700 | [diff] [blame] | 1081 | static GlyphCacheProc GetGlyphCacheProc(TextEncoding encoding, |
| 1082 | bool isDevKern, |
| 1083 | bool needFullMetrics); |
reed@google.com | d5f2079 | 2012-05-16 14:15:02 +0000 | [diff] [blame] | 1084 | |
| 1085 | SkScalar measure_text(SkGlyphCache*, const char* text, size_t length, |
| 1086 | int* count, SkRect* bounds) const; |
| 1087 | |
brianosman | a1e8f8d | 2016-04-08 06:47:54 -0700 | [diff] [blame] | 1088 | enum ScalerContextFlags : uint32_t { |
| 1089 | kNone_ScalerContextFlags = 0, |
| 1090 | |
| 1091 | kFakeGamma_ScalerContextFlag = 1 << 0, |
| 1092 | kBoostContrast_ScalerContextFlag = 1 << 1, |
| 1093 | |
| 1094 | kFakeGammaAndBoostContrast_ScalerContextFlags = |
| 1095 | kFakeGamma_ScalerContextFlag | kBoostContrast_ScalerContextFlag, |
bungeman | f6d1e60 | 2016-02-22 13:20:28 -0800 | [diff] [blame] | 1096 | }; |
| 1097 | |
joshualitt | fd45079 | 2015-03-13 08:38:43 -0700 | [diff] [blame] | 1098 | /* |
| 1099 | * Allocs an SkDescriptor on the heap and return it to the caller as a refcnted |
| 1100 | * SkData. Caller is responsible for managing the lifetime of this object. |
| 1101 | */ |
reed | a9322c2 | 2016-04-12 06:47:05 -0700 | [diff] [blame] | 1102 | void getScalerContextDescriptor(SkScalerContextEffects*, SkAutoDescriptor*, |
| 1103 | const SkSurfaceProps& surfaceProps, |
brianosman | a1e8f8d | 2016-04-08 06:47:54 -0700 | [diff] [blame] | 1104 | uint32_t scalerContextFlags, const SkMatrix*) const; |
joshualitt | fd45079 | 2015-03-13 08:38:43 -0700 | [diff] [blame] | 1105 | |
brianosman | a1e8f8d | 2016-04-08 06:47:54 -0700 | [diff] [blame] | 1106 | SkGlyphCache* detachCache(const SkSurfaceProps* surfaceProps, uint32_t scalerContextFlags, |
bungeman | f6d1e60 | 2016-02-22 13:20:28 -0800 | [diff] [blame] | 1107 | const SkMatrix*) const; |
reed@google.com | d5f2079 | 2012-05-16 14:15:02 +0000 | [diff] [blame] | 1108 | |
brianosman | a1e8f8d | 2016-04-08 06:47:54 -0700 | [diff] [blame] | 1109 | void descriptorProc(const SkSurfaceProps* surfaceProps, uint32_t scalerContextFlags, |
bungeman | f6d1e60 | 2016-02-22 13:20:28 -0800 | [diff] [blame] | 1110 | const SkMatrix* deviceMatrix, |
reed | a9322c2 | 2016-04-12 06:47:05 -0700 | [diff] [blame] | 1111 | void (*proc)(SkTypeface*, const SkScalerContextEffects&, |
| 1112 | const SkDescriptor*, void*), |
bungeman | f6d1e60 | 2016-02-22 13:20:28 -0800 | [diff] [blame] | 1113 | void* context) const; |
reed@android.com | d252db0 | 2009-04-01 18:31:44 +0000 | [diff] [blame] | 1114 | |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 1115 | /* |
| 1116 | * The luminance color is used to determine which Gamma Canonical color to map to. This is |
| 1117 | * really only used by backends which want to cache glyph masks, and need some way to know if |
| 1118 | * they need to generate new masks based off a given color. |
| 1119 | */ |
| 1120 | SkColor computeLuminanceColor() const; |
| 1121 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1122 | enum { |
reed@google.com | ed43dff | 2013-06-04 16:56:27 +0000 | [diff] [blame] | 1123 | /* This is the size we use when we ask for a glyph's path. We then |
| 1124 | * post-transform it as we draw to match the request. |
| 1125 | * This is done to try to re-use cache entries for the path. |
| 1126 | * |
| 1127 | * This value is somewhat arbitrary. In theory, it could be 1, since |
| 1128 | * we store paths as floats. However, we get the path from the font |
| 1129 | * scaler, and it may represent its paths as fixed-point (or 26.6), |
| 1130 | * so we shouldn't ask for something too big (might overflow 16.16) |
| 1131 | * or too small (underflow 26.6). |
| 1132 | * |
| 1133 | * This value could track kMaxSizeForGlyphCache, assuming the above |
| 1134 | * constraints, but since we ask for unhinted paths, the two values |
| 1135 | * need not match per-se. |
| 1136 | */ |
| 1137 | kCanonicalTextSizeForPaths = 64, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1138 | }; |
reed@google.com | ed43dff | 2013-06-04 16:56:27 +0000 | [diff] [blame] | 1139 | |
| 1140 | static bool TooBigToUseCache(const SkMatrix& ctm, const SkMatrix& textM); |
| 1141 | |
reed@google.com | ed43dff | 2013-06-04 16:56:27 +0000 | [diff] [blame] | 1142 | // Set flags/hinting/textSize up to use for drawing text as paths. |
| 1143 | // Returns scale factor to restore the original textSize, since will will |
| 1144 | // have change it to kCanonicalTextSizeForPaths. |
| 1145 | SkScalar setupForAsPaths(); |
| 1146 | |
Mike Reed | d5bee5d | 2017-06-01 14:45:44 -0400 | [diff] [blame] | 1147 | static SkScalar MaxCacheSize2(); |
reed@google.com | ed43dff | 2013-06-04 16:56:27 +0000 | [diff] [blame] | 1148 | |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 1149 | friend class SkAutoGlyphCache; |
jvanverth | 2d2a68c | 2014-06-10 06:42:56 -0700 | [diff] [blame] | 1150 | friend class SkAutoGlyphCacheNoGamma; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1151 | friend class SkCanvas; |
| 1152 | friend class SkDraw; |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 1153 | friend class SkPDFDevice; |
joshualitt | e76b4bb | 2015-12-28 07:23:58 -0800 | [diff] [blame] | 1154 | friend class GrAtlasTextBlob; |
joshualitt | dbd3593 | 2015-04-02 09:19:04 -0700 | [diff] [blame] | 1155 | friend class GrAtlasTextContext; |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 1156 | friend class GrStencilAndCoverTextContext; |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 1157 | friend class GrPathRendering; |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 1158 | friend class GrTextUtils; |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 1159 | friend class GrGLPathRendering; |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 1160 | friend class SkScalerContext; |
caryclark | 0449bcf | 2016-02-09 13:25:45 -0800 | [diff] [blame] | 1161 | friend class SkTextBaseIter; |
reed@google.com | ed43dff | 2013-06-04 16:56:27 +0000 | [diff] [blame] | 1162 | friend class SkCanonicalizePaint; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1163 | }; |
| 1164 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1165 | #endif |