blob: caa2030e6fd3b1164b159c43ef201f21e6ea33fc [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,
mike@reedtribe.orgddc813b2013-06-08 12:58:19 +0000631 };
632 enum {
633 kAlignCount = 3
reed@android.com8a1c16f2008-12-17 15:59:43 +0000634 };
reed@google.com9d07fec2011-03-16 20:02:59 +0000635
reed@android.com8a1c16f2008-12-17 15:59:43 +0000636 /** Return the paint's Align value for drawing text.
637 @return the paint's Align value for drawing text.
638 */
639 Align getTextAlign() const { return (Align)fTextAlign; }
reed@google.com9d07fec2011-03-16 20:02:59 +0000640
reed@android.com8a1c16f2008-12-17 15:59:43 +0000641 /** Set the paint's text alignment.
642 @param align set the paint's Align value for drawing text.
643 */
644 void setTextAlign(Align align);
645
646 /** Return the paint's text size.
647 @return the paint's text size.
648 */
649 SkScalar getTextSize() const { return fTextSize; }
650
651 /** Set the paint's text size. This value must be > 0
652 @param textSize set the paint's text size.
653 */
654 void setTextSize(SkScalar textSize);
655
656 /** Return the paint's horizontal scale factor for text. The default value
657 is 1.0.
658 @return the paint's scale factor in X for drawing/measuring text
659 */
660 SkScalar getTextScaleX() const { return fTextScaleX; }
661
662 /** Set the paint's horizontal scale factor for text. The default value
663 is 1.0. Values > 1.0 will stretch the text wider. Values < 1.0 will
664 stretch the text narrower.
665 @param scaleX set the paint's scale factor in X for drawing/measuring
666 text.
667 */
668 void setTextScaleX(SkScalar scaleX);
669
670 /** Return the paint's horizontal skew factor for text. The default value
671 is 0.
672 @return the paint's skew factor in X for drawing text.
673 */
674 SkScalar getTextSkewX() const { return fTextSkewX; }
675
676 /** Set the paint's horizontal skew factor for text. The default value
677 is 0. For approximating oblique text, use values around -0.25.
678 @param skewX set the paint's skew factor in X for drawing text.
679 */
680 void setTextSkewX(SkScalar skewX);
681
reed@google.com1f1543f2012-09-12 21:08:33 +0000682#ifdef SK_SUPPORT_HINTING_SCALE_FACTOR
683 /** Return the paint's scale factor used for correctly rendering
684 glyphs in high DPI mode without text subpixel positioning.
685 @return the scale factor used for rendering glyphs in high DPI mode.
686 */
687 SkScalar getHintingScaleFactor() const { return fHintingScaleFactor; }
688
689 /** Set the paint's scale factor used for correctly rendering
690 glyphs in high DPI mode without text subpixel positioning.
691 @param the scale factor used for rendering glyphs in high DPI mode.
692 */
693 void setHintingScaleFactor(SkScalar hintingScaleFactor);
694#endif
695
reed@android.com8a1c16f2008-12-17 15:59:43 +0000696 /** Describes how to interpret the text parameters that are passed to paint
697 methods like measureText() and getTextWidths().
698 */
699 enum TextEncoding {
700 kUTF8_TextEncoding, //!< the text parameters are UTF8
701 kUTF16_TextEncoding, //!< the text parameters are UTF16
robertphillips@google.com69705572012-03-21 19:46:50 +0000702 kUTF32_TextEncoding, //!< the text parameters are UTF32
reed@android.com8a1c16f2008-12-17 15:59:43 +0000703 kGlyphID_TextEncoding //!< the text parameters are glyph indices
704 };
reed@google.com9d07fec2011-03-16 20:02:59 +0000705
706 TextEncoding getTextEncoding() const { return (TextEncoding)fTextEncoding; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000707
708 void setTextEncoding(TextEncoding encoding);
709
710 struct FontMetrics {
711 SkScalar fTop; //!< The greatest distance above the baseline for any glyph (will be <= 0)
712 SkScalar fAscent; //!< The recommended distance above the baseline (will be <= 0)
713 SkScalar fDescent; //!< The recommended distance below the baseline (will be >= 0)
714 SkScalar fBottom; //!< The greatest distance below the baseline for any glyph (will be >= 0)
715 SkScalar fLeading; //!< The recommended distance to add between lines of text (will be >= 0)
agl@chromium.orgcc3096b2009-04-22 22:09:04 +0000716 SkScalar fAvgCharWidth; //!< the average charactor width (>= 0)
717 SkScalar fXMin; //!< The minimum bounding box x value for all glyphs
718 SkScalar fXMax; //!< The maximum bounding box x value for all glyphs
719 SkScalar fXHeight; //!< the height of an 'x' in px, or 0 if no 'x' in face
reed@android.com8a1c16f2008-12-17 15:59:43 +0000720 };
reed@google.com9d07fec2011-03-16 20:02:59 +0000721
reed@android.com8a1c16f2008-12-17 15:59:43 +0000722 /** Return the recommend spacing between lines (which will be
723 fDescent - fAscent + fLeading).
724 If metrics is not null, return in it the font metrics for the
reed@google.com9d07fec2011-03-16 20:02:59 +0000725 typeface/pointsize/etc. currently set in the paint.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000726 @param metrics If not null, returns the font metrics for the
727 current typeface/pointsize/etc setting in this
728 paint.
729 @param scale If not 0, return width as if the canvas were scaled
730 by this value
731 @param return the recommended spacing between lines
732 */
733 SkScalar getFontMetrics(FontMetrics* metrics, SkScalar scale = 0) const;
reed@google.com9d07fec2011-03-16 20:02:59 +0000734
reed@android.com8a1c16f2008-12-17 15:59:43 +0000735 /** Return the recommend line spacing. This will be
736 fDescent - fAscent + fLeading
737 */
738 SkScalar getFontSpacing() const { return this->getFontMetrics(NULL, 0); }
739
740 /** Convert the specified text into glyph IDs, returning the number of
741 glyphs ID written. If glyphs is NULL, it is ignore and only the count
742 is returned.
743 */
744 int textToGlyphs(const void* text, size_t byteLength,
745 uint16_t glyphs[]) const;
746
reed@android.coma5dcaf62010-02-05 17:12:32 +0000747 /** Return true if all of the specified text has a corresponding non-zero
748 glyph ID. If any of the code-points in the text are not supported in
749 the typeface (i.e. the glyph ID would be zero), then return false.
750
751 If the text encoding for the paint is kGlyph_TextEncoding, then this
752 returns true if all of the specified glyph IDs are non-zero.
753 */
754 bool containsText(const void* text, size_t byteLength) const;
755
reed@android.com9d3a9852010-01-08 14:07:42 +0000756 /** Convert the glyph array into Unichars. Unconvertable glyphs are mapped
757 to zero. Note: this does not look at the text-encoding setting in the
758 paint, only at the typeface.
759 */
760 void glyphsToUnichars(const uint16_t glyphs[], int count,
761 SkUnichar text[]) const;
762
reed@android.com8a1c16f2008-12-17 15:59:43 +0000763 /** Return the number of drawable units in the specified text buffer.
764 This looks at the current TextEncoding field of the paint. If you also
765 want to have the text converted into glyph IDs, call textToGlyphs
766 instead.
767 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000768 int countText(const void* text, size_t byteLength) const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000769 return this->textToGlyphs(text, byteLength, NULL);
770 }
771
reed@google.com44da42e2011-11-10 20:04:47 +0000772 /** Return the width of the text. This will return the vertical measure
773 * if isVerticalText() is true, in which case the returned value should
774 * be treated has a height instead of a width.
775 *
776 * @param text The text to be measured
777 * @param length Number of bytes of text to measure
778 * @param bounds If not NULL, returns the bounds of the text,
779 * relative to (0, 0).
780 * @param scale If not 0, return width as if the canvas were scaled
781 * by this value
782 * @return The advance width of the text
783 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000784 SkScalar measureText(const void* text, size_t length,
785 SkRect* bounds, SkScalar scale = 0) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000786
reed@google.com44da42e2011-11-10 20:04:47 +0000787 /** Return the width of the text. This will return the vertical measure
788 * if isVerticalText() is true, in which case the returned value should
789 * be treated has a height instead of a width.
790 *
791 * @param text Address of the text
792 * @param length Number of bytes of text to measure
reed@google.com97ecd1d2012-05-15 19:25:17 +0000793 * @return The advance width of the text
reed@google.com44da42e2011-11-10 20:04:47 +0000794 */
reed@google.com9d07fec2011-03-16 20:02:59 +0000795 SkScalar measureText(const void* text, size_t length) const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000796 return this->measureText(text, length, NULL, 0);
797 }
reed@google.com9d07fec2011-03-16 20:02:59 +0000798
reed@android.com8a1c16f2008-12-17 15:59:43 +0000799 /** Specify the direction the text buffer should be processed in breakText()
800 */
801 enum TextBufferDirection {
802 /** When measuring text for breakText(), begin at the start of the text
803 buffer and proceed forward through the data. This is the default.
804 */
805 kForward_TextBufferDirection,
806 /** When measuring text for breakText(), begin at the end of the text
807 buffer and proceed backwards through the data.
808 */
809 kBackward_TextBufferDirection
810 };
811
reed@google.com44da42e2011-11-10 20:04:47 +0000812 /** Return the number of bytes of text that were measured. If
813 * isVerticalText() is true, then the vertical advances are used for
814 * the measurement.
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000815 *
reed@google.com44da42e2011-11-10 20:04:47 +0000816 * @param text The text to be measured
817 * @param length Number of bytes of text to measure
818 * @param maxWidth Maximum width. Only the subset of text whose accumulated
819 * widths are <= maxWidth are measured.
820 * @param measuredWidth Optional. If non-null, this returns the actual
821 * width of the measured text.
822 * @param tbd Optional. The direction the text buffer should be
823 * traversed during measuring.
824 * @return The number of bytes of text that were measured. Will be
825 * <= length.
826 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000827 size_t breakText(const void* text, size_t length, SkScalar maxWidth,
828 SkScalar* measuredWidth = NULL,
829 TextBufferDirection tbd = kForward_TextBufferDirection)
830 const;
831
reed@google.com44da42e2011-11-10 20:04:47 +0000832 /** Return the advances for the text. These will be vertical advances if
833 * isVerticalText() returns true.
834 *
835 * @param text the text
836 * @param byteLength number of bytes to of text
837 * @param widths If not null, returns the array of advances for
838 * the glyphs. If not NULL, must be at least a large
839 * as the number of unichars in the specified text.
840 * @param bounds If not null, returns the bounds for each of
841 * character, relative to (0, 0)
842 * @return the number of unichars in the specified text.
843 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000844 int getTextWidths(const void* text, size_t byteLength, SkScalar widths[],
845 SkRect bounds[] = NULL) const;
846
847 /** Return the path (outline) for the specified text.
848 Note: just like SkCanvas::drawText, this will respect the Align setting
849 in the paint.
850 */
851 void getTextPath(const void* text, size_t length, SkScalar x, SkScalar y,
852 SkPath* path) const;
853
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000854 void getPosTextPath(const void* text, size_t length,
reed@google.comca0062e2012-07-20 11:20:32 +0000855 const SkPoint pos[], SkPath* path) const;
856
djsollen@google.com56c69772011-11-08 19:00:26 +0000857#ifdef SK_BUILD_FOR_ANDROID
djsollen@google.com4bd2bdb2013-03-08 18:35:13 +0000858 const SkGlyph& getUnicharMetrics(SkUnichar, const SkMatrix*);
859 const SkGlyph& getGlyphMetrics(uint16_t, const SkMatrix*);
860 const void* findImage(const SkGlyph&, const SkMatrix*);
djsollen@google.comf5dbe2f2011-04-15 13:41:26 +0000861
862 uint32_t getGenerationID() const;
djsollen@google.com4bd2bdb2013-03-08 18:35:13 +0000863 void setGenerationID(uint32_t generationID);
djsollen@google.com60abb072012-02-15 18:49:15 +0000864
865 /** Returns the base glyph count for the strike associated with this paint
866 */
867 unsigned getBaseGlyphCount(SkUnichar text) const;
commit-bot@chromium.orgc7a20e42013-05-13 14:09:13 +0000868
869 const SkPaintOptionsAndroid& getPaintOptionsAndroid() const {
870 return fPaintOptionsAndroid;
871 }
872 void setPaintOptionsAndroid(const SkPaintOptionsAndroid& options);
djsollen@google.comf5dbe2f2011-04-15 13:41:26 +0000873#endif
874
reed@google.com632e1a22011-10-06 12:37:00 +0000875 // returns true if the paint's settings (e.g. xfermode + alpha) resolve to
876 // mean that we need not draw at all (e.g. SrcOver + 0-alpha)
877 bool nothingToDraw() const;
878
reed@google.coma584aed2012-05-16 14:06:02 +0000879 ///////////////////////////////////////////////////////////////////////////
reed@google.comd5f20792012-05-16 14:15:02 +0000880 // would prefer to make these private...
881
reed@google.coma584aed2012-05-16 14:06:02 +0000882 /** Returns true if the current paint settings allow for fast computation of
883 bounds (i.e. there is nothing complex like a patheffect that would make
884 the bounds computation expensive.
885 */
886 bool canComputeFastBounds() const {
887 if (this->getLooper()) {
888 return this->getLooper()->canComputeFastBounds(*this);
889 }
890 return !this->getRasterizer();
891 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000892
reed@google.coma584aed2012-05-16 14:06:02 +0000893 /** Only call this if canComputeFastBounds() returned true. This takes a
894 raw rectangle (the raw bounds of a shape), and adjusts it for stylistic
895 effects in the paint (e.g. stroking). If needed, it uses the storage
896 rect parameter. It returns the adjusted bounds that can then be used
897 for quickReject tests.
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000898
reed@google.coma584aed2012-05-16 14:06:02 +0000899 The returned rect will either be orig or storage, thus the caller
900 should not rely on storage being set to the result, but should always
901 use the retured value. It is legal for orig and storage to be the same
902 rect.
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000903
reed@google.coma584aed2012-05-16 14:06:02 +0000904 e.g.
905 if (paint.canComputeFastBounds()) {
906 SkRect r, storage;
907 path.computeBounds(&r, SkPath::kFast_BoundsType);
908 const SkRect& fastR = paint.computeFastBounds(r, &storage);
909 if (canvas->quickReject(fastR, ...)) {
910 // don't draw the path
911 }
912 }
913 */
914 const SkRect& computeFastBounds(const SkRect& orig, SkRect* storage) const {
915 SkPaint::Style style = this->getStyle();
916 // ultra fast-case: filling with no effects that affect geometry
917 if (kFill_Style == style) {
918 uintptr_t effects = reinterpret_cast<uintptr_t>(this->getLooper());
919 effects |= reinterpret_cast<uintptr_t>(this->getMaskFilter());
920 effects |= reinterpret_cast<uintptr_t>(this->getPathEffect());
921 if (!effects) {
922 return orig;
923 }
924 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000925
reed@google.coma584aed2012-05-16 14:06:02 +0000926 return this->doComputeFastBounds(orig, storage, style);
927 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000928
reed@google.coma584aed2012-05-16 14:06:02 +0000929 const SkRect& computeFastStrokeBounds(const SkRect& orig,
930 SkRect* storage) const {
reed@google.com73a02582012-05-16 19:21:12 +0000931 return this->doComputeFastBounds(orig, storage, kStroke_Style);
reed@google.coma584aed2012-05-16 14:06:02 +0000932 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000933
reed@google.coma584aed2012-05-16 14:06:02 +0000934 // Take the style explicitly, so the caller can force us to be stroked
935 // without having to make a copy of the paint just to change that field.
936 const SkRect& doComputeFastBounds(const SkRect& orig, SkRect* storage,
937 Style) const;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000938
reed@google.comed43dff2013-06-04 16:56:27 +0000939 /**
940 * Return a matrix that applies the paint's text values: size, scale, skew
941 */
942 static SkMatrix* SetTextMatrix(SkMatrix* matrix, SkScalar size,
943 SkScalar scaleX, SkScalar skewX) {
944 matrix->setScale(size * scaleX, size);
945 if (skewX) {
946 matrix->postSkew(skewX, 0);
947 }
948 return matrix;
949 }
skia.committer@gmail.com8f6ef402013-06-05 07:01:06 +0000950
reed@google.comed43dff2013-06-04 16:56:27 +0000951 SkMatrix* setTextMatrix(SkMatrix* matrix) const {
952 return SetTextMatrix(matrix, fTextSize, fTextScaleX, fTextSkewX);
953 }
skia.committer@gmail.com8f6ef402013-06-05 07:01:06 +0000954
robertphillips@google.com791f12e2013-02-14 13:53:53 +0000955 SkDEVCODE(void toString(SkString*) const;)
956
reed@google.comd5f20792012-05-16 14:15:02 +0000957private:
958 SkTypeface* fTypeface;
959 SkScalar fTextSize;
960 SkScalar fTextScaleX;
961 SkScalar fTextSkewX;
reed@google.com1f1543f2012-09-12 21:08:33 +0000962#ifdef SK_SUPPORT_HINTING_SCALE_FACTOR
963 SkScalar fHintingScaleFactor;
964#endif
reed@google.coma584aed2012-05-16 14:06:02 +0000965
reed@google.comd5f20792012-05-16 14:15:02 +0000966 SkPathEffect* fPathEffect;
967 SkShader* fShader;
968 SkXfermode* fXfermode;
969 SkMaskFilter* fMaskFilter;
970 SkColorFilter* fColorFilter;
971 SkRasterizer* fRasterizer;
972 SkDrawLooper* fLooper;
973 SkImageFilter* fImageFilter;
reed@google.comb0a34d82012-07-11 19:57:55 +0000974 SkAnnotation* fAnnotation;
reed@google.comd5f20792012-05-16 14:15:02 +0000975
976 SkColor fColor;
977 SkScalar fWidth;
978 SkScalar fMiterLimit;
reed@google.comb0a34d82012-07-11 19:57:55 +0000979 // all of these bitfields should add up to 32
980 unsigned fFlags : 16;
reed@google.comd5f20792012-05-16 14:15:02 +0000981 unsigned fTextAlign : 2;
982 unsigned fCapType : 2;
983 unsigned fJoinType : 2;
984 unsigned fStyle : 2;
985 unsigned fTextEncoding : 2; // 3 values
986 unsigned fHinting : 2;
reed@google.comb0a34d82012-07-11 19:57:55 +0000987 unsigned fPrivFlags : 4; // these are not flattened/unflattened
988
989 enum PrivFlags {
990 kNoDrawAnnotation_PrivFlag = 1 << 0,
991 };
reed@google.comd5f20792012-05-16 14:15:02 +0000992
993 SkDrawCacheProc getDrawCacheProc() const;
994 SkMeasureCacheProc getMeasureCacheProc(TextBufferDirection dir,
995 bool needFullMetrics) const;
996
997 SkScalar measure_text(SkGlyphCache*, const char* text, size_t length,
998 int* count, SkRect* bounds) const;
999
bungeman@google.com532470f2013-01-22 19:25:14 +00001000 SkGlyphCache* detachCache(const SkDeviceProperties* deviceProperties, const SkMatrix*) const;
reed@google.comd5f20792012-05-16 14:15:02 +00001001
bungeman@google.com532470f2013-01-22 19:25:14 +00001002 void descriptorProc(const SkDeviceProperties* deviceProperties, const SkMatrix* deviceMatrix,
reed@google.com90808e82013-03-19 14:44:54 +00001003 void (*proc)(SkTypeface*, const SkDescriptor*, void*),
reed@google.comd5f20792012-05-16 14:15:02 +00001004 void* context, bool ignoreGamma = false) const;
reed@android.comd252db02009-04-01 18:31:44 +00001005
bungeman@google.comb24b4fa2012-09-04 13:49:59 +00001006 static void Term();
1007
reed@android.com8a1c16f2008-12-17 15:59:43 +00001008 enum {
reed@google.comed43dff2013-06-04 16:56:27 +00001009 /* This is the size we use when we ask for a glyph's path. We then
1010 * post-transform it as we draw to match the request.
1011 * This is done to try to re-use cache entries for the path.
1012 *
1013 * This value is somewhat arbitrary. In theory, it could be 1, since
1014 * we store paths as floats. However, we get the path from the font
1015 * scaler, and it may represent its paths as fixed-point (or 26.6),
1016 * so we shouldn't ask for something too big (might overflow 16.16)
1017 * or too small (underflow 26.6).
1018 *
1019 * This value could track kMaxSizeForGlyphCache, assuming the above
1020 * constraints, but since we ask for unhinted paths, the two values
1021 * need not match per-se.
1022 */
1023 kCanonicalTextSizeForPaths = 64,
1024
1025 /*
1026 * Above this size (taking into account CTM and textSize), we never use
1027 * the cache for bits or metrics (we might overflow), so we just ask
1028 * for a caononical size and post-transform that.
1029 */
1030 kMaxSizeForGlyphCache = 256,
reed@android.com8a1c16f2008-12-17 15:59:43 +00001031 };
reed@google.comed43dff2013-06-04 16:56:27 +00001032
1033 static bool TooBigToUseCache(const SkMatrix& ctm, const SkMatrix& textM);
1034
1035 bool tooBigToUseCache() const;
1036 bool tooBigToUseCache(const SkMatrix& ctm) const;
skia.committer@gmail.com8f6ef402013-06-05 07:01:06 +00001037
reed@google.comed43dff2013-06-04 16:56:27 +00001038 // Set flags/hinting/textSize up to use for drawing text as paths.
1039 // Returns scale factor to restore the original textSize, since will will
1040 // have change it to kCanonicalTextSizeForPaths.
1041 SkScalar setupForAsPaths();
1042
1043 static SkScalar MaxCacheSize2() {
1044 static const SkScalar kMaxSize = SkIntToScalar(kMaxSizeForGlyphCache);
1045 static const SkScalar kMag2Max = kMaxSize * kMaxSize;
1046 return kMag2Max;
1047 }
1048
vandebo@chromium.org28be72b2010-11-11 21:37:00 +00001049 friend class SkAutoGlyphCache;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001050 friend class SkCanvas;
1051 friend class SkDraw;
bungeman@google.comb24b4fa2012-09-04 13:49:59 +00001052 friend class SkGraphics; // So Term() can be called.
vandebo@chromium.org28be72b2010-11-11 21:37:00 +00001053 friend class SkPDFDevice;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001054 friend class SkTextToPathIter;
reed@google.comed43dff2013-06-04 16:56:27 +00001055 friend class SkCanonicalizePaint;
djsollen@google.comb44cd652011-12-01 17:09:21 +00001056
1057#ifdef SK_BUILD_FOR_ANDROID
commit-bot@chromium.orgc7a20e42013-05-13 14:09:13 +00001058 SkPaintOptionsAndroid fPaintOptionsAndroid;
1059
djsollen@google.comb44cd652011-12-01 17:09:21 +00001060 // In order for the == operator to work properly this must be the last field
1061 // in the struct so that we can do a memcmp to this field's offset.
1062 uint32_t fGenerationID;
1063#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +00001064};
1065
reed@android.com8a1c16f2008-12-17 15:59:43 +00001066#endif