question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@font-face not included in SVGs

See original GitHub issue

I’m currently attempting to render out some SVG graphs to JPEG. It works fine after inlining all styles, as there were some “insecure operation” warnings when trying to read from CSS, but one thing I just cannot get working is using web fonts in SVG.

I’ve tried both importing the fonts using @import from Google Fonts, and defining the font with @font-face.

I tried putting fontFamily: 'Roboto' in the style object of options, as well as inlining style={{fontFamily: 'Roboto'}} directly on a <text> SVG element, neither worked.

Probably worth mentioning I’m using React for this. I’m kinda running out of ideas. Any help?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
junkdeckcommented, Dec 14, 2018

Found a workaround for this, posting in case anyone else has the same issue.

const node = document.getElementById('chart-container')
node.querySelectorAll('text').forEach( tag => 
  (tag.style.fontFamily = "Roboto, Arial, Sans Serif")
)
0reactions
vivcat[bot]commented, Dec 8, 2021

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

Read more comments on GitHub >

github_iconTop Results From Across the Web

svg @font-face works in svg but not when included in a page
I tried to circumvent the problem by defining the font in a separate stylesheet, and include it like this: <?xml-stylesheet type="text/css" href ...
Read more >
Using Fonts in SVG - Vecta.io
There are 3 different ways to use fonts in SVG - SVG fonts (deprecated), web-safe fonts, and web fonts, each with pros and...
Read more >
SVG fonts - SVG: Scalable Vector Graphics - MDN Web Docs
Following <font-face-src> is a <missing-glyph> element. This defines what should be displayed if a certain glyph is not found in the font and...
Read more >
Using Custom Fonts With SVG in an Image Tag | CSS-Tricks
The idea is to have many SVGs that all share a single CSS or a single font file ... Each image is self-contained,...
Read more >
Embedded fonts in SVG files not loaded - Prince forum
This only happens when SVG image is included with the <img> tag. However, if the SVG code is embedded directly into HTML, the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found