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