gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r11803: More cleanup, tests.


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r11803: More cleanup, tests.
Date: Mon, 25 Jan 2010 13:55:05 +0100
User-agent: Bazaar (2.0.2)

------------------------------------------------------------
revno: 11803 [merge]
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Mon 2010-01-25 13:55:05 +0100
message:
  More cleanup, tests.
modified:
  libcore/asobj/flash/text/TextFormat_as.cpp
  testsuite/actionscript.all/TextFormat.as
=== modified file 'libcore/asobj/flash/text/TextFormat_as.cpp'
--- a/libcore/asobj/flash/text/TextFormat_as.cpp        2010-01-25 11:37:17 
+0000
+++ b/libcore/asobj/flash/text/TextFormat_as.cpp        2010-01-25 12:29:02 
+0000
@@ -39,38 +39,67 @@
 // Functions and templates for reducing code duplication.
 namespace {
 
+/// Set functors may need access to fn_call resources, e.g. SWF version.
+//
+/// Currently only as_value::to_string() needs this, but in future other
+/// conversions may follow.
+struct SetBase
+{
+    SetBase(const fn_call& fn) : _fn(fn) {}
+    const fn_call& fn() const {
+        return _fn;
+    }
+private:
+    const fn_call& _fn;
+};
+
+/// Convert pixels to twips, treating negative values as 0.
 struct
-PositiveTwips
+PositiveTwips : SetBase
 {
+    PositiveTwips(const fn_call& fn) : SetBase(fn) {}
     int operator()(const as_value& val) const {
         return pixelsToTwips(std::max<int>(toInt(val), 0));
     }
 };
 
-struct
-TwipsToPixels
-{
-    template<typename T> double operator()(const T& t) const {
-        return twipsToPixels(t);
-    }
-};
-
-struct
-PixelsToTwips
-{
+/// Convert an argument from a number of pixels into twips.
+struct
+PixelsToTwips : SetBase
+{
+    PixelsToTwips(const fn_call& fn) : SetBase(fn) {}
     boost::int32_t operator()(const as_value& val) const {
         return pixelsToTwips(val.to_number());
     }
 };
 
+/// Convert the as_value to a boolean.
 struct
-ToBool
+ToBool : SetBase
 {
+    ToBool(const fn_call& fn) : SetBase(fn) {}
     bool operator()(const as_value& val) const {
         return val.to_bool();
     }
 };
 
+/// Convert the as_value to a string.
+struct
+ToString : SetBase
+{
+    ToString(const fn_call& fn) : SetBase(fn) {}
+    std::string operator()(const as_value& val) const {
+        return val.to_string(getSWFVersion(fn()));
+    }
+};
+
+
+/// Get functors.
+//
+/// Conversions and processing are done when setting, so these functors should
+/// be relatively simple.
+
+/// Do nothing, i.e. return exactly the same argument that was passed.
 struct
 Nothing
 {
@@ -79,6 +108,15 @@
     }
 };
 
+/// Convert internal twip values to pixel values for ActionScript.
+struct
+TwipsToPixels
+{
+    template<typename T> double operator()(const T& t) const {
+        return twipsToPixels(t);
+    }
+};
+
 /// Produce a function to set a TextFormat property
 //
 /// @tparam T       The type of the Relay (should be TextFormat_as)
@@ -104,7 +142,9 @@
             return as_value();
         }
 
-        (relay->*F)(P()(arg));
+        // The function P takes care of converting the argument to the
+        // required type.
+        (relay->*F)(P(fn)(arg));
         return as_value();
     }
 
@@ -158,13 +198,13 @@
        TextField::TextAlignment parseAlignString(const std::string& align);
        TextField::TextFormatDisplay parseDisplayString(const std::string& 
display);
 
+    /// Align works a bit differently, so is currently not a template.
     as_value textformat_align(const fn_call& fn);
+
+    /// Display is never null, so not a template.
        as_value textformat_display(const fn_call& fn);
        as_value textformat_tabStops(const fn_call& fn);
-       as_value textformat_target(const fn_call& fn);
-       as_value textformat_url(const fn_call& fn);
        as_value textformat_color(const fn_call& fn);
-       as_value textformat_font(const fn_call& fn);
        as_value textformat_getTextExtent(const fn_call& fn);
 
 }
@@ -203,8 +243,13 @@
     // instead of one function for both. Needs testing.
     vm.registerNative(textformat_new, 110, 0);
     
