feat(banners-lib): text to svg converting

This commit is contained in:
Guz013
2023-12-01 15:32:52 -03:00
parent 2a464eeee4
commit fc3243dfe7
5 changed files with 28 additions and 0 deletions

View File

@@ -16,5 +16,8 @@
"@types/node": "^20.10.0",
"eslint": "^8.54.0",
"linkedom": "^0.16.4"
},
"dependencies": {
"@fredli74/typr": "^0.3.8"
}
}

View File

@@ -3,6 +3,7 @@
*/
import getLocalLayout from './layouts.js';
import { isValidIcon } from './utils.js';
import fontSvg from './text-svg.js';
/**
* @param {Readonly<string>} string - The string to be converted.
@@ -198,6 +199,8 @@ async function banner(object) {
},
);
dom.appendChild(stringToHtml(`<g transform="translate(30, 40)"><path d="${fontSvg}" transform="scale(0.01, -0.01)" fill="#ff0000" /></g>`, doc));
return htmlToString(dom, doc);
}

View File

@@ -0,0 +1,14 @@
import * as typr from '@fredli74/typr';
const buffer = await fetch(
import.meta.resolve('/packages/banners/static/CalSans-SemiBold.ttf'),
);
const font = new typr.Font(await buffer.arrayBuffer());
const glyhps = font.stringToGlyphs('Hello world');
const path = font.glyphsToPath(glyhps);
const svg = font.pathToSVG(path);
export default svg;

Binary file not shown.

8
pnpm-lock.yaml generated
View File

@@ -41,6 +41,10 @@ importers:
version: 0.34.6
packages/banners:
dependencies:
'@fredli74/typr':
specifier: ^0.3.8
version: 0.3.8
devDependencies:
'@types/node':
specifier: ^20.10.0
@@ -597,6 +601,10 @@ packages:
engines: {node: '>=14'}
dev: true
/@fredli74/typr@0.3.8:
resolution: {integrity: sha512-0Wr3arrJUOoF5HyE8/nusPsdOQaUEd9t0dq8GTHBgSakuh543VqQklIpuRWF/nEnoxkIJzHpCYYesWTyEqgrFg==}
dev: false
/@humanwhocodes/config-array@0.11.13:
resolution: {integrity: sha512-JSBDMiDKSzQVngfRjOdFXgFfklaXI4K9nLF49Auh21lmBWRLIK3+xTErTWD4KU54pb6coM6ESE7Awz/FNU3zgQ==}
engines: {node: '>=10.10.0'}