UNPKG

tav-media

Version:

Cross platform media editing framework

23 lines (22 loc) 891 B
import { ScalerContext as NativeScaleContext } from '../core/scaler-context'; import { getCanvas2D } from './canvas'; import { NativeImage } from './native-image'; export class ScalerContext extends NativeScaleContext { generateImage(text, bounds) { const canvas = getCanvas2D(); canvas.width = bounds.right - bounds.left; canvas.height = bounds.bottom - bounds.top; const context = canvas.getContext('2d'); context.font = this.fontString(); context.fillText(text, -bounds.left, -bounds.top); return new NativeImage(canvas, true); } loadCanvas() { if (!ScalerContext.canvas) { ScalerContext.setCanvas(getCanvas2D()); ScalerContext.canvas.width = 10; ScalerContext.canvas.height = 10; ScalerContext.setContext(ScalerContext.canvas.getContext('2d')); } } }