@node-projects/web-component-designer-zpl 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -2
- package/THIRD-PARTY-LICENSES.md +432 -0
- package/dist/assets/fonts/LICENSE-APACHE-2.0.txt +202 -0
- package/dist/assets/fonts/NOTICE.md +27 -0
- package/dist/assets/fonts/OCRA-NOTICE.md +27 -0
- package/dist/assets/fonts/OCRA.ttf +0 -0
- package/dist/assets/fonts/OCRB-NOTICE.md +21 -0
- package/dist/assets/fonts/OCRB.ttf +0 -0
- package/dist/assets/fonts/PrintLabMono-NOTICE.md +24 -0
- package/dist/assets/fonts/PrintLabMono.ttf +0 -0
- package/dist/assets/fonts/PrintLabZPL-Bold.ttf +0 -0
- package/dist/assets/fonts/PrintLabZPL-Bold.woff2 +0 -0
- package/dist/assets/fonts/VeraMono-Bold.ttf +0 -0
- package/dist/assets/fonts/VeraMono-NOTICE.md +57 -0
- package/dist/assets/fonts/VeraMono.ttf +0 -0
- package/dist/assets/licenses/BWIP-JS-LICENSE.txt +23 -0
- package/dist/assets/licenses/ZPLab-LICENSE.txt +21 -0
- package/dist/barcodes/barcodeRegistry.d.ts +124 -0
- package/dist/barcodes/barcodeRegistry.js +357 -0
- package/dist/barcodes/bwipRenderer.d.ts +70 -0
- package/dist/barcodes/bwipRenderer.js +552 -0
- package/dist/fonts/zplFonts.d.ts +27 -0
- package/dist/fonts/zplFonts.js +85 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.js +10 -3
- package/dist/services/ZplBarcodeElementsService.d.ts +5 -0
- package/dist/services/ZplBarcodeElementsService.js +16 -0
- package/dist/services/ZplBarcodePropertiesService.d.ts +10 -0
- package/dist/services/ZplBarcodePropertiesService.js +59 -0
- package/dist/services/ZplDiagonalLineExtension.d.ts +46 -0
- package/dist/services/ZplDiagonalLineExtension.js +255 -0
- package/dist/services/ZplElementResizeStrategy.d.ts +20 -0
- package/dist/services/ZplElementResizeStrategy.js +182 -0
- package/dist/services/ZplGraphicResizeStrategy.d.ts +18 -0
- package/dist/services/ZplGraphicResizeStrategy.js +81 -0
- package/dist/services/ZplIncludeInOutputPropertiesService.d.ts +12 -0
- package/dist/services/ZplIncludeInOutputPropertiesService.js +50 -0
- package/dist/services/ZplParserService.d.ts +7 -4
- package/dist/services/ZplParserService.js +214 -249
- package/dist/services/ZplSelectionExtensionProvider.d.ts +9 -0
- package/dist/services/ZplSelectionExtensionProvider.js +15 -0
- package/dist/services/ZplTextEditExtension.d.ts +20 -0
- package/dist/services/ZplTextEditExtension.js +80 -0
- package/dist/services/ZplTextPropertiesService.d.ts +8 -0
- package/dist/services/ZplTextPropertiesService.js +24 -0
- package/dist/services/hiddenMetadata.d.ts +17 -0
- package/dist/services/hiddenMetadata.js +95 -0
- package/dist/services/zplResizeGeometry.d.ts +6 -0
- package/dist/services/zplResizeGeometry.js +8 -0
- package/dist/setupZplServiceContainer.js +24 -5
- package/dist/widgets/elements.json +0 -24
- package/dist/widgets/views/zpl-demo-view.js +2 -1
- package/dist/widgets/zpl-barcode.d.ts +68 -14
- package/dist/widgets/zpl-barcode.js +162 -74
- package/dist/widgets/zpl-comment.d.ts +2 -0
- package/dist/widgets/zpl-comment.js +6 -3
- package/dist/widgets/zpl-graphic-box.d.ts +12 -0
- package/dist/widgets/zpl-graphic-box.js +49 -13
- package/dist/widgets/zpl-graphic-circle.d.ts +2 -0
- package/dist/widgets/zpl-graphic-circle.js +7 -0
- package/dist/widgets/zpl-graphic-diagonal-line.d.ts +2 -0
- package/dist/widgets/zpl-graphic-diagonal-line.js +7 -0
- package/dist/widgets/zpl-image.d.ts +4 -1
- package/dist/widgets/zpl-image.js +17 -14
- package/dist/widgets/zpl-text.d.ts +38 -8
- package/dist/widgets/zpl-text.js +183 -49
- package/dist/zplHelper.d.ts +1 -1
- package/dist/zplHelper.js +5 -1
- package/package.json +9 -4
- package/dist/extensions/ZplLayoutResizeExtensionProvider.d.ts +0 -4
- package/dist/extensions/ZplLayoutResizeExtensionProvider.js +0 -16
- package/dist/jsBarcodeOptions.d.ts +0 -27
- package/dist/jsBarcodeOptions.js +0 -14
- package/dist/qr.d.ts +0 -11
- package/dist/qr.js +0 -759
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { ZplGraphicCircle } from '../widgets/zpl-graphic-circle.js';
|
|
2
|
+
import { ZplGraphicDiagonalLine } from '../widgets/zpl-graphic-diagonal-line.js';
|
|
3
|
+
const circleHandles = ['n-resize', 'w-resize', 's-resize', 'e-resize'];
|
|
4
|
+
function crossedHandle(handle, crossedX, crossedY) {
|
|
5
|
+
let result = handle;
|
|
6
|
+
if (crossedX) {
|
|
7
|
+
const horizontal = {
|
|
8
|
+
'nw-resize': 'ne-resize', 'ne-resize': 'nw-resize',
|
|
9
|
+
'sw-resize': 'se-resize', 'se-resize': 'sw-resize',
|
|
10
|
+
'w-resize': 'e-resize', 'e-resize': 'w-resize'
|
|
11
|
+
};
|
|
12
|
+
result = horizontal[result] ?? result;
|
|
13
|
+
}
|
|
14
|
+
if (crossedY) {
|
|
15
|
+
const vertical = {
|
|
16
|
+
'nw-resize': 'sw-resize', 'sw-resize': 'nw-resize',
|
|
17
|
+
'ne-resize': 'se-resize', 'se-resize': 'ne-resize',
|
|
18
|
+
'n-resize': 's-resize', 's-resize': 'n-resize'
|
|
19
|
+
};
|
|
20
|
+
result = vertical[result] ?? result;
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
export class ZplGraphicResizeStrategy {
|
|
25
|
+
isHandledElement(designItem) {
|
|
26
|
+
return designItem.element instanceof ZplGraphicCircle || designItem.element instanceof ZplGraphicDiagonalLine;
|
|
27
|
+
}
|
|
28
|
+
getEnabledHandles(designItem) {
|
|
29
|
+
if (designItem.element instanceof ZplGraphicCircle)
|
|
30
|
+
return circleHandles;
|
|
31
|
+
// Diagonals use ZplDiagonalLineExtension. Returning no generic resize
|
|
32
|
+
// handles keeps rectangle-based resize semantics out of endpoint editing.
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
begin(context) {
|
|
36
|
+
const element = context.designItem.element;
|
|
37
|
+
return {
|
|
38
|
+
originalWidth: element.style.width,
|
|
39
|
+
originalHeight: element.style.height,
|
|
40
|
+
originalLeft: element.style.left,
|
|
41
|
+
originalTop: element.style.top,
|
|
42
|
+
originalRight: element.style.right,
|
|
43
|
+
originalBottom: element.style.bottom
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
preview(context, rawState) {
|
|
47
|
+
void rawState;
|
|
48
|
+
const element = context.designItem.element;
|
|
49
|
+
const crossedX = context.currentSize.width < 0;
|
|
50
|
+
const crossedY = context.currentSize.height < 0;
|
|
51
|
+
const width = Math.max(1, Math.abs(context.currentSize.width));
|
|
52
|
+
const height = Math.max(1, Math.abs(context.currentSize.height));
|
|
53
|
+
element.style.width = `${width}px`;
|
|
54
|
+
element.style.height = `${height}px`;
|
|
55
|
+
return {
|
|
56
|
+
width,
|
|
57
|
+
height,
|
|
58
|
+
anchorHandle: crossedHandle(context.handle, crossedX, crossedY)
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
commit(context, rawState) {
|
|
62
|
+
const state = rawState;
|
|
63
|
+
const element = context.designItem.element;
|
|
64
|
+
const width = element.style.width;
|
|
65
|
+
const height = element.style.height;
|
|
66
|
+
element.style.width = state.originalWidth;
|
|
67
|
+
element.style.height = state.originalHeight;
|
|
68
|
+
context.designItem.setStyle('width', width);
|
|
69
|
+
context.designItem.setStyle('height', height);
|
|
70
|
+
}
|
|
71
|
+
cancel(context, rawState) {
|
|
72
|
+
const state = rawState;
|
|
73
|
+
const element = context.designItem.element;
|
|
74
|
+
element.style.width = state.originalWidth;
|
|
75
|
+
element.style.height = state.originalHeight;
|
|
76
|
+
element.style.left = state.originalLeft;
|
|
77
|
+
element.style.top = state.originalTop;
|
|
78
|
+
element.style.right = state.originalRight;
|
|
79
|
+
element.style.bottom = state.originalBottom;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AbstractPropertiesService, IDesignItem, IProperty, RefreshMode, ValueType } from '@node-projects/web-component-designer';
|
|
2
|
+
export declare class ZplIncludeInOutputPropertiesService extends AbstractPropertiesService {
|
|
3
|
+
name: string;
|
|
4
|
+
getRefreshMode(): RefreshMode;
|
|
5
|
+
isHandledElement(designItem: IDesignItem): boolean;
|
|
6
|
+
getProperties(): Promise<IProperty[]>;
|
|
7
|
+
getValue(designItems: IDesignItem[]): boolean;
|
|
8
|
+
getUnsetValue(): boolean;
|
|
9
|
+
isSet(): ValueType;
|
|
10
|
+
setValue(designItems: IDesignItem[], _property: IProperty, value: boolean): Promise<void>;
|
|
11
|
+
clearValue(designItems: IDesignItem[], property: IProperty): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { AbstractPropertiesService, PropertyType, RefreshMode, ValueType } from '@node-projects/web-component-designer';
|
|
2
|
+
const includeProperty = {
|
|
3
|
+
name: 'includeInZplOutput',
|
|
4
|
+
displayName: 'Include in ZPL output',
|
|
5
|
+
type: 'boolean',
|
|
6
|
+
propertyType: PropertyType.attribute,
|
|
7
|
+
attributeName: 'node-projects-hide-at-run-time',
|
|
8
|
+
defaultValue: true,
|
|
9
|
+
description: 'When disabled, the item is preserved in metadata comments but omitted from printer output.'
|
|
10
|
+
};
|
|
11
|
+
export class ZplIncludeInOutputPropertiesService extends AbstractPropertiesService {
|
|
12
|
+
name = 'zplIncludeInOutput';
|
|
13
|
+
getRefreshMode() {
|
|
14
|
+
return RefreshMode.fullOnValueChange;
|
|
15
|
+
}
|
|
16
|
+
isHandledElement(designItem) {
|
|
17
|
+
return !designItem.isRootItem && designItem.element.localName.startsWith('zpl-');
|
|
18
|
+
}
|
|
19
|
+
async getProperties() {
|
|
20
|
+
return [{ ...includeProperty, service: this }];
|
|
21
|
+
}
|
|
22
|
+
getValue(designItems) {
|
|
23
|
+
return designItems.length > 0 && designItems.every(item => !item.hideAtRunTime);
|
|
24
|
+
}
|
|
25
|
+
getUnsetValue() {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
isSet() {
|
|
29
|
+
return ValueType.all;
|
|
30
|
+
}
|
|
31
|
+
async setValue(designItems, _property, value) {
|
|
32
|
+
if (designItems.length === 0)
|
|
33
|
+
return;
|
|
34
|
+
const group = designItems[0].openGroup(value ? 'Include in ZPL output' : 'Exclude from ZPL output');
|
|
35
|
+
try {
|
|
36
|
+
for (const designItem of designItems) {
|
|
37
|
+
if (this.isHandledElement(designItem))
|
|
38
|
+
designItem.hideAtRunTime = !value;
|
|
39
|
+
}
|
|
40
|
+
group.commit();
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
group.abort();
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
clearValue(designItems, property) {
|
|
48
|
+
void this.setValue(designItems, property, true);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IDesignItem, IHtmlParserService, IHtmlWriterOptions, IHtmlWriterService, InstanceServiceContainer, ITextWriter, ServiceContainer } from '@node-projects/web-component-designer';
|
|
2
|
+
export { createHiddenZplComments, decodeHiddenZplComments, tokenizeZpl } from './hiddenMetadata.js';
|
|
3
|
+
/** Zebra uses zero/omitted width as the natural aspect ratio. */
|
|
4
|
+
export declare const parseZplFontWidth: (value: string | undefined) => number;
|
|
2
5
|
export declare class ZplParserService implements IHtmlParserService, IHtmlWriterService {
|
|
3
6
|
options: IHtmlWriterOptions;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
write(textWriter: ITextWriter, designItems: IDesignItem[],
|
|
7
|
+
parse(source: string, serviceContainer: ServiceContainer, instanceServiceContainer: InstanceServiceContainer, _parseSnippet: boolean): Promise<IDesignItem[]>;
|
|
8
|
+
private _parse;
|
|
9
|
+
write(textWriter: ITextWriter, designItems: IDesignItem[], _rootContainerKeepInline: boolean, updatePositions?: boolean): void;
|
|
7
10
|
}
|
|
@@ -1,266 +1,231 @@
|
|
|
1
|
-
import { DesignItem } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { DesignItem, hideAtRunTimeAttributeName } from '@node-projects/web-component-designer';
|
|
2
|
+
import { attributesForBarcode, barcodeCommandRegistry, getBarcodeFieldOriginOffset, readBarcodeProps } from '../barcodes/barcodeRegistry.js';
|
|
3
|
+
import { barcodeFieldOriginAboveOffset, barcodeHorizontalInsets } from '../barcodes/bwipRenderer.js';
|
|
4
|
+
import { ZplBarcode } from '../widgets/zpl-barcode.js';
|
|
5
|
+
import { ZplComment } from '../widgets/zpl-comment.js';
|
|
6
|
+
import { ZplGraphicBox } from '../widgets/zpl-graphic-box.js';
|
|
7
|
+
import { ZplGraphicCircle } from '../widgets/zpl-graphic-circle.js';
|
|
8
|
+
import { ZplGraphicDiagonalLine } from '../widgets/zpl-graphic-diagonal-line.js';
|
|
9
|
+
import { ZplImage } from '../widgets/zpl-image.js';
|
|
10
|
+
import { getZplTextOutputOffset, ZplText } from '../widgets/zpl-text.js';
|
|
11
|
+
import { createHiddenZplComments, hiddenPayloads, tokenizeZpl } from './hiddenMetadata.js';
|
|
12
|
+
export { createHiddenZplComments, decodeHiddenZplComments, tokenizeZpl } from './hiddenMetadata.js';
|
|
13
|
+
const first = (...values) => values.find(value => value !== '' && value != null && value !== 'NaN');
|
|
14
|
+
/** Zebra uses zero/omitted width as the natural aspect ratio. */
|
|
15
|
+
export const parseZplFontWidth = (value) => Number(first(value, 0));
|
|
16
|
+
function setPosition(element, x, y) {
|
|
17
|
+
element.style.position = 'absolute';
|
|
18
|
+
element.style.left = `${Number.isFinite(x) ? x : 0}px`;
|
|
19
|
+
element.style.top = `${Number.isFinite(y) ? y : 0}px`;
|
|
20
|
+
}
|
|
21
|
+
function designItem(element, serviceContainer, instanceServiceContainer) {
|
|
22
|
+
return DesignItem.createDesignItemFromInstance(element, serviceContainer, instanceServiceContainer);
|
|
13
23
|
}
|
|
14
24
|
export class ZplParserService {
|
|
15
25
|
options = {};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
case 'R':
|
|
19
|
-
{
|
|
20
|
-
el.style.transform = 'rotate(90deg) translateY(-100%)';
|
|
21
|
-
el.style.transformOrigin = '0% 0%';
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
;
|
|
25
|
-
case 'I': {
|
|
26
|
-
el.style.transform = 'rotate(180deg)';
|
|
27
|
-
el.style.transformOrigin = '50% 50%';
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
case 'B':
|
|
31
|
-
{
|
|
32
|
-
el.style.transform = 'rotate(270deg)';
|
|
33
|
-
el.style.transformOrigin = '100% 100%';
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
;
|
|
37
|
-
}
|
|
38
|
-
return;
|
|
26
|
+
async parse(source, serviceContainer, instanceServiceContainer, _parseSnippet) {
|
|
27
|
+
return this._parse(source, serviceContainer, instanceServiceContainer, true);
|
|
39
28
|
}
|
|
40
|
-
async
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
29
|
+
async _parse(source, serviceContainer, instanceServiceContainer, includeHidden) {
|
|
30
|
+
const tokens = tokenizeZpl(source);
|
|
31
|
+
const hidden = includeHidden ? hiddenPayloads(tokens) : [];
|
|
32
|
+
const validMetadataComments = new Set(hidden.flatMap(payload => [...payload.comments]));
|
|
33
|
+
const graphics = new Map();
|
|
34
|
+
const result = [];
|
|
35
|
+
let x = 0;
|
|
36
|
+
let y = 0;
|
|
37
|
+
let fontName = '0';
|
|
38
|
+
let fontHeight = 30;
|
|
39
|
+
let fontWidth = 0;
|
|
40
|
+
let fontRotation = 'N';
|
|
41
|
+
let by = { moduleWidth: 2, wideRatio: 3, barHeight: 100 };
|
|
42
|
+
let labelReverse = false;
|
|
43
|
+
let fieldReverse = false;
|
|
44
|
+
let pendingBarcode = null;
|
|
45
|
+
for (const token of tokens) {
|
|
46
|
+
const fields = token.data.split(',');
|
|
47
|
+
if (token.prefix === '~' && token.command === 'DG') {
|
|
48
|
+
const name = fields[0].replace(/^[A-Z]:/i, '');
|
|
49
|
+
graphics.set(name, { name, totalBytes: Number(fields[1]), bytesPerRow: Number(fields[2]), hexData: fields.slice(3).join(',') });
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (token.prefix !== '^')
|
|
53
|
+
continue;
|
|
54
|
+
if (token.command === 'FO') {
|
|
55
|
+
// ^FR is scoped to one field and a new origin starts a new one.
|
|
56
|
+
fieldReverse = false;
|
|
57
|
+
x = Number(fields[0]) || 0;
|
|
58
|
+
y = Number(fields[1]) || 0;
|
|
59
|
+
}
|
|
60
|
+
else if (token.command === 'LR') {
|
|
61
|
+
labelReverse = token.data.toUpperCase().startsWith('Y');
|
|
62
|
+
}
|
|
63
|
+
else if (token.command === 'FR') {
|
|
64
|
+
fieldReverse = true;
|
|
65
|
+
}
|
|
66
|
+
else if (token.command === 'FS') {
|
|
67
|
+
fieldReverse = false;
|
|
68
|
+
}
|
|
69
|
+
else if (token.command === 'CF') {
|
|
70
|
+
fontName = fields[0] || '0';
|
|
71
|
+
fontHeight = Number(first(fields[1], 30));
|
|
72
|
+
// An omitted width means the font's natural aspect ratio. For
|
|
73
|
+
// bitmap fonts A-H this also means "use the height
|
|
74
|
+
// magnification"; substituting the numeric height would pick
|
|
75
|
+
// a different (usually much wider) cell magnification.
|
|
76
|
+
fontWidth = parseZplFontWidth(fields[2]);
|
|
77
|
+
fontRotation = 'N';
|
|
78
|
+
}
|
|
79
|
+
else if (token.command[0] === 'A' && /^[0A-H]$/.test(token.command[1])) {
|
|
80
|
+
fontName = token.command[1];
|
|
81
|
+
fontRotation = fields[0] || 'N';
|
|
82
|
+
fontHeight = Number(first(fields[1], fontHeight, 30));
|
|
83
|
+
fontWidth = parseZplFontWidth(fields[2]);
|
|
84
|
+
}
|
|
85
|
+
else if (token.command === 'BY') {
|
|
86
|
+
by = {
|
|
87
|
+
moduleWidth: Number(first(fields[0], by.moduleWidth, 2)),
|
|
88
|
+
wideRatio: Number(first(fields[1], by.wideRatio, 3)),
|
|
89
|
+
barHeight: Number(first(fields[2], by.barHeight, 100))
|
|
54
90
|
};
|
|
55
91
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
p = p.replaceAll("\n", "");
|
|
74
|
-
p = p.replaceAll("\r", "");
|
|
75
|
-
let command = p.substring(0, 2);
|
|
76
|
-
let fieldString = p.substring(2);
|
|
77
|
-
let fields = fieldString.split(",");
|
|
78
|
-
switch (command) {
|
|
79
|
-
case "XA":
|
|
80
|
-
case "XZ":
|
|
81
|
-
break;
|
|
82
|
-
case "FX":
|
|
83
|
-
let comment = new ZplComment();
|
|
84
|
-
comment.style.position = "absolute";
|
|
85
|
-
comment.style.left = x + "px";
|
|
86
|
-
comment.style.top = y + "px";
|
|
87
|
-
comment.setAttribute("content", fieldString);
|
|
88
|
-
designItems.push(DesignItem.createDesignItemFromInstance(comment, serviceContainer, instanceServiceContainer));
|
|
89
|
-
break;
|
|
90
|
-
case "AA": //Ax x=fontname
|
|
91
|
-
case "A0": {
|
|
92
|
-
fontName = command[1];
|
|
93
|
-
rotation = getSetValue(fields[0], 'N');
|
|
94
|
-
let defaultFontWidth = 15;
|
|
95
|
-
switch (fontName) {
|
|
96
|
-
case "A":
|
|
97
|
-
defaultFontWidth = 15;
|
|
98
|
-
break;
|
|
99
|
-
case "0":
|
|
100
|
-
defaultFontWidth = fontHeight;
|
|
101
|
-
}
|
|
102
|
-
fontHeight = parseInt(getSetValue(fields[1], defaultFontWidth));
|
|
103
|
-
fontWidth = parseInt(getSetValue(fields[2], defaultFontWidth));
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
case "CF": //we should switch to use A, CF is default font
|
|
107
|
-
rotation = 'N';
|
|
108
|
-
fontName = fields[0];
|
|
109
|
-
fontHeight = parseInt(fields[1]);
|
|
110
|
-
let defaultFontWidth = 15;
|
|
111
|
-
switch (fontName) {
|
|
112
|
-
case "A":
|
|
113
|
-
defaultFontWidth = 15;
|
|
114
|
-
break;
|
|
115
|
-
case "0":
|
|
116
|
-
defaultFontWidth = fontHeight;
|
|
117
|
-
}
|
|
118
|
-
fontWidth = parseInt(getSetValue(fields[2], defaultFontWidth));
|
|
119
|
-
break;
|
|
120
|
-
case "FO":
|
|
121
|
-
x = parseInt(fields[0]);
|
|
122
|
-
y = parseInt(fields[1]);
|
|
123
|
-
//a = parseInt(fields[2]);
|
|
124
|
-
break;
|
|
125
|
-
case "GB":
|
|
126
|
-
let rect = new ZplGraphicBox();
|
|
127
|
-
rect.style.position = "absolute";
|
|
128
|
-
rect.style.left = x + "px";
|
|
129
|
-
rect.style.top = y + "px";
|
|
130
|
-
rect.style.width = getSetValue(fields[0], fields[2], '1') + "px";
|
|
131
|
-
rect.style.height = getSetValue(fields[1], fields[2], '1') + "px";
|
|
132
|
-
rect.setAttribute("stroke-width", getSetValue(fields[2], '1'));
|
|
133
|
-
rect.setAttribute("stroke-color", getSetValue(fields[3], 'B') == "B" ? "black" : "white");
|
|
134
|
-
rect.setAttribute("corner-rounding", getSetValue(fields[4], '0'));
|
|
135
|
-
designItems.push(DesignItem.createDesignItemFromInstance(rect, serviceContainer, instanceServiceContainer));
|
|
136
|
-
break;
|
|
137
|
-
case "GD":
|
|
138
|
-
let line = new ZplGraphicDiagonalLine();
|
|
139
|
-
line.style.position = "absolute";
|
|
140
|
-
line.style.left = x + "px";
|
|
141
|
-
line.style.top = y + "px";
|
|
142
|
-
line.style.width = getSetValue(fields[0], fields[2], '1') + "px";
|
|
143
|
-
line.style.height = getSetValue(fields[1], fields[2], '1') + "px";
|
|
144
|
-
line.setAttribute("stroke-width", getSetValue(fields[2], '1'));
|
|
145
|
-
line.setAttribute("stroke-color", getSetValue(fields[3], 'B') == "B" ? "black" : "white");
|
|
146
|
-
line.setAttribute("orientation", getSetValue(fields[4], 'R'));
|
|
147
|
-
designItems.push(DesignItem.createDesignItemFromInstance(line, serviceContainer, instanceServiceContainer));
|
|
148
|
-
break;
|
|
149
|
-
case "GE":
|
|
150
|
-
let circle = new ZplGraphicCircle();
|
|
151
|
-
circle.style.position = "absolute";
|
|
152
|
-
circle.style.left = x + "px";
|
|
153
|
-
circle.style.top = y + "px";
|
|
154
|
-
circle.style.width = getSetValue(fields[0], fields[2], '1') + "px";
|
|
155
|
-
circle.style.height = getSetValue(fields[1], fields[2], '1') + "px";
|
|
156
|
-
circle.setAttribute("stroke-width", getSetValue(fields[2], '1'));
|
|
157
|
-
circle.setAttribute("stroke-color", getSetValue(fields[3], 'B') == "B" ? "black" : "white");
|
|
158
|
-
designItems.push(DesignItem.createDesignItemFromInstance(circle, serviceContainer, instanceServiceContainer));
|
|
159
|
-
break;
|
|
160
|
-
case "BY":
|
|
161
|
-
bw = parseInt(getSetValue(fields[0], "2"));
|
|
162
|
-
br = parseFloat(getSetValue(fields[1], "3"));
|
|
163
|
-
bh = parseInt(getSetValue(fields[2], "10"));
|
|
164
|
-
break;
|
|
165
|
-
case "BC":
|
|
166
|
-
bc = true;
|
|
167
|
-
// bo = getSetValue(fields[0], 'N');
|
|
168
|
-
barcode = new ZplBarcode();
|
|
169
|
-
barcode.style.position = "absolute";
|
|
170
|
-
barcode.style.left = x + "px";
|
|
171
|
-
barcode.style.top = y + "px";
|
|
172
|
-
barcode.setAttribute("type", "CODE128");
|
|
173
|
-
if (bw)
|
|
174
|
-
barcode.setAttribute("width", bw.toString());
|
|
175
|
-
if (br)
|
|
176
|
-
barcode.setAttribute("ratio", br.toString());
|
|
177
|
-
barcode.setAttribute("height", getSetValue(fields[1], bh).toString());
|
|
178
|
-
break;
|
|
179
|
-
case "BQ":
|
|
180
|
-
qr = true;
|
|
181
|
-
bc = true;
|
|
182
|
-
// bo = getSetValue(fields[0], 'N');
|
|
183
|
-
barcode = new ZplBarcode();
|
|
184
|
-
barcode.style.position = "absolute";
|
|
185
|
-
barcode.style.left = x + "px";
|
|
186
|
-
barcode.style.top = y + "px";
|
|
187
|
-
barcode.setAttribute("type", "QR");
|
|
188
|
-
if (bw)
|
|
189
|
-
barcode.setAttribute("width", bw.toString());
|
|
190
|
-
if (br)
|
|
191
|
-
barcode.setAttribute("ratio", br.toString());
|
|
192
|
-
barcode.setAttribute("height", getSetValue(fields[2], bh).toString());
|
|
193
|
-
break;
|
|
194
|
-
case "FD":
|
|
195
|
-
if (bc) {
|
|
196
|
-
if (qr)
|
|
197
|
-
barcode.setAttribute("content", fieldString.substring(3));
|
|
198
|
-
else
|
|
199
|
-
barcode.setAttribute("content", fieldString);
|
|
200
|
-
designItems.push(DesignItem.createDesignItemFromInstance(barcode, serviceContainer, instanceServiceContainer));
|
|
201
|
-
bc = false;
|
|
202
|
-
qr = false;
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
let text = new ZplText();
|
|
206
|
-
text.style.position = "absolute";
|
|
207
|
-
text.style.left = x + "px";
|
|
208
|
-
text.style.top = y + "px";
|
|
209
|
-
text.setAttribute("font-name", fontName);
|
|
210
|
-
text.setAttribute("font-height", fontHeight.toString());
|
|
211
|
-
text.setAttribute("font-width", fontWidth.toString());
|
|
212
|
-
text.setAttribute("content", fieldString);
|
|
213
|
-
if (rotation) {
|
|
214
|
-
this.createTransform(rotation, text);
|
|
92
|
+
else if (barcodeCommandRegistry[token.command]) {
|
|
93
|
+
const definition = barcodeCommandRegistry[token.command];
|
|
94
|
+
const element = new ZplBarcode();
|
|
95
|
+
const values = definition.parse(fields, by);
|
|
96
|
+
const attributes = attributesForBarcode(definition.type, values);
|
|
97
|
+
for (const [name, value] of Object.entries(attributes))
|
|
98
|
+
element.setAttribute(name, value);
|
|
99
|
+
pendingBarcode = { element, definition, outputX: x, outputY: y };
|
|
100
|
+
}
|
|
101
|
+
else if (token.command === 'FD') {
|
|
102
|
+
if (pendingBarcode) {
|
|
103
|
+
let content = token.data;
|
|
104
|
+
if (pendingBarcode.definition.type === 'qrcode') {
|
|
105
|
+
const prefix = content.match(/^([HQML])A,/);
|
|
106
|
+
if (prefix) {
|
|
107
|
+
pendingBarcode.element.setAttribute('error-correction', prefix[1]);
|
|
108
|
+
content = content.slice(prefix[0].length);
|
|
215
109
|
}
|
|
216
|
-
designItems.push(DesignItem.createDesignItemFromInstance(text, serviceContainer, instanceServiceContainer));
|
|
217
110
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
111
|
+
pendingBarcode.element.setAttribute('content', content);
|
|
112
|
+
const props = readBarcodeProps(pendingBarcode.element);
|
|
113
|
+
const offset = getBarcodeFieldOriginOffset(props.type, props.rotation);
|
|
114
|
+
const aboveOffset = props.rotation === 'N' ? barcodeFieldOriginAboveOffset(props) : 0;
|
|
115
|
+
const horizontalOffset = props.rotation === 'N' ? barcodeHorizontalInsets(props).left : 0;
|
|
116
|
+
setPosition(pendingBarcode.element, pendingBarcode.outputX - offset.x - horizontalOffset, pendingBarcode.outputY - offset.y - aboveOffset);
|
|
117
|
+
result.push(designItem(pendingBarcode.element, serviceContainer, instanceServiceContainer));
|
|
118
|
+
pendingBarcode = null;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
const element = new ZplText();
|
|
122
|
+
const offset = getZplTextOutputOffset(fontRotation);
|
|
123
|
+
setPosition(element, x - offset.x, y - offset.y);
|
|
124
|
+
element.setAttribute('font-name', fontName);
|
|
125
|
+
element.setAttribute('font-height', String(fontHeight));
|
|
126
|
+
element.setAttribute('font-width', String(fontWidth));
|
|
127
|
+
element.setAttribute('rotation', fontRotation);
|
|
128
|
+
element.setAttribute('content', token.data);
|
|
129
|
+
result.push(designItem(element, serviceContainer, instanceServiceContainer));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else if (token.command === 'GB') {
|
|
133
|
+
const element = new ZplGraphicBox();
|
|
134
|
+
setPosition(element, x, y);
|
|
135
|
+
const width = Number(first(fields[0], fields[2], 1));
|
|
136
|
+
const height = Number(first(fields[1], fields[2], 1));
|
|
137
|
+
const thickness = Number(first(fields[2], 1));
|
|
138
|
+
element.style.width = `${width}px`;
|
|
139
|
+
element.style.height = `${height}px`;
|
|
140
|
+
element.setAttribute('stroke-width', String(thickness));
|
|
141
|
+
element.setAttribute('stroke-color', fields[3] === 'W' ? 'white' : 'black');
|
|
142
|
+
element.setAttribute('corner-rounding', String(first(fields[4], 0)));
|
|
143
|
+
if (thickness >= Math.min(width, height))
|
|
144
|
+
element.setAttribute('filled', '');
|
|
145
|
+
if (labelReverse || fieldReverse)
|
|
146
|
+
element.setAttribute('reverse', '');
|
|
147
|
+
result.push(designItem(element, serviceContainer, instanceServiceContainer));
|
|
148
|
+
}
|
|
149
|
+
else if (token.command === 'GD') {
|
|
150
|
+
const element = new ZplGraphicDiagonalLine();
|
|
151
|
+
setPosition(element, x, y);
|
|
152
|
+
element.style.width = `${Number(first(fields[0], fields[2], 1))}px`;
|
|
153
|
+
element.style.height = `${Number(first(fields[1], fields[2], 1))}px`;
|
|
154
|
+
element.setAttribute('stroke-width', String(first(fields[2], 1)));
|
|
155
|
+
element.setAttribute('stroke-color', fields[3] === 'W' ? 'white' : 'black');
|
|
156
|
+
element.setAttribute('orientation', String(first(fields[4], 'R')));
|
|
157
|
+
result.push(designItem(element, serviceContainer, instanceServiceContainer));
|
|
158
|
+
}
|
|
159
|
+
else if (token.command === 'GE') {
|
|
160
|
+
const element = new ZplGraphicCircle();
|
|
161
|
+
setPosition(element, x, y);
|
|
162
|
+
element.style.width = `${Number(first(fields[0], fields[2], 1))}px`;
|
|
163
|
+
element.style.height = `${Number(first(fields[1], fields[2], 1))}px`;
|
|
164
|
+
element.setAttribute('stroke-width', String(first(fields[2], 1)));
|
|
165
|
+
element.setAttribute('stroke-color', fields[3] === 'W' ? 'white' : 'black');
|
|
166
|
+
result.push(designItem(element, serviceContainer, instanceServiceContainer));
|
|
233
167
|
}
|
|
168
|
+
else if (token.command === 'XG') {
|
|
169
|
+
const name = fields[0].replace(/^[A-Z]:/i, '');
|
|
170
|
+
const graphic = graphics.get(name);
|
|
171
|
+
if (!graphic)
|
|
172
|
+
continue;
|
|
173
|
+
const element = new ZplImage();
|
|
174
|
+
setPosition(element, x, y);
|
|
175
|
+
element.setAttribute('total-bytes', String(graphic.totalBytes));
|
|
176
|
+
element.setAttribute('bytes-per-row', String(graphic.bytesPerRow));
|
|
177
|
+
element.setAttribute('image-name', name);
|
|
178
|
+
element.setAttribute('hex-image', graphic.hexData);
|
|
179
|
+
element.setAttribute('scale-x', String(first(fields[1], 1)));
|
|
180
|
+
element.setAttribute('scale-y', String(first(fields[2], 1)));
|
|
181
|
+
result.push(designItem(element, serviceContainer, instanceServiceContainer));
|
|
182
|
+
}
|
|
183
|
+
else if (token.command === 'FX' && !validMetadataComments.has(token.data)) {
|
|
184
|
+
const element = new ZplComment();
|
|
185
|
+
setPosition(element, x, y);
|
|
186
|
+
element.setAttribute('content', token.data);
|
|
187
|
+
result.push(designItem(element, serviceContainer, instanceServiceContainer));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
for (const payload of hidden) {
|
|
191
|
+
const hiddenItems = await this._parse(payload.zpl, serviceContainer, instanceServiceContainer, false);
|
|
192
|
+
for (const item of hiddenItems)
|
|
193
|
+
item._withoutUndoSetAttribute(hideAtRunTimeAttributeName, '');
|
|
194
|
+
result.splice(Math.min(payload.index, result.length), 0, ...hiddenItems);
|
|
234
195
|
}
|
|
235
|
-
return
|
|
196
|
+
return result;
|
|
236
197
|
}
|
|
237
|
-
write(textWriter, designItems,
|
|
238
|
-
|
|
239
|
-
for (
|
|
240
|
-
if (
|
|
241
|
-
|
|
242
|
-
textWriter.writeLine(d.element.createZplImage());
|
|
243
|
-
//@ts-ignore
|
|
244
|
-
tx += d.element.createZplImage() + '\n';
|
|
198
|
+
write(textWriter, designItems, _rootContainerKeepInline, updatePositions) {
|
|
199
|
+
textWriter.writeLine('^XA');
|
|
200
|
+
for (const designItem of designItems) {
|
|
201
|
+
if (!designItem.hideAtRunTime && designItem.element instanceof ZplImage) {
|
|
202
|
+
textWriter.writeLine(designItem.element.createZplImage());
|
|
245
203
|
}
|
|
246
204
|
}
|
|
247
|
-
for (let
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
205
|
+
for (let index = 0; index < designItems.length; index++) {
|
|
206
|
+
const designItem = designItems[index];
|
|
207
|
+
const start = textWriter.position;
|
|
208
|
+
if (designItem.hideAtRunTime) {
|
|
209
|
+
const miniLines = ['^XA'];
|
|
210
|
+
if (designItem.element instanceof ZplImage)
|
|
211
|
+
miniLines.push(designItem.element.createZplImage());
|
|
212
|
+
const createZpl = designItem.element.createZpl;
|
|
213
|
+
if (createZpl)
|
|
214
|
+
miniLines.push(createZpl.call(designItem.element));
|
|
215
|
+
miniLines.push('^XZ');
|
|
216
|
+
for (const comment of createHiddenZplComments(index, miniLines.join('\n')))
|
|
217
|
+
textWriter.writeLine(comment);
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
const createZpl = designItem.element.createZpl;
|
|
221
|
+
if (createZpl)
|
|
222
|
+
textWriter.writeLine(createZpl.call(designItem.element));
|
|
223
|
+
}
|
|
224
|
+
const end = textWriter.position;
|
|
225
|
+
if (updatePositions && designItem.instanceServiceContainer.designItemDocumentPositionService) {
|
|
226
|
+
designItem.instanceServiceContainer.designItemDocumentPositionService.setPosition(designItem, { start, length: end - start });
|
|
262
227
|
}
|
|
263
228
|
}
|
|
264
|
-
textWriter.writeLine(
|
|
229
|
+
textWriter.writeLine('^XZ');
|
|
265
230
|
}
|
|
266
231
|
}
|