-    vm.registerNative(textformat_font, 110, 1);
-    vm.registerNative(textformat_font, 110, 2);
+    vm.registerNative(
+            Get<const TextFormat_as, std::string, &TextFormat_as::font>::get,
+            110, 1);
+    vm.registerNative(
+            Set<TextFormat_as, std::string, &TextFormat_as::fontSet,
+            ToString>::set, 
+            110, 2);
     
     vm.registerNative(
             Get<const TextFormat_as, boost::uint16_t,
@@ -218,11 +263,21 @@
     vm.registerNative(textformat_color, 110, 5);
     vm.registerNative(textformat_color, 110, 6);
     
-    vm.registerNative(textformat_url, 110, 7);
-    vm.registerNative(textformat_url, 110, 8);
+    vm.registerNative(
+            Get<const TextFormat_as, std::string, &TextFormat_as::url>::get,
+            110, 7);
+    vm.registerNative(
+            Set<TextFormat_as, std::string, &TextFormat_as::urlSet,
+            ToString>::set, 
+            110, 8);
     
-    vm.registerNative(textformat_target, 110, 9);
-    vm.registerNative(textformat_target, 110, 10);
+    vm.registerNative(
+            Get<const TextFormat_as, std::string, &TextFormat_as::target>::get,
+            110, 9);
+    vm.registerNative(
+            Set<TextFormat_as, std::string, &TextFormat_as::targetSet,
+            ToString>::set, 
+            110, 10);
     
     vm.registerNative(
             Get<const TextFormat_as, bool, &TextFormat_as::bold>::get,
@@ -301,7 +356,7 @@
 
     vm.registerNative(
             Get<const TextFormat_as, bool, &TextFormat_as::bullet,
-            ToBool>::get, 110, 31);
+            Nothing>::get, 110, 31);
     vm.registerNative(
             Set<TextFormat_as, bool, &TextFormat_as::bulletSet,
             ToBool>::set, 
@@ -443,59 +498,17 @@
 }
 
 as_value
-textformat_target(const fn_call& fn)
-{
-    TextFormat_as* relay = ensure<ThisIsNative<TextFormat_as> >(fn);
-
-       as_value ret;
-
-       if ( fn.nargs == 0 ) // getter
-       {
-               if (relay->target()) ret.set_string(*relay->target());
-               else ret.set_null();
-       }
-       else // setter
-       {
-               relay->targetSet(fn.arg(0).to_string());
-       }
-
-       return ret;
-}
-
-as_value
-textformat_url(const fn_call& fn)
-{
-    TextFormat_as* relay = ensure<ThisIsNative<TextFormat_as> >(fn);
-
-       as_value ret;
-
-       if ( fn.nargs == 0 ) // getter
-       {
-               if (relay->url()) ret.set_string(*relay->url());
-               else ret.set_null();
-       }
-       else // setter
-       {
-               relay->urlSet(fn.arg(0).to_string());
-       }
-
-       return ret;
-}
-
-as_value
 textformat_color(const fn_call& fn)
 {
     TextFormat_as* relay = ensure<ThisIsNative<TextFormat_as> >(fn);
 
        as_value ret;
 
-       if ( fn.nargs == 0 ) // getter
-       {
+       if (fn.nargs == 0) {
                if (relay->color()) ret.set_double(relay->color()->toRGB());
                else ret.set_null();
        }
-       else // setter
-       {
+       else {
                rgba newcolor;
                newcolor.parseRGB(toInt(fn.arg(0)));
                relay->colorSet(newcolor);
@@ -505,45 +518,24 @@
 }
 
 as_value
-textformat_font(const fn_call& fn)
-{
-    TextFormat_as* relay = ensure<ThisIsNative<TextFormat_as> >(fn);
-
-       as_value ret;
-
-       if ( fn.nargs == 0 ) // getter
-       {
-               if (relay->font()) ret.set_string(*relay->font());
-               else ret.set_null();
-       }
-       else // setter
-       {
-               relay->fontSet(fn.arg(0).to_string());
-       }
-
-       return ret;
-}
-
-as_value
 textformat_align(const fn_call& fn)
 {
     TextFormat_as* relay = ensure<ThisIsNative<TextFormat_as> >(fn);
 
-   as_value ret;
+    as_value ret;
 
-   if ( fn.nargs == 0 ) // getter
-   {
-       if (relay->align()) {
+    if (fn.nargs == 0) {
+        if (relay->align()) {
             ret.set_string(getAlignString(*relay->align()));
         }
         else ret.set_null();
-   }
-   else // setter
-   {
-       relay->alignSet(fn.arg(0).to_string());
-   }
+    }
+    else // setter
+    {
+        relay->alignSet(fn.arg(0).to_string());
+    }
 
-   return ret;
+    return ret;
 }
 
 

=== modified file 'testsuite/actionscript.all/TextFormat.as'
--- a/testsuite/actionscript.all/TextFormat.as  2010-01-25 07:23:53 +0000
+++ b/testsuite/actionscript.all/TextFormat.as  2010-01-25 12:29:02 +0000
@@ -280,6 +280,24 @@
 tf.size = undefined;
 check_equals(tf.size, null);
 
+// align
+tf.align = "hi";
+check_equals(tf.align, null);
+tf.align = "Left";
+check_equals(tf.align, "left");
+tf.align = "o";
+check_equals(tf.align, "left");
+tf.align = "righto";
+check_equals(tf.align, "left");
+tf.align = "center";
+check_equals(tf.align, "center");
+tf.align = "right";
+check_equals(tf.align, "right");
+tf.align = undefined;
+check_equals(tf.align, "right");
+tf.align = null;
+check_equals(tf.align, "right");
+
 // Check tabStops property.
 // The passed array is processed before assignment, not simply stored.
 tf = new TextFormat();
@@ -385,9 +403,9 @@
 #endif
 
 #if OUTPUT_VERSION < 7
-    check_totals(114);
+    check_totals(122);
 #elif OUTPUT_VERSION == 7
-    check_totals(150);
+    check_totals(158);
 #else 
-    check_totals(150);
+    check_totals(158);
 #endif


reply via email to

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