| OLD | NEW |
| 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 "SkPath.h" | 9 #include "SkPath.h" |
| 10 #include "SkRRect.h" | 10 #include "SkRRect.h" |
| 11 #include "stdio.h" | |
| 12 #include "stdlib.h" | |
| 13 | 11 |
| 14 SkJSONCanvas::SkJSONCanvas(int width, int height, SkWStream& out) | 12 SkJSONCanvas::SkJSONCanvas(int width, int height, SkWStream& out) |
| 15 » : INHERITED(width, height) | 13 : INHERITED(width, height) |
| 16 » , fOut(out) | 14 , fOut(out) |
| 17 » , fFirstCommand(true) { | 15 , fRoot(Json::objectValue) |
| 18 » fOut.writeText("{\"" SKJSONCANVAS_VERSION "\":1, \"" SKJSONCANVAS_COMMAN
DS | 16 , fCommands(Json::arrayValue) { |
| 19 "\":["); | 17 fRoot[SKJSONCANVAS_VERSION] = Json::Value(1); |
| 20 } | 18 } |
| 21 | 19 |
| 22 void SkJSONCanvas::finish() { | 20 void SkJSONCanvas::finish() { |
| 23 » fOut.writeText("]}"); | 21 fRoot[SKJSONCANVAS_COMMANDS] = fCommands; |
| 24 } | 22 fOut.writeText(Json::FastWriter().write(fRoot).c_str()); |
| 25 | 23 } |
| 26 void SkJSONCanvas::writef(const char* format, ...) { | 24 |
| 27 va_list args; | 25 Json::Value SkJSONCanvas::makePoint(const SkPoint& point) { |
| 28 va_start(args, format); | 26 Json::Value result(Json::arrayValue); |
| 29 SkString s; | 27 result.append(Json::Value(point.x())); |
| 30 s.appendVAList(format, args); | 28 result.append(Json::Value(point.y())); |
| 31 fOut.writeText(s.c_str()); | 29 return result; |
| 32 } | 30 } |
| 33 | 31 |
| 34 void SkJSONCanvas::open(const char* name) { | 32 Json::Value SkJSONCanvas::makePoint(SkScalar x, SkScalar y) { |
| 35 » if (fFirstCommand) { | 33 Json::Value result(Json::arrayValue); |
| 36 » » fFirstCommand = false; | 34 result.append(Json::Value(x)); |
| 37 » } | 35 result.append(Json::Value(y)); |
| 38 » else { | 36 return result; |
| 39 » » fOut.writeText(","); | 37 } |
| 40 » } | 38 |
| 41 » this->writef("{\"" SKJSONCANVAS_COMMAND "\":\"%s\"", name); | 39 Json::Value SkJSONCanvas::makeRect(const SkRect& rect) { |
| 42 } | 40 Json::Value result(Json::arrayValue); |
| 43 | 41 result.append(Json::Value(rect.left())); |
| 44 void SkJSONCanvas::close() { | 42 result.append(Json::Value(rect.top())); |
| 45 » fOut.writeText("}"); | 43 result.append(Json::Value(rect.right())); |
| 46 } | 44 result.append(Json::Value(rect.bottom())); |
| 47 | 45 return result; |
| 48 void SkJSONCanvas::writeString(const char* name, const char* text) { | 46 } |
| 49 this->writeString(name, text, strlen(text)); | 47 |
| 50 } | 48 Json::Value SkJSONCanvas::makeRRect(const SkRRect& rrect) { |
| 51 | 49 Json::Value result(Json::arrayValue); |
| 52 void SkJSONCanvas::writeString(const char* name, const void* text, size_t length
) { | 50 result.append(this->makeRect(rrect.rect())); |
| 53 » // TODO: escaping | 51 result.append(this->makePoint(rrect.radii(SkRRect::kUpperLeft_Corner))); |
| 54 » this->writef(",\"%s\":\"", name); | 52 result.append(this->makePoint(rrect.radii(SkRRect::kUpperRight_Corner))); |
| 55 » fOut.write(text, length); | 53 result.append(this->makePoint(rrect.radii(SkRRect::kLowerLeft_Corner))); |
| 56 » fOut.writeText("\""); | 54 result.append(this->makePoint(rrect.radii(SkRRect::kLowerRight_Corner))); |
| 57 } | 55 return result; |
| 58 | 56 } |
| 59 void SkJSONCanvas::writePoint(const char* name, const SkPoint& point) { | 57 |
| 60 » this->writef(",\"%s\":[%f, %f]", name, point.x(), point.y()); | 58 Json::Value SkJSONCanvas::makePath(const SkPath& path) { |
| 61 } | 59 Json::Value result(Json::arrayValue); |
| 62 | |
| 63 void SkJSONCanvas::writeRect(const char* name, const SkRect& rect) { | |
| 64 » this->writef(",\"%s\":[%f, %f, %f, %f]", name, rect.left(), rect.top(),
rect.right(), | |
| 65 » » » » rect.bottom()); | |
| 66 } | |
| 67 | |
| 68 void SkJSONCanvas::writeRRect(const char* name, const SkRRect& rrect) { | |
| 69 » SkRect rect = rrect.rect(); | |
| 70 » SkVector corner1 = rrect.radii(SkRRect::kUpperLeft_Corner); | |
| 71 » SkVector corner2 = rrect.radii(SkRRect::kUpperRight_Corner); | |
| 72 » SkVector corner3 = rrect.radii(SkRRect::kLowerLeft_Corner); | |
| 73 » SkVector corner4 = rrect.radii(SkRRect::kLowerRight_Corner); | |
| 74 » this->writef(",\"%s\":[[%f, %f, %f, %f],[%f, %f],[%f, %f],[%f, %f],[%f,
%f]]", name, | |
| 75 » » » » rect.left(), rect.top(), rect.right(), rect.bot
tom(), corner1.x(), corner1.y(), | |
| 76 » » » » corner2.x(), corner2.y(), corner3.x(), corner3.
y(), corner4.x(), corner4.y()); | |
| 77 } | |
| 78 | |
| 79 void SkJSONCanvas::writePath(const char* name, const SkPath& path) { | |
| 80 » SkString text("["); | |
| 81 SkPath::Iter iter(path, false); | 60 SkPath::Iter iter(path, false); |
| 82 SkPoint pts[4]; | 61 SkPoint pts[4]; |
| 83 bool first = true; | |
| 84 SkPath::Verb verb; | 62 SkPath::Verb verb; |
| 85 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { | 63 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { |
| 86 if (first) { | |
| 87 first = false; | |
| 88 } | |
| 89 else { | |
| 90 text.append(","); | |
| 91 } | |
| 92 switch (verb) { | 64 switch (verb) { |
| 93 case SkPath::kLine_Verb: | 65 case SkPath::kLine_Verb: { |
| 94 text.appendf("{\"" SKJSONCANVAS_VERB_LINE "\":[%f,%f]}", pts[1].
x(), pts[1].y()); | 66 Json::Value line(Json::objectValue); |
| 95 break; | 67 line[SKJSONCANVAS_VERB_LINE] = this->makePoint(pts[1]); |
| 96 case SkPath::kQuad_Verb: | 68 result.append(line); |
| 97 text.appendf("{\"" SKJSONCANVAS_VERB_QUAD "\":[[%f,%f],[%f,%f]]}
", pts[1].x(), | 69 break; |
| 98 pts[1].y(), pts[2].x(), pts[2].y()); | 70 } |
| 99 break; | 71 case SkPath::kQuad_Verb: { |
| 100 case SkPath::kCubic_Verb: | 72 Json::Value quad(Json::objectValue); |
| 101 text.appendf("{\"" SKJSONCANVAS_VERB_CUBIC "\":[[%f,%f],[%f,%f],
[%f,%f]]}", | 73 Json::Value coords(Json::arrayValue); |
| 102 pts[1].x(), pts[1].y(), pts[2].x(), pts[2].y(), pts
[3].x(), | 74 coords.append(this->makePoint(pts[1])); |
| 103 pts[3].y()); | 75 coords.append(this->makePoint(pts[2])); |
| 104 break; | 76 quad[SKJSONCANVAS_VERB_QUAD] = coords; |
| 105 case SkPath::kConic_Verb: | 77 result.append(quad); |
| 106 text.appendf("{\"" SKJSONCANVAS_VERB_CONIC "\":[[%f,%f],[%f,%f],
%f]}", pts[1].x(), | 78 break; |
| 107 pts[1].y(), pts[2].x(), pts[2].y(), iter.conicWeigh
t()); | 79 } |
| 108 break; | 80 case SkPath::kCubic_Verb: { |
| 109 case SkPath::kMove_Verb: | 81 Json::Value cubic(Json::objectValue); |
| 110 text.appendf("{\"" SKJSONCANVAS_VERB_MOVE "\":[%f,%f]}", pts[0].
x(), pts[0].y()); | 82 Json::Value coords(Json::arrayValue); |
| 111 break; | 83 coords.append(this->makePoint(pts[1])); |
| 84 coords.append(this->makePoint(pts[2])); |
| 85 coords.append(this->makePoint(pts[3])); |
| 86 cubic[SKJSONCANVAS_VERB_CUBIC] = coords; |
| 87 result.append(cubic); |
| 88 break; |
| 89 } |
| 90 case SkPath::kConic_Verb: { |
| 91 Json::Value conic(Json::objectValue); |
| 92 Json::Value coords(Json::arrayValue); |
| 93 coords.append(this->makePoint(pts[1])); |
| 94 coords.append(this->makePoint(pts[2])); |
| 95 coords.append(Json::Value(iter.conicWeight())); |
| 96 conic[SKJSONCANVAS_VERB_CONIC] = coords; |
| 97 result.append(conic); |
| 98 break; |
| 99 } |
| 100 case SkPath::kMove_Verb: { |
| 101 Json::Value move(Json::objectValue); |
| 102 move[SKJSONCANVAS_VERB_MOVE] = this->makePoint(pts[0]); |
| 103 result.append(move); |
| 104 break; |
| 105 } |
| 112 case SkPath::kClose_Verb: | 106 case SkPath::kClose_Verb: |
| 113 text.appendf("\"" SKJSONCANVAS_VERB_CLOSE "\""); | 107 result.append(Json::Value(SKJSONCANVAS_VERB_CLOSE)); |
| 114 break; | 108 break; |
| 115 case SkPath::kDone_Verb: | 109 case SkPath::kDone_Verb: |
| 116 break; | 110 break; |
| 117 } | 111 } |
| 118 } | 112 } |
| 119 text.appendf("]"); | 113 return result; |
| 120 » this->writef(",\"" SKJSONCANVAS_ATTRIBUTE_PATH "\":%s", text.c_str()); | 114 } |
| 121 } | 115 |
| 122 | 116 Json::Value SkJSONCanvas::makeRegion(const SkRegion& region) { |
| 123 void SkJSONCanvas::writeRegion(const char* name, const SkRegion& region) { | 117 return Json::Value("<unimplemented>"); |
| 124 » this->writef(",\"%s\":\"<unimplemented>\"", name); | 118 } |
| 125 } | 119 |
| 126 | 120 Json::Value SkJSONCanvas::makePaint(const SkPaint& paint) { |
| 127 void SkJSONCanvas::writePaint(const SkPaint& paint) { | 121 Json::Value result(Json::objectValue); |
| 128 » this->writef(",\"" SKJSONCANVAS_ATTRIBUTE_PAINT "\":{"); | 122 SkColor color = paint.getColor(); |
| 129 » SkColor color = paint.getColor(); | 123 if (color != SK_ColorBLACK) { |
| 130 » bool first = true; | 124 Json::Value colorValue(Json::arrayValue); |
| 131 » if (color != SK_ColorBLACK) { | 125 colorValue.append(Json::Value(SkColorGetA(color))); |
| 132 » » this->writef("\"" SKJSONCANVAS_ATTRIBUTE_COLOR "\":[%d,%d,%d,%d]
", SkColorGetA(color), | 126 colorValue.append(Json::Value(SkColorGetR(color))); |
| 133 SkColorGetR(color), SkColorGetG(color), SkColorGetB(color))
; | 127 colorValue.append(Json::Value(SkColorGetG(color))); |
| 134 » » first = false; | 128 colorValue.append(Json::Value(SkColorGetB(color))); |
| 135 » } | 129 result[SKJSONCANVAS_ATTRIBUTE_COLOR] = colorValue;; |
| 130 } |
| 136 SkPaint::Style style = paint.getStyle(); | 131 SkPaint::Style style = paint.getStyle(); |
| 137 if (style != SkPaint::kFill_Style) { | 132 if (style != SkPaint::kFill_Style) { |
| 138 if (first) { | |
| 139 first = false; | |
| 140 } | |
| 141 else { | |
| 142 fOut.writeText(","); | |
| 143 } | |
| 144 switch (style) { | 133 switch (style) { |
| 145 case SkPaint::kStroke_Style: | 134 case SkPaint::kStroke_Style: { |
| 146 fOut.writeText("\"" SKJSONCANVAS_ATTRIBUTE_STYLE "\":\"" | 135 Json::Value stroke(SKJSONCANVAS_STYLE_STROKE); |
| 147 SKJSONCANVAS_STYLE_STROKE "\""); | 136 result[SKJSONCANVAS_ATTRIBUTE_STYLE] = stroke; |
| 148 break; | 137 break; |
| 149 case SkPaint::kStrokeAndFill_Style: | 138 } |
| 150 fOut.writeText("\"" SKJSONCANVAS_ATTRIBUTE_STYLE "\":\"" | 139 case SkPaint::kStrokeAndFill_Style: { |
| 151 SKJSONCANVAS_STYLE_STROKEANDFILL "\""); | 140 Json::Value strokeAndFill(SKJSONCANVAS_STYLE_STROKEANDFILL); |
| 152 break; | 141 result[SKJSONCANVAS_ATTRIBUTE_STYLE] = strokeAndFill; |
| 142 break; |
| 143 } |
| 153 default: SkASSERT(false); | 144 default: SkASSERT(false); |
| 154 } | 145 } |
| 155 } | 146 } |
| 156 SkScalar strokeWidth = paint.getStrokeWidth(); | 147 SkScalar strokeWidth = paint.getStrokeWidth(); |
| 157 if (strokeWidth != 0.0f) { | 148 if (strokeWidth != 0.0f) { |
| 158 if (first) { | 149 result[SKJSONCANVAS_ATTRIBUTE_STROKEWIDTH] = Json::Value(strokeWidth); |
| 159 first = false; | |
| 160 } | |
| 161 else { | |
| 162 fOut.writeText(","); | |
| 163 } | |
| 164 this->writef("\"" SKJSONCANVAS_ATTRIBUTE_STROKEWIDTH "\":%f", strokeWidt
h); | |
| 165 } | 150 } |
| 166 if (paint.isAntiAlias()) { | 151 if (paint.isAntiAlias()) { |
| 167 if (first) { | 152 result[SKJSONCANVAS_ATTRIBUTE_ANTIALIAS] = Json::Value(true); |
| 168 first = false; | 153 } |
| 169 } | 154 return result; |
| 170 else { | 155 } |
| 171 fOut.writeText(","); | 156 |
| 172 } | 157 Json::Value SkJSONCanvas::makeMatrix(const SkMatrix& matrix) { |
| 173 fOut.writeText("\"" SKJSONCANVAS_ATTRIBUTE_ANTIALIAS "\":true"); | 158 Json::Value result(Json::arrayValue); |
| 174 } | 159 Json::Value row1(Json::arrayValue); |
| 175 » fOut.writeText("}"); | 160 row1.append(Json::Value(matrix[0])); |
| 176 } | 161 row1.append(Json::Value(matrix[1])); |
| 177 | 162 row1.append(Json::Value(matrix[2])); |
| 178 void SkJSONCanvas::writeMatrix(const char* name, const SkMatrix& matrix) { | 163 result.append(row1); |
| 179 » this->writef(",\"%s\":[[%f,%f,%f],[%f,%f,%f],[%f,%f,%f]]", name, | 164 Json::Value row2(Json::arrayValue); |
| 180 » » » » matrix[0], matrix[1], matrix[2], | 165 row2.append(Json::Value(matrix[3])); |
| 181 » » » » matrix[3], matrix[4], matrix[5], | 166 row2.append(Json::Value(matrix[4])); |
| 182 » » » » matrix[6], matrix[7], matrix[8]); | 167 row2.append(Json::Value(matrix[5])); |
| 183 } | 168 result.append(row2); |
| 184 | 169 Json::Value row3(Json::arrayValue); |
| 185 void SkJSONCanvas::writeRegionOp(const char* name, SkRegion::Op op) { | 170 row3.append(Json::Value(matrix[6])); |
| 186 » this->writef(",\"%s\":\"", name); | 171 row3.append(Json::Value(matrix[7])); |
| 187 » switch (op) { | 172 row3.append(Json::Value(matrix[8])); |
| 173 result.append(row3); |
| 174 return result; |
| 175 } |
| 176 |
| 177 Json::Value SkJSONCanvas::makeRegionOp(SkRegion::Op op) { |
| 178 switch (op) { |
| 188 case SkRegion::kDifference_Op: | 179 case SkRegion::kDifference_Op: |
| 189 fOut.writeText(SKJSONCANVAS_REGIONOP_DIFFERENCE); | 180 return Json::Value(SKJSONCANVAS_REGIONOP_DIFFERENCE); |
| 190 break; | |
| 191 case SkRegion::kIntersect_Op: | 181 case SkRegion::kIntersect_Op: |
| 192 fOut.writeText(SKJSONCANVAS_REGIONOP_INTERSECT); | 182 return Json::Value(SKJSONCANVAS_REGIONOP_INTERSECT); |
| 193 break; | |
| 194 case SkRegion::kUnion_Op: | 183 case SkRegion::kUnion_Op: |
| 195 fOut.writeText(SKJSONCANVAS_REGIONOP_UNION); | 184 return Json::Value(SKJSONCANVAS_REGIONOP_UNION); |
| 196 break; | |
| 197 case SkRegion::kXOR_Op: | 185 case SkRegion::kXOR_Op: |
| 198 fOut.writeText(SKJSONCANVAS_REGIONOP_XOR); | 186 return Json::Value(SKJSONCANVAS_REGIONOP_XOR); |
| 199 break; | |
| 200 case SkRegion::kReverseDifference_Op: | 187 case SkRegion::kReverseDifference_Op: |
| 201 fOut.writeText(SKJSONCANVAS_REGIONOP_REVERSE_DIFFERENCE); | 188 return Json::Value(SKJSONCANVAS_REGIONOP_REVERSE_DIFFERENCE); |
| 202 break; | |
| 203 case SkRegion::kReplace_Op: | 189 case SkRegion::kReplace_Op: |
| 204 fOut.writeText(SKJSONCANVAS_REGIONOP_REPLACE); | 190 return Json::Value(SKJSONCANVAS_REGIONOP_REPLACE); |
| 205 break; | |
| 206 default: | 191 default: |
| 207 SkASSERT(false); | 192 SkASSERT(false); |
| 193 return Json::Value("<invalid region op>"); |
| 208 }; | 194 }; |
| 209 fOut.writeText("\""); | 195 } |
| 210 } | 196 |
| 211 | 197 Json::Value SkJSONCanvas::makeEdgeStyle(SkCanvas::ClipEdgeStyle edgeStyle) { |
| 212 void SkJSONCanvas::writeEdgeStyle(const char* name, SkCanvas::ClipEdgeStyle edge
Style) { | 198 switch (edgeStyle) { |
| 213 » this->writef(",\"%s\":\"", name); | 199 case SkCanvas::kHard_ClipEdgeStyle: |
| 214 » switch (edgeStyle) { | 200 return Json::Value(SKJSONCANVAS_EDGESTYLE_HARD); |
| 215 case SkCanvas::kHard_ClipEdgeStyle: fOut.writeText(SKJSONCANVAS_EDGESTYL
E_HARD); break; | 201 case SkCanvas::kSoft_ClipEdgeStyle: |
| 216 case SkCanvas::kSoft_ClipEdgeStyle: fOut.writeText(SKJSONCANVAS_EDGESTYL
E_SOFT); break; | 202 return Json::Value(SKJSONCANVAS_EDGESTYLE_SOFT); |
| 217 default: SkASSERT(false); | 203 default: |
| 204 SkASSERT(false); |
| 205 return Json::Value("<invalid edge style>"); |
| 218 }; | 206 }; |
| 219 fOut.writeText("\""); | 207 } |
| 220 } | 208 |
| 221 | 209 Json::Value SkJSONCanvas::makePointMode(SkCanvas::PointMode mode) { |
| 222 void SkJSONCanvas::writePointMode(const char* name, SkCanvas::PointMode mode) { | |
| 223 this->writef(",\"%s\":\"", name); | |
| 224 switch (mode) { | 210 switch (mode) { |
| 225 case SkCanvas::kPoints_PointMode: fOut.writeText(SKJSONCANVAS_POINTMODE
_POINTS); break; | 211 case SkCanvas::kPoints_PointMode: |
| 226 case SkCanvas::kLines_PointMode: fOut.writeText(SKJSONCANVAS_POINTMODE
_LINES); break; | 212 return Json::Value(SKJSONCANVAS_POINTMODE_POINTS); |
| 227 case SkCanvas::kPolygon_PointMode: fOut.writeText(SKJSONCANVAS_POINTMODE
_POLYGON); break; | 213 case SkCanvas::kLines_PointMode: |
| 228 default: SkASSERT(false); | 214 return Json::Value(SKJSONCANVAS_POINTMODE_LINES); |
| 215 case SkCanvas::kPolygon_PointMode: |
| 216 return Json::Value(SKJSONCANVAS_POINTMODE_POLYGON); |
| 217 default: |
| 218 SkASSERT(false); |
| 219 return Json::Value("<invalid point mode>"); |
| 229 }; | 220 }; |
| 230 fOut.writeText("\""); | |
| 231 } | 221 } |
| 232 | 222 |
| 233 void SkJSONCanvas::updateMatrix() { | 223 void SkJSONCanvas::updateMatrix() { |
| 234 » const SkMatrix& matrix = this->getTotalMatrix(); | 224 const SkMatrix& matrix = this->getTotalMatrix(); |
| 235 » if (matrix != fLastMatrix) { | 225 if (matrix != fLastMatrix) { |
| 236 » » this->open(SKJSONCANVAS_COMMAND_MATRIX); | 226 Json::Value command(Json::objectValue); |
| 237 » » this->writeMatrix(SKJSONCANVAS_ATTRIBUTE_MATRIX, matrix); | 227 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_MATRIX)
; |
| 238 » » fLastMatrix = matrix; | 228 command[SKJSONCANVAS_ATTRIBUTE_MATRIX] = this->makeMatrix(matrix); |
| 239 » » this->close(); | 229 fCommands.append(command); |
| 240 » } | 230 fLastMatrix = matrix; |
| 231 } |
| 241 } | 232 } |
| 242 | 233 |
| 243 void SkJSONCanvas::onDrawPaint(const SkPaint& paint) { | 234 void SkJSONCanvas::onDrawPaint(const SkPaint& paint) { |
| 244 » this->open(SKJSONCANVAS_COMMAND_PAINT); | 235 Json::Value command(Json::objectValue); |
| 245 » this->writePaint(paint); | 236 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_PAINT); |
| 246 » this->close(); | 237 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); |
| 238 fCommands.append(command); |
| 247 } | 239 } |
| 248 | 240 |
| 249 void SkJSONCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) { | 241 void SkJSONCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) { |
| 250 » this->updateMatrix(); | 242 this->updateMatrix(); |
| 251 » this->open(SKJSONCANVAS_COMMAND_RECT); | 243 Json::Value command(Json::objectValue); |
| 252 » this->writeRect(SKJSONCANVAS_ATTRIBUTE_COORDS, rect); | 244 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_RECT); |
| 253 » this->writePaint(paint); | 245 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRect(rect); |
| 254 » this->close(); | 246 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); |
| 247 fCommands.append(command); |
| 255 } | 248 } |
| 256 | 249 |
| 257 void SkJSONCanvas::onDrawOval(const SkRect& rect, const SkPaint& paint) { | 250 void SkJSONCanvas::onDrawOval(const SkRect& rect, const SkPaint& paint) { |
| 258 » this->updateMatrix(); | 251 this->updateMatrix(); |
| 259 » this->open(SKJSONCANVAS_COMMAND_OVAL); | 252 Json::Value command(Json::objectValue); |
| 260 » this->writeRect(SKJSONCANVAS_ATTRIBUTE_COORDS, rect); | 253 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_OVAL); |
| 261 » this->writePaint(paint); | 254 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRect(rect); |
| 262 » this->close(); | 255 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); |
| 256 fCommands.append(command); |
| 263 } | 257 } |
| 264 | 258 |
| 265 void SkJSONCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { | 259 void SkJSONCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { |
| 266 » this->updateMatrix(); | 260 this->updateMatrix(); |
| 267 » this->open(SKJSONCANVAS_COMMAND_RRECT); | 261 Json::Value command(Json::objectValue); |
| 268 » this->writeRRect(SKJSONCANVAS_ATTRIBUTE_COORDS, rrect); | 262 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_RRECT); |
| 269 » this->writePaint(paint); | 263 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRRect(rrect); |
| 270 » this->close();} | 264 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); |
| 265 fCommands.append(command); |
| 266 } |
| 271 | 267 |
| 272 void SkJSONCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, cons
t SkPaint& paint) { | 268 void SkJSONCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, cons
t SkPaint& paint) { |
| 273 this->updateMatrix(); | 269 this->updateMatrix(); |
| 274 this->open(SKJSONCANVAS_COMMAND_DRRECT); | 270 Json::Value command(Json::objectValue); |
| 275 this->writeRRect(SKJSONCANVAS_ATTRIBUTE_OUTER, outer); | 271 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_RRECT); |
| 276 this->writeRRect(SKJSONCANVAS_ATTRIBUTE_INNER, inner); | 272 command[SKJSONCANVAS_ATTRIBUTE_INNER] = this->makeRRect(inner); |
| 277 this->writePaint(paint); | 273 command[SKJSONCANVAS_ATTRIBUTE_OUTER] = this->makeRRect(outer); |
| 278 this->close(); | 274 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); |
| 275 fCommands.append(command); |
| 279 } | 276 } |
| 280 | 277 |
| 281 void SkJSONCanvas::onDrawPoints(SkCanvas::PointMode mode, size_t count, const Sk
Point pts[], | 278 void SkJSONCanvas::onDrawPoints(SkCanvas::PointMode mode, size_t count, const Sk
Point pts[], |
| 282 » » » » » » » » const SkPaint& p
aint) { | 279 const SkPaint& paint) { |
| 283 this->updateMatrix(); | 280 this->updateMatrix(); |
| 284 this->open(SKJSONCANVAS_COMMAND_POINTS); | 281 Json::Value command(Json::objectValue); |
| 285 this->writePointMode(SKJSONCANVAS_ATTRIBUTE_MODE, mode); | 282 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_POINTS); |
| 286 fOut.writeText(",\"" SKJSONCANVAS_ATTRIBUTE_POINTS "\":["); | 283 command[SKJSONCANVAS_ATTRIBUTE_MODE] = this->makePointMode(mode); |
| 284 Json::Value points(Json::arrayValue); |
| 287 for (size_t i = 0; i < count; i++) { | 285 for (size_t i = 0; i < count; i++) { |
| 288 if (i != 0) { | 286 points.append(this->makePoint(pts[i])); |
| 289 fOut.writeText(","); | 287 } |
| 290 } | 288 command[SKJSONCANVAS_ATTRIBUTE_POINTS] = points; |
| 291 this->writef("[%f,%f]", pts[i].x(), pts[i].y()); | 289 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); |
| 292 } | 290 fCommands.append(command); |
| 293 fOut.writeText("]"); | |
| 294 this->writePaint(paint); | |
| 295 this->close(); | |
| 296 } | 291 } |
| 297 | 292 |
| 298 void SkJSONCanvas::onDrawVertices(SkCanvas::VertexMode, int vertexCount, const S
kPoint vertices[], | 293 void SkJSONCanvas::onDrawVertices(SkCanvas::VertexMode, int vertexCount, const S
kPoint vertices[], |
| 299 const SkPoint texs[], const SkColor colors[],
SkXfermode*, | 294 const SkPoint texs[], const SkColor colors[],
SkXfermode*, |
| 300 const uint16_t indices[], int indexCount, cons
t SkPaint&) { | 295 const uint16_t indices[], int indexCount, cons
t SkPaint&) { |
| 301 SkDebugf("unsupported: drawVertices\n"); | 296 SkDebugf("unsupported: drawVertices\n"); |
| 302 } | 297 } |
| 303 | 298 |
| 304 void SkJSONCanvas::onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[]
, const SkColor[], | 299 void SkJSONCanvas::onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[]
, const SkColor[], |
| 305 int count, SkXfermode::Mode, const SkRect* cull,
const SkPaint*) { | 300 int count, SkXfermode::Mode, const SkRect* cull,
const SkPaint*) { |
| 306 SkDebugf("unsupported: drawAtlas\n"); | 301 SkDebugf("unsupported: drawAtlas\n"); |
| 307 } | 302 } |
| 308 | 303 |
| 309 void SkJSONCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) { | 304 void SkJSONCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) { |
| 310 » this->updateMatrix(); | 305 this->updateMatrix(); |
| 311 » this->open(SKJSONCANVAS_COMMAND_PATH); | 306 Json::Value command(Json::objectValue); |
| 312 » this->writePath(SKJSONCANVAS_ATTRIBUTE_PATH, path); | 307 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_PATH); |
| 313 » this->writePaint(paint); | 308 command[SKJSONCANVAS_ATTRIBUTE_PATH] = this->makePath(path); |
| 314 » this->close();} | 309 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); |
| 310 fCommands.append(command); |
| 311 } |
| 315 | 312 |
| 316 void SkJSONCanvas::onDrawImage(const SkImage*, SkScalar dx, SkScalar dy, const S
kPaint*) { | 313 void SkJSONCanvas::onDrawImage(const SkImage*, SkScalar dx, SkScalar dy, const S
kPaint*) { |
| 317 SkDebugf("unsupported: drawImage\n"); | 314 SkDebugf("unsupported: drawImage\n"); |
| 318 } | 315 } |
| 319 | 316 |
| 320 void SkJSONCanvas::onDrawImageRect(const SkImage*, const SkRect*, const SkRect&,
const SkPaint*, | 317 void SkJSONCanvas::onDrawImageRect(const SkImage*, const SkRect*, const SkRect&,
const SkPaint*, |
| 321 SkCanvas::SrcRectConstraint) { | 318 SkCanvas::SrcRectConstraint) { |
| 322 SkDebugf("unsupported: drawImageRect\n"); | 319 SkDebugf("unsupported: drawImageRect\n"); |
| 323 } | 320 } |
| 324 | 321 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 337 } | 334 } |
| 338 | 335 |
| 339 void SkJSONCanvas::onDrawBitmapNine(const SkBitmap&, const SkIRect& center, cons
t SkRect& dst, | 336 void SkJSONCanvas::onDrawBitmapNine(const SkBitmap&, const SkIRect& center, cons
t SkRect& dst, |
| 340 const SkPaint*) { | 337 const SkPaint*) { |
| 341 SkDebugf("unsupported: drawBitmapNine\n"); | 338 SkDebugf("unsupported: drawBitmapNine\n"); |
| 342 } | 339 } |
| 343 | 340 |
| 344 void SkJSONCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, | 341 void SkJSONCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, |
| 345 SkScalar y, const SkPaint& paint) { | 342 SkScalar y, const SkPaint& paint) { |
| 346 this->updateMatrix(); | 343 this->updateMatrix(); |
| 347 this->open(SKJSONCANVAS_COMMAND_TEXT); | 344 Json::Value command(Json::objectValue); |
| 348 this->writeString(SKJSONCANVAS_ATTRIBUTE_TEXT, text, byteLength); | 345 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_TEXT); |
| 349 this->writePoint(SKJSONCANVAS_ATTRIBUTE_COORDS, { x, y }); | 346 command[SKJSONCANVAS_ATTRIBUTE_TEXT] = Json::Value((const char*) text, |
| 350 this->writePaint(paint); | 347 ((const char*) text) + by
teLength); |
| 351 this->close(); | 348 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makePoint(x, y); |
| 349 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); |
| 350 fCommands.append(command); |
| 352 } | 351 } |
| 353 | 352 |
| 354 void SkJSONCanvas::onDrawPosText(const void* text, size_t byteLength, | 353 void SkJSONCanvas::onDrawPosText(const void* text, size_t byteLength, |
| 355 const SkPoint pos[], const SkPaint& paint) { | 354 const SkPoint pos[], const SkPaint& paint) { |
| 356 SkDebugf("unsupported: drawPosText\n"); | 355 SkDebugf("unsupported: drawPosText\n"); |
| 357 } | 356 } |
| 358 | 357 |
| 359 void SkJSONCanvas::onDrawPosTextH(const void* text, size_t byteLength, | 358 void SkJSONCanvas::onDrawPosTextH(const void* text, size_t byteLength, |
| 360 const SkScalar xpos[], SkScalar constY, | 359 const SkScalar xpos[], SkScalar constY, |
| 361 const SkPaint& paint) { | 360 const SkPaint& paint) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 377 const SkPoint texCoords[4], SkXfermode* xmode, | 376 const SkPoint texCoords[4], SkXfermode* xmode, |
| 378 const SkPaint& paint) { | 377 const SkPaint& paint) { |
| 379 SkDebugf("unsupported: drawPatch\n"); | 378 SkDebugf("unsupported: drawPatch\n"); |
| 380 } | 379 } |
| 381 | 380 |
| 382 void SkJSONCanvas::onDrawDrawable(SkDrawable*, const SkMatrix*) { | 381 void SkJSONCanvas::onDrawDrawable(SkDrawable*, const SkMatrix*) { |
| 383 SkDebugf("unsupported: drawDrawable\n"); | 382 SkDebugf("unsupported: drawDrawable\n"); |
| 384 } | 383 } |
| 385 | 384 |
| 386 void SkJSONCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle
edgeStyle) { | 385 void SkJSONCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle
edgeStyle) { |
| 387 » this->updateMatrix(); | 386 this->updateMatrix(); |
| 388 » this->open(SKJSONCANVAS_COMMAND_CLIPRECT); | 387 Json::Value command(Json::objectValue); |
| 389 » this->writeRect(SKJSONCANVAS_ATTRIBUTE_COORDS, rect); | 388 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPRECT); |
| 390 » this->writeRegionOp(SKJSONCANVAS_ATTRIBUTE_REGIONOP, op); | 389 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRect(rect); |
| 391 » this->writeEdgeStyle(SKJSONCANVAS_ATTRIBUTE_EDGESTYLE, edgeStyle); | 390 command[SKJSONCANVAS_ATTRIBUTE_REGIONOP] = this->makeRegionOp(op); |
| 392 » this->close(); | 391 command[SKJSONCANVAS_ATTRIBUTE_EDGESTYLE] = this->makeEdgeStyle(edgeStyle); |
| 392 fCommands.append(command); |
| 393 } | 393 } |
| 394 | 394 |
| 395 void SkJSONCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeSt
yle edgeStyle) { | 395 void SkJSONCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeSt
yle edgeStyle) { |
| 396 » this->updateMatrix(); | 396 this->updateMatrix(); |
| 397 » this->open(SKJSONCANVAS_COMMAND_CLIPRRECT); | 397 Json::Value command(Json::objectValue); |
| 398 » this->writeRRect(SKJSONCANVAS_ATTRIBUTE_COORDS, rrect); | 398 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPRRECT); |
| 399 » this->writeRegionOp(SKJSONCANVAS_ATTRIBUTE_REGIONOP, op); | 399 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRRect(rrect); |
| 400 » this->writeEdgeStyle(SKJSONCANVAS_ATTRIBUTE_EDGESTYLE, edgeStyle); | 400 command[SKJSONCANVAS_ATTRIBUTE_REGIONOP] = this->makeRegionOp(op); |
| 401 » this->close(); | 401 command[SKJSONCANVAS_ATTRIBUTE_EDGESTYLE] = this->makeEdgeStyle(edgeStyle); |
| 402 fCommands.append(command); |
| 402 } | 403 } |
| 403 | 404 |
| 404 void SkJSONCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle
edgeStyle) { | 405 void SkJSONCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle
edgeStyle) { |
| 405 » updateMatrix(); | 406 this->updateMatrix(); |
| 406 » this->open(SKJSONCANVAS_COMMAND_CLIPPATH); | 407 Json::Value command(Json::objectValue); |
| 407 » this->writePath(SKJSONCANVAS_ATTRIBUTE_PATH, path); | 408 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPPATH); |
| 408 » this->writeRegionOp(SKJSONCANVAS_ATTRIBUTE_REGIONOP, op); | 409 command[SKJSONCANVAS_ATTRIBUTE_PATH] = this->makePath(path); |
| 409 » this->writeEdgeStyle(SKJSONCANVAS_ATTRIBUTE_EDGESTYLE, edgeStyle); | 410 command[SKJSONCANVAS_ATTRIBUTE_REGIONOP] = this->makeRegionOp(op); |
| 410 » this->close(); | 411 command[SKJSONCANVAS_ATTRIBUTE_EDGESTYLE] = this->makeEdgeStyle(edgeStyle); |
| 412 fCommands.append(command); |
| 411 } | 413 } |
| 412 | 414 |
| 413 void SkJSONCanvas::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) { | 415 void SkJSONCanvas::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) { |
| 414 » this->open(SKJSONCANVAS_COMMAND_CLIPREGION); | 416 this->updateMatrix(); |
| 415 » this->writeRegion(SKJSONCANVAS_ATTRIBUTE_DEVICEREGION, deviceRgn); | 417 Json::Value command(Json::objectValue); |
| 416 » this->writeRegionOp(SKJSONCANVAS_ATTRIBUTE_REGIONOP, op); | 418 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPREGION)
; |
| 417 » this->close(); | 419 command[SKJSONCANVAS_ATTRIBUTE_REGION] = this->makeRegion(deviceRgn); |
| 420 command[SKJSONCANVAS_ATTRIBUTE_REGIONOP] = this->makeRegionOp(op); |
| 421 fCommands.append(command); |
| 418 } | 422 } |
| 419 | 423 |
| 420 void SkJSONCanvas::willSave() { | 424 void SkJSONCanvas::willSave() { |
| 421 » this->open(SKJSONCANVAS_COMMAND_SAVE); | 425 Json::Value command(Json::objectValue); |
| 422 » this->close(); | 426 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_SAVE); |
| 427 fCommands.append(command); |
| 423 } | 428 } |
| 424 | 429 |
| 425 void SkJSONCanvas::willRestore() { | 430 void SkJSONCanvas::willRestore() { |
| 426 » this->open(SKJSONCANVAS_COMMAND_RESTORE); | 431 Json::Value command(Json::objectValue); |
| 427 » this->close(); | 432 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_RESTORE); |
| 433 fCommands.append(command); |
| 428 } | 434 } |
| OLD | NEW |