Author: alink
Date: Sun Mar 29 00:03:46 2009
New Revision: 34217
URL: http://svn.gna.org/viewcvs/wesnoth?rev=34217&view=rev
Log:
Apply patch #1140 (Fixed line wrap for CJK languages) from sylecn
Modified:
trunk/changelog
trunk/data/core/about.cfg
trunk/src/help.cpp
trunk/src/marked-up_text.cpp
trunk/src/marked-up_text.hpp
Modified: trunk/changelog
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/changelog?rev=34217&r1=34216&r2=34217&view=diff
==============================================================================
--- trunk/changelog (original)
+++ trunk/changelog Sun Mar 29 00:03:46 2009
@@ -17,6 +17,8 @@
* new translations: Icelandic
* updated translations: British English, Catalan, Chinese (Simplified),
German, Finnish, Hebrew, Italian, Russian, Slovak, Turkish
+ * Updated CJK character range
+ * Fixed word wrapping in CJK languages (patch #1140 from sylecn)
* AI:
* Fixed incorrect handling of poisoning attacks when suggesting best attack
in user interface
Modified: trunk/data/core/about.cfg
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/core/about.cfg?rev=34217&r1=34216&r2=34217&view=diff
==============================================================================
--- trunk/data/core/about.cfg (original)
+++ trunk/data/core/about.cfg Sun Mar 29 00:03:46 2009
@@ -889,6 +889,10 @@
name = "Stéphane Gimenez (gim)"
[/entry]
[entry]
+ name = "sylecn"
+ email = "sylecn_AT_gmail.com"
+ [/entry]
+ [entry]
name = "Thomas Prevost (zancdar)"
email = "thomas.prevost_AT_gmail.com"
[/entry]
@@ -1064,6 +1068,7 @@
[/entry]
[entry]
name = "sylecn"
+ email = "sylecn_AT_gmail.com"
[/entry]
[entry]
name = "Teamzhangmeng"
Modified: trunk/src/help.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/help.cpp?rev=34217&r1=34216&r2=34217&view=diff
==============================================================================
--- trunk/src/help.cpp (original)
+++ trunk/src/help.cpp Sun Mar 29 00:03:46 2009
@@ -2995,7 +2995,19 @@
// This word is '\n'.
first_word_end = first_word_start+1;
}
- return s.substr(0, first_word_end);
+
+ //if no gap(' ' or '\n') found, test if it is CJK character
+ std::string re = s.substr(0, first_word_end);
+
+ utils::utf8_iterator ch(re);
+ if (ch == utils::utf8_iterator::end(re))
+ return re;
+
+ wchar_t firstchar = *ch;
+ if (font::is_cjk_char(firstchar)) {
+ re = utils::wchar_to_string(firstchar);
+ }
+ return re;
}
/**
Modified: trunk/src/marked-up_text.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/marked-up_text.cpp?rev=34217&r1=34216&r2=34217&view=diff
==============================================================================
--- trunk/src/marked-up_text.cpp (original)
+++ trunk/src/marked-up_text.cpp Sun Mar 29 00:03:46 2009
@@ -242,6 +242,39 @@
}
}
+bool is_cjk_char(const wchar_t ch)
+{
+ /**
+ * You can check these range at http://unicode.org/charts/
+ * see the "East Asian Scripts" part.
+ * Notice that not all characters in that part is still in use today,
so don't list them all here.
+ * Below are characters that I guess may be used in wesnoth
translations.
+ */
+
+ //FIXME add range from Japanese-specific and Korean-specific section if
you know the characters are used today.
+ return
+ //Han Ideographs: all except Supplement
+ (ch >= 0x4e00 && ch < 0x9fcf) ||
+ (ch >= 0x3400 && ch < 0x4dbf) ||
+ (ch >= 0x20000 && ch < 0x2a6df) ||
+ (ch >= 0xf900 && ch < 0xfaff) ||
+ (ch >= 0x3190 && ch < 0x319f) ||
+
+ //Radicals: all except Ideographic Description
+ (ch >= 0x2e80 && ch < 0x2eff) ||
+ (ch >= 0x2f00 && ch < 0x2fdf) ||
+ (ch >= 0x31c0 && ch < 0x31ef) ||
+
+ //Chinese-specific: Bopomofo
+ (ch >= 0x3000 && ch < 0x303f) ||
+
+ //Japanese-specific: Halfwidth Katakana
+ (ch >= 0xff00 && ch < 0xffef) ||
+
+ //Korean-specific: Hangul Syllables, Halfwidth Jamo
+ (ch >= 0xac00 && ch < 0xd7af) ||
+ (ch >= 0xff00 && ch < 0xffef);
+}
static void cut_word(std::string& line, std::string& word, int font_size, int
style, int max_width)
{
std::string tmp = line;
@@ -276,19 +309,41 @@
*
* * the following characters cannot end a line (so we will never break after
them):
* ï¼ãï¼»ï½ãããããââ
+ *
+ * Unicode range that concerns word wrap for Chinese:
+ * å
¨è§ASCIIãå
¨è§ä¸è±ææ ç¹ (Fullwidth Character for ASCII,
English punctuations and part of Chinese punctuations)
+ * http://www.unicode.org/charts/PDF/UFF00.pdf
+ * CJK æ ç¹ç¬¦å· (CJK punctuations)
+ * http://www.unicode.org/charts/PDF/U3000.pdf
*/
-inline bool no_break_after(wchar_t ch)
+inline bool no_break_after(const wchar_t ch)
{
return
+ /**
+ * don't break after these Japanese characters
+ */
ch == 0x2018 || ch == 0x201c || ch == 0x3008 || ch == 0x300a ||
ch == 0x300c ||
ch == 0x300e || ch == 0x3010 || ch == 0x3014 || ch == 0xff08 ||
ch == 0xff3b ||
- ch == 0xff5b;
-
-}
-
-inline bool no_break_before(wchar_t ch)
+ ch == 0xff5b ||
+
+ /**
+ * FIXME don't break after these Korean characters
+ */
+
+ /**
+ * don't break after these Chinese characters
+ * contains left side of different kinds of brackets and quotes
+ */
+ ch == 0x3014 || ch == 0x3016 || ch == 0x3008 || ch == 0x301a ||
ch == 0x3008 ||
+ ch == 0x300a || ch == 0x300c || ch == 0x300e || ch == 0x3010 ||
ch == 0x301d;
+}
+
+inline bool no_break_before(const wchar_t ch)
{
return
+ /**
+ * don't break before these Japanese characters
+ */
ch == 0x2019 || ch == 0x201d || ch == 0x2026 || ch == 0x3001 ||
ch == 0x3002 ||
ch == 0x3005 || ch == 0x3009 || ch == 0x300b || ch == 0x300d ||
ch == 0x300f ||
ch == 0x3011 || ch == 0x3015 || ch == 0x3041 || ch == 0x3043 ||
ch == 0x3045 ||
@@ -298,31 +353,39 @@
ch == 0x30e3 || ch == 0x30e5 || ch == 0x30e7 || ch == 0x30ee ||
ch == 0x30f5 ||
ch == 0x30f6 || ch == 0x30fb || ch == 0x30fc || ch == 0x30fd ||
ch == 0x30fe ||
ch == 0xff01 || ch == 0xff09 || ch == 0xff0c || ch == 0xff0e ||
ch == 0xff1a ||
- ch == 0xff1b || ch == 0xff1f || ch == 0xff3d || ch == 0xff5d;
-}
-
-inline bool break_before(wchar_t ch)
+ ch == 0xff1b || ch == 0xff1f || ch == 0xff3d || ch == 0xff5d ||
+
+ /**
+ * FIXME don't break before these Korean characters
+ */
+
+ /**
+ * don't break before these Chinese characters
+ * contains
+ * many Chinese punctuations that should not start a line
+ * and right side of different kinds of brackets, quotes
+ */
+ ch == 0x3001 || ch == 0x3002 || ch == 0x301c || ch == 0xff01 ||
ch == 0xff0c ||
+ ch == 0xff0d || ch == 0xff0e || ch == 0xff1a || ch == 0xff1b ||
ch == 0xff1f ||
+ ch == 0xff64 || ch == 0xff65 || ch == 0x3015 || ch == 0x3017 ||
ch == 0x3009 ||
+ ch == 0x301b || ch == 0x3009 || ch == 0x300b || ch == 0x300d ||
ch == 0x300f ||
+ ch == 0x3011 || ch == 0x301e;
+}
+
+inline bool break_before(const wchar_t ch)
{
if(no_break_before(ch))
return false;
- return ch == ' ' ||
- // CKJ characters
- (ch >= 0x3000 && ch < 0xa000) ||
- (ch >= 0xf900 && ch < 0xfb00) ||
- (ch >= 0xff00 && ch < 0xfff0);
-}
-
-inline bool break_after(wchar_t ch)
+ return is_cjk_char(ch);
+}
+
+inline bool break_after(const wchar_t ch)
{
if(no_break_after(ch))
return false;
- return ch == ' ' ||
- // CKJ characters
- (ch >= 0x3000 && ch < 0xa000) ||
- (ch >= 0xf900 && ch < 0xfb00) ||
- (ch >= 0xff00 && ch < 0xfff0);
+ return is_cjk_char(ch);
}
} // end of anon namespace
Modified: trunk/src/marked-up_text.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/marked-up_text.hpp?rev=34217&r1=34216&r2=34217&view=diff
==============================================================================
--- trunk/src/marked-up_text.hpp (original)
+++ trunk/src/marked-up_text.hpp Sun Mar 29 00:03:46 2009
@@ -82,6 +82,14 @@
*/
bool is_format_char(char c);
+/**
+ * Determine if a wchar_t is a CJK character
+ *
+ * @retval true Input-char is a CJK char
+ * @retval false Input-char is a not CJK char.
+ */
+bool is_cjk_char(const wchar_t ch);
+
/** Create string of color-markup, such as "<255,255,0>" for yellow. */
std::string color2markup(const SDL_Color color);
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits