OSDN Git Service

update SWFED_VERSION from 0.55a to 0.55
[swfed/swfed.git] / src / swf_line_style.c
1 #include <stdio.h>
2 #include "bitstream.h"
3 #include "swf_line_style.h"
4
5 int
6 swf_line_style_parse(bitstream_t *bs, swf_line_style_t *line_style,
7                      swf_tag_t *tag) {
8     int result;
9     if (tag->code == 46) { // DefineMorphShape
10         result = bitstream_getbytesLE(bs, 2);
11         if (result == -1) {
12             return 1;
13         }
14         line_style->width = result;
15         line_style->width_morph = bitstream_getbytesLE(bs, 2);
16         swf_rgba_parse(bs, &(line_style->rgba));
17         swf_rgba_parse(bs, &(line_style->rgba_morph));
18     } else if (tag->code == 83 || tag->code == 84) {
19         // DefineShape4 || DefineMorphShape2
20         if (tag->code == 84) { // DefineMorphShape2
21             line_style->width_morph = bitstream_getbytesLE(bs, 2);
22         }
23         result = bitstream_getbits(bs, 2);
24         if (result == -1) {
25             return 1;
26         }
27         line_style->start_cap_style = result;
28         line_style->join_style = bitstream_getbits(bs, 2);
29         line_style->has_fill = bitstream_getbits(bs, 1);
30         line_style->no_hscale = bitstream_getbits(bs, 1);
31         line_style->no_vscale = bitstream_getbits(bs, 1);
32         line_style->pixel_hinting = bitstream_getbits(bs, 1);
33         line_style->reserved = bitstream_getbits(bs, 5);
34         line_style->no_close = bitstream_getbits(bs, 1);
35         line_style->end_cap_style = bitstream_getbits(bs, 2);
36         if (line_style->join_style == 2) {
37             line_style->miter_limit_factor = bitstream_getbytesLE(bs, 2);
38         }
39         if (line_style->has_fill) {
40             swf_fill_style_parse(bs, &(line_style->fill_style), tag);
41         } else {
42             swf_rgba_parse(bs, &(line_style->rgba));
43             if (tag->code == 84) { // DefineMorphShape2
44                 swf_rgba_parse(bs, &(line_style->rgba_morph));
45             }
46         }
47     } else if (tag->code == 32) { // DefineShape3
48         result = bitstream_getbytesLE(bs, 2);
49         if (result == -1) {
50             return 1;
51         }
52         line_style->width = result;
53         swf_rgba_parse(bs, &(line_style->rgba));
54     } else {
55         result = bitstream_getbytesLE(bs, 2);
56         if (result == -1) {
57             return 1;
58         }
59         line_style->width = result;
60         swf_rgb_parse(bs, &(line_style->rgb));
61     }
62     return 0;
63 }
64
65 int
66 swf_line_style_build(bitstream_t *bs, swf_line_style_t *line_style,
67                      swf_tag_t *tag) {
68     if (tag->code == 46) { // DefineMorphShape
69         bitstream_putbytesLE(bs, line_style->width, 2);
70         bitstream_putbytesLE(bs, line_style->width_morph, 2);
71         swf_rgba_build(bs, &(line_style->rgba));
72         swf_rgba_build(bs, &(line_style->rgba_morph));
73     } else if (tag->code == 83 || tag->code == 84) {
74         // DefineShape4 || DefineMorphShape2
75         if (tag->code == 84) { // DefineMorphShape2
76             bitstream_putbytesLE(bs, line_style->width_morph, 2);
77         }
78         bitstream_putbits(bs, line_style->start_cap_style, 2);
79         bitstream_putbits(bs, line_style->join_style, 2);
80         bitstream_putbits(bs, line_style->has_fill, 1);
81         bitstream_putbits(bs, line_style->no_hscale, 1);
82         bitstream_putbits(bs, line_style->no_vscale, 1);
83         bitstream_putbits(bs, line_style->pixel_hinting, 1);
84         bitstream_putbits(bs, line_style->reserved , 5);
85         bitstream_putbits(bs, line_style->no_close, 1);
86         bitstream_putbits(bs, line_style->end_cap_style, 2);
87         if (line_style->join_style == 2) {
88             bitstream_putbytesLE(bs, line_style->miter_limit_factor, 2);
89         }
90         if (line_style->has_fill) {
91             swf_fill_style_build(bs, &(line_style->fill_style), tag);
92         } else {
93             swf_rgba_build(bs, &(line_style->rgba));
94             if (tag->code == 84) { // DefineMorphShape2
95                 swf_rgba_build(bs, &(line_style->rgba_morph));
96             }
97         }
98     } else if (tag->code == 32) { // DefineShape3
99         bitstream_putbytesLE(bs, line_style->width, 2);
100         swf_rgba_build(bs, &(line_style->rgba));
101     } else {
102         bitstream_putbytesLE(bs, line_style->width, 2);
103         swf_rgb_build(bs, &(line_style->rgb));
104     }
105     return 0;
106 }
107
108 int
109 swf_line_style_print(swf_line_style_t *line_style, int indent_depth,
110                      swf_tag_t *tag) {
111     if (line_style == NULL) {
112         fprintf(stderr, "swf_line_style_print: line_style == NULL\n");
113         return 1;
114     }
115     if (tag->code == 46) { // DefineMorphShape
116         print_indent(indent_depth);
117         printf("width=%.2f  width_morph=%.2f\n",
118                (float) line_style->width / SWF_TWIPS,
119                (float) line_style->width_morph / SWF_TWIPS);
120         swf_rgba_print(&(line_style->rgba), indent_depth);
121         swf_rgba_print(&(line_style->rgba_morph), indent_depth);
122     } else if (tag->code == 83 || tag->code == 84) {
123         // DefineShape4 || DefineMorphShape2
124         if (tag->code == 84) { // DefineMorphShape2
125             print_indent(indent_depth);
126             printf("width_morph=%d\n", line_style->width_morph);
127         }
128         print_indent(indent_depth);
129         printf("start_cap_style=%u  join_style=%u  has_fill=%u\n",
130                line_style->start_cap_style,
131                line_style->join_style, line_style->has_fill);
132         print_indent(indent_depth);
133         printf("no_hscale=%u  no_vscale=%u  pixel_hinting=%u\n",
134                line_style->no_hscale, line_style->no_vscale,
135                line_style->pixel_hinting);
136         print_indent(indent_depth);
137         printf("(reserved=%u)  no_close=%u end_cap_style=%u\n",
138                line_style->reserved, line_style->no_close,
139                line_style->end_cap_style);
140         if (line_style->join_style == 2) {
141             print_indent(indent_depth);
142             printf("miter_limit_factor=%u\n", line_style->miter_limit_factor);
143         }
144         if (line_style->has_fill) {
145             swf_fill_style_print(&(line_style->fill_style), indent_depth + 1,
146                 tag);
147         } else {
148             swf_rgba_print(&(line_style->rgba), indent_depth);
149             if (tag->code == 84) { // DefineMorphShape2
150                 swf_rgba_print(&(line_style->rgba_morph), indent_depth);
151             }
152         }
153     } else if (tag->code == 32) { // DefineShape3
154         print_indent(indent_depth);
155         printf("width=%.2f ", (float) line_style->width / SWF_TWIPS);
156         swf_rgba_print(&(line_style->rgba), 0);
157     } else {
158         print_indent(indent_depth);
159         printf("width=%.2f ", (float) line_style->width / SWF_TWIPS);
160         swf_rgb_print(&(line_style->rgb), 0);
161     }
162     return 0;
163 }
164
165 int
166 swf_line_style_delete(swf_line_style_t *line_style) {
167     if (line_style->has_fill) {
168         swf_fill_style_delete(&(line_style->fill_style));
169     }
170     return 0;
171 }