forked from launchaco/logo_builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfont-generator.js
More file actions
26 lines (22 loc) · 834 Bytes
/
Copy pathfont-generator.js
File metadata and controls
26 lines (22 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const TextToSVG = require('text-to-svg');
const fs = require("fs");
const options = { x: 0, y: 0, fontSize: 14, anchor: 'left baseline' };
const generateFont = (text, fontName) => {
let path = '';
if (fontName.indexOf('.ttf') >= 0) {
path = `./fonts/${fontName}`;
} else if (fontName.indexOf('.otf') >= 0) {
path = `./fonts/${fontName}`;
} else {
if (fs.existsSync(`./fonts/${fontName}.ttf`)) {
path = `./fonts/${fontName}.ttf`;
} else if (fs.existsSync(`./fonts/${fontName}.otf`)) {
path = `./fonts/${fontName}.otf`;
}
}
const textToSVG = TextToSVG.loadSync(path);
return `<svg class="font-svg-class" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 300 300"><g>${textToSVG.getPath(text)}</g></svg>`;
};
module.exports = {
generateFont,
};