wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src font.cpp


From: Jon Daniel
Subject: [Wesnoth-cvs-commits] wesnoth/src font.cpp
Date: Fri, 04 Mar 2005 11:52:08 -0500

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Jon Daniel <address@hidden>     05/03/04 16:52:07

Modified files:
        src            : font.cpp 

Log message:
        updated measure_ucs2_text_line

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/font.cpp.diff?tr1=1.113&tr2=1.114&r1=text&r2=text

Patches:
Index: wesnoth/src/font.cpp
diff -u wesnoth/src/font.cpp:1.113 wesnoth/src/font.cpp:1.114
--- wesnoth/src/font.cpp:1.113  Fri Mar  4 12:34:37 2005
+++ wesnoth/src/font.cpp        Fri Mar  4 16:52:07 2005
@@ -1,4 +1,4 @@
-/* $Id: font.cpp,v 1.113 2005/03/04 12:34:37 j_daniel Exp $ */
+/* $Id: font.cpp,v 1.114 2005/03/04 16:52:07 j_daniel Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -577,52 +577,73 @@
        return render_text(str, size, colour, style);
 }
 
-//measure a single line of ucs2 text with a specific font_size and style
-//without newline chars.
+//Measure a single line of ucs2 text with a specific font_size and
+//style without newline chars.
+//
+//This is INSECURE with lines which are WIDER than UINT16_MAX pixels.
+//
+//It is intended for the command_line widget only which has a line
+//length restriction and small font size.
 SDL_Rect measure_ucs2_text_line(ucs2_string::const_iterator first, 
ucs2_string::const_iterator last, int font_size, int style) {
        wassert(last - first >= 0);
-
-       ucs2_string chunk((last - first ) + 2);
-
+       
        SDL_Rect rect;
        rect.w = 0;
        rect.h = 0;
+
+       ucs2_string chunk((last - first ) + 2);
+       ucs2_string::iterator chunk_itor = chunk.begin();
+       *chunk_itor = 0;
+
        int current_font = 0;
 
+       //set the font for the first char
        if(*first < font_map.size() && font_map[*first] >= 0) {
                current_font = font_map[*first];
-       }       
-
+       }
+       
        for(;first != last; ++first) {
                if(*first < font_map.size() && font_map[*first] >= 0 && 
font_map[*first] != current_font) {
                        TTF_Font* ttfont = get_font(font_id(current_font, 
font_size));
                        if(ttfont == NULL) {
-                               chunk.clear();
+                               chunk_itor = chunk.begin();
+                               *(chunk_itor++) = *first;
+                               current_font = font_map[*first];
                                continue;
                        }
-                       chunk.push_back(0);
+                       *(chunk_itor++) = 0;
+                       
                        font_style_setter const style_setter(ttfont, style);
+
                        TTF_SizeUNICODE(ttfont, (Uint16 const *)&chunk.front(), 
(int*)&rect.x, (int*)&rect.y);
+
                        rect.w += rect.x;
                        rect.h = maximum<Sint16>(rect.h, rect.y);
-                       chunk.clear();
+                       
+                       chunk_itor = chunk.begin();
+                       
                        current_font = font_map[*first];
                }
-               chunk.push_back(*first);
+               *(chunk_itor++) = *first;
        }
-       if (!chunk.empty()) {
+       if (chunk_itor != chunk.begin()) {
                TTF_Font* ttfont = get_font(font_id(current_font, font_size));
                if(ttfont == NULL) {
                        rect.x = 0;
                        rect.y = 0;
                        return rect;
                }
-               chunk.push_back(0);
+               *(chunk_itor++) = 0;
+
                font_style_setter const style_setter(ttfont, style);
+
                TTF_SizeUNICODE(ttfont, (Uint16 const *)&chunk.front(), 
(int*)&rect.x, (int*)&rect.y);
+
                rect.w += rect.x;
                rect.h = maximum<Sint16>(rect.h, rect.y);
        }
+       //reset rect.x and rec.y because we abused it to store the area
+       //of the last chunk
        rect.x = 0;
        rect.y = 0;
        return rect;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]