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