سؤال

How can I get the list of available fonts?

I would be nicer if I did not have to depend on something huge.

My solution so far is to list the directory /usr/share/fonts on linux and C:\Windows\Fonts on windows. Is this the right way to do that?

هل كانت مفيدة؟

المحلول

No, that is NOT the right way. However, the problem is that there really isn't a right way, short of standardising on something like freetype or writing your own library with lots of backends for different operating systems.

To be more clear: most operating systems have bitmapped fonts, outline fonts, different font encodings, various other font formats which occur, but aren't as well supported, or are supported via some additional plugins, non-alphabetic fonts (think of Wingdings, chess pieces, etc.), colored fonts, TeX fonts, postscript fonts, 3D fonts, etc.

Furthermore, you may not even have a standard way of listing them. Most operating systems list fonts by name and size, for instance, but the X Window System traditionally listed fonts by a lot of column headings, including their weight, whether they were sans/serif, fixed/variable spacing, italic vs. oblique, etc.

FURTHERMORE, you have issues like user fonts vs. system-wide fonts, and even network fonts, and font servers, and now web fonts.

In short, fonts are complicated. It's for reasons like this, that libraries like freetype exist. I'd suggest just using one.

BUT, if you do want a quicker, more hackish solution, then listing those dirs is a start. You should probably make the two methods you mention two possible back ends, with default backends chosen for Linux vs. windows, but perhaps the possibility of listing /usr/share/X11/fonts, or listing fonts via defoma, for example, instead.

نصائح أخرى

Well... I would use OpenGL and the default (guaranteed) fonts, a list of which can be found HERE

Or I would take a look at these links:

  1. Platform independent way to get font directory?
  2. Fonts in a multi-platform environment
  3. OpenGL Font tutorial

Or you could just use a graphic library (SDL, OpenGL), and a BITMAP, with the font in it... And use that for text! :)

Good luck, I hope you find what you are looking for!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top