custom font for svg text,tspan
See original GitHub issueI wrote following code to support cyrillic and chinese characters when using doc.text
const robotoRegularBase64 = await import('./roboto.ttf'); // with webpack url-loader
const robotoRegular = b64arraybuffer.decode(
robotoRegularBase64.split('data:font/ttf;base64,')[1]
); // turn base64 into arraybuffer
doc.registerFont('Roboto-Regular', robotoRegular); // pass roboto regular as arraybuffer
doc.font('Roboto-Regular'); // use the font
This works quite fine when using doc.text, but I would also like the svg elements to use that font, what is the recommended way of doing this? Maybe incuding css/style? <text>
and <tspan>
elements don’t seem to use the doc.font defined font family by default.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:7 (1 by maintainers)
Top Results From Across the Web
font-family - SVG: Scalable Vector Graphics - MDN Web Docs
The font-family attribute indicates which font family will be used to render the text, specified as a prioritized list of font family names...
Read more >How to specify font-family in SVG - Stack Overflow
1. Generate the embedded font url as base64 ... Download the font file you want to use under .ttf extension. We will need...
Read more >How do I use a custom font in an SVG image on my site?
Show activity on this post. I created a custom Facebook icon using Inkscape and saved it as an svg. It uses the same...
Read more >Using Fonts in SVG - Vecta.io
The usage is done by embedding glyph information into SVG when rendered. SVG fonts are defined using <font> element. <font id="Font1" horiz ...
Read more >SVG `text` and Small, Scalable, Accessible Typographic ...
but it even works for SVG-as-<img> (or background-image , presumably) as well, as long as the font-family references the custom font by the ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If you want to use the same font for the whole svg it’s quite simple:
SVGtoPDF(doc, svg, x, y, { fontCallback: () => 'Roboto-Regular' });
To support several fonts
To convert
your.svg
first put all the fonts you’re going to need in a path like./fonts