swfmill 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. data/.document +5 -0
  2. data/.gitignore +23 -0
  3. data/.swfmill +240 -0
  4. data/LICENSE +340 -0
  5. data/README.rdoc +37 -0
  6. data/Rakefile +59 -0
  7. data/VERSION +1 -0
  8. data/ext/.gitignore +5 -0
  9. data/ext/extconf.rb +86 -0
  10. data/ext/swfmill/.gitignore +27 -0
  11. data/ext/swfmill/AUTHORS +9 -0
  12. data/ext/swfmill/COPYING +340 -0
  13. data/ext/swfmill/Makefile.am +14 -0
  14. data/ext/swfmill/Makefile.in +635 -0
  15. data/ext/swfmill/NEWS +189 -0
  16. data/ext/swfmill/README +170 -0
  17. data/ext/swfmill/TODO +33 -0
  18. data/ext/swfmill/aclocal.m4 +7712 -0
  19. data/ext/swfmill/autogen.sh +7 -0
  20. data/ext/swfmill/compile +142 -0
  21. data/ext/swfmill/config.guess +1516 -0
  22. data/ext/swfmill/config.sub +1626 -0
  23. data/ext/swfmill/configure +21868 -0
  24. data/ext/swfmill/configure.ac +55 -0
  25. data/ext/swfmill/depcomp +589 -0
  26. data/ext/swfmill/install-sh +519 -0
  27. data/ext/swfmill/ltmain.sh +6964 -0
  28. data/ext/swfmill/missing +367 -0
  29. data/ext/swfmill/src/Geom.cpp +107 -0
  30. data/ext/swfmill/src/Geom.h +100 -0
  31. data/ext/swfmill/src/Makefile.am +86 -0
  32. data/ext/swfmill/src/Makefile.in +1025 -0
  33. data/ext/swfmill/src/SWF.h +11941 -0
  34. data/ext/swfmill/src/SWFAction.cpp +41 -0
  35. data/ext/swfmill/src/SWFAction.h +19 -0
  36. data/ext/swfmill/src/SWFBasic.h +7 -0
  37. data/ext/swfmill/src/SWFFile.cpp +406 -0
  38. data/ext/swfmill/src/SWFFile.h +34 -0
  39. data/ext/swfmill/src/SWFFilter.cpp +25 -0
  40. data/ext/swfmill/src/SWFFilter.h +15 -0
  41. data/ext/swfmill/src/SWFGlyphList.cpp +262 -0
  42. data/ext/swfmill/src/SWFGlyphList.h +34 -0
  43. data/ext/swfmill/src/SWFIdItem.h +85 -0
  44. data/ext/swfmill/src/SWFIdItems.h +16 -0
  45. data/ext/swfmill/src/SWFItem.cpp +235 -0
  46. data/ext/swfmill/src/SWFItem.h +60 -0
  47. data/ext/swfmill/src/SWFList.h +179 -0
  48. data/ext/swfmill/src/SWFReader.cpp +352 -0
  49. data/ext/swfmill/src/SWFReader.h +73 -0
  50. data/ext/swfmill/src/SWFShapeItem.cpp +220 -0
  51. data/ext/swfmill/src/SWFShapeItem.h +45 -0
  52. data/ext/swfmill/src/SWFShapeMaker.cpp +401 -0
  53. data/ext/swfmill/src/SWFShapeMaker.h +128 -0
  54. data/ext/swfmill/src/SWFTag.cpp +49 -0
  55. data/ext/swfmill/src/SWFTag.h +20 -0
  56. data/ext/swfmill/src/SWFTrait.cpp +35 -0
  57. data/ext/swfmill/src/SWFTrait.h +22 -0
  58. data/ext/swfmill/src/SWFWriter.cpp +312 -0
  59. data/ext/swfmill/src/SWFWriter.h +84 -0
  60. data/ext/swfmill/src/base64.c +110 -0
  61. data/ext/swfmill/src/base64.h +15 -0
  62. data/ext/swfmill/src/codegen/Makefile.am +15 -0
  63. data/ext/swfmill/src/codegen/Makefile.in +346 -0
  64. data/ext/swfmill/src/codegen/basic.xsl +45 -0
  65. data/ext/swfmill/src/codegen/basics.xsl +235 -0
  66. data/ext/swfmill/src/codegen/dumper.xsl +109 -0
  67. data/ext/swfmill/src/codegen/header.xsl +131 -0
  68. data/ext/swfmill/src/codegen/mk.xsl +26 -0
  69. data/ext/swfmill/src/codegen/parser.xsl +196 -0
  70. data/ext/swfmill/src/codegen/parsexml.xsl +312 -0
  71. data/ext/swfmill/src/codegen/size.xsl +189 -0
  72. data/ext/swfmill/src/codegen/source.xml +2197 -0
  73. data/ext/swfmill/src/codegen/writer.xsl +190 -0
  74. data/ext/swfmill/src/codegen/writexml.xsl +138 -0
  75. data/ext/swfmill/src/swfmill.cpp +482 -0
  76. data/ext/swfmill/src/swft/Makefile.am +55 -0
  77. data/ext/swfmill/src/swft/Makefile.in +717 -0
  78. data/ext/swfmill/src/swft/Parser.cpp +76 -0
  79. data/ext/swfmill/src/swft/Parser.h +37 -0
  80. data/ext/swfmill/src/swft/SVGAttributeParser.cpp +78 -0
  81. data/ext/swfmill/src/swft/SVGAttributeParser.h +35 -0
  82. data/ext/swfmill/src/swft/SVGColor.cpp +116 -0
  83. data/ext/swfmill/src/swft/SVGColor.h +37 -0
  84. data/ext/swfmill/src/swft/SVGColors.h +167 -0
  85. data/ext/swfmill/src/swft/SVGGradient.cpp +258 -0
  86. data/ext/swfmill/src/swft/SVGGradient.h +81 -0
  87. data/ext/swfmill/src/swft/SVGPathParser.cpp +155 -0
  88. data/ext/swfmill/src/swft/SVGPathParser.h +126 -0
  89. data/ext/swfmill/src/swft/SVGPointsParser.cpp +51 -0
  90. data/ext/swfmill/src/swft/SVGPointsParser.h +25 -0
  91. data/ext/swfmill/src/swft/SVGStyle.cpp +181 -0
  92. data/ext/swfmill/src/swft/SVGStyle.h +80 -0
  93. data/ext/swfmill/src/swft/SVGTransformParser.cpp +72 -0
  94. data/ext/swfmill/src/swft/SVGTransformParser.h +32 -0
  95. data/ext/swfmill/src/swft/readpng.c +305 -0
  96. data/ext/swfmill/src/swft/readpng.h +92 -0
  97. data/ext/swfmill/src/swft/swft.cpp +251 -0
  98. data/ext/swfmill/src/swft/swft.h +64 -0
  99. data/ext/swfmill/src/swft/swft_document.cpp +57 -0
  100. data/ext/swfmill/src/swft/swft_import.cpp +38 -0
  101. data/ext/swfmill/src/swft/swft_import_binary.cpp +82 -0
  102. data/ext/swfmill/src/swft/swft_import_jpeg.cpp +255 -0
  103. data/ext/swfmill/src/swft/swft_import_mp3.cpp +268 -0
  104. data/ext/swfmill/src/swft/swft_import_png.cpp +231 -0
  105. data/ext/swfmill/src/swft/swft_import_ttf.cpp +519 -0
  106. data/ext/swfmill/src/swft/swft_import_wav.cpp +255 -0
  107. data/ext/swfmill/src/swft/swft_path.cpp +178 -0
  108. data/ext/swfmill/src/xslt/Makefile.am +51 -0
  109. data/ext/swfmill/src/xslt/Makefile.in +536 -0
  110. data/ext/swfmill/src/xslt/README +19 -0
  111. data/ext/swfmill/src/xslt/assemble.xsl +38 -0
  112. data/ext/swfmill/src/xslt/simple-deprecated.xslt +62 -0
  113. data/ext/swfmill/src/xslt/simple-elements.xslt +627 -0
  114. data/ext/swfmill/src/xslt/simple-import.xslt +565 -0
  115. data/ext/swfmill/src/xslt/simple-svg.xslt +383 -0
  116. data/ext/swfmill/src/xslt/simple-tools.xslt +255 -0
  117. data/ext/swfmill/src/xslt/simple.cpp +1686 -0
  118. data/ext/swfmill/src/xslt/simple.xml +7 -0
  119. data/ext/swfmill/src/xslt/xslt.h +7 -0
  120. data/ext/swfmill/test/Makefile.am +1 -0
  121. data/ext/swfmill/test/Makefile.in +490 -0
  122. data/ext/swfmill/test/xml/Makefile.am +20 -0
  123. data/ext/swfmill/test/xml/Makefile.in +353 -0
  124. data/ext/swfmill/test/xml/test-xml +21 -0
  125. data/ext/swfmill_ext.cc +375 -0
  126. data/lib/swfmill.rb +30 -0
  127. data/spec/data/swfmill-banner1.swf +0 -0
  128. data/spec/spec.opts +1 -0
  129. data/spec/spec_helper.rb +14 -0
  130. data/spec/swfmill_spec.rb +125 -0
  131. metadata +206 -0
