fontello / svg2ttf

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

some svg font cannot be converted to ttf( Exception ) #6

Closed mogadanez closed 11 years ago

mogadanez commented 11 years ago

https://dl.dropboxusercontent.com/u/760909/in.svg

First of all it does not have metadata, and fails at

function load(str) {
  var doc = (new DOMParser()).parseFromString(str, "application/xml");

  var metadata = doc.getElementsByTagName('metadata')[0];
  var fontElem = doc.getElementsByTagName('font')[0];
  var fontFaceElem = fontElem.getElementsByTagName('font-face')[0];

  var font = {
    metadata: metadata.firstChild.data

if fix it by adding check

metadata: metadata!= null ?metadata.firstChild.data: null,

not it fails on create ttf:in os2.js:

buffer.js:784
    throw TypeError('value is out of bounds');
          ^
TypeError: value is out of bounds
    at TypeError (<anonymous>)
    at checkInt (buffer.js:784:11)
    at Buffer.writeInt16BE (buffer.js:908:5)
    at Object.jDataView._nodeBufferAction (E:\temp\fonts\svg2ttf\node_modules\jDataView\src\jDataView.js:293:101)
    at Object.jDataView._action (E:\temp\fonts\svg2ttf\node_modules\jDataView\src\jDataView.js:270:15)
    at Object.proto.(anonymous function) [as setInt16] (E:\temp\fonts\svg2ttf\node_modules\jDataView\src\jDataView.js:677:9)
    at Object.proto.(anonymous function) [as writeInt16] (E:\temp\fonts\svg2ttf\node_modules\jDataView\src\jDataView.js:680:22)
    at Object.createOS2Table [as create] (E:\temp\fonts\svg2ttf\lib\ttf\tables\os2.js:36:7)
    at E:\temp\fonts\svg2ttf\lib\ttf.js:99:26
    at Function.forEach (E:\temp\fonts\svg2ttf\node_modules\lodash\dist\lodash.js:2590:15)

because in buf.writeInt16(font.avgWidth); // xAvgCharWidth avgWidth is NaN

mogadanez commented 11 years ago

it works only descent="..." or ascent="..." attributes provided in tag

puzrin commented 11 years ago

Could you give some additional info, how you got source svg file? Is it generated by some well-known software or you did it manually?

puzrin commented 11 years ago

I dont hesitate, thas convertor has bugs, but your source also miss mandatory xml headers and that looks strange.

mogadanez commented 11 years ago

i got this svg from tx.exe tool ( included in http://www.adobe.com/devnet/opentype/afdko/topic_overview.html ) Initially i have pdf file, than i do:

  1. mutool.exe extract in.pdf => this one extract all embeded fonts .
  2. tx.exe -svg -a some.cff => this one convert extracted cff to svg.
  3. Next, I try to use svg2ttf.js to convert this svg to ttf.
mogadanez commented 11 years ago

Actually i can try patch my svg file with required data.

Metadata of font that i have:

Weight              "Light"
FontBBox            {-80,-244,1534,1209}
FSType              0
sup.srcFontType     CFF (name-keyed)
sup.nGlyphs         79
## Private
BlueValues          {-12,0,552,565,741,753}
OtherBlues          {-179,-165}
puzrin commented 11 years ago

Ok. Thanks for info. I'll fix trivial bugs, don't worry.

One more question. Does your font have descent = -200 ? That seems to be the only case, when it can be skipped in src.

Also, please note, that due lack of time convertor features are limited. It does not supports kerning, ligatures and some things, that can be significant for text, but not significant for icons.

mogadanez commented 11 years ago

Probably we can contribute for some features, but we need some starting bump, due this area is new for us. this is source font extracted from Pdf. https://dl.dropboxusercontent.com/u/760909/in.cff Actually, since we work with external pdf's, we can have different range of fonts.

Also, as a font-guru, probably you have an advice how to convert font from pdf to web fonts( css + .eot +.ttf + .svg + .woff)

puzrin commented 11 years ago

I never worked with cff and never extracted fonts from pdf. My knowledge is limited to making iconic fonts only, for web.

also we used fontforge & ttx to control result.

puzrin commented 11 years ago

Fixed crashes. But i still strongly recommend to add descent/ascent attributes, because those have no default values, according to SVG font specs. Now i use 850/-150, but this can be wrong for your case.