⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swfdec_tag.c

📁 Swfdec still is development software, but has also followed a rigid no-crashes-allowed policy. I b
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Swfdec * Copyright (C) 2003-2006 David Schleef <ds@schleef.org> *		 2005-2006 Eric Anholt <eric@anholt.net> *		 2006-2007 Benjamin Otte <otte@gnome.org> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. *  * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. *  * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor,  * Boston, MA  02110-1301  USA */#ifdef HAVE_CONFIG_H#include "config.h"#endif#include <zlib.h>#include <math.h>#include <string.h>#include <stdlib.h>#include "swfdec_tag.h"#include "swfdec_bits.h"#include "swfdec_button.h"#include "swfdec_debug.h"#include "swfdec_edittext.h"#include "swfdec_font.h"#include "swfdec_image.h"#include "swfdec_morphshape.h"#include "swfdec_movie.h" /* for SwfdecContent */#include "swfdec_pattern.h"#include "swfdec_root_sprite.h"#include "swfdec_script.h"#include "swfdec_shape.h"#include "swfdec_sound.h"#include "swfdec_sprite.h"#include "swfdec_text.h"#include "swfdec_video.h"inttag_func_end (SwfdecSwfDecoder * s){  return SWFDEC_STATUS_OK;}inttag_func_protect (SwfdecSwfDecoder * s){  if (s->protection) {    SWFDEC_INFO ("This file is really protected.");    g_free (s->password);    s->password = NULL;  }  s->protection = TRUE;  if (swfdec_bits_left (&s->b)) {    /* FIXME: What's this for? */    swfdec_bits_get_u16 (&s->b);    s->password = swfdec_bits_get_string (&s->b);  }  return SWFDEC_STATUS_OK;}inttag_func_frame_label (SwfdecSwfDecoder * s){  SwfdecSpriteFrame *frame = &s->parse_sprite->frames[s->parse_sprite->parse_frame];    if (frame->label) {    SWFDEC_WARNING ("frame %d already has a label (%s)", s->parse_sprite->parse_frame, frame->label);    g_free (frame->label);  }  frame->label = swfdec_bits_get_string (&s->b);  SWFDEC_LOG ("frame %d named %s", s->parse_sprite->parse_frame, frame->label);  return SWFDEC_STATUS_OK;}/* text */static intdefine_text (SwfdecSwfDecoder * s, int rgba){  SwfdecBits *bits = &s->b;  int id;  int n_glyph_bits;  int n_advance_bits;  SwfdecText *text = NULL;  SwfdecTextGlyph glyph = { 0 };  id = swfdec_bits_get_u16 (bits);  text = swfdec_swf_decoder_create_character (s, id, SWFDEC_TYPE_TEXT);  if (!text)    return SWFDEC_STATUS_OK;  glyph.color = 0xffffffff;  swfdec_bits_get_rect (bits, &SWFDEC_GRAPHIC (text)->extents);  swfdec_bits_get_matrix (bits, &text->transform, &text->transform_inverse);  swfdec_bits_syncbits (bits);  n_glyph_bits = swfdec_bits_get_u8 (bits);  n_advance_bits = swfdec_bits_get_u8 (bits);  //printf("  n_glyph_bits = %d\n", n_glyph_bits);  //printf("  n_advance_bits = %d\n", n_advance_bits);  while (swfdec_bits_peekbits (bits, 8) != 0) {    int type;    type = swfdec_bits_getbit (bits);    if (type == 0) {      /* glyph record */      int n_glyphs;      int i;      n_glyphs = swfdec_bits_getbits (bits, 7);      if (glyph.font == NULL)	SWFDEC_ERROR ("no font for %d glyphs", n_glyphs);      for (i = 0; i < n_glyphs; i++) {        glyph.glyph = swfdec_bits_getbits (bits, n_glyph_bits);	if (glyph.font != NULL)	  g_array_append_val (text->glyphs, glyph);        glyph.x += swfdec_bits_getsbits (bits, n_advance_bits);      }    } else {      /* state change */      int reserved;      int has_font;      int has_color;      int has_y_offset;      int has_x_offset;      reserved = swfdec_bits_getbits (bits, 3);      has_font = swfdec_bits_getbit (bits);      has_color = swfdec_bits_getbit (bits);      has_y_offset = swfdec_bits_getbit (bits);      has_x_offset = swfdec_bits_getbit (bits);      if (has_font) {        glyph.font = swfdec_swf_decoder_get_character (s, swfdec_bits_get_u16 (bits));        //printf("  font = %d\n",font);      }      if (has_color) {        if (rgba) {          glyph.color = swfdec_bits_get_rgba (bits);        } else {          glyph.color = swfdec_bits_get_color (bits);        }        //printf("  color = %08x\n",glyph.color);      }      if (has_x_offset) {        glyph.x = swfdec_bits_get_s16 (bits);      }      if (has_y_offset) {        glyph.y = swfdec_bits_get_s16 (bits);      }      if (has_font) {        glyph.height = swfdec_bits_get_u16 (bits);      }    }    swfdec_bits_syncbits (bits);  }  swfdec_bits_get_u8 (bits);  return SWFDEC_STATUS_OK;}inttag_func_define_text (SwfdecSwfDecoder * s){  return define_text (s, 0);}inttag_func_define_text_2 (SwfdecSwfDecoder * s){  return define_text (s, 1);}inttag_func_define_sprite (SwfdecSwfDecoder * s){  SwfdecBits parse;  int id;  SwfdecSprite *sprite;  int ret;  guint tag;  parse = s->b;  id = swfdec_bits_get_u16 (&parse);  sprite = swfdec_swf_decoder_create_character (s, id, SWFDEC_TYPE_SPRITE);  if (!sprite)    return SWFDEC_STATUS_OK;  SWFDEC_LOG ("  ID: %d", id);  swfdec_sprite_set_n_frames (sprite, swfdec_bits_get_u16 (&parse), SWFDEC_DECODER (s)->rate);  s->parse_sprite = sprite;  do {    int x;    guint tag_len;    SwfdecBuffer *buffer;    SwfdecTagFunc *func;    x = swfdec_bits_get_u16 (&parse);    tag = (x >> 6) & 0x3ff;    tag_len = x & 0x3f;    if (tag_len == 0x3f) {      tag_len = swfdec_bits_get_u32 (&parse);    }    SWFDEC_INFO ("sprite parsing at %td, tag %d %s, length %d",        parse.ptr - parse.buffer->data, tag,        swfdec_swf_decoder_get_tag_name (tag), tag_len);    if (tag_len == 0) {      buffer = NULL;      swfdec_bits_init_data (&s->b, NULL, 0);    } else {      buffer = swfdec_bits_get_buffer (&parse, tag_len);      if (buffer == NULL) {	SWFDEC_ERROR ("tag claims to be %u bytes long, but not enough bytes remaining",	    tag_len);	break;      }      swfdec_bits_init (&s->b, buffer);    }    func = swfdec_swf_decoder_get_tag_func (tag);    if (func == NULL) {      SWFDEC_WARNING ("tag function not implemented for %d %s",          tag, swfdec_swf_decoder_get_tag_name (tag));    } else if ((swfdec_swf_decoder_get_tag_flag (tag) & 1) == 0) {      SWFDEC_ERROR ("invalid tag %d %s during DefineSprite",          tag, swfdec_swf_decoder_get_tag_name (tag));    } else {      ret = func (s);      if (swfdec_bits_left (&s->b)) {        SWFDEC_WARNING ("early parse finish (%d bytes)", 	    swfdec_bits_left (&s->b) / 8);      }    }    if (buffer)      swfdec_buffer_unref (buffer);  } while (tag != 0);  s->b = parse;  /* this assumes that no recursive DefineSprite happens and we check it doesn't */  s->parse_sprite = s->main_sprite;  SWFDEC_LOG ("done parsing this sprite");  return SWFDEC_STATUS_OK;}inttag_func_do_action (SwfdecSwfDecoder * s){  SwfdecScript *script;  char *name;  name = g_strdup_printf ("Sprite%u.Frame%u", SWFDEC_CHARACTER (s->parse_sprite)->id,      s->parse_sprite->parse_frame);  script = swfdec_script_new_for_player (SWFDEC_DECODER (s)->player, &s->b, name, s->version);  g_free (name);  if (script)    swfdec_sprite_add_action (s->parse_sprite, SWFDEC_SPRITE_ACTION_SCRIPT, script);  return SWFDEC_STATUS_OK;}static voidswfdec_button_append_content (SwfdecButton *button, guint states, SwfdecContent *content){  guint i;  SwfdecContent *cur = NULL;  for (i = 0; i < 4; i++) {    if (!cur && (states & 1)) {      cur = content;      if (content->end != G_MAXUINT) {	/* need a copy here */	cur = swfdec_content_new (content->depth);	*cur = *content;	cur->sequence = cur;      }      cur->start = i;      button->records = g_list_append (button->records, cur);    }    if (cur && !(states & 1)) {      cur->end = i;      cur = NULL;    }    states >>= 1;  }  if (cur) {    SwfdecRect rect;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -