1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkJSONCanvas_DEFINED
#define SkJSONCanvas_DEFINED
#include "SkCanvas.h"
#include "SkStream.h"
#include "SkJSONCPP.h"
#define SKJSONCANVAS_VERSION "version"
#define SKJSONCANVAS_COMMANDS "commands"
#define SKJSONCANVAS_COMMAND "command"
#define SKJSONCANVAS_COMMAND_TRANSLATE "Translate"
#define SKJSONCANVAS_COMMAND_SCALE "Scale"
#define SKJSONCANVAS_COMMAND_MATRIX "Matrix"
#define SKJSONCANVAS_COMMAND_PAINT "Paint"
#define SKJSONCANVAS_COMMAND_RECT "Rect"
#define SKJSONCANVAS_COMMAND_OVAL "Oval"
#define SKJSONCANVAS_COMMAND_RRECT "RRect"
#define SKJSONCANVAS_COMMAND_DRRECT "DRRect"
#define SKJSONCANVAS_COMMAND_POINTS "Points"
#define SKJSONCANVAS_COMMAND_VERTICES "Vertices"
#define SKJSONCANVAS_COMMAND_ATLAS "Atlas"
#define SKJSONCANVAS_COMMAND_PATH "Path"
#define SKJSONCANVAS_COMMAND_IMAGE "Image"
#define SKJSONCANVAS_COMMAND_IMAGERECT "ImageRect"
#define SKJSONCANVAS_COMMAND_IMAGENINE "ImageNine"
#define SKJSONCANVAS_COMMAND_BITMAP "Bitmap"
#define SKJSONCANVAS_COMMAND_BITMAPRECT "BitmapRect"
#define SKJSONCANVAS_COMMAND_BITMAPNINE "BitmapNine"
#define SKJSONCANVAS_COMMAND_TEXT "Text"
#define SKJSONCANVAS_COMMAND_POSTEXT "PosText"
#define SKJSONCANVAS_COMMAND_POSTEXTH "PosTextH"
#define SKJSONCANVAS_COMMAND_TEXTONPATH "TextOnPath"
#define SKJSONCANVAS_COMMAND_TEXTBLOB "TextBlob"
#define SKJSONCANVAS_COMMAND_PATCH "Patch"
#define SKJSONCANVAS_COMMAND_DRAWABLE "Drawable"
#define SKJSONCANVAS_COMMAND_CLIPRECT "ClipRect"
#define SKJSONCANVAS_COMMAND_CLIPRRECT "ClipRRect"
#define SKJSONCANVAS_COMMAND_CLIPPATH "ClipPath"
#define SKJSONCANVAS_COMMAND_CLIPREGION "ClipRegion"
#define SKJSONCANVAS_COMMAND_SAVE "Save"
#define SKJSONCANVAS_COMMAND_RESTORE "Restore"
#define SKJSONCANVAS_COMMAND_SAVELAYER "SaveLayer"
#define SKJSONCANVAS_ATTRIBUTE_MATRIX "matrix"
#define SKJSONCANVAS_ATTRIBUTE_COORDS "coords"
#define SKJSONCANVAS_ATTRIBUTE_BOUNDS "bounds"
#define SKJSONCANVAS_ATTRIBUTE_PAINT "paint"
#define SKJSONCANVAS_ATTRIBUTE_OUTER "outer"
#define SKJSONCANVAS_ATTRIBUTE_INNER "inner"
#define SKJSONCANVAS_ATTRIBUTE_MODE "mode"
#define SKJSONCANVAS_ATTRIBUTE_POINTS "points"
#define SKJSONCANVAS_ATTRIBUTE_PATH "path"
#define SKJSONCANVAS_ATTRIBUTE_TEXT "text"
#define SKJSONCANVAS_ATTRIBUTE_COLOR "color"
#define SKJSONCANVAS_ATTRIBUTE_ALPHA "alpha"
#define SKJSONCANVAS_ATTRIBUTE_STYLE "style"
#define SKJSONCANVAS_ATTRIBUTE_STROKEWIDTH "strokeWidth"
#define SKJSONCANVAS_ATTRIBUTE_STROKEMITER "strokeMiter"
#define SKJSONCANVAS_ATTRIBUTE_CAP "cap"
#define SKJSONCANVAS_ATTRIBUTE_ANTIALIAS "antiAlias"
#define SKJSONCANVAS_ATTRIBUTE_REGION "region"
#define SKJSONCANVAS_ATTRIBUTE_REGIONOP "op"
#define SKJSONCANVAS_ATTRIBUTE_EDGESTYLE "edgeStyle"
#define SKJSONCANVAS_ATTRIBUTE_DEVICEREGION "deviceRegion"
#define SKJSONCANVAS_ATTRIBUTE_BLUR "blur"
#define SKJSONCANVAS_ATTRIBUTE_SIGMA "sigma"
#define SKJSONCANVAS_ATTRIBUTE_QUALITY "quality"
#define SKJSONCANVAS_ATTRIBUTE_TEXTALIGN "textAlign"
#define SKJSONCANVAS_ATTRIBUTE_TEXTSIZE "textSize"
#define SKJSONCANVAS_ATTRIBUTE_TEXTSCALEX "textScaleX"
#define SKJSONCANVAS_ATTRIBUTE_TEXTSKEWX "textSkewX"
#define SKJSONCANVAS_ATTRIBUTE_DASHING "dashing"
#define SKJSONCANVAS_ATTRIBUTE_INTERVALS "intervals"
#define SKJSONCANVAS_ATTRIBUTE_PHASE "phase"
#define SKJSONCANVAS_ATTRIBUTE_FILLTYPE "fillType"
#define SKJSONCANVAS_ATTRIBUTE_VERBS "verbs"
#define SKJSONCANVAS_ATTRIBUTE_NAME "name"
#define SKJSONCANVAS_ATTRIBUTE_BYTES "bytes"
#define SKJSONCANVAS_ATTRIBUTE_SHADER "shader"
#define SKJSONCANVAS_ATTRIBUTE_PATHEFFECT "pathEffect"
#define SKJSONCANVAS_ATTRIBUTE_MASKFILTER "maskFilter"
#define SKJSONCANVAS_ATTRIBUTE_XFERMODE "xfermode"
#define SKJSONCANVAS_ATTRIBUTE_BACKDROP "backdrop"
#define SKJSONCANVAS_ATTRIBUTE_COLORFILTER "colorfilter"
#define SKJSONCANVAS_ATTRIBUTE_IMAGEFILTER "imagefilter"
#define SKJSONCANVAS_ATTRIBUTE_IMAGE "image"
#define SKJSONCANVAS_ATTRIBUTE_BITMAP "bitmap"
#define SKJSONCANVAS_ATTRIBUTE_SRC "src"
#define SKJSONCANVAS_ATTRIBUTE_DST "dst"
#define SKJSONCANVAS_ATTRIBUTE_STRICT "strict"
#define SKJSONCANVAS_ATTRIBUTE_DESCRIPTION "description"
#define SKJSONCANVAS_ATTRIBUTE_X "x"
#define SKJSONCANVAS_ATTRIBUTE_Y "y"
#define SKJSONCANVAS_ATTRIBUTE_RUNS "runs"
#define SKJSONCANVAS_ATTRIBUTE_POSITIONS "positions"
#define SKJSONCANVAS_ATTRIBUTE_GLYPHS "glyphs"
#define SKJSONCANVAS_ATTRIBUTE_FONT "font"
#define SKJSONCANVAS_ATTRIBUTE_TYPEFACE "typeface"
#define SKJSONCANVAS_VERB_MOVE "move"
#define SKJSONCANVAS_VERB_LINE "line"
#define SKJSONCANVAS_VERB_QUAD "quad"
#define SKJSONCANVAS_VERB_CUBIC "cubic"
#define SKJSONCANVAS_VERB_CONIC "conic"
#define SKJSONCANVAS_VERB_CLOSE "close"
#define SKJSONCANVAS_STYLE_FILL "fill"
#define SKJSONCANVAS_STYLE_STROKE "stroke"
#define SKJSONCANVAS_STYLE_STROKEANDFILL "strokeAndFill"
#define SKJSONCANVAS_POINTMODE_POINTS "points"
#define SKJSONCANVAS_POINTMODE_LINES "lines"
#define SKJSONCANVAS_POINTMODE_POLYGON "polygon"
#define SKJSONCANVAS_REGIONOP_DIFFERENCE "difference"
#define SKJSONCANVAS_REGIONOP_INTERSECT "intersect"
#define SKJSONCANVAS_REGIONOP_UNION "union"
#define SKJSONCANVAS_REGIONOP_XOR "xor"
#define SKJSONCANVAS_REGIONOP_REVERSE_DIFFERENCE "reverseDifference"
#define SKJSONCANVAS_REGIONOP_REPLACE "replace"
#define SKJSONCANVAS_BLURSTYLE_NORMAL "normal"
#define SKJSONCANVAS_BLURSTYLE_SOLID "solid"
#define SKJSONCANVAS_BLURSTYLE_OUTER "outer"
#define SKJSONCANVAS_BLURSTYLE_INNER "inner"
#define SKJSONCANVAS_BLURQUALITY_LOW "low"
#define SKJSONCANVAS_BLURQUALITY_HIGH "high"
#define SKJSONCANVAS_ALIGN_LEFT "left"
#define SKJSONCANVAS_ALIGN_CENTER "center"
#define SKJSONCANVAS_ALIGN_RIGHT "right"
#define SKJSONCANVAS_FILLTYPE_WINDING "winding"
#define SKJSONCANVAS_FILLTYPE_EVENODD "evenOdd"
#define SKJSONCANVAS_FILLTYPE_INVERSEWINDING "inverseWinding"
#define SKJSONCANVAS_FILLTYPE_INVERSEEVENODD "inverseEvenOdd"
#define SKJSONCANVAS_CAP_BUTT "butt"
#define SKJSONCANVAS_CAP_ROUND "round"
#define SKJSONCANVAS_CAP_SQUARE "square"
#define SKJSONCANVAS_COLORTYPE_ARGB4444 "ARGB4444"
#define SKJSONCANVAS_COLORTYPE_RGBA8888 "RGBA8888"
#define SKJSONCANVAS_COLORTYPE_BGRA8888 "BGRA8888"
#define SKJSONCANVAS_COLORTYPE_565 "565"
#define SKJSONCANVAS_COLORTYPE_GRAY8 "Gray8"
#define SKJSONCANVAS_COLORTYPE_INDEX8 "Index8"
#define SKJSONCANVAS_COLORTYPE_ALPHA8 "Alpha8"
#define SKJSONCANVAS_ALPHATYPE_OPAQUE "opaque"
#define SKJSONCANVAS_ALPHATYPE_PREMUL "premul"
#define SKJSONCANVAS_ALPHATYPE_UNPREMUL "unpremul"
/*
* Implementation of SkCanvas which writes JSON when drawn to. The JSON describes all of the draw
* commands issued to the canvas, and can later be turned back into draw commands using
* SkJSONRenderer. Be sure to call finish() when you are done drawing.
*/
class SkJSONCanvas : public SkCanvas {
public:
/* Create a canvas which writes to the specified output stream. */
SkJSONCanvas(int width, int height, SkWStream& out, bool sendBinaries = false);
/* Complete the JSON document. */
void finish();
static Json::Value MakeMatrix(const SkMatrix& matrix);
static Json::Value MakeIRect(const SkIRect& irect);
// overridden SkCanvas API
void didConcat(const SkMatrix&) override;
void didSetMatrix(const SkMatrix&) override;
void onDrawPaint(const SkPaint&) override;
void onDrawRect(const SkRect&, const SkPaint&) override;
void onDrawOval(const SkRect&, const SkPaint&) override;
void onDrawRRect(const SkRRect&, const SkPaint&) override;
void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
void onDrawPoints(SkCanvas::PointMode, size_t count, const SkPoint pts[],
const SkPaint&) override;
void onDrawVertices(SkCanvas::VertexMode, int vertexCount, const SkPoint vertices[],
const SkPoint texs[], const SkColor colors[], SkXfermode*,
const uint16_t indices[], int indexCount, const SkPaint&) override;
void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[],
int count, SkXfermode::Mode, const SkRect* cull, const SkPaint*) override;
void onDrawPath(const SkPath&, const SkPaint&) override;
void onDrawImage(const SkImage*, SkScalar dx, SkScalar dy, const SkPaint*) override;
void onDrawImageRect(const SkImage*, const SkRect*, const SkRect&, const SkPaint*,
SrcRectConstraint) override;
void onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst,
const SkPaint*) override;
void onDrawBitmap(const SkBitmap&, SkScalar dx, SkScalar dy, const SkPaint*) override;
void onDrawBitmapRect(const SkBitmap&, const SkRect*, const SkRect&, const SkPaint*,
SkCanvas::SrcRectConstraint) override;
void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
const SkPaint*) override;
void onDrawText(const void* text, size_t byteLength, SkScalar x,
SkScalar y, const SkPaint& paint) override;
void onDrawPosText(const void* text, size_t byteLength,
const SkPoint pos[], const SkPaint& paint) override;
void onDrawPosTextH(const void* text, size_t byteLength,
const SkScalar xpos[], SkScalar constY,
const SkPaint& paint) override;
void onDrawTextOnPath(const void* text, size_t byteLength,
const SkPath& path, const SkMatrix* matrix,
const SkPaint& paint) override;
void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
const SkPaint& paint) override;
void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint) override;
void onDrawDrawable(SkDrawable*, const SkMatrix*) override;
void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) override;
void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) override;
void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) override;
void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) override;
void willSave() override;
void willRestore() override;
SkCanvas::SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec& rec) override;
private:
// Helpers to turn values into JSON, these could probably be static
Json::Value makePoint(const SkPoint& point);
Json::Value makePoint(SkScalar x, SkScalar y);
Json::Value makeRect(const SkRect& rect);
Json::Value makeRRect(const SkRRect& rrect);
Json::Value makePath(const SkPath& path);
Json::Value makeRegion(const SkRegion& region);
Json::Value makePaint(const SkPaint& paint);
Json::Value makeRegionOp(SkRegion::Op op);
Json::Value makeEdgeStyle(SkCanvas::ClipEdgeStyle edgeStyle);
Json::Value makePointMode(SkCanvas::PointMode mode);
void updateMatrix();
SkWStream& fOut;
Json::Value fRoot;
Json::Value fCommands;
bool fSendBinaries;
typedef SkCanvas INHERITED;
};
#endif
|