[Top][All Lists]
[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 00:49:04 -0500 |
CVSROOT: /cvsroot/wesnoth
Module name: wesnoth
Branch:
Changes by: Jon Daniel <address@hidden> 05/03/04 05:49:04
Modified files:
src : font.cpp
Log message:
* changed text_chunk to store utf8 and ucs2 versions of the text
* cleaned up split text and updated it to fill ucs2 values too
* minor changes to measure_ucs2_text_line
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/font.cpp.diff?tr1=1.110&tr2=1.111&r1=text&r2=text
Patches:
Index: wesnoth/src/font.cpp
diff -u wesnoth/src/font.cpp:1.110 wesnoth/src/font.cpp:1.111
--- wesnoth/src/font.cpp:1.110 Fri Mar 4 04:26:15 2005
+++ wesnoth/src/font.cpp Fri Mar 4 05:49:04 2005
@@ -1,4 +1,4 @@
-/* $Id: font.cpp,v 1.110 2005/03/04 04:26:15 j_daniel Exp $ */
+/* $Id: font.cpp,v 1.111 2005/03/04 05:49:04 j_daniel Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -65,50 +65,39 @@
struct text_chunk
{
- text_chunk(subset_id subset, const std::string& text) : subset(subset),
text(text) {};
-
+ text_chunk(subset_id subset) : subset(subset) {}
+ text_chunk(subset_id subset, std::string const & text) :
subset(subset), text(text) {}
+ text_chunk(subset_id subset, ucs2_string const & ucs2_text) :
subset(subset), ucs2_text(ucs2_text) {}
+ text_chunk(subset_id subset, std::string const & text, ucs2_string
const & ucs2_text) : subset(subset), text(text), ucs2_text(ucs2_text) {}
subset_id subset;
std::string text;
+ ucs2_string ucs2_text;
};
std::vector<subset_id> font_map;
-//Splits the UTF-8 text into chunks of UTF-8 text using the same font.
-//Converts UTF-8 bytes into one wchar_t at a time and gets the subset
-//id for it. The correspondending UTF-8 bytes then are appended to a
-//chunk.
-std::vector<text_chunk> split_text(const std::string& utf8_text) {
- bool first = true;
- int current_font = 0;
- std::string current_chunk;
+//Splits the UTF-8 text into text_chunks using the same font.
+std::vector<text_chunk> split_text(std::string const & utf8_text) {
+ text_chunk current_chunk(0);
std::vector<text_chunk> chunks;
try {
- //size_t i = 0;
- for(utils::utf8_iterator ch(utf8_text); ch !=
utils::utf8_iterator::end(utf8_text); ++ch) {
-
- if(first) {
- if(*ch < font_map.size() && font_map[*ch] >= 0)
{
- current_font = font_map[*ch];
- } else {
- current_font = 0;
- }
- first = false;
- }
-
- if(*ch >= font_map.size() || font_map[*ch] < 0) {
- current_chunk.append(ch.substr().first,
ch.substr().second);
- } else if(font_map[*ch] == current_font) {
- current_chunk.append(ch.substr().first,
ch.substr().second);
- } else {
- chunks.push_back(text_chunk(current_font,
current_chunk));
- current_chunk.clear();
- current_chunk.append(ch.substr().first,
ch.substr().second);
- current_font = font_map[*ch];
+ utils::utf8_iterator ch(utf8_text);
+ if(*ch < font_map.size() && font_map[*ch] >= 0) {
+ current_chunk.subset = font_map[*ch];
+ }
+ for(; ch != utils::utf8_iterator::end(utf8_text); ++ch) {
+ if(*ch < font_map.size() && font_map[*ch] >= 0 &&
font_map[*ch] != current_chunk.subset) {
+ chunks.push_back(current_chunk);
+ current_chunk.text.clear();
+ current_chunk.ucs2_text.clear();
+ current_chunk.subset = font_map[*ch];
}
+ current_chunk.ucs2_text.push_back((Uint16)*ch);
+ current_chunk.text.append(ch.substr().first,
ch.substr().second);
}
- if (!current_chunk.empty()) {
- chunks.push_back(text_chunk(current_font,
current_chunk));
+ if (!current_chunk.text.empty()) {
+ chunks.push_back(current_chunk);
}
}
catch(utils::invalid_utf8_exception e) {
@@ -612,7 +601,7 @@
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.h = maximum<Sint16>(rect.h, rect.y);
chunk.clear();
current_font = font_map[*first];
}
@@ -620,11 +609,16 @@
}
if (!chunk.empty()) {
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);
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.h = maximum<Sint16>(rect.h, rect.y);
}
rect.x = 0;
rect.y = 0;
- [Wesnoth-cvs-commits] wesnoth/src font.cpp, Philippe Plantier, 2005/03/01
- [Wesnoth-cvs-commits] wesnoth/src font.cpp,
Jon Daniel <=
- [Wesnoth-cvs-commits] wesnoth/src font.cpp, Jon Daniel, 2005/03/04
- [Wesnoth-cvs-commits] wesnoth/src font.cpp, Jon Daniel, 2005/03/04
- [Wesnoth-cvs-commits] wesnoth/src font.cpp, Jon Daniel, 2005/03/04
- [Wesnoth-cvs-commits] wesnoth/src font.cpp, Jon Daniel, 2005/03/04
- [Wesnoth-cvs-commits] wesnoth/src font.cpp, David White, 2005/03/07