Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Finding System Font Files?
Forum Updated to NodeBB v4.3 + New Features

Finding System Font Files?

Scheduled Pinned Locked Moved General and Desktop
17 Posts 8 Posters 12.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    goetz
    wrote on last edited by
    #7

    As far as I remember it, Qt relies on the operating system/window system facilities for getting the fonts and does not open the files itself.

    http://www.catb.org/~esr/faqs/smart-questions.html

    1 Reply Last reply
    0
    • L Offline
      L Offline
      LiamMaru
      wrote on last edited by
      #8

      [quote author="Volker" date="1294232781"]As far as I remember it, Qt relies on the operating system/window system facilities for getting the fonts and does not open the files itself.

      [/quote]

      Ah okay, well that might mean I'll have to write my own methods for acquiring the system fonts list. I'm honestly not entirely sure how dependent Qt is on win32 or the host operating system whatever it may be, weather it just acquires a rendering context and makes everything look pretty from there, or something else. I'm familiar with FreeType, and have used that in the past (and am now) used it to load and render fonts, does everything you could need.

      The fonts directory is a sticky point, I'm going to produce something similar to what QFontDatabase provides, but with a mapping to the files a particular face/family combination came from. How the directories will enter into this, remains to be seen.

      1 Reply Last reply
      0
      • I Offline
        I Offline
        ixSci
        wrote on last edited by
        #9

        Hi, just have stumbled on "QDesktopServices::storageLocation":http://doc.qt.nokia.com/4.7/qdesktopservices.html#storageLocation and I hope it will help you. But I didn't try it myself, though.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #10

          [quote author="ixSci" date="1294612188"]Hi, just have stumbled on "QDesktopServices::storageLocation":http://doc.qt.nokia.com/4.7/qdesktopservices.html#storageLocation and I hope it will help you. But I didn't try it myself, though.[/quote]

          Unfortunately this gives you only the location for the user fonts, not the system fonts :-/

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • I Offline
            I Offline
            ixSci
            wrote on last edited by
            #11

            Volker, I just have tested it and it gave me C:\Windows\Fonts. As long as I know there is no such a notion as user fonts in Windows. Is it there a user fonts notion in unix family?

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #12

              Not necessarily a Unix issue, more of a Unix/Linux flavour. Most of them have some font dir in the user's home dir because writing to the system directory is forbidden for many of the users (no root password!). On my old KDE box it's in $HOME/.fonts. The new linux/freedesktop standards may set it different!

              Mac OS X does have a user font dir too: $HOME/Library/Fonts.

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • L Offline
                L Offline
                LiamMaru
                wrote on last edited by
                #13

                ixSciixSci, great find, thanks!

                Volker, the users font directory is largely sufficient, the system fonts directory can be picked up by navigating from root. If the user knows enough to move it, then he should be smart enough to specify where he moved it to in the settings/directories dialog of my application :).

                I should also add, there is no notion of user fonts on a windows PC. There is however, System and user fonts on Unix, and on OSX there is a third concept, network fonts. I aim to support all concepts as much as possible, however system fonts is the minimum target at this time.

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  clivel
                  wrote on last edited by
                  #14

                  Tagging onto this old thread, because I have a similar question, which was not answered.

                  I need to read data directly from TTF font files when a user chooses a font from something like a QFontDialog. Unfortunately neither the QFont returned from QFontDialog or even QFontDatabase include any reference to the actual file.

                  So instead I iterate through the font files, parsing out the font name etc from each file so that I can populate a font selection dialog box that maps a user selected font directly to the actual file.

                  My problem is finding the font files, Qt 5 provides QStandardPaths::FontsLocation
                  or on 4.x QDesktopServices::FontsLocation. These return a path to the user fonts directory.
                  On Windows which does not differentiate between user and system fonts this works well, returning C:/Windows/Fonts
                  However on Linux it only returns the user font directory e.g /home/clivel/.fonts which by default is empty so doesn't really help because most applications offer fonts from the system font directory for the user to choose from. e.g on Ubuntu 12.04, the list of available fonts displayed by the Gimp are from the system directory which is /usr/share/fonts/truetype.

                  So, after that long winded explanation, my question is, how do I get the system fonts directory?
                  I could of course hardcode /usr/share/fonts but besides being klunky, I am not sure how universal this is across Linux systems.

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    jbarnesweb
                    wrote on last edited by
                    #15

                    This is only a partial treatment of the question. The system fonts directory varies across platforms, even distributions. Some Linux distros use /usr/share/fonts, some /usr/local/share/fonts. Libraries like fontconfig address this in a good way, but Qt may or may not be compiled with fontconfig.

                    One way to address this is to distribute fontconfig configured per platform supported. In other words add a dir element to the local.conf fontconfig parent element for each directory containing system or user fonts. Then you would link against your fontconfig lib and use the library api to get the font files.

                    I wish QFontDatabase would provide the actual font file matched...

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      clivel
                      wrote on last edited by
                      #16

                      Hi Jbarnes,
                      Thanks for the response, It really would be great if QFontDatabase provided the actual font file.

                      What I did in the end was a multi-pronged approach:
                      First I check if either /etc/fonts/fonts.conf and /etc/fonts/local.conf exist, and if so parse them for the location of font files between <dir> and </dir> tags.

                      I then also check both the locations you mention; /usr/share/fonts and the /usr/local/share/fonts for fonts and finally check the user font directory returned by Qt (~/.fonts).

                      Hopefully that will take care of most Linux distributions.

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        jbarnesweb
                        wrote on last edited by
                        #17

                        Of course, there is no guarantee that fonconfig is installed on a desktop. In most Linux distro's, it is by default. There is also a chance that fontconfig is installed as a user library. You might want to check for it during your installation. FONTCONFIG_PATH is a useful environment variable to check, also.

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved