fontello / svg2ttf

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

add an option to opt out of USE_TYPO_METRICS #120

Open kseino opened 2 years ago

kseino commented 2 years ago

Added useTypoMetrics options to set REGULAR to fsSelection. https://docs.microsoft.com/en-us/typography/opentype/spec/os2#fsselection

Use cases We use custom icon fonts generated thanks to svg2ttf in Flutter project. Flutter renders extra ascent when Use Typo Metrics is enabled. useTypoMetrics options will solve this problem.

https://github.com/fontello/svg2ttf/issues/95#issuecomment-631370838

kseino commented 2 years ago

@puzrin Could you review please :pray:

puzrin commented 2 years ago

Could you use fork for a while? I'm still busy with extremely urgent fixes on my project, which made all this stuff possible.

Sorry for unexpected delays.

kseino commented 2 years ago

related https://github.com/flutter/flutter/issues/98909

kseino commented 2 years ago

@puzrin Could you please review this PR?

We are looking forward to this option!

velkrissz commented 1 year ago

I encountered the same problem when generating an icon font for a Flutter app.

I avoided the issue without changing the Use Typo Metrics flag. (Tested on Android and iOS) Based on some experimenting, the problem disappears if the OS/2 sTypoLineGap is set to 0. Based on my understanding, this won't cause any problem as we use this for icons, not real fonts, I monkey-patched the Font "class" using the following snippet based on the actual implementation and it seems to be working just fine.

import * as sfnt from "svg2ttf/lib/sfnt.js";
// ...
Object.defineProperty(sfnt.Font.prototype, "int_lineGap", { value: 0 });

This bypasses the built-in 9% of font ascent minus descent calculation. I suggest adding a lineGap parameter to the options object. (SVG font face does not define a similar param.)