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

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

Issue 1644903003: added support for more features in JSON (blurs, dashing, different path fill types, etc.) (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 | « tools/json/SkJSONCanvas.h ('k') | tools/json/SkJSONRenderer.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 #include "SkJSONCanvas.h" 8 #include "SkJSONCanvas.h"
9 #include "SkMaskFilter.h"
10 #include "SkPaintDefaults.h"
9 #include "SkPath.h" 11 #include "SkPath.h"
12 #include "SkPathEffect.h"
10 #include "SkRRect.h" 13 #include "SkRRect.h"
11 14
12 SkJSONCanvas::SkJSONCanvas(int width, int height, SkWStream& out) 15 SkJSONCanvas::SkJSONCanvas(int width, int height, SkWStream& out)
13 : INHERITED(width, height) 16 : INHERITED(width, height)
14 , fOut(out) 17 , fOut(out)
15 , fRoot(Json::objectValue) 18 , fRoot(Json::objectValue)
16 , fCommands(Json::arrayValue) { 19 , fCommands(Json::arrayValue) {
17 fRoot[SKJSONCANVAS_VERSION] = Json::Value(1); 20 fRoot[SKJSONCANVAS_VERSION] = Json::Value(1);
18 } 21 }
19 22
(...skipping 23 matching lines...) Expand all
43 result.append(Json::Value(rect.right())); 46 result.append(Json::Value(rect.right()));
44 result.append(Json::Value(rect.bottom())); 47 result.append(Json::Value(rect.bottom()));
45 return result; 48 return result;
46 } 49 }
47 50
48 Json::Value SkJSONCanvas::makeRRect(const SkRRect& rrect) { 51 Json::Value SkJSONCanvas::makeRRect(const SkRRect& rrect) {
49 Json::Value result(Json::arrayValue); 52 Json::Value result(Json::arrayValue);
50 result.append(this->makeRect(rrect.rect())); 53 result.append(this->makeRect(rrect.rect()));
51 result.append(this->makePoint(rrect.radii(SkRRect::kUpperLeft_Corner))); 54 result.append(this->makePoint(rrect.radii(SkRRect::kUpperLeft_Corner)));
52 result.append(this->makePoint(rrect.radii(SkRRect::kUpperRight_Corner))); 55 result.append(this->makePoint(rrect.radii(SkRRect::kUpperRight_Corner)));
56 result.append(this->makePoint(rrect.radii(SkRRect::kLowerRight_Corner)));
53 result.append(this->makePoint(rrect.radii(SkRRect::kLowerLeft_Corner))); 57 result.append(this->makePoint(rrect.radii(SkRRect::kLowerLeft_Corner)));
54 result.append(this->makePoint(rrect.radii(SkRRect::kLowerRight_Corner)));
55 return result; 58 return result;
56 } 59 }
57 60
58 Json::Value SkJSONCanvas::makePath(const SkPath& path) { 61 Json::Value SkJSONCanvas::makePath(const SkPath& path) {
59 Json::Value result(Json::arrayValue); 62 Json::Value result(Json::objectValue);
63 switch (path.getFillType()) {
64 case SkPath::kWinding_FillType:
65 result[SKJSONCANVAS_ATTRIBUTE_FILLTYPE] = SKJSONCANVAS_FILLTYPE_WIND ING;
66 break;
67 case SkPath::kEvenOdd_FillType:
68 result[SKJSONCANVAS_ATTRIBUTE_FILLTYPE] = SKJSONCANVAS_FILLTYPE_EVEN ODD;
69 break;
70 case SkPath::kInverseWinding_FillType:
71 result[SKJSONCANVAS_ATTRIBUTE_FILLTYPE] = SKJSONCANVAS_FILLTYPE_INVE RSEWINDING;
72 break;
73 case SkPath::kInverseEvenOdd_FillType:
74 result[SKJSONCANVAS_ATTRIBUTE_FILLTYPE] = SKJSONCANVAS_FILLTYPE_INVE RSEEVENODD;
75 break;
76 }
77 Json::Value verbs(Json::arrayValue);
60 SkPath::Iter iter(path, false); 78 SkPath::Iter iter(path, false);
61 SkPoint pts[4]; 79 SkPoint pts[4];
62 SkPath::Verb verb; 80 SkPath::Verb verb;
63 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { 81 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
64 switch (verb) { 82 switch (verb) {
65 case SkPath::kLine_Verb: { 83 case SkPath::kLine_Verb: {
66 Json::Value line(Json::objectValue); 84 Json::Value line(Json::objectValue);
67 line[SKJSONCANVAS_VERB_LINE] = this->makePoint(pts[1]); 85 line[SKJSONCANVAS_VERB_LINE] = this->makePoint(pts[1]);
68 result.append(line); 86 verbs.append(line);
69 break; 87 break;
70 } 88 }
71 case SkPath::kQuad_Verb: { 89 case SkPath::kQuad_Verb: {
72 Json::Value quad(Json::objectValue); 90 Json::Value quad(Json::objectValue);
73 Json::Value coords(Json::arrayValue); 91 Json::Value coords(Json::arrayValue);
74 coords.append(this->makePoint(pts[1])); 92 coords.append(this->makePoint(pts[1]));
75 coords.append(this->makePoint(pts[2])); 93 coords.append(this->makePoint(pts[2]));
76 quad[SKJSONCANVAS_VERB_QUAD] = coords; 94 quad[SKJSONCANVAS_VERB_QUAD] = coords;
77 result.append(quad); 95 verbs.append(quad);
78 break; 96 break;
79 } 97 }
80 case SkPath::kCubic_Verb: { 98 case SkPath::kCubic_Verb: {
81 Json::Value cubic(Json::objectValue); 99 Json::Value cubic(Json::objectValue);
82 Json::Value coords(Json::arrayValue); 100 Json::Value coords(Json::arrayValue);
83 coords.append(this->makePoint(pts[1])); 101 coords.append(this->makePoint(pts[1]));
84 coords.append(this->makePoint(pts[2])); 102 coords.append(this->makePoint(pts[2]));
85 coords.append(this->makePoint(pts[3])); 103 coords.append(this->makePoint(pts[3]));
86 cubic[SKJSONCANVAS_VERB_CUBIC] = coords; 104 cubic[SKJSONCANVAS_VERB_CUBIC] = coords;
87 result.append(cubic); 105 verbs.append(cubic);
88 break; 106 break;
89 } 107 }
90 case SkPath::kConic_Verb: { 108 case SkPath::kConic_Verb: {
91 Json::Value conic(Json::objectValue); 109 Json::Value conic(Json::objectValue);
92 Json::Value coords(Json::arrayValue); 110 Json::Value coords(Json::arrayValue);
93 coords.append(this->makePoint(pts[1])); 111 coords.append(this->makePoint(pts[1]));
94 coords.append(this->makePoint(pts[2])); 112 coords.append(this->makePoint(pts[2]));
95 coords.append(Json::Value(iter.conicWeight())); 113 coords.append(Json::Value(iter.conicWeight()));
96 conic[SKJSONCANVAS_VERB_CONIC] = coords; 114 conic[SKJSONCANVAS_VERB_CONIC] = coords;
97 result.append(conic); 115 verbs.append(conic);
98 break; 116 break;
99 } 117 }
100 case SkPath::kMove_Verb: { 118 case SkPath::kMove_Verb: {
101 Json::Value move(Json::objectValue); 119 Json::Value move(Json::objectValue);
102 move[SKJSONCANVAS_VERB_MOVE] = this->makePoint(pts[0]); 120 move[SKJSONCANVAS_VERB_MOVE] = this->makePoint(pts[0]);
103 result.append(move); 121 verbs.append(move);
104 break; 122 break;
105 } 123 }
106 case SkPath::kClose_Verb: 124 case SkPath::kClose_Verb:
107 result.append(Json::Value(SKJSONCANVAS_VERB_CLOSE)); 125 verbs.append(Json::Value(SKJSONCANVAS_VERB_CLOSE));
108 break; 126 break;
109 case SkPath::kDone_Verb: 127 case SkPath::kDone_Verb:
110 break; 128 break;
111 } 129 }
112 } 130 }
131 result[SKJSONCANVAS_ATTRIBUTE_VERBS] = verbs;
113 return result; 132 return result;
114 } 133 }
115 134
116 Json::Value SkJSONCanvas::makeRegion(const SkRegion& region) { 135 Json::Value SkJSONCanvas::makeRegion(const SkRegion& region) {
117 return Json::Value("<unimplemented>"); 136 return Json::Value("<unimplemented>");
118 } 137 }
119 138
139 void store_scalar(Json::Value* target, const char* key, SkScalar value, SkScalar defaultValue) {
140 if (value != defaultValue) {
141 (*target)[key] = Json::Value(value);
142 }
143 }
144
145 void store_bool(Json::Value* target, const char* key, bool value, bool defaultVa lue) {
146 if (value != defaultValue) {
147 (*target)[key] = Json::Value(value);
148 }
149 }
150
120 Json::Value SkJSONCanvas::makePaint(const SkPaint& paint) { 151 Json::Value SkJSONCanvas::makePaint(const SkPaint& paint) {
121 Json::Value result(Json::objectValue); 152 Json::Value result(Json::objectValue);
122 SkColor color = paint.getColor(); 153 SkColor color = paint.getColor();
123 if (color != SK_ColorBLACK) { 154 if (color != SK_ColorBLACK) {
124 Json::Value colorValue(Json::arrayValue); 155 Json::Value colorValue(Json::arrayValue);
125 colorValue.append(Json::Value(SkColorGetA(color))); 156 colorValue.append(Json::Value(SkColorGetA(color)));
126 colorValue.append(Json::Value(SkColorGetR(color))); 157 colorValue.append(Json::Value(SkColorGetR(color)));
127 colorValue.append(Json::Value(SkColorGetG(color))); 158 colorValue.append(Json::Value(SkColorGetG(color)));
128 colorValue.append(Json::Value(SkColorGetB(color))); 159 colorValue.append(Json::Value(SkColorGetB(color)));
129 result[SKJSONCANVAS_ATTRIBUTE_COLOR] = colorValue;; 160 result[SKJSONCANVAS_ATTRIBUTE_COLOR] = colorValue;;
130 } 161 }
131 SkPaint::Style style = paint.getStyle(); 162 SkPaint::Style style = paint.getStyle();
132 if (style != SkPaint::kFill_Style) { 163 if (style != SkPaint::kFill_Style) {
133 switch (style) { 164 switch (style) {
134 case SkPaint::kStroke_Style: { 165 case SkPaint::kStroke_Style: {
135 Json::Value stroke(SKJSONCANVAS_STYLE_STROKE); 166 Json::Value stroke(SKJSONCANVAS_STYLE_STROKE);
136 result[SKJSONCANVAS_ATTRIBUTE_STYLE] = stroke; 167 result[SKJSONCANVAS_ATTRIBUTE_STYLE] = stroke;
137 break; 168 break;
138 } 169 }
139 case SkPaint::kStrokeAndFill_Style: { 170 case SkPaint::kStrokeAndFill_Style: {
140 Json::Value strokeAndFill(SKJSONCANVAS_STYLE_STROKEANDFILL); 171 Json::Value strokeAndFill(SKJSONCANVAS_STYLE_STROKEANDFILL);
141 result[SKJSONCANVAS_ATTRIBUTE_STYLE] = strokeAndFill; 172 result[SKJSONCANVAS_ATTRIBUTE_STYLE] = strokeAndFill;
142 break; 173 break;
143 } 174 }
144 default: SkASSERT(false); 175 default: SkASSERT(false);
145 } 176 }
146 } 177 }
147 SkScalar strokeWidth = paint.getStrokeWidth(); 178 store_scalar(&result, SKJSONCANVAS_ATTRIBUTE_STROKEWIDTH, paint.getStrokeWid th(), 0.0f);
148 if (strokeWidth != 0.0f) { 179 store_bool(&result, SKJSONCANVAS_ATTRIBUTE_ANTIALIAS, paint.isAntiAlias(), f alse);
149 result[SKJSONCANVAS_ATTRIBUTE_STROKEWIDTH] = Json::Value(strokeWidth); 180 SkMaskFilter* maskFilter = paint.getMaskFilter();
181 if (maskFilter != nullptr) {
182 SkMaskFilter::BlurRec blurRec;
183 if (maskFilter->asABlur(&blurRec)) {
184 Json::Value blur(Json::objectValue);
185 blur[SKJSONCANVAS_ATTRIBUTE_SIGMA] = Json::Value(blurRec.fSigma);
186 switch (blurRec.fStyle) {
187 case SkBlurStyle::kNormal_SkBlurStyle:
188 blur[SKJSONCANVAS_ATTRIBUTE_STYLE] = Json::Value(SKJSONCANVA S_BLURSTYLE_NORMAL);
189 break;
190 case SkBlurStyle::kSolid_SkBlurStyle:
191 blur[SKJSONCANVAS_ATTRIBUTE_STYLE] = Json::Value(SKJSONCANVA S_BLURSTYLE_SOLID);
192 break;
193 case SkBlurStyle::kOuter_SkBlurStyle:
194 blur[SKJSONCANVAS_ATTRIBUTE_STYLE] = Json::Value(SKJSONCANVA S_BLURSTYLE_OUTER);
195 break;
196 case SkBlurStyle::kInner_SkBlurStyle:
197 blur[SKJSONCANVAS_ATTRIBUTE_STYLE] = Json::Value(SKJSONCANVA S_BLURSTYLE_INNER);
198 break;
199 default:
200 SkASSERT(false);
201 }
202 switch (blurRec.fQuality) {
203 case SkBlurQuality::kLow_SkBlurQuality:
204 blur[SKJSONCANVAS_ATTRIBUTE_QUALITY] = Json::Value(SKJSONCAN VAS_BLURQUALITY_LOW);
205 break;
206 case SkBlurQuality::kHigh_SkBlurQuality:
207 blur[SKJSONCANVAS_ATTRIBUTE_QUALITY] = Json::Value(SKJSONCAN VAS_BLURQUALITY_HIGH);
208 break;
209 default:
210 SkASSERT(false);
211 }
212 result[SKJSONCANVAS_ATTRIBUTE_BLUR] = blur;
213 }
214 else {
215 SkDebugf("unimplemented: non-blur maskfilter");
216 SkASSERT(false);
217 }
150 } 218 }
151 if (paint.isAntiAlias()) { 219 SkPathEffect* pathEffect = paint.getPathEffect();
152 result[SKJSONCANVAS_ATTRIBUTE_ANTIALIAS] = Json::Value(true); 220 if (pathEffect != nullptr) {
221 SkPathEffect::DashInfo dashInfo;
222 SkPathEffect::DashType dashType = pathEffect->asADash(&dashInfo);
223 if (dashType == SkPathEffect::kDash_DashType) {
224 dashInfo.fIntervals = (SkScalar*) sk_malloc_throw(dashInfo.fCount * sizeof(SkScalar));
225 pathEffect->asADash(&dashInfo);
226 Json::Value dashing(Json::objectValue);
227 Json::Value intervals(Json::arrayValue);
228 for (int32_t i = 0; i < dashInfo.fCount; i++) {
229 intervals.append(Json::Value(dashInfo.fIntervals[i]));
230 }
231 free(dashInfo.fIntervals);
232 dashing[SKJSONCANVAS_ATTRIBUTE_INTERVALS] = intervals;
233 dashing[SKJSONCANVAS_ATTRIBUTE_PHASE] = dashInfo.fPhase;
234 result[SKJSONCANVAS_ATTRIBUTE_DASHING] = dashing;
235 }
236 else {
237 SkDebugf("unimplemented: non-dash patheffect");
238 SkASSERT(false);
239 }
240 }
241 store_scalar(&result, SKJSONCANVAS_ATTRIBUTE_TEXTSIZE, paint.getTextSize(),
242 SkPaintDefaults_TextSize);
243 store_scalar(&result, SKJSONCANVAS_ATTRIBUTE_TEXTSCALEX, paint.getTextScaleX (), SK_Scalar1);
244 store_scalar(&result, SKJSONCANVAS_ATTRIBUTE_TEXTSCALEX, paint.getTextSkewX( ), 0.0f);
245 SkPaint::Align textAlign = paint.getTextAlign();
246 if (textAlign != SkPaint::kLeft_Align) {
247 switch (textAlign) {
248 case SkPaint::kCenter_Align: {
249 result[SKJSONCANVAS_ATTRIBUTE_TEXTALIGN] = SKJSONCANVAS_ALIGN_CE NTER;
250 break;
251 }
252 case SkPaint::kRight_Align: {
253 result[SKJSONCANVAS_ATTRIBUTE_TEXTALIGN] = SKJSONCANVAS_ALIGN_RI GHT;
254 break;
255 }
256 default: SkASSERT(false);
257 }
153 } 258 }
154 return result; 259 return result;
155 } 260 }
156 261
157 Json::Value SkJSONCanvas::makeMatrix(const SkMatrix& matrix) { 262 Json::Value SkJSONCanvas::makeMatrix(const SkMatrix& matrix) {
158 Json::Value result(Json::arrayValue); 263 Json::Value result(Json::arrayValue);
159 Json::Value row1(Json::arrayValue); 264 Json::Value row1(Json::arrayValue);
160 row1.append(Json::Value(matrix[0])); 265 row1.append(Json::Value(matrix[0]));
161 row1.append(Json::Value(matrix[1])); 266 row1.append(Json::Value(matrix[1]));
162 row1.append(Json::Value(matrix[2])); 267 row1.append(Json::Value(matrix[2]));
(...skipping 24 matching lines...) Expand all
187 case SkRegion::kReverseDifference_Op: 292 case SkRegion::kReverseDifference_Op:
188 return Json::Value(SKJSONCANVAS_REGIONOP_REVERSE_DIFFERENCE); 293 return Json::Value(SKJSONCANVAS_REGIONOP_REVERSE_DIFFERENCE);
189 case SkRegion::kReplace_Op: 294 case SkRegion::kReplace_Op:
190 return Json::Value(SKJSONCANVAS_REGIONOP_REPLACE); 295 return Json::Value(SKJSONCANVAS_REGIONOP_REPLACE);
191 default: 296 default:
192 SkASSERT(false); 297 SkASSERT(false);
193 return Json::Value("<invalid region op>"); 298 return Json::Value("<invalid region op>");
194 }; 299 };
195 } 300 }
196 301
197 Json::Value SkJSONCanvas::makeEdgeStyle(SkCanvas::ClipEdgeStyle edgeStyle) {
198 switch (edgeStyle) {
199 case SkCanvas::kHard_ClipEdgeStyle:
200 return Json::Value(SKJSONCANVAS_EDGESTYLE_HARD);
201 case SkCanvas::kSoft_ClipEdgeStyle:
202 return Json::Value(SKJSONCANVAS_EDGESTYLE_SOFT);
203 default:
204 SkASSERT(false);
205 return Json::Value("<invalid edge style>");
206 };
207 }
208
209 Json::Value SkJSONCanvas::makePointMode(SkCanvas::PointMode mode) { 302 Json::Value SkJSONCanvas::makePointMode(SkCanvas::PointMode mode) {
210 switch (mode) { 303 switch (mode) {
211 case SkCanvas::kPoints_PointMode: 304 case SkCanvas::kPoints_PointMode:
212 return Json::Value(SKJSONCANVAS_POINTMODE_POINTS); 305 return Json::Value(SKJSONCANVAS_POINTMODE_POINTS);
213 case SkCanvas::kLines_PointMode: 306 case SkCanvas::kLines_PointMode:
214 return Json::Value(SKJSONCANVAS_POINTMODE_LINES); 307 return Json::Value(SKJSONCANVAS_POINTMODE_LINES);
215 case SkCanvas::kPolygon_PointMode: 308 case SkCanvas::kPolygon_PointMode:
216 return Json::Value(SKJSONCANVAS_POINTMODE_POLYGON); 309 return Json::Value(SKJSONCANVAS_POINTMODE_POLYGON);
217 default: 310 default:
218 SkASSERT(false); 311 SkASSERT(false);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_TEXT); 438 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_TEXT);
346 command[SKJSONCANVAS_ATTRIBUTE_TEXT] = Json::Value((const char*) text, 439 command[SKJSONCANVAS_ATTRIBUTE_TEXT] = Json::Value((const char*) text,
347 ((const char*) text) + by teLength); 440 ((const char*) text) + by teLength);
348 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makePoint(x, y); 441 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makePoint(x, y);
349 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); 442 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint);
350 fCommands.append(command); 443 fCommands.append(command);
351 } 444 }
352 445
353 void SkJSONCanvas::onDrawPosText(const void* text, size_t byteLength, 446 void SkJSONCanvas::onDrawPosText(const void* text, size_t byteLength,
354 const SkPoint pos[], const SkPaint& paint) { 447 const SkPoint pos[], const SkPaint& paint) {
355 SkDebugf("unsupported: drawPosText\n"); 448 this->updateMatrix();
449 Json::Value command(Json::objectValue);
450 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_POSTEXT);
451 command[SKJSONCANVAS_ATTRIBUTE_TEXT] = Json::Value((const char*) text,
452 ((const char*) text) + by teLength);
453 Json::Value coords(Json::arrayValue);
454 for (size_t i = 0; i < byteLength; i++) {
455 coords.append(this->makePoint(pos[i]));
456 }
457 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = coords;
458 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint);
459 fCommands.append(command);
356 } 460 }
357 461
358 void SkJSONCanvas::onDrawPosTextH(const void* text, size_t byteLength, 462 void SkJSONCanvas::onDrawPosTextH(const void* text, size_t byteLength,
359 const SkScalar xpos[], SkScalar constY, 463 const SkScalar xpos[], SkScalar constY,
360 const SkPaint& paint) { 464 const SkPaint& paint) {
361 SkDebugf("unsupported: drawPosTextH\n"); 465 SkDebugf("unsupported: drawPosTextH\n");
362 } 466 }
363 467
364 void SkJSONCanvas::onDrawTextOnPath(const void* text, size_t byteLength, 468 void SkJSONCanvas::onDrawTextOnPath(const void* text, size_t byteLength,
365 const SkPath& path, const SkMatrix* matrix, 469 const SkPath& path, const SkMatrix* matrix,
(...skipping 15 matching lines...) Expand all
381 void SkJSONCanvas::onDrawDrawable(SkDrawable*, const SkMatrix*) { 485 void SkJSONCanvas::onDrawDrawable(SkDrawable*, const SkMatrix*) {
382 SkDebugf("unsupported: drawDrawable\n"); 486 SkDebugf("unsupported: drawDrawable\n");
383 } 487 }
384 488
385 void SkJSONCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) { 489 void SkJSONCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
386 this->updateMatrix(); 490 this->updateMatrix();
387 Json::Value command(Json::objectValue); 491 Json::Value command(Json::objectValue);
388 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPRECT); 492 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPRECT);
389 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRect(rect); 493 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRect(rect);
390 command[SKJSONCANVAS_ATTRIBUTE_REGIONOP] = this->makeRegionOp(op); 494 command[SKJSONCANVAS_ATTRIBUTE_REGIONOP] = this->makeRegionOp(op);
391 command[SKJSONCANVAS_ATTRIBUTE_EDGESTYLE] = this->makeEdgeStyle(edgeStyle); 495 command[SKJSONCANVAS_ATTRIBUTE_ANTIALIAS] = (edgeStyle == SkCanvas::kSoft_Cl ipEdgeStyle);
392 fCommands.append(command); 496 fCommands.append(command);
393 } 497 }
394 498
395 void SkJSONCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeSt yle edgeStyle) { 499 void SkJSONCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeSt yle edgeStyle) {
396 this->updateMatrix(); 500 this->updateMatrix();
397 Json::Value command(Json::objectValue); 501 Json::Value command(Json::objectValue);
398 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPRRECT); 502 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPRRECT);
399 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRRect(rrect); 503 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRRect(rrect);
400 command[SKJSONCANVAS_ATTRIBUTE_REGIONOP] = this->makeRegionOp(op); 504 command[SKJSONCANVAS_ATTRIBUTE_REGIONOP] = this->makeRegionOp(op);
401 command[SKJSONCANVAS_ATTRIBUTE_EDGESTYLE] = this->makeEdgeStyle(edgeStyle); 505 command[SKJSONCANVAS_ATTRIBUTE_ANTIALIAS] = (edgeStyle == SkCanvas::kSoft_Cl ipEdgeStyle);
402 fCommands.append(command); 506 fCommands.append(command);
403 } 507 }
404 508
405 void SkJSONCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) { 509 void SkJSONCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
406 this->updateMatrix(); 510 this->updateMatrix();
407 Json::Value command(Json::objectValue); 511 Json::Value command(Json::objectValue);
408 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPPATH); 512 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPPATH);
409 command[SKJSONCANVAS_ATTRIBUTE_PATH] = this->makePath(path); 513 command[SKJSONCANVAS_ATTRIBUTE_PATH] = this->makePath(path);
410 command[SKJSONCANVAS_ATTRIBUTE_REGIONOP] = this->makeRegionOp(op); 514 command[SKJSONCANVAS_ATTRIBUTE_REGIONOP] = this->makeRegionOp(op);
411 command[SKJSONCANVAS_ATTRIBUTE_EDGESTYLE] = this->makeEdgeStyle(edgeStyle); 515 command[SKJSONCANVAS_ATTRIBUTE_ANTIALIAS] = (edgeStyle == SkCanvas::kSoft_Cl ipEdgeStyle);
412 fCommands.append(command); 516 fCommands.append(command);
413 } 517 }
414 518
415 void SkJSONCanvas::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) { 519 void SkJSONCanvas::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
416 this->updateMatrix(); 520 this->updateMatrix();
417 Json::Value command(Json::objectValue); 521 Json::Value command(Json::objectValue);
418 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPREGION) ; 522 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPREGION) ;
419 command[SKJSONCANVAS_ATTRIBUTE_REGION] = this->makeRegion(deviceRgn); 523 command[SKJSONCANVAS_ATTRIBUTE_REGION] = this->makeRegion(deviceRgn);
420 command[SKJSONCANVAS_ATTRIBUTE_REGIONOP] = this->makeRegionOp(op); 524 command[SKJSONCANVAS_ATTRIBUTE_REGIONOP] = this->makeRegionOp(op);
421 fCommands.append(command); 525 fCommands.append(command);
422 } 526 }
423 527
424 void SkJSONCanvas::willSave() { 528 void SkJSONCanvas::willSave() {
529 this->updateMatrix();
425 Json::Value command(Json::objectValue); 530 Json::Value command(Json::objectValue);
426 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_SAVE); 531 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_SAVE);
427 fCommands.append(command); 532 fCommands.append(command);
428 } 533 }
429 534
430 void SkJSONCanvas::willRestore() { 535 void SkJSONCanvas::willRestore() {
431 Json::Value command(Json::objectValue); 536 Json::Value command(Json::objectValue);
432 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_RESTORE); 537 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_RESTORE);
433 fCommands.append(command); 538 fCommands.append(command);
434 } 539 }
OLDNEW
« no previous file with comments | « tools/json/SkJSONCanvas.h ('k') | tools/json/SkJSONRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698