};
}
-void SkJSONCanvas::updateMatrix() {
- const SkMatrix& matrix = this->getTotalMatrix();
- if (matrix != fLastMatrix) {
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_MATRIX);
- command[SKJSONCANVAS_ATTRIBUTE_MATRIX] = MakeMatrix(matrix);
- fCommands.append(command);
- fLastMatrix = matrix;
+void SkJSONCanvas::didConcat(const SkMatrix& matrix) {
+ Json::Value command(Json::objectValue);
+ switch (matrix.getType()) {
+ case SkMatrix::kTranslate_Mask:
+ command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_TRANSLATE);
+ command[SKJSONCANVAS_ATTRIBUTE_X] = Json::Value(matrix.get(SkMatrix::kMTransX));
+ command[SKJSONCANVAS_ATTRIBUTE_Y] = Json::Value(matrix.get(SkMatrix::kMTransY));
+ break;
+ case SkMatrix::kScale_Mask:
+ command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_SCALE);
+ command[SKJSONCANVAS_ATTRIBUTE_X] = Json::Value(matrix.get(SkMatrix::kMScaleX));
+ command[SKJSONCANVAS_ATTRIBUTE_Y] = Json::Value(matrix.get(SkMatrix::kMScaleY));
+ break;
+ default:
+ this->didSetMatrix(this->getTotalMatrix());
+ return;
}
+ fCommands.append(command);
+}
+
+void SkJSONCanvas::didSetMatrix(const SkMatrix& matrix) {
+ Json::Value command(Json::objectValue);
+ command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_MATRIX);
+ command[SKJSONCANVAS_ATTRIBUTE_MATRIX] = this->makeMatrix(matrix);
+ fCommands.append(command);
}
void SkJSONCanvas::onDrawPaint(const SkPaint& paint) {
}
void SkJSONCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) {
- this->updateMatrix();
Json::Value command(Json::objectValue);
command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_RECT);
command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRect(rect);
}
void SkJSONCanvas::onDrawOval(const SkRect& rect, const SkPaint& paint) {
- this->updateMatrix();
Json::Value command(Json::objectValue);
command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_OVAL);
command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRect(rect);
}
void SkJSONCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) {
- this->updateMatrix();
Json::Value command(Json::objectValue);
command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_RRECT);
command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRRect(rrect);
}
void SkJSONCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) {
- this->updateMatrix();
Json::Value command(Json::objectValue);
command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_RRECT);
command[SKJSONCANVAS_ATTRIBUTE_INNER] = this->makeRRect(inner);
void SkJSONCanvas::onDrawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint pts[],
const SkPaint& paint) {
- this->updateMatrix();
Json::Value command(Json::objectValue);
command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_POINTS);
command[SKJSONCANVAS_ATTRIBUTE_MODE] = this->makePointMode(mode);
const SkPoint texs[], const SkColor colors[], SkXfermode*,
const uint16_t indices[], int indexCount, const SkPaint&) {
SkDebugf("unsupported: drawVertices\n");
+ Json::Value command(Json::objectValue);
+ command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_VERTICES);
+ fCommands.append(command);
}
void SkJSONCanvas::onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[],
int count, SkXfermode::Mode, const SkRect* cull, const SkPaint*) {
SkDebugf("unsupported: drawAtlas\n");
+ Json::Value command(Json::objectValue);
+ command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_ATLAS);
+ fCommands.append(command);
}
void SkJSONCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) {
- this->updateMatrix();
Json::Value command(Json::objectValue);
command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_PATH);
command[SKJSONCANVAS_ATTRIBUTE_PATH] = this->makePath(path);
const SkPaint* paint) {
Json::Value encoded;
if (flatten(*image, &encoded, fSendBinaries)) {
- this->updateMatrix();
Json::Value command(Json::objectValue);
command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_IMAGE);
command[SKJSONCANVAS_ATTRIBUTE_IMAGE] = encoded;
const SkPaint* paint, SkCanvas::SrcRectConstraint constraint) {
Json::Value encoded;
if (flatten(*image, &encoded, fSendBinaries)) {
- this->updateMatrix();
Json::Value command(Json::objectValue);
command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_IMAGERECT);
command[SKJSONCANVAS_ATTRIBUTE_IMAGE] = encoded;
void SkJSONCanvas::onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst,
const SkPaint*) {
SkDebugf("unsupported: drawImageNine\n");
+ Json::Value command(Json::objectValue);
+ command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_IMAGENINE);
+ fCommands.append(command);
}
void SkJSONCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar dx, SkScalar dy,
const SkPaint* paint) {
Json::Value encoded;
if (flatten(bitmap, &encoded, fSendBinaries)) {
- this->updateMatrix();
Json::Value command(Json::objectValue);
command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_BITMAP);
command[SKJSONCANVAS_ATTRIBUTE_BITMAP] = encoded;
const SkPaint* paint, SkCanvas::SrcRectConstraint constraint) {
Json::Value encoded;
if (flatten(bitmap, &encoded, fSendBinaries)) {
- this->updateMatrix();
Json::Value command(Json::objectValue);
command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_BITMAPRECT);
command[SKJSONCANVAS_ATTRIBUTE_BITMAP] = encoded;
void SkJSONCanvas::onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
const SkPaint*) {
SkDebugf("unsupported: drawBitmapNine\n");
+ Json::Value command(Json::objectValue);
+ command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_BITMAPNINE);
+ fCommands.append(command);
}
void SkJSONCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x,
SkScalar y, const SkPaint& paint) {
- this->updateMatrix();
Json::Value command(Json::objectValue);
command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_TEXT);
command[SKJSONCANVAS_ATTRIBUTE_TEXT] = Json::Value((const char*) text,
void SkJSONCanvas::onDrawPosText(const void* text, size_t byteLength,
const SkPoint pos[], const SkPaint& paint) {
- this->updateMatrix();
Json::Value command(Json::objectValue);
command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_POSTEXT);
command[SKJSONCANVAS_ATTRIBUTE_TEXT] = Json::Value((const char*) text,
const SkScalar xpos[], SkScalar constY,
const SkPaint& paint) {
SkDebugf("unsupported: drawPosTextH\n");
+ Json::Value command(Json::objectValue);
+ command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_POSTEXTH);
+ fCommands.append(command);
}
void SkJSONCanvas::onDrawTextOnPath(const void* text, size_t byteLength,
const SkPath& path, const SkMatrix* matrix,
const SkPaint& paint) {
- SkDebugf("unsupported: drawTextOnPath\n");
+ Json::Value command(Json::objectValue);
+ command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_TEXTONPATH);
+ command[SKJSONCANVAS_ATTRIBUTE_TEXT] = Json::Value((const char*) text,
+ ((const char*) text) + byteLength);
+ command[SKJSONCANVAS_ATTRIBUTE_PATH] = this->makePath(path);
+ if (matrix != nullptr) {
+ command[SKJSONCANVAS_ATTRIBUTE_MATRIX] = this->makeMatrix(*matrix);
+ }
+ command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint);
+ fCommands.append(command);
}
void SkJSONCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
const SkPaint& paint) {
SkDebugf("unsupported: drawTextBlob\n");
+ Json::Value command(Json::objectValue);
+ command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_TEXTBLOB);
+ fCommands.append(command);
}
void SkJSONCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
const SkPoint texCoords[4], SkXfermode* xmode,
const SkPaint& paint) {
SkDebugf("unsupported: drawPatch\n");
+ Json::Value command(Json::objectValue);
+ command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_PATCH);
+ fCommands.append(command);
}
void SkJSONCanvas::onDrawDrawable(SkDrawable*, const SkMatrix*) {
SkDebugf("unsupported: drawDrawable\n");
+ Json::Value command(Json::objectValue);
+ command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_DRAWABLE);
+ fCommands.append(command);
}
void SkJSONCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
- this->updateMatrix();
Json::Value command(Json::objectValue);
command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPRECT);
command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRect(rect);
}
void SkJSONCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
- this->updateMatrix();
Json::Value command(Json::objectValue);
command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPRRECT);
command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRRect(rrect);
}
void SkJSONCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
- this->updateMatrix();
Json::Value command(Json::objectValue);
command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPPATH);
command[SKJSONCANVAS_ATTRIBUTE_PATH] = this->makePath(path);
}
void SkJSONCanvas::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
- this->updateMatrix();
Json::Value command(Json::objectValue);
command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPREGION);
command[SKJSONCANVAS_ATTRIBUTE_REGION] = this->makeRegion(deviceRgn);
}
void SkJSONCanvas::willSave() {
- this->updateMatrix();
Json::Value command(Json::objectValue);
command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_SAVE);
fCommands.append(command);
}
SkCanvas::SaveLayerStrategy SkJSONCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) {
- this->updateMatrix();
Json::Value command(Json::objectValue);
command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_SAVELAYER);
if (rec.fBounds != nullptr) {
class Renderer {
public:
- void getPaint(Json::Value& command, SkPaint* paint);
+ void getPaint(Json::Value& paint, SkPaint* result);
- void getRect(Json::Value& command, const char* name, SkRect* rect);
+ void getRect(Json::Value& rect, SkRect* result);
- void getRRect(Json::Value& command, const char* name, SkRRect* rrect);
+ void getRRect(Json::Value& rrect, SkRRect* result);
- void getPath(Json::Value& command, SkPath* path);
+ void getPath(Json::Value& path, SkPath* result);
- SkRegion::Op getRegionOp(Json::Value& command);
+ void getMatrix(Json::Value& matrix, SkMatrix* result);
+
+ SkRegion::Op getRegionOp(Json::Value& op);
void processCommand(Json::Value& command, SkCanvas* target);
+ void processTranslate(Json::Value& command, SkCanvas* target);
+
+ void processScale(Json::Value& command, SkCanvas* target);
+
void processMatrix(Json::Value& command, SkCanvas* target);
void processSave(Json::Value& command, SkCanvas* target);
void processPosText(Json::Value& command, SkCanvas* target);
+ void processTextOnPath(Json::Value& command, SkCanvas* target);
+
void processPoints(Json::Value& command, SkCanvas* target);
void processImage(Json::Value& command, SkCanvas* target);
void Renderer::processCommand(Json::Value& command, SkCanvas* target) {
const char* name = command[SKJSONCANVAS_COMMAND].asCString();
// TODO speed this up with a hash
- if (!strcmp(name, SKJSONCANVAS_COMMAND_MATRIX)) {
+ if (!strcmp(name, SKJSONCANVAS_COMMAND_TRANSLATE)) {
+ this->processTranslate(command, target);
+ }
+ else if (!strcmp(name, SKJSONCANVAS_COMMAND_SCALE)) {
+ this->processScale(command, target);
+ }
+ else if (!strcmp(name, SKJSONCANVAS_COMMAND_MATRIX)) {
this->processMatrix(command, target);
}
else if (!strcmp(name, SKJSONCANVAS_COMMAND_SAVE)) {
else if (!strcmp(name, SKJSONCANVAS_COMMAND_POSTEXT)) {
this->processPosText(command, target);
}
+ else if (!strcmp(name, SKJSONCANVAS_COMMAND_TEXTONPATH)) {
+ this->processTextOnPath(command, target);
+ }
else if (!strcmp(name, SKJSONCANVAS_COMMAND_POINTS)) {
this->processPoints(command, target);
}
}
}
-void Renderer::getPaint(Json::Value& command, SkPaint* result) {
- Json::Value jsonPaint = command[SKJSONCANVAS_ATTRIBUTE_PAINT];
- apply_paint_color(jsonPaint, result);
- apply_paint_shader(jsonPaint, result);
- apply_paint_patheffect(jsonPaint, result);
- apply_paint_maskfilter(jsonPaint, result);
- apply_paint_xfermode(jsonPaint, result);
- apply_paint_imagefilter(jsonPaint, result);
- apply_paint_style(jsonPaint, result);
- apply_paint_strokewidth(jsonPaint, result);
- apply_paint_strokemiter(jsonPaint, result);
- apply_paint_cap(jsonPaint, result);
- apply_paint_antialias(jsonPaint, result);
- apply_paint_blur(jsonPaint, result);
- apply_paint_dashing(jsonPaint, result);
- apply_paint_textalign(jsonPaint, result);
- apply_paint_textsize(jsonPaint, result);
- apply_paint_textscalex(jsonPaint, result);
- apply_paint_textskewx(jsonPaint, result);
-}
-
-void Renderer::getRect(Json::Value& command, const char* name, SkRect* result) {
- Json::Value rect = command[name];
+void Renderer::getPaint(Json::Value& paint, SkPaint* result) {
+ apply_paint_color(paint, result);
+ apply_paint_shader(paint, result);
+ apply_paint_patheffect(paint, result);
+ apply_paint_maskfilter(paint, result);
+ apply_paint_xfermode(paint, result);
+ apply_paint_imagefilter(paint, result);
+ apply_paint_style(paint, result);
+ apply_paint_strokewidth(paint, result);
+ apply_paint_strokemiter(paint, result);
+ apply_paint_cap(paint, result);
+ apply_paint_antialias(paint, result);
+ apply_paint_blur(paint, result);
+ apply_paint_dashing(paint, result);
+ apply_paint_textalign(paint, result);
+ apply_paint_textsize(paint, result);
+ apply_paint_textscalex(paint, result);
+ apply_paint_textskewx(paint, result);
+}
+
+void Renderer::getRect(Json::Value& rect, SkRect* result) {
result->set(rect[0].asFloat(), rect[1].asFloat(), rect[2].asFloat(), rect[3].asFloat());
}
-void Renderer::getRRect(Json::Value& command, const char* name, SkRRect* result) {
- Json::Value rrect = command[name];
+void Renderer::getRRect(Json::Value& rrect, SkRRect* result) {
SkVector radii[4] = {
{ rrect[1][0].asFloat(), rrect[1][1].asFloat() },
{ rrect[2][0].asFloat(), rrect[2][1].asFloat() },
};
result->setRectRadii(SkRect::MakeLTRB(rrect[0][0].asFloat(), rrect[0][1].asFloat(),
rrect[0][2].asFloat(), rrect[0][3].asFloat()),
- radii);
+ radii);
}
-void Renderer::getPath(Json::Value& command, SkPath* result) {
- Json::Value path = command[SKJSONCANVAS_ATTRIBUTE_PATH];
+void Renderer::getMatrix(Json::Value& matrix, SkMatrix* result) {
+ SkScalar values[] = {
+ matrix[0][0].asFloat(), matrix[0][1].asFloat(), matrix[0][2].asFloat(),
+ matrix[1][0].asFloat(), matrix[1][1].asFloat(), matrix[1][2].asFloat(),
+ matrix[2][0].asFloat(), matrix[2][1].asFloat(), matrix[2][2].asFloat()
+ };
+ result->set9(values);
+}
+
+void Renderer::getPath(Json::Value& path, SkPath* result) {
const char* fillType = path[SKJSONCANVAS_ATTRIBUTE_FILLTYPE].asCString();
if (!strcmp(fillType, SKJSONCANVAS_FILLTYPE_WINDING)) {
result->setFillType(SkPath::kWinding_FillType);
}
}
-SkRegion::Op Renderer::getRegionOp(Json::Value& command) {
- const char* op = command[SKJSONCANVAS_ATTRIBUTE_REGIONOP].asCString();
+SkRegion::Op Renderer::getRegionOp(Json::Value& jsonOp) {
+ const char* op = jsonOp.asCString();
if (!strcmp(op, SKJSONCANVAS_REGIONOP_DIFFERENCE)) {
return SkRegion::kDifference_Op;
}
return SkRegion::kIntersect_Op;
}
+void Renderer::processTranslate(Json::Value& command, SkCanvas* target) {
+ target->translate(command[SKJSONCANVAS_ATTRIBUTE_X].asFloat(),
+ command[SKJSONCANVAS_ATTRIBUTE_Y].asFloat());
+}
+
+void Renderer::processScale(Json::Value& command, SkCanvas* target) {
+ target->scale(command[SKJSONCANVAS_ATTRIBUTE_X].asFloat(),
+ command[SKJSONCANVAS_ATTRIBUTE_Y].asFloat());
+}
+
void Renderer::processMatrix(Json::Value& command, SkCanvas* target) {
- Json::Value jsonMatrix = command[SKJSONCANVAS_ATTRIBUTE_MATRIX];
SkMatrix matrix;
- SkScalar values[] = {
- jsonMatrix[0][0].asFloat(), jsonMatrix[0][1].asFloat(), jsonMatrix[0][2].asFloat(),
- jsonMatrix[1][0].asFloat(), jsonMatrix[1][1].asFloat(), jsonMatrix[1][2].asFloat(),
- jsonMatrix[2][0].asFloat(), jsonMatrix[2][1].asFloat(), jsonMatrix[2][2].asFloat()
- };
- matrix.set9(values);
+ this->getMatrix(command[SKJSONCANVAS_ATTRIBUTE_MATRIX], &matrix);
target->setMatrix(matrix);
}
SkCanvas::SaveLayerRec rec;
SkRect bounds;
if (command.isMember(SKJSONCANVAS_ATTRIBUTE_BOUNDS)) {
- this->getRect(command, SKJSONCANVAS_ATTRIBUTE_BOUNDS, &bounds);
+ this->getRect(command[SKJSONCANVAS_ATTRIBUTE_BOUNDS], &bounds);
rec.fBounds = &bounds;
}
SkPaint paint;
if (command.isMember(SKJSONCANVAS_ATTRIBUTE_PAINT)) {
- this->getPaint(command, &paint);
+ this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
rec.fPaint = &paint;
}
if (command.isMember(SKJSONCANVAS_ATTRIBUTE_BACKDROP)) {
void Renderer::processPaint(Json::Value& command, SkCanvas* target) {
SkPaint paint;
- this->getPaint(command, &paint);
+ this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
target->drawPaint(paint);
}
void Renderer::processRect(Json::Value& command, SkCanvas* target) {
SkRect rect;
- this->getRect(command, SKJSONCANVAS_ATTRIBUTE_COORDS, &rect);
+ this->getRect(command[SKJSONCANVAS_ATTRIBUTE_COORDS], &rect);
SkPaint paint;
- this->getPaint(command, &paint);
+ this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
target->drawRect(rect, paint);
}
void Renderer::processRRect(Json::Value& command, SkCanvas* target) {
SkRRect rrect;
- this->getRRect(command, SKJSONCANVAS_ATTRIBUTE_COORDS, &rrect);
+ this->getRRect(command[SKJSONCANVAS_ATTRIBUTE_COORDS], &rrect);
SkPaint paint;
- this->getPaint(command, &paint);
+ this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
target->drawRRect(rrect, paint);
}
void Renderer::processOval(Json::Value& command, SkCanvas* target) {
SkRect rect;
- this->getRect(command, SKJSONCANVAS_ATTRIBUTE_COORDS, &rect);
+ this->getRect(command[SKJSONCANVAS_ATTRIBUTE_COORDS], &rect);
SkPaint paint;
- this->getPaint(command, &paint);
+ this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
target->drawOval(rect, paint);
}
void Renderer::processPath(Json::Value& command, SkCanvas* target) {
- Json::Value jsonPath = command[SKJSONCANVAS_ATTRIBUTE_PATH];
SkPath path;
- this->getPath(command, &path);
+ this->getPath(command[SKJSONCANVAS_ATTRIBUTE_PATH], &path);
SkPaint paint;
- this->getPaint(command, &paint);
+ this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
target->drawPath(path, paint);
}
void Renderer::processText(Json::Value& command, SkCanvas* target) {
const char* text = command[SKJSONCANVAS_ATTRIBUTE_TEXT].asCString();
SkPaint paint;
- this->getPaint(command, &paint);
+ this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
Json::Value coords = command[SKJSONCANVAS_ATTRIBUTE_COORDS];
target->drawText(text, strlen(text), coords[0].asFloat(), coords[1].asFloat(), paint);
}
void Renderer::processPosText(Json::Value& command, SkCanvas* target) {
const char* text = command[SKJSONCANVAS_ATTRIBUTE_TEXT].asCString();
SkPaint paint;
- this->getPaint(command, &paint);
+ this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
Json::Value coords = command[SKJSONCANVAS_ATTRIBUTE_COORDS];
int count = (int) coords.size();
SkPoint* points = (SkPoint*) sk_malloc_throw(count * sizeof(SkPoint));
free(points);
}
+void Renderer::processTextOnPath(Json::Value& command, SkCanvas* target) {
+ const char* text = command[SKJSONCANVAS_ATTRIBUTE_TEXT].asCString();
+ SkPath path;
+ this->getPath(command[SKJSONCANVAS_ATTRIBUTE_PATH], &path);
+ SkMatrix* matrixPtr;
+ SkMatrix matrix;
+ if (command.isMember(SKJSONCANVAS_ATTRIBUTE_MATRIX)) {
+ this->getMatrix(command[SKJSONCANVAS_ATTRIBUTE_MATRIX], &matrix);
+ matrixPtr = &matrix;
+ }
+ else {
+ matrixPtr = nullptr;
+ }
+ SkPaint paint;
+ this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
+ target->drawTextOnPath(text, strlen(text), path, matrixPtr, paint);
+}
+
void Renderer::processPoints(Json::Value& command, SkCanvas* target) {
SkCanvas::PointMode mode;
const char* jsonMode = command[SKJSONCANVAS_ATTRIBUTE_MODE].asCString();
points[i] = SkPoint::Make(jsonPoints[i][0].asFloat(), jsonPoints[i][1].asFloat());
}
SkPaint paint;
- this->getPaint(command, &paint);
+ this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
target->drawPoints(mode, count, points, paint);
free(points);
}
void Renderer::processClipRect(Json::Value& command, SkCanvas* target) {
SkRect rect;
- this->getRect(command, SKJSONCANVAS_ATTRIBUTE_COORDS, &rect);
- target->clipRect(rect, this->getRegionOp(command),
+ this->getRect(command[SKJSONCANVAS_ATTRIBUTE_COORDS], &rect);
+ target->clipRect(rect, this->getRegionOp(command[SKJSONCANVAS_ATTRIBUTE_REGIONOP]),
command[SKJSONCANVAS_ATTRIBUTE_ANTIALIAS].asBool());
}
void Renderer::processClipRRect(Json::Value& command, SkCanvas* target) {
SkRRect rrect;
- this->getRRect(command, SKJSONCANVAS_ATTRIBUTE_COORDS, &rrect);
- target->clipRRect(rrect, this->getRegionOp(command),
+ this->getRRect(command[SKJSONCANVAS_ATTRIBUTE_COORDS], &rrect);
+ target->clipRRect(rrect, this->getRegionOp(command[SKJSONCANVAS_ATTRIBUTE_REGIONOP]),
command[SKJSONCANVAS_ATTRIBUTE_ANTIALIAS].asBool());
}
void Renderer::processClipPath(Json::Value& command, SkCanvas* target) {
SkPath path;
- this->getPath(command, &path);
- target->clipPath(path, this->getRegionOp(command),
+ this->getPath(command[SKJSONCANVAS_ATTRIBUTE_PATH], &path);
+ target->clipPath(path, this->getRegionOp(command[SKJSONCANVAS_ATTRIBUTE_REGIONOP]),
command[SKJSONCANVAS_ATTRIBUTE_ANTIALIAS].asBool());
}
SkPaint* paintPtr;
SkPaint paint;
if (command.isMember(SKJSONCANVAS_ATTRIBUTE_PAINT)) {
- this->getPaint(command, &paint);
+ this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
paintPtr = &paint;
}
else {
return;
}
SkRect dst;
- this->getRect(command, SKJSONCANVAS_ATTRIBUTE_DST, &dst);
+ this->getRect(command[SKJSONCANVAS_ATTRIBUTE_DST], &dst);
SkPaint* paintPtr;
SkPaint paint;
if (command.isMember(SKJSONCANVAS_ATTRIBUTE_PAINT)) {
- this->getPaint(command, &paint);
+ this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
paintPtr = &paint;
}
else {
}
if (command.isMember(SKJSONCANVAS_ATTRIBUTE_SRC)) {
SkRect src;
- this->getRect(command, SKJSONCANVAS_ATTRIBUTE_SRC, &src);
+ this->getRect(command[SKJSONCANVAS_ATTRIBUTE_SRC], &src);
target->drawImageRect(image, src, dst, paintPtr, constraint);
}
else {
SkPaint* paintPtr;
SkPaint paint;
if (command.isMember(SKJSONCANVAS_ATTRIBUTE_PAINT)) {
- this->getPaint(command, &paint);
+ this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
paintPtr = &paint;
}
else {
return;
}
SkRect dst;
- this->getRect(command, SKJSONCANVAS_ATTRIBUTE_DST, &dst);
+ this->getRect(command[SKJSONCANVAS_ATTRIBUTE_DST], &dst);
SkPaint* paintPtr;
SkPaint paint;
if (command.isMember(SKJSONCANVAS_ATTRIBUTE_PAINT)) {
- this->getPaint(command, &paint);
+ this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
paintPtr = &paint;
}
else {
}
if (command.isMember(SKJSONCANVAS_ATTRIBUTE_SRC)) {
SkRect src;
- this->getRect(command, SKJSONCANVAS_ATTRIBUTE_SRC, &src);
+ this->getRect(command[SKJSONCANVAS_ATTRIBUTE_SRC], &src);
target->drawBitmapRect(*bitmap, src, dst, paintPtr, constraint);
}
else {