GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: bars, line and print check follow the data the printer encodes · u8array/ZPLab@37ce700

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages
    • core/src
      • lib
        • barcodeDims.ts
        • barcodeHri.ts
        • barcodeRawGeometry.test.ts
        • barcodeRawGeometry.ts
        • firmwareData.test.ts
        • firmwareData.ts
        • zplParser
          • flushField.ts
      • registry
        • barcode1d.ts
        • codabar.ts
        • code39.ts
        • code93.ts
        • ean13.ts
        • ean8.ts
        • firmwareRules.ts
        • hriFormatters.ts
        • logmars.ts
        • planet.ts
        • plessey.ts
        • upcEanExtension.ts
        • upca.ts
        • upce.ts
      • types
        • ObjectType.ts
        • ZplEmit.ts
    • headless/src
      • tools.test.ts
    • server/src
      • app.test.ts
  • src
    • components/Canvas
      • BarcodeObject.tsx
    • lib
      • eanUpcValidate.ts
    • registry
      • hriFormatters.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/core/src/lib/barcodeDims.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/lib/barcodeDims.ts
+9-27Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { LabelObject } from "../types/Group";
77
import { errorMessage } from "./errorMessage";
88
import { clampCodablockColumns, CODABLOCK_PREVIEW_COLUMNS_MIN } from "../registry/codablock";
99
import { EC_PERCENT_MIN, EC_PERCENT_MAX } from "../registry/aztec";
10-
import { upceData6FromFd } from "../registry/hriFormatters";
10+
import { firmwareData } from "./firmwareData";
1111
import type { Gs1DatabarProps } from "../registry/gs1databar";
1212
import { isAxisSwapped, objectRotation } from "../registry/rotation";
1313
import { dotsToPx, mmToDots, pxToDots } from "./coordinates";
@@ -221,14 +221,9 @@ export interface EanUpcHriFragment {
221221
xModule: number;
222222
}
223223