@@ -0,0 +1,251 @@
1
+ #include <libxslt/extensions.h>
2
+ #include <libxml/uri.h>
3
+ #include <libxslt/xsltutils.h>
4
+ #include <libxslt/variables.h>
5
+ #include <libxml/xpathInternals.h>
6
+ #include <cstdlib>
7
+ #include <cstring>
8
+ #include "swft.h"
9
+
10
+ #define TMP_STRLEN 0xFF
11
+ #define SWFT_MAPSIZE 32
12
+
13
+ using namespace SWF;
14
+
15
+ void *swft_init( xsltTransformContextPtr ctx, const xmlChar *URI );
16
+ void swft_shutdown( xsltTransformContextPtr ctx, const xmlChar *URI, void *data );
17
+
18
+ static void swft_error( xsltTransformContextPtr ctx, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr comp );
19
+
20
+ static void swft_nextid( xmlXPathParserContextPtr ctx, int nargs );
21
+ static void swft_nextdepth( xmlXPathParserContextPtr ctx, int nargs );
22
+
23
+ static void swft_pushmap( xsltTransformContextPtr ctx, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr comp );
24
+ static void swft_popmap( xsltTransformContextPtr ctx, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr comp );
25
+
26
+ static void swft_mapid( xmlXPathParserContextPtr ctx, int nargs );
27
+ static void swft_setmap( xmlXPathParserContextPtr ctx, int nargs );
28
+
29
+ // in swft_import_*.cpp
30
+ // FIXME why are these not static? any reason?
31
+ void swft_import_jpeg( xmlXPathParserContextPtr ctx, int nargs );
32
+ void swft_import_jpega( xmlXPathParserContextPtr ctx, int nargs );
33
+ void swft_import_png( xmlXPathParserContextPtr ctx, int nargs );
34
+ void swft_import_ttf( xmlXPathParserContextPtr ctx, int nargs );
35
+ void swft_import_mp3( xmlXPathParserContextPtr ctx, int nargs );
36
+ void swft_import_wav( xmlXPathParserContextPtr ctx, int nargs );
37
+ void swft_import_binary( xmlXPathParserContextPtr ctx, int nargs );
38
+
39
+ // in swft_document
40
+ void swft_document( xmlXPathParserContextPtr ctx, int nargs );
41
+
42
+ // in swft_path
43
+ void swft_path( xmlXPathParserContextPtr ctx, int nargs );
44
+ void swft_bounds( xmlXPathParserContextPtr ctx, int nargs );
45
+ void swft_transform( xmlXPathParserContextPtr ctx, int nargs );
46
+
47
+ static void swft_pushgradient( xsltTransformContextPtr ctx, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr com ) {
48
+ swft_ctx *c = (swft_ctx*)xsltGetExtData( ctx, SWFT_NAMESPACE );
49
+ xmlChar *id, *href;
50
+ SVGGradient *gradient;
51
+
52
+ id = xmlGetProp(node, (const xmlChar *)"id");
53
+ if(id) {
54
+ if(!xmlStrcmp(node->name, (const xmlChar *)"linearGradient")) {
55
+ gradient = new SVGLinearGradient();
56
+ } else if(!xmlStrcmp(node->name, (const xmlChar *)"radialGradient")) {
57
+ gradient = new SVGRadialGradient();
58
+ }
59
+
60
+ href = xmlGetProp(node, (const xmlChar *)"href");
61
+ if (href) {
62
+ string hrefStr = (const char *)href;
63
+ hrefStr.erase(0, 1);
64
+
65
+ map<string, SVGGradient*>::iterator i = c->gradients.find(hrefStr);
66
+ if(i != c->gradients.end()) {
67
+ *gradient = *((*i).second);
68
+ }
69
+
70
+ xmlFree(href);
71
+ }
72
+
73
+ gradient->parse(node);
74
+ c->gradients[(char *)id] = gradient;
75
+ xmlFree(id);
76
+ }
77
+
78
+ }
79
+
80
+ static void swft_popstyle( xsltTransformContextPtr ctx, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr com ) {
81
+ swft_ctx *c = (swft_ctx*)xsltGetExtData( ctx, SWFT_NAMESPACE );
82
+ c->styles.pop();
83
+ }
84
+
85
+ static void swft_pushstyle( xsltTransformContextPtr ctx, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr com ) {
86
+ swft_ctx *c = (swft_ctx*)xsltGetExtData( ctx, SWFT_NAMESPACE );
87
+
88
+ SVGStyle style;
89
+ if(c->styles.size() > 0) {
90
+ style = c->styles.top();
91
+ }
92
+ style.parseNode(node, c->gradients);
93
+ c->styles.push(style);
94
+ }
95
+
96
+ static void swft_nextid( xmlXPathParserContextPtr ctx, int nargs ) {
97
+ char tmp[TMP_STRLEN];
98
+ swft_ctx *c = (swft_ctx*)xsltGetExtData( xsltXPathGetTransformContext(ctx), SWFT_NAMESPACE );
99
+ snprintf(tmp,TMP_STRLEN,"%i", c->last_id++ );
100
+ valuePush(ctx, xmlXPathNewString((const xmlChar *)tmp));
101
+ }
102
+
103
+ static void swft_nextdepth( xmlXPathParserContextPtr ctx, int nargs ) {
104
+ char tmp[TMP_STRLEN];
105
+ swft_ctx *c = (swft_ctx*)xsltGetExtData( xsltXPathGetTransformContext(ctx), SWFT_NAMESPACE );
106
+ snprintf(tmp,TMP_STRLEN,"%i", c->last_depth++ );
107
+ valuePush(ctx, xmlXPathNewString((const xmlChar *)tmp));
108
+ }
109
+
110
+ static void swft_pushmap( xsltTransformContextPtr ctx, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr comp ) {
111
+ swft_ctx *c = (swft_ctx*)xsltGetExtData( ctx, SWFT_NAMESPACE );
112
+ c->pushMap();
113
+ }
114
+
115
+ static void swft_popmap( xsltTransformContextPtr ctx, xmlNodePtr node, xmlNodePtr inst, xsltElemPreCompPtr comp ) {
116
+ swft_ctx *c = (swft_ctx*)xsltGetExtData( ctx, SWFT_NAMESPACE );
117
+ c->popMap();
118
+ }
119
+
120
+ static void swft_setmap( xmlXPathParserContextPtr ctx, int nargs ) {
121
+ swft_ctx *c = (swft_ctx*)xsltGetExtData( xsltXPathGetTransformContext(ctx), SWFT_NAMESPACE );
122
+
123
+ if( (nargs != 2) ) {
124
+ xmlXPathSetArityError(ctx);
125
+ return;
126
+ }
127
+
128
+ int to = (int)xmlXPathPopNumber(ctx);
129
+ xmlChar *from = xmlXPathPopString(ctx);
130
+ if( xmlXPathCheckError(ctx) )
131
+ return;
132
+
133
+ c->setMap((const char *)from,to);
134
+
135
+ xmlFree( from );
136
+ valuePush(ctx, xmlXPathNewString((const xmlChar *)""));
137
+ }
138
+
139
+ static void swft_bump_id( xmlXPathParserContextPtr ctx, int nargs ) {
140
+ swft_ctx *c = (swft_ctx*)xsltGetExtData( xsltXPathGetTransformContext(ctx), SWFT_NAMESPACE );
141
+
142
+ if( (nargs != 1) ) {
143
+ xmlXPathSetArityError(ctx);
144
+ return;
145
+ }
146
+
147
+ int offset = (int)xmlXPathPopNumber(ctx);
148
+ if( xmlXPathCheckError(ctx) )
149
+ return;
150
+
151
+ if( offset >= c->last_id ) c->last_id = offset+1;
152
+
153
+ valuePush(ctx, xmlXPathNewString((const xmlChar *)""));
154
+ }
155
+
156
+ static void swft_bump_depth( xmlXPathParserContextPtr ctx, int nargs ) {
157
+ swft_ctx *c = (swft_ctx*)xsltGetExtData( xsltXPathGetTransformContext(ctx), SWFT_NAMESPACE );
158
+
159
+ if( (nargs != 1) ) {
160
+ xmlXPathSetArityError(ctx);
161
+ return;
162
+ }
163
+
164
+ int offset = (int)xmlXPathPopNumber(ctx);
165
+ if( xmlXPathCheckError(ctx) )
166
+ return;
167
+
168
+ if( offset >= c->last_depth ) c->last_depth = offset+1;
169
+
170
+ valuePush(ctx, xmlXPathNewString((const xmlChar *)""));
171
+ }
172
+
173
+ static void swft_mapid( xmlXPathParserContextPtr ctx, int nargs ) {
174
+ char tmp[TMP_STRLEN];
175
+ xmlXPathObjectPtr obj;
176
+ xmlChar *oldID;
177
+ int newID;
178
+ swft_ctx *c = (swft_ctx*)xsltGetExtData( xsltXPathGetTransformContext(ctx), SWFT_NAMESPACE );
179
+
180
+ xmlXPathStringFunction(ctx, 1);
181
+ if (ctx->value->type != XPATH_STRING) {
182
+ xsltTransformError(xsltXPathGetTransformContext(ctx), NULL, NULL,
183
+ "swft:mapid() : invalid arg expecting a string (the old id)\n");
184
+ ctx->error = XPATH_INVALID_TYPE;
185
+ return;
186
+ }
187
+ obj = valuePop(ctx);
188
+ if (obj->stringval == NULL) {
189
+ valuePush(ctx, xmlXPathNewNodeSet(NULL));
190
+ return;
191
+ }
192
+ // (int)xmlXPathStringEvalNumber()
193
+ oldID = obj->stringval;
194
+ newID = c->doMap((const char*)oldID);
195
+
196
+ xmlFree( oldID );
197
+
198
+ snprintf(tmp,TMP_STRLEN,"%i", newID );
199
+ valuePush(ctx, xmlXPathNewString((const xmlChar *)tmp));
200
+ }
201
+
202
+ unsigned char *swft_get_filename( xmlChar *filenameUTF ) {
203
+ int l = strlen((const char*)filenameUTF);
204
+ int l2 = l;
205
+ unsigned char *filename = (unsigned char *)malloc(l+1);
206
+ UTF8Toisolat1( filename, &l2, filenameUTF, &l );
207
+ filename[l2] = 0;
208
+ return filename;
209
+ }
210
+
211
+ void swft_register() {
212
+ xsltRegisterExtModule((const xmlChar *)SWFT_NAMESPACE,
213
+ swft_init, swft_shutdown );
214
+ }
215
+
216
+ void *swft_init( xsltTransformContextPtr ctx, const xmlChar *URI ) {
217
+ xsltRegisterExtFunction( ctx, (const xmlChar *) "next-id", SWFT_NAMESPACE, swft_nextid);
218
+ xsltRegisterExtFunction( ctx, (const xmlChar *) "next-depth", SWFT_NAMESPACE, swft_nextdepth);
219
+ xsltRegisterExtFunction( ctx, (const xmlChar *) "map-id", SWFT_NAMESPACE, swft_mapid);
220
+ xsltRegisterExtElement( ctx, (const xmlChar *) "push-map", SWFT_NAMESPACE, swft_pushmap);
221
+ xsltRegisterExtElement( ctx, (const xmlChar *) "pop-map", SWFT_NAMESPACE, swft_popmap);
222
+ xsltRegisterExtFunction( ctx, (const xmlChar *) "set-map", SWFT_NAMESPACE, swft_setmap);
223
+ xsltRegisterExtFunction( ctx, (const xmlChar *) "bump-id", SWFT_NAMESPACE, swft_bump_id);
224
+ xsltRegisterExtFunction( ctx, (const xmlChar *) "bump-depth", SWFT_NAMESPACE, swft_bump_depth);
225
+
226
+ xsltRegisterExtFunction( ctx, (const xmlChar *) "document", SWFT_NAMESPACE, swft_document);
227
+ xsltRegisterExtFunction( ctx, (const xmlChar *) "path", SWFT_NAMESPACE, swft_path);
228
+ // xsltRegisterExtFunction( ctx, (const xmlChar *) "bounds", SWFT_NAMESPACE, swft_bounds);
229
+ xsltRegisterExtFunction( ctx, (const xmlChar *) "transform", SWFT_NAMESPACE, swft_transform);
230
+ xsltRegisterExtElement( ctx, (const xmlChar *) "push-style", SWFT_NAMESPACE, swft_pushstyle);
231
+ xsltRegisterExtElement( ctx, (const xmlChar *) "pop-style", SWFT_NAMESPACE, swft_popstyle);
232
+ xsltRegisterExtElement( ctx, (const xmlChar *) "push-gradient", SWFT_NAMESPACE, swft_pushgradient);
233
+
234
+ xsltRegisterExtFunction( ctx, (const xmlChar *) "import-jpeg", SWFT_NAMESPACE, swft_import_jpeg );
235
+ xsltRegisterExtFunction( ctx, (const xmlChar *) "import-jpega", SWFT_NAMESPACE, swft_import_jpega );
236
+ xsltRegisterExtFunction( ctx, (const xmlChar *) "import-png", SWFT_NAMESPACE, swft_import_png );
237
+ xsltRegisterExtFunction( ctx, (const xmlChar *) "import-ttf", SWFT_NAMESPACE, swft_import_ttf );
238
+ xsltRegisterExtFunction( ctx, (const xmlChar *) "import-mp3", SWFT_NAMESPACE, swft_import_mp3 );
239
+ xsltRegisterExtFunction( ctx, (const xmlChar *) "import-wav", SWFT_NAMESPACE, swft_import_wav );
240
+ xsltRegisterExtFunction( ctx, (const xmlChar *) "import-binary", SWFT_NAMESPACE, swft_import_binary );
241
+
242
+ swft_ctx *c = new swft_ctx;
243
+ return c;
244
+ }
245
+
246
+ void swft_shutdown( xsltTransformContextPtr ctx, const xmlChar *URI, void *data ) {
247
+ swft_ctx *c = (swft_ctx*)data;
248
+ delete c;
249
+ }
250
+
251
+
@@ -0,0 +1,64 @@
1
+ #ifndef SWF_SWFT_H
2
+ #define SWF_SWFT_H
3
+
4
+ #include <libxml/xpathInternals.h>
5
+ #include <string>
6
+ #include <stack>
7
+ #include <map>
8
+ #include "SVGGradient.h"
9
+ #include "SVGStyle.h"
10
+
11
+ void swft_register();
12
+
13
+ // utility functoins for import (in swft_import.cpp)
14
+ void swft_addFileName( xmlNodePtr node, const char *filename );
15
+ void swft_addData( xmlNodePtr node, char *data, int length );
16
+
17
+ unsigned char *swft_get_filename( xmlChar *string );
18
+
19
+ #define SWFT_NAMESPACE ((const xmlChar*)"http://subsignal.org/swfml/swft")
20
+
21
+ class swft_ctx {
22
+ public:
23
+ std::stack<SWF::SVGStyle> styles;
24
+ std::map<std::string, SWF::SVGGradient*> gradients;
25
+
26
+ int last_id;
27
+ int last_depth;
28
+ std::stack<std::map<std::string,int>*> maps;
29
+
30
+ bool quiet;
31
+
32
+ swft_ctx() {
33
+ last_id = last_depth = 1;
34
+ pushMap();
35
+ }
36
+
37
+ void pushMap() {
38
+ maps.push( new std::map<std::string,int> );
39
+ }
40
+ void popMap() {
41
+ maps.pop();
42
+ }
43
+
44
+ int doMap( const char *oldID ) {
45
+ int id = atoi( oldID );
46
+ if( id == 65535 ) return id;
47
+
48
+ std::map<std::string,int>& m = *(maps.top());
49
+ int r = m[oldID];
50
+ if( r == 0 ) {
51
+ r = last_id++;
52
+ m[oldID] = r;
53
+ }
54
+
55
+ return r;
56
+ }
57
+
58
+ void setMap( const char *oldID, int newID ) {
59
+ std::map<std::string,int>& m = *(maps.top());
60
+ m[oldID] = newID;
61
+ }
62
+ };
63
+
64
+ #endif
@@ -0,0 +1,57 @@
1
+ #include "SWFShapeMaker.h"
2
+ #include "SWFFile.h"
3
+ #include "swft.h"
4
+ #include <libxslt/extensions.h>
5
+ #include <libxml/uri.h>
6
+ #include <libxslt/xsltutils.h>
7
+ #include <libxml/xpathInternals.h>
8
+
9
+ using namespace SWF;
10
+
11
+ void swft_document( xmlXPathParserContextPtr ctx, int nargs ) {
12
+ xsltTransformContextPtr tctx;
13
+ xmlChar *uri;
14
+ xsltDocumentPtr xsltdoc;
15
+ xmlDocPtr doc = NULL;
16
+ xmlXPathObjectPtr obj;
17
+ xmlChar *base = NULL;
18
+ char sig;
19
+ File import;
20
+
21
+ xmlXPathStringFunction(ctx, 1);
22
+ if (ctx->value->type != XPATH_STRING) {
23
+ xsltTransformError(xsltXPathGetTransformContext(ctx), NULL, NULL,
24
+ "swft:document() : invalid arg expecting a string\n");
25
+ ctx->error = XPATH_INVALID_TYPE;
26
+ return;
27
+ }
28
+ obj = valuePop(ctx);
29
+ if (obj->stringval == NULL) {
30
+ valuePush(ctx, xmlXPathNewNodeSet(NULL));
31
+ return;
32
+ }
33
+
34
+ tctx = xsltXPathGetTransformContext(ctx);
35
+
36
+ uri = swft_get_filename( obj->stringval );
37
+
38
+ FILE *fp = fopen( (const char *)uri, "rb" );
39
+ if( !fp ) {
40
+ xsltTransformError(xsltXPathGetTransformContext(ctx), NULL, NULL,
41
+ "swft:document() : failed to read file '%s'\n", (const char *)uri);
42
+ valuePush(ctx, xmlXPathNewNodeSet(NULL));
43
+ return;
44
+ }
45
+
46
+ import.load( fp );
47
+ doc = import.getXML();
48
+
49
+ if( !doc ) {
50
+ xsltTransformError(xsltXPathGetTransformContext(ctx), NULL, NULL,
51
+ "swft:document() : could not parse SWF '%s'\n", (const char *)uri);
52
+ valuePush(ctx, xmlXPathNewNodeSet(NULL));
53
+ return;
54
+ }
55
+ valuePush( ctx, xmlXPathNewNodeSet( (xmlNodePtr)doc ) );
56
+ return;
57
+ }
@@ -0,0 +1,38 @@
1
+ #include <libxslt/extensions.h>
2
+ #include <libxslt/xsltutils.h>
3
+ #include <libxml/xpathInternals.h>
4
+ #include "base64.h"
5
+ #include <cstring>
6
+
7
+ void swft_addFileName( xmlNodePtr node, const char *filename ) {
8
+ char *name, *n;
9
+ const char *basename, *b;
10
+ int l;
11
+
12
+ // figure basename (filename without path)
13
+ b = strrchr( filename, '/' );
14
+ basename = b ? b+1 : filename;
15
+
16
+ l = strlen(basename);
17
+ name = new char[l + 1];
18
+ strncpy( name, basename, l + 1 ); // copy string including null terminator
19
+
20
+ // separate extension (set position of last . as end of string)
21
+ n = strrchr( name, '.' );
22
+ if( n ) n[0]=0;
23
+
24
+ xmlSetProp( node, (const xmlChar *)"name", (const xmlChar *)name );
25
+
26
+ delete[] name;
27
+ }
28
+
29
+ void swft_addData( xmlNodePtr node, char *data, int sz ) {
30
+ char *tmpstr = new char[ (sz * 3) ];
31
+
32
+ int l = base64_encode( tmpstr, data, sz );
33
+ if( l > 0 ) {
34
+ tmpstr[l] = 0;
35
+ xmlNewTextChild( node, NULL, (const xmlChar *)"data", (const xmlChar *)tmpstr );
36
+ }
37
+ delete tmpstr;
38
+ }
@@ -0,0 +1,82 @@
1
+ #include <libxslt/extensions.h>
2
+ #include <libxslt/xsltutils.h>
3
+ #include <libxslt/variables.h>
4
+ #include <libxml/xpathInternals.h>
5
+ #include "swft.h"
6
+ #include <sys/types.h>
7
+ #include <sys/stat.h>
8
+ #include <cstring>
9
+ #include "readpng.h"
10
+ #include <zlib.h>
11
+
12
+ #define TMP_STRLEN 0xff
13
+
14
+ void swft_import_binary( xmlXPathParserContextPtr ctx, int nargs ) {
15
+ xsltTransformContextPtr tctx;
16
+ unsigned char *filename;
17
+ xsltDocumentPtr xsltdoc;
18
+ xmlDocPtr doc = NULL;
19
+ xmlNodePtr node;
20
+ xmlXPathObjectPtr obj;
21
+ char tmp[TMP_STRLEN];
22
+
23
+ xmlXPathStringFunction(ctx, 1);
24
+ if (ctx->value->type != XPATH_STRING) {
25
+ xsltTransformError(xsltXPathGetTransformContext(ctx), NULL, NULL,
26
+ "swft:import-binary() : invalid arg expecting a string\n");
27
+ ctx->error = XPATH_INVALID_TYPE;
28
+ return;
29
+ }
30
+ obj = valuePop(ctx);
31
+ if (obj->stringval == NULL) {
32
+ valuePush(ctx, xmlXPathNewNodeSet(NULL));
33
+ return;
34
+ }
35
+
36
+ tctx = xsltXPathGetTransformContext(ctx);
37
+ filename = swft_get_filename( obj->stringval );
38
+
39
+ bool quiet = true;
40
+ xmlXPathObjectPtr quietObj = xsltVariableLookup( tctx, (const xmlChar*)"quiet", NULL );
41
+ if( quietObj && quietObj->stringval ) { quiet = !strcmp("true",(const char*)quietObj->stringval ); };
42
+
43
+
44
+ FILE *fp = fopen( (const char *)filename, "rb" );
45
+ if( !fp ) {
46
+ xsltTransformError(xsltXPathGetTransformContext(ctx), NULL, NULL,
47
+ "swft:import-binary() : failed to read file '%s'\n", (const char *)filename);
48
+ valuePush(ctx, xmlXPathNewNodeSet(NULL));
49
+ return;
50
+ }
51
+
52
+ doc = xmlNewDoc( (const xmlChar *)"1.0");
53
+ doc->xmlRootNode = xmlNewDocNode( doc, NULL, (const xmlChar *)"binary", NULL );
54
+ node = doc->xmlRootNode;
55
+
56
+ swft_addFileName( node, (const char *)filename );
57
+
58
+ // add data
59
+ unsigned char *data = NULL;
60
+ int size;
61
+ struct stat filestat;
62
+ if( stat( (const char *)filename, &filestat ) ) goto fail;
63
+ size = filestat.st_size;
64
+
65
+ data = new unsigned char[size];
66
+ if( fread( data, 1, size, fp ) != size ) {
67
+ fprintf(stderr,"WARNING: could not read enough (%i) bytes for binary %s\n", size, filename );
68
+ goto fail;
69
+ }
70
+
71
+ if( !quiet ) {
72
+ fprintf(stderr,"Importing binary: '%s'\n",filename);
73
+ }
74
+
75
+ swft_addData( node, (char*)data, size );
76
+ valuePush( ctx, xmlXPathNewNodeSet( (xmlNodePtr)doc ) );
77
+
78
+ fail:
79
+ if( fp ) fclose(fp);
80
+ if( data ) delete data;
81
+ }
82
+