opentype.js
opentype.js copied to clipboard
IsFixedPitch data from post table lost on export
When I try to export my monospaced fonts using opentype.js they export with the post table value 'isFixedPitch' of 0 even though the value of the font object is 1 (1 meaning that it is a monospaced font, 0 meaning proportional).
Expected Behavior
the 'isFixedPitch' value should follow the value of the font object's value
Steps to Reproduce (for bugs)
Load a monospaced font in OpenType.js and console.log the font object as well and the font.toTables(). Notice that the 'isFixedPitch' value in the post table is different in the font object and the tables.
Your Environment
- Version used: 1.3.1
- Font used: DM Mono but could be any monospaced font
- Browser Name and version: Chrome Version 115.0.5790.170 (Official Build) (x86_64)
- Operating System and version (desktop or mobile): Desktop
- Link to your project:
Any update here?
Nope, sorry. Nobody seems to have time to look into this currently. If someone finds where this needs to be set during export, a PR would be welcome.
The title of this issue should be changed, because it is not just about the post table font metadata. Commit Mono's use case is about isFixedPitch flag in CFF table as well. My comment in that issue goes into it.
Currently, Commit Mono sets the flag correctly here
through here
https://github.com/opentypejs/opentype.js/blob/aa8ad76467a27f086a19a7d3e12479a3d4fd93aa/src/tables/sfnt.mjs#L347
but in here
https://github.com/opentypejs/opentype.js/blob/aa8ad76467a27f086a19a7d3e12479a3d4fd93aa/src/tables/cff.mjs#L1603
there is a bug in opentypejs after that line where topDictOptions.isFixedPitch is ignored and not added to the attrs variable.
Also, Commit Mono has a weird bug here where it sets numberOfHMetrics to 3. That line can be erased, since the value ought to be calculated, not set. I think the code for setting fsSelection is wrong too when it comes to the regular style. (bit 6 must be set)
This is just from reading the code, and I have not touched nor built any code. I beg your pardon that this is as far as I am inclined.
edit: I don't think numberOfHMetrics matters. I saw a font show up in 'Fixed Width' without having the value of 1.
There is a claim here that the original bug regarding the flag in the post table is already fixed in the master branch of opentypejs. So please consider this issue to be regarding the bug mentioned in my previous post.