From f6806bd1ea413ea4fd7d374a9fe71027735e8a9a Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Wed, 20 Nov 2013 00:22:39 +0000 Subject: [PATCH] - added unit tests for arabic handling in fribidi - added default property value for right to left mixed in english.lng - fixed bug in arabic.lng file --- source/shared_lib/sources/graphics/font.cpp | 30 ++++++---------- .../tests/shared_lib/graphics/font_test.cpp | 36 ++++++++++++++++++- 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/source/shared_lib/sources/graphics/font.cpp b/source/shared_lib/sources/graphics/font.cpp index e20ca2666..4e2cea080 100644 --- a/source/shared_lib/sources/graphics/font.cpp +++ b/source/shared_lib/sources/graphics/font.cpp @@ -370,8 +370,8 @@ void Font::bidi_cvt(string &str_) { #ifdef HAVE_FRIBIDI - - //printf("BEFORE: [%s]\n",str_.c_str()); + const bool debugFribidi = false; + if(debugFribidi == true) printf("BEFORE: [%s]\n",str_.c_str()); string new_value = ""; bool hasSoftNewLines = false; @@ -390,7 +390,7 @@ void Font::bidi_cvt(string &str_) { lines.push_back(str_); } - //printf("Lines: %d\n",(int)lines.size()); + if(debugFribidi == true) printf("Lines: %d\n",(int)lines.size()); for(int lineIndex = 0; lineIndex < (int)lines.size(); ++lineIndex) { if(lineIndex > 0) { @@ -402,7 +402,7 @@ void Font::bidi_cvt(string &str_) { } } str_ = lines[lineIndex]; - //printf("Line: %d [%s]\n",lineIndex,str_.c_str()); + if(debugFribidi == true) printf("Line: %d [%s] Font::fontSupportMixedRightToLeft = %d\n",lineIndex,str_.c_str(),Font::fontSupportMixedRightToLeft); vector words; if(Font::fontSupportMixedRightToLeft == true) { @@ -424,12 +424,9 @@ void Font::bidi_cvt(string &str_) { nonASCIIWordList.reserve(words.size()); for(int wordIndex = 0; wordIndex < (int)words.size(); ++wordIndex) { - //if(wordIndex > 0) { - // new_value += " "; - //} str_ = words[wordIndex]; - //printf("Word: %d [%s]\n",wordIndex,str_.c_str()); + if(debugFribidi == true) printf("Word: %d [%s]\n",wordIndex,str_.c_str()); //FriBidi C string holding the original text (that is probably with logical hebrew) FriBidiChar *logical = NULL; @@ -499,14 +496,7 @@ void Font::bidi_cvt(string &str_) { //Insert the output string into the result str_ = op; - //printf("LOG2VIS: [%s]\n",str_.c_str()); - - // if(ascii_char_map.empty() == false) { - // for (int index = 0; index < (int)ascii_char_map.size(); ++index) { - // str_.insert(ascii_char_map[index].second,1,ascii_char_map[index].first); - // } - // } - //printf("AFTER: [%s]\n",str_.c_str()); + if(debugFribidi == true) printf("LOG2VIS: [%s]\n",str_.c_str()); } //printf("AFTER: [%s]\n",str_.c_str()); @@ -552,18 +542,18 @@ void Font::bidi_cvt(string &str_) { } } - //printf("Building New Line: %d [%s]\n",lineIndex,new_value.c_str()); + if(debugFribidi == true) printf("Building New Line: %d [%s]\n",lineIndex,new_value.c_str()); for(int wordIndex = 0; wordIndex < (int)wordList.size(); ++wordIndex) { - //printf("wordIndex: %d [%s]\n",wordIndex,wordList[wordIndex].c_str()); + if(debugFribidi == true) printf("wordIndex: %d [%s]\n",wordIndex,wordList[wordIndex].c_str()); if(wordIndex > 0) { new_value += " "; } new_value += wordList[wordIndex]; } - //printf("New Line: %d [%s]\n",lineIndex,new_value.c_str()); + if(debugFribidi == true) printf("New Line: %d [%s]\n",lineIndex,new_value.c_str()); } str_ = new_value; - //printf("NEW: [%s]\n",str_.c_str()); + if(debugFribidi == true) printf("NEW: [%s]\n",str_.c_str()); #endif diff --git a/source/tests/shared_lib/graphics/font_test.cpp b/source/tests/shared_lib/graphics/font_test.cpp index 2b98228e1..c02f60601 100644 --- a/source/tests/shared_lib/graphics/font_test.cpp +++ b/source/tests/shared_lib/graphics/font_test.cpp @@ -39,6 +39,7 @@ class FontTest : public CppUnit::TestFixture { public: void test_bidi_newline_handling() { + string text = "\n\nHP: 9000/9000\nArmor: 0 (Stone)\nSight: 15\nProduce Slave"; string expected = text; #ifdef HAVE_FRIBIDI @@ -46,6 +47,7 @@ public: //printf("Expected: [%s] result[%s]\n",expected.c_str(),text.c_str()); CPPUNIT_ASSERT_EQUAL( expected,text ); #endif + } void test_LTR_RTL_Mixed() { Font::fontSupportMixedRightToLeft = true; @@ -120,7 +122,6 @@ public: CPPUNIT_ASSERT_EQUAL( expected_result4,FactionName_indian ); #endif - // This test still failing: xx IP xx string LanIP = "כתובות IP מקומי:192.168.0.150 ( 61357 / 61357 )"; string expected5 = LanIP; //printf("LanIP [%s]\n",LanIP.c_str()); @@ -135,6 +136,39 @@ public: CPPUNIT_ASSERT_EQUAL( expected_result5,LanIP ); #endif + + string IntroText1_ar = "مبني على الحاصلة على جائزة Glest الكلاسيكية"; + //printf("START IntroText1_ar [%s]\n",IntroText1_ar.c_str()); + string expected6 = IntroText1_ar; + //printf("LanIP [%s]\n",LanIP.c_str()); + + CPPUNIT_ASSERT_EQUAL( 75,(int)IntroText1_ar.size() ); + +#ifdef HAVE_FRIBIDI + //printf("Before IntroText1_ar [%s]\n",IntroText1_ar.c_str()); + Font::bidi_cvt(IntroText1_ar); + //printf("After IntroText1_ar [%s]\n",IntroText1_ar.c_str()); + + CPPUNIT_ASSERT_EQUAL( 104,(int)IntroText1_ar.size() ); + string expected_result6 = "ﺓﺰﺋﺎﺟ ﻰﻠﻋ ﺔﻠﺻﺎﺤﻟﺍ ﻰﻠﻋ ﻲﻨﺒﻣ Glest ﺔﻴﻜﻴﺳﻼﻜﻟﺍ"; + + CPPUNIT_ASSERT_EQUAL( expected_result6,IntroText1_ar ); +#endif + + string IntroText2 = "فريق MegaGlest يقدم"; + string expected7 = IntroText2; + + CPPUNIT_ASSERT_EQUAL( 27,(int)IntroText2.size() ); + +#ifdef HAVE_FRIBIDI + Font::bidi_cvt(IntroText2); + + CPPUNIT_ASSERT_EQUAL( 35,(int)IntroText2.size() ); + string expected_result7 = "ﻖﻳﺮﻓ MegaGlest ﻡﺪﻘﻳ"; + + CPPUNIT_ASSERT_EQUAL( expected_result7,IntroText2 ); +#endif + } };