5 std::vector<FT_Face> fonts;
11 if (FT_Init_FreeType(&library))
12 throw std::runtime_error("FreeType init failed.");
15 if (FT_New_Face(library, "/usr/share/fonts/truetype/msttcorefonts/Georgia.ttf", 0, &face))
16 throw std::runtime_error("Face opening failed.");
17 if (FT_Set_Char_Size(face, 0, 12 * 64, 96, 96))
18 throw std::runtime_error("Size set failed.");
19 fonts.push_back(face);
22 if (FT_New_Face(library, "/usr/share/fonts/truetype/freefont/FreeSerif.ttf", 0, &face)) {
23 std::fprintf(stderr, "Warning: Couldn't open FreeSerif, some glyphs might not be available\n");
25 if (FT_Set_Char_Size(face, 0, 12 * 64, 96, 96))
26 throw std::runtime_error("Size set failed.");
27 fonts.push_back(face);
31 if (FT_New_Face(library, "arialuni.ttf", 0, &face)) {
32 std::fprintf(stderr, "Warning: Couldn't open Arial Unicode MS, some glyphs might not be available\n");
34 if (FT_Set_Char_Size(face, 0, 12 * 64, 96, 96))
35 throw std::runtime_error("Size set failed.");
36 fonts.push_back(face);
40 unsigned my_draw_text(const widestring &str, unsigned char *buf, int xpos, int ypos, bool real_render, int r, int g, int b)
45 for (widestring::const_iterator i = str.begin(); i != str.end(); ++i) {
47 for (std::vector<FT_Face>::const_iterator j = fonts.begin(); j != fonts.end(); ++j) {
48 glyph_index = FT_Get_Char_Index(*j, *i);
52 if (FT_Load_Glyph(*j, glyph_index, FT_LOAD_RENDER))
53 throw std::runtime_error("Couldn't load glyph");
57 if (glyph_index == 0) {
58 std::fprintf(stderr, "Warning: Could not find a glyph in any font for U+%x, ignoring\n", *i);
64 FT_Bitmap *bm = &(slot->bitmap);
65 for (y = 0; y < bm->rows; y++) {
67 int dsty = ypos - slot->bitmap_top + y;
68 if (dsty < 0 || dsty > 599) continue;
70 unsigned char *dst = buf + dsty * 800*4 + (x + xpos + slot->bitmap_left)*4;
71 unsigned char *src = bm->buffer + y * bm->width;
72 for (xx = 0; xx < bm->width; xx++) {
73 *dst = (*dst * (256-*src) + r * *src) >> 8;
75 *dst = (*dst * (256-*src) + g * *src) >> 8;
77 *dst = (*dst * (256-*src) + b * *src) >> 8;
85 x += slot->advance.x >> 6;