Prevent GlyphNotCached due to ordering issues
Created by: michaelfairley
The BTreeMap ordering in gpu_cache doesn't really work, since it's a one-dimensional ordering across a two-dimensional space. It's possible for adjacent glyphs in the map to not be considered "matches" (because their scale is the same but their position is not within the position tolerance), while matches further away in the map do match.
This PR changes rect_for
and cache_queued
to check every glyph already in all_glyphs
for similarity, rather than only the ones adjacent to it in the BTreeMap. This comes with a very minor performance hit, but luckily helps simplify some code. I think that this was the only place where the ordering aspect of the BTreeMap was actually being used, so you could likely convert to a HashMap to gain a tiny bit of performance back.
There's also an additional fix that prevents changes to the oldest_in_use_row
from moving it forward in the LRU, since that could make it "more recent" than other currently-in-use rows.
I've also tested this branch against my game, where it's fixed a noticeable bug that causes various characters to occasionally not show up (due to GlyphNotCached
).
(P.S. Huge thanks for the library! I'm shipping my game in the next few weeks, and rusttype has been perfect for my font rendering needs.)