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