| 40 | // Needed for getenv in createFont |
| 41 | #include <stdlib.h> |
| 42 | XftFont *loadFont(const char *name, S32 size, Display *display) |
| 43 | { |
| 44 | XftFont *fontInfo = NULL; |
| 45 | const char* fontname = name; |
| 46 | if (dStrlen(fontname)==0) |
| 47 | fontname = "arial"; |
| 48 | else if (stristr(name, "arial") != NULL) |
| 49 | fontname = "arial"; |
| 50 | else if (stristr(name, "lucida console") != NULL) |
| 51 | fontname = "lucida console"; |
| 52 | |
| 53 | const char* weight = "medium"; |
| 54 | const char* slant = "roman"; // no slant |
| 55 | |
| 56 | if (stristr(name, "bold") != NULL) |
| 57 | weight = "bold"; |
| 58 | if (stristr(name, "italic") != NULL) |
| 59 | slant = "italic"; |
| 60 | |
| 61 | int mSize = size - 2 - (int)((float)size * 0.1); |
| 62 | char xfontName[512]; |
| 63 | // We specify a lower DPI to get 'correct' looking fonts, if we go with the |
| 64 | // native DPI the fonts are to big and don't fit the widgets. |
| 65 | dSprintf(xfontName, 512, "%s-%d:%s:slant=%s:dpi=76", fontname, mSize, weight, slant); |
| 66 | |
| 67 | // Lets see if Xft can get a font for us. |
| 68 | char xftname[1024]; |
| 69 | fontInfo = XftFontOpenName(display, DefaultScreen(display), xfontName); |
| 70 | // Cant find a suitabke font, default to a known font (6x10) |
| 71 | if ( !fontInfo ) |
| 72 | { |
| 73 | dSprintf(xfontName, 512, "6x10-%d:%s:slant=%s:dpi=76", mSize, weight, slant); |
| 74 | fontInfo = XftFontOpenName(display, DefaultScreen(display), xfontName); |
| 75 | } |
| 76 | XftNameUnparse(fontInfo->pattern, xftname, 1024); |
| 77 | |
| 78 | #ifdef DEBUG |
| 79 | Con::printf("Font '%s %d' mapped to '%s'\n", name, size, xftname); |
| 80 | #endif |
| 81 | |
| 82 | return fontInfo; |
| 83 | } |
| 84 | |
| 85 | |
| 86 | //GOldFont* createFont(const char *name, dsize_t size, U32 charset) |