gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ChangeLog server/edit_text_character.cpp ...


From: Benjamin Wolsey
Subject: [Gnash-commit] gnash ChangeLog server/edit_text_character.cpp ...
Date: Wed, 06 Feb 2008 12:00:39 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Benjamin Wolsey <bwy>   08/02/06 12:00:39

Modified files:
        .              : ChangeLog 
        server         : edit_text_character.cpp 
        server/vm      : ASHandlers.cpp 
        testsuite/actionscript.all: String.as 

Log message:
        SWF4 and 5 read only the first byte of a multi-byte character. However, 
SWF5 uses ISO-8895 (8-bit characters) for strings, allowing values up to 256.
        
        In SWF5, chr(246) should return an 8-bit ö char, but this is not the 
same as a utf-8 ö:
        
        x = chr(246);
        trace (ord(x));
        
        gives 246, whereas
        
        trace (ord("ö"));
        
        gives 195, the unsigned value of the first utf-8 char.
        
        Gnash needs therefore to preserve the difference between the two 
encodings, i.e. not convert SWF5 strings to canonical utf-8 strings ('UCS4'). 

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.5569&r2=1.5570
http://cvs.savannah.gnu.org/viewcvs/gnash/server/edit_text_character.cpp?cvsroot=gnash&r1=1.146&r2=1.147
http://cvs.savannah.gnu.org/viewcvs/gnash/server/vm/ASHandlers.cpp?cvsroot=gnash&r1=1.192&r2=1.193
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/String.as?cvsroot=gnash&r1=1.38&r2=1.39

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.5569
retrieving revision 1.5570
diff -u -b -r1.5569 -r1.5570
--- ChangeLog   6 Feb 2008 11:27:32 -0000       1.5569
+++ ChangeLog   6 Feb 2008 12:00:38 -0000       1.5570
@@ -1,5 +1,13 @@
 2008-02-06 Benjamin Wolsey <address@hidden>
 
+       * testsuite/actionscript.all/String.as: new failing tests for 
+         SWF5 string methods. Some chr() and ord() tests now pass.
+       * server/vm/ASHandlers.cpp: SWF4 and 5 handle multi-byte characters
+         differently.
+       * server/edit_text_character.cpp: use const reference.
+
+2008-02-06 Benjamin Wolsey <address@hidden>
+
        * testsuite/actionscript.all/String.as: tests for chr() and
          ord().
 

Index: server/edit_text_character.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/edit_text_character.cpp,v
retrieving revision 1.146
retrieving revision 1.147
diff -u -b -r1.146 -r1.147
--- server/edit_text_character.cpp      5 Feb 2008 12:01:51 -0000       1.146
+++ server/edit_text_character.cpp      6 Feb 2008 12:00:38 -0000       1.147
@@ -697,11 +697,10 @@
 void
 edit_text_character::updateText(const std::string& str)
 {
-       std::wstring wstr = utf8::decodeCanonicalString(str);
+       const std::wstring& wstr = utf8::decodeCanonicalString(str);
        updateText(wstr);
 }
 
