blob: e39f49942e0770ff6701dcd6be33c2b6d33122d2 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.come4f10a72012-05-15 20:47:50 +00002
reed@android.com8a1c16f2008-12-17 15:59:43 +00003/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00005 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00006 * Use of this source code is governed by a BSD-style license that can be
7 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00008 */
9
epoger@google.comec3ed6a2011-07-28 14:26:00 +000010
reed@android.com8a1c16f2008-12-17 15:59:43 +000011#ifndef SkPaint_DEFINED
12#define SkPaint_DEFINED
13
14#include "SkColor.h"
reed@google.com9efd9a02012-01-30 15:41:43 +000015#include "SkDrawLooper.h"
reed@google.comed43dff2013-06-04 16:56:27 +000016#include "SkMatrix.h"
reed@android.coma0f5d152009-06-22 17:38:10 +000017#include "SkXfermode.h"
commit-bot@chromium.orgc7a20e42013-05-13 14:09:13 +000018#ifdef SK_BUILD_FOR_ANDROID
19#include "SkPaintOptionsAndroid.h"
20#endif
reed@android.coma0f5d152009-06-22 17:38:10 +000021
reed@google.comb0a34d82012-07-11 19:57:55 +000022class SkAnnotation;
reed@android.com8a1c16f2008-12-17 15:59:43 +000023class SkAutoGlyphCache;
24class SkColorFilter;
25class SkDescriptor;
bungeman@google.com532470f2013-01-22 19:25:14 +000026struct SkDeviceProperties;
reed@android.com8a1c16f2008-12-17 15:59:43 +000027class SkFlattenableReadBuffer;
28class SkFlattenableWriteBuffer;
29struct SkGlyph;
30struct SkRect;
31class SkGlyphCache;
reed@google.com15356a62011-11-03 19:29:08 +000032class SkImageFilter;
reed@android.com8a1c16f2008-12-17 15:59:43 +000033class SkMaskFilter;
reed@android.com8a1c16f2008-12-17 15:59:43 +000034class SkPath;
35class SkPathEffect;
djsollen@google.comc73dd5c2012-08-07 15:54:32 +000036struct SkPoint;
reed@android.com8a1c16f2008-12-17 15:59:43 +000037class SkRasterizer;
38class SkShader;
reed@android.com8a1c16f2008-12-17 15:59:43 +000039class SkTypeface;
reed@android.com8a1c16f2008-12-17 15:59:43 +000040
41typedef const SkGlyph& (*SkDrawCacheProc)(SkGlyphCache*, const char**,
42 SkFixed x, SkFixed y);
43
44typedef const SkGlyph& (*SkMeasureCacheProc)(SkGlyphCache*, const char**);
45
humper@google.comb0889472013-07-09 21:37:14 +000046#define kBicubicFilterBitmap_Flag kHighQualityFilterBitmap_Flag
47
reed@android.com8a1c16f2008-12-17 15:59:43 +000048/** \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.comb0889472013-07-09 21:37:14 +000053
ctguil@chromium.org7ffb1b22011-03-15 21:27:08 +000054class SK_API SkPaint {
reed@android.com8a1c16f2008-12-17 15:59:43 +000055public:
56 SkPaint();
57 SkPaint(const SkPaint& paint);
58 ~SkPaint();
59
60 SkPaint& operator=(const SkPaint&);
61
reed@google.comb530ef52011-07-20 19:55:42 +000062 SK_API friend bool operator==(const SkPaint& a, const SkPaint& b);
63 friend bool operator!=(const SkPaint& a, const SkPaint& b) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000064 return !(a == b);
65 }
reed@google.com9d07fec2011-03-16 20:02:59 +000066
reed@android.com8a1c16f2008-12-17 15:59:43 +000067 void flatten(SkFlattenableWriteBuffer&) const;
68 void unflatten(SkFlattenableReadBuffer&);
69
70 /** Restores the paint to its initial settings.
71 */
72 void reset();
73
agl@chromium.org309485b2009-07-21 17:41:32 +000074 /** 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.com1f902872012-06-01 13:15:47 +000088 kFull_Hinting = 3
agl@chromium.org309485b2009-07-21 17:41:32 +000089 };
90
reed@google.com9d07fec2011-03-16 20:02:59 +000091 Hinting getHinting() const {
agl@chromium.org309485b2009-07-21 17:41:32 +000092 return static_cast<Hinting>(fHinting);
93 }
94
djsollen@google.comf5dbe2f2011-04-15 13:41:26 +000095 void setHinting(Hinting hintingLevel);
agl@chromium.org309485b2009-07-21 17:41:32 +000096
reed@android.com8a1c16f2008-12-17 15:59:43 +000097 /** 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.comc9683152013-07-18 13:47:01 +0000101
102 // DEPRECATED -- use setFilterLevel instead
103 kFilterBitmap_Flag = 0x02, // temporary flag
104
reed@android.com8a1c16f2008-12-17 15:59:43 +0000105 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.org309485b2009-07-21 17:41:32 +0000110 kSubpixelText_Flag = 0x80, //!< mask to enable subpixel text positioning
reed@android.com8a1c16f2008-12-17 15:59:43 +0000111 kDevKernText_Flag = 0x100, //!< mask to enable device kerning text
agl@chromium.org309485b2009-07-21 17:41:32 +0000112 kLCDRenderText_Flag = 0x200, //!< mask to enable subpixel glyph renderering
agl@chromium.orge95c91e2010-01-04 18:27:55 +0000113 kEmbeddedBitmapText_Flag = 0x400, //!< mask to enable embedded bitmap strikes
agl@chromium.orga2c71cb2010-06-17 20:49:17 +0000114 kAutoHinting_Flag = 0x800, //!< mask to force Freetype's autohinter
reed@google.com830a23e2011-11-10 15:20:49 +0000115 kVerticalText_Flag = 0x1000,
reed@google.com8351aab2012-01-18 17:06:35 +0000116 kGenA8FromLCD_Flag = 0x2000, // hack for GDI -- do not use if you can help it
reed@google.comc9683152013-07-18 13:47:01 +0000117
118 // DEPRECATED -- use setFilterLevel instead
humper@google.comb0889472013-07-09 21:37:14 +0000119 kHighQualityFilterBitmap_Flag = 0x4000, // temporary flag
reed@google.comc9683152013-07-18 13:47:01 +0000120 // DEPRECATED -- use setFilterLevel instead
humper@google.com387db0a2013-07-09 14:13:04 +0000121 kHighQualityDownsampleBitmap_Flag = 0x8000, // temporary flag
reed@google.com32538982011-09-30 20:57:05 +0000122
agl@chromium.org309485b2009-07-21 17:41:32 +0000123 // 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.com8a1c16f2008-12-17 15:59:43 +0000125
humper@google.com387db0a2013-07-09 14:13:04 +0000126 kAllFlags = 0xFFFF
reed@android.com8a1c16f2008-12-17 15:59:43 +0000127 };
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.com9d07fec2011-03-16 20:02:59 +0000142 bool isAntiAlias() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000143 return SkToBool(this->getFlags() & kAntiAlias_Flag);
144 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000145
reed@android.com8a1c16f2008-12-17 15:59:43 +0000146 /** 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.com9d07fec2011-03-16 20:02:59 +0000150
reed@android.com8a1c16f2008-12-17 15:59:43 +0000151 /** 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.com9d07fec2011-03-16 20:02:59 +0000154 bool isDither() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000155 return SkToBool(this->getFlags() & kDither_Flag);
156 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000157
reed@android.com8a1c16f2008-12-17 15:59:43 +0000158 /** 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.com9d07fec2011-03-16 20:02:59 +0000162
reed@android.com8a1c16f2008-12-17 15:59:43 +0000163 /** 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.com9d07fec2011-03-16 20:02:59 +0000166 bool isLinearText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000167 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.com9d07fec2011-03-16 20:02:59 +0000179 bool isSubpixelText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000180 return SkToBool(this->getFlags() & kSubpixelText_Flag);
181 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000182
reed@google.com84b437e2011-08-01 12:45:35 +0000183 /**
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.com8a1c16f2008-12-17 15:59:43 +0000188 void setSubpixelText(bool subpixelText);
agl@chromium.org309485b2009-07-21 17:41:32 +0000189
reed@google.com9d07fec2011-03-16 20:02:59 +0000190 bool isLCDRenderText() const {
agl@chromium.org309485b2009-07-21 17:41:32 +0000191 return SkToBool(this->getFlags() & kLCDRenderText_Flag);
192 }
193
reed@google.com84b437e2011-08-01 12:45:35 +0000194 /**
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.org309485b2009-07-21 17:41:32 +0000201
reed@google.com9d07fec2011-03-16 20:02:59 +0000202 bool isEmbeddedBitmapText() const {
agl@chromium.orge95c91e2010-01-04 18:27:55 +0000203 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.com9d07fec2011-03-16 20:02:59 +0000212 bool isAutohinted() const {
agl@chromium.orga2c71cb2010-06-17 20:49:17 +0000213 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.com830a23e2011-11-10 15:20:49 +0000223 bool isVerticalText() const {
224 return SkToBool(this->getFlags() & kVerticalText_Flag);
225 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000226
reed@google.com830a23e2011-11-10 15:20:49 +0000227 /**
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.com8a1c16f2008-12-17 15:59:43 +0000237 /** 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.com9d07fec2011-03-16 20:02:59 +0000240 bool isUnderlineText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000241 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.com9d07fec2011-03-16 20:02:59 +0000253 bool isStrikeThruText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000254 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.com9d07fec2011-03-16 20:02:59 +0000266 bool isFakeBoldText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000267 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.com9d07fec2011-03-16 20:02:59 +0000279 bool isDevKernText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000280 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.comc9683152013-07-18 13:47:01 +0000289 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.com8a1c16f2008-12-17 15:59:43 +0000315 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000316
reed@google.comc9683152013-07-18 13:47:01 +0000317 /**
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.com8a1c16f2008-12-17 15:59:43 +0000324
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.com9d07fec2011-03-16 20:02:59 +0000328
reed@android.comed881c22009-09-15 14:10:42 +0000329 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.com8a1c16f2008-12-17 15:59:43 +0000333 */
334 enum Style {
reed@android.comed881c22009-09-15 14:10:42 +0000335 kFill_Style, //!< fill the geometry
336 kStroke_Style, //!< stroke the geometry
337 kStrokeAndFill_Style, //!< fill and stroke the geometry
mike@reedtribe.orgaac2fb82013-02-04 05:17:10 +0000338 };
339 enum {
340 kStyleCount = kStrokeAndFill_Style + 1
reed@android.com8a1c16f2008-12-17 15:59:43 +0000341 };
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.com9d07fec2011-03-16 20:02:59 +0000376
reed@android.com8a1c16f2008-12-17 15:59:43 +0000377 /** 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.com9d07fec2011-03-16 20:02:59 +0000392 /** Return the width for stroking.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000393 <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.com9d07fec2011-03-16 20:02:59 +0000401 /** Set the width for stroking.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000402 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.com4bbdeac2013-01-24 21:03:11 +0000474 /**
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.com8a1c16f2008-12-17 15:59:43 +0000488
reed@android.com8a1c16f2008-12-17 15:59:43 +0000489 /** 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.com880dc472012-05-11 14:47:03 +0000497 * 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.com8a1c16f2008-12-17 15:59:43 +0000512 SkShader* setShader(SkShader* shader);
reed@google.com9d07fec2011-03-16 20:02:59 +0000513
reed@android.com8a1c16f2008-12-17 15:59:43 +0000514 /** 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.coma0f5d152009-06-22 17:38:10 +0000547
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.com0baf1932009-06-24 12:41:42 +0000552 SkXfermode* setXfermodeMode(SkXfermode::Mode);
reed@android.coma0f5d152009-06-22 17:38:10 +0000553
reed@android.com8a1c16f2008-12-17 15:59:43 +0000554 /** 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.com15356a62011-11-03 19:29:08 +0000634 SkImageFilter* getImageFilter() const { return fImageFilter; }
635 SkImageFilter* setImageFilter(SkImageFilter*);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000636
reed@google.comb0a34d82012-07-11 19:57:55 +0000637 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.com15356a62011-11-03 19:29:08 +0000647
reed@google.com9d07fec2011-03-16 20:02:59 +0000648 /**
649 * Return the paint's SkDrawLooper (if any). Does not affect the looper's
650 * reference count.
651 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000652 SkDrawLooper* getLooper() const { return fLooper; }
reed@google.com9d07fec2011-03-16 20:02:59 +0000653
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.com8a1c16f2008-12-17 15:59:43 +0000666
667 enum Align {
668 kLeft_Align,
669 kCenter_Align,
670 kRight_Align,
mike@reedtribe.orgddc813b2013-06-08 12:58:19 +0000671 };
672 enum {
673 kAlignCount = 3
reed@android.com8a1c16f2008-12-17 15:59:43 +0000674 };
reed@google.com9d07fec2011-03-16 20:02:59 +0000675
reed@android.com8a1c16f2008-12-17 15:59:43 +0000676 /** 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.com9d07fec2011-03-16 20:02:59 +0000680
reed@android.com8a1c16f2008-12-17 15:59:43 +0000681 /** 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.com1f1543f2012-09-12 21:08:33 +0000722#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.com8a1c16f2008-12-17 15:59:43 +0000736 /** 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.com69705572012-03-21 19:46:50 +0000742 kUTF32_TextEncoding, //!< the text parameters are UTF32
reed@android.com8a1c16f2008-12-17 15:59:43 +0000743 kGlyphID_TextEncoding //!< the text parameters are glyph indices
744 };
reed@google.com9d07fec2011-03-16 20:02:59 +0000745
746 TextEncoding getTextEncoding() const { return (TextEncoding)fTextEncoding; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000747
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.orgcc3096b2009-04-22 22:09:04 +0000756 SkScalar fAvgCharWidth; //!< the average charactor width (>= 0)
bungeman@google.come9d83192013-06-21 05:31:38 +0000757 SkScalar fMaxCharWidth; //!< the max charactor width (>= 0)
agl@chromium.orgcc3096b2009-04-22 22:09:04 +0000758 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.com8a1c16f2008-12-17 15:59:43 +0000761 };
reed@google.com9d07fec2011-03-16 20:02:59 +0000762
reed@android.com8a1c16f2008-12-17 15:59:43 +0000763 /** 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.com9d07fec2011-03-16 20:02:59 +0000766 typeface/pointsize/etc. currently set in the paint.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000767 @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.com9d07fec2011-03-16 20:02:59 +0000775
reed@android.com8a1c16f2008-12-17 15:59:43 +0000776 /** 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.coma5dcaf62010-02-05 17:12:32 +0000788 /** 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.com9d3a9852010-01-08 14:07:42 +0000797 /** 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.com8a1c16f2008-12-17 15:59:43 +0000804 /** 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.com9d07fec2011-03-16 20:02:59 +0000809 int countText(const void* text, size_t byteLength) const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000810 return this->textToGlyphs(text, byteLength, NULL);
811 }
812
reed@google.com44da42e2011-11-10 20:04:47 +0000813 /** 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.com9d07fec2011-03-16 20:02:59 +0000825 SkScalar measureText(const void* text, size_t length,
826 SkRect* bounds, SkScalar scale = 0) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000827
reed@google.com44da42e2011-11-10 20:04:47 +0000828 /** 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.com97ecd1d2012-05-15 19:25:17 +0000834 * @return The advance width of the text
reed@google.com44da42e2011-11-10 20:04:47 +0000835 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000836 SkScalar measureText(const void* text, size_t length) const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000837 return this->measureText(text, length, NULL, 0);
838 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000839
reed@android.com8a1c16f2008-12-17 15:59:43 +0000840 /** 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.com44da42e2011-11-10 20:04:47 +0000853 /** 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.comfbfcd562012-08-23 18:09:54 +0000856 *
reed@google.com44da42e2011-11-10 20:04:47 +0000857 * @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.com8a1c16f2008-12-17 15:59:43 +0000868 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.com44da42e2011-11-10 20:04:47 +0000873 /** 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.com8a1c16f2008-12-17 15:59:43 +0000885 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.comfbfcd562012-08-23 18:09:54 +0000895 void getPosTextPath(const void* text, size_t length,
reed@google.comca0062e2012-07-20 11:20:32 +0000896 const SkPoint pos[], SkPath* path) const;
897
djsollen@google.com56c69772011-11-08 19:00:26 +0000898#ifdef SK_BUILD_FOR_ANDROID
djsollen@google.com4bd2bdb2013-03-08 18:35:13 +0000899 const SkGlyph& getUnicharMetrics(SkUnichar, const SkMatrix*);
900 const SkGlyph& getGlyphMetrics(uint16_t, const SkMatrix*);
901 const void* findImage(const SkGlyph&, const SkMatrix*);
djsollen@google.comf5dbe2f2011-04-15 13:41:26 +0000902
903 uint32_t getGenerationID() const;
djsollen@google.com4bd2bdb2013-03-08 18:35:13 +0000904 void setGenerationID(uint32_t generationID);
djsollen@google.com60abb072012-02-15 18:49:15 +0000905
906 /** Returns the base glyph count for the strike associated with this paint
907 */
908 unsigned getBaseGlyphCount(SkUnichar text) const;
commit-bot@chromium.orgc7a20e42013-05-13 14:09:13 +0000909
910 const SkPaintOptionsAndroid& getPaintOptionsAndroid() const {
911 return fPaintOptionsAndroid;
912 }
913 void setPaintOptionsAndroid(const SkPaintOptionsAndroid& options);
djsollen@google.comf5dbe2f2011-04-15 13:41:26 +0000914#endif
915
reed@google.com632e1a22011-10-06 12:37:00 +0000916 // 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.coma584aed2012-05-16 14:06:02 +0000920 ///////////////////////////////////////////////////////////////////////////
reed@google.comd5f20792012-05-16 14:15:02 +0000921 // would prefer to make these private...
922
reed@google.coma584aed2012-05-16 14:06:02 +0000923 /** 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.comfbfcd562012-08-23 18:09:54 +0000933
reed@google.coma584aed2012-05-16 14:06:02 +0000934 /** 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.comfbfcd562012-08-23 18:09:54 +0000939
reed@google.coma584aed2012-05-16 14:06:02 +0000940 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.comfbfcd562012-08-23 18:09:54 +0000944
reed@google.coma584aed2012-05-16 14:06:02 +0000945 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.comfbfcd562012-08-23 18:09:54 +0000966
reed@google.coma584aed2012-05-16 14:06:02 +0000967 return this->doComputeFastBounds(orig, storage, style);
968 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000969
reed@google.coma584aed2012-05-16 14:06:02 +0000970 const SkRect& computeFastStrokeBounds(const SkRect& orig,
971 SkRect* storage) const {
reed@google.com73a02582012-05-16 19:21:12 +0000972 return this->doComputeFastBounds(orig, storage, kStroke_Style);
reed@google.coma584aed2012-05-16 14:06:02 +0000973 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000974
reed@google.coma584aed2012-05-16 14:06:02 +0000975 // 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.comfbfcd562012-08-23 18:09:54 +0000979
reed@google.comed43dff2013-06-04 16:56:27 +0000980 /**
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.com8f6ef402013-06-05 07:01:06 +0000991
reed@google.comed43dff2013-06-04 16:56:27 +0000992 SkMatrix* setTextMatrix(SkMatrix* matrix) const {
993 return SetTextMatrix(matrix, fTextSize, fTextScaleX, fTextSkewX);
994 }
skia.committer@gmail.com8f6ef402013-06-05 07:01:06 +0000995
robertphillips@google.com791f12e2013-02-14 13:53:53 +0000996 SkDEVCODE(void toString(SkString*) const;)
997
reed@google.comd5f20792012-05-16 14:15:02 +0000998private:
999 SkTypeface* fTypeface;
1000 SkScalar fTextSize;
1001 SkScalar fTextScaleX;
1002 SkScalar fTextSkewX;
reed@google.com1f1543f2012-09-12 21:08:33 +00001003#ifdef SK_SUPPORT_HINTING_SCALE_FACTOR
1004 SkScalar fHintingScaleFactor;
1005#endif
reed@google.coma584aed2012-05-16 14:06:02 +00001006
reed@google.comd5f20792012-05-16 14:15:02 +00001007 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.comb0a34d82012-07-11 19:57:55 +00001015 SkAnnotation* fAnnotation;
reed@google.comd5f20792012-05-16 14:15:02 +00001016
1017 SkColor fColor;
1018 SkScalar fWidth;
1019 SkScalar fMiterLimit;
reed@google.comb0a34d82012-07-11 19:57:55 +00001020 // all of these bitfields should add up to 32
1021 unsigned fFlags : 16;
reed@google.comd5f20792012-05-16 14:15:02 +00001022 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.comb0a34d82012-07-11 19:57:55 +00001028 unsigned fPrivFlags : 4; // these are not flattened/unflattened
1029
1030 enum PrivFlags {
1031 kNoDrawAnnotation_PrivFlag = 1 << 0,
1032 };
reed@google.comd5f20792012-05-16 14:15:02 +00001033
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.com532470f2013-01-22 19:25:14 +00001041 SkGlyphCache* detachCache(const SkDeviceProperties* deviceProperties, const SkMatrix*) const;
reed@google.comd5f20792012-05-16 14:15:02 +00001042
bungeman@google.com532470f2013-01-22 19:25:14 +00001043 void descriptorProc(const SkDeviceProperties* deviceProperties, const SkMatrix* deviceMatrix,
reed@google.com90808e82013-03-19 14:44:54 +00001044 void (*proc)(SkTypeface*, const SkDescriptor*, void*),
reed@google.comd5f20792012-05-16 14:15:02 +00001045 void* context, bool ignoreGamma = false) const;
reed@android.comd252db02009-04-01 18:31:44 +00001046
bungeman@google.comb24b4fa2012-09-04 13:49:59 +00001047 static void Term();
1048
reed@android.com8a1c16f2008-12-17 15:59:43 +00001049 enum {
reed@google.comed43dff2013-06-04 16:56:27 +00001050 /* 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.com8a1c16f2008-12-17 15:59:43 +00001072 };
reed@google.comed43dff2013-06-04 16:56:27 +00001073
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.com8f6ef402013-06-05 07:01:06 +00001078
reed@google.comed43dff2013-06-04 16:56:27 +00001079 // 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.org28be72b2010-11-11 21:37:00 +00001090 friend class SkAutoGlyphCache;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001091 friend class SkCanvas;
1092 friend class SkDraw;
bungeman@google.comb24b4fa2012-09-04 13:49:59 +00001093 friend class SkGraphics; // So Term() can be called.
vandebo@chromium.org28be72b2010-11-11 21:37:00 +00001094 friend class SkPDFDevice;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001095 friend class SkTextToPathIter;
reed@google.comed43dff2013-06-04 16:56:27 +00001096 friend class SkCanonicalizePaint;
djsollen@google.comb44cd652011-12-01 17:09:21 +00001097
1098#ifdef SK_BUILD_FOR_ANDROID
commit-bot@chromium.orgc7a20e42013-05-13 14:09:13 +00001099 SkPaintOptionsAndroid fPaintOptionsAndroid;
1100
djsollen@google.comb44cd652011-12-01 17:09:21 +00001101 // 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.com8a1c16f2008-12-17 15:59:43 +00001105};
1106
reed@android.com8a1c16f2008-12-17 15:59:43 +00001107#endif