[Swfdec] 11 commits - libswfdec/swfdec_as_strings.c libswfdec/swfdec_text_field.c libswfdec/swfdec_text_field.h libswfdec/swfdec_text_field_movie_as.c libswfdec/swfdec_text_field_movie.c libswfdec/swfdec_text_field_movie.h test/trace

Pekka Lampila medar at kemper.freedesktop.org
Thu Oct 18 04:23:57 PDT 2007


 libswfdec/swfdec_as_strings.c            |    4 
 libswfdec/swfdec_text_field.c            |    1 
 libswfdec/swfdec_text_field.h            |   34 ---
 libswfdec/swfdec_text_field_movie.c      |  265 ++++++++++++++++---------------
 libswfdec/swfdec_text_field_movie.h      |   47 ++++-
 libswfdec/swfdec_text_field_movie_as.c   |  115 +++++++++++--
 test/trace/Makefile.am                   |   17 +
 test/trace/text-field-scroll-5.swf       |binary
 test/trace/text-field-scroll-5.swf.trace |   54 ++++++
 test/trace/text-field-scroll-6.swf       |binary
 test/trace/text-field-scroll-6.swf.trace |   48 +++++
 test/trace/text-field-scroll-7.swf       |binary
 test/trace/text-field-scroll-7.swf.trace |   54 ++++++
 test/trace/text-field-scroll-8.swf       |binary
 test/trace/text-field-scroll-8.swf.trace |   54 ++++++
 test/trace/text-field-scroll.as          |   84 +++++++++
 16 files changed, 595 insertions(+), 182 deletions(-)

New commits:
commit 7a7c57b5c37865db3ae98b61369ad06f0ff80c4a
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Thu Oct 18 14:08:14 2007 +0300

    Add a test case for TextField's scrolling properties
    
    Part of it is commented out in version 6 at the moment

diff --git a/test/trace/Makefile.am b/test/trace/Makefile.am
index 2384a8e..945ee2e 100644
--- a/test/trace/Makefile.am
+++ b/test/trace/Makefile.am
@@ -1,4 +1,4 @@
-check_PROGRAMS = trace
+check_PROGRAMS = trace thumb
 
 TESTS = $(check_PROGRAMS)
 
@@ -6,12 +6,18 @@ trace_SOURCES = \
 	swfdec_interaction.c \
 	trace.c
 
+thumb_SOURCES = \
+	thumb.c
+
 noinst_HEADERS = \
 	swfdec_interaction.h
 
 trace_CFLAGS = $(GLOBAL_CFLAGS) $(SWFDEC_CFLAGS) $(CAIRO_CFLAGS) $(GTHREAD_CFLAGS)
 trace_LDFLAGS = $(SWFDEC_LIBS) $(CAIRO_LIBS) $(GTHREAD_LIBS)
 
+thumb_CFLAGS = $(GLOBAL_CFLAGS) $(SWFDEC_CFLAGS) $(CAIRO_CFLAGS)
+thumb_LDFLAGS = $(SWFDEC_LIBS) $(CAIRO_LIBS)
+
 EXTRA_DIST = \
 	README \
 	abort-really-aborts.as \
@@ -1850,6 +1856,15 @@ EXTRA_DIST = \
 	text-field-length-7.swf.trace \
 	text-field-length-8.swf \
 	text-field-length-8.swf.trace \
+	text-field-scroll.as \
+	text-field-scroll-5.swf \
+	text-field-scroll-5.swf.trace \
+	text-field-scroll-6.swf \
+	text-field-scroll-6.swf.trace \
+	text-field-scroll-7.swf \
+	text-field-scroll-7.swf.trace \
+	text-field-scroll-8.swf \
+	text-field-scroll-8.swf.trace \
 	text-field-values.as \
 	text-field-values-5.swf \
 	text-field-values-5.swf.trace \
diff --git a/test/trace/text-field-scroll-5.swf b/test/trace/text-field-scroll-5.swf
new file mode 100644
index 0000000..2798fa9
Binary files /dev/null and b/test/trace/text-field-scroll-5.swf differ
diff --git a/test/trace/text-field-scroll-5.swf.trace b/test/trace/text-field-scroll-5.swf.trace
new file mode 100644
index 0000000..91239a2
--- /dev/null
+++ b/test/trace/text-field-scroll-5.swf.trace
@@ -0,0 +1,54 @@
+# EMPTY
+bottomScroll: 
+hscroll: 
+maxhscroll: 
+maxscroll: 
+scroll: 
+# WITH TEXT
+bottomScroll: 
+hscroll: 200
+maxhscroll: 
+maxscroll: 
+scroll: 3
+# WITH WORD WRAP
+bottomScroll: 
+hscroll: 200
+maxhscroll: 
+maxscroll: 
+scroll: 3
+# WITHOUT WORD WRAP
+bottomScroll: 
+hscroll: 200
+maxhscroll: 
+maxscroll: 
+scroll: 3
+# WITH WORD WRAP - SCROLL RESET
+bottomScroll: 
+hscroll: 200
+maxhscroll: 
+maxscroll: 
+scroll: 3
+# WITH WORD WRAP - FORMAT RESET
+bottomScroll: 
+hscroll: 200
+maxhscroll: 
+maxscroll: 
+scroll: 3
+# WITH WORD WRAP - TEXT RESET
+bottomScroll: 
+hscroll: 200
+maxhscroll: 
+maxscroll: 
+scroll: 3
+# WITHOUT WORD WRAP - FORMAT RESET
+bottomScroll: 
+hscroll: 200
+maxhscroll: 
+maxscroll: 
+scroll: 30
+# WITHOUT WORD WRAP - TEXT RESET
+bottomScroll: 
+hscroll: 200
+maxhscroll: 
+maxscroll: 
+scroll: 30
diff --git a/test/trace/text-field-scroll-6.swf b/test/trace/text-field-scroll-6.swf
new file mode 100644
index 0000000..6fc812f
Binary files /dev/null and b/test/trace/text-field-scroll-6.swf differ
diff --git a/test/trace/text-field-scroll-6.swf.trace b/test/trace/text-field-scroll-6.swf.trace
new file mode 100644
index 0000000..f70c3a5
--- /dev/null
+++ b/test/trace/text-field-scroll-6.swf.trace
@@ -0,0 +1,48 @@
+# EMPTY
+bottomScroll: 1
+hscroll: 0
+maxhscroll: 0
+maxscroll: 1
+scroll: 1
+# WITH TEXT
+bottomScroll: 8
+hscroll: 200
+maxhscroll: ~500
+maxscroll: 11
+scroll: 3
+# WITH WORD WRAP
+bottomScroll: 8
+hscroll: 200
+maxhscroll: 0
+maxscroll: 11
+scroll: 3
+# WITHOUT WORD WRAP
+bottomScroll: 8
+hscroll: 200
+maxhscroll: ~500
+maxscroll: 11
+scroll: 3
+# WITH WORD WRAP - SCROLL RESET
+bottomScroll: 8
+hscroll: 200
+maxhscroll: 0
+maxscroll: 11
+scroll: 3
+# WITH WORD WRAP - TEXT RESET
+bottomScroll: 8
+hscroll: 0
+maxhscroll: 0
+maxscroll: 79
+scroll: 3
+# WITHOUT WORD WRAP - FORMAT RESET
+bottomScroll: 30
+hscroll: 0
+maxhscroll: ~500
+maxscroll: 11
+scroll: 30
+# WITHOUT WORD WRAP - TEXT RESET
+bottomScroll: 16
+hscroll: 0
+maxhscroll: ~500
+maxscroll: 11
+scroll: 11
diff --git a/test/trace/text-field-scroll-7.swf b/test/trace/text-field-scroll-7.swf
new file mode 100644
index 0000000..b36d45b
Binary files /dev/null and b/test/trace/text-field-scroll-7.swf differ
diff --git a/test/trace/text-field-scroll-7.swf.trace b/test/trace/text-field-scroll-7.swf.trace
new file mode 100644
index 0000000..903af5c
--- /dev/null
+++ b/test/trace/text-field-scroll-7.swf.trace
@@ -0,0 +1,54 @@
+# EMPTY
+bottomScroll: 1
+hscroll: 0
+maxhscroll: 0
+maxscroll: 1
+scroll: 1
+# WITH TEXT
+bottomScroll: 8
+hscroll: 200
+maxhscroll: ~500
+maxscroll: 11
+scroll: 3
+# WITH WORD WRAP
+bottomScroll: 8
+hscroll: 200
+maxhscroll: 0
+maxscroll: 11
+scroll: 3
+# WITHOUT WORD WRAP
+bottomScroll: 8
+hscroll: 200
+maxhscroll: ~500
+maxscroll: 11
+scroll: 3
+# WITH WORD WRAP - SCROLL RESET
+bottomScroll: 8
+hscroll: 200
+maxhscroll: 0
+maxscroll: 11
+scroll: 3
+# WITH WORD WRAP - FORMAT RESET
+bottomScroll: 8
+hscroll: 200
+maxhscroll: 0
+maxscroll: 79
+scroll: 3
+# WITH WORD WRAP - TEXT RESET
+bottomScroll: 8
+hscroll: 0
+maxhscroll: 0
+maxscroll: 79
+scroll: 3
+# WITHOUT WORD WRAP - FORMAT RESET
+bottomScroll: 30
+hscroll: 0
+maxhscroll: ~500
+maxscroll: 11
+scroll: 30
+# WITHOUT WORD WRAP - TEXT RESET
+bottomScroll: 16
+hscroll: 0
+maxhscroll: ~500
+maxscroll: 11
+scroll: 11
diff --git a/test/trace/text-field-scroll-8.swf b/test/trace/text-field-scroll-8.swf
new file mode 100644
index 0000000..964bd2a
Binary files /dev/null and b/test/trace/text-field-scroll-8.swf differ
diff --git a/test/trace/text-field-scroll-8.swf.trace b/test/trace/text-field-scroll-8.swf.trace
new file mode 100644
index 0000000..903af5c
--- /dev/null
+++ b/test/trace/text-field-scroll-8.swf.trace
@@ -0,0 +1,54 @@
+# EMPTY
+bottomScroll: 1
+hscroll: 0
+maxhscroll: 0
+maxscroll: 1
+scroll: 1
+# WITH TEXT
+bottomScroll: 8
+hscroll: 200
+maxhscroll: ~500
+maxscroll: 11
+scroll: 3
+# WITH WORD WRAP
+bottomScroll: 8
+hscroll: 200
+maxhscroll: 0
+maxscroll: 11
+scroll: 3
+# WITHOUT WORD WRAP
+bottomScroll: 8
+hscroll: 200
+maxhscroll: ~500
+maxscroll: 11
+scroll: 3
+# WITH WORD WRAP - SCROLL RESET
+bottomScroll: 8
+hscroll: 200
+maxhscroll: 0
+maxscroll: 11
+scroll: 3
+# WITH WORD WRAP - FORMAT RESET
+bottomScroll: 8
+hscroll: 200
+maxhscroll: 0
+maxscroll: 79
+scroll: 3
+# WITH WORD WRAP - TEXT RESET
+bottomScroll: 8
+hscroll: 0
+maxhscroll: 0
+maxscroll: 79
+scroll: 3
+# WITHOUT WORD WRAP - FORMAT RESET
+bottomScroll: 30
+hscroll: 0
+maxhscroll: ~500
+maxscroll: 11
+scroll: 30
+# WITHOUT WORD WRAP - TEXT RESET
+bottomScroll: 16
+hscroll: 0
+maxhscroll: ~500
+maxscroll: 11
+scroll: 11
diff --git a/test/trace/text-field-scroll.as b/test/trace/text-field-scroll.as
new file mode 100644
index 0000000..78e65f5
--- /dev/null
+++ b/test/trace/text-field-scroll.as
@@ -0,0 +1,84 @@
+// makeswf -v 7 -r 1 -o test-7.swf test.as
+
+function trace_scroll_properties () {
+  trace ("bottomScroll: " + t.bottomScroll);
+  trace ("hscroll: " + t.hscroll);
+  if (t.maxhscroll > 100) {
+    trace ("maxhscroll: ~" + (t.maxhscroll - t.maxhscroll % 100));
+  } else {
+    trace ("maxhscroll: " + t.maxhscroll);
+  }
+  trace ("maxscroll: " + t.maxscroll);
+  trace ("scroll: " + t.scroll);
+}
+
+this.createTextField ("t", 1, 0, 0, 100, 100);
+
+var fmt = new TextFormat ();
+fmt.size = 14;
+t.setNewTextFormat (fmt);
+
+trace ("# EMPTY");
+trace_scroll_properties ();
+
+trace ("# WITH TEXT");
+
+t.text = "asdfo jsofa jsapofjpsajf pjsadpfjsapf josapof jsafjposajf pjsapfj dposajf pojsap fjpasjpfjdsap jfpsajpfd jsapjfdpsajfjpsdajfp\r aposdjf jsapofj\r posajp posaj fsa jfdsapof jposaj fjsapofd paposdjf dsaj\r pfjsapd jpdsaj joasf jpoasjpfjdpsajfpsaj pfposa jfpsaj pfjdapsjfpajp\rasdfo jsofa jsapofjpsajf pjsadpfjsapf josapof jsafjposajf pjsapfj dposajf pojsap fjpasjpfjdsap jfpsajpfd jsapjfdpsajfjpsdajfp\r aposdjf jsapofj\r posajp posaj fsa jfdsapof jposaj fjsapofd paposdjf dsaj\r pfjsapd jpdsaj joasf jpoasjpfjdpsajfpsaj pfposa jfpsaj pfjdapsjfpajp\rasdfo jsofa jsapofjpsajf pjsadpfjsapf josapof jsafjposajf pjsapfj dposajf pojsap fjpasjpfjdsap jfpsajpfd jsapjfdpsajfjpsdajfp\r aposdjf jsapofj\r posajp posaj fsa jfdsapof jposaj fjsapofd paposdjf dsaj\r pfjsapd jpdsaj joasf jpoasjpfjdpsajfpsaj pfposa jfpsaj pfjdapsjfpajp\rasdfo jsofa jsapofjpsajf pjsadpfjsapf josapof jsafjposajf pjsapfj dposajf pojsap fjpasjpfjdsap jfpsajpfd jsapjfdpsajfjpsdajfp\r aposdjf jsapofj\r posajp posaj fsa jfdsapof jposaj fjsapofd paposdjf dsaj\r pfjsapd jpdsaj joasf jpoasjpfjdpsajfpsaj pfposa jfpsaj pfjdapsjfpajp";
+
+t.scroll = 3;
+t.hscroll = 200;
+
+trace_scroll_properties ();
+
+trace ("# WITH WORD WRAP");
+
+t.wordWrap = true;
+
+trace_scroll_properties ();
+
+trace ("# WITHOUT WORD WRAP");
+
+t.wordWrap = false;
+
+trace_scroll_properties ();
+
+trace ("# WITH WORD WRAP - SCROLL RESET");
+
+t.wordWrap = true;
+t.scroll = 3;
+
+trace_scroll_properties ();
+
+// FIXME: version 6 gives crazy value for maxscroll here
+#if __SWF_VERSION__ != 6
+trace ("# WITH WORD WRAP - FORMAT RESET");
+
+var fmt = new TextFormat ();
+t.setTextFormat (fmt);
+
+trace_scroll_properties ();
+#endif
+
+trace ("# WITH WORD WRAP - TEXT RESET");
+
+t.text = t.text;
+
+trace_scroll_properties ();
+
+t.scroll = 30;
+
+trace ("# WITHOUT WORD WRAP - FORMAT RESET");
+
+t.wordWrap = false;
+var fmt = new TextFormat ();
+t.setTextFormat (fmt);
+
+trace_scroll_properties ();
+
+trace ("# WITHOUT WORD WRAP - TEXT RESET");
+
+t.text = t.text;
+
+trace_scroll_properties ();
+
+loadMovie ("FSCommand:quit", "");
commit 54f5a8f4d82a2e01c8c2f2391cd682cc15a562e5
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Thu Oct 18 13:54:54 2007 +0300

    More TextField's scroll properties compatibility fixes

