1 |
|
2 | const { columns } = require('@sutton-signwriting/core/fsw');
|
3 | const { columnSvg } = require('./fsw-column-svg');
|
4 | const fs = require('fs');
|
5 | const path = require('path');
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | const columnsSvg = async (fswText, options) => {
|
26 | const cols = columns(fswText, options);
|
27 | let svgs = [];
|
28 | for (let i=0; i<cols.columns.length; i++){
|
29 | svgs.push(await columnSvg(cols.columns[i],{...cols.options,...{width:cols.widths[i]}}));
|
30 | }
|
31 | return svgs;
|
32 | }
|
33 |
|
34 | const parseArg = (val) => {
|
35 | try {
|
36 | return JSON.parse(val)
|
37 | } catch {
|
38 | return undefined
|
39 | }
|
40 | }
|
41 |
|
42 | const helpArgs = () => {
|
43 | console.log("FSW Columns SVG\n");
|
44 | console.log("Usage: node fsw/fsw-columns-svg.js FswText [OutputFile] [Arguments]\n");
|
45 | console.log("ColumnOptions");
|
46 | console.log(" https://www.sutton-signwriting.io/core/#columnoptions\n");
|
47 | console.log("StyleObject");
|
48 | console.log(" https://www.sutton-signwriting.io/core/#styleobject\n");
|
49 | console.log("Arguments for ColumnOptions");
|
50 | console.log("--height the height of the column");
|
51 | console.log("--width the width of the column");
|
52 | console.log("--offset the lane offset for left and right lanes");
|
53 | console.log("--pad amount of padding before and after signs as well as at top, left, and right of column");
|
54 | console.log("--margin amount of space at bottom of column that is not available");
|
55 | console.log("--dynamic enables variable width column");
|
56 | console.log("--background background color for column");
|
57 | console.log("--style an object of style options for signs");
|
58 | console.log("--puncuation an object of punctuation options");
|
59 | process.exit(1);
|
60 | }
|
61 |
|
62 | if (require.main === module) {
|
63 | const args = require('minimist')(process.argv.slice(2));
|
64 | const fswText = args._[0];
|
65 | let file = args._[1]
|
66 | if (!fswText || args.help) helpArgs();
|
67 |
|
68 | args.style = parseArg(args["style"])
|
69 | args.punctuation = parseArg(args["punctuation"])
|
70 | args.detail = parseArg(args["detail"])
|
71 |
|
72 | args.options = parseArg(args["options"])
|
73 | args.options = (typeof args.options == 'object')?args.options:{};
|
74 | Object.keys(args).map((key)=>{
|
75 | switch (key) {
|
76 | case '_':
|
77 | case 'options':
|
78 | break;
|
79 | default:
|
80 | args.options[key] = args[key]
|
81 | }
|
82 | })
|
83 | columnsSvg(fswText,args.options).then( svgs => {
|
84 | if (file) {
|
85 | let ext = path.extname(file);
|
86 | if (!ext) {
|
87 | ext = ".svg";
|
88 | file += ext;
|
89 | }
|
90 | svgs.map( (svg,i) => {
|
91 | const out = file.replace(ext,"-" + (1+i) + ext);
|
92 | fs.writeFileSync(out, svg);
|
93 | })
|
94 | } else {
|
95 | svgs.map( (svg,i) => {
|
96 | console.log("========== SVG Column " + (1+i) + " ==========")
|
97 | console.log(svg);
|
98 | })
|
99 | }
|
100 | })
|
101 |
|
102 | } else {
|
103 | module.exports = { columnsSvg }
|
104 | }
|