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