diff --git a/libswfdec/swfdec_text_field_movie.c b/libswfdec/swfdec_text_field_movie.c
index 4a91792..5cfc7dd 100644
--- a/libswfdec/swfdec_text_field_movie.c
+++ b/libswfdec/swfdec_text_field_movie.c
@@ -679,7 +679,8 @@ swfdec_text_field_movie_render (SwfdecMovie *movie, cairo_t *cr,
 }
 
 void
-swfdec_text_field_movie_update_scroll (SwfdecTextFieldMovie *text)
+swfdec_text_field_movie_update_scroll (SwfdecTextFieldMovie *text,
+    gboolean check_limits)
 {
   SwfdecLayout *layouts;
   int i, num, y, visible, all, height;
@@ -729,11 +730,16 @@ swfdec_text_field_movie_update_scroll (SwfdecTextFieldMovie *text)
   layouts = NULL;
 
   text->scroll_max = all - visible + 1;
-  text->scroll = CLAMP(text->scroll, 1, text->scroll_max);
-  text->scroll_bottom = text->scroll + (visible > 0 ? visible - 1 : 0);
-
   text->hscroll_max = SWFDEC_TWIPS_TO_DOUBLE (width_max - width);
-  text->hscroll = CLAMP(text->hscroll, 0, text->hscroll_max);
+
+  if (check_limits) {
+    text->scroll = CLAMP(text->scroll, 1, text->scroll_max);
+    text->scroll_bottom = text->scroll + (visible > 0 ? visible - 1 : 0);
+    text->hscroll = CLAMP(text->hscroll, 0, text->hscroll_max);
+  } else {
+    text->scroll_bottom = MAX (CLAMP(text->scroll, 1, text->scroll_max) +
+      (visible > 0 ? visible - 1 : 0), text->scroll);
+  }
 }
 
 gboolean
@@ -1018,7 +1024,8 @@ swfdec_text_field_movie_set_text_format (SwfdecTextFieldMovie *text,
 
   swfdec_movie_invalidate (SWFDEC_MOVIE (text));
   swfdec_text_field_movie_auto_size (text);
-  swfdec_text_field_movie_update_scroll (text);
+  // special case: update the max values, not the current values
+  swfdec_text_field_movie_update_scroll (text, FALSE);
 }
 
 static void
@@ -1465,5 +1472,5 @@ swfdec_text_field_movie_set_text (SwfdecTextFieldMovie *text, const char *str,
 
   swfdec_movie_invalidate (SWFDEC_MOVIE (text));
   swfdec_text_field_movie_auto_size (text);
-  swfdec_text_field_movie_update_scroll (text);
+  swfdec_text_field_movie_update_scroll (text, TRUE);
 }
diff --git a/libswfdec/swfdec_text_field_movie.h b/libswfdec/swfdec_text_field_movie.h
index 56c81cb..5555156 100644
--- a/libswfdec/swfdec_text_field_movie.h
+++ b/libswfdec/swfdec_text_field_movie.h
@@ -120,7 +120,8 @@ void		swfdec_text_field_movie_set_text		(SwfdecTextFieldMovie *	movie,
 							 const char *		str,
 							 gboolean		html);
 gboolean	swfdec_text_field_movie_auto_size	(SwfdecTextFieldMovie *	text);
