[Swfdec-commits] 10 commits - swfdec/swfdec_button.c swfdec/swfdec_event.c swfdec/swfdec_text_field_movie_as.c swfdec/swfdec_text_field_movie.c swfdec/swfdec_text_field_movie.h swfdec/swfdec_text_layout.c swfdec/swfdec_text_layout.h test/custom test/image test/trace

Benjamin Otte company at kemper.freedesktop.org
Mon May 12 09:51:20 PDT 2008


 swfdec/swfdec_button.c                        |    2 
 swfdec/swfdec_event.c                         |    2 
 swfdec/swfdec_text_field_movie.c              |  118 ++++++++++++++++++--------
 swfdec/swfdec_text_field_movie.h              |    9 +
 swfdec/swfdec_text_field_movie_as.c           |   10 --
 swfdec/swfdec_text_layout.c                   |    5 -
 swfdec/swfdec_text_layout.h                   |    3 
 test/custom/Makefile.am                       |    9 +
 test/custom/button-event-with-key-5.swf       |binary
 test/custom/button-event-with-key-5.swf.trace |    3 
 test/custom/button-event-with-key-6.swf       |binary
 test/custom/button-event-with-key-6.swf.trace |    3 
 test/custom/button-event-with-key-7.swf       |binary
 test/custom/button-event-with-key-7.swf.trace |    3 
 test/custom/button-event-with-key-8.swf       |binary
 test/custom/button-event-with-key-8.swf.trace |    3 
 test/custom/button-event-with-key.c           |   60 +++++++++++++
 test/custom/button-events.stas                |    9 +
 test/custom/button-events.sts                 |binary
 test/custom/button-hittest.stas               |    9 +
 test/custom/button-hittest.sts                |binary
 test/custom/crash-0.5.90-up-to-date.stas      |    9 +
 test/custom/crash-0.5.90-up-to-date.sts       |binary
 test/custom/crash-0.5.90-up-to-date.swf.trace |    4 
 test/custom/definebutton.stas                 |    9 +
 test/custom/definebutton.sts                  |binary
 test/custom/mouse-addProperty-relevant.stas   |    9 +
 test/custom/mouse-addProperty-relevant.sts    |binary
 test/custom/mouse-movie-below.stas            |    9 +
 test/custom/mouse-movie-below.sts             |binary
 test/custom/mouse-scaled.stas                 |    9 +
 test/custom/mouse-scaled.sts                  |binary
 test/image/Makefile.am                        |    9 +
 test/image/text-field-border-scale-5.swf      |binary
 test/image/text-field-border-scale-5.swf.png  |binary
 test/image/text-field-border-scale-6.swf      |binary
 test/image/text-field-border-scale-6.swf.png  |binary
 test/image/text-field-border-scale-7.swf      |binary
 test/image/text-field-border-scale-7.swf.png  |binary
 test/image/text-field-border-scale-8.swf      |binary
 test/image/text-field-border-scale-8.swf.png  |binary
 test/image/text-field-border-scale.as         |   29 ++++++
 test/trace/Makefile.am                        |    9 +
 test/trace/replaceText-newline-5.swf          |binary
 test/trace/replaceText-newline-5.swf.trace    |    3 
 test/trace/replaceText-newline-6.swf          |binary
 test/trace/replaceText-newline-6.swf.trace    |    3 
 test/trace/replaceText-newline-7.swf          |binary
 test/trace/replaceText-newline-7.swf.trace    |    3 
 test/trace/replaceText-newline-8.swf          |binary
 test/trace/replaceText-newline-8.swf.trace    |    3 
 test/trace/replaceText-newline.as             |   22 ++++
 52 files changed, 314 insertions(+), 64 deletions(-)

New commits:
commit f67ef3fd8bf52984a1cbf874e425bd11c109bbcc
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon May 12 18:49:17 2008 +0200

    add test for recent event changes

diff --git a/test/custom/Makefile.am b/test/custom/Makefile.am
index 6ae3773..746e12e 100644
--- a/test/custom/Makefile.am
+++ b/test/custom/Makefile.am
@@ -23,6 +23,15 @@ EXTRA_DIST = \
 	button-events-menu-7.swf.trace \
 	button-events-menu-8.swf \
 	button-events-menu-8.swf.trace \
+	button-event-with-key-5.swf \
+	button-event-with-key-5.swf.trace \
+	button-event-with-key-6.swf \
+	button-event-with-key-6.swf.trace \
+	button-event-with-key-7.swf \
+	button-event-with-key-7.swf.trace \
+	button-event-with-key-8.swf \
+	button-event-with-key-8.swf.trace \
+	button-event-with-key.c \
 	button-hittest-5.swf \
 	button-hittest-5.swf.trace \
 	button-hittest-6.swf \
