[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Wesnoth-cvs-commits] wesnoth/src font.hpp font.cpp
From: |
Jon Daniel |
Subject: |
[Wesnoth-cvs-commits] wesnoth/src font.hpp font.cpp |
Date: |
Thu, 03 Mar 2005 23:26:15 -0500 |
CVSROOT: /cvsroot/wesnoth
Module name: wesnoth
Branch:
Changes by: Jon Daniel <address@hidden> 05/03/04 04:26:15
Modified files:
src : font.hpp font.cpp
Log message:
Added measure_ucs2_text_line function which retrieves the pixel width
annd height of the
range [first, last) in a specific font size and style.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/font.hpp.diff?tr1=1.49&tr2=1.50&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/font.cpp.diff?tr1=1.109&tr2=1.110&r1=text&r2=text
Patches:
Index: wesnoth/src/font.cpp
diff -u wesnoth/src/font.cpp:1.109 wesnoth/src/font.cpp:1.110
--- wesnoth/src/font.cpp:1.109 Thu Mar 3 21:52:39 2005
+++ wesnoth/src/font.cpp Fri Mar 4 04:26:15 2005
@@ -1,4 +1,4 @@
-/* $Id: font.cpp,v 1.109 2005/03/03 21:52:39 gruikya Exp $ */
+/* $Id: font.cpp,v 1.110 2005/03/04 04:26:15 j_daniel Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -24,6 +24,7 @@
#include "tooltips.hpp"
#include "util.hpp"
#include "serialization/string_utils.hpp"
+#include "wassert.hpp"
#include <algorithm>
#include <cstdio>
@@ -584,6 +585,53 @@
return render_text(str, size, colour, style);
}
+//measure a single line of ucs2 text with a specific font_size and style
+//without newline chars.
+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;
+ int current_font = 0;
+
+ 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();
+ continue;
+ }
+ chunk.push_back(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<int>(rect.h, rect.y);
+ chunk.clear();
+ current_font = font_map[*first];
+ }
+ chunk.push_back(*first);
+ }
+ if (!chunk.empty()) {
+ TTF_Font* ttfont = get_font(font_id(current_font, font_size));
+ chunk.push_back(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<int>(rect.h, rect.y);
+ }
+ rect.x = 0;
+ rect.y = 0;
+ return rect;
+}
+
+
SDL_Rect draw_text_line(surface gui_surface, const SDL_Rect& area, int size,
const SDL_Color& colour, const std::string& text,
int x, int y, bool use_tooltips, int style)
Index: wesnoth/src/font.hpp
diff -u wesnoth/src/font.hpp:1.49 wesnoth/src/font.hpp:1.50
--- wesnoth/src/font.hpp:1.49 Sat Feb 26 18:52:24 2005
+++ wesnoth/src/font.hpp Fri Mar 4 04:26:15 2005
@@ -1,4 +1,4 @@
-/* $Id: font.hpp,v 1.49 2005/02/26 18:52:24 gruikya Exp $ */
+/* $Id: font.hpp,v 1.50 2005/03/04 04:26:15 j_daniel Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -95,7 +95,10 @@
// Returns a SDL surface containing the text rendered in a given colour.
surface get_rendered_text(const std::string& text, int size, const SDL_Color&
colour, int style=0);
-
+
+//measures the width and height of a single ucs2 text line
+SDL_Rect measure_ucs2_text_line(ucs2_string::const_iterator first,
ucs2_string::const_iterator last, int font_size = SIZE_NORMAL, int style =
TTF_STYLE_NORMAL);
+
// Returns the maximum height of a font, in pixels
int get_max_height(int size);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Wesnoth-cvs-commits] wesnoth/src font.hpp font.cpp,
Jon Daniel <=