@zebrash/core 0.1.0 → 0.1.4
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/assets/fonts-browser.d.ts +2 -0
- package/dist/assets/fonts-browser.d.ts.map +1 -1
- package/dist/assets/fonts-browser.js +6 -0
- package/dist/assets/fonts.d.ts +3 -6
- package/dist/assets/fonts.d.ts.map +1 -1
- package/dist/assets/fonts.js +15 -5
- package/dist/assets/index.d.ts +1 -1
- package/dist/assets/index.d.ts.map +1 -1
- package/dist/assets/index.js +1 -1
- package/dist/drawer-options.d.ts +20 -2
- package/dist/drawer-options.d.ts.map +1 -1
- package/dist/drawer-options.js +3 -1
- package/dist/drawer.d.ts +27 -0
- package/dist/drawer.d.ts.map +1 -1
- package/dist/drawer.js +96 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/svg/emitter.d.ts +76 -0
- package/dist/svg/emitter.d.ts.map +1 -0
- package/dist/svg/emitter.js +207 -0
- package/dist/svg/font_embed.d.ts +12 -0
- package/dist/svg/font_embed.d.ts.map +1 -0
- package/dist/svg/font_embed.js +61 -0
- package/dist/svg-drawers/barcode_128.d.ts +3 -0
- package/dist/svg-drawers/barcode_128.d.ts.map +1 -0
- package/dist/svg-drawers/barcode_128.js +74 -0
- package/dist/svg-drawers/barcode_2of5.d.ts +3 -0
- package/dist/svg-drawers/barcode_2of5.d.ts.map +1 -0
- package/dist/svg-drawers/barcode_2of5.js +36 -0
- package/dist/svg-drawers/barcode_39.d.ts +3 -0
- package/dist/svg-drawers/barcode_39.d.ts.map +1 -0
- package/dist/svg-drawers/barcode_39.js +34 -0
- package/dist/svg-drawers/barcode_aztec.d.ts +3 -0
- package/dist/svg-drawers/barcode_aztec.d.ts.map +1 -0
- package/dist/svg-drawers/barcode_aztec.js +48 -0
- package/dist/svg-drawers/barcode_datamatrix.d.ts +3 -0
- package/dist/svg-drawers/barcode_datamatrix.d.ts.map +1 -0
- package/dist/svg-drawers/barcode_datamatrix.js +44 -0
- package/dist/svg-drawers/barcode_ean13.d.ts +3 -0
- package/dist/svg-drawers/barcode_ean13.d.ts.map +1 -0
- package/dist/svg-drawers/barcode_ean13.js +76 -0
- package/dist/svg-drawers/barcode_paint_svg.d.ts +35 -0
- package/dist/svg-drawers/barcode_paint_svg.d.ts.map +1 -0
- package/dist/svg-drawers/barcode_paint_svg.js +144 -0
- package/dist/svg-drawers/barcode_pdf417.d.ts +3 -0
- package/dist/svg-drawers/barcode_pdf417.d.ts.map +1 -0
- package/dist/svg-drawers/barcode_pdf417.js +43 -0
- package/dist/svg-drawers/barcode_qr.d.ts +3 -0
- package/dist/svg-drawers/barcode_qr.d.ts.map +1 -0
- package/dist/svg-drawers/barcode_qr.js +39 -0
- package/dist/svg-drawers/graphic_box.d.ts +3 -0
- package/dist/svg-drawers/graphic_box.d.ts.map +1 -0
- package/dist/svg-drawers/graphic_box.js +64 -0
- package/dist/svg-drawers/graphic_circle.d.ts +3 -0
- package/dist/svg-drawers/graphic_circle.d.ts.map +1 -0
- package/dist/svg-drawers/graphic_circle.js +19 -0
- package/dist/svg-drawers/graphic_diagonal_line.d.ts +3 -0
- package/dist/svg-drawers/graphic_diagonal_line.d.ts.map +1 -0
- package/dist/svg-drawers/graphic_diagonal_line.js +36 -0
- package/dist/svg-drawers/graphic_field.d.ts +3 -0
- package/dist/svg-drawers/graphic_field.d.ts.map +1 -0
- package/dist/svg-drawers/graphic_field.js +72 -0
- package/dist/svg-drawers/index.d.ts +10 -0
- package/dist/svg-drawers/index.d.ts.map +1 -0
- package/dist/svg-drawers/index.js +41 -0
- package/dist/svg-drawers/maxicode.d.ts +3 -0
- package/dist/svg-drawers/maxicode.d.ts.map +1 -0
- package/dist/svg-drawers/maxicode.js +87 -0
- package/dist/svg-drawers/svg_element_drawer.d.ts +13 -0
- package/dist/svg-drawers/svg_element_drawer.d.ts.map +1 -0
- package/dist/svg-drawers/svg_element_drawer.js +2 -0
- package/dist/svg-drawers/text_field.d.ts +3 -0
- package/dist/svg-drawers/text_field.d.ts.map +1 -0
- package/dist/svg-drawers/text_field.js +264 -0
- package/dist/svg-drawers/transform.d.ts +20 -0
- package/dist/svg-drawers/transform.d.ts.map +1 -0
- package/dist/svg-drawers/transform.js +52 -0
- package/package.json +11 -2
- package/dist/assets/fonts-browser.js.map +0 -1
- package/dist/assets/fonts.js.map +0 -1
- package/dist/assets/index.js.map +0 -1
- package/dist/assets/register.js.map +0 -1
- package/dist/barcodes/aztec/azteccode.js.map +0 -1
- package/dist/barcodes/aztec/encoder.js.map +0 -1
- package/dist/barcodes/aztec/errorcorrection.js.map +0 -1
- package/dist/barcodes/aztec/highlevel.js.map +0 -1
- package/dist/barcodes/aztec/index.js.map +0 -1
- package/dist/barcodes/aztec/state.js.map +0 -1
- package/dist/barcodes/aztec/token.js.map +0 -1
- package/dist/barcodes/code128/code128.js.map +0 -1
- package/dist/barcodes/code128/encoder.js.map +0 -1
- package/dist/barcodes/code128/index.js.map +0 -1
- package/dist/barcodes/code39/encoder.js.map +0 -1
- package/dist/barcodes/code39/index.js.map +0 -1
- package/dist/barcodes/datamatrix/datamatrix_writer.js.map +0 -1
- package/dist/barcodes/datamatrix/encoder/ascii_encoder.js.map +0 -1
- package/dist/barcodes/datamatrix/encoder/base256_encoder.js.map +0 -1
- package/dist/barcodes/datamatrix/encoder/byte_matrix.js.map +0 -1
- package/dist/barcodes/datamatrix/encoder/c40_encoder.js.map +0 -1
- package/dist/barcodes/datamatrix/encoder/datamatrix_symbol_info_144.js.map +0 -1
- package/dist/barcodes/datamatrix/encoder/default_placement.js.map +0 -1
- package/dist/barcodes/datamatrix/encoder/dimension.js.map +0 -1
- package/dist/barcodes/datamatrix/encoder/edifact_encoder.js.map +0 -1
- package/dist/barcodes/datamatrix/encoder/encoder.js.map +0 -1
- package/dist/barcodes/datamatrix/encoder/encoder_context.js.map +0 -1
- package/dist/barcodes/datamatrix/encoder/error_correction.js.map +0 -1
- package/dist/barcodes/datamatrix/encoder/high_level_encoder.js.map +0 -1
- package/dist/barcodes/datamatrix/encoder/options.js.map +0 -1
- package/dist/barcodes/datamatrix/encoder/symbol_info.js.map +0 -1
- package/dist/barcodes/datamatrix/encoder/symbol_shape_hint.js.map +0 -1
- package/dist/barcodes/datamatrix/encoder/text_encoder.js.map +0 -1
- package/dist/barcodes/datamatrix/encoder/x12_encoder.js.map +0 -1
- package/dist/barcodes/datamatrix/index.js.map +0 -1
- package/dist/barcodes/ean13/ean13.js.map +0 -1
- package/dist/barcodes/ean13/encoder.js.map +0 -1
- package/dist/barcodes/ean13/index.js.map +0 -1
- package/dist/barcodes/maxicode/index.js.map +0 -1
- package/dist/barcodes/maxicode/maxicode.js.map +0 -1
- package/dist/barcodes/maxicode/readsolomon.js.map +0 -1
- package/dist/barcodes/maxicode/symbolgrid.js.map +0 -1
- package/dist/barcodes/pdf417/codewords.js.map +0 -1
- package/dist/barcodes/pdf417/dimensions.js.map +0 -1
- package/dist/barcodes/pdf417/encoder.js.map +0 -1
- package/dist/barcodes/pdf417/errorcorrection.js.map +0 -1
- package/dist/barcodes/pdf417/highlevel.js.map +0 -1
- package/dist/barcodes/pdf417/index.js.map +0 -1
- package/dist/barcodes/qrcode/encoder/block-pair.js.map +0 -1
- package/dist/barcodes/qrcode/encoder/byte-matrix.js.map +0 -1
- package/dist/barcodes/qrcode/encoder/character-set-eci.js.map +0 -1
- package/dist/barcodes/qrcode/encoder/encoder.js.map +0 -1
- package/dist/barcodes/qrcode/encoder/error-correction-level.js.map +0 -1
- package/dist/barcodes/qrcode/encoder/format-information.js.map +0 -1
- package/dist/barcodes/qrcode/encoder/index.js.map +0 -1
- package/dist/barcodes/qrcode/encoder/mask-util.js.map +0 -1
- package/dist/barcodes/qrcode/encoder/matrix-util.js.map +0 -1
- package/dist/barcodes/qrcode/encoder/mode.js.map +0 -1
- package/dist/barcodes/qrcode/encoder/options.js.map +0 -1
- package/dist/barcodes/qrcode/encoder/qrcode.js.map +0 -1
- package/dist/barcodes/qrcode/encoder/string-utils.js.map +0 -1
- package/dist/barcodes/qrcode/encoder/version.js.map +0 -1
- package/dist/barcodes/qrcode/index.js.map +0 -1
- package/dist/barcodes/qrcode/qrcode-writer.js.map +0 -1
- package/dist/barcodes/twooffive/encoder.js.map +0 -1
- package/dist/barcodes/twooffive/index.js.map +0 -1
- package/dist/barcodes/utils/bit_array.js.map +0 -1
- package/dist/barcodes/utils/bit_matrix.js.map +0 -1
- package/dist/barcodes/utils/bitlist.js.map +0 -1
- package/dist/barcodes/utils/bitlist_image.js.map +0 -1
- package/dist/barcodes/utils/bitlist_widenarrow.js.map +0 -1
- package/dist/barcodes/utils/bitops.js.map +0 -1
- package/dist/barcodes/utils/galoisfield.js.map +0 -1
- package/dist/barcodes/utils/gfpoly.js.map +0 -1
- package/dist/barcodes/utils/index.js.map +0 -1
- package/dist/barcodes/utils/reedsolomon.js.map +0 -1
- package/dist/barcodes/utils/runeint.js.map +0 -1
- package/dist/drawer-options.js.map +0 -1
- package/dist/drawer.js.map +0 -1
- package/dist/drawers/barcode_128.js.map +0 -1
- package/dist/drawers/barcode_2of5.js.map +0 -1
- package/dist/drawers/barcode_39.js.map +0 -1
- package/dist/drawers/barcode_aztec.js.map +0 -1
- package/dist/drawers/barcode_datamatrix.js.map +0 -1
- package/dist/drawers/barcode_ean13.js.map +0 -1
- package/dist/drawers/barcode_paint.js.map +0 -1
- package/dist/drawers/barcode_pdf417.js.map +0 -1
- package/dist/drawers/barcode_qr.js.map +0 -1
- package/dist/drawers/drawer_state.js.map +0 -1
- package/dist/drawers/element_drawer.js.map +0 -1
- package/dist/drawers/graphic_box.js.map +0 -1
- package/dist/drawers/graphic_circle.js.map +0 -1
- package/dist/drawers/graphic_diagonal_line.js.map +0 -1
- package/dist/drawers/graphic_field.js.map +0 -1
- package/dist/drawers/index.js.map +0 -1
- package/dist/drawers/maxicode.js.map +0 -1
- package/dist/drawers/text_field.js.map +0 -1
- package/dist/elements/barcode_128.js.map +0 -1
- package/dist/elements/barcode_2of5.js.map +0 -1
- package/dist/elements/barcode_39.js.map +0 -1
- package/dist/elements/barcode_aztec.js.map +0 -1
- package/dist/elements/barcode_datamatrix.js.map +0 -1
- package/dist/elements/barcode_ean13.js.map +0 -1
- package/dist/elements/barcode_info.js.map +0 -1
- package/dist/elements/barcode_pdf417.js.map +0 -1
- package/dist/elements/barcode_qr.js.map +0 -1
- package/dist/elements/field_alignment.js.map +0 -1
- package/dist/elements/field_block.js.map +0 -1
- package/dist/elements/field_info.js.map +0 -1
- package/dist/elements/field_orientation.js.map +0 -1
- package/dist/elements/font.js.map +0 -1
- package/dist/elements/graphic_box.js.map +0 -1
- package/dist/elements/graphic_circle.js.map +0 -1
- package/dist/elements/graphic_diagonal_line.js.map +0 -1
- package/dist/elements/graphic_field.js.map +0 -1
- package/dist/elements/graphic_symbol.js.map +0 -1
- package/dist/elements/index.js.map +0 -1
- package/dist/elements/label_info.js.map +0 -1
- package/dist/elements/label_position.js.map +0 -1
- package/dist/elements/line_color.js.map +0 -1
- package/dist/elements/maxicode.js.map +0 -1
- package/dist/elements/reverse_print.js.map +0 -1
- package/dist/elements/stored_format.js.map +0 -1
- package/dist/elements/stored_graphics.js.map +0 -1
- package/dist/elements/text_alignment.js.map +0 -1
- package/dist/elements/text_field.js.map +0 -1
- package/dist/encodings/decode.js.map +0 -1
- package/dist/encodings/index.js.map +0 -1
- package/dist/hex/decode.js.map +0 -1
- package/dist/hex/index.js.map +0 -1
- package/dist/images/colors.js.map +0 -1
- package/dist/images/encode.js.map +0 -1
- package/dist/images/index.js.map +0 -1
- package/dist/images/reverse_print.js.map +0 -1
- package/dist/images/scaled.js.map +0 -1
- package/dist/images/zerofill.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/parser.js.map +0 -1
- package/dist/parsers/barcode_128.js.map +0 -1
- package/dist/parsers/barcode_2of5.js.map +0 -1
- package/dist/parsers/barcode_39.js.map +0 -1
- package/dist/parsers/barcode_aztec.js.map +0 -1
- package/dist/parsers/barcode_datamatrix.js.map +0 -1
- package/dist/parsers/barcode_ean13.js.map +0 -1
- package/dist/parsers/barcode_field_defaults.js.map +0 -1
- package/dist/parsers/barcode_parsers.js.map +0 -1
- package/dist/parsers/barcode_pdf417.js.map +0 -1
- package/dist/parsers/barcode_qr.js.map +0 -1
- package/dist/parsers/change_charset.js.map +0 -1
- package/dist/parsers/change_default_font.js.map +0 -1
- package/dist/parsers/change_font.js.map +0 -1
- package/dist/parsers/change_font_alias.js.map +0 -1
- package/dist/parsers/command_parser.js.map +0 -1
- package/dist/parsers/download_format.js.map +0 -1
- package/dist/parsers/download_graphics.js.map +0 -1
- package/dist/parsers/download_unbounded_ttf.js.map +0 -1
- package/dist/parsers/field_block.js.map +0 -1
- package/dist/parsers/field_data.js.map +0 -1
- package/dist/parsers/field_number.js.map +0 -1
- package/dist/parsers/field_orientation.js.map +0 -1
- package/dist/parsers/field_origin.js.map +0 -1
- package/dist/parsers/field_reverse_print.js.map +0 -1
- package/dist/parsers/field_separator.js.map +0 -1
- package/dist/parsers/field_typeset.js.map +0 -1
- package/dist/parsers/field_value.js.map +0 -1
- package/dist/parsers/graphic_box.js.map +0 -1
- package/dist/parsers/graphic_circle.js.map +0 -1
- package/dist/parsers/graphic_diagonal_line.js.map +0 -1
- package/dist/parsers/graphic_field.js.map +0 -1
- package/dist/parsers/graphic_format_parsers.js.map +0 -1
- package/dist/parsers/graphic_symbol.js.map +0 -1
- package/dist/parsers/hex_escape.js.map +0 -1
- package/dist/parsers/image_load.js.map +0 -1
- package/dist/parsers/index.js.map +0 -1
- package/dist/parsers/label_home.js.map +0 -1
- package/dist/parsers/label_reverse_print.js.map +0 -1
- package/dist/parsers/maxicode.js.map +0 -1
- package/dist/parsers/print_orientation.js.map +0 -1
- package/dist/parsers/print_width.js.map +0 -1
- package/dist/parsers/recall_format.js.map +0 -1
- package/dist/parsers/recall_graphics.js.map +0 -1
- package/dist/platform/browser.js.map +0 -1
- package/dist/platform/inflate.js.map +0 -1
- package/dist/platform/node.js.map +0 -1
- package/dist/platform/types.js.map +0 -1
- package/dist/platform-browser.js.map +0 -1
- package/dist/platform.js.map +0 -1
- package/dist/printers/fs.js.map +0 -1
- package/dist/printers/index.js.map +0 -1
- package/dist/printers/virtual.js.map +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SvgFontEmbedMode } from "../drawer-options.ts";
|
|
2
|
+
import { type FontKey } from "../assets/fonts.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Build the `<style>` body that goes inside the SVG's `<defs>` for the
|
|
5
|
+
* fonts the label actually uses.
|
|
6
|
+
*
|
|
7
|
+
* `mode === "url"` → `@font-face { src: url("<cdn>/font.ttf") format("truetype"); }`
|
|
8
|
+
* `mode === "embed"` → `@font-face { src: url("data:font/ttf;base64,…") format("truetype"); }`
|
|
9
|
+
* `mode === "none"` → empty string (caller's `<text font-family>` is on its own).
|
|
10
|
+
*/
|
|
11
|
+
export declare function buildFontFaceCss(usedFonts: ReadonlySet<FontKey>, mode: SvgFontEmbedMode): Promise<string>;
|
|
12
|
+
//# sourceMappingURL=font_embed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"font_embed.d.ts","sourceRoot":"","sources":["../../src/svg/font_embed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,OAAO,EAAE,KAAK,OAAO,EAAoD,MAAM,oBAAoB,CAAC;AAUpG;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,CACpC,SAAS,EAAE,WAAW,CAAC,OAAO,CAAC,EAC/B,IAAI,EAAE,gBAAgB,GACrB,OAAO,CAAC,MAAM,CAAC,CAqBjB"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { getEmbeddedFont, getFontBaseUrl, getFontFilename } from "../assets/fonts.js";
|
|
2
|
+
import { EmbeddedFontFamilies } from "../assets/register.js";
|
|
3
|
+
const familyByKey = {
|
|
4
|
+
HelveticaBold: EmbeddedFontFamilies.HelveticaBold,
|
|
5
|
+
DejavuSansMono: EmbeddedFontFamilies.DejavuSansMono,
|
|
6
|
+
DejavuSansMonoBold: EmbeddedFontFamilies.DejavuSansMonoBold,
|
|
7
|
+
ZplGS: EmbeddedFontFamilies.ZplGS,
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Build the `<style>` body that goes inside the SVG's `<defs>` for the
|
|
11
|
+
* fonts the label actually uses.
|
|
12
|
+
*
|
|
13
|
+
* `mode === "url"` → `@font-face { src: url("<cdn>/font.ttf") format("truetype"); }`
|
|
14
|
+
* `mode === "embed"` → `@font-face { src: url("data:font/ttf;base64,…") format("truetype"); }`
|
|
15
|
+
* `mode === "none"` → empty string (caller's `<text font-family>` is on its own).
|
|
16
|
+
*/
|
|
17
|
+
export async function buildFontFaceCss(usedFonts, mode) {
|
|
18
|
+
if (mode === "none" || usedFonts.size === 0)
|
|
19
|
+
return "";
|
|
20
|
+
if (mode === "url") {
|
|
21
|
+
const base = getFontBaseUrl();
|
|
22
|
+
const rules = [...usedFonts].map((key) => {
|
|
23
|
+
const url = base + getFontFilename(key);
|
|
24
|
+
return faceRule(familyByKey[key], `url("${url}") format("truetype")`);
|
|
25
|
+
});
|
|
26
|
+
return wrap(rules);
|
|
27
|
+
}
|
|
28
|
+
// mode === "embed"
|
|
29
|
+
const rules = await Promise.all([...usedFonts].map(async (key) => {
|
|
30
|
+
const bytes = await getEmbeddedFont(key);
|
|
31
|
+
const b64 = base64Encode(bytes);
|
|
32
|
+
return faceRule(familyByKey[key], `url("data:font/ttf;base64,${b64}") format("truetype")`);
|
|
33
|
+
}));
|
|
34
|
+
return wrap(rules);
|
|
35
|
+
}
|
|
36
|
+
function faceRule(family, src) {
|
|
37
|
+
return `@font-face{font-family:"${family}";src:${src};font-weight:normal;font-style:normal;}`;
|
|
38
|
+
}
|
|
39
|
+
function wrap(rules) {
|
|
40
|
+
return `<style>${rules.join("")}</style>`;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Universal base64 encoder. Uses `Buffer` on Node (faster, handles huge
|
|
44
|
+
* inputs without repeated string concat), falls back to `btoa(String
|
|
45
|
+
* .fromCharCode(...))` chunked-loop on the browser. The `fromCharCode`
|
|
46
|
+
* spread is chunked to stay under the JS engine's argument-count limit on
|
|
47
|
+
* very large arrays.
|
|
48
|
+
*/
|
|
49
|
+
function base64Encode(bytes) {
|
|
50
|
+
if (typeof Buffer !== "undefined") {
|
|
51
|
+
return Buffer.from(bytes).toString("base64");
|
|
52
|
+
}
|
|
53
|
+
let bin = "";
|
|
54
|
+
const chunk = 0x8000;
|
|
55
|
+
for (let i = 0; i < bytes.length; i += chunk) {
|
|
56
|
+
const slice = bytes.subarray(i, Math.min(i + chunk, bytes.length));
|
|
57
|
+
bin += String.fromCharCode(...slice);
|
|
58
|
+
}
|
|
59
|
+
return btoa(bin);
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=font_embed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barcode_128.d.ts","sourceRoot":"","sources":["../../src/svg-drawers/barcode_128.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAehE,wBAAgB,sBAAsB,IAAI,gBAAgB,CAsDzD"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// SVG analogue of `drawers/barcode_128.ts`.
|
|
2
|
+
import { ESCAPE_FNC_1, encodeCode128Auto, encodeCode128NoMode } from "../barcodes/code128/index.js";
|
|
3
|
+
import { adjustImageTypeSetPosition } from "../drawers/element_drawer.js";
|
|
4
|
+
import { BarcodeModeEan, BarcodeModeNo, BarcodeModeUcc, } from "../elements/index.js";
|
|
5
|
+
import { paintBitArrayBarsSvg, paintHumanReadableTextSvg } from "./barcode_paint_svg.js";
|
|
6
|
+
import { rotateForOrientation } from "./transform.js";
|
|
7
|
+
const PARENS_AND_SPACES = /[()\s]+/g;
|
|
8
|
+
export function newBarcode128SvgDrawer() {
|
|
9
|
+
return {
|
|
10
|
+
draw(emitter, element) {
|
|
11
|
+
const barcode = element;
|
|
12
|
+
if (!barcode || barcode._kind !== "Barcode128WithData")
|
|
13
|
+
return;
|
|
14
|
+
let content = barcode.data;
|
|
15
|
+
let text = barcode.data;
|
|
16
|
+
if (barcode.mode === BarcodeModeEan) {
|
|
17
|
+
const ean = modifyBarcodeContentEanMode(content);
|
|
18
|
+
content = ean.content;
|
|
19
|
+
text = ean.text;
|
|
20
|
+
}
|
|
21
|
+
else if (barcode.mode === BarcodeModeUcc) {
|
|
22
|
+
content = modifyBarcodeContentUccMode(content);
|
|
23
|
+
}
|
|
24
|
+
const moduleWidth = Math.max(barcode.width, 1);
|
|
25
|
+
const moduleHeight = Math.max(barcode.height, 1);
|
|
26
|
+
let bits;
|
|
27
|
+
if (barcode.mode === BarcodeModeNo) {
|
|
28
|
+
const out = encodeCode128NoMode(content);
|
|
29
|
+
bits = [...out.bits];
|
|
30
|
+
text = out.humanReadable;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
const out = encodeCode128Auto(content);
|
|
34
|
+
bits = [...out.bits];
|
|
35
|
+
}
|
|
36
|
+
const width = bits.length * moduleWidth;
|
|
37
|
+
const height = moduleHeight;
|
|
38
|
+
const pos = adjustImageTypeSetPosition(width, height, barcode.position, barcode.orientation);
|
|
39
|
+
emitter.save();
|
|
40
|
+
try {
|
|
41
|
+
rotateForOrientation(emitter, width, height, pos, barcode.orientation);
|
|
42
|
+
paintBitArrayBarsSvg(emitter, bits, pos, moduleWidth, height);
|
|
43
|
+
if (barcode.line) {
|
|
44
|
+
paintHumanReadableTextSvg(emitter, text, pos, barcode.lineAbove, moduleWidth, width, height);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
emitter.restore();
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function modifyBarcodeContentEanMode(content) {
|
|
54
|
+
const text = content.replaceAll(">8", "");
|
|
55
|
+
let next = content.replace(PARENS_AND_SPACES, "");
|
|
56
|
+
next = next.replaceAll(">8", ESCAPE_FNC_1);
|
|
57
|
+
if (!next.startsWith(ESCAPE_FNC_1))
|
|
58
|
+
next = ESCAPE_FNC_1 + next;
|
|
59
|
+
return { content: next, text };
|
|
60
|
+
}
|
|
61
|
+
function modifyBarcodeContentUccMode(content) {
|
|
62
|
+
const padded = content.padStart(19, "0").slice(0, 19);
|
|
63
|
+
const checksumDigit = calculateUccBarcodeChecksumDigit(padded);
|
|
64
|
+
return ESCAPE_FNC_1 + padded + checksumDigit;
|
|
65
|
+
}
|
|
66
|
+
function calculateUccBarcodeChecksumDigit(content) {
|
|
67
|
+
let checksum = 0;
|
|
68
|
+
for (let i = 0; i < 19; i++) {
|
|
69
|
+
const code = content.charCodeAt(i) - 48;
|
|
70
|
+
checksum += code * ((i % 2) * 2 + 7);
|
|
71
|
+
}
|
|
72
|
+
return checksum % 10;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=barcode_128.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barcode_2of5.d.ts","sourceRoot":"","sources":["../../src/svg-drawers/barcode_2of5.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAShE,wBAAgB,uBAAuB,IAAI,gBAAgB,CAsC1D"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// SVG analogue of `drawers/barcode_2of5.ts`.
|
|
2
|
+
import { encodeInterleaved2of5 } from "../barcodes/twooffive/index.js";
|
|
3
|
+
import { adjustImageTypeSetPosition } from "../drawers/element_drawer.js";
|
|
4
|
+
import { paintBitArrayBarsSvg, paintHumanReadableTextSvg } from "./barcode_paint_svg.js";
|
|
5
|
+
import { rotateForOrientation } from "./transform.js";
|
|
6
|
+
const NON_DIGIT = /[^0-9]+/g;
|
|
7
|
+
export function newBarcode2of5SvgDrawer() {
|
|
8
|
+
return {
|
|
9
|
+
draw(emitter, element) {
|
|
10
|
+
const barcode = element;
|
|
11
|
+
if (!barcode || barcode._kind !== "Barcode2of5WithData")
|
|
12
|
+
return;
|
|
13
|
+
const content = barcode.data.replace(NON_DIGIT, "");
|
|
14
|
+
const moduleWidth = Math.max(barcode.width, 1);
|
|
15
|
+
const moduleHeight = Math.max(barcode.height, 1);
|
|
16
|
+
const result = encodeInterleaved2of5(content, barcode.checkDigit);
|
|
17
|
+
const bits = result.bits;
|
|
18
|
+
const text = result.content;
|
|
19
|
+
const width = bits.length * moduleWidth;
|
|
20
|
+
const height = moduleHeight;
|
|
21
|
+
const pos = adjustImageTypeSetPosition(width, height, barcode.position, barcode.orientation);
|
|
22
|
+
emitter.save();
|
|
23
|
+
try {
|
|
24
|
+
rotateForOrientation(emitter, width, height, pos, barcode.orientation);
|
|
25
|
+
paintBitArrayBarsSvg(emitter, bits, pos, moduleWidth, height);
|
|
26
|
+
if (barcode.line) {
|
|
27
|
+
paintHumanReadableTextSvg(emitter, text, pos, barcode.lineAbove, moduleWidth, width, height);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
emitter.restore();
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=barcode_2of5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barcode_39.d.ts","sourceRoot":"","sources":["../../src/svg-drawers/barcode_39.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAOhE,wBAAgB,qBAAqB,IAAI,gBAAgB,CAqCxD"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// SVG analogue of `drawers/barcode_39.ts`.
|
|
2
|
+
import { encodeCode39 } from "../barcodes/code39/index.js";
|
|
3
|
+
import { adjustImageTypeSetPosition } from "../drawers/element_drawer.js";
|
|
4
|
+
import { paintBitArrayBarsSvg, paintHumanReadableTextSvg } from "./barcode_paint_svg.js";
|
|
5
|
+
import { rotateForOrientation } from "./transform.js";
|
|
6
|
+
export function newBarcode39SvgDrawer() {
|
|
7
|
+
return {
|
|
8
|
+
draw(emitter, element) {
|
|
9
|
+
const barcode = element;
|
|
10
|
+
if (!barcode || barcode._kind !== "Barcode39WithData")
|
|
11
|
+
return;
|
|
12
|
+
const content = barcode.data;
|
|
13
|
+
const text = `*${barcode.data}*`;
|
|
14
|
+
const moduleWidth = Math.max(barcode.width, 1);
|
|
15
|
+
const moduleHeight = Math.max(barcode.height, 1);
|
|
16
|
+
const bits = encodeCode39(content);
|
|
17
|
+
const width = bits.length * moduleWidth;
|
|
18
|
+
const height = moduleHeight;
|
|
19
|
+
const pos = adjustImageTypeSetPosition(width, height, barcode.position, barcode.orientation);
|
|
20
|
+
emitter.save();
|
|
21
|
+
try {
|
|
22
|
+
rotateForOrientation(emitter, width, height, pos, barcode.orientation);
|
|
23
|
+
paintBitArrayBarsSvg(emitter, bits, pos, moduleWidth, height);
|
|
24
|
+
if (barcode.line) {
|
|
25
|
+
paintHumanReadableTextSvg(emitter, text, pos, barcode.lineAbove, moduleWidth, width, height);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
emitter.restore();
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=barcode_39.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barcode_aztec.d.ts","sourceRoot":"","sources":["../../src/svg-drawers/barcode_aztec.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAahE,wBAAgB,wBAAwB,IAAI,gBAAgB,CAwC3D"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// SVG analogue of `drawers/barcode_aztec.ts`.
|
|
2
|
+
import { AZTEC_DEFAULT_EC_PERCENT, AZTEC_DEFAULT_LAYERS, encodeAztec, } from "../barcodes/aztec/index.js";
|
|
3
|
+
import { adjustImageTypeSetPosition } from "../drawers/element_drawer.js";
|
|
4
|
+
import { paintBitMatrixCellsSvg } from "./barcode_paint_svg.js";
|
|
5
|
+
import { rotateForOrientation } from "./transform.js";
|
|
6
|
+
const SIZE_FULL_RANGE_OFFSET = 200;
|
|
7
|
+
export function newBarcodeAztecSvgDrawer() {
|
|
8
|
+
return {
|
|
9
|
+
draw(emitter, element) {
|
|
10
|
+
const barcode = element;
|
|
11
|
+
if (!barcode || barcode._kind !== "BarcodeAztecWithData")
|
|
12
|
+
return;
|
|
13
|
+
let layers = AZTEC_DEFAULT_LAYERS;
|
|
14
|
+
let minECCPercent = AZTEC_DEFAULT_EC_PERCENT;
|
|
15
|
+
if (barcode.size > 0) {
|
|
16
|
+
if (barcode.size >= SIZE_FULL_RANGE_OFFSET && barcode.size <= SIZE_FULL_RANGE_OFFSET + 32) {
|
|
17
|
+
layers = barcode.size - SIZE_FULL_RANGE_OFFSET;
|
|
18
|
+
}
|
|
19
|
+
else if (barcode.size >= 1 && barcode.size <= 99) {
|
|
20
|
+
minECCPercent = barcode.size;
|
|
21
|
+
}
|
|
22
|
+
else if (barcode.size >= 101 && barcode.size <= 104) {
|
|
23
|
+
layers = -(barcode.size - 100);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
throw new Error(`aztec barcode size/mode ${barcode.size} is not supported`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const magnification = Math.max(barcode.magnification, 1);
|
|
30
|
+
const matrix = encodeAztec(new TextEncoder().encode(barcode.data), {
|
|
31
|
+
minECCPercent,
|
|
32
|
+
userSpecifiedLayers: layers,
|
|
33
|
+
});
|
|
34
|
+
const width = matrix.width * magnification;
|
|
35
|
+
const height = matrix.height * magnification;
|
|
36
|
+
const pos = adjustImageTypeSetPosition(width, height, barcode.position, barcode.orientation);
|
|
37
|
+
emitter.save();
|
|
38
|
+
try {
|
|
39
|
+
rotateForOrientation(emitter, width, height, pos, barcode.orientation);
|
|
40
|
+
paintBitMatrixCellsSvg(emitter, matrix, pos, magnification);
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
emitter.restore();
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=barcode_aztec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barcode_datamatrix.d.ts","sourceRoot":"","sources":["../../src/svg-drawers/barcode_datamatrix.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAWhE,wBAAgB,6BAA6B,IAAI,gBAAgB,CAsChE"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// SVG analogue of `drawers/barcode_datamatrix.ts`.
|
|
2
|
+
import { SymbolShapeHint } from "../barcodes/datamatrix/encoder/symbol_shape_hint.js";
|
|
3
|
+
import { encodeDatamatrix } from "../barcodes/datamatrix/index.js";
|
|
4
|
+
import { adjustImageTypeSetPosition } from "../drawers/element_drawer.js";
|
|
5
|
+
import { DatamatrixRatioRectangular } from "../elements/index.js";
|
|
6
|
+
import { paintBitMatrixCellsSvg } from "./barcode_paint_svg.js";
|
|
7
|
+
import { rotateForOrientation } from "./transform.js";
|
|
8
|
+
const GS_BYTE = String.fromCharCode(29);
|
|
9
|
+
export function newBarcodeDatamatrixSvgDrawer() {
|
|
10
|
+
return {
|
|
11
|
+
draw(emitter, element) {
|
|
12
|
+
const barcode = element;
|
|
13
|
+
if (!barcode || barcode._kind !== "BarcodeDatamatrixWithData")
|
|
14
|
+
return;
|
|
15
|
+
const columns = Math.max(barcode.columns, 1);
|
|
16
|
+
const rows = Math.max(barcode.rows, 1);
|
|
17
|
+
const shape = barcode.ratio === DatamatrixRatioRectangular
|
|
18
|
+
? SymbolShapeHint.FORCE_RECTANGLE
|
|
19
|
+
: SymbolShapeHint.FORCE_SQUARE;
|
|
20
|
+
let data = barcode.data;
|
|
21
|
+
const fnc1 = `${barcode.escape}1`;
|
|
22
|
+
let gs1 = false;
|
|
23
|
+
if (data.startsWith(fnc1)) {
|
|
24
|
+
gs1 = true;
|
|
25
|
+
data = data.slice(fnc1.length);
|
|
26
|
+
}
|
|
27
|
+
data = data.replaceAll(fnc1, GS_BYTE);
|
|
28
|
+
const matrix = encodeDatamatrix(data, columns, rows, { shape, gs1 });
|
|
29
|
+
const scale = Math.max(barcode.height, 1);
|
|
30
|
+
const width = matrix.width * scale;
|
|
31
|
+
const height = matrix.height * scale;
|
|
32
|
+
const pos = adjustImageTypeSetPosition(width, height, barcode.position, barcode.orientation);
|
|
33
|
+
emitter.save();
|
|
34
|
+
try {
|
|
35
|
+
rotateForOrientation(emitter, width, height, pos, barcode.orientation);
|
|
36
|
+
paintBitMatrixCellsSvg(emitter, matrix, pos, scale);
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
emitter.restore();
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=barcode_datamatrix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barcode_ean13.d.ts","sourceRoot":"","sources":["../../src/svg-drawers/barcode_ean13.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAqBhE,wBAAgB,wBAAwB,IAAI,gBAAgB,CAwC3D"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// SVG analogue of `drawers/barcode_ean13.ts`.
|
|
2
|
+
import { calculateEan13GuardExtension, encodeEan13, isGuardBar, sanitizeContent, } from "../barcodes/ean13/index.js";
|
|
3
|
+
import { adjustImageTypeSetPosition } from "../drawers/element_drawer.js";
|
|
4
|
+
import { FieldOrientation90, FieldOrientation180, } from "../elements/index.js";
|
|
5
|
+
import { paintEan13TextSvg } from "./barcode_paint_svg.js";
|
|
6
|
+
import { rotateForOrientation } from "./transform.js";
|
|
7
|
+
const BLACK = "#000000";
|
|
8
|
+
export function newBarcodeEan13SvgDrawer() {
|
|
9
|
+
return {
|
|
10
|
+
draw(emitter, element) {
|
|
11
|
+
const barcode = element;
|
|
12
|
+
if (!barcode || barcode._kind !== "BarcodeEan13WithData")
|
|
13
|
+
return;
|
|
14
|
+
const moduleWidth = Math.max(barcode.width, 1);
|
|
15
|
+
const moduleHeight = Math.max(barcode.height, 1);
|
|
16
|
+
const text = sanitizeContent(barcode.data);
|
|
17
|
+
const bits = encodeEan13(text);
|
|
18
|
+
if (bits === null)
|
|
19
|
+
return;
|
|
20
|
+
const width = bits.length * moduleWidth;
|
|
21
|
+
const height = moduleHeight;
|
|
22
|
+
const guardExtension = calculateEan13GuardExtension(moduleWidth);
|
|
23
|
+
let pos = adjustImageTypeSetPosition(width, height, barcode.position, barcode.orientation);
|
|
24
|
+
pos = adjustEan13Position(pos, barcode.orientation, guardExtension);
|
|
25
|
+
emitter.save();
|
|
26
|
+
try {
|
|
27
|
+
rotateForOrientation(emitter, width, height, pos, barcode.orientation);
|
|
28
|
+
paintEan13BarsSvg(emitter, bits, pos, moduleWidth, height, guardExtension);
|
|
29
|
+
if (barcode.line) {
|
|
30
|
+
paintEan13TextSvg(emitter, text, pos, barcode.lineAbove, width, height, moduleWidth, guardExtension);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
emitter.restore();
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* EAN-13 bar painting: guard bars (start, middle, end groups) extend the
|
|
41
|
+
* full `barHeight + guardExtension`; data bars stop at `barHeight` so the
|
|
42
|
+
* digits sit in the remaining white space.
|
|
43
|
+
*
|
|
44
|
+
* Two-height variant precludes the run-collapse trick used elsewhere —
|
|
45
|
+
* adjacent bars may differ in height, so we emit them per-module.
|
|
46
|
+
*/
|
|
47
|
+
function paintEan13BarsSvg(emitter, bits, pos, moduleWidth, barHeight, guardExtension) {
|
|
48
|
+
const len = bits.length;
|
|
49
|
+
for (let i = 0; i < len; i++) {
|
|
50
|
+
if (!bits.at(i))
|
|
51
|
+
continue;
|
|
52
|
+
const x = pos.x + i * moduleWidth;
|
|
53
|
+
const h = isGuardBar(i) ? barHeight + guardExtension : barHeight;
|
|
54
|
+
emitter.rect(x, pos.y, moduleWidth, h, BLACK);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function adjustEan13Position(pos, ori, guardExtension) {
|
|
58
|
+
if (pos.calculateFromBottom)
|
|
59
|
+
return pos;
|
|
60
|
+
let { x, y } = pos;
|
|
61
|
+
switch (ori) {
|
|
62
|
+
case FieldOrientation90:
|
|
63
|
+
x -= guardExtension;
|
|
64
|
+
break;
|
|
65
|
+
case FieldOrientation180:
|
|
66
|
+
y -= guardExtension;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
x,
|
|
71
|
+
y,
|
|
72
|
+
calculateFromBottom: pos.calculateFromBottom,
|
|
73
|
+
automaticPosition: pos.automaticPosition,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=barcode_ean13.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { BitMatrix } from "../barcodes/utils/index.ts";
|
|
2
|
+
import type { LabelPosition } from "../elements/index.ts";
|
|
3
|
+
import type { SvgEmitter } from "../svg/emitter.ts";
|
|
4
|
+
/** Minimal shape for any 1D bit sequence painter input — same as canvas helper. */
|
|
5
|
+
export interface BitSequence {
|
|
6
|
+
readonly length: number;
|
|
7
|
+
at(i: number): boolean | undefined;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Walk a 1D bit pattern and emit vertical bars `moduleWidth` wide and
|
|
11
|
+
* `barHeight` tall, starting at `pos`. Adjacent dark modules merge into a
|
|
12
|
+
* single wider `<rect>`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function paintBitArrayBarsSvg(emitter: SvgEmitter, bits: BitSequence | readonly boolean[], pos: LabelPosition, moduleWidth: number, barHeight: number): void;
|
|
15
|
+
/**
|
|
16
|
+
* Walk a 2D bit matrix and emit cells. `moduleSize` is the cell width;
|
|
17
|
+
* `moduleHeight` defaults to a square cell (used by QR/Aztec/DataMatrix)
|
|
18
|
+
* but can be passed separately for PDF417 where rows are taller than they
|
|
19
|
+
* are wide. Horizontally adjacent dark cells in a row collapse into one
|
|
20
|
+
* `<rect>`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function paintBitMatrixCellsSvg(emitter: SvgEmitter, matrix: BitMatrix, pos: LabelPosition, moduleSize: number, moduleHeight?: number): void;
|
|
23
|
+
/**
|
|
24
|
+
* Render the barcode's human-readable line below (or above) the bars.
|
|
25
|
+
* Mirrors `paintHumanReadableText` on the canvas side.
|
|
26
|
+
*/
|
|
27
|
+
export declare function paintHumanReadableTextSvg(emitter: SvgEmitter, text: string, pos: LabelPosition, lineAbove: boolean, barWidth: number, width: number, height: number): void;
|
|
28
|
+
/**
|
|
29
|
+
* EAN-13's specialised human-readable rendering. Mirrors `paintEan13Text`
|
|
30
|
+
* on the canvas side, including the layout where the first digit sits to
|
|
31
|
+
* the LEFT of the bars and the remaining 12 are split into two groups of
|
|
32
|
+
* six centred under each half of the bars.
|
|
33
|
+
*/
|
|
34
|
+
export declare function paintEan13TextSvg(emitter: SvgEmitter, text: string, pos: LabelPosition, lineAbove: boolean, width: number, height: number, barWidth: number, guardExtension: number): void;
|
|
35
|
+
//# sourceMappingURL=barcode_paint_svg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barcode_paint_svg.d.ts","sourceRoot":"","sources":["../../src/svg-drawers/barcode_paint_svg.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAYpD,mFAAmF;AACnF,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,EAAE,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;CACpC;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE,WAAW,GAAG,SAAS,OAAO,EAAE,EACtC,GAAG,EAAE,aAAa,EAClB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GAChB,IAAI,CA6BN;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,UAAU,EACnB,MAAM,EAAE,SAAS,EACjB,GAAG,EAAE,aAAa,EAClB,UAAU,EAAE,MAAM,EAClB,YAAY,GAAE,MAAmB,GAChC,IAAI,CA+BN;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,aAAa,EAClB,SAAS,EAAE,OAAO,EAClB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,IAAI,CAWN;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,aAAa,EAClB,SAAS,EAAE,OAAO,EAClB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,MAAM,GACrB,IAAI,CAwDN"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// SVG analogues of the canvas helpers in `drawers/barcode_paint.ts`.
|
|
2
|
+
//
|
|
3
|
+
// Two notable differences from the canvas versions:
|
|
4
|
+
// 1. Adjacent dark cells in a row collapse into a single wider `<rect>`.
|
|
5
|
+
// A QR code with several thousand modules would otherwise emit one
|
|
6
|
+
// element per dark cell — runs are typically 10×–100× more compact.
|
|
7
|
+
// 2. Text uses the SVG `<text>` element with a tracked `FontKey` so the
|
|
8
|
+
// drawer can emit a matching `@font-face` rule once.
|
|
9
|
+
import { EmbeddedFontFamilies, FONT0_NAME, FONT1_NAME } from "../assets/index.js";
|
|
10
|
+
const BLACK = "#000000";
|
|
11
|
+
// Map canvas family-name aliases → FontKey for SvgEmitter font-tracking.
|
|
12
|
+
const FONT_KEY_FOR_FAMILY = new Map([
|
|
13
|
+
[EmbeddedFontFamilies.HelveticaBold, "HelveticaBold"],
|
|
14
|
+
[EmbeddedFontFamilies.DejavuSansMono, "DejavuSansMono"],
|
|
15
|
+
]);
|
|
16
|
+
/**
|
|
17
|
+
* Walk a 1D bit pattern and emit vertical bars `moduleWidth` wide and
|
|
18
|
+
* `barHeight` tall, starting at `pos`. Adjacent dark modules merge into a
|
|
19
|
+
* single wider `<rect>`.
|
|
20
|
+
*/
|
|
21
|
+
export function paintBitArrayBarsSvg(emitter, bits, pos, moduleWidth, barHeight) {
|
|
22
|
+
const seq = bits;
|
|
23
|
+
const len = seq.length;
|
|
24
|
+
let runStart = -1;
|
|
25
|
+
for (let i = 0; i < len; i++) {
|
|
26
|
+
const on = seq.at(i) === true;
|
|
27
|
+
if (on && runStart < 0) {
|
|
28
|
+
runStart = i;
|
|
29
|
+
}
|
|
30
|
+
else if (!on && runStart >= 0) {
|
|
31
|
+
emitter.rect(pos.x + runStart * moduleWidth, pos.y, (i - runStart) * moduleWidth, barHeight, BLACK);
|
|
32
|
+
runStart = -1;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (runStart >= 0) {
|
|
36
|
+
emitter.rect(pos.x + runStart * moduleWidth, pos.y, (len - runStart) * moduleWidth, barHeight, BLACK);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Walk a 2D bit matrix and emit cells. `moduleSize` is the cell width;
|
|
41
|
+
* `moduleHeight` defaults to a square cell (used by QR/Aztec/DataMatrix)
|
|
42
|
+
* but can be passed separately for PDF417 where rows are taller than they
|
|
43
|
+
* are wide. Horizontally adjacent dark cells in a row collapse into one
|
|
44
|
+
* `<rect>`.
|
|
45
|
+
*/
|
|
46
|
+
export function paintBitMatrixCellsSvg(emitter, matrix, pos, moduleSize, moduleHeight = moduleSize) {
|
|
47
|
+
const moduleW = moduleSize;
|
|
48
|
+
const moduleH = moduleHeight;
|
|
49
|
+
for (let r = 0; r < matrix.height; r++) {
|
|
50
|
+
let runStart = -1;
|
|
51
|
+
for (let c = 0; c < matrix.width; c++) {
|
|
52
|
+
const on = matrix.at(c, r);
|
|
53
|
+
if (on && runStart < 0) {
|
|
54
|
+
runStart = c;
|
|
55
|
+
}
|
|
56
|
+
else if (!on && runStart >= 0) {
|
|
57
|
+
emitter.rect(pos.x + runStart * moduleW, pos.y + r * moduleH, (c - runStart) * moduleW, moduleH, BLACK);
|
|
58
|
+
runStart = -1;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (runStart >= 0) {
|
|
62
|
+
emitter.rect(pos.x + runStart * moduleW, pos.y + r * moduleH, (matrix.width - runStart) * moduleW, moduleH, BLACK);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Render the barcode's human-readable line below (or above) the bars.
|
|
68
|
+
* Mirrors `paintHumanReadableText` on the canvas side.
|
|
69
|
+
*/
|
|
70
|
+
export function paintHumanReadableTextSvg(emitter, text, pos, lineAbove, barWidth, width, height) {
|
|
71
|
+
const fontSize = Math.max(barWidth, 1) * 10;
|
|
72
|
+
const x = pos.x + width / 2;
|
|
73
|
+
const y = lineAbove ? pos.y - fontSize / 2 : pos.y + height + fontSize;
|
|
74
|
+
emitter.text(x, y, text, {
|
|
75
|
+
fontFamily: FONT1_NAME,
|
|
76
|
+
fontKey: FONT_KEY_FOR_FAMILY.get(FONT1_NAME),
|
|
77
|
+
fontSize,
|
|
78
|
+
anchor: "middle",
|
|
79
|
+
fill: BLACK,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* EAN-13's specialised human-readable rendering. Mirrors `paintEan13Text`
|
|
84
|
+
* on the canvas side, including the layout where the first digit sits to
|
|
85
|
+
* the LEFT of the bars and the remaining 12 are split into two groups of
|
|
86
|
+
* six centred under each half of the bars.
|
|
87
|
+
*/
|
|
88
|
+
export function paintEan13TextSvg(emitter, text, pos, lineAbove, width, height, barWidth, guardExtension) {
|
|
89
|
+
const fontSize = Math.round(width / 13);
|
|
90
|
+
const family = FONT0_NAME;
|
|
91
|
+
const fontKey = FONT_KEY_FOR_FAMILY.get(FONT0_NAME);
|
|
92
|
+
if (text.length === 13 && !lineAbove) {
|
|
93
|
+
// Mirrors the canvas drawer's anchor placement: text top sits below the
|
|
94
|
+
// data-bar baseline; SVG `dominant-baseline: text-top` gives us the
|
|
95
|
+
// same anchor as canvas's `textBaseline = "top"`.
|
|
96
|
+
const y = pos.y + height + fontSize - guardExtension;
|
|
97
|
+
const first = text[0];
|
|
98
|
+
const left = text.slice(1, 7);
|
|
99
|
+
const right = text.slice(7, 13);
|
|
100
|
+
emitter.text(pos.x - barWidth * 2, y, first, {
|
|
101
|
+
fontFamily: family,
|
|
102
|
+
fontKey,
|
|
103
|
+
fontSize,
|
|
104
|
+
anchor: "middle",
|
|
105
|
+
baseline: "text-top",
|
|
106
|
+
fill: BLACK,
|
|
107
|
+
});
|
|
108
|
+
for (let k = 0; k < 6; k++) {
|
|
109
|
+
const cx = pos.x + (3 + k * 7 + 3.5) * barWidth;
|
|
110
|
+
emitter.text(cx, y, left[k], {
|
|
111
|
+
fontFamily: family,
|
|
112
|
+
fontKey,
|
|
113
|
+
fontSize,
|
|
114
|
+
anchor: "middle",
|
|
115
|
+
baseline: "text-top",
|
|
116
|
+
fill: BLACK,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
for (let k = 0; k < 6; k++) {
|
|
120
|
+
const cx = pos.x + (50 + k * 7 + 3.5) * barWidth;
|
|
121
|
+
emitter.text(cx, y, right[k], {
|
|
122
|
+
fontFamily: family,
|
|
123
|
+
fontKey,
|
|
124
|
+
fontSize,
|
|
125
|
+
anchor: "middle",
|
|
126
|
+
baseline: "text-top",
|
|
127
|
+
fill: BLACK,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
const x = pos.x + width / 2;
|
|
133
|
+
const y = pos.y - guardExtension / 2 - fontSize;
|
|
134
|
+
emitter.text(x, y, text, {
|
|
135
|
+
fontFamily: family,
|
|
136
|
+
fontKey,
|
|
137
|
+
fontSize,
|
|
138
|
+
anchor: "middle",
|
|
139
|
+
baseline: "text-top",
|
|
140
|
+
fill: BLACK,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=barcode_paint_svg.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barcode_pdf417.d.ts","sourceRoot":"","sources":["../../src/svg-drawers/barcode_pdf417.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAuBhE,wBAAgB,yBAAyB,IAAI,gBAAgB,CA+B5D"}
|