diff --git a/test/custom/button-event-with-key-5.swf b/test/custom/button-event-with-key-5.swf
new file mode 100644
index 0000000..df58cf0
Binary files /dev/null and b/test/custom/button-event-with-key-5.swf differ
diff --git a/test/custom/button-event-with-key-5.swf.trace b/test/custom/button-event-with-key-5.swf.trace
new file mode 100644
index 0000000..361ae55
--- /dev/null
+++ b/test/custom/button-event-with-key-5.swf.trace
@@ -0,0 +1,3 @@
+_level0 click
+_level0 unclick
+_level0 click
diff --git a/test/custom/button-event-with-key-6.swf b/test/custom/button-event-with-key-6.swf
new file mode 100644
index 0000000..efb9a95
Binary files /dev/null and b/test/custom/button-event-with-key-6.swf differ
diff --git a/test/custom/button-event-with-key-6.swf.trace b/test/custom/button-event-with-key-6.swf.trace
new file mode 100644
index 0000000..361ae55
--- /dev/null
+++ b/test/custom/button-event-with-key-6.swf.trace
@@ -0,0 +1,3 @@
+_level0 click
+_level0 unclick
+_level0 click
diff --git a/test/custom/button-event-with-key-7.swf b/test/custom/button-event-with-key-7.swf
new file mode 100644
index 0000000..3665a25
Binary files /dev/null and b/test/custom/button-event-with-key-7.swf differ
diff --git a/test/custom/button-event-with-key-7.swf.trace b/test/custom/button-event-with-key-7.swf.trace
new file mode 100644
index 0000000..361ae55
--- /dev/null
+++ b/test/custom/button-event-with-key-7.swf.trace
@@ -0,0 +1,3 @@
+_level0 click
+_level0 unclick
+_level0 click
diff --git a/test/custom/button-event-with-key-8.swf b/test/custom/button-event-with-key-8.swf
new file mode 100644
index 0000000..2667bb2
Binary files /dev/null and b/test/custom/button-event-with-key-8.swf differ
diff --git a/test/custom/button-event-with-key-8.swf.trace b/test/custom/button-event-with-key-8.swf.trace
new file mode 100644
index 0000000..361ae55
--- /dev/null
+++ b/test/custom/button-event-with-key-8.swf.trace
@@ -0,0 +1,3 @@
+_level0 click
+_level0 unclick
+_level0 click
diff --git a/test/custom/button-event-with-key.c b/test/custom/button-event-with-key.c
new file mode 100644
index 0000000..552f837
--- /dev/null
+++ b/test/custom/button-event-with-key.c
@@ -0,0 +1,60 @@
+/* gcc `pkg-config --libs --cflags libming` button-event-with-key.c -o button-event-with-key && ./button-event-with-key
+ */
+
+#include <ming.h>
+
+static SWFCharacter
+get_rectangle (int r, int g, int b)
+{
+  SWFShape shape;
+  SWFFillStyle fill;
+
+  shape = newSWFShape ();
+  fill = SWFShape_addSolidFillStyle (shape, r, g, b, 255);
+  SWFShape_setRightFillStyle (shape, fill);
+  SWFShape_drawLineTo (shape, 100, 0);
+  SWFShape_drawLineTo (shape, 100, 100);
+  SWFShape_drawLineTo (shape, 0, 100);
+  SWFShape_drawLineTo (shape, 0, 0);
+
+  return (SWFCharacter) shape;
+}
+
+static void
+do_movie (int version)
+{
+  SWFMovie movie;
+  SWFButton button;
+  SWFDisplayItem item;
+  char name[100];
+
+  movie = newSWFMovieWithVersion (version);
+  movie = newSWFMovie();
+  SWFMovie_setRate (movie, 1);
+  SWFMovie_setDimension (movie, 200, 150);
+
+  button = newSWFButton ();
+  SWFButton_addCharacter (button, get_rectangle (255, 0, 0), SWFBUTTON_HIT | SWFBUTTON_UP | SWFBUTTON_DOWN | SWFBUTTON_OVER);
+  SWFButton_addAction (button, newSWFAction ("trace (this + \" click\");"), SWFBUTTON_KEYPRESS (13) | SWFBUTTON_MOUSEDOWN);
+  SWFButton_addAction (button, newSWFAction ("trace (this + \" unclick\");"), SWFBUTTON_KEYPRESS (32) | SWFBUTTON_MOUSEUP);
+
+  item = SWFMovie_add (movie, (SWFBlock) button);
+  SWFMovie_nextFrame (movie);
+
+  sprintf (name, "button-event-with-key-%d.swf", version);
+  SWFMovie_save (movie, name);
+}
+
+int
+main (int argc, char **argv)
+{
+  int i;
+
+  if (Ming_init ())
+    return 1;
+
+  for (i = 5; i < 9; i++)
+    do_movie (i);
+
+  return 0;
+}
commit 07a5bb85558eb291b833fc2472b9e7446a03e8e8
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon May 12 18:46:40 2008 +0200

    Fix broken trace data
    
    Another thing that must not happen...

diff --git a/test/custom/crash-0.5.90-up-to-date.swf.trace b/test/custom/crash-0.5.90-up-to-date.swf.trace
index e69de29..af8b2b3 100644
--- a/test/custom/crash-0.5.90-up-to-date.swf.trace
+++ b/test/custom/crash-0.5.90-up-to-date.swf.trace
@@ -0,0 +1,4 @@
+hi
+hi
+hi
+hi
commit 2561d9e3de702ca39c62e09850486ecc71d9bd47
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon May 12 18:45:36 2008 +0200

    fix scripts to use "new" way to compare trace output
    
    This was introduced for Swfdec 0.5.90, so we've been not running tests in here
    for a _really_ long time.
    We seriously need to fix this.

