Caching and reusing platform-level font objects
Hi. I have a limited device that only supports limited number of fonts internally. Therefore it is important that Qt does internal optimization for reusing system-level font objects. For example:
shall result in a same system-level font (handle) internally. Does Qt implement this reliably or I need to roll my own parameter-based font caching?
Before migrating to Qt I had to implemented such caching which was the only way to handle system limitations.
Re: Caching and reusing platform-level font objects
That's a good question.
I would assume it does do such caching, but you can probably check for yourself.
The code for Qt is easily browsable over at woboq.org https://code.woboq.org/qt5/qtbase/sr...t/qfont.h.html
Cheers,
_
Re: Caching and reusing platform-level font objects
Tanks anda_skoa,
I was hoping to save time and avoid debugging Qt, but...
Here is what I found:
QFont holds an internal shared data object of QFontPrivate following Qt's shared data object scheme (pattern). QFontPrivate has members called:
Code:
QFontDef request;
mutable QFontEngineData *engineData;
Which seem to be related to the internal font support involving classes like QFontCache, QFontEngineData, QFontData, QFontDef, etc. Those suppose caching of objects through object maps - which is mentioned in the documentation as well:
Quote:
Loading fonts can be expensive, especially on X11. QFont contains extensive optimizations to make the copying of QFont objects fast, and to cache the results of the slow window system functions it depends upon.
But the above are all internals.
Therefore the only optimization one can do is saving unnecessary QFontPrivate object creation. This is to save creating two identical instances - one for each line in case of following constructor:
One shall decide how to proceed and if this kind of light optimization deserves the efforts.