@bobfrankston/brother-label 1.0.13 → 1.0.14
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 +20 -3
- package/api.d.ts +11 -0
- package/api.d.ts.map +1 -1
- package/api.js +105 -0
- package/api.js.map +1 -1
- package/api.ts +110 -0
- package/cli.js +219 -79
- package/cli.js.map +1 -1
- package/cli.ts +221 -61
- package/index.d.ts +1 -1
- package/index.d.ts.map +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/index.ts +3 -0
- package/package.json +3 -3
- package/brother-print.d.ts +0 -3
- package/brother-print.d.ts.map +0 -1
- package/brother-print.js +0 -629
- package/brother-print.js.map +0 -1
- package/brother-print.ts +0 -697
package/README.md
CHANGED
|
@@ -35,6 +35,14 @@ Use `<img qr="data">` to embed QR codes directly in HTML - they're converted to
|
|
|
35
35
|
<img qr="any data here" class="my-qr">
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
+
### Multi-segment labels
|
|
39
|
+
Combine multiple `-text` and `-qr` segments on a single label, printed side-by-side in order:
|
|
40
|
+
```bash
|
|
41
|
+
brother-print -text "Hello" -qr "https://example.com"
|
|
42
|
+
brother-print -text "Top\nBottom" -qr "https://example.com" -text "More text"
|
|
43
|
+
brother-print -t "Label" -q "data" -o combined.png
|
|
44
|
+
```
|
|
45
|
+
|
|
38
46
|
### Print image
|
|
39
47
|
```bash
|
|
40
48
|
brother-print image photo.png
|
|
@@ -48,7 +56,7 @@ brother-print preview "Test Label" -o preview.png
|
|
|
48
56
|
### Configuration
|
|
49
57
|
```bash
|
|
50
58
|
brother-print config --show # Show current config
|
|
51
|
-
brother-print config -
|
|
59
|
+
brother-print config -s 12 # Set default tape size
|
|
52
60
|
brother-print config -p "Brother PT-P710BT" # Set default printer
|
|
53
61
|
brother-print list # List Brother printers
|
|
54
62
|
```
|
|
@@ -56,10 +64,17 @@ brother-print list # List Brother printers
|
|
|
56
64
|
### Options
|
|
57
65
|
| Option | Description |
|
|
58
66
|
|--------|-------------|
|
|
67
|
+
| `-t, --text` | Force input as literal text; repeatable for multi-segment labels |
|
|
68
|
+
| `-q, --qr` | QR code segment; repeatable for multi-segment labels |
|
|
69
|
+
| `-s, --tape <size>` | Tape size: 6, 9, 12, 18, 24 (mm) |
|
|
59
70
|
| `-p, --printer <name>` | Printer name |
|
|
60
|
-
| `-t, --tape <size>` | Tape size: 6mm, 9mm, 12mm, 18mm, 24mm, or 'auto' |
|
|
61
|
-
| `-l, --label <text>` | Text label beside QR code (qr command only) |
|
|
62
71
|
| `-o, --output <file>` | Save to file instead of printing |
|
|
72
|
+
| `-a, --aspect <ratio>` | Aspect ratio width:height for HTML (e.g., 3.5:2) |
|
|
73
|
+
| `-H, --height <size>` | Text height: 12mm, .5in, or 50% (of tape height) |
|
|
74
|
+
| `-w, --html` | Force input as HTML file path |
|
|
75
|
+
| `-i, --image` | Force input as image file path |
|
|
76
|
+
|
|
77
|
+
Single-hyphen long options are supported: `-text` works the same as `--text`, `-tape` as `--tape`, etc. Single letters are strict: `-t` means `--text`, not the start of `-tape`.
|
|
63
78
|
|
|
64
79
|
## API Usage
|
|
65
80
|
|
|
@@ -175,6 +190,8 @@ interface PrintResult {
|
|
|
175
190
|
|----------|-------------|
|
|
176
191
|
| `print(options)` | Render and print a label |
|
|
177
192
|
| `render(options)` | Render label to PNG buffer |
|
|
193
|
+
| `renderSegments(segments, tape?, textHeight?)` | Render multiple text/qr segments side-by-side |
|
|
194
|
+
| `printSegments(segments, options?)` | Render and print multiple segments |
|
|
178
195
|
| `getConfig()` | Get current configuration |
|
|
179
196
|
| `setConfig(config)` | Set default tape/printer |
|
|
180
197
|
| `getConfigPath()` | Get config file path |
|
package/api.d.ts
CHANGED
|
@@ -31,10 +31,21 @@ export interface PrintOptions {
|
|
|
31
31
|
export interface PrintResult {
|
|
32
32
|
image: Buffer;
|
|
33
33
|
}
|
|
34
|
+
export interface Segment {
|
|
35
|
+
type: "text" | "qr";
|
|
36
|
+
value: string;
|
|
37
|
+
}
|
|
34
38
|
export declare function getConfig(): PrinterConfig;
|
|
35
39
|
export declare function setConfig(config: Partial<PrinterConfig>): void;
|
|
36
40
|
export declare function getConfigPath(): string;
|
|
37
41
|
export declare function listPrinters(): Promise<PrinterInfo[]>;
|
|
38
42
|
export declare function render(options: PrintOptions): Promise<Buffer>;
|
|
39
43
|
export declare function print(options: PrintOptions): Promise<PrintResult>;
|
|
44
|
+
export declare function renderSegments(segments: Segment[], tape?: TapeSize, textHeight?: string, space?: string): Promise<Buffer>;
|
|
45
|
+
export declare function printSegments(segments: Segment[], options?: {
|
|
46
|
+
tape?: TapeSize;
|
|
47
|
+
printer?: string;
|
|
48
|
+
textHeight?: string;
|
|
49
|
+
space?: string;
|
|
50
|
+
}): Promise<PrintResult>;
|
|
40
51
|
//# sourceMappingURL=api.d.ts.map
|
package/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["api.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AAC5C,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,UAAU,CAAC;AAEnD,MAAM,WAAW,aAAa;IAC1B,WAAW,CAAC,EAAE,QAAQ,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,WAAW;IACxB,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,YAAY;IAEzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,EAAE,CAAC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CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAOnK"}
|
package/api.js
CHANGED
|
@@ -129,6 +129,39 @@ function resolveSettings(options) {
|
|
|
129
129
|
printer: options.printer ?? config.defaultPrinter ?? DEFAULT_PRINTER,
|
|
130
130
|
};
|
|
131
131
|
}
|
|
132
|
+
// Parse a size spec (12px, 1mm, .2in, 50%) to pixels
|
|
133
|
+
function parseSize(spec, referencePx) {
|
|
134
|
+
const trimmed = spec.trim().toLowerCase();
|
|
135
|
+
if (trimmed.endsWith("px")) {
|
|
136
|
+
const px = parseFloat(trimmed.slice(0, -2));
|
|
137
|
+
if (isNaN(px) || px < 0)
|
|
138
|
+
throw new Error(`Invalid size: ${spec}`);
|
|
139
|
+
return Math.round(px);
|
|
140
|
+
}
|
|
141
|
+
if (trimmed.endsWith("%")) {
|
|
142
|
+
const pct = parseFloat(trimmed.slice(0, -1));
|
|
143
|
+
if (isNaN(pct) || pct < 0)
|
|
144
|
+
throw new Error(`Invalid size: ${spec}`);
|
|
145
|
+
return Math.round(referencePx * pct / 100);
|
|
146
|
+
}
|
|
147
|
+
if (trimmed.endsWith("mm")) {
|
|
148
|
+
const mm = parseFloat(trimmed.slice(0, -2));
|
|
149
|
+
if (isNaN(mm) || mm < 0)
|
|
150
|
+
throw new Error(`Invalid size: ${spec}`);
|
|
151
|
+
return Math.round(mm * PRINT_DPI / 25.4);
|
|
152
|
+
}
|
|
153
|
+
if (trimmed.endsWith("in")) {
|
|
154
|
+
const inches = parseFloat(trimmed.slice(0, -2));
|
|
155
|
+
if (isNaN(inches) || inches < 0)
|
|
156
|
+
throw new Error(`Invalid size: ${spec}`);
|
|
157
|
+
return Math.round(inches * PRINT_DPI);
|
|
158
|
+
}
|
|
159
|
+
// Bare number → pixels
|
|
160
|
+
const px = parseFloat(trimmed);
|
|
161
|
+
if (!isNaN(px) && px >= 0)
|
|
162
|
+
return Math.round(px);
|
|
163
|
+
throw new Error(`Invalid size: ${spec}. Use "12px", "1mm", ".2in", or "50%"`);
|
|
164
|
+
}
|
|
132
165
|
// Parse text height spec to pixels
|
|
133
166
|
function parseTextHeight(spec, tapeHeightPx) {
|
|
134
167
|
const trimmed = spec.trim().toLowerCase();
|
|
@@ -413,4 +446,76 @@ export async function print(options) {
|
|
|
413
446
|
await printBuffer(image, printer, tape);
|
|
414
447
|
return { image };
|
|
415
448
|
}
|
|
449
|
+
// Render multiple segments side-by-side into a single image
|
|
450
|
+
export async function renderSegments(segments, tape, textHeight, space) {
|
|
451
|
+
const config = getConfig();
|
|
452
|
+
const effectiveTape = tape ?? config.defaultTape ?? 24;
|
|
453
|
+
const tapeSize = TAPE_SIZES[effectiveTape];
|
|
454
|
+
// Render each segment individually
|
|
455
|
+
const buffers = [];
|
|
456
|
+
for (const seg of segments) {
|
|
457
|
+
if (seg.type === "text") {
|
|
458
|
+
buffers.push(await renderText(seg.value, effectiveTape, textHeight));
|
|
459
|
+
}
|
|
460
|
+
else {
|
|
461
|
+
buffers.push(await renderQr(seg.value, effectiveTape));
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
if (buffers.length === 1) {
|
|
465
|
+
return buffers[0];
|
|
466
|
+
}
|
|
467
|
+
// Load all rendered images and trim horizontal whitespace
|
|
468
|
+
const images = [];
|
|
469
|
+
for (const buf of buffers) {
|
|
470
|
+
const img = await Jimp.read(buf);
|
|
471
|
+
// Find leftmost and rightmost non-white columns to trim padding
|
|
472
|
+
let left = img.width;
|
|
473
|
+
let right = 0;
|
|
474
|
+
for (let x = 0; x < img.width; x++) {
|
|
475
|
+
for (let y = 0; y < img.height; y++) {
|
|
476
|
+
const pixel = img.getPixelColor(x, y);
|
|
477
|
+
if (pixel !== 0xffffffff) {
|
|
478
|
+
if (x < left)
|
|
479
|
+
left = x;
|
|
480
|
+
if (x > right)
|
|
481
|
+
right = x;
|
|
482
|
+
break;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
if (right >= left) {
|
|
487
|
+
const margin = 4; // small margin around content
|
|
488
|
+
const cropLeft = Math.max(0, left - margin);
|
|
489
|
+
const cropRight = Math.min(img.width - 1, right + margin);
|
|
490
|
+
const cropWidth = cropRight - cropLeft + 1;
|
|
491
|
+
img.crop({ x: cropLeft, y: 0, w: cropWidth, h: img.height });
|
|
492
|
+
}
|
|
493
|
+
images.push({ img, width: img.width, height: img.height });
|
|
494
|
+
}
|
|
495
|
+
// Composite left-to-right
|
|
496
|
+
const gap = space ? parseSize(space, tapeSize.height) : 2;
|
|
497
|
+
let totalWidth = 0;
|
|
498
|
+
for (let i = 0; i < images.length; i++) {
|
|
499
|
+
totalWidth += images[i].width;
|
|
500
|
+
if (i < images.length - 1)
|
|
501
|
+
totalWidth += gap;
|
|
502
|
+
}
|
|
503
|
+
const canvas = new Jimp({ width: totalWidth, height: tapeSize.height, color: 0xffffffff });
|
|
504
|
+
let x = 0;
|
|
505
|
+
for (let i = 0; i < images.length; i++) {
|
|
506
|
+
const yOffset = Math.round((tapeSize.height - images[i].height) / 2);
|
|
507
|
+
canvas.composite(images[i].img, x, yOffset);
|
|
508
|
+
x += images[i].width + gap;
|
|
509
|
+
}
|
|
510
|
+
return canvas.getBuffer("image/png");
|
|
511
|
+
}
|
|
512
|
+
// Print multiple segments as a single label
|
|
513
|
+
export async function printSegments(segments, options) {
|
|
514
|
+
const config = getConfig();
|
|
515
|
+
const tape = options?.tape ?? config.defaultTape ?? 24;
|
|
516
|
+
const printer = options?.printer ?? config.defaultPrinter ?? DEFAULT_PRINTER;
|
|
517
|
+
const image = await renderSegments(segments, tape, options?.textHeight, options?.space);
|
|
518
|
+
await printBuffer(image, printer, tape);
|
|
519
|
+
return { image };
|
|
520
|
+
}
|
|
416
521
|
//# sourceMappingURL=api.js.map
|
package/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["api.ts"],"names":[],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C,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;gBACnB,MAAM,CAAC,IAAI,KAAK,CAAC,oBAAoB,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YACzD,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;YAAS,CAAC;QACP,IAAI,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC1B,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAC5B,CAAC;IACL,CAAC;AACL,CAAC;AAED,qBAAqB;AACrB,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,OAAqB;IAC9C,eAAe,CAAC,OAAO,CAAC,CAAC;IACzB,MAAM,EAAE,IAAI,EAAE,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;IAC1C,OAAO,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,OAAqB;IAC7C,eAAe,CAAC,OAAO,CAAC,CAAC;IACzB,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;IACnD,MAAM,KAAK,GAAG,MAAM,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACjD,MAAM,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IACxC,OAAO,EAAE,KAAK,EAAE,CAAC;AACrB,CAAC","sourcesContent":["/**\r\n * Brother Label Printer API\r\n * Programmatic interface for printing labels on Brother P-touch printers\r\n */\r\n\r\nimport * as fs from \"fs\";\r\nimport * as path from \"path\";\r\nimport { fileURLToPath } from \"url\";\r\nimport * as os from \"os\";\r\nimport { renderHtmlFile, renderHtmlString, closeBrowser } from \"./render.js\";\r\nimport { Jimp, loadFont, measureText, measureTextHeight } from \"jimp\";\r\nimport { spawn } from \"child_process\";\r\nimport QRCode from \"qrcode\";\r\n\r\n// Types\r\nexport type TapeSize = 6 | 9 | 12 | 18 | 24;\r\nexport type Orientation = \"landscape\" | \"portrait\";\r\n\r\nexport interface PrinterConfig {\r\n defaultTape?: TapeSize;\r\n defaultPrinter?: string;\r\n}\r\n\r\nexport interface PrinterInfo {\r\n name: string;\r\n}\r\n\r\nexport interface PrintOptions {\r\n // Content (exactly one required)\r\n text?: string;\r\n html?: string;\r\n htmlPath?: string;\r\n textFile?: string;\r\n imagePath?: string;\r\n imageBuffer?: Buffer;\r\n qr?: string; // QR code data to encode\r\n\r\n // Settings\r\n tape?: TapeSize;\r\n printer?: string;\r\n orientation?: Orientation;\r\n length?: number; // explicit length in mm\r\n basePath?: string; // base path for inline HTML resources\r\n aspect?: string; // width:height ratio for HTML (e.g., \"3.5:2\")\r\n qrLabel?: string; // optional text label beside QR code\r\n textHeight?: string; // text height: \"12mm\", \".5in\", \"50%\" (of tape height)\r\n}\r\n\r\nexport interface PrintResult {\r\n image: Buffer;\r\n}\r\n\r\n// Constants\r\nconst CONFIG_PATH = path.join(os.homedir(), \".brother-label.json\");\r\nconst DEFAULT_PRINTER = \"Brother PT-P710BT\";\r\nconst PRINT_DPI = 300; // High resolution for quality output\r\n\r\n// Tape sizes: height is printable area in pixels at 300 DPI\r\nconst TAPE_SIZES: Record<TapeSize, { width: number; height: number }> = {\r\n 6: { width: 1137, height: 56 }, // 3.79\" x 0.19\" @ 300 DPI\r\n 9: { width: 1137, height: 84 }, // 3.79\" x 0.28\" @ 300 DPI\r\n 12: { width: 1137, height: 113 }, // 3.79\" x 0.38\" @ 300 DPI\r\n 18: { width: 1137, height: 169 }, // 3.79\" x 0.56\" @ 300 DPI\r\n 24: { width: 1137, height: 213 }, // 3.79\" x 0.71\" @ 300 DPI\r\n};\r\n\r\n// Brother CustomMediaSize names and widths in microns\r\nconst MEDIA_OPTIONS: Record<TapeSize, { name: string; width: number }> = {\r\n 6: { name: \"CustomMediaSize257\", width: 5900 },\r\n 9: { name: \"CustomMediaSize258\", width: 9000 },\r\n 12: { name: \"CustomMediaSize259\", width: 11900 },\r\n 18: { name: \"CustomMediaSize260\", width: 18100 },\r\n 24: { name: \"CustomMediaSize261\", width: 24000 },\r\n};\r\n\r\n// Config functions\r\nexport function getConfig(): PrinterConfig {\r\n try {\r\n if (fs.existsSync(CONFIG_PATH)) {\r\n const raw = JSON.parse(fs.readFileSync(CONFIG_PATH, \"utf-8\"));\r\n // Handle legacy format where tape was stored as \"24mm\" string\r\n if (typeof raw.defaultTape === \"string\") {\r\n raw.defaultTape = parseInt(raw.defaultTape.replace(\"mm\", \"\"), 10) as TapeSize;\r\n }\r\n return raw;\r\n }\r\n } catch {\r\n // Ignore config errors\r\n }\r\n return {};\r\n}\r\n\r\nexport function setConfig(config: Partial<PrinterConfig>): void {\r\n const current = getConfig();\r\n const merged = { ...current, ...config };\r\n fs.writeFileSync(CONFIG_PATH, JSON.stringify(merged, null, 2));\r\n}\r\n\r\nexport function getConfigPath(): string {\r\n return CONFIG_PATH;\r\n}\r\n\r\n// Printer listing\r\nexport async function listPrinters(): Promise<PrinterInfo[]> {\r\n return new Promise((resolve, reject) => {\r\n const ps = spawn(\"powershell\", [\r\n \"-Command\",\r\n \"Get-Printer | Where-Object { $_.Name -like '*Brother*' -or $_.Name -like '*PT*' -or $_.Name -like '*QL*' } | Select-Object -ExpandProperty Name\"\r\n ], { stdio: \"pipe\" });\r\n\r\n let stdout = \"\";\r\n let stderr = \"\";\r\n ps.stdout.on(\"data\", (data) => { stdout += data.toString(); });\r\n ps.stderr.on(\"data\", (data) => { stderr += data.toString(); });\r\n\r\n ps.on(\"close\", (code) => {\r\n if (code !== 0) {\r\n reject(new Error(`Failed to list printers: ${stderr}`));\r\n return;\r\n }\r\n const printers = stdout.trim().split(\"\\n\")\r\n .filter(p => p.trim())\r\n .map(name => ({ name: name.trim() }));\r\n resolve(printers);\r\n });\r\n });\r\n}\r\n\r\n// Calculate HTML viewport dimensions from tape height and optional aspect ratio\r\nfunction getHtmlDimensions(tapeHeight: number, aspect?: string): { width?: number; height: number } {\r\n if (!aspect) {\r\n // Auto-detect width from content\r\n return { width: undefined, height: tapeHeight };\r\n }\r\n\r\n // Parse aspect ratio \"width:height\" or \"width/height\" (e.g., \"3.5:2\" or \"3.5/2\")\r\n const separator = aspect.includes(\"/\") ? \"/\" : \":\";\r\n const parts = aspect.split(separator);\r\n if (parts.length !== 2) {\r\n throw new Error(`Invalid aspect ratio: ${aspect}. Use format \"width:height\" or \"width/height\"`);\r\n }\r\n const aspectWidth = parseFloat(parts[0]);\r\n const aspectHeight = parseFloat(parts[1]);\r\n if (isNaN(aspectWidth) || isNaN(aspectHeight) || aspectHeight === 0) {\r\n throw new Error(`Invalid aspect ratio: ${aspect}. Use format \"width:height\" (e.g., \"3.5:2\")`);\r\n }\r\n\r\n // Scale so height fits tape, width is proportional\r\n const height = tapeHeight;\r\n const width = Math.round(tapeHeight * (aspectWidth / aspectHeight));\r\n return { width, height };\r\n}\r\n\r\n// Validation\r\nfunction validateOptions(options: PrintOptions): void {\r\n const contentFields = [\r\n options.text,\r\n options.html,\r\n options.htmlPath,\r\n options.textFile,\r\n options.imagePath,\r\n options.imageBuffer,\r\n options.qr,\r\n ].filter(f => f !== undefined);\r\n\r\n if (contentFields.length === 0) {\r\n throw new Error(\"No content provided. Specify one of: text, html, htmlPath, textFile, imagePath, imageBuffer, qr\");\r\n }\r\n if (contentFields.length > 1) {\r\n throw new Error(\"Multiple content options provided. Specify exactly one.\");\r\n }\r\n\r\n if (options.tape !== undefined && !TAPE_SIZES[options.tape]) {\r\n throw new Error(`Invalid tape size: ${options.tape}. Valid sizes: 6, 9, 12, 18, 24`);\r\n }\r\n}\r\n\r\n// Resolve effective settings from options + config + defaults\r\nfunction resolveSettings(options: PrintOptions): { tape: TapeSize; printer: string } {\r\n const config = getConfig();\r\n return {\r\n tape: options.tape ?? config.defaultTape ?? 24,\r\n printer: options.printer ?? config.defaultPrinter ?? DEFAULT_PRINTER,\r\n };\r\n}\r\n\r\n// Parse text height spec to pixels\r\nfunction parseTextHeight(spec: string, tapeHeightPx: number): number {\r\n const trimmed = spec.trim().toLowerCase();\r\n if (trimmed.endsWith(\"%\")) {\r\n const pct = parseFloat(trimmed.slice(0, -1));\r\n if (isNaN(pct) || pct <= 0) throw new Error(`Invalid text height: ${spec}`);\r\n return Math.round(tapeHeightPx * pct / 100);\r\n }\r\n if (trimmed.endsWith(\"mm\")) {\r\n const mm = parseFloat(trimmed.slice(0, -2));\r\n if (isNaN(mm) || mm <= 0) throw new Error(`Invalid text height: ${spec}`);\r\n return Math.round(mm * PRINT_DPI / 25.4);\r\n }\r\n if (trimmed.endsWith(\"in\")) {\r\n const inches = parseFloat(trimmed.slice(0, -2));\r\n if (isNaN(inches) || inches <= 0) throw new Error(`Invalid text height: ${spec}`);\r\n return Math.round(inches * PRINT_DPI);\r\n }\r\n throw new Error(`Invalid text height: ${spec}. Use \"12mm\", \".5in\", or \"50%\"`);\r\n}\r\n\r\n// Render text to image buffer\r\nasync function renderText(text: string, tape: TapeSize, textHeightSpec?: string): Promise<Buffer> {\r\n const tapeSize = TAPE_SIZES[tape];\r\n const targetHeight = textHeightSpec\r\n ? Math.min(parseTextHeight(textHeightSpec, tapeSize.height), tapeSize.height)\r\n : tapeSize.height;\r\n const lines = text.split(\"\\\\n\").join(\"\\n\");\r\n\r\n // Load largest font for quality\r\n const fontDir = path.join(path.dirname(fileURLToPath(import.meta.url)), \"node_modules/@jimp/plugin-print/fonts/open-sans\");\r\n const fontPath = path.join(fontDir, \"open-sans-128-black\", \"open-sans-128-black.fnt\");\r\n const font = await loadFont(fontPath);\r\n\r\n // Measure text\r\n const textWidth = measureText(font, lines);\r\n const textHeight = measureTextHeight(font, lines, textWidth + 100);\r\n\r\n // Create temp image for text\r\n const padding = 10;\r\n const imgWidth = textWidth + padding * 2;\r\n const imgHeight = textHeight + padding * 2;\r\n\r\n const tempImage = new Jimp({ width: imgWidth, height: imgHeight, color: 0xffffffff });\r\n tempImage.print({ font, x: padding, y: padding, text: lines });\r\n\r\n // Scale to fit tape height\r\n const scale = targetHeight / imgHeight;\r\n const finalWidth = Math.round(imgWidth * scale);\r\n const finalHeight = Math.round(imgHeight * scale);\r\n tempImage.resize({ w: finalWidth, h: finalHeight });\r\n\r\n // Create final image with padding\r\n const canvasHeight = tapeSize.height;\r\n const hPadding = Math.round(canvasHeight * 0.2);\r\n const outputWidth = finalWidth + hPadding * 2;\r\n const image = new Jimp({ width: outputWidth, height: canvasHeight, color: 0xffffffff });\r\n\r\n const xOffset = hPadding;\r\n const yOffset = Math.round((canvasHeight - finalHeight) / 2);\r\n image.composite(tempImage, xOffset, yOffset);\r\n\r\n return image.getBuffer(\"image/png\");\r\n}\r\n\r\n// Render QR code to image buffer\r\nasync function renderQr(data: string, tape: TapeSize, labelText?: string): Promise<Buffer> {\r\n const tapeSize = TAPE_SIZES[tape];\r\n const targetHeight = tapeSize.height;\r\n const qrSize = Math.floor(targetHeight * 0.95);\r\n\r\n // Margins in pixels at PRINT_DPI (3mm left, 4mm right)\r\n const pxPerMm = PRINT_DPI / 25.4;\r\n const leftMargin = Math.round(3 * pxPerMm);\r\n const rightMargin = Math.round(4 * pxPerMm);\r\n\r\n // Generate QR code at high resolution\r\n const qrBuffer = await QRCode.toBuffer(data, {\r\n type: \"png\",\r\n width: qrSize,\r\n margin: 0,\r\n errorCorrectionLevel: \"M\",\r\n color: { dark: \"#000000\", light: \"#ffffff\" },\r\n });\r\n\r\n const qrImage = await Jimp.read(qrBuffer);\r\n\r\n if (!labelText) {\r\n // QR only\r\n const outputWidth = leftMargin + qrSize + rightMargin;\r\n const image = new Jimp({ width: outputWidth, height: targetHeight, color: 0xffffffff });\r\n const yOffset = Math.floor((targetHeight - qrSize) / 2);\r\n image.composite(qrImage, leftMargin, yOffset);\r\n return image.getBuffer(\"image/png\");\r\n }\r\n\r\n // QR + text label\r\n const fontDir = path.join(path.dirname(fileURLToPath(import.meta.url)), \"node_modules/@jimp/plugin-print/fonts/open-sans\");\r\n const fontPath = path.join(fontDir, \"open-sans-64-black\", \"open-sans-64-black.fnt\");\r\n const font = await loadFont(fontPath);\r\n\r\n const textWidth = measureText(font, labelText);\r\n const textHeight = measureTextHeight(font, labelText, textWidth + 50);\r\n\r\n // Scale text to fit beside QR\r\n const maxTextHeight = targetHeight * 0.8;\r\n const textScale = Math.min(1, maxTextHeight / textHeight);\r\n const scaledTextWidth = Math.round(textWidth * textScale);\r\n const scaledTextHeight = Math.round(textHeight * textScale);\r\n\r\n // Create text image\r\n const textImg = new Jimp({ width: textWidth + 20, height: textHeight + 20, color: 0xffffffff });\r\n textImg.print({ font, x: 10, y: 10, text: labelText });\r\n if (textScale < 1) {\r\n textImg.resize({ w: scaledTextWidth, h: scaledTextHeight });\r\n }\r\n\r\n // Compose: QR on left, text on right\r\n const gap = Math.floor(targetHeight * 0.15);\r\n const outputWidth = leftMargin + qrSize + gap + scaledTextWidth + rightMargin;\r\n const image = new Jimp({ width: outputWidth, height: targetHeight, color: 0xffffffff });\r\n\r\n const qrY = Math.floor((targetHeight - qrSize) / 2);\r\n image.composite(qrImage, leftMargin, qrY);\r\n\r\n const textY = Math.floor((targetHeight - scaledTextHeight) / 2);\r\n image.composite(textImg, leftMargin + qrSize + gap, textY);\r\n\r\n return image.getBuffer(\"image/png\");\r\n}\r\n\r\n// Render content to image buffer\r\nasync function renderContent(options: PrintOptions, tape: TapeSize): Promise<Buffer> {\r\n const tapeSize = TAPE_SIZES[tape];\r\n\r\n if (options.text !== undefined) {\r\n return renderText(options.text, tape, options.textHeight);\r\n }\r\n\r\n if (options.textFile !== undefined) {\r\n const text = fs.readFileSync(options.textFile, \"utf-8\");\r\n return renderText(text, tape, options.textHeight);\r\n }\r\n\r\n if (options.html !== undefined) {\r\n const { width, height } = getHtmlDimensions(tapeSize.height, options.aspect);\r\n const buffer = await renderHtmlString(options.html, { width, height, tapeMm: tape }, options.basePath);\r\n await closeBrowser();\r\n return buffer;\r\n }\r\n\r\n if (options.htmlPath !== undefined) {\r\n const { width, height } = getHtmlDimensions(tapeSize.height, options.aspect);\r\n const buffer = await renderHtmlFile(options.htmlPath, { width, height, tapeMm: tape });\r\n await closeBrowser();\r\n return buffer;\r\n }\r\n\r\n if (options.imagePath !== undefined) {\r\n return fs.readFileSync(options.imagePath);\r\n }\r\n\r\n if (options.imageBuffer !== undefined) {\r\n return options.imageBuffer;\r\n }\r\n\r\n if (options.qr !== undefined) {\r\n return renderQr(options.qr, tape, options.qrLabel);\r\n }\r\n\r\n throw new Error(\"No content to render\");\r\n}\r\n\r\n// Print single image buffer to printer\r\nasync function printBuffer(imageBuffer: Buffer, printer: string, tape: TapeSize): Promise<void> {\r\n const media = MEDIA_OPTIONS[tape];\r\n\r\n const tempPath = path.join(os.tmpdir(), `label-${Date.now()}.png`);\r\n fs.writeFileSync(tempPath, imageBuffer);\r\n\r\n try {\r\n await new Promise<void>((resolve, reject) => {\r\n const psScript = `\r\nAdd-Type -AssemblyName System.Drawing\r\nAdd-Type -AssemblyName System.Printing\r\nAdd-Type -AssemblyName ReachFramework\r\nAdd-Type -AssemblyName PresentationCore\r\n\r\n$img = [System.Drawing.Image]::FromFile('${tempPath.replace(/\\\\/g, \"\\\\\\\\\")}')\r\n\r\n$DPI = ${PRINT_DPI}\r\n$MICRONS_PER_INCH = 25400\r\n\r\n$labelLengthMicrons = [int]($img.Width / $DPI * $MICRONS_PER_INCH) + 3000 # +2mm offset +1mm buffer\r\n$tapeWidthMicrons = ${media.width}\r\n\r\n$imgWidthWpf = $img.Width / $DPI * 96\r\n$imgHeightWpf = $img.Height / $DPI * 96\r\n\r\n$ticketXml = @\"\r\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<psf:PrintTicket xmlns:psf=\"http://schemas.microsoft.com/windows/2003/08/printing/printschemaframework\"\r\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" version=\"1\"\r\n xmlns:psk=\"http://schemas.microsoft.com/windows/2003/08/printing/printschemakeywords\"\r\n xmlns:ns0001=\"http://schemas.brother.info/mfc/printing/2006/11/printschemakeywords\">\r\n <psf:Feature name=\"psk:PageMediaSize\">\r\n <psf:Option name=\"ns0001:${media.name}\">\r\n <psf:ScoredProperty name=\"psk:MediaSizeWidth\">\r\n <psf:Value xsi:type=\"xsd:integer\">${media.width}</psf:Value>\r\n </psf:ScoredProperty>\r\n <psf:ScoredProperty name=\"psk:MediaSizeHeight\">\r\n <psf:ParameterRef name=\"psk:PageMediaSizeMediaSizeHeight\" />\r\n </psf:ScoredProperty>\r\n </psf:Option>\r\n </psf:Feature>\r\n <psf:ParameterInit name=\"psk:PageMediaSizeMediaSizeHeight\">\r\n <psf:Value xsi:type=\"xsd:integer\">$labelLengthMicrons</psf:Value>\r\n </psf:ParameterInit>\r\n <psf:Feature name=\"psk:PageOrientation\">\r\n <psf:Option name=\"psk:Landscape\" />\r\n </psf:Feature>\r\n <psf:Feature name=\"ns0001:PageRollFeedToEndOfSheet\">\r\n <psf:Option name=\"ns0001:FeedToImageEdge\" />\r\n </psf:Feature>\r\n <psf:Feature name=\"psk:PageMediaType\">\r\n <psf:Option name=\"psk:Label\" />\r\n </psf:Feature>\r\n <psf:Feature name=\"ns0001:JobRollCutAtEndOfJob\">\r\n <psf:Option name=\"ns0001:Cut\" />\r\n </psf:Feature>\r\n</psf:PrintTicket>\r\n\"@\r\n\r\n$xmlBytes = [System.Text.Encoding]::UTF8.GetBytes($ticketXml)\r\n$memStream = New-Object System.IO.MemoryStream(,$xmlBytes)\r\n$ticket = New-Object System.Printing.PrintTicket($memStream)\r\n\r\n$server = New-Object System.Printing.LocalPrintServer\r\n$queue = $server.GetPrintQueue('${printer}')\r\n\r\n$xpsPath = [System.IO.Path]::GetTempFileName() + \".xps\"\r\n\r\n$pageWidth = $labelLengthMicrons / $MICRONS_PER_INCH * 96\r\n$pageHeight = $tapeWidthMicrons / $MICRONS_PER_INCH * 96\r\n\r\n$package = [System.IO.Packaging.Package]::Open($xpsPath, [System.IO.FileMode]::Create)\r\n$xpsDoc = New-Object System.Windows.Xps.Packaging.XpsDocument($package)\r\n$writer = [System.Windows.Xps.Packaging.XpsDocument]::CreateXpsDocumentWriter($xpsDoc)\r\n\r\n$visual = New-Object System.Windows.Media.DrawingVisual\r\n$dc = $visual.RenderOpen()\r\n\r\n$bitmapImg = New-Object System.Windows.Media.Imaging.BitmapImage\r\n$bitmapImg.BeginInit()\r\n$bitmapImg.UriSource = New-Object System.Uri('${tempPath.replace(/\\\\/g, \"\\\\\\\\\")}')\r\n$bitmapImg.EndInit()\r\n\r\n$yOffset = ($pageHeight - $imgHeightWpf) / 2\r\n$xOffset = 2 / 25.4 * 96 # 2mm left margin in WPF units\r\n$rect = New-Object System.Windows.Rect($xOffset, $yOffset, $imgWidthWpf, $imgHeightWpf)\r\n$dc.DrawImage($bitmapImg, $rect)\r\n$dc.Close()\r\n\r\n$writer.Write($visual, $ticket)\r\n\r\n$xpsDoc.Close()\r\n$package.Close()\r\n$img.Dispose()\r\n\r\n$xpsDocForPrint = New-Object System.Windows.Xps.Packaging.XpsDocument($xpsPath, [System.IO.FileAccess]::Read)\r\n$seq = $xpsDocForPrint.GetFixedDocumentSequence()\r\n\r\n$xpsWriter = [System.Printing.PrintQueue]::CreateXpsDocumentWriter($queue)\r\n$xpsWriter.Write($seq, $ticket)\r\n\r\n$xpsDocForPrint.Close()\r\nRemove-Item $xpsPath -ErrorAction SilentlyContinue\r\n`;\r\n\r\n const ps = spawn(\"powershell\", [\"-Command\", psScript], { stdio: \"pipe\" });\r\n\r\n let stdout = \"\";\r\n let stderr = \"\";\r\n ps.stdout.on(\"data\", (data) => { stdout += data.toString(); });\r\n ps.stderr.on(\"data\", (data) => { stderr += data.toString(); });\r\n\r\n ps.on(\"close\", (code) => {\r\n if (code === 0) {\r\n resolve();\r\n } else {\r\n reject(new Error(`Print failed: ${stderr}`));\r\n }\r\n });\r\n\r\n ps.on(\"error\", (err) => {\r\n reject(new Error(`Failed to print: ${err.message}`));\r\n });\r\n });\r\n } finally {\r\n if (fs.existsSync(tempPath)) {\r\n fs.unlinkSync(tempPath);\r\n }\r\n }\r\n}\r\n\r\n// Main API functions\r\nexport async function render(options: PrintOptions): Promise<Buffer> {\r\n validateOptions(options);\r\n const { tape } = resolveSettings(options);\r\n return renderContent(options, tape);\r\n}\r\n\r\nexport async function print(options: PrintOptions): Promise<PrintResult> {\r\n validateOptions(options);\r\n const { tape, printer } = resolveSettings(options);\r\n const image = await renderContent(options, tape);\r\n await printBuffer(image, printer, tape);\r\n return { image };\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["api.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AACtE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,MAAM,MAAM,QAAQ,CAAC;AA6C5B,YAAY;AACZ,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,qBAAqB,CAAC,CAAC;AACnE,MAAM,eAAe,GAAG,mBAAmB,CAAC;AAC5C,MAAM,SAAS,GAAG,GAAG,CAAC,CAAE,qCAAqC;AAE7D,4DAA4D;AAC5D,MAAM,UAAU,GAAwD;IACpE,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAM,0BAA0B;IAC9D,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,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AAC;QACrC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QACrE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAU,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;QACnD,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,GAAG,CAAC;IAC/B,CAAC;IAED,OAAO,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;AACzC,CAAC;AAED,4CAA4C;AAC5C,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,QAAmB,EAAE,OAAoF;IACzI,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,MAAM,IAAI,GAAa,OAAO,EAAE,IAAI,IAAI,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC;IACjE,MAAM,OAAO,GAAW,OAAO,EAAE,OAAO,IAAI,MAAM,CAAC,cAAc,IAAI,eAAe,CAAC;IACrF,MAAM,KAAK,GAAG,MAAM,cAAc,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IACxF,MAAM,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IACxC,OAAO,EAAE,KAAK,EAAE,CAAC;AACrB,CAAC","sourcesContent":["/**\r\n * Brother Label Printer API\r\n * Programmatic interface for printing labels on Brother P-touch printers\r\n */\r\n\r\nimport * as fs from \"fs\";\r\nimport * as path from \"path\";\r\nimport { fileURLToPath } from \"url\";\r\nimport * as os from \"os\";\r\nimport { renderHtmlFile, renderHtmlString, closeBrowser } from \"./render.js\";\r\nimport { Jimp, loadFont, measureText, measureTextHeight } from \"jimp\";\r\nimport { spawn } from \"child_process\";\r\nimport QRCode from \"qrcode\";\r\n\r\n// Types\r\nexport type TapeSize = 6 | 9 | 12 | 18 | 24;\r\nexport type Orientation = \"landscape\" | \"portrait\";\r\n\r\nexport interface PrinterConfig {\r\n defaultTape?: TapeSize;\r\n defaultPrinter?: string;\r\n}\r\n\r\nexport interface PrinterInfo {\r\n name: string;\r\n}\r\n\r\nexport interface PrintOptions {\r\n // Content (exactly one required)\r\n text?: string;\r\n html?: string;\r\n htmlPath?: string;\r\n textFile?: string;\r\n imagePath?: string;\r\n imageBuffer?: Buffer;\r\n qr?: string; // QR code data to encode\r\n\r\n // Settings\r\n tape?: TapeSize;\r\n printer?: string;\r\n orientation?: Orientation;\r\n length?: number; // explicit length in mm\r\n basePath?: string; // base path for inline HTML resources\r\n aspect?: string; // width:height ratio for HTML (e.g., \"3.5:2\")\r\n qrLabel?: string; // optional text label beside QR code\r\n textHeight?: string; // text height: \"12mm\", \".5in\", \"50%\" (of tape height)\r\n}\r\n\r\nexport interface PrintResult {\r\n image: Buffer;\r\n}\r\n\r\nexport interface Segment {\r\n type: \"text\" | \"qr\";\r\n value: string;\r\n}\r\n\r\n// Constants\r\nconst CONFIG_PATH = path.join(os.homedir(), \".brother-label.json\");\r\nconst DEFAULT_PRINTER = \"Brother PT-P710BT\";\r\nconst PRINT_DPI = 300; // High resolution for quality output\r\n\r\n// Tape sizes: height is printable area in pixels at 300 DPI\r\nconst TAPE_SIZES: Record<TapeSize, { width: number; height: number }> = {\r\n 6: { width: 1137, height: 56 }, // 3.79\" x 0.19\" @ 300 DPI\r\n 9: { width: 1137, height: 84 }, // 3.79\" x 0.28\" @ 300 DPI\r\n 12: { width: 1137, height: 113 }, // 3.79\" x 0.38\" @ 300 DPI\r\n 18: { width: 1137, height: 169 }, // 3.79\" x 0.56\" @ 300 DPI\r\n 24: { width: 1137, height: 213 }, // 3.79\" x 0.71\" @ 300 DPI\r\n};\r\n\r\n// Brother CustomMediaSize names and widths in microns\r\nconst MEDIA_OPTIONS: Record<TapeSize, { name: string; width: number }> = {\r\n 6: { name: \"CustomMediaSize257\", width: 5900 },\r\n 9: { name: \"CustomMediaSize258\", width: 9000 },\r\n 12: { name: \"CustomMediaSize259\", width: 11900 },\r\n 18: { name: \"CustomMediaSize260\", width: 18100 },\r\n 24: { name: \"CustomMediaSize261\", width: 24000 },\r\n};\r\n\r\n// Config functions\r\nexport function getConfig(): PrinterConfig {\r\n try {\r\n if (fs.existsSync(CONFIG_PATH)) {\r\n const raw = JSON.parse(fs.readFileSync(CONFIG_PATH, \"utf-8\"));\r\n // Handle legacy format where tape was stored as \"24mm\" string\r\n if (typeof raw.defaultTape === \"string\") {\r\n raw.defaultTape = parseInt(raw.defaultTape.replace(\"mm\", \"\"), 10) as TapeSize;\r\n }\r\n return raw;\r\n }\r\n } catch {\r\n // Ignore config errors\r\n }\r\n return {};\r\n}\r\n\r\nexport function setConfig(config: Partial<PrinterConfig>): void {\r\n const current = getConfig();\r\n const merged = { ...current, ...config };\r\n fs.writeFileSync(CONFIG_PATH, JSON.stringify(merged, null, 2));\r\n}\r\n\r\nexport function getConfigPath(): string {\r\n return CONFIG_PATH;\r\n}\r\n\r\n// Printer listing\r\nexport async function listPrinters(): Promise<PrinterInfo[]> {\r\n return new Promise((resolve, reject) => {\r\n const ps = spawn(\"powershell\", [\r\n \"-Command\",\r\n \"Get-Printer | Where-Object { $_.Name -like '*Brother*' -or $_.Name -like '*PT*' -or $_.Name -like '*QL*' } | Select-Object -ExpandProperty Name\"\r\n ], { stdio: \"pipe\" });\r\n\r\n let stdout = \"\";\r\n let stderr = \"\";\r\n ps.stdout.on(\"data\", (data) => { stdout += data.toString(); });\r\n ps.stderr.on(\"data\", (data) => { stderr += data.toString(); });\r\n\r\n ps.on(\"close\", (code) => {\r\n if (code !== 0) {\r\n reject(new Error(`Failed to list printers: ${stderr}`));\r\n return;\r\n }\r\n const printers = stdout.trim().split(\"\\n\")\r\n .filter(p => p.trim())\r\n .map(name => ({ name: name.trim() }));\r\n resolve(printers);\r\n });\r\n });\r\n}\r\n\r\n// Calculate HTML viewport dimensions from tape height and optional aspect ratio\r\nfunction getHtmlDimensions(tapeHeight: number, aspect?: string): { width?: number; height: number } {\r\n if (!aspect) {\r\n // Auto-detect width from content\r\n return { width: undefined, height: tapeHeight };\r\n }\r\n\r\n // Parse aspect ratio \"width:height\" or \"width/height\" (e.g., \"3.5:2\" or \"3.5/2\")\r\n const separator = aspect.includes(\"/\") ? \"/\" : \":\";\r\n const parts = aspect.split(separator);\r\n if (parts.length !== 2) {\r\n throw new Error(`Invalid aspect ratio: ${aspect}. Use format \"width:height\" or \"width/height\"`);\r\n }\r\n const aspectWidth = parseFloat(parts[0]);\r\n const aspectHeight = parseFloat(parts[1]);\r\n if (isNaN(aspectWidth) || isNaN(aspectHeight) || aspectHeight === 0) {\r\n throw new Error(`Invalid aspect ratio: ${aspect}. Use format \"width:height\" (e.g., \"3.5:2\")`);\r\n }\r\n\r\n // Scale so height fits tape, width is proportional\r\n const height = tapeHeight;\r\n const width = Math.round(tapeHeight * (aspectWidth / aspectHeight));\r\n return { width, height };\r\n}\r\n\r\n// Validation\r\nfunction validateOptions(options: PrintOptions): void {\r\n const contentFields = [\r\n options.text,\r\n options.html,\r\n options.htmlPath,\r\n options.textFile,\r\n options.imagePath,\r\n options.imageBuffer,\r\n options.qr,\r\n ].filter(f => f !== undefined);\r\n\r\n if (contentFields.length === 0) {\r\n throw new Error(\"No content provided. Specify one of: text, html, htmlPath, textFile, imagePath, imageBuffer, qr\");\r\n }\r\n if (contentFields.length > 1) {\r\n throw new Error(\"Multiple content options provided. Specify exactly one.\");\r\n }\r\n\r\n if (options.tape !== undefined && !TAPE_SIZES[options.tape]) {\r\n throw new Error(`Invalid tape size: ${options.tape}. Valid sizes: 6, 9, 12, 18, 24`);\r\n }\r\n}\r\n\r\n// Resolve effective settings from options + config + defaults\r\nfunction resolveSettings(options: PrintOptions): { tape: TapeSize; printer: string } {\r\n const config = getConfig();\r\n return {\r\n tape: options.tape ?? config.defaultTape ?? 24,\r\n printer: options.printer ?? config.defaultPrinter ?? DEFAULT_PRINTER,\r\n };\r\n}\r\n\r\n// Parse a size spec (12px, 1mm, .2in, 50%) to pixels\r\nfunction parseSize(spec: string, referencePx: number): number {\r\n const trimmed = spec.trim().toLowerCase();\r\n if (trimmed.endsWith(\"px\")) {\r\n const px = parseFloat(trimmed.slice(0, -2));\r\n if (isNaN(px) || px < 0) throw new Error(`Invalid size: ${spec}`);\r\n return Math.round(px);\r\n }\r\n if (trimmed.endsWith(\"%\")) {\r\n const pct = parseFloat(trimmed.slice(0, -1));\r\n if (isNaN(pct) || pct < 0) throw new Error(`Invalid size: ${spec}`);\r\n return Math.round(referencePx * pct / 100);\r\n }\r\n if (trimmed.endsWith(\"mm\")) {\r\n const mm = parseFloat(trimmed.slice(0, -2));\r\n if (isNaN(mm) || mm < 0) throw new Error(`Invalid size: ${spec}`);\r\n return Math.round(mm * PRINT_DPI / 25.4);\r\n }\r\n if (trimmed.endsWith(\"in\")) {\r\n const inches = parseFloat(trimmed.slice(0, -2));\r\n if (isNaN(inches) || inches < 0) throw new Error(`Invalid size: ${spec}`);\r\n return Math.round(inches * PRINT_DPI);\r\n }\r\n // Bare number → pixels\r\n const px = parseFloat(trimmed);\r\n if (!isNaN(px) && px >= 0) return Math.round(px);\r\n throw new Error(`Invalid size: ${spec}. Use \"12px\", \"1mm\", \".2in\", or \"50%\"`);\r\n}\r\n\r\n// Parse text height spec to pixels\r\nfunction parseTextHeight(spec: string, tapeHeightPx: number): number {\r\n const trimmed = spec.trim().toLowerCase();\r\n if (trimmed.endsWith(\"%\")) {\r\n const pct = parseFloat(trimmed.slice(0, -1));\r\n if (isNaN(pct) || pct <= 0) throw new Error(`Invalid text height: ${spec}`);\r\n return Math.round(tapeHeightPx * pct / 100);\r\n }\r\n if (trimmed.endsWith(\"mm\")) {\r\n const mm = parseFloat(trimmed.slice(0, -2));\r\n if (isNaN(mm) || mm <= 0) throw new Error(`Invalid text height: ${spec}`);\r\n return Math.round(mm * PRINT_DPI / 25.4);\r\n }\r\n if (trimmed.endsWith(\"in\")) {\r\n const inches = parseFloat(trimmed.slice(0, -2));\r\n if (isNaN(inches) || inches <= 0) throw new Error(`Invalid text height: ${spec}`);\r\n return Math.round(inches * PRINT_DPI);\r\n }\r\n throw new Error(`Invalid text height: ${spec}. Use \"12mm\", \".5in\", or \"50%\"`);\r\n}\r\n\r\n// Render text to image buffer\r\nasync function renderText(text: string, tape: TapeSize, textHeightSpec?: string): Promise<Buffer> {\r\n const tapeSize = TAPE_SIZES[tape];\r\n const targetHeight = textHeightSpec\r\n ? Math.min(parseTextHeight(textHeightSpec, tapeSize.height), tapeSize.height)\r\n : tapeSize.height;\r\n const lines = text.split(\"\\\\n\").join(\"\\n\");\r\n\r\n // Load largest font for quality\r\n const fontDir = path.join(path.dirname(fileURLToPath(import.meta.url)), \"node_modules/@jimp/plugin-print/fonts/open-sans\");\r\n const fontPath = path.join(fontDir, \"open-sans-128-black\", \"open-sans-128-black.fnt\");\r\n const font = await loadFont(fontPath);\r\n\r\n // Measure text\r\n const textWidth = measureText(font, lines);\r\n const textHeight = measureTextHeight(font, lines, textWidth + 100);\r\n\r\n // Create temp image for text\r\n const padding = 10;\r\n const imgWidth = textWidth + padding * 2;\r\n const imgHeight = textHeight + padding * 2;\r\n\r\n const tempImage = new Jimp({ width: imgWidth, height: imgHeight, color: 0xffffffff });\r\n tempImage.print({ font, x: padding, y: padding, text: lines });\r\n\r\n // Scale to fit tape height\r\n const scale = targetHeight / imgHeight;\r\n const finalWidth = Math.round(imgWidth * scale);\r\n const finalHeight = Math.round(imgHeight * scale);\r\n tempImage.resize({ w: finalWidth, h: finalHeight });\r\n\r\n // Create final image with padding\r\n const canvasHeight = tapeSize.height;\r\n const hPadding = Math.round(canvasHeight * 0.2);\r\n const outputWidth = finalWidth + hPadding * 2;\r\n const image = new Jimp({ width: outputWidth, height: canvasHeight, color: 0xffffffff });\r\n\r\n const xOffset = hPadding;\r\n const yOffset = Math.round((canvasHeight - finalHeight) / 2);\r\n image.composite(tempImage, xOffset, yOffset);\r\n\r\n return image.getBuffer(\"image/png\");\r\n}\r\n\r\n// Render QR code to image buffer\r\nasync function renderQr(data: string, tape: TapeSize, labelText?: string): Promise<Buffer> {\r\n const tapeSize = TAPE_SIZES[tape];\r\n const targetHeight = tapeSize.height;\r\n const qrSize = Math.floor(targetHeight * 0.95);\r\n\r\n // Margins in pixels at PRINT_DPI (3mm left, 4mm right)\r\n const pxPerMm = PRINT_DPI / 25.4;\r\n const leftMargin = Math.round(3 * pxPerMm);\r\n const rightMargin = Math.round(4 * pxPerMm);\r\n\r\n // Generate QR code at high resolution\r\n const qrBuffer = await QRCode.toBuffer(data, {\r\n type: \"png\",\r\n width: qrSize,\r\n margin: 0,\r\n errorCorrectionLevel: \"M\",\r\n color: { dark: \"#000000\", light: \"#ffffff\" },\r\n });\r\n\r\n const qrImage = await Jimp.read(qrBuffer);\r\n\r\n if (!labelText) {\r\n // QR only\r\n const outputWidth = leftMargin + qrSize + rightMargin;\r\n const image = new Jimp({ width: outputWidth, height: targetHeight, color: 0xffffffff });\r\n const yOffset = Math.floor((targetHeight - qrSize) / 2);\r\n image.composite(qrImage, leftMargin, yOffset);\r\n return image.getBuffer(\"image/png\");\r\n }\r\n\r\n // QR + text label\r\n const fontDir = path.join(path.dirname(fileURLToPath(import.meta.url)), \"node_modules/@jimp/plugin-print/fonts/open-sans\");\r\n const fontPath = path.join(fontDir, \"open-sans-64-black\", \"open-sans-64-black.fnt\");\r\n const font = await loadFont(fontPath);\r\n\r\n const textWidth = measureText(font, labelText);\r\n const textHeight = measureTextHeight(font, labelText, textWidth + 50);\r\n\r\n // Scale text to fit beside QR\r\n const maxTextHeight = targetHeight * 0.8;\r\n const textScale = Math.min(1, maxTextHeight / textHeight);\r\n const scaledTextWidth = Math.round(textWidth * textScale);\r\n const scaledTextHeight = Math.round(textHeight * textScale);\r\n\r\n // Create text image\r\n const textImg = new Jimp({ width: textWidth + 20, height: textHeight + 20, color: 0xffffffff });\r\n textImg.print({ font, x: 10, y: 10, text: labelText });\r\n if (textScale < 1) {\r\n textImg.resize({ w: scaledTextWidth, h: scaledTextHeight });\r\n }\r\n\r\n // Compose: QR on left, text on right\r\n const gap = Math.floor(targetHeight * 0.15);\r\n const outputWidth = leftMargin + qrSize + gap + scaledTextWidth + rightMargin;\r\n const image = new Jimp({ width: outputWidth, height: targetHeight, color: 0xffffffff });\r\n\r\n const qrY = Math.floor((targetHeight - qrSize) / 2);\r\n image.composite(qrImage, leftMargin, qrY);\r\n\r\n const textY = Math.floor((targetHeight - scaledTextHeight) / 2);\r\n image.composite(textImg, leftMargin + qrSize + gap, textY);\r\n\r\n return image.getBuffer(\"image/png\");\r\n}\r\n\r\n// Render content to image buffer\r\nasync function renderContent(options: PrintOptions, tape: TapeSize): Promise<Buffer> {\r\n const tapeSize = TAPE_SIZES[tape];\r\n\r\n if (options.text !== undefined) {\r\n return renderText(options.text, tape, options.textHeight);\r\n }\r\n\r\n if (options.textFile !== undefined) {\r\n const text = fs.readFileSync(options.textFile, \"utf-8\");\r\n return renderText(text, tape, options.textHeight);\r\n }\r\n\r\n if (options.html !== undefined) {\r\n const { width, height } = getHtmlDimensions(tapeSize.height, options.aspect);\r\n const buffer = await renderHtmlString(options.html, { width, height, tapeMm: tape }, options.basePath);\r\n await closeBrowser();\r\n return buffer;\r\n }\r\n\r\n if (options.htmlPath !== undefined) {\r\n const { width, height } = getHtmlDimensions(tapeSize.height, options.aspect);\r\n const buffer = await renderHtmlFile(options.htmlPath, { width, height, tapeMm: tape });\r\n await closeBrowser();\r\n return buffer;\r\n }\r\n\r\n if (options.imagePath !== undefined) {\r\n return fs.readFileSync(options.imagePath);\r\n }\r\n\r\n if (options.imageBuffer !== undefined) {\r\n return options.imageBuffer;\r\n }\r\n\r\n if (options.qr !== undefined) {\r\n return renderQr(options.qr, tape, options.qrLabel);\r\n }\r\n\r\n throw new Error(\"No content to render\");\r\n}\r\n\r\n// Print single image buffer to printer\r\nasync function printBuffer(imageBuffer: Buffer, printer: string, tape: TapeSize): Promise<void> {\r\n const media = MEDIA_OPTIONS[tape];\r\n\r\n const tempPath = path.join(os.tmpdir(), `label-${Date.now()}.png`);\r\n fs.writeFileSync(tempPath, imageBuffer);\r\n\r\n try {\r\n await new Promise<void>((resolve, reject) => {\r\n const psScript = `\r\nAdd-Type -AssemblyName System.Drawing\r\nAdd-Type -AssemblyName System.Printing\r\nAdd-Type -AssemblyName ReachFramework\r\nAdd-Type -AssemblyName PresentationCore\r\n\r\n$img = [System.Drawing.Image]::FromFile('${tempPath.replace(/\\\\/g, \"\\\\\\\\\")}')\r\n\r\n$DPI = ${PRINT_DPI}\r\n$MICRONS_PER_INCH = 25400\r\n\r\n$labelLengthMicrons = [int]($img.Width / $DPI * $MICRONS_PER_INCH) + 3000 # +2mm offset +1mm buffer\r\n$tapeWidthMicrons = ${media.width}\r\n\r\n$imgWidthWpf = $img.Width / $DPI * 96\r\n$imgHeightWpf = $img.Height / $DPI * 96\r\n\r\n$ticketXml = @\"\r\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<psf:PrintTicket xmlns:psf=\"http://schemas.microsoft.com/windows/2003/08/printing/printschemaframework\"\r\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" version=\"1\"\r\n xmlns:psk=\"http://schemas.microsoft.com/windows/2003/08/printing/printschemakeywords\"\r\n xmlns:ns0001=\"http://schemas.brother.info/mfc/printing/2006/11/printschemakeywords\">\r\n <psf:Feature name=\"psk:PageMediaSize\">\r\n <psf:Option name=\"ns0001:${media.name}\">\r\n <psf:ScoredProperty name=\"psk:MediaSizeWidth\">\r\n <psf:Value xsi:type=\"xsd:integer\">${media.width}</psf:Value>\r\n </psf:ScoredProperty>\r\n <psf:ScoredProperty name=\"psk:MediaSizeHeight\">\r\n <psf:ParameterRef name=\"psk:PageMediaSizeMediaSizeHeight\" />\r\n </psf:ScoredProperty>\r\n </psf:Option>\r\n </psf:Feature>\r\n <psf:ParameterInit name=\"psk:PageMediaSizeMediaSizeHeight\">\r\n <psf:Value xsi:type=\"xsd:integer\">$labelLengthMicrons</psf:Value>\r\n </psf:ParameterInit>\r\n <psf:Feature name=\"psk:PageOrientation\">\r\n <psf:Option name=\"psk:Landscape\" />\r\n </psf:Feature>\r\n <psf:Feature name=\"ns0001:PageRollFeedToEndOfSheet\">\r\n <psf:Option name=\"ns0001:FeedToImageEdge\" />\r\n </psf:Feature>\r\n <psf:Feature name=\"psk:PageMediaType\">\r\n <psf:Option name=\"psk:Label\" />\r\n </psf:Feature>\r\n <psf:Feature name=\"ns0001:JobRollCutAtEndOfJob\">\r\n <psf:Option name=\"ns0001:Cut\" />\r\n </psf:Feature>\r\n</psf:PrintTicket>\r\n\"@\r\n\r\n$xmlBytes = [System.Text.Encoding]::UTF8.GetBytes($ticketXml)\r\n$memStream = New-Object System.IO.MemoryStream(,$xmlBytes)\r\n$ticket = New-Object System.Printing.PrintTicket($memStream)\r\n\r\n$server = New-Object System.Printing.LocalPrintServer\r\n$queue = $server.GetPrintQueue('${printer}')\r\n\r\n$xpsPath = [System.IO.Path]::GetTempFileName() + \".xps\"\r\n\r\n$pageWidth = $labelLengthMicrons / $MICRONS_PER_INCH * 96\r\n$pageHeight = $tapeWidthMicrons / $MICRONS_PER_INCH * 96\r\n\r\n$package = [System.IO.Packaging.Package]::Open($xpsPath, [System.IO.FileMode]::Create)\r\n$xpsDoc = New-Object System.Windows.Xps.Packaging.XpsDocument($package)\r\n$writer = [System.Windows.Xps.Packaging.XpsDocument]::CreateXpsDocumentWriter($xpsDoc)\r\n\r\n$visual = New-Object System.Windows.Media.DrawingVisual\r\n$dc = $visual.RenderOpen()\r\n\r\n$bitmapImg = New-Object System.Windows.Media.Imaging.BitmapImage\r\n$bitmapImg.BeginInit()\r\n$bitmapImg.UriSource = New-Object System.Uri('${tempPath.replace(/\\\\/g, \"\\\\\\\\\")}')\r\n$bitmapImg.EndInit()\r\n\r\n$yOffset = ($pageHeight - $imgHeightWpf) / 2\r\n$xOffset = 2 / 25.4 * 96 # 2mm left margin in WPF units\r\n$rect = New-Object System.Windows.Rect($xOffset, $yOffset, $imgWidthWpf, $imgHeightWpf)\r\n$dc.DrawImage($bitmapImg, $rect)\r\n$dc.Close()\r\n\r\n$writer.Write($visual, $ticket)\r\n\r\n$xpsDoc.Close()\r\n$package.Close()\r\n$img.Dispose()\r\n\r\n$xpsDocForPrint = New-Object System.Windows.Xps.Packaging.XpsDocument($xpsPath, [System.IO.FileAccess]::Read)\r\n$seq = $xpsDocForPrint.GetFixedDocumentSequence()\r\n\r\n$xpsWriter = [System.Printing.PrintQueue]::CreateXpsDocumentWriter($queue)\r\n$xpsWriter.Write($seq, $ticket)\r\n\r\n$xpsDocForPrint.Close()\r\nRemove-Item $xpsPath -ErrorAction SilentlyContinue\r\n`;\r\n\r\n const ps = spawn(\"powershell\", [\"-Command\", psScript], { stdio: \"pipe\" });\r\n\r\n let stdout = \"\";\r\n let stderr = \"\";\r\n ps.stdout.on(\"data\", (data) => { stdout += data.toString(); });\r\n ps.stderr.on(\"data\", (data) => { stderr += data.toString(); });\r\n\r\n ps.on(\"close\", (code) => {\r\n if (code === 0) {\r\n resolve();\r\n } else {\r\n reject(new Error(`Print failed: ${stderr}`));\r\n }\r\n });\r\n\r\n ps.on(\"error\", (err) => {\r\n reject(new Error(`Failed to print: ${err.message}`));\r\n });\r\n });\r\n } finally {\r\n if (fs.existsSync(tempPath)) {\r\n fs.unlinkSync(tempPath);\r\n }\r\n }\r\n}\r\n\r\n// Main API functions\r\nexport async function render(options: PrintOptions): Promise<Buffer> {\r\n validateOptions(options);\r\n const { tape } = resolveSettings(options);\r\n return renderContent(options, tape);\r\n}\r\n\r\nexport async function print(options: PrintOptions): Promise<PrintResult> {\r\n validateOptions(options);\r\n const { tape, printer } = resolveSettings(options);\r\n const image = await renderContent(options, tape);\r\n await printBuffer(image, printer, tape);\r\n return { image };\r\n}\r\n\r\n// Render multiple segments side-by-side into a single image\r\nexport async function renderSegments(segments: Segment[], tape?: TapeSize, textHeight?: string, space?: string): Promise<Buffer> {\r\n const config = getConfig();\r\n const effectiveTape: TapeSize = tape ?? config.defaultTape ?? 24;\r\n const tapeSize = TAPE_SIZES[effectiveTape];\r\n\r\n // Render each segment individually\r\n const buffers: Buffer[] = [];\r\n for (const seg of segments) {\r\n if (seg.type === \"text\") {\r\n buffers.push(await renderText(seg.value, effectiveTape, textHeight));\r\n } else {\r\n buffers.push(await renderQr(seg.value, effectiveTape));\r\n }\r\n }\r\n\r\n if (buffers.length === 1) {\r\n return buffers[0];\r\n }\r\n\r\n // Load all rendered images and trim horizontal whitespace\r\n const images: Array<{ img: Awaited<ReturnType<typeof Jimp.read>>; width: number; height: number }> = [];\r\n for (const buf of buffers) {\r\n const img = await Jimp.read(buf);\r\n // Find leftmost and rightmost non-white columns to trim padding\r\n let left = img.width;\r\n let right = 0;\r\n for (let x = 0; x < img.width; x++) {\r\n for (let y = 0; y < img.height; y++) {\r\n const pixel = img.getPixelColor(x, y);\r\n if (pixel !== 0xffffffff) {\r\n if (x < left) left = x;\r\n if (x > right) right = x;\r\n break;\r\n }\r\n }\r\n }\r\n if (right >= left) {\r\n const margin = 4; // small margin around content\r\n const cropLeft = Math.max(0, left - margin);\r\n const cropRight = Math.min(img.width - 1, right + margin);\r\n const cropWidth = cropRight - cropLeft + 1;\r\n img.crop({ x: cropLeft, y: 0, w: cropWidth, h: img.height });\r\n }\r\n images.push({ img, width: img.width, height: img.height });\r\n }\r\n\r\n // Composite left-to-right\r\n const gap = space ? parseSize(space, tapeSize.height) : 2;\r\n let totalWidth = 0;\r\n for (let i = 0; i < images.length; i++) {\r\n totalWidth += images[i].width;\r\n if (i < images.length - 1) totalWidth += gap;\r\n }\r\n\r\n const canvas = new Jimp({ width: totalWidth, height: tapeSize.height, color: 0xffffffff });\r\n let x = 0;\r\n for (let i = 0; i < images.length; i++) {\r\n const yOffset = Math.round((tapeSize.height - images[i].height) / 2);\r\n canvas.composite(images[i].img as any, x, yOffset);\r\n x += images[i].width + gap;\r\n }\r\n\r\n return canvas.getBuffer(\"image/png\");\r\n}\r\n\r\n// Print multiple segments as a single label\r\nexport async function printSegments(segments: Segment[], options?: { tape?: TapeSize; printer?: string; textHeight?: string; space?: string }): Promise<PrintResult> {\r\n const config = getConfig();\r\n const tape: TapeSize = options?.tape ?? config.defaultTape ?? 24;\r\n const printer: string = options?.printer ?? config.defaultPrinter ?? DEFAULT_PRINTER;\r\n const image = await renderSegments(segments, tape, options?.textHeight, options?.space);\r\n await printBuffer(image, printer, tape);\r\n return { image };\r\n}\r\n"]}
|
package/api.ts
CHANGED
|
@@ -50,6 +50,11 @@ export interface PrintResult {
|
|
|
50
50
|
image: Buffer;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
export interface Segment {
|
|
54
|
+
type: "text" | "qr";
|
|
55
|
+
value: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
53
58
|
// Constants
|
|
54
59
|
const CONFIG_PATH = path.join(os.homedir(), ".brother-label.json");
|
|
55
60
|
const DEFAULT_PRINTER = "Brother PT-P710BT";
|
|
@@ -184,6 +189,35 @@ function resolveSettings(options: PrintOptions): { tape: TapeSize; printer: stri
|
|
|
184
189
|
};
|
|
185
190
|
}
|
|
186
191
|
|
|
192
|
+
// Parse a size spec (12px, 1mm, .2in, 50%) to pixels
|
|
193
|
+
function parseSize(spec: string, referencePx: number): number {
|
|
194
|
+
const trimmed = spec.trim().toLowerCase();
|
|
195
|
+
if (trimmed.endsWith("px")) {
|
|
196
|
+
const px = parseFloat(trimmed.slice(0, -2));
|
|
197
|
+
if (isNaN(px) || px < 0) throw new Error(`Invalid size: ${spec}`);
|
|
198
|
+
return Math.round(px);
|
|
199
|
+
}
|
|
200
|
+
if (trimmed.endsWith("%")) {
|
|
201
|
+
const pct = parseFloat(trimmed.slice(0, -1));
|
|
202
|
+
if (isNaN(pct) || pct < 0) throw new Error(`Invalid size: ${spec}`);
|
|
203
|
+
return Math.round(referencePx * pct / 100);
|
|
204
|
+
}
|
|
205
|
+
if (trimmed.endsWith("mm")) {
|
|
206
|
+
const mm = parseFloat(trimmed.slice(0, -2));
|
|
207
|
+
if (isNaN(mm) || mm < 0) throw new Error(`Invalid size: ${spec}`);
|
|
208
|
+
return Math.round(mm * PRINT_DPI / 25.4);
|
|
209
|
+
}
|
|
210
|
+
if (trimmed.endsWith("in")) {
|
|
211
|
+
const inches = parseFloat(trimmed.slice(0, -2));
|
|
212
|
+
if (isNaN(inches) || inches < 0) throw new Error(`Invalid size: ${spec}`);
|
|
213
|
+
return Math.round(inches * PRINT_DPI);
|
|
214
|
+
}
|
|
215
|
+
// Bare number → pixels
|
|
216
|
+
const px = parseFloat(trimmed);
|
|
217
|
+
if (!isNaN(px) && px >= 0) return Math.round(px);
|
|
218
|
+
throw new Error(`Invalid size: ${spec}. Use "12px", "1mm", ".2in", or "50%"`);
|
|
219
|
+
}
|
|
220
|
+
|
|
187
221
|
// Parse text height spec to pixels
|
|
188
222
|
function parseTextHeight(spec: string, tapeHeightPx: number): number {
|
|
189
223
|
const trimmed = spec.trim().toLowerCase();
|
|
@@ -503,3 +537,79 @@ export async function print(options: PrintOptions): Promise<PrintResult> {
|
|
|
503
537
|
await printBuffer(image, printer, tape);
|
|
504
538
|
return { image };
|
|
505
539
|
}
|
|
540
|
+
|
|
541
|
+
// Render multiple segments side-by-side into a single image
|
|
542
|
+
export async function renderSegments(segments: Segment[], tape?: TapeSize, textHeight?: string, space?: string): Promise<Buffer> {
|
|
543
|
+
const config = getConfig();
|
|
544
|
+
const effectiveTape: TapeSize = tape ?? config.defaultTape ?? 24;
|
|
545
|
+
const tapeSize = TAPE_SIZES[effectiveTape];
|
|
546
|
+
|
|
547
|
+
// Render each segment individually
|
|
548
|
+
const buffers: Buffer[] = [];
|
|
549
|
+
for (const seg of segments) {
|
|
550
|
+
if (seg.type === "text") {
|
|
551
|
+
buffers.push(await renderText(seg.value, effectiveTape, textHeight));
|
|
552
|
+
} else {
|
|
553
|
+
buffers.push(await renderQr(seg.value, effectiveTape));
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
if (buffers.length === 1) {
|
|
558
|
+
return buffers[0];
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
// Load all rendered images and trim horizontal whitespace
|
|
562
|
+
const images: Array<{ img: Awaited<ReturnType<typeof Jimp.read>>; width: number; height: number }> = [];
|
|
563
|
+
for (const buf of buffers) {
|
|
564
|
+
const img = await Jimp.read(buf);
|
|
565
|
+
// Find leftmost and rightmost non-white columns to trim padding
|
|
566
|
+
let left = img.width;
|
|
567
|
+
let right = 0;
|
|
568
|
+
for (let x = 0; x < img.width; x++) {
|
|
569
|
+
for (let y = 0; y < img.height; y++) {
|
|
570
|
+
const pixel = img.getPixelColor(x, y);
|
|
571
|
+
if (pixel !== 0xffffffff) {
|
|
572
|
+
if (x < left) left = x;
|
|
573
|
+
if (x > right) right = x;
|
|
574
|
+
break;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
if (right >= left) {
|
|
579
|
+
const margin = 4; // small margin around content
|
|
580
|
+
const cropLeft = Math.max(0, left - margin);
|
|
581
|
+
const cropRight = Math.min(img.width - 1, right + margin);
|
|
582
|
+
const cropWidth = cropRight - cropLeft + 1;
|
|
583
|
+
img.crop({ x: cropLeft, y: 0, w: cropWidth, h: img.height });
|
|
584
|
+
}
|
|
585
|
+
images.push({ img, width: img.width, height: img.height });
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
// Composite left-to-right
|
|
589
|
+
const gap = space ? parseSize(space, tapeSize.height) : 2;
|
|
590
|
+
let totalWidth = 0;
|
|
591
|
+
for (let i = 0; i < images.length; i++) {
|
|
592
|
+
totalWidth += images[i].width;
|
|
593
|
+
if (i < images.length - 1) totalWidth += gap;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
const canvas = new Jimp({ width: totalWidth, height: tapeSize.height, color: 0xffffffff });
|
|
597
|
+
let x = 0;
|
|
598
|
+
for (let i = 0; i < images.length; i++) {
|
|
599
|
+
const yOffset = Math.round((tapeSize.height - images[i].height) / 2);
|
|
600
|
+
canvas.composite(images[i].img as any, x, yOffset);
|
|
601
|
+
x += images[i].width + gap;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
return canvas.getBuffer("image/png");
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
// Print multiple segments as a single label
|
|
608
|
+
export async function printSegments(segments: Segment[], options?: { tape?: TapeSize; printer?: string; textHeight?: string; space?: string }): Promise<PrintResult> {
|
|
609
|
+
const config = getConfig();
|
|
610
|
+
const tape: TapeSize = options?.tape ?? config.defaultTape ?? 24;
|
|
611
|
+
const printer: string = options?.printer ?? config.defaultPrinter ?? DEFAULT_PRINTER;
|
|
612
|
+
const image = await renderSegments(segments, tape, options?.textHeight, options?.space);
|
|
613
|
+
await printBuffer(image, printer, tape);
|
|
614
|
+
return { image };
|
|
615
|
+
}
|