adobe-type-tools / opentype-svg

Tools and sample files for making OpenType-SVG fonts
MIT License
212 stars 17 forks source link

fonts2svg viewBox is calculated incorrectly #22

Closed davidgodzsak closed 3 years ago

davidgodzsak commented 3 years ago

I think to calculate the viewbox correctly we could use the minX, minY, maxX and maxY parameters from TTF header table instead of unitsPerEm. I have some fonts I transform with this tool that get clip out from the viewbox.

How could I submit a PR to fix this?

miguelsousa commented 3 years ago

Please share the examples that suggest that the current logic is incorrect.

davidgodzsak commented 3 years ago

Here are a few examples using KoHo-Regular from google fonts:

J:

Screenshot 2021-05-22 at 21 34 47
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -1000 1000 1000">
    <path fill="#000000" d="M30 -74L73 -119Q104 -81 139.5 -64Q175 -47 225 -47Q299 -47 339 -84.5Q379 -122 379 -192V-700H451V-190Q451 -93 393 -41Q335 11 227 11Q162 11 116.5 -8.5Q71 -28 30 -74Z"/>
</svg>

,:

Screenshot 2021-05-22 at 21 34 10
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -1000 1000 1000">
    <path fill="#000000" d="M154 -27Q154 19 136 54.5Q118 90 81 122L59 100Q84 77 96.5 54Q109 31 110 5Q102 11 87 11Q70 11 60 -0.5Q50 -12 50 -32Q50 -53 65.5 -71Q81 -89 103 -89Q127 -89 140.5 -73Q154 -57 154 -27Z"/>
</svg>

}:

Screenshot 2021-05-22 at 21 33 47
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -1000 1000 1000">
    <path fill="#000000" d="M30 -74L73 -119Q104 -81 139.5 -64Q175 -47 225 -47Q299 -47 339 -84.5Q379 -122 379 -192V-700H451V-190Q451 -93 393 -41Q335 11 227 11Q162 11 116.5 -8.5Q71 -28 30 -74Z"/>
</svg>
miguelsousa commented 3 years ago

The SVGs are being generated as expected. The parts of the glyphs that are not visible are below the font's baseline. For your purposes, adjusting the viewBox may be something desired but it's a kind of change that should NOT be done by default. If you want to submit a patch, put it behind an option.

davidgodzsak commented 3 years ago

Hmm makes sense, but wouldn't it be desirable to also render the descender and a line gap under the font, when creating the SVG?

miguelsousa commented 3 years ago

wouldn't it be desirable to also render the descender and a line gap under the font, when creating the SVG?

In the context of making OT-SVG fonts it's not desirable because the viewBox plays a role in how the SVG artwork is scaled and positioned within the line of text. If you start changing the viewBox to, for example, vertically center the paths within the window, all of the SVGs will also be vertically centered which is definitely not desired.

davidgodzsak commented 3 years ago

I created a PR for this https://github.com/adobe-type-tools/opentype-svg/pull/23, behind a flag.

miguelsousa commented 3 years ago

Fixed by #23