1 |
|
2 | const { db } = require('../db/db');
|
3 | const { swu, convert } = require('@sutton-signwriting/core');
|
4 |
|
5 | const blank = null;
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | const symbolNormalize = async (swuSym) => {
|
23 | const blank = '';
|
24 | const parsed = swu.parse.symbol(swuSym);
|
25 | if (!parsed.symbol) return blank;
|
26 |
|
27 | const res = await db.query('select width,height from symbol where id=?', [convert.swu2id(parsed.symbol)]);
|
28 | const sym = res[0]
|
29 | if (!sym) return blank;
|
30 |
|
31 | return `${parsed.symbol}${convert.coord2swu([500 - parseInt( (sym.width+1) / 2), 500 - parseInt( (sym.height+1) / 2)])}${parsed.style || ''}`;
|
32 | }
|
33 |
|
34 | if (require.main === module) {
|
35 | symbolNormalize(process.argv[2]).then( res => {
|
36 | console.log(res);
|
37 | })
|
38 | } else {
|
39 | module.exports = { symbolNormalize }
|
40 | }
|