EnumeratePlatformFonts for X11
by Gary "ChunkyKs" Briggs · in Torque Game Builder · 12/13/2006 (6:04 pm) · 1 replies
LevelBuilderTextObject needs an enumeratePlatformFonts function. Avert your eyes, those with sensitive dispositions, X11 API code can be found herein!
[slap this on the end of x86UNIXFont.cc, it's prototyped already in platform/ somewhere]
Gary (-;
[slap this on the end of x86UNIXFont.cc, it's prototyped already in platform/ somewhere]
void enumeratePlatformFonts( Vector<StringTableEntry>& fonts, char* fontFamily ) {
char **xfonts;
int maxfonts = 10000; // This is a lot of fonts.
// My Mac's X Server has 5834
char pattern[32] = "*";
int count;
Display *display = XOpenDisplay(getenv("DISPLAY"));
if(NULL == display) {
Con::errorf("Couldn't open the display %s", getenv("DISPLAY"));
}
if(fontFamily) {
dSprintf(pattern, 32, "-%s-*", fontFamily);
// There is a space reserved for X fonts IN HELL
}
xfonts = XListFonts(display, pattern, maxfonts, &count);
char **f = xfonts;
while(*f) {
if(NULL != fontFamily || '-' != **f ) {
// Only show aliases, unless
// they've asked for a specific famliy
fonts.push_back( StringTable->insert(*f));
}
f++;
}
XFreeFontNames(xfonts);
XCloseDisplay(display);
}Gary (-;
Torque Owner Eric Robinson
void enumeratePlatformFonts( Vector<StringTableEntry> &fonts, char* fontFamily) { Display *display = XOpenDisplay(getenv("DISPLAY")); int screen; XftFontSet *fs; char *name; int i; Con::printf("enumeratePlatformFonts: howdy!"); if (!display) AssertFatal(false, "enumeratePlatformFonts: cannot connect to X server"); screen = DefaultScreen(display); fs = XftListFonts(display, screen, 0, XFT_FAMILY, NULL); for (i = 0; i < fs->nfont; i++) { if (XftPatternGetString(fs->fonts[i], XFT_FAMILY, 0, &name) == XftResultMatch) { Con::printf("enumeratePlatformFonts: name=%s", name); StringTableEntry steBuffer = StringTable->insert( name ); fonts.push_back( steBuffer ); } } XftFontSetDestroy(fs); XCloseDisplay(display); Con::printf("enumeratePlatformFonts: bye bye"); }Here's his post: