1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/include/core/SkPaint.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,1156 @@ 1.4 + 1.5 + 1.6 +/* 1.7 + * Copyright 2006 The Android Open Source Project 1.8 + * 1.9 + * Use of this source code is governed by a BSD-style license that can be 1.10 + * found in the LICENSE file. 1.11 + */ 1.12 + 1.13 + 1.14 +#ifndef SkPaint_DEFINED 1.15 +#define SkPaint_DEFINED 1.16 + 1.17 +#include "SkColor.h" 1.18 +#include "SkDrawLooper.h" 1.19 +#include "SkMatrix.h" 1.20 +#include "SkXfermode.h" 1.21 +#ifdef SK_BUILD_FOR_ANDROID 1.22 +#include "SkPaintOptionsAndroid.h" 1.23 +#endif 1.24 + 1.25 +class SkAnnotation; 1.26 +class SkAutoGlyphCache; 1.27 +class SkColorFilter; 1.28 +class SkDescriptor; 1.29 +struct SkDeviceProperties; 1.30 +class SkReadBuffer; 1.31 +class SkWriteBuffer; 1.32 +struct SkGlyph; 1.33 +struct SkRect; 1.34 +class SkGlyphCache; 1.35 +class SkImageFilter; 1.36 +class SkMaskFilter; 1.37 +class SkPath; 1.38 +class SkPathEffect; 1.39 +struct SkPoint; 1.40 +class SkRasterizer; 1.41 +class SkShader; 1.42 +class SkTypeface; 1.43 + 1.44 +typedef const SkGlyph& (*SkDrawCacheProc)(SkGlyphCache*, const char**, 1.45 + SkFixed x, SkFixed y); 1.46 + 1.47 +typedef const SkGlyph& (*SkMeasureCacheProc)(SkGlyphCache*, const char**); 1.48 + 1.49 +#define kBicubicFilterBitmap_Flag kHighQualityFilterBitmap_Flag 1.50 + 1.51 +/** \class SkPaint 1.52 + 1.53 + The SkPaint class holds the style and color information about how to draw 1.54 + geometries, text and bitmaps. 1.55 +*/ 1.56 + 1.57 +class SK_API SkPaint { 1.58 + enum { 1.59 + // DEPRECATED -- use setFilterLevel instead 1.60 + kFilterBitmap_Flag = 0x02, // temporary flag 1.61 + // DEPRECATED -- use setFilterLevel instead 1.62 + kHighQualityFilterBitmap_Flag = 0x4000, // temporary flag 1.63 + // DEPRECATED -- use setFilterLevel instead 1.64 + kHighQualityDownsampleBitmap_Flag = 0x8000, // temporary flag 1.65 + }; 1.66 +public: 1.67 + SkPaint(); 1.68 + SkPaint(const SkPaint& paint); 1.69 + ~SkPaint(); 1.70 + 1.71 + SkPaint& operator=(const SkPaint&); 1.72 + 1.73 + SK_API friend bool operator==(const SkPaint& a, const SkPaint& b); 1.74 + friend bool operator!=(const SkPaint& a, const SkPaint& b) { 1.75 + return !(a == b); 1.76 + } 1.77 + 1.78 + void flatten(SkWriteBuffer&) const; 1.79 + void unflatten(SkReadBuffer&); 1.80 + 1.81 + /** Restores the paint to its initial settings. 1.82 + */ 1.83 + void reset(); 1.84 + 1.85 + /** Specifies the level of hinting to be performed. These names are taken 1.86 + from the Gnome/Cairo names for the same. They are translated into 1.87 + Freetype concepts the same as in cairo-ft-font.c: 1.88 + kNo_Hinting -> FT_LOAD_NO_HINTING 1.89 + kSlight_Hinting -> FT_LOAD_TARGET_LIGHT 1.90 + kNormal_Hinting -> <default, no option> 1.91 + kFull_Hinting -> <same as kNormalHinting, unless we are rendering 1.92 + subpixel glyphs, in which case TARGET_LCD or 1.93 + TARGET_LCD_V is used> 1.94 + */ 1.95 + enum Hinting { 1.96 + kNo_Hinting = 0, 1.97 + kSlight_Hinting = 1, 1.98 + kNormal_Hinting = 2, //!< this is the default 1.99 + kFull_Hinting = 3 1.100 + }; 1.101 + 1.102 + Hinting getHinting() const { 1.103 + return static_cast<Hinting>(fHinting); 1.104 + } 1.105 + 1.106 + void setHinting(Hinting hintingLevel); 1.107 + 1.108 + /** Specifies the bit values that are stored in the paint's flags. 1.109 + */ 1.110 + enum Flags { 1.111 + kAntiAlias_Flag = 0x01, //!< mask to enable antialiasing 1.112 + kDither_Flag = 0x04, //!< mask to enable dithering 1.113 + kUnderlineText_Flag = 0x08, //!< mask to enable underline text 1.114 + kStrikeThruText_Flag = 0x10, //!< mask to enable strike-thru text 1.115 + kFakeBoldText_Flag = 0x20, //!< mask to enable fake-bold text 1.116 + kLinearText_Flag = 0x40, //!< mask to enable linear-text 1.117 + kSubpixelText_Flag = 0x80, //!< mask to enable subpixel text positioning 1.118 + kDevKernText_Flag = 0x100, //!< mask to enable device kerning text 1.119 + kLCDRenderText_Flag = 0x200, //!< mask to enable subpixel glyph renderering 1.120 + kEmbeddedBitmapText_Flag = 0x400, //!< mask to enable embedded bitmap strikes 1.121 + kAutoHinting_Flag = 0x800, //!< mask to force Freetype's autohinter 1.122 + kVerticalText_Flag = 0x1000, 1.123 + kGenA8FromLCD_Flag = 0x2000, // hack for GDI -- do not use if you can help it 1.124 + kDistanceFieldTextTEMP_Flag = 0x4000, //!< TEMPORARY mask to enable distance fields 1.125 + // currently overrides LCD and subpixel rendering 1.126 + // when adding extra flags, note that the fFlags member is specified 1.127 + // with a bit-width and you'll have to expand it. 1.128 + 1.129 + kAllFlags = 0xFFFF 1.130 + }; 1.131 + 1.132 + /** Return the paint's flags. Use the Flag enum to test flag values. 1.133 + @return the paint's flags (see enums ending in _Flag for bit masks) 1.134 + */ 1.135 + uint32_t getFlags() const { return fFlags; } 1.136 + 1.137 + /** Set the paint's flags. Use the Flag enum to specific flag values. 1.138 + @param flags The new flag bits for the paint (see Flags enum) 1.139 + */ 1.140 + void setFlags(uint32_t flags); 1.141 + 1.142 + /** Helper for getFlags(), returning true if kAntiAlias_Flag bit is set 1.143 + @return true if the antialias bit is set in the paint's flags. 1.144 + */ 1.145 + bool isAntiAlias() const { 1.146 + return SkToBool(this->getFlags() & kAntiAlias_Flag); 1.147 + } 1.148 + 1.149 + /** Helper for setFlags(), setting or clearing the kAntiAlias_Flag bit 1.150 + @param aa true to enable antialiasing, false to disable it 1.151 + */ 1.152 + void setAntiAlias(bool aa); 1.153 + 1.154 + /** Helper for getFlags(), returning true if kDither_Flag bit is set 1.155 + @return true if the dithering bit is set in the paint's flags. 1.156 + */ 1.157 + bool isDither() const { 1.158 + return SkToBool(this->getFlags() & kDither_Flag); 1.159 + } 1.160 + 1.161 + /** Helper for setFlags(), setting or clearing the kDither_Flag bit 1.162 + @param dither true to enable dithering, false to disable it 1.163 + */ 1.164 + void setDither(bool dither); 1.165 + 1.166 + /** Helper for getFlags(), returning true if kLinearText_Flag bit is set 1.167 + @return true if the lineartext bit is set in the paint's flags 1.168 + */ 1.169 + bool isLinearText() const { 1.170 + return SkToBool(this->getFlags() & kLinearText_Flag); 1.171 + } 1.172 + 1.173 + /** Helper for setFlags(), setting or clearing the kLinearText_Flag bit 1.174 + @param linearText true to set the linearText bit in the paint's flags, 1.175 + false to clear it. 1.176 + */ 1.177 + void setLinearText(bool linearText); 1.178 + 1.179 + /** Helper for getFlags(), returning true if kSubpixelText_Flag bit is set 1.180 + @return true if the lineartext bit is set in the paint's flags 1.181 + */ 1.182 + bool isSubpixelText() const { 1.183 + return SkToBool(this->getFlags() & kSubpixelText_Flag); 1.184 + } 1.185 + 1.186 + /** 1.187 + * Helper for setFlags(), setting or clearing the kSubpixelText_Flag. 1.188 + * @param subpixelText true to set the subpixelText bit in the paint's 1.189 + * flags, false to clear it. 1.190 + */ 1.191 + void setSubpixelText(bool subpixelText); 1.192 + 1.193 + bool isLCDRenderText() const { 1.194 + return SkToBool(this->getFlags() & kLCDRenderText_Flag); 1.195 + } 1.196 + 1.197 + /** 1.198 + * Helper for setFlags(), setting or clearing the kLCDRenderText_Flag. 1.199 + * Note: antialiasing must also be on for lcd rendering 1.200 + * @param lcdText true to set the LCDRenderText bit in the paint's flags, 1.201 + * false to clear it. 1.202 + */ 1.203 + void setLCDRenderText(bool lcdText); 1.204 + 1.205 + bool isEmbeddedBitmapText() const { 1.206 + return SkToBool(this->getFlags() & kEmbeddedBitmapText_Flag); 1.207 + } 1.208 + 1.209 + /** Helper for setFlags(), setting or clearing the kEmbeddedBitmapText_Flag bit 1.210 + @param useEmbeddedBitmapText true to set the kEmbeddedBitmapText bit in the paint's flags, 1.211 + false to clear it. 1.212 + */ 1.213 + void setEmbeddedBitmapText(bool useEmbeddedBitmapText); 1.214 + 1.215 + bool isAutohinted() const { 1.216 + return SkToBool(this->getFlags() & kAutoHinting_Flag); 1.217 + } 1.218 + 1.219 + /** Helper for setFlags(), setting or clearing the kAutoHinting_Flag bit 1.220 + @param useAutohinter true to set the kEmbeddedBitmapText bit in the 1.221 + paint's flags, 1.222 + false to clear it. 1.223 + */ 1.224 + void setAutohinted(bool useAutohinter); 1.225 + 1.226 + bool isVerticalText() const { 1.227 + return SkToBool(this->getFlags() & kVerticalText_Flag); 1.228 + } 1.229 + 1.230 + /** 1.231 + * Helper for setting or clearing the kVerticalText_Flag bit in 1.232 + * setFlags(...). 1.233 + * 1.234 + * If this bit is set, then advances are treated as Y values rather than 1.235 + * X values, and drawText will places its glyphs vertically rather than 1.236 + * horizontally. 1.237 + */ 1.238 + void setVerticalText(bool); 1.239 + 1.240 + /** Helper for getFlags(), returning true if kUnderlineText_Flag bit is set 1.241 + @return true if the underlineText bit is set in the paint's flags. 1.242 + */ 1.243 + bool isUnderlineText() const { 1.244 + return SkToBool(this->getFlags() & kUnderlineText_Flag); 1.245 + } 1.246 + 1.247 + /** Helper for setFlags(), setting or clearing the kUnderlineText_Flag bit 1.248 + @param underlineText true to set the underlineText bit in the paint's 1.249 + flags, false to clear it. 1.250 + */ 1.251 + void setUnderlineText(bool underlineText); 1.252 + 1.253 + /** Helper for getFlags(), returns true if kStrikeThruText_Flag bit is set 1.254 + @return true if the strikeThruText bit is set in the paint's flags. 1.255 + */ 1.256 + bool isStrikeThruText() const { 1.257 + return SkToBool(this->getFlags() & kStrikeThruText_Flag); 1.258 + } 1.259 + 1.260 + /** Helper for setFlags(), setting or clearing the kStrikeThruText_Flag bit 1.261 + @param strikeThruText true to set the strikeThruText bit in the 1.262 + paint's flags, false to clear it. 1.263 + */ 1.264 + void setStrikeThruText(bool strikeThruText); 1.265 + 1.266 + /** Helper for getFlags(), returns true if kFakeBoldText_Flag bit is set 1.267 + @return true if the kFakeBoldText_Flag bit is set in the paint's flags. 1.268 + */ 1.269 + bool isFakeBoldText() const { 1.270 + return SkToBool(this->getFlags() & kFakeBoldText_Flag); 1.271 + } 1.272 + 1.273 + /** Helper for setFlags(), setting or clearing the kFakeBoldText_Flag bit 1.274 + @param fakeBoldText true to set the kFakeBoldText_Flag bit in the paint's 1.275 + flags, false to clear it. 1.276 + */ 1.277 + void setFakeBoldText(bool fakeBoldText); 1.278 + 1.279 + /** Helper for getFlags(), returns true if kDevKernText_Flag bit is set 1.280 + @return true if the kernText bit is set in the paint's flags. 1.281 + */ 1.282 + bool isDevKernText() const { 1.283 + return SkToBool(this->getFlags() & kDevKernText_Flag); 1.284 + } 1.285 + 1.286 + /** Helper for setFlags(), setting or clearing the kKernText_Flag bit 1.287 + @param kernText true to set the kKernText_Flag bit in the paint's 1.288 + flags, false to clear it. 1.289 + */ 1.290 + void setDevKernText(bool devKernText); 1.291 + 1.292 + /** Helper for getFlags(), returns true if kDistanceFieldTextTEMP_Flag bit is set 1.293 + @return true if the distanceFieldText bit is set in the paint's flags. 1.294 + */ 1.295 + bool isDistanceFieldTextTEMP() const { 1.296 + return SkToBool(this->getFlags() & kDistanceFieldTextTEMP_Flag); 1.297 + } 1.298 + 1.299 + /** Helper for setFlags(), setting or clearing the kDistanceFieldTextTEMP_Flag bit 1.300 + @param distanceFieldText true to set the kDistanceFieldTextTEMP_Flag bit in the paint's 1.301 + flags, false to clear it. 1.302 + */ 1.303 + void setDistanceFieldTextTEMP(bool distanceFieldText); 1.304 + 1.305 + enum FilterLevel { 1.306 + kNone_FilterLevel, 1.307 + kLow_FilterLevel, 1.308 + kMedium_FilterLevel, 1.309 + kHigh_FilterLevel 1.310 + }; 1.311 + 1.312 + /** 1.313 + * Return the filter level. This affects the quality (and performance) of 1.314 + * drawing scaled images. 1.315 + */ 1.316 + FilterLevel getFilterLevel() const; 1.317 + 1.318 + /** 1.319 + * Set the filter level. This affects the quality (and performance) of 1.320 + * drawing scaled images. 1.321 + */ 1.322 + void setFilterLevel(FilterLevel); 1.323 + 1.324 + /** 1.325 + * If the predicate is true, set the filterLevel to Low, else set it to 1.326 + * None. 1.327 + */ 1.328 + SK_ATTR_DEPRECATED("use setFilterLevel") 1.329 + void setFilterBitmap(bool doFilter) { 1.330 + this->setFilterLevel(doFilter ? kLow_FilterLevel : kNone_FilterLevel); 1.331 + } 1.332 + 1.333 + /** 1.334 + * Returns true if getFilterLevel() returns anything other than None. 1.335 + */ 1.336 + SK_ATTR_DEPRECATED("use getFilterLevel") 1.337 + bool isFilterBitmap() const { 1.338 + return kNone_FilterLevel != this->getFilterLevel(); 1.339 + } 1.340 + 1.341 + /** Styles apply to rect, oval, path, and text. 1.342 + Bitmaps are always drawn in "fill", and lines are always drawn in 1.343 + "stroke". 1.344 + 1.345 + Note: strokeandfill implicitly draws the result with 1.346 + SkPath::kWinding_FillType, so if the original path is even-odd, the 1.347 + results may not appear the same as if it was drawn twice, filled and 1.348 + then stroked. 1.349 + */ 1.350 + enum Style { 1.351 + kFill_Style, //!< fill the geometry 1.352 + kStroke_Style, //!< stroke the geometry 1.353 + kStrokeAndFill_Style, //!< fill and stroke the geometry 1.354 + }; 1.355 + enum { 1.356 + kStyleCount = kStrokeAndFill_Style + 1 1.357 + }; 1.358 + 1.359 + /** Return the paint's style, used for controlling how primitives' 1.360 + geometries are interpreted (except for drawBitmap, which always assumes 1.361 + kFill_Style). 1.362 + @return the paint's Style 1.363 + */ 1.364 + Style getStyle() const { return (Style)fStyle; } 1.365 + 1.366 + /** Set the paint's style, used for controlling how primitives' 1.367 + geometries are interpreted (except for drawBitmap, which always assumes 1.368 + Fill). 1.369 + @param style The new style to set in the paint 1.370 + */ 1.371 + void setStyle(Style style); 1.372 + 1.373 + /** Return the paint's color. Note that the color is a 32bit value 1.374 + containing alpha as well as r,g,b. This 32bit value is not 1.375 + premultiplied, meaning that its alpha can be any value, regardless of 1.376 + the values of r,g,b. 1.377 + @return the paint's color (and alpha). 1.378 + */ 1.379 + SkColor getColor() const { return fColor; } 1.380 + 1.381 + /** Set the paint's color. Note that the color is a 32bit value containing 1.382 + alpha as well as r,g,b. This 32bit value is not premultiplied, meaning 1.383 + that its alpha can be any value, regardless of the values of r,g,b. 1.384 + @param color The new color (including alpha) to set in the paint. 1.385 + */ 1.386 + void setColor(SkColor color); 1.387 + 1.388 + /** Helper to getColor() that just returns the color's alpha value. 1.389 + @return the alpha component of the paint's color. 1.390 + */ 1.391 + uint8_t getAlpha() const { return SkToU8(SkColorGetA(fColor)); } 1.392 + 1.393 + /** Helper to setColor(), that only assigns the color's alpha value, 1.394 + leaving its r,g,b values unchanged. 1.395 + @param a set the alpha component (0..255) of the paint's color. 1.396 + */ 1.397 + void setAlpha(U8CPU a); 1.398 + 1.399 + /** Helper to setColor(), that takes a,r,g,b and constructs the color value 1.400 + using SkColorSetARGB() 1.401 + @param a The new alpha component (0..255) of the paint's color. 1.402 + @param r The new red component (0..255) of the paint's color. 1.403 + @param g The new green component (0..255) of the paint's color. 1.404 + @param b The new blue component (0..255) of the paint's color. 1.405 + */ 1.406 + void setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b); 1.407 + 1.408 + /** Return the width for stroking. 1.409 + <p /> 1.410 + A value of 0 strokes in hairline mode. 1.411 + Hairlines always draw 1-pixel wide, regardless of the matrix. 1.412 + @return the paint's stroke width, used whenever the paint's style is 1.413 + Stroke or StrokeAndFill. 1.414 + */ 1.415 + SkScalar getStrokeWidth() const { return fWidth; } 1.416 + 1.417 + /** Set the width for stroking. 1.418 + Pass 0 to stroke in hairline mode. 1.419 + Hairlines always draw 1-pixel wide, regardless of the matrix. 1.420 + @param width set the paint's stroke width, used whenever the paint's 1.421 + style is Stroke or StrokeAndFill. 1.422 + */ 1.423 + void setStrokeWidth(SkScalar width); 1.424 + 1.425 + /** Return the paint's stroke miter value. This is used to control the 1.426 + behavior of miter joins when the joins angle is sharp. 1.427 + @return the paint's miter limit, used whenever the paint's style is 1.428 + Stroke or StrokeAndFill. 1.429 + */ 1.430 + SkScalar getStrokeMiter() const { return fMiterLimit; } 1.431 + 1.432 + /** Set the paint's stroke miter value. This is used to control the 1.433 + behavior of miter joins when the joins angle is sharp. This value must 1.434 + be >= 0. 1.435 + @param miter set the miter limit on the paint, used whenever the 1.436 + paint's style is Stroke or StrokeAndFill. 1.437 + */ 1.438 + void setStrokeMiter(SkScalar miter); 1.439 + 1.440 + /** Cap enum specifies the settings for the paint's strokecap. This is the 1.441 + treatment that is applied to the beginning and end of each non-closed 1.442 + contour (e.g. lines). 1.443 + */ 1.444 + enum Cap { 1.445 + kButt_Cap, //!< begin/end contours with no extension 1.446 + kRound_Cap, //!< begin/end contours with a semi-circle extension 1.447 + kSquare_Cap, //!< begin/end contours with a half square extension 1.448 + 1.449 + kCapCount, 1.450 + kDefault_Cap = kButt_Cap 1.451 + }; 1.452 + 1.453 + /** Join enum specifies the settings for the paint's strokejoin. This is 1.454 + the treatment that is applied to corners in paths and rectangles. 1.455 + */ 1.456 + enum Join { 1.457 + kMiter_Join, //!< connect path segments with a sharp join 1.458 + kRound_Join, //!< connect path segments with a round join 1.459 + kBevel_Join, //!< connect path segments with a flat bevel join 1.460 + 1.461 + kJoinCount, 1.462 + kDefault_Join = kMiter_Join 1.463 + }; 1.464 + 1.465 + /** Return the paint's stroke cap type, controlling how the start and end 1.466 + of stroked lines and paths are treated. 1.467 + @return the line cap style for the paint, used whenever the paint's 1.468 + style is Stroke or StrokeAndFill. 1.469 + */ 1.470 + Cap getStrokeCap() const { return (Cap)fCapType; } 1.471 + 1.472 + /** Set the paint's stroke cap type. 1.473 + @param cap set the paint's line cap style, used whenever the paint's 1.474 + style is Stroke or StrokeAndFill. 1.475 + */ 1.476 + void setStrokeCap(Cap cap); 1.477 + 1.478 + /** Return the paint's stroke join type. 1.479 + @return the paint's line join style, used whenever the paint's style is 1.480 + Stroke or StrokeAndFill. 1.481 + */ 1.482 + Join getStrokeJoin() const { return (Join)fJoinType; } 1.483 + 1.484 + /** Set the paint's stroke join type. 1.485 + @param join set the paint's line join style, used whenever the paint's 1.486 + style is Stroke or StrokeAndFill. 1.487 + */ 1.488 + void setStrokeJoin(Join join); 1.489 + 1.490 + /** 1.491 + * Applies any/all effects (patheffect, stroking) to src, returning the 1.492 + * result in dst. The result is that drawing src with this paint will be 1.493 + * the same as drawing dst with a default paint (at least from the 1.494 + * geometric perspective). 1.495 + * 1.496 + * @param src input path 1.497 + * @param dst output path (may be the same as src) 1.498 + * @param cullRect If not null, the dst path may be culled to this rect. 1.499 + * @return true if the path should be filled, or false if it should be 1.500 + * drawn with a hairline (width == 0) 1.501 + */ 1.502 + bool getFillPath(const SkPath& src, SkPath* dst, 1.503 + const SkRect* cullRect = NULL) const; 1.504 + 1.505 + /** Get the paint's shader object. 1.506 + <p /> 1.507 + The shader's reference count is not affected. 1.508 + @return the paint's shader (or NULL) 1.509 + */ 1.510 + SkShader* getShader() const { return fShader; } 1.511 + 1.512 + /** Set or clear the shader object. 1.513 + * Shaders specify the source color(s) for what is being drawn. If a paint 1.514 + * has no shader, then the paint's color is used. If the paint has a 1.515 + * shader, then the shader's color(s) are use instead, but they are 1.516 + * modulated by the paint's alpha. This makes it easy to create a shader 1.517 + * once (e.g. bitmap tiling or gradient) and then change its transparency 1.518 + * w/o having to modify the original shader... only the paint's alpha needs 1.519 + * to be modified. 1.520 + * <p /> 1.521 + * Pass NULL to clear any previous shader. 1.522 + * As a convenience, the parameter passed is also returned. 1.523 + * If a previous shader exists, its reference count is decremented. 1.524 + * If shader is not NULL, its reference count is incremented. 1.525 + * @param shader May be NULL. The shader to be installed in the paint 1.526 + * @return shader 1.527 + */ 1.528 + SkShader* setShader(SkShader* shader); 1.529 + 1.530 + /** Get the paint's colorfilter. If there is a colorfilter, its reference 1.531 + count is not changed. 1.532 + @return the paint's colorfilter (or NULL) 1.533 + */ 1.534 + SkColorFilter* getColorFilter() const { return fColorFilter; } 1.535 + 1.536 + /** Set or clear the paint's colorfilter, returning the parameter. 1.537 + <p /> 1.538 + If the paint already has a filter, its reference count is decremented. 1.539 + If filter is not NULL, its reference count is incremented. 1.540 + @param filter May be NULL. The filter to be installed in the paint 1.541 + @return filter 1.542 + */ 1.543 + SkColorFilter* setColorFilter(SkColorFilter* filter); 1.544 + 1.545 + /** Get the paint's xfermode object. 1.546 + <p /> 1.547 + The xfermode's reference count is not affected. 1.548 + @return the paint's xfermode (or NULL) 1.549 + */ 1.550 + SkXfermode* getXfermode() const { return fXfermode; } 1.551 + 1.552 + /** Set or clear the xfermode object. 1.553 + <p /> 1.554 + Pass NULL to clear any previous xfermode. 1.555 + As a convenience, the parameter passed is also returned. 1.556 + If a previous xfermode exists, its reference count is decremented. 1.557 + If xfermode is not NULL, its reference count is incremented. 1.558 + @param xfermode May be NULL. The new xfermode to be installed in the 1.559 + paint 1.560 + @return xfermode 1.561 + */ 1.562 + SkXfermode* setXfermode(SkXfermode* xfermode); 1.563 + 1.564 + /** Create an xfermode based on the specified Mode, and assign it into the 1.565 + paint, returning the mode that was set. If the Mode is SrcOver, then 1.566 + the paint's xfermode is set to null. 1.567 + */ 1.568 + SkXfermode* setXfermodeMode(SkXfermode::Mode); 1.569 + 1.570 + /** Get the paint's patheffect object. 1.571 + <p /> 1.572 + The patheffect reference count is not affected. 1.573 + @return the paint's patheffect (or NULL) 1.574 + */ 1.575 + SkPathEffect* getPathEffect() const { return fPathEffect; } 1.576 + 1.577 + /** Set or clear the patheffect object. 1.578 + <p /> 1.579 + Pass NULL to clear any previous patheffect. 1.580 + As a convenience, the parameter passed is also returned. 1.581 + If a previous patheffect exists, its reference count is decremented. 1.582 + If patheffect is not NULL, its reference count is incremented. 1.583 + @param effect May be NULL. The new patheffect to be installed in the 1.584 + paint 1.585 + @return effect 1.586 + */ 1.587 + SkPathEffect* setPathEffect(SkPathEffect* effect); 1.588 + 1.589 + /** Get the paint's maskfilter object. 1.590 + <p /> 1.591 + The maskfilter reference count is not affected. 1.592 + @return the paint's maskfilter (or NULL) 1.593 + */ 1.594 + SkMaskFilter* getMaskFilter() const { return fMaskFilter; } 1.595 + 1.596 + /** Set or clear the maskfilter object. 1.597 + <p /> 1.598 + Pass NULL to clear any previous maskfilter. 1.599 + As a convenience, the parameter passed is also returned. 1.600 + If a previous maskfilter exists, its reference count is decremented. 1.601 + If maskfilter is not NULL, its reference count is incremented. 1.602 + @param maskfilter May be NULL. The new maskfilter to be installed in 1.603 + the paint 1.604 + @return maskfilter 1.605 + */ 1.606 + SkMaskFilter* setMaskFilter(SkMaskFilter* maskfilter); 1.607 + 1.608 + // These attributes are for text/fonts 1.609 + 1.610 + /** Get the paint's typeface object. 1.611 + <p /> 1.612 + The typeface object identifies which font to use when drawing or 1.613 + measuring text. The typeface reference count is not affected. 1.614 + @return the paint's typeface (or NULL) 1.615 + */ 1.616 + SkTypeface* getTypeface() const { return fTypeface; } 1.617 + 1.618 + /** Set or clear the typeface object. 1.619 + <p /> 1.620 + Pass NULL to clear any previous typeface. 1.621 + As a convenience, the parameter passed is also returned. 1.622 + If a previous typeface exists, its reference count is decremented. 1.623 + If typeface is not NULL, its reference count is incremented. 1.624 + @param typeface May be NULL. The new typeface to be installed in the 1.625 + paint 1.626 + @return typeface 1.627 + */ 1.628 + SkTypeface* setTypeface(SkTypeface* typeface); 1.629 + 1.630 + /** Get the paint's rasterizer (or NULL). 1.631 + <p /> 1.632 + The raster controls how paths/text are turned into alpha masks. 1.633 + @return the paint's rasterizer (or NULL) 1.634 + */ 1.635 + SkRasterizer* getRasterizer() const { return fRasterizer; } 1.636 + 1.637 + /** Set or clear the rasterizer object. 1.638 + <p /> 1.639 + Pass NULL to clear any previous rasterizer. 1.640 + As a convenience, the parameter passed is also returned. 1.641 + If a previous rasterizer exists in the paint, its reference count is 1.642 + decremented. If rasterizer is not NULL, its reference count is 1.643 + incremented. 1.644 + @param rasterizer May be NULL. The new rasterizer to be installed in 1.645 + the paint. 1.646 + @return rasterizer 1.647 + */ 1.648 + SkRasterizer* setRasterizer(SkRasterizer* rasterizer); 1.649 + 1.650 + SkImageFilter* getImageFilter() const { return fImageFilter; } 1.651 + SkImageFilter* setImageFilter(SkImageFilter*); 1.652 + 1.653 + SkAnnotation* getAnnotation() const { return fAnnotation; } 1.654 + SkAnnotation* setAnnotation(SkAnnotation*); 1.655 + 1.656 + /** 1.657 + * Returns true if there is an annotation installed on this paint, and 1.658 + * the annotation specifics no-drawing. 1.659 + */ 1.660 + SK_ATTR_DEPRECATED("use getAnnotation and check for non-null") 1.661 + bool isNoDrawAnnotation() const { return this->getAnnotation() != NULL; } 1.662 + 1.663 + /** 1.664 + * Return the paint's SkDrawLooper (if any). Does not affect the looper's 1.665 + * reference count. 1.666 + */ 1.667 + SkDrawLooper* getLooper() const { return fLooper; } 1.668 + 1.669 + /** 1.670 + * Set or clear the looper object. 1.671 + * <p /> 1.672 + * Pass NULL to clear any previous looper. 1.673 + * As a convenience, the parameter passed is also returned. 1.674 + * If a previous looper exists in the paint, its reference count is 1.675 + * decremented. If looper is not NULL, its reference count is 1.676 + * incremented. 1.677 + * @param looper May be NULL. The new looper to be installed in the paint. 1.678 + * @return looper 1.679 + */ 1.680 + SkDrawLooper* setLooper(SkDrawLooper* looper); 1.681 + 1.682 + enum Align { 1.683 + kLeft_Align, 1.684 + kCenter_Align, 1.685 + kRight_Align, 1.686 + }; 1.687 + enum { 1.688 + kAlignCount = 3 1.689 + }; 1.690 + 1.691 + /** Return the paint's Align value for drawing text. 1.692 + @return the paint's Align value for drawing text. 1.693 + */ 1.694 + Align getTextAlign() const { return (Align)fTextAlign; } 1.695 + 1.696 + /** Set the paint's text alignment. 1.697 + @param align set the paint's Align value for drawing text. 1.698 + */ 1.699 + void setTextAlign(Align align); 1.700 + 1.701 + /** Return the paint's text size. 1.702 + @return the paint's text size. 1.703 + */ 1.704 + SkScalar getTextSize() const { return fTextSize; } 1.705 + 1.706 + /** Set the paint's text size. This value must be > 0 1.707 + @param textSize set the paint's text size. 1.708 + */ 1.709 + void setTextSize(SkScalar textSize); 1.710 + 1.711 + /** Return the paint's horizontal scale factor for text. The default value 1.712 + is 1.0. 1.713 + @return the paint's scale factor in X for drawing/measuring text 1.714 + */ 1.715 + SkScalar getTextScaleX() const { return fTextScaleX; } 1.716 + 1.717 + /** Set the paint's horizontal scale factor for text. The default value 1.718 + is 1.0. Values > 1.0 will stretch the text wider. Values < 1.0 will 1.719 + stretch the text narrower. 1.720 + @param scaleX set the paint's scale factor in X for drawing/measuring 1.721 + text. 1.722 + */ 1.723 + void setTextScaleX(SkScalar scaleX); 1.724 + 1.725 + /** Return the paint's horizontal skew factor for text. The default value 1.726 + is 0. 1.727 + @return the paint's skew factor in X for drawing text. 1.728 + */ 1.729 + SkScalar getTextSkewX() const { return fTextSkewX; } 1.730 + 1.731 + /** Set the paint's horizontal skew factor for text. The default value 1.732 + is 0. For approximating oblique text, use values around -0.25. 1.733 + @param skewX set the paint's skew factor in X for drawing text. 1.734 + */ 1.735 + void setTextSkewX(SkScalar skewX); 1.736 + 1.737 + /** Describes how to interpret the text parameters that are passed to paint 1.738 + methods like measureText() and getTextWidths(). 1.739 + */ 1.740 + enum TextEncoding { 1.741 + kUTF8_TextEncoding, //!< the text parameters are UTF8 1.742 + kUTF16_TextEncoding, //!< the text parameters are UTF16 1.743 + kUTF32_TextEncoding, //!< the text parameters are UTF32 1.744 + kGlyphID_TextEncoding //!< the text parameters are glyph indices 1.745 + }; 1.746 + 1.747 + TextEncoding getTextEncoding() const { return (TextEncoding)fTextEncoding; } 1.748 + 1.749 + void setTextEncoding(TextEncoding encoding); 1.750 + 1.751 + struct FontMetrics { 1.752 + /** Flags which indicate the confidence level of various metrics. 1.753 + A set flag indicates that the metric may be trusted. 1.754 + */ 1.755 + enum FontMetricsFlags { 1.756 + kUnderlineThinknessIsValid_Flag = 1 << 0, 1.757 + kUnderlinePositionIsValid_Flag = 1 << 1, 1.758 + }; 1.759 + 1.760 + uint32_t fFlags; //!< Bit field to identify which values are unknown 1.761 + SkScalar fTop; //!< The greatest distance above the baseline for any glyph (will be <= 0) 1.762 + SkScalar fAscent; //!< The recommended distance above the baseline (will be <= 0) 1.763 + SkScalar fDescent; //!< The recommended distance below the baseline (will be >= 0) 1.764 + SkScalar fBottom; //!< The greatest distance below the baseline for any glyph (will be >= 0) 1.765 + SkScalar fLeading; //!< The recommended distance to add between lines of text (will be >= 0) 1.766 + SkScalar fAvgCharWidth; //!< the average character width (>= 0) 1.767 + SkScalar fMaxCharWidth; //!< the max character width (>= 0) 1.768 + SkScalar fXMin; //!< The minimum bounding box x value for all glyphs 1.769 + SkScalar fXMax; //!< The maximum bounding box x value for all glyphs 1.770 + SkScalar fXHeight; //!< The height of an 'x' in px, or 0 if no 'x' in face 1.771 + SkScalar fCapHeight; //!< The cap height (> 0), or 0 if cannot be determined. 1.772 + SkScalar fUnderlineThickness; //!< underline thickness, or 0 if cannot be determined 1.773 + 1.774 + /** Underline Position - position of the top of the Underline stroke 1.775 + relative to the baseline, this can have following values 1.776 + - Negative - means underline should be drawn above baseline. 1.777 + - Positive - means below baseline. 1.778 + - Zero - mean underline should be drawn on baseline. 1.779 + */ 1.780 + SkScalar fUnderlinePosition; //!< underline position, or 0 if cannot be determined 1.781 + 1.782 + /** If the fontmetrics has a valid underlinethickness, return true, and set the 1.783 + thickness param to that value. If it doesn't return false and ignore the 1.784 + thickness param. 1.785 + */ 1.786 + bool hasUnderlineThickness(SkScalar* thickness) const { 1.787 + if (SkToBool(fFlags & kUnderlineThinknessIsValid_Flag)) { 1.788 + *thickness = fUnderlineThickness; 1.789 + return true; 1.790 + } 1.791 + return false; 1.792 + } 1.793 + 1.794 + /** If the fontmetrics has a valid underlineposition, return true, and set the 1.795 + thickness param to that value. If it doesn't return false and ignore the 1.796 + thickness param. 1.797 + */ 1.798 + bool hasUnderlinePosition(SkScalar* position) const { 1.799 + if (SkToBool(fFlags & kUnderlinePositionIsValid_Flag)) { 1.800 + *position = fUnderlinePosition; 1.801 + return true; 1.802 + } 1.803 + return false; 1.804 + } 1.805 + 1.806 + }; 1.807 + 1.808 + /** Return the recommend spacing between lines (which will be 1.809 + fDescent - fAscent + fLeading). 1.810 + If metrics is not null, return in it the font metrics for the 1.811 + typeface/pointsize/etc. currently set in the paint. 1.812 + @param metrics If not null, returns the font metrics for the 1.813 + current typeface/pointsize/etc setting in this 1.814 + paint. 1.815 + @param scale If not 0, return width as if the canvas were scaled 1.816 + by this value 1.817 + @param return the recommended spacing between lines 1.818 + */ 1.819 + SkScalar getFontMetrics(FontMetrics* metrics, SkScalar scale = 0) const; 1.820 + 1.821 + /** Return the recommend line spacing. This will be 1.822 + fDescent - fAscent + fLeading 1.823 + */ 1.824 + SkScalar getFontSpacing() const { return this->getFontMetrics(NULL, 0); } 1.825 + 1.826 + /** Convert the specified text into glyph IDs, returning the number of 1.827 + glyphs ID written. If glyphs is NULL, it is ignore and only the count 1.828 + is returned. 1.829 + */ 1.830 + int textToGlyphs(const void* text, size_t byteLength, 1.831 + uint16_t glyphs[]) const; 1.832 + 1.833 + /** Return true if all of the specified text has a corresponding non-zero 1.834 + glyph ID. If any of the code-points in the text are not supported in 1.835 + the typeface (i.e. the glyph ID would be zero), then return false. 1.836 + 1.837 + If the text encoding for the paint is kGlyph_TextEncoding, then this 1.838 + returns true if all of the specified glyph IDs are non-zero. 1.839 + */ 1.840 + bool containsText(const void* text, size_t byteLength) const; 1.841 + 1.842 + /** Convert the glyph array into Unichars. Unconvertable glyphs are mapped 1.843 + to zero. Note: this does not look at the text-encoding setting in the 1.844 + paint, only at the typeface. 1.845 + */ 1.846 + void glyphsToUnichars(const uint16_t glyphs[], int count, 1.847 + SkUnichar text[]) const; 1.848 + 1.849 + /** Return the number of drawable units in the specified text buffer. 1.850 + This looks at the current TextEncoding field of the paint. If you also 1.851 + want to have the text converted into glyph IDs, call textToGlyphs 1.852 + instead. 1.853 + */ 1.854 + int countText(const void* text, size_t byteLength) const { 1.855 + return this->textToGlyphs(text, byteLength, NULL); 1.856 + } 1.857 + 1.858 + /** Return the width of the text. This will return the vertical measure 1.859 + * if isVerticalText() is true, in which case the returned value should 1.860 + * be treated has a height instead of a width. 1.861 + * 1.862 + * @param text The text to be measured 1.863 + * @param length Number of bytes of text to measure 1.864 + * @param bounds If not NULL, returns the bounds of the text, 1.865 + * relative to (0, 0). 1.866 + * @param scale If not 0, return width as if the canvas were scaled 1.867 + * by this value 1.868 + * @return The advance width of the text 1.869 + */ 1.870 + SkScalar measureText(const void* text, size_t length, 1.871 + SkRect* bounds, SkScalar scale = 0) const; 1.872 + 1.873 + /** Return the width of the text. This will return the vertical measure 1.874 + * if isVerticalText() is true, in which case the returned value should 1.875 + * be treated has a height instead of a width. 1.876 + * 1.877 + * @param text Address of the text 1.878 + * @param length Number of bytes of text to measure 1.879 + * @return The advance width of the text 1.880 + */ 1.881 + SkScalar measureText(const void* text, size_t length) const { 1.882 + return this->measureText(text, length, NULL, 0); 1.883 + } 1.884 + 1.885 + /** Specify the direction the text buffer should be processed in breakText() 1.886 + */ 1.887 + enum TextBufferDirection { 1.888 + /** When measuring text for breakText(), begin at the start of the text 1.889 + buffer and proceed forward through the data. This is the default. 1.890 + */ 1.891 + kForward_TextBufferDirection, 1.892 + /** When measuring text for breakText(), begin at the end of the text 1.893 + buffer and proceed backwards through the data. 1.894 + */ 1.895 + kBackward_TextBufferDirection 1.896 + }; 1.897 + 1.898 + /** Return the number of bytes of text that were measured. If 1.899 + * isVerticalText() is true, then the vertical advances are used for 1.900 + * the measurement. 1.901 + * 1.902 + * @param text The text to be measured 1.903 + * @param length Number of bytes of text to measure 1.904 + * @param maxWidth Maximum width. Only the subset of text whose accumulated 1.905 + * widths are <= maxWidth are measured. 1.906 + * @param measuredWidth Optional. If non-null, this returns the actual 1.907 + * width of the measured text. 1.908 + * @param tbd Optional. The direction the text buffer should be 1.909 + * traversed during measuring. 1.910 + * @return The number of bytes of text that were measured. Will be 1.911 + * <= length. 1.912 + */ 1.913 + size_t breakText(const void* text, size_t length, SkScalar maxWidth, 1.914 + SkScalar* measuredWidth = NULL, 1.915 + TextBufferDirection tbd = kForward_TextBufferDirection) 1.916 + const; 1.917 + 1.918 + /** Return the advances for the text. These will be vertical advances if 1.919 + * isVerticalText() returns true. 1.920 + * 1.921 + * @param text the text 1.922 + * @param byteLength number of bytes to of text 1.923 + * @param widths If not null, returns the array of advances for 1.924 + * the glyphs. If not NULL, must be at least a large 1.925 + * as the number of unichars in the specified text. 1.926 + * @param bounds If not null, returns the bounds for each of 1.927 + * character, relative to (0, 0) 1.928 + * @return the number of unichars in the specified text. 1.929 + */ 1.930 + int getTextWidths(const void* text, size_t byteLength, SkScalar widths[], 1.931 + SkRect bounds[] = NULL) const; 1.932 + 1.933 + /** Return the path (outline) for the specified text. 1.934 + Note: just like SkCanvas::drawText, this will respect the Align setting 1.935 + in the paint. 1.936 + */ 1.937 + void getTextPath(const void* text, size_t length, SkScalar x, SkScalar y, 1.938 + SkPath* path) const; 1.939 + 1.940 + void getPosTextPath(const void* text, size_t length, 1.941 + const SkPoint pos[], SkPath* path) const; 1.942 + 1.943 +#ifdef SK_BUILD_FOR_ANDROID 1.944 + uint32_t getGenerationID() const; 1.945 + void setGenerationID(uint32_t generationID); 1.946 + 1.947 + /** Returns the base glyph count for the strike associated with this paint 1.948 + */ 1.949 + unsigned getBaseGlyphCount(SkUnichar text) const; 1.950 + 1.951 + const SkPaintOptionsAndroid& getPaintOptionsAndroid() const { 1.952 + return fPaintOptionsAndroid; 1.953 + } 1.954 + void setPaintOptionsAndroid(const SkPaintOptionsAndroid& options); 1.955 +#endif 1.956 + 1.957 + // returns true if the paint's settings (e.g. xfermode + alpha) resolve to 1.958 + // mean that we need not draw at all (e.g. SrcOver + 0-alpha) 1.959 + bool nothingToDraw() const; 1.960 + 1.961 + /////////////////////////////////////////////////////////////////////////// 1.962 + // would prefer to make these private... 1.963 + 1.964 + /** Returns true if the current paint settings allow for fast computation of 1.965 + bounds (i.e. there is nothing complex like a patheffect that would make 1.966 + the bounds computation expensive. 1.967 + */ 1.968 + bool canComputeFastBounds() const { 1.969 + if (this->getLooper()) { 1.970 + return this->getLooper()->canComputeFastBounds(*this); 1.971 + } 1.972 + return !this->getRasterizer(); 1.973 + } 1.974 + 1.975 + /** Only call this if canComputeFastBounds() returned true. This takes a 1.976 + raw rectangle (the raw bounds of a shape), and adjusts it for stylistic 1.977 + effects in the paint (e.g. stroking). If needed, it uses the storage 1.978 + rect parameter. It returns the adjusted bounds that can then be used 1.979 + for quickReject tests. 1.980 + 1.981 + The returned rect will either be orig or storage, thus the caller 1.982 + should not rely on storage being set to the result, but should always 1.983 + use the retured value. It is legal for orig and storage to be the same 1.984 + rect. 1.985 + 1.986 + e.g. 1.987 + if (paint.canComputeFastBounds()) { 1.988 + SkRect r, storage; 1.989 + path.computeBounds(&r, SkPath::kFast_BoundsType); 1.990 + const SkRect& fastR = paint.computeFastBounds(r, &storage); 1.991 + if (canvas->quickReject(fastR, ...)) { 1.992 + // don't draw the path 1.993 + } 1.994 + } 1.995 + */ 1.996 + const SkRect& computeFastBounds(const SkRect& orig, SkRect* storage) const { 1.997 + SkPaint::Style style = this->getStyle(); 1.998 + // ultra fast-case: filling with no effects that affect geometry 1.999 + if (kFill_Style == style) { 1.1000 + uintptr_t effects = reinterpret_cast<uintptr_t>(this->getLooper()); 1.1001 + effects |= reinterpret_cast<uintptr_t>(this->getMaskFilter()); 1.1002 + effects |= reinterpret_cast<uintptr_t>(this->getPathEffect()); 1.1003 + effects |= reinterpret_cast<uintptr_t>(this->getImageFilter()); 1.1004 + if (!effects) { 1.1005 + return orig; 1.1006 + } 1.1007 + } 1.1008 + 1.1009 + return this->doComputeFastBounds(orig, storage, style); 1.1010 + } 1.1011 + 1.1012 + const SkRect& computeFastStrokeBounds(const SkRect& orig, 1.1013 + SkRect* storage) const { 1.1014 + return this->doComputeFastBounds(orig, storage, kStroke_Style); 1.1015 + } 1.1016 + 1.1017 + // Take the style explicitly, so the caller can force us to be stroked 1.1018 + // without having to make a copy of the paint just to change that field. 1.1019 + const SkRect& doComputeFastBounds(const SkRect& orig, SkRect* storage, 1.1020 + Style) const; 1.1021 + 1.1022 + /** 1.1023 + * Return a matrix that applies the paint's text values: size, scale, skew 1.1024 + */ 1.1025 + static SkMatrix* SetTextMatrix(SkMatrix* matrix, SkScalar size, 1.1026 + SkScalar scaleX, SkScalar skewX) { 1.1027 + matrix->setScale(size * scaleX, size); 1.1028 + if (skewX) { 1.1029 + matrix->postSkew(skewX, 0); 1.1030 + } 1.1031 + return matrix; 1.1032 + } 1.1033 + 1.1034 + SkMatrix* setTextMatrix(SkMatrix* matrix) const { 1.1035 + return SetTextMatrix(matrix, fTextSize, fTextScaleX, fTextSkewX); 1.1036 + } 1.1037 + 1.1038 + SK_TO_STRING_NONVIRT() 1.1039 + 1.1040 + struct FlatteningTraits { 1.1041 + static void Flatten(SkWriteBuffer& buffer, const SkPaint& paint); 1.1042 + static void Unflatten(SkReadBuffer& buffer, SkPaint* paint); 1.1043 + }; 1.1044 + 1.1045 +private: 1.1046 + SkTypeface* fTypeface; 1.1047 + SkScalar fTextSize; 1.1048 + SkScalar fTextScaleX; 1.1049 + SkScalar fTextSkewX; 1.1050 + 1.1051 + SkPathEffect* fPathEffect; 1.1052 + SkShader* fShader; 1.1053 + SkXfermode* fXfermode; 1.1054 + SkMaskFilter* fMaskFilter; 1.1055 + SkColorFilter* fColorFilter; 1.1056 + SkRasterizer* fRasterizer; 1.1057 + SkDrawLooper* fLooper; 1.1058 + SkImageFilter* fImageFilter; 1.1059 + SkAnnotation* fAnnotation; 1.1060 + 1.1061 + SkColor fColor; 1.1062 + SkScalar fWidth; 1.1063 + SkScalar fMiterLimit; 1.1064 + 1.1065 + union { 1.1066 + struct { 1.1067 + // all of these bitfields should add up to 32 1.1068 + unsigned fFlags : 16; 1.1069 + unsigned fTextAlign : 2; 1.1070 + unsigned fCapType : 2; 1.1071 + unsigned fJoinType : 2; 1.1072 + unsigned fStyle : 2; 1.1073 + unsigned fTextEncoding : 2; // 3 values 1.1074 + unsigned fHinting : 2; 1.1075 + //unsigned fFreeBits : 4; 1.1076 + }; 1.1077 + uint32_t fBitfields; 1.1078 + }; 1.1079 + uint32_t getBitfields() const { return fBitfields; } 1.1080 + void setBitfields(uint32_t bitfields); 1.1081 + 1.1082 + uint32_t fDirtyBits; 1.1083 + 1.1084 + SkDrawCacheProc getDrawCacheProc() const; 1.1085 + SkMeasureCacheProc getMeasureCacheProc(TextBufferDirection dir, 1.1086 + bool needFullMetrics) const; 1.1087 + 1.1088 + SkScalar measure_text(SkGlyphCache*, const char* text, size_t length, 1.1089 + int* count, SkRect* bounds) const; 1.1090 + 1.1091 + SkGlyphCache* detachCache(const SkDeviceProperties* deviceProperties, const SkMatrix*) const; 1.1092 + 1.1093 + void descriptorProc(const SkDeviceProperties* deviceProperties, const SkMatrix* deviceMatrix, 1.1094 + void (*proc)(SkTypeface*, const SkDescriptor*, void*), 1.1095 + void* context, bool ignoreGamma = false) const; 1.1096 + 1.1097 + static void Term(); 1.1098 + 1.1099 + enum { 1.1100 + /* This is the size we use when we ask for a glyph's path. We then 1.1101 + * post-transform it as we draw to match the request. 1.1102 + * This is done to try to re-use cache entries for the path. 1.1103 + * 1.1104 + * This value is somewhat arbitrary. In theory, it could be 1, since 1.1105 + * we store paths as floats. However, we get the path from the font 1.1106 + * scaler, and it may represent its paths as fixed-point (or 26.6), 1.1107 + * so we shouldn't ask for something too big (might overflow 16.16) 1.1108 + * or too small (underflow 26.6). 1.1109 + * 1.1110 + * This value could track kMaxSizeForGlyphCache, assuming the above 1.1111 + * constraints, but since we ask for unhinted paths, the two values 1.1112 + * need not match per-se. 1.1113 + */ 1.1114 + kCanonicalTextSizeForPaths = 64, 1.1115 + 1.1116 + /* 1.1117 + * Above this size (taking into account CTM and textSize), we never use 1.1118 + * the cache for bits or metrics (we might overflow), so we just ask 1.1119 + * for a caononical size and post-transform that. 1.1120 + */ 1.1121 + kMaxSizeForGlyphCache = 256, 1.1122 + }; 1.1123 + 1.1124 + static bool TooBigToUseCache(const SkMatrix& ctm, const SkMatrix& textM); 1.1125 + 1.1126 + bool tooBigToUseCache() const; 1.1127 + bool tooBigToUseCache(const SkMatrix& ctm) const; 1.1128 + 1.1129 + // Set flags/hinting/textSize up to use for drawing text as paths. 1.1130 + // Returns scale factor to restore the original textSize, since will will 1.1131 + // have change it to kCanonicalTextSizeForPaths. 1.1132 + SkScalar setupForAsPaths(); 1.1133 + 1.1134 + static SkScalar MaxCacheSize2() { 1.1135 + static const SkScalar kMaxSize = SkIntToScalar(kMaxSizeForGlyphCache); 1.1136 + static const SkScalar kMag2Max = kMaxSize * kMaxSize; 1.1137 + return kMag2Max; 1.1138 + } 1.1139 + 1.1140 + friend class SkAutoGlyphCache; 1.1141 + friend class SkCanvas; 1.1142 + friend class SkDraw; 1.1143 + friend class SkGraphics; // So Term() can be called. 1.1144 + friend class SkPDFDevice; 1.1145 + friend class GrBitmapTextContext; 1.1146 + friend class GrDistanceFieldTextContext; 1.1147 + friend class SkTextToPathIter; 1.1148 + friend class SkCanonicalizePaint; 1.1149 + 1.1150 +#ifdef SK_BUILD_FOR_ANDROID 1.1151 + SkPaintOptionsAndroid fPaintOptionsAndroid; 1.1152 + 1.1153 + // In order for the == operator to work properly this must be the last field 1.1154 + // in the struct so that we can do a memcmp to this field's offset. 1.1155 + uint32_t fGenerationID; 1.1156 +#endif 1.1157 +}; 1.1158 + 1.1159 +#endif