• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Aressera

How to enumerate the installed font paths on a system?

8 posts in this topic

I'm looking to see if there is a better solution to this problem than my current implementation. Currently, I search certain predefined system paths for font files ("C:\Windows\Fonts\" on Windows and "/System/Library/Fonts/", "/Library/Fonts/" on OS X), then open each file with Freetype to determine the font's family and face names, then cache this information, along with the file's path, for later use. The problem is that this is really slow (a couple of seconds).

 

I've looked at the available functionality on OS X and Windows and the only font management tools allow you to list the installed font names but don't allow you to get the path on the system where the font file is stored. Therefore, there's no way for me to use a library like Freetype to open the file.

 

Am I missing something or is there no better way to do this?

0

Share this post


Link to post
Share on other sites

It seems very odd that you would ever need to to this on both platforms.  Either you are using a MacOS / Cocoa based interface, or you are using a Windows-based interface, or you are using .NET or Qt or some other framework that handles the cross-platform stuff.

 

Without using a cross-platform library the same code won't work on both OSX and Windows.

 

For Windows you can use EnumFontFamilies to get the list.

 

For OS X you can use NSFontManager::availableFontFamilies to get the list.

 

For .NET or Qt or other libraries, these also have their own font family enumeration capabilities.

0

Share this post


Link to post
Share on other sites

I'm aware of those methods but they only seem to return the font names, but not the path the associated font files. I'm totally OK with using a platform-specific API (with #ifdefs) to do this but the provided ones on both platforms don't provide the necessary information.

 

I'm using the fonts as part of an OpenGL-based GUI system, so I can't really use the built-in text rendering either. I just don't want to have to scan the system myself for the necessary files when the OS has probably already done this and cached the information.

0

Share this post


Link to post
Share on other sites

Your method of enumerating all the fonts by parsing each individual file is going to be slow.  Look at other apps that do it, such as GIMP, and observe that it can take a long time for it to enumerate all the fonts.

 

If you are going to use your own font rendering system then yes, it will be slow.  That's just the cost of parsing a ton of files.

 

The whole point of using the OS to get the font list is that the OS has already parsed the data and has an index of the details you need.

0

Share this post


Link to post
Share on other sites

Yeah, just commenting on what Frob said ... I think you would be better off presenting the user with the font list you get from the OS and then when the user actually selects a font somehow mapping that font back to a font file (and possibly erring out if something goes wrong) rather than opening all the font files with FreeType which is what, I'm guessing, is really slow. (However, a couple of seconds actually isn't that bad -- I mean don't you just need to do this once at startup?)

0

Share this post


Link to post
Share on other sites

Yes, that's what I'd like to do, I'm just having trouble with the "somehow mapping that font back to a font file" part. Since the font files aren't guaranteed to be named with any convention I can't assume that they'll even contain the font name in their filenames. I know my current solution isn't ideal, that's why I'm asking for ideas.

 

Here is the basic interface for my font management system. Currently it caches the available font files behind the scenes (slow!) in a hash map internally so that the user can get the file containing the font with the given name. In general use (as part of a game's GUI) this won't be a huge issue because the game will just bundle the necessary font file with the game itself at a known path, however I still need to be able to access commonly available fonts (with fallbacks in case of failure) so that I can have a good default font for the rendered GUI elements if none is provided by the game.

FontManager fonts;
FontInfo fontInfo; // contains path to font file.

// Get a font file path for the given font family/style name
fonts.getFont( "times new roman", // font family name
               "" // optional font face name (i.e. bold, italic)
                &fontInfo );

// Get a sensible default system font file.
fonts.getDefaultFont( &fontInfo );
Edited by Aressera
0

Share this post


Link to post
Share on other sites

I'm just having trouble with the "somehow mapping that font back to a font file" part.

 

Well, that code project code is doing the following ( I think)

 

(1) Uses the registry to get a list of registry key -> font filename mappings, where the registry keys are like marked-up display names.

(2) Given a font display name, returns the filename associated with the first registry key that includes the display name as a substring.

 

You could use (1) because it is presumably faster than iterating over the file system, but do something more intelligent for (2). Namely you could write a function that given a font display name returns the set of all likely registry keys and open just those font files to find the one you want. But I  don't know exactly what is in the registry; maybe what the code project project is doing is good enough.

Edited by jwezorek
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0