-void		swfdec_text_field_movie_update_scroll	(SwfdecTextFieldMovie *	text);
+void		swfdec_text_field_movie_update_scroll	(SwfdecTextFieldMovie *	text,
+							 gboolean		check_limits);
 void		swfdec_text_field_movie_set_text_format	(SwfdecTextFieldMovie *	text,
 							 SwfdecTextFormat *	format,
 							 guint			start_index,
diff --git a/libswfdec/swfdec_text_field_movie_as.c b/libswfdec/swfdec_text_field_movie_as.c
index 7a82477..b71fc77 100644
--- a/libswfdec/swfdec_text_field_movie_as.c
+++ b/libswfdec/swfdec_text_field_movie_as.c
@@ -638,6 +638,7 @@ swfdec_text_field_movie_do_set_scroll (SwfdecAsContext *cx,
 
   value = CLAMP (value, 1, text->scroll_max);
   if (value != text->scroll) {
+    text->scroll_bottom += value - text->scroll;
     text->scroll = value;
     swfdec_movie_invalidate (SWFDEC_MOVIE (text));
   }
commit 4af53a00442c9ba8a35979cb3641566bdc106a42
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Thu Oct 18 13:22:44 2007 +0300

    Make TextField's scroll properties more compatible
    
    Remove swfdec_text_field_movie_changed function and make other places call the
    required invalidate, auto_size and scroll property fixing functions themselves

diff --git a/libswfdec/swfdec_text_field_movie.c b/libswfdec/swfdec_text_field_movie.c
index 36a3801..4a91792 100644
--- a/libswfdec/swfdec_text_field_movie.c
+++ b/libswfdec/swfdec_text_field_movie.c
@@ -679,8 +679,7 @@ swfdec_text_field_movie_render (SwfdecMovie *movie, cairo_t *cr,
 }
 
 void
-swfdec_text_field_movie_get_scroll_info (SwfdecTextFieldMovie *text,
-    int *scroll_last, int *scroll_max, int *hscroll_last, int *hscroll_max)
+swfdec_text_field_movie_update_scroll (SwfdecTextFieldMovie *text)
 {
   SwfdecLayout *layouts;
   int i, num, y, visible, all, height;
@@ -729,66 +728,20 @@ swfdec_text_field_movie_get_scroll_info (SwfdecTextFieldMovie *text,
   swfdec_text_field_movie_free_layouts (layouts);
   layouts = NULL;
 
-  if (scroll_last)
-    *scroll_last = text->scroll + (visible > 0 ? visible - 1 : 0);
-  if (scroll_max)
-    *scroll_max = all - visible + 1;
+  text->scroll_max = all - visible + 1;
+  text->scroll = CLAMP(text->scroll, 1, text->scroll_max);
+  text->scroll_bottom = text->scroll + (visible > 0 ? visible - 1 : 0);
 
-  if (hscroll_last)
-    *hscroll_last = text->hscroll + SWFDEC_TWIPS_TO_DOUBLE (width);
-  if (hscroll_max)
-    *hscroll_max = SWFDEC_TWIPS_TO_DOUBLE (width_max - width);
+  text->hscroll_max = SWFDEC_TWIPS_TO_DOUBLE (width_max - width);
+  text->hscroll = CLAMP(text->hscroll, 0, text->hscroll_max);
 }
 
-void
-swfdec_text_field_movie_set_scroll (SwfdecTextFieldMovie *text, int value)
-{
-  g_return_if_fail (SWFDEC_IS_TEXT_FIELD_MOVIE (text));
-
-  if (value <= 1) {
-    value = 1;
-  } else {
-    int max;
-
-    swfdec_text_field_movie_get_scroll_info (text, NULL, &max, NULL, NULL);
-    if (value > max)
-      value = max;
-  }
-
-  if (text->scroll != value) {
-    text->scroll = value;
-    swfdec_movie_invalidate (SWFDEC_MOVIE (text));
-  }
-}
-
-void
-swfdec_text_field_movie_set_hscroll (SwfdecTextFieldMovie *text, int value)
-{
-  g_return_if_fail (SWFDEC_IS_TEXT_FIELD_MOVIE (text));
-
-  if (value <= 0) {
-    value = 0;
-  } else {
-    int max;
-
-    swfdec_text_field_movie_get_scroll_info (text, NULL, NULL, NULL, &max);
-    if (value > max)
-      value = max;
-  }
-
-  if (text->hscroll != value) {
-    text->hscroll = value;
-    swfdec_movie_invalidate (SWFDEC_MOVIE (text));
-  }
-}
-
-static gboolean
+gboolean
 swfdec_text_field_movie_auto_size (SwfdecTextFieldMovie *text)
 {
   SwfdecLayout *layouts;
   guint height;
   int i, width, diff;
-  gboolean changed;
 
   g_return_val_if_fail (SWFDEC_IS_TEXT_FIELD_MOVIE (text), FALSE);
 
@@ -811,6 +764,14 @@ swfdec_text_field_movie_auto_size (SwfdecTextFieldMovie *text)
   swfdec_text_field_movie_free_layouts (layouts);
   layouts = NULL;
 
+  if ((text->text->word_wrap || SWFDEC_MOVIE (text)->original_extents.x1 -
+      SWFDEC_MOVIE (text)->original_extents.x0 == width) &&
+      (SWFDEC_GRAPHIC (text->text)->extents.y1 -
+	SWFDEC_GRAPHIC (text->text)->extents.y0 == height))
+    return FALSE;
+
+  swfdec_movie_invalidate (SWFDEC_MOVIE (text));
+
   if (!text->text->word_wrap && SWFDEC_MOVIE (text)->original_extents.x1 -
       SWFDEC_MOVIE (text)->original_extents.x0 != width)
   {
@@ -832,7 +793,6 @@ swfdec_text_field_movie_auto_size (SwfdecTextFieldMovie *text)
       default:
 	g_assert_not_reached ();
     }
-    changed = TRUE;
   }
 
   if (SWFDEC_GRAPHIC (text->text)->extents.y1 -
@@ -840,24 +800,12 @@ swfdec_text_field_movie_auto_size (SwfdecTextFieldMovie *text)
   {
     SWFDEC_GRAPHIC (text->text)->extents.y1 =
       SWFDEC_GRAPHIC (text->text)->extents.y0 + height;
-    changed = TRUE;
   }
 
-  return changed;
-}
+  swfdec_movie_queue_update (SWFDEC_MOVIE (text),
+      SWFDEC_MOVIE_INVALID_CONTENTS);
 
-void
-swfdec_text_field_movie_changed (SwfdecTextFieldMovie *text)
-{
-  swfdec_movie_invalidate (SWFDEC_MOVIE (text));
-
-  if (swfdec_text_field_movie_auto_size (text)) {
-    swfdec_movie_queue_update (SWFDEC_MOVIE (text),
-	SWFDEC_MOVIE_INVALID_CONTENTS);
-  }
-
-  swfdec_text_field_movie_set_scroll (text, text->scroll);
-  swfdec_text_field_movie_set_hscroll (text, text->hscroll);
+  return TRUE;
 }
 
 static void
@@ -1068,7 +1016,9 @@ swfdec_text_field_movie_set_text_format (SwfdecTextFieldMovie *text,
     }
   }
 
-  swfdec_text_field_movie_changed (text);
+  swfdec_movie_invalidate (SWFDEC_MOVIE (text));
+  swfdec_text_field_movie_auto_size (text);
+  swfdec_text_field_movie_update_scroll (text);
 }
 
 static void
@@ -1513,5 +1463,7 @@ swfdec_text_field_movie_set_text (SwfdecTextFieldMovie *text, const char *str,
     }
   }
 
-  swfdec_text_field_movie_changed (text);
+  swfdec_movie_invalidate (SWFDEC_MOVIE (text));
+  swfdec_text_field_movie_auto_size (text);
+  swfdec_text_field_movie_update_scroll (text);
 }
diff --git a/libswfdec/swfdec_text_field_movie.h b/libswfdec/swfdec_text_field_movie.h
index f862c0b..56c81cb 100644
--- a/libswfdec/swfdec_text_field_movie.h
+++ b/libswfdec/swfdec_text_field_movie.h
@@ -93,7 +93,10 @@ struct _SwfdecTextFieldMovie {
   SwfdecStyleSheet *	style_sheet;
 
   int			scroll;
+  int			scroll_max;
+  int			scroll_bottom;
   int			hscroll;
+  int			hscroll_max;
   gboolean		mouse_wheel_enabled;
 
   const char *		restrict_;
@@ -116,20 +119,12 @@ GType		swfdec_text_field_movie_get_type		(void);
 void		swfdec_text_field_movie_set_text		(SwfdecTextFieldMovie *	movie,
 							 const char *		str,
 							 gboolean		html);
-void		swfdec_text_field_movie_changed		(SwfdecTextFieldMovie *	text);
+gboolean	swfdec_text_field_movie_auto_size	(SwfdecTextFieldMovie *	text);
+void		swfdec_text_field_movie_update_scroll	(SwfdecTextFieldMovie *	text);
 void		swfdec_text_field_movie_set_text_format	(SwfdecTextFieldMovie *	text,
 							 SwfdecTextFormat *	format,
 							 guint			start_index,
 							 guint			end_index);
-void		swfdec_text_field_movie_get_scroll_info	(SwfdecTextFieldMovie *	text,
-							 int *			scroll_last,
-							 int *			scroll_max,
-							 int *			hscroll_last,
-							 int *			hscroll_max);
-void		swfdec_text_field_movie_set_scroll	(SwfdecTextFieldMovie *	text,
-							 int			value);
-void		swfdec_text_field_movie_set_hscroll	(SwfdecTextFieldMovie *	text,
-							 int			value);
 const char *	swfdec_text_field_movie_get_html_text	(SwfdecTextFieldMovie *		text);
 void		swfdec_text_field_movie_set_listen_variable (SwfdecTextFieldMovie *	text,
 							 const char *			value);
diff --git a/libswfdec/swfdec_text_field_movie_as.c b/libswfdec/swfdec_text_field_movie_as.c
index 9d5c71c..7a82477 100644
--- a/libswfdec/swfdec_text_field_movie_as.c
+++ b/libswfdec/swfdec_text_field_movie_as.c
@@ -116,6 +116,8 @@ swfdec_text_field_movie_set_html (SwfdecAsContext *cx, SwfdecAsObject *object,
   swfdec_as_value_to_number (cx, &argv[0]);
 
   text->text->html = value;
+
+  // FIXME: resize? invalidate?
 }
 
 static void
@@ -312,7 +314,7 @@ swfdec_text_field_movie_set_selectable (SwfdecAsContext *cx,
 
   text->text->selectable = value;
 
-  // FIXME: If selection made and removing selectable force redraw?
+  // FIXME: invalidate
 }
 
 static void
@@ -349,6 +351,8 @@ swfdec_text_field_movie_do_set_type (SwfdecAsContext *cx,
   } else if (!g_strcasecmp (value, SWFDEC_AS_STR_dynamic)) {
     text->text->input = FALSE;
   }
+
+  // FIXME: invalidate
 }
 
 static void
@@ -520,12 +524,10 @@ swfdec_text_field_movie_get_bottomScroll (SwfdecAsContext *cx,
     SwfdecAsValue *ret)
 {
   SwfdecTextFieldMovie *text;
-  int last;
 
   SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
 
-  swfdec_text_field_movie_get_scroll_info (text, &last, NULL, NULL, NULL);
-  SWFDEC_AS_VALUE_SET_NUMBER (ret, last);
+  SWFDEC_AS_VALUE_SET_NUMBER (ret, text->scroll_bottom);
 }
 
 static void
@@ -550,7 +552,11 @@ swfdec_text_field_movie_do_set_hscroll (SwfdecAsContext *cx,
 
   SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "i", &value);
 
-  swfdec_text_field_movie_set_hscroll (text, value);
+  value = CLAMP (value, 0, text->hscroll_max);
+  if (value != text->hscroll) {
+    text->hscroll = value;
+    swfdec_movie_invalidate (SWFDEC_MOVIE (text));
+  }
 }
 
 static void
