Author: cazfi Date: Thu Jan 29 05:16:58 2015 New Revision: 27889 URL: http://svn.gna.org/viewcvs/freeciv?rev=27889&view=rev Log: Fixed sdl2-client constant width surface creation to handle UTF-8 correctly.
See patch #5750 Modified: trunk/client/gui-sdl2/gui_string.c Modified: trunk/client/gui-sdl2/gui_string.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/gui_string.c?rev=27889&r1=27888&r2=27889&view=diff ============================================================================== --- trunk/client/gui-sdl2/gui_string.c (original) +++ trunk/client/gui-sdl2/gui_string.c Thu Jan 29 05:16:58 2015 @@ -844,7 +844,7 @@ Wrap text to make it fit to given screen width. **************************************************************************/ bool convert_utf8_str_to_const_surface_width(utf8_str *pstr, int width) -{ +{ int w; bool converted = FALSE; @@ -855,13 +855,16 @@ if (w > width) { /* cut string length to w length by replacing space " " with new line "\n" */ bool resize = FALSE; - int len = 0, adv; + int len = 0; char *ptr_rev, *ptr = pstr->text; converted = TRUE; do { if (!resize) { + char utf8char[9]; + int i; + int fw, fh; if (*ptr == '\0') { resize = TRUE; @@ -874,15 +877,20 @@ continue; } + utf8char[0] = ptr[0]; + for (i = 1; i < 8 && (ptr[i] & (128 + 64)) == 128; i++) { + utf8char[i] = ptr[i]; + } + utf8char[i] = '\0'; if (!((pstr->style & 0x0F) & TTF_STYLE_NORMAL)) { TTF_SetFontStyle(pstr->font, (pstr->style & 0x0F)); } - TTF_GlyphMetrics(pstr->font, *ptr, NULL, NULL, NULL, NULL, &adv); + TTF_SizeUTF8(pstr->font, utf8char, &fw, &fh); if (!((pstr->style & 0x0F) & TTF_STYLE_NORMAL)) { TTF_SetFontStyle(pstr->font, TTF_STYLE_NORMAL); } - len += adv; + len += fw; if (len > width) { ptr_rev = ptr; @@ -904,7 +912,7 @@ } } - ptr++; + ptr += i; } else { if (pstr->ptsize > 8) { change_ptsize_utf8(pstr, pstr->ptsize - 1); @@ -913,7 +921,7 @@ log_error("Can't convert string to const width"); break; } - } + } } while (w > width); } _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits