1c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org/*
2c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org * Copyright 2014 Google Inc.
3c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org *
4c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org *
5c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org * Use of this source code is governed by a BSD-style license that can be
6c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org * found in the LICENSE file.
7c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org *
8c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org */
9c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org
10f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.org#include "Path2D.h"
11c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org#include "Global.h"
12c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org
13f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.orgGlobal* Path2D::gGlobal = NULL;
14c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org
15f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.orgvoid Path2D::ConstructPath(const v8::FunctionCallbackInfo<Value>& args) {
16c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    HandleScope handleScope(gGlobal->getIsolate());
17f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.org    Path2D* path = new Path2D();
18b163984ae775ae229b8f7fc5573f9d28eaf33c19commit-bot@chromium.org    args.This()->SetInternalField(
19b163984ae775ae229b8f7fc5573f9d28eaf33c19commit-bot@chromium.org            0, External::New(gGlobal->getIsolate(), path));
20c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org}
21c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org
22c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org#define ADD_METHOD(name, fn) \
23c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    constructor->InstanceTemplate()->Set( \
24c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org            String::NewFromUtf8( \
25c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org                    global->getIsolate(), name, \
26c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org                    String::kInternalizedString), \
27b163984ae775ae229b8f7fc5573f9d28eaf33c19commit-bot@chromium.org            FunctionTemplate::New(global->getIsolate(), fn))
28c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org
29f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.org// Install the constructor in the global scope so Path2Ds can be constructed
30c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org// in JS.
31f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.orgvoid Path2D::AddToGlobal(Global* global) {
32c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    gGlobal = global;
33c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org
34c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    // Create a stack-allocated handle scope.
35c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    HandleScope handleScope(gGlobal->getIsolate());
36c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org
37c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    Handle<Context> context = gGlobal->getContext();
38c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org
39c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    // Enter the scope so all operations take place in the scope.
40c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    Context::Scope contextScope(context);
41c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org
42c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    Local<FunctionTemplate> constructor = FunctionTemplate::New(
43f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.org            gGlobal->getIsolate(), Path2D::ConstructPath);
44c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    constructor->InstanceTemplate()->SetInternalFieldCount(1);
45c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org
46cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org    ADD_METHOD("closePath", ClosePath);
47c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    ADD_METHOD("moveTo", MoveTo);
48c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    ADD_METHOD("lineTo", LineTo);
49c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    ADD_METHOD("quadraticCurveTo", QuadraticCurveTo);
50c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    ADD_METHOD("bezierCurveTo", BezierCurveTo);
51c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    ADD_METHOD("arc", Arc);
52c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    ADD_METHOD("rect", Rect);
53cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org    ADD_METHOD("oval", Oval);
54e1df56579f815fe1f788380e9342abe5284bab51commit-bot@chromium.org    ADD_METHOD("conicTo", ConicTo);
55c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org
56b163984ae775ae229b8f7fc5573f9d28eaf33c19commit-bot@chromium.org    context->Global()->Set(String::NewFromUtf8(
57f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.org            gGlobal->getIsolate(), "Path2D"), constructor->GetFunction());
58c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org}
59c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org
60f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.orgPath2D* Path2D::Unwrap(const v8::FunctionCallbackInfo<Value>& args) {
61c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    Handle<External> field = Handle<External>::Cast(
62c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org            args.This()->GetInternalField(0));
63c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    void* ptr = field->Value();
64f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.org    return static_cast<Path2D*>(ptr);
65c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org}
66c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org
67f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.orgvoid Path2D::ClosePath(const v8::FunctionCallbackInfo<Value>& args) {
68f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.org    Path2D* path = Unwrap(args);
69c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    path->fSkPath.close();
70c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org}
71c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org
72f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.orgvoid Path2D::MoveTo(const v8::FunctionCallbackInfo<Value>& args) {
73c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    if (args.Length() != 2) {
74c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org        args.GetIsolate()->ThrowException(
75c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org                v8::String::NewFromUtf8(
76c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org                        args.GetIsolate(), "Error: 2 arguments required."));
77c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org        return;
78c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    }
79c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    double x = args[0]->NumberValue();
80c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    double y = args[1]->NumberValue();
81f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.org    Path2D* path = Unwrap(args);
82c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    path->fSkPath.moveTo(SkDoubleToScalar(x), SkDoubleToScalar(y));
83c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org}
84c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org
85f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.orgvoid Path2D::LineTo(const v8::FunctionCallbackInfo<Value>& args) {
86c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    if (args.Length() != 2) {
87c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org        args.GetIsolate()->ThrowException(
88c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org                v8::String::NewFromUtf8(
89c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org                        args.GetIsolate(), "Error: 2 arguments required."));
90c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org        return;
91c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    }
92c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    double x = args[0]->NumberValue();
93c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    double y = args[1]->NumberValue();
94f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.org    Path2D* path = Unwrap(args);
95c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    path->fSkPath.lineTo(SkDoubleToScalar(x), SkDoubleToScalar(y));
96c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org}
97c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org
98f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.orgvoid Path2D::QuadraticCurveTo(const v8::FunctionCallbackInfo<Value>& args) {
99c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    if (args.Length() != 4) {
100c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org        args.GetIsolate()->ThrowException(
101c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org                v8::String::NewFromUtf8(
102c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org                        args.GetIsolate(), "Error: 4 arguments required."));
103c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org        return;
104c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    }
105c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    double cpx = args[0]->NumberValue();
106c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    double cpy = args[1]->NumberValue();
107c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    double x = args[2]->NumberValue();
108c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    double y = args[3]->NumberValue();
109f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.org    Path2D* path = Unwrap(args);
110c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    // TODO(jcgregorio) Doesn't handle the empty last path case correctly per
111c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    // the HTML 5 spec.
112c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    path->fSkPath.quadTo(
113c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org            SkDoubleToScalar(cpx), SkDoubleToScalar(cpy),
114c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org            SkDoubleToScalar(x), SkDoubleToScalar(y));
115c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org}
116c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org
117f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.orgvoid Path2D::BezierCurveTo(const v8::FunctionCallbackInfo<Value>& args) {
118c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    if (args.Length() != 6) {
119c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org        args.GetIsolate()->ThrowException(
120c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org                v8::String::NewFromUtf8(
121c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org                        args.GetIsolate(), "Error: 6 arguments required."));
122c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org        return;
123c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    }
124c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    double cp1x = args[0]->NumberValue();
125c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    double cp1y = args[1]->NumberValue();
126c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    double cp2x = args[2]->NumberValue();
127c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    double cp2y = args[3]->NumberValue();
128c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    double x = args[4]->NumberValue();
129c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    double y = args[5]->NumberValue();
130f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.org    Path2D* path = Unwrap(args);
131c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    // TODO(jcgregorio) Doesn't handle the empty last path case correctly per
132c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    // the HTML 5 spec.
133c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    path->fSkPath.cubicTo(
134c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org            SkDoubleToScalar(cp1x), SkDoubleToScalar(cp1y),
135c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org            SkDoubleToScalar(cp2x), SkDoubleToScalar(cp2y),
136c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org            SkDoubleToScalar(x), SkDoubleToScalar(y));
137c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org}
138c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org
139f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.orgvoid Path2D::Arc(const v8::FunctionCallbackInfo<Value>& args) {
140c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    if (args.Length() != 5 && args.Length() != 6) {
141c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org        args.GetIsolate()->ThrowException(
142c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org                v8::String::NewFromUtf8(
143c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org                        args.GetIsolate(), "Error: 5 or 6 args required."));
144c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org        return;
145c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    }
146c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    double x          = args[0]->NumberValue();
147c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    double y          = args[1]->NumberValue();
148c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    double radius     = args[2]->NumberValue();
149c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    double startAngle = args[3]->NumberValue();
150c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    double endAngle   = args[4]->NumberValue();
151c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    bool antiClockwise = false;
152c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    if (args.Length() == 6) {
153c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org       antiClockwise = args[5]->BooleanValue();
154c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    }
155c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    double sweepAngle;
156c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    if (!antiClockwise) {
157c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org      sweepAngle = endAngle - startAngle;
158c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    } else {
159c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org      sweepAngle = startAngle - endAngle;
160c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org      startAngle = endAngle;
161c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    }
162c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org
163f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.org    Path2D* path = Unwrap(args);
164c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    SkRect rect = {
165c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org        SkDoubleToScalar(x-radius),
166c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org        SkDoubleToScalar(y-radius),
167c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org        SkDoubleToScalar(x+radius),
168c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org        SkDoubleToScalar(y+radius)
169c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    };
170c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org
171c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    path->fSkPath.addArc(rect, SkRadiansToDegrees(startAngle),
172c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org                         SkRadiansToDegrees(sweepAngle));
173c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org}
174c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org
175f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.orgvoid Path2D::Rect(const v8::FunctionCallbackInfo<Value>& args) {
176c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    if (args.Length() != 4) {
177c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org        args.GetIsolate()->ThrowException(
178c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org                v8::String::NewFromUtf8(
179c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org                        args.GetIsolate(), "Error: 4 arguments required."));
180c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org        return;
181c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    }
182c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    double x = args[0]->NumberValue();
183c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    double y = args[1]->NumberValue();
184c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    double w = args[2]->NumberValue();
185c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    double h = args[3]->NumberValue();
186c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org
187c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    SkRect rect = {
188c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org        SkDoubleToScalar(x),
189c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org        SkDoubleToScalar(y),
190c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org        SkDoubleToScalar(x) + SkDoubleToScalar(w),
191c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org        SkDoubleToScalar(y) + SkDoubleToScalar(h)
192c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    };
193f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.org    Path2D* path = Unwrap(args);
194c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org    path->fSkPath.addRect(rect);
195c8d732800e1a660fca6d2478fc24d6e6935ef8adcommit-bot@chromium.org}
196cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org
197f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.orgvoid Path2D::Oval(const v8::FunctionCallbackInfo<Value>& args) {
198cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org    if (args.Length() != 4 && args.Length() != 5) {
199cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org        args.GetIsolate()->ThrowException(
200cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org                v8::String::NewFromUtf8(
201cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org                        args.GetIsolate(), "Error: 4 or 5 args required."));
202cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org        return;
203cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org    }
204cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org    double x          = args[0]->NumberValue();
205cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org    double y          = args[1]->NumberValue();
206cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org    double radiusX    = args[2]->NumberValue();
207cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org    double radiusY    = args[3]->NumberValue();
208cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org    SkPath::Direction dir = SkPath::kCW_Direction;
209cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org    if (args.Length() == 5 && !args[4]->BooleanValue()) {
210cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org        dir = SkPath::kCCW_Direction;
211cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org    }
212f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.org    Path2D* path = Unwrap(args);
213cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org    SkRect rect = {
214cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org        SkDoubleToScalar(x-radiusX),
215cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org        SkDoubleToScalar(y-radiusX),
216cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org        SkDoubleToScalar(x+radiusY),
217cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org        SkDoubleToScalar(y+radiusY)
218cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org    };
219cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org
220cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org    path->fSkPath.addOval(rect, dir);
221cd110186256cee6acb0d503ab4af4b7ea7dc48a1commit-bot@chromium.org}
222e1df56579f815fe1f788380e9342abe5284bab51commit-bot@chromium.org
223f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.orgvoid Path2D::ConicTo(const v8::FunctionCallbackInfo<Value>& args) {
224e1df56579f815fe1f788380e9342abe5284bab51commit-bot@chromium.org    if (args.Length() != 5) {
225e1df56579f815fe1f788380e9342abe5284bab51commit-bot@chromium.org        args.GetIsolate()->ThrowException(
226e1df56579f815fe1f788380e9342abe5284bab51commit-bot@chromium.org                v8::String::NewFromUtf8(
227e1df56579f815fe1f788380e9342abe5284bab51commit-bot@chromium.org                        args.GetIsolate(), "Error: 5 args required."));
228e1df56579f815fe1f788380e9342abe5284bab51commit-bot@chromium.org        return;
229e1df56579f815fe1f788380e9342abe5284bab51commit-bot@chromium.org    }
230e1df56579f815fe1f788380e9342abe5284bab51commit-bot@chromium.org    double x1 = args[0]->NumberValue();
231e1df56579f815fe1f788380e9342abe5284bab51commit-bot@chromium.org    double y1 = args[1]->NumberValue();
232e1df56579f815fe1f788380e9342abe5284bab51commit-bot@chromium.org    double x2 = args[2]->NumberValue();
233e1df56579f815fe1f788380e9342abe5284bab51commit-bot@chromium.org    double y2 = args[3]->NumberValue();
234e1df56579f815fe1f788380e9342abe5284bab51commit-bot@chromium.org    double w  = args[4]->NumberValue();
235f679d1bf38a9e319c2b38fa53852f05b7f246e8ecommit-bot@chromium.org    Path2D* path = Unwrap(args);
236e1df56579f815fe1f788380e9342abe5284bab51commit-bot@chromium.org
237e1df56579f815fe1f788380e9342abe5284bab51commit-bot@chromium.org    path->fSkPath.conicTo(
238e1df56579f815fe1f788380e9342abe5284bab51commit-bot@chromium.org            SkDoubleToScalar(x1),
239e1df56579f815fe1f788380e9342abe5284bab51commit-bot@chromium.org            SkDoubleToScalar(y1),
240e1df56579f815fe1f788380e9342abe5284bab51commit-bot@chromium.org            SkDoubleToScalar(x2),
241e1df56579f815fe1f788380e9342abe5284bab51commit-bot@chromium.org            SkDoubleToScalar(y2),
242e1df56579f815fe1f788380e9342abe5284bab51commit-bot@chromium.org            SkDoubleToScalar(w)
243e1df56579f815fe1f788380e9342abe5284bab51commit-bot@chromium.org            );
244e1df56579f815fe1f788380e9342abe5284bab51commit-bot@chromium.org}
245