Results 1 to 3 of 3

Thread: Caching and reusing platform-level font objects

  1. #1
    Join Date
    May 2019
    Posts
    6
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows Android

    Default 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:
    Qt Code:
    1. QFont f1("Arial", 18);
    2. QFont f2("Arial", 18);
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,336
    Thanks
    36
    Thanked 1,528 Times in 1,479 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    _

  3. #3
    Join Date
    May 2019
    Posts
    6
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows Android

    Default 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:
    Qt Code:
    1. QFontDef request;
    2. mutable QFontEngineData *engineData;
    To copy to clipboard, switch view to plain text mode 
    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:
    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:
    Qt Code:
    1. QFont f1("Arial", 18);
    2. QFont f2("Arial", 18);
    To copy to clipboard, switch view to plain text mode 
    One shall decide how to proceed and if this kind of light optimization deserves the efforts.

Similar Threads

  1. Cross platform font issue.
    By manmohan in forum Newbie
    Replies: 3
    Last Post: 16th April 2013, 08:38
  2. How to handle cross platform font sizes
    By Berryblue031 in forum Qt Programming
    Replies: 2
    Last Post: 27th June 2011, 14:55
  3. Qt Designer Platform specific font size for labels
    By abey in forum Qt Tools
    Replies: 0
    Last Post: 16th February 2011, 16:21
  4. Replies: 1
    Last Post: 11th November 2010, 00:31
  5. How to using/setting the font caching
    By iceman in forum Newbie
    Replies: 5
    Last Post: 28th July 2010, 05:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.