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,352 @@
1
+ #include "SWFReader.h"
2
+ #include "SWFTag.h"
3
+ #include "SWFAction.h"
4
+ #include <cstring>
5
+
6
+ namespace SWF {
7
+
8
+ Reader::Reader( const unsigned char *d, size_t l ) {
9
+ data = d;
10
+ length = l;
11
+ pos = 0;
12
+ buf = bits = 0;
13
+ err = 0;
14
+ }
15
+
16
+ bool Reader::getData( void *dst, size_t len ) {
17
+ if( pos+len > length ) {
18
+ err = SWFR_EOF;
19
+ pos = length+1;
20
+ return false;
21
+ } else {
22
+ memcpy( dst, &data[pos], len );
23
+ pos += len;
24
+ return true;
25
+ }
26
+ }
27
+
28
+ uint8_t Reader::getByte() {
29
+ if( pos+1 > length ) {
30
+ err = SWFR_EOF;
31
+ pos = length+1;
32
+ return 0;
33
+ }
34
+ return data[pos++];
35
+ }
36
+
37
+ uint16_t Reader::getWord() {
38
+ if( pos+2 > length ) {
39
+ err = SWFR_EOF;
40
+ pos = length+1;
41
+ return 0;
42
+ }
43
+ // FIXME x86-centric?
44
+ int r = data[pos++];
45
+ r += data[pos++]<<8;
46
+ return r;
47
+ }
48
+
49
+ uint32_t Reader::getInt() {
50
+ if( pos+4 > length ) {
51
+ err = SWFR_EOF;
52
+ pos = length+1;
53
+ return 0;
54
+ }
55
+ int r;
56
+
57
+ // FIXME x86-centric?
58
+ r = data[pos++];
59
+ r += data[pos++]<<8;
60
+ r += data[pos++]<<16;
61
+ r += data[pos++]<<24;
62
+
63
+ return r;
64
+ }
65
+
66
+ uint64_t Reader::getInt64() {
67
+ if( pos+8 > length ) {
68
+ err = SWFR_EOF;
69
+ pos = length+1;
70
+ return 0;
71
+ }
72
+ uint64_t val;
73
+ val = (uint64_t)getInt() << 32;
74
+ val |= (uint64_t)getInt();
75
+ return( val );
76
+ }
77
+
78
+ uint32_t Reader::getU30() {
79
+ uint32_t r = 0;
80
+ unsigned char c;
81
+
82
+ for( int i = 0; i < 5; i++ ) {
83
+ c = data[pos++];
84
+ r |= (c & 0x7F) << (7 * i);
85
+
86
+ if( !(c & 0x80) ) {
87
+ return r;
88
+ }
89
+
90
+ if( pos > length ) {
91
+ err = SWFR_EOF;
92
+ pos = length+1;
93
+ return 0;
94
+ }
95
+ }
96
+
97
+ return r;
98
+ }
99
+
100
+ int Reader::getS24() {
101
+ if( pos+3 > length ) {
102
+ err = SWFR_EOF;
103
+ pos = length+1;
104
+ return 0;
105
+ }
106
+
107
+ int r = data[pos++];
108
+ r += data[pos++]<<8;
109
+ r += ((signed char)data[pos++])<<16;
110
+ return r;
111
+ }
112
+
113
+ float Reader::getFloat() {
114
+ /*
115
+ if( pos+4 > length ) {
116
+ err = SWFR_EOF;
117
+ pos = length+1;
118
+ return 0;
119
+ }
120
+ // FIXME x86-centric?
121
+ int r = data[pos++];
122
+ r += data[pos++]<<8;
123
+ r += data[pos++]<<16;
124
+ r += data[pos++]<<24;
125
+ return *((float*)&r);
126
+ */
127
+ union {
128
+ float f;
129
+ uint32_t ul;
130
+ } u;
131
+
132
+ u.ul = getInt();
133
+ return u.f;
134
+ }
135
+
136
+ double Reader::getDouble() {
137
+ /* if( pos+8 > length ) {
138
+ err = SWFR_EOF;
139
+ pos = length+1;
140
+ return 0;
141
+ }
142
+ // FIXME x86-centric?
143
+ char value[8];
144
+ value[4] = data[pos++];
145
+ value[5] = data[pos++];
146
+ value[6] = data[pos++];
147
+ value[7] = data[pos++];
148
+ value[0] = data[pos++];
149
+ value[1] = data[pos++];
150
+ value[2] = data[pos++];
151
+ value[3] = data[pos++];
152
+
153
+ return *(double*)value;
154
+ */
155
+ union {
156
+ double d;
157
+ uint64_t ull;
158
+ } u;
159
+
160
+ u.ull = getInt64();
161
+ return u.d;
162
+ }
163
+
164
+ double Reader::getDouble2() {
165
+ if( pos+8 > length ) {
166
+ err = SWFR_EOF;
167
+ pos = length+1;
168
+ return 0;
169
+ }
170
+
171
+ union {
172
+ double d;
173
+ char c[8];
174
+ } u;
175
+
176
+
177
+ // FIXME x86-centric?
178
+ for( int i = 0; i < 8; i++ ) {
179
+ u.c[i] = data[pos++];
180
+ }
181
+
182
+ return u.d;
183
+ }
184
+
185
+ float Reader::getHalf() {
186
+ uint16_t r = getWord();
187
+
188
+ int sign = (r & 0x8000) >> 15;
189
+ int exp = (r & 0x7C00) >> 10;
190
+ int man = (r & 0x3FF);
191
+
192
+ if(exp == 0) {
193
+ if(man != 0) {
194
+ while(!(man & 0x400)) {
195
+ man <<= 1;
196
+ exp -= 1;
197
+ }
198
+ exp += 1 - 15 + 127;
199
+ man &= 0x3FF;
200
+ }
201
+ } else if(exp == 0x1F) {
202
+ exp = 0xFF;
203
+ } else {
204
+ exp += -15 + 127;
205
+ }
206
+
207
+ union {
208
+ float f;
209
+ uint32_t ul;
210
+ } u;
211
+
212
+ u.ul = (sign << 31) | (exp << 23) | (man << 13);
213
+ return u.f;
214
+ }
215
+
216
+ unsigned int Reader::getEncodedU32() {
217
+
218
+ unsigned int result = data[pos++];
219
+ if (!(result & 0x00000080)) return result;
220
+
221
+ result = (result & 0x0000007f) | data[pos++] << 7;
222
+ if (!(result & 0x00004000)) return result;
223
+
224
+ result = (result & 0x00003fff) | data[pos++] << 14;
225
+ if (!(result & 0x00200000)) return result;
226
+
227
+ result = (result & 0x001fffff) | data[pos++] << 21;
228
+ if (!(result & 0x10000000)) return result;
229
+
230
+ result = (result & 0x0fffffff) | data[pos++] << 28;
231
+ return result;
232
+
233
+ }
234
+
235
+ double Reader::getFixed( int bytesize, int exp ) {
236
+ /* putFixed/getFixed are deprecated: they implicitly to byteAlign */
237
+
238
+ double r = 0;
239
+ if( pos+bytesize > length ) {
240
+ err = SWFR_EOF;
241
+ pos = length+1;
242
+ return 0;
243
+ }
244
+
245
+ for( int i=0; i<bytesize; i++ ) {
246
+ r += data[pos++]<<(8*i);
247
+ }
248
+ return r / ((double)(1<<exp));
249
+ }
250
+
251
+ char *Reader::getString() {
252
+ byteAlign();
253
+ const char *src = (const char *)&data[pos];
254
+ size_t len = strlen(src) + 1;
255
+ char *dst = new char[len];
256
+ strcpy(dst, src);
257
+ pos += len;
258
+ return( dst );
259
+ }
260
+
261
+ char *Reader::getPString() {
262
+ byteAlign();
263
+ int len = getByte();
264
+ char *dst = new char[len+1];
265
+ getData( dst, len );
266
+ dst[len]=0;
267
+ return( dst );
268
+ }
269
+
270
+ char *Reader::getPStringU30() {
271
+ byteAlign();
272
+ uint32_t len = getU30();
273
+ char *dst = new char[len+1];
274
+ getData( dst, len );
275
+ dst[len]=0;
276
+ return( dst );
277
+ }
278
+
279
+ long Reader::getNBitInt( int n, bool is_signed ) {
280
+ // FIXME: unefficient, maybe incorrect!
281
+ int orig_n = n;
282
+ long r = buf;
283
+ if( n == bits ) {
284
+ bits = buf = 0;
285
+ goto ret;
286
+ }
287
+ if( n > bits ) {
288
+ n -= bits;
289
+ while( n > 8 ) {
290
+ r <<= 8;
291
+ r += getByte();
292
+ n-=8;
293
+ }
294
+ buf = getByte();
295
+
296
+ if( n > 0 ) {
297
+ r <<= n;
298
+ bits = 8-n;
299
+
300
+ r += buf >> (8-n);
301
+ buf &= (1<<bits)-1;
302
+ }
303
+ goto ret;
304
+ }
305
+
306
+ r = buf >> (bits-n);
307
+ bits -= n;
308
+ buf &= (1<<bits)-1;
309
+
310
+ ret:
311
+ long sign = (1<<(orig_n-1));
312
+ if( is_signed && (r&sign)!=0 ) {
313
+ r |= - (long) sign;
314
+ }
315
+
316
+ return r;
317
+ }
318
+
319
+ double Reader::getNBitFixed( int n, int m, bool is_signed ) {
320
+ double d;
321
+ d = getNBitInt( n, is_signed );
322
+ d /= (double)(1<<m);
323
+ return d;
324
+ }
325
+
326
+ double Reader::getNBitFixed2( int n, int m, bool is_signed ) {
327
+ if( n%8 != 0 ) {
328
+ fprintf(stderr,"WARNING: fixedpoint2 needs a size that is divisible by 8");
329
+ return 0;
330
+ }
331
+ return( getFixed( n/8, m ) );
332
+ }
333
+
334
+ void Reader::dump( int len, int ofs ) {
335
+ const unsigned char *d = &data[pos+ofs];
336
+
337
+ int i=0;
338
+ printf("DumpingReader %i - %i\n", pos+ofs, pos+ofs+len );
339
+ while( i<len ) {
340
+ for( int n=0; n<4 && i<len; n++ ) {
341
+ for( int b=7; b>=0; b-- ) {
342
+ printf( d[i] & (1<<b) ? "1" : "0" );
343
+ }
344
+ printf(" 0x%02X %03i ", d[i], d[i] );
345
+ printf(" ");
346
+ i++;
347
+ }
348
+ printf("\n");
349
+ }
350
+ }
351
+
352
+ }
@@ -0,0 +1,73 @@
1
+ #ifndef SWF_Reader_H
2
+ #define SWF_Reader_H
3
+
4
+ #include <cstdio>
5
+ #include <stdint.h>
6
+ #include "SWFBasic.h"
7
+
8
+ namespace SWF {
9
+
10
+ #define SWFR_OK 0
11
+ #define SWFR_ERROR 1
12
+ #define SWFR_EOF 2
13
+
14
+ class Reader {
15
+ public:
16
+ Reader( const unsigned char *data, size_t length );
17
+
18
+ // these implicitly do byteAlign()
19
+ bool getData( void *dst, size_t length );
20
+ uint8_t getByte();
21
+ uint16_t getWord();
22
+ uint32_t getInt();
23
+ uint64_t getInt64();
24
+ uint32_t getU30();
25
+ int getS24();
26
+ float getFloat();
27
+ double getDouble();
28
+ double getDouble2();
29
+ float getHalf();
30
+ double getFixed( int bytesize, int decimals );
31
+ char *getString();
32
+ char *getPString();
33
+ char *getPStringU30();
34
+
35
+ unsigned int getEncodedU32();
36
+
37
+ // this one cares about the current bit position
38
+ long getNBitInt( int n, bool is_signed = false );
39
+ double getNBitFixed( int n, int m, bool is_signed = false ); // n bits total, m bits after decimal point.
40
+ double getNBitFixed2( int n, int m, bool is_signed = false );
41
+
42
+ // set bit position to next byte.
43
+ void byteAlign() {
44
+ if( buf != 0 ) fprintf(stderr,"buf is nonzero in byteAlign() @%i\n", pos );
45
+ buf = bits = 0; }
46
+
47
+ int getError() { return err; }
48
+
49
+ const unsigned char *getRawData() { return data; }
50
+ int getPosition() { return pos; }
51
+ int getLength() { return length; }
52
+ int getBits() { return bits; }
53
+ void setEOF() { pos=length; }
54
+ void seekTo( int p ) { pos=p; }
55
+
56
+ void dump( int n, int ofs ); // dumps n bytes from current position to stdout
57
+
58
+ protected:
59
+ // the uncompressed swf data and our position within
60
+ const unsigned char *data;
61
+ int pos, length;
62
+
63
+ // buf is the current byte when in "NBit mode"
64
+ // bits is the number of bits represented in buf.
65
+ uint8_t buf, bits;
66
+
67
+ int err;
68
+
69
+ bool read( void *dst, size_t n );
70
+ };
71
+
72
+ }
73
+ #endif
@@ -0,0 +1,220 @@
1
+ #include <SWFShapeItem.h>
2
+ #include "SWF.h"
3
+ #include <cstring>
4
+
5
+ namespace SWF {
6
+
7
+ ShapeItem::ShapeItem() {
8
+ type = 0;
9
+ }
10
+
11
+ bool ShapeItem::isEnd() {
12
+ if( type != 0 ) return false;
13
+ ShapeSetup *self = (ShapeSetup*)this;
14
+ return( !( self->gethasNewStyles()
15
+ || self->gethasLineStyle()
16
+ || self->gethasFillStyle0()
17
+ || self->gethasFillStyle1()
18
+ || self->gethasMoveTo()) );
19
+ }
20
+
21
+ int ShapeItem::getHeaderSize(int size) {
22
+ switch( type ) {
23
+ case 0:
24
+ return 1;
25
+ case 1:
26
+ case 2:
27
+ return 2;
28
+ }
29
+ return 0;
30
+ }
31
+
32
+ ShapeItem *ShapeItem::get( Reader *r, int end, Context *ctx ) {
33
+
34
+ if( r->getPosition() == end && r->getBits() < 6 ) {
35
+ return NULL;
36
+ }
37
+
38
+ ShapeItem *ret;
39
+ int type = 0;
40
+ int isSetup = !r->getNBitInt(1);
41
+
42
+ if( isSetup ) {
43
+ ret = new ShapeSetup;
44
+ type = 0;
45
+ } else {
46
+ int isLine = r->getNBitInt(1);
47
+
48
+ if( isLine ) {
49
+ ret = new LineTo;
50
+ type = 1;
51
+ } else {
52
+ ret = new CurveTo;
53
+ type = 2;
54
+ }
55
+ }
56
+
57
+ ret->setType( type );
58
+ ret->parse( r, end, ctx );
59
+ return ret;
60
+ }
61
+
62
+ ShapeItem *ShapeItem::getByName( const char *name ) {
63
+
64
+ ShapeItem *ret = NULL;
65
+ int type = 0;
66
+ if( !strcmp( name, "ShapeSetup" ) ) {
67
+ ret = new ShapeSetup;
68
+ type = 0;
69
+ } else if( !strcmp( name, "LineTo" ) ) {
70
+ ret = new LineTo;
71
+ type = 1;
72
+ } else if( !strcmp( name, "CurveTo" ) ) {
73
+ ret = new CurveTo;
74
+ type = 2;
75
+ }
76
+
77
+ if( ret ) {
78
+ ret->setType( type );
79
+ }
80
+
81
+ return ret;
82
+ }
83
+
84
+ void ShapeItem::writeHeader( Writer *w, Context *ctx, size_t len ) {
85
+ if( type == 0 ) {
86
+ w->putNBitInt(0,1);
87
+ } else {
88
+ w->putNBitInt(1,1);
89
+ if( type == 1 ) {
90
+ w->putNBitInt(1,1);
91
+ } else {
92
+ w->putNBitInt(0,1);
93
+ }
94
+ }
95
+ }
96
+
97
+ LineTo::LineTo() {
98
+ bits = x = y = 0;
99
+ type = 1;
100
+ }
101
+
102
+ bool LineTo::parse( Reader *r, int end, Context *ctx ) {
103
+ file_offset = r->getPosition();
104
+
105
+ bits = r->getNBitInt( 4 );
106
+ int hasBoth = r->getNBitInt(1);
107
+
108
+ x=y=0;
109
+
110
+ if( hasBoth ) {
111
+ x = r->getNBitInt(bits+2,true);
112
+ y = r->getNBitInt(bits+2,true);
113
+ } else {
114
+ int hasY = r->getNBitInt(1);
115
+ if( hasY ) {
116
+ y = r->getNBitInt(bits+2,true);
117
+ } else {
118
+ x = r->getNBitInt(bits+2,true);
119
+ }
120
+ }
121
+ if( ctx->debugTrace ) {
122
+ fprintf(stderr,"PARSE LineTo @%i: %ibits %i/%i\n", file_offset, bits, x, y );
123
+ }
124
+ return r->getError() == SWFR_OK;
125
+ }
126
+
127
+ void LineTo::dump( int n, Context *ctx ) {
128
+ for( int i=0; i<n; i++ ) printf(" ");
129
+ printf("LineTo (%i+2bit) ", bits);
130
+ if( x ) printf("%i,", x); else printf("-,");
131
+ if( y ) printf("%i", y); else printf("-");
132
+ printf("\n");
133
+ }
134
+
135
+ size_t LineTo::calcSize( Context *ctx, int start_at ) {
136
+ int r=start_at;
137
+ if( x != 0 && y != 0 ) {
138
+ r += 4 + 1 + ((bits+2)*2);
139
+ } else {
140
+ r += 4 + 2 + (bits+2);
141
+ }
142
+ r += ShapeItem::getHeaderSize(r-start_at);
143
+ return r-start_at;
144
+ }
145
+
146
+ void LineTo::write( Writer *w, Context *ctx ) {
147
+ if( ctx->debugTrace ) {
148
+ printf("WRITE LineTo @%i %ibits %i/%i\n", w->getBitPosition()/8, bits, x, y );
149
+ dump(1,ctx);
150
+ }
151
+
152
+ ShapeItem::writeHeader( w, ctx, 0 );
153
+ w->putNBitInt( bits, 4 );
154
+
155
+ if( x != 0 && y != 0 ) {
156
+ w->putNBitInt(1,1);
157
+ w->putNBitInt(x,bits+2,true);
158
+ w->putNBitInt(y,bits+2,true);
159
+ } else if( x != 0 ) {
160
+ w->putNBitInt(0,1);
161
+ w->putNBitInt(0,1);
162
+ w->putNBitInt(x,bits+2,true);
163
+ } else {
164
+ w->putNBitInt(0,1);
165
+ w->putNBitInt(1,1);
166
+ w->putNBitInt(y,bits+2,true);
167
+ }
168
+ }
169
+
170
+ void LineTo::writeXML( xmlNodePtr xml, Context *ctx ) {
171
+ char tmp[32];
172
+ xmlNodePtr node = xmlNewChild( xml, NULL, (const xmlChar *)"LineTo", NULL );
173
+
174
+ snprintf( tmp, 32, "%i", x );
175
+ xmlSetProp( node, (const xmlChar *)"x", (const xmlChar *)tmp );
176
+
177
+ snprintf( tmp, 32, "%i", y );
178
+ xmlSetProp( node, (const xmlChar *)"y", (const xmlChar *)tmp );
179
+ }
180
+
181
+ void LineTo::parseXML( xmlNodePtr node, Context *ctx ) {
182
+ xmlChar *tmp;
183
+
184
+ x = y = 0;
185
+ bits = 0;
186
+
187
+ tmp = xmlGetProp( node, (const xmlChar *)"x" );
188
+ if( tmp ) {
189
+ sscanf( (char*)tmp, "%i", &x);
190
+ xmlFree( tmp );
191
+ int b = SWFBitsNeeded( x, true );
192
+ b -= 2;
193
+ if( b<0 ) b=0;
194
+ if( b > bits ) bits = b;
195
+ }
196
+
197
+ tmp = xmlGetProp( node, (const xmlChar *)"y" );
198
+ if( tmp ) {
199
+ sscanf( (char*)tmp, "%i", &y);
200
+ xmlFree( tmp );
201
+ int b = SWFBitsNeeded( y, true );
202
+ b -= 2;
203
+ if( b<0 ) b=0;
204
+ if( b > bits ) bits = b;
205
+ }
206
+ }
207
+
208
+ void LineTo::setx( int _x ) {
209
+ int b = SWFBitsNeeded( _x, true );
210
+ if( b > bits ) bits = b;
211
+ x = _x;
212
+ }
213
+
214
+ void LineTo::sety( int _y ) {
215
+ int b = SWFBitsNeeded( _y, true );
216
+ if( b > bits ) bits = b;
217
+ y = _y;
218
+ }
219
+
220
+ }