SVG icon indicating copy to clipboard operation
SVG copied to clipboard

Fonts are ignored by SVG to PNG converter

Open MarvinKlein1508 opened this issue 3 years ago • 3 comments

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

MarvinKlein1508 avatar Apr 04 '22 14:04 MarvinKlein1508

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%).

mrbean-bremen avatar Apr 10 '22 17:04 mrbean-bremen

@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");

MarvinKlein1508 avatar Apr 11 '22 09:04 MarvinKlein1508

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.

mrbean-bremen avatar Apr 11 '22 18:04 mrbean-bremen