diff --git a/test/custom/button-events.stas b/test/custom/button-events.stas
index 865329d..711f219 100644
--- a/test/custom/button-events.stas
+++ b/test/custom/button-events.stas
@@ -22,7 +22,6 @@ run_test = function (t, file) {
   print ("Testing " + file);
   try {
     t.reset (file);
-    t.trace (file + ".trace");
     t.advance (1000);
     t.mouse_move (50, 50);
     t.advance (1000);
@@ -40,7 +39,13 @@ run_test = function (t, file) {
     t.advance (1000);
     t.mouse_release (140, 140);
     t.advance (1000);
-    t.trace ();
+    var expected = Buffer.load (file + ".trace");
+    var diff = t.trace.diff (expected);
+    if (diff) {
+      error ("different trace output");
+      Native.print (diff);
+      return false;
+    }
   } catch (e) {
     if (e) {
       error (e);
diff --git a/test/custom/button-events.sts b/test/custom/button-events.sts
index 378773f..e84a420 100644
Binary files a/test/custom/button-events.sts and b/test/custom/button-events.sts differ
diff --git a/test/custom/button-hittest.stas b/test/custom/button-hittest.stas
index 865329d..711f219 100644
--- a/test/custom/button-hittest.stas
+++ b/test/custom/button-hittest.stas
@@ -22,7 +22,6 @@ run_test = function (t, file) {
   print ("Testing " + file);
   try {
     t.reset (file);
-    t.trace (file + ".trace");
     t.advance (1000);
     t.mouse_move (50, 50);
     t.advance (1000);
@@ -40,7 +39,13 @@ run_test = function (t, file) {
     t.advance (1000);
     t.mouse_release (140, 140);
     t.advance (1000);
-    t.trace ();
+    var expected = Buffer.load (file + ".trace");
+    var diff = t.trace.diff (expected);
+    if (diff) {
+      error ("different trace output");
+      Native.print (diff);
+      return false;
+    }
   } catch (e) {
     if (e) {
       error (e);
diff --git a/test/custom/button-hittest.sts b/test/custom/button-hittest.sts
index 378773f..e84a420 100644
Binary files a/test/custom/button-hittest.sts and b/test/custom/button-hittest.sts differ
diff --git a/test/custom/crash-0.5.90-up-to-date.stas b/test/custom/crash-0.5.90-up-to-date.stas
index 865329d..711f219 100644
--- a/test/custom/crash-0.5.90-up-to-date.stas
+++ b/test/custom/crash-0.5.90-up-to-date.stas
@@ -22,7 +22,6 @@ run_test = function (t, file) {
   print ("Testing " + file);
   try {
     t.reset (file);
-    t.trace (file + ".trace");
     t.advance (1000);
     t.mouse_move (50, 50);
     t.advance (1000);
@@ -40,7 +39,13 @@ run_test = function (t, file) {
     t.advance (1000);
     t.mouse_release (140, 140);
     t.advance (1000);
-    t.trace ();
+    var expected = Buffer.load (file + ".trace");
+    var diff = t.trace.diff (expected);
+    if (diff) {
+      error ("different trace output");
+      Native.print (diff);
+      return false;
+    }
   } catch (e) {
     if (e) {
       error (e);
diff --git a/test/custom/crash-0.5.90-up-to-date.sts b/test/custom/crash-0.5.90-up-to-date.sts
index 378773f..e84a420 100644
Binary files a/test/custom/crash-0.5.90-up-to-date.sts and b/test/custom/crash-0.5.90-up-to-date.sts differ
diff --git a/test/custom/definebutton.stas b/test/custom/definebutton.stas
index 865329d..711f219 100644
--- a/test/custom/definebutton.stas
+++ b/test/custom/definebutton.stas
@@ -22,7 +22,6 @@ run_test = function (t, file) {
   print ("Testing " + file);
   try {
     t.reset (file);
-    t.trace (file + ".trace");
     t.advance (1000);
     t.mouse_move (50, 50);
     t.advance (1000);
@@ -40,7 +39,13 @@ run_test = function (t, file) {
     t.advance (1000);
     t.mouse_release (140, 140);
     t.advance (1000);
-    t.trace ();
+    var expected = Buffer.load (file + ".trace");
+    var diff = t.trace.diff (expected);
+    if (diff) {
+      error ("different trace output");
+      Native.print (diff);
+      return false;
+    }
   } catch (e) {
     if (e) {
       error (e);
diff --git a/test/custom/definebutton.sts b/test/custom/definebutton.sts
index 378773f..e84a420 100644
Binary files a/test/custom/definebutton.sts and b/test/custom/definebutton.sts differ
diff --git a/test/custom/mouse-addProperty-relevant.stas b/test/custom/mouse-addProperty-relevant.stas
index 7d2f269..337adf4 100644
--- a/test/custom/mouse-addProperty-relevant.stas
+++ b/test/custom/mouse-addProperty-relevant.stas
@@ -22,7 +22,6 @@ run_test = function (t, file) {
   print ("Testing " + file);
   try {
     t.reset (file);
-    t.trace (file + ".trace");
     t.advance (1000);
     t.mouse_move (50, 50);
     t.advance (1000);
@@ -32,7 +31,13 @@ run_test = function (t, file) {
     t.advance (1000);
     t.mouse_release (140, 140);
     t.advance (1000);
-    t.trace ();
+    var expected = Buffer.load (file + ".trace");
+    var diff = t.trace.diff (expected);
+    if (diff) {
+      error ("different trace output");
+      Native.print (diff);
+      return false;
+    }
   } catch (e) {
     if (e) {
       error (e);
diff --git a/test/custom/mouse-addProperty-relevant.sts b/test/custom/mouse-addProperty-relevant.sts
index 24dd0ad..996e330 100644
Binary files a/test/custom/mouse-addProperty-relevant.sts and b/test/custom/mouse-addProperty-relevant.sts differ
diff --git a/test/custom/mouse-movie-below.stas b/test/custom/mouse-movie-below.stas
index 6617b65..182a7e5 100644
--- a/test/custom/mouse-movie-below.stas
+++ b/test/custom/mouse-movie-below.stas
@@ -22,7 +22,6 @@ run_test = function (t, file) {
   print ("Testing " + file);
   try {
     t.reset (file);
-    t.trace (file + ".trace");
     t.advance (300);
     t.mouse_move (50, 50);
     t.advance (300);
@@ -40,7 +39,13 @@ run_test = function (t, file) {
     t.advance (300);
     t.mouse_release (140, 140);
     t.advance (300);
-    t.trace ();
+    var expected = Buffer.load (file + ".trace");
+    var diff = t.trace.diff (expected);
+    if (diff) {
+      error ("different trace output");
+      Native.print (diff);
+      return false;
+    }
   } catch (e) {
     if (e) {
       error (e);
diff --git a/test/custom/mouse-movie-below.sts b/test/custom/mouse-movie-below.sts
index b904d09..c2120a5 100644
Binary files a/test/custom/mouse-movie-below.sts and b/test/custom/mouse-movie-below.sts differ
diff --git a/test/custom/mouse-scaled.stas b/test/custom/mouse-scaled.stas
index 2900795..acc1d26 100644
--- a/test/custom/mouse-scaled.stas
+++ b/test/custom/mouse-scaled.stas
@@ -22,7 +22,6 @@ run_test = function (t, file) {
   print ("Testing " + file);
   try {
     t.reset (file);
-    t.trace (file + ".trace");
     t.advance (500);
     t.mouse_move (50, 50);
     t.advance (500);
@@ -32,7 +31,13 @@ run_test = function (t, file) {
     t.advance (500);
     t.mouse_release (100, 100);
     t.advance (1000);
-    t.trace ();
+    var expected = Buffer.load (file + ".trace");
+    var diff = t.trace.diff (expected);
+    if (diff) {
+      error ("different trace output");
+      Native.print (diff);
+      return false;
+    }
   } catch (e) {
     if (e) {
       error (e);
diff --git a/test/custom/mouse-scaled.sts b/test/custom/mouse-scaled.sts
index 359978b..fd28604 100644
Binary files a/test/custom/mouse-scaled.sts and b/test/custom/mouse-scaled.sts differ
commit efc6971cf7844a7e165043bd105cb22c435386ad
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon May 12 18:31:48 2008 +0200

    if a key was specified, add SWFDEC_EVENT_KEY_PRESS to the events

diff --git a/swfdec/swfdec_button.c b/swfdec/swfdec_button.c
index 26215ae..60a93de 100644
--- a/swfdec/swfdec_button.c
+++ b/swfdec/swfdec_button.c
@@ -222,6 +222,8 @@ tag_func_define_button_2 (SwfdecSwfDecoder * s, guint tag)
     key = condition >> 9;
     condition &= 0x1FF;
     condition = swfdec_button_translate_conditions (condition, button->menubutton);
+    if (key)
+      condition |= 1 << SWFDEC_EVENT_KEY_DOWN;
 
     SWFDEC_LOG (" length = %d", length);
 
commit 10a23d805116770c6886ef7e8e2b17d6b2dcc620
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon May 12 18:31:30 2008 +0200

    compare keys only for KEY_PRESS events

diff --git a/swfdec/swfdec_event.c b/swfdec/swfdec_event.c
index 136f4cd..98ff505 100644
--- a/swfdec/swfdec_event.c
+++ b/swfdec/swfdec_event.c
@@ -185,7 +185,7 @@ swfdec_event_list_execute (SwfdecEventList *list, SwfdecAsObject *object,
   for (i = 0; i < list->events->len; i++) {
     SwfdecEvent *event = &g_array_index (list->events, SwfdecEvent, i);
     if ((event->conditions & condition) &&
-	event->key == key) {
+	(condition != 1 << SWFDEC_EVENT_KEY_DOWN || event->key == key)) {
       SWFDEC_LOG ("executing script for event %u on scriptable %p", condition, object);
       swfdec_as_object_run (object, event->script);
     }
commit 58584f8c01a467192f74a3abd3cb5679d0764785
Author: Benjamin Otte <otte at gnome.org>
Date:   Fri May 9 21:58:49 2008 +0200

    implement hscroll and hscroll_max

diff --git a/swfdec/swfdec_text_field_movie.c b/swfdec/swfdec_text_field_movie.c
index 5c8cee8..a7ee238 100644
--- a/swfdec/swfdec_text_field_movie.c
+++ b/swfdec/swfdec_text_field_movie.c
@@ -121,9 +121,9 @@ swfdec_text_field_movie_render (SwfdecMovie *movie, cairo_t *cr,
   swfdec_text_field_movie_get_visible_area (text, &area);
 
   /* render the layout */
-  cairo_translate (cr, area.x, area.y);
-  cairo_rectangle (cr, 0, 0, area.width, area.height);
+  cairo_rectangle (cr, area.x, area.y, area.width, area.height);
   cairo_clip (cr);
+  cairo_translate (cr, (double) area.x - text->hscroll, area.y);
   swfdec_text_layout_render (text->layout, cr, ctrans,
       text->scroll, area.height);
 }
@@ -305,7 +305,7 @@ swfdec_text_field_movie_layout_changed (SwfdecTextLayout *layout,
     SwfdecTextFieldMovie *text)
 {
   double scale;
-  guint w, h;
+  guint w, h, max;
 
   swfdec_movie_invalidate_last (SWFDEC_MOVIE (text));
 
@@ -320,6 +320,12 @@ swfdec_text_field_movie_layout_changed (SwfdecTextLayout *layout,
   }
 
   swfdec_text_field_movie_update_scroll (text);
+
+  max = swfdec_text_field_movie_get_hscroll_max (text);
+  if (text->hscroll > max) {
+    text->hscroll = max;
+    text->scroll_changed = TRUE;
+  }
 }
 
 static void
@@ -990,3 +996,20 @@ swfdec_text_field_movie_get_visible_area (SwfdecTextFieldMovie *text, SwfdecRect
   rect->y = text->stage_rect.y + round (BORDER_TOP * text->yscale) - 1;
   return TRUE;
 }
+
+guint
+swfdec_text_field_movie_get_hscroll_max (SwfdecTextFieldMovie *text)
+{
+  SwfdecRectangle area;
+  guint width;
+
+  g_return_val_if_fail (SWFDEC_IS_TEXT_FIELD_MOVIE (text), 0);
+
+  swfdec_text_field_movie_get_visible_area (text, &area);
+  width = swfdec_text_layout_get_width (text->layout);
+  if ((guint) area.width >= width)
+    return 0;
+  else
+    return width - area.width;
+}
+
diff --git a/swfdec/swfdec_text_field_movie.h b/swfdec/swfdec_text_field_movie.h
index d0cc5f2..a533ff6 100644
--- a/swfdec/swfdec_text_field_movie.h
+++ b/swfdec/swfdec_text_field_movie.h
@@ -81,8 +81,7 @@ struct _SwfdecTextFieldMovie {
   guint			scroll;		/* current scroll offset in lines (0-indexed) */
   guint			scroll_max;	/* scroll must be smaller than this value */
   guint			lines_visible;	/* number of lines currently visible */
-  int			hscroll;
-  int			hscroll_max;
+  guint			hscroll;	/* horizontal scrolling offset in pixels */
   gboolean		mouse_wheel_enabled;
 
   const char *		restrict_;
@@ -115,6 +114,10 @@ void		swfdec_text_field_movie_replace_text	(SwfdecTextFieldMovie *		text,
 							 guint				end_index,
 							 const char *			str);
 
+gboolean	swfdec_text_field_movie_get_visible_area(SwfdecTextFieldMovie *	text,
+							 SwfdecRectangle *	rect);
+guint		swfdec_text_field_movie_get_hscroll_max (SwfdecTextFieldMovie *	text);
+
 /* implemented in swfdec_text_field_movie_as.c */
 void		swfdec_text_field_movie_init_properties	(SwfdecAsContext *	cx);
 
@@ -123,8 +126,5 @@ void		swfdec_text_field_movie_html_parse	(SwfdecTextFieldMovie *	text,
 							 const char *		str);
 const char *	swfdec_text_field_movie_get_html_text	(SwfdecTextFieldMovie *		text);
 
-gboolean	swfdec_text_field_movie_get_visible_area(SwfdecTextFieldMovie *	text,
-							 SwfdecRectangle *	rect);
-
 G_END_DECLS
 #endif
diff --git a/swfdec/swfdec_text_field_movie_as.c b/swfdec/swfdec_text_field_movie_as.c
index 979341f..c4ac58d 100644
--- a/swfdec/swfdec_text_field_movie_as.c
+++ b/swfdec/swfdec_text_field_movie_as.c
@@ -608,8 +608,8 @@ swfdec_text_field_movie_do_set_hscroll (SwfdecAsContext *cx,
 
   SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "i", &value);
 
-  value = CLAMP (value, 0, text->hscroll_max);
-  if (value != text->hscroll) {
+  value = CLAMP (value, 0, (int) swfdec_text_field_movie_get_hscroll_max (text));
+  if ((guint) value != text->hscroll) {
     text->hscroll = value;
     text->scroll_changed = TRUE;
     swfdec_movie_invalidate_last (SWFDEC_MOVIE (text));
@@ -625,11 +625,7 @@ swfdec_text_field_movie_get_maxhscroll (SwfdecAsContext *cx,
 
   SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
 
-  if (!text->word_wrap) {
-    SWFDEC_AS_VALUE_SET_NUMBER (ret, text->hscroll_max);
-  } else {
-    SWFDEC_AS_VALUE_SET_NUMBER (ret, 0);
-  }
+  SWFDEC_AS_VALUE_SET_INT (ret, swfdec_text_field_movie_get_hscroll_max (text));
 }
 
 static void
commit 19d4208f16ba80270bafb2f3e35b7375c1e4a159
Author: Benjamin Otte <otte at gnome.org>
Date:   Fri May 9 20:50:38 2008 +0200

    add test for border scaling

diff --git a/swfdec/swfdec_text_field_movie.c b/swfdec/swfdec_text_field_movie.c
index 9ef61df..5c8cee8 100644
--- a/swfdec/swfdec_text_field_movie.c
+++ b/swfdec/swfdec_text_field_movie.c
@@ -118,7 +118,7 @@ swfdec_text_field_movie_render (SwfdecMovie *movie, cairo_t *cr,
     cairo_stroke (cr);
   }
 
-  swfdec_movie_get_visible_area (text, &area);
+  swfdec_text_field_movie_get_visible_area (text, &area);
 
   /* render the layout */
   cairo_translate (cr, area.x, area.y);
@@ -965,7 +965,7 @@ swfdec_text_field_movie_set_text (SwfdecTextFieldMovie *text, const char *str,
 }
 
 gboolean
-swfdec_movie_get_visible_area (SwfdecTextFieldMovie *text, SwfdecRectangle *rect)
+swfdec_text_field_movie_get_visible_area (SwfdecTextFieldMovie *text, SwfdecRectangle *rect)
 {
   int tmp;
 
diff --git a/swfdec/swfdec_text_field_movie.h b/swfdec/swfdec_text_field_movie.h
index b7eeb22..d0cc5f2 100644
--- a/swfdec/swfdec_text_field_movie.h
+++ b/swfdec/swfdec_text_field_movie.h
@@ -123,7 +123,7 @@ void		swfdec_text_field_movie_html_parse	(SwfdecTextFieldMovie *	text,
 							 const char *		str);
 const char *	swfdec_text_field_movie_get_html_text	(SwfdecTextFieldMovie *		text);
 
-gboolean	swfdec_movie_get_visible_area		(SwfdecTextFieldMovie *	text,
+gboolean	swfdec_text_field_movie_get_visible_area(SwfdecTextFieldMovie *	text,
 							 SwfdecRectangle *	rect);
 
 G_END_DECLS
diff --git a/test/image/Makefile.am b/test/image/Makefile.am
index 7455a0b..5667a68 100644
--- a/test/image/Makefile.am
+++ b/test/image/Makefile.am
@@ -395,6 +395,15 @@ EXTRA_DIST = \
 	text-field-border-8.swf \
 	text-field-border-8.swf.png \
 	text-field-border.as \
+	text-field-border-scale-5.swf \
+	text-field-border-scale-5.swf.png \
+	text-field-border-scale-6.swf \
+	text-field-border-scale-6.swf.png \
+	text-field-border-scale-7.swf \
+	text-field-border-scale-7.swf.png \
+	text-field-border-scale-8.swf \
+	text-field-border-scale-8.swf.png \
+	text-field-border-scale.as \
 	text-field-color-transform.as \
 	text-field-color-transform-6.swf \
 	text-field-color-transform-6.swf.png \
diff --git a/test/image/text-field-border-scale-5.swf b/test/image/text-field-border-scale-5.swf
new file mode 100644
index 0000000..e13d934
Binary files /dev/null and b/test/image/text-field-border-scale-5.swf differ
diff --git a/test/image/text-field-border-scale-5.swf.png b/test/image/text-field-border-scale-5.swf.png
new file mode 100644
index 0000000..6c3cb83
Binary files /dev/null and b/test/image/text-field-border-scale-5.swf.png differ
diff --git a/test/image/text-field-border-scale-6.swf b/test/image/text-field-border-scale-6.swf
new file mode 100644
index 0000000..82e7de2
Binary files /dev/null and b/test/image/text-field-border-scale-6.swf differ
diff --git a/test/image/text-field-border-scale-6.swf.png b/test/image/text-field-border-scale-6.swf.png
new file mode 100644
index 0000000..8e89e3f
Binary files /dev/null and b/test/image/text-field-border-scale-6.swf.png differ
diff --git a/test/image/text-field-border-scale-7.swf b/test/image/text-field-border-scale-7.swf
new file mode 100644
index 0000000..8652853
Binary files /dev/null and b/test/image/text-field-border-scale-7.swf differ
diff --git a/test/image/text-field-border-scale-7.swf.png b/test/image/text-field-border-scale-7.swf.png
new file mode 100644
index 0000000..1d97fbc
Binary files /dev/null and b/test/image/text-field-border-scale-7.swf.png differ
diff --git a/test/image/text-field-border-scale-8.swf b/test/image/text-field-border-scale-8.swf
new file mode 100644
index 0000000..238fb5e
Binary files /dev/null and b/test/image/text-field-border-scale-8.swf differ
diff --git a/test/image/text-field-border-scale-8.swf.png b/test/image/text-field-border-scale-8.swf.png
new file mode 100644
index 0000000..a6c6ab9
Binary files /dev/null and b/test/image/text-field-border-scale-8.swf.png differ
diff --git a/test/image/text-field-border-scale.as b/test/image/text-field-border-scale.as
new file mode 100644
index 0000000..954f343
--- /dev/null
+++ b/test/image/text-field-border-scale.as
@@ -0,0 +1,29 @@
+// makeswf -v 7 -s 200x150 -r 1 -o text-field-border-scale.swf text-field-border-scale.as
+
+createTextField ("s", 0, 0, 0, 90, 20);
+var tf = new TextFormat ();
+tf.font = "Bitstream Vera Sans";
+s.setNewTextFormat (tf);
+s.border = true;
+s.text = "Hello World";
+
+createTextField ("t", 1, 0, 30, 45, 20);
+t.setNewTextFormat (tf);
+t.border = true;
+t.text = "Hello World";
+t._xscale = 200;
+
+createTextField ("u", 2, 0, 60, 100, 20);
+u.setNewTextFormat (tf);
+u.border = true;
+u.text = "Hello World";
+u._xscale = 90;
+
+tf.size = 6;
+
+createTextField ("a", 10, 100, 0, 90, 10);
+a.setNewTextFormat (tf);
+a.border = true;
+a.text = "Hello World";
+a._yscale = 200;
+
commit a68487cfdcbe690f783ccd014855c067d073f7f5
Author: Benjamin Otte <otte at gnome.org>
Date:   Fri May 9 20:35:54 2008 +0200

    scale the borders

diff --git a/swfdec/swfdec_text_field_movie.c b/swfdec/swfdec_text_field_movie.c
index f7cd507..9ef61df 100644
--- a/swfdec/swfdec_text_field_movie.c
+++ b/swfdec/swfdec_text_field_movie.c
@@ -39,10 +39,10 @@
 
 G_DEFINE_TYPE (SwfdecTextFieldMovie, swfdec_text_field_movie, SWFDEC_TYPE_ACTOR)
 
-#define BORDER_TOP 1
+#define BORDER_TOP 2
 #define BORDER_LEFT 2
 #define BORDER_RIGHT 2
-#define BORDER_BOTTOM 1
+#define BORDER_BOTTOM 2
 
 /*** VFUNCS ***/
 
@@ -90,6 +90,7 @@ swfdec_text_field_movie_render (SwfdecMovie *movie, cairo_t *cr,
 {
   static const cairo_matrix_t identity = { 1, 0, 0, 1, 0, 0 };
   SwfdecTextFieldMovie *text = SWFDEC_TEXT_FIELD_MOVIE (movie);
+  SwfdecRectangle area;
   SwfdecColor color;
 
   /* textfields don't mask */
@@ -117,22 +118,14 @@ swfdec_text_field_movie_render (SwfdecMovie *movie, cairo_t *cr,
     cairo_stroke (cr);
   }
 
-  /* no more stuff to do if area too small or no text in existance */
-  if (text->stage_rect.width <= BORDER_LEFT + BORDER_RIGHT ||
-      text->stage_rect.height <= BORDER_TOP + BORDER_BOTTOM)
-    return;
+  swfdec_movie_get_visible_area (text, &area);
 
-  /* FIXME: we want to draw a cursor if there's no text, but for now... */
-  if (swfdec_text_buffer_get_length (text->text) == 0)
-    return;
   /* render the layout */
-  cairo_translate (cr, text->stage_rect.x + BORDER_LEFT, text->stage_rect.y + BORDER_TOP);
-  cairo_rectangle (cr, 0, 0, 
-      text->stage_rect.width - BORDER_LEFT - BORDER_RIGHT, 
-      text->stage_rect.height - BORDER_TOP - BORDER_BOTTOM);
+  cairo_translate (cr, area.x, area.y);
+  cairo_rectangle (cr, 0, 0, area.width, area.height);
   cairo_clip (cr);
   swfdec_text_layout_render (text->layout, cr, ctrans,
-      text->scroll, text->stage_rect.height - BORDER_TOP + BORDER_BOTTOM, &text->stage_rect);
+      text->scroll, area.height);
 }
 
 gboolean
@@ -272,9 +265,9 @@ swfdec_text_field_movie_update_area (SwfdecTextFieldMovie *text)
   /* FIXME: floor, ceil or round? */
   text->stage_rect.width = round (x) - text->stage_rect.x;
   text->stage_rect.height = round (y) - text->stage_rect.y;
-  text->xscale = matrix.xx;
-  text->yscale = matrix.yy;
-  swfdec_text_layout_set_scale (text->layout, matrix.yy * SWFDEC_TWIPS_SCALE_FACTOR);
+  text->xscale = matrix.xx * SWFDEC_TWIPS_SCALE_FACTOR;
+  text->yscale = matrix.yy * SWFDEC_TWIPS_SCALE_FACTOR;
+  swfdec_text_layout_set_scale (text->layout, text->yscale);
   if (text->word_wrap && text->stage_rect.width >= BORDER_LEFT + BORDER_RIGHT) {
     swfdec_text_layout_set_wrap_width (text->layout, text->stage_rect.width - 
 	BORDER_LEFT - BORDER_RIGHT);
@@ -970,3 +963,30 @@ swfdec_text_field_movie_set_text (SwfdecTextFieldMovie *text, const char *str,
 
   swfdec_movie_invalidate_last (SWFDEC_MOVIE (text));
 }
+
+gboolean
+swfdec_movie_get_visible_area (SwfdecTextFieldMovie *text, SwfdecRectangle *rect)
+{
+  int tmp;
+
+  g_return_val_if_fail (SWFDEC_IS_TEXT_FIELD_MOVIE (text), FALSE);
+  g_return_val_if_fail (rect != NULL, FALSE);
+
+  tmp = round ((BORDER_LEFT + BORDER_RIGHT) * text->xscale);
+  if (tmp >= text->stage_rect.width) {
+    *rect = text->stage_rect;
+    return FALSE;
+  } else {
+    rect->width = text->stage_rect.width - tmp;
+  }
+  tmp = round ((BORDER_TOP + BORDER_BOTTOM) * text->yscale);
+  if (tmp >= text->stage_rect.height) {
+    *rect = text->stage_rect;
+    return FALSE;
+  } else {
+    rect->height = text->stage_rect.height - tmp;
+  }
+  rect->x = text->stage_rect.x + round (BORDER_LEFT * text->xscale);
+  rect->y = text->stage_rect.y + round (BORDER_TOP * text->yscale) - 1;
+  return TRUE;
+}
diff --git a/swfdec/swfdec_text_field_movie.h b/swfdec/swfdec_text_field_movie.h
index aba0d7d..b7eeb22 100644
--- a/swfdec/swfdec_text_field_movie.h
+++ b/swfdec/swfdec_text_field_movie.h
@@ -123,6 +123,8 @@ void		swfdec_text_field_movie_html_parse	(SwfdecTextFieldMovie *	text,
 							 const char *		str);
 const char *	swfdec_text_field_movie_get_html_text	(SwfdecTextFieldMovie *		text);
 
+gboolean	swfdec_movie_get_visible_area		(SwfdecTextFieldMovie *	text,
+							 SwfdecRectangle *	rect);
 
 G_END_DECLS
 #endif
diff --git a/swfdec/swfdec_text_layout.c b/swfdec/swfdec_text_layout.c
index 8af09d0..632941d 100644
--- a/swfdec/swfdec_text_layout.c
+++ b/swfdec/swfdec_text_layout.c
@@ -763,14 +763,12 @@ out:
  * @ctrans: The color transform to apply.
  * @row: index of the first row to render.
  * @height: The height in pixels of the visible area.
- * @inval: The invalid area.
  *
  * Renders the contents of the layout into the given Cairo context.
  **/
 void
 swfdec_text_layout_render (SwfdecTextLayout *layout, cairo_t *cr, 
-    const SwfdecColorTransform *ctrans, guint row, guint height,
-    const SwfdecRectangle *inval)
+    const SwfdecColorTransform *ctrans, guint row, guint height)
 {
   GSequenceIter *iter;
   SwfdecTextBlock *block;
@@ -781,7 +779,6 @@ swfdec_text_layout_render (SwfdecTextLayout *layout, cairo_t *cr,
   g_return_if_fail (cr != NULL);
   g_return_if_fail (ctrans != NULL);
   g_return_if_fail (row < swfdec_text_layout_get_n_rows (layout));
-  g_return_if_fail (inval != NULL);
   
   swfdec_text_layout_ensure (layout);
 
diff --git a/swfdec/swfdec_text_layout.h b/swfdec/swfdec_text_layout.h
index 75f969f..dfb521f 100644
--- a/swfdec/swfdec_text_layout.h
+++ b/swfdec/swfdec_text_layout.h
@@ -83,8 +83,7 @@ void			swfdec_text_layout_render		(SwfdecTextLayout *	layout,
 								 cairo_t *		cr, 
 								 const SwfdecColorTransform *ctrans,
 								 guint			row,
-								 guint			height,
-								 const SwfdecRectangle *inval);
+								 guint			height);
 
 
 G_END_DECLS
commit b3be2f686f26d004a67b8adb2faa2f9033ef2544
Author: Benjamin Otte <otte at gnome.org>
Date:   Fri May 9 14:06:53 2008 +0200

    add test that ensures TextField.replaceText handles newlines correctly

diff --git a/test/trace/Makefile.am b/test/trace/Makefile.am
index d6d548c..575ef1b 100644
--- a/test/trace/Makefile.am
+++ b/test/trace/Makefile.am
@@ -2619,6 +2619,15 @@ EXTRA_DIST = \
 	removesprite-depths-6.swf.trace \
 	removesprite-depths-7.swf \
 	removesprite-depths-7.swf.trace \
+	replaceText-newline-5.swf \
+	replaceText-newline-5.swf.trace \
+	replaceText-newline-6.swf \
+	replaceText-newline-6.swf.trace \
+	replaceText-newline-7.swf \
+	replaceText-newline-7.swf.trace \
+	replaceText-newline-8.swf \
+	replaceText-newline-8.swf.trace \
+	replaceText-newline.as \
 	rewind-remove.c \
 	rewind-remove-5.swf \
 	rewind-remove-5.swf.trace \
diff --git a/test/trace/replaceText-newline-5.swf b/test/trace/replaceText-newline-5.swf
new file mode 100644
index 0000000..b615a37
Binary files /dev/null and b/test/trace/replaceText-newline-5.swf differ
diff --git a/test/trace/replaceText-newline-5.swf.trace b/test/trace/replaceText-newline-5.swf.trace
new file mode 100644
index 0000000..7c44e9f
--- /dev/null
+++ b/test/trace/replaceText-newline-5.swf.trace
@@ -0,0 +1,3 @@
+ ()
+ ()
+ ()
diff --git a/test/trace/replaceText-newline-6.swf b/test/trace/replaceText-newline-6.swf
new file mode 100644
index 0000000..f3e06a1
Binary files /dev/null and b/test/trace/replaceText-newline-6.swf differ
diff --git a/test/trace/replaceText-newline-6.swf.trace b/test/trace/replaceText-newline-6.swf.trace
new file mode 100644
index 0000000..34989a2
--- /dev/null
+++ b/test/trace/replaceText-newline-6.swf.trace
@@ -0,0 +1,3 @@
+ab (3)
+ab (3)
+ab (3)
diff --git a/test/trace/replaceText-newline-7.swf b/test/trace/replaceText-newline-7.swf
new file mode 100644
index 0000000..314454b
Binary files /dev/null and b/test/trace/replaceText-newline-7.swf differ
diff --git a/test/trace/replaceText-newline-7.swf.trace b/test/trace/replaceText-newline-7.swf.trace
new file mode 100644
index 0000000..99d9098
--- /dev/null
+++ b/test/trace/replaceText-newline-7.swf.trace
@@ -0,0 +1,3 @@
+ab (3)
+a\rcb (5)
+ad\rcb (7)
diff --git a/test/trace/replaceText-newline-8.swf b/test/trace/replaceText-newline-8.swf
new file mode 100644
index 0000000..17ab837
Binary files /dev/null and b/test/trace/replaceText-newline-8.swf differ
diff --git a/test/trace/replaceText-newline-8.swf.trace b/test/trace/replaceText-newline-8.swf.trace
new file mode 100644
index 0000000..99d9098
--- /dev/null
+++ b/test/trace/replaceText-newline-8.swf.trace
@@ -0,0 +1,3 @@
+ab (3)
+a\rcb (5)
+ad\rcb (7)
diff --git a/test/trace/replaceText-newline.as b/test/trace/replaceText-newline.as
new file mode 100644
index 0000000..51c7a52
--- /dev/null
+++ b/test/trace/replaceText-newline.as
@@ -0,0 +1,22 @@
+// makeswf -v 7 -s 200x150 -r 1 -o replaceText-newline.swf replaceText-newline.as
+
+createTextField ("t", 0, 0, 0, 100, 150);
+var tf = new TextFormat ();
+tf.font = "Bitstream Vera Sans";
+t.setNewTextFormat (tf);
+t.border = true;
+
+function sanitize (str) {
+  var a = str.split ("\r");
+  return a.join ("\\r");
+};
+
+t.html = true;
+t.htmlText = "a\rb";
+trace (sanitize (t.text) + " (" + t.length + ")");
+t.replaceText (1, 1, "\nc");
+trace (sanitize (t.text) + " (" + t.length + ")");
+t.replaceText (1, 1, "\rd");
+trace (sanitize (t.text) + " (" + t.length + ")");
+
+getURL ("fscommand:quit", "");
commit 9229698a6392bc427e50f61f89fda44cec9c6b69
Author: Benjamin Otte <otte at gnome.org>
Date:   Fri May 9 13:49:21 2008 +0200

    redo \r and \n handling
    
    We now treat \r as an invisible line break and \n as a visible line break.
    "vivisbile" in this context means that they will produce output when querying
    text variables: \n will result in a <p> or \r in the output, \r will not
    result in any output.

diff --git a/swfdec/swfdec_text_field_movie.c b/swfdec/swfdec_text_field_movie.c
index e7fa1fb..f7cd507 100644
--- a/swfdec/swfdec_text_field_movie.c
+++ b/swfdec/swfdec_text_field_movie.c
@@ -865,25 +865,33 @@ swfdec_text_field_movie_set_listen_variable (SwfdecTextFieldMovie *text,
 const char *
 swfdec_text_field_movie_get_text (SwfdecTextFieldMovie *text)
 {
-  char *str, *p;
-
-  str = g_strdup (swfdec_text_buffer_get_text (text->text));
-
-  // if input was orginally html, remove all \r
-  if (text->input_html) {
-    p = str;
-    while ((p = strchr (p, '\r')) != NULL) {
-      memmove (p, p + 1, strlen (p));
-    }
-  }
-
-  // change all \n to \r
-  p = str;
+  char *ret, *p;
+  const char *org;
+  gsize filled, len;
+
+  org = swfdec_text_buffer_get_text (text->text);
+  len = swfdec_text_buffer_get_length (text->text);
+
+  ret = g_new (char, len + 1);
+  /* remove all \r */
+  filled = 0;
+  while ((p = strchr (org, '\r'))) {
+    memcpy (ret + filled, org, p - org);
+    filled += p - org;
+    org = p + 1;
+    len--;
+  }
+  g_assert (len >= filled);
+  memcpy (ret + filled, org, len - filled);
+  ret[len] = 0;
+
+  /* change all \n to \r */
+  p = ret;
   while ((p = strchr (p, '\n')) != NULL) {
     *p = '\r';
   }
 
-  return swfdec_as_context_give_string (SWFDEC_AS_OBJECT (text)->context, str);
+  return swfdec_as_context_give_string (SWFDEC_AS_OBJECT (text)->context, ret);
 }
 
 void
@@ -939,8 +947,6 @@ swfdec_text_field_movie_set_text (SwfdecTextFieldMovie *text, const char *str,
   swfdec_text_buffer_set_attributes (text->text, 0, 0, &text->default_attributes,
       SWFDEC_TEXT_ATTRIBUTES_MASK);
 
-  text->input_html = html;
-
   if (SWFDEC_AS_OBJECT (text)->context->version >= 7 &&
       text->style_sheet != NULL)
   {
@@ -953,7 +959,12 @@ swfdec_text_field_movie_set_text (SwfdecTextFieldMovie *text, const char *str,
     if (html) {
       swfdec_text_field_movie_html_parse (text, str);
     } else {
-      swfdec_text_buffer_insert_text (text->text, 0, str);
+      char *s, *p;
+      s = p = g_strdup (str);
+      while ((p = strchr (p, '\r')))
+	*p = '\n';
+      swfdec_text_buffer_insert_text (text->text, 0, s);
+      g_free (s);
     }
   }
 
diff --git a/swfdec/swfdec_text_field_movie.h b/swfdec/swfdec_text_field_movie.h
index 6789432..aba0d7d 100644
--- a/swfdec/swfdec_text_field_movie.h
+++ b/swfdec/swfdec_text_field_movie.h
@@ -61,7 +61,6 @@ struct _SwfdecTextFieldMovie {
   gboolean		background;
  
   SwfdecTextBuffer *	text;		/* the text + formatting */
-  gboolean		input_html;	/* whether orginal input was given as HTML */
 
   SwfdecTextLayout *	layout;		/* the layouted text */
   guint			layout_width;	/* text width in pixels */


More information about the Swfdec-commits mailing list