Convert SVG to PNG Error: Font not found

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
dominik.haag
Posts: 4
Joined: 2018-09-27T00:32:49-07:00
Authentication code: 1152

Convert SVG to PNG Error: Font not found

Post by dominik.haag »

We have an Issue with some SVG's which are delivered by our customer when converting them to png using ImageMagick:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Creator: CorelDRAW -->
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="86.2565mm" height="48.5981mm" style="shape-rendering:geometricPrecision; text-rendering:geometricPrecision; image-rendering:optimizeQuality; fill-rule:evenodd; clip-rule:evenodd"
viewBox="0 0 12.9052 7.27099"
 xmlns:xlink="http://www.w3.org/1999/xlink">
 <defs>
  <font id="FontID0" font-variant="normal" style="fill-rule:nonzero" font-weight="700">
	<font-face 
		font-family="Arial">
	</font-face>
   <missing-glyph><path d="M0 0z"/></missing-glyph>
   <glyph unicode="2" horiz-adv-x="556"><path d="M505.827 127.496l0 -127.496 -480.992 0c5.33858,48.1732 20.8346,93.8268 46.9921,137.008 26,43.1654 77.5118,100.331 154.173,171.654 62,57.5118 99.8268,96.6772 113.827,117.165 18.8346,28.3465 28.3465,56.3465 28.3465,84 0,30.5039 -8.17323,54 -24.6772,70.5039 -16.4882,16.5039 -39.1654,24.6772 -68.1575,24.6772 -28.6772,0 -51.3386,-8.67717 -68.3307,-25.8425 -16.8346,-17.3386 -26.6772,-46 -29.3386,-86l-136.661 13.6693c8.15748,75.4961 33.6535,129.669 76.6614,162.661 42.9921,32.8346 96.6614,49.3386 161.165,49.3386 70.6614,0 126.173,-19.1654 166.504,-57.1654 40.3307,-38.1732 60.4882,-85.4961 60.4882,-142.173 0,-32.1575 -5.82677,-62.8346 -17.3228,-92 -11.4961,-29.1654 -29.8425,-59.6693 -54.8346,-91.4961 -16.6614,-21.1654 -46.6614,-51.6693 -89.8425,-91.3386 -43.3228,-39.6535 -70.8189,-66.1575 -82.3307,-79.1654 -11.4961,-12.9921 -20.9921,-25.6693 -28.1575,-38l272.488 0z"/></glyph>
   <glyph unicode="1" horiz-adv-x="556"><path d="M393.496 0l-137.165 0 0 517.165c-50.1575,-46.9921 -109.165,-81.6693 -177.165,-104l0 124.504c35.6693,11.6693 74.6614,33.8268 116.661,66.5039 42,32.8346 70.8346,70.9921 86.3465,114.661l111.323 0 0 -718.835z"/></glyph>
  </font>
  <style type="text/css">
   <![CDATA[
    @font-face { font-family:"Arial";src:url("#FontID0") format(svg)}
    .str0 {stroke:#1F1A17;stroke-width:0.0114006}
    .str2 {stroke:#1F1A17;stroke-width:0.029923}
    .str1 {stroke:#1F1A17;stroke-width:0.0114006;stroke-dasharray:0.022801 0.011401 0.011401 0.022801}
    .fil0 {fill:none}
    .fil2 {fill:#1F1A17}
    .fil1 {fill:white}
    .fil3 {fill:#1F1A17;fill-rule:nonzero}
    .fnt0 {font-weight:bold;font-size:0.950054;font-family:'Arial'}
   ]]>
  </style>
 </defs>
 <g id="Beschriftung">
  <g id="_148566112">
   <g id="Test.cdr">
    <path id="_148578976" class="fil0 str0" d="M9.97157 0.655268c0,-0.00541605 -0.00435379,-0.00991946 -0.00976984,-0.0100392"/>
    <line id="_148578592" class="fil0 str0" x1="7.82358" y1="0.63872" x2="7.82627" y2= "0.638496" />
   </g>
   <g>
    <g>
     <circle id="_148564384" class="fil1 str2" cx="0.64549" cy="0.64549" r="0.630529"/>
     <text x="0.392918" y="1.01741" id="_148578304" class="fil2 fnt0">1</text>
    </g>
    <g>
     <circle id="_149684328" class="fil1 str2" cx="0.683134" cy="2.38514" r="0.630529"/>
     <text x="0.430561" y="2.75706" id="_149684424" class="fil2 fnt0">2</text>
    </g>
    <g>
     <path id="_150542728" class="fil3" d="M4.60402 2.45551l0.22734 -0.501883 0.342513 0.457597 -0.569853 0.044286zm-3.30635 -1.85805l3.48124 1.577 -0.0432985 0.0960826 -3.48124 -1.577 0.0432985 -0.0960826z"/>
    </g>
    <g>
     <path id="_149684232" class="fil3" d="M2.35784 2.81131l0.0773209 -0.545196 0.456909 0.342872 -0.534229 0.202324zm-1.03696 -0.478333l1.12582 0.159669 -0.0144229 0.104341 -1.12582 -0.159669 0.0144229 -0.104341z"/>
    </g>
   </g>
  </g>
 </g>
</svg>
ImageMagick throws the following error even if the Font Arial is properly installed :
** (magick.exe:3868): WARNING **: couldn't load font ""Arial" Bold Not-Rotated 0.94921875", falling back to "Sans Bold Not-Rotated 0.94921875", expect ugly output.
We found out that ImageMagick seems to have Problems with the fontname placed in quotes in the CDATA section:
If we remove the quotes arround the fontname the problem does not occur.

SVG without quotes:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Creator: CorelDRAW -->
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="86.2565mm" height="48.5981mm" style="shape-rendering:geometricPrecision; text-rendering:geometricPrecision; image-rendering:optimizeQuality; fill-rule:evenodd; clip-rule:evenodd"
viewBox="0 0 12.9052 7.27099"
 xmlns:xlink="http://www.w3.org/1999/xlink">
 <defs>
  <font id="FontID0" font-variant="normal" style="fill-rule:nonzero" font-weight="700">
	<font-face 
		font-family="Arial">
	</font-face>
   <missing-glyph><path d="M0 0z"/></missing-glyph>
   <glyph unicode="2" horiz-adv-x="556"><path d="M505.827 127.496l0 -127.496 -480.992 0c5.33858,48.1732 20.8346,93.8268 46.9921,137.008 26,43.1654 77.5118,100.331 154.173,171.654 62,57.5118 99.8268,96.6772 113.827,117.165 18.8346,28.3465 28.3465,56.3465 28.3465,84 0,30.5039 -8.17323,54 -24.6772,70.5039 -16.4882,16.5039 -39.1654,24.6772 -68.1575,24.6772 -28.6772,0 -51.3386,-8.67717 -68.3307,-25.8425 -16.8346,-17.3386 -26.6772,-46 -29.3386,-86l-136.661 13.6693c8.15748,75.4961 33.6535,129.669 76.6614,162.661 42.9921,32.8346 96.6614,49.3386 161.165,49.3386 70.6614,0 126.173,-19.1654 166.504,-57.1654 40.3307,-38.1732 60.4882,-85.4961 60.4882,-142.173 0,-32.1575 -5.82677,-62.8346 -17.3228,-92 -11.4961,-29.1654 -29.8425,-59.6693 -54.8346,-91.4961 -16.6614,-21.1654 -46.6614,-51.6693 -89.8425,-91.3386 -43.3228,-39.6535 -70.8189,-66.1575 -82.3307,-79.1654 -11.4961,-12.9921 -20.9921,-25.6693 -28.1575,-38l272.488 0z"/></glyph>
   <glyph unicode="1" horiz-adv-x="556"><path d="M393.496 0l-137.165 0 0 517.165c-50.1575,-46.9921 -109.165,-81.6693 -177.165,-104l0 124.504c35.6693,11.6693 74.6614,33.8268 116.661,66.5039 42,32.8346 70.8346,70.9921 86.3465,114.661l111.323 0 0 -718.835z"/></glyph>
  </font>
  <style type="text/css">
   <![CDATA[
    @font-face { font-family:Arial;src:url("#FontID0") format(svg)}
    .str0 {stroke:#1F1A17;stroke-width:0.0114006}
    .str2 {stroke:#1F1A17;stroke-width:0.029923}
    .str1 {stroke:#1F1A17;stroke-width:0.0114006;stroke-dasharray:0.022801 0.011401 0.011401 0.022801}
    .fil0 {fill:none}
    .fil2 {fill:#1F1A17}
    .fil1 {fill:white}
    .fil3 {fill:#1F1A17;fill-rule:nonzero}
    .fnt0 {font-weight:bold;font-size:0.950054;font-family:Arial}
   ]]>
  </style>
 </defs>
 <g id="Beschriftung">
  <g id="_148566112">
   <g id="Test.cdr">
    <path id="_148578976" class="fil0 str0" d="M9.97157 0.655268c0,-0.00541605 -0.00435379,-0.00991946 -0.00976984,-0.0100392"/>
    <line id="_148578592" class="fil0 str0" x1="7.82358" y1="0.63872" x2="7.82627" y2= "0.638496" />
   </g>
   <g>
    <g>
     <circle id="_148564384" class="fil1 str2" cx="0.64549" cy="0.64549" r="0.630529"/>
     <text x="0.392918" y="1.01741" id="_148578304" class="fil2 fnt0">1</text>
    </g>
    <g>
     <circle id="_149684328" class="fil1 str2" cx="0.683134" cy="2.38514" r="0.630529"/>
     <text x="0.430561" y="2.75706" id="_149684424" class="fil2 fnt0">2</text>
    </g>
    <g>
     <path id="_150542728" class="fil3" d="M4.60402 2.45551l0.22734 -0.501883 0.342513 0.457597 -0.569853 0.044286zm-3.30635 -1.85805l3.48124 1.577 -0.0432985 0.0960826 -3.48124 -1.577 0.0432985 -0.0960826z"/>
    </g>
    <g>
     <path id="_149684232" class="fil3" d="M2.35784 2.81131l0.0773209 -0.545196 0.456909 0.342872 -0.534229 0.202324zm-1.03696 -0.478333l1.12582 0.159669 -0.0144229 0.104341 -1.12582 -0.159669 0.0144229 -0.104341z"/>
    </g>
   </g>
  </g>
 </g>
</svg>
It seems that theese svg's where created with Coral Draw. It would be great if ImageMagick could handle such SVG's properly.

Tested with ImageMagick 7.0.8-12 Q16 x64 2018-09-23 as well as with ImageMagick-7.0.5-10-Q16
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert SVG to PNG Error: Font not found

Post by fmw42 »

I have tested your SVG file using IM 7.0.8-12 Q16 Mac OSX Sierra using both the internal MSVG SVG renderer and using Inkscape (0.92.3_4) called by Imagemagick. Neither give that error message. The MSVG rendered does not work properly and the main area is black. The Inkscape version seems to render correctly.

Code: Select all

magick -background none MSVG:corel.svg corel_msvg.png
Image

Code: Select all

magick -background none corel.svg corel_inkscape.png
Image

I also used RSVG (2.42.2_2) delegate, but IM 7.0.8.12 has a problem so I used IM 6.9.10.12. (I created a special RSVG entry in my delegates.xml file to be able to use RSVG as well as Inkscape)

Code: Select all

magick -background none RSVG:corel.svg corel_rsvg.png
magick: unable to open image 'RSVG:corel.svg': No such file or directory @ error/blob.c/OpenBlob/3489.

Code: Select all

convert -background none RSVG:corel.svg corel_rsvg.png
Image


Photoshop shows a rendering with transparent background similar to the RSVG and Inkscape results, which vary slightly.
dominik.haag
Posts: 4
Joined: 2018-09-27T00:32:49-07:00
Authentication code: 1152

Re: Convert SVG to PNG Error: Font not found

Post by dominik.haag »

Thanks for your investigation.

It seems that the problem does only occur unter Windows (Tested with Windows 10).
With debian stable (ImageMagick 6.9.7-4 Q16 x86_64 20170114) we could not reproduce the Problem.

I saw some changes in the rsvg-lib made in August which mentioned changes with quotes. The rsvg-Lib used in ImageMagick is from Dec 2017.

Unter Windows transforming the svg using inkscape works fine.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert SVG to PNG Error: Font not found

Post by fmw42 »

Have you tried updating the RSVG delegate if that is what you are using? Or have you tried using Inkscape?
dominik.haag
Posts: 4
Joined: 2018-09-27T00:32:49-07:00
Authentication code: 1152

Re: Convert SVG to PNG Error: Font not found

Post by dominik.haag »

For the test with inkscape I used the command line for Inkscape directly, not the way via ImageMagick.
The cmd for the Inkscape-Test was:
inkscape.exe Test-Orig.svg --export-png=Inkscapetest.png
dominik.haag
Posts: 4
Joined: 2018-09-27T00:32:49-07:00
Authentication code: 1152

Re: Convert SVG to PNG Error: Font not found

Post by dominik.haag »

Does somebody have an idea on how to solve that problem?
Post Reply