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