|
| 1 | +import { Canvas, CanvasContext, createCanvas } from "../../"; |
| 2 | + |
| 3 | +// The following code is for testing typings only. It does not produce any sensible output. |
| 4 | + |
| 5 | +// Canvas |
| 6 | +const canvas: Canvas = createCanvas(100, 100); |
| 7 | +canvas.width = 100; |
| 8 | +canvas.height = 100; |
| 9 | +canvas.backColor = "#fff"; |
| 10 | +canvas.backColor = 0xffffffff; |
| 11 | + |
| 12 | +// Context |
| 13 | +const ctx: CanvasContext = canvas.getContext("2d", {}); |
| 14 | +const ctx2: CanvasContext = canvas.getContext("2d"); |
| 15 | +const ctx3: CanvasContext = canvas.getContext(); |
| 16 | + |
| 17 | +// State management |
| 18 | +ctx.save(); |
| 19 | +ctx.restore(); |
| 20 | + |
| 21 | +// Transforms |
| 22 | +ctx.resetTransform(); |
| 23 | +ctx.rotate(52); |
| 24 | +ctx.scale(1.5, 1.5); |
| 25 | +ctx.setTransform(1, 0, 0, 1, 0, 0); |
| 26 | +ctx.transform(1, 0, 0, 1, 0, 0); |
| 27 | +ctx.translate(10, 10); |
| 28 | + |
| 29 | +// Drawing |
| 30 | +ctx.fillStyle = 0xffffffff; |
| 31 | +ctx.fillStyle = "#0000ff"; |
| 32 | +ctx.beginPath(); |
| 33 | +ctx.moveTo(90, 90); |
| 34 | +ctx.lineTo(90, 50); |
| 35 | +ctx.arc(50, 50, 50, 0, Math.PI); |
| 36 | +ctx.closePath(); |
| 37 | +ctx.fill(); |
| 38 | +ctx.fill("evenodd"); |
| 39 | +ctx.fill("nonzero"); |
| 40 | +ctx.fillRect(0, 0, 10, 10); |
| 41 | +ctx.clearRect(0, 0, 20, 20); |
| 42 | + |
| 43 | +// Export |
| 44 | +const dataUri1: string = canvas.toDataURL(); |
| 45 | +const dataUri2: string = canvas.toDataURL("image/png"); |
| 46 | +const dataUri3: string = canvas.toDataURL("image/png", 0.92); |
| 47 | +const pngWithoutKeywords: Buffer = canvas.toPng(); |
| 48 | +const pngWithKeywords: Buffer = canvas.toPng({ "Software": "canvas-renderer 1.0" }); |
0 commit comments