Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exporting fonts must set UPM=1000, even if their UPM is higher than that. #115

Closed
mattlag opened this issue May 13, 2015 · 9 comments
Closed

Comments

@mattlag
Copy link
Contributor

mattlag commented May 13, 2015

Ran into a bunch of issues when trying to export a font where it looked like the letter spacing and line height / bounding box were all messed up:

image

Finally figured it out that the setting options.unitsPerEm = 1000 regardless of the font's UPM solved the issue:

image

This is Merriweather Sans with a UPM of 2048, but exported at 1000.

Also, the blinking cursor seems to be the right height, but the selection area seems to be too small:

image

I'm on Windows, I tried this out in PowerPoint, Word, and Adobe Illustrator.

@mattlag mattlag changed the title Exporting fonts have to have UPM=1000, even if their UPM is higher than that. Exporting fonts must set UPM=1000, even if their UPM is higher than that. May 13, 2015
@fdb
Copy link
Contributor

fdb commented May 14, 2015

Thanks for the detailed report Matt; I'll look into it next week.

@rkusa
Copy link

rkusa commented May 20, 2015

I seem to have the same issue. I am playing with replacing my own font implementation in pdfjs with opentype.js. Chrome, Firefox (pdf.js) and Mac Preview are displaying the font correctly, however, Adobe Reader messes it up:

screen shot 2015-05-20 at 10 08 24

Please let me know if I can do anything helping to track down this issue.

@fdb
Copy link
Contributor

fdb commented May 20, 2015

@rkusa That's weird -- can you send me the font + code you used to generate this?

@mattlag
Copy link
Contributor Author

mattlag commented May 20, 2015

I thought I'd add this as well -

Here is my font export code:
https://github.com/mattlag/Glyphr-Studio/blob/master/dev/js/io_otf_export.js

Which relies heavily on the Glyph object:
https://github.com/mattlag/Glyphr-Studio/blob/master/dev/js/obj_glyph.js

I first encountered this, and documented a lot of details in this bug:
glyphr-studio/Glyphr-Studio-1#176

In the process I used TTX to investigate the exported OTF, but couldn't see anything that would cause problems (but, I'm rather novice at the full implications of OTF table values). All the postscript code for the glyphs was exported correctly. @davelab6 did a TTX diff of Merriweather Sans original vs. Merriweather Sans exported through Glyphr Studio:
https://github.com/davelab6/example-bellweather/pull/1/files?diff=split

So, hopefully this helps.

@fdb
Copy link
Contributor

fdb commented May 20, 2015

@mattlag thanks so much! I'll investigate and let you know.

@fdb fdb closed this as completed in a73de65 Jun 3, 2015
@fdb
Copy link
Contributor

fdb commented Jun 3, 2015

I've tracked the bug to the CFF fontMatrix, which defines an affine transform for the glyph outlines. The fontMatrix defaults to [0.001 0 0 0.001 0 0]which works fine with fonts with a UPM of 1000. Other fonts need to set the matrix to a different scale value, e.g. fonts with a UPM of 2048 use 1/2048 = 0.000488281.

OpenType.js didn't set the fontMatrix anywhere, and so all fonts used the default font matrix, which is only suitable for fonts with a UPM of 1000.

I now create a fontMatrix based on the unitsPerEm.

Thanks @mattlag and @davelab6 for helping me find the bug. Especially the TTX export helped in tracking down the bug.

Also, please let me know if anything else is off.

@mattlag
Copy link
Contributor Author

mattlag commented Jun 3, 2015

Awesome - thanks! I'll update to 0.4.7 and let you know if anything goes wrong.

@fdb
Copy link
Contributor

fdb commented Jun 3, 2015

@mattlag please use version 0.4.8, which I just pushed (and includes the fix).

@mattlag
Copy link
Contributor Author

mattlag commented Jun 3, 2015

Great - will do. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants