label-printer 0.9.1 → 0.10.0
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/dist/index.d.mts +34 -5
- package/dist/index.d.ts +34 -5
- package/dist/index.js +138 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +138 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -102,7 +102,7 @@ interface CommandGenerator<T extends Command> {
|
|
|
102
102
|
line: (start: Point, end: Point, thickness: number) => T;
|
|
103
103
|
image: (image: BitmapLike, x: number, y: number, mode?: GraphicMode) => T;
|
|
104
104
|
qrCode: (content: string, width: number, x: number, y: number) => T;
|
|
105
|
-
barCode: (content: string, x: number, y: number, type: BarcodeType, height: number, rotation: Rotation, humanReadable: BarcodeHumanReable, alignment: Alignment) => T;
|
|
105
|
+
barCode: (content: string, x: number, y: number, type: BarcodeType, height: number, rotation: Rotation, humanReadable: BarcodeHumanReable, alignment: Alignment, barWidth?: number) => T;
|
|
106
106
|
/**
|
|
107
107
|
* Should instruct the printer to display the image of the label on its screen instead of printing it
|
|
108
108
|
*/
|
|
@@ -162,7 +162,7 @@ type LabelDirection = "normal" | "inverse";
|
|
|
162
162
|
type ECCLevel = "L" | "M" | "Q" | "H";
|
|
163
163
|
type AutoManual = "A" | "M";
|
|
164
164
|
type QRModel = "M1" | "M2";
|
|
165
|
-
type BarcodeType = "
|
|
165
|
+
type BarcodeType = "128" | "EAN128" | "25" | "25C" | "39" | "39C" | "93" | "EAN13" | "EAN13+2" | "EAN13+5" | "EAN8" | "EAN8+2" | "EAN8+5" | "CODA" | "POST" | "UPCA" | "UPCA+2" | "UPCA+5" | "UPCE" | "UPCE+2" | "UPCE+5" | "CPOST" | "MSI" | "MSIC" | "PLESSEY" | "ITF14" | "EAN14" | "11" | "TELEPEN" | "TELEPENN" | "PLANET" | "CODE49" | "DPI" | "DPL";
|
|
166
166
|
type BarcodeHumanReable = "none" | "left" | "right" | "center";
|
|
167
167
|
|
|
168
168
|
/**
|
|
@@ -420,7 +420,16 @@ declare class TSPLCommandGenerator implements CommandGenerator<TSPLCommand> {
|
|
|
420
420
|
line(start: Point, end: Point, thickness: number): TSPLCommand;
|
|
421
421
|
image(image: BitmapLike, x: number, y: number, mode?: GraphicMode | undefined): TSPLCommand;
|
|
422
422
|
qrCode(content: string, width: number, x: number, y: number): TSPLCommand;
|
|
423
|
-
barCode(content: string, x: number, y: number, type: BarcodeType, height: number, rotation: Rotation, humanReadable: BarcodeHumanReable, alignment: Alignment): TSPLCommand;
|
|
423
|
+
barCode(content: string, x: number, y: number, type: BarcodeType, height: number, rotation: Rotation, humanReadable: BarcodeHumanReable, alignment: Alignment, barWidth?: number): TSPLCommand;
|
|
424
|
+
/**
|
|
425
|
+
* Calculates the narrow and wide element widths for a barcode type based on the
|
|
426
|
+
* TSPL documentation's standard narrow:wide ratios.
|
|
427
|
+
*
|
|
428
|
+
* Types that only support 1:1 (continuous barcodes like CODE128, EAN, UPC) get
|
|
429
|
+
* narrow === wide. All other types use the 1:3 ratio, which is the industry
|
|
430
|
+
* standard for variable-ratio symbologies (CODE39, ITF14, codabar, MSI…).
|
|
431
|
+
*/
|
|
432
|
+
private static narrowWideFor;
|
|
424
433
|
private cellCount;
|
|
425
434
|
}
|
|
426
435
|
declare const _default: TSPLCommandGenerator;
|
|
@@ -514,6 +523,8 @@ type PrintConfig = {
|
|
|
514
523
|
/** Width of the text in dots */
|
|
515
524
|
textWidth: (text: string, font: FontOption) => number;
|
|
516
525
|
getFontName: (font: FontOption) => string;
|
|
526
|
+
/** Factor to correct text width measurement vs printer rendering (default 1.0, typical 0.9-1.0) */
|
|
527
|
+
textWidthCorrectionFactor: number;
|
|
517
528
|
};
|
|
518
529
|
/**
|
|
519
530
|
* A component that can be directly printed to label printer
|
|
@@ -565,10 +576,18 @@ declare class Label extends Printable {
|
|
|
565
576
|
*/
|
|
566
577
|
private fields;
|
|
567
578
|
private fontCounter;
|
|
579
|
+
private _textWidthCorrectionFactor;
|
|
568
580
|
/**
|
|
569
581
|
* Configuration used when generating commands
|
|
570
582
|
*/
|
|
571
583
|
get printConfig(): PrintConfig;
|
|
584
|
+
/**
|
|
585
|
+
* Sets a correction factor for text width measurement.
|
|
586
|
+
* Values < 1.0 make text wrap less aggressively (more chars per line).
|
|
587
|
+
* Useful when the printer renders text narrower than fontkit measures.
|
|
588
|
+
* @param factor Correction factor (default 1.0, typical range 0.9-1.0)
|
|
589
|
+
*/
|
|
590
|
+
setTextWidthCorrectionFactor(factor: number): void;
|
|
572
591
|
constructor(width: number, height: number, dimensionUnit?: UnitSystem, dpi?: number, density?: number);
|
|
573
592
|
commandForLanguage(language: PrinterLanguage, config?: PrintConfig): Promise<Command>;
|
|
574
593
|
/**
|
|
@@ -653,7 +672,6 @@ declare class Text extends LabelField {
|
|
|
653
672
|
private type;
|
|
654
673
|
private context;
|
|
655
674
|
private readonly lineSpacing;
|
|
656
|
-
private endsWithBreak;
|
|
657
675
|
/**
|
|
658
676
|
* Width of the text.
|
|
659
677
|
* If set, the text will be clipped to this size
|
|
@@ -664,6 +682,7 @@ declare class Text extends LabelField {
|
|
|
664
682
|
* Height of the text box, if empty and the type is multiline, the box can grow infinitely
|
|
665
683
|
*/
|
|
666
684
|
private height;
|
|
685
|
+
private endsWithBreak;
|
|
667
686
|
constructor(content: string, x: number, y: number, formatted?: boolean);
|
|
668
687
|
/**
|
|
669
688
|
* Sets the field to single line
|
|
@@ -720,10 +739,20 @@ declare class BarCode extends LabelField {
|
|
|
720
739
|
private readonly y;
|
|
721
740
|
private readonly type;
|
|
722
741
|
private readonly height;
|
|
742
|
+
private readonly barWidth;
|
|
723
743
|
private rotation;
|
|
724
744
|
private humanReadable;
|
|
725
745
|
private readonly alignment;
|
|
726
|
-
|
|
746
|
+
/**
|
|
747
|
+
* @param content Content to encode
|
|
748
|
+
* @param x X coordinate in dots
|
|
749
|
+
* @param y Y coordinate in dots
|
|
750
|
+
* @param type Barcode symbology
|
|
751
|
+
* @param height Height of the barcode in dots
|
|
752
|
+
* @param barWidth Width of the narrow bar element in dots. The wide element width is
|
|
753
|
+
* calculated automatically based on the symbology's standard ratio.
|
|
754
|
+
*/
|
|
755
|
+
constructor(content: string, x: number, y: number, type: BarcodeType, height: number, barWidth?: number);
|
|
727
756
|
setRotation(rotation: Rotation): void;
|
|
728
757
|
setHumanReadable(humanReadable: BarcodeHumanReable): void;
|
|
729
758
|
commandForLanguage(language: PrinterLanguage, _config?: PrintConfig | undefined): Promise<Command>;
|
package/dist/index.d.ts
CHANGED
|
@@ -102,7 +102,7 @@ interface CommandGenerator<T extends Command> {
|
|
|
102
102
|
line: (start: Point, end: Point, thickness: number) => T;
|
|
103
103
|
image: (image: BitmapLike, x: number, y: number, mode?: GraphicMode) => T;
|
|
104
104
|
qrCode: (content: string, width: number, x: number, y: number) => T;
|
|
105
|
-
barCode: (content: string, x: number, y: number, type: BarcodeType, height: number, rotation: Rotation, humanReadable: BarcodeHumanReable, alignment: Alignment) => T;
|
|
105
|
+
barCode: (content: string, x: number, y: number, type: BarcodeType, height: number, rotation: Rotation, humanReadable: BarcodeHumanReable, alignment: Alignment, barWidth?: number) => T;
|
|
106
106
|
/**
|
|
107
107
|
* Should instruct the printer to display the image of the label on its screen instead of printing it
|
|
108
108
|
*/
|
|
@@ -162,7 +162,7 @@ type LabelDirection = "normal" | "inverse";
|
|
|
162
162
|
type ECCLevel = "L" | "M" | "Q" | "H";
|
|
163
163
|
type AutoManual = "A" | "M";
|
|
164
164
|
type QRModel = "M1" | "M2";
|
|
165
|
-
type BarcodeType = "
|
|
165
|
+
type BarcodeType = "128" | "EAN128" | "25" | "25C" | "39" | "39C" | "93" | "EAN13" | "EAN13+2" | "EAN13+5" | "EAN8" | "EAN8+2" | "EAN8+5" | "CODA" | "POST" | "UPCA" | "UPCA+2" | "UPCA+5" | "UPCE" | "UPCE+2" | "UPCE+5" | "CPOST" | "MSI" | "MSIC" | "PLESSEY" | "ITF14" | "EAN14" | "11" | "TELEPEN" | "TELEPENN" | "PLANET" | "CODE49" | "DPI" | "DPL";
|
|
166
166
|
type BarcodeHumanReable = "none" | "left" | "right" | "center";
|
|
167
167
|
|
|
168
168
|
/**
|
|
@@ -420,7 +420,16 @@ declare class TSPLCommandGenerator implements CommandGenerator<TSPLCommand> {
|
|
|
420
420
|
line(start: Point, end: Point, thickness: number): TSPLCommand;
|
|
421
421
|
image(image: BitmapLike, x: number, y: number, mode?: GraphicMode | undefined): TSPLCommand;
|
|
422
422
|
qrCode(content: string, width: number, x: number, y: number): TSPLCommand;
|
|
423
|
-
barCode(content: string, x: number, y: number, type: BarcodeType, height: number, rotation: Rotation, humanReadable: BarcodeHumanReable, alignment: Alignment): TSPLCommand;
|
|
423
|
+
barCode(content: string, x: number, y: number, type: BarcodeType, height: number, rotation: Rotation, humanReadable: BarcodeHumanReable, alignment: Alignment, barWidth?: number): TSPLCommand;
|
|
424
|
+
/**
|
|
425
|
+
* Calculates the narrow and wide element widths for a barcode type based on the
|
|
426
|
+
* TSPL documentation's standard narrow:wide ratios.
|
|
427
|
+
*
|
|
428
|
+
* Types that only support 1:1 (continuous barcodes like CODE128, EAN, UPC) get
|
|
429
|
+
* narrow === wide. All other types use the 1:3 ratio, which is the industry
|
|
430
|
+
* standard for variable-ratio symbologies (CODE39, ITF14, codabar, MSI…).
|
|
431
|
+
*/
|
|
432
|
+
private static narrowWideFor;
|
|
424
433
|
private cellCount;
|
|
425
434
|
}
|
|
426
435
|
declare const _default: TSPLCommandGenerator;
|
|
@@ -514,6 +523,8 @@ type PrintConfig = {
|
|
|
514
523
|
/** Width of the text in dots */
|
|
515
524
|
textWidth: (text: string, font: FontOption) => number;
|
|
516
525
|
getFontName: (font: FontOption) => string;
|
|
526
|
+
/** Factor to correct text width measurement vs printer rendering (default 1.0, typical 0.9-1.0) */
|
|
527
|
+
textWidthCorrectionFactor: number;
|
|
517
528
|
};
|
|
518
529
|
/**
|
|
519
530
|
* A component that can be directly printed to label printer
|
|
@@ -565,10 +576,18 @@ declare class Label extends Printable {
|
|
|
565
576
|
*/
|
|
566
577
|
private fields;
|
|
567
578
|
private fontCounter;
|
|
579
|
+
private _textWidthCorrectionFactor;
|
|
568
580
|
/**
|
|
569
581
|
* Configuration used when generating commands
|
|
570
582
|
*/
|
|
571
583
|
get printConfig(): PrintConfig;
|
|
584
|
+
/**
|
|
585
|
+
* Sets a correction factor for text width measurement.
|
|
586
|
+
* Values < 1.0 make text wrap less aggressively (more chars per line).
|
|
587
|
+
* Useful when the printer renders text narrower than fontkit measures.
|
|
588
|
+
* @param factor Correction factor (default 1.0, typical range 0.9-1.0)
|
|
589
|
+
*/
|
|
590
|
+
setTextWidthCorrectionFactor(factor: number): void;
|
|
572
591
|
constructor(width: number, height: number, dimensionUnit?: UnitSystem, dpi?: number, density?: number);
|
|
573
592
|
commandForLanguage(language: PrinterLanguage, config?: PrintConfig): Promise<Command>;
|
|
574
593
|
/**
|
|
@@ -653,7 +672,6 @@ declare class Text extends LabelField {
|
|
|
653
672
|
private type;
|
|
654
673
|
private context;
|
|
655
674
|
private readonly lineSpacing;
|
|
656
|
-
private endsWithBreak;
|
|
657
675
|
/**
|
|
658
676
|
* Width of the text.
|
|
659
677
|
* If set, the text will be clipped to this size
|
|
@@ -664,6 +682,7 @@ declare class Text extends LabelField {
|
|
|
664
682
|
* Height of the text box, if empty and the type is multiline, the box can grow infinitely
|
|
665
683
|
*/
|
|
666
684
|
private height;
|
|
685
|
+
private endsWithBreak;
|
|
667
686
|
constructor(content: string, x: number, y: number, formatted?: boolean);
|
|
668
687
|
/**
|
|
669
688
|
* Sets the field to single line
|
|
@@ -720,10 +739,20 @@ declare class BarCode extends LabelField {
|
|
|
720
739
|
private readonly y;
|
|
721
740
|
private readonly type;
|
|
722
741
|
private readonly height;
|
|
742
|
+
private readonly barWidth;
|
|
723
743
|
private rotation;
|
|
724
744
|
private humanReadable;
|
|
725
745
|
private readonly alignment;
|
|
726
|
-
|
|
746
|
+
/**
|
|
747
|
+
* @param content Content to encode
|
|
748
|
+
* @param x X coordinate in dots
|
|
749
|
+
* @param y Y coordinate in dots
|
|
750
|
+
* @param type Barcode symbology
|
|
751
|
+
* @param height Height of the barcode in dots
|
|
752
|
+
* @param barWidth Width of the narrow bar element in dots. The wide element width is
|
|
753
|
+
* calculated automatically based on the symbology's standard ratio.
|
|
754
|
+
*/
|
|
755
|
+
constructor(content: string, x: number, y: number, type: BarcodeType, height: number, barWidth?: number);
|
|
727
756
|
setRotation(rotation: Rotation): void;
|
|
728
757
|
setHumanReadable(humanReadable: BarcodeHumanReable): void;
|
|
729
758
|
commandForLanguage(language: PrinterLanguage, _config?: PrintConfig | undefined): Promise<Command>;
|
package/dist/index.js
CHANGED
|
@@ -271,11 +271,6 @@ function dotToPoint(dots, dpi) {
|
|
|
271
271
|
const inch = dots / dpi;
|
|
272
272
|
return Math.round(inch * pointsPerInch);
|
|
273
273
|
}
|
|
274
|
-
function pointsToDots(points, dpi) {
|
|
275
|
-
const pointsPerInch2 = 72;
|
|
276
|
-
const dots = points * dpi / pointsPerInch2;
|
|
277
|
-
return dots;
|
|
278
|
-
}
|
|
279
274
|
|
|
280
275
|
// src/helpers/ImageDataParser.ts
|
|
281
276
|
function parsePNG(buffer2) {
|
|
@@ -1507,7 +1502,7 @@ var QRLengthMapping = {
|
|
|
1507
1502
|
};
|
|
1508
1503
|
|
|
1509
1504
|
// src/commands/tspl/TSPLCommandGenerator.ts
|
|
1510
|
-
var TSPLCommandGenerator = class {
|
|
1505
|
+
var TSPLCommandGenerator = class _TSPLCommandGenerator {
|
|
1511
1506
|
commandGroup(commands) {
|
|
1512
1507
|
return new TSPLCommandGroup(commands);
|
|
1513
1508
|
}
|
|
@@ -1548,8 +1543,41 @@ var TSPLCommandGenerator = class {
|
|
|
1548
1543
|
const cellWidth = Math.round(width / cellCount);
|
|
1549
1544
|
return new TSPLQRCommand(`A${content}`, x, y, cellWidth, "H", "M");
|
|
1550
1545
|
}
|
|
1551
|
-
barCode(content, x, y, type, height, rotation, humanReadable, alignment) {
|
|
1552
|
-
|
|
1546
|
+
barCode(content, x, y, type, height, rotation, humanReadable, alignment, barWidth = 2) {
|
|
1547
|
+
const { narrow, wide } = _TSPLCommandGenerator.narrowWideFor(type, barWidth);
|
|
1548
|
+
return new TSPLBarcodeCommand(x, y, type, height, narrow, wide, content, rotation, humanReadable, alignment);
|
|
1549
|
+
}
|
|
1550
|
+
/**
|
|
1551
|
+
* Calculates the narrow and wide element widths for a barcode type based on the
|
|
1552
|
+
* TSPL documentation's standard narrow:wide ratios.
|
|
1553
|
+
*
|
|
1554
|
+
* Types that only support 1:1 (continuous barcodes like CODE128, EAN, UPC) get
|
|
1555
|
+
* narrow === wide. All other types use the 1:3 ratio, which is the industry
|
|
1556
|
+
* standard for variable-ratio symbologies (CODE39, ITF14, codabar, MSI…).
|
|
1557
|
+
*/
|
|
1558
|
+
static narrowWideFor(type, barWidth) {
|
|
1559
|
+
switch (type) {
|
|
1560
|
+
case "25":
|
|
1561
|
+
case "25C":
|
|
1562
|
+
case "39":
|
|
1563
|
+
case "39C":
|
|
1564
|
+
case "93":
|
|
1565
|
+
case "CODA":
|
|
1566
|
+
case "MSI":
|
|
1567
|
+
case "MSIC":
|
|
1568
|
+
case "PLESSEY":
|
|
1569
|
+
case "ITF14":
|
|
1570
|
+
case "11":
|
|
1571
|
+
case "TELEPEN":
|
|
1572
|
+
case "TELEPENN":
|
|
1573
|
+
case "DPI":
|
|
1574
|
+
case "DPL":
|
|
1575
|
+
return { narrow: barWidth, wide: 3 * barWidth };
|
|
1576
|
+
case "CPOST":
|
|
1577
|
+
return { narrow: barWidth, wide: barWidth * 7 / 3 };
|
|
1578
|
+
default:
|
|
1579
|
+
return { narrow: barWidth, wide: barWidth };
|
|
1580
|
+
}
|
|
1553
1581
|
}
|
|
1554
1582
|
cellCount(content) {
|
|
1555
1583
|
const limits = Object.keys(QRLengthMapping).map((limit) => Number(limit)).sort((a, b) => a - b);
|
|
@@ -1665,6 +1693,8 @@ var StringUtils = class {
|
|
|
1665
1693
|
}
|
|
1666
1694
|
};
|
|
1667
1695
|
var isWhitespace = (text) => text.trim() === "";
|
|
1696
|
+
var BREAK_AFTER_CHARS = /* @__PURE__ */ new Set([",", ";", ":", "."]);
|
|
1697
|
+
var isBreakAfterChar = (ch) => BREAK_AFTER_CHARS.has(ch);
|
|
1668
1698
|
|
|
1669
1699
|
// src/helpers/USBUtils.ts
|
|
1670
1700
|
var unsupportedUsbError = "usb-unsupported";
|
|
@@ -2081,7 +2111,6 @@ var TSPLPrinter = class _TSPLPrinter extends Printer {
|
|
|
2081
2111
|
static try(device) {
|
|
2082
2112
|
return __async(this, null, function* () {
|
|
2083
2113
|
if (!device.opened) yield device.openAndConfigure();
|
|
2084
|
-
console.log("Response: ", device.opened);
|
|
2085
2114
|
const testCommand = new TSPLRawCommand("~!I");
|
|
2086
2115
|
yield testCommand.writeTo(device);
|
|
2087
2116
|
const response = yield device.readString(64);
|
|
@@ -2423,6 +2452,7 @@ var Label = class extends Printable {
|
|
|
2423
2452
|
*/
|
|
2424
2453
|
this.fields = [];
|
|
2425
2454
|
this.fontCounter = 0;
|
|
2455
|
+
this._textWidthCorrectionFactor = 0.935;
|
|
2426
2456
|
this.width = width;
|
|
2427
2457
|
this.height = height;
|
|
2428
2458
|
this.unitSystem = dimensionUnit;
|
|
@@ -2440,16 +2470,24 @@ var Label = class extends Printable {
|
|
|
2440
2470
|
if (indexedFont == null) {
|
|
2441
2471
|
return text.length * font.size;
|
|
2442
2472
|
} else {
|
|
2443
|
-
const size = dotToPoint(font.size, this.dpi);
|
|
2444
2473
|
const fontObject = indexedFont.font;
|
|
2445
2474
|
const run = fontObject.layout(text);
|
|
2446
|
-
|
|
2447
|
-
return pointsToDots(scaledWidth, this.dpi);
|
|
2475
|
+
return font.size * this._textWidthCorrectionFactor * run.advanceWidth / fontObject.unitsPerEm;
|
|
2448
2476
|
}
|
|
2449
2477
|
},
|
|
2450
|
-
getFontName: this.getFontName.bind(this)
|
|
2478
|
+
getFontName: this.getFontName.bind(this),
|
|
2479
|
+
textWidthCorrectionFactor: this._textWidthCorrectionFactor
|
|
2451
2480
|
};
|
|
2452
2481
|
}
|
|
2482
|
+
/**
|
|
2483
|
+
* Sets a correction factor for text width measurement.
|
|
2484
|
+
* Values < 1.0 make text wrap less aggressively (more chars per line).
|
|
2485
|
+
* Useful when the printer renders text narrower than fontkit measures.
|
|
2486
|
+
* @param factor Correction factor (default 1.0, typical range 0.9-1.0)
|
|
2487
|
+
*/
|
|
2488
|
+
setTextWidthCorrectionFactor(factor) {
|
|
2489
|
+
this._textWidthCorrectionFactor = factor;
|
|
2490
|
+
}
|
|
2453
2491
|
commandForLanguage(language, config) {
|
|
2454
2492
|
return __async(this, null, function* () {
|
|
2455
2493
|
const configuration = config != null ? config : this.printConfig;
|
|
@@ -2827,22 +2865,91 @@ var Text = class extends LabelField {
|
|
|
2827
2865
|
commands.push(this.textCommand(remainingContent, x, y, font, features));
|
|
2828
2866
|
remainingContent = "";
|
|
2829
2867
|
} else {
|
|
2830
|
-
let
|
|
2831
|
-
|
|
2832
|
-
|
|
2868
|
+
let lo = 0, hi = remainingContent.length - 1;
|
|
2869
|
+
let rowEndIndex = -1;
|
|
2870
|
+
while (lo <= hi) {
|
|
2871
|
+
const mid = Math.floor((lo + hi) / 2);
|
|
2872
|
+
if (textWidhtFunction(remainingContent.substring(0, mid + 1), font) <= rowWidth) {
|
|
2873
|
+
rowEndIndex = mid;
|
|
2874
|
+
lo = mid + 1;
|
|
2875
|
+
} else {
|
|
2876
|
+
hi = mid - 1;
|
|
2877
|
+
}
|
|
2878
|
+
}
|
|
2833
2879
|
let originalRowEndIndex = rowEndIndex;
|
|
2834
|
-
|
|
2880
|
+
rowWidth = this.width;
|
|
2881
|
+
if (rowEndIndex < 0) {
|
|
2835
2882
|
x = this.x;
|
|
2836
2883
|
y += font.size + this.lineSpacing;
|
|
2837
2884
|
continue;
|
|
2838
2885
|
}
|
|
2839
|
-
while (!(!isWhitespace(remainingContent.charAt(rowEndIndex)) && (rowEndIndex == remainingContent.length - 1 || isWhitespace(remainingContent.charAt(rowEndIndex + 1)))) && rowEndIndex > 0) {
|
|
2886
|
+
while (!(!isWhitespace(remainingContent.charAt(rowEndIndex)) && (rowEndIndex == remainingContent.length - 1 || isWhitespace(remainingContent.charAt(rowEndIndex + 1))) || isBreakAfterChar(remainingContent.charAt(rowEndIndex))) && rowEndIndex > 0) {
|
|
2840
2887
|
rowEndIndex--;
|
|
2841
2888
|
}
|
|
2842
2889
|
let nextRowStartIndex = rowEndIndex + 1;
|
|
2843
|
-
|
|
2890
|
+
const foundWordBoundary = !isWhitespace(remainingContent.charAt(rowEndIndex)) && (rowEndIndex == remainingContent.length - 1 || isWhitespace(remainingContent.charAt(rowEndIndex + 1))) || isBreakAfterChar(remainingContent.charAt(rowEndIndex));
|
|
2891
|
+
const MIN_WORD_BREAK_CHARS = 2;
|
|
2892
|
+
if (!foundWordBoundary) {
|
|
2844
2893
|
rowEndIndex = originalRowEndIndex;
|
|
2845
2894
|
nextRowStartIndex = originalRowEndIndex + 1;
|
|
2895
|
+
let wordEnd = originalRowEndIndex + 1;
|
|
2896
|
+
while (wordEnd < remainingContent.length && !isWhitespace(remainingContent.charAt(wordEnd))) {
|
|
2897
|
+
wordEnd++;
|
|
2898
|
+
}
|
|
2899
|
+
const charsOnNext = wordEnd - originalRowEndIndex - 1;
|
|
2900
|
+
if (charsOnNext > 0 && charsOnNext < MIN_WORD_BREAK_CHARS) {
|
|
2901
|
+
const adjusted = originalRowEndIndex - (MIN_WORD_BREAK_CHARS - charsOnNext);
|
|
2902
|
+
if (adjusted >= 0) {
|
|
2903
|
+
rowEndIndex = adjusted;
|
|
2904
|
+
nextRowStartIndex = adjusted + 1;
|
|
2905
|
+
}
|
|
2906
|
+
}
|
|
2907
|
+
} else if (originalRowEndIndex > rowEndIndex) {
|
|
2908
|
+
let wordStart = rowEndIndex + 1;
|
|
2909
|
+
while (wordStart <= originalRowEndIndex && isWhitespace(remainingContent.charAt(wordStart))) {
|
|
2910
|
+
wordStart++;
|
|
2911
|
+
}
|
|
2912
|
+
let fullWordEnd = wordStart;
|
|
2913
|
+
while (fullWordEnd < remainingContent.length && !isWhitespace(remainingContent.charAt(fullWordEnd))) {
|
|
2914
|
+
fullWordEnd++;
|
|
2915
|
+
}
|
|
2916
|
+
const lineWithFullWord = textWidhtFunction(remainingContent.substring(0, fullWordEnd), font);
|
|
2917
|
+
if (lineWithFullWord <= rowWidth) {
|
|
2918
|
+
rowEndIndex = fullWordEnd - 1;
|
|
2919
|
+
nextRowStartIndex = fullWordEnd;
|
|
2920
|
+
} else {
|
|
2921
|
+
let lo2 = wordStart, hi2 = fullWordEnd - 1;
|
|
2922
|
+
let midBreak = -1;
|
|
2923
|
+
while (lo2 <= hi2) {
|
|
2924
|
+
const mid2 = Math.floor((lo2 + hi2) / 2);
|
|
2925
|
+
if (textWidhtFunction(remainingContent.substring(0, mid2 + 1), font) <= rowWidth) {
|
|
2926
|
+
midBreak = mid2;
|
|
2927
|
+
lo2 = mid2 + 1;
|
|
2928
|
+
} else {
|
|
2929
|
+
hi2 = mid2 - 1;
|
|
2930
|
+
}
|
|
2931
|
+
}
|
|
2932
|
+
let usedMidWordBreak = false;
|
|
2933
|
+
if (midBreak >= wordStart) {
|
|
2934
|
+
let charsOnLine = midBreak - wordStart + 1;
|
|
2935
|
+
let charsOnNext = fullWordEnd - midBreak - 1;
|
|
2936
|
+
if (charsOnNext > 0 && charsOnNext < MIN_WORD_BREAK_CHARS) {
|
|
2937
|
+
midBreak -= MIN_WORD_BREAK_CHARS - charsOnNext;
|
|
2938
|
+
charsOnLine = midBreak - wordStart + 1;
|
|
2939
|
+
}
|
|
2940
|
+
if (charsOnLine >= MIN_WORD_BREAK_CHARS) {
|
|
2941
|
+
rowEndIndex = midBreak;
|
|
2942
|
+
nextRowStartIndex = midBreak + 1;
|
|
2943
|
+
usedMidWordBreak = true;
|
|
2944
|
+
}
|
|
2945
|
+
}
|
|
2946
|
+
if (!usedMidWordBreak) {
|
|
2947
|
+
nextRowStartIndex = rowEndIndex + 1;
|
|
2948
|
+
while (isWhitespace(remainingContent.charAt(nextRowStartIndex)) && nextRowStartIndex < remainingContent.length) {
|
|
2949
|
+
nextRowStartIndex++;
|
|
2950
|
+
}
|
|
2951
|
+
}
|
|
2952
|
+
}
|
|
2846
2953
|
} else {
|
|
2847
2954
|
while (isWhitespace(remainingContent.charAt(nextRowStartIndex)) && nextRowStartIndex < remainingContent.length) {
|
|
2848
2955
|
nextRowStartIndex++;
|
|
@@ -2941,13 +3048,23 @@ var Text = class extends LabelField {
|
|
|
2941
3048
|
|
|
2942
3049
|
// src/labels/fields/BarCode.ts
|
|
2943
3050
|
var BarCode = class extends LabelField {
|
|
2944
|
-
|
|
3051
|
+
/**
|
|
3052
|
+
* @param content Content to encode
|
|
3053
|
+
* @param x X coordinate in dots
|
|
3054
|
+
* @param y Y coordinate in dots
|
|
3055
|
+
* @param type Barcode symbology
|
|
3056
|
+
* @param height Height of the barcode in dots
|
|
3057
|
+
* @param barWidth Width of the narrow bar element in dots. The wide element width is
|
|
3058
|
+
* calculated automatically based on the symbology's standard ratio.
|
|
3059
|
+
*/
|
|
3060
|
+
constructor(content, x, y, type, height, barWidth = 2) {
|
|
2945
3061
|
super();
|
|
2946
3062
|
this.content = content;
|
|
2947
3063
|
this.x = x;
|
|
2948
3064
|
this.y = y;
|
|
2949
3065
|
this.type = type;
|
|
2950
3066
|
this.height = height;
|
|
3067
|
+
this.barWidth = barWidth;
|
|
2951
3068
|
this.rotation = 0;
|
|
2952
3069
|
this.humanReadable = "none";
|
|
2953
3070
|
this.alignment = "left";
|
|
@@ -2960,7 +3077,7 @@ var BarCode = class extends LabelField {
|
|
|
2960
3077
|
}
|
|
2961
3078
|
commandForLanguage(language, _config) {
|
|
2962
3079
|
return __async(this, null, function* () {
|
|
2963
|
-
return yield this.commandGeneratorFor(language).barCode(this.content, this.x, this.y, this.type, this.height, this.rotation, this.humanReadable, this.alignment);
|
|
3080
|
+
return yield this.commandGeneratorFor(language).barCode(this.content, this.x, this.y, this.type, this.height, this.rotation, this.humanReadable, this.alignment, this.barWidth);
|
|
2964
3081
|
});
|
|
2965
3082
|
}
|
|
2966
3083
|
};
|