raphlinus / font-rs

Apache License 2.0
756 stars 49 forks source link

Fix rounding bug in lookup_glyph_id and fix a corner case. #33

Closed golddranks closed 6 years ago

golddranks commented 6 years ago

An attempt to fix the bug described here: https://github.com/raphlinus/font-rs/issues/32

Additionally, found a corner case where it underflows when the code point searched for is smaller than any of the code points supported by the font.

rtsuk commented 6 years ago

Hmmm, https://docs.microsoft.com/en-us/typography/opentype/spec/cmap#format-4-segment-mapping-to-delta-values doesn't say anything about rounding up, and integer division usually truncates.

What font and code point are you testing with?

golddranks commented 6 years ago

Oops, now there is a case where 1 divided by 2 doesn't go to 0 so the loop never terminaties. Fixing that.

I'm using https://fonts.google.com/specimen/Kosugi+Maru and the code point it fails with is 赤, U+8d64.

golddranks commented 6 years ago

https://github.com/raphlinus/font-rs/pull/34 fixes this with more robust and easily-understandable logic so I'm closing this.