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.

Setting font-family on SVG text element has no effect

See original GitHub issue

I’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:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
lovellcommented, Jan 17, 2019

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.

<text font-family="'sans'" ...
0reactions
lovellcommented, Mar 19, 2019

sharp v0.22.0 now available, providing libvips v8.7.4 and librsvg v2.45.5.

Read more comments on GitHub >

github_iconTop 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 >

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