Source code: com/anotherbigidea/flash/writers/SWFTagTypesImpl.java
1 /****************************************************************
2 * Copyright (c) 2001, David N. Main, All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or
5 * without modification, are permitted provided that the
6 * following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
16 *
17 * 3. The name of the author may not be used to endorse or
18 * promote products derived from this software without specific
19 * prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
31 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
32 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 ****************************************************************/
34 package com.anotherbigidea.flash.writers;
35
36 import java.io.IOException;
37 import java.io.InputStream;
38 import java.util.Vector;
39
40 import com.anotherbigidea.flash.interfaces.SWFActions;
41 import com.anotherbigidea.flash.interfaces.SWFFileSignature;
42 import com.anotherbigidea.flash.interfaces.SWFShape;
43 import com.anotherbigidea.flash.interfaces.SWFTagTypes;
44 import com.anotherbigidea.flash.interfaces.SWFText;
45 import com.anotherbigidea.flash.interfaces.SWFVectors;
46 import com.anotherbigidea.flash.structs.AlphaColor;
47 import com.anotherbigidea.flash.structs.AlphaTransform;
48 import com.anotherbigidea.flash.structs.Color;
49 import com.anotherbigidea.flash.structs.ColorTransform;
50 import com.anotherbigidea.flash.structs.Matrix;
51 import com.anotherbigidea.flash.structs.Rect;
52 import com.anotherbigidea.flash.structs.SoundInfo;
53
54 /**
55 * A pass-through implementation of the SWFTagTypes and SWFFileSignature
56 * interfaces - useful as a base class
57 */
58 public class SWFTagTypesImpl implements SWFTagTypes, SWFFileSignature
59 {
60 protected SWFTagTypes mTagtypes;
61
62 /**
63 * @param tags may be null
64 */
65 public SWFTagTypesImpl( SWFTagTypes tags )
66 {
67 mTagtypes = tags;
68 }
69
70 /**
71 * SWFTags interface
72 */
73 public void tag( int tagType, boolean longTag, byte[] contents )
74 throws IOException
75 {
76 if( mTagtypes != null ) mTagtypes.tag( tagType, longTag, contents );
77 }
78
79 /**
80 * @see SWFFileSignature#signature(String)
81 */
82 public void signature( String sig ) {
83 if( mTagtypes != null && mTagtypes instanceof SWFFileSignature ) {
84 ((SWFFileSignature) mTagtypes).signature( sig );
85 }
86 }
87
88 /**
89 * SWFHeader interface.
90 * Sets movie length to -1 to force a recalculation since the length
91 * cannot be guaranteed to be the same as the original.
92 */
93 public void header( int version, long length,
94 int twipsWidth, int twipsHeight,
95 int frameRate, int frameCount ) throws IOException
96 {
97 if( mTagtypes != null ) mTagtypes.header( version, length, twipsWidth, twipsHeight,
98 frameRate, frameCount );
99 }
100
101 /**
102 * SWFTagTypes interface
103 */
104 public void tagEnd() throws IOException
105 {
106 if( mTagtypes != null ) mTagtypes.tagEnd();
107 }
108
109 /**
110 * SWFTagTypes interface
111 */
112 public void tagDefineSound( int id, int format, int frequency,
113 boolean bits16, boolean stereo,
114 int sampleCount, byte[] soundData )
115 throws IOException
116 {
117 if( mTagtypes != null ) mTagtypes.tagDefineSound( id, format, frequency,
118 bits16, stereo, sampleCount, soundData );
119 }
120
121 /**
122 * SWFTagTypes interface
123 */
124 public void tagDefineButtonSound( int buttonId,
125 int rollOverSoundId, SoundInfo rollOverSoundInfo,
126 int rollOutSoundId, SoundInfo rollOutSoundInfo,
127 int pressSoundId, SoundInfo pressSoundInfo,
128 int releaseSoundId, SoundInfo releaseSoundInfo )
129 throws IOException
130 {
131 if( mTagtypes != null ) mTagtypes.tagDefineButtonSound( buttonId,
132 rollOverSoundId, rollOverSoundInfo,
133 rollOutSoundId, rollOutSoundInfo,
134 pressSoundId, pressSoundInfo,
135 releaseSoundId, releaseSoundInfo );
136 }
137
138 /**
139 * SWFTagTypes interface
140 */
141 public void tagStartSound( int soundId, SoundInfo info ) throws IOException
142 {
143 if( mTagtypes != null ) mTagtypes.tagStartSound( soundId, info );
144 }
145
146 /**
147 * SWFTagTypes interface
148 */
149 public void tagSoundStreamHead(
150 int playbackFrequency, boolean playback16bit, boolean playbackStereo,
151 int streamFormat, int streamFrequency, boolean stream16bit, boolean streamStereo,
152 int averageSampleCount ) throws IOException
153 {
154 if( mTagtypes != null ) mTagtypes.tagSoundStreamHead(
155 playbackFrequency, playback16bit, playbackStereo,
156 streamFormat, streamFrequency, stream16bit, streamStereo,
157 averageSampleCount );
158 }
159
160 /**
161 * SWFTagTypes interface
162 */
163 public void tagSoundStreamHead2(
164 int playbackFrequency, boolean playback16bit, boolean playbackStereo,
165 int streamFormat, int streamFrequency, boolean stream16bit, boolean streamStereo,
166 int averageSampleCount ) throws IOException
167 {
168 if( mTagtypes != null ) mTagtypes.tagSoundStreamHead2(
169 playbackFrequency, playback16bit, playbackStereo,
170 streamFormat, streamFrequency, stream16bit, streamStereo,
171 averageSampleCount );
172 }
173
174 /**
175 * SWFTagTypes interface
176 */
177 public void tagSoundStreamBlock( byte[] soundData ) throws IOException
178 {
179 if( mTagtypes != null ) mTagtypes.tagSoundStreamBlock( soundData );
180 }
181
182 /**
183 * SWFTagTypes interface
184 */
185 public void tagSerialNumber( String serialNumber ) throws IOException
186 {
187 if( mTagtypes != null ) mTagtypes.tagSerialNumber( serialNumber );
188 }
189
190 /**
191 * SWFTagTypes interface
192 */
193 public void tagGenerator( byte[] data ) throws IOException
194 {
195 if( mTagtypes != null ) mTagtypes.tagGenerator( data );
196 }
197
198 /**
199 * SWFTagTypes interface
200 */
201 public void tagGeneratorText( byte[] data ) throws IOException
202 {
203 if( mTagtypes != null ) mTagtypes.tagGeneratorText( data );
204 }
205
206 /**
207 * SWFTagTypes interface
208 */
209 public void tagGeneratorFont( byte[] data ) throws IOException
210 {
211 if( mTagtypes != null ) mTagtypes.tagGeneratorFont( data );
212 }
213
214 /**
215 * SWFTagTypes interface
216 */
217 public void tagGeneratorCommand( byte[] data ) throws IOException
218 {
219 if( mTagtypes != null ) mTagtypes.tagGeneratorCommand( data );
220 }
221
222 /**
223 * SWFTagTypes interface
224 */
225 public void tagNameCharacter( byte[] data ) throws IOException
226 {
227 if( mTagtypes != null ) mTagtypes.tagNameCharacter( data );
228 }
229
230 /**
231 * SWFTagTypes interface
232 */
233 public void tagDefineBits( int id, byte[] imageData ) throws IOException
234 {
235 if( mTagtypes != null ) mTagtypes.tagDefineBits( id, imageData );
236 }
237
238 /**
239 * SWFTagTypes interface
240 */
241 public void tagJPEGTables( byte[] jpegEncodingData ) throws IOException
242 {
243 if( mTagtypes != null ) mTagtypes.tagJPEGTables( jpegEncodingData );
244 }
245
246 /**
247 * SWFTagTypes interface
248 */
249 public void tagDefineBitsJPEG3( int id, byte[] imageData, byte[] alphaData )
250 throws IOException
251 {
252 if( mTagtypes != null ) mTagtypes.tagDefineBitsJPEG3( id, imageData, alphaData );
253 }
254
255 /**
256 * SWFTagTypes interface
257 */
258 public void tagShowFrame() throws IOException
259 {
260 if( mTagtypes != null ) mTagtypes.tagShowFrame();
261 }
262
263 /**
264 * SWFTagTypes interface
265 */
266 public SWFActions tagDoAction() throws IOException
267 {
268 if( mTagtypes != null ) return mTagtypes.tagDoAction();
269 return null;
270 }
271
272 /**
273 * SWFTagTypes interface
274 */
275 public SWFActions tagDoInitAction( int spriteId ) throws IOException
276 {
277 if( mTagtypes != null ) return mTagtypes.tagDoInitAction( spriteId );
278 return null;
279 }
280
281 /**
282 * SWFTagTypes interface
283 */
284 public SWFShape tagDefineShape( int id, Rect outline ) throws IOException
285 {
286 if( mTagtypes != null ) return mTagtypes.tagDefineShape( id, outline );
287 return null;
288 }
289
290 /**
291 * SWFTagTypes interface
292 */
293 public SWFShape tagDefineShape2( int id, Rect outline ) throws IOException
294 {
295 if( mTagtypes != null ) return mTagtypes.tagDefineShape2( id, outline );
296 return null;
297 }
298
299 /**
300 * SWFTagTypes interface
301 */
302 public SWFShape tagDefineShape3( int id, Rect outline ) throws IOException
303 {
304 if( mTagtypes != null ) return mTagtypes.tagDefineShape3( id, outline );
305 return null;
306 }
307
308 /**
309 * SWFTagTypes interface
310 */
311 public void tagFreeCharacter( int charId ) throws IOException
312 {
313 if( mTagtypes != null ) mTagtypes.tagFreeCharacter( charId );
314 }
315
316 /**
317 * SWFTagTypes interface
318 */
319 public void tagPlaceObject( int charId, int depth,
320 Matrix matrix, AlphaTransform cxform )
321 throws IOException
322 {
323 if( mTagtypes != null ) mTagtypes.tagPlaceObject( charId, depth, matrix, cxform );
324 }
325
326 /**
327 * SWFTagTypes interface
328 */
329 public SWFActions tagPlaceObject2( boolean isMove,
330 int clipDepth,
331 int depth,
332 int charId,
333 Matrix matrix,
334 AlphaTransform cxform,
335 int ratio,
336 String name,
337 int clipActionFlags )
338 throws IOException
339 {
340 if( mTagtypes != null ) return mTagtypes.tagPlaceObject2( isMove, clipDepth, depth,
341 charId, matrix, cxform, ratio,
342 name, clipActionFlags );
343 return null;
344 }
345
346 /**
347 * SWFTagTypes interface
348 */
349 public void tagRemoveObject( int charId, int depth ) throws IOException
350 {
351 if( mTagtypes != null ) mTagtypes.tagRemoveObject( charId, depth );
352 }
353
354 /**
355 * SWFTagTypes interface
356 */
357 public void tagRemoveObject2(int depth ) throws IOException
358 {
359 if( mTagtypes != null ) mTagtypes.tagRemoveObject2( depth );
360 }
361
362 /**
363 * SWFTagTypes interface
364 */
365 public void tagSetBackgroundColor( Color color ) throws IOException
366 {
367 if( mTagtypes != null ) mTagtypes.tagSetBackgroundColor( color );
368 }
369
370 /**
371 * SWFTagTypes interface
372 */
373 public void tagFrameLabel( String label ) throws IOException
374 {
375 if( mTagtypes != null ) mTagtypes.tagFrameLabel( label );
376 }
377
378 /**
379 * SWFTagTypes interface
380 */
381 public void tagFrameLabel( String label, boolean isAnchor ) throws IOException {
382 if( mTagtypes != null ) mTagtypes.tagFrameLabel( label, isAnchor );
383 }
384
385 /**
386 * SWFTagTypes interface
387 */
388 public SWFTagTypes tagDefineSprite( int id ) throws IOException
389 {
390 if( mTagtypes != null ) return mTagtypes.tagDefineSprite( id );
391 return null;
392 }
393
394 /**
395 * SWFTagTypes interface
396 */
397 public void tagProtect( byte[] password ) throws IOException
398 {
399 if( mTagtypes != null ) mTagtypes.tagProtect( password );
400 }
401
402 /**
403 * SWFTagTypes interface
404 */
405 public void tagEnableDebug( byte[] password ) throws IOException
406 {
407 if( mTagtypes != null ) mTagtypes.tagEnableDebug( password );
408 }
409
410 /**
411 * SWFTagTypes interface
412 */
413 public void tagEnableDebug2( byte[] password ) throws IOException
414 {
415 if( mTagtypes != null ) mTagtypes.tagEnableDebug2( password );
416 }
417
418 /**
419 * SWFTagTypes interface
420 */
421 public SWFVectors tagDefineFont( int id, int numGlyphs ) throws IOException
422 {
423 if( mTagtypes != null ) return mTagtypes.tagDefineFont( id, numGlyphs );
424 return null;
425 }
426
427 /**
428 * SWFTagTypes interface
429 */
430 public void tagDefineFontInfo( int fontId, String fontName, int flags, int[] codes )
431 throws IOException
432 {
433 if( mTagtypes != null ) mTagtypes.tagDefineFontInfo( fontId, fontName, flags, codes );
434 }
435
436 /**
437 * SWFTagTypes interface
438 */
439 public void tagDefineFontInfo2( int fontId, String fontName, int flags, int[] codes, int languageCode )
440 throws IOException
441 {
442 if( mTagtypes != null ) mTagtypes.tagDefineFontInfo2( fontId, fontName, flags, codes, languageCode );
443 }
444
445 /**
446 * SWFTagTypes interface
447 */
448 public SWFVectors tagDefineFont2( int id, int flags, String name, int numGlyphs,
449 int ascent, int descent, int leading,
450 int[] codes, int[] advances, Rect[] bounds,
451 int[] kernCodes1, int[] kernCodes2,
452 int[] kernAdjustments ) throws IOException
453 {
454 if( mTagtypes != null ) return mTagtypes.tagDefineFont2( id, flags, name, numGlyphs,
455 ascent, descent, leading, codes, advances,
456 bounds, kernCodes1, kernCodes2, kernAdjustments );
457 return null;
458 }
459
460 /**
461 * SWFTagTypes interface
462 */
463 public void tagDefineTextField( int fieldId, String fieldName,
464 String initialText, Rect boundary, int flags,
465 AlphaColor textColor, int alignment, int fontId, int fontSize,
466 int charLimit, int leftMargin, int rightMargin, int indentation,
467 int lineSpacing )
468 throws IOException
469 {
470 if( mTagtypes != null ) mTagtypes.tagDefineTextField( fieldId, fieldName, initialText,
471 boundary, flags, textColor, alignment, fontId,
472 fontSize, charLimit, leftMargin, rightMargin,
473 indentation, lineSpacing );
474 }
475
476 /**
477 * SWFTagTypes interface
478 */
479 public SWFText tagDefineText( int id, Rect bounds, Matrix matrix )
480 throws IOException
481 {
482 if( mTagtypes != null ) return mTagtypes.tagDefineText( id, bounds, matrix );
483
484 return null;
485 }
486
487 /**
488 * SWFTagTypes interface
489 */
490 public SWFText tagDefineText2( int id, Rect bounds, Matrix matrix ) throws IOException
491 {
492 if( mTagtypes != null ) return mTagtypes.tagDefineText2( id, bounds, matrix );
493 return null;
494 }
495
496 /**
497 * SWFTagTypes interface
498 */
499 public SWFActions tagDefineButton( int id, Vector buttonRecords )
500 throws IOException
501 {
502 if( mTagtypes != null ) return mTagtypes.tagDefineButton( id, buttonRecords );
503 return null;
504 }
505
506 /**
507 * SWFTagTypes interface
508 */
509 public void tagButtonCXForm( int buttonId, ColorTransform transform )
510 throws IOException
511 {
512 if( mTagtypes != null ) mTagtypes.tagButtonCXForm( buttonId, transform );
513 }
514
515 /**
516 * SWFTagTypes interface
517 */
518 public SWFActions tagDefineButton2( int id,
519 boolean trackAsMenu,
520 Vector buttonRecord2s )
521 throws IOException
522 {
523 if( mTagtypes != null ) return mTagtypes.tagDefineButton2( id, trackAsMenu,
524 buttonRecord2s );
525 return null;
526 }
527
528 /**
529 * SWFTagTypes interface
530 */
531 public void tagExport( String[] names, int[] ids ) throws IOException
532 {
533 if( mTagtypes != null ) mTagtypes.tagExport( names, ids );
534 }
535
536 /**
537 * SWFTagTypes interface
538 */
539 public void tagImport( String movieName, String[] names, int[] ids )
540 throws IOException
541 {
542 if( mTagtypes != null ) mTagtypes.tagImport( movieName, names, ids );
543 }
544
545 /**
546 * SWFTagTypes interface
547 */
548 public void tagDefineQuickTimeMovie( int id, String filename ) throws IOException
549 {
550 if( mTagtypes != null ) mTagtypes.tagDefineQuickTimeMovie( id, filename );
551 }
552
553 /**
554 * SWFTagTypes interface
555 */
556 public void tagDefineBitsJPEG2( int id, byte[] data ) throws IOException
557 {
558 if( mTagtypes != null ) mTagtypes.tagDefineBitsJPEG2( id, data );
559 }
560
561 /**
562 * SWFTagTypes interface
563 */
564 public void tagDefineBitsJPEG2( int id, InputStream jpegImage ) throws IOException
565 {
566 if( mTagtypes != null ) mTagtypes.tagDefineBitsJPEG2( id, jpegImage );
567 }
568
569 /**
570 * SWFTagTypes interface
571 */
572 public SWFShape tagDefineMorphShape( int id, Rect startBounds, Rect endBounds )
573 throws IOException
574 {
575 if( mTagtypes != null ) return mTagtypes.tagDefineMorphShape( id, startBounds, endBounds );
576 return null;
577 }
578
579 /**
580 * SWFTagTypes interface
581 */
582 public void tagDefineBitsLossless( int id, int format, int width, int height,
583 Color[] colors, byte[] imageData )
584 throws IOException
585 {
586 if( mTagtypes != null ) mTagtypes.tagDefineBitsLossless( id , format, width, height,
587 colors, imageData );
588 }
589
590 /**
591 * SWFTagTypes interface
592 */
593 public void tagDefineBitsLossless2( int id, int format, int width, int height,
594 Color[] colors, byte[] imageData )
595 throws IOException
596 {
597 if( mTagtypes != null ) mTagtypes.tagDefineBitsLossless2( id , format, width, height,
598 colors, imageData );
599 }
600 }