@kreiseck/kasseneck-api 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +67 -0
- package/dist/cjs/pos/texte.d.ts +51 -0
- package/dist/cjs/pos/texte.js +32 -0
- package/dist/cjs/printing/code-table-preview.d.ts +15 -0
- package/dist/cjs/printing/code-table-preview.js +24 -0
- package/dist/cjs/printing/code-tables.d.ts +77 -0
- package/dist/cjs/printing/code-tables.js +224 -0
- package/dist/cjs/printing/escpos.d.ts +19 -6
- package/dist/cjs/printing/escpos.js +27 -48
- package/dist/cjs/printing/index.d.ts +2 -0
- package/dist/cjs/printing/index.js +8 -1
- package/dist/cjs/printing/printable.d.ts +14 -2
- package/dist/cjs/printing/printable.js +36 -2
- package/dist/cjs/react/index.js +7 -0
- package/dist/cjs/receipt/blatt.d.ts +9 -0
- package/dist/cjs/receipt/code-table-reference-data.d.ts +6 -0
- package/dist/cjs/receipt/code-table-reference-data.js +11 -0
- package/dist/cjs/receipt/code-table-test-sheet.d.ts +58 -0
- package/dist/cjs/receipt/code-table-test-sheet.js +155 -0
- package/dist/cjs/receipt/index.d.ts +1 -0
- package/dist/cjs/receipt/index.js +6 -1
- package/dist/cjs/receipt/layout-escpos.d.ts +6 -1
- package/dist/cjs/receipt/layout-escpos.js +11 -7
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/pos/texte.d.ts +51 -0
- package/dist/esm/pos/texte.js +32 -0
- package/dist/esm/printing/code-table-preview.d.ts +15 -0
- package/dist/esm/printing/code-table-preview.js +21 -0
- package/dist/esm/printing/code-tables.d.ts +77 -0
- package/dist/esm/printing/code-tables.js +215 -0
- package/dist/esm/printing/escpos.d.ts +19 -6
- package/dist/esm/printing/escpos.js +27 -48
- package/dist/esm/printing/index.d.ts +2 -0
- package/dist/esm/printing/index.js +2 -0
- package/dist/esm/printing/printable.d.ts +14 -2
- package/dist/esm/printing/printable.js +36 -2
- package/dist/esm/react/index.js +7 -0
- package/dist/esm/receipt/blatt.d.ts +9 -0
- package/dist/esm/receipt/code-table-reference-data.d.ts +6 -0
- package/dist/esm/receipt/code-table-reference-data.js +8 -0
- package/dist/esm/receipt/code-table-test-sheet.d.ts +58 -0
- package/dist/esm/receipt/code-table-test-sheet.js +149 -0
- package/dist/esm/receipt/index.d.ts +1 -0
- package/dist/esm/receipt/index.js +1 -0
- package/dist/esm/receipt/layout-escpos.d.ts +6 -1
- package/dist/esm/receipt/layout-escpos.js +11 -7
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/fixtures/code-table-preview.json +14 -0
- package/fixtures/code-table-receipts.json +84 -0
- package/fixtures/code-tables.json +12 -0
- package/fixtures/expected/code-table-receipt.long-item-name.iso8859_15.hex +27 -0
- package/fixtures/expected/code-table-receipt.long-item-name.pc437.hex +27 -0
- package/fixtures/expected/code-table-receipt.long-item-name.pc850.hex +27 -0
- package/fixtures/expected/code-table-receipt.long-item-name.pc858.hex +27 -0
- package/fixtures/expected/code-table-receipt.long-item-name.replacement.hex +27 -0
- package/fixtures/expected/code-table-receipt.long-item-name.wpc1252.hex +27 -0
- package/fixtures/expected/code-table-receipt.sale-cash.iso8859_15.hex +34 -0
- package/fixtures/expected/code-table-receipt.sale-cash.pc437.hex +34 -0
- package/fixtures/expected/code-table-receipt.sale-cash.pc850.hex +34 -0
- package/fixtures/expected/code-table-receipt.sale-cash.pc858.hex +34 -0
- package/fixtures/expected/code-table-receipt.sale-cash.replacement.hex +34 -0
- package/fixtures/expected/code-table-receipt.sale-cash.wpc1252.hex +34 -0
- package/fixtures/expected/code-table-receipt.special-characters.iso8859_15.hex +30 -0
- package/fixtures/expected/code-table-receipt.special-characters.pc437.hex +30 -0
- package/fixtures/expected/code-table-receipt.special-characters.pc850.hex +30 -0
- package/fixtures/expected/code-table-receipt.special-characters.pc858.hex +30 -0
- package/fixtures/expected/code-table-receipt.special-characters.replacement.hex +30 -0
- package/fixtures/expected/code-table-receipt.special-characters.wpc1252.hex +30 -0
- package/fixtures/expected/code-table-receipt.test-cashregister-sale.iso8859_15.hex +44 -0
- package/fixtures/expected/code-table-receipt.test-cashregister-sale.pc437.hex +44 -0
- package/fixtures/expected/code-table-receipt.test-cashregister-sale.pc850.hex +44 -0
- package/fixtures/expected/code-table-receipt.test-cashregister-sale.pc858.hex +44 -0
- package/fixtures/expected/code-table-receipt.test-cashregister-sale.replacement.hex +44 -0
- package/fixtures/expected/code-table-receipt.test-cashregister-sale.wpc1252.hex +44 -0
- package/fixtures/expected/code-table-test-sheet.lines.json +209 -0
- package/fixtures/expected/code-table-test-sheet.mm58.hex +62 -0
- package/fixtures/expected/code-table-test-sheet.mm80.hex +63 -0
- package/fixtures/hobex-hps-codes.json +1 -1
- package/fixtures/invoice-api.schema.json +1 -1
- package/fixtures/invoice-texts.json +1 -1
- package/fixtures/pos-texts.json +58 -1
- package/fixtures/surface.json +1 -1
- package/package.json +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,73 @@ Was vor 0.7.0 geschah, steht in der Commit-Historie (`git log`); ab hier wird
|
|
|
4
4
|
es hier geführt. Ein Eintrag nennt die Änderung **und ihren Grund** —
|
|
5
5
|
nur der Grund überlebt den nächsten Umbau.
|
|
6
6
|
|
|
7
|
+
## 1.1.1
|
|
8
|
+
|
|
9
|
+
The code-table test sheet asks for the right row. Reason: a Bluetooth
|
|
10
|
+
printer that only knows PC437 printed rows 2 and 3 with correct umlauts but
|
|
11
|
+
wrong glyphs for `€` and `§` (`╒`, `⌡`), and row 4 correct with gaps for
|
|
12
|
+
`€` and `§`. "The first row that looks exactly like above" confused users,
|
|
13
|
+
and "the row with correct umlauts" would pick row 2. The rule now is: the
|
|
14
|
+
row with no wrong character; a gap is fine; if several fit, the one with
|
|
15
|
+
the fewest gaps; if none fits, 6.
|
|
16
|
+
|
|
17
|
+
Additive, no breaking change; receipts are byte for byte the same (the 24
|
|
18
|
+
`code-table-receipt.*.hex` files are unchanged).
|
|
19
|
+
|
|
20
|
+
- **Test sheet** (`./receipt`): reference heading `codetable.reference` is
|
|
21
|
+
now "So sehen die Zeichen richtig aus" (32 columns; with a colon it would
|
|
22
|
+
wrap), the footer is the new rule: `codetable.instruction_title` (bold),
|
|
23
|
+
`codetable.instruction`, `codetable.instruction_none` ("Passt keine:
|
|
24
|
+
{number}.", the replacement row). As before, everything outside the test
|
|
25
|
+
rows prints with replacement letters (pure ASCII), so "Lücke" from the
|
|
26
|
+
catalogue stands as "Luecke" on the sheet, on paper and in the line model.
|
|
27
|
+
Rows, big numbers, margins and the end reset are unchanged. Contract:
|
|
28
|
+
`fixtures/expected/code-table-test-sheet.*`.
|
|
29
|
+
- **Screen texts** (`fixtures/pos-texts.json`): `codetable.question` is now
|
|
30
|
+
"In welcher Zeile steht kein falsches Zeichen?"; new
|
|
31
|
+
`codetable.question_hint`, `codetable.preview_title`, `codetable.apply`,
|
|
32
|
+
`codetable.other_row`.
|
|
33
|
+
- **Preview** (`./printing`): `codeTablePreviewText(table)` returns the
|
|
34
|
+
sample "Käsekrainer 3,50 €" / "Tee 80°" as it prints with that table
|
|
35
|
+
(lines joined by `\n`), e.g. `pc437` gives "Käsekrainer 3,50 EUR", so the
|
|
36
|
+
user sees the effect of a row before applying it. Shared contract with the
|
|
37
|
+
Dart twin: `fixtures/code-table-preview.json`.
|
|
38
|
+
|
|
39
|
+
## 1.1.0
|
|
40
|
+
|
|
41
|
+
Receipt printers that print umlauts and special characters correctly.
|
|
42
|
+
Reason: `ESC t n` selects the character table, but the number n differs
|
|
43
|
+
between manufacturers; many low-cost printers ignore `ESC t 16` or put
|
|
44
|
+
another table there and print garbage instead of `ä`. The printer wizard
|
|
45
|
+
now prints a test sheet, the user taps the first row that looks right, and
|
|
46
|
+
the register keeps that choice per printer on the device.
|
|
47
|
+
|
|
48
|
+
Additive, no breaking change. Without a chosen table every receipt is byte
|
|
49
|
+
for byte the same as in 1.0.0 (all golden receipts unchanged).
|
|
50
|
+
|
|
51
|
+
- **Code-table catalogue** (`./printing`): `CodeTableId`, `CodeTable`,
|
|
52
|
+
`CODE_TABLES` (six tables: `wpc1252` = `ESC t 16`, `pc858` = 19,
|
|
53
|
+
`pc850` = 2, `pc437` = 0, `iso8859_15` = 40, `replacement` = 0),
|
|
54
|
+
`codeTableById`, `codeTableFromSetting`, `encodeForCodeTable`. For
|
|
55
|
+
ä ö ü Ä Ö Ü ß € § ° every table answers with its own byte or, where the
|
|
56
|
+
table lacks the character, with replacement letters (`ae`, `EUR`, `Par.`,
|
|
57
|
+
`Grad`), never `?`. Shared contract with the Dart twin:
|
|
58
|
+
`fixtures/code-tables.json`.
|
|
59
|
+
- **Test sheet** (`./receipt`): `codeTableTestSheet` (line model for the
|
|
60
|
+
screen, 32 columns) and `codeTableTestSheetBytes` (ESC/POS, centred on
|
|
61
|
+
80 mm), `codeTableReferenceImage`. Contract:
|
|
62
|
+
`fixtures/expected/code-table-test-sheet.*`. New texts in
|
|
63
|
+
`fixtures/pos-texts.json` (`codetable.*`).
|
|
64
|
+
- **Receipts with a chosen table**: `escPosLayoutBytes(layout, { codeTable })`
|
|
65
|
+
accepts a `CodeTableId`. `€`, `§` and `°` go out as the table's real
|
|
66
|
+
byte where the table has them, otherwise as replacement letters. Missing
|
|
67
|
+
characters are replaced in the text before the columns are laid out, so
|
|
68
|
+
a character that becomes several letters never shifts a column.
|
|
69
|
+
`escPosPrintableText(text, codeTable?)` takes the same optional table;
|
|
70
|
+
without it (or with `null`/`CP1252`) it behaves as before.
|
|
71
|
+
- **`CP437` and `§`**: on the old `CP437` name `§` now prints as `Par.`
|
|
72
|
+
(was `?`), with the columns measured after the replacement.
|
|
73
|
+
|
|
7
74
|
## 1.0.0
|
|
8
75
|
|
|
9
76
|
The package speaks the English API `/v3` and nothing else, and its own
|
package/dist/cjs/pos/texte.d.ts
CHANGED
|
@@ -469,6 +469,19 @@ declare const MELDUNGEN_ROH: {
|
|
|
469
469
|
readonly 'print.wizard_cancelled': {
|
|
470
470
|
readonly text: "Nichts gespeichert.";
|
|
471
471
|
};
|
|
472
|
+
readonly 'codetable.question': {
|
|
473
|
+
readonly text: "In welcher Zeile steht kein falsches Zeichen?";
|
|
474
|
+
};
|
|
475
|
+
readonly 'codetable.question_hint': {
|
|
476
|
+
readonly text: "Lücken sind in Ordnung.";
|
|
477
|
+
};
|
|
478
|
+
readonly 'codetable.instruction': {
|
|
479
|
+
readonly text: "Die Zeile, in der KEIN falsches Zeichen steht. Eine Lücke ist in Ordnung. Passen mehrere, die mit den wenigsten Lücken.";
|
|
480
|
+
};
|
|
481
|
+
readonly 'codetable.instruction_none': {
|
|
482
|
+
readonly text: "Passt keine: {number}.";
|
|
483
|
+
readonly placeholders: readonly ["number"];
|
|
484
|
+
};
|
|
472
485
|
readonly 'bluetooth.off': {
|
|
473
486
|
readonly text: "Bluetooth ist ausgeschaltet. Bitte einschalten und erneut suchen.";
|
|
474
487
|
readonly only: readonly ["app"];
|
|
@@ -964,6 +977,44 @@ declare const BESCHRIFTUNGEN_ROH: {
|
|
|
964
977
|
readonly 'cancellation.difference': {
|
|
965
978
|
readonly text: "Differenz";
|
|
966
979
|
};
|
|
980
|
+
readonly 'codetable.title': {
|
|
981
|
+
readonly text: "ZEICHENSATZ-TEST";
|
|
982
|
+
};
|
|
983
|
+
readonly 'codetable.reference': {
|
|
984
|
+
readonly text: "So sehen die Zeichen richtig aus";
|
|
985
|
+
};
|
|
986
|
+
readonly 'codetable.replacement_note': {
|
|
987
|
+
readonly text: "(Ersatz, passt immer)";
|
|
988
|
+
};
|
|
989
|
+
readonly 'codetable.missing': {
|
|
990
|
+
readonly text: "ohne {chars}";
|
|
991
|
+
readonly placeholders: readonly ["chars"];
|
|
992
|
+
};
|
|
993
|
+
readonly 'codetable.print_again': {
|
|
994
|
+
readonly text: "Nochmal drucken";
|
|
995
|
+
};
|
|
996
|
+
readonly 'codetable.not_checked': {
|
|
997
|
+
readonly text: "Umlaute noch nicht geprüft";
|
|
998
|
+
};
|
|
999
|
+
readonly 'codetable.check': {
|
|
1000
|
+
readonly text: "Umlaute prüfen";
|
|
1001
|
+
};
|
|
1002
|
+
readonly 'codetable.current': {
|
|
1003
|
+
readonly text: "Zeichensatz: Nr. {number}";
|
|
1004
|
+
readonly placeholders: readonly ["number"];
|
|
1005
|
+
};
|
|
1006
|
+
readonly 'codetable.instruction_title': {
|
|
1007
|
+
readonly text: "Welche Zeile nehmen?";
|
|
1008
|
+
};
|
|
1009
|
+
readonly 'codetable.preview_title': {
|
|
1010
|
+
readonly text: "So steht es dann am Bon:";
|
|
1011
|
+
};
|
|
1012
|
+
readonly 'codetable.apply': {
|
|
1013
|
+
readonly text: "Übernehmen";
|
|
1014
|
+
};
|
|
1015
|
+
readonly 'codetable.other_row': {
|
|
1016
|
+
readonly text: "Andere Zeile";
|
|
1017
|
+
};
|
|
967
1018
|
};
|
|
968
1019
|
export type LabelKey = keyof typeof BESCHRIFTUNGEN_ROH;
|
|
969
1020
|
export declare const LABELS: Record<LabelKey, TextEntry>;
|
package/dist/cjs/pos/texte.js
CHANGED
|
@@ -255,6 +255,18 @@ const MELDUNGEN_ROH = {
|
|
|
255
255
|
// Abbrechen an jeder Stelle: nichts gespeichert. Der Satz sagt genau das,
|
|
256
256
|
// damit niemand einen halb eingerichteten Drucker vermutet.
|
|
257
257
|
'print.wizard_cancelled': { text: 'Nichts gespeichert.' },
|
|
258
|
+
// Zeichensatz-Test im Drucker-Wizard: das Testblatt nennt die Anleitung,
|
|
259
|
+
// der Bildschirm stellt die Frage daneben. Die Regel ist „kein falsches
|
|
260
|
+
// Zeichen“, nicht „erste Zeile“ und nicht „Umlaute richtig“: ein Drucker
|
|
261
|
+
// mit nur PC437 druckt Zeile 2 und 3 mit richtigen Umlauten, aber falschem
|
|
262
|
+
// € und § (╒, ⌡); richtig ist dort Zeile 4, mit Luecken fuer € und §.
|
|
263
|
+
// Am Papier steht „Lücke“ als „Luecke“ (Ersatzbuchstaben wie jeder Text
|
|
264
|
+
// ausserhalb der Testzeilen), am Bildschirm mit Umlaut.
|
|
265
|
+
'codetable.question': { text: 'In welcher Zeile steht kein falsches Zeichen?' },
|
|
266
|
+
'codetable.question_hint': { text: 'Lücken sind in Ordnung.' },
|
|
267
|
+
'codetable.instruction': { text: 'Die Zeile, in der KEIN falsches Zeichen steht. Eine Lücke ist in Ordnung. Passen mehrere, die mit den wenigsten Lücken.' },
|
|
268
|
+
// `{number}` ist die Ersatz-Zeile (6), die immer passt.
|
|
269
|
+
'codetable.instruction_none': { text: 'Passt keine: {number}.', placeholders: ['number'] },
|
|
258
270
|
'bluetooth.off': { text: 'Bluetooth ist ausgeschaltet. Bitte einschalten und erneut suchen.', only: ['app'] },
|
|
259
271
|
'bluetooth.permission_missing': { text: 'Bitte die Freigabe in den Geräte-Einstellungen erteilen.', only: ['app'] },
|
|
260
272
|
'bluetooth.search_failed': { text: 'Die Suche ist fehlgeschlagen: {reason}', placeholders: ['reason'], only: ['app'] },
|
|
@@ -566,6 +578,26 @@ const BESCHRIFTUNGEN_ROH = {
|
|
|
566
578
|
'cancellation.all_cash': { text: 'Alles bar' },
|
|
567
579
|
'cancellation.payment_remainder': { text: 'Rest {amount}', placeholders: ['amount'] },
|
|
568
580
|
'cancellation.difference': { text: 'Differenz' },
|
|
581
|
+
// --- Zeichensatz-Test (Testblatt und Drucker & Lade) ----------------------
|
|
582
|
+
// Das Testblatt druckt diese Texte mit Ersatzbuchstaben (reines ASCII);
|
|
583
|
+
// die Knoepfe stehen nur am Bildschirm. `{chars}` sind die fehlenden Zeichen einer Zeile
|
|
584
|
+
// („€“ bzw. „€ §“), `{number}` die gewaehlte Zeile (1-6).
|
|
585
|
+
'codetable.title': { text: 'ZEICHENSATZ-TEST' },
|
|
586
|
+
// Genau 32 Spalten: mit Doppelpunkt waeren es 33, die Ueberschrift braeche um.
|
|
587
|
+
'codetable.reference': { text: 'So sehen die Zeichen richtig aus' },
|
|
588
|
+
'codetable.replacement_note': { text: '(Ersatz, passt immer)' },
|
|
589
|
+
'codetable.missing': { text: 'ohne {chars}', placeholders: ['chars'] },
|
|
590
|
+
'codetable.print_again': { text: 'Nochmal drucken' },
|
|
591
|
+
'codetable.not_checked': { text: 'Umlaute noch nicht geprüft' },
|
|
592
|
+
'codetable.check': { text: 'Umlaute prüfen' },
|
|
593
|
+
'codetable.current': { text: 'Zeichensatz: Nr. {number}', placeholders: ['number'] },
|
|
594
|
+
// Ueberschrift der Anleitung am Testblatt.
|
|
595
|
+
'codetable.instruction_title': { text: 'Welche Zeile nehmen?' },
|
|
596
|
+
// Nach der Wahl: das Beispiel so, wie es mit der Zeile am Bon steht
|
|
597
|
+
// (`codeTablePreviewText`), dann uebernehmen oder zurueck zur Frage.
|
|
598
|
+
'codetable.preview_title': { text: 'So steht es dann am Bon:' },
|
|
599
|
+
'codetable.apply': { text: 'Übernehmen' },
|
|
600
|
+
'codetable.other_row': { text: 'Andere Zeile' },
|
|
569
601
|
};
|
|
570
602
|
exports.LABELS = BESCHRIFTUNGEN_ROH;
|
|
571
603
|
/** Die Beschriftung zum Schluessel, Platzhalter ersetzt; fehlt ein Wert, wirft es wie `messageText`. */
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Die Vorschau im Drucker-Wizard: nach der Wahl einer Zeile zeigt der
|
|
3
|
+
* Bildschirm ein Beispiel so, wie es mit dieser Tabelle am Bon steht. Wer
|
|
4
|
+
* Zeile 4 (PC437) waehlt, sieht „3,50 EUR“ statt „3,50 €“, bevor er
|
|
5
|
+
* uebernimmt. Gemeinsamer Prueffall mit dem Dart-Zwilling:
|
|
6
|
+
* `fixtures/code-table-preview.json`.
|
|
7
|
+
*/
|
|
8
|
+
import { type CodeTableId } from './code-tables.js';
|
|
9
|
+
/**
|
|
10
|
+
* Das Beispiel mit den Ersetzungen der Tabelle, Zeilen durch `\n` getrennt:
|
|
11
|
+
* fehlt der Tabelle ein Zeichen, stehen seine Ersatzbuchstaben da
|
|
12
|
+
* (`pc437` -> „Käsekrainer 3,50 EUR“, `replacement` -> „Kaesekrainer 3,50 EUR“).
|
|
13
|
+
* Eine unbekannte Kennung wird gemeldet.
|
|
14
|
+
*/
|
|
15
|
+
export declare function codeTablePreviewText(table: CodeTableId): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.codeTablePreviewText = codeTablePreviewText;
|
|
4
|
+
/**
|
|
5
|
+
* Die Vorschau im Drucker-Wizard: nach der Wahl einer Zeile zeigt der
|
|
6
|
+
* Bildschirm ein Beispiel so, wie es mit dieser Tabelle am Bon steht. Wer
|
|
7
|
+
* Zeile 4 (PC437) waehlt, sieht „3,50 EUR“ statt „3,50 €“, bevor er
|
|
8
|
+
* uebernimmt. Gemeinsamer Prueffall mit dem Dart-Zwilling:
|
|
9
|
+
* `fixtures/code-table-preview.json`.
|
|
10
|
+
*/
|
|
11
|
+
const code_tables_js_1 = require("./code-tables.js");
|
|
12
|
+
const printable_js_1 = require("./printable.js");
|
|
13
|
+
/** Das Beispiel: Umlaut, €, °. */
|
|
14
|
+
const BEISPIEL = ['Käsekrainer 3,50 €', 'Tee 80°'];
|
|
15
|
+
/**
|
|
16
|
+
* Das Beispiel mit den Ersetzungen der Tabelle, Zeilen durch `\n` getrennt:
|
|
17
|
+
* fehlt der Tabelle ein Zeichen, stehen seine Ersatzbuchstaben da
|
|
18
|
+
* (`pc437` -> „Käsekrainer 3,50 EUR“, `replacement` -> „Kaesekrainer 3,50 EUR“).
|
|
19
|
+
* Eine unbekannte Kennung wird gemeldet.
|
|
20
|
+
*/
|
|
21
|
+
function codeTablePreviewText(table) {
|
|
22
|
+
(0, code_tables_js_1.codeTableById)(table);
|
|
23
|
+
return BEISPIEL.map((zeile) => (0, printable_js_1.escPosPrintableText)(zeile, table)).join('\n');
|
|
24
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Katalog der Code-Tabellen fuer Bondrucker und die Umwandlung von Text in
|
|
3
|
+
* Bytes je Tabelle.
|
|
4
|
+
*
|
|
5
|
+
* Warum ein Katalog: `ESC t n` waehlt die Zeichentabelle, aber die Nummer n
|
|
6
|
+
* ist nicht einheitlich. Epson legt WPC1252 auf 16, viele guenstige Drucker
|
|
7
|
+
* nummerieren anders oder kennen die Tabelle gar nicht. Wer am Testblatt
|
|
8
|
+
* sieht, welche Nummer seine Umlaute richtig druckt, waehlt hier die
|
|
9
|
+
* passende Tabelle. Gemeinsamer Prueffall mit dem Dart-Zwilling:
|
|
10
|
+
* `fixtures/code-tables.json`.
|
|
11
|
+
*
|
|
12
|
+
* Jede Tabelle setzt die zehn deutschen Zeichen (Umlaute, ß, €, §, °) auf
|
|
13
|
+
* ein Byte oder, wo die Tabelle das Zeichen nicht hat, auf Ersatzbuchstaben
|
|
14
|
+
* (`€` -> `EUR`). Fuer diese zehn Zeichen kommt nie `?` heraus.
|
|
15
|
+
*/
|
|
16
|
+
/** Kennung einer Code-Tabelle. */
|
|
17
|
+
export type CodeTableId = 'wpc1252' | 'pc858' | 'pc850' | 'pc437' | 'iso8859_15' | 'replacement';
|
|
18
|
+
/** Eine Code-Tabelle des Katalogs. */
|
|
19
|
+
export interface CodeTable {
|
|
20
|
+
/** Kennung. */
|
|
21
|
+
id: CodeTableId;
|
|
22
|
+
/** Nummer auf dem Testblatt (1-6). */
|
|
23
|
+
number: 1 | 2 | 3 | 4 | 5 | 6;
|
|
24
|
+
/** n fuer `ESC t n`. */
|
|
25
|
+
escT: number;
|
|
26
|
+
/** Zeichen der zehn, die diese Tabelle nicht hat und durch Ersatzbuchstaben druckt. */
|
|
27
|
+
missing: readonly string[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Ersatzbuchstaben fuer eines der zehn Zeichen (paketintern, fuer
|
|
31
|
+
* `escPosPrintableText` mit gewaehlter Tabelle).
|
|
32
|
+
*/
|
|
33
|
+
export declare function ersatzBuchstaben(zeichen: string): string;
|
|
34
|
+
/** Alle Code-Tabellen in der Reihenfolge des Testblatts (Nummer 1-6). */
|
|
35
|
+
export declare const CODE_TABLES: readonly CodeTable[];
|
|
36
|
+
/** Die Tabelle zu einer Kennung; eine unbekannte Kennung wird gemeldet. */
|
|
37
|
+
export declare function codeTableById(id: CodeTableId): CodeTable;
|
|
38
|
+
/**
|
|
39
|
+
* Tabelle aus der gespeicherten Einstellung (`cp1252`/`cp437`). Alles andere,
|
|
40
|
+
* auch keine Einstellung, ist die Vorgabe `wpc1252`.
|
|
41
|
+
*/
|
|
42
|
+
export declare function codeTableFromSetting(setting: 'cp1252' | 'cp437' | null | undefined): CodeTableId;
|
|
43
|
+
/**
|
|
44
|
+
* Zeichen, die das Vorbild vor dem Kodieren ersetzt (generator.dart `_encode`).
|
|
45
|
+
*
|
|
46
|
+
* **Eine bewusste Abweichung:** Fuer `•` sagt generator.dart `.`,
|
|
47
|
+
* print_paper.dart (portiert als `escPosPrintableText`) dagegen `*`. In Darts
|
|
48
|
+
* eigener Kette faellt das nie auf, weil print_paper vor dem Erzeuger ersetzt
|
|
49
|
+
* und der Erzeuger den Punkt nie zu sehen bekommt -- die gedruckte Antwort ist
|
|
50
|
+
* dort also `*`. Ein Verbraucher dieses Pakets kann `escPosText` aber auch
|
|
51
|
+
* direkt aufrufen, und dann duerfen nicht zwei Zeichen fuer dasselbe Zeichen
|
|
52
|
+
* herauskommen. Deshalb gilt hier dieselbe Antwort wie dort.
|
|
53
|
+
*/
|
|
54
|
+
export declare const ZEICHEN_ERSATZ: ReadonlyArray<readonly [string, string]>;
|
|
55
|
+
/**
|
|
56
|
+
* Latin-1-Byte -> CP437-Byte fuer die Zeichen, die CP437 kennt (deutsche
|
|
57
|
+
* Umlaute, ß, westeuropaeische Akzente, Waehrungs-/Sonderzeichen). Alles
|
|
58
|
+
* andere ab 0x80 hat in CP437 keinen Platz und wird zu "?".
|
|
59
|
+
*/
|
|
60
|
+
export declare const CP437_AUS_LATIN1: ReadonlyMap<number, number>;
|
|
61
|
+
/**
|
|
62
|
+
* Wandelt Text in die Bytes einer Code-Tabelle: erst die vorhandenen
|
|
63
|
+
* Ersetzungen (`ZEICHEN_ERSATZ`), dann die zehn deutschen Zeichen je Tabelle
|
|
64
|
+
* (Byte oder Ersatzbuchstaben), ASCII unveraendert, alles uebrige ueber die
|
|
65
|
+
* Abbildung der Tabelle, sonst `?`. Ein Zeichen, das die Tabelle nicht
|
|
66
|
+
* kennt, ist genau ein Byte; nur die Ersatzbuchstaben machen aus einem
|
|
67
|
+
* Zeichen mehrere. Spalten darum immer an den fertigen Bytes messen.
|
|
68
|
+
*/
|
|
69
|
+
export declare function encodeForCodeTable(text: string, table: CodeTableId): Uint8Array;
|
|
70
|
+
/** Wendet `ZEICHEN_ERSATZ` an (paketintern, nicht exportiert ueber den Einstieg). */
|
|
71
|
+
export declare function replaceKnownCharacters(text: string): string;
|
|
72
|
+
/**
|
|
73
|
+
* Wie `encodeForCodeTable`, aber fuer Text, der `ZEICHEN_ERSATZ` schon hinter
|
|
74
|
+
* sich hat (paketintern: der alte Pfad in `encodeEscPosText` ersetzt vor der
|
|
75
|
+
* Latin-1-Pruefung und soll nicht zweimal ersetzen).
|
|
76
|
+
*/
|
|
77
|
+
export declare function encodeReplaced(aufbereitet: string, table: CodeTableId): Uint8Array;
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Katalog der Code-Tabellen fuer Bondrucker und die Umwandlung von Text in
|
|
4
|
+
* Bytes je Tabelle.
|
|
5
|
+
*
|
|
6
|
+
* Warum ein Katalog: `ESC t n` waehlt die Zeichentabelle, aber die Nummer n
|
|
7
|
+
* ist nicht einheitlich. Epson legt WPC1252 auf 16, viele guenstige Drucker
|
|
8
|
+
* nummerieren anders oder kennen die Tabelle gar nicht. Wer am Testblatt
|
|
9
|
+
* sieht, welche Nummer seine Umlaute richtig druckt, waehlt hier die
|
|
10
|
+
* passende Tabelle. Gemeinsamer Prueffall mit dem Dart-Zwilling:
|
|
11
|
+
* `fixtures/code-tables.json`.
|
|
12
|
+
*
|
|
13
|
+
* Jede Tabelle setzt die zehn deutschen Zeichen (Umlaute, ß, €, §, °) auf
|
|
14
|
+
* ein Byte oder, wo die Tabelle das Zeichen nicht hat, auf Ersatzbuchstaben
|
|
15
|
+
* (`€` -> `EUR`). Fuer diese zehn Zeichen kommt nie `?` heraus.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.CP437_AUS_LATIN1 = exports.ZEICHEN_ERSATZ = exports.CODE_TABLES = void 0;
|
|
19
|
+
exports.ersatzBuchstaben = ersatzBuchstaben;
|
|
20
|
+
exports.codeTableById = codeTableById;
|
|
21
|
+
exports.codeTableFromSetting = codeTableFromSetting;
|
|
22
|
+
exports.encodeForCodeTable = encodeForCodeTable;
|
|
23
|
+
exports.replaceKnownCharacters = replaceKnownCharacters;
|
|
24
|
+
exports.encodeReplaced = encodeReplaced;
|
|
25
|
+
/** Die zehn Zeichen, fuer die jede Tabelle eine feste Antwort hat. */
|
|
26
|
+
const ZEHN_ZEICHEN = ['ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü', 'ß', '€', '§', '°'];
|
|
27
|
+
/** Ersatzbuchstaben, wenn die Tabelle das Zeichen nicht hat. */
|
|
28
|
+
const ERSATZ_BUCHSTABEN = {
|
|
29
|
+
'ä': 'ae', 'ö': 'oe', 'ü': 'ue', 'Ä': 'Ae', 'Ö': 'Oe', 'Ü': 'Ue', 'ß': 'ss', '€': 'EUR', '§': 'Par.', '°': 'Grad',
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Byte je Zeichen und Tabelle; fehlt ein Zeichen, gilt der Ersatz. Werte aus
|
|
33
|
+
* den Zeichentabellen (Windows-1252, IBM 858/850/437, ISO 8859-15).
|
|
34
|
+
*/
|
|
35
|
+
const BYTES_JE_TABELLE = {
|
|
36
|
+
wpc1252: { 'ä': 0xe4, 'ö': 0xf6, 'ü': 0xfc, 'Ä': 0xc4, 'Ö': 0xd6, 'Ü': 0xdc, 'ß': 0xdf, '€': 0x80, '§': 0xa7, '°': 0xb0 },
|
|
37
|
+
pc858: { 'ä': 0x84, 'ö': 0x94, 'ü': 0x81, 'Ä': 0x8e, 'Ö': 0x99, 'Ü': 0x9a, 'ß': 0xe1, '€': 0xd5, '§': 0xf5, '°': 0xf8 },
|
|
38
|
+
pc850: { 'ä': 0x84, 'ö': 0x94, 'ü': 0x81, 'Ä': 0x8e, 'Ö': 0x99, 'Ü': 0x9a, 'ß': 0xe1, '§': 0xf5, '°': 0xf8 },
|
|
39
|
+
pc437: { 'ä': 0x84, 'ö': 0x94, 'ü': 0x81, 'Ä': 0x8e, 'Ö': 0x99, 'Ü': 0x9a, 'ß': 0xe1, '°': 0xf8 },
|
|
40
|
+
iso8859_15: { 'ä': 0xe4, 'ö': 0xf6, 'ü': 0xfc, 'Ä': 0xc4, 'Ö': 0xd6, 'Ü': 0xdc, 'ß': 0xdf, '€': 0xa4, '§': 0xa7, '°': 0xb0 },
|
|
41
|
+
replacement: {},
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Ersatzbuchstaben fuer eines der zehn Zeichen (paketintern, fuer
|
|
45
|
+
* `escPosPrintableText` mit gewaehlter Tabelle).
|
|
46
|
+
*/
|
|
47
|
+
function ersatzBuchstaben(zeichen) {
|
|
48
|
+
const ersatz = ERSATZ_BUCHSTABEN[zeichen];
|
|
49
|
+
if (ersatz === undefined)
|
|
50
|
+
throw new Error(`Kein Ersatz fuer ${zeichen}`);
|
|
51
|
+
return ersatz;
|
|
52
|
+
}
|
|
53
|
+
function tabelle(id, number, escT) {
|
|
54
|
+
const bytes = BYTES_JE_TABELLE[id];
|
|
55
|
+
return Object.freeze({ id, number, escT, missing: Object.freeze(ZEHN_ZEICHEN.filter((z) => bytes[z] === undefined)) });
|
|
56
|
+
}
|
|
57
|
+
/** Alle Code-Tabellen in der Reihenfolge des Testblatts (Nummer 1-6). */
|
|
58
|
+
exports.CODE_TABLES = Object.freeze([
|
|
59
|
+
tabelle('wpc1252', 1, 16),
|
|
60
|
+
tabelle('pc858', 2, 19),
|
|
61
|
+
tabelle('pc850', 3, 2),
|
|
62
|
+
tabelle('pc437', 4, 0),
|
|
63
|
+
tabelle('iso8859_15', 5, 40),
|
|
64
|
+
tabelle('replacement', 6, 0),
|
|
65
|
+
]);
|
|
66
|
+
/** Die Tabelle zu einer Kennung; eine unbekannte Kennung wird gemeldet. */
|
|
67
|
+
function codeTableById(id) {
|
|
68
|
+
const gefunden = exports.CODE_TABLES.find((t) => t.id === id);
|
|
69
|
+
if (gefunden === undefined)
|
|
70
|
+
throw new Error(`Unbekannte Code-Tabelle: ${String(id)}`);
|
|
71
|
+
return gefunden;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Tabelle aus der gespeicherten Einstellung (`cp1252`/`cp437`). Alles andere,
|
|
75
|
+
* auch keine Einstellung, ist die Vorgabe `wpc1252`.
|
|
76
|
+
*/
|
|
77
|
+
function codeTableFromSetting(setting) {
|
|
78
|
+
return setting === 'cp437' ? 'pc437' : 'wpc1252';
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Zeichen, die das Vorbild vor dem Kodieren ersetzt (generator.dart `_encode`).
|
|
82
|
+
*
|
|
83
|
+
* **Eine bewusste Abweichung:** Fuer `•` sagt generator.dart `.`,
|
|
84
|
+
* print_paper.dart (portiert als `escPosPrintableText`) dagegen `*`. In Darts
|
|
85
|
+
* eigener Kette faellt das nie auf, weil print_paper vor dem Erzeuger ersetzt
|
|
86
|
+
* und der Erzeuger den Punkt nie zu sehen bekommt -- die gedruckte Antwort ist
|
|
87
|
+
* dort also `*`. Ein Verbraucher dieses Pakets kann `escPosText` aber auch
|
|
88
|
+
* direkt aufrufen, und dann duerfen nicht zwei Zeichen fuer dasselbe Zeichen
|
|
89
|
+
* herauskommen. Deshalb gilt hier dieselbe Antwort wie dort.
|
|
90
|
+
*/
|
|
91
|
+
exports.ZEICHEN_ERSATZ = [
|
|
92
|
+
['’', "'"], // typografisches Apostroph
|
|
93
|
+
['´', "'"], // Akut
|
|
94
|
+
['•', '*'], // Aufzaehlungspunkt (siehe Kommentar oben)
|
|
95
|
+
];
|
|
96
|
+
/**
|
|
97
|
+
* Latin-1-Byte -> CP437-Byte fuer die Zeichen, die CP437 kennt (deutsche
|
|
98
|
+
* Umlaute, ß, westeuropaeische Akzente, Waehrungs-/Sonderzeichen). Alles
|
|
99
|
+
* andere ab 0x80 hat in CP437 keinen Platz und wird zu "?".
|
|
100
|
+
*/
|
|
101
|
+
exports.CP437_AUS_LATIN1 = new Map([
|
|
102
|
+
[0xc7, 0x80], [0xfc, 0x81], [0xe9, 0x82], [0xe2, 0x83], [0xe4, 0x84], [0xe0, 0x85], [0xe5, 0x86], [0xe7, 0x87],
|
|
103
|
+
[0xea, 0x88], [0xeb, 0x89], [0xe8, 0x8a], [0xef, 0x8b], [0xee, 0x8c], [0xec, 0x8d], [0xc4, 0x8e], [0xc5, 0x8f],
|
|
104
|
+
[0xc9, 0x90], [0xe6, 0x91], [0xc6, 0x92], [0xf4, 0x93], [0xf6, 0x94], [0xf2, 0x95], [0xfb, 0x96], [0xf9, 0x97],
|
|
105
|
+
[0xff, 0x98], [0xd6, 0x99], [0xdc, 0x9a], [0xa2, 0x9b], [0xa3, 0x9c], [0xa5, 0x9d], [0xe1, 0xa0], [0xed, 0xa1],
|
|
106
|
+
[0xf3, 0xa2], [0xfa, 0xa3], [0xf1, 0xa4], [0xd1, 0xa5], [0xaa, 0xa6], [0xba, 0xa7], [0xbf, 0xa8], [0xac, 0xaa],
|
|
107
|
+
[0xbd, 0xab], [0xbc, 0xac], [0xa1, 0xad], [0xab, 0xae], [0xbb, 0xaf], [0xdf, 0xe1], [0xb5, 0xe6], [0xb1, 0xf1],
|
|
108
|
+
[0xf7, 0xf6], [0xb0, 0xf8], [0xb7, 0xfa], [0xb2, 0xfd], [0xa0, 0xff],
|
|
109
|
+
]);
|
|
110
|
+
/**
|
|
111
|
+
* Latin-1-Byte -> PC850-Byte (IBM 850, gleich fuer 858 bis auf das €, das
|
|
112
|
+
* die zehn Zeichen oben schon setzen). PC850 hat fuer jedes Latin-1-Zeichen
|
|
113
|
+
* ab 0xA0 einen Platz; die Steuerzeichen 0x80-0x9F werden zu "?".
|
|
114
|
+
*/
|
|
115
|
+
const PC850_AUS_LATIN1 = new Map([
|
|
116
|
+
[0xa0, 0xff], [0xa1, 0xad], [0xa2, 0xbd], [0xa3, 0x9c], [0xa4, 0xcf], [0xa5, 0xbe], [0xa6, 0xdd], [0xa7, 0xf5],
|
|
117
|
+
[0xa8, 0xf9], [0xa9, 0xb8], [0xaa, 0xa6], [0xab, 0xae], [0xac, 0xaa], [0xad, 0xf0], [0xae, 0xa9], [0xaf, 0xee],
|
|
118
|
+
[0xb0, 0xf8], [0xb1, 0xf1], [0xb2, 0xfd], [0xb3, 0xfc], [0xb4, 0xef], [0xb5, 0xe6], [0xb6, 0xf4], [0xb7, 0xfa],
|
|
119
|
+
[0xb8, 0xf7], [0xb9, 0xfb], [0xba, 0xa7], [0xbb, 0xaf], [0xbc, 0xac], [0xbd, 0xab], [0xbe, 0xf3], [0xbf, 0xa8],
|
|
120
|
+
[0xc0, 0xb7], [0xc1, 0xb5], [0xc2, 0xb6], [0xc3, 0xc7], [0xc4, 0x8e], [0xc5, 0x8f], [0xc6, 0x92], [0xc7, 0x80],
|
|
121
|
+
[0xc8, 0xd4], [0xc9, 0x90], [0xca, 0xd2], [0xcb, 0xd3], [0xcc, 0xde], [0xcd, 0xd6], [0xce, 0xd7], [0xcf, 0xd8],
|
|
122
|
+
[0xd0, 0xd1], [0xd1, 0xa5], [0xd2, 0xe3], [0xd3, 0xe0], [0xd4, 0xe2], [0xd5, 0xe5], [0xd6, 0x99], [0xd7, 0x9e],
|
|
123
|
+
[0xd8, 0x9d], [0xd9, 0xeb], [0xda, 0xe9], [0xdb, 0xea], [0xdc, 0x9a], [0xdd, 0xed], [0xde, 0xe8], [0xdf, 0xe1],
|
|
124
|
+
[0xe0, 0x85], [0xe1, 0xa0], [0xe2, 0x83], [0xe3, 0xc6], [0xe4, 0x84], [0xe5, 0x86], [0xe6, 0x91], [0xe7, 0x87],
|
|
125
|
+
[0xe8, 0x8a], [0xe9, 0x82], [0xea, 0x88], [0xeb, 0x89], [0xec, 0x8d], [0xed, 0xa1], [0xee, 0x8c], [0xef, 0x8b],
|
|
126
|
+
[0xf0, 0xd0], [0xf1, 0xa4], [0xf2, 0x95], [0xf3, 0xa2], [0xf4, 0x93], [0xf5, 0xe4], [0xf6, 0x94], [0xf7, 0xf6],
|
|
127
|
+
[0xf8, 0x9b], [0xf9, 0x97], [0xfa, 0xa3], [0xfb, 0x96], [0xfc, 0x81], [0xfd, 0xec], [0xfe, 0xe7], [0xff, 0x98],
|
|
128
|
+
]);
|
|
129
|
+
const FRAGEZEICHEN = 0x3f;
|
|
130
|
+
/**
|
|
131
|
+
* Windows-1252 belegt 0x80-0x9F mit eigenen Zeichen (Latin-1 hat dort nur
|
|
132
|
+
* Steuerzeichen). € setzen die zehn Zeichen, ’ und • ersetzt ZEICHEN_ERSATZ
|
|
133
|
+
* vorher (eine Antwort auf jedem Ausgabeweg); der Rest steht hier.
|
|
134
|
+
*/
|
|
135
|
+
const WPC1252_NEU = new Map([
|
|
136
|
+
[0x201a, 0x82], [0x0192, 0x83], [0x201e, 0x84], [0x2026, 0x85], [0x2020, 0x86], [0x2021, 0x87], [0x02c6, 0x88],
|
|
137
|
+
[0x2030, 0x89], [0x0160, 0x8a], [0x2039, 0x8b], [0x0152, 0x8c], [0x017d, 0x8e], [0x2018, 0x91], [0x2019, 0x92],
|
|
138
|
+
[0x201c, 0x93], [0x201d, 0x94], [0x2022, 0x95], [0x2013, 0x96], [0x2014, 0x97], [0x02dc, 0x98], [0x2122, 0x99],
|
|
139
|
+
[0x0161, 0x9a], [0x203a, 0x9b], [0x0153, 0x9c], [0x017e, 0x9e], [0x0178, 0x9f],
|
|
140
|
+
]);
|
|
141
|
+
/**
|
|
142
|
+
* ISO 8859-15 belegt acht Stellen anders als Latin-1: dort stehen € Š š Ž ž
|
|
143
|
+
* Œ œ Ÿ statt ¤ ¦ ¨ ´ ¸ ¼ ½ ¾. Die acht Latin-1-Zeichen fehlen der Tabelle
|
|
144
|
+
* (Ersetzung, sonst `?`), die neuen stehen hier mit ihrem Byte (€ setzen
|
|
145
|
+
* schon die zehn Zeichen). C1-Steuerzeichen (0x80-0x9F) gehen nie roh hinaus.
|
|
146
|
+
*/
|
|
147
|
+
const ISO8859_15_ANDERS = new Set([0xa4, 0xa6, 0xa8, 0xb4, 0xb8, 0xbc, 0xbd, 0xbe]);
|
|
148
|
+
const ISO8859_15_NEU = new Map([
|
|
149
|
+
[0x0160, 0xa6], [0x0161, 0xa8], [0x017d, 0xb4], [0x017e, 0xb8], [0x0152, 0xbc], [0x0153, 0xbd], [0x0178, 0xbe],
|
|
150
|
+
]);
|
|
151
|
+
/** Byte fuer ein Zeichen ab 0x80, das nicht zu den zehn gehoert. */
|
|
152
|
+
function uebrigesZeichen(codepunkt, id) {
|
|
153
|
+
switch (id) {
|
|
154
|
+
case 'wpc1252':
|
|
155
|
+
if (codepunkt < 0xa0)
|
|
156
|
+
return FRAGEZEICHEN; // C1-Steuerzeichen
|
|
157
|
+
if (codepunkt <= 0xff)
|
|
158
|
+
return codepunkt;
|
|
159
|
+
return WPC1252_NEU.get(codepunkt) ?? FRAGEZEICHEN;
|
|
160
|
+
case 'iso8859_15':
|
|
161
|
+
if (codepunkt < 0xa0)
|
|
162
|
+
return FRAGEZEICHEN; // C1-Steuerzeichen
|
|
163
|
+
if (codepunkt <= 0xff)
|
|
164
|
+
return ISO8859_15_ANDERS.has(codepunkt) ? FRAGEZEICHEN : codepunkt;
|
|
165
|
+
return ISO8859_15_NEU.get(codepunkt) ?? FRAGEZEICHEN;
|
|
166
|
+
case 'pc437':
|
|
167
|
+
return exports.CP437_AUS_LATIN1.get(codepunkt) ?? FRAGEZEICHEN;
|
|
168
|
+
case 'pc858':
|
|
169
|
+
case 'pc850':
|
|
170
|
+
return PC850_AUS_LATIN1.get(codepunkt) ?? FRAGEZEICHEN;
|
|
171
|
+
case 'replacement':
|
|
172
|
+
return FRAGEZEICHEN;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Wandelt Text in die Bytes einer Code-Tabelle: erst die vorhandenen
|
|
177
|
+
* Ersetzungen (`ZEICHEN_ERSATZ`), dann die zehn deutschen Zeichen je Tabelle
|
|
178
|
+
* (Byte oder Ersatzbuchstaben), ASCII unveraendert, alles uebrige ueber die
|
|
179
|
+
* Abbildung der Tabelle, sonst `?`. Ein Zeichen, das die Tabelle nicht
|
|
180
|
+
* kennt, ist genau ein Byte; nur die Ersatzbuchstaben machen aus einem
|
|
181
|
+
* Zeichen mehrere. Spalten darum immer an den fertigen Bytes messen.
|
|
182
|
+
*/
|
|
183
|
+
function encodeForCodeTable(text, table) {
|
|
184
|
+
return encodeReplaced(replaceKnownCharacters(text), table);
|
|
185
|
+
}
|
|
186
|
+
/** Wendet `ZEICHEN_ERSATZ` an (paketintern, nicht exportiert ueber den Einstieg). */
|
|
187
|
+
function replaceKnownCharacters(text) {
|
|
188
|
+
let aufbereitet = text;
|
|
189
|
+
for (const [von, nach] of exports.ZEICHEN_ERSATZ) {
|
|
190
|
+
aufbereitet = aufbereitet.split(von).join(nach);
|
|
191
|
+
}
|
|
192
|
+
return aufbereitet;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Wie `encodeForCodeTable`, aber fuer Text, der `ZEICHEN_ERSATZ` schon hinter
|
|
196
|
+
* sich hat (paketintern: der alte Pfad in `encodeEscPosText` ersetzt vor der
|
|
197
|
+
* Latin-1-Pruefung und soll nicht zweimal ersetzen).
|
|
198
|
+
*/
|
|
199
|
+
function encodeReplaced(aufbereitet, table) {
|
|
200
|
+
const bytesDerTabelle = BYTES_JE_TABELLE[table];
|
|
201
|
+
if (bytesDerTabelle === undefined)
|
|
202
|
+
throw new Error(`Unbekannte Code-Tabelle: ${String(table)}`);
|
|
203
|
+
const bytes = [];
|
|
204
|
+
for (const zeichen of aufbereitet) {
|
|
205
|
+
const codepunkt = zeichen.codePointAt(0);
|
|
206
|
+
if (codepunkt < 0x80) {
|
|
207
|
+
bytes.push(codepunkt);
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
const byte = bytesDerTabelle[zeichen];
|
|
211
|
+
if (byte !== undefined) {
|
|
212
|
+
bytes.push(byte);
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
const ersatz = ERSATZ_BUCHSTABEN[zeichen];
|
|
216
|
+
if (ersatz !== undefined) {
|
|
217
|
+
for (let i = 0; i < ersatz.length; i++)
|
|
218
|
+
bytes.push(ersatz.charCodeAt(i));
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
bytes.push(uebrigesZeichen(codepunkt, table));
|
|
222
|
+
}
|
|
223
|
+
return Uint8Array.from(bytes);
|
|
224
|
+
}
|
|
@@ -23,11 +23,14 @@
|
|
|
23
23
|
* `ESC t 16` und bleiben in CP437; dann werden die Umlaute auf ihre
|
|
24
24
|
* CP437-Plaetze umkodiert (ä = 0x84, ü = 0x81, ß = 0xE1, ...). Zeichen ohne
|
|
25
25
|
* CP437-Platz werden zu `?` — weiterhin ein Byte je Zeichen.
|
|
26
|
+
* Weitere Tabellen (PC858, PC850, ISO 8859-15, reine Ersatzbuchstaben) und
|
|
27
|
+
* ihre `ESC t`-Nummern stehen im Katalog `code-tables.ts`.
|
|
26
28
|
*
|
|
27
29
|
* Nicht enthalten (bewusst): Bilddekodierung (PNG/JPEG liest die Huelle),
|
|
28
30
|
* Capability-Profile einzelner Druckermodelle, Kassenlade, 1D-Barcodes.
|
|
29
31
|
* Fertige einfarbige Rasterbilder (Logo) gehen ueber [escPosRasterImage].
|
|
30
32
|
*/
|
|
33
|
+
import { type CodeTableId } from './code-tables.js';
|
|
31
34
|
import { type QrModuleSize } from './qr-groesse.js';
|
|
32
35
|
/** Papierbreite der Bonrolle. */
|
|
33
36
|
export type PosPaperSize = 'mm58' | 'mm80';
|
|
@@ -37,8 +40,12 @@ export type PosAlign = 'left' | 'center' | 'right';
|
|
|
37
40
|
export type PosFont = 'fontA' | 'fontB';
|
|
38
41
|
/** Voller oder teilweiser Papierschnitt. */
|
|
39
42
|
export type PosCutMode = 'full' | 'partial';
|
|
40
|
-
/**
|
|
41
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Vom Drucker zu verwendende Codepage: eine Tabelle des Katalogs
|
|
45
|
+
* (`CODE_TABLES`) oder einer der alten Namen. `CP1252` entspricht `wpc1252`,
|
|
46
|
+
* `CP437` entspricht `pc437`.
|
|
47
|
+
*/
|
|
48
|
+
export type PosCodeTable = 'CP437' | 'CP1252' | CodeTableId;
|
|
42
49
|
/** Zeichenvergroesserung (1 = einfach, 2 = doppelt, ... bis 8). */
|
|
43
50
|
export type PosTextSize = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
44
51
|
/** Modulgroesse des QR-Codes (Punkte je Modul). */
|
|
@@ -171,10 +178,16 @@ export interface EscPosDocument {
|
|
|
171
178
|
styles: AktuelleStile;
|
|
172
179
|
}
|
|
173
180
|
/**
|
|
174
|
-
* Kodiert Text so, wie ihn der Drucker erwartet: ein Byte je Zeichen
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
181
|
+
* Kodiert Text so, wie ihn der Drucker erwartet: ein Byte je Zeichen in der
|
|
182
|
+
* gewaehlten Tabelle (`encodeForCodeTable`). Ein Umlaut wird damit zu genau
|
|
183
|
+
* einem Byte -- Voraussetzung dafuer, dass die Spaltenrechnung stimmt.
|
|
184
|
+
*
|
|
185
|
+
* Die alten Namen `CP1252` und `CP437` bleiben streng: ein Zeichen ausserhalb
|
|
186
|
+
* Latin-1 wird gemeldet statt verstuemmelt (vorher `escPosPrintableText`
|
|
187
|
+
* anwenden). `CP1252` gibt Latin-1 byte-gleich wie bisher aus (auch ein
|
|
188
|
+
* C1-Steuerzeichen roh, das `wpc1252` zu `?` macht); `CP437` hat die Bytes
|
|
189
|
+
* von `pc437`. Die Tabellen des Katalogs wandeln dagegen jedes Zeichen um
|
|
190
|
+
* (Ersatzbuchstaben, sonst `?`).
|
|
178
191
|
*/
|
|
179
192
|
export declare function encodeEscPosText(text: string, codeTable?: PosCodeTable): Uint8Array;
|
|
180
193
|
/** Zeichen je Zeile fuer Papier und Schrift (`fontA`, wenn nichts gesetzt ist). */
|