@@ -559,12 +565,14 @@ swfdec_text_field_movie_get_maxhscroll (SwfdecAsContext *cx,
     SwfdecAsValue *ret)
 {
   SwfdecTextFieldMovie *text;
-  int max;
 
   SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
 
-  swfdec_text_field_movie_get_scroll_info (text, NULL, NULL, NULL, &max);
-  SWFDEC_AS_VALUE_SET_NUMBER (ret, max);
+  if (!text->text->word_wrap) {
+    SWFDEC_AS_VALUE_SET_NUMBER (ret, text->hscroll_max);
+  } else {
+    SWFDEC_AS_VALUE_SET_NUMBER (ret, 0);
+  }
 }
 
 static void
@@ -573,12 +581,10 @@ swfdec_text_field_movie_get_maxscroll (SwfdecAsContext *cx,
     SwfdecAsValue *ret)
 {
   SwfdecTextFieldMovie *text;
-  int max;
 
   SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
 
-  swfdec_text_field_movie_get_scroll_info (text, NULL, &max, NULL, NULL);
-  SWFDEC_AS_VALUE_SET_NUMBER (ret, max);
+  SWFDEC_AS_VALUE_SET_NUMBER (ret, text->scroll_max);
 }
 
 static void
@@ -630,7 +636,11 @@ swfdec_text_field_movie_do_set_scroll (SwfdecAsContext *cx,
 
   SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "i", &value);
 
-  swfdec_text_field_movie_set_scroll (text, value);
+  value = CLAMP (value, 1, text->scroll_max);
+  if (value != text->scroll) {
+    text->scroll = value;
+    swfdec_movie_invalidate (SWFDEC_MOVIE (text));
+  }
 }
 
 /*
@@ -700,8 +710,10 @@ swfdec_text_field_movie_set_autoSize (SwfdecAsContext *cx,
     text->text->auto_size = SWFDEC_AUTO_SIZE_CENTER;
   }
 
-  if (text->text->auto_size != old)
-    swfdec_text_field_movie_changed (text);
+  if (text->text->auto_size != old) {
+    swfdec_text_field_movie_auto_size (text);
+    // FIXME: fix scrolling
+  }
 }
 
 static void
@@ -760,7 +772,9 @@ swfdec_text_field_movie_set_wordWrap (SwfdecAsContext *cx,
 
   if (text->text->word_wrap != value) {
     text->text->word_wrap = value;
-    swfdec_text_field_movie_changed (text);
+    swfdec_movie_invalidate (SWFDEC_MOVIE (text));
+    swfdec_text_field_movie_auto_size (text);
+    // special case: don't set scrolling
   }
 }
 
@@ -795,6 +809,8 @@ swfdec_text_field_movie_set_embedFonts (SwfdecAsContext *cx,
     SWFDEC_FIXME ("Using embed fonts in TextField not supported");
 
   text->text->embed_fonts = value;
+
+  // FIXME: resize
 }
 
 static void
commit 012c5ba8a76250fd2585c13b2b43bb8980a28d73
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Thu Oct 18 11:35:27 2007 +0300

    Some fixes to TextField's scrolling

diff --git a/libswfdec/swfdec_text_field_movie.c b/libswfdec/swfdec_text_field_movie.c
index 00e096b..36a3801 100644
--- a/libswfdec/swfdec_text_field_movie.c
+++ b/libswfdec/swfdec_text_field_movie.c
@@ -683,14 +683,15 @@ swfdec_text_field_movie_get_scroll_info (SwfdecTextFieldMovie *text,
     int *scroll_last, int *scroll_max, int *hscroll_last, int *hscroll_max)
 {
   SwfdecLayout *layouts;
-  int i, num, y, visible, all, height, width, width_max;
+  int i, num, y, visible, all, height;
+  double width, width_max;
 
   g_return_if_fail (SWFDEC_IS_TEXT_FIELD_MOVIE (text));
 
   layouts = swfdec_text_field_movie_get_layouts (text, &num, NULL, NULL, NULL);
 
   width = SWFDEC_MOVIE (text)->original_extents.x1 -
-    SWFDEC_MOVIE (text)->original_extents.x1;
+    SWFDEC_MOVIE (text)->original_extents.x0;
   height = SWFDEC_MOVIE (text)->original_extents.y1 -
     SWFDEC_MOVIE (text)->original_extents.y0;
 
@@ -729,14 +730,14 @@ swfdec_text_field_movie_get_scroll_info (SwfdecTextFieldMovie *text,
   layouts = NULL;
 
   if (scroll_last)
-    *scroll_last = text->scroll + visible;
+    *scroll_last = text->scroll + (visible > 0 ? visible - 1 : 0);
   if (scroll_max)
-    *scroll_max = all - visible;
+    *scroll_max = all - visible + 1;
 
   if (hscroll_last)
-    *hscroll_last = text->hscroll + width;
+    *hscroll_last = text->hscroll + SWFDEC_TWIPS_TO_DOUBLE (width);
   if (hscroll_max)
-    *hscroll_max = width_max - width;
+    *hscroll_max = SWFDEC_TWIPS_TO_DOUBLE (width_max - width);
 }
 
 void
@@ -810,8 +811,8 @@ swfdec_text_field_movie_auto_size (SwfdecTextFieldMovie *text)
   swfdec_text_field_movie_free_layouts (layouts);
   layouts = NULL;
 
-  if (!text->text->word_wrap && SWFDEC_GRAPHIC (text->text)->extents.x1 -
-      SWFDEC_GRAPHIC (text->text)->extents.x0 != width)
+  if (!text->text->word_wrap && SWFDEC_MOVIE (text)->original_extents.x1 -
+      SWFDEC_MOVIE (text)->original_extents.x0 != width)
   {
     switch (text->text->auto_size) {
       case SWFDEC_AUTO_SIZE_LEFT:
diff --git a/libswfdec/swfdec_text_field_movie_as.c b/libswfdec/swfdec_text_field_movie_as.c
index f750448..9d5c71c 100644
--- a/libswfdec/swfdec_text_field_movie_as.c
+++ b/libswfdec/swfdec_text_field_movie_as.c
@@ -953,6 +953,7 @@ swfdec_text_field_movie_createTextField (SwfdecAsContext *cx,
       SWFDEC_GRAPHIC (edittext), name);
   g_assert (SWFDEC_IS_TEXT_FIELD_MOVIE (movie));
   swfdec_movie_initialize (movie);
+  swfdec_movie_update (movie);
 
   swfdec_as_object_get_variable (cx->global, SWFDEC_AS_STR_TextField, &val);
   if (!SWFDEC_AS_VALUE_IS_OBJECT (&val))
commit d82e0f10ad95f99807e49975e05662ff94ff7dba
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Thu Oct 18 11:02:04 2007 +0300

    Clean up scroll code. Add maxhscroll, maxscroll and bottomScroll properties

diff --git a/libswfdec/swfdec_as_strings.c b/libswfdec/swfdec_as_strings.c
index 49c7dc2..522716f 100644
--- a/libswfdec/swfdec_as_strings.c
+++ b/libswfdec/swfdec_as_strings.c
@@ -412,5 +412,8 @@ const char swfdec_as_strings[] =
   SWFDEC_AS_CONSTANT_STRING ("restrict")
   SWFDEC_AS_CONSTANT_STRING ("mouseWheelEnabled")
   SWFDEC_AS_CONSTANT_STRING ("hscroll")
+  SWFDEC_AS_CONSTANT_STRING ("maxhscroll")
+  SWFDEC_AS_CONSTANT_STRING ("maxscroll")
+  SWFDEC_AS_CONSTANT_STRING ("bottomScroll")
   /* add more here */
 ;
diff --git a/libswfdec/swfdec_text_field_movie.c b/libswfdec/swfdec_text_field_movie.c
index 453025a..00e096b 100644
--- a/libswfdec/swfdec_text_field_movie.c
+++ b/libswfdec/swfdec_text_field_movie.c
@@ -679,17 +679,22 @@ swfdec_text_field_movie_render (SwfdecMovie *movie, cairo_t *cr,
 }
 
 void
-swfdec_text_field_movie_set_scroll (SwfdecTextFieldMovie *text, int value)
+swfdec_text_field_movie_get_scroll_info (SwfdecTextFieldMovie *text,
+    int *scroll_last, int *scroll_max, int *hscroll_last, int *hscroll_max)
 {
   SwfdecLayout *layouts;
-  int i, num, y, visible, all, height;
+  int i, num, y, visible, all, height, width, width_max;
 
   g_return_if_fail (SWFDEC_IS_TEXT_FIELD_MOVIE (text));
 
   layouts = swfdec_text_field_movie_get_layouts (text, &num, NULL, NULL, NULL);
 
+  width = SWFDEC_MOVIE (text)->original_extents.x1 -
+    SWFDEC_MOVIE (text)->original_extents.x1;
   height = SWFDEC_MOVIE (text)->original_extents.y1 -
     SWFDEC_MOVIE (text)->original_extents.y0;
+
+  width_max = width;
   y = 0;
   all = 0;
   visible = 0;
@@ -700,6 +705,9 @@ swfdec_text_field_movie_set_scroll (SwfdecTextFieldMovie *text, int value)
     PangoLayoutIter *iter_line;
     PangoRectangle rect;
 
+    if (layouts[i].width > width_max)
+      width_max = layouts[i].width;
+
     y += layout->height;
 
     iter_line = pango_layout_get_iter (layout->layout);
@@ -713,15 +721,37 @@ swfdec_text_field_movie_set_scroll (SwfdecTextFieldMovie *text, int value)
 
       all++;
     } while (pango_layout_iter_next_line (iter_line));
+
+    pango_layout_iter_free (iter_line);
   }
 
   swfdec_text_field_movie_free_layouts (layouts);
   layouts = NULL;
 
