1 /* ====================================================================
2 * Copyright (c) 2000-2003 by Soheil Seyfaie. All rights reserved.
3 * This program is free software; you can redistribute it and/or modify
4 * it under the same terms as Perl itself.
5 * ====================================================================
6 *
7 * $Id$
8 */
9
10 #include "perl_swf.h"
11
12 static char *SWF_Fill_tag[] = {
13 "SWFFILL_SOLID",
14 "SWFFILL_GRADIENT",
15 "SWFFILL_LINEAR_GRADIENT",
16 "SWFFILL_RADIAL_GRADIENT",
17 "SWFFILL_FOCAL_GRADIENT",
18 "SWFFILL_BITMAP",
19 "SWFFILL_TILED_BITMAP",
20 "SWFFILL_CLIPPED_BITMAP",
21 "SWFFILL_NONSMOOTHED_TILED_BITMAP",
22 "SWFFILL_NONSMOOTHED_CLIPPED_BITMAP",
23 NULL,
24 };
25
26 static char *SWF_Button_tag[] = {
27 "SWFBUTTON_HIT",
28 "SWFBUTTON_DOWN",
29 "SWFBUTTON_OVER",
30 "SWFBUTTON_UP",
31 "SWFBUTTON_MOUSEUPOUTSIDE",
32 "SWFBUTTON_DRAGOVER",
33 "SWFBUTTON_DRAGOUT",
34 "SWFBUTTON_MOUSEUP",
35 "SWFBUTTON_MOUSEDOWN",
36 "SWFBUTTON_MOUSEOUT",
37 "SWFBUTTON_MOUSEOVER",
38 "SWFBUTTON_KEYPRESS",
39 "SWFBUTTON_ONKEYPRESS",
40 NULL,
41 };
42
43 static char *SWF_Sound_tag[] = {
44 "SWF_SOUND_NOT_COMPRESSED",
45 "SWF_SOUND_ADPCM_COMPRESSED",
46 "SWF_SOUND_MP3_COMPRESSED",
47 "SWF_SOUND_NOT_COMPRESSED_LE",
48 "SWF_SOUND_NELLY_COMPRESSED",
49 "SWF_SOUND_5KHZ",
50 "SWF_SOUND_11KHZ",
51 "SWF_SOUND_22KHZ",
52 "SWF_SOUND_44KHZ",
53 "SWF_SOUND_8BITS",
54 "SWF_SOUND_16BITS",
55 "SWF_SOUND_MONO",
56 "SWF_SOUND_STEREO",
57 NULL,
58 };
59
60 static char *SWF_TextField_tag[] = {
61 "SWFTEXTFIELD_NOEDIT",
62 "SWFTEXTFIELD_PASSWORD",
63 "SWFTEXTFIELD_DRAWBOX",
64 "SWFTEXTFIELD_MULTILINE",
65 "SWFTEXTFIELD_WORDWRAP",
66 "SWFTEXTFIELD_NOSELECT",
67 "SWFTEXTFIELD_ALIGN_LEFT",
68 "SWFTEXTFIELD_ALIGN_RIGHT",
69 "SWFTEXTFIELD_ALIGN_CENTER",
70 "SWFTEXTFIELD_ALIGN_JUSTIFY",
71 "SWFTEXTFIELD_HTML",
72 "SWFTEXTFIELD_HASLENGTH",
73 "SWFTEXTFIELD_USEFONT",
74 "SWFTEXTFIELD_AUTOSIZE",
75 NULL,
76 };
77
78
79 static char *SWF_DisplayItem_tag[] = {
80 "SWFACTION_ONLOAD",
81 "SWFACTION_ENTERFRAME",
82 "SWFACTION_UNLOAD",
83 "SWFACTION_MOUSEMOVE",
84 "SWFACTION_MOUSEDOWN",
85 "SWFACTION_MOUSEUP",
86 "SWFACTION_KEYDOWN",
87 "SWFACTION_KEYUP",
88 "SWFACTION_DATA",
89 "SWFBLEND_MODE_NULL",
90 "SWFBLEND_MODE_NORMAL",
91 "SWFBLEND_MODE_LAYER",
92 "SWFBLEND_MODE_MULT",
93 "SWFBLEND_MODE_SCREEN",
94 "SWFBLEND_MODE_DARKEN",
95 "SWFBLEND_MODE_LIGHTEN",
96 "SWFBLEND_MODE_ADD",
97 "SWFBLEND_MODE_SUB",
98 "SWFBLEND_MODE_DIFF",
99 "SWFBLEND_MODE_INV",
100 "SWFBLEND_MODE_ALPHA",
101 "SWFBLEND_MODE_ERASE",
102 "SWFBLEND_MODE_OVERLAY",
103 "SWFBLEND_MODE_HARDLIGHT",
104 NULL,
105 };
106
107 static char *SWF_Filter_tag[] = {
108 "SWF_FILTER_MODE_INNER",
109 "SWF_FILTER_MODE_KO",
110 "SWF_FILTER_MODE_COMPOSITE",
111 "SWF_FILTER_MODE_ONTOP",
112 "SWF_FILTER_CLAMP",
113 "SWF_FILTER_FLAG_PRESERVE_ALPHA",
114 NULL,
115 };
116
117 static char *SWF_Gradient_tag[] = {
118 "SWF_GRADIENT_PAD",
119 "SWF_GRADIENT_REFLECT",
120 "SWF_GRADIENT_REPEAT",
121 "SWF_GRADIENT_NORMAL",
122 "SWF_GRADIENT_LINEAR",
123 NULL,
124 };
125
126 static char *SWF_Shape_tag[] = {
127 "SWF_SHAPE_USESCALINGSTROKES",
128 "SWF_SHAPE_USENONSCALINGSTROKES",
129 "SWF_LINESTYLE_CAP_ROUND",
130 "SWF_LINESTYLE_CAP_NONE",
131 "SWF_LINESTYLE_CAP_SQUARE",
132 "SWF_LINESTYLE_JOIN_ROUND",
133 "SWF_LINESTYLE_JOIN_BEVEL",
134 "SWF_LINESTYLE_JOIN_MITER",
135 "SWF_LINESTYLE_FLAG_NOHSCALE",
136 "SWF_LINESTYLE_FLAG_NOVSCALE",
137 "SWF_LINESTYLE_FLAG_HINTING",
138 "SWF_LINESTYLE_FLAG_NOCLOSE",
139 "SWF_LINESTYLE_FLAG_ENDCAP_ROUND",
140 "SWF_LINESTYLE_FLAG_ENDCAP_NONE",
141 "SWF_LINESTYLE_FLAG_ENDCAP_SQUARE",
142 NULL,
143 };
144
145 static char *SWF_Video_tag[] = {
146 "SWFVIDEOSTREAM_MODE_AUTO",
147 "SWFVIDEOSTREAM_MODE_MANUAL",
148 NULL,
149 };
150
151
export_tags(char * tag)152 static char **export_tags(char *tag) {
153 switch (*tag) {
154 case 'B':
155 if(strEQ("Button", tag))
156 return SWF_Button_tag;
157 case 'D':
158 if(strEQ("DisplayItem", tag))
159 return SWF_DisplayItem_tag;
160 case 'F':
161 if(strEQ("Fill", tag))
162 return SWF_Fill_tag;
163 if(strEQ("Filter", tag))
164 return SWF_Filter_tag;
165 case 'G':
166 if(strEQ("Gradient", tag))
167 return SWF_Gradient_tag;
168 case 'S':
169 if(strEQ("Sound", tag))
170 return SWF_Sound_tag;
171 if(strEQ("Shape", tag))
172 return SWF_Shape_tag;
173 case 'T':
174 if(strEQ("Text", tag))
175 return SWF_TextField_tag;
176 case 'V':
177 if(strEQ("Video", tag))
178 return SWF_Video_tag;
179 default:
180 croak("unknown tag `%s'", tag);
181 }
182 }
183
184
export_cv(SV * class,SV * caller,char * sub)185 void export_cv(SV *class, SV *caller, char *sub)
186 {
187 GV *gv;
188 #if 0
189 fprintf(stderr, "Here is the result: *%s::%s = \\&%s::%s\n",
190 SvPVX(caller), sub, SvPVX(class), sub);
191 #endif
192 gv = gv_fetchpv(form("%s::%s",SvPVX( caller), sub), TRUE, SVt_PVCV);
193 GvCV_set(gv, perl_get_cv(form("%s::%s", SvPVX(class), sub), TRUE));
194 GvIMPORTED_CV_on(gv);
195 GvMULTI_on(gv);
196 }
197
my_import(SV * pclass,SV * caller,SV * sv)198 static void my_import(SV *pclass, SV *caller, SV *sv)
199 {
200 char *sym = SvPV(sv,na), **tags;
201 int i;
202
203 switch (*sym) {
204 case ':':
205 ++sym;
206 tags = export_tags(sym);
207 for(i=0; tags[i]; i++) {
208 export_cv(pclass, caller, tags[i]);
209 }
210 break;
211 case '$':
212 case '%':
213 case '*':
214 case '@':
215 croak("\"%s\" is not exported by the SWF module", sym);
216 case '&':
217 ++sym;
218 default:
219 if(isALPHA(sym[0])) {
220 export_cv(pclass, caller, sym);
221 break;
222 }
223 else {
224 croak("Can't export symbol: %s", sym);
225 }
226 }
227 }
228