forked from syncfusion/ej2-javascript-ui-controls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvg-renderer.ts
65 lines (61 loc) · 2.48 KB
/
svg-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
import { IBarcodeRenderer } from './IRenderer';
import { createSvgElement } from '../utility/dom-util';
import { BaseAttributes } from './canvas-interface';
/**
* svg renderer
*/
/** @private */
export class BarcodeSVGRenderering implements IBarcodeRenderer {
/**
* 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 .
* @private
*/
// eslint-disable-next-line
public renderRootElement(attribute: Object, backGroundColor: string, ): HTMLElement {
const canvasObj: HTMLElement = createSvgElement('svg', attribute) as HTMLElement;
canvasObj.setAttribute('style', 'background:' + backGroundColor);
return canvasObj;
}
/**
* Draw the rect for the barcode.\
*
* @returns {HTMLElement} Draw the barcode SVG .
* @param {Object} svg - Provide the canvas element .
* @param {Object} attribute - Provide the canvas element .
* @private
*/
public renderRect(svg: HTMLElement, attribute: BaseAttributes): HTMLElement {
const rect: SVGRectElement = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
rect.setAttribute('x', attribute.x.toString());
rect.setAttribute('y', attribute.y.toString());
rect.setAttribute('width', attribute.width.toString());
rect.setAttribute('height', attribute.height.toString());
rect.setAttribute('fill', attribute.color);
rect.setAttribute('style', 'shape-rendering: crispEdges');
svg.appendChild(rect);
return svg;
}
/**
* Draw the text for the barcode.\
*
* @returns {HTMLElement} Draw the barcode SVG .
* @param {Object} svg - Provide the canvas element .
* @param {Object} attribute - Provide the canvas element .
* @private
*/
public renderText(svg: HTMLElement, attribute: BaseAttributes): HTMLElement {
const text: SVGTextElement = document.createElementNS('http://www.w3.org/2000/svg', 'text');
text.setAttribute('x', attribute.x.toString());
text.setAttribute('y', attribute.y.toString());
text.setAttribute('fill', attribute.color);
text.style.fontSize = attribute.stringSize.toString() + 'px';
text.style.fontFamily = attribute.fontStyle;
text.textContent = attribute.string;
svg.appendChild(text);
return svg;
}
}