-
 void
 edit_text_character::updateText(const std::wstring& wstr)
 {
@@ -1183,9 +1182,6 @@
 
        std::wstring::const_iterator it = _text.begin();
        
-       // decodeNextUnicodeCharacter(std::string::const_iterator &it) works,
-       // but unfortunately nothing is encoded in utf8.
-       
        while (boost::uint32_t code = *it++)
        {
                if ( _embedFonts )

Index: server/vm/ASHandlers.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/vm/ASHandlers.cpp,v
retrieving revision 1.192
retrieving revision 1.193
diff -u -b -r1.192 -r1.193
--- server/vm/ASHandlers.cpp    5 Feb 2008 15:34:41 -0000       1.192
+++ server/vm/ASHandlers.cpp    6 Feb 2008 12:00:38 -0000       1.193
@@ -17,7 +17,7 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 //
 
-/* $Id: ASHandlers.cpp,v 1.192 2008/02/05 15:34:41 bwy Exp $ */
+/* $Id: ASHandlers.cpp,v 1.193 2008/02/06 12:00:38 bwy Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "gnashconfig.h"
@@ -1635,16 +1635,20 @@
 //    GNASH_REPORT_FUNCTION;
     as_environment& env = thread.env;
     thread.ensureStack(1);
-    const std::wstring& wstr = 
utf8::decodeCanonicalString(env.top(0).to_string());
 
-    // TODO: what charcode here ?
+    // Should return 0 
 
-    if ( wstr.empty() )
+    if (env.get_version() <= 5)
     {
-       env.top(0).set_int(0);
+       // SWF4-5 return the unsigned value of the first char of a 
+       // multi-byte character.
+        const std::string& str = env.top(0).to_string();
+       env.top(0).set_int(static_cast<unsigned char>(str[0]));
     }
     else
     {
+       // SWF6+ handles multi-byte unicode characters.
+        const std::wstring& wstr = 
utf8::decodeCanonicalString(env.top(0).to_string());
        env.top(0).set_int(wstr[0]);
     }
 }
@@ -1656,11 +1660,32 @@
     as_environment& env = thread.env;
     thread.ensureStack(1);
     
-    std::wstring ret = L"";
-    wchar_t t(env.top(0).to_int());
-    ret.push_back(t);
+    boost::uint32_t c = env.top(0).to_int();
 
+    // If the argument to chr() is '0', we return
+    // nothing, not NULL
+    if (c == 0) env.top(0).set_string("");
+    
+    else
+    {
+        // SWF5 returns the unsigned value of the last byte.
+        if (env.get_version() <= 5)
+        {
+           std::string ret = "";
+           // This adds an unsigned char to a string, giving
+           // IS0-8859 8-bit characters.
+           // Values above 256 evaluate to value % 256, 
+           // which is expected behaviour.
+           ret.push_back(static_cast<unsigned char>(c));
+            env.top(0).set_string(ret);
+        }
+        else
+        {
+            std::wstring ret = L"";    
+            ret.push_back(static_cast<wchar_t>(c));
     env.top(0).set_string(utf8::encodeCanonicalString(ret));
+        }
+    }
 }
 
 void

Index: testsuite/actionscript.all/String.as
===================================================================
RCS file: /sources/gnash/gnash/testsuite/actionscript.all/String.as,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -b -r1.38 -r1.39
--- testsuite/actionscript.all/String.as        6 Feb 2008 11:27:33 -0000       
1.38
+++ testsuite/actionscript.all/String.as        6 Feb 2008 12:00:39 -0000       
1.39
@@ -16,8 +16,6 @@
 
 // Original author: Mike Carlson - June 19th, 2006
 
-rcsid="$Id: String.as,v 1.38 2008/02/06 11:27:33 bwy Exp $";
-
 #include "check.as"
 
 check_equals(typeof(String), 'function');
@@ -293,23 +291,21 @@
 
 // Chars greater than 128
 #if OUTPUT_VERSION > 5
-xcheck_equals (chr(246), "ö");
-xcheck_equals (chr(486), "Ǧ");
-trace ("Ǧ");
-trace(chr(486));
-xcheck_equals (chr(998), "Ϧ");
-xcheck_equals (ord("ö"), 246);
-xcheck_equals (ord("Ϧ"), 998);
+check_equals (chr(246), "ö");
+check_equals (chr(486), "Ǧ");
+check_equals (chr(998), "Ϧ");
+check_equals (ord("ö"), 246);
+check_equals (ord("Ϧ"), 998);
 #else // version <= 5
-xcheck_equals (chr(486), "æ");
-xcheck_equals (chr(865), "a");
-xcheck_equals (ord("ö"), 195);
-xcheck_equals (ord("Ö"), 195);
-xcheck_equals (ord("ǵ"), 199);
-xcheck_equals (ord("Ϧ"), 207);
+xcheck_equals (typeof(chr(486)), string);
+check_equals (chr(865), "a");
+check_equals (ord("ö"), 195);
+check_equals (ord("Ö"), 195);
+check_equals (ord("ǵ"), 199);
+check_equals (ord("Ϧ"), 207);
 #endif
 
-#if OUTPUT_VERSION > 5
+
 
 //-------------------------------------------
 // Check multi-byte chars with all string
@@ -319,13 +315,18 @@
 // These tests are only correct with SWF6 and above.
 
 var a = new String("Längere Wörter");
+
+#if OUTPUT_VERSION > 5
 check_equals (a.length, 14);
 check_equals (a.substring(2,4), "ng");
 check_equals (a.charAt(1), "ä");
 check_equals (a.charAt(2), "n");
 check_equals (a.slice(3,5), "ge");
 check_equals (a.charCodeAt(9), 246);
-
+#else
+xcheck_equals (a.length, 16);
+xcheck_equals (a.slice(3,5), "ng");
+xcheck_equals (a.charCodeAt(10), 195);
 #endif
 
 // see check.as
@@ -529,7 +530,7 @@
 check_equals(r, "s:");
 
 #if OUTPUT_VERSION < 6
- check_totals(185);
+ check_totals(188);
 #else
  check_totals(218);
 #endif




reply via email to

[Prev in Thread] Current Thread [Next in Thread]