21 TTF_Font *win_ttf::ttf = NULL;
24 win_ttf::win_ttf (
const char *color,
const string & file) :
win_font ()
29 Color.r = 255; Color.g = 173; Color.b = 123;
32 Color.r = 139; Color.g = 185; Color.b = 238;
35 Color.r = 205; Color.g = 254; Color.b = 148;
38 Color.r = 255; Color.g = 238; Color.b = 123;
41 Color.r = 222; Color.g = 133; Color.b = 230;
44 Color.r = 255; Color.g = 255; Color.b = 255;
52 u_int16 real_height_ = TTF_FontAscent (ttf);
53 height_ = screen::dbl_mode () ? (real_height_+3) >> 1 : real_height_+1;
54 cursor = &operator[](
'_');
55 length_ = cursor->length ();
58 else win_font::load ((
char *) color);
65 if (refcount == 0 && ttf != NULL)
69 bool win_ttf::load (
const string & file)
74 u_int32 size = screen::dbl_mode () ? 22 : 12;
77 if (ttf != NULL)
return true;
80 if (file !=
"" && file[0] ==
'/')
90 path += WIN_FONT_DIRECTORY;
93 path += file ==
"" ?
"avatar.ttf" : file;
97 ttf = TTF_OpenFont (path.c_str (), size);
101 printf (
"*** error loading font '%s':\n %s\n", path.c_str (), TTF_GetError ());
106 while (TTF_FontAscent (ttf) > (screen::dbl_mode () ? 24 : 13)) {
108 TTF_OpenFont (path.c_str (), --size);
114 bool win_ttf::in_table(
u_int16 tmp)
116 if (win_font::in_table (tmp) ==
true)
return true;
119 if (tmp > 0x80 || isprint (tmp)) {
128 static u_int16 unichar[2] = { 0, 0 };
131 static SDL_Color bg = { 0x00, 0x00, 0x00, 0 };
132 static SDL_Color white = { 0xff, 0xff, 0xff, 0 };
133 if (win_font::in_table (glyph))
return *(glyphs[glyph]);
134 if (ttf == NULL)
return *(glyphs[
' ']);
136 SDL_Surface *s = TTF_RenderUNICODE_Shaded (ttf, unichar, Color, bg);
137 if (s == NULL)
return *(glyphs[
' ']);
140 image *glph =
new image (tmp.length(), height_,
false);
143 s = TTF_RenderUNICODE_Solid (ttf, unichar, bg);
146 image shadow (s, white);
147 shadow.draw (1, 1+height_-shadow.height(), 0, 0, shadow.length(), shadow.height(), NULL, glph);
151 fprintf (stderr,
"%s\n", TTF_GetError ());
154 tmp.draw (0, height_-tmp.height(), 0, 0, tmp.length(), tmp.height(), NULL, glph);
155 glyphs[glyph] = glph;