[Swfdec-commits] 5 commits - swfdec/swfdec_net_stream.c swfdec/swfdec_text_format.c swfdec/swfdec_text_layout.c swfdec/swfdec_text_layout.h vivified/code
Benjamin Otte
company at kemper.freedesktop.org
Wed May 14 10:08:00 PDT 2008
swfdec/swfdec_net_stream.c | 8 +-
swfdec/swfdec_text_format.c | 99 ++++++++++----------------------
swfdec/swfdec_text_layout.c | 29 +++++++++
swfdec/swfdec_text_layout.h | 3
vivified/code/vivi_parser_scanner_lex.l | 1
5 files changed, 72 insertions(+), 68 deletions(-)
New commits:
commit 9cb95483e0e32f3bd217a8f6ec23cd7d40123d2c
Author: Benjamin Otte <otte at gnome.org>
Date: Wed May 14 19:07:30 2008 +0200
implement TextFormat.getTextExtent() using new text API
diff --git a/swfdec/swfdec_text_format.c b/swfdec/swfdec_text_format.c
index b98179b..ec5706b 100644
--- a/swfdec/swfdec_text_format.c
+++ b/swfdec/swfdec_text_format.c
@@ -35,6 +35,9 @@
#include "swfdec_internal.h"
#include "swfdec_as_internal.h"
#include "swfdec_player_internal.h"
+/* for getTextExtent */
+#include "swfdec_text_buffer.h"
+#include "swfdec_text_layout.h"
G_DEFINE_TYPE (SwfdecTextFormat, swfdec_text_format, SWFDEC_TYPE_AS_OBJECT)
@@ -804,84 +807,50 @@ swfdec_text_format_getTextExtent (SwfdecAsContext *cx, SwfdecAsObject *object,
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
SwfdecTextFormat *format;
- SwfdecAsObject *obj = swfdec_as_object_new_empty (cx);
+ SwfdecTextBuffer *buffer;
+ SwfdecTextLayout *layout;
+ SwfdecAsObject *obj;
SwfdecAsValue val;
- const gchar *text;
- gint height = 0, width = 0, text_field_width = 0, text_field_height = 0;
- gint ascent = 0, descent = 0;
- GList *item_list;
- PangoAnalysis analysis;
- PangoFontMap *fontmap;
- PangoContext *pcontext;
- PangoAttrList *attrs;
- PangoGlyphString *glyph_string = pango_glyph_string_new();
- PangoRectangle ink_rect;
- PangoFontDescription *desc;
- PangoFont *font;
+ const char* text;
+ int i, j;
SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FORMAT, &format, "s", &text);
- /* If the string is empty we'll just leave all the values as 0. */
- if (text != SWFDEC_AS_STR_EMPTY){
- fontmap = pango_cairo_font_map_get_default ();
- pcontext =
- pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP (fontmap));
-
- attrs = pango_attr_list_new ();
- item_list = pango_itemize (pcontext, text, 0, strlen (text), attrs, NULL);
- pango_attr_list_unref (attrs);
-
- analysis = ((PangoItem *)(item_list[0].data))->analysis;
- pango_shape (text, strlen (text), &analysis, glyph_string);
-
- desc = pango_font_description_new ();
- pango_font_description_set_family_static (desc, format->attr.font);
- pango_font_description_set_size (desc, format->attr.size * PANGO_SCALE);
- if (format->attr.bold){
- pango_font_description_set_weight (desc, PANGO_WEIGHT_BOLD);
- }
- if (format->attr.italic)
- pango_font_description_set_style (desc, PANGO_STYLE_ITALIC);
-
- font = pango_font_map_load_font (fontmap, pcontext, desc);
- pango_glyph_string_extents (glyph_string, font, &ink_rect, NULL);
-
- pango_glyph_string_free (glyph_string);
- g_list_foreach (item_list, (GFunc) pango_item_free, NULL);
- g_list_free (item_list);
- pango_font_description_free (desc);
- g_object_unref (G_OBJECT (pcontext));
- g_object_unref (G_OBJECT (font));
-
- width = ink_rect.width / PANGO_SCALE + format->attr.left_margin
- + format->attr.right_margin;
- height = ink_rect.height / PANGO_SCALE + format->attr.leading;
- ascent = PANGO_ASCENT(ink_rect) / PANGO_SCALE;
- descent = PANGO_DESCENT (ink_rect) / PANGO_SCALE;
- text_field_width = ink_rect.width / PANGO_SCALE + format->attr.left_margin
- + format->attr.right_margin + 4;
- text_field_height = ink_rect.height / PANGO_SCALE + 4 + format->attr.leading;
- }
+ obj = swfdec_as_object_new_empty (cx);
+ if (obj == NULL)
+ return;
- SWFDEC_AS_VALUE_SET_INT (&val, width);
+ buffer = swfdec_text_buffer_new ();
+ swfdec_text_buffer_set_attributes (buffer, 0, 0,
+ &format->attr, format->values_set);
+ swfdec_text_buffer_append_text (buffer, text);
+ layout = swfdec_text_layout_new (buffer);
+
+ i = swfdec_text_layout_get_width (layout);
+ SWFDEC_AS_VALUE_SET_INT (&val, i);
swfdec_as_object_set_variable (obj, SWFDEC_AS_STR_width, &val);
+ if (i)
+ i += 4;
+ SWFDEC_AS_VALUE_SET_INT (&val, i);
+ swfdec_as_object_set_variable (obj, SWFDEC_AS_STR_textFieldWidth, &val);
- SWFDEC_AS_VALUE_SET_INT (&val, height);
+ i = swfdec_text_layout_get_height (layout);
+ SWFDEC_AS_VALUE_SET_INT (&val, i);
swfdec_as_object_set_variable (obj, SWFDEC_AS_STR_height, &val);
+ if (i)
+ i += 4;
+ SWFDEC_AS_VALUE_SET_INT (&val, i);
+ swfdec_as_object_set_variable (obj, SWFDEC_AS_STR_textFieldHeight, &val);
- SWFDEC_AS_VALUE_SET_INT (&val, ascent);
+ swfdec_text_layout_get_ascent_descent (layout, &i, &j);
+ SWFDEC_AS_VALUE_SET_INT (&val, i);
swfdec_as_object_set_variable (obj, SWFDEC_AS_STR_ascent, &val);
-
- SWFDEC_AS_VALUE_SET_INT (&val, descent);
+ SWFDEC_AS_VALUE_SET_INT (&val, j);
swfdec_as_object_set_variable (obj, SWFDEC_AS_STR_descent, &val);
- SWFDEC_AS_VALUE_SET_INT (&val, text_field_width);
- swfdec_as_object_set_variable (obj, SWFDEC_AS_STR_textFieldWidth, &val);
-
- SWFDEC_AS_VALUE_SET_INT (&val, text_field_height);
- swfdec_as_object_set_variable (obj, SWFDEC_AS_STR_textFieldHeight, &val);
-
SWFDEC_AS_VALUE_SET_OBJECT (ret, obj);
+ g_object_unref (layout);
+ g_object_unref (buffer);
}
void
diff --git a/swfdec/swfdec_text_layout.c b/swfdec/swfdec_text_layout.c
index 775cb5b..505d41c 100644
--- a/swfdec/swfdec_text_layout.c
+++ b/swfdec/swfdec_text_layout.c
@@ -772,6 +772,35 @@ out:
return MAX (count, 1);
}
+void
+swfdec_text_layout_get_ascent_descent (SwfdecTextLayout *layout, int *ascent,
+ int *descent)
+{
+ SwfdecTextBlock *block;
+ GSequenceIter *iter;
+ PangoLayoutLine *line;
+ PangoRectangle rect;
+
+ g_return_if_fail (SWFDEC_IS_TEXT_LAYOUT (layout));
+ g_return_if_fail (ascent != NULL);
+ g_return_if_fail (descent != NULL);
+
+ if (swfdec_text_buffer_get_length (layout->text) == 0) {
+ *ascent = 0;
+ *descent = 0;
+ return;
+ }
+
+ swfdec_text_layout_ensure (layout);
+ iter = g_sequence_get_begin_iter (layout->blocks);
+ block = g_sequence_get (iter);
+ line = pango_layout_get_line_readonly (block->layout, 0);
+ pango_layout_line_get_pixel_extents (line, NULL, &rect);
+
+ *ascent = PANGO_ASCENT (rect) - 1; /* don't ask me... */
+ *descent = PANGO_DESCENT (rect);
+}
+
static int
swfdec_text_layout_get_line_offset (SwfdecTextLayout *layout,
SwfdecTextBlock *block, PangoLayoutLine *line)
diff --git a/swfdec/swfdec_text_layout.h b/swfdec/swfdec_text_layout.h
index 34fc3a3..dccd79c 100644
--- a/swfdec/swfdec_text_layout.h
+++ b/swfdec/swfdec_text_layout.h
@@ -82,6 +82,9 @@ guint swfdec_text_layout_get_visible_rows (SwfdecTextLayout * layout,
guint height);
guint swfdec_text_layout_get_visible_rows_end (SwfdecTextLayout * layout,
guint height);
+void swfdec_text_layout_get_ascent_descent (SwfdecTextLayout * layout,
+ int * ascent,
+ int * descent);
void swfdec_text_layout_render (SwfdecTextLayout * layout,
cairo_t * cr,
commit 255d8e976ab700d9030e9e107edd116ecfe9af15
Author: Benjamin Otte <otte at gnome.org>
Date: Wed May 14 18:02:01 2008 +0200
remove debugging printf that complained on 32bit
diff --git a/vivified/code/vivi_parser_scanner_lex.l b/vivified/code/vivi_parser_scanner_lex.l
index 76d6c62..50dfa88 100644
--- a/vivified/code/vivi_parser_scanner_lex.l
+++ b/vivified/code/vivi_parser_scanner_lex.l
@@ -300,7 +300,6 @@ identifier_part [$_a-zA-Z0-9]
if (result == 0) {
ERROR ("Invalid escape sequence %s", yytext);
} else {
- g_print (":: %lu\n", result);
g_string_append_unichar (value->value.v_string, result);
}
}
commit e7530c21408249c3bea3dc6a2b7a7581d29e8da0
Merge: f38ea83... 5dcacb8...
Author: Benjamin Otte <otte at gnome.org>
Date: Wed May 14 17:53:22 2008 +0200
Merge branch '0.6'
Conflicts:
swfdec/swfdec_net_stream.c
commit 5dcacb87f3098ff9603f75ba5d25526c4f3696a1
Author: Benjamin Otte <otte at gnome.org>
Date: Wed May 14 17:45:12 2008 +0200
more places where the FLV decoder can be gone (fixes #15932)
diff --git a/swfdec/swfdec_net_stream.c b/swfdec/swfdec_net_stream.c
index 39b5463..5e057bf 100644
--- a/swfdec/swfdec_net_stream.c
+++ b/swfdec/swfdec_net_stream.c
@@ -108,6 +108,8 @@ swfdec_net_stream_video_goto (SwfdecNetStream *stream, guint timestamp)
cairo_surface_destroy (stream->surface);
stream->surface = NULL;
}
+ if (stream->flvdecoder == NULL)
+ return;
if (stream->flvdecoder->video) {
buffer = swfdec_flv_decoder_get_video (stream->flvdecoder, timestamp,
FALSE, &format, &stream->current_time, &stream->next_time);
@@ -142,7 +144,7 @@ swfdec_net_stream_video_goto (SwfdecNetStream *stream, guint timestamp)
swfdec_net_stream_update_playing (stream);
}
if (process_events) {
- while (process_events_from <= stream->current_time) {
+ while (stream->flvdecoder && process_events_from <= stream->current_time) {
SwfdecAsValue name, value;
SwfdecBits bits;
SwfdecBuffer *event = swfdec_flv_decoder_get_data (stream->flvdecoder, process_events_from, &process_events_from);
commit bd1aff30e24967543069d0a1c27241860dd18682
Author: Benjamin Otte <otte at gnome.org>
Date: Wed May 14 17:31:10 2008 +0200
check the onStatus event emission didn't remove the FLV decoder (fixes #15932)
diff --git a/swfdec/swfdec_net_stream.c b/swfdec/swfdec_net_stream.c
index 5db95d8..39b5463 100644
--- a/swfdec/swfdec_net_stream.c
+++ b/swfdec/swfdec_net_stream.c
@@ -303,6 +303,8 @@ swfdec_net_stream_stream_target_close (SwfdecStreamTarget *target,
swfdec_decoder_eof (SWFDEC_DECODER (ns->flvdecoder));
swfdec_net_stream_onstatus (ns, SWFDEC_AS_STR_NetStream_Buffer_Flush,
SWFDEC_AS_STR_status);
+ if (ns->flvdecoder == NULL)
+ return;
swfdec_net_stream_video_goto (ns, ns->current_time);
ns->buffering = FALSE;
if (swfdec_flv_decoder_get_video_info (ns->flvdecoder, &first, &last) &&
More information about the Swfdec-commits
mailing list