26 std::string win_ttf::path_;
28 TTF_Font *win_ttf::ttf = NULL;
31 win_ttf::win_ttf (
const char *color,
const string & file) :
win_font ()
36 Color.r = 255; Color.g = 173; Color.b = 123;
39 Color.r = 139; Color.g = 185; Color.b = 238;
42 Color.r = 205; Color.g = 254; Color.b = 148;
45 Color.r = 255; Color.g = 238; Color.b = 123;
48 Color.r = 222; Color.g = 133; Color.b = 230;
51 Color.r = 255; Color.g = 255; Color.b = 255;
61 cursor = &operator[](
'_');
62 length_ = cursor->length ();
65 else win_font::load ((
char *) color);
71 if (refcount == 0 && ttf != NULL)
75 static int glyph_height (TTF_Font *ttf,
const u_int16 & chr)
78 if (TTF_GlyphIsProvided(ttf, chr))
80 TTF_GlyphMetrics(ttf, chr, NULL, NULL, &miny, &maxy, NULL);
83 return TTF_FontHeight(ttf)/2;
86 bool win_ttf::load (
const string & file)
95 if (ttf != NULL)
return true;
98 if (file.size() > 1 && (file[0] ==
'/' || file[1] ==
':'))
105 path = WIN_DIRECTORY;
108 path += WIN_FONT_DIRECTORY;
111 path += file ==
"" ?
"Aclonica.ttf" : file;
115 ttf = TTF_OpenFont (
path.c_str (), size);
119 printf (
"*** error loading font '%s':\n %s\n",
path.c_str (), TTF_GetError ());
123 TTF_SetFontHinting(ttf, TTF_HINTING_LIGHT);
126 avg_size += glyph_height(ttf,
'c');
127 avg_size += glyph_height(ttf,
'C');
128 avg_size += glyph_height(ttf,
'0');
129 avg_size += glyph_height(ttf,
':');
138 ttf = TTF_OpenFont (
path.c_str (), --size);
139 TTF_SetFontHinting(ttf, TTF_HINTING_LIGHT);
141 avg_size += glyph_height(ttf,
'c');
142 avg_size += glyph_height(ttf,
'C');
143 avg_size += glyph_height(ttf,
'0');
144 avg_size += glyph_height(ttf,
':');
151 bool win_ttf::in_table(
u_int16 tmp)
153 if (win_font::in_table (tmp) ==
true)
return true;
156 if (tmp > 0x80 || isprint (tmp)) {
168 static SDL_Color bg = { 0x00, 0x00, 0x00, 0 };
169 static SDL_Color white = { 0xff, 0xff, 0xff, 0 };
181 int real_height_ = TTF_FontHeight(ttf) +
screen::scale() - 1;
183 cursor = &operator[](
'_');
184 length_ = cursor->
length ();
188 else if (win_font::in_table (glyph))
190 return *(glyphs[glyph]);
195 return *(glyphs[
' ']);
198 SDL_Surface *s = TTF_RenderUNICODE_Shaded (ttf, unichar, Color, bg);
201 return *(glyphs[
' ']);
211 s = TTF_RenderUNICODE_Solid (ttf, unichar, bg);
214 image shadow (s, white);
215 shadow.draw (1, 1+height_-shadow.height(), 0, 0, shadow.length(), shadow.height(), NULL, glph);
219 fprintf (stderr,
"%s\n", TTF_GetError ());
222 tmp.draw (0, height_-tmp.height(), 0, 0, tmp.length(), tmp.height(), NULL, glph);
225 glyphs[glyph] = glph;
233 #ifdef HAVE_TTF_GETFONTKERNINGSIZEGLYPHS 236 return TTF_GetFontKerningSizeGlyphs(ttf, char1, char2) + overflow[char1];
239 return overflow[char1];
#define u_int16
16 bits long unsigned integer
u_int16 length() const
Returns the length of the drawable.
void fillrect(s_int16 x, s_int16 y, u_int16 l, u_int16 h, u_int32 col, drawing_area *da_opt=NULL)
Fills an area of the surface with a given color.
u_int8 scale() const
Get the surfaces current scaling factor.
Image manipulation class.
#define u_int32
32 bits long unsigned integer
static u_int8 scale()
Scale factor of the screen.
A* pathfinding algorithm implementation class.
static u_int32 trans_col()
Returns the translucent color in screen's depth format.
#define s_int8
8 bits long signed integer