Closed golddranks closed 5 years ago
I think I see how to fix this properly. The logic is subtle. In any case, a good methodology for trying to fix this is to see whether you can replicate a test case with the existing font, then do cargo test
before uploading a PR.
I'm getting a bug where the
lookup_glyph_id
function can't find a glyph even if it exists. Here's a "trace" of the binary search it performs:The actual range that includes the glyph is in index
3451
, so it's off by one. It's still in the range when the size is33
:3483-33 = 3450
, but drops from the range the next step:3467-16 = 3451
(this is non-inclusive, as the size printed here was the size of the last step).We can see that the the correrct result is excluded from the range because of a rounding error: Rust rounds always towards zero so
33/2
becomes16
, which makes it here lose enough of it's "jumping power" for it not to reach the correct range.It seems to me that the correct thing to do is to ensure that the result is always rounded up.