| 11 | * @internal |
| 12 | */ |
| 13 | export class Html5Canvas implements ICanvas { |
| 14 | private _measureCanvas: HTMLCanvasElement; |
| 15 | private _measureContext: CanvasRenderingContext2D; |
| 16 | private _canvas: HTMLCanvasElement | null = null; |
| 17 | private _context!: CanvasRenderingContext2D; |
| 18 | private _color: Color = new Color(0, 0, 0, 0xff); |
| 19 | private _font: Font = new Font('Arial', 10, FontStyle.Plain); |
| 20 | private _musicFont?: Font; |
| 21 | private _lineWidth: number = 0; |
| 22 | |
| 23 | public settings!: Settings; |
| 24 | |
| 25 | public constructor() { |
| 26 | this._measureCanvas = document.createElement('canvas'); |
| 27 | this._measureCanvas.width = 10; |
| 28 | this._measureCanvas.height = 10; |
| 29 | this._measureCanvas.style.width = '10px'; |
| 30 | this._measureCanvas.style.height = '10px'; |
| 31 | this._measureContext = this._measureCanvas.getContext('2d')!; |
| 32 | this._measureContext.textBaseline = 'hanging'; |
| 33 | } |
| 34 | |
| 35 | public destroy() {} |
| 36 | |
| 37 | public onRenderFinished(): unknown { |
| 38 | return null; |
| 39 | } |
| 40 | |
| 41 | public beginRender(width: number, height: number): void { |
| 42 | this._musicFont = new Font( |
| 43 | this.settings.display.resources.smuflFontFamilyName!, |
| 44 | this.settings.display.resources.engravingSettings.musicFontSize, |
| 45 | FontStyle.Plain, |
| 46 | FontWeight.Regular |
| 47 | ); |
| 48 | |
| 49 | |
| 50 | const scale = this.settings.display.scale; |
| 51 | |
| 52 | this._canvas = document.createElement('canvas'); |
| 53 | this._canvas.width = (width * Environment.highDpiFactor) | 0; |
| 54 | this._canvas.height = (height * Environment.highDpiFactor) | 0; |
| 55 | this._canvas.style.width = `${width}px`; |
| 56 | this._canvas.style.height = `${height}px`; |
| 57 | this._context = this._canvas.getContext('2d')!; |
| 58 | this._context.textBaseline = 'hanging'; |
| 59 | this._context.scale(Environment.highDpiFactor * scale, Environment.highDpiFactor * scale); |
| 60 | this._context.lineWidth = this._lineWidth; |
| 61 | } |
| 62 | |
| 63 | public endRender(): unknown { |
| 64 | const result: HTMLCanvasElement = this._canvas!; |
| 65 | this._canvas = null; |
| 66 | return result; |
| 67 | } |
| 68 | |
| 69 | public get color(): Color { |
| 70 | return this._color; |
nothing calls this directly
no outgoing calls
no test coverage detected