3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ReceiptLineをCLIでSVG変換

Last updated at Posted at 2020-07-19

レシート記述言語ReceiptLinenpmで提供されている。
マクドナルドのレシートを再現した際に、「ビジュアルエディタでなくコマンドラインから簡単に実行したいな」と思ったのでコマンドrltosvgを書いた。(GitHubはこちら)

実装

rltosvg
#!/usr/bin/node

// $ npm -g install receiptline
// $ ./rltosvg <cpl int> <encoding> <import filepath> <export filepath>
const usage = './rltosvg <cpl int> <encoding> <import filepath> <export filepath>';

// print args
// console.log(process.argv);
const args = process.argv;
if (args.length !== 6) throw `Err: ${usage}`;

// read lib
const receiptline = require('receiptline');
const fs = require('fs');

// configrate
const option = {
    cpl: parseInt(args[2]),
    encoding: args[3],
    upsideDown: false,
    gamma: 1.8,
    command: 'svg'
};

// import
const input = fs.readFileSync(args[4], 'utf8').toString();

// compile
const data = receiptline.transform(input, option);

// export
fs.writeFile(args[5], data, {flag: 'w'}, (err) => {
  if (err) throw err + "\nErr: export";
  console.log('Success.');
});

実行例

ハマりどころは、エンコードを日本語を含んだときはcp932、英語のみならcp437にするところ

./rltosvg 48 cp932 code.rl out.svg

問題点

この方式だと、現時点でbase64画像が表示できない
解決方法募集中です

v1.0.2で修正済み

3
3
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?