From 159db297573a15089c91f3da9d889067e13d74f9 Mon Sep 17 00:00:00 2001 From: Ivan Hetman Date: Thu, 8 Dec 2022 17:44:51 +0200 Subject: [PATCH] JSO: add Path2D to Canvas API (#646) --- .../jso/canvas/CanvasRenderingContext2D.java | 12 ++++ .../java/org/teavm/jso/canvas/Path2D.java | 63 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 jso/apis/src/main/java/org/teavm/jso/canvas/Path2D.java diff --git a/jso/apis/src/main/java/org/teavm/jso/canvas/CanvasRenderingContext2D.java b/jso/apis/src/main/java/org/teavm/jso/canvas/CanvasRenderingContext2D.java index 023b6efc4..e72334f58 100644 --- a/jso/apis/src/main/java/org/teavm/jso/canvas/CanvasRenderingContext2D.java +++ b/jso/apis/src/main/java/org/teavm/jso/canvas/CanvasRenderingContext2D.java @@ -45,18 +45,26 @@ public interface CanvasRenderingContext2D extends JSObject { boolean isPointInPath(double x, double y); + boolean isPointInPath(Path2D path, double x, double y); + boolean isPointInStroke(double x, double y); + boolean isPointInStroke(Path2D path, double x, double y); + void quadraticCurveTo(double cpx, double cpy, double x, double y); void rect(double x, double y, double width, double height); void scrollPathIntoView(); + void scrollPathIntoView(Path2D path); + // Clip void clip(); + void clip(Path2D path); + // Creating images, gradients and patterns ImageData createImageData(double width, double height); @@ -105,6 +113,8 @@ public interface CanvasRenderingContext2D extends JSObject { void fill(); + void fill(Path2D path); + void fillRect(double x, double y, double width, double height); void fillText(String text, double x, double y, double maxWidth); @@ -115,6 +125,8 @@ public interface CanvasRenderingContext2D extends JSObject { void stroke(); + void stroke(Path2D path); + void strokeRect(double x, double y, double w, double h); void strokeText(String text, double x, double y, double maxWidth); diff --git a/jso/apis/src/main/java/org/teavm/jso/canvas/Path2D.java b/jso/apis/src/main/java/org/teavm/jso/canvas/Path2D.java new file mode 100644 index 000000000..5d8e7b31f --- /dev/null +++ b/jso/apis/src/main/java/org/teavm/jso/canvas/Path2D.java @@ -0,0 +1,63 @@ +/* + * Copyright 2022 ihromant. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.jso.canvas; + +import netscape.javascript.JSObject; +import org.teavm.interop.NoSideEffects; +import org.teavm.jso.JSBody; + +public abstract class Path2D extends JSObject { + private Path2D() { + } + + @JSBody(script = "return new Path2D();") + @NoSideEffects + public static native Path2D create(); + + @JSBody(params = "path", script = "return new Path2D(path);") + @NoSideEffects + public static native Path2D create(Path2D path); + + @JSBody(params = "svg", script = "return new Path2D(svg);") + @NoSideEffects + public static native Path2D create(String svg); + + public abstract void addPath(Path2D path); + + public abstract void closePath(); + + public abstract void moveTo(double x, double y); + + public abstract void lineTo(double x, double y); + + public abstract void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y); + + public abstract void quadraticCurveTo(double cpx, double cpy, double x, double y); + + public abstract void arc(double x, double y, double radius, double startAngle, double endAngle); + + public abstract void arc(double x, double y, double radius, double startAngle, double endAngle, boolean counterclockwise); + + public abstract void arcTo(double x1, double y1, double x2, double y2, double radius); + + public abstract void ellipse(double x, double y, double radiusX, double radiusY, double rotation, double startAngle, double endAngle); + + public abstract void ellipse(double x, double y, double radiusX, double radiusY, double rotation, double startAngle, double endAngle, boolean counterclockwise); + + public abstract void rect(double x, double y, double width, double height); + + public abstract void roundRect(double x, double y, double width, double height, JSObject radii); +}