Author: cazfi Date: Tue Aug 25 18:52:36 2015 New Revision: 29676 URL: http://svn.gna.org/viewcvs/freeciv?rev=29676&view=rev Log: Replaced string16 uses with utf8_str use in sdl2-client canvas.c
See patch #6280 Modified: branches/S2_6/client/gui-sdl2/canvas.c branches/S2_6/client/gui-sdl2/gui_string.c branches/S2_6/client/gui-sdl2/gui_string.h branches/S2_6/client/gui-sdl2/messagewin.c branches/S2_6/client/gui-sdl2/widget_button.c branches/S2_6/client/gui-sdl2/widget_combo.c branches/S2_6/client/gui-sdl2/widget_edit.c branches/S2_6/client/gui-sdl2/widget_label.c branches/S2_6/client/gui-sdl2/widget_window.c Modified: branches/S2_6/client/gui-sdl2/canvas.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-sdl2/canvas.c?rev=29676&r1=29675&r2=29676&view=diff ============================================================================== --- branches/S2_6/client/gui-sdl2/canvas.c (original) +++ branches/S2_6/client/gui-sdl2/canvas.c Tue Aug 25 18:52:36 2015 @@ -186,18 +186,24 @@ ****************************************************************************/ void get_text_size(int *width, int *height, enum client_font font, const char *text) -{ - SDL_String16 *pText = create_string16(NULL, 0, *fonts[font]); - copy_chars_to_string16(pText, text); +{ + utf8_str *ptext = create_utf8_str(NULL, 0, *fonts[font]); + SDL_Rect size; + + fc_assert(width != NULL || height != NULL); + + copy_chars_to_utf8_str(ptext, text); + utf8_str_size(ptext, &size); if (width) { - *width = str16size(pText).w; + *width = size.w; } + if (height) { - *height = str16size(pText).h; + *height = size.h; } - FREESTRING16(pText); + FREEUTF8STR(ptext); } /**************************************************************************** @@ -209,17 +215,18 @@ enum client_font font, struct color *pcolor, const char *text) { - SDL_Surface *pTmp; - SDL_String16 *pText = create_string16(NULL, 0, *fonts[font]); - copy_chars_to_string16(pText, text); - - pText->fgcol = *pcolor->color; - pText->bgcol = (SDL_Color) {0, 0, 0, 0}; - - pTmp = create_text_surf_from_str16(pText); - - blit_entire_src(pTmp, pcanvas->surf, canvas_x, canvas_y); - - FREESTRING16(pText); - FREESURFACE(pTmp); -} + SDL_Surface *ptmp; + utf8_str *ptext = create_utf8_str(NULL, 0, *fonts[font]); + + copy_chars_to_utf8_str(ptext, text); + + ptext->fgcol = *pcolor->color; + ptext->bgcol = (SDL_Color) {0, 0, 0, 0}; + + ptmp = create_text_surf_from_utf8(ptext); + + blit_entire_src(ptmp, pcanvas->surf, canvas_x, canvas_y); + + FREEUTF8STR(ptext); + FREESURFACE(ptmp); +} Modified: branches/S2_6/client/gui-sdl2/gui_string.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-sdl2/gui_string.c?rev=29676&r1=29675&r2=29676&view=diff ============================================================================== --- branches/S2_6/client/gui-sdl2/gui_string.c (original) +++ branches/S2_6/client/gui-sdl2/gui_string.c Tue Aug 25 18:52:36 2015 @@ -160,10 +160,8 @@ /************************************************************************** Calculate display size of string. **************************************************************************/ -SDL_Rect utf8_str_size(utf8_str *pstr) -{ - SDL_Rect ret = {0, 0, 0, 0}; - +void utf8_str_size(utf8_str *pstr, SDL_Rect *fill) +{ if (pstr != NULL && pstr->text != NULL && pstr->text != '\0') { char *current = pstr->text; char c = *current; @@ -213,13 +211,11 @@ TTF_SetFontStyle(pstr->font, TTF_STYLE_NORMAL); } - ret.w = w; - ret.h = h; + fill->w = w; + fill->h = h; } else { - ret.h = (pstr ? TTF_FontHeight(pstr->font) : 0); - } - - return ret; + fill->h = (pstr ? TTF_FontHeight(pstr->font) : 0); + } } /************************************************************************** @@ -845,14 +841,14 @@ **************************************************************************/ bool convert_utf8_str_to_const_surface_width(utf8_str *pstr, int width) { - int w; + SDL_Rect size; bool converted = FALSE; fc_assert_ret_val(pstr != NULL, FALSE); fc_assert_ret_val(pstr->text != NULL, FALSE); - w = utf8_str_size(pstr).w; - if (w > width) { + utf8_str_size(pstr, &size); + if (size.w > width) { /* cut string length to w length by replacing space " " with new line "\n" */ bool resize = FALSE; int len = 0; @@ -897,7 +893,7 @@ while (ptr_rev != pstr->text) { if (*ptr_rev == ' ') { *ptr_rev = '\n'; - w = utf8_str_size(pstr).w; + utf8_str_size(pstr, &size); len = 0; break; } @@ -916,14 +912,14 @@ } else { if (pstr->ptsize > 8) { change_ptsize_utf8(pstr, pstr->ptsize - 1); - w = utf8_str_size(pstr).w; + utf8_str_size(pstr, &size); } else { log_error("Can't convert string to const width"); break; } } - } while (w > width); + } while (size.w > width); } return converted; Modified: branches/S2_6/client/gui-sdl2/gui_string.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-sdl2/gui_string.h?rev=29676&r1=29675&r2=29676&view=diff ============================================================================== --- branches/S2_6/client/gui-sdl2/gui_string.h (original) +++ branches/S2_6/client/gui-sdl2/gui_string.h Tue Aug 25 18:52:36 2015 @@ -87,7 +87,7 @@ utf8_str *pstr); SDL_Surface *create_text_surf_from_utf8(utf8_str *pstr); SDL_Surface *create_text_surf_smaller_than_w(utf8_str *pstr, int w); -SDL_Rect utf8_str_size(utf8_str *pstr); +void utf8_str_size(utf8_str *pstr, SDL_Rect *fill); void change_ptsize_utf8(utf8_str *pstr, Uint16 new_ptsize); void unload_font(Uint16 ptsize); @@ -102,8 +102,6 @@ #define str16len(pString16) str16size(pString16).w #define str16height(pString16) str16size(pString16).h - -#define utf8_str_height(pstr) utf8_str_size(pstr).h /* * here we use ordinary free( ... ) because check is made Modified: branches/S2_6/client/gui-sdl2/messagewin.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-sdl2/messagewin.c?rev=29676&r1=29675&r2=29676&view=diff ============================================================================== --- branches/S2_6/client/gui-sdl2/messagewin.c (original) +++ branches/S2_6/client/gui-sdl2/messagewin.c Tue Aug 25 18:52:36 2015 @@ -240,6 +240,7 @@ struct widget *pWindow = NULL; SDL_Surface *pBackground; SDL_Rect area; + SDL_Rect size; if (pMsg_Dlg) { return; @@ -269,7 +270,8 @@ /* define content area */ area.w = (adj_size(520) - (pWindow->size.w - pWindow->area.w)); - area.h = (N_MSG_VIEW + 1) * utf8_str_height(pstr); + utf8_str_size(pstr, &size); + area.h = (N_MSG_VIEW + 1) * size.h; FREEUTF8STR(pstr); Modified: branches/S2_6/client/gui-sdl2/widget_button.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-sdl2/widget_button.c?rev=29676&r1=29675&r2=29676&view=diff ============================================================================== --- branches/S2_6/client/gui-sdl2/widget_button.c (original) +++ branches/S2_6/client/gui-sdl2/widget_button.c Tue Aug 25 18:52:36 2015 @@ -287,10 +287,10 @@ /* if BOLD == true then longest wight */ if (!(pstr->style & TTF_STYLE_BOLD)) { pstr->style |= TTF_STYLE_BOLD; - buf = utf8_str_size(pstr); + utf8_str_size(pstr, &buf); pstr->style &= ~TTF_STYLE_BOLD; } else { - buf = utf8_str_size(pstr); + utf8_str_size(pstr, &buf); } w = MAX(w, buf.w); Modified: branches/S2_6/client/gui-sdl2/widget_combo.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-sdl2/widget_combo.c?rev=29676&r1=29675&r2=29676&view=diff ============================================================================== --- branches/S2_6/client/gui-sdl2/widget_combo.c (original) +++ branches/S2_6/client/gui-sdl2/widget_combo.c Tue Aug 25 18:52:36 2015 @@ -252,7 +252,7 @@ if (NULL != pstr) { combo->string_utf8->style |= SF_CENTER; - buf = utf8_str_size(pstr); + utf8_str_size(pstr, &buf); buf.h += adj_size(4); } Modified: branches/S2_6/client/gui-sdl2/widget_edit.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-sdl2/widget_edit.c?rev=29676&r1=29675&r2=29676&view=diff ============================================================================== --- branches/S2_6/client/gui-sdl2/widget_edit.c (original) +++ branches/S2_6/client/gui-sdl2/widget_edit.c Tue Aug 25 18:52:36 2015 @@ -365,7 +365,7 @@ if (pstr != NULL) { pEdit->string_utf8->style |= SF_CENTER; - buf = utf8_str_size(pstr); + utf8_str_size(pstr, &buf); buf.h += adj_size(4); } Modified: branches/S2_6/client/gui-sdl2/widget_label.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-sdl2/widget_label.c?rev=29676&r1=29675&r2=29676&view=diff ============================================================================== --- branches/S2_6/client/gui-sdl2/widget_label.c (original) +++ branches/S2_6/client/gui-sdl2/widget_label.c Tue Aug 25 18:52:36 2015 @@ -134,7 +134,7 @@ text->style |= TTF_STYLE_BOLD; } - buf = utf8_str_size(text); + utf8_str_size(text, &buf); if (without_box && !bold) { text->style &= ~TTF_STYLE_BOLD; Modified: branches/S2_6/client/gui-sdl2/widget_window.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-sdl2/widget_window.c?rev=29676&r1=29675&r2=29676&view=diff ============================================================================== --- branches/S2_6/client/gui-sdl2/widget_window.c (original) +++ branches/S2_6/client/gui-sdl2/widget_window.c Tue Aug 25 18:52:36 2015 @@ -201,7 +201,9 @@ } if (title != NULL) { - SDL_Rect size = utf8_str_size(title); + SDL_Rect size; + + utf8_str_size(title, &size); w += size.w + adj_size(10); h += MAX(size.h, WINDOW_TITLE_HEIGHT + 1); _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits