[Swfdec] 3 commits - libswfdec/swfdec_html_parser.c libswfdec/swfdec_text_field_movie.c

Pekka Lampila medar at kemper.freedesktop.org
Fri Oct 19 05:35:52 PDT 2007


 libswfdec/swfdec_html_parser.c      |   89 +++++++++++++++++++++++-------------
 libswfdec/swfdec_text_field_movie.c |    1 
 2 files changed, 60 insertions(+), 30 deletions(-)

New commits:
commit b4c20d7519ae5d93c9ba3258bde8444aebdd1be6
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Fri Oct 19 15:32:39 2007 +0300

    If closing tag doesn't match in the HTML parser, close tags until it does

diff --git a/libswfdec/swfdec_html_parser.c b/libswfdec/swfdec_html_parser.c
index 5bd0367..5d9153a 100644
--- a/libswfdec/swfdec_html_parser.c
+++ b/libswfdec/swfdec_html_parser.c
@@ -270,16 +270,17 @@ swfdec_text_field_movie_html_parse_tag (ParserData *data, const char *p)
 
   if (close)
   {
-    if (data->tags_open != NULL) {
-      tag = (ParserTag *)data->tags_open->data;
-    } else {
-      tag = NULL;
-    }
+    GSList *iter;
 
-    if (tag != NULL && name_length == tag->name_length &&
-	!g_strncasecmp (name, tag->name, name_length))
+    for (iter = data->tags_open; iter != NULL; iter = iter->next)
     {
+      tag = iter->data;
+
       swfdec_text_field_movie_html_parse_close_tag (data, tag);
+
+      if (name_length == tag->name_length &&
+	  !g_strncasecmp (name, tag->name, name_length))
+	break;
     }
 
     end = strchr (end, '>');
commit ba1618408e635618fa4f6908e0bacf5a69bebb1d
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Fri Oct 19 15:26:22 2007 +0300

    Clean up TextField's HTML parsing code somewhat, fix few version 6 issues

diff --git a/libswfdec/swfdec_html_parser.c b/libswfdec/swfdec_html_parser.c
index 5d058df..5bd0367 100644
--- a/libswfdec/swfdec_html_parser.c
+++ b/libswfdec/swfdec_html_parser.c
@@ -44,6 +44,39 @@ typedef struct {
   GSList *		tags_closed;
 } ParserData;
 
+static void
+swfdec_text_field_movie_html_parse_close_tag (ParserData *data, ParserTag *tag)
+{
+  if (data->cx->version < 7 &&
+      ((tag->name_length == 1 && !g_strncasecmp (tag->name, "p", 1)) ||
+       (tag->name_length == 2 && !g_strncasecmp (tag->name, "li", 2))))
+  {
+    GSList *iter;
+
+    for (iter = data->tags_closed; iter != NULL; iter = iter->next) {
+      ParserTag *f = iter->data;
+      if (f->end_index < tag->index)
+	break;
+      if (f->name_length == 4 && !g_strncasecmp (f->name, "font", 4)) {
+	ParserTag *n = g_new0 (ParserTag, 1);
+	n->name = f->name;
+	n->name_length = f->name_length;
+	n->index = data->text->len;
+	n->end_index = data->text->len + 1;
+	n->format = swfdec_text_format_copy (f->format);
+	data->tags_closed = g_slist_prepend (data->tags_closed, n);
+	break;
+      }
+    }
+    data->text = g_string_append_c (data->text, '\r');
+  }
+
+  tag->end_index = data->text->len;
+
+  data->tags_open = g_slist_remove (data->tags_open, tag);
+  data->tags_closed = g_slist_prepend (data->tags_closed, tag);
+}
+
 static const char *
 swfdec_text_field_movie_html_parse_comment (ParserData *data, const char *p)
 {
@@ -246,17 +279,7 @@ swfdec_text_field_movie_html_parse_tag (ParserData *data, const char *p)
     if (tag != NULL && name_length == tag->name_length &&
 	!g_strncasecmp (name, tag->name, name_length))
     {
-      if (data->cx->version == 6) {
-	if ((name_length == 1 && !g_strncasecmp (name, "p", 1)) ||
-	    (name_length == 2 && !g_strncasecmp (name, "li", 2))) {
-	  data->text = g_string_append_c (data->text, '\r');
-	}
-      }
-
-      tag->end_index = data->text->len;
-
-      data->tags_open = g_slist_remove (data->tags_open, tag);
-      data->tags_closed = g_slist_prepend (data->tags_closed, tag);
+      swfdec_text_field_movie_html_parse_close_tag (data, tag);
     }
 
     end = strchr (end, '>');
@@ -265,7 +288,7 @@ swfdec_text_field_movie_html_parse_tag (ParserData *data, const char *p)
   }
   else
   {
-    if (data->cx->version == 6 &&
+    if (data->cx->version < 7 &&
 	(name_length == 2 && !g_strncasecmp (name, "br", 2))) {
       data->text = g_string_append_c (data->text, '\r');
       tag = NULL;
@@ -273,6 +296,22 @@ swfdec_text_field_movie_html_parse_tag (ParserData *data, const char *p)
       SwfdecAsObject *object;
       SwfdecAsValue val;
 
+      if (data->cx->version < 7 &&
+	  ((name_length == 1 && !g_strncasecmp (name, "p", 1)) ||
+	   (name_length == 2 && !g_strncasecmp (name, "li", 2))))
+      {
+	GSList *iter;
+
+	for (iter = data->tags_open; iter != NULL; iter = iter->next) {
+	  ParserTag *f = iter->data;
+	  if ((f->name_length == 1 && !g_strncasecmp (f->name, "p", 1)) ||
+	      (f->name_length == 2 && !g_strncasecmp (f->name, "li", 2))) {
+	    data->text = g_string_append_c (data->text, '\r');
+	    break;
+	  }
+	}
+      }
+
       tag = g_new0 (ParserTag, 1);
       tag->name = name;
       tag->name_length = name_length;
@@ -386,19 +425,8 @@ swfdec_text_field_movie_html_parse (SwfdecTextFieldMovie *text, const char *str)
 
   // close remaining tags
   while (data.tags_open != NULL) {
-    ParserTag *tag = (ParserTag *)data.tags_open->data;
-
-    if (data.cx->version == 6) {
-      if ((tag->name_length == 1 && !g_strncasecmp (tag->name, "p", 1)) ||
-	  (tag->name_length == 2 && !g_strncasecmp (tag->name, "li", 2))) {
-	data.text = g_string_append_c (data.text, '\r');
-      }
-    }
-
-    tag->end_index = data.text->len;
-
-    data.tags_open = g_slist_remove (data.tags_open, tag);
-    data.tags_closed = g_slist_prepend (data.tags_closed, tag);
+    swfdec_text_field_movie_html_parse_close_tag (&data,
+	(ParserTag *)data.tags_open->data);
   }
 
   // set parsed text
commit a700c8838e1b7894f55337caf9faae8bba842e4b
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Fri Oct 19 14:27:57 2007 +0300

    Fix a bug in swfdec_text_field_movie_set_text_format

diff --git a/libswfdec/swfdec_text_field_movie.c b/libswfdec/swfdec_text_field_movie.c
index 737357b..b0e26a8 100644
--- a/libswfdec/swfdec_text_field_movie.c
+++ b/libswfdec/swfdec_text_field_movie.c
@@ -1031,6 +1031,7 @@ swfdec_text_field_movie_set_text_format (SwfdecTextFieldMovie *text,
 	swfdec_text_format_equal (findex->format,
 	  ((SwfdecFormatIndex *)next->data)->format))
     {
+      ((SwfdecFormatIndex *)next->data)->index = findex->index;
       text->formats = g_slist_remove (text->formats, findex);
       findex = findex_prev;
     }


More information about the Swfdec mailing list