fontello / svg2ttf

SVG -> TTF font convertor
MIT License
521 stars 79 forks source link

Exception thrown when no font element present in svg #17

Closed nzbart closed 10 years ago

nzbart commented 10 years ago

I have an svg that renders correctly in Inkscape, but causes svg2ttf to throw the following exception:

var fontFaceElem = fontElem.getElementsByTagName('font-face')[0];
                              ^                                   
TypeError: Cannot call method 'getElementsByTagName' of undefined 

There is no font element in the svg, which is below:

<?xml version="1.0" encoding="utf-8"?>
<!-- Generated by IcoMoon.io -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="32" height="32" viewBox="0 0 32 32">
<g>
</g>
    <path d="M15.805 1.282c-8.13 0.109-14.632 6.787-14.523 14.917 0.109 8.125 6.787 14.629 14.917 14.52 8.126-0.109 14.63-6.787 14.52-14.917-0.107-8.126-6.786-14.629-14.914-14.52zM15.762 24.96h-0.082c-1.251-0.037-2.134-0.96-2.099-2.194 0.035-1.211 0.939-2.093 2.15-2.093l0.074 0.002c1.286 0.038 2.16 0.952 2.122 2.221-0.035 1.214-0.926 2.064-2.165 2.064zM21.027 14.509c-0.296 0.418-0.942 0.938-1.758 1.573l-0.899 0.621c-0.493 0.384-0.79 0.744-0.901 1.098-0.090 0.282-0.131 0.354-0.139 0.922l-0.002 0.146h-3.429l0.010-0.291c0.042-1.194 0.072-1.894 0.566-2.475 0.776-0.91 2.488-2.013 2.56-2.059 0.245-0.186 0.451-0.395 0.606-0.619 0.36-0.496 0.518-0.888 0.518-1.27 0-0.533-0.158-1.026-0.47-1.464-0.301-0.424-0.872-0.638-1.698-0.638-0.819 0-1.379 0.261-1.715 0.794-0.347 0.549-0.52 1.123-0.52 1.712v0.147h-3.536l0.006-0.154c0.091-2.166 0.864-3.725 2.298-4.635 0.899-0.581 2.019-0.874 3.325-0.874 1.71 0 3.157 0.416 4.293 1.235 1.152 0.83 1.736 2.075 1.736 3.698 0 0.909-0.286 1.762-0.851 2.536z" fill="#000000" />
</svg>

Is it valid to have the missing font element, and should svg2ttf cater for this scenario?

puzrin commented 10 years ago

That's not font, that's simple svg image. Of cause, it can't be converted.

svg2ttf requires valid svg font on input.

nzbart commented 10 years ago

I was mislead by the description of this project, which says

svg2ttf converts SVG graphics to TTF format.

Now that I have read your feedback and re-read the Readme, the only clue that would suggest to me that the "SVG graphics" must actually be an "SVG font" is the name of the svgFontString variable in the API.

puzrin commented 10 years ago

Yes, description is not enouth good.

tfburton commented 9 years ago

This got me too

puzrin commented 9 years ago

Thanks for reminder. I've updated description & improved error message. If you need generator from icons - try to search "dependens" of this project on npm https://www.npmjs.com/package/svg2ttf