A platform independent way to get a font catalog?

Is there a way to find where fonts are stored on Windows, OSX or Linux? If not, is there a way to guarantee specific paths (e.g. X: / Windows / Fonts /) for all three platforms? What ifdefs would I use for them?

thanks

+7
c ++ fonts
source share
2 answers

This will be one of those β€œsimple” problems that may have an advanced solution, depending on what you need this information for.

I will have to apologize for the answers to an undetermined amount of Linux, since font management in Linux distributions is incompatible and can be very customizable, it can depend on the desktop environment, it can be remotely maintained, etc.

Environment check

You can test various platforms using macros defined for specific environments.

  • Windows - #if defined(_WIN32)
    • _WIN32 defined for both 32-bit and 64-bit Windows.
  • Mac OSX - #if defined(_APPLE_) && defined(_MACH_)
    • _APPLE_ defined for all Apple computers, and _MACH_ is defined if the system supports Mach, a la Mac OSX system calls
  • Linux (generic) - #if defined(linux) || defined(__linux) #if defined(linux) || defined(__linux)

Font Catalog Location

  • Window
    • On Windows later version 3.1, the font directory is located in %WINDIR%\fonts .
  • Mac OS X
    • Mac OSX has several font directories
      • /System/Library/Fonts - Fonts needed for the system. Do not touch them.
      • /Library/Fonts - Additional fonts that can be used by all users. This usually happens when fonts go if used by other applications.
      • ~/Library/Fonts - Fonts specific to each user.
      • /Network/Library/Fonts - Fonts available to users on the network.
  • Linux
    • As mentioned above, a Linux distribution may not specify font directories at all. I remember that I dealt with this problem a while ago, since Linux distributions do not use any specific font management.
    • There may be XFS (X Font Server) serving the fonts remotely.
    • The most common font locations on Linux distributions are /usr/share/fonts , /usr/local/share/fonts and custom ~/.fonts
    • On some systems, font directories can be configured in /etc/fonts/fonts.conf or /etc/fonts/local.conf .

Resources

+10
source share

Suppose the target OS has a font folder. For example, it is possible that the Linux installation will be console only and have no font directory at all.

In any case, I think there is no platform independent way. You can write your own platform-independent function, but inside it you will need to check the current OS (through some IFDEFs, I can’t say that), and then call the correct function. But then again - I would not be sure that you can get it under Linux at all.

0
source share

All Articles