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 - Improve SDL_ttf glyph cache system
Summary: Improve SDL_ttf glyph cache system
Status: RESOLVED FIXED
Alias: None
Product: SDL_ttf
Classification: Unclassified
Component: misc (show other bugs)
Version: unspecified
Hardware: x86_64 Linux
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-10-12 13:47 UTC by Sylvain
Modified: 2018-11-06 14:29 UTC (History)
0 users

See Also:


Attachments
patch (2.36 KB, patch)
2018-10-12 13:48 UTC, Sylvain
Details | Diff
patch updated (4.34 KB, patch)
2018-11-03 07:08 UTC, Sylvain
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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