loveencounterflow / svgttf

NodeJS library to convert Illustrator or Inkscape SVG drawings to SVG and TTF fonts
MIT License
30 stars 4 forks source link

Converting svgttf-sample-font does not work #1

Open h6ah4i opened 9 years ago

h6ah4i commented 9 years ago

Hi. I am trying to use the svgttf command but getting the following error.

Instructions

# on host machine
docker run -i -t ubuntu /bin/bash

# on docker virtual machine
cd home/
sudo apt-get install git make curl
git clone https://github.com/visionmedia/n
cd n
make install
n stable
curl -L http://npmjs.org/install.sh | sh
npm install svgttf
cd node_modules/
node svgttf/lib/main.js -f svgttf/art svgttf-sample-font svg /tmp ttf

Results

# node svgttf/lib/main.js -f svgttf/art svgttf-sample-font svg /tmp ttf
svg2ttf/svg-to-svg-font  ▶  font-name:           'svgttf-sample-font'
svg2ttf/svg-to-svg-font  ▶  input-directory:     'svgttf/art'
svg2ttf/svg-to-svg-font  ▶  input-extension:     'svg'
svg2ttf/svg-to-svg-font  ▶  input-format:        'svg'
svg2ttf/svg-to-svg-font  ▶  input-glob:          '/home/n/node_modules/svgttf/art/svgttf-sample-font-+([0-9a-f]).svg'
svg2ttf/svg-to-svg-font  ▶  input-routes:        [ '/home/n/node_modules/svgttf/art/svgttf-sample-font-e000.svg' ]
svg2ttf/svg-to-svg-font  ▶  output-directory:    '/tmp'
svg2ttf/svg-to-svg-font  ▶  output-extension:    'ttf'
svg2ttf/svg-to-svg-font  ▶  output-format:       'ttf'
svg2ttf/svg-to-svg-font  ▶  output-route:        '/tmp/svgttf-sample-font.ttf'
svg2ttf/svg-to-svg-font  ▶  overwrite:           true
svg2ttf/svg-to-svg-font  ▶  reading files for font 'svgttf-sample-font'
svg2ttf/svg-to-svg-font  ▶  svgttf-sample-font-e000.svg: found 52 outlines
svg2ttf/svg-to-svg-font  ▶  svgttf-sample-font-e000.svg: assigned fallback
svg2ttf/svg-to-svg-font  ☛  svgttf-sample-font-e000.svg: added 51 glyph outlines to [ 0xe01a .. 0xe068 ]
svg2ttf/svg-to-svg-font  ▶  filled 28 positions with fallback outline from svgttf-sample-font-e000.svg
svg2ttf/svg-to-svg-font  ☛  added 51 glyph outlines to [ 0xe01a .. 0xe068 ]
/home/n/node_modules/svgttf/node_modules/svgpath/lib/parse.js:45
  this.max    = path.length;
                    ^
TypeError: Cannot read property 'length' of undefined
    at new State (/home/n/node_modules/svgttf/node_modules/svgpath/lib/parse.js:45:21)
    at pathParse (/home/n/node_modules/svgttf/node_modules/svgpath/lib/parse.js:220:15)
    at new SvgPath (/home/n/node_modules/svgttf/node_modules/svgpath/lib/svgpath.js:30:16)
    at /home/n/node_modules/svgttf/node_modules/svg2ttf/index.js:104:19
    at Function.forEach (/home/n/node_modules/svgttf/node_modules/lodash/dist/lodash.js:3017:15)
    at svg2ttf (/home/n/node_modules/svgttf/node_modules/svg2ttf/index.js:101:5)
    at Object._write_ttf (/home/n/node_modules/svgttf/lib/main.js:226:52)
    at Object.main (/home/n/node_modules/svgttf/lib/main.js:218:17)
    at /home/n/node_modules/svgttf/lib/main.js:550:24
    at Object.<anonymous> (/home/n/node_modules/svgttf/lib/main.js:553:13)
alexanderbird commented 6 years ago

I don't have time at the moment to make a PR, but as a monkey patch you can insert the following on line 220 of node_modules/svgpath/lib/parse.js (the first line of the pathParse function):

if(!svgPath) { return { segments: [] } }

So you get:

module.exports = function pathParse(svgPath) {
  if(!svgPath) { return { segments: [] } } 
  var state = new State(svgPath);
  var max = state.max;
  ....

I've been able to use it without trouble after making that change to the installed package.