224-
/** bwip raw geometry (bars + HRI text) for an EAN/UPC symbol. UPC-E
225-
* accepts 6-digit content but bwip rejects it, so pre-pad with the
226-
* number-system digit as the firmware does. Shared by the bars and HRI
227-
* paths so both encode the identical symbol. */
224+
/** bwip raw geometry of the EAN/UPC symbol, shared by the bars and the HRI line. */
228225
export function rawEanUpc(bwip: BwipEngine, type: EanUpcType, text: string): BwipRawLinear | null {
229-
// UPC-E: always feed bwip the canonical 7-digit form (NS 0 + 6 data),
230-
// NS-aware so a content that already carries the prefix is not doubled.
231-
const encoded = type === "upce" ? `0${upceData6FromFd(text)}` : text;
226+
const encoded = firmwareData(type, text);
232227
try {
233228
const stack = bwip.raw({ bcid: type, text: encoded, includetext: true }) as BwipRawLinear[];
234229
return stack?.[0] ?? null;
@@ -268,14 +263,7 @@ export function buildBwipOptions(
268263
case "upce": {
269264
const p = obj.props;
270265
const scale = bwipScale1D(p.moduleWidth, renderScale, renderDpmm);
271-
let text: string;
272-
if (obj.type === "upce") {
273-
const r = p.content || "000000";
274-
text = r.length === 6 ? `0${r}` : r;
275-
} else {
276-
text = p.content || "0";
277-
}
278-
opts = { bcid, text, scale, height: 10 };
266+
opts = { bcid, text: firmwareData(obj.type, p.content) || "0", scale, height: 10 };
279267
break;
280268
}
281269
case "code49": {
@@ -304,7 +292,7 @@ export function buildBwipOptions(
304292
// bwip splits ^BS into ean2/ean5 by length; non-2 falls back to ean5.
305293
// HRI rendered as separate Konva overlay (Zebra puts it above bars)
306294
// so rotation lands at the firmware anchor.
307-
const text = p.content || "00000";
295+
const text = firmwareData(obj.type, p.content) || "00000";
308296
const variantBcid = text.length === 2 ? "ean2" : "ean5";
309297
opts = {
310298
bcid: variantBcid,
@@ -343,10 +331,7 @@ export function buildBwipOptions(
343331
case "codabar": {
344332
const p = obj.props;
345333
const scale = bwipScale1D(p.moduleWidth, renderScale, renderDpmm);
346-
// Zebra silently uppercases for these symbologies; bwip-js throws.
347-
const needsUpper = obj.type === "code39" || obj.type === "codabar";
348-
const raw = p.content || "0";
349-
const text = needsUpper ? raw.toUpperCase() : raw;
334+
const text = firmwareData(obj.type, p.content || "0");
350335
// ^B3/^B2 e encode Mod 43 / Mod 10 into the bars (ZD230-measured: +1
351336
// char / +1 digit pair). Codabar's e-slot is a spec-fixed N and the
352337
// 2of5 pair has no check param.
@@ -360,7 +345,7 @@ export function buildBwipOptions(
360345
const scale = bwipScale1D(p.moduleWidth, renderScale, renderDpmm);
361346
// Zebra ^BA always encodes the C+K check chars; the ZPL e param only
362347
// gates the HRI. Without includecheck bwip's symbol is 18 modules short.
363-
opts = { bcid, text: p.content || "0", scale, height: 10, includecheck: true };
348+
opts = { bcid, text: firmwareData(obj.type, p.content || "0"), scale, height: 10, includecheck: true };
364349
break;
365350
}
366351
case "code11": {
@@ -393,10 +378,9 @@ export function buildBwipOptions(
393378
case "logmars": {
394379
const p = obj.props;
395380
const scale = bwipScale1D(p.moduleWidth, renderScale, renderDpmm);
396-
// LOGMARS is a Code39 subset; same uppercase rule applies.
397381
opts = {
398382
bcid,
399-
text: (p.content || "0").toUpperCase(),
383+
text: firmwareData(obj.type, p.content || "0"),
400384
scale,
401385
height: 10,
402386
includecheck: true,
@@ -1124,9 +1108,7 @@ export function barcodeEncodeIssueWith(
11241108
function encodeFailureReason(bwip: BwipEngine, obj: LeafObject, dpmm: number): string {
11251109
try {
11261110
if (EAN_UPC_TYPES.has(obj.type)) {
1127-
const text = getObjectStringContent(obj) ?? "";
1128-
const encoded = obj.type === "upce" ? `0${upceData6FromFd(text)}` : text;
1129-
bwip.raw({ bcid: obj.type, text: encoded, includetext: true });
1111+
bwip.raw({ bcid: obj.type, text: firmwareData(obj.type, getObjectStringContent(obj) ?? ""), includetext: true });
11301112
return "the encoder produced no symbol for this payload";
11311113
}
11321114
// barcodeDimsPx routes these past buildBwipOptions, so their missing BCID
Collapse file

‎packages/core/src/lib/barcodeHri.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/lib/barcodeHri.ts
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Pure HRI text-zone resolution shared by the barcode renderer (getDisplaySize)
22
// and the group-rotation bbox probe, so zone height and side never drift apart.
33

4-
import { isGs1Active, ObjectRegistry, type LeafObject } from "../registry";
4+
import { getEntry, isGs1Active, ObjectRegistry, type LeafObject } from "../registry";
5+
import type { HriFormatProps } from "../types/ZplEmit";
6+
import { firmwareData } from "./firmwareData";
57
import {
68
EAN_TEXT_ZONE_DOTS,
79
LOGMARS_TEXT_ZONE_DOTS,
@@ -61,6 +63,11 @@ export function hriZoneDots(moduleWidth: number): number {
6163
return 7 * (Math.max(1, Math.round(moduleWidth)) + 1);
6264
}
6365

66+
/** The line text: the type's own format, else the data the firmware encodes. */
67+
export function hriText(type: string, content: string, props?: HriFormatProps): string {
68+
return getEntry(type)?.hri?.formatHri?.(content, props) ?? firmwareData(type, content);
69+
}
70+
6471
/** Firmware-reserved HRI text-zone height in dots. ^BS reserves it only when
6572
* printInterpretation is on; other EAN/UPC reserve the fixed guard zone always;
6673
* the rest reserve a module-scaled line, but only with the line turned on. */
Collapse file

‎packages/core/src/lib/barcodeRawGeometry.test.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/lib/barcodeRawGeometry.test.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe("zebraWidthBarText", () => {
1414
expect(zebraWidthBarText("plessey", "")).toBe("0");
1515
});
1616

17-
it("pads PLANET like firmware (11/13 digits) and strips non-digits", () => {
17+
it("fills PLANET to 11 or 13 digits and strips non-digits", () => {
1818
expect(zebraWidthBarText("planet", "12345678")).toBe("00012345678");
1919
expect(zebraWidthBarText("planet", "123456789012")).toBe("0123456789012");
2020
expect(zebraWidthBarText("planet", "1a2b3")).toBe("00000000123");
Collapse file

‎packages/core/src/lib/barcodeRawGeometry.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/lib/barcodeRawGeometry.ts
+3-10Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
import { PLESSEY_RATIO } from "../registry/plessey";
12+
import { firmwareData } from "./firmwareData";
1213

1314
export interface RawBarRect {
1415
x: number;
@@ -30,17 +31,9 @@ export const ZEBRA_WIDTH_BAR_TYPES: ReadonlySet<string> = new Set(
3031
Object.keys(ZEBRA_WIDTH_BCID),
3132
);
3233

33-
/** Encode text per type: Plessey uppercases like firmware, PLANET strips to
34-
* digits and pads to 11/13, POSTNET stays verbatim (bwip throws on
35-
* non-digits, which is the encode error the preflight surfaces; stripping
36-
* would silently encode a shorter symbol). */
34+
/** The text the bars encode. Empty content becomes "0". */
3735
export function zebraWidthBarText(type: ZebraWidthBarType, content: string): string {
38-
if (type === "plessey") return (content || "0").toUpperCase();
39-
if (type === "postal") return content || "0";
40-
let text = (content || "0").replace(/\D/g, "") || "0";
41-
if (text.length < 11) text = text.padStart(11, "0");
42-
else if (text.length === 12) text = text.padStart(13, "0");
43-
return text;
36+
return firmwareData(type, content || "0");
4437
}
4538

4639
/** First entry of a bwipjs.raw() stack; absorbs the per-site double cast
Collapse file

‎packages/core/src/lib/firmwareData.test.ts‎

Copy file name to clipboard
+73Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { describe, expect, it } from "vitest";
2+
import bwipjs from "bwip-js/generic";
3+
import { getEntry, type LeafObject } from "../registry";
4+
import { barcodeEncodeIssueWith, type BwipEngine } from "./barcodeDims";
5+
import { hriText } from "./barcodeHri";
6+
import { firmwareData } from "./firmwareData";
7+
8+
describe("firmwareData", () => {
9+
// Each row is a ZD230 preview of the right-hand data.
10+
it.each<[string, string, string]>([
11+
["ean13", "12345", "000000012345"],
12+
["ean13", "5901234123450", "590123412345"],
13+
["ean8", "123", "0000123"],
14+
["ean8", "12345679", "1234567"],
15+
["upca", "123", "00000000123"],
16+
["upca", "123456789019", "12345678901"],
17+
["upcEanExtension", "1", "01"],
18+
["upcEanExtension", "123", "00123"],
19+
["upcEanExtension", "1234", "01234"],
20+
["upcEanExtension", "123456", "12345"],
21+
["upcEanExtension", "1234567", "12345"],
22+
["code39", "abc", "ABC"],
23+
["code93", "abc", "ABC"],
24+
["logmars", "abc", "ABC"],
25+
["codabar", "a123b", "A123B"],
26+
["plessey", "ab12", "AB12"],
27+
])("reads %s data %s as %s", (type, typed, encoded) => {
28+
expect(firmwareData(type, typed)).toBe(encoded);
29+
});
30+
31+
it("uppercases a to z and leaves other letters", () => {
32+
expect(firmwareData("code93", "stra" + String.fromCharCode(223) + "e")).toBe("STRA" + String.fromCharCode(223) + "E");
33+
});
34+
35+
it.each(["code93", "codabar", "plessey"])("shows the encoded data in the %s line", (type) => {
36+
expect(hriText(type, "ab12")).toBe("AB12");
37+
});
38+
39+
it.each(["123", "12a3"])("shows PLANET data %s without the fill in the line", (typed) => {
40+
expect(hriText("planet", typed)).toBe("123");
41+
});
42+
43+
it.each<[string, string]>([
44+
["ean13", "12345678901234"],
45+
["ean8", "123456789"],
46+
["upca", "1234567890123"],
47+
["ean13", "12A45"],
48+
["ean13", ""],
49+
])("leaves %s data %s as typed, where the printer prints something else or nothing", (type, typed) => {
50+
expect(firmwareData(type, typed)).toBe(typed);
51+
});
52+
});
53+
54+
describe("the print check on data the firmware adjusts", () => {
55+
const leaf = (type: string, content: string) =>
56+
({ id: "x", type, x: 0, y: 0, rotation: 0, props: { ...(getEntry(type)?.defaultProps as object), content } }) as unknown as LeafObject;
57+
58+
it.each<[string, string]>([
59+
["ean13", "12345"],
60+
["ean13", "5901234123450"],
61+
["ean8", "123"],
62+
["upca", "123"],
63+
["upcEanExtension", "1"],
64+
["upcEanExtension", "123"],
65+
["code93", "abc"],
66+
])("takes %s data %s, which the printer prints", (type, content) => {
67+
expect(barcodeEncodeIssueWith(bwipjs as unknown as BwipEngine, leaf(type, content), 8)).toBeNull();
68+
});
69+
70+
it("refuses an EAN-13 that is two digits too long", () => {
71+
expect(barcodeEncodeIssueWith(bwipjs as unknown as BwipEngine, leaf("ean13", "12345678901234"), 8)).not.toBeNull();
72+
});
73+
});
Collapse file

‎packages/core/src/lib/firmwareData.ts‎

Copy file name to clipboard
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { getEntry } from "../registry";
2+
3+
/** The data the firmware encodes from a field, per the registry rule. */
4+
export function firmwareData(type: string, content: string): string {
5+
return getEntry(type)?.firmwareData?.(content) ?? content;
6+
}
Collapse file

‎packages/core/src/lib/zplParser/flushField.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/lib/zplParser/flushField.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import type { MaxicodeProps } from "../../registry/maxicode";
4343
import type { MicroPdf417Props } from "../../registry/micropdf417";
4444
import type { CodablockProps } from "../../registry/codablock";
4545
import type { Tlc39Props } from "../../registry/tlc39";
46-
import { upceData6FromFd } from "../../registry/hriFormatters";
46+
import { upceData6FromFd } from "../../registry/firmwareRules";
4747
import { decodeFH, makeObj, variableNameFromComment } from "./helpers";
4848
import { notePartial,
4949
getPosType,
Collapse file

‎packages/core/src/registry/barcode1d.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/registry/barcode1d.ts
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ export interface Barcode1DCoreConfig<P extends Barcode1DProps = Barcode1DProps>
5656
interpretationLocked?: boolean;
5757
/** See {@link HriBehavior}. */
5858
hri?: HriBehavior;
59+
/** See {@link ObjectTypeCore.firmwareData}. */
60+
firmwareData?: (content: string) => string;
5961
/** Transform stored content into the ^FD payload (e.g. UPC-E prepends
6062
* the number-system digit the spec requires). Default: identity. */
6163
fdContent?: (content: string) => string;
@@ -153,6 +155,7 @@ export function createBarcode1DCore<P extends Barcode1DProps = Barcode1DProps>(
153155
heightLocked: config.heightLocked,
154156
interpretationLocked: config.interpretationLocked,
155157
hri: config.hri,
158+
firmwareData: config.firmwareData,
156159
// GS1 mode swaps in the shared GS1 element-string spec; the static half
157160
// stays the symbology's own rule.
158161
contentSpec: config.gs1Capable
Collapse file

‎packages/core/src/registry/codabar.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/registry/codabar.ts
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { BARCODE_1D_PROP_SPECS, createBarcode1DCore, type Barcode1DCoreConfig } from './barcode1d';
2+
import { upperAZ } from './firmwareRules';
23
export type { Barcode1DProps as CodabarProps } from "./barcode1d";
34

45
export const codabarCoreConfig: Barcode1DCoreConfig = {
56
label: "Codabar",
67
icon: "CBA",
78
placeholderContent: 'A12345A',
9+
firmwareData: upperAZ,
810
group: 'legacy',
911
propSpecs: BARCODE_1D_PROP_SPECS,
1012
zplCommand: (p) => {
Collapse file

‎packages/core/src/registry/code39.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/registry/code39.ts
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { BARCODE_1D_PROP_SPECS, createBarcode1DCore, type Barcode1DCoreConfig } from './barcode1d';
2+
import { upperAZ } from './firmwareRules';
23
import { formatCode39Hri } from './hriFormatters';
34
export type { Barcode1DProps as Code39Props } from './barcode1d';
45

56
export const code39CoreConfig: Barcode1DCoreConfig = {
67
label: 'Code 39',
78
icon: '|·|',
89
placeholderContent: 'CODE39',
10+
firmwareData: upperAZ,
911
group: 'code-1d',
1012
propSpecs: BARCODE_1D_PROP_SPECS,
1113
zplCommand: (p) => {

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.