-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcanvas-writer.ts
More file actions
38 lines (29 loc) · 1.35 KB
/
canvas-writer.ts
File metadata and controls
38 lines (29 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import type { Point, Quad, Style, Writer } from "../types.js";
import { ImageWriter, type ImageWriterOptions } from "./image-writer.js";
export type CanvasWriterOptions = ImageWriterOptions;
export class CanvasWriter implements Writer<HTMLCanvasElement> {
private writer: ImageWriter;
constructor(optionsOrWidth: CanvasWriterOptions | number, height?: number, scale?: number, zoom?: number) {
this.writer = new ImageWriter(optionsOrWidth as ImageWriterOptions | number, height, scale, zoom);
}
async begin(): Promise<void> {
await this.writer.begin();
}
async drawPolygon(points: Quad, style: Style): Promise<void> {
await this.writer.drawPolygon(points, style);
}
async drawPolyline(points: Point[], closed: boolean, style: Style): Promise<void> {
await this.writer.drawPolyline(points, closed, style);
}
async drawText(quad: Quad, text: string, style: Style): Promise<void> {
await this.writer.drawText(quad, text, style);
}
async drawImage(quad: Quad, dataUrl: string, width: number, height: number, style: Style, rgbData?: number[]): Promise<void> {
await this.writer.drawImage(quad, dataUrl, width, height, style, rgbData);
}
async end(): Promise<HTMLCanvasElement> {
const result = await this.writer.end();
await result.finalize();
return result.getCanvas();
}
}