Results 1 to 5 of 5

Thread: How to find the filepath to a font

  1. #1
    Join Date
    Feb 2010
    Location
    Los Angeles
    Posts
    61
    Thanks
    9
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question How to find the filepath to a font

    Hello all,

    I am working under linux with Qt4.7 and need to find the path to a selected QFont. So far I have tried:

    1. QDesktopServices::storageLocation(QDesktopServices ::FontsLocation) -- points to a dir that does not exists
    2. QFont::rawName () -- returns an empty string


    Any suggestions?
    Markus

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to find the filepath to a font

    Qt uses FontConfig to abstract away the management of actual font files, multiple font directories, substitutions, user preferences etc. AFAICT there is no way to obtain the underlying font file (*.ttf for example) through Qt.

    1. The directory returned by default is somewhere you can place fonts and FontConfig will generally find them. It is "~/.fonts" on my machines. If it does not exist that FontConfig path is simply ignored. See /etc/fonts/fonts.conf or the equivalent on your machine to see where FontConfig looks for fonts.
    2. As the docs say, rawName() returns an empty string if FontConfig is in use, and XLFD string otherwise. It does not return a file path.

    Why do you need to do this?

  3. The following user says thank you to ChrisW67 for this useful post:

    Markus (13th November 2013)

  4. #3
    Join Date
    Feb 2010
    Location
    Los Angeles
    Posts
    61
    Thanks
    9
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to find the filepath to a font

    Quote Originally Posted by ChrisW67 View Post
    1. The directory returned by default is somewhere you can place fonts and FontConfig will generally find them. It is "~/.fonts" on my machines. If it does not exist that FontConfig path is simply ignored. See /etc/fonts/fonts.conf or the equivalent on your machine to see where FontConfig looks for fonts.
    2. As the docs say, rawName() returns an empty string if FontConfig is in use, and XLFD string otherwise. It does not return a file path.

    Why do you need to do this?
    it returns "~/.fonts" on my OS so it seems FontConfig is used. I dont know anything about that so I will have to look into it.
    I need this because I am writing a GUI to a Lua based render engine and I need to pass in the path to the selected font.

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to find the filepath to a font

    Lua has some access to the same FontConfig mechanism though the gd library (possibly others) so it should get the same result if it asks for the same font by family name, size etc. Perhaps you can send a font name rather than file path?

  6. #5
    Join Date
    Feb 2010
    Location
    Los Angeles
    Posts
    61
    Thanks
    9
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to find the filepath to a font

    I am using fontconfig now and just pass the family name, style and size to it. Works now!
    Thanks
    Markus

Similar Threads

  1. QFontDatabase:Cannot find font directory
    By soumya in forum Qt for Embedded and Mobile
    Replies: 9
    Last Post: 10th November 2014, 07:08
  2. Replies: 2
    Last Post: 16th October 2013, 12:56
  3. unable to find font when placed under lib/font dir
    By menkey18 in forum Qt Programming
    Replies: 6
    Last Post: 14th December 2012, 08:45
  4. QFileInfo::filePath and std::ofstream
    By TorAn in forum Qt Programming
    Replies: 1
    Last Post: 2nd December 2010, 01:55
  5. Find font files
    By kovid in forum Qt Programming
    Replies: 0
    Last Post: 8th June 2008, 23:59

Tags for this Thread

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.