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

Make the font cache a separate object #74

Merged
merged 6 commits into from
Feb 24, 2021
Merged

Make the font cache a separate object #74

merged 6 commits into from
Feb 24, 2021

Conversation

jwiggins
Copy link
Member

@jwiggins jwiggins commented Feb 24, 2021

This is a rather sizable refactor which aims to fix the [Windows] text rendering bugs introduced in #65.

Instead of creating thread_local globals in Font for management of glyph caching, I've separated out the font cache into a new FontCache object which exists independently of the Canvas* and Font objects. A font cache can be shared between any number of canvas instances, as long as one takes care not to use the cache simultaneously from multiple threads.

One big downside of this change is that it breaks the existing Font API by moving the Font.string_width method to FontCache.width. Therefore I intend to bump the package's major version number to 2, as an extra warning to downstream users. Canvas* classes also need to be passed a FontCache instance at construction time, but existing code can continue to work without modification due to some Python wrappers in the package's __init__ module.

It should fix #62, but some tests are needed.

Fixes #62

@jwiggins jwiggins force-pushed the refactor/font-cache branch from 6317090 to 9b49315 Compare February 24, 2021 15:47
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

Successfully merging this pull request may close these issues.

font.width(text) produce different results before and after drawing
1 participant