tags:

views:

69

answers:

2

Is there a way I could find where fonts are stored on either Windows, OSX, or Linux? If not, is there a way I can guarantee certain paths (such as X:/Windows/Fonts/) for all 3 platforms? What ifdefs would I use for these?

Thanks

A: 

That's assuming the target OS has a font folder. For example, it's quite feasible for a Linux installation to be console-only and not have a font directory at all.

Anyways, my best guess is that there is no platform independent way. You can write your own platform independent function, but within it will have to check the current OS (via some IFDEF's, I cannot say what) and then call the right function. But again - I wouldn't be so sure you can obtain it under Linux at all.

Vilx-
To make matters worse, even on a unix system with XWindows, the fonts could be getting generated mainly through a font server, which could be on a remote machine and completely opaque/unavailable to the client programs.
TokenMacGuy
+3  A: 

This is going to be one of those 'simple' problems could have an over-the-top solution depending on what you need this information for.

I will have to apologize for the vaguer Linux answers, as font management across Linux distributions are not consistent and can be very configurable, can be influenced by desktop environment, can be remotely served, etc.

Checking for environment

You can check various platforms via the use of macros defined for specific environments.

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

Font directory locations

  • Windows
    • On Windows newer than 3.1, the font directory is located in %WINDIR%\fonts.
  • Mac OS X
    • Mac OSX has multiple font directories
      • /System/Library/Fonts - Fonts necessary for the system. Do not touch these.
      • /Library/Fonts - Additional fonts that can be used by all users. This is generally where fonts go if they are to be used by other applications.
      • ~/Library/Fonts - Fonts specific to each user.
      • /Network/Library/Fonts - Fonts shared for users on a network.
  • Linux
    • As mentioned above, a Linux distribution may not have specified font directories at all. I remember dealing with this issue a while back since Linux distros don't use any specific font management.
    • There could be an XFS (X Font Server) serving up fonts remotely.
    • The most common locations for fonts across Linux distributions are /usr/share/fonts, /usr/local/share/fonts, and user-specific ~/.fonts
    • Some systems may have configured font directories in the file /etc/fonts/fonts.conf or /etc/fonts/local.conf.

Resources:

birryree
Thanks this is a great answer!
Milo
Note that on Win Vista and newer, fonts can be installed anywhere, not just the `%WINDIR%\Fonts` directory. The registry holds the install locations.
Otaku
@Otaku that's good information to know - can you provide any links or info I can put into my post?
birryree