We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4307

Summary: Improve SDL_ttf glyph cache system
Product: SDL_ttf Reporter: Sylvain <sylvain.becker>
Component: miscAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: unspecified   
Hardware: x86_64   
OS: Linux   
Attachments: patch
patch updated

Description Sylvain 2018-10-12 13:47:01 UTC
There are many glyph cache misses with SDL_ttf because it use characters itselves as keys. It's more efficient to use FT indexes as keys.
Comment 1 Sylvain 2018-10-12 13:48:39 UTC
Created attachment 3368 [details]
patch
Comment 2 Sylvain 2018-10-19 13:07:19 UTC
Update: I was too optimistic when I said it would reduce number of collisions when caching glyphs, hence, be more efficient.
In fact, I took into account the initialisation of cache, because it calls "Flush_Glyph" the first time for Glyph cache system. I was mistaken.

In the end, it seems to be the same. Maybe a little bit less of collision with Index, when using Arabic or Chinese, but this is minimal and that can also be my test-case.



But, in favour of the patch
===========================

Using Index instead of Glyph is a better option to ease the integration of a text shaping engine into SDL_ttf (like in bug 3046 and bug 3211). It also doesn't break current SDL_ttf.

This way, SDL_ttf can have in the future a function to render an array of indexes e.g: 
  
    SDL_Surface *TTF_RenderINDEX_Solid(TTF_Font *font, int *indexes, int nb_indexes, SDL_Color fg);

Where (indexes, nb_indexes) would be produced by a text shaping engine.

Having a text shaping engine is essential to render text correctly. To be picky, even English language needs it to render ligatures like "fi".
https://en.wikipedia.org/wiki/Typographic_ligature
https://en.wikipedia.org/wiki/Typographic_ligature#/media/File:Ligatures.svg
Comment 3 Sam Lantinga 2018-11-02 23:49:16 UTC
Can you rebase this patch on the current code in Mercurial?

Thanks!
Comment 4 Sylvain 2018-11-03 07:08:29 UTC
Created attachment 3436 [details]
patch updated

I've updated the patch and changed it a little bit. 
(no need to have twice the index in the cache slot!)
Comment 5 Sam Lantinga 2018-11-06 14:29:17 UTC
Patch added, thanks!
https://hg.libsdl.org/SDL_ttf/rev/1fc2b16737da