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