Setting font-family on SVG text element has no effect
See original GitHub issueI’m unable to change the font of the text in the SVG. I tried to run FC_DEBUG and it looks like no matter what is selects Liberation Serif.
I have fontconfig version 2.12.6 installed on my system.
This is the SVG I’m using
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 108 16" version="1.1"><text font-family="sans-serif" font-size="12px" x="54" y="12" fill="#000000" text-anchor="middle" >Fancy Text</text></svg>
'use strict';
const sharp = require('sharp');
const fs = require('fs');
let buffer = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 108 16" version="1.1"><text font-family="sans-serif" font-size="12px" x="54" y="12" fill="#000000" text-anchor="middle" >Fancy Text</text></svg>';
sharp(Buffer.from(buffer))
.toBuffer().then(buffer => {
fs.writeFile('Sans-serif.png', buffer, (err) => { });
});
If I view the same SVG in the browser it looks correct.
– Esben N.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Font-family for svg text is not working? - Stack Overflow
2) I am trying to render on svg text with dynamic font .For first time when I am applying the font Its not...
Read more >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 >Text — SVG 2
The larger glyphs have a font-size of 96px so their extra height is 24px (25% of 96px). The extra height is evenly divided...
Read more >How To Use SVG Font Properties - Vanseo Design
We'll look at these properties as attributes on SVG text elements here. ... to note when using it with SVG is the line-height...
Read more >Chapter 4. Multiline SVG Text - O'Reilly
In both cases, the adjustments on the <tspan> elements do not change. The effect of a dy attribute is always calculated from 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
Perfect, thank you, it looks like you’ve run into https://gitlab.gnome.org/GNOME/librsvg/issues/319 that was fixed in librsvg v2.44.0. You can workaround this for now by wrapping the font-family names in quotes.
sharp v0.22.0 now available, providing libvips v8.7.4 and librsvg v2.45.5.