Search in sources :

Example 1 with WindingRule

use of com.gargoylesoftware.htmlunit.javascript.host.canvas.rendering.RenderingBackend.WindingRule in project htmlunit by HtmlUnit.

the class CanvasRenderingContext2D method clip.

/**
 * Creates a new clipping region.
 * @param context the JavaScript context
 * @param thisObj the scriptable
 * @param args the arguments passed into the method
 * @param function the function
 */
@JsxFunction
public static void clip(final Context context, final Scriptable thisObj, final Object[] args, final Function function) {
    if (!(thisObj instanceof CanvasRenderingContext2D)) {
        throw Context.reportRuntimeError("CanvasRenderingContext2D.getImageData() failed - this is not a CanvasRenderingContext2D");
    }
    final CanvasRenderingContext2D canvas = (CanvasRenderingContext2D) thisObj;
    RenderingBackend.WindingRule windingRule = WindingRule.NON_ZERO;
    if (args.length == 1) {
        final String windingRuleParam = ScriptRuntime.toString(args[0]);
        if ("evenodd".contentEquals(windingRuleParam)) {
            windingRule = WindingRule.EVEN_ODD;
        }
        canvas.getRenderingBackend().clip(windingRule, null);
    }
    if (args.length > 1) {
        if (!(args[0] instanceof Path2D)) {
            throw Context.reportRuntimeError("CanvasRenderingContext2D.clip() failed - the first parameter has to be a Path2D");
        }
        final String windingRuleParam = ScriptRuntime.toString(args[1]);
        if ("evenodd".contentEquals(windingRuleParam)) {
            windingRule = WindingRule.EVEN_ODD;
        }
        LOG.info("CanvasRenderingContext2D.clip(path, fillRule) not yet implemented");
    // canvas.getRenderingBackend().clip(windingRule, (Path2D) args[0]);
    }
    canvas.getRenderingBackend().clip(WindingRule.NON_ZERO, null);
}
Also used : AwtRenderingBackend(com.gargoylesoftware.htmlunit.javascript.host.canvas.rendering.AwtRenderingBackend) RenderingBackend(com.gargoylesoftware.htmlunit.javascript.host.canvas.rendering.RenderingBackend) WindingRule(com.gargoylesoftware.htmlunit.javascript.host.canvas.rendering.RenderingBackend.WindingRule) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Aggregations

JsxFunction (com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)1 AwtRenderingBackend (com.gargoylesoftware.htmlunit.javascript.host.canvas.rendering.AwtRenderingBackend)1 RenderingBackend (com.gargoylesoftware.htmlunit.javascript.host.canvas.rendering.RenderingBackend)1 WindingRule (com.gargoylesoftware.htmlunit.javascript.host.canvas.rendering.RenderingBackend.WindingRule)1