From: Ondřej Hošek Date: Fri, 13 May 2005 05:13:30 +0000 (+0000) Subject: * From now on, there is UTF-8 decoding in the Font class. It should support all chara... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=df735aa09e4aee204c4004488276df236803f814;p=supertux.git * From now on, there is UTF-8 decoding in the Font class. It should support all characters we have in the font files until now. * Fixed some errors in cs.po * Ignored any .mo file from SVN, since programs like poEdit generate them and tinygettext simply parses .po files SVN-Revision: 2477 --- diff --git a/data/locale/cs.po b/data/locale/cs.po index ec7cbbad7..0e6eb72da 100644 --- a/data/locale/cs.po +++ b/data/locale/cs.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: SuperTux 0.2\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2005-05-11 20:00+0100\n" +"PO-Revision-Date: 2005-05-12 20:08+0100\n" "Last-Translator: Ondřej HoÅ¡ek \n" "Language-Team: Czech\n" "MIME-Version: 1.0\n" @@ -70,7 +70,7 @@ msgid "" "redistribute it under certain conditions; see the file COPYING for details.\n" msgstr "" "Copyright (c) 2005 Tým vývojářů SuperTuxu\n" -"Tato hra přichází BEZ JAKÉKOLIV ZÁRUKY.Tento program je volný software, smíš jej\n" +"Tato hra přichází BEZ JAKÉKOLIV ZÁRUKY. Tento program je volný software, smíš jej\n" "distribuovat dle pokynů v souboru COPYING.\n" #: src/title.cpp:402 @@ -137,17 +137,17 @@ msgstr "Nejvyšší skóré: %d" #: src/statistics.cpp:174 #, c-format msgid "Max coins collected: %d / %d" -msgstr "Nejvíce sesbíraných mincí: %d / %d" +msgstr "Nejvíce mincí: %d / %d" #: src/statistics.cpp:178 #, c-format msgid "Max fragging: %d / %d" -msgstr "Nejvíce zneÅ¡kodněných protivníků: %d / %d" +msgstr "Nejvíce zneÅ¡kod. protivníků: %d / %d" #: src/statistics.cpp:182 #, c-format msgid "Min time needed: %d / %d" -msgstr "Nejméně upotřebeného času: %d / %d" +msgstr "Nejméně upotřebeného času: %d / %d" #: src/misc.cpp:79 #: src/misc.cpp:98 diff --git a/src/main.cpp b/src/main.cpp index a48b3f4f4..1ce98bc05 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -133,7 +133,7 @@ static void find_directories() static void init_tinygettext() { dictionary_manager.add_directory(datadir + "/locale"); - dictionary_manager.set_charset("ISO8859-1"); + dictionary_manager.set_charset("UTF-8"); } static void print_usage(const char* argv0) diff --git a/src/video/font.cpp b/src/video/font.cpp index bdcd54102..90a319e5b 100644 --- a/src/video/font.cpp +++ b/src/video/font.cpp @@ -45,7 +45,7 @@ Font::Font(const std::string& file, FontType ntype, int nw, int nh, break; } last_char = first_char + (chars->h / h) * 16; - if(last_char > 127) // we have left out some control chars at 128-159 + if(last_char > 127 && last_char < 160) // we have left out some control chars at 128-159 last_char += 32; // Load shadow font. @@ -88,6 +88,10 @@ Font::get_text_width(const std::string& text) const if(hl == 0) hl = text.size(); + for (uint i = 0; i < text.size(); i++) + if ((unsigned char) text[i] > 0xC2 && (unsigned char) text[i] < 0xC6) + hl--; // control characters are a WASTE. + return hl * w; } @@ -166,12 +170,54 @@ Font::draw_chars(Surface* pchars, const std::string& text, const Vector& pos, uint32_t drawing_effect, uint8_t alpha) const { SurfaceImpl* impl = pchars->impl; + int utf8suppl = 0; Vector p = pos; for(size_t i = 0; i < text.size(); ++i) { int c = (unsigned char) text[i]; - if(c > 127) // correct for the 32 controlchars at 128-159 + int d = 0; + if(c > 127 && c < 160) // correct for the 32 controlchars at 128-159 c -= 32; + if (c > 0xC2 && text.size() == i+1) // string ends with control char + { + std::cerr << "String \"" << text << "\" is malformed.\n"; + return; + } + else + d = (unsigned char) text[i+1]; + + if (c == 0xC3 && d < 160) // first-byte identifier of U0080 ("C1 Control Characters and Latin-1 Supplement") + { // iso-8859-1 equiv character is capital A with tilde above, signified as "C3 83" in utf-8 + utf8suppl = 64; + continue; + } + else if (c == 0xC3 && d >= 160) // U0080 pt. 2 + { + utf8suppl = 32; + continue; + } + else if (c == 0xC4 && d < 160) + { + utf8suppl = 128; + continue; + } + else if (c == 0xC4 && d >= 160) + { + utf8suppl = 96; + continue; + } + else if (c == 0xC5 && d < 160) // first-byte identifier of U0100 ("Latin Extended-A") + { // iso-8859-1 equiv character is capital A with ring above, signified as "C3 85" in utf-8 + utf8suppl = 192; + continue; + } + else if (c == 0xC5 && d >= 160) // first-byte identifier of U0100 ("Latin Extended-A") + { // iso-8859-1 equiv character is capital A with ring above, signified as "C3 85" in utf-8 + utf8suppl = 160; + continue; + } + // insert more clauses here once somebody will need them + // a non-printable character? if(c == '\n') { p.x = pos.x; @@ -182,6 +228,9 @@ Font::draw_chars(Surface* pchars, const std::string& text, const Vector& pos, p.x += w; continue; } + + c += utf8suppl; + utf8suppl = 0; int index = c - first_char; int source_x = (index % 16) * w;