-
Notifications
You must be signed in to change notification settings - Fork 469
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
Issue with Unicode code points above 16bit max 65536 #314
Comments
By the way, rendering is also broken in OpenType.js for codepoints outside the Basic Multilingual Plane. This is one reason why OpenType.js fails quite many tests in the test suite; compare the test report for OpenType.js to that of fontkit. |
I'm only just learning about the details of open type cmap table format 4 as used in opentype.js, but I think this function found in cmap.js could be the source of the 16bit unicode code point limitation:
However, the spec is not super clear to me on this points (see https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6cmap.html or https://www.microsoft.com/typography/otspec/cmap.htm#customPlatform_OTF) Can anyone confirm the correct calculation for the offset? |
I think the format 4 is limited by the 16bit limitation and the only way to put 32bit code-points is to use another format. |
I'm not clear on the spec, but If that is the case, then I think for current implementation with CMAP format 4, it would be better for opentype.js to not try to encode unicode code points outside of 16bit range since it produces broken font file. Format 12 implementation would be very nice to have tho. |
Yeah we should definitely support format 12. However, I'm completely swamped at the moment... |
@Jolg42 thank you! that looks great. It looks like it will certainly solve my problem. If the pull request is merged I can test it immediately, otherwise let me know if you would like my to run a test on your branch and I'll go about reconfiguring m project to do that. |
@halmos If you could run a test on my branch it would be great 😉 (As there are no unit test on the cmap tables and that I didn't have time to run many tests.) |
@Jolg42 - I've tested your format 12 implementation with the Stix font. It passes OTS-sanitize and loads in the browser with no problem. From my POV the pull request looks great. Great work! and thank you. |
Fixed by #315 |
opentype.js Font creation still suffers from this issue. Glyphs with unicode Steps to reproduce: const font = new Font({
ascender: 1000,
descender: 0,
familyName: 'test',
styleName: 'test',
unitsPerEm: 1000,
glyphs: [
new Glyph({ name: '.notdef', advanceWidth: 0, unicode: -1 }),
new Glyph({ name: '?', advanceWidth: 1000, unicode: 0x10000 })
]
})
font.download('./test.otf') |
Just out of curiosity I tried cloning the repo and building myself... |
Thank you for the report, I'll look into it! |
After spending quite some time investigating this, I just found out that 0xFFFF (as well as U+10FFFF) as the highest possible 16-bit (or 32-bit) value is a non-character. So it shouldn't ever happen to be assigned to a glyph. By the way, loading a font with it assigned into the glyph inspector, it will actually display the code point, so fontforge showing -1 instead is probably a special treatment for those non-characters. As the codfe points above work as intended, I'll close this issue again. |
Expected Behavior
When testing download of Microsoft Stix font, the resulting file is not validated by OTS-Sanitize and produces errors in the browser. The resulting font should load normally.
Current Behavior
Both OTS-Sanitize and chrome report :
OTS parsing error: cmap: Out of order end range (54272 <= 65533)
.It seems that the CMAP table creation function may have a problem with code points above 16bits / 65536. I'm not certain, but glyphs with unicode values over 65536 seem to be bit shifted to drop their first bit. For example, in the error above code point 54272 is listed as glyph id 2297 in the opentype.js web font inspector. However the correct code point is 119808. If you remove the first bit of 119808 it becomes 54272. I haven't been able to parse the table creation functions completely enough to understand how they are working, but I suspect their may be an issue with bitshifting 32 bit numbers, possibly something to do with the sign.
Steps to Reproduce (for bugs)
Your Environment
The text was updated successfully, but these errors were encountered: