'use strict'; const { ArgumentParser } = require('argparse'); const { version, description } = require('./package.json'); const hershey = require('hersheytext'); const { writeFile } = require('fs-extra'); const { basename } = require('path'); const footer = ''; const W = 107; const H = 99; const charW = 3.25; //mm const charH = 4.0; //mm const header = ``; let options = { font : 'ems_nixish', scale : 0.005, weight : 1 }; async function loadFont (fontPath) { let str; let fileName; let fontName; try { hershey.addSVGFont(fontPath); } catch (err) { console.error(err); process.exit(1); } fileName = basename(fontPath); fontName = fileName.split('.').slice(0, -1).join('.'); options = { font : fontName }; } function textPos (str) { const UNIT = 21000 / W; const len = str.length; const w = len * charW; const h = charH; const x = ((W - w) / 2.0) * UNIT; const y = 1 * UNIT; return { x, y }; } async function main () { const fontPath = args.font; const num = (args.number + '').replace('\\n', '\n'); const size = args.size || '8.5x11'; const output = args.output || `number_${num}.svg`; let data; //console.log(num) try { //await loadFont(fontPath); } catch (err) { console.error(err); } //options.pos = { x: 50, y: 50 }; options.pos = textPos(num); data = hershey.renderTextSVG(num, options); try { await writeFile(output, `${header}\n${data}\n${footer}`); } catch (err) { console.error(err); } } const parser = new ArgumentParser({ description }); parser.add_argument('-v', '--version', { action: 'version', version }); parser.add_argument('-f', '--font', { help: 'Path to font' }); parser.add_argument('-n', '--number', { help: 'Number to write' }); parser.add_argument('-o', '--output', { help: 'Output svg' }); const args = parser.parse_args(); main();