@Override public Canvas fillPath(Path path) { assert path instanceof HtmlPath; ((HtmlPath) path).replay(ctx); ctx.fill(); isDirty = true; return this; }
private void drawGradient() { final Context2d ctx = canvas.getContext2d(); // draw gradient ctx.setFillStyle("#ffffff"); //$NON-NLS-1$ ctx.fillRect(0, 0, 26, 180); final Hsl hsl = new Hsl(0, 100, 50); for (int y = 0; y <= 179; y++) { hsl.setH(y * 2); ctx.setFillStyle(Colors.hsl2html(hsl)); ctx.fillRect(3, y, 20, 1); } // draw handle if (handleY >= 0) { ctx.setFillStyle("#000000"); //$NON-NLS-1$ ctx.beginPath(); ctx.moveTo(3, handleY); ctx.lineTo(0, handleY - 3); ctx.lineTo(0, handleY + 3); ctx.closePath(); ctx.fill(); ctx.moveTo(23, handleY); ctx.lineTo(26, handleY - 3); ctx.lineTo(26, handleY + 3); ctx.closePath(); ctx.fill(); } }
if (sprite.getFill() != null && sprite.getFill() != Color.NONE) { ctx.setGlobalAlpha(Double.isNaN(sprite.getFillOpacity()) ? opacity : opacity * sprite.getFillOpacity()); ctx.fill();
@Override public Canvas fillPath(Path path) { assert path instanceof HtmlPath; ((HtmlPath) path).replay(ctx); ctx.fill(); isDirty = true; return this; }
private void drawGradient(final boolean drawHandle) { final Context2d ctx = canvas.getContext2d(); // draw gradient final Hsl hsl = new Hsl(hue, 0, 50); for (int x = 0; x <= 179; x++) { hsl.setS(Math.round(x * 100 / 179)); final CanvasGradient grad = ctx.createLinearGradient(x, 0, x, 179); grad.addColorStop(0, "#000000"); //$NON-NLS-1$ grad.addColorStop(0.5, Colors.hsl2html(hsl)); grad.addColorStop(1, "#ffffff"); //$NON-NLS-1$ ctx.setFillStyle(grad); ctx.fillRect(x, 0, 1, 180); } // draw handle if (drawHandle) { ctx.beginPath(); ctx.arc(handleX, handleY, 4, 0, Math.PI * 2, false); ctx.closePath(); ctx.setFillStyle("#ffffff"); //$NON-NLS-1$ ctx.fill(); ctx.beginPath(); ctx.arc(handleX, handleY, 3, 0, Math.PI * 2, false); ctx.closePath(); ctx.setFillStyle("#000000"); //$NON-NLS-1$ ctx.fill(); } }
@Override public Canvas fillRoundRect(float x, float y, float w, float h, float radius) { addRoundRectPath(x, y, w, h, radius); ctx.fill(); isDirty = true; return this; }
@Override public Canvas fillPath(Path path) { assert path instanceof HtmlPath; ((HtmlPath) path).replay(ctx); ctx.fill(); isDirty = true; return this; }
@Override public Canvas fillRoundRect(float x, float y, float w, float h, float radius) { addRoundRectPath(x, y, w, h, radius); ctx.fill(); isDirty = true; return this; }
@Override public Canvas fillRoundRect(float x, float y, float w, float h, float radius) { addRoundRectPath(x, y, w, h, radius); ctx.fill(); isDirty = true; return this; }
@Override public Canvas fillCircle(float x, float y, float radius) { ctx.beginPath(); ctx.arc(x, y, radius, 0, 2 * Math.PI); ctx.fill(); isDirty = true; return this; }
@Override public Canvas fillCircle(float x, float y, float radius) { ctx.beginPath(); ctx.arc(x, y, radius, 0, 2 * Math.PI); ctx.fill(); isDirty = true; return this; }
@Override public Canvas fillCircle(float x, float y, float radius) { ctx.beginPath(); ctx.arc(x, y, radius, 0, 2 * Math.PI); ctx.fill(); isDirty = true; return this; }
Canvas canvas = Canvas.createIfSupported(); Context2d context1 = canvas.getContext2d(); context1.beginPath(); context1.moveTo(25,0); context1.lineTo(0,20); context1.lineTo(25,40); context1.lineTo(25,0); context1.fill(); context1.closePath();
protected void appendPath(Context2d ctx, PathSprite sprite) { ctx.beginPath(); sprite.toAbsolute(); // sprite = sprite.copy().toCurve(); PrecisePoint currentPoint = new PrecisePoint(); PrecisePoint movePoint = new PrecisePoint(); PrecisePoint curvePoint = new PrecisePoint(); PrecisePoint quadraticPoint = new PrecisePoint(); appendPathCommands(ctx, sprite.getCommands(), currentPoint, movePoint, curvePoint, quadraticPoint); double opacity = Double.isNaN(sprite.getOpacity()) ? 1.0 : sprite.getOpacity(); if (sprite.getFill() != null && sprite.getFill() != Color.NONE) { ctx.setGlobalAlpha(Double.isNaN(sprite.getFillOpacity()) ? opacity : opacity * sprite.getFillOpacity()); ctx.fill(); } if (sprite.getStroke() != null && sprite.getStroke() != Color.NONE && sprite.getStrokeWidth() != 0) { ctx.setLineCap(sprite.getStrokeLineCap() == null ? LineCap.BUTT : sprite.getStrokeLineCap()); ctx.setLineJoin(sprite.getStrokeLineJoin() == null ? LineJoin.MITER : sprite.getStrokeLineJoin()); ctx.setMiterLimit(sprite.getMiterLimit() == Double.NaN ? 4 : sprite.getMiterLimit()); ctx.setGlobalAlpha(Double.isNaN(sprite.getStrokeOpacity()) ? opacity : opacity * sprite.getStrokeOpacity()); ctx.stroke(); } }
@Override public void paint(Canvas canvas, Matrix matrix) { if (Geometry.POLYGON.equals(geometry.getGeometryType())) { canvas.getContext2d().save(); canvas.getContext2d().setFillStyle(fillStyle); canvas.getContext2d().setStrokeStyle(strokeStyle); canvas.getContext2d().setLineWidth(strokeWidthPixels / matrix.getXx()); canvas.getContext2d().beginPath(); for (Geometry ring : geometry.getGeometries()) { Coordinate[] coords = ring.getCoordinates(); canvas.getContext2d().moveTo(coords[0].getX(), coords[0].getY()); for (int i = 1; i < coords.length - 1; i++) { canvas.getContext2d().lineTo(coords[i].getX(), coords[i].getY()); } } canvas.getContext2d().closePath(); canvas.getContext2d().fill(); canvas.getContext2d().stroke(); canvas.getContext2d().restore(); } }
@Override public void paint(Canvas canvas, Matrix matrix) { if (Geometry.POLYGON.equals(geometry.getGeometryType())) { canvas.getContext2d().save(); canvas.getContext2d().setFillStyle(fillStyle); canvas.getContext2d().setStrokeStyle(strokeStyle); canvas.getContext2d().setLineWidth(strokeWidthPixels / matrix.getXx()); canvas.getContext2d().beginPath(); for (Geometry ring : geometry.getGeometries()) { Coordinate[] coords = ring.getCoordinates(); canvas.getContext2d().moveTo(coords[0].getX(), coords[0].getY()); for (int i = 1; i < coords.length - 1; i++) { canvas.getContext2d().lineTo(coords[i].getX(), coords[i].getY()); } } canvas.getContext2d().closePath(); canvas.getContext2d().fill(); canvas.getContext2d().stroke(); canvas.getContext2d().restore(); } }