Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: site/user/api/skpaint.md

Issue 1127383010: Documentation: SkCanvas API (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-05-19 (Tuesday) 13:19:57 EDT Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « site/user/api/skmatrix.md ('k') | site/user/api/skrect.md » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 SkPaint
2 =======
3
4 *color, stroke, font, effects*
5
6 <!-- Updated Jan 17, 2013 by humper@google.com -->
7
8 Anytime you draw something in Skia, and want to specify what color it
9 is, or how it blends with the background, or what style or font to
10 draw it in, you specify those attributes in a paint.
11
12 Unlike `SkCanvas`, paints do not maintain an internal stack of state
13 (i.e. there is no save/restore on a paint). However, paints are
14 relatively light-weight, so the client may create and maintain any
15 number of paint objects, each setup for a particular use. Factoring
16 all of these color and stylistic attribute out of the canvas state,
17 and into (multiple) paint objects, allows canvas' save/restore to be
18 that much more efficient, as all they have to do is maintain the stack
19 of matrix and clip settings.
20
21 <!--?prettify lang=cc?-->
22
23 SkPaint paint1, paint2, paint3;
24
25 paint1.setColor(0xFFFF0000:
26 paint1.setStyle(SkPaint::kFill_Style);
27
28 paint2.setColor(0x8000FF00);
29 paint2.setStyle(SkPaint::kStroke_Style);
30 paint2.setStrokeWidth(SkIntToScalar(3));
31
32 paint3.setColor(0xFF888888);
33 paint3.setTextSize(SkIntToScalar(24));
34 paint3.setTextScaleX(SkFloatToScalar(0.75f));
35
36
37 This shows three different paints, each setup to draw in a different
38 style. Now the caller can intermix these paints freely, either using
39 them as is, or modifying them as the drawing proceeds.
40
41 <!--?prettify lang=cc?-->
42
43 canvas->drawRect(..., paint1);
44 canvas->drawRect(..., paint2);
45
46 paint2.setStrokeWidth(SkIntToScalar(5));
47 canvas->drawOval(..., paint2);
48
49 canvas->drawText(..., paint3);
50 paint3.setColor(0xFF0000FF);
51 canvas->drawText(..., paint3);
52
53
54 Beyond simple attributes such as color, strokes, and text values,
55 paints support effects. These are subclasses of different aspects of
56 the drawing pipeline, that when referenced by a paint (each of them is
57 reference-counted), are called to override some part of the drawing
58 pipeline.
59
60 For example, to draw using a gradient instead of a single color,
61 assign a SkShader to the paint.
62
63 <!--?prettify lang=cc?-->
64
65 SkShader* shader = SkGradientShader::CreateLinear(...);
66 paint.setShader(shader);
67 shader->unref();
68
69 Now, anything drawn with that paint will be drawn with the gradient
70 specified in the call to CreateLinear(). The shader object that is
71 returned is reference-counted. Whenever any effects object, like a
72 shader, is assigned to a paint, its reference-count is increased by
73 the paint. To balance this, the caller in the above example calls
74 unref() on the shader once it has assigned it to the paint. Now the
75 paint is the only "owner" of that shader, and it will automatically
76 call unref() on the shader when either the paint goes out of scope, or
77 if another shader (or null) is assigned to it.
78
79 There are 6 types of effects that can be assigned to a paint:
80
81 * **SkPathEffect** - modifications to the geometry (path) before it
82 generates an alpha mask (e.g. dashing)
83 * **SkRasterizer** - composing custom mask layers (e.g. shadows)
84 * **SkMaskFilter** - modifications to the alpha mask before it is
85 colorized and drawn (e.g. blur, emboss)
86 * **SkShader** - e.g. gradients (linear, radial, sweep), bitmap patterns
87 (clamp, repeat, mirror)
88 * **SkColorFilter** - modify the source color(s) before applying the
89 xfermode (e.g. color matrix)
90 * **SkXfermode** - e.g. porter-duff transfermodes, blend modes
91
92 Paints also hold a reference to a SkTypeface. The typeface represents
93 a specific font style, to be used for measuring and drawing
94 text. Speaking of which, paints are used not only for drawing text,
95 but also for measuring it.
96
97 <!--?prettify lang=cc?-->
98
99 paint.measureText(...);
100 paint.getTextBounds(...);
101 paint.textToGlyphs(...);
102 paint.getFontMetrics(...);
OLDNEW
« no previous file with comments | « site/user/api/skmatrix.md ('k') | site/user/api/skrect.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698