-  if (value < 1) {
+  if (scroll_last)
+    *scroll_last = text->scroll + visible;
+  if (scroll_max)
+    *scroll_max = all - visible;
+
+  if (hscroll_last)
+    *hscroll_last = text->hscroll + width;
+  if (hscroll_max)
+    *hscroll_max = width_max - width;
+}
+
+void
+swfdec_text_field_movie_set_scroll (SwfdecTextFieldMovie *text, int value)
+{
+  g_return_if_fail (SWFDEC_IS_TEXT_FIELD_MOVIE (text));
+
+  if (value <= 1) {
     value = 1;
-  } else if (value > all - visible + 1) {
-    value = all - visible + 1;
+  } else {
+    int max;
+
+    swfdec_text_field_movie_get_scroll_info (text, NULL, &max, NULL, NULL);
+    if (value > max)
+      value = max;
   }
 
   if (text->scroll != value) {
@@ -733,29 +763,16 @@ swfdec_text_field_movie_set_scroll (SwfdecTextFieldMovie *text, int value)
 void
 swfdec_text_field_movie_set_hscroll (SwfdecTextFieldMovie *text, int value)
 {
-  SwfdecLayout *layouts;
-  int i, width, width_max;
-
   g_return_if_fail (SWFDEC_IS_TEXT_FIELD_MOVIE (text));
 
-  layouts = swfdec_text_field_movie_get_layouts (text, NULL, NULL, NULL, NULL);
-
-  width = SWFDEC_MOVIE (text)->original_extents.x1 -
-    SWFDEC_MOVIE (text)->original_extents.x1;
-
-  width_max = width;
-  for (i = 0; layouts[i].layout != NULL; i++) {
-    if (layouts[i].width > width_max)
-      width_max = layouts[i].width;
-  }
-
-  swfdec_text_field_movie_free_layouts (layouts);
-  layouts = NULL;
-
-  if (value < 0) {
+  if (value <= 0) {
     value = 0;
-  } else if (value > width_max - width) {
-    value = width_max - width;
+  } else {
+    int max;
+
+    swfdec_text_field_movie_get_scroll_info (text, NULL, NULL, NULL, &max);
+    if (value > max)
+      value = max;
   }
 
   if (text->hscroll != value) {
@@ -839,7 +856,7 @@ swfdec_text_field_movie_changed (SwfdecTextFieldMovie *text)
   }
 
   swfdec_text_field_movie_set_scroll (text, text->scroll);
-  swfdec_text_field_movie_set_hscroll (text, text->scroll);
+  swfdec_text_field_movie_set_hscroll (text, text->hscroll);
 }
 
 static void
diff --git a/libswfdec/swfdec_text_field_movie.h b/libswfdec/swfdec_text_field_movie.h
index a2443c2..f862c0b 100644
--- a/libswfdec/swfdec_text_field_movie.h
+++ b/libswfdec/swfdec_text_field_movie.h
@@ -121,6 +121,11 @@ void		swfdec_text_field_movie_set_text_format	(SwfdecTextFieldMovie *	text,
 							 SwfdecTextFormat *	format,
 							 guint			start_index,
 							 guint			end_index);
+void		swfdec_text_field_movie_get_scroll_info	(SwfdecTextFieldMovie *	text,
+							 int *			scroll_last,
+							 int *			scroll_max,
+							 int *			hscroll_last,
+							 int *			hscroll_max);
 void		swfdec_text_field_movie_set_scroll	(SwfdecTextFieldMovie *	text,
 							 int			value);
 void		swfdec_text_field_movie_set_hscroll	(SwfdecTextFieldMovie *	text,
diff --git a/libswfdec/swfdec_text_field_movie_as.c b/libswfdec/swfdec_text_field_movie_as.c
index 0a6942e..f750448 100644
--- a/libswfdec/swfdec_text_field_movie_as.c
+++ b/libswfdec/swfdec_text_field_movie_as.c
@@ -515,6 +515,20 @@ swfdec_text_field_movie_set_borderColor (SwfdecAsContext *cx,
  * Native properties: Scrolling
  */
 static void
+swfdec_text_field_movie_get_bottomScroll (SwfdecAsContext *cx,
+    SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
+    SwfdecAsValue *ret)
+{
+  SwfdecTextFieldMovie *text;
+  int last;
+
+  SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
+
+  swfdec_text_field_movie_get_scroll_info (text, &last, NULL, NULL, NULL);
+  SWFDEC_AS_VALUE_SET_NUMBER (ret, last);
+}
+
+static void
 swfdec_text_field_movie_do_get_hscroll (SwfdecAsContext *cx,
     SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
     SwfdecAsValue *ret)
@@ -538,7 +552,35 @@ swfdec_text_field_movie_do_set_hscroll (SwfdecAsContext *cx,
 
   swfdec_text_field_movie_set_hscroll (text, value);
 }
-  
+
+static void
+swfdec_text_field_movie_get_maxhscroll (SwfdecAsContext *cx,
+    SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
+    SwfdecAsValue *ret)
+{
+  SwfdecTextFieldMovie *text;
+  int max;
+
+  SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
+
+  swfdec_text_field_movie_get_scroll_info (text, NULL, NULL, NULL, &max);
+  SWFDEC_AS_VALUE_SET_NUMBER (ret, max);
+}
+
+static void
+swfdec_text_field_movie_get_maxscroll (SwfdecAsContext *cx,
+    SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
+    SwfdecAsValue *ret)
+{
+  SwfdecTextFieldMovie *text;
+  int max;
+
+  SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
+
+  swfdec_text_field_movie_get_scroll_info (text, NULL, &max, NULL, NULL);
+  SWFDEC_AS_VALUE_SET_NUMBER (ret, max);
+}
+
 static void
 swfdec_text_field_movie_get_mouseWheelEnabled (SwfdecAsContext *cx,
     SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
@@ -1039,18 +1081,18 @@ swfdec_text_field_movie_init_properties (SwfdecAsContext *cx)
       swfdec_text_field_movie_set_borderColor);
 
   // scrolling
-  /*swfdec_text_field_movie_add_variable (proto, SWFDEC_AS_STR_bottomScroll,
+  swfdec_text_field_movie_add_variable (proto, SWFDEC_AS_STR_bottomScroll,
       swfdec_text_field_movie_get_bottomScroll,
-      swfdec_text_field_movie_set_readonly);*/
+      swfdec_text_field_movie_set_readonly);
   swfdec_text_field_movie_add_variable (proto, SWFDEC_AS_STR_hscroll,
       swfdec_text_field_movie_do_get_hscroll,
       swfdec_text_field_movie_do_set_hscroll);
-  /*swfdec_text_field_movie_add_variable (proto, SWFDEC_AS_STR_maxhscroll,
+  swfdec_text_field_movie_add_variable (proto, SWFDEC_AS_STR_maxhscroll,
       swfdec_text_field_movie_get_maxhscroll,
-      swfdec_text_field_movie_set_readonly);*/
-  /*swfdec_text_field_movie_add_variable (proto, SWFDEC_AS_STR_maxscroll,
+      swfdec_text_field_movie_set_readonly);
+  swfdec_text_field_movie_add_variable (proto, SWFDEC_AS_STR_maxscroll,
       swfdec_text_field_movie_get_maxscroll,
-      swfdec_text_field_movie_set_readonly);*/
+      swfdec_text_field_movie_set_readonly);
   swfdec_text_field_movie_add_variable (proto, SWFDEC_AS_STR_mouseWheelEnabled,
       swfdec_text_field_movie_get_mouseWheelEnabled,
       swfdec_text_field_movie_set_mouseWheelEnabled);
commit 2d956eafde92cefacac977f1ce6ac01792de591f
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Thu Oct 18 10:09:26 2007 +0300

    Actually use the hscroll property

diff --git a/libswfdec/swfdec_text_field_movie.c b/libswfdec/swfdec_text_field_movie.c
index 8e4175f..453025a 100644
--- a/libswfdec/swfdec_text_field_movie.c
+++ b/libswfdec/swfdec_text_field_movie.c
@@ -619,7 +619,7 @@ swfdec_text_field_movie_render (SwfdecMovie *movie, cairo_t *cr,
 
   first = TRUE;
   linenum = 0;
-  x = movie->original_extents.x0;
+  x = movie->original_extents.x0 + text_movie->hscroll;
   y = movie->original_extents.y0 + 1;
   cairo_move_to (cr, x, y);
 
commit 5cf24956515d939dd04364520fb3b7a6688659b2
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Thu Oct 18 01:18:15 2007 +0300

    Add hscroll property to TextField object

diff --git a/libswfdec/swfdec_as_strings.c b/libswfdec/swfdec_as_strings.c
index 16ea014..49c7dc2 100644
--- a/libswfdec/swfdec_as_strings.c
+++ b/libswfdec/swfdec_as_strings.c
@@ -411,5 +411,6 @@ const char swfdec_as_strings[] =
   SWFDEC_AS_CONSTANT_STRING ("variable")
   SWFDEC_AS_CONSTANT_STRING ("restrict")
   SWFDEC_AS_CONSTANT_STRING ("mouseWheelEnabled")
+  SWFDEC_AS_CONSTANT_STRING ("hscroll")
   /* add more here */
 ;
diff --git a/libswfdec/swfdec_text_field_movie_as.c b/libswfdec/swfdec_text_field_movie_as.c
index 876c078..0a6942e 100644
--- a/libswfdec/swfdec_text_field_movie_as.c
+++ b/libswfdec/swfdec_text_field_movie_as.c
@@ -515,6 +515,31 @@ swfdec_text_field_movie_set_borderColor (SwfdecAsContext *cx,
  * Native properties: Scrolling
  */
 static void
+swfdec_text_field_movie_do_get_hscroll (SwfdecAsContext *cx,
+    SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
+    SwfdecAsValue *ret)
+{
+  SwfdecTextFieldMovie *text;
+
+  SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
+
+  SWFDEC_AS_VALUE_SET_NUMBER (ret, text->hscroll);
+}
+
+static void
+swfdec_text_field_movie_do_set_hscroll (SwfdecAsContext *cx,
+    SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
+    SwfdecAsValue *ret)
+{
+  SwfdecTextFieldMovie *text;
+  int value;
+
+  SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "i", &value);
+
+  swfdec_text_field_movie_set_hscroll (text, value);
+}
+  
+static void
 swfdec_text_field_movie_get_mouseWheelEnabled (SwfdecAsContext *cx,
     SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
     SwfdecAsValue *ret)
@@ -1017,9 +1042,9 @@ swfdec_text_field_movie_init_properties (SwfdecAsContext *cx)
   /*swfdec_text_field_movie_add_variable (proto, SWFDEC_AS_STR_bottomScroll,
       swfdec_text_field_movie_get_bottomScroll,
       swfdec_text_field_movie_set_readonly);*/
-  /*swfdec_text_field_movie_add_variable (proto, SWFDEC_AS_STR_hscroll,
-      swfdec_text_field_movie_get_hscroll,
-      swfdec_text_field_movie_set_hscroll);*/
+  swfdec_text_field_movie_add_variable (proto, SWFDEC_AS_STR_hscroll,
+      swfdec_text_field_movie_do_get_hscroll,
+      swfdec_text_field_movie_do_set_hscroll);
   /*swfdec_text_field_movie_add_variable (proto, SWFDEC_AS_STR_maxhscroll,
       swfdec_text_field_movie_get_maxhscroll,
       swfdec_text_field_movie_set_readonly);*/
commit 4eaad8eddd2e8168948da3b40c75bafe4725ad28
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Thu Oct 18 01:15:12 2007 +0300

    TextField: Use original_extents not extents. Add function to set hscroll

diff --git a/libswfdec/swfdec_text_field_movie.c b/libswfdec/swfdec_text_field_movie.c
index 50ce2c6..8e4175f 100644
--- a/libswfdec/swfdec_text_field_movie.c
+++ b/libswfdec/swfdec_text_field_movie.c
@@ -579,8 +579,7 @@ swfdec_text_field_movie_render (SwfdecMovie *movie, cairo_t *cr,
   SwfdecRect limit;
   SwfdecColor color;
   SwfdecParagraph *paragraphs;
-  int i, y, x;
-  guint linenum;
+  int i, y, x, linenum;
   gboolean first;
 
   g_return_if_fail (SWFDEC_IS_TEXT_FIELD_MOVIE (movie));
@@ -620,8 +619,8 @@ swfdec_text_field_movie_render (SwfdecMovie *movie, cairo_t *cr,
 
   first = TRUE;
   linenum = 0;
-  x = SWFDEC_GRAPHIC (text)->extents.x0;
-  y = SWFDEC_GRAPHIC (text)->extents.y0 + 1;
+  x = movie->original_extents.x0;
+  y = movie->original_extents.y0 + 1;
   cairo_move_to (cr, x, y);
 
   for (i = 0; layouts[i].layout != NULL/* && y < limit.y1*/; i++)
@@ -646,7 +645,7 @@ swfdec_text_field_movie_render (SwfdecMovie *movie, cairo_t *cr,
 	skipped = rect.y;
 
       if (!first &&
-	  y + rect.y + rect.height > SWFDEC_GRAPHIC (text)->extents.y1)
+	  y + rect.y + rect.height > movie->original_extents.y1)
 	break;
 
       first = FALSE;
@@ -680,18 +679,17 @@ swfdec_text_field_movie_render (SwfdecMovie *movie, cairo_t *cr,
 }
 
 void
-swfdec_text_field_movie_set_scroll (SwfdecTextFieldMovie *text, guint value)
+swfdec_text_field_movie_set_scroll (SwfdecTextFieldMovie *text, int value)
 {
   SwfdecLayout *layouts;
-  int i, num;
-  guint y, visible, all, height;
+  int i, num, y, visible, all, height;
 
   g_return_if_fail (SWFDEC_IS_TEXT_FIELD_MOVIE (text));
 
   layouts = swfdec_text_field_movie_get_layouts (text, &num, NULL, NULL, NULL);
 
-  height = SWFDEC_GRAPHIC (text->text)->extents.y1 -
-    SWFDEC_GRAPHIC (text->text)->extents.y0;
+  height = SWFDEC_MOVIE (text)->original_extents.y1 -
+    SWFDEC_MOVIE (text)->original_extents.y0;
   y = 0;
   all = 0;
   visible = 0;
@@ -732,6 +730,40 @@ swfdec_text_field_movie_set_scroll (SwfdecTextFieldMovie *text, guint value)
   }
 }
 
+void
+swfdec_text_field_movie_set_hscroll (SwfdecTextFieldMovie *text, int value)
+{
+  SwfdecLayout *layouts;
+  int i, width, width_max;
+
+  g_return_if_fail (SWFDEC_IS_TEXT_FIELD_MOVIE (text));
+
+  layouts = swfdec_text_field_movie_get_layouts (text, NULL, NULL, NULL, NULL);
+
+  width = SWFDEC_MOVIE (text)->original_extents.x1 -
+    SWFDEC_MOVIE (text)->original_extents.x1;
+
+  width_max = width;
+  for (i = 0; layouts[i].layout != NULL; i++) {
+    if (layouts[i].width > width_max)
+      width_max = layouts[i].width;
+  }
+
+  swfdec_text_field_movie_free_layouts (layouts);
+  layouts = NULL;
+
+  if (value < 0) {
+    value = 0;
+  } else if (value > width_max - width) {
+    value = width_max - width;
+  }
+
+  if (text->hscroll != value) {
+    text->hscroll = value;
+    swfdec_movie_invalidate (SWFDEC_MOVIE (text));
+  }
+}
+
 static gboolean
 swfdec_text_field_movie_auto_size (SwfdecTextFieldMovie *text)
 {
@@ -807,6 +839,7 @@ swfdec_text_field_movie_changed (SwfdecTextFieldMovie *text)
   }
 
   swfdec_text_field_movie_set_scroll (text, text->scroll);
+  swfdec_text_field_movie_set_hscroll (text, text->scroll);
 }
 
 static void
diff --git a/libswfdec/swfdec_text_field_movie.h b/libswfdec/swfdec_text_field_movie.h
index d75a13e..a2443c2 100644
--- a/libswfdec/swfdec_text_field_movie.h
+++ b/libswfdec/swfdec_text_field_movie.h
@@ -92,7 +92,8 @@ struct _SwfdecTextFieldMovie {
   gboolean		embed_fonts;
   SwfdecStyleSheet *	style_sheet;
 
-  guint			scroll;
+  int			scroll;
+  int			hscroll;
   gboolean		mouse_wheel_enabled;
 
   const char *		restrict_;
@@ -121,7 +122,9 @@ void		swfdec_text_field_movie_set_text_format	(SwfdecTextFieldMovie *	text,
 							 guint			start_index,
 							 guint			end_index);
 void		swfdec_text_field_movie_set_scroll	(SwfdecTextFieldMovie *	text,
-							 guint			value);
+							 int			value);
+void		swfdec_text_field_movie_set_hscroll	(SwfdecTextFieldMovie *	text,
+							 int			value);
 const char *	swfdec_text_field_movie_get_html_text	(SwfdecTextFieldMovie *		text);
 void		swfdec_text_field_movie_set_listen_variable (SwfdecTextFieldMovie *	text,
 							 const char *			value);
commit 18de960f1186481f41b4bd68bdce3429730e8abc
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Thu Oct 18 00:59:05 2007 +0300

    Check scrolling when TextField's contents have changed

diff --git a/libswfdec/swfdec_text_field_movie.c b/libswfdec/swfdec_text_field_movie.c
index f38661f..50ce2c6 100644
--- a/libswfdec/swfdec_text_field_movie.c
+++ b/libswfdec/swfdec_text_field_movie.c
@@ -805,6 +805,8 @@ swfdec_text_field_movie_changed (SwfdecTextFieldMovie *text)
     swfdec_movie_queue_update (SWFDEC_MOVIE (text),
 	SWFDEC_MOVIE_INVALID_CONTENTS);
   }
+
+  swfdec_text_field_movie_set_scroll (text, text->scroll);
 }
 
 static void
commit 8a3a357a168ea428b0d30f8d3395f4d5dbf510f5
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Thu Oct 18 00:57:27 2007 +0300

    Clean up TextField code (no caching of paragraphs etc.)

diff --git a/libswfdec/swfdec_text_field.h b/libswfdec/swfdec_text_field.h
index d1d41e2..cdbe1ec 100644
--- a/libswfdec/swfdec_text_field.h
+++ b/libswfdec/swfdec_text_field.h
@@ -39,38 +39,6 @@ typedef struct _SwfdecTextFieldClass SwfdecTextFieldClass;
 #define SWFDEC_TEXT_FIELD(obj)                    (G_TYPE_CHECK_INSTANCE_CAST ((obj), SWFDEC_TYPE_TEXT_FIELD, SwfdecTextField))
 #define SWFDEC_TEXT_FIELD_CLASS(klass)            (G_TYPE_CHECK_CLASS_CAST ((klass), SWFDEC_TYPE_TEXT_FIELD, SwfdecTextFieldClass))
 
-typedef struct {
-  PangoLayout *		layout;
-  int			render_offset_x;
-  int			height;
-  int			width;
-} SwfdecLayout;
-
-typedef struct {
-  guint			index_;
-
-  PangoAlignment	align;
-  gboolean		justify;
-  int			leading;
-  int			block_indent;
-  int			left_margin;
-  int			right_margin;
-  PangoTabArray *	tab_stops;
-} SwfdecBlock;
-
-typedef struct {
-  const char		*text;
-  guint			text_length;
-
-  gboolean		bullet;
-  int			indent;
-
-  GList *		blocks;		// SwfdecBlock
-
-  GList *		attrs;	// PangoAttribute
-  PangoAttrList *	attrs_list;
-} SwfdecParagraph;
-
 typedef enum {
   SWFDEC_AUTO_SIZE_NONE,
   SWFDEC_AUTO_SIZE_LEFT,
diff --git a/libswfdec/swfdec_text_field_movie.c b/libswfdec/swfdec_text_field_movie.c
index 48fa71d..f38661f 100644
--- a/libswfdec/swfdec_text_field_movie.c
+++ b/libswfdec/swfdec_text_field_movie.c
@@ -289,33 +289,36 @@ swfdec_text_field_movie_generate_paragraph (SwfdecTextFieldMovie *text,
   attr_underline = NULL;
 }
 
-static void
-swfdec_text_field_movie_generate_paragraphs (SwfdecTextFieldMovie *text)
+static SwfdecParagraph *
+swfdec_text_field_movie_get_paragraphs (SwfdecTextFieldMovie *text, int *num)
 {
+  SwfdecParagraph *paragraphs;
   const char *p, *end;
-  int num, i;
+  int count, i;
 
   g_assert (SWFDEC_IS_TEXT_FIELD_MOVIE (text));
 
-  num = 0;
+  count = 0;
   p = text->text_display;
   while (p != NULL && *p != '\0') {
-    num++;
+    count++;
     p = strchr (p, '\r');
     if (p != NULL) p++;
   }
 
-  text->paragraphs = g_new0 (SwfdecParagraph, num + 1);
+  paragraphs = g_new0 (SwfdecParagraph, count + 1);
+  if (num != NULL)
+    *num = count;
 
   i = 0;
   p = text->text_display;
   while (*p != '\0') {
-    g_assert (i < num);
+    g_assert (i < count);
     end = strchr (p, '\r');
     if (end == NULL)
       end = strchr (p, '\0');
 
-    swfdec_text_field_movie_generate_paragraph (text, &text->paragraphs[i],
+    swfdec_text_field_movie_generate_paragraph (text, &paragraphs[i],
 	p - text->text_display, end - text->text_display);
 
     p = end;
@@ -323,23 +326,60 @@ swfdec_text_field_movie_generate_paragraphs (SwfdecTextFieldMovie *text)
 
     i++;
   }
-  g_assert (i == num);
+  g_assert (i == count);
+
+  return paragraphs;
+}
+
+static void
+swfdec_text_field_movie_free_paragraphs (SwfdecParagraph *paragraphs)
+{
+  GList *iter;
+  int i;
+
+  g_return_if_fail (paragraphs != NULL);
+
+  for (i = 0; paragraphs[i].text != NULL; i++)
+  {
+    for (iter = paragraphs[i].blocks; iter != NULL; iter = iter->next) {
+      pango_tab_array_free (((SwfdecBlock *)(iter->data))->tab_stops);
+    }
+    g_list_free (paragraphs[i].blocks);
+
+    for (iter = paragraphs[i].attrs; iter != NULL; iter = iter->next) {
+      pango_attribute_destroy ((PangoAttribute *)(iter->data));
+    }
+    g_list_free (paragraphs[i].attrs);
+
+    if (paragraphs[i].attrs_list != NULL)
+      pango_attr_list_unref (paragraphs[i].attrs_list);
+  }
+  g_free (paragraphs);
 }
 
 /*
  * Rendering
  */
 static SwfdecLayout *
-swfdec_text_field_movie_generate_layouts (SwfdecTextField *text, cairo_t *cr,
-    const SwfdecParagraph *paragraphs, const SwfdecColorTransform *trans,
-    const SwfdecRect *inval, int *num)
+swfdec_text_field_movie_get_layouts (SwfdecTextFieldMovie *text, int *num,
+    cairo_t *cr, const SwfdecParagraph *paragraphs,
+    const SwfdecColorTransform *trans)
 {
   GArray *layouts;
   guint i;
+  SwfdecParagraph *paragraphs_free;
+
+  g_assert (SWFDEC_IS_TEXT_FIELD_MOVIE (text));
 
-  g_return_val_if_fail (SWFDEC_IS_TEXT_FIELD (text), NULL);
-  g_return_val_if_fail (cr != NULL, NULL);
-  g_return_val_if_fail (paragraphs != NULL, NULL);
+  if (cr == NULL)
+    cr = text->cr;
+
+  if (paragraphs == NULL) {
+    paragraphs_free = swfdec_text_field_movie_get_paragraphs (text, NULL);
+    paragraphs = paragraphs_free;
+  } else {
+    paragraphs_free = NULL;
+  }
 
   layouts = g_array_new (TRUE, TRUE, sizeof (SwfdecLayout));
 
@@ -375,8 +415,8 @@ swfdec_text_field_movie_generate_layouts (SwfdecTextField *text, cairo_t *cr,
 
       // set rendering position
       layout.render_offset_x = block->left_margin + block->block_indent;
-      width = SWFDEC_GRAPHIC (text)->extents.x1 -
-	SWFDEC_GRAPHIC (text)->extents.x0 - block->left_margin -
+      width = SWFDEC_MOVIE (text)->original_extents.x1 -
+	SWFDEC_MOVIE (text)->original_extents.x0 - block->left_margin -
 	block->right_margin - block->block_indent;
 
       if (block->index_ == 0 && paragraphs[i].indent < 0) {
@@ -387,7 +427,7 @@ swfdec_text_field_movie_generate_layouts (SwfdecTextField *text, cairo_t *cr,
 	width += -indent;
       }
 
-      if (text->word_wrap) {
+      if (text->text->word_wrap) {
 	pango_layout_set_wrap (playout, PANGO_WRAP_WORD_CHAR);
 	pango_layout_set_width (playout, width * PANGO_SCALE);
 	pango_layout_set_alignment (playout, block->align);
@@ -458,7 +498,7 @@ swfdec_text_field_movie_generate_layouts (SwfdecTextField *text, cairo_t *cr,
 	  paragraphs[i].text + block->index_ + skip,
 	  paragraphs[i].text_length - block->index_ - skip);
 
-      if (iter->next != NULL && text->word_wrap)
+      if (iter->next != NULL && text->text->word_wrap)
       {
 	PangoLayoutLine *line;
 	int line_num;
@@ -498,17 +538,36 @@ swfdec_text_field_movie_generate_layouts (SwfdecTextField *text, cairo_t *cr,
 
       layouts = g_array_append_val (layouts, layout);
 
-      if (!text->word_wrap)
+      if (!text->text->word_wrap)
 	break;
     }
   }
 
+  if (paragraphs_free != NULL) {
+    swfdec_text_field_movie_free_paragraphs (paragraphs_free);
+    paragraphs_free = NULL;
+    paragraphs = NULL;
+  }
+
   if (num != NULL)
     *num = layouts->len;
 
   return (SwfdecLayout *)g_array_free (layouts, FALSE);
 }
 
+static void
+swfdec_text_field_movie_free_layouts (SwfdecLayout *layouts)
+{
+  int i;
+
+  g_return_if_fail (layouts != NULL);
+
+  for (i = 0; layouts[i].layout != NULL; i++) {
+    g_object_unref (layouts[i].layout);
+  }
+
+  g_free (layouts);
+}
 
 static void
 swfdec_text_field_movie_render (SwfdecMovie *movie, cairo_t *cr,
@@ -519,7 +578,7 @@ swfdec_text_field_movie_render (SwfdecMovie *movie, cairo_t *cr,
   SwfdecLayout *layouts;
   SwfdecRect limit;
   SwfdecColor color;
-  const SwfdecParagraph *paragraphs;
+  SwfdecParagraph *paragraphs;
   int i, y, x;
   guint linenum;
   gboolean first;
@@ -532,9 +591,7 @@ swfdec_text_field_movie_render (SwfdecMovie *movie, cairo_t *cr,
   text_movie = SWFDEC_TEXT_FIELD_MOVIE (movie);
   text = SWFDEC_TEXT_FIELD (movie->graphic);
 
-  if (text_movie->paragraphs == NULL)
-    swfdec_text_field_movie_generate_paragraphs (text_movie);
-  paragraphs = text_movie->paragraphs;
+  paragraphs = swfdec_text_field_movie_get_paragraphs (text_movie, NULL);
 
   swfdec_rect_intersect (&limit, &movie->original_extents, inval);
 
@@ -558,8 +615,8 @@ swfdec_text_field_movie_render (SwfdecMovie *movie, cairo_t *cr,
     cairo_stroke (cr);
   }
 
-  layouts = swfdec_text_field_movie_generate_layouts (text, cr, paragraphs,
-      trans, inval, NULL);
+  layouts = swfdec_text_field_movie_get_layouts (text_movie, NULL, cr,
+      paragraphs, trans);
 
   first = TRUE;
   linenum = 0;
@@ -617,64 +674,9 @@ swfdec_text_field_movie_render (SwfdecMovie *movie, cairo_t *cr,
     }
   }
 
-  for (i = 0; layouts[i].layout != NULL; i++) {
-    g_object_unref (layouts[i].layout);
-  }
-
-  g_free (layouts);
-}
-
-static void
-swfdec_text_field_movie_free_paragraphs (SwfdecTextFieldMovie *text)
-{
-  GList *iter;
-  int i;
-
-  if (text->paragraphs) {
-    for (i = 0; text->paragraphs[i].text != NULL; i++)
-    {
-      for (iter = text->paragraphs[i].blocks; iter != NULL; iter = iter->next) {
-	pango_tab_array_free (((SwfdecBlock *)(iter->data))->tab_stops);
-      }
-      g_list_free (text->paragraphs[i].blocks);
-
-      for (iter = text->paragraphs[i].attrs; iter != NULL; iter = iter->next) {
-	pango_attribute_destroy ((PangoAttribute *)(iter->data));
-      }
-      g_list_free (text->paragraphs[i].attrs);
-
-      if (text->paragraphs[i].attrs_list != NULL)
-	pango_attr_list_unref (text->paragraphs[i].attrs_list);
-    }
-    g_free (text->paragraphs);
-    text->paragraphs = NULL;
-  }
-}
-
-static SwfdecLayout *
-swfdec_text_field_movie_get_layouts (SwfdecTextFieldMovie *text, int *num)
-{
-  g_return_val_if_fail (SWFDEC_IS_TEXT_FIELD_MOVIE (text), NULL);
-
-  if (text->paragraphs == NULL)
-    swfdec_text_field_movie_generate_paragraphs (text);
-
-  return swfdec_text_field_movie_generate_layouts (text->text, text->cr,
-      text->paragraphs, NULL, NULL, num);
-}
-
-static void
-swfdec_text_field_movie_free_layouts (SwfdecLayout *layouts)
-{
-  int i;
-
-  g_return_if_fail (layouts != NULL);
-
-  for (i = 0; layouts[i].layout != NULL; i++) {
-    g_object_unref (layouts[i].layout);
-  }
+  swfdec_text_field_movie_free_layouts (layouts);
 
-  g_free (layouts);
+  swfdec_text_field_movie_free_paragraphs (paragraphs);
 }
 
 void
@@ -686,7 +688,7 @@ swfdec_text_field_movie_set_scroll (SwfdecTextFieldMovie *text, guint value)
 
   g_return_if_fail (SWFDEC_IS_TEXT_FIELD_MOVIE (text));
 
-  layouts = swfdec_text_field_movie_get_layouts (text, &num);
+  layouts = swfdec_text_field_movie_get_layouts (text, &num, NULL, NULL, NULL);
 
   height = SWFDEC_GRAPHIC (text->text)->extents.y1 -
     SWFDEC_GRAPHIC (text->text)->extents.y0;
@@ -716,6 +718,7 @@ swfdec_text_field_movie_set_scroll (SwfdecTextFieldMovie *text, guint value)
   }
 
   swfdec_text_field_movie_free_layouts (layouts);
+  layouts = NULL;
 
   if (value < 1) {
     value = 1;
@@ -742,7 +745,7 @@ swfdec_text_field_movie_auto_size (SwfdecTextFieldMovie *text)
   if (text->text->auto_size == SWFDEC_AUTO_SIZE_NONE)
     return FALSE;
 
-  layouts = swfdec_text_field_movie_get_layouts (text, NULL);
+  layouts = swfdec_text_field_movie_get_layouts (text, NULL, NULL, NULL, NULL);
 
   width = 0;
   height = 3;
@@ -756,6 +759,7 @@ swfdec_text_field_movie_auto_size (SwfdecTextFieldMovie *text)
   }
 
   swfdec_text_field_movie_free_layouts (layouts);
+  layouts = NULL;
 
   if (!text->text->word_wrap && SWFDEC_GRAPHIC (text->text)->extents.x1 -
       SWFDEC_GRAPHIC (text->text)->extents.x0 != width)
@@ -793,10 +797,8 @@ swfdec_text_field_movie_auto_size (SwfdecTextFieldMovie *text)
 }
 
 void
-swfdec_text_field_movie_format_changed (SwfdecTextFieldMovie *text)
+swfdec_text_field_movie_changed (SwfdecTextFieldMovie *text)
 {
-  swfdec_text_field_movie_free_paragraphs (text);
-
   swfdec_movie_invalidate (SWFDEC_MOVIE (text));
 
   if (swfdec_text_field_movie_auto_size (text)) {
@@ -813,8 +815,6 @@ swfdec_text_field_movie_dispose (GObject *object)
 
   text = SWFDEC_TEXT_FIELD_MOVIE (object);
 
-  swfdec_text_field_movie_free_paragraphs (text);
-
   for (iter = text->formats; iter != NULL; iter = iter->next) {
     g_free (text->formats->data);
     text->formats->data = NULL;
@@ -1015,7 +1015,7 @@ swfdec_text_field_movie_set_text_format (SwfdecTextFieldMovie *text,
     }
   }
 
-  swfdec_text_field_movie_format_changed (text);
+  swfdec_text_field_movie_changed (text);
 }
 
 static void
@@ -1460,5 +1460,5 @@ swfdec_text_field_movie_set_text (SwfdecTextFieldMovie *text, const char *str,
     }
   }
 
-  swfdec_text_field_movie_format_changed (text);
+  swfdec_text_field_movie_changed (text);
 }
diff --git a/libswfdec/swfdec_text_field_movie.h b/libswfdec/swfdec_text_field_movie.h
index d0b9c60..d75a13e 100644
--- a/libswfdec/swfdec_text_field_movie.h
+++ b/libswfdec/swfdec_text_field_movie.h
@@ -39,6 +39,38 @@ typedef struct _SwfdecTextFieldMovieClass SwfdecTextFieldMovieClass;
 #define SWFDEC_TEXT_FIELD_MOVIE_CLASS(klass)            (G_TYPE_CHECK_CLASS_CAST ((klass), SWFDEC_TYPE_TEXT_FIELD_MOVIE, SwfdecTextFieldMovieClass))
 
 typedef struct {
+  PangoLayout *		layout;
+  int			render_offset_x;
+  int			height;
+  int			width;
+} SwfdecLayout;
+
+typedef struct {
+  guint			index_;
+
+  PangoAlignment	align;
+  gboolean		justify;
+  int			leading;
+  int			block_indent;
+  int			left_margin;
+  int			right_margin;
+  PangoTabArray *	tab_stops;
+} SwfdecBlock;
+
+typedef struct {
+  const char		*text;
+  guint			text_length;
+
+  gboolean		bullet;
+  int			indent;
+
+  GList *		blocks;		// SwfdecBlock
+
+  GList *		attrs;	// PangoAttribute
+  PangoAttrList *	attrs_list;
+} SwfdecParagraph;
+
+typedef struct {
   guint			index;
   SwfdecTextFormat *	format;
 } SwfdecFormatIndex;
@@ -72,9 +104,6 @@ struct _SwfdecTextFieldMovie {
   // outside the rendering functions
   cairo_surface_t *	surface;
   cairo_t *		cr;
-
-  /* for rendering */
-  SwfdecParagraph *	paragraphs;
 };
 
 struct _SwfdecTextFieldMovieClass {
@@ -86,7 +115,7 @@ GType		swfdec_text_field_movie_get_type		(void);
 void		swfdec_text_field_movie_set_text		(SwfdecTextFieldMovie *	movie,
 							 const char *		str,
 							 gboolean		html);
-void		swfdec_text_field_movie_format_changed	(SwfdecTextFieldMovie *	text);
+void		swfdec_text_field_movie_changed		(SwfdecTextFieldMovie *	text);
 void		swfdec_text_field_movie_set_text_format	(SwfdecTextFieldMovie *	text,
 							 SwfdecTextFormat *	format,
 							 guint			start_index,
diff --git a/libswfdec/swfdec_text_field_movie_as.c b/libswfdec/swfdec_text_field_movie_as.c
index 72b0dcf..876c078 100644
--- a/libswfdec/swfdec_text_field_movie_as.c
+++ b/libswfdec/swfdec_text_field_movie_as.c
@@ -634,7 +634,7 @@ swfdec_text_field_movie_set_autoSize (SwfdecAsContext *cx,
   }
 
   if (text->text->auto_size != old)
-    swfdec_text_field_movie_format_changed (text);
+    swfdec_text_field_movie_changed (text);
 }
 
 static void
@@ -693,7 +693,7 @@ swfdec_text_field_movie_set_wordWrap (SwfdecAsContext *cx,
 
   if (text->text->word_wrap != value) {
     text->text->word_wrap = value;
-    swfdec_text_field_movie_format_changed (text);
+    swfdec_text_field_movie_changed (text);
   }
 }
 
commit 68afb7c3585cd826bf7b361898049b3e1ab57bf4
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Wed Oct 17 23:55:39 2007 +0300

    Move scroll variable from TextField to TextFieldMovie

diff --git a/libswfdec/swfdec_text_field.c b/libswfdec/swfdec_text_field.c
index eef12ab..7b5c688 100644
--- a/libswfdec/swfdec_text_field.c
+++ b/libswfdec/swfdec_text_field.c
@@ -87,7 +87,6 @@ swfdec_text_field_class_init (SwfdecTextFieldClass * g_class)
 static void
 swfdec_text_field_init (SwfdecTextField * text)
 {
-  text->scroll = 1;
 }
 
 int
diff --git a/libswfdec/swfdec_text_field.h b/libswfdec/swfdec_text_field.h
index a6220f3..d1d41e2 100644
--- a/libswfdec/swfdec_text_field.h
+++ b/libswfdec/swfdec_text_field.h
@@ -95,8 +95,6 @@ struct _SwfdecTextField
   gboolean		multiline;
   SwfdecAutoSize	auto_size;
 
-  int			scroll;
-
   gboolean		border;
   gboolean		background;
 
diff --git a/libswfdec/swfdec_text_field_movie.c b/libswfdec/swfdec_text_field_movie.c
index 2f4b41e..48fa71d 100644
--- a/libswfdec/swfdec_text_field_movie.c
+++ b/libswfdec/swfdec_text_field_movie.c
@@ -520,7 +520,8 @@ swfdec_text_field_movie_render (SwfdecMovie *movie, cairo_t *cr,
   SwfdecRect limit;
   SwfdecColor color;
   const SwfdecParagraph *paragraphs;
-  int i, y, x, linenum;
+  int i, y, x;
+  guint linenum;
   gboolean first;
 
   g_return_if_fail (SWFDEC_IS_TEXT_FIELD_MOVIE (movie));
@@ -578,13 +579,13 @@ swfdec_text_field_movie_render (SwfdecMovie *movie, cairo_t *cr,
 
     skipped = 0;
     do {
-      if (++linenum < text->scroll)
+      if (++linenum < text_movie->scroll)
 	continue;
 
       pango_layout_iter_get_line_extents (iter_line, NULL, &rect);
       pango_extents_to_pixels (NULL, &rect);
 
-      if (linenum == text->scroll)
+      if (linenum == text_movie->scroll)
 	skipped = rect.y;
 
       if (!first &&
@@ -609,7 +610,7 @@ swfdec_text_field_movie_render (SwfdecMovie *movie, cairo_t *cr,
 	  -(pango_layout_iter_get_baseline (iter_line) / PANGO_SCALE - skipped));
     } while (pango_layout_iter_next_line (iter_line));
 
-    if (linenum >= text->scroll) {
+    if (linenum >= text_movie->scroll) {
       cairo_rel_move_to (cr, 0, layout->height - skipped);
       y += layout->height - skipped;
       skipped = 0;
@@ -677,10 +678,11 @@ swfdec_text_field_movie_free_layouts (SwfdecLayout *layouts)
 }
 
 void
-swfdec_text_field_movie_set_scroll (SwfdecTextFieldMovie *text, int value)
+swfdec_text_field_movie_set_scroll (SwfdecTextFieldMovie *text, guint value)
 {
   SwfdecLayout *layouts;
-  int i, num, y, visible, all, height;
+  int i, num;
+  guint y, visible, all, height;
 
   g_return_if_fail (SWFDEC_IS_TEXT_FIELD_MOVIE (text));
 
@@ -721,8 +723,8 @@ swfdec_text_field_movie_set_scroll (SwfdecTextFieldMovie *text, int value)
     value = all - visible + 1;
   }
 
-  if (text->text->scroll != value) {
-    text->text->scroll = value;
+  if (text->scroll != value) {
+    text->scroll = value;
     swfdec_movie_invalidate (SWFDEC_MOVIE (text));
   }
 }
@@ -934,6 +936,7 @@ swfdec_text_field_movie_init (SwfdecTextFieldMovie *text)
   text->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
   text->cr = cairo_create (text->surface);
 
+  text->scroll = 1;
   text->mouse_wheel_enabled = TRUE;
 }
 
diff --git a/libswfdec/swfdec_text_field_movie.h b/libswfdec/swfdec_text_field_movie.h
index a181cb7..d0b9c60 100644
--- a/libswfdec/swfdec_text_field_movie.h
+++ b/libswfdec/swfdec_text_field_movie.h
@@ -60,7 +60,9 @@ struct _SwfdecTextFieldMovie {
   gboolean		embed_fonts;
   SwfdecStyleSheet *	style_sheet;
 
+  guint			scroll;
   gboolean		mouse_wheel_enabled;
+
   const char *		restrict_;
 
   SwfdecColor		border_color;
@@ -90,7 +92,7 @@ void		swfdec_text_field_movie_set_text_format	(SwfdecTextFieldMovie *	text,
 							 guint			start_index,
 							 guint			end_index);
 void		swfdec_text_field_movie_set_scroll	(SwfdecTextFieldMovie *	text,
-							 int			value);
+							 guint			value);
 const char *	swfdec_text_field_movie_get_html_text	(SwfdecTextFieldMovie *		text);
 void		swfdec_text_field_movie_set_listen_variable (SwfdecTextFieldMovie *	text,
 							 const char *			value);
diff --git a/libswfdec/swfdec_text_field_movie_as.c b/libswfdec/swfdec_text_field_movie_as.c
index 2930c66..72b0dcf 100644
--- a/libswfdec/swfdec_text_field_movie_as.c
+++ b/libswfdec/swfdec_text_field_movie_as.c
@@ -550,7 +550,7 @@ swfdec_text_field_movie_do_get_scroll (SwfdecAsContext *cx,
 
   SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
 
-  SWFDEC_AS_VALUE_SET_NUMBER (ret, text->text->scroll);
+  SWFDEC_AS_VALUE_SET_NUMBER (ret, text->scroll);
 }
 
 static void


More information about the Swfdec mailing list