MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / loadFont

Function loadFont

Engine/source/platformX11/X11Font.client.cpp:42–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40// Needed for getenv in createFont
41#include <stdlib.h>
42XftFont *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)

Callers 2

createMethod · 0.70
incLoadCountMethod · 0.50

Calls 4

stristrFunction · 0.85
dSprintfFunction · 0.85
printfFunction · 0.85
dStrlenFunction · 0.50

Tested by

no test coverage detected