OSDN Git Service

DefineShape 系の実装てはじめ
authoryoya <yoya@7c90b180-03d5-4157-b861-58a559ae9d1e>
Mon, 18 May 2009 16:48:54 +0000 (16:48 +0000)
committeryoya <yoya@7c90b180-03d5-4157-b861-58a559ae9d1e>
Mon, 18 May 2009 16:48:54 +0000 (16:48 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/swfed/trunk@126 7c90b180-03d5-4157-b861-58a559ae9d1e

src/swf_tag_shape.c [new file with mode: 0644]
src/swf_tag_shape.h [new file with mode: 0644]

diff --git a/src/swf_tag_shape.c b/src/swf_tag_shape.c
new file mode 100644 (file)
index 0000000..7c0155d
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+  +----------------------------------------------------------------------+
+  | Author: yoya@awm.jp                                                  |
+  +----------------------------------------------------------------------+
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include "bitstream.h"
+#include "swf_tag_shape.h"
+#include "swf_object.h"
+
+swf_tag_detail_handler_t shape_detail_handler;
+
+swf_tag_detail_handler_t *
+swf_tag_shape_detail_handler(void) {
+    shape_detail_handler.create   = swf_tag_shape_create_detail;
+    shape_detail_handler.input    = swf_tag_shape_input_detail;
+    shape_detail_handler.identity = swf_tag_shape_identity_detail;
+    shape_detail_handler.output   = swf_tag_shape_output_detail;
+    shape_detail_handler.print    = swf_tag_shape_print_detail;
+    shape_detail_handler.destroy  = swf_tag_shape_destroy_detail;
+    return &shape_detail_handler;
+}
+
+void *
+swf_tag_shape_create_detail(void) {
+    swf_tag_shape_detail_t *swf_tag_shape;
+    swf_tag_shape = calloc(sizeof(*swf_tag_shape), 1);
+    if (swf_tag_shape == NULL) {
+        fprintf(stderr, "ERROR: swf_tag_shape_create_detail: can't calloc\n");
+        return NULL;
+    }
+    return swf_tag_shape;
+}
+
+int
+swf_tag_shape_input_detail(swf_tag_t *tag, struct swf_object_ *swf) {
+    swf_tag_shape_detail_t *swf_tag_shape = tag->detail;
+    unsigned char *data  = tag->data;
+    unsigned long length = tag->length;
+    bitstream_t *bs;
+    swf_tag_t **_tag;
+    if (swf_tag_shape == NULL) {
+        fprintf(stderr, "ERROR: swf_tag_shape_input_detail: swf_tag_shape == NULL\n");
+        return 1;
+    }
+    bs = bitstream_open();
+    bitstream_input(bs, data, length);
+    swf_tag_shape->shape_id = bitstream_getbytesLE(bs, 2);
+    bitstream_close(bs);
+    return 0;
+}
+
+int swf_tag_shape_identity_detail(swf_tag_t *tag, int id) {
+    unsigned char *data = tag->data;
+    bitstream_t *bs;
+    int shape_id;
+    if (tag->detail) {
+        swf_tag_shape_detail_t *swf_tag_shape = (swf_tag_shape_detail_t *) tag->detail;
+        if (swf_tag_shape->shape_id == id) {
+            return 0;
+        }        
+        return 1;
+    }
+    bs = bitstream_open();
+    bitstream_input(bs, data, 2);
+    shape_id = bitstream_getbytesLE(bs, 2);
+    bitstream_close(bs);
+    if (id == shape_id) {
+        return 0;
+    }        
+    return 1;
+}
+
+unsigned char *
+swf_tag_shape_output_detail(swf_tag_t *tag, unsigned long *length,
+                           struct swf_object_ *swf) {
+    swf_tag_shape_detail_t *swf_tag_shape = (swf_tag_shape_detail_t *) tag->detail;
+    bitstream_t *bs;
+    unsigned char *data;
+    swf_tag_t *_tag;
+    *length = 0;
+    bs = bitstream_open();
+    bitstream_putbytesLE(bs, swf_tag_shape->shape_id, 2);
+    data = bitstream_steal(bs, length);
+    bitstream_close(bs);
+    return data;
+}
+
+void
+swf_tag_shape_print_detail(swf_tag_t *tag,
+                          struct swf_object_ *swf) {
+    swf_tag_shape_detail_t *swf_tag_shape = (swf_tag_shape_detail_t *) tag->detail;
+    int i;
+    swf_tag_t *_tag;
+    printf("\tshape_id=%d\n", swf_tag_shape->shape_id);
+    return ;
+}
+
+void
+swf_tag_shape_destroy_detail(swf_tag_t *tag) {
+    swf_tag_shape_detail_t *swf_tag_shape = (swf_tag_shape_detail_t *) tag->detail;
+    if (swf_tag_shape) {
+        free(swf_tag_shape);
+    }
+    return ;
+}
diff --git a/src/swf_tag_shape.h b/src/swf_tag_shape.h
new file mode 100644 (file)
index 0000000..98ee7a9
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+  +----------------------------------------------------------------------+
+  | Author: yoya@awm.jp                                                  |
+  +----------------------------------------------------------------------+
+*/
+
+#ifndef __SWF_TAG_SHAPE__H__
+#define __SWF_TAG_SHAPE__H__
+
+#include "swf_rect.h"
+// #include "swf_morph_shape_with_style.h"
+// #include "swf_shape_with_style.h"
+#include "swf_tag.h"
+
+typedef struct swf_tag_shape_detail_ {
+    int shape_id;
+    swf_rect_t rect;
+    //
+    unsigned char is_morph:1;    // DefineMorphShape, DefineMorphShape2
+    unsigned char has_strokes:1; // Defineshape4, DefineMorphShape2
+    // is_morph
+    swf_rect_t rect_morph;   // MorphShape(1) or 2
+    //has_strokes
+    swf_rect_t stroke_rect;  // Shape4 or MorphShape4
+    //// is_morph
+    swf_rect_t stroke_rect_morph;   // & MorphShape(1) or 2
+    //
+    // 6bit reserved area
+    unsigned char define_shape_non_scaling_strokes;
+    unsigned char define_shape_scaling_strokes;
+    // is_morph
+    unsigned long offset_morph;
+//     swf_morph_shape_with_style_t  morph_shape_with_style;
+    // else
+//     swf_shape_with_style_t  morph_shape_with_style;
+} swf_tag_shape_detail_t;
+
+extern swf_tag_detail_handler_t *swf_tag_shape_detail_handler(void);
+
+extern void *swf_tag_shape_create_detail(void);
+extern int swf_tag_shape_input_detail(swf_tag_t *tag, struct swf_object_ *swf);
+extern int swf_tag_shape_identity_detail(swf_tag_t *tag, int id);
+extern unsigned char *swf_tag_shape_output_detail(swf_tag_t *tag,
+                                                   unsigned long *length,
+                                                   struct swf_object_ *swf);
+extern void swf_tag_shape_print_detail(swf_tag_t *tag,
+                                        struct swf_object_ *swf);
+extern void swf_tag_shape_destroy_detail(swf_tag_t *tag);
+
+#endif /* __SWF_TAG_SHAPE__H__ */