opentype.js icon indicating copy to clipboard operation
opentype.js copied to clipboard

Character path missing commands at smaller sizes

Open gingerchris opened this issue 6 months ago • 3 comments
trafficstars

Using the latest master branch, I'm seeing an issue where a path command is being dropped when rendering a certain character. If I increase the font size, the issue is not present, which makes me suspect there's some kind of rounding going on that causes this issue.

I've created a reproduction here comparing the current NPM release of opentype.js with a current build from the main branch.

Rendering this S character from Bodoni font at size 72 - all is good.

Image

At size 53 it seems to be missing the final command and is drawing a diagonal line to close the path instead of a vertical one

Image

gingerchris avatar May 20 '25 15:05 gingerchris

Also noticed that trying a much smaller size (in this case 3) it's completely wrong

Image

gingerchris avatar May 20 '25 15:05 gingerchris

Can you please check the console to see if there appear any errors?

Connum avatar May 21 '25 07:05 Connum

I see errors related to the platform (stackblitz) but after it's loaded I can clear the console, reload the preview and no errors come up. I have also validated this behaviour in nodejs and produced the same result

gingerchris avatar May 21 '25 08:05 gingerchris

Cadillac1010 avatar Sep 23 '25 06:09 Cadillac1010

Opentype v2.0 post-optimization seems to have flaws.

Explicit optimization options should fix the problem

  const d = path.toPathData({
    optimize: false,
    decimalPlaces: 3,
    flipY: false,
  });

My assumption: the optimization checks for coinciding control point coordinates after rounding – for smaller font-sizes this will result in more commands being dropped.

Ideally the flipY default should be changed to false or the y-axis flipping shouldn't happen before (in the command parsing)

However, the above options won't be compatible with V1.3 API. I you can do without variable font support you should probably stick with v1.3.4

herrstrietzel avatar Nov 11 '25 01:11 herrstrietzel