1 /* libsswf_tag_base.c++ -- written by Alexis WILKE for Made to Order Software Corp. (c) 2002-2008 */
2 
3 /*
4 
5 Copyright (c) 2002-2008 Made to Order Software Corp.
6 
7 Permission is hereby granted, free of charge, to any
8 person obtaining a copy of this software and
9 associated documentation files (the "Software"), to
10 deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify,
12 merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom
14 the Software is furnished to do so, subject to the
15 following conditions:
16 
17 The above copyright notice and this permission notice
18 shall be included in all copies or substantial
19 portions of the Software.
20 
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
22 ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
23 LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
24 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
25 EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
28 ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 SOFTWARE.
31 
32 */
33 
34 /** \file
35  *
36  * \brief The implementation of the sswf::TagBase and sswf::TagBaseID classes
37  *
38  * This file declares the body of the functions which are not
39  * inline. It is part of the SSWF library.
40  */
41 
42 #include	"sswf/libsswf.h"
43 
44 using namespace sswf;
45 
46 
47 
48 /////////////////////////////////////////// TagBase
49 
50 /** \class sswf::TagBase
51  *
52  * \brief The base of all the tags
53  *
54  * The TagBase class is the base class for all the tags. You cannot
55  * instantiate a TagBase since it has several pure virtual functions
56  * (and it would not make sense.)
57  *
58  * The TagBase defines basic functions and functions that the other
59  * tags re-implement.
60  *
61  * There is a set of functions used to manage the tree of tags:
62  *
63  *	Name		Type of the tag (in a string)
64  *	Label		Retrieve the label of the tag
65  *	WhichFrame	Frame number where this tag resides
66  *	SetLabel	Give a label to the tag
67  *	FindLabelledTag	Search the tree for an object with that name
68  *	FindTagWithID	Search the tree for an object with that identifier
69  *	Children	Get a pointer to all the children of that tag
70  *	Next		Get a pointer to the next tag
71  *	Previous	Get a pointer to the previous tag
72  *	Parent		Get a pointer to the parent
73  *	Header		Get a pointer to the header (parent most tag)
74  *	TypeFlags	Type of a tag defined with flags
75  *
76  * The tree is always started with a Header. The header can be the parent
77  * of any other tag. Sprites can themselves be composed of a certain number
78  * of sub-tags.
79  *
80  * Tags use the MinimumVersion() and Version() functions to know more about
81  * the version of the current movie being saved.
82  *
83  * The following functions are used to help you save the movie. Mainly the
84  * tags when saving themselves use these functions as helpers.
85  *
86  *	Save		Save the whole tag and its content
87  *	PreSave		Prepare the tag to be saved (usually to determine the
88  *			minimum version required to save that tag)
89  *	PreSave2ndPass	Prepare the tag once the exact version of the movie
90  *			is known (especially used by the TagFont); this may
91  *			still generate a fatal error if the tag cannot be
92  *			saved properly
93  *	SaveString	Save a C string
94  *	SaveTag		Save the tag number and size
95  *	SIBitSize	Number of bits necessary to save a specified value
96  *	UIBitSize	Number of bits necessary to save a specified value
97  *	Double2Signed	Transform a double in a fixed value
98  *	Signed2Double	Transform a fixed value to a double
99  *
100  * \sa <a href="../SWFalexref.html#swf_tag">SWF Alexis' Reference&mdash;swf_tag</a>
101  */
102 
103 
104 /** \typedef sswf::TagBase::swf_type_t
105  *
106  * \brief An integer holding flags representing the type of a tag.
107  *
108  * This type is used by the sswf::TagBase::TypeFlags() function.
109  * It represents different flags that different tags can set. They
110  * are used to determine the generic type of a tag.
111  *
112  * The two main groups of tags are the CONTROL tags and the DEFINE
113  * tags.
114  */
115 
116 
117 
118 
119 /** \typedef sswf::TagBase::swf_tag_t
120  *
121  * \brief Defines all the tags supported by SSWF.
122  *
123  * This type lists all the tags supported by SSWF. The numbers are
124  * those saved in the final SWF output.
125  *
126  * The \ref SWF_TAG_UNKNOWN and \ref SWF_TAG_max are only for the
127  * SSWF library to declare unknown tags and know what the largest
128  * possible value in the current version.
129  *
130  * The \ref SWF_TAG_END has the special value of zero.
131  */
132 
133 
134 /** \var sswf::TagBase::SWF_TAG_UNKNOWN
135  *
136  * \brief An undefined or unknown tag
137  *
138  * This special SSWF tag value is used to mark an unknown or undefined
139  * tag number. It cannot be saved in an SWF file.
140  *
141  * <br>
142  * <br>
143  */
144 
145 
146 /** \var sswf::TagBase::SWF_TAG_END
147  *
148  * \brief The last tag in a list of tags.
149  *
150  * This tag is used to terminate a list of tags. In general you don't
151  * need to terminate your lists since the library does it for you.
152  *
153  * Also, the library will ensure that a \ref SWF_TAG_SHOW_FRAME is included.
154  *
155  * \sa SWF_TAG_DEFINE_SPRITE
156  * \sa <a href="../SWFalexref.html#tag_end">SWF Alexis' Reference</a>
157  *
158  * <br>
159  * <br>
160  */
161 
162 
163 /** \var sswf::TagBase::SWF_TAG_SHOW_FRAME
164  *
165  * \brief This tag marks the end of the current frame.
166  *
167  * An SWF movie is composed of a set of frames. Each frame is
168  * terminated with one %SWF_TAG_SHOW_FRAME tag.
169  *
170  * Adding multiple %SWF_TAG_SHOW_FRAME tags one after another
171  * is a way to slow down the playback at different location in
172  * your SWF movie.
173  *
174  * There should be a show frame tag before any end tag.
175  *
176  * \sa SWF_TAG_END
177  * \sa SWF_TAG_DEFINE_SPRITE
178  * \sa <a href="../SWFalexref.html#tag_showframe">SWF Alexis' Reference</a>
179  *
180  * <br>
181  * <br>
182  */
183 
184 
185 /** \var sswf::TagBase::SWF_TAG_DEFINE_SHAPE
186  *
187  * \brief Defines a shape
188  *
189  * Of the different graphical objects supported by SWF, the shapes
190  * are the primary ones. Shapes are vector based objects.
191  *
192  * \sa SWF_TAG_DEFINE_SHAPE2
193  * \sa SWF_TAG_DEFINE_SHAPE3
194  * \sa SWF_TAG_DEFINE_SHAPE4
195  * \sa SWF_TAG_DEFINE_MORPH_SHAPE
196  * \sa SWF_TAG_DEFINE_MORPH_SHAPE2
197  * \sa <a href="../SWFalexref.html#tag_defineshape">SWF Alexis' Reference</a>
198  *
199  * <br>
200  * <br>
201  */
202 
203 
204 /** \var sswf::TagBase::SWF_TAG_PLACE_OBJECT
205  *
206  * \brief Place an object in the display list
207  *
208  * This tag places an object such as a shape or a sprite in the
209  * current display list.
210  *
211  * \sa SWF_TAG_PLACE_OBJECT2
212  * \sa SWF_TAG_PLACE_OBJECT3
213  * \sa SWF_TAG_DEFINE_SPRITE
214  * \sa <a href="../SWFalexref.html#tag_placeobject">SWF Alexis' Reference</a>
215  *
216  * <br>
217  * <br>
218  */
219 
220 
221 /** \var sswf::TagBase::SWF_TAG_REMOVE_OBJECT
222  *
223  * \brief Remove an object from the display list
224  *
225  * This tag removes an object from the display list. You need to specify the
226  * object identifier and the depth at which it was inserted.
227  *
228  * You can use the SWF_TAG_REMOVE_OBJECT2 to reduce the size of the tag used
229  * to remove an object since in that case the identifier is not included. In
230  * most cases, the depth is enough since only one object should be inserted
231  * at one depth.
232  *
233  * \sa SWF_TAG_REMOVE_OBJECT2
234  * \sa SWF_TAG_DEFINE_SPRITE
235  * \sa <a href="../SWFalexref.html#tag_removeobject">SWF Alexis' Reference</a>
236  *
237  * <br>
238  * <br>
239  */
240 
241 
242 /** \var sswf::TagBase::SWF_TAG_DEFINE_BITS
243  *
244  * \brief This tag is deprecated. Please use SWF_TAG_DEFINE_BITS_JPEG instead.
245  *
246  * \sa SWF_TAG_DEFINE_BITS_JPEG
247  *
248  * <br>
249  * <br>
250  */
251 
252 
253 /** \var sswf::TagBase::SWF_TAG_DEFINE_BITS_JPEG
254  *
255  * \brief Define a JPEG image data.
256  *
257  * This tag is used to define a 2D image.
258  *
259  * This is a synonym of SWF_TAG_DEFINE_BITS which is deprecated in the SSWF
260  * library.
261  *
262  * \sa SWF_TAG_DEFINE_BITS_LOSSLESS
263  * \sa SWF_TAG_DEFINE_BITS_LOSSLESS2
264  * \sa SWF_TAG_JPEG_TABLES
265  * \sa SWF_TAG_DEFINE_BITS_JPEG2
266  * \sa SWF_TAG_DEFINE_BITS_JPEG3
267  * \sa <a href="../SWFalexref.html#tag_definebits">SWF Alexis' Reference</a>
268  *
269  * <br>
270  * <br>
271  */
272 
273 
274 /** \var sswf::TagBase::SWF_TAG_DEFINE_BUTTON
275  *
276  * \brief Define some image data.
277  *
278  * This tag is used to define a button. This really means an active area (it does
279  * not need to react to clicks.)
280  *
281  * \sa SWF_TAG_DEFINE_BUTTON2
282  * \sa SWF_TAG_DEFINE_BUTTON_COLOR_TRANSFORM
283  * \sa <a href="../SWFalexref.html#tag_definebutton">SWF Alexis' Reference</a>
284  *
285  * <br>
286  * <br>
287  */
288 
289 
290 /** \var sswf::TagBase::SWF_TAG_JPEG_TABLES
291  *
292  * \brief Define compression tables for JPEG images.
293  *
294  * To save some space, multiple JPEG images may share the same set of compression
295  * tables. In reality, this can result in a high decrease in decompressed image
296  * quality and in practice it is rarely used these days.
297  *
298  * \sa SWF_TAG_DEFINE_BITS_JPEG
299  * \sa <a href="../SWFalexref.html#tag_jpegtables">SWF Alexis' Reference</a>
300  *
301  * <br>
302  * <br>
303  */
304 
305 
306 /** \var sswf::TagBase::SWF_TAG_SET_BACKGROUND_COLOR
307  *
308  * \brief Defines the color to use for the animation background.
309  *
310  * To save some space, multiple JPEG images may share the same set of compression
311  * tables. In reality, this can result in a high decrease in decompressed image
312  * quality and in practice it is rarely used these days.
313  *
314  * \sa <a href="../SWFalexref.html#tag_setbackgroundcolor">SWF Alexis' Reference</a>
315  *
316  * <br>
317  * <br>
318  */
319 
320 
321 /** \var sswf::TagBase::SWF_TAG_DEFINE_FONT
322  *
323  * \brief Define a version 1 font
324  *
325  * This tag is used to declare an internal or external font definition.
326  * Fonts are composed of glyphs which happen to be shapes.
327  *
328  * \warning
329  * This font cannot be referenced from an SWF_TAG_TEXT_FIELD tag. Instead,
330  * you need to use an SWF_TAG_DEFINE_FONT2.
331  *
332  * \sa SWF_TAG_DEFINE_FONT2
333  * \sa SWF_TAG_DEFINE_FONT3
334  * \sa SWF_TAG_TEXT_FIELD
335  * \sa SWF_TAG_DEFINE_FONT_ALIGN_ZONES
336  * \sa SWF_TAG_CSM_TEXT_SETTINGS
337  * \sa <a href="../SWFalexref.html#tag_definefont">SWF Alexis' Reference</a>
338  *
339  * <br>
340  * <br>
341  */
342 
343 
344 /** \var sswf::TagBase::SWF_TAG_DEFINE_TEXT
345  *
346  * \brief Define a graphical object to draw text
347  *
348  * This tag defines a string to be displayed using a specified font.
349  *
350  * \sa SWF_TAG_DEFINE_TEXT2
351  * \sa SWF_TAG_TEXT_FIELD
352  * \sa <a href="../SWFalexref.html#tag_definetext">SWF Alexis' Reference</a>
353  *
354  * <br>
355  * <br>
356  */
357 
358 
359 /** \var sswf::TagBase::SWF_TAG_DO_ACTION
360  *
361  * \brief Define an SWF ActionScript
362  *
363  * This tag is used to execute an ActionScript.
364  *
365  * \sa SWF_TAG_DO_INIT_ACTION
366  * \sa SWF_TAG_DEFINE_SPRITE
367  * \sa SWF_TAG_ACTIONSCRIPT2
368  * \sa SWF_TAG_ACTIONSCRIPT2_DEFINE
369  * \sa SWF_TAG_ACTIONSCRIPT2_INSTANTIATE
370  * \sa <a href="../SWFalexref.html#tag_doaction">SWF Alexis' Reference</a>
371  *
372  * <br>
373  * <br>
374  */
375 
376 
377 /** \var sswf::TagBase::SWF_TAG_DEFINE_FONT_INFO
378  *
379  * \brief Define font metrics, names, etc.
380  *
381  * This tag is used to define more details about a font such as its
382  * name and whether to try to use the system font if available.
383  *
384  * \sa SWF_TAG_DEFINE_FONT_INFO2
385  * \sa SWF_TAG_DEFINE_TEXT
386  * \sa SWF_TAG_TEXT_FIELD
387  * \sa <a href="../SWFalexref.html#tag_definefontinfo">SWF Alexis' Reference</a>
388  *
389  * <br>
390  * <br>
391  */
392 
393 
394 /** \var sswf::TagBase::SWF_TAG_DEFINE_SOUND
395  *
396  * \brief Define a sound data block
397  *
398  * This tag defines a block of data which represent a sound. It
399  * can be played with the \ref SWF_TAG_START_SOUND tag.
400  *
401  * \sa <a href="../SWFalexref.html#tag_definesound">SWF Alexis' Reference</a>
402  *
403  * <br>
404  * <br>
405  */
406 
407 
408 /** \var sswf::TagBase::SWF_TAG_START_SOUND
409  *
410  * \brief Starts playing a sound
411  *
412  * This tag starts playing a sound previously defined with
413  * an \ref SWF_TAG_DEFINE_SOUND tag. The same sound can be
414  * played multiple times. Also this tag can be used to stop
415  * playing a sound (which is why there are no 'stop sound'
416  * tag.)
417  *
418  * \sa SWF_TAG_DEFINE_SOUND
419  * \sa SWF_TAG_DEFINE_SPRITE
420  * \sa <a href="../SWFalexref.html#tag_startsound">SWF Alexis' Reference</a>
421  *
422  * <br>
423  * <br>
424  */
425 
426 
427 /** \var sswf::TagBase::SWF_TAG_DEFINE_BUTTON_SOUND
428  *
429  * \brief Attach sound effects to a button
430  *
431  * This tag attaches sound effects to a button. The
432  * sounds will be played whenever a given event occur.
433  *
434  * \sa <a href="../SWFalexref.html#tag_definebuttonsound">SWF Alexis' Reference</a>
435  *
436  * <br>
437  * <br>
438  */
439 
440 
441 /** \var sswf::TagBase::SWF_TAG_SOUND_STREAM_HEAD
442  *
443  * \brief Header defining a streaming sound
444  *
445  * This tag initializes a streaming sound effect. The actual data of
446  * the sound effect is in the SWF_TAG_SOUND_STREAM_BLOCK tags which
447  * follow.
448  *
449  * \sa SWF_TAG_SOUND_STREAM_BLOCK
450  * \sa SWF_TAG_SOUND_STREAM_HEAD2
451  * \sa SWF_TAG_DEFINE_SPRITE
452  * \sa <a href="../SWFalexref.html#tag_soundstreamhead">SWF Alexis' Reference</a>
453  *
454  * <br>
455  * <br>
456  */
457 
458 
459 /** \var sswf::TagBase::SWF_TAG_SOUND_STREAM_BLOCK
460  *
461  * \brief Block of data of a streaming sound
462  *
463  * This tag defines data for the streaming sound started with
464  * an SWF_TAG_SOUND_STREAM_HEAD or SWF_TAG_SOUND_STREAM_HEAD2 tag.
465  *
466  * \sa SWF_TAG_SOUND_STREAM_HEAD
467  * \sa SWF_TAG_SOUND_STREAM_HEAD2
468  * \sa SWF_TAG_DEFINE_SPRITE
469  * \sa <a href="../SWFalexref.html#tag_soundstreamblock">SWF Alexis' Reference</a>
470  *
471  * <br>
472  * <br>
473  */
474 
475 
476 /** \var sswf::TagBase::SWF_TAG_DEFINE_BITS_LOSSLESS
477  *
478  * \brief Define a PNG image data.
479  *
480  * This tag inserts a PNG image. This can be used for much higher image
481  * quality, but it is in general larger than a JPEG image.
482  *
483  * \sa SWF_TAG_DEFINE_BITS_LOSSLESS2
484  * \sa SWF_TAG_DEFINE_BITS_JPEG
485  * \sa SWF_TAG_DEFINE_BITS_JPEG2
486  * \sa SWF_TAG_DEFINE_BITS_JPEG3
487  * \sa <a href="../SWFalexref.html#tag_definebitslossless">SWF Alexis' Reference</a>
488  *
489  * <br>
490  * <br>
491  */
492 
493 
494 /** \var sswf::TagBase::SWF_TAG_DEFINE_BITS_JPEG2
495  *
496  * \brief Define a JPEG image data and tables.
497  *
498  * This tag inserts a complete JPEG image, meaning the JPEG data and tables
499  * are all saved in this tag.
500  *
501  * \sa SWF_TAG_DEFINE_BITS_JPEG
502  * \sa SWF_TAG_DEFINE_BITS_JPEG3
503  * \sa SWF_TAG_DEFINE_BITS_LOSSLESS
504  * \sa SWF_TAG_DEFINE_BITS_LOSSLESS2
505  * \sa <a href="../SWFalexref.html#tag_definebitsjpeg2">SWF Alexis' Reference</a>
506  *
507  * <br>
508  * <br>
509  */
510 
511 
512 
513 
514 /** \var sswf::TagBase::SWF_TAG_DEFINE_SHAPE2
515  *
516  * \brief Define an extended shape.
517  *
518  * This tag is used to define a shape. This tag extends the SWF_TAG_DEFINE_SHAPE
519  * by allowing more vectices within a single shape.
520  *
521  * \sa SWF_TAG_DEFINE_SHAPE
522  * \sa SWF_TAG_DEFINE_SHAPE3
523  * \sa SWF_TAG_DEFINE_SHAPE4
524  * \sa SWF_TAG_DEFINE_MORPH_SHAPE
525  * \sa SWF_TAG_DEFINE_MORPH_SHAPE2
526  * \sa <a href="../SWFalexref.html#tag_defineshape2">SWF Alexis' Reference</a>
527  *
528  * <br>
529  * <br>
530  */
531 
532 
533 
534 /** \var sswf::TagBase::SWF_TAG_DEFINE_BUTTON_COLOR_TRANSFORM
535  *
536  * \brief Define a simple color transformation for a button.
537  *
538  * This tag is a button complete used to allow a color transformation of the
539  * shape used in a button.
540  *
541  * If you really need color transformations, it is usually better to use the
542  * SWF_TAG_DEFINE_BUTTON2 and get the color transformation on a per state
543  * basis.
544  *
545  * \sa SWF_TAG_DEFINE_BUTTON
546  * \sa SWF_TAG_DEFINE_BUTTON2
547  * \sa <a href="../SWFalexref.html#tag_definebuttoncxform">SWF Alexis' Reference</a>
548  *
549  * <br>
550  * <br>
551  */
552 
553 
554 
555 /** \var sswf::TagBase::SWF_TAG_PROTECT
556  *
557  * \brief Mark the movie as protected (opposed to open)
558  *
559  * This precense of this tag marks the entire movie as protected. The concept is
560  * that a protected movie cannot be edited by a person other than the author (who
561  * has the source file used to generate this movie.)
562  *
563  * This tag was introducted in version 4 and it 100% protects the movie. That is,
564  * even the author cannot re-read the movie (unless you either remove this tag
565  * from the movie or you use a tool which ignores the tag.)
566  *
567  * In order for the authors to be able to re-read the movie later, you need to let
568  * the author enter a password. This is done using the SWF_TAG_PROTECT_DEBUG or
569  * SWF_TAG_PROTECT_DEBUG2 tag (which tag to use will actually depend on the movie
570  * version and not what you want to do with it.)
571  *
572  * \sa SWF_TAG_PROTECT_DEBUG
573  * \sa SWF_TAG_PROTECT_DEBUG2
574  * \sa <a href="../SWFalexref.html#tag_protect">SWF Alexis' Reference</a>
575  *
576  * <br>
577  * <br>
578  */
579 
580 
581 
582 /** \var sswf::TagBase::SWF_TAG_PLACE_OBJECT2
583  *
584  * \brief Place or remove an object.
585  *
586  * This tag lets you place, replace or remove an object at a given depth.
587  *
588  * \sa SWF_TAG_PLACE_OBJECT
589  * \sa SWF_TAG_PLACE_OBJECT3
590  * \sa SWF_TAG_DEFINE_SPRITE
591  * \sa <a href="../SWFalexref.html#tag_placeobject2">SWF Alexis' Reference</a>
592  *
593  * <br>
594  * <br>
595  */
596 
597 
598 
599 /** \var sswf::TagBase::SWF_TAG_REMOVE_OBJECT2
600  *
601  * \brief Remove an object at a specified depth.
602  *
603  * This tag lets you remove one object at a given depth without having to
604  * specify its reference ID.
605  *
606  * \sa SWF_TAG_REMOVE_OBJECT
607  * \sa SWF_TAG_DEFINE_SPRITE
608  * \sa <a href="../SWFalexref.html#tag_removeobject2">SWF Alexis' Reference</a>
609  *
610  * <br>
611  * <br>
612  */
613 
614 
615 
616 /** \var sswf::TagBase::SWF_TAG_DEFINE_SHAPE3
617  *
618  * \brief Defines a shape which supports transparency.
619  *
620  * This tag is similar to the SWF_TAG_DEFINE_SHAPE and SWF_TAG_DEFINE_SHAPE2.
621  * It adds the capability to define an alpha channel along the shape colors.
622  *
623  * \sa SWF_TAG_DEFINE_SHAPE
624  * \sa SWF_TAG_DEFINE_SHAPE2
625  * \sa SWF_TAG_DEFINE_SHAPE4
626  * \sa SWF_TAG_DEFINE_MORPH_SHAPE
627  * \sa SWF_TAG_DEFINE_MORPH_SHAPE2
628  * \sa <a href="../SWFalexref.html#tag_defineshape3">SWF Alexis' Reference</a>
629  *
630  * <br>
631  * <br>
632  */
633 
634 
635 
636 /** \var sswf::TagBase::SWF_TAG_DEFINE_TEXT2
637  *
638  * \brief Defines a text which supports transparency.
639  *
640  * This tag is similar to the SWF_TAG_DEFINE_TEXT. It adds the capability
641  * to define an alpha channel along the glyphs colors.
642  *
643  * \sa SWF_TAG_DEFINE_TEXT
644  * \sa SWF_TAG_TEXT_FIELD
645  * \sa SWF_TAG_DEFINE_FONT_INFO
646  * \sa SWF_TAG_DEFINE_FONT_INFO2
647  * \sa <a href="../SWFalexref.html#tag_definetext2">SWF Alexis' Reference</a>
648  *
649  * <br>
650  * <br>
651  */
652 
653 
654 
655 /** \var sswf::TagBase::SWF_TAG_DEFINE_BUTTON2
656  *
657  * \brief Defines a button which reacts upon a set of predefined events.
658  *
659  * This tag is similar to the SWF_TAG_DEFINE_BUTTON. It adds the capability
660  * to define an event which needs to occur for the linked actions to be
661  * executed.
662  *
663  * \sa SWF_TAG_DEFINE_BUTTON
664  * \sa <a href="../SWFalexref.html#tag_definebutton2">SWF Alexis' Reference</a>
665  *
666  * <br>
667  * <br>
668  */
669 
670 
671 
672 /** \var sswf::TagBase::SWF_TAG_DEFINE_BITS_JPEG3
673  *
674  * \brief Defines a JPEG image with an Alpha channel.
675  *
676  * This tag is an extension of the SWF_TAG_DEFINE_BITS_JPEG2 which supports
677  * an alpha channel. Thus this tag includes a full JPEG definition and a
678  * plane compressed with zlib to define an Alpha channel.
679  *
680  * \sa SWF_TAG_DEFINE_BITS_LOSSLESS
681  * \sa SWF_TAG_DEFINE_BITS_LOSSLESS2
682  * \sa SWF_TAG_DEFINE_BITS_JPEG
683  * \sa SWF_TAG_DEFINE_BITS_JPEG2
684  * \sa <a href="../SWFalexref.html#tag_definebitsjpeg3">SWF Alexis' Reference</a>
685  *
686  * <br>
687  * <br>
688  */
689 
690 
691 
692 /** \var sswf::TagBase::SWF_TAG_DEFINE_BITS_LOSSLESS2
693  *
694  * \brief Defines a loss less image with an Alpha channel.
695  *
696  * This tag is an extension of the SWF_TAG_DEFINE_BITS_LOSSLESS which supports
697  * an alpha channel. Thus this tag includes a full JPEG definition and a
698  * plane compressed with zlib to define an Alpha channel.
699  *
700  * \sa SWF_TAG_DEFINE_BITS_LOSSLESS
701  * \sa SWF_TAG_DEFINE_BITS_JPEG
702  * \sa SWF_TAG_DEFINE_BITS_JPEG2
703  * \sa SWF_TAG_DEFINE_BITS_JPEG3
704  * \sa <a href="../SWFalexref.html#tag_definebitslossless2">SWF Alexis' Reference</a>
705  *
706  * <br>
707  * <br>
708  */
709 
710 
711 
712 /** \var sswf::TagBase::SWF_TAG_DEFINE_SPRITE
713  *
714  * \brief Defines a sprite: an object composed of any number of other objects
715  *
716  * A sprite is composed of a control list. This means any tag marked as a
717  * CONTROL tag such as SWF_TAG_PLACE_OBJECT. You cannot use a definition tag
718  * within a sprite. However, you can put a script which creates new objects.
719  *
720  * \sa SWF_TAG_DO_ACTION
721  * \sa SWF_TAG_END
722  * \sa SWF_TAG_FRAME_LABEL
723  * \sa SWF_TAG_PLACE_OBJECT
724  * \sa SWF_TAG_PLACE_OBJECT2
725  * \sa SWF_TAG_PLACE_OBJECT3
726  * \sa SWF_TAG_REMOVE_OBJECT
727  * \sa SWF_TAG_REMOVE_OBJECT2
728  * \sa SWF_TAG_SHOW_FRAME
729  * \sa SWF_TAG_SOUND_STREAM_BLOCK
730  * \sa SWF_TAG_SOUND_STREAM_HEAD
731  * \sa SWF_TAG_SOUND_STREAM_HEAD2
732  * \sa SWF_TAG_START_SOUND
733  * \sa <a href="../SWFalexref.html#tag_definesprite">SWF Alexis' Reference</a>
734  *
735  * <br>
736  * <br>
737  */
738 
739 
740 
741 
742 
743 /** \var sswf::TagBase::SWF_TAG_PRODUCT_INFO
744  *
745  * \brief Defines the name of the product used to create the SWF file.
746  *
747  * This tag holds information about the product used to create this SWF file.
748  *
749  * It is all defined as numbers (Identifiers). It includes many versions and the
750  * date when it was compiled.
751  *
752  * \sa <a href="../SWFalexref.html#tag_productinfo">SWF Alexis' Reference</a>
753  *
754  * <br>
755  * <br>
756  */
757 
758 
759 
760 /** \var sswf::TagBase::SWF_TAG_FRAME_LABEL
761  *
762  * \brief Defines the name of the current frame
763  *
764  * This tag names a frame in order to allow scripts to jump to that
765  * frame by name.
766  *
767  * A URL can also specify a frame label (since version 6 of SWF).
768  *
769  * \sa SWF_TAG_DO_ACTION
770  * \sa SWF_TAG_DEFINE_SPRITE
771  * \sa <a href="../SWFalexref.html#tag_framelabel">SWF Alexis' Reference</a>
772  *
773  * <br>
774  * <br>
775  */
776 
777 
778 
779 /** \var sswf::TagBase::SWF_TAG_SOUND_STREAM_HEAD2
780  *
781  * \brief Initializes the streaming sound effect.
782  *
783  * This tag initializes a streaming sound effect. The actual data of
784  * the sound effect is in the SWF_TAG_SOUND_STREAM_BLOCK tags which
785  * follow.
786  *
787  * \sa SWF_TAG_SOUND_STREAM_BLOCK
788  * \sa SWF_TAG_SOUND_STREAM_HEAD
789  * \sa SWF_TAG_DEFINE_SPRITE
790  * \sa <a href="../SWFalexref.html#tag_soundstreamhead2">SWF Alexis' Reference</a>
791  *
792  * <br>
793  * <br>
794  */
795 
796 
797 
798 /** \var sswf::TagBase::SWF_TAG_DEFINE_MORPH_SHAPE
799  *
800  * \brief Defines a set of shapes to morph.
801  *
802  * This tag is similar to the SWF_TAG_DEFINE_SHAPE tag except that it defines
803  * two shapes. When placing this shape with SWF_TAG_PLACE_OBJECT2, you can
804  * specify the morphing position (percentage).
805  *
806  * \sa SWF_TAG_DEFINE_SHAPE
807  * \sa SWF_TAG_DEFINE_SHAPE2
808  * \sa SWF_TAG_DEFINE_SHAPE3
809  * \sa SWF_TAG_DEFINE_SHAPE4
810  * \sa SWF_TAG_DEFINE_MORPH_SHAPE2
811  * \sa <a href="../SWFalexref.html#tag_definemorphshape">SWF Alexis' Reference</a>
812  *
813  * <br>
814  * <br>
815  */
816 
817 
818 
819 /** \var sswf::TagBase::SWF_TAG_DEFINE_FONT2
820  *
821  * \brief Defines a set of glyphs in a font.
822  *
823  * This tag is used to declare an internal or external font definition.
824  * Internal fonts are composed of glyphs which happen to be shapes.
825  *
826  * This font (or a newer version) is required if you reference the font
827  * from an SWF_TAG_TEXT_FIELD tag.
828  *
829  * \sa SWF_TAG_DEFINE_FONT
830  * \sa SWF_TAG_DEFINE_FONT3
831  * \sa SWF_TAG_TEXT_FIELD
832  * \sa SWF_TAG_DEFINE_FONT_ALIGN_ZONES
833  * \sa SWF_TAG_CSM_TEXT_SETTINGS
834  * \sa <a href="../SWFalexref.html#tag_definefont2">SWF Alexis' Reference</a>
835  *
836  * <br>
837  * <br>
838  */
839 
840 
841 
842 /** \var sswf::TagBase::SWF_TAG_DEFINE_INFO
843  *
844  * \brief Put info in the file.
845  *
846  * This tag seems to be used by Macromedia Flash MX to insert some sort of
847  * a comment in the SWF movies. Do not use unless you know what you're doing!
848  *
849  * \sa <a href="../SWFalexref.html#tag_defineinfo">SWF Alexis' Reference</a>
850  *
851  * <br>
852  * <br>
853  */
854 
855 
856 
857 /** \var sswf::TagBase::SWF_TAG_TEXT_FIELD
858  *
859  * \brief Defines a field of editable text.
860  *
861  * This tag is used to create an edit box where end users can type text.
862  * You can specify the font, sizes, edit mode (it can even be read-only!)
863  *
864  * This can be used as a dynamic box to display a string to the user
865  * (i.e. an ActionScript can write a string in a text field.)
866  *
867  * \sa SWF_TAG_DEFINE_TEXT
868  * \sa SWF_TAG_DEFINE_TEXT2
869  * \sa SWF_TAG_DEFINE_FONT_INFO
870  * \sa SWF_TAG_DEFINE_FONT_INFO2
871  * \sa SWF_TAG_SET_TAB_INDEX
872  * \sa <a href="../SWFalexref.html#tag_defineedittext">SWF Alexis' Reference</a>
873  *
874  * <br>
875  * <br>
876  */
877 
878 
879 
880 /** \var sswf::TagBase::SWF_TAG_EXPORT
881  *
882  * \brief Make objects visible to the external world.
883  *
884  * This tag lists objects from this SWF movie that you want to be able to
885  * used from other SWF movies with the use of the SWF_TAG_IMPORT tag.
886  *
887  * \sa SWF_TAG_IMPORT
888  * \sa SWF_TAG_IMPORT2
889  * \sa <a href="../SWFalexref.html#tag_export">SWF Alexis' Reference</a>
890  *
891  * <br>
892  * <br>
893  */
894 
895 
896 
897 /** \var sswf::TagBase::SWF_TAG_IMPORT
898  *
899  * \brief Retrieve objects from another SWF movie.
900  *
901  * This tag lists the objects from another movie that this SWF movie is
902  * interested in. The resulting effect is as if these objects had been
903  * defined in this SWF movie. This tag can be used in movies version
904  * 5, 6 or 7. Since version 8, use must SWF_TAG_IMPORT2.
905  *
906  * \sa SWF_TAG_EXPORT
907  * \sa SWF_TAG_IMPORT2
908  * \sa <a href="../SWFalexref.html#tag_import">SWF Alexis' Reference</a>
909  *
910  * <br>
911  * <br>
912  */
913 
914 
915 
916 /** \var sswf::TagBase::SWF_TAG_PROTECT_DEBUG
917  *
918  * \brief Mark the animation as protected and include a password.
919  *
920  * This tag is used to add a password to your animation. This in effect
921  * protects the movie so you are the only one who can load it (and thus
922  * debug it.)
923  *
924  * This tag is only available in SWF version 5.
925  *
926  * \warning
927  * Of course, tools which ignore this tag will be capable of reading
928  * your entire animation since this is just one tag among others and
929  * it isn't used to decode the rest of the animation.
930  *
931  * \sa SWF_TAG_PROTECT
932  * \sa SWF_TAG_PROTECT_DEBUG2
933  * \sa <a href="../SWFalexref.html#tag_protectdebug">SWF Alexis' Reference</a>
934  *
935  * <br>
936  * <br>
937  */
938 
939 
940 
941 /** \var sswf::TagBase::SWF_TAG_DO_INIT_ACTION
942  *
943  * \brief Execute actions only once.
944  *
945  * This tag is like the SWF_TAG_DO_ACTION but it is executed at most
946  * once per session even when the display list loops through that tag
947  * over and over again.
948  *
949  * "It is often used to initialize a sprite"&mdash;which means that
950  * quite often it will be used to initialize an object class.
951  *
952  * Note that the tag is not part of the sprite. It references it.
953  *
954  * \sa SWF_TAG_DO_ACTION
955  * \sa SWF_TAG_ACTIONSCRIPT2
956  * \sa SWF_TAG_ACTIONSCRIPT2_DEFINE
957  * \sa SWF_TAG_ACTIONSCRIPT2_INSTANTIATE
958  * \sa <a href="../SWFalexref.html#tag_doinitaction">SWF Alexis' Reference</a>
959  *
960  * <br>
961  * <br>
962  */
963 
964 
965 
966 
967 
968 
969 
970 /** \var sswf::TagBase::SWF_TAG_DEFINE_FONT_INFO2
971  *
972  * \brief Defines a font including language specifications.
973  *
974  * This tag declares additional information about a font (i.e. use a corresponding
975  * system font name or a list of glyphs to declare an embedded font.)
976  *
977  * This is similar to the SWF_TAG_DEFINE_FONT_INFO plus the
978  * language support.
979  *
980  * \sa SWF_TAG_DEFINE_FONT_INFO
981  * \sa SWF_TAG_DEFINE_TEXT
982  * \sa SWF_TAG_TEXT_FIELD
983  * \sa <a href="../SWFalexref.html#tag_definefontinfo2">SWF Alexis' Reference</a>
984  *
985  * <br>
986  * <br>
987  */
988 
989 
990 
991 
992 
993 
994 /** \var sswf::TagBase::SWF_TAG_PROTECT_DEBUG2
995  *
996  * \brief Mark the animation as protected and include a password.
997  *
998  * This tag is used to add a password to your animation. This in effect
999  * protects the movie so you are the only one who can load it (and thus
1000  * debug it.)
1001  *
1002  * This tag is available since SWF version 6. It includes an additional
1003  * 2 bytes (compared to SWF_TAG_PROTECT_DEBUG) for what looks like a version
1004  * or a compression mode for the password.
1005  *
1006  * \warning
1007  * Of course, tools which ignore this tag will be capable of reading
1008  * your entire animation since this is just one tag among others and
1009  * it isn't used to decode the rest of the animation.
1010  *
1011  * \sa <a href="../SWFalexref.html#tag_protectdebug2">SWF Alexis' Reference</a>
1012  *
1013  * <br>
1014  * <br>
1015  */
1016 
1017 
1018 
1019 
1020 
1021 /** \var sswf::TagBase::SWF_TAG_SCRIPT_LIMITS
1022  *
1023  * \brief Define different limits for script execution.
1024  *
1025  * This tag is used to change script limits. For instance, it happens
1026  * that someone writes a loop which lasts forever (in computer world
1027  * this means more than one frame). This may be a problem when you are
1028  * trying to playback streaming sound, a realtime video and complex
1029  * animated sprites.
1030  *
1031  * The default is to stop these scritps after a small amount of time
1032  * elapsed. If that time is too small, then you can increase it with
1033  * this tag.
1034  *
1035  * \sa <a href="../SWFalexref.html#tag_scriptlimits">SWF Alexis' Reference</a>
1036  *
1037  * <br>
1038  * <br>
1039  */
1040 
1041 
1042 
1043 
1044 
1045 /** \var sswf::TagBase::SWF_TAG_SET_TAB_INDEX
1046  *
1047  * \brief Define the position or indices of each tab stops
1048  *
1049  * This tag is used in link with the HTML support of the SWF_TAG_TEXT_FIELD
1050  * tag.
1051  *
1052  * \sa SWF_TAG_TEXT_FIELD
1053  * \sa <a href="../SWFalexref.html#tag_settabindex">SWF Alexis' Reference</a>
1054  *
1055  * <br>
1056  * <br>
1057  */
1058 
1059 
1060 
1061 
1062 
1063 
1064 /** \var sswf::TagBase::SWF_TAG_FILE_ATTRIBUTES
1065  *
1066  * \brief Define some attributes in regard to the use of the file.
1067  *
1068  * This tag must be the very first after the header. It is used to make sure
1069  * that the player can support the movie. A set of flags are defined to
1070  * determine whether all the capabilities required by that movie can be met.
1071  *
1072  * The library hides this tag within the sswf::TagHeader object.
1073  *
1074  * \sa SWF_TAG_TEXT_FIELD
1075  * \sa <a href="../SWFalexref.html#tag_fileattributes">SWF Alexis' Reference</a>
1076  *
1077  * <br>
1078  * <br>
1079  */
1080 
1081 
1082 
1083 
1084 
1085 
1086 /** \var sswf::TagBase::SWF_TAG_PLACE_OBJECT3
1087  *
1088  * \brief Place or remove an object.
1089  *
1090  * This place object adds support for blend modes, filters and bitmap caching
1091  * which the SWF_TAG_PLACE_OBJECT2 does not support.
1092  *
1093  * It can be used inside a sprite.
1094  *
1095  * \sa SWF_TAG_PLACE_OBJECT
1096  * \sa SWF_TAG_PLACE_OBJECT2
1097  * \sa SWF_TAG_DEFINE_SPRITE
1098  * \sa <a href="../SWFalexref.html#tag_placeobject3">SWF Alexis' Reference</a>
1099  *
1100  * <br>
1101  * <br>
1102  */
1103 
1104 
1105 
1106 
1107 
1108 
1109 /** \var sswf::TagBase::SWF_TAG_IMPORT2
1110  *
1111  * \brief Retrieve objects from another SWF movie.
1112  *
1113  * This tag lists the objects from another movie that this SWF movie is
1114  * interested in. The resulting effect is as if these objects had been
1115  * defined in this SWF movie.
1116  *
1117  * Use this tag instead of SWF_TAG_IMPORT in a version 8 or newer of SWF.
1118  * You must use SWF_TAG_IMPORT for an animation version 5, 6 ot 7.
1119  *
1120  * \sa SWF_TAG_IMPORT
1121  * \sa SWF_TAG_EXPORT
1122  * \sa <a href="../SWFalexref.html#tag_import2">SWF Alexis' Reference</a>
1123  *
1124  * <br>
1125  * <br>
1126  */
1127 
1128 
1129 
1130 
1131 
1132 
1133 /** \var sswf::TagBase::SWF_TAG_DEFINE_FONT_ALIGN_ZONES
1134  *
1135  * \brief Define hints on how to align the glyphs of a font.
1136  *
1137  * This tag defines a few hints used to know how to place glyphs on the
1138  * screen. This is useful to avoid glyphs rendered on half pixels and
1139  * thus getting too blurry. This alignment definition is really only
1140  * partially useful for italic fonts.
1141  *
1142  * \sa SWF_TAG_DEFINE_FONT
1143  * \sa SWF_TAG_DEFINE_FONT2
1144  * \sa SWF_TAG_DEFINE_FONT3
1145  * \sa SWF_TAG_CSM_TEXT_SETTINGS
1146  * \sa <a href="../SWFalexref.html#tag_definefontalignzones">SWF Alexis' Reference</a>
1147  *
1148  * <br>
1149  * <br>
1150  */
1151 
1152 
1153 
1154 
1155 
1156 
1157 /** \var sswf::TagBase::SWF_TAG_CSM_TEXT_SETTINGS
1158  *
1159  * \brief Define hints on how to align and render the glyphs of a font.
1160  *
1161  * This tag defines a few hints used to know how to place glyphs on the
1162  * screen and which renderer to use to draw the font.
1163  *
1164  * Note that the selection of the mode is really poor since it gives you
1165  * a way to force CRT or LCD monitor but nothing dynamic...
1166  *
1167  * \sa SWF_TAG_DEFINE_FONT
1168  * \sa SWF_TAG_DEFINE_FONT2
1169  * \sa SWF_TAG_DEFINE_FONT3
1170  * \sa SWF_TAG_DEFINE_FONT_ALIGN_ZONES
1171  * \sa <a href="../SWFalexref.html#tag_csmtextsettings">SWF Alexis' Reference</a>
1172  *
1173  * <br>
1174  * <br>
1175  */
1176 
1177 
1178 
1179 
1180 
1181 
1182 /** \var sswf::TagBase::SWF_TAG_DEFINE_FONT3
1183  *
1184  * \brief Defines a set of glyphs in a font.
1185  *
1186  * This tag is used to declare an internal or external font definition.
1187  * Internal fonts are composed of glyphs which happen to be shapes.
1188  *
1189  * The main difference between this font definition and the
1190  * SWF_TAG_DEFINE_FONT2 is that sub-pixels have an extra 20 sub-divisions.
1191  *
1192  * \sa SWF_TAG_DEFINE_FONT
1193  * \sa SWF_TAG_DEFINE_FONT2
1194  * \sa SWF_TAG_DEFINE_FONT_ALIGN_ZONES
1195  * \sa SWF_TAG_CSM_TEXT_SETTINGS
1196  * \sa <a href="../SWFalexref.html#tag_definefont3">SWF Alexis' Reference</a>
1197  *
1198  * <br>
1199  * <br>
1200  */
1201 
1202 
1203 
1204 
1205 
1206 
1207 /** \var sswf::TagBase::SWF_TAG_METADATA
1208  *
1209  * \brief Defines humain readable information about the animation.
1210  *
1211  * This tag needs to be defined near the beginning of the movie and it includes
1212  * a set of humain readable strings saved in a string formatted using some XML.
1213  * The only purpose of this tag (at this time) is for search engines to reference
1214  * your animation properly without having to understand the complex format that
1215  * is SWF.
1216  *
1217  * \sa <a href="../SWFalexref.html#tag_metadata">SWF Alexis' Reference</a>
1218  *
1219  * <br>
1220  * <br>
1221  */
1222 
1223 
1224 
1225 
1226 
1227 
1228 /** \var sswf::TagBase::SWF_TAG_DEFINE_SCALING_GRID
1229  *
1230  * \brief Defines a grid used to resize an object.
1231  *
1232  * This tag defines a rectangle within the specified shape which is fully resized.
1233  * The top and bottom edges are only stretched horizontally; the left and right edges
1234  * are only stretched vertically; the corners are never resized.
1235  *
1236  * This is quite used by sswf::TagButton and sswf::TagSprite.
1237  *
1238  * \sa SWF_TAG_DEFINE_BUTTON
1239  * \sa SWF_TAG_DEFINE_BUTTON2
1240  * \sa sswf::TagButton
1241  * \sa SWF_TAG_DEFINE_SPRITE
1242  * \sa sswf::TagSprite
1243  * \sa <a href="../SWFalexref.html#tag_definescalinggrid">SWF Alexis' Reference</a>
1244  *
1245  * <br>
1246  * <br>
1247  */
1248 
1249 
1250 
1251 
1252 
1253 /** \var sswf::TagBase::SWF_TAG_DEFINE_SHAPE4
1254  *
1255  * \brief Defines a shape with enhanced strokes
1256  *
1257  * This shape is similar to all the previous shapes plus it lets you
1258  * choose which stroke to use. You can select how the strokes are
1259  * rendered and whether they follow the scaling factor.
1260  *
1261  * \sa SWF_TAG_DEFINE_SHAPE
1262  * \sa SWF_TAG_DEFINE_SHAPE2
1263  * \sa SWF_TAG_DEFINE_SHAPE3
1264  * \sa SWF_TAG_DEFINE_MORPH_SHAPE
1265  * \sa SWF_TAG_DEFINE_MORPH_SHAPE2
1266  * \sa <a href="../SWFalexref.html#tag_defineshape4">SWF Alexis' Reference</a>
1267  *
1268  * <br>
1269  * <br>
1270  */
1271 
1272 
1273 
1274 
1275 
1276 
1277 /** \var sswf::TagBase::SWF_TAG_DEFINE_MORPH_SHAPE2
1278  *
1279  * \brief Defines a morphing shape with enhanced strokes
1280  *
1281  * This morphing shape is similar to SWF_TAG_DEFINE_MORPH_SHAPE but
1282  * it also support a way for the user to choose which stroke to use.
1283  *
1284  * \sa SWF_TAG_DEFINE_SHAPE
1285  * \sa SWF_TAG_DEFINE_SHAPE2
1286  * \sa SWF_TAG_DEFINE_SHAPE3
1287  * \sa SWF_TAG_DEFINE_SHAPE4
1288  * \sa SWF_TAG_DEFINE_MORPH_SHAPE
1289  * \sa <a href="../SWFalexref.html#tag_definemorphshape2">SWF Alexis' Reference</a>
1290  *
1291  * <br>
1292  * <br>
1293  */
1294 
1295 
1296 
1297 
1298 
1299 
1300 /** \var sswf::TagBase::SWF_TAG_ACTIONSCRIPT2
1301  *
1302  * \brief Defines a block of ActionScript version 2
1303  *
1304  * This tag defines a list of actions to be executed. This is similar to
1305  * the SWF_TAG_DOACTION except that it supports a really object oriented
1306  * definition set.
1307  *
1308  * \sa SWF_TAG_DOACTION
1309  * \sa <a href="../SWFalexref.html#tag_doabc">SWF Alexis' Reference</a>
1310  *
1311  * <br>
1312  * <br>
1313  */
1314 
1315 
1316 
1317 
1318 /** \var sswf::TagBase::SWF_TAG_ACTIONSCRIPT2_INSTANTIATE
1319  *
1320  * \brief Instantiate objects from a previously defined ActionScript version 2 block
1321  *
1322  * This tag defines a list of objects to create. The objects are defined in the
1323  * SWF_TAG_ACTIONSCRIPT2_DEFINE referenced by this tag.
1324  *
1325  * \sa SWF_TAG_ACTIONSCRIPT2_DEFINE
1326  * \sa <a href="../SWFalexref.html#tag_symbolclass">SWF Alexis' Reference</a>
1327  *
1328  * <br>
1329  * <br>
1330  */
1331 
1332 
1333 
1334 
1335 /** \var sswf::TagBase::SWF_TAG_ACTIONSCRIPT2_DEFINE
1336  *
1337  * \brief Create an ActionScript version 2 which can later be referenced
1338  *
1339  * This tag defines a list of classes to instantiate later with the use of an
1340  * SWF_TAG_ACTIONSCRIPT2_INSTANTIATE.
1341  *
1342  * \sa SWF_TAG_ACTIONSCRIPT2_INSTANTIATE
1343  * \sa <a href="../SWFalexref.html#tag_doabcdefine">SWF Alexis' Reference</a>
1344  *
1345  * <br>
1346  * <br>
1347  */
1348 
1349 
1350 
1351 
1352 /** \var sswf::TagBase::SWF_TAG_SCENE_FRAME_DATA
1353  *
1354  * \brief Define raw data for a scene and frame.
1355  *
1356  * This tag defines raw data usable by a scene and frame.
1357  *
1358  * \sa SWF_TAG_DEFINE_BINARY_DATA
1359  * \sa <a href="../SWFalexref.html#tag_definesceneandframedata">SWF Alexis' Reference</a>
1360  *
1361  * <br>
1362  * <br>
1363  */
1364 
1365 
1366 
1367 
1368 /** \var sswf::TagBase::SWF_TAG_DEFINE_BINARY_DATA
1369  *
1370  * \brief Define binary data a script can use later.
1371  *
1372  * This tag defines some user defined binary data.
1373  *
1374  * \sa SWF_TAG_SCENE_FRAME_DATA
1375  * \sa <a href="../SWFalexref.html#tag_definebinarydata">SWF Alexis' Reference</a>
1376  *
1377  * <br>
1378  * <br>
1379  */
1380 
1381 
1382 
1383 
1384 
1385 /** \var sswf::TagBase::SWF_TAG_DEFINE_FONT_NAME
1386  *
1387  * \brief Define the name and copyright of a font.
1388  *
1389  * This tag defines the legal name and copyright of an embedded font.
1390  *
1391  * \sa SWF_TAG_DEFINE_FONT
1392  * \sa SWF_TAG_DEFINE_FONT2
1393  * \sa SWF_TAG_DEFINE_FONT3
1394  * \sa SWF_TAG_DEFINE_FONT_INFO
1395  * \sa SWF_TAG_DEFINE_FONT_INFO2
1396  * \sa <a href="../SWFalexref.html#tag_definebinarydata">SWF Alexis' Reference</a>
1397  *
1398  * <br>
1399  * <br>
1400  */
1401 
1402 
1403 
1404 
1405 
1406 
1407 /** \var sswf::TagBase::SWF_TAG_max
1408  *
1409  * \brief Mark the end of the list of tags.
1410  *
1411  * No tag is defined beyond this point, SWF_TAG_max included, in what the SSWF
1412  * library supports. Also, new tags may be created by Macromedia beyond this point
1413  * before SSWF is updated.
1414  *
1415  * This can be used for a rather weak test to know whether a tag number is valid.
1416  * It is a weak test since many values between 0 and SWF_TAG_max are not defined.
1417  */
1418 
1419 
1420 
1421 
1422 
1423 
1424 
1425 
1426 
1427 /** \brief Initialize the base information of a tag
1428  *
1429  * Each tag needs to have a name. The name is actually the type of the
1430  * tag and not a user name. This is enforced by all the derived tags
1431  * (i.e. the users of the library cannot themselves define this name.)
1432  *
1433  * The parent can be set to NULL (especially if you are creating the
1434  * TagHeader object). Otherwise it needs to be a tag which supports
1435  * having children (i.e. TagHeader or TagSprite).
1436  *
1437  * \note
1438  * It is possible to add a TagEnd which is not at the very end of
1439  * the movie. This is useful in order to test the movie up to that
1440  * point.
1441  *
1442  * \bug
1443  * When creating a child (i.e. the parent pointer is not null) the
1444  * new child is linked at the end of the existing list of children.
1445  * At this time, there is no way to change the order of children
1446  * other than creating a new parent and add all the children in the
1447  * new order...
1448  *
1449  * The parent is now given a chance to reject a child. When that
1450  * happens, the constructor \e returns \e normally, but the new
1451  * tag is not becoming a child of the specified parent. You can
1452  * test this with the following line of code:
1453  *
1454  * \code
1455  *	if(sswf::TagBase::Parent() != parent) ... // oops!
1456  * \endcode
1457  *
1458  * \param name The type of the tag in the form of a string
1459  * \param parent The parent tag (a header or a sprite)
1460  */
TagBase(const char * name,TagBase * parent)1461 TagBase::TagBase(const char *name, TagBase *parent)
1462 {
1463 	register TagBase		*tail;
1464 	ErrorManager::error_code_t	err;
1465 
1466 	if(parent != 0) {
1467 		err = parent->OnNewChild(name);
1468 		if(err != ErrorManager::ERROR_CODE_NONE) {
1469 			// that parent did not accept this child
1470 			OnError(err, "the parent tag \"%s\" did not accept the child \"%s\"", parent->Name(), name);
1471 			parent = 0;
1472 		}
1473 	}
1474 
1475 	f_userdata = 0;		// by default we initialize to zero
1476 
1477 	f_name = name;
1478 	f_label = 0;		// no label by default, use SetLabel() to set it
1479 
1480 	f_parent = parent;
1481 	f_next = 0;
1482 	f_previous = 0;
1483 	f_children = 0;
1484 
1485 	f_frames = 0;		// should be reset each time it is to be used!
1486 
1487 	// link into the parent if there is one
1488 	if(parent != 0) {
1489 		// the order is VERY important so we HAVE to
1490 		// link at the end of the list
1491 		tail = parent->f_children;
1492 		if(tail == 0) {
1493 			parent->f_children = this;
1494 		}
1495 		else {
1496 			while(tail->f_next != 0) {
1497 				tail = tail->f_next;
1498 			}
1499 			// NOTE: if(tail->f_name == 'end') error?
1500 			// at this time, we let people add tags after the end...
1501 			f_previous = tail;
1502 			tail->f_next = this;
1503 		}
1504 	}
1505 }
1506 
1507 
1508 /** \brief Clean up the base information of a tag
1509  *
1510  * This function takes care of deleting all the children
1511  * of a tag and unlinking the tag from its sibling and/or
1512  * parent.
1513  */
~TagBase()1514 TagBase::~TagBase()
1515 {
1516 	// if we are being deleted, we ought to delete our children
1517 	// (we may change that at a later time, but it seems as if it were a valid argument right now)
1518 	while(f_children != 0) {
1519 #if DEBUG
1520 #if 0
1521 // IsBuffer() isn't a valid function at this time
1522 fprintf(stderr, "Delete child [%s] [%s] (%d)\n",
1523 				f_children->f_name,
1524 				f_children->f_label == 0 ? "<no label>" : f_children->f_label,
1525 				Buffer::IsBuffer(f_children));
1526 		assert(Buffer::IsBuffer(f_children) == 0, "a tag object can't be attached to another object (name: \"%s\", label: \"%s\")",
1527 				f_children->f_name,
1528 				f_children->f_label == 0 ? "<no label>" : f_children->f_label);
1529 #endif
1530 #endif
1531 		delete f_children;
1532 	}
1533 
1534 	if(f_previous == 0) {
1535 		if(f_parent != 0) {
1536 			f_parent->f_children = f_next;
1537 		}
1538 	}
1539 	else {
1540 		f_previous->f_next = f_next;
1541 	}
1542 	if(f_next != 0) {
1543 		f_next->f_previous = f_previous;
1544 	}
1545 }
1546 
1547 
1548 /** \brief Check the validity of this child for a parent tag
1549  *
1550  * Whenever a tag is added as a child to another tag, the parent has
1551  * a chance to tell whether it accepts the child.
1552  *
1553  * For instance, a sswf::TagHeader cannot be a child of any other tag.
1554  *
1555  * The sswf::TagSprite also only accept a small set of the control
1556  * tags.
1557  *
1558  * \warning
1559  * This function is called from the constructor and thus it cannot
1560  * use any virtual function on the child. This is why you only
1561  * receive the name of the child and not a pointer to it.
1562  *
1563  * \sa sswf::TagHeader::OnNewChild(const char *child)
1564  * \sa sswf::TagSprite::OnNewChild(const char *child)
1565  */
OnNewChild(const char * child_name) const1566 ErrorManager::error_code_t TagBase::OnNewChild(const char *child_name) const
1567 {
1568 	// by default no children allowed in tags
1569 	return ErrorManager::ERROR_CODE_CHILDREN_NOT_SUPPORTED;
1570 }
1571 
1572 
1573 
1574 
1575 /** \fn TagBase::Save(Data& data)
1576  *
1577  * \brief Pre-save all the children tags of this tag.
1578  *
1579  * The Save() function is the one you want to call to save
1580  * an SWF movie.
1581  *
1582  * You may use the Save() on any tag, however, if you do so
1583  * you need to properly initialize the system. For that
1584  * purpose, you may want to look at the code in the
1585  * TagHeader::Save(Data& data) function.
1586  *
1587  * Otherwise, you simply have to call the Save() function of
1588  * the TagHeader. That will save the entire movie with the
1589  * smallest possible version (or fail if something cannot be
1590  * saved with the present parameters.)
1591  *
1592  * The TagHeader::Save() function first calls the PreSave()
1593  * functions, the PreSave2ndPass() and then the Save() functions
1594  * of all the children.
1595  *
1596  * The other tag Save() function simply save the tag within the
1597  * specified Data buffer. Note however that the TagSprite will
1598  * also call the Save() function of all of its children. Yet it
1599  * does not call the PreSave() functions.
1600  *
1601  * The Save() function saves the movie in a Data buffer. Later
1602  * you need to save that buffer on disk or some other medium.
1603  *
1604  * \return Zero when the Save() succeeds, non-zero if it fails
1605  *
1606  * \sa TagBase::PreSave()
1607  * \sa TagBase::PreSave2ndPass()
1608  */
1609 
1610 /** \brief Pre-save all the children tags of this tag.
1611  *
1612  * This function calls the PreSave() function of all
1613  * the children unless one returns a non-zero value
1614  * in which case that value will be returned and the
1615  * process stopped.
1616  *
1617  * This function is aumatically called by the TagHeader
1618  * and TagSprite in order to pre-save their children.
1619  *
1620  * The PreSave() functions are expected to be used to
1621  * test whether a tag can be saved. Especially, most
1622  * tags will call the MinimumVersion() function with
1623  * the version required to save these tags. This
1624  * ensures that you can save the entire movie in a
1625  * valid SWF. Please, see the reference of each tag
1626  * for more information about what their PreSave()
1627  * function does.
1628  *
1629  * You should not have to call this function directly.
1630  *
1631  * \result Zero if the PreSave() succeeds; non-zero otherwise
1632  */
PreSave(void)1633 ErrorManager::error_code_t TagBase::PreSave(void)
1634 {
1635 	TagBase				*p;
1636 	ErrorManager::error_code_t	ec;
1637 
1638 //printf("--- PreSave %p (%s)\n", this, Name());
1639 
1640 	/*
1641 	 * By default we simply call the PreSave() of
1642 	 * every child in this object
1643 	 *
1644 	 * Objects can overload this function and do their own
1645 	 * PreSave() tests.
1646 	 */
1647 	p = Children();
1648 	while(p != 0) {
1649 		ec = p->PreSave();
1650 		if(ec != ErrorManager::ERROR_CODE_NONE) {
1651 			return ec;
1652 		}
1653 		p = p->Next();
1654 	}
1655 
1656 	return ErrorManager::ERROR_CODE_NONE;
1657 }
1658 
1659 
1660 
1661 /** \brief Pre-save all the children tags of this tag.
1662  *
1663  * The PreSave2ndPass() is the same as the PreSave()
1664  * function for the TagBase(). It calls the PreSave2ndPass()
1665  * of all the children unless one returns a non-zero value
1666  * in which case the process stops and that value is returned.
1667  *
1668  * The second pass is used to check more information about the
1669  * tag and prepare data such as tables. This is especially
1670  * necessary for the TagFont which needs to create all the
1671  * character tables to know the offsets to characters, etc.
1672  * This is important because that tag may be accessed before
1673  * its Save() function is called and it would still need to
1674  * know where these characters are!
1675  *
1676  * \return Zero when the PreSave2ndPass() successed; non-zero otherwise
1677  */
PreSave2ndPass(void)1678 ErrorManager::error_code_t TagBase::PreSave2ndPass(void)
1679 {
1680 	TagBase				*p;
1681 	ErrorManager::error_code_t	ec;
1682 
1683 //printf("--- PreSave2ndPass %p (%s)\n", this, Name());
1684 
1685 	/*
1686 	 * By default we simply call the PreSave2ndPass() of
1687 	 * every child in this object
1688 	 */
1689 	p = Children();
1690 	while(p != 0) {
1691 		ec = p->PreSave2ndPass();
1692 		if(ec != 0) {
1693 			return ec;
1694 		}
1695 		p = p->Next();
1696 	}
1697 
1698 	return ErrorManager::ERROR_CODE_NONE;
1699 }
1700 
1701 
1702 /** \brief Save a C string in a Data buffer
1703  *
1704  * Save a C string in the specified Data buffer. This is
1705  * a simple process since you just have to save the string
1706  * and then add a null terminator. However, in movies prior
1707  * version 6, you need to convert the string to some locale
1708  * encoding specified by the user. This is done transparently
1709  * whenever this function is called.
1710  *
1711  * This function calls the TagHeader::SaveEncodedString()
1712  * function. Note that the function will fail if the tag was
1713  * not created in a TagHeader.
1714  *
1715  * \return The length of the string not including the null terminator
1716  * or -1 when an error occured
1717  *
1718  * \sa TagHeader::SaveEncodedString(Data& data, const char *string)
1719  */
SaveString(Data & data,const char * string)1720 ErrorManager::error_code_t TagBase::SaveString(Data& data, const char *string)
1721 {
1722 	TagHeader *header = Header();
1723 	if(header != 0) {
1724 		return header->SaveEncodedString(data, string);
1725 	}
1726 	return ErrorManager::ERROR_CODE_NO_HEADER;
1727 }
1728 
1729 
1730 
1731 /** \brief Frame number of this tag
1732  *
1733  * All tags are saved between TagShowFrame tags. The number of
1734  * TagShowFrame before a tag, not including the current tag,
1735  * determines the frame number of that tag.
1736  *
1737  * This function will count the number of TagShowFrame before
1738  * 'this' tag. This number is used in different actions to be
1739  * able to select the frame to go to, which needs to be loaded, etc.
1740  *
1741  * The tag needs to have a Header or a Sprite as a parent for
1742  * this function to work.
1743  *
1744  * \return The frame on which this tag is defined
1745  */
WhichFrame(void) const1746 sswf_frame_t TagBase::WhichFrame(void) const
1747 {
1748 	sswf_frame_t	result;
1749 	const TagBase	*p;
1750 
1751 	if(strcmp(f_name, "header") == 0 || f_parent == 0) {
1752 		/* there can't really be a frame in a header tag!!! */
1753 		return 0;
1754 	}
1755 
1756 	if(strcmp(f_parent->f_name, "header") != 0 && strcmp(f_parent->f_name, "sprite") != 0) {
1757 		/* at this time other possible cases aren't supported... */
1758 		return 0;
1759 	}
1760 
1761 	result = 0;
1762 	p = this->f_previous;	/* start with the previous since we don't want to include the current ShowFrame */
1763 	while(p != 0) {
1764 		if(strcmp(p->f_name, "showframe") == 0) {
1765 			result++;
1766 		}
1767 		p = p->f_previous;
1768 	}
1769 
1770 	return result;
1771 }
1772 
1773 
1774 /** \brief Name the tag (user name, internal)
1775  *
1776  * Each tag can receive a name. This is used on tags which need
1777  * to be found later. Mainly, tags which an action script needs
1778  * to access.
1779  *
1780  * This name is NOT saved in the final output. It is only a
1781  * convenience of the SSWF library. Some tags accept a name
1782  * which will be saved in the SSWF library.
1783  *
1784  * A label name will often be used so you can later search for a
1785  * tag to go to from within an action script.
1786  *
1787  * \note The name can be specified in UTF-8 or any other format. This
1788  * is specific to your code.
1789  *
1790  * \param label The name of this tag
1791  *
1792  * \bug The system does not search the existing tree to know whether
1793  * the specified label is already in use (for speed reasons). It is
1794  * expected that the developer using the SSWF library knows how to
1795  * avoid reusing the same name.
1796  *
1797  * That developer can test whether the name is already in use by calling
1798  * the FindLabel() function first. If it returns a non-null pointer,
1799  * then the specified label is already in use.
1800  *
1801  * If the developer has a sorted array with all the names, it will be
1802  * a lot faster to search than the tree of tags!
1803  *
1804  * \sa TagPlace::SetName(const char *name)
1805  * \sa TagBase::FindLabel(const TagBase *p, const char *label)
1806  * \sa TagBase::FindLabelledTag(const char *label) const
1807  */
SetLabel(const char * label)1808 void TagBase::SetLabel(const char *label)
1809 {
1810 	MemFree(f_label);
1811 	f_label = StrDup(label);
1812 }
1813 
1814 
1815 /** \brief Return the label of a tag
1816  *
1817  * The label of a tag is a user specified name.
1818  * It can be anything and it is set using
1819  * TagBase::SetLabel(const char *label).
1820  *
1821  * \return A pointer to the label.
1822  *
1823  * \bug The pointer returned is the copy kept by the object. DO NOT MODIFY IT!
1824  */
Label(void) const1825 const char *TagBase::Label(void) const
1826 {
1827 	return f_label;
1828 }
1829 
1830 
1831 /** \brief Find the tag with the specified user name
1832  *
1833  * This function is used to search a tag using the label set using
1834  * the SetLabel(const char *label) function.
1835  *
1836  * All the siblings of the specified tag are search as well as all the
1837  * children. The pointer of the first object with the same name is
1838  * returned.
1839  *
1840  * The search first check if the first object in the specified tree
1841  * matches. If not, then its children are searched. If none of its
1842  * children are searched then the next object is checked. Usually,
1843  * the pointer to you TagHeader is used.
1844  *
1845  * \param p A pointer to a tag, usually the Header()
1846  * \param label The label to search for
1847  *
1848  * \return A pointer to the tag with the specified label or NULL
1849  *
1850  * \bug This function is slow.
1851  *
1852  * \sa TagBase::SetLabel(const char *label)
1853  * \sa TagBase::FindLabelledTag(const char *label) const
1854  */
FindLabel(const TagBase * p,const char * label) const1855 TagBase *TagBase::FindLabel(const TagBase *p, const char *label) const
1856 {
1857 	const TagBase		*n;
1858 
1859 	while(p->f_previous != 0) {	// should always be false!
1860 		p = p->f_previous;
1861 	}
1862 	while(p != 0) {
1863 		if(p->f_label != 0 && strcmp(p->f_label, label) == 0) {
1864 			return const_cast<TagBase *>(p);
1865 		}
1866 		if(p->f_children != 0) {
1867 			n = FindLabel(p->f_children, label);
1868 			if(n != 0) {
1869 				return const_cast<TagBase *>(n);
1870 			}
1871 		}
1872 		p = p->f_next;
1873 	}
1874 
1875 	return 0;
1876 }
1877 
1878 
1879 /** \brief Find a tag in the entire tree
1880  *
1881  * This function is the same as the
1882  * sswf::TagBase::FindLabel(const TagBase *p, const char *label) const
1883  * but it will always start the search from the Header() tag.
1884  *
1885  * If the label is set to NULL or the empty string, then the
1886  * root tag is returned (i.e. the Header() tag).
1887  *
1888  * \param label The label to search for
1889  *
1890  * \return A pointer to the tag with the specified label or NULL
1891  *
1892  * \sa sswf::TagBase::FindLabel(const TagBase *p, const char *label) const
1893  * \sa sswf::TagBase::SetLabel(const char *label)
1894  */
FindLabelledTag(const char * label) const1895 TagBase *TagBase::FindLabelledTag(const char *label) const
1896 {
1897 	// this search looks in the entire tree available
1898 	const TagBase		*p;
1899 
1900 	// start searching from the root tag
1901 	p = this;
1902 	if(p == 0) {
1903 		// happens when 'this' is still a null pointer!
1904 		return 0;
1905 	}
1906 	while(p->f_parent != 0) {
1907 		p = p->f_parent;
1908 	}
1909 
1910 	if(label == 0 || label[0] == '\0') {
1911 		// return the root in this case
1912 		return const_cast<TagBase *>(p);
1913 	}
1914 
1915 	return FindLabel(p, label);
1916 }
1917 
1918 
1919 /** \brief Find a tag using its identifier
1920  *
1921  * Search the tree for a tag with the specified identifier.
1922  *
1923  * This function searches for the first tag in the specified
1924  * list. It then tests that tag with the specified identifier.
1925  * If it matches, it returns that object. Otherwise it will
1926  * check all the children of that object. If one of the child
1927  * matches, then that child is returned. Otherwise the next
1928  * tag is tested.
1929  *
1930  * Each object is expected to have a unique identifier within
1931  * a single movie. This is enforced by the automatic assignment
1932  * of identifiers at the time a TagBaseID is created.
1933  *
1934  * Note that a tag which has no identifier will never be returned
1935  * by this function.
1936  *
1937  * \note A valid identifier cannot be zero or have bit 15 set.
1938  *
1939  * \param p Start with the siblings of this tag
1940  * \param id The identifier to search for
1941  * \param search_import Whether to search within TagImport tags
1942  *
1943  * \return The pointer of the tag with the specified identifier or NULL
1944  *
1945  * \sa TagBase::FindLabel(const TagBase *p, const char *label)
1946  * \sa TagBase::FindLabelledTag(const char *label) const
1947  * \sa TagBase::FindTagWithID(sswf_id_t id, bool search_import) const
1948  */
FindID(const TagBase * p,sswf_id_t id,bool search_import) const1949 TagBase *TagBase::FindID(const TagBase *p, sswf_id_t id, bool search_import) const
1950 {
1951 	const TagBase		*n;
1952 	const TagBaseID		*tag_id;
1953 
1954 	if(p == 0 || id == SSWF_ID_NONE) {
1955 		return 0;
1956 	}
1957 
1958 	while(p->f_previous != 0) {	// should always be false!
1959 		p = p->f_previous;
1960 	}
1961 	// search this level first
1962 	while(p != 0) {
1963 		if((p->TypeFlags() & SWF_TYPE_HAS_ID) != 0) {
1964 			// some additional protection, just in case!
1965 			// it is easy to make a mistake and put the wrong flag somewhere
1966 			tag_id = dynamic_cast<const TagBaseID *>(p);
1967 			assert(tag_id != 0, "A tag with SWF_TYPE_HAS_ID is not derived from TagBaseID");
1968 			if(tag_id && tag_id->HasIdentification()) {
1969 				return const_cast<TagBase *>(p);
1970 			}
1971 		}
1972 		else if(search_import && strcmp(p->Name(), "import") == 0) {
1973 			// import objects can offer multiple IDs
1974 			if(dynamic_cast<const TagImport *>(p)->HasID(id) != 0) {
1975 				return const_cast<TagBase *>(p);
1976 			}
1977 		}
1978 		if(p->f_children != 0) {
1979 			n = FindID(p->f_children, id, search_import);
1980 			if(n != 0) {
1981 				return const_cast<TagBase *>(n);
1982 			}
1983 		}
1984 		p = p->f_next;
1985 	}
1986 
1987 	return 0;
1988 }
1989 
1990 
1991 /** \brief Find a tag anywhere in the tree using its identifier
1992  *
1993  * Search the entire tree for a tag with the specified
1994  * identifier.
1995  *
1996  * This function calls
1997  * TagBase::FindID(const TagBase *p, sswf_id_t id, bool search_import) const
1998  * with the Header() as the starting point tag.
1999  *
2000  * Note that the header has no identifier and thus the header
2001  * will never be returned.
2002  *
2003  * \note A valid identifier cannot be zero or have bit 15 set.
2004  *
2005  * \param id The identifier to search for
2006  * \param search_import Whether to search within TagImport tags
2007  *
2008  * \return The pointer of the tag with the specified identifier or NULL
2009  *
2010  * \sa TagBase::FindLabel(const TagBase *p, const char *label)
2011  * \sa TagBase::FindLabelledTag(const char *label) const
2012  * \sa TagBase::FindID(const TagBase *p, sswf_id_t id, bool search_import) const
2013  */
FindTagWithID(sswf_id_t id,bool search_import) const2014 TagBase *TagBase::FindTagWithID(sswf_id_t id, bool search_import) const
2015 {
2016 	// this search looks in the entire tree available
2017 	const TagBase		*p;
2018 
2019 	// start searching from the root tag
2020 	p = this;
2021 	if(p == 0) {
2022 		return 0;		// works when this is still a nul pointer!
2023 	}
2024 	while(p->f_parent != 0) {
2025 		p = p->f_parent;
2026 	}
2027 
2028 	return FindID(p, id, search_import);
2029 }
2030 
2031 
2032 /** \brief Save a tag in the specified Data buffer
2033  *
2034  * This function generates a tag header given a tag and
2035  * a size. It knows how to handle small (63 bytes or less)
2036  * tags and large (64 or more) tags.
2037  *
2038  * \note
2039  * The main problem is that you need to know the size of
2040  * the tag at the time you call this function and the
2041  * data of the tag have come after.
2042  *
2043  * In most cases, this is handled by first saving all the
2044  * data in a separate buffer, get the size of that buffer,
2045  * create the tag and then copy the separate buffer in this
2046  * Data buffer.
2047  *
2048  * \param data The buffer where the tag is to be saved
2049  * \param tag The SWF tag to save
2050  * \param size The size of the tag
2051  *
2052  * \bug This function has no concept of the tag being saved
2053  * and thus it does not check the validity of the tag nor
2054  * of the size for that tag.
2055  *
2056  * \sa TagBase::SaveString(Data& data, const char *string)
2057  */
SaveTag(Data & data,swf_tag_t tag,size_t size)2058 int TagBase::SaveTag(Data& data, swf_tag_t tag, size_t size)
2059 {
2060 	// large tag?
2061 	//
2062 	// Note that Macromedia documented the fact that certain
2063 	// tags just cannot be saved with a small tag. These are
2064 	// tested here. This information is quite well hidden!!!
2065 	// If you look at their docs, it says:
2066 	//
2067 	//		RECORDHEADER (long)
2068 	//
2069 	// Well... until version 1.8.0 I had not noticed and
2070 	// the other day, when I created very small Lossless images
2071 	// it did not want to work!!!
2072 	if(size >= 63
2073 	|| tag == SWF_TAG_DEFINE_BITS_LOSSLESS
2074 	|| tag == SWF_TAG_DEFINE_BITS_LOSSLESS2
2075 	|| tag == SWF_TAG_DEFINE_BITS_JPEG
2076 	|| tag == SWF_TAG_DEFINE_BITS_JPEG2
2077 	|| tag == SWF_TAG_DEFINE_BITS_JPEG3
2078 	|| tag == SWF_TAG_SOUND_STREAM_BLOCK
2079 	) {
2080 		data.PutShort((tag << 6) + 63);
2081 		data.PutLong(size);
2082 	}
2083 	else {
2084 		data.PutShort((tag << 6) + size);
2085 	}
2086 
2087 	return 0;
2088 }
2089 
2090 
2091 
2092 
2093 /** \brief Number of bits necessary to save the specified signed value
2094  *
2095  * This function counts the number of bits necessary to save the
2096  * specified signed value in a bit field.
2097  *
2098  * This is used by many tags to know what size to use to save
2099  * a set of values such as the coordinates of a rectangle.
2100  *
2101  * The input value is expected to be signed and thus a value such
2102  * as -1 will get a size of 1 and not 32.
2103  *
2104  * \param value The signed value of which the number of bits is to be
2105  * computed
2106  *
2107  * \return The number of bits required to save that value
2108  *
2109  * \sa TagBase::UIBitSize(unsigned long value)
2110  */
SIBitSize(long value)2111 long TagBase::SIBitSize(long value)
2112 {
2113 	long	cnt;
2114 
2115 	// fix by Adam Polkosnik who has a 64 bit processor
2116 	if(value < 0) {
2117 		value = ~value;
2118 	}
2119 
2120 	cnt = 1;
2121 	while(value > 0) {
2122 		cnt++;
2123 		value /= 2;
2124 	}
2125 
2126 	return cnt;
2127 }
2128 
2129 
2130 /** \brief Number of bits necessary to save the specified unsigned value
2131  *
2132  * This function counts the number of bits necessary to save the
2133  * specified unsigned value in a bit field.
2134  *
2135  * This is used by many tags to know what size to use to save
2136  * a set of values such as the coordinates of a rectangle.
2137  *
2138  * The input value is expected to not be signed and thus a value such
2139  * as -1 will get a size of 32.
2140  *
2141  * \param value The unsigned value of which the number of bits is to be
2142  * computed
2143  *
2144  * \return The number of bits required to save that value
2145  *
2146  * \sa TagBase::SIBitSize(long value)
2147  */
UIBitSize(unsigned long value)2148 long TagBase::UIBitSize(unsigned long value)
2149 {
2150 	long	cnt;
2151 
2152 	// fix by Adam Polkosnik who has a 64 bit processor
2153 	cnt = 0;
2154 	do {
2155 		cnt++;
2156 		value /= 2;
2157 	} while(value > 0);
2158 
2159 	return cnt;
2160 }
2161 
2162 
2163 /** \brief Converts a double to a 16 bits fixed number
2164  *
2165  * This function converts a double to a fixed number defined on 16
2166  * bits (i.e. 8 bits before and 8 bits after the decimal point.)
2167  *
2168  * This function clamps the value between -32768 and +32767.
2169  *
2170  * \param value The double to convert to a fixed number of 16 bits
2171  *
2172  * \return A signed fixed number of 16 bits (8.8 fixed point)
2173  *
2174  * \sa TagBase::Double2Signed(double value)
2175  * \sa TagBase::Signed2Double(long value)
2176  */
Double2Signed16(double value)2177 long TagBase::Double2Signed16(double value)
2178 {
2179 	long		r;
2180 
2181 	r = (long) rint(value * 256.0);
2182 
2183 	/* clamp the result */
2184 	if(r < (short) 0x8000) {
2185 		return (short) 0x8000;
2186 	}
2187 	if(r > (short) 0x7FFF) {
2188 		return (short) 0x7FFF;
2189 	}
2190 	return r;
2191 }
2192 
2193 
2194 /** \brief Converts a double to a 32 bits fixed number
2195  *
2196  * This function converts a double to a fixed number defined on 32
2197  * bits.
2198  *
2199  * Note that at this time the function does not test for overflow
2200  * or underflow errors.
2201  *
2202  * \param value The double to convert to a fixed number of 32 bits
2203  *
2204  * \return Fixed number of 32 bits (16.16 fixed point)
2205  *
2206  * \sa TagBase::Double2Signed16(double value)
2207  * \sa TagBase::Signed2Double(long value)
2208  */
Double2Signed(double value)2209 long TagBase::Double2Signed(double value)
2210 {
2211 	// assert(?, "overflow"); -- should we otherwise have a bound checking mechanism
2212 	return (long) rint(value * 65536.0);
2213 }
2214 
2215 
2216 /** \brief Converts a 32 bits fixed number to a double
2217  *
2218  * This function converts a fixed number defined on 32 bits to
2219  * a double.
2220  *
2221  * \param value The fixed 32 bits fixed number to convert to a double
2222  *
2223  * \return The double representation
2224  *
2225  * \sa TagBase::Double2Signed(long value)
2226  */
Signed2Double(long value)2227 double TagBase::Signed2Double(long value)
2228 {
2229 	return (double) value / 65536.0;
2230 }
2231 
2232 
2233 /** \brief Called automatically each time a TagShowFrame is saved
2234  *
2235  * This function is automatically called each time a TagShowFrame
2236  * is saved in the output movie. This is used to know the total
2237  * number of frames saved in a movie and add that information to
2238  * the TagHeader.
2239  *
2240  * \sa TagShowFrame::Save(Data& data)
2241  * \sa TagBase::ResetFrames(void)
2242  * \sa TagBase::FrameCount(void) const
2243  */
ShowFrame(void)2244 void TagBase::ShowFrame(void)
2245 {
2246 	f_frames++;
2247 }
2248 
2249 
2250 /** \brief Reset the frames counter
2251  *
2252  * This function is called once when the Save() starts to
2253  * reset the frame counter to zero.
2254  *
2255  * \sa TagShowFrame::Save(Data& data)
2256  * \sa TagBase::ShowFrame(void)
2257  * \sa TagBase::FrameCount(void) const
2258  */
ResetFrames(void)2259 void TagBase::ResetFrames(void)
2260 {
2261 	f_frames = 0;
2262 }
2263 
2264 
2265 /** \brief Returns the current number of frames counted so far
2266  *
2267  * This function is called to know how many TagShowFrame have been
2268  * saved so far (at the end, to know how many frames were saved
2269  * total.)
2270  *
2271  * \sa TagShowFrame::Save(Data& data)
2272  * \sa TagBase::ShowFrame(void)
2273  * \sa TagBase::ResetFrames(void)
2274  */
FrameCount(void) const2275 sswf_frame_t TagBase::FrameCount(void) const
2276 {
2277 	return f_frames;
2278 }
2279 
2280 
2281 
2282 
2283 /** \brief Request for a minimum version for this movie
2284  *
2285  * This function is to be used within the PreSave() functions.
2286  *
2287  * Using this function outside that realm results in an error.
2288  *
2289  * Whenever the movie is to be saved, a call to all the tags
2290  * PreSave() functions is made. If any tag requires a minimum
2291  * version to be saved (i.e. TagMetadata requires at least version
2292  * 8 to be legally saved in an SWF movie,) this function is
2293  * called with that minimum requirement.
2294  *
2295  * Note that this function calls the function of the same name
2296  * in the Header(). Trying to call this function before a save
2297  * will have no effect. Instead, use the
2298  * TagHeader::SetMinimumVersion(unsigned char version).
2299  *
2300  * \sa TagHeader::MinimumVersion(unsigned char version)
2301  */
MinimumVersion(unsigned char version)2302 void TagBase::MinimumVersion(unsigned char version)
2303 {
2304 	TagHeader *header = Header();
2305 	if(header != 0) {
2306 		header->MinimumVersion(version);
2307 	}
2308 }
2309 
2310 
2311 
2312 /** \brief Return the current movie version
2313  *
2314  * Whenever the movie is being saved, some tag need to know the
2315  * exact version of the entire movie. This is checked using
2316  * this function.
2317  *
2318  * For instance, the TagImport needs to know whether you are saving
2319  * a version 7 or earlier or a version 8 or newer to know whether to
2320  * save the import information in an SWF_TAG_IMPORT or SWF_TAG_IMPORT2
2321  * respectively.
2322  *
2323  * This function returns zero when the specified tag was not correctly
2324  * initialized. Otherwise it queries the header for a version which
2325  * should always be at least 1.
2326  *
2327  * \return The current movie version or zero if the header is not accessible
2328  */
Version(void) const2329 unsigned char TagBase::Version(void) const
2330 {
2331 	TagHeader *header = Header();
2332 	if(header != 0) {
2333 		return Header()->Version();
2334 	}
2335 	// a version of 0 represent an error
2336 	return 0;
2337 }
2338 
2339 
2340 /** \fn TagBase::TypeFlags(void) const
2341  *
2342  * \brief Retrieve a set of flags desribing the type of the tag
2343  *
2344  * This function returns some flags that can be used to know where
2345  * to place a tag in a movie, whether a tag is unique, etc.
2346  *
2347  * If a tag has specifics which are not described here, it often
2348  * can be checked using its name and special handling.
2349  *
2350  * The existing flags are:
2351  *
2352  *	\ref SWF_TYPE_DEFINE	This is a definition tag (Sprite, Shape...)
2353  *
2354  *	\ref SWF_TYPE_CONTROL	This is a control tag (ShowFrame,
2355  *				PlaceObject...)
2356  *
2357  *	\ref SWF_TYPE_UNIQUE	This can be used once throughout the
2358  *				whole movie
2359  *
2360  *	\ref SWF_TYPE_START	This tag should be at the start of the movie
2361  *
2362  *	\ref SWF_TYPE_ONE	At most one per frame
2363  *
2364  *	\ref SWF_TYPE_REFERENCE	This tag references another
2365  *
2366  *	\ref SWF_TYPE_HAS_ID	This tag has an identifier
2367  *
2368  *	\ref SWF_TYPE_SCRIPT	This object can accept action scripts
2369  *
2370  *	\ref SWF_TYPE_SPRITE	This is a sprite (can include other tags)
2371  *
2372  *	\ref SWF_TYPE_HEADER	The header object
2373  *
2374  * \note	These flags are constant (actually hard coded!) and will not
2375  *		change between calls. They even rarely change between versions.
2376  *
2377  * \return	The set of flags for the given tag
2378  *
2379  * \sa sswf::TagBase::Name(void) const
2380  */
2381 
2382 
2383 /** \brief Search the TagHeader and return its pointer
2384  *
2385  * This function searches for the Header of a movie.
2386  *
2387  * It does so by testing 'this' tag name to "header". If
2388  * it is equal return 'this' tag. Otherwise try again
2389  * with the parent tag.
2390  *
2391  * If the Header is not found, then NULL is returned.
2392  *
2393  * \return The Header or NULL
2394  *
2395  * \sa TagBase::Parent(void) const
2396  */
Header(void) const2397 TagHeader *TagBase::Header(void) const
2398 {
2399 	const TagBase		*p;
2400 
2401 	// when in the header, we return the header!
2402 	p = this;
2403 	while(p != 0) {
2404 		if(strcmp(p->Name(), "header") == 0) {
2405 			return const_cast<TagHeader *>(dynamic_cast<const TagHeader *>(p));
2406 		}
2407 		p = p->f_parent;
2408 	}
2409 
2410 	return 0;
2411 }
2412 
2413 /** \brief Call the error manager OnError() function
2414  *
2415  * This function calls the
2416  * sswf::ErrorManager::OnError(error_code_t errcode, const char *message, va_list ap) const
2417  * whenever possible.
2418  *
2419  * The function fails whenever the tag was not correctly initialized with a
2420  * valid sswf::TagHeader as the root tag.
2421  *
2422  * \param errcode	The code of this error
2423  * \param message	The message for this error
2424  * \param ap		Arguments for the message
2425  *
2426  * \return Usually the input error code; the user may change it
2427  */
OnError(ErrorManager::error_code_t errcode,const char * message,va_list ap) const2428 ErrorManager::error_code_t TagBase::OnError(ErrorManager::error_code_t errcode, const char *message, va_list ap) const
2429 {
2430 	TagHeader *header = Header();
2431 	if(header == 0) {
2432 		return errcode;
2433 	}
2434 
2435 	return header->OnError(errcode, message, ap);
2436 }
2437 
2438 
2439 /** \brief Call the error manager OnError() function
2440  *
2441  * This function calls the
2442  * sswf::ErrorManager::OnError(error_code_t errcode, const char *message, va_list ap) const
2443  * whenever possible.
2444  *
2445  * The function fails whenever the tag was not correctly initialized with a
2446  * valid sswf::TagHeader as the root tag.
2447  *
2448  * \param errcode	The code of this error
2449  * \param message	The message for this error
2450  * \param ...		Arguments for the message
2451  *
2452  * \return Usually the input error code; the user may change it
2453  */
OnError(ErrorManager::error_code_t errcode,const char * message,...) const2454 ErrorManager::error_code_t TagBase::OnError(ErrorManager::error_code_t errcode, const char *message, ...) const
2455 {
2456 	TagHeader *header = Header();
2457 	if(header == 0) {
2458 		return errcode;
2459 	}
2460 
2461 	va_list ap;
2462 	va_start(ap, message);
2463 	ErrorManager::error_code_t ec = header->OnError(errcode, message, ap);
2464 	va_end(ap);
2465 	return ec;
2466 }
2467 
2468 
2469 /** \brief Return the name (i.e. the type) of a tag
2470  *
2471  * This function returns the name of this tag.
2472  *
2473  * The name of a tag is actually a hard coded type name.
2474  * For instance, the TagHeader's name is "header".
2475  *
2476  * \return The name of this tag
2477  *
2478  * \bug The name is not copied. DO NOT MODIFY IT!
2479  */
Name(void) const2480 const char *TagBase::Name(void) const
2481 {
2482 	return f_name;
2483 }
2484 
2485 
2486 /** \brief Retrieve the first child
2487  *
2488  * The SWF movies are organized as a tree of tags. The top most is the
2489  * Header. The Header includes many definition and control tags. It
2490  * can include Sprites. Sprites can themselves include control tags.
2491  *
2492  * The pointer returned by this function represents the first
2493  * child.
2494  *
2495  * \return A pointer to a tag or NULL
2496  *
2497  * \sa TagBase::Header(void) const
2498  * \sa TagBase::Parent(void)
2499  * \sa TagBase::Next(void)
2500  * \sa TagBase::Previous(void)
2501  */
Children(void)2502 TagBase *TagBase::Children(void)
2503 {
2504 	return f_children;
2505 }
2506 
2507 
2508 /** \brief Retrieve the following tag
2509  *
2510  * Tags are defined in a list which includes many siblings. It is
2511  * possible to walk the list using the Next() and Previous() functions.
2512  *
2513  * The last tag of a list has a NULL Next() pointer.
2514  *
2515  * \return A pointer to a tag or NULL
2516  *
2517  * \sa TagBase::Parent(void)
2518  * \sa TagBase::Header(void) const
2519  * \sa TagBase::Previous(void)
2520  * \sa TagBase::Children(void)
2521  */
Next(void)2522 TagBase *TagBase::Next(void)
2523 {
2524 	return f_next;
2525 }
2526 
2527 
2528 /** \brief Retrieve the preceeding tag
2529  *
2530  * Tags are defined in a list which includes many siblings. It is
2531  * possible to walk the list using the Next() and Previous() functions.
2532  *
2533  * The first tag of a list has a NULL Previous() pointer.
2534  *
2535  * \return A pointer to a tag or NULL
2536  *
2537  * \sa TagBase::Next(void)
2538  * \sa TagBase::Header(void) const
2539  * \sa TagBase::Parent(void)
2540  * \sa TagBase::Children(void)
2541  */
Previous(void)2542 TagBase *TagBase::Previous(void)
2543 {
2544 	return f_previous;
2545 }
2546 
2547 
2548 /** \brief Retrieve the parent tag
2549  *
2550  * This function returns the parent of a tag. All tags except the
2551  * Header() will have a parent.
2552  *
2553  * At this time, only the Header and a Sprite can be parents.
2554  *
2555  * This function is used to find the Header().
2556  *
2557  * \sa TagBase::Children(void)
2558  * \sa TagBase::Next(void)
2559  * \sa TagBase::Previous(void)
2560  * \sa TagBase::Header(void) const
2561  */
Parent(void)2562 TagBase *TagBase::Parent(void)
2563 {
2564 	return f_parent;
2565 }
2566 
2567 
2568 
2569 /////////////////////////////////////////// TagBaseID
2570 
2571 /** \class sswf::TagBaseID
2572  *
2573  * \brief The base of all the tags with an ID
2574  *
2575  * A set of tags have an identifier. They all derive from the TagBaseID
2576  * class.
2577  *
2578  * The TagBaseID class is used to manage the identifiers.
2579  *
2580  * It knows how to allocate a new identifier, how to forfeit an identifier,
2581  * how to save an identifier.
2582  *
2583  * For instance, a TagSprite derives from the TagBaseID()
2584  *
2585  * \sa <a href="../SWFalexref.html#swf_tag">SWF Alexis' Reference&mdash;swf_tag</a>
2586  */
2587 
2588 
2589 
2590 /** \brief Initialize the base information of a tag with an identifier
2591  *
2592  * Tag which include an identifier will be derived from this
2593  * TagBaseID class.
2594  *
2595  * Whenever created, they are automatically assigned a unique identifier
2596  * (see the sswf::TagHeader::NextID(void) function).
2597  *
2598  * The TagBaseID is itself derived from the TagBase object. The name and
2599  * parent parameters are directly passed down to the TagBase constructor.
2600  *
2601  * \warning
2602  * If the tag is created without a parent, or an invalid parent pointer,
2603  * then the sswf::TagHeader::NextID(void) function cannot be found. The
2604  * result is that no identifier is assigned this the tag.
2605  *
2606  * \param name The type of the tag in the form of a string
2607  * \param parent The parent tag (a header or a sprite)
2608  */
TagBaseID(const char * name,TagBase * parent)2609 TagBaseID::TagBaseID(const char *name, TagBase *parent)
2610 	: TagBase(name, parent)
2611 {
2612 	assert(parent != 0, "a tag with an identification must have a header as its parent");
2613 
2614 	TagHeader *header = Header();
2615 	if(header != 0) {
2616 		f_id = header->NextID();
2617 		f_identified = true;
2618 	}
2619 	else {
2620 		f_id = SSWF_ID_NONE;
2621 	}
2622 }
2623 
2624 
2625 /** \brief Destroys the base information of a tag with an identifier
2626  *
2627  * The destructor releases the identification of the object and returns.
2628  *
2629  * \note
2630  * In general, the release of the identification is not required.
2631  *
2632  * \warning
2633  * I added the destructor because it is needed under MinGW when compiling
2634  * with .dll libraries. Otherwise it does not know what function to call.
2635  * (an auto-destructor cannot be auto-imported) Otherwise, the functionality
2636  * of the destructor will usually not be of much necessity.
2637  */
~TagBaseID()2638 TagBaseID::~TagBaseID()
2639 {
2640 	// we don't need this object identification anymore
2641 	NoIdentification();
2642 }
2643 
2644 
2645 /** \brief Return this tag identifier
2646  *
2647  * This function returns the identifier which was given to this tag
2648  * or SSWF_ID_NONE when it was cancelled by a call to
2649  * TagBaseID::NoIdentification().
2650  *
2651  * \return the tag identifier or SSWF_ID_NONE
2652  */
Identification(void) const2653 sswf_id_t TagBaseID::Identification(void) const
2654 {
2655 	return f_id;
2656 }
2657 
2658 
2659 /** \brief Release the identification for this tag
2660  *
2661  * It is possible that a tag which usually has an identifier does not
2662  * actually need it (at this time this is the case only for Glyphs
2663  * which are shapes without identification.)
2664  *
2665  * This function will release the identification which can then not
2666  * be used.
2667  *
2668  * Whenever possible, the identifier of this object will be returned
2669  * to the pool of available identifiers.
2670  */
NoIdentification(void)2671 void TagBaseID::NoIdentification(void)
2672 {
2673 	if(f_identified) {
2674 		TagHeader *header = Header();
2675 		if(header != 0) {
2676 			header->RemoveID(f_id);
2677 		}
2678 		f_id = SSWF_ID_NONE;
2679 		f_identified = false;
2680 	}
2681 }
2682 
2683 
2684 /** \brief Test whether a tag which should have an ID really has one
2685  *
2686  * This function checks whether a tag supposed to have an identifier
2687  * really has one.
2688  *
2689  * \return true when the object is still identified, and false otherwise
2690  */
HasIdentification(void) const2691 bool TagBaseID::HasIdentification(void) const
2692 {
2693 	return f_identified;
2694 }
2695 
2696 
2697 /** \brief Save the object identifier in a Data buffer
2698  *
2699  * This function will save the identifier of 'this' tag in the
2700  * specified Data buffer.
2701  *
2702  * \param data The data buffer used to save the tag
2703  *
2704  * \return The function returns 0 when it succeeds and non-zero when it fails
2705  */
SaveID(Data & data) const2706 int TagBaseID::SaveID(Data& data) const
2707 {
2708 	assert(f_identified, "the identification of this object was removed or never assigned");
2709 
2710 	if(!f_identified) {
2711 		return 1;
2712 	}
2713 
2714 	data.PutShort(f_id);
2715 
2716 	return 0;
2717 }
2718 
2719 
2720 
2721 /* The following options fold the documentation; use 'zi' to turn on and off
2722  *
2723  * vim: foldexpr=getline(v\:lnum)!~'^/\\*\\*'&&getline(v\:lnum)!~'^\ \\*'?0\:1 foldcolumn=2 foldmethod=expr
2724  */
2725