0

Hi guys I have an application running on a serverless node environment (vercel) and I need to generate an svg using custom (end user defined) fonts, I have the files hosted on an s3 bucket and when I parse the svg I am downloading all the fonts used to a local folder

I use sharp js to generate the images from svg but I am running into a problem because I don't know the names of the fonts, the only information I have is the file name which could be anything because it is uploaded by the user, sharp allows me to pass a path tp a fontconfig file to add custom fonts but since I don't know the names of the fonts I don't know how to go about adding the font to fontconfig, ideally I would like a way to add a font by adding a name that I choose (probably some variation of the file name) and a path to the actual file, this way I can reference it in my svg and get the correct font, I just don't know if that's even possible with fontconfig and if it is I font know how to do it

I would be ok parsing the font names from the files binary but I don't know how to do that either and it seems like the first approach if possible will be easier

  • Provided you have a valid path to the font file – [opentype.js](https://github.com/opentypejs/opentype.js) or [fontkit](https://github.com/foliojs/fontkit) could parse the font file's data table to to retrieve a font-family name record. Fontkit might be better suited as it has inbuilt woff2 support - opentype.js needs an additional [woff2ttf library](https://github.com/fontello/wawoff2). – herrstrietzel Jun 30 '23 at 02:31

0 Answers0