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

Side by Side Diff: tools/json/SkJSONCanvas.h

Issue 1662503003: support for more features when rendering to/from JSON (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 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 | « gyp/json.gyp ('k') | tools/json/SkJSONCanvas.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkJSONCanvas_DEFINED 8 #ifndef SkJSONCanvas_DEFINED
9 #define SkJSONCanvas_DEFINED 9 #define SkJSONCanvas_DEFINED
10 10
(...skipping 27 matching lines...) Expand all
38 #define SKJSONCANVAS_COMMAND_TEXTONPATH "TextOnPath" 38 #define SKJSONCANVAS_COMMAND_TEXTONPATH "TextOnPath"
39 #define SKJSONCANVAS_COMMAND_TEXTBLOB "TextBlob" 39 #define SKJSONCANVAS_COMMAND_TEXTBLOB "TextBlob"
40 #define SKJSONCANVAS_COMMAND_PATCH "Patch" 40 #define SKJSONCANVAS_COMMAND_PATCH "Patch"
41 #define SKJSONCANVAS_COMMAND_DRAWABLE "Drawable" 41 #define SKJSONCANVAS_COMMAND_DRAWABLE "Drawable"
42 #define SKJSONCANVAS_COMMAND_CLIPRECT "ClipRect" 42 #define SKJSONCANVAS_COMMAND_CLIPRECT "ClipRect"
43 #define SKJSONCANVAS_COMMAND_CLIPRRECT "ClipRRect" 43 #define SKJSONCANVAS_COMMAND_CLIPRRECT "ClipRRect"
44 #define SKJSONCANVAS_COMMAND_CLIPPATH "ClipPath" 44 #define SKJSONCANVAS_COMMAND_CLIPPATH "ClipPath"
45 #define SKJSONCANVAS_COMMAND_CLIPREGION "ClipRegion" 45 #define SKJSONCANVAS_COMMAND_CLIPREGION "ClipRegion"
46 #define SKJSONCANVAS_COMMAND_SAVE "Save" 46 #define SKJSONCANVAS_COMMAND_SAVE "Save"
47 #define SKJSONCANVAS_COMMAND_RESTORE "Restore" 47 #define SKJSONCANVAS_COMMAND_RESTORE "Restore"
48 #define SKJSONCANVAS_COMMAND_SAVELAYER "SaveLayer"
48 49
49 #define SKJSONCANVAS_ATTRIBUTE_MATRIX "matrix" 50 #define SKJSONCANVAS_ATTRIBUTE_MATRIX "matrix"
50 #define SKJSONCANVAS_ATTRIBUTE_COORDS "coords" 51 #define SKJSONCANVAS_ATTRIBUTE_COORDS "coords"
52 #define SKJSONCANVAS_ATTRIBUTE_BOUNDS "bounds"
51 #define SKJSONCANVAS_ATTRIBUTE_PAINT "paint" 53 #define SKJSONCANVAS_ATTRIBUTE_PAINT "paint"
52 #define SKJSONCANVAS_ATTRIBUTE_OUTER "outer" 54 #define SKJSONCANVAS_ATTRIBUTE_OUTER "outer"
53 #define SKJSONCANVAS_ATTRIBUTE_INNER "inner" 55 #define SKJSONCANVAS_ATTRIBUTE_INNER "inner"
54 #define SKJSONCANVAS_ATTRIBUTE_MODE "mode" 56 #define SKJSONCANVAS_ATTRIBUTE_MODE "mode"
55 #define SKJSONCANVAS_ATTRIBUTE_POINTS "points" 57 #define SKJSONCANVAS_ATTRIBUTE_POINTS "points"
56 #define SKJSONCANVAS_ATTRIBUTE_PATH "path" 58 #define SKJSONCANVAS_ATTRIBUTE_PATH "path"
57 #define SKJSONCANVAS_ATTRIBUTE_TEXT "text" 59 #define SKJSONCANVAS_ATTRIBUTE_TEXT "text"
58 #define SKJSONCANVAS_ATTRIBUTE_COLOR "color" 60 #define SKJSONCANVAS_ATTRIBUTE_COLOR "color"
59 #define SKJSONCANVAS_ATTRIBUTE_STYLE "style" 61 #define SKJSONCANVAS_ATTRIBUTE_STYLE "style"
60 #define SKJSONCANVAS_ATTRIBUTE_STROKEWIDTH "strokeWidth" 62 #define SKJSONCANVAS_ATTRIBUTE_STROKEWIDTH "strokeWidth"
63 #define SKJSONCANVAS_ATTRIBUTE_STROKEMITER "strokeMiter"
64 #define SKJSONCANVAS_ATTRIBUTE_CAP "cap"
61 #define SKJSONCANVAS_ATTRIBUTE_ANTIALIAS "antiAlias" 65 #define SKJSONCANVAS_ATTRIBUTE_ANTIALIAS "antiAlias"
62 #define SKJSONCANVAS_ATTRIBUTE_REGION "region" 66 #define SKJSONCANVAS_ATTRIBUTE_REGION "region"
63 #define SKJSONCANVAS_ATTRIBUTE_REGIONOP "op" 67 #define SKJSONCANVAS_ATTRIBUTE_REGIONOP "op"
64 #define SKJSONCANVAS_ATTRIBUTE_EDGESTYLE "edgeStyle" 68 #define SKJSONCANVAS_ATTRIBUTE_EDGESTYLE "edgeStyle"
65 #define SKJSONCANVAS_ATTRIBUTE_DEVICEREGION "deviceRegion" 69 #define SKJSONCANVAS_ATTRIBUTE_DEVICEREGION "deviceRegion"
66 #define SKJSONCANVAS_ATTRIBUTE_BLUR "blur" 70 #define SKJSONCANVAS_ATTRIBUTE_BLUR "blur"
67 #define SKJSONCANVAS_ATTRIBUTE_SIGMA "sigma" 71 #define SKJSONCANVAS_ATTRIBUTE_SIGMA "sigma"
68 #define SKJSONCANVAS_ATTRIBUTE_QUALITY "quality" 72 #define SKJSONCANVAS_ATTRIBUTE_QUALITY "quality"
69 #define SKJSONCANVAS_ATTRIBUTE_TEXTALIGN "textAlign" 73 #define SKJSONCANVAS_ATTRIBUTE_TEXTALIGN "textAlign"
70 #define SKJSONCANVAS_ATTRIBUTE_TEXTSIZE "textSize" 74 #define SKJSONCANVAS_ATTRIBUTE_TEXTSIZE "textSize"
71 #define SKJSONCANVAS_ATTRIBUTE_TEXTSCALEX "textScaleX" 75 #define SKJSONCANVAS_ATTRIBUTE_TEXTSCALEX "textScaleX"
72 #define SKJSONCANVAS_ATTRIBUTE_TEXTSKEWX "textSkewX" 76 #define SKJSONCANVAS_ATTRIBUTE_TEXTSKEWX "textSkewX"
73 #define SKJSONCANVAS_ATTRIBUTE_DASHING "dashing" 77 #define SKJSONCANVAS_ATTRIBUTE_DASHING "dashing"
74 #define SKJSONCANVAS_ATTRIBUTE_INTERVALS "intervals" 78 #define SKJSONCANVAS_ATTRIBUTE_INTERVALS "intervals"
75 #define SKJSONCANVAS_ATTRIBUTE_PHASE "phase" 79 #define SKJSONCANVAS_ATTRIBUTE_PHASE "phase"
76 #define SKJSONCANVAS_ATTRIBUTE_FILLTYPE "fillType" 80 #define SKJSONCANVAS_ATTRIBUTE_FILLTYPE "fillType"
77 #define SKJSONCANVAS_ATTRIBUTE_VERBS "verbs" 81 #define SKJSONCANVAS_ATTRIBUTE_VERBS "verbs"
82 #define SKJSONCANVAS_ATTRIBUTE_NAME "name"
83 #define SKJSONCANVAS_ATTRIBUTE_BYTES "bytes"
84 #define SKJSONCANVAS_ATTRIBUTE_SHADER "shader"
85 #define SKJSONCANVAS_ATTRIBUTE_PATHEFFECT "pathEffect"
86 #define SKJSONCANVAS_ATTRIBUTE_MASKFILTER "maskFilter"
87 #define SKJSONCANVAS_ATTRIBUTE_XFERMODE "xfermode"
88 #define SKJSONCANVAS_ATTRIBUTE_BACKDROP "backdrop"
89 #define SKJSONCANVAS_ATTRIBUTE_IMAGE "image"
90 #define SKJSONCANVAS_ATTRIBUTE_BITMAP "bitmap"
91 #define SKJSONCANVAS_ATTRIBUTE_SRC "src"
92 #define SKJSONCANVAS_ATTRIBUTE_DST "dst"
93 #define SKJSONCANVAS_ATTRIBUTE_STRICT "strict"
94 #define SKJSONCANVAS_ATTRIBUTE_DESCRIPTION "description"
78 95
79 #define SKJSONCANVAS_VERB_MOVE "move" 96 #define SKJSONCANVAS_VERB_MOVE "move"
80 #define SKJSONCANVAS_VERB_LINE "line" 97 #define SKJSONCANVAS_VERB_LINE "line"
81 #define SKJSONCANVAS_VERB_QUAD "quad" 98 #define SKJSONCANVAS_VERB_QUAD "quad"
82 #define SKJSONCANVAS_VERB_CUBIC "cubic" 99 #define SKJSONCANVAS_VERB_CUBIC "cubic"
83 #define SKJSONCANVAS_VERB_CONIC "conic" 100 #define SKJSONCANVAS_VERB_CONIC "conic"
84 #define SKJSONCANVAS_VERB_CLOSE "close" 101 #define SKJSONCANVAS_VERB_CLOSE "close"
85 102
86 #define SKJSONCANVAS_STYLE_FILL "fill" 103 #define SKJSONCANVAS_STYLE_FILL "fill"
87 #define SKJSONCANVAS_STYLE_STROKE "stroke" 104 #define SKJSONCANVAS_STYLE_STROKE "stroke"
(...skipping 20 matching lines...) Expand all
108 125
109 #define SKJSONCANVAS_ALIGN_LEFT "left" 126 #define SKJSONCANVAS_ALIGN_LEFT "left"
110 #define SKJSONCANVAS_ALIGN_CENTER "center" 127 #define SKJSONCANVAS_ALIGN_CENTER "center"
111 #define SKJSONCANVAS_ALIGN_RIGHT "right" 128 #define SKJSONCANVAS_ALIGN_RIGHT "right"
112 129
113 #define SKJSONCANVAS_FILLTYPE_WINDING "winding" 130 #define SKJSONCANVAS_FILLTYPE_WINDING "winding"
114 #define SKJSONCANVAS_FILLTYPE_EVENODD "evenOdd" 131 #define SKJSONCANVAS_FILLTYPE_EVENODD "evenOdd"
115 #define SKJSONCANVAS_FILLTYPE_INVERSEWINDING "inverseWinding" 132 #define SKJSONCANVAS_FILLTYPE_INVERSEWINDING "inverseWinding"
116 #define SKJSONCANVAS_FILLTYPE_INVERSEEVENODD "inverseEvenOdd" 133 #define SKJSONCANVAS_FILLTYPE_INVERSEEVENODD "inverseEvenOdd"
117 134
135 #define SKJSONCANVAS_CAP_BUTT "butt"
136 #define SKJSONCANVAS_CAP_ROUND "round"
137 #define SKJSONCANVAS_CAP_SQUARE "square"
138
118 /* 139 /*
119 * Implementation of SkCanvas which writes JSON when drawn to. The JSON describe s all of the draw 140 * Implementation of SkCanvas which writes JSON when drawn to. The JSON describe s all of the draw
120 * commands issued to the canvas, and can later be turned back into draw command s using 141 * commands issued to the canvas, and can later be turned back into draw command s using
121 * SkJSONRenderer. Be sure to call finish() when you are done drawing. 142 * SkJSONRenderer. Be sure to call finish() when you are done drawing.
122 */ 143 */
123 class SkJSONCanvas : public SkCanvas { 144 class SkJSONCanvas : public SkCanvas {
124 public: 145 public:
125 /* Create a canvas which writes to the specified output stream. */ 146 /* Create a canvas which writes to the specified output stream. */
126 SkJSONCanvas(int width, int height, SkWStream& out); 147 SkJSONCanvas(int width, int height, SkWStream& out, bool sendBinaries = fals e);
127 148
128 /* Complete the JSON document. */ 149 /* Complete the JSON document. */
129 void finish(); 150 void finish();
130 151
131 // overridden SkCanvas API 152 // overridden SkCanvas API
132 153
133 void onDrawPaint(const SkPaint&) override; 154 void onDrawPaint(const SkPaint&) override;
134 155
135 void onDrawRect(const SkRect&, const SkPaint&) override; 156 void onDrawRect(const SkRect&, const SkPaint&) override;
136 157
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeSt yle) override; 216 void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeSt yle) override;
196 217
197 void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle ) override; 218 void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle ) override;
198 219
199 void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) override; 220 void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) override;
200 221
201 void willSave() override; 222 void willSave() override;
202 223
203 void willRestore() override; 224 void willRestore() override;
204 225
226 SkCanvas::SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec& rec) ov erride;
227
205 private: 228 private:
206 Json::Value makePoint(const SkPoint& point); 229 Json::Value makePoint(const SkPoint& point);
207 230
208 Json::Value makePoint(SkScalar x, SkScalar y); 231 Json::Value makePoint(SkScalar x, SkScalar y);
209 232
210 Json::Value makeRect(const SkRect& rect); 233 Json::Value makeRect(const SkRect& rect);
211 234
212 Json::Value makeRRect(const SkRRect& rrect); 235 Json::Value makeRRect(const SkRRect& rrect);
213 236
214 Json::Value makePath(const SkPath& path); 237 Json::Value makePath(const SkPath& path);
215 238
216 Json::Value makeRegion(const SkRegion& region); 239 Json::Value makeRegion(const SkRegion& region);
217 240
218 Json::Value makePaint(const SkPaint& paint); 241 Json::Value makePaint(const SkPaint& paint);
219 242
220 Json::Value makeRegionOp(SkRegion::Op op); 243 Json::Value makeRegionOp(SkRegion::Op op);
221 244
222 Json::Value makeEdgeStyle(SkCanvas::ClipEdgeStyle edgeStyle); 245 Json::Value makeEdgeStyle(SkCanvas::ClipEdgeStyle edgeStyle);
223 246
224 Json::Value makePointMode(SkCanvas::PointMode mode); 247 Json::Value makePointMode(SkCanvas::PointMode mode);
225 248
226 Json::Value makeMatrix(const SkMatrix& matrix); 249 Json::Value makeMatrix(const SkMatrix& matrix);
227 250
228 void updateMatrix(); 251 void updateMatrix();
229 252
230 SkWStream& fOut; 253 SkWStream& fOut;
231 SkMatrix fLastMatrix; 254 SkMatrix fLastMatrix;
232 Json::Value fRoot; 255 Json::Value fRoot;
233 Json::Value fCommands; 256 Json::Value fCommands;
257 bool fSendBinaries;
234 258
235 typedef SkCanvas INHERITED; 259 typedef SkCanvas INHERITED;
236 }; 260 };
237 261
238 #endif 262 #endif
OLDNEW
« no previous file with comments | « gyp/json.gyp ('k') | tools/json/SkJSONCanvas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698