-
Notifications
You must be signed in to change notification settings - Fork 156
/
Copy pathrenderer.ts
69 lines (60 loc) · 2.3 KB
/
renderer.ts
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { BarcodeCanvasRenderer } from './canvas-renderer';
import { IBarcodeRenderer } from './IRenderer';
import { BarcodeSVGRenderering } from './svg-renderer';
/**
* Renderer
*/
/**
* Renderer module is used to render basic barcode elements
*/
/** @private */
export class BarcodeRenderer {
/** @private */
public renderer: IBarcodeRenderer = null;
public isSvgMode: boolean = null;
constructor(name: string, isSvgMode: boolean) {
this.isSvgMode = isSvgMode;
this.renderer = isSvgMode ? new BarcodeSVGRenderering() : new BarcodeCanvasRenderer();
}
/**
* Draw the root element for the barcode.\
*
* @returns {HTMLElement} Draw the barcode SVG .
* @param {Object} attribute - Provide the canvas element .
* @param {string} backGroundColor - Provide the canvas element .
* @param {number} width - Provide the canvas element .
* @param {number} height - Provide the canvas element .
* @private
*/
// eslint-disable-next-line
public renderRootElement(attribute: Object, backGroundColor: string, width: number, height: number): HTMLElement {
const canvasObj: HTMLElement = this.renderer.renderRootElement(attribute, backGroundColor, width, height) as HTMLCanvasElement;
return canvasObj;
}
/**
* Draw the rect for the barcode.\
*
* @returns {HTMLElement} Draw the barcode SVG .
* @param {Object} canvas - Provide the canvas element .
* @param {Object} attribute - Provide the canvas element .
* @private
*/
// eslint-disable-next-line
public renderRectElement(canvas: HTMLCanvasElement, attribute: Object): HTMLElement {
const canvasObj: HTMLElement = this.renderer.renderRect(canvas, attribute) as HTMLCanvasElement;
return canvasObj;
}
/**
* Draw the text for the barcode.\
*
* @returns {HTMLElement} Draw the barcode SVG .
* @param {Object} canvas - Provide the canvas element .
* @param {Object} attribute - Provide the canvas element .
* @private
*/
// eslint-disable-next-line
public renderTextElement(canvas: HTMLCanvasElement, attribute: Object): HTMLElement {
const canvasObj: HTMLElement = this.renderer.renderText(canvas, attribute) as HTMLCanvasElement;
return canvasObj;
}
}