27#ifdef SDL2_PLAIN_INCLUDE
67 #define adj_font(size) size
70#define ptsize_default() adj_font(default_font_size(active_theme))
108 if (pstr != NULL && pstr->
text != NULL && pstr->
text[0] !=
'\0') {
109 char *current = pstr->
text;
111 bool new_line =
FALSE;
124 if (!((pstr->
style & 0x0F) & TTF_STYLE_NORMAL)) {
125 TTF_SetFontStyle(pstr->
font, (pstr->
style & 0x0F));
129 int ww, hh,
count = 0;
134 while (utf8_texts[
count]) {
135 if (TTF_SizeUTF8(pstr->
font, utf8_texts[
count], &ww, &hh) < 0) {
139 }
while (utf8_texts[
count]);
140 log_error(
"TTF_SizeUTF8() return ERROR!");
148 if (TTF_SizeUTF8(pstr->
font, pstr->
text, &w, &h) < 0) {
149 log_error(
"TTF_SizeUTF8() return ERROR!");
153 if (!((pstr->
style & 0x0F) & TTF_STYLE_NORMAL)) {
154 TTF_SetFontStyle(pstr->
font, TTF_STYLE_NORMAL);
161 fill->h = (pstr ? TTF_FontHeight(pstr->
font) : 0);
217 log_error(
"create_utf8_str(): load_font() failed");
223 str->style = TTF_STYLE_NORMAL;
224 str->bgcol = (SDL_Color) {0, 0, 0, 0};
258 n = (strlen(pchars) + 1);
262 size_t n1 = (3 * pstr->
n_alloc) / 2;
279 SDL_Rect dst_rect = { x, y, 0, 0 };
282 if (
alphablit(text, NULL, dest, &dst_rect, 255) < 0) {
283 log_error(
"write_utf8(): couldn't blit text to display: %s",
300 SDL_Surface *text = NULL;
306 if (!((pstr->
style & 0x0F) & TTF_STYLE_NORMAL)) {
307 TTF_SetFontStyle(pstr->
font, (pstr->
style & 0x0F));
312 text = TTF_RenderUTF8_Shaded(pstr->
font,
317 text = TTF_RenderUTF8_Solid(pstr->
font, pstr->
text, pstr->
fgcol);
320 text = TTF_RenderUTF8_Blended(pstr->
font, pstr->
text, pstr->
fgcol);
325 log_debug(
"create_utf8_surf: Font is generally %d big, and "
326 "string is %d big", TTF_FontHeight(pstr->
font), text->h);
327 log_debug(
"create_utf8_surf: String is %d length", text->w);
329 log_debug(
"create_utf8_surf: text NULL");
333 if (!((pstr->
style & 0x0F) & TTF_STYLE_NORMAL)) {
334 TTF_SetFontStyle(pstr->
font, TTF_STYLE_NORMAL);
345 SDL_Rect des = {0, 0, 0, 0};
346 SDL_Surface *text = NULL, **tmp = NULL;
347 Uint16 i, w = 0,
count = 0;
349 char *buf = pstr->
text;
352 while (utf8_texts[
count]) {
358 for (i = 0; i <
count; i++) {
359 pstr->
text = utf8_texts[i];
372 if (SDL_GetColorKey(tmp[0], &
color) < 0) {
373 color = SDL_MapRGBA(tmp[0]->format, 0, 0, 0, 0);
379 SDL_FillRect(text, NULL,
color);
380 SDL_SetColorKey(text, SDL_TRUE,
color);
384 w,
count * tmp[0]->h, tmp[0]->flags);
385 SDL_FillRect(text, NULL,
color);
389 SDL_FillRect(text, NULL,
color);
394 for (i = 0; i <
count; i++) {
396 des.x = (w - tmp[i]->w) / 2;
399 des.x = w - tmp[i]->w;
405 alphablit(tmp[i], NULL, text, &des, 255);
411 for (i = 0; i <
count; i++) {
427 if (pstr != NULL && pstr->
text != NULL) {
428 char *current = pstr->
text;
429 char c = *(pstr->
text);
452 bool converted =
FALSE;
462 char *ptr_rev, *ptr = pstr->
text;
483 utf8char[0] = ptr[0];
484 for (i = 1; i < 8 && (ptr[i] & (128 + 64)) == 128; i++) {
485 utf8char[i] = ptr[i];
488 if (!((pstr->
style & 0x0F) & TTF_STYLE_NORMAL)) {
489 TTF_SetFontStyle(pstr->
font, (pstr->
style & 0x0F));
491 TTF_SizeUTF8(pstr->
font, utf8char, &fw, &fh);
492 if (!((pstr->
style & 0x0F) & TTF_STYLE_NORMAL)) {
493 TTF_SetFontStyle(pstr->
font, TTF_STYLE_NORMAL);
500 while (ptr_rev != pstr->
text) {
501 if (*ptr_rev ==
' ') {
507 if (*ptr_rev ==
'\n') {
513 if (ptr_rev == pstr->
text) {
524 log_error(
"Can't convert string to const width");
563 if (new_ptsize == 0) {
567 if (pstr->
ptsize == new_ptsize) {
571 if ((buf =
load_font(new_ptsize)) == NULL) {
572 log_error(
"change_ptsize: load_font() failed");
577 pstr->
ptsize = new_ptsize;
597 TTF_Font *font_tmp = NULL;
602 while (font_tab_tmp != NULL) {
604 font_tab_tmp->
count++;
606 return font_tab_tmp->
font;
609 font_tab_tmp = font_tab_tmp->
next;
622 log_error(
"load_font: Couldn't load %d pt font from %s: %s",
634 while (font_tab_tmp->
next) {
635 font_tab_tmp = font_tab_tmp->
next;
639 font_tab_tmp = font_tab_tmp->
next;
643 font_tab_tmp->
count = 1;
644 font_tab_tmp->
font = font_tmp;
645 font_tab_tmp->
next = NULL;
659 log_error(
"unload_font: Trying unload from empty Font ARRAY");
663 while (font_tab_tmp != NULL) {
667 font_tab_prev = font_tab_tmp;
668 font_tab_tmp = font_tab_tmp->
next;
671 if (font_tab_tmp == NULL) {
672 log_error(
"unload_font: Trying unload Font which is "
673 "not included in Font ARRAY");
677 if (--font_tab_tmp->
count > 0) {
681 TTF_CloseFont(font_tab_tmp->
font);
682 font_tab_tmp->
font = NULL;
684 if (font_tab_prev == NULL) {
687 font_tab_prev->
next = font_tab_tmp->
next;
690 font_tab_tmp->
next = NULL;
707 if (font_tab_tmp->
font) {
708 TTF_CloseFont(font_tab_tmp->
font);
struct canvas int int struct sprite int int int width
SDL_Color * get_theme_color(enum theme_color themecolor)
SDL_Surface * create_surf_with_format(SDL_PixelFormat *pf, int width, int height, Uint32 flags)
int alphablit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect, unsigned char alpha_mod)
SDL_Surface * create_surf(int width, int height, Uint32 flags)
static TTF_Font * load_font(Uint16 ptsize)
void change_ptsize_utf8(utf8_str *pstr, Uint16 new_ptsize)
void utf8_str_size(utf8_str *pstr, SDL_Rect *fill)
utf8_str * copy_chars_to_utf8_str(utf8_str *pstr, const char *pchars)
SDL_Surface * create_text_surf_from_utf8(utf8_str *pstr)
void change_fonto_utf8(utf8_str *pstr, enum font_origin origin)
static char * font_with_full_path
void unload_font(Uint16 ptsize)
utf8_str * create_utf8_str(char *in_text, size_t n_alloc, Uint16 ptsize)
utf8_str * create_utf8_str_fonto(char *in_text, size_t n_alloc, enum font_origin origin)
static struct ttf_font_chain * font_tab
int write_utf8(SDL_Surface *dest, Sint16 x, Sint16 y, utf8_str *pstr)
static SDL_Surface * create_utf8_multi_surf(utf8_str *pstr)
bool convert_utf8_str_to_const_surface_width(utf8_str *pstr, int width)
static SDL_Surface * create_utf8_surf(utf8_str *pstr)
void free_font_system(void)
SDL_Surface * create_text_surf_smaller_than_w(utf8_str *pstr, int w)
static Uint16 fonto_ptsize(enum font_origin origin)
#define fc_assert_ret_val(condition, val)
#define log_debug(message,...)
#define log_error(message,...)
#define fc_calloc(n, esz)
#define fc_realloc(ptr, sz)
struct ttf_font_chain * next
int fc_snprintf(char *str, size_t n, const char *format,...)
const char * theme_font_filename(const struct theme *t)
struct theme * active_theme
char ** create_new_line_utf8strs(const char *pstr)