svg-net / SVG

Fork of the ms svg library
http://svg-net.github.io/SVG/
Microsoft Public License
1.16k stars 473 forks source link

Fonts are ignored by SVG to PNG converter #967

Open MarvinKlein1508 opened 2 years ago

MarvinKlein1508 commented 2 years ago

Description

Fonts wont be translated into the PNG file. The PNG File will contain an empty image.

Example data

1

using (var stream = new MemoryStream(filenameSvg))
{
    var svgDocument = SvgDocument.Open<SvgDocument>(stream);
    var bitmap = svgDocument.Draw();
    bitmap.Save(filenamePng, System.Drawing.Imaging.ImageFormat.Png);
}

Used Versions

SVG 3.4.1 .NET 6.0.3 Windows 10 21H1

mrbean-bremen commented 2 years ago

This seems to be a combination of problems. Embedded fonts using URL are not supported, so the font won't be used, but that just means that a default font will be used instead. Additionally, there seems to be some miscalcualtion of the text position, related both to the usage of nested svgs, and the relative x position of the tspan element (50%).

MarvinKlein1508 commented 2 years ago

@mrbean-bremen

As a workaround we convert the SVG via Imagick in PHP. And download the result instead. This also works with embedded fonts. Perhaps this helps you to implement the function into this library as well.

$im = new Imagick();
$im->readImageBlob($svg);
$im->setImageFormat("png24");
mrbean-bremen commented 2 years ago

Thanks! I'm not really the person to implement this, but hopefully it will help someone who is more experience with fonts to have a look.