blob: 624f39c36d89f88c989cecbf074547ad0e4ffbcd [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
46/** \class SkPaint
47
48 The SkPaint class holds the style and color information about how to draw
49 geometries, text and bitmaps.
50*/
ctguil@chromium.org7ffb1b22011-03-15 21:27:08 +000051class SK_API SkPaint {
reed@android.com8a1c16f2008-12-17 15:59:43 +000052public:
53 SkPaint();
54 SkPaint(const SkPaint& paint);
55 ~SkPaint();
56
57 SkPaint& operator=(const SkPaint&);
58
reed@google.comb530ef52011-07-20 19:55:42 +000059 SK_API friend bool operator==(const SkPaint& a, const SkPaint& b);
60 friend bool operator!=(const SkPaint& a, const SkPaint& b) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000061 return !(a == b);
62 }
reed@google.com9d07fec2011-03-16 20:02:59 +000063
reed@android.com8a1c16f2008-12-17 15:59:43 +000064 void flatten(SkFlattenableWriteBuffer&) const;
65 void unflatten(SkFlattenableReadBuffer&);
66
67 /** Restores the paint to its initial settings.
68 */
69 void reset();
70
agl@chromium.org309485b2009-07-21 17:41:32 +000071 /** Specifies the level of hinting to be performed. These names are taken
72 from the Gnome/Cairo names for the same. They are translated into
73 Freetype concepts the same as in cairo-ft-font.c:
74 kNo_Hinting -> FT_LOAD_NO_HINTING
75 kSlight_Hinting -> FT_LOAD_TARGET_LIGHT
76 kNormal_Hinting -> <default, no option>
77 kFull_Hinting -> <same as kNormalHinting, unless we are rendering
78 subpixel glyphs, in which case TARGET_LCD or
79 TARGET_LCD_V is used>
80 */
81 enum Hinting {
82 kNo_Hinting = 0,
83 kSlight_Hinting = 1,
84 kNormal_Hinting = 2, //!< this is the default
tomhudson@google.com1f902872012-06-01 13:15:47 +000085 kFull_Hinting = 3
agl@chromium.org309485b2009-07-21 17:41:32 +000086 };
87
reed@google.com9d07fec2011-03-16 20:02:59 +000088 Hinting getHinting() const {
agl@chromium.org309485b2009-07-21 17:41:32 +000089 return static_cast<Hinting>(fHinting);
90 }
91
djsollen@google.comf5dbe2f2011-04-15 13:41:26 +000092 void setHinting(Hinting hintingLevel);
agl@chromium.org309485b2009-07-21 17:41:32 +000093
reed@android.com8a1c16f2008-12-17 15:59:43 +000094 /** Specifies the bit values that are stored in the paint's flags.
95 */
96 enum Flags {
97 kAntiAlias_Flag = 0x01, //!< mask to enable antialiasing
98 kFilterBitmap_Flag = 0x02, //!< mask to enable bitmap filtering
99 kDither_Flag = 0x04, //!< mask to enable dithering
100 kUnderlineText_Flag = 0x08, //!< mask to enable underline text
101 kStrikeThruText_Flag = 0x10, //!< mask to enable strike-thru text
102 kFakeBoldText_Flag = 0x20, //!< mask to enable fake-bold text
103 kLinearText_Flag = 0x40, //!< mask to enable linear-text
agl@chromium.org309485b2009-07-21 17:41:32 +0000104 kSubpixelText_Flag = 0x80, //!< mask to enable subpixel text positioning
reed@android.com8a1c16f2008-12-17 15:59:43 +0000105 kDevKernText_Flag = 0x100, //!< mask to enable device kerning text
agl@chromium.org309485b2009-07-21 17:41:32 +0000106 kLCDRenderText_Flag = 0x200, //!< mask to enable subpixel glyph renderering
agl@chromium.orge95c91e2010-01-04 18:27:55 +0000107 kEmbeddedBitmapText_Flag = 0x400, //!< mask to enable embedded bitmap strikes
agl@chromium.orga2c71cb2010-06-17 20:49:17 +0000108 kAutoHinting_Flag = 0x800, //!< mask to force Freetype's autohinter
reed@google.com830a23e2011-11-10 15:20:49 +0000109 kVerticalText_Flag = 0x1000,
reed@google.com8351aab2012-01-18 17:06:35 +0000110 kGenA8FromLCD_Flag = 0x2000, // hack for GDI -- do not use if you can help it
reed@google.com25b3bd52013-05-22 13:55:54 +0000111 kBicubicFilterBitmap_Flag = 0x4000, // temporary flag
reed@google.com32538982011-09-30 20:57:05 +0000112
agl@chromium.org309485b2009-07-21 17:41:32 +0000113 // when adding extra flags, note that the fFlags member is specified
114 // with a bit-width and you'll have to expand it.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000115
reed@google.com25b3bd52013-05-22 13:55:54 +0000116 kAllFlags = 0x7FFF
reed@android.com8a1c16f2008-12-17 15:59:43 +0000117 };
118
119 /** Return the paint's flags. Use the Flag enum to test flag values.
120 @return the paint's flags (see enums ending in _Flag for bit masks)
121 */
122 uint32_t getFlags() const { return fFlags; }
123
124 /** Set the paint's flags. Use the Flag enum to specific flag values.
125 @param flags The new flag bits for the paint (see Flags enum)
126 */
127 void setFlags(uint32_t flags);
128
129 /** Helper for getFlags(), returning true if kAntiAlias_Flag bit is set
130 @return true if the antialias bit is set in the paint's flags.
131 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000132 bool isAntiAlias() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000133 return SkToBool(this->getFlags() & kAntiAlias_Flag);
134 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000135
reed@android.com8a1c16f2008-12-17 15:59:43 +0000136 /** Helper for setFlags(), setting or clearing the kAntiAlias_Flag bit
137 @param aa true to enable antialiasing, false to disable it
138 */
139 void setAntiAlias(bool aa);
reed@google.com9d07fec2011-03-16 20:02:59 +0000140
reed@android.com8a1c16f2008-12-17 15:59:43 +0000141 /** Helper for getFlags(), returning true if kDither_Flag bit is set
142 @return true if the dithering bit is set in the paint's flags.
143 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000144 bool isDither() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000145 return SkToBool(this->getFlags() & kDither_Flag);
146 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000147
reed@android.com8a1c16f2008-12-17 15:59:43 +0000148 /** Helper for setFlags(), setting or clearing the kDither_Flag bit
149 @param dither true to enable dithering, false to disable it
150 */
151 void setDither(bool dither);
reed@google.com9d07fec2011-03-16 20:02:59 +0000152
reed@android.com8a1c16f2008-12-17 15:59:43 +0000153 /** Helper for getFlags(), returning true if kLinearText_Flag bit is set
154 @return true if the lineartext bit is set in the paint's flags
155 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000156 bool isLinearText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000157 return SkToBool(this->getFlags() & kLinearText_Flag);
158 }
159
160 /** Helper for setFlags(), setting or clearing the kLinearText_Flag bit
161 @param linearText true to set the linearText bit in the paint's flags,
162 false to clear it.
163 */
164 void setLinearText(bool linearText);
165
166 /** Helper for getFlags(), returning true if kSubpixelText_Flag bit is set
167 @return true if the lineartext bit is set in the paint's flags
168 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000169 bool isSubpixelText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000170 return SkToBool(this->getFlags() & kSubpixelText_Flag);
171 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000172
reed@google.com84b437e2011-08-01 12:45:35 +0000173 /**
174 * Helper for setFlags(), setting or clearing the kSubpixelText_Flag.
175 * @param subpixelText true to set the subpixelText bit in the paint's
176 * flags, false to clear it.
177 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000178 void setSubpixelText(bool subpixelText);
agl@chromium.org309485b2009-07-21 17:41:32 +0000179
reed@google.com9d07fec2011-03-16 20:02:59 +0000180 bool isLCDRenderText() const {
agl@chromium.org309485b2009-07-21 17:41:32 +0000181 return SkToBool(this->getFlags() & kLCDRenderText_Flag);
182 }
183
reed@google.com84b437e2011-08-01 12:45:35 +0000184 /**
185 * Helper for setFlags(), setting or clearing the kLCDRenderText_Flag.
186 * Note: antialiasing must also be on for lcd rendering
187 * @param lcdText true to set the LCDRenderText bit in the paint's flags,
188 * false to clear it.
189 */
190 void setLCDRenderText(bool lcdText);
agl@chromium.org309485b2009-07-21 17:41:32 +0000191
reed@google.com9d07fec2011-03-16 20:02:59 +0000192 bool isEmbeddedBitmapText() const {
agl@chromium.orge95c91e2010-01-04 18:27:55 +0000193 return SkToBool(this->getFlags() & kEmbeddedBitmapText_Flag);
194 }
195
196 /** Helper for setFlags(), setting or clearing the kEmbeddedBitmapText_Flag bit
197 @param useEmbeddedBitmapText true to set the kEmbeddedBitmapText bit in the paint's flags,
198 false to clear it.
199 */
200 void setEmbeddedBitmapText(bool useEmbeddedBitmapText);
201
reed@google.com9d07fec2011-03-16 20:02:59 +0000202 bool isAutohinted() const {
agl@chromium.orga2c71cb2010-06-17 20:49:17 +0000203 return SkToBool(this->getFlags() & kAutoHinting_Flag);
204 }
205
206 /** Helper for setFlags(), setting or clearing the kAutoHinting_Flag bit
207 @param useAutohinter true to set the kEmbeddedBitmapText bit in the
208 paint's flags,
209 false to clear it.
210 */
211 void setAutohinted(bool useAutohinter);
212
reed@google.com830a23e2011-11-10 15:20:49 +0000213 bool isVerticalText() const {
214 return SkToBool(this->getFlags() & kVerticalText_Flag);
215 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000216
reed@google.com830a23e2011-11-10 15:20:49 +0000217 /**
218 * Helper for setting or clearing the kVerticalText_Flag bit in
219 * setFlags(...).
220 *
221 * If this bit is set, then advances are treated as Y values rather than
222 * X values, and drawText will places its glyphs vertically rather than
223 * horizontally.
224 */
225 void setVerticalText(bool);
226
reed@android.com8a1c16f2008-12-17 15:59:43 +0000227 /** Helper for getFlags(), returning true if kUnderlineText_Flag bit is set
228 @return true if the underlineText bit is set in the paint's flags.
229 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000230 bool isUnderlineText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000231 return SkToBool(this->getFlags() & kUnderlineText_Flag);
232 }
233
234 /** Helper for setFlags(), setting or clearing the kUnderlineText_Flag bit
235 @param underlineText true to set the underlineText bit in the paint's
236 flags, false to clear it.
237 */
238 void setUnderlineText(bool underlineText);
239
240 /** Helper for getFlags(), returns true if kStrikeThruText_Flag bit is set
241 @return true if the strikeThruText bit is set in the paint's flags.
242 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000243 bool isStrikeThruText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000244 return SkToBool(this->getFlags() & kStrikeThruText_Flag);
245 }
246
247 /** Helper for setFlags(), setting or clearing the kStrikeThruText_Flag bit
248 @param strikeThruText true to set the strikeThruText bit in the
249 paint's flags, false to clear it.
250 */
251 void setStrikeThruText(bool strikeThruText);
252
253 /** Helper for getFlags(), returns true if kFakeBoldText_Flag bit is set
254 @return true if the kFakeBoldText_Flag bit is set in the paint's flags.
255 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000256 bool isFakeBoldText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000257 return SkToBool(this->getFlags() & kFakeBoldText_Flag);
258 }
259
260 /** Helper for setFlags(), setting or clearing the kFakeBoldText_Flag bit
261 @param fakeBoldText true to set the kFakeBoldText_Flag bit in the paint's
262 flags, false to clear it.
263 */
264 void setFakeBoldText(bool fakeBoldText);
265
266 /** Helper for getFlags(), returns true if kDevKernText_Flag bit is set
267 @return true if the kernText bit is set in the paint's flags.
268 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000269 bool isDevKernText() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000270 return SkToBool(this->getFlags() & kDevKernText_Flag);
271 }
272
273 /** Helper for setFlags(), setting or clearing the kKernText_Flag bit
274 @param kernText true to set the kKernText_Flag bit in the paint's
275 flags, false to clear it.
276 */
277 void setDevKernText(bool devKernText);
278
reed@google.com9d07fec2011-03-16 20:02:59 +0000279 bool isFilterBitmap() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000280 return SkToBool(this->getFlags() & kFilterBitmap_Flag);
281 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000282
reed@android.com8a1c16f2008-12-17 15:59:43 +0000283 void setFilterBitmap(bool filterBitmap);
284
285 /** Styles apply to rect, oval, path, and text.
286 Bitmaps are always drawn in "fill", and lines are always drawn in
287 "stroke".
reed@google.com9d07fec2011-03-16 20:02:59 +0000288
reed@android.comed881c22009-09-15 14:10:42 +0000289 Note: strokeandfill implicitly draws the result with
290 SkPath::kWinding_FillType, so if the original path is even-odd, the
291 results may not appear the same as if it was drawn twice, filled and
292 then stroked.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000293 */
294 enum Style {
reed@android.comed881c22009-09-15 14:10:42 +0000295 kFill_Style, //!< fill the geometry
296 kStroke_Style, //!< stroke the geometry
297 kStrokeAndFill_Style, //!< fill and stroke the geometry
mike@reedtribe.orgaac2fb82013-02-04 05:17:10 +0000298 };
299 enum {
300 kStyleCount = kStrokeAndFill_Style + 1
reed@android.com8a1c16f2008-12-17 15:59:43 +0000301 };
302
303 /** Return the paint's style, used for controlling how primitives'
304 geometries are interpreted (except for drawBitmap, which always assumes
305 kFill_Style).
306 @return the paint's Style
307 */
308 Style getStyle() const { return (Style)fStyle; }
309
310 /** Set the paint's style, used for controlling how primitives'
311 geometries are interpreted (except for drawBitmap, which always assumes
312 Fill).
313 @param style The new style to set in the paint
314 */
315 void setStyle(Style style);
316
317 /** Return the paint's color. Note that the color is a 32bit value
318 containing alpha as well as r,g,b. This 32bit value is not
319 premultiplied, meaning that its alpha can be any value, regardless of
320 the values of r,g,b.
321 @return the paint's color (and alpha).
322 */
323 SkColor getColor() const { return fColor; }
324
325 /** Set the paint's color. Note that the color is a 32bit value containing
326 alpha as well as r,g,b. This 32bit value is not premultiplied, meaning
327 that its alpha can be any value, regardless of the values of r,g,b.
328 @param color The new color (including alpha) to set in the paint.
329 */
330 void setColor(SkColor color);
331
332 /** Helper to getColor() that just returns the color's alpha value.
333 @return the alpha component of the paint's color.
334 */
335 uint8_t getAlpha() const { return SkToU8(SkColorGetA(fColor)); }
reed@google.com9d07fec2011-03-16 20:02:59 +0000336
reed@android.com8a1c16f2008-12-17 15:59:43 +0000337 /** Helper to setColor(), that only assigns the color's alpha value,
338 leaving its r,g,b values unchanged.
339 @param a set the alpha component (0..255) of the paint's color.
340 */
341 void setAlpha(U8CPU a);
342
343 /** Helper to setColor(), that takes a,r,g,b and constructs the color value
344 using SkColorSetARGB()
345 @param a The new alpha component (0..255) of the paint's color.
346 @param r The new red component (0..255) of the paint's color.
347 @param g The new green component (0..255) of the paint's color.
348 @param b The new blue component (0..255) of the paint's color.
349 */
350 void setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b);
351
reed@google.com9d07fec2011-03-16 20:02:59 +0000352 /** Return the width for stroking.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000353 <p />
354 A value of 0 strokes in hairline mode.
355 Hairlines always draw 1-pixel wide, regardless of the matrix.
356 @return the paint's stroke width, used whenever the paint's style is
357 Stroke or StrokeAndFill.
358 */
359 SkScalar getStrokeWidth() const { return fWidth; }
360
reed@google.com9d07fec2011-03-16 20:02:59 +0000361 /** Set the width for stroking.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000362 Pass 0 to stroke in hairline mode.
363 Hairlines always draw 1-pixel wide, regardless of the matrix.
364 @param width set the paint's stroke width, used whenever the paint's
365 style is Stroke or StrokeAndFill.
366 */
367 void setStrokeWidth(SkScalar width);
368
369 /** Return the paint's stroke miter value. This is used to control the
370 behavior of miter joins when the joins angle is sharp.
371 @return the paint's miter limit, used whenever the paint's style is
372 Stroke or StrokeAndFill.
373 */
374 SkScalar getStrokeMiter() const { return fMiterLimit; }
375
376 /** Set the paint's stroke miter value. This is used to control the
377 behavior of miter joins when the joins angle is sharp. This value must
378 be >= 0.
379 @param miter set the miter limit on the paint, used whenever the
380 paint's style is Stroke or StrokeAndFill.
381 */
382 void setStrokeMiter(SkScalar miter);
383
384 /** Cap enum specifies the settings for the paint's strokecap. This is the
385 treatment that is applied to the beginning and end of each non-closed
386 contour (e.g. lines).
387 */
388 enum Cap {
389 kButt_Cap, //!< begin/end contours with no extension
390 kRound_Cap, //!< begin/end contours with a semi-circle extension
391 kSquare_Cap, //!< begin/end contours with a half square extension
392
393 kCapCount,
394 kDefault_Cap = kButt_Cap
395 };
396
397 /** Join enum specifies the settings for the paint's strokejoin. This is
398 the treatment that is applied to corners in paths and rectangles.
399 */
400 enum Join {
401 kMiter_Join, //!< connect path segments with a sharp join
402 kRound_Join, //!< connect path segments with a round join
403 kBevel_Join, //!< connect path segments with a flat bevel join
404
405 kJoinCount,
406 kDefault_Join = kMiter_Join
407 };
408
409 /** Return the paint's stroke cap type, controlling how the start and end
410 of stroked lines and paths are treated.
411 @return the line cap style for the paint, used whenever the paint's
412 style is Stroke or StrokeAndFill.
413 */
414 Cap getStrokeCap() const { return (Cap)fCapType; }
415
416 /** Set the paint's stroke cap type.
417 @param cap set the paint's line cap style, used whenever the paint's
418 style is Stroke or StrokeAndFill.
419 */
420 void setStrokeCap(Cap cap);
421
422 /** Return the paint's stroke join type.
423 @return the paint's line join style, used whenever the paint's style is
424 Stroke or StrokeAndFill.
425 */
426 Join getStrokeJoin() const { return (Join)fJoinType; }
427
428 /** Set the paint's stroke join type.
429 @param join set the paint's line join style, used whenever the paint's
430 style is Stroke or StrokeAndFill.
431 */
432 void setStrokeJoin(Join join);
433
reed@google.com4bbdeac2013-01-24 21:03:11 +0000434 /**
435 * Applies any/all effects (patheffect, stroking) to src, returning the
436 * result in dst. The result is that drawing src with this paint will be
437 * the same as drawing dst with a default paint (at least from the
438 * geometric perspective).
439 *
440 * @param src input path
441 * @param dst output path (may be the same as src)
442 * @param cullRect If not null, the dst path may be culled to this rect.
443 * @return true if the path should be filled, or false if it should be
444 * drawn with a hairline (width == 0)
445 */
446 bool getFillPath(const SkPath& src, SkPath* dst,
447 const SkRect* cullRect = NULL) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000448
reed@android.com8a1c16f2008-12-17 15:59:43 +0000449 /** Get the paint's shader object.
450 <p />
451 The shader's reference count is not affected.
452 @return the paint's shader (or NULL)
453 */
454 SkShader* getShader() const { return fShader; }
455
456 /** Set or clear the shader object.
reed@google.com880dc472012-05-11 14:47:03 +0000457 * Shaders specify the source color(s) for what is being drawn. If a paint
458 * has no shader, then the paint's color is used. If the paint has a
459 * shader, then the shader's color(s) are use instead, but they are
460 * modulated by the paint's alpha. This makes it easy to create a shader
461 * once (e.g. bitmap tiling or gradient) and then change its transparency
462 * w/o having to modify the original shader... only the paint's alpha needs
463 * to be modified.
464 * <p />
465 * Pass NULL to clear any previous shader.
466 * As a convenience, the parameter passed is also returned.
467 * If a previous shader exists, its reference count is decremented.
468 * If shader is not NULL, its reference count is incremented.
469 * @param shader May be NULL. The shader to be installed in the paint
470 * @return shader
471 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000472 SkShader* setShader(SkShader* shader);
reed@google.com9d07fec2011-03-16 20:02:59 +0000473
reed@android.com8a1c16f2008-12-17 15:59:43 +0000474 /** Get the paint's colorfilter. If there is a colorfilter, its reference
475 count is not changed.
476 @return the paint's colorfilter (or NULL)
477 */
478 SkColorFilter* getColorFilter() const { return fColorFilter; }
479
480 /** Set or clear the paint's colorfilter, returning the parameter.
481 <p />
482 If the paint already has a filter, its reference count is decremented.
483 If filter is not NULL, its reference count is incremented.
484 @param filter May be NULL. The filter to be installed in the paint
485 @return filter
486 */
487 SkColorFilter* setColorFilter(SkColorFilter* filter);
488
489 /** Get the paint's xfermode object.
490 <p />
491 The xfermode's reference count is not affected.
492 @return the paint's xfermode (or NULL)
493 */
494 SkXfermode* getXfermode() const { return fXfermode; }
495
496 /** Set or clear the xfermode object.
497 <p />
498 Pass NULL to clear any previous xfermode.
499 As a convenience, the parameter passed is also returned.
500 If a previous xfermode exists, its reference count is decremented.
501 If xfermode is not NULL, its reference count is incremented.
502 @param xfermode May be NULL. The new xfermode to be installed in the
503 paint
504 @return xfermode
505 */
506 SkXfermode* setXfermode(SkXfermode* xfermode);
reed@android.coma0f5d152009-06-22 17:38:10 +0000507
508 /** Create an xfermode based on the specified Mode, and assign it into the
509 paint, returning the mode that was set. If the Mode is SrcOver, then
510 the paint's xfermode is set to null.
511 */
reed@android.com0baf1932009-06-24 12:41:42 +0000512 SkXfermode* setXfermodeMode(SkXfermode::Mode);
reed@android.coma0f5d152009-06-22 17:38:10 +0000513
reed@android.com8a1c16f2008-12-17 15:59:43 +0000514 /** Get the paint's patheffect object.
515 <p />
516 The patheffect reference count is not affected.
517 @return the paint's patheffect (or NULL)
518 */
519 SkPathEffect* getPathEffect() const { return fPathEffect; }
520
521 /** Set or clear the patheffect object.
522 <p />
523 Pass NULL to clear any previous patheffect.
524 As a convenience, the parameter passed is also returned.
525 If a previous patheffect exists, its reference count is decremented.
526 If patheffect is not NULL, its reference count is incremented.
527 @param effect May be NULL. The new patheffect to be installed in the
528 paint
529 @return effect
530 */
531 SkPathEffect* setPathEffect(SkPathEffect* effect);
532
533 /** Get the paint's maskfilter object.
534 <p />
535 The maskfilter reference count is not affected.
536 @return the paint's maskfilter (or NULL)
537 */
538 SkMaskFilter* getMaskFilter() const { return fMaskFilter; }
539
540 /** Set or clear the maskfilter object.
541 <p />
542 Pass NULL to clear any previous maskfilter.
543 As a convenience, the parameter passed is also returned.
544 If a previous maskfilter exists, its reference count is decremented.
545 If maskfilter is not NULL, its reference count is incremented.
546 @param maskfilter May be NULL. The new maskfilter to be installed in
547 the paint
548 @return maskfilter
549 */
550 SkMaskFilter* setMaskFilter(SkMaskFilter* maskfilter);
551
552 // These attributes are for text/fonts
553
554 /** Get the paint's typeface object.
555 <p />
556 The typeface object identifies which font to use when drawing or
557 measuring text. The typeface reference count is not affected.
558 @return the paint's typeface (or NULL)
559 */
560 SkTypeface* getTypeface() const { return fTypeface; }
561
562 /** Set or clear the typeface object.
563 <p />
564 Pass NULL to clear any previous typeface.
565 As a convenience, the parameter passed is also returned.
566 If a previous typeface exists, its reference count is decremented.
567 If typeface is not NULL, its reference count is incremented.
568 @param typeface May be NULL. The new typeface to be installed in the
569 paint
570 @return typeface
571 */
572 SkTypeface* setTypeface(SkTypeface* typeface);
573
574 /** Get the paint's rasterizer (or NULL).
575 <p />
576 The raster controls how paths/text are turned into alpha masks.
577 @return the paint's rasterizer (or NULL)
578 */
579 SkRasterizer* getRasterizer() const { return fRasterizer; }
580
581 /** Set or clear the rasterizer object.
582 <p />
583 Pass NULL to clear any previous rasterizer.
584 As a convenience, the parameter passed is also returned.
585 If a previous rasterizer exists in the paint, its reference count is
586 decremented. If rasterizer is not NULL, its reference count is
587 incremented.
588 @param rasterizer May be NULL. The new rasterizer to be installed in
589 the paint.
590 @return rasterizer
591 */
592 SkRasterizer* setRasterizer(SkRasterizer* rasterizer);
593
reed@google.com15356a62011-11-03 19:29:08 +0000594 SkImageFilter* getImageFilter() const { return fImageFilter; }
595 SkImageFilter* setImageFilter(SkImageFilter*);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000596
reed@google.comb0a34d82012-07-11 19:57:55 +0000597 SkAnnotation* getAnnotation() const { return fAnnotation; }
598 SkAnnotation* setAnnotation(SkAnnotation*);
599
600 /**
601 * Returns true if there is an annotation installed on this paint, and
602 * the annotation specifics no-drawing.
603 */
604 bool isNoDrawAnnotation() const {
605 return SkToBool(fPrivFlags & kNoDrawAnnotation_PrivFlag);
606 }
reed@google.com15356a62011-11-03 19:29:08 +0000607
reed@google.com9d07fec2011-03-16 20:02:59 +0000608 /**
609 * Return the paint's SkDrawLooper (if any). Does not affect the looper's
610 * reference count.
611 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000612 SkDrawLooper* getLooper() const { return fLooper; }
reed@google.com9d07fec2011-03-16 20:02:59 +0000613
614 /**
615 * Set or clear the looper object.
616 * <p />
617 * Pass NULL to clear any previous looper.
618 * As a convenience, the parameter passed is also returned.
619 * If a previous looper exists in the paint, its reference count is
620 * decremented. If looper is not NULL, its reference count is
621 * incremented.
622 * @param looper May be NULL. The new looper to be installed in the paint.
623 * @return looper
624 */
625 SkDrawLooper* setLooper(SkDrawLooper* looper);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000626
627 enum Align {
628 kLeft_Align,
629 kCenter_Align,
630 kRight_Align,
631
632 kAlignCount
633 };
reed@google.com9d07fec2011-03-16 20:02:59 +0000634
reed@android.com8a1c16f2008-12-17 15:59:43 +0000635 /** Return the paint's Align value for drawing text.
636 @return the paint's Align value for drawing text.
637 */
638 Align getTextAlign() const { return (Align)fTextAlign; }
reed@google.com9d07fec2011-03-16 20:02:59 +0000639
reed@android.com8a1c16f2008-12-17 15:59:43 +0000640 /** Set the paint's text alignment.
641 @param align set the paint's Align value for drawing text.
642 */
643 void setTextAlign(Align align);
644
645 /** Return the paint's text size.
646 @return the paint's text size.
647 */
648 SkScalar getTextSize() const { return fTextSize; }
649
650 /** Set the paint's text size. This value must be > 0
651 @param textSize set the paint's text size.
652 */
653 void setTextSize(SkScalar textSize);
654
655 /** Return the paint's horizontal scale factor for text. The default value
656 is 1.0.
657 @return the paint's scale factor in X for drawing/measuring text
658 */
659 SkScalar getTextScaleX() const { return fTextScaleX; }
660
661 /** Set the paint's horizontal scale factor for text. The default value
662 is 1.0. Values > 1.0 will stretch the text wider. Values < 1.0 will
663 stretch the text narrower.
664 @param scaleX set the paint's scale factor in X for drawing/measuring
665 text.
666 */
667 void setTextScaleX(SkScalar scaleX);
668
669 /** Return the paint's horizontal skew factor for text. The default value
670 is 0.
671 @return the paint's skew factor in X for drawing text.
672 */
673 SkScalar getTextSkewX() const { return fTextSkewX; }
674
675 /** Set the paint's horizontal skew factor for text. The default value
676 is 0. For approximating oblique text, use values around -0.25.
677 @param skewX set the paint's skew factor in X for drawing text.
678 */
679 void setTextSkewX(SkScalar skewX);
680
reed@google.com1f1543f2012-09-12 21:08:33 +0000681#ifdef SK_SUPPORT_HINTING_SCALE_FACTOR
682 /** Return the paint's scale factor used for correctly rendering
683 glyphs in high DPI mode without text subpixel positioning.
684 @return the scale factor used for rendering glyphs in high DPI mode.
685 */
686 SkScalar getHintingScaleFactor() const { return fHintingScaleFactor; }
687
688 /** Set the paint's scale factor used for correctly rendering
689 glyphs in high DPI mode without text subpixel positioning.
690 @param the scale factor used for rendering glyphs in high DPI mode.
691 */
692 void setHintingScaleFactor(SkScalar hintingScaleFactor);
693#endif
694
reed@android.com8a1c16f2008-12-17 15:59:43 +0000695 /** Describes how to interpret the text parameters that are passed to paint
696 methods like measureText() and getTextWidths().
697 */
698 enum TextEncoding {
699 kUTF8_TextEncoding, //!< the text parameters are UTF8
700 kUTF16_TextEncoding, //!< the text parameters are UTF16
robertphillips@google.com69705572012-03-21 19:46:50 +0000701 kUTF32_TextEncoding, //!< the text parameters are UTF32
reed@android.com8a1c16f2008-12-17 15:59:43 +0000702 kGlyphID_TextEncoding //!< the text parameters are glyph indices
703 };
reed@google.com9d07fec2011-03-16 20:02:59 +0000704
705 TextEncoding getTextEncoding() const { return (TextEncoding)fTextEncoding; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000706
707 void setTextEncoding(TextEncoding encoding);
708
709 struct FontMetrics {
710 SkScalar fTop; //!< The greatest distance above the baseline for any glyph (will be <= 0)
711 SkScalar fAscent; //!< The recommended distance above the baseline (will be <= 0)
712 SkScalar fDescent; //!< The recommended distance below the baseline (will be >= 0)
713 SkScalar fBottom; //!< The greatest distance below the baseline for any glyph (will be >= 0)
714 SkScalar fLeading; //!< The recommended distance to add between lines of text (will be >= 0)
agl@chromium.orgcc3096b2009-04-22 22:09:04 +0000715 SkScalar fAvgCharWidth; //!< the average charactor width (>= 0)
716 SkScalar fXMin; //!< The minimum bounding box x value for all glyphs
717 SkScalar fXMax; //!< The maximum bounding box x value for all glyphs
718 SkScalar fXHeight; //!< the height of an 'x' in px, or 0 if no 'x' in face
reed@android.com8a1c16f2008-12-17 15:59:43 +0000719 };
reed@google.com9d07fec2011-03-16 20:02:59 +0000720
reed@android.com8a1c16f2008-12-17 15:59:43 +0000721 /** Return the recommend spacing between lines (which will be
722 fDescent - fAscent + fLeading).
723 If metrics is not null, return in it the font metrics for the
reed@google.com9d07fec2011-03-16 20:02:59 +0000724 typeface/pointsize/etc. currently set in the paint.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000725 @param metrics If not null, returns the font metrics for the
726 current typeface/pointsize/etc setting in this
727 paint.
728 @param scale If not 0, return width as if the canvas were scaled
729 by this value
730 @param return the recommended spacing between lines
731 */
732 SkScalar getFontMetrics(FontMetrics* metrics, SkScalar scale = 0) const;
reed@google.com9d07fec2011-03-16 20:02:59 +0000733
reed@android.com8a1c16f2008-12-17 15:59:43 +0000734 /** Return the recommend line spacing. This will be
735 fDescent - fAscent + fLeading
736 */
737 SkScalar getFontSpacing() const { return this->getFontMetrics(NULL, 0); }
738
739 /** Convert the specified text into glyph IDs, returning the number of
740 glyphs ID written. If glyphs is NULL, it is ignore and only the count
741 is returned.
742 */
743 int textToGlyphs(const void* text, size_t byteLength,
744 uint16_t glyphs[]) const;
745
reed@android.coma5dcaf62010-02-05 17:12:32 +0000746 /** Return true if all of the specified text has a corresponding non-zero
747 glyph ID. If any of the code-points in the text are not supported in
748 the typeface (i.e. the glyph ID would be zero), then return false.
749
750 If the text encoding for the paint is kGlyph_TextEncoding, then this
751 returns true if all of the specified glyph IDs are non-zero.
752 */
753 bool containsText(const void* text, size_t byteLength) const;
754
reed@android.com9d3a9852010-01-08 14:07:42 +0000755 /** Convert the glyph array into Unichars. Unconvertable glyphs are mapped
756 to zero. Note: this does not look at the text-encoding setting in the
757 paint, only at the typeface.
758 */
759 void glyphsToUnichars(const uint16_t glyphs[], int count,
760 SkUnichar text[]) const;
761
reed@android.com8a1c16f2008-12-17 15:59:43 +0000762 /** Return the number of drawable units in the specified text buffer.
763 This looks at the current TextEncoding field of the paint. If you also
764 want to have the text converted into glyph IDs, call textToGlyphs
765 instead.
766 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000767 int countText(const void* text, size_t byteLength) const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000768 return this->textToGlyphs(text, byteLength, NULL);
769 }
770
reed@google.com44da42e2011-11-10 20:04:47 +0000771 /** Return the width of the text. This will return the vertical measure
772 * if isVerticalText() is true, in which case the returned value should
773 * be treated has a height instead of a width.
774 *
775 * @param text The text to be measured
776 * @param length Number of bytes of text to measure
777 * @param bounds If not NULL, returns the bounds of the text,
778 * relative to (0, 0).
779 * @param scale If not 0, return width as if the canvas were scaled
780 * by this value
781 * @return The advance width of the text
782 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000783 SkScalar measureText(const void* text, size_t length,
784 SkRect* bounds, SkScalar scale = 0) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000785
reed@google.com44da42e2011-11-10 20:04:47 +0000786 /** Return the width of the text. This will return the vertical measure
787 * if isVerticalText() is true, in which case the returned value should
788 * be treated has a height instead of a width.
789 *
790 * @param text Address of the text
791 * @param length Number of bytes of text to measure
reed@google.com97ecd1d2012-05-15 19:25:17 +0000792 * @return The advance width of the text
reed@google.com44da42e2011-11-10 20:04:47 +0000793 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000794 SkScalar measureText(const void* text, size_t length) const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000795 return this->measureText(text, length, NULL, 0);
796 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000797
reed@android.com8a1c16f2008-12-17 15:59:43 +0000798 /** Specify the direction the text buffer should be processed in breakText()
799 */
800 enum TextBufferDirection {
801 /** When measuring text for breakText(), begin at the start of the text
802 buffer and proceed forward through the data. This is the default.
803 */
804 kForward_TextBufferDirection,
805 /** When measuring text for breakText(), begin at the end of the text
806 buffer and proceed backwards through the data.
807 */
808 kBackward_TextBufferDirection
809 };
810
reed@google.com44da42e2011-11-10 20:04:47 +0000811 /** Return the number of bytes of text that were measured. If
812 * isVerticalText() is true, then the vertical advances are used for
813 * the measurement.
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000814 *
reed@google.com44da42e2011-11-10 20:04:47 +0000815 * @param text The text to be measured
816 * @param length Number of bytes of text to measure
817 * @param maxWidth Maximum width. Only the subset of text whose accumulated
818 * widths are <= maxWidth are measured.
819 * @param measuredWidth Optional. If non-null, this returns the actual
820 * width of the measured text.
821 * @param tbd Optional. The direction the text buffer should be
822 * traversed during measuring.
823 * @return The number of bytes of text that were measured. Will be
824 * <= length.
825 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000826 size_t breakText(const void* text, size_t length, SkScalar maxWidth,
827 SkScalar* measuredWidth = NULL,
828 TextBufferDirection tbd = kForward_TextBufferDirection)
829 const;
830
reed@google.com44da42e2011-11-10 20:04:47 +0000831 /** Return the advances for the text. These will be vertical advances if
832 * isVerticalText() returns true.
833 *
834 * @param text the text
835 * @param byteLength number of bytes to of text
836 * @param widths If not null, returns the array of advances for
837 * the glyphs. If not NULL, must be at least a large
838 * as the number of unichars in the specified text.
839 * @param bounds If not null, returns the bounds for each of
840 * character, relative to (0, 0)
841 * @return the number of unichars in the specified text.
842 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000843 int getTextWidths(const void* text, size_t byteLength, SkScalar widths[],
844 SkRect bounds[] = NULL) const;
845
846 /** Return the path (outline) for the specified text.
847 Note: just like SkCanvas::drawText, this will respect the Align setting
848 in the paint.
849 */
850 void getTextPath(const void* text, size_t length, SkScalar x, SkScalar y,
851 SkPath* path) const;
852
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000853 void getPosTextPath(const void* text, size_t length,
reed@google.comca0062e2012-07-20 11:20:32 +0000854 const SkPoint pos[], SkPath* path) const;
855
djsollen@google.com56c69772011-11-08 19:00:26 +0000856#ifdef SK_BUILD_FOR_ANDROID
djsollen@google.com4bd2bdb2013-03-08 18:35:13 +0000857 const SkGlyph& getUnicharMetrics(SkUnichar, const SkMatrix*);
858 const SkGlyph& getGlyphMetrics(uint16_t, const SkMatrix*);
859 const void* findImage(const SkGlyph&, const SkMatrix*);
djsollen@google.comf5dbe2f2011-04-15 13:41:26 +0000860
861 uint32_t getGenerationID() const;
djsollen@google.com4bd2bdb2013-03-08 18:35:13 +0000862 void setGenerationID(uint32_t generationID);
djsollen@google.com60abb072012-02-15 18:49:15 +0000863
864 /** Returns the base glyph count for the strike associated with this paint
865 */
866 unsigned getBaseGlyphCount(SkUnichar text) const;
commit-bot@chromium.orgc7a20e42013-05-13 14:09:13 +0000867
868 const SkPaintOptionsAndroid& getPaintOptionsAndroid() const {
869 return fPaintOptionsAndroid;
870 }
871 void setPaintOptionsAndroid(const SkPaintOptionsAndroid& options);
djsollen@google.comf5dbe2f2011-04-15 13:41:26 +0000872#endif
873
reed@google.com632e1a22011-10-06 12:37:00 +0000874 // returns true if the paint's settings (e.g. xfermode + alpha) resolve to
875 // mean that we need not draw at all (e.g. SrcOver + 0-alpha)
876 bool nothingToDraw() const;
877
reed@google.coma584aed2012-05-16 14:06:02 +0000878 ///////////////////////////////////////////////////////////////////////////
reed@google.comd5f20792012-05-16 14:15:02 +0000879 // would prefer to make these private...
880
reed@google.coma584aed2012-05-16 14:06:02 +0000881 /** Returns true if the current paint settings allow for fast computation of
882 bounds (i.e. there is nothing complex like a patheffect that would make
883 the bounds computation expensive.
884 */
885 bool canComputeFastBounds() const {
886 if (this->getLooper()) {
887 return this->getLooper()->canComputeFastBounds(*this);
888 }
889 return !this->getRasterizer();
890 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000891
reed@google.coma584aed2012-05-16 14:06:02 +0000892 /** Only call this if canComputeFastBounds() returned true. This takes a
893 raw rectangle (the raw bounds of a shape), and adjusts it for stylistic
894 effects in the paint (e.g. stroking). If needed, it uses the storage
895 rect parameter. It returns the adjusted bounds that can then be used
896 for quickReject tests.
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000897
reed@google.coma584aed2012-05-16 14:06:02 +0000898 The returned rect will either be orig or storage, thus the caller
899 should not rely on storage being set to the result, but should always
900 use the retured value. It is legal for orig and storage to be the same
901 rect.
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000902
reed@google.coma584aed2012-05-16 14:06:02 +0000903 e.g.
904 if (paint.canComputeFastBounds()) {
905 SkRect r, storage;
906 path.computeBounds(&r, SkPath::kFast_BoundsType);
907 const SkRect& fastR = paint.computeFastBounds(r, &storage);
908 if (canvas->quickReject(fastR, ...)) {
909 // don't draw the path
910 }
911 }
912 */
913 const SkRect& computeFastBounds(const SkRect& orig, SkRect* storage) const {
914 SkPaint::Style style = this->getStyle();
915 // ultra fast-case: filling with no effects that affect geometry
916 if (kFill_Style == style) {
917 uintptr_t effects = reinterpret_cast<uintptr_t>(this->getLooper());
918 effects |= reinterpret_cast<uintptr_t>(this->getMaskFilter());
919 effects |= reinterpret_cast<uintptr_t>(this->getPathEffect());
920 if (!effects) {
921 return orig;
922 }
923 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000924
reed@google.coma584aed2012-05-16 14:06:02 +0000925 return this->doComputeFastBounds(orig, storage, style);
926 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000927
reed@google.coma584aed2012-05-16 14:06:02 +0000928 const SkRect& computeFastStrokeBounds(const SkRect& orig,
929 SkRect* storage) const {
reed@google.com73a02582012-05-16 19:21:12 +0000930 return this->doComputeFastBounds(orig, storage, kStroke_Style);
reed@google.coma584aed2012-05-16 14:06:02 +0000931 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000932
reed@google.coma584aed2012-05-16 14:06:02 +0000933 // Take the style explicitly, so the caller can force us to be stroked
934 // without having to make a copy of the paint just to change that field.
935 const SkRect& doComputeFastBounds(const SkRect& orig, SkRect* storage,
936 Style) const;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000937
reed@google.comed43dff2013-06-04 16:56:27 +0000938 /**
939 * Return a matrix that applies the paint's text values: size, scale, skew
940 */
941 static SkMatrix* SetTextMatrix(SkMatrix* matrix, SkScalar size,
942 SkScalar scaleX, SkScalar skewX) {
943 matrix->setScale(size * scaleX, size);
944 if (skewX) {
945 matrix->postSkew(skewX, 0);
946 }
947 return matrix;
948 }
949
950 SkMatrix* setTextMatrix(SkMatrix* matrix) const {
951 return SetTextMatrix(matrix, fTextSize, fTextScaleX, fTextSkewX);
952 }
953
robertphillips@google.com791f12e2013-02-14 13:53:53 +0000954 SkDEVCODE(void toString(SkString*) const;)
955
reed@google.comd5f20792012-05-16 14:15:02 +0000956private:
957 SkTypeface* fTypeface;
958 SkScalar fTextSize;
959 SkScalar fTextScaleX;
960 SkScalar fTextSkewX;
reed@google.com1f1543f2012-09-12 21:08:33 +0000961#ifdef SK_SUPPORT_HINTING_SCALE_FACTOR
962 SkScalar fHintingScaleFactor;
963#endif
reed@google.coma584aed2012-05-16 14:06:02 +0000964
reed@google.comd5f20792012-05-16 14:15:02 +0000965 SkPathEffect* fPathEffect;
966 SkShader* fShader;
967 SkXfermode* fXfermode;
968 SkMaskFilter* fMaskFilter;
969 SkColorFilter* fColorFilter;
970 SkRasterizer* fRasterizer;
971 SkDrawLooper* fLooper;
972 SkImageFilter* fImageFilter;
reed@google.comb0a34d82012-07-11 19:57:55 +0000973 SkAnnotation* fAnnotation;
reed@google.comd5f20792012-05-16 14:15:02 +0000974
975 SkColor fColor;
976 SkScalar fWidth;
977 SkScalar fMiterLimit;
reed@google.comb0a34d82012-07-11 19:57:55 +0000978 // all of these bitfields should add up to 32
979 unsigned fFlags : 16;
reed@google.comd5f20792012-05-16 14:15:02 +0000980 unsigned fTextAlign : 2;
981 unsigned fCapType : 2;
982 unsigned fJoinType : 2;
983 unsigned fStyle : 2;
984 unsigned fTextEncoding : 2; // 3 values
985 unsigned fHinting : 2;
reed@google.comb0a34d82012-07-11 19:57:55 +0000986 unsigned fPrivFlags : 4; // these are not flattened/unflattened
987
988 enum PrivFlags {
989 kNoDrawAnnotation_PrivFlag = 1 << 0,
990 };
reed@google.comd5f20792012-05-16 14:15:02 +0000991
992 SkDrawCacheProc getDrawCacheProc() const;
993 SkMeasureCacheProc getMeasureCacheProc(TextBufferDirection dir,
994 bool needFullMetrics) const;
995
996 SkScalar measure_text(SkGlyphCache*, const char* text, size_t length,
997 int* count, SkRect* bounds) const;
998
bungeman@google.com532470f2013-01-22 19:25:14 +0000999 SkGlyphCache* detachCache(const SkDeviceProperties* deviceProperties, const SkMatrix*) const;
reed@google.comd5f20792012-05-16 14:15:02 +00001000
bungeman@google.com532470f2013-01-22 19:25:14 +00001001 void descriptorProc(const SkDeviceProperties* deviceProperties, const SkMatrix* deviceMatrix,
reed@google.com90808e82013-03-19 14:44:54 +00001002 void (*proc)(SkTypeface*, const SkDescriptor*, void*),
reed@google.comd5f20792012-05-16 14:15:02 +00001003 void* context, bool ignoreGamma = false) const;
reed@android.comd252db02009-04-01 18:31:44 +00001004
bungeman@google.comb24b4fa2012-09-04 13:49:59 +00001005 static void Term();
1006
reed@android.com8a1c16f2008-12-17 15:59:43 +00001007 enum {
reed@google.comed43dff2013-06-04 16:56:27 +00001008 /* This is the size we use when we ask for a glyph's path. We then
1009 * post-transform it as we draw to match the request.
1010 * This is done to try to re-use cache entries for the path.
1011 *
1012 * This value is somewhat arbitrary. In theory, it could be 1, since
1013 * we store paths as floats. However, we get the path from the font
1014 * scaler, and it may represent its paths as fixed-point (or 26.6),
1015 * so we shouldn't ask for something too big (might overflow 16.16)
1016 * or too small (underflow 26.6).
1017 *
1018 * This value could track kMaxSizeForGlyphCache, assuming the above
1019 * constraints, but since we ask for unhinted paths, the two values
1020 * need not match per-se.
1021 */
1022 kCanonicalTextSizeForPaths = 64,
1023
1024 /*
1025 * Above this size (taking into account CTM and textSize), we never use
1026 * the cache for bits or metrics (we might overflow), so we just ask
1027 * for a caononical size and post-transform that.
1028 */
1029 kMaxSizeForGlyphCache = 256,
reed@android.com8a1c16f2008-12-17 15:59:43 +00001030 };
reed@google.comed43dff2013-06-04 16:56:27 +00001031
1032 static bool TooBigToUseCache(const SkMatrix& ctm, const SkMatrix& textM);
1033
1034 bool tooBigToUseCache() const;
1035 bool tooBigToUseCache(const SkMatrix& ctm) const;
1036
1037 // Set flags/hinting/textSize up to use for drawing text as paths.
1038 // Returns scale factor to restore the original textSize, since will will
1039 // have change it to kCanonicalTextSizeForPaths.
1040 SkScalar setupForAsPaths();
1041
1042 static SkScalar MaxCacheSize2() {
1043 static const SkScalar kMaxSize = SkIntToScalar(kMaxSizeForGlyphCache);
1044 static const SkScalar kMag2Max = kMaxSize * kMaxSize;
1045 return kMag2Max;
1046 }
1047
vandebo@chromium.org28be72b2010-11-11 21:37:00 +00001048 friend class SkAutoGlyphCache;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001049 friend class SkCanvas;
1050 friend class SkDraw;
bungeman@google.comb24b4fa2012-09-04 13:49:59 +00001051 friend class SkGraphics; // So Term() can be called.
vandebo@chromium.org28be72b2010-11-11 21:37:00 +00001052 friend class SkPDFDevice;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001053 friend class SkTextToPathIter;
reed@google.comed43dff2013-06-04 16:56:27 +00001054 friend class SkCanonicalizePaint;
djsollen@google.comb44cd652011-12-01 17:09:21 +00001055
1056#ifdef SK_BUILD_FOR_ANDROID
commit-bot@chromium.orgc7a20e42013-05-13 14:09:13 +00001057 SkPaintOptionsAndroid fPaintOptionsAndroid;
1058
djsollen@google.comb44cd652011-12-01 17:09:21 +00001059 // In order for the == operator to work properly this must be the last field
1060 // in the struct so that we can do a memcmp to this field's offset.
1061 uint32_t fGenerationID;
1062#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +00001063};
1064
reed@android.com8a1c16f2008-12-17 15:59:43 +00001065#endif