5 #include "fontConfig.h"
7 static TTF_Font
*g_font
;
10 static bool_t isFontInit
= FALSE
;
12 bool_t
font_is_inicialized()
19 char *arg
[] = {":lang=he:outline=true:style=Book", "family", "style", "weight", "file", NULL
};
21 font_config_t
*font_list
;
24 assert(interface_is_inicialized() == TRUE
);
26 res
= fontconfig_init();
32 font_list
= fontconfig_find(arg
);
35 for(i = 0 ; font_list[i].path != NULL ; i++ )
37 printf("path[%d]=%s\nflag[%d]=%s\n\n", i, font_list[i].path, i, font_list[i].flag);
40 if (font_list
== NULL
) {
41 error("Unable to locate a font");
45 font_file
= strdup(font_list
[0].path
);
48 fontconfig_del_list(font_list
);
51 if (TTF_Init() == -1) {
53 error("SDL: %s", SDL_GetError());
57 accessExistFile(font_file
);
59 g_font
= TTF_OpenFont(font_file
, fontSize
);
60 TTF_SetFontStyle(g_font
, TTF_STYLE_NORMAL
);
62 debug("Loading font [%s]", font_file
);
69 * Shows text *string on coordinates [x,y] with RGB color
71 void font_draw(char *string
, int x
, int y
, int r
, int g
, int b
)
75 SDL_Color font_color
= {r
, g
, b
, SDL_ALPHA_OPAQUE
};
77 assert( string
!= NULL
);
79 text
= TTF_RenderUTF8_Blended(g_font
, string
, font_color
);
81 /* because if string=="" TTF_RenderUTF8_Blended returns NULLĀ */
83 image
= image_new(text
);
84 image_draw(image
, x
, y
, 0, 0, image
->w
, image
->h
);
89 void font_drawMaxSize(char *s
, int x
, int y
, int w
, int h
, int r
, int g
, int b
)
91 SDL_Rect src_rect
, dst_rect
;
94 SDL_Color font_color
= {r
, g
, b
, SDL_ALPHA_OPAQUE
};
99 text
= TTF_RenderUTF8_Blended(g_font
, s
, font_color
);
123 /* possibly broken */
124 image_draw(i
, x
, y
, 0, 0, my_w
, my_h
);
129 * Returns size of the font
136 void font_text_size(char *s
, int *w
, int *h
)
142 TTF_SizeUTF8(g_font
, s
, w
, h
);
146 * Frees font from memory
150 TTF_CloseFont(g_font
);
153 debug("Unloading font");