epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | e4f10a7 | 2012-05-15 20:47:50 +0000 | [diff] [blame] | 2 | |
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 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 5 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 6 | * Use of this source code is governed by a BSD-style license that can be |
| 7 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 10 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 11 | #ifndef SkPaint_DEFINED |
| 12 | #define SkPaint_DEFINED |
| 13 | |
| 14 | #include "SkColor.h" |
reed@google.com | 9efd9a0 | 2012-01-30 15:41:43 +0000 | [diff] [blame] | 15 | #include "SkDrawLooper.h" |
reed@google.com | ed43dff | 2013-06-04 16:56:27 +0000 | [diff] [blame] | 16 | #include "SkMatrix.h" |
reed@android.com | a0f5d15 | 2009-06-22 17:38:10 +0000 | [diff] [blame] | 17 | #include "SkXfermode.h" |
commit-bot@chromium.org | c7a20e4 | 2013-05-13 14:09:13 +0000 | [diff] [blame] | 18 | #ifdef SK_BUILD_FOR_ANDROID |
| 19 | #include "SkPaintOptionsAndroid.h" |
| 20 | #endif |
reed@android.com | a0f5d15 | 2009-06-22 17:38:10 +0000 | [diff] [blame] | 21 | |
reed@google.com | b0a34d8 | 2012-07-11 19:57:55 +0000 | [diff] [blame] | 22 | class SkAnnotation; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 23 | class SkAutoGlyphCache; |
| 24 | class SkColorFilter; |
| 25 | class SkDescriptor; |
bungeman@google.com | 532470f | 2013-01-22 19:25:14 +0000 | [diff] [blame] | 26 | struct SkDeviceProperties; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 27 | class SkFlattenableReadBuffer; |
| 28 | class SkFlattenableWriteBuffer; |
| 29 | struct SkGlyph; |
| 30 | struct SkRect; |
| 31 | class SkGlyphCache; |
reed@google.com | 15356a6 | 2011-11-03 19:29:08 +0000 | [diff] [blame] | 32 | class SkImageFilter; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 33 | class SkMaskFilter; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 34 | class SkPath; |
| 35 | class SkPathEffect; |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 36 | struct SkPoint; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 37 | class SkRasterizer; |
| 38 | class SkShader; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 39 | class SkTypeface; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 40 | |
| 41 | typedef const SkGlyph& (*SkDrawCacheProc)(SkGlyphCache*, const char**, |
| 42 | SkFixed x, SkFixed y); |
| 43 | |
| 44 | typedef const SkGlyph& (*SkMeasureCacheProc)(SkGlyphCache*, const char**); |
| 45 | |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 46 | #define kBicubicFilterBitmap_Flag kHighQualityFilterBitmap_Flag |
| 47 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 48 | /** \class SkPaint |
| 49 | |
| 50 | The SkPaint class holds the style and color information about how to draw |
| 51 | geometries, text and bitmaps. |
| 52 | */ |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 53 | |
ctguil@chromium.org | 7ffb1b2 | 2011-03-15 21:27:08 +0000 | [diff] [blame] | 54 | class SK_API SkPaint { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 55 | public: |
| 56 | SkPaint(); |
| 57 | SkPaint(const SkPaint& paint); |
| 58 | ~SkPaint(); |
| 59 | |
| 60 | SkPaint& operator=(const SkPaint&); |
| 61 | |
reed@google.com | b530ef5 | 2011-07-20 19:55:42 +0000 | [diff] [blame] | 62 | SK_API friend bool operator==(const SkPaint& a, const SkPaint& b); |
| 63 | friend bool operator!=(const SkPaint& a, const SkPaint& b) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 64 | return !(a == b); |
| 65 | } |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 66 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 67 | void flatten(SkFlattenableWriteBuffer&) const; |
| 68 | void unflatten(SkFlattenableReadBuffer&); |
| 69 | |
| 70 | /** Restores the paint to its initial settings. |
| 71 | */ |
| 72 | void reset(); |
| 73 | |
agl@chromium.org | 309485b | 2009-07-21 17:41:32 +0000 | [diff] [blame] | 74 | /** Specifies the level of hinting to be performed. These names are taken |
| 75 | from the Gnome/Cairo names for the same. They are translated into |
| 76 | Freetype concepts the same as in cairo-ft-font.c: |
| 77 | kNo_Hinting -> FT_LOAD_NO_HINTING |
| 78 | kSlight_Hinting -> FT_LOAD_TARGET_LIGHT |
| 79 | kNormal_Hinting -> <default, no option> |
| 80 | kFull_Hinting -> <same as kNormalHinting, unless we are rendering |
| 81 | subpixel glyphs, in which case TARGET_LCD or |
| 82 | TARGET_LCD_V is used> |
| 83 | */ |
| 84 | enum Hinting { |
| 85 | kNo_Hinting = 0, |
| 86 | kSlight_Hinting = 1, |
| 87 | kNormal_Hinting = 2, //!< this is the default |
tomhudson@google.com | 1f90287 | 2012-06-01 13:15:47 +0000 | [diff] [blame] | 88 | kFull_Hinting = 3 |
agl@chromium.org | 309485b | 2009-07-21 17:41:32 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 91 | Hinting getHinting() const { |
agl@chromium.org | 309485b | 2009-07-21 17:41:32 +0000 | [diff] [blame] | 92 | return static_cast<Hinting>(fHinting); |
| 93 | } |
| 94 | |
djsollen@google.com | f5dbe2f | 2011-04-15 13:41:26 +0000 | [diff] [blame] | 95 | void setHinting(Hinting hintingLevel); |
agl@chromium.org | 309485b | 2009-07-21 17:41:32 +0000 | [diff] [blame] | 96 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 97 | /** Specifies the bit values that are stored in the paint's flags. |
| 98 | */ |
| 99 | enum Flags { |
| 100 | kAntiAlias_Flag = 0x01, //!< mask to enable antialiasing |
reed@google.com | c968315 | 2013-07-18 13:47:01 +0000 | [diff] [blame^] | 101 | |
| 102 | // DEPRECATED -- use setFilterLevel instead |
| 103 | kFilterBitmap_Flag = 0x02, // temporary flag |
| 104 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 105 | kDither_Flag = 0x04, //!< mask to enable dithering |
| 106 | kUnderlineText_Flag = 0x08, //!< mask to enable underline text |
| 107 | kStrikeThruText_Flag = 0x10, //!< mask to enable strike-thru text |
| 108 | kFakeBoldText_Flag = 0x20, //!< mask to enable fake-bold text |
| 109 | kLinearText_Flag = 0x40, //!< mask to enable linear-text |
agl@chromium.org | 309485b | 2009-07-21 17:41:32 +0000 | [diff] [blame] | 110 | kSubpixelText_Flag = 0x80, //!< mask to enable subpixel text positioning |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 111 | kDevKernText_Flag = 0x100, //!< mask to enable device kerning text |
agl@chromium.org | 309485b | 2009-07-21 17:41:32 +0000 | [diff] [blame] | 112 | kLCDRenderText_Flag = 0x200, //!< mask to enable subpixel glyph renderering |
agl@chromium.org | e95c91e | 2010-01-04 18:27:55 +0000 | [diff] [blame] | 113 | kEmbeddedBitmapText_Flag = 0x400, //!< mask to enable embedded bitmap strikes |
agl@chromium.org | a2c71cb | 2010-06-17 20:49:17 +0000 | [diff] [blame] | 114 | kAutoHinting_Flag = 0x800, //!< mask to force Freetype's autohinter |
reed@google.com | 830a23e | 2011-11-10 15:20:49 +0000 | [diff] [blame] | 115 | kVerticalText_Flag = 0x1000, |
reed@google.com | 8351aab | 2012-01-18 17:06:35 +0000 | [diff] [blame] | 116 | kGenA8FromLCD_Flag = 0x2000, // hack for GDI -- do not use if you can help it |
reed@google.com | c968315 | 2013-07-18 13:47:01 +0000 | [diff] [blame^] | 117 | |
| 118 | // DEPRECATED -- use setFilterLevel instead |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 119 | kHighQualityFilterBitmap_Flag = 0x4000, // temporary flag |
reed@google.com | c968315 | 2013-07-18 13:47:01 +0000 | [diff] [blame^] | 120 | // DEPRECATED -- use setFilterLevel instead |
humper@google.com | 387db0a | 2013-07-09 14:13:04 +0000 | [diff] [blame] | 121 | kHighQualityDownsampleBitmap_Flag = 0x8000, // temporary flag |
reed@google.com | 3253898 | 2011-09-30 20:57:05 +0000 | [diff] [blame] | 122 | |
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 | */ |
| 132 | uint32_t getFlags() const { return fFlags; } |
| 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 | |
reed@google.com | c968315 | 2013-07-18 13:47:01 +0000 | [diff] [blame^] | 289 | enum FilterLevel { |
| 290 | kNone_FilterLevel, |
| 291 | kLow_FilterLevel, |
| 292 | kMedium_FilterLevel, |
| 293 | kHigh_FilterLevel |
| 294 | }; |
| 295 | |
| 296 | /** |
| 297 | * Return the filter level. This affects the quality (and performance) of |
| 298 | * drawing scaled images. |
| 299 | */ |
| 300 | FilterLevel getFilterLevel() const; |
| 301 | |
| 302 | /** |
| 303 | * Set the filter level. This affects the quality (and performance) of |
| 304 | * drawing scaled images. |
| 305 | */ |
| 306 | void setFilterLevel(FilterLevel); |
| 307 | |
| 308 | /** |
| 309 | * DEPRECATED: use setFilterLevel instead. |
| 310 | * If the predicate is true, set the filterLevel to Low, else set it to |
| 311 | * None. |
| 312 | */ |
| 313 | void setFilterBitmap(bool doFilter) { |
| 314 | this->setFilterLevel(doFilter ? kLow_FilterLevel : kNone_FilterLevel); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 315 | } |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 316 | |
reed@google.com | c968315 | 2013-07-18 13:47:01 +0000 | [diff] [blame^] | 317 | /** |
| 318 | * DEPRECATED: call getFilterLevel() instead. |
| 319 | * Returns true if getFilterLevel() returns anything other than None. |
| 320 | */ |
| 321 | bool isFilterBitmap() const { |
| 322 | return kNone_FilterLevel != this->getFilterLevel(); |
| 323 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 324 | |
| 325 | /** Styles apply to rect, oval, path, and text. |
| 326 | Bitmaps are always drawn in "fill", and lines are always drawn in |
| 327 | "stroke". |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 328 | |
reed@android.com | ed881c2 | 2009-09-15 14:10:42 +0000 | [diff] [blame] | 329 | Note: strokeandfill implicitly draws the result with |
| 330 | SkPath::kWinding_FillType, so if the original path is even-odd, the |
| 331 | results may not appear the same as if it was drawn twice, filled and |
| 332 | then stroked. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 333 | */ |
| 334 | enum Style { |
reed@android.com | ed881c2 | 2009-09-15 14:10:42 +0000 | [diff] [blame] | 335 | kFill_Style, //!< fill the geometry |
| 336 | kStroke_Style, //!< stroke the geometry |
| 337 | kStrokeAndFill_Style, //!< fill and stroke the geometry |
mike@reedtribe.org | aac2fb8 | 2013-02-04 05:17:10 +0000 | [diff] [blame] | 338 | }; |
| 339 | enum { |
| 340 | kStyleCount = kStrokeAndFill_Style + 1 |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 341 | }; |
| 342 | |
| 343 | /** Return the paint's style, used for controlling how primitives' |
| 344 | geometries are interpreted (except for drawBitmap, which always assumes |
| 345 | kFill_Style). |
| 346 | @return the paint's Style |
| 347 | */ |
| 348 | Style getStyle() const { return (Style)fStyle; } |
| 349 | |
| 350 | /** Set the paint's style, used for controlling how primitives' |
| 351 | geometries are interpreted (except for drawBitmap, which always assumes |
| 352 | Fill). |
| 353 | @param style The new style to set in the paint |
| 354 | */ |
| 355 | void setStyle(Style style); |
| 356 | |
| 357 | /** Return the paint's color. Note that the color is a 32bit value |
| 358 | containing alpha as well as r,g,b. This 32bit value is not |
| 359 | premultiplied, meaning that its alpha can be any value, regardless of |
| 360 | the values of r,g,b. |
| 361 | @return the paint's color (and alpha). |
| 362 | */ |
| 363 | SkColor getColor() const { return fColor; } |
| 364 | |
| 365 | /** Set the paint's color. Note that the color is a 32bit value containing |
| 366 | alpha as well as r,g,b. This 32bit value is not premultiplied, meaning |
| 367 | that its alpha can be any value, regardless of the values of r,g,b. |
| 368 | @param color The new color (including alpha) to set in the paint. |
| 369 | */ |
| 370 | void setColor(SkColor color); |
| 371 | |
| 372 | /** Helper to getColor() that just returns the color's alpha value. |
| 373 | @return the alpha component of the paint's color. |
| 374 | */ |
| 375 | uint8_t getAlpha() const { return SkToU8(SkColorGetA(fColor)); } |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 376 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 377 | /** Helper to setColor(), that only assigns the color's alpha value, |
| 378 | leaving its r,g,b values unchanged. |
| 379 | @param a set the alpha component (0..255) of the paint's color. |
| 380 | */ |
| 381 | void setAlpha(U8CPU a); |
| 382 | |
| 383 | /** Helper to setColor(), that takes a,r,g,b and constructs the color value |
| 384 | using SkColorSetARGB() |
| 385 | @param a The new alpha component (0..255) of the paint's color. |
| 386 | @param r The new red component (0..255) of the paint's color. |
| 387 | @param g The new green component (0..255) of the paint's color. |
| 388 | @param b The new blue component (0..255) of the paint's color. |
| 389 | */ |
| 390 | void setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b); |
| 391 | |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 392 | /** Return the width for stroking. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 393 | <p /> |
| 394 | A value of 0 strokes in hairline mode. |
| 395 | Hairlines always draw 1-pixel wide, regardless of the matrix. |
| 396 | @return the paint's stroke width, used whenever the paint's style is |
| 397 | Stroke or StrokeAndFill. |
| 398 | */ |
| 399 | SkScalar getStrokeWidth() const { return fWidth; } |
| 400 | |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 401 | /** Set the width for stroking. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 402 | Pass 0 to stroke in hairline mode. |
| 403 | Hairlines always draw 1-pixel wide, regardless of the matrix. |
| 404 | @param width set the paint's stroke width, used whenever the paint's |
| 405 | style is Stroke or StrokeAndFill. |
| 406 | */ |
| 407 | void setStrokeWidth(SkScalar width); |
| 408 | |
| 409 | /** Return the paint's stroke miter value. This is used to control the |
| 410 | behavior of miter joins when the joins angle is sharp. |
| 411 | @return the paint's miter limit, used whenever the paint's style is |
| 412 | Stroke or StrokeAndFill. |
| 413 | */ |
| 414 | SkScalar getStrokeMiter() const { return fMiterLimit; } |
| 415 | |
| 416 | /** Set the paint's stroke miter value. This is used to control the |
| 417 | behavior of miter joins when the joins angle is sharp. This value must |
| 418 | be >= 0. |
| 419 | @param miter set the miter limit on the paint, used whenever the |
| 420 | paint's style is Stroke or StrokeAndFill. |
| 421 | */ |
| 422 | void setStrokeMiter(SkScalar miter); |
| 423 | |
| 424 | /** Cap enum specifies the settings for the paint's strokecap. This is the |
| 425 | treatment that is applied to the beginning and end of each non-closed |
| 426 | contour (e.g. lines). |
| 427 | */ |
| 428 | enum Cap { |
| 429 | kButt_Cap, //!< begin/end contours with no extension |
| 430 | kRound_Cap, //!< begin/end contours with a semi-circle extension |
| 431 | kSquare_Cap, //!< begin/end contours with a half square extension |
| 432 | |
| 433 | kCapCount, |
| 434 | kDefault_Cap = kButt_Cap |
| 435 | }; |
| 436 | |
| 437 | /** Join enum specifies the settings for the paint's strokejoin. This is |
| 438 | the treatment that is applied to corners in paths and rectangles. |
| 439 | */ |
| 440 | enum Join { |
| 441 | kMiter_Join, //!< connect path segments with a sharp join |
| 442 | kRound_Join, //!< connect path segments with a round join |
| 443 | kBevel_Join, //!< connect path segments with a flat bevel join |
| 444 | |
| 445 | kJoinCount, |
| 446 | kDefault_Join = kMiter_Join |
| 447 | }; |
| 448 | |
| 449 | /** Return the paint's stroke cap type, controlling how the start and end |
| 450 | of stroked lines and paths are treated. |
| 451 | @return the line cap style for the paint, used whenever the paint's |
| 452 | style is Stroke or StrokeAndFill. |
| 453 | */ |
| 454 | Cap getStrokeCap() const { return (Cap)fCapType; } |
| 455 | |
| 456 | /** Set the paint's stroke cap type. |
| 457 | @param cap set the paint's line cap style, used whenever the paint's |
| 458 | style is Stroke or StrokeAndFill. |
| 459 | */ |
| 460 | void setStrokeCap(Cap cap); |
| 461 | |
| 462 | /** Return the paint's stroke join type. |
| 463 | @return the paint's line join style, used whenever the paint's style is |
| 464 | Stroke or StrokeAndFill. |
| 465 | */ |
| 466 | Join getStrokeJoin() const { return (Join)fJoinType; } |
| 467 | |
| 468 | /** Set the paint's stroke join type. |
| 469 | @param join set the paint's line join style, used whenever the paint's |
| 470 | style is Stroke or StrokeAndFill. |
| 471 | */ |
| 472 | void setStrokeJoin(Join join); |
| 473 | |
reed@google.com | 4bbdeac | 2013-01-24 21:03:11 +0000 | [diff] [blame] | 474 | /** |
| 475 | * Applies any/all effects (patheffect, stroking) to src, returning the |
| 476 | * result in dst. The result is that drawing src with this paint will be |
| 477 | * the same as drawing dst with a default paint (at least from the |
| 478 | * geometric perspective). |
| 479 | * |
| 480 | * @param src input path |
| 481 | * @param dst output path (may be the same as src) |
| 482 | * @param cullRect If not null, the dst path may be culled to this rect. |
| 483 | * @return true if the path should be filled, or false if it should be |
| 484 | * drawn with a hairline (width == 0) |
| 485 | */ |
| 486 | bool getFillPath(const SkPath& src, SkPath* dst, |
| 487 | const SkRect* cullRect = NULL) const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 488 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 489 | /** Get the paint's shader object. |
| 490 | <p /> |
| 491 | The shader's reference count is not affected. |
| 492 | @return the paint's shader (or NULL) |
| 493 | */ |
| 494 | SkShader* getShader() const { return fShader; } |
| 495 | |
| 496 | /** Set or clear the shader object. |
reed@google.com | 880dc47 | 2012-05-11 14:47:03 +0000 | [diff] [blame] | 497 | * Shaders specify the source color(s) for what is being drawn. If a paint |
| 498 | * has no shader, then the paint's color is used. If the paint has a |
| 499 | * shader, then the shader's color(s) are use instead, but they are |
| 500 | * modulated by the paint's alpha. This makes it easy to create a shader |
| 501 | * once (e.g. bitmap tiling or gradient) and then change its transparency |
| 502 | * w/o having to modify the original shader... only the paint's alpha needs |
| 503 | * to be modified. |
| 504 | * <p /> |
| 505 | * Pass NULL to clear any previous shader. |
| 506 | * As a convenience, the parameter passed is also returned. |
| 507 | * If a previous shader exists, its reference count is decremented. |
| 508 | * If shader is not NULL, its reference count is incremented. |
| 509 | * @param shader May be NULL. The shader to be installed in the paint |
| 510 | * @return shader |
| 511 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 512 | SkShader* setShader(SkShader* shader); |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 513 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 514 | /** Get the paint's colorfilter. If there is a colorfilter, its reference |
| 515 | count is not changed. |
| 516 | @return the paint's colorfilter (or NULL) |
| 517 | */ |
| 518 | SkColorFilter* getColorFilter() const { return fColorFilter; } |
| 519 | |
| 520 | /** Set or clear the paint's colorfilter, returning the parameter. |
| 521 | <p /> |
| 522 | If the paint already has a filter, its reference count is decremented. |
| 523 | If filter is not NULL, its reference count is incremented. |
| 524 | @param filter May be NULL. The filter to be installed in the paint |
| 525 | @return filter |
| 526 | */ |
| 527 | SkColorFilter* setColorFilter(SkColorFilter* filter); |
| 528 | |
| 529 | /** Get the paint's xfermode object. |
| 530 | <p /> |
| 531 | The xfermode's reference count is not affected. |
| 532 | @return the paint's xfermode (or NULL) |
| 533 | */ |
| 534 | SkXfermode* getXfermode() const { return fXfermode; } |
| 535 | |
| 536 | /** Set or clear the xfermode object. |
| 537 | <p /> |
| 538 | Pass NULL to clear any previous xfermode. |
| 539 | As a convenience, the parameter passed is also returned. |
| 540 | If a previous xfermode exists, its reference count is decremented. |
| 541 | If xfermode is not NULL, its reference count is incremented. |
| 542 | @param xfermode May be NULL. The new xfermode to be installed in the |
| 543 | paint |
| 544 | @return xfermode |
| 545 | */ |
| 546 | SkXfermode* setXfermode(SkXfermode* xfermode); |
reed@android.com | a0f5d15 | 2009-06-22 17:38:10 +0000 | [diff] [blame] | 547 | |
| 548 | /** Create an xfermode based on the specified Mode, and assign it into the |
| 549 | paint, returning the mode that was set. If the Mode is SrcOver, then |
| 550 | the paint's xfermode is set to null. |
| 551 | */ |
reed@android.com | 0baf193 | 2009-06-24 12:41:42 +0000 | [diff] [blame] | 552 | SkXfermode* setXfermodeMode(SkXfermode::Mode); |
reed@android.com | a0f5d15 | 2009-06-22 17:38:10 +0000 | [diff] [blame] | 553 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 554 | /** Get the paint's patheffect object. |
| 555 | <p /> |
| 556 | The patheffect reference count is not affected. |
| 557 | @return the paint's patheffect (or NULL) |
| 558 | */ |
| 559 | SkPathEffect* getPathEffect() const { return fPathEffect; } |
| 560 | |
| 561 | /** Set or clear the patheffect object. |
| 562 | <p /> |
| 563 | Pass NULL to clear any previous patheffect. |
| 564 | As a convenience, the parameter passed is also returned. |
| 565 | If a previous patheffect exists, its reference count is decremented. |
| 566 | If patheffect is not NULL, its reference count is incremented. |
| 567 | @param effect May be NULL. The new patheffect to be installed in the |
| 568 | paint |
| 569 | @return effect |
| 570 | */ |
| 571 | SkPathEffect* setPathEffect(SkPathEffect* effect); |
| 572 | |
| 573 | /** Get the paint's maskfilter object. |
| 574 | <p /> |
| 575 | The maskfilter reference count is not affected. |
| 576 | @return the paint's maskfilter (or NULL) |
| 577 | */ |
| 578 | SkMaskFilter* getMaskFilter() const { return fMaskFilter; } |
| 579 | |
| 580 | /** Set or clear the maskfilter object. |
| 581 | <p /> |
| 582 | Pass NULL to clear any previous maskfilter. |
| 583 | As a convenience, the parameter passed is also returned. |
| 584 | If a previous maskfilter exists, its reference count is decremented. |
| 585 | If maskfilter is not NULL, its reference count is incremented. |
| 586 | @param maskfilter May be NULL. The new maskfilter to be installed in |
| 587 | the paint |
| 588 | @return maskfilter |
| 589 | */ |
| 590 | SkMaskFilter* setMaskFilter(SkMaskFilter* maskfilter); |
| 591 | |
| 592 | // These attributes are for text/fonts |
| 593 | |
| 594 | /** Get the paint's typeface object. |
| 595 | <p /> |
| 596 | The typeface object identifies which font to use when drawing or |
| 597 | measuring text. The typeface reference count is not affected. |
| 598 | @return the paint's typeface (or NULL) |
| 599 | */ |
| 600 | SkTypeface* getTypeface() const { return fTypeface; } |
| 601 | |
| 602 | /** Set or clear the typeface object. |
| 603 | <p /> |
| 604 | Pass NULL to clear any previous typeface. |
| 605 | As a convenience, the parameter passed is also returned. |
| 606 | If a previous typeface exists, its reference count is decremented. |
| 607 | If typeface is not NULL, its reference count is incremented. |
| 608 | @param typeface May be NULL. The new typeface to be installed in the |
| 609 | paint |
| 610 | @return typeface |
| 611 | */ |
| 612 | SkTypeface* setTypeface(SkTypeface* typeface); |
| 613 | |
| 614 | /** Get the paint's rasterizer (or NULL). |
| 615 | <p /> |
| 616 | The raster controls how paths/text are turned into alpha masks. |
| 617 | @return the paint's rasterizer (or NULL) |
| 618 | */ |
| 619 | SkRasterizer* getRasterizer() const { return fRasterizer; } |
| 620 | |
| 621 | /** Set or clear the rasterizer object. |
| 622 | <p /> |
| 623 | Pass NULL to clear any previous rasterizer. |
| 624 | As a convenience, the parameter passed is also returned. |
| 625 | If a previous rasterizer exists in the paint, its reference count is |
| 626 | decremented. If rasterizer is not NULL, its reference count is |
| 627 | incremented. |
| 628 | @param rasterizer May be NULL. The new rasterizer to be installed in |
| 629 | the paint. |
| 630 | @return rasterizer |
| 631 | */ |
| 632 | SkRasterizer* setRasterizer(SkRasterizer* rasterizer); |
| 633 | |
reed@google.com | 15356a6 | 2011-11-03 19:29:08 +0000 | [diff] [blame] | 634 | SkImageFilter* getImageFilter() const { return fImageFilter; } |
| 635 | SkImageFilter* setImageFilter(SkImageFilter*); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 636 | |
reed@google.com | b0a34d8 | 2012-07-11 19:57:55 +0000 | [diff] [blame] | 637 | SkAnnotation* getAnnotation() const { return fAnnotation; } |
| 638 | SkAnnotation* setAnnotation(SkAnnotation*); |
| 639 | |
| 640 | /** |
| 641 | * Returns true if there is an annotation installed on this paint, and |
| 642 | * the annotation specifics no-drawing. |
| 643 | */ |
| 644 | bool isNoDrawAnnotation() const { |
| 645 | return SkToBool(fPrivFlags & kNoDrawAnnotation_PrivFlag); |
| 646 | } |
reed@google.com | 15356a6 | 2011-11-03 19:29:08 +0000 | [diff] [blame] | 647 | |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 648 | /** |
| 649 | * Return the paint's SkDrawLooper (if any). Does not affect the looper's |
| 650 | * reference count. |
| 651 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 652 | SkDrawLooper* getLooper() const { return fLooper; } |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 653 | |
| 654 | /** |
| 655 | * Set or clear the looper object. |
| 656 | * <p /> |
| 657 | * Pass NULL to clear any previous looper. |
| 658 | * As a convenience, the parameter passed is also returned. |
| 659 | * If a previous looper exists in the paint, its reference count is |
| 660 | * decremented. If looper is not NULL, its reference count is |
| 661 | * incremented. |
| 662 | * @param looper May be NULL. The new looper to be installed in the paint. |
| 663 | * @return looper |
| 664 | */ |
| 665 | SkDrawLooper* setLooper(SkDrawLooper* looper); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 666 | |
| 667 | enum Align { |
| 668 | kLeft_Align, |
| 669 | kCenter_Align, |
| 670 | kRight_Align, |
mike@reedtribe.org | ddc813b | 2013-06-08 12:58:19 +0000 | [diff] [blame] | 671 | }; |
| 672 | enum { |
| 673 | kAlignCount = 3 |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 674 | }; |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 675 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 676 | /** Return the paint's Align value for drawing text. |
| 677 | @return the paint's Align value for drawing text. |
| 678 | */ |
| 679 | Align getTextAlign() const { return (Align)fTextAlign; } |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 680 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 681 | /** Set the paint's text alignment. |
| 682 | @param align set the paint's Align value for drawing text. |
| 683 | */ |
| 684 | void setTextAlign(Align align); |
| 685 | |
| 686 | /** Return the paint's text size. |
| 687 | @return the paint's text size. |
| 688 | */ |
| 689 | SkScalar getTextSize() const { return fTextSize; } |
| 690 | |
| 691 | /** Set the paint's text size. This value must be > 0 |
| 692 | @param textSize set the paint's text size. |
| 693 | */ |
| 694 | void setTextSize(SkScalar textSize); |
| 695 | |
| 696 | /** Return the paint's horizontal scale factor for text. The default value |
| 697 | is 1.0. |
| 698 | @return the paint's scale factor in X for drawing/measuring text |
| 699 | */ |
| 700 | SkScalar getTextScaleX() const { return fTextScaleX; } |
| 701 | |
| 702 | /** Set the paint's horizontal scale factor for text. The default value |
| 703 | is 1.0. Values > 1.0 will stretch the text wider. Values < 1.0 will |
| 704 | stretch the text narrower. |
| 705 | @param scaleX set the paint's scale factor in X for drawing/measuring |
| 706 | text. |
| 707 | */ |
| 708 | void setTextScaleX(SkScalar scaleX); |
| 709 | |
| 710 | /** Return the paint's horizontal skew factor for text. The default value |
| 711 | is 0. |
| 712 | @return the paint's skew factor in X for drawing text. |
| 713 | */ |
| 714 | SkScalar getTextSkewX() const { return fTextSkewX; } |
| 715 | |
| 716 | /** Set the paint's horizontal skew factor for text. The default value |
| 717 | is 0. For approximating oblique text, use values around -0.25. |
| 718 | @param skewX set the paint's skew factor in X for drawing text. |
| 719 | */ |
| 720 | void setTextSkewX(SkScalar skewX); |
| 721 | |
reed@google.com | 1f1543f | 2012-09-12 21:08:33 +0000 | [diff] [blame] | 722 | #ifdef SK_SUPPORT_HINTING_SCALE_FACTOR |
| 723 | /** Return the paint's scale factor used for correctly rendering |
| 724 | glyphs in high DPI mode without text subpixel positioning. |
| 725 | @return the scale factor used for rendering glyphs in high DPI mode. |
| 726 | */ |
| 727 | SkScalar getHintingScaleFactor() const { return fHintingScaleFactor; } |
| 728 | |
| 729 | /** Set the paint's scale factor used for correctly rendering |
| 730 | glyphs in high DPI mode without text subpixel positioning. |
| 731 | @param the scale factor used for rendering glyphs in high DPI mode. |
| 732 | */ |
| 733 | void setHintingScaleFactor(SkScalar hintingScaleFactor); |
| 734 | #endif |
| 735 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 | |
| 746 | TextEncoding getTextEncoding() const { return (TextEncoding)fTextEncoding; } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 747 | |
| 748 | void setTextEncoding(TextEncoding encoding); |
| 749 | |
| 750 | struct FontMetrics { |
| 751 | SkScalar fTop; //!< The greatest distance above the baseline for any glyph (will be <= 0) |
| 752 | SkScalar fAscent; //!< The recommended distance above the baseline (will be <= 0) |
| 753 | SkScalar fDescent; //!< The recommended distance below the baseline (will be >= 0) |
| 754 | SkScalar fBottom; //!< The greatest distance below the baseline for any glyph (will be >= 0) |
| 755 | SkScalar fLeading; //!< The recommended distance to add between lines of text (will be >= 0) |
agl@chromium.org | cc3096b | 2009-04-22 22:09:04 +0000 | [diff] [blame] | 756 | SkScalar fAvgCharWidth; //!< the average charactor width (>= 0) |
bungeman@google.com | e9d8319 | 2013-06-21 05:31:38 +0000 | [diff] [blame] | 757 | SkScalar fMaxCharWidth; //!< the max charactor width (>= 0) |
agl@chromium.org | cc3096b | 2009-04-22 22:09:04 +0000 | [diff] [blame] | 758 | SkScalar fXMin; //!< The minimum bounding box x value for all glyphs |
| 759 | SkScalar fXMax; //!< The maximum bounding box x value for all glyphs |
| 760 | SkScalar fXHeight; //!< the height of an 'x' in px, or 0 if no 'x' in face |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 761 | }; |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 762 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 763 | /** Return the recommend spacing between lines (which will be |
| 764 | fDescent - fAscent + fLeading). |
| 765 | 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] | 766 | typeface/pointsize/etc. currently set in the paint. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 767 | @param metrics If not null, returns the font metrics for the |
| 768 | current typeface/pointsize/etc setting in this |
| 769 | paint. |
| 770 | @param scale If not 0, return width as if the canvas were scaled |
| 771 | by this value |
| 772 | @param return the recommended spacing between lines |
| 773 | */ |
| 774 | SkScalar getFontMetrics(FontMetrics* metrics, SkScalar scale = 0) const; |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 775 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 776 | /** Return the recommend line spacing. This will be |
| 777 | fDescent - fAscent + fLeading |
| 778 | */ |
| 779 | SkScalar getFontSpacing() const { return this->getFontMetrics(NULL, 0); } |
| 780 | |
| 781 | /** Convert the specified text into glyph IDs, returning the number of |
| 782 | glyphs ID written. If glyphs is NULL, it is ignore and only the count |
| 783 | is returned. |
| 784 | */ |
| 785 | int textToGlyphs(const void* text, size_t byteLength, |
| 786 | uint16_t glyphs[]) const; |
| 787 | |
reed@android.com | a5dcaf6 | 2010-02-05 17:12:32 +0000 | [diff] [blame] | 788 | /** Return true if all of the specified text has a corresponding non-zero |
| 789 | glyph ID. If any of the code-points in the text are not supported in |
| 790 | the typeface (i.e. the glyph ID would be zero), then return false. |
| 791 | |
| 792 | If the text encoding for the paint is kGlyph_TextEncoding, then this |
| 793 | returns true if all of the specified glyph IDs are non-zero. |
| 794 | */ |
| 795 | bool containsText(const void* text, size_t byteLength) const; |
| 796 | |
reed@android.com | 9d3a985 | 2010-01-08 14:07:42 +0000 | [diff] [blame] | 797 | /** Convert the glyph array into Unichars. Unconvertable glyphs are mapped |
| 798 | to zero. Note: this does not look at the text-encoding setting in the |
| 799 | paint, only at the typeface. |
| 800 | */ |
| 801 | void glyphsToUnichars(const uint16_t glyphs[], int count, |
| 802 | SkUnichar text[]) const; |
| 803 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 804 | /** Return the number of drawable units in the specified text buffer. |
| 805 | This looks at the current TextEncoding field of the paint. If you also |
| 806 | want to have the text converted into glyph IDs, call textToGlyphs |
| 807 | instead. |
| 808 | */ |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 809 | int countText(const void* text, size_t byteLength) const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 810 | return this->textToGlyphs(text, byteLength, NULL); |
| 811 | } |
| 812 | |
reed@google.com | 44da42e | 2011-11-10 20:04:47 +0000 | [diff] [blame] | 813 | /** Return the width of the text. This will return the vertical measure |
| 814 | * if isVerticalText() is true, in which case the returned value should |
| 815 | * be treated has a height instead of a width. |
| 816 | * |
| 817 | * @param text The text to be measured |
| 818 | * @param length Number of bytes of text to measure |
| 819 | * @param bounds If not NULL, returns the bounds of the text, |
| 820 | * relative to (0, 0). |
| 821 | * @param scale If not 0, return width as if the canvas were scaled |
| 822 | * by this value |
| 823 | * @return The advance width of the text |
| 824 | */ |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 825 | SkScalar measureText(const void* text, size_t length, |
| 826 | SkRect* bounds, SkScalar scale = 0) const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 827 | |
reed@google.com | 44da42e | 2011-11-10 20:04:47 +0000 | [diff] [blame] | 828 | /** Return the width of the text. This will return the vertical measure |
| 829 | * if isVerticalText() is true, in which case the returned value should |
| 830 | * be treated has a height instead of a width. |
| 831 | * |
| 832 | * @param text Address of the text |
| 833 | * @param length Number of bytes of text to measure |
reed@google.com | 97ecd1d | 2012-05-15 19:25:17 +0000 | [diff] [blame] | 834 | * @return The advance width of the text |
reed@google.com | 44da42e | 2011-11-10 20:04:47 +0000 | [diff] [blame] | 835 | */ |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 836 | SkScalar measureText(const void* text, size_t length) const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 837 | return this->measureText(text, length, NULL, 0); |
| 838 | } |
reed@google.com | 9d07fec | 2011-03-16 20:02:59 +0000 | [diff] [blame] | 839 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 840 | /** Specify the direction the text buffer should be processed in breakText() |
| 841 | */ |
| 842 | enum TextBufferDirection { |
| 843 | /** When measuring text for breakText(), begin at the start of the text |
| 844 | buffer and proceed forward through the data. This is the default. |
| 845 | */ |
| 846 | kForward_TextBufferDirection, |
| 847 | /** When measuring text for breakText(), begin at the end of the text |
| 848 | buffer and proceed backwards through the data. |
| 849 | */ |
| 850 | kBackward_TextBufferDirection |
| 851 | }; |
| 852 | |
reed@google.com | 44da42e | 2011-11-10 20:04:47 +0000 | [diff] [blame] | 853 | /** Return the number of bytes of text that were measured. If |
| 854 | * isVerticalText() is true, then the vertical advances are used for |
| 855 | * the measurement. |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 856 | * |
reed@google.com | 44da42e | 2011-11-10 20:04:47 +0000 | [diff] [blame] | 857 | * @param text The text to be measured |
| 858 | * @param length Number of bytes of text to measure |
| 859 | * @param maxWidth Maximum width. Only the subset of text whose accumulated |
| 860 | * widths are <= maxWidth are measured. |
| 861 | * @param measuredWidth Optional. If non-null, this returns the actual |
| 862 | * width of the measured text. |
| 863 | * @param tbd Optional. The direction the text buffer should be |
| 864 | * traversed during measuring. |
| 865 | * @return The number of bytes of text that were measured. Will be |
| 866 | * <= length. |
| 867 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 868 | size_t breakText(const void* text, size_t length, SkScalar maxWidth, |
| 869 | SkScalar* measuredWidth = NULL, |
| 870 | TextBufferDirection tbd = kForward_TextBufferDirection) |
| 871 | const; |
| 872 | |
reed@google.com | 44da42e | 2011-11-10 20:04:47 +0000 | [diff] [blame] | 873 | /** Return the advances for the text. These will be vertical advances if |
| 874 | * isVerticalText() returns true. |
| 875 | * |
| 876 | * @param text the text |
| 877 | * @param byteLength number of bytes to of text |
| 878 | * @param widths If not null, returns the array of advances for |
| 879 | * the glyphs. If not NULL, must be at least a large |
| 880 | * as the number of unichars in the specified text. |
| 881 | * @param bounds If not null, returns the bounds for each of |
| 882 | * character, relative to (0, 0) |
| 883 | * @return the number of unichars in the specified text. |
| 884 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 885 | int getTextWidths(const void* text, size_t byteLength, SkScalar widths[], |
| 886 | SkRect bounds[] = NULL) const; |
| 887 | |
| 888 | /** Return the path (outline) for the specified text. |
| 889 | Note: just like SkCanvas::drawText, this will respect the Align setting |
| 890 | in the paint. |
| 891 | */ |
| 892 | void getTextPath(const void* text, size_t length, SkScalar x, SkScalar y, |
| 893 | SkPath* path) const; |
| 894 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 895 | void getPosTextPath(const void* text, size_t length, |
reed@google.com | ca0062e | 2012-07-20 11:20:32 +0000 | [diff] [blame] | 896 | const SkPoint pos[], SkPath* path) const; |
| 897 | |
djsollen@google.com | 56c6977 | 2011-11-08 19:00:26 +0000 | [diff] [blame] | 898 | #ifdef SK_BUILD_FOR_ANDROID |
djsollen@google.com | 4bd2bdb | 2013-03-08 18:35:13 +0000 | [diff] [blame] | 899 | const SkGlyph& getUnicharMetrics(SkUnichar, const SkMatrix*); |
| 900 | const SkGlyph& getGlyphMetrics(uint16_t, const SkMatrix*); |
| 901 | const void* findImage(const SkGlyph&, const SkMatrix*); |
djsollen@google.com | f5dbe2f | 2011-04-15 13:41:26 +0000 | [diff] [blame] | 902 | |
| 903 | uint32_t getGenerationID() const; |
djsollen@google.com | 4bd2bdb | 2013-03-08 18:35:13 +0000 | [diff] [blame] | 904 | void setGenerationID(uint32_t generationID); |
djsollen@google.com | 60abb07 | 2012-02-15 18:49:15 +0000 | [diff] [blame] | 905 | |
| 906 | /** Returns the base glyph count for the strike associated with this paint |
| 907 | */ |
| 908 | unsigned getBaseGlyphCount(SkUnichar text) const; |
commit-bot@chromium.org | c7a20e4 | 2013-05-13 14:09:13 +0000 | [diff] [blame] | 909 | |
| 910 | const SkPaintOptionsAndroid& getPaintOptionsAndroid() const { |
| 911 | return fPaintOptionsAndroid; |
| 912 | } |
| 913 | void setPaintOptionsAndroid(const SkPaintOptionsAndroid& options); |
djsollen@google.com | f5dbe2f | 2011-04-15 13:41:26 +0000 | [diff] [blame] | 914 | #endif |
| 915 | |
reed@google.com | 632e1a2 | 2011-10-06 12:37:00 +0000 | [diff] [blame] | 916 | // returns true if the paint's settings (e.g. xfermode + alpha) resolve to |
| 917 | // mean that we need not draw at all (e.g. SrcOver + 0-alpha) |
| 918 | bool nothingToDraw() const; |
| 919 | |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 920 | /////////////////////////////////////////////////////////////////////////// |
reed@google.com | d5f2079 | 2012-05-16 14:15:02 +0000 | [diff] [blame] | 921 | // would prefer to make these private... |
| 922 | |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 923 | /** Returns true if the current paint settings allow for fast computation of |
| 924 | bounds (i.e. there is nothing complex like a patheffect that would make |
| 925 | the bounds computation expensive. |
| 926 | */ |
| 927 | bool canComputeFastBounds() const { |
| 928 | if (this->getLooper()) { |
| 929 | return this->getLooper()->canComputeFastBounds(*this); |
| 930 | } |
| 931 | return !this->getRasterizer(); |
| 932 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 933 | |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 934 | /** Only call this if canComputeFastBounds() returned true. This takes a |
| 935 | raw rectangle (the raw bounds of a shape), and adjusts it for stylistic |
| 936 | effects in the paint (e.g. stroking). If needed, it uses the storage |
| 937 | rect parameter. It returns the adjusted bounds that can then be used |
| 938 | for quickReject tests. |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 939 | |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 940 | The returned rect will either be orig or storage, thus the caller |
| 941 | should not rely on storage being set to the result, but should always |
| 942 | use the retured value. It is legal for orig and storage to be the same |
| 943 | rect. |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 944 | |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 945 | e.g. |
| 946 | if (paint.canComputeFastBounds()) { |
| 947 | SkRect r, storage; |
| 948 | path.computeBounds(&r, SkPath::kFast_BoundsType); |
| 949 | const SkRect& fastR = paint.computeFastBounds(r, &storage); |
| 950 | if (canvas->quickReject(fastR, ...)) { |
| 951 | // don't draw the path |
| 952 | } |
| 953 | } |
| 954 | */ |
| 955 | const SkRect& computeFastBounds(const SkRect& orig, SkRect* storage) const { |
| 956 | SkPaint::Style style = this->getStyle(); |
| 957 | // ultra fast-case: filling with no effects that affect geometry |
| 958 | if (kFill_Style == style) { |
| 959 | uintptr_t effects = reinterpret_cast<uintptr_t>(this->getLooper()); |
| 960 | effects |= reinterpret_cast<uintptr_t>(this->getMaskFilter()); |
| 961 | effects |= reinterpret_cast<uintptr_t>(this->getPathEffect()); |
| 962 | if (!effects) { |
| 963 | return orig; |
| 964 | } |
| 965 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 966 | |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 967 | return this->doComputeFastBounds(orig, storage, style); |
| 968 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 969 | |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 970 | const SkRect& computeFastStrokeBounds(const SkRect& orig, |
| 971 | SkRect* storage) const { |
reed@google.com | 73a0258 | 2012-05-16 19:21:12 +0000 | [diff] [blame] | 972 | return this->doComputeFastBounds(orig, storage, kStroke_Style); |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 973 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 974 | |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 975 | // Take the style explicitly, so the caller can force us to be stroked |
| 976 | // without having to make a copy of the paint just to change that field. |
| 977 | const SkRect& doComputeFastBounds(const SkRect& orig, SkRect* storage, |
| 978 | Style) const; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 979 | |
reed@google.com | ed43dff | 2013-06-04 16:56:27 +0000 | [diff] [blame] | 980 | /** |
| 981 | * Return a matrix that applies the paint's text values: size, scale, skew |
| 982 | */ |
| 983 | static SkMatrix* SetTextMatrix(SkMatrix* matrix, SkScalar size, |
| 984 | SkScalar scaleX, SkScalar skewX) { |
| 985 | matrix->setScale(size * scaleX, size); |
| 986 | if (skewX) { |
| 987 | matrix->postSkew(skewX, 0); |
| 988 | } |
| 989 | return matrix; |
| 990 | } |
skia.committer@gmail.com | 8f6ef40 | 2013-06-05 07:01:06 +0000 | [diff] [blame] | 991 | |
reed@google.com | ed43dff | 2013-06-04 16:56:27 +0000 | [diff] [blame] | 992 | SkMatrix* setTextMatrix(SkMatrix* matrix) const { |
| 993 | return SetTextMatrix(matrix, fTextSize, fTextScaleX, fTextSkewX); |
| 994 | } |
skia.committer@gmail.com | 8f6ef40 | 2013-06-05 07:01:06 +0000 | [diff] [blame] | 995 | |
robertphillips@google.com | 791f12e | 2013-02-14 13:53:53 +0000 | [diff] [blame] | 996 | SkDEVCODE(void toString(SkString*) const;) |
| 997 | |
reed@google.com | d5f2079 | 2012-05-16 14:15:02 +0000 | [diff] [blame] | 998 | private: |
| 999 | SkTypeface* fTypeface; |
| 1000 | SkScalar fTextSize; |
| 1001 | SkScalar fTextScaleX; |
| 1002 | SkScalar fTextSkewX; |
reed@google.com | 1f1543f | 2012-09-12 21:08:33 +0000 | [diff] [blame] | 1003 | #ifdef SK_SUPPORT_HINTING_SCALE_FACTOR |
| 1004 | SkScalar fHintingScaleFactor; |
| 1005 | #endif |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 1006 | |
reed@google.com | d5f2079 | 2012-05-16 14:15:02 +0000 | [diff] [blame] | 1007 | SkPathEffect* fPathEffect; |
| 1008 | SkShader* fShader; |
| 1009 | SkXfermode* fXfermode; |
| 1010 | SkMaskFilter* fMaskFilter; |
| 1011 | SkColorFilter* fColorFilter; |
| 1012 | SkRasterizer* fRasterizer; |
| 1013 | SkDrawLooper* fLooper; |
| 1014 | SkImageFilter* fImageFilter; |
reed@google.com | b0a34d8 | 2012-07-11 19:57:55 +0000 | [diff] [blame] | 1015 | SkAnnotation* fAnnotation; |
reed@google.com | d5f2079 | 2012-05-16 14:15:02 +0000 | [diff] [blame] | 1016 | |
| 1017 | SkColor fColor; |
| 1018 | SkScalar fWidth; |
| 1019 | SkScalar fMiterLimit; |
reed@google.com | b0a34d8 | 2012-07-11 19:57:55 +0000 | [diff] [blame] | 1020 | // all of these bitfields should add up to 32 |
| 1021 | unsigned fFlags : 16; |
reed@google.com | d5f2079 | 2012-05-16 14:15:02 +0000 | [diff] [blame] | 1022 | unsigned fTextAlign : 2; |
| 1023 | unsigned fCapType : 2; |
| 1024 | unsigned fJoinType : 2; |
| 1025 | unsigned fStyle : 2; |
| 1026 | unsigned fTextEncoding : 2; // 3 values |
| 1027 | unsigned fHinting : 2; |
reed@google.com | b0a34d8 | 2012-07-11 19:57:55 +0000 | [diff] [blame] | 1028 | unsigned fPrivFlags : 4; // these are not flattened/unflattened |
| 1029 | |
| 1030 | enum PrivFlags { |
| 1031 | kNoDrawAnnotation_PrivFlag = 1 << 0, |
| 1032 | }; |
reed@google.com | d5f2079 | 2012-05-16 14:15:02 +0000 | [diff] [blame] | 1033 | |
| 1034 | SkDrawCacheProc getDrawCacheProc() const; |
| 1035 | SkMeasureCacheProc getMeasureCacheProc(TextBufferDirection dir, |
| 1036 | bool needFullMetrics) const; |
| 1037 | |
| 1038 | SkScalar measure_text(SkGlyphCache*, const char* text, size_t length, |
| 1039 | int* count, SkRect* bounds) const; |
| 1040 | |
bungeman@google.com | 532470f | 2013-01-22 19:25:14 +0000 | [diff] [blame] | 1041 | SkGlyphCache* detachCache(const SkDeviceProperties* deviceProperties, const SkMatrix*) const; |
reed@google.com | d5f2079 | 2012-05-16 14:15:02 +0000 | [diff] [blame] | 1042 | |
bungeman@google.com | 532470f | 2013-01-22 19:25:14 +0000 | [diff] [blame] | 1043 | void descriptorProc(const SkDeviceProperties* deviceProperties, const SkMatrix* deviceMatrix, |
reed@google.com | 90808e8 | 2013-03-19 14:44:54 +0000 | [diff] [blame] | 1044 | void (*proc)(SkTypeface*, const SkDescriptor*, void*), |
reed@google.com | d5f2079 | 2012-05-16 14:15:02 +0000 | [diff] [blame] | 1045 | void* context, bool ignoreGamma = false) const; |
reed@android.com | d252db0 | 2009-04-01 18:31:44 +0000 | [diff] [blame] | 1046 | |
bungeman@google.com | b24b4fa | 2012-09-04 13:49:59 +0000 | [diff] [blame] | 1047 | static void Term(); |
| 1048 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1049 | enum { |
reed@google.com | ed43dff | 2013-06-04 16:56:27 +0000 | [diff] [blame] | 1050 | /* This is the size we use when we ask for a glyph's path. We then |
| 1051 | * post-transform it as we draw to match the request. |
| 1052 | * This is done to try to re-use cache entries for the path. |
| 1053 | * |
| 1054 | * This value is somewhat arbitrary. In theory, it could be 1, since |
| 1055 | * we store paths as floats. However, we get the path from the font |
| 1056 | * scaler, and it may represent its paths as fixed-point (or 26.6), |
| 1057 | * so we shouldn't ask for something too big (might overflow 16.16) |
| 1058 | * or too small (underflow 26.6). |
| 1059 | * |
| 1060 | * This value could track kMaxSizeForGlyphCache, assuming the above |
| 1061 | * constraints, but since we ask for unhinted paths, the two values |
| 1062 | * need not match per-se. |
| 1063 | */ |
| 1064 | kCanonicalTextSizeForPaths = 64, |
| 1065 | |
| 1066 | /* |
| 1067 | * Above this size (taking into account CTM and textSize), we never use |
| 1068 | * the cache for bits or metrics (we might overflow), so we just ask |
| 1069 | * for a caononical size and post-transform that. |
| 1070 | */ |
| 1071 | kMaxSizeForGlyphCache = 256, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1072 | }; |
reed@google.com | ed43dff | 2013-06-04 16:56:27 +0000 | [diff] [blame] | 1073 | |
| 1074 | static bool TooBigToUseCache(const SkMatrix& ctm, const SkMatrix& textM); |
| 1075 | |
| 1076 | bool tooBigToUseCache() const; |
| 1077 | bool tooBigToUseCache(const SkMatrix& ctm) const; |
skia.committer@gmail.com | 8f6ef40 | 2013-06-05 07:01:06 +0000 | [diff] [blame] | 1078 | |
reed@google.com | ed43dff | 2013-06-04 16:56:27 +0000 | [diff] [blame] | 1079 | // Set flags/hinting/textSize up to use for drawing text as paths. |
| 1080 | // Returns scale factor to restore the original textSize, since will will |
| 1081 | // have change it to kCanonicalTextSizeForPaths. |
| 1082 | SkScalar setupForAsPaths(); |
| 1083 | |
| 1084 | static SkScalar MaxCacheSize2() { |
| 1085 | static const SkScalar kMaxSize = SkIntToScalar(kMaxSizeForGlyphCache); |
| 1086 | static const SkScalar kMag2Max = kMaxSize * kMaxSize; |
| 1087 | return kMag2Max; |
| 1088 | } |
| 1089 | |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 1090 | friend class SkAutoGlyphCache; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1091 | friend class SkCanvas; |
| 1092 | friend class SkDraw; |
bungeman@google.com | b24b4fa | 2012-09-04 13:49:59 +0000 | [diff] [blame] | 1093 | friend class SkGraphics; // So Term() can be called. |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 1094 | friend class SkPDFDevice; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1095 | friend class SkTextToPathIter; |
reed@google.com | ed43dff | 2013-06-04 16:56:27 +0000 | [diff] [blame] | 1096 | friend class SkCanonicalizePaint; |
djsollen@google.com | b44cd65 | 2011-12-01 17:09:21 +0000 | [diff] [blame] | 1097 | |
| 1098 | #ifdef SK_BUILD_FOR_ANDROID |
commit-bot@chromium.org | c7a20e4 | 2013-05-13 14:09:13 +0000 | [diff] [blame] | 1099 | SkPaintOptionsAndroid fPaintOptionsAndroid; |
| 1100 | |
djsollen@google.com | b44cd65 | 2011-12-01 17:09:21 +0000 | [diff] [blame] | 1101 | // In order for the == operator to work properly this must be the last field |
| 1102 | // in the struct so that we can do a memcmp to this field's offset. |
| 1103 | uint32_t fGenerationID; |
| 1104 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1105 | }; |
| 1106 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1107 | #endif |