libsswf.h

Go to the documentation of this file.
00001 /* libsswf.h -- written by Alexis WILKE for Made to Order Software Corp. (c) 2002-2007 */
00002 #ifndef LIBSSWF_H
00003 #define LIBSSWF_H
00004 
00005 /*
00006 
00007 Copyright (c) 2002-2007 Made to Order Software Corp.
00008 
00009 Permission is hereby granted, free of charge, to any
00010 person obtaining a copy of this software and
00011 associated documentation files (the "Software"), to
00012 deal in the Software without restriction, including
00013 without limitation the rights to use, copy, modify,
00014 merge, publish, distribute, sublicense, and/or sell
00015 copies of the Software, and to permit persons to whom
00016 the Software is furnished to do so, subject to the
00017 following conditions:
00018 
00019 The above copyright notice and this permission notice
00020 shall be included in all copies or substantial
00021 portions of the Software.
00022 
00023 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
00024 ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
00025 LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
00026 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
00027 EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
00029 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00030 ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00031 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00032 SOFTWARE.
00033 
00034 */
00035 
00036 /** \file
00037  *
00038  * \brief The header to include to use the SSWF C++ library
00039  *
00040  * The libsswf.h file includes all the necessary classes
00041  * for the SSWF library.
00042  */
00043 
00044 
00045 
00046 #include        <stdarg.h>
00047 #include        <stdio.h>
00048 #include        <stdlib.h>
00049 #ifndef _MSVC
00050 #include        <unistd.h>
00051 #endif
00052 #include        <string.h>
00053 #include        <limits.h>
00054 #include        <errno.h>
00055 #include        <zlib.h>
00056 #include        <math.h>
00057 #include        <ctype.h>
00058 #include        <wctype.h>
00059 #ifdef STATIC_ICONV
00060 #include        <iconv.h.static>
00061 #else
00062 #include        <iconv.h>
00063 #endif
00064 
00065 #if _MSVC
00066 typedef __int8                  int8_t;
00067 typedef unsigned __int8         uint8_t;
00068 typedef __int16                 int16_t;
00069 typedef unsigned __int16        uint16_t;
00070 typedef __int32                 int32_t;
00071 typedef unsigned __int32        uint32_t;
00072 typedef __int64                 int64_t;
00073 typedef unsigned __int64        uint64_t;
00074 #elif IRIX
00075 #include        <inttypes.h>
00076 #else
00077 #include        <stdint.h>
00078 #endif
00079 
00080 #if IRIX
00081 #include        <sys/endian.h>
00082 #endif
00083 
00084 #include        "sswf/libsswf-config.h"
00085 
00086 /* wint_t is an "equivalent" to wchar_t without being limited to 16 bits as on MS-Windows */
00087 #ifndef _MSVC
00088 #ifndef __APPLE_CC__
00089 #ifndef _WINT_T
00090 #define _WINT_T
00091 typedef unsigned int    wint_t;
00092 #endif
00093 #endif
00094 #endif
00095 
00096 #ifndef M_PI
00097 #define M_PI            3.14159265358979323846
00098 #endif
00099 
00100 
00101 #ifdef _MSVC
00102 #define strcasecmp      stricmp
00103 #define rint(x)         ((double) (long) floor(x + 0.5))
00104 #endif
00105 
00106 #ifdef _LIBICONV_H
00107 #define ICONV_INPUT_CAST
00108 #else
00109 /* older versions of iconv() were broken in regard to the
00110  * input buffer which wasn't const; newer versions have the
00111  * _LIBICONV_H #define at the start so this is good to know
00112  * whether we have to cast or not.
00113  */
00114 #define ICONV_INPUT_CAST        (char**)
00115 #endif
00116 
00117 
00118 
00119 /* The following I use to tell my C++ to C tool
00120  * what needs to be exposed in C & PHP.
00121  * These macros show you what is equivalent in C++
00122  *
00123  * exposed_class        A class we want exposed in C.
00124  *
00125  * invisible            Members which are public in C++ but
00126  *                      not exposed to C users.
00127  */
00128 #define exposed_class   class
00129 #define invisible       public
00130 
00131 
00132 
00133 /** \brief The C++ SSWF library namespace
00134  * 
00135  * The SSWF library is fully defined with the 'sswf' namespace.
00136  *
00137  * Do 'using namespace sswf;' to "get rid of it".
00138  *
00139  * The SSWF library is a full set of classes and functions used to create
00140  * SWF binary files. The library supports most of the tags available in
00141  * SWF and is used to compress them in the appropriate format for use
00142  * by a Flash player.
00143  *
00144  * One important point about this library: it hides from you, the user,
00145  * the lower layers of the SWF tags. For one thing, you will never have
00146  * to worry about how to compress the data in a valid SWF tag. But not
00147  * only that, the library takes care of selecting the appropriate tag
00148  * depending on the output movie version and what each tag support.
00149  *
00150  * For instance, when you create a TagFont, the library hides from you
00151  * the fact that it supports 3 different types of DefineFont tags (and
00152  * once version 8 is supported, it will hide the DefineFontAlignZones).
00153  * This means you don't need to know all the details of how to create
00154  * a font. Such details are important for the library, but not to you.
00155  *
00156  * None the less, it is complicated to create a valid SWF shape and the
00157  * library does not do that automatically for you. For more information
00158  * about each specific tag, please read the corresponding documentation.
00159  */
00160 namespace sswf
00161 {
00162 
00163 
00164 
00165 
00166 void assert(int cond, const char *format, ...)
00167 #ifndef _MSVC
00168                         __attribute__ ((format (printf, 2, 3)))
00169 #endif
00170                 ;
00171 
00172 
00173 #if DEBUG
00174 inline void assert(int cond, const char *format, ...)
00175 {
00176         va_list         ap;
00177 
00178         // if the condition is true then we have no problem!
00179         if(cond) {
00180                 return;
00181         }
00182         fflush(stdout);
00183         fflush(stderr);
00184         fprintf(stderr, "\n");
00185         va_start(ap, format);
00186         vfprintf(stderr, format, ap);
00187         va_end(ap);
00188         fprintf(stderr, ".\n");
00189         fflush(stderr);         // some systems don't do this inside the abort()!
00190         abort();
00191 }
00192 #else
00193 inline void assert(int /*cond*/, const char * /*format*/, ...) {}
00194 #endif
00195 
00196 
00197 typedef unsigned short          sswf_id_t;              // object ID reference
00198 typedef unsigned short          sswf_frame_t;           // frame counter
00199 typedef int32_t                 sswf_ucs4_t;            // a wide character (must be at least 32 bits)
00200 
00201 
00202 #define SSWF_ID_NONE            ((sswf_id_t) -1)        // this is an invalid ID (it seems)
00203 
00204 
00205 extern  void                    swap(void *s1, void *s2, size_t size);
00206 extern  int                     wctomb(const sswf_ucs4_t *wc, size_t wc_len, char *mb, size_t& mb_size);
00207 extern  int                     mbtowc(const char *mb, size_t mb_len, sswf_ucs4_t *& wc, size_t& wc_len);
00208 extern  char *                  wcname(sswf_ucs4_t wc, char *result);
00209 extern  long                    wcslen(sswf_ucs4_t *wcstr);
00210 
00211 inline unsigned short           swap_short(unsigned short s)
00212                                 {
00213                                         return (s >> 8) | (s << 8);
00214                                 }
00215 
00216 inline unsigned int             swap_int(unsigned int l)
00217                                 {
00218                                         return (l >> 24) | (l << 24)
00219                                                 | ((l >> 8) & 0x0000FF00)
00220                                                 | ((l << 8) & 0x00FF0000);
00221                                 }
00222 
00223 extern  const char *            sswf_version(void);
00224 
00225 
00226 
00227 
00228 /*
00229  * Your class derives from ErrorManager::ErrorHandler, you pass a pointer
00230  * to the TagHeader object and whenever an error occurs in the SSWF
00231  * library, the OnError() function is called. You can then decide what to do
00232  * (i.e. print the message in a file and then throw, exit or return...)
00233  */
00234 class ErrorManager
00235 {
00236 public:
00237         enum error_code_t {
00238                 ERROR_CODE_NONE = 0,
00239 
00240                 ERROR_CODE_ACTION_OVERFLOW,
00241                 ERROR_CODE_BUTTON_MISSING_STATE,
00242                 ERROR_CODE_CHILDREN_NOT_SUPPORTED,
00243                 ERROR_CODE_COMPRESSED_SOUND_8BITS,
00244                 ERROR_CODE_ENDED_ACTION_SCRIPT,
00245                 ERROR_CODE_FILE_NOT_FOUND,
00246                 ERROR_CODE_JPEG,
00247                 ERROR_CODE_ICONV_ENCODER_NOT_AVAILABLE,
00248                 ERROR_CODE_ICONV_FAILED,
00249                 ERROR_CODE_IO,
00250                 ERROR_CODE_INCOMPATIBLE_CHILD,
00251                 ERROR_CODE_INTERNAL_ERROR,
00252                 ERROR_CODE_INVALID_OBJECT_EXPORTED,
00253                 ERROR_CODE_INVALID_DEPTH,
00254                 ERROR_CODE_MISSING_FRAME_NAME,
00255                 ERROR_CODE_NO_HEADER,
00256                 ERROR_CODE_NO_STATES,
00257                 ERROR_CODE_NO_SUCH_GLYPH,
00258                 ERROR_CODE_LABEL_NOT_FOUND,
00259                 ERROR_CODE_LABEL_OVERFLOW,
00260                 ERROR_CODE_OBJECT_NOT_FOUND,
00261                 ERROR_CODE_REGISTER_OVERFLOW,
00262                 ERROR_CODE_START_SOUND_NO_INFO,
00263                 ERROR_CODE_TWO_OR_MORE_JPEGTABLES,
00264                 ERROR_CODE_TWO_OR_MORE_METADATA,
00265                 ERROR_CODE_UNEXPECTED_EVENT_FLAG,
00266                 ERROR_CODE_UNKNOWN_OBJECT_EXPORTED,
00267                 ERROR_CODE_UNSUPPORTED_IMAGE_FORMAT,
00268                 ERROR_CODE_UNSUPPORTED_SOUND_FORMAT,
00269                 ERROR_CODE_VERSION_UNSATISFIED,
00270 
00271                 ERROR_CODE_max
00272         };
00273 
00274                                 ErrorManager(void);
00275 
00276         void                    Reset(void);
00277         int                     Count(void) const;
00278         static error_code_t     KeepFirst(error_code_t a, error_code_t b);
00279 
00280         error_code_t            OnError(error_code_t errcode, const char *message, va_list ap) const;
00281 
00282 public:
00283         class InternalErrorException {};
00284 
00285         class ErrorHandler
00286         {
00287         public:
00288                 virtual                 ~ErrorHandler();
00289                 virtual error_code_t    OnError(error_code_t errcode, const char *msg) = 0;
00290         };
00291 
00292         ErrorHandler *          SetErrorHandler(ErrorHandler *error_handler);
00293         error_code_t            OnError(error_code_t errcode, const char *message, ...) const;
00294 
00295 private:
00296         mutable int             f_error_count;
00297         ErrorHandler *          f_error_handler;
00298 };
00299 
00300 
00301 
00302 
00303 
00304 
00305 class Buffer;
00306 class MemBuffer
00307 {
00308 public:
00309                                 MemBuffer(void);
00310         virtual                 ~MemBuffer();
00311 
00312         void                    AttachBuffer(Buffer *buffer);
00313         Buffer *                GetBuffer(void) const;
00314 
00315 private:
00316         Buffer *                f_buffer;
00317 };
00318 
00319 
00320 class Buffer
00321 {
00322 public:
00323                                 Buffer(Buffer **head, size_t size, const char *info);
00324                                 Buffer(Buffer **head, MemBuffer *ptr, size_t size, const char *info);
00325                                 //Buffer(Buffer **head, void *ptr, size_t size, const char *info);
00326                                 ~Buffer();
00327 
00328         void *                  Realloc(size_t size);
00329         void *                  Data(void) const { return f_data; }
00330         Buffer *                Next(void) const { return (Buffer *) f_next; }
00331         Buffer *                Previous(void) const { return (Buffer *) f_previous; }
00332         size_t                  Size(void) const { return f_size; }
00333         const char *            Info(void) const { return f_info; }
00334 
00335         static Buffer *         FindBuffer(void *ptr);
00336 #if 0
00337 // this is totally wrong and it simply can't be used safely
00338         static bool             IsBuffer(void *ptr);
00339 #endif
00340 
00341 private:
00342         /// Hold the magic and a pointer to the actual buffer
00343         struct mem_buffer_t {
00344                 unsigned long   f_magic;        // to make sure we have indeed a valid buffer
00345                 Buffer *        f_buffer;       // reference back to 'this' buffer
00346         };
00347         enum {
00348                 DMAGIC = (unsigned long) 0x53535746,    // direct (malloc)
00349                 OMAGIC = (unsigned long) 0x5353574F     // object (new/delete)
00350         };
00351 #define SSWF_ALIGN(value, modulo)       (((value) + ((modulo) - 1)) & - (long) (modulo))
00352 #define SSWF_SPACE                      SSWF_ALIGN(sizeof(mem_buffer_t), sizeof(double))
00353 #if DEBUG
00354         void                            Test(void);
00355 #define SSWF_SAFE                       (sizeof(double) * 32)
00356 #define SSWF_TEST                       ((long)0xBADC0FFE)
00357 #else
00358 #define SSWF_SAFE                       0
00359 #endif
00360 
00361         Buffer **               f_head;         // header for this list of buffers
00362         Buffer *                f_next;
00363         Buffer *                f_previous;
00364         const char *            f_info;
00365         size_t                  f_size;
00366         mutable void *          f_data;
00367 };
00368 
00369 
00370 class MemoryManager
00371 {
00372 public:
00373                                 MemoryManager(void);
00374         virtual                 ~MemoryManager();
00375 
00376         void                    MemAttach(MemBuffer *ptr, size_t size, const char *info);       // used when you require the use of a ::new ... call
00377         void *                  MemAlloc(size_t size, const char *info);
00378         void *                  MemRealloc(void *ptr, size_t size, const char *info);   // info used ONLY if ptr == 0
00379         void                    MemFree(void *ptr);
00380         void                    MemClean(void *ptr);
00381         char *                  StrDup(const char *string);
00382         char *                  StrCat(const char *s1, const char *s2);
00383 #if DEBUG
00384         void                    MemTest(void *ptr);
00385 #endif
00386         unsigned long           Size(void *ptr);
00387 
00388 private:
00389         Buffer *                f_head;
00390 };
00391 
00392 
00393 
00394 class ItemBase : public MemBuffer
00395 {
00396 public:
00397                                 ItemBase(void) {}
00398         virtual                 ~ItemBase() {}
00399 };
00400 
00401 
00402 class Vectors : public MemoryManager, public MemBuffer
00403 {
00404 public:
00405                                 Vectors(void);
00406                                 Vectors(const Vectors& vector);
00407                                 ~Vectors();
00408 
00409         ItemBase *              Get(int index) const;
00410         void                    Set(int index, ItemBase *vector);
00411         void                    Insert(int index, ItemBase *vector);
00412         void                    SetSize(int size);
00413         int                     Count(void) const { return f_count; }
00414         void                    Empty(void) { f_count = 0; }    // currently we keep the f_vectors buffer
00415 
00416 public:
00417         Vectors&                operator = (const Vectors& vectors);
00418 
00419 private:
00420         int                     f_count;                // # of valid pointers
00421         int                     f_max;                  // max. # of pointers until realloc
00422         ItemBase **             f_vectors;              // an array of pointers
00423 };
00424 
00425 
00426 
00427 
00428 
00429 
00430 
00431 class Data : public MemoryManager
00432 {
00433 public:
00434                                 Data(void);
00435                                 ~Data();
00436 
00437         void                    Empty(void) { f_pos = 0; }              // make the buffer empty (reset/restart)
00438         void                    Align(void);                            // align to the next byte
00439         void                    Overwrite(size_t offset, const void *ptr, size_t size);
00440         void                    OverwriteByte(size_t offset, char c);
00441         void                    OverwriteShort(size_t offset, short s);
00442         void                    OverwriteLong(size_t offset, long l);
00443         void                    Write(const void *ptr, size_t size);    // write bytes
00444         void                    WriteBits(long value, size_t bits);     // write the 'bits' lower bits of 'value'
00445         void                    PutByte(char c);                        // write one byte
00446         void                    PutShort(short s);                      // write one short (auto-swap)
00447         void                    PutLong(long l);                        // write one long (auto-swap)
00448         void                    PutString(const char *string);          // write a null terminated string (including the terminator)
00449         void                    Append(const Data& append);             // append another data buffer in here
00450 
00451         void                    Read(void *& ptr, size_t& size);        // retrieve the buffer and its size rounded up to the next byte (Align() is called once)
00452                                                                         // if you want the size in bits, use the Size() function call
00453 
00454         unsigned long           ByteSize(void) const { return (f_pos + CHAR_BIT - 1) / CHAR_BIT; }
00455         unsigned long           GetSize(void) const { return f_pos; }   // total size in bits
00456         void                    SetSize(unsigned long size);
00457 
00458 private:
00459         void                    AdjustSize(size_t size);
00460 
00461         unsigned long           f_pos;
00462         unsigned long           f_size;
00463         char *                  f_data;
00464 };
00465 
00466 
00467 
00468 
00469 
00470 
00471 // the following are structures used within the tags defined afterward
00472 class SRectangle
00473 {
00474 public:
00475                                 SRectangle(void);
00476 
00477         void                    Reset(void);
00478         void                    Set(long xmin, long xmax, long ymin, long ymax);
00479         void                    SetReorder(long xmin, long xmax, long ymin, long ymax);
00480         long                    XMin(void) const;
00481         long                    XMax(void) const;
00482         long                    YMin(void) const;
00483         long                    YMax(void) const;
00484         bool                    IsEmpty(void) const;
00485 
00486         void                    Save(Data& data) const;
00487 
00488 private:
00489         long                    f_xmin;
00490         long                    f_xmax;
00491         long                    f_ymin;
00492         long                    f_ymax;
00493 };
00494 
00495 
00496 class Color
00497 {
00498 public:
00499                                 Color(void) { Reset(); }
00500 
00501         void                    Reset(void);
00502         void                    Set(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha = 255);
00503         unsigned char           Red(void)   const { return f_red;   }
00504         unsigned char           Green(void) const { return f_green; }
00505         unsigned char           Blue(void)  const { return f_blue;  }
00506         unsigned char           Alpha(void) const { return f_alpha; }
00507 
00508         void                    Save(Data& data, bool save_alpha = true);
00509 
00510         bool                    IsSolid(void) const { return f_alpha == 255; }
00511         bool                    IsInvisible(void) const { return f_alpha == 0; }
00512 
00513 public:
00514         bool                    operator == (const Color& color) const;
00515         bool                    operator != (const Color& color) const;
00516 
00517 private:
00518         unsigned char           f_red;
00519         unsigned char           f_green;
00520         unsigned char           f_blue;
00521         unsigned char           f_alpha;
00522 };
00523 
00524 
00525 
00526 class ColorTransform
00527 {
00528 public:
00529                                 ColorTransform(void);
00530 
00531         void                    Reset(void);
00532         void                    SetAdd(double red, double green, double blue, double alpha = 0.0);
00533         void                    SetMult(double red, double green, double blue, double alpha = 1.0);
00534         double                  AddRed(void)    const { return f_add_red;   }
00535         double                  AddGreen(void)  const { return f_add_green; }
00536         double                  AddBlue(void)   const { return f_add_blue;  }
00537         double                  AddAlpha(void)  const { return f_add_alpha; }
00538         double                  MultRed(void)   const { return f_add_red;   }
00539         double                  MultGreen(void) const { return f_add_green; }
00540         double                  MultBlue(void)  const { return f_add_blue;  }
00541         double                  MultAlpha(void) const { return f_add_alpha; }
00542 
00543         void                    Save(Data& data, bool save_alpha = true);
00544 
00545         bool                    IsNull(bool with_alpha) const;          // if true we can ignore this transformation!
00546         bool                    IsSolidCompatible(void) const;          // if true we can ignore the alpha channel!
00547 
00548 private:
00549         double                  f_add_red;
00550         double                  f_add_green;
00551         double                  f_add_blue;
00552         double                  f_add_alpha;
00553         double                  f_mult_red;
00554         double                  f_mult_green;
00555         double                  f_mult_blue;
00556         double                  f_mult_alpha;
00557 };
00558 
00559 
00560 
00561 class Matrix
00562 {
00563 public:
00564                                 Matrix(void);
00565 
00566         void                    Reset(void);
00567         void                    SetScale(double x, double y) { f_scale_x = x; f_scale_y = y; }
00568         void                    SetScale(double scale) { f_scale_x = scale; f_scale_y = scale; }
00569         void                    SetRotate(double rotate);
00570         void                    SetSkew(double skew0, double skew1) { f_skew_0 = skew0; f_skew_1 = skew1; }
00571         void                    SetTranslate(long x, long y) { f_translate_x = x; f_translate_y = y; }
00572 
00573         void                    Save(Data& data);
00574 
00575         bool                    IsNull(void) const;
00576 
00577 public:
00578         bool                    operator == (const Matrix& matrix) const;
00579         bool                    operator != (const Matrix& matrix) const;
00580 
00581 private:
00582         /// Matrix of longs; used to compute the matrix to be saved in the movie
00583         struct signed_matrix_t {
00584                 long    m[4];
00585         };
00586 
00587         void                    ComputeMatrix(signed_matrix_t& m) const;
00588 
00589         double                  f_scale_x;
00590         double                  f_scale_y;
00591         double                  f_rotate;
00592         long                    f_translate_x;
00593         long                    f_translate_y;
00594         double                  f_skew_0;
00595         double                  f_skew_1;
00596 };
00597 
00598 
00599 
00600 class Envelope : public ItemBase
00601 {
00602 public:
00603                                 Envelope(unsigned long p, unsigned short l, unsigned short r);
00604                                 Envelope(const Envelope& envelope);
00605 
00606         unsigned long           Position(void) const;
00607         unsigned short          Left(void) const;
00608         unsigned short          Right(void) const;
00609         void                    Save(Data& data) const;
00610 
00611 private:
00612         unsigned long           f_position;
00613         unsigned short          f_left;
00614         unsigned short          f_right;
00615 };
00616 
00617 
00618 class SoundInfo : public MemoryManager
00619 {
00620 public:
00621                                 SoundInfo(void);
00622 
00623         void                    SetSoundID(sswf_id_t id);
00624         void                    StopSound(bool stop = true);
00625         void                    NoMultiple(bool no_multiple = true);
00626         void                    SetRange(unsigned long start, unsigned long end);
00627         void                    SetLoop(unsigned short loop);
00628         void                    AddEnvelope(const Envelope& envelope);
00629 
00630         void                    Save(Data& data) const;
00631 
00632 private:
00633         sswf_id_t               f_sound_id;
00634         bool                    f_stop;                 // if true, ignore all the other info
00635         bool                    f_no_multiple;          // never play this sound more than once
00636         unsigned long           f_start_position;       // start playing from this sample
00637         unsigned long           f_end_position;         // stop playing at this sample
00638         unsigned short          f_loop;                 // repeat the sound this many times
00639         Vectors                 f_envelopes;            // a list of position + volume information
00640 };
00641 
00642 
00643 
00644 
00645 class BlendMode
00646 {
00647 public:
00648         enum blend_mode_t {
00649                 BLEND_MODE_UNDEFINED = -1,
00650                 BLEND_MODE_NORMAL = 1,
00651                 BLEND_MODE_LAYER = 2,
00652                 BLEND_MODE_MULTIPLY = 3,
00653                 BLEND_MODE_SCREEN = 4,
00654                 BLEND_MODE_LIGHTEN = 5,
00655                 BLEND_MODE_DARKEN = 6,
00656                 BLEND_MODE_DIFFERENCE = 7,
00657                 BLEND_MODE_ADD = 8,
00658                 BLEND_MODE_SUBTRACT = 9,
00659                 BLEND_MODE_INVERT = 10,
00660                 BLEND_MODE_ALPHA = 11,
00661                 BLEND_MODE_ERASE = 12,
00662                 BLEND_MODE_OVERLAY = 13,
00663                 BLEND_MODE_HARDLIGHT = 14
00664         };
00665 
00666                                 BlendMode(void);
00667 
00668         bool                    HasBlendMode(void) const;
00669         void                    SetBlendMode(blend_mode_t blend_mode_value);
00670         bool                    SetBlendModeByName(const char *blend_mode_name);
00671         blend_mode_t            GetBlendMode(void) const;
00672 
00673         void                    Save(Data& data);
00674 
00675 private:
00676         blend_mode_t            f_blend_mode;
00677 };
00678 
00679 
00680 class State : public ItemBase
00681 {
00682 public:
00683         // Use with SetFlags()
00684         enum state_flags_t {
00685                 STATE_FLAG_UP           = 0x01,
00686                 STATE_FLAG_OVER         = 0x02,
00687                 STATE_FLAG_DOWN         = 0x04,
00688                 STATE_FLAG_HIT_TEST     = 0x08,
00689 
00690                 STATE_ALL_FLAGS         = 0x0F
00691         };
00692 
00693 
00694                                 State(void);
00695 
00696         void                    Reset(void);
00697         void                    SetObjectID(sswf_id_t id);
00698         void                    SetFlags(unsigned char flags);
00699         void                    SetLayer(unsigned short layer);
00700         void                    SetMatrix(const Matrix& matrix);
00701         void                    SetColorTransform(const ColorTransform& color_transform);
00702         bool                    HasColorTransform(void) const;
00703         void                    SetBlendMode(const BlendMode& blend_mode);
00704         void                    Save(Data& data, bool color_transform = false);
00705 
00706 private:
00707         sswf_id_t               f_id;
00708         bool                    f_has_color_transform;
00709         unsigned char           f_flags;
00710         unsigned short          f_layer;
00711         Matrix                  f_matrix;
00712         ColorTransform          f_color_transform;
00713         BlendMode               f_blend_mode;
00714 };
00715 
00716 
00717 
00718 
00719 
00720 class Action;
00721 class Event : public MemoryManager, public ItemBase
00722 {
00723 public:
00724                                 Event(void);
00725 
00726         void                    Reset(void);
00727         void                    SetEvents(unsigned long events);
00728         void                    SetKey(unsigned char key);
00729         unsigned long           Events(void) const;     // PlaceObject2 flags
00730         unsigned long           Conditions(void) const; // DefineButton2 flags
00731         unsigned char           Key(void) const;
00732         Vectors&                Actions(void);
00733 
00734         static unsigned long    StringToEvents(const char *s);
00735         static unsigned char    StringToKeyCode(const char *s);
00736 
00737         // the flags are saved with the following bits
00738         // in a PlaceObject2
00739         // these have to be converted when saved in a
00740         // DefineButton2 tag
00741         enum event_flag_t {
00742                 EVENT_COND_MENU_LEAVE           = 0x80000000,   // for DefineButton2
00743                 EVENT_COND_MENU_ENTER           = 0x40000000,   // for DefineButton2
00744 
00745                 EVENT_CONSTRUCT                 = 0x00040000,   // V7.x
00746                 EVENT_KEY_PRESS                 = 0x00020000,   // V6.x
00747                 EVENT_POINTER_DRAG_LEAVE        = 0x00010000,   // V6.x shared with DefineButton2
00748                 EVENT_POINTER_DRAG_ENTER        = 0x00008000,   // V5.x shared with DefineButton2
00749                 EVENT_POINTER_LEAVE             = 0x00004000,   // V5.x shared with DefineButton2
00750                 EVENT_POINTER_ENTER             = 0x00002000,   // V5.x shared with DefineButton2
00751                 EVENT_POINTER_RELEASE_OUTSIDE   = 0x00001000,   // V5.x shared with DefineButton2
00752                 EVENT_POINTER_RELEASE_INSIDE    = 0x00000800,   // V5.x shared with DefineButton2
00753                 EVENT_POINTER_PUSH              = 0x00000400,   // V5.x shared with DefineButton2
00754                 EVENT_INITIALIZE                = 0x00000200,   // V5.x
00755                 EVENT_DATA                      = 0x00000100,   // V5.x
00756                 EVENT_KEY_UP                    = 0x00000080,   // V6.x
00757                 EVENT_KEY_DOWN                  = 0x00000040,   // V6.x
00758                 EVENT_POINTER_UP                = 0x00000020,   // V6.x
00759                 EVENT_POINTER_DOWN              = 0x00000010,   // V6.x
00760                 EVENT_POINTER_MOVE              = 0x00000008,   // V6.x
00761                 EVENT_UNLOAD                    = 0x00000004,   // V6.x
00762                 EVENT_ENTER_FRAME               = 0x00000002,   // V6.x
00763                 EVENT_ONLOAD                    = 0x00000001    // V5.x
00764         };
00765 #define SSWF_EVENT_V5                   0x0000FF01      // flags present in V5
00766 #define SSWF_EVENT_V6                   0x000300FE      // flags added in V6
00767 #define SSWF_EVENT_V7                   0x00040000      // flag added in V7
00768 #define SSWF_EVENT_CONDITIONS           0xC001FC00      // flags used by conditions in DefineButton2
00769 #define SSWF_EVENT_COUNT                20
00770         struct event_names_t {
00771                 event_flag_t            f_flag;
00772                 const char *            f_name;
00773         };
00774 
00775         enum condition_flag_t {
00776                 CONDITION_KEY_MASK                      = 0xFE00,
00777                 CONDITION_KEY_SHIFT                     = 9,
00778                 CONDITION_MENU_LEAVE                    = 0x0100,       // OVER_DOWN_TO_IDLE
00779                 CONDITION_MENU_ENTER                    = 0x0080,       // IDLE_TO_OVER_DOWN
00780                 CONDITION_POINTER_RELEASE_OUTSIDE       = 0x0040,       // OUT_DOWN_TO_IDLE
00781                 CONDITION_POINTER_DRAG_ENTER            = 0x0020,       // OUT_DOWN_TO_OVER_DOWN
00782                 CONDITION_POINTER_DRAG_LEAVE            = 0x0010,       // OVER_DOWN_TO_OUT_DOWN
00783                 CONDITION_POINTER_RELEASE_INSIDE        = 0x0008,       // OVER_DOWN_TO_OVER_UP
00784                 CONDITION_POINTER_PUSH                  = 0x0004,       // OVER_UP_TO_OVER_DOWN
00785                 CONDITION_POINTER_LEAVE                 = 0x0002,       // OVER_UP_TO_IDLE
00786                 CONDITION_POINTER_ENTER                 = 0x0001        // IDLE_TO_OVER_UP
00787         };
00788 
00789         enum key_code_t {
00790                 KEY_CODE_NONE = 0,
00791                 KEY_CODE_LEFT_ARROW = 1,
00792                 KEY_CODE_RIGHT_ARROW = 2,
00793                 KEY_CODE_HOME = 3,
00794                 KEY_CODE_END = 4,
00795                 KEY_CODE_INSERT = 5,
00796                 KEY_CODE_DELETE = 6,
00797                 KEY_CODE_BACKSPACE = 8,
00798                 KEY_CODE_ENTER = 13,
00799                 KEY_CODE_UP_ARROW = 14,
00800                 KEY_CODE_DOWN_ARROW = 15,
00801                 KEY_CODE_PAGE_UP = 16,
00802                 KEY_CODE_PAGE_DOWN = 17,
00803                 KEY_CODE_TAB = 18,
00804                 KEY_CODE_ESCAPE = 19,
00805                 KEY_CODE_SPACE = 20,            // equal to ' '
00806                 // and also all the ASCII codes from 32 to 126
00807         };
00808 #define SSWF_KEY_COUNT                  15
00809         struct key_names_t {
00810                 key_code_t              f_code;
00811                 const char *            f_name;
00812         };
00813 
00814 public:
00815         static const event_names_t      g_event_names[SSWF_EVENT_COUNT];
00816         static const key_names_t        g_key_names[SSWF_KEY_COUNT];
00817 
00818 private:
00819         unsigned long           f_events;
00820         unsigned char           f_key;
00821         Vectors                 f_actions;
00822 };
00823 
00824 
00825 
00826 
00827 
00828 class Style : public ItemBase
00829 {
00830 public:
00831         enum style_t {
00832                 STYLE_TYPE_UNKNOWN = 0,
00833                 STYLE_TYPE_NO_LINE,
00834                 STYLE_TYPE_NO_FILL,
00835                 STYLE_TYPE_LINE,
00836                 STYLE_TYPE_SOLID,
00837                 STYLE_TYPE_GRADIENT_LINEAR,
00838                 STYLE_TYPE_GRADIENT_RADIAL,
00839                 STYLE_TYPE_BITMAP_TILLED,
00840                 STYLE_TYPE_BITMAP_CLIPPED,
00841                 STYLE_TYPE_BITMAP_HARDEDGE_TILLED,
00842                 STYLE_TYPE_BITMAP_HARDEDGE_CLIPPED,
00843 
00844                 STYLE_TYPE_MATRIX,              // intermediate type used when a matrix is defined before
00845                                                 // a gradient or bitmap info (or the SetType() is called)
00846 
00847                 STYLE_TYPE_max
00848         };
00849 
00850                                 Style(void);
00851 
00852         void                    Reset(void);
00853         style_t                 Type(void) const { return f_style; }
00854         bool                    HasMorph(void) const { return f_morph; }
00855         bool                    HasAlpha(void) const { return f_use_alpha; }
00856         bool                    HasHardEdges(void) const { return f_style == STYLE_TYPE_BITMAP_HARDEDGE_TILLED
00857                                                                 || f_style == STYLE_TYPE_BITMAP_HARDEDGE_CLIPPED; }
00858         void                    SetType(style_t style_type);
00859         void                    SetLine(int index, unsigned short width, const Color& color);
00860         void                    SetColor(int index, const Color& color);
00861         void                    SetGradient(int index, int pos, const Color& color);
00862         void                    SetMatrix(int index, const Matrix& matrix);
00863         void                    SetBitmap(sswf_id_t id_ref);
00864         void                    SetClipping(void);
00865 
00866         void                    Save(Data& data, bool save_alpha, bool save_morph);
00867 
00868 public:
00869         bool                    operator == (const Style& style) const;
00870 
00871 private:
00872         // the style
00873         style_t                 f_style;
00874 
00875         // whether this is for a DefineMorphShape or not
00876         bool                    f_morph;
00877 
00878         // whether some color alpha is not 255
00879         bool                    f_use_alpha;
00880 
00881         // a line width
00882         unsigned short          f_line_width[2];
00883 
00884         // solid fill or line colors
00885         Color                   f_color[2];
00886 
00887         // bitmap reference (its ID)
00888         sswf_id_t               f_bitmap_ref;
00889 
00890         // matrices - 1 or 2 - regular of morph shapes
00891         Matrix                  f_matrix[2];
00892 
00893         // gradient positions & colors - 8 or 16 - regular or morph shapes
00894         signed char             f_gradient;             // largest index used (0..7 only or -1 when no gradient)
00895         unsigned char           f_gradient_pos[16];
00896         Color                   f_gradient_color[16];
00897 };
00898 
00899 
00900 
00901 
00902 
00903 class Edges : public MemoryManager, public ItemBase
00904 {
00905 public:
00906         // This structure is too complex at this time to reproduce
00907         // automatically in C. We do not need it anyway.
00908         struct edge_t {
00909                 long            f_x;
00910                 long            f_y;
00911                 long            f_ctrl_x;               /* LONG_MIN if a line only */
00912                 long            f_ctrl_y;
00913 
00914                                 edge_t(void)
00915                                 {
00916                                         f_x = 0;
00917                                         f_y = 0;
00918                                         f_ctrl_x = LONG_MIN;
00919                                         f_ctrl_y = LONG_MIN;
00920                                 }
00921                                 edge_t(long x, long y)
00922                                 {
00923                                         f_x = x;
00924                                         f_y = y;
00925                                         f_ctrl_x = LONG_MIN;
00926                                         f_ctrl_y = LONG_MIN;
00927                                 }
00928                                 edge_t(long x, long y, long ctrl_x, long ctrl_y)
00929                                 {
00930                                         f_x = x;
00931                                         f_y = y;
00932                                         f_ctrl_x = ctrl_x;
00933                                         f_ctrl_y = ctrl_y;
00934                                 }
00935                                 edge_t(const edge_t& edge)
00936                                 {
00937                                         f_x = edge.f_x;
00938                                         f_y = edge.f_y;
00939                                         f_ctrl_x = edge.f_ctrl_x;
00940                                         f_ctrl_y = edge.f_ctrl_y;
00941                                 }
00942                 edge_t&         operator = (const edge_t& edge)
00943                                 {
00944                                         if(this != &edge) {
00945                                                 f_x = edge.f_x;
00946                                                 f_y = edge.f_y;
00947                                                 f_ctrl_x = edge.f_ctrl_x;
00948                                                 f_ctrl_y = edge.f_ctrl_y;
00949                                         }
00950                                         return *this;
00951                                 }
00952                 bool            IsLine(void) const { return f_ctrl_x == LONG_MIN || f_ctrl_y == LONG_MIN; }
00953         };
00954 
00955 public:
00956         // This should be private but cl (C++ compiler from Mr Microsoft) does not
00957         // understand the use of private too well...
00958         enum {
00959                 // better with a power of two (we use * and / a lot with it!)
00960                 EDGE_BLOCK = 64
00961         };
00962 
00963                                 Edges(void);
00964         virtual                 ~Edges();
00965 
00966         //void                  Reset(void); -- not implemented yet
00967         void                    Set(long x, long y) { edge_t edge(x, y); Set(-1, edge); }
00968         void                    Set(long x, long y, long ctrl_x, long ctrl_y) { edge_t edge(x, y, ctrl_x, ctrl_y); Set(-1, edge); }
00969         void                    Set(int index, long x, long y, long ctrl_x, long ctrl_y) { edge_t edge(x, y, ctrl_x, ctrl_y); Set(index, edge); }
00970 
00971         void                    Save(Data& data, long& x, long& y);
00972 
00973 public:
00974         void                    Set(const edge_t& edge) { Set(-1, edge); }
00975         void                    Set(int index, const edge_t& edge);
00976 
00977 private:
00978         /// One set of edges; when full, allocate another
00979         struct array_edge_t : public ItemBase {
00980                 edge_t          f_edge[EDGE_BLOCK];
00981         };
00982 
00983                                 // no copy operators at this time
00984                                 Edges(const Edges& edges) {}
00985         Edges&                  operator = (const Edges& edges) { return *this; }
00986 
00987         void                    SaveEdge(Data& data, const edge_t& edge, long& x, long& y);
00988 
00989         Vectors                 f_edges;
00990         int                     f_pos;          /* position in the current array */
00991         array_edge_t            f_array;        /* current array; when full, put in f_edges */
00992 };
00993 
00994 
00995 
00996 
00997 
00998 
00999 
01000 // one can't create a tag base, only full qualified
01001 // tags can be created (see below)
01002 class TagHeader;
01003 class TagBase : public MemoryManager
01004 {
01005 public:
01006         // anything in the file is represented by a tag
01007         enum swf_tag_t {
01008                 SWF_TAG_UNKNOWN = -1,           // undefined tag
01009 
01010                 // V1.0
01011                 SWF_TAG_END = 0,                        // mark the end of the flash script
01012                 SWF_TAG_SHOW_FRAME = 1,                 // show the current frame
01013                 SWF_TAG_DEFINE_SHAPE = 2,               // define a vector based shape
01014                 SWF_TAG_PLACE_OBJECT = 4,               // place an object in the current frame
01015                 SWF_TAG_REMOVE_OBJECT = 5,              // remove specified object
01016                 SWF_TAG_DEFINE_BITS = 6,                // JPEG data bit stream (old name, I will obsolete this name at some point)
01017                 SWF_TAG_DEFINE_BITS_JPEG = 6,           // JPEG data bit stream (renaming)
01018                 SWF_TAG_DEFINE_BUTTON = 7,              // define an action button
01019                 SWF_TAG_JPEG_TABLES = 8,                // define the JPEG tables
01020                 SWF_TAG_SET_BACKGROUND_COLOR = 9,       // define the RGB color for the background
01021                 SWF_TAG_DEFINE_FONT = 10,               // links a list of shapes to characters
01022                 SWF_TAG_DEFINE_TEXT = 11,               // define a text to be printed with a font
01023                 SWF_TAG_DO_ACTION = 12,                 // action to perform in this frame
01024                 SWF_TAG_DEFINE_FONT_INFO = 13,          // font metrics
01025 
01026                 // V2.0
01027                 SWF_TAG_DEFINE_SOUND = 14,              // define how a sound effect will be played
01028                 SWF_TAG_START_SOUND = 15,               // start playing a sound effect
01029                 SWF_TAG_DEFINE_BUTTON_SOUND = 17,       // sound effects attached to a button
01030                 SWF_TAG_SOUND_STREAM_HEAD = 18,         // define how a sound effect will be loaded & played
01031                 SWF_TAG_SOUND_STREAM_BLOCK = 19,        // actual sound samples to play (embedded with the rest)
01032                 SWF_TAG_DEFINE_BITS_LOSSLESS = 20,      // a loss less compressed image
01033                 SWF_TAG_DEFINE_BITS_JPEG2 = 21,         // a complete JPEG definition
01034                 SWF_TAG_DEFINE_SHAPE2 = 22,             // define a shape including large number of styles
01035                 SWF_TAG_DEFINE_BUTTON_COLOR_TRANSFORM = 23,     // how a button changes color
01036                 SWF_TAG_PROTECT = 24,                   // whether the resulting file is protected against editing
01037 
01038                 // V3.0
01039                 SWF_TAG_PLACE_OBJECT2 = 26,             // extended place
01040                 SWF_TAG_REMOVE_OBJECT2 = 28,            // simplified remove
01041                 SWF_TAG_DEFINE_SHAPE3 = 32,             // define a shape including RGBA colors
01042                 SWF_TAG_DEFINE_TEXT2 = 33,              // define a text to draw including RGBA colors
01043                 SWF_TAG_DEFINE_BUTTON2 = 34,            // define an action button with RGBA colors and color transformation
01044                 SWF_TAG_DEFINE_BITS_JPEG3 = 35,         // define two JPEG images, one RGB and one GREY used as the alpha channel
01045                 SWF_TAG_DEFINE_BITS_LOSSLESS2 = 36,     // define a loss less image with an alpha channel
01046                 SWF_TAG_DEFINE_SPRITE = 39,             // define a movie as an object to play in another movie
01047                 SWF_TAG_FRAME_LABEL = 43,               // name a place holder in the movie
01048                 SWF_TAG_SOUND_STREAM_HEAD2 = 45,        // define a sound effect with more details for embedded playing
01049                 SWF_TAG_DEFINE_MORPH_SHAPE = 46,        // define a shape which can easilly be changed with a position
01050                 SWF_TAG_DEFINE_FONT2 = 48,              // define a set of fonts
01051                 SWF_TAG_DEFINE_INFO = 49,               // define a comment about the generator, etc.
01052 
01053                 // V4.0
01054                 SWF_TAG_TEXT_FIELD = 37,                // define an area with text which can be edited
01055 
01056                 // V5.0
01057                 SWF_TAG_EXPORT = 56,                    // export a set of definitions to other files
01058                 SWF_TAG_IMPORT = 57,                    // look for definitions from another file (supported up to V7.0)
01059                 SWF_TAG_PROTECT_DEBUG = 58,             // a password to protect debugging of flash movies -- use only in V5.x movies
01060 
01061                 // V6.0
01062                 SWF_TAG_DO_INIT_ACTION = 59,            // action to perform once on specified sprite in this frame
01063                 SWF_TAG_DEFINE_FONT_INFO2 = 62,         // font metrics including language reference
01064                 SWF_TAG_PROTECT_DEBUG2 = 64,            // a password to protect debugging of flash movies
01065 
01066                 // V7.0
01067                 SWF_TAG_SCRIPT_LIMITS = 65,             // the recursive depth and script timeout parameters
01068                 SWF_TAG_SET_TAB_INDEX = 66,             // the depth of an object to be set at the given index (next/previous Tab key positioning)
01069 
01070                 // V8.0
01071                 SWF_TAG_FILE_ATTRIBUTES = 69,           // file attributes appended right after the header (see TagHeader)
01072                 SWF_TAG_PLACE_OBJECT3 = 70,             // place an object with blend mode, filters, bitmap caching
01073                 SWF_TAG_IMPORT2 = 71,                   // look for definitions from another file (only supported tag in V8.0+)
01074                 SWF_TAG_DEFINE_FONT_ALIGN_ZONES = 73,   // define hints to properly align fonts to pixel boundaries
01075                 SWF_TAG_CSM_TEXT_SETTINGS = 74,         // extra information about text (on how to render text)
01076                 SWF_TAG_DEFINE_FONT3 = 75,              // define a set of fonts which uses lines with caps information
01077                 SWF_TAG_METADATA = 77,                  // an XML document describing the Flash movie
01078                 SWF_TAG_DEFINE_SCALING_GRID = 78,       // a grid to avoid scaling the edges of an object
01079                 SWF_TAG_DEFINE_SHAPE4 = 83,             // define a vector based shape with end caps definitions
01080                 SWF_TAG_DEFINE_MORPH_SHAPE2 = 84,       // define a shape which can easilly be changed with a position
01081 
01082                 SWF_TAG_max             // just end this list really
01083         };
01084         typedef long                    swf_type_t;
01085 
01086 #define SWF_TYPE_DEFINE                 0x00000001      // a definition tag, must be in the main movie
01087 #define SWF_TYPE_CONTROL                0x00000002      // a control tag, can be in sprites as well
01088 #define SWF_TYPE_UNIQUE                 0x00000004      // a unique tag, can't be duplicated in the movie (merge if possible)
01089 #define SWF_TYPE_START                  0x00000008      // if present, put it near the start of the movie
01090 #define SWF_TYPE_ONE                    0x00000010      // (should) use at most one per frame
01091 #define SWF_TYPE_REFERENCE              0x00000020      // object includes references to other objects
01092 #define SWF_TYPE_HAS_ID                 0x00000040      // this object was derived from TagBaseID and has an ID
01093 
01094 #define SWF_TYPE_SCRIPT                 0x20000000      // object can accept action scripts
01095 #define SWF_TYPE_SPRITE                 0x40000000      // this is a sprite (can include other tags)
01096 #define SWF_TYPE_HEADER                 0x80000000      // the header
01097 
01098         virtual                         ~TagBase();
01099 
01100         ErrorManager::error_code_t      SaveString(Data& data, const char *string);
01101         static int                      SaveTag(Data& data, swf_tag_t tag, size_t size);
01102 
01103         static long                     SIBitSize(long value);          // return the number of bits necessary to represent a signed integer
01104         static long                     UIBitSize(unsigned long value); // return the number of bits necessary to represent an unsigned integer
01105         static long                     Double2Signed16(double value);  // return a valid fixed value 8.8 bits from a double
01106         static long                     Double2Signed(double value);    // return a valid fixed value 16.16 bits from a double
01107         static double                   Signed2Double(long value);      // return a valid double from a fixed value 16.16 bits
01108 
01109         virtual void                    MinimumVersion(unsigned char version);
01110         virtual unsigned char           Version(void) const;
01111 
01112         const char *                    Name(void) const;       // return the name (type) of this tag
01113         const char *                    Label(void) const;
01114         void                            ResetFrames(void);
01115         void                            ShowFrame(void);
01116         sswf_frame_t                    FrameCount(void) const;
01117 
01118         sswf_frame_t                    WhichFrame(void) const;
01119         void                            SetLabel(const char *label);
01120         TagBase *                       FindLabelledTag(const char *label) const;
01121         TagBase *                       FindTagWithID(sswf_id_t id, bool search_import = true) const;
01122         TagBase *                       Children(void);
01123         TagBase *                       Next(void);
01124         TagBase *                       Previous(void);
01125         TagBase *                       Parent(void);
01126         TagHeader *                     Header(void) const;
01127         virtual ErrorManager::error_code_t OnError(ErrorManager::error_code_t errcode, const char *message, va_list ap) const;
01128 
01129 public:
01130         virtual ErrorManager::error_code_t Save(Data& data) = 0;        // print out a tag in a Data buffer
01131         virtual swf_type_t              TypeFlags(void) const = 0;
01132         virtual ErrorManager::error_code_t OnError(ErrorManager::error_code_t errcode, const char *message, ...) const;
01133 
01134         /** \brief A pointer you are welcome to use
01135          *
01136          * This pointer is public and is provided so users of any one of
01137          * the tag classes can save a pointer back to his/her own
01138          * container.
01139          *
01140          * The library initializes this pointer to NULL on construction
01141          * and never touches it again until the object is deleted.
01142          */
01143         void *                          f_userdata;             // anything you feel necessary!
01144 
01145 protected:
01146                                 // only sub-classes can create a TagBase
01147                                         TagBase(const char *name, TagBase *parent);
01148         virtual ErrorManager::error_code_t PreSave(void);               // called by the header Save() function
01149         virtual ErrorManager::error_code_t PreSave2ndPass(void);        // called by the header Save() function after all the PreSave() were called
01150 
01151         virtual ErrorManager::error_code_t OnNewChild(const char *child_name) const;
01152 
01153 private:
01154         TagBase *                       FindLabel(const TagBase *p, const char *label) const;
01155         TagBase *                       FindID(const TagBase *p, sswf_id_t id, bool search_import) const;
01156 
01157         const char *                    f_name;
01158         char *                          f_label;
01159 
01160         TagBase *                       f_parent;
01161         TagBase *                       f_next;
01162         TagBase *                       f_previous;
01163         TagBase *                       f_children;
01164 
01165         sswf_frame_t                    f_frames;               // total number of frames
01166 };
01167 
01168 
01169 
01170 
01171 
01172 
01173 /********************* TAGS WITHOUT IDs (possibly references though) ****/
01174 
01175 
01176 // The TagHeader includes the TagFileAttributes because
01177 // it is very much like an extension of the header and not
01178 // a separate tag. Also it needs to be unique and saved right
01179 // after the header. Thus it becomes totally transparent to
01180 // you. At this time you have the SetUseNetwork() function to
01181 // set the network flag and add a TagMetadata to set the
01182 // metadata flag (that is automatic.)
01183 class TagHeader : public TagBase, public ErrorManager
01184 {
01185 public:
01186                                         TagHeader(void);
01187         virtual                         ~TagHeader();
01188 
01189         virtual ErrorManager::error_code_t Save(Data& data);
01190         ErrorManager::error_code_t      SaveEncodedString(Data& data, const char *string);
01191         virtual swf_type_t              TypeFlags(void) const;
01192         virtual ErrorManager::error_code_t OnError(ErrorManager::error_code_t errcode, const char *message, va_list ap) const;
01193 
01194         sswf_id_t                       NextID(void);
01195         void                            RemoveID(sswf_id_t id);
01196 
01197 /////////////// SETUP FUNCTIONS
01198         virtual unsigned char           Version(void) const;                            // retrieve the selected version
01199         void                            SetVersion(unsigned char version);              // save a movie with that version if set
01200         void                            SetMinimumVersion(unsigned char version);       // the minimum version you want to support
01201         void                            SetMaximumVersion(unsigned char version);       // the maximum version you want to support
01202 
01203         void                            SetCompress(bool compress = true);
01204         void                            SetAutoOrder(bool auto_order = true);
01205         void                            SetUseNetwork(bool use_network = true);
01206         void                            SetFrame(const SRectangle& rect);
01207         const SRectangle&               Frame(void) const;
01208 
01209         void                            SetOutputEncoding(const char *encoding);
01210         void                            SetRate(float rate);
01211         float                           Rate(void) const;
01212 
01213 public:
01214         virtual void                    MinimumVersion(unsigned char version);          // used internally to determine the minimum version
01215         ErrorManager::error_code_t      DefineMinimumVersion(int& min_version);         // function used to compute the minimum version (a negative result represents an error)
01216         virtual ErrorManager::error_code_t OnError(ErrorManager::error_code_t errcode, const char *message, ...) const;
01217 
01218 protected:
01219         virtual ErrorManager::error_code_t PreSave(void);               // overwrite the base PreSave() so we can know whether we have a Metadata tag
01220         virtual ErrorManager::error_code_t OnNewChild(const char *child_name) const;
01221 
01222 private:
01223         // NOTE: use 0 to get a default version (a version computed from the options used)
01224         unsigned char                   f_version;              // file version (0 to 8 at time of writing)
01225         unsigned char                   f_min_version;          // once the whole file was saved, this is the minimum version we need to use
01226         unsigned char                   f_minimum_version;      // user defined minimum version; the system will start with this minimum version instead of 1
01227         unsigned char                   f_maximum_version;      // user defined maximum version; if a larger version is required, return an error
01228         SRectangle                      f_frame;                // the frame rectangle
01229         float                           f_rate;                 // frames per second (8.8 fixed number in file)
01230         bool                            f_compress;             // compress the resulting movie (v6.x upward)
01231         bool                            f_auto_order;           // automatically order definition tags (discard unused definitions also)
01232         bool                            f_use_network;          // whether the SWF movie is authorized to access the network when launched locally
01233         bool                            f_has_metadata;         // whether the SWF movie includes a TagMetadata
01234         bool                            f_has_jpegtables;       // whether the SWF movie includes a TagJPEGTables
01235         sswf_id_t                       f_next_id;              // returned and then increased when NextID() is called
01236         char *                          f_output_encoding;      // encoding used prior V6.x SWF files
01237         bool                            f_iconvertor_open;      // whether the f_iconvertor is a valid descriptor
01238         iconv_t                         f_iconvertor;           // to convert strings from U18N to user specified encoding
01239 #if DEBUG
01240         bool                            f_saving;               // if true the f_min_version can't be changed ever anymore
01241 #endif
01242 };
01243 
01244 
01245 
01246 
01247 // Actions:
01248 //
01249 //      Whenever you want to create an action, you simply
01250 //      create a new Action object with the proper type
01251 //      unless you need to use an action which requires
01252 //      some additional data. The actions which require
01253 //      additional data are listed here:
01254 //
01255 //      Action Name             Data
01256 //
01257 //      ActionBranch            label
01258 //      ActionCallFrame         <nothing -- this is a mistake from Macromedia>
01259 //      ActionDictionary        strings
01260 //      ActionFunction          name, registers, parameters, body (actions)
01261 //      ActionGoto              frame name, play flag
01262 //      ActionLabel             label (generates no output code)
01263 //      ActionPushData          strings, floats, doubles, etc.
01264 //      ActionSetTarget         target name
01265 //      ActionStoreRegister     register number
01266 //      ActionTry               try, catch and finally actions and identifier/register
01267 //      ActionURL               url, target and method
01268 //      ActionWaitForFrame      frame name, actions
01269 //      ActionWith              actions to execute with the specified object
01270 
01271 
01272 class ActionLabel;
01273 class Action : public ItemBase
01274 {
01275 public:
01276         enum action_t {
01277                 ACTION_UNKNOWN                  = -1,   /* unknown action (invalid) */
01278                 ACTION_LABEL                    = -2,   /* used to mark a position within the actions */
01279                 ACTION_min                      = 0x00, /* the minimum action number */
01280 
01281                 /* all the valid Flash actions */
01282                 ACTION_END                      = 0x00, /* this is automatically added by the higher level Save()'s */
01283                 ACTION_NEXT_FRAME               = 0x04,
01284                 ACTION_PREVIOUS_FRAME           = 0x05,
01285                 ACTION_PLAY                     = 0x06,
01286                 ACTION_STOP                     = 0x07,
01287                 ACTION_TOGGLE_QUALITY           = 0x08,
01288                 ACTION_STOP_SOUND               = 0x09,
01289                 ACTION_ADD                      = 0x0A,
01290                 /*ACTION_SUBSTRACT              = 0x0B, -- this is the wrong spelling, it is not totally obsolete */
01291                 ACTION_SUBTRACT                 = 0x0B,
01292                 ACTION_MULTIPLY                 = 0x0C,
01293                 ACTION_DIVIDE                   = 0x0D,
01294                 ACTION_EQUAL                    = 0x0E,
01295                 ACTION_LESS_THAN                = 0x0F,
01296                 ACTION_LOGICAL_AND              = 0x10,
01297                 ACTION_LOGICAL_OR               = 0x11,
01298                 ACTION_LOGICAL_NOT              = 0x12,
01299                 ACTION_STRING_EQUAL             = 0x13,
01300                 ACTION_STRING_LENGTH            = 0x14,
01301                 ACTION_SUB_STRING               = 0x15,
01302                 ACTION_POP                      = 0x17,
01303                 ACTION_INTEGRAL_PART            = 0x18,
01304                 ACTION_GET_VARIABLE             = 0x1C,
01305                 ACTION_SET_VARIABLE             = 0x1D,
01306                 ACTION_SET_TARGET2              = 0x20,
01307                 ACTION_CONCATENATE              = 0x21,
01308                 ACTION_GET_PROPERTY             = 0x22,
01309                 ACTION_SET_PROPERTY             = 0x23,
01310                 ACTION_DUPLICATE_SPRITE         = 0x24,
01311                 ACTION_REMOVE_SPRITE            = 0x25,
01312                 ACTION_TRACE                    = 0x26,
01313                 ACTION_START_DRAG               = 0x27,
01314                 ACTION_STOP_DRAG                = 0x28,
01315                 ACTION_STRING_LESS_THAN         = 0x29,
01316                 ACTION_THROW                    = 0x2A,
01317                 ACTION_CAST_OBJECT              = 0x2B,
01318                 ACTION_IMPLEMENTS               = 0x2C,
01319                 ACTION_FSCOMMAND2               = 0x2D,
01320                 ACTION_RANDOM                   = 0x30,
01321                 ACTION_MBSTRING_LENGTH          = 0x31,
01322                 ACTION_ORD                      = 0x32,
01323                 ACTION_CHR                      = 0x33,
01324                 ACTION_GET_TIMER                = 0x34,
01325                 ACTION_SUB_MBSTRING             = 0x35,
01326                 ACTION_MBORD                    = 0x36,
01327                 ACTION_MBCHR                    = 0x37,
01328                 ACTION_DELETE                   = 0x3A,
01329                 ACTION_SET_LOCAL_VAR            = 0x3C,
01330                 ACTION_SET_LOCAL_VARIABLE       = 0x3C,
01331                 ACTION_CALL_FUNCTION            = 0x3D,
01332                 ACTION_RETURN                   = 0x3E,
01333                 ACTION_MODULO                   = 0x3F,
01334                 ACTION_NEW                      = 0x40,
01335                 ACTION_DECLARE_LOCAL_VAR        = 0x41,
01336                 ACTION_DECLARE_LOCAL_VARIABLE   = 0x41,
01337                 ACTION_DECLARE_ARRAY            = 0x42,
01338                 ACTION_DECLARE_OBJECT           = 0x43,
01339                 ACTION_TYPE_OF                  = 0x44,
01340                 ACTION_GET_TARGET               = 0x45,
01341                 ACTION_ENUMERATE                = 0x46,
01342                 ACTION_ADD_TYPED                = 0x47,
01343                 ACTION_LESS_THAN_TYPED          = 0x48,
01344                 ACTION_EQUAL_TYPED              = 0x49,
01345                 ACTION_NUMBER                   = 0x4A,
01346                 ACTION_STRING                   = 0x4B,
01347                 ACTION_DUPLICATE                = 0x4C,
01348                 ACTION_SWAP                     = 0x4D,
01349                 ACTION_GET_MEMBER               = 0x4E,
01350                 ACTION_SET_MEMBER               = 0x4F,
01351                 ACTION_INCREMENT                = 0x50,
01352                 ACTION_DECREMENT                = 0x51,
01353                 ACTION_CALL_METHOD              = 0x52,
01354                 ACTION_NEW_METHOD               = 0x53,
01355                 ACTION_INSTANCE_OF              = 0x54,
01356                 ACTION_ENUMERATE_OBJECT         = 0x55,
01357                 ACTION_AND                      = 0x60,
01358                 ACTION_OR                       = 0x61,
01359                 ACTION_XOR                      = 0x62,
01360                 ACTION_SHIFT_LEFT               = 0x63,
01361                 ACTION_SHIFT_RIGHT              = 0x64,
01362                 ACTION_SHIFT_RIGHT_UNSIGNED     = 0x65,
01363                 ACTION_STRICT_EQUAL             = 0x66,
01364                 ACTION_GREATER_THAN_TYPED       = 0x67,
01365                 ACTION_STRING_GREATER_THAN      = 0x68,
01366                 ACTION_EXTENDS                  = 0x69,
01367                 ACTION_GOTO_FRAME               = 0x81,
01368                 ACTION_URL                      = 0x83,
01369                 ACTION_STORE_REGISTER           = 0x87,
01370                 ACTION_DECLARE_DICTIONARY       = 0x88,
01371                 ACTION_STRICT_MODE              = 0x89,
01372                 ACTION_WAIT_FOR_FRAME           = 0x8A,
01373                 ACTION_SET_TARGET               = 0x8B,
01374                 ACTION_GOTO_LABEL               = 0x8C,
01375                 ACTION_WAIT_FOR_FRAME2          = 0x8D,
01376                 ACTION_DECLARE_FUNCTION2        = 0x8E,
01377                 ACTION_TRY                      = 0x8F,
01378                 ACTION_WITH                     = 0x94,
01379                 ACTION_PUSH_DATA                = 0x96,
01380                 ACTION_BRANCH_ALWAYS            = 0x99,
01381                 ACTION_URL2                     = 0x9A,
01382                 ACTION_DECLARE_FUNCTION         = 0x9B,
01383                 ACTION_BRANCH_IF_TRUE           = 0x9D,
01384                 ACTION_CALL_FRAME               = 0x9E,
01385                 ACTION_GOTO_EXPRESSION          = 0x9F,
01386 
01387                 ACTION_max              = 0xFF          /* the maximum action number */
01388         };
01389 
01390                                         Action(TagBase *tag, action_t action);
01391         virtual                         ~Action() {}
01392 
01393         virtual Action *                Duplicate(void) const;
01394         unsigned long                   Offset(void) const { return f_offset; }
01395         virtual unsigned char           Version(void) const { return f_min_version; }
01396 
01397         ErrorManager::error_code_t      Save(Data& data);
01398         virtual Vectors *               SubList(void);
01399         ErrorManager::error_code_t      SaveList(const Vectors *list, Data& data, const Vectors *extra = 0);
01400         static int                      MinimumListVersion(const Vectors& list);
01401         static int                      GetMaximumRegister(const Vectors& list);
01402         static ActionLabel *            FindLabel(const Vectors& list, const char *label);
01403 
01404 public:
01405         ErrorManager::error_code_t      OnError(ErrorManager::error_code_t errcode, const char *message, ...) const;
01406 
01407 protected:
01408         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
01409         virtual ErrorManager::error_code_t Save2ndPass(const Vectors& list, Data& data);
01410         virtual int                     GetMaxRegister(void) const { return 0; }
01411         ErrorManager::error_code_t      SaveString(Data& data, const char *string);
01412         TagBase *                       Tag(void) const { return const_cast<TagBase *>(f_tag); }
01413 
01414         const action_t                  f_action;
01415         unsigned long                   f_offset;               /* offset where this tag is being saved (saved for branches and with statments) */
01416 
01417 private:
01418 #if DEBUG
01419         /*
01420          * Forbid copies (only in DEBUG mode so we don't have extra functions
01421          * for nothing otherwise) If you need a copy, use the Duplicate() instead
01422          */
01423                                         Action(const Action& action);
01424         Action&                         operator = (const Action& action);
01425 #endif
01426 
01427         TagBase *                       f_tag;
01428         unsigned char                   f_min_version;          /* minimum version to use this action */
01429 };
01430 
01431 
01432 class ActionBranch : public Action, public MemoryManager
01433 {
01434 public:
01435         /* one of:
01436          *      ACTION_BRANCH_ALWAYS
01437          *      ACTION_BRANCH_IF_TRUE
01438          */
01439                                         ActionBranch(TagBase *tag, action_t action = ACTION_BRANCH_ALWAYS);
01440 
01441         void                            SetLabel(const char *label);
01442 
01443 private:
01444         virtual Action *                Duplicate(void) const;
01445         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
01446         virtual ErrorManager::error_code_t Save2ndPass(const Vectors& list, Data& data);
01447 
01448         char *                          f_label;
01449 };
01450 
01451 
01452 
01453 class ActionCallFrame : public Action, public MemoryManager
01454 {
01455 public:
01456                                         ActionCallFrame(TagBase *tag);
01457 
01458 private:
01459         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
01460 };
01461 
01462 
01463 
01464 class ActionDictionary : public Action, public MemoryManager
01465 {
01466 public:
01467                                         ActionDictionary(TagBase *tag);
01468 
01469         void                            AddString(const char *string);
01470 
01471 private:
01472         /// Holds one dictionary string
01473         struct string_t : public ItemBase
01474         {
01475                 /// Pointer to the dictionary string
01476                 char *          f_string;
01477         };
01478 
01479         virtual Action *                Duplicate(void) const;
01480         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
01481 
01482         /// Array of dictionary strings
01483         Vectors                         f_strings;
01484 };
01485 
01486 
01487 
01488 class ActionFunction : public Action, public MemoryManager
01489 {
01490 public:
01491         /* one of:
01492          *      ACTION_DECLARE_FUNCTION
01493          *      ACTION_DECLARE_FUNCTION2
01494          */
01495                                         ActionFunction(TagBase *tag, action_t action = ACTION_DECLARE_FUNCTION);
01496 
01497         enum action_function_t {
01498                 ACTION_FUNCTION_LOAD_THIS          = 0x0001,
01499                 ACTION_FUNCTION_SUPPRESS_THIS      = 0x0002,
01500                 ACTION_FUNCTION_LOAD_ARGUMENTS     = 0x0004,
01501                 ACTION_FUNCTION_SUPPRESS_ARGUMENTS = 0x0008,
01502                 ACTION_FUNCTION_LOAD_SUPER         = 0x0010,
01503                 ACTION_FUNCTION_SUPPRESS_SUPER     = 0x0020,
01504                 ACTION_FUNCTION_LOAD_ROOT          = 0x0040,
01505                 ACTION_FUNCTION_LOAD_PARENT        = 0x0080,
01506                 ACTION_FUNCTION_LOAD_GLOBAL        = 0x0100
01507         };
01508 
01509         void                            SetName(const char *name);
01510         void                            SetRegistersCount(unsigned int count);
01511         void                            AddParameter(const char *name, int register_number = -1);
01512         void                            AddAction(Action *action);
01513         virtual Vectors *               SubList(void);
01514 
01515         // flags for the ASSetPropFlags(obj, props, flags [, allow])
01516         // (see include/sswf/scripts/global/extensions.asc)
01517         enum as_set_prop_flags_t {
01518                 PROP_FLAG_IS_HIDDEN = 1,
01519                 PROP_FLAG_CAN_DELETE = 2,
01520                 PROP_FLAG_CAN_OVERWRITE = 4
01521         };
01522 
01523 private:
01524         /// Hold the parameters name and register number
01525         struct parameter_t : public ItemBase
01526         {
01527                 /// The name of the parameter
01528                 char *          f_name;
01529                 /// The register number (-1 means no register and 0 means auto-assign the number)
01530                 int             f_register_number;      // if -1, use the name, if 0, auto-assign
01531         };
01532 
01533         virtual Action *                Duplicate(void) const;
01534         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
01535 
01536         char *                          f_name;
01537         unsigned int                    f_registers_count;
01538         unsigned short                  f_flags;
01539         Vectors                         f_parameters;
01540         Vectors                         f_actions;
01541 };
01542 
01543 
01544 
01545 class ActionGoto : public Action, public MemoryManager
01546 {
01547 public:
01548         /* one of:
01549          *      ACTION_GOTO_FRAME
01550          *      ACTION_GOTO_LABEL
01551          *      ACTION_GOTO_EXPRESSION
01552          */
01553                                         ActionGoto(TagBase *tag, action_t action = ACTION_GOTO_FRAME);
01554 
01555         void                            SetFrameName(const char *frame_name);
01556         void                            SetPlay(bool play) { f_play = play; }
01557 
01558 private:
01559         virtual Action *                Duplicate(void) const;
01560         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
01561 
01562         char *                          f_frame_name;
01563         bool                            f_play;
01564 };
01565 
01566 
01567 
01568 class ActionLabel : public Action, public MemoryManager
01569 {
01570 public:
01571                                         ActionLabel(TagBase *tag);
01572 
01573         void                            SetLabel(const char *label);
01574         const char *                    GetLabel(void) const { return f_label; }
01575 
01576 private:
01577         virtual Action *                Duplicate(void) const;
01578         // we shall never even try to save a label! so no SaveData() is necessary
01579 
01580         char *                          f_label;
01581 };
01582 
01583 
01584 
01585 
01586 class ActionPushData : public Action, public MemoryManager
01587 {
01588 public:
01589                                         ActionPushData(TagBase *tag);
01590                                         
01591         void                            AddEmptyString(void) { AddString(0); }
01592         void                            AddString(const char *string);
01593         void                            AddTrue(void) { AddBoolean(true); }
01594         void                            AddFalse(void) { AddBoolean(false); }
01595         void                            AddBoolean(bool value);
01596         void                            AddInteger(long value);
01597         void                            AddFloat(float value);
01598         void                            AddDouble(double value);
01599         void                            AddNull(void);
01600         void                            AddLookup(unsigned short index);
01601         void                            AddRegister(unsigned char reg_index);
01602         void                            AddUndefined(void);
01603 
01604 private:
01605         enum action_immediate_type_t
01606         {
01607                 ACTION_IMMEDIATE_TYPE_UNKNOWN           = -1,
01608                 ACTION_IMMEDIATE_TYPE_STRING            = 0x00,
01609                 ACTION_IMMEDIATE_TYPE_FLOAT             = 0x01,
01610                 ACTION_IMMEDIATE_TYPE_NULL              = 0x02,
01611                 ACTION_IMMEDIATE_TYPE_UNDEFINED         = 0x03,
01612                 ACTION_IMMEDIATE_TYPE_REGISTER          = 0x04,
01613                 ACTION_IMMEDIATE_TYPE_BOOLEAN           = 0x05,
01614                 ACTION_IMMEDIATE_TYPE_DOUBLE            = 0x06,
01615                 ACTION_IMMEDIATE_TYPE_INTEGER           = 0x07,
01616                 ACTION_IMMEDIATE_TYPE_LOOKUP            = 0x08,
01617                 ACTION_IMMEDIATE_TYPE_LOOKUP_LARGE      = 0x09
01618         };
01619         /// One data entry of a PushData action
01620         struct action_immediate_t : public ItemBase
01621         {
01622                 action_immediate_type_t f_type;
01623                 union
01624                 {
01625                         char *          f_string;
01626                         float           f_float32;
01627                         double          f_float64;
01628                         bool            f_boolean;
01629                         long            f_integer32;
01630                         unsigned short  f_lookup;
01631                         unsigned char   f_register;
01632                 } f_data;
01633 
01634                 action_immediate_t(action_immediate_type_t type)
01635                 {
01636                         f_type = type;
01637                         memset(&f_data, 0, sizeof(f_data));
01638                 }
01639         };
01640 
01641         virtual Action *                Duplicate(void) const;
01642         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
01643         virtual int                     GetMaxRegister(void) const;
01644 
01645         Vectors                         f_data;
01646 };
01647 
01648 
01649 
01650 
01651 class ActionSetTarget : public Action, public MemoryManager
01652 {
01653 public:
01654                                         ActionSetTarget(TagBase *tag);
01655 
01656         void                            SetTarget(const char *target);
01657 
01658 private:
01659         virtual Action *                Duplicate(void) const;
01660         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
01661 
01662         char *                          f_target;
01663 };
01664 
01665 
01666 class ActionStoreRegister : public Action, public MemoryManager
01667 {
01668 public:
01669                                         ActionStoreRegister(TagBase *tag);
01670 
01671         void                            SetRegister(unsigned char reg);
01672 
01673 private:
01674         virtual Action *                Duplicate(void) const;
01675         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
01676         virtual int                     GetMaxRegister(void) const;
01677 
01678         unsigned char                   f_reg;
01679 };
01680 
01681 
01682 class ActionStrictMode : public Action, public MemoryManager
01683 {
01684 public:
01685                                         ActionStrictMode(TagBase *tag);
01686 
01687         void                            SetStrict(bool strict);
01688 
01689 private:
01690         virtual Action *                Duplicate(void) const;
01691         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
01692 
01693         bool                            f_strict;
01694 };
01695 
01696 
01697 class ActionTry : public Action, public MemoryManager
01698 {
01699 public:
01700                                         ActionTry(TagBase *tag);
01701                                         
01702         void                            AddTryAction(Action *action);
01703         void                            AddCatchAction(Action *action);
01704         void                            AddFinallyAction(Action *action);
01705         void                            SetIdentifier(int register_number);             // Catch(#)
01706         void                            SetIdentifier(const char *variable_name);       // Catch(var)
01707                                         
01708         Vectors *                       SubListTry(void);
01709         Vectors *                       SubListCatch(void);
01710         Vectors *                       SubListFinally(void);
01711 
01712 private:
01713         virtual Action *                Duplicate(void) const;
01714         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
01715         virtual int                     GetMaxRegister(void) const;
01716         virtual unsigned char           Version(void) const;
01717 
01718         int                             f_register;
01719         char *                          f_variable_name;
01720         bool                            f_has_catch;
01721         bool                            f_has_finally;
01722         Vectors                         f_actions_try;
01723         Vectors                         f_actions_catch;
01724         Vectors                         f_actions_finally;
01725 };
01726 
01727 
01728 
01729 class ActionURL : public Action, public MemoryManager
01730 {
01731 public:
01732         /* one of:
01733          *      ACTION_URL
01734          *      ACTION_URL2
01735          */
01736                                         ActionURL(TagBase *tag, action_t action = ACTION_URL);
01737 
01738         enum url_method_t {
01739                 URL_METHOD_UNDEFINED = -1,
01740                 URL_METHOD_NOVARIABLE = 0,
01741                 URL_METHOD_NOVARIABLES = URL_METHOD_NOVARIABLE,
01742                 URL_METHOD_GET = 1,
01743                 URL_METHOD_POST = 2
01744         };
01745 
01746         void                            SetURL(const char *url, const char *target);
01747         void                            SetMethod(url_method_t method);
01748 
01749 private:
01750         virtual Action *                Duplicate(void) const;
01751         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
01752 
01753         char *                          f_url;
01754         char *                          f_target;
01755         url_method_t                    f_method;
01756 };
01757 
01758 
01759 
01760 class ActionWaitForFrame : public Action, public MemoryManager
01761 {
01762 public:
01763         /* one of:
01764          *      ACTION_WAIT_FOR_FRAME
01765          *      ACTION_WAIT_FOR_FRAME2
01766          */
01767                                         ActionWaitForFrame(TagBase *tag, action_t action = ACTION_WAIT_FOR_FRAME);
01768 
01769         void                            SetFrameName(const char *name);
01770         void                            AddAction(Action *action);
01771         virtual Vectors *               SubList(void);
01772 
01773 private:
01774         virtual Action *                Duplicate(void) const;
01775         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
01776 
01777         Vectors                         f_actions;      // actions executed once frame is loaded
01778         char *                          f_frame_name;
01779 };
01780 
01781 
01782 
01783 class ActionWith : public Action, public MemoryManager
01784 {
01785 public:
01786                                         ActionWith(TagBase *tag);
01787 
01788         void                            AddAction(Action *action);
01789         virtual Vectors *               SubList(void);
01790 
01791 private:
01792         virtual Action *                Duplicate(void) const;
01793         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
01794 
01795         Vectors                         f_actions;
01796 };
01797 
01798 
01799 
01800 
01801 
01802 
01803 class TagDoAction : public TagBase
01804 {
01805 public:
01806         /* one of:
01807          *      SWF_TAG_DO_ACTION
01808          *      SWF_TAG_DO_INIT_ACTION (uses this when sprite ID was defined)
01809          */
01810                                 TagDoAction(TagBase *parent);
01811 
01812         virtual ErrorManager::error_code_t Save(Data& data);
01813         virtual swf_type_t      TypeFlags(void) const;
01814 
01815 /////////////// SETUP FUNCTIONS
01816         void                    SetAction(const Action& action);
01817         void                    SetSprite(sswf_id_t sprite);
01818         Vectors&                Actions(void) { return f_actions; }
01819 
01820 private:
01821         virtual ErrorManager::error_code_t PreSave(void);               // called by the header Save() function
01822 
01823         sswf_id_t               f_sprite;
01824         Vectors                 f_actions;
01825 };
01826 
01827 
01828 
01829 
01830 
01831 class TagMetadata : public TagBase
01832 {
01833 public:
01834                                 TagMetadata(TagBase *parent);
01835 
01836         virtual ErrorManager::error_code_t Save(Data& data);
01837         virtual swf_type_t      TypeFlags(void) const;
01838 
01839 /////////////// SETUP FUNCTIONS
01840         // You should not call all of these functions.
01841         // There are three groups decreasing priority:
01842         //
01843         //  o Read the RDF from a file
01844         //
01845         //      SetFilename()
01846         //
01847         //  o Define the RDF verbatim
01848         //
01849         //      SetMetadata()
01850         //
01851         //  o Set values to be saved in an RDF built by SSWF
01852         //
01853         //      SetTitle()
01854         //      SetDescription()
01855         //      SetAuthor()
01856         //      SetPublisher()
01857         //      SetCopyright()
01858         //      SetURL()
01859         //
01860         void                    SetFilename(const char *filename);
01861         void                    SetMetadata(const char *xml);
01862         void                    SetTitle(const char *title);
01863         void                    SetDescription(const char *description);
01864         void                    SetAuthor(const char *description);
01865         void                    SetPublisher(const char *publisher);
01866         void                    SetCopyright(const char *copyright);
01867         void                    SetURL(const char *url);
01868 
01869 private:
01870         virtual ErrorManager::error_code_t PreSave(void);               // called by the header Save() function
01871 
01872         char *                  f_xml;
01873         char *                  f_filename;
01874         char *                  f_title;
01875         char *                  f_description;
01876         char *                  f_author;
01877         char *                  f_publisher;
01878         char *                  f_copyright;
01879         char *                  f_url;
01880 };
01881 
01882 
01883 
01884 
01885 
01886 class TagPlace : public TagBase
01887 {
01888 public:
01889                                         TagPlace(TagBase *parent);
01890 
01891         virtual ErrorManager::error_code_t Save(Data& data);
01892         virtual swf_type_t              TypeFlags(void) const;
01893 
01894 /////////////// SETUP FUNCTIONS
01895         void                            SetObjectID(sswf_id_t id);
01896         void                            SetDepth(int depth);
01897         void                            SetClip(int depth);
01898         void                            SetMatrix(const Matrix& matrix);
01899         void                            SetColorTransform(const ColorTransform& color_transform);
01900         void                            SetName(const char *name);
01901         void                            SetMorphPosition(int position);
01902         void                            SetBlendMode(const BlendMode& blend_mode);
01903         void                            SetBitmapCaching(int bitmap_caching);
01904         void                            Replace(void);
01905         void                            Place(void);
01906         bool                            AddEvent(Event *event);
01907 
01908 private:
01909         virtual ErrorManager::error_code_t PreSave(void);               // called by the header Save() function
01910 
01911         bool                            f_id_defined;
01912         sswf_id_t                       f_id;
01913         int                             f_replace;
01914         int                             f_depth;
01915         int                             f_clip_depth;
01916         char *                          f_name;
01917         unsigned long                   f_events_all_flags;
01918         int                             f_position;             // morph position
01919         BlendMode                       f_blend_mode;
01920         int                             f_bitmap_caching;
01921         bool                            f_has_matrix;
01922         Matrix                          f_matrix;
01923         ColorTransform                  f_color_transform;
01924         Vectors                         f_events;
01925 };
01926 
01927 
01928 
01929 class TagRemove : public TagBase
01930 {
01931 public:
01932                                 TagRemove(TagBase *parent);
01933 
01934         virtual ErrorManager::error_code_t Save(Data& data);
01935         virtual swf_type_t      TypeFlags(void) const;
01936 
01937 /////////////// SETUP FUNCTIONS
01938         void                    SetDepth(int depth) { f_depth = depth; }
01939         void                    SetObjectID(sswf_id_t id) { f_id = id; }
01940 
01941 private:
01942         virtual ErrorManager::error_code_t PreSave(void);               // called by the header Save() function
01943 
01944         int                     f_depth;
01945         sswf_id_t               f_id;
01946 };
01947 
01948 
01949 
01950 class TagScriptLimits : public TagBase
01951 {
01952 public:
01953                                 TagScriptLimits(TagBase *parent);
01954 
01955         virtual ErrorManager::error_code_t Save(Data& data);
01956         virtual swf_type_t      TypeFlags(void) const;
01957 
01958 /////////////// SETUP FUNCTIONS
01959         void                    SetMaxRecursionDepth(int depth);
01960         void                    SetTimeoutSeconds(int timeout);
01961         int                     GetMaxRecursionDepth(void) const;
01962         int                     GetTimeoutSeconds(void) const;
01963 
01964 private:
01965         virtual ErrorManager::error_code_t PreSave(void);
01966 
01967         int                     f_depth;
01968         int                     f_timeout;
01969 };
01970 
01971 
01972 
01973 class TagSetTabIndex : public TagBase
01974 {
01975 public:
01976                                 TagSetTabIndex(TagBase *parent);
01977 
01978         virtual ErrorManager::error_code_t Save(Data& data);
01979         virtual swf_type_t      TypeFlags(void) const;
01980 
01981 /////////////// SETUP FUNCTIONS
01982         void                    SetDepth(int depth);
01983         void                    SetIndex(int timeout);
01984         int                     GetDepth(void) const;
01985         int                     GetIndex(void) const;
01986 
01987 private:
01988         virtual ErrorManager::error_code_t PreSave(void);
01989 
01990         int                     f_depth;
01991         int                     f_index;
01992 };
01993 
01994 
01995 
01996 class TagSetBackgroundColor : public TagBase
01997 {
01998 public:
01999                                 TagSetBackgroundColor(TagBase *parent);
02000 
02001         virtual ErrorManager::error_code_t Save(Data& data);
02002         virtual swf_type_t      TypeFlags(void) const;
02003 
02004 /////////////// SETUP FUNCTIONS
02005         void                    SetColor(Color& color);
02006         Color&                  GetColor(void);
02007 
02008 private:
02009         Color                   f_color;
02010 };
02011 
02012 
02013 class TagShowFrame : public TagBase
02014 {
02015 public:
02016                                 TagShowFrame(TagBase *parent);
02017 
02018         virtual ErrorManager::error_code_t Save(Data& data);
02019         virtual swf_type_t      TypeFlags(void) const;
02020 };
02021 
02022 
02023 class TagEnd : public TagBase
02024 {
02025 public:
02026                                 TagEnd(TagBase *parent);
02027 
02028         virtual ErrorManager::error_code_t Save(Data& data);
02029         virtual swf_type_t      TypeFlags(void) const;
02030 };
02031 
02032 
02033 class TagFrameLabel : public TagBase 
02034 {
02035 public:
02036                                 TagFrameLabel(TagBase *parent);
02037 
02038         virtual ErrorManager::error_code_t Save(Data& data);
02039         virtual swf_type_t      TypeFlags(void) const;
02040 
02041 /////////////// SETUP FUNCTIONS
02042         void                    SetFrameLabel(const char *label);
02043 
02044 private:
02045         virtual ErrorManager::error_code_t PreSave(void);
02046 
02047         char *                  f_label;
02048 };
02049 
02050 
02051 
02052 class TagExport : public TagBase 
02053 {
02054 public:
02055                                 TagExport(TagBase *parent);
02056 
02057         virtual ErrorManager::error_code_t Save(Data& data);
02058         virtual swf_type_t      TypeFlags(void) const;
02059 
02060 /////////////// SETUP FUNCTIONS
02061         void                    SetObject(sswf_id_t id, const char *name);
02062 
02063 private:
02064         /// One export entry with the identifier of the object to export and the export name
02065         struct export_t : public ItemBase
02066         {
02067                 sswf_id_t       f_id;
02068                 const char *    f_name;
02069         };
02070 
02071         virtual ErrorManager::error_code_t PreSave(void);
02072 
02073         Vectors                 f_objects;
02074 };
02075 
02076 
02077 
02078 class TagImport : public TagBase 
02079 {
02080 public:
02081         /* one of:
02082          *      SWF_TAG_IMPORT (movies before version 8)
02083          *      SWF_TAG_IMPORT2 (since version 8)
02084          */
02085                                 TagImport(TagBase *parent);
02086 
02087         virtual ErrorManager::error_code_t Save(Data& data);
02088         virtual swf_type_t      TypeFlags(void) const;
02089         const char *            HasID(sswf_id_t id) const;
02090         sswf_id_t               HasName(const char *name) const;
02091 
02092 /////////////// SETUP FUNCTIONS
02093         void                    SetURL(const char *url);
02094         void                    SetFilename(const char *filename);
02095         void                    AddName(const char *name, const char *type);
02096 
02097 private:
02098         /// Defines each imported object identifier, name and type
02099         struct import_t : public ItemBase
02100         {
02101                 sswf_id_t       f_id;           // dynamically allocated
02102                 const char *    f_name;         // external symbol name
02103                 const char *    f_type;         // user specified type
02104         };
02105 
02106         virtual ErrorManager::error_code_t PreSave(void);
02107 
02108         char *                  f_url;
02109         char *                  f_filename;
02110         Vectors                 f_objects;
02111 };
02112 
02113 
02114 
02115 class TagProtect : public TagBase 
02116 {
02117 public:
02118         /* one of:
02119          *      SWF_TAG_PROTECT
02120          *      SWF_TAG_PROTECT_DEBUG
02121          *      SWF_TAG_PROTECT_DEBUG2
02122          *      (now with automatic selection only)
02123          */
02124                                 TagProtect(TagBase *parent);
02125 
02126         virtual ErrorManager::error_code_t Save(Data& data);
02127         virtual swf_type_t      TypeFlags(void) const;
02128 
02129 /////////////// SETUP FUNCTIONS
02130         void                    SetPassword(const char *password);
02131         void                    SetEncodedPassword(const char *password);
02132 
02133 private:
02134         virtual ErrorManager::error_code_t PreSave(void);
02135 
02136         char *                  f_password;
02137 };
02138 
02139 
02140 
02141 class TagInfo : public TagBase 
02142 {
02143 public:
02144                                 TagInfo(TagBase *parent);
02145 
02146         virtual ErrorManager::error_code_t Save(Data& data);
02147         virtual swf_type_t      TypeFlags(void) const;
02148 
02149 /////////////// SETUP FUNCTIONS
02150         void                    SetInfo(const char *info);
02151         void                    SetVersion(long version);
02152 
02153 private:
02154         virtual ErrorManager::error_code_t PreSave(void);
02155 
02156         char *                  f_info;
02157         long                    f_version;
02158 };
02159 
02160 
02161 class TagStartSound : public TagBase 
02162 {
02163 public:
02164                                 TagStartSound(TagBase *parent);
02165 
02166         virtual ErrorManager::error_code_t Save(Data& data);
02167         virtual swf_type_t      TypeFlags(void) const;
02168 
02169         void                    SetInfo(SoundInfo *sound_info);
02170 
02171 private:
02172         virtual ErrorManager::error_code_t PreSave(void);
02173 
02174         SoundInfo *             f_sound_info;
02175 };
02176 
02177 
02178 
02179 
02180 class TagScalingGrid
02181 {
02182 public:
02183         virtual                 ~TagScalingGrid();
02184 
02185         ErrorManager::error_code_t GridSave(Data& data, sswf_id_t id);
02186         ErrorManager::error_code_t GridPreSave(void);
02187 
02188         const SRectangle&       Grid(void) const;
02189 
02190 /////////////// SETUP FUNCTIONS
02191         void                    SetGrid(const SRectangle& rect);
02192 
02193 private:
02194         SRectangle              f_grid;
02195 };
02196 
02197 
02198 
02199 
02200 
02201 
02202 
02203 
02204 /****************************************/
02205 /****************************************/
02206 /********************* TAGS WITH IDs ****/
02207 /****************************************/
02208 /****************************************/
02209 
02210 class TagBaseID : public TagBase
02211 {
02212 public:
02213         virtual                 ~TagBaseID();
02214 
02215         virtual sswf_id_t       Identification(void) const;
02216         void                    NoIdentification(void);
02217         bool                    HasIdentification(void) const;
02218 
02219         int                     SaveID(Data& data) const;
02220 
02221 public:
02222                                 TagBaseID(const char *name, TagBase *parent);
02223 
02224 private:
02225         sswf_id_t               f_id;
02226         bool                    f_identified;
02227 };
02228 
02229 
02230 
02231 
02232 class TagButton : public TagBaseID, public TagScalingGrid
02233 {
02234 public:
02235                                 TagButton(TagBase *parent);
02236 
02237         virtual ErrorManager::error_code_t Save(Data& data);
02238         virtual swf_type_t      TypeFlags(void) const;
02239 
02240 /////////////// SETUP FUNCTIONS
02241         void                    SetState(const State& state);
02242         void                    SetAction(const Action& action);
02243         void                    SetMenu(bool menu = true);
02244         Vectors&                Actions(void);
02245         bool                    AddEvent(Event *event);
02246 
02247 private:
02248         virtual ErrorManager::error_code_t PreSave(void);               // called by the header Save() function
02249 
02250         bool                    f_save_button2;
02251         bool                    f_menu;                 // whether to track as a menu
02252         Vectors                 f_states;
02253         Vectors                 f_actions;
02254         Vectors                 f_events;
02255 };
02256 
02257 
02258 class TagShape;
02259 class TagFont : public TagBaseID
02260 {
02261 public:
02262         enum font_type_t {
02263                 FONT_TYPE_BEST = 0,             // create the best possible result
02264                 FONT_TYPE_ASCII,
02265                 FONT_TYPE_UNICODE,
02266                 FONT_TYPE_SHIFTJIS,
02267         };
02268         enum font_language_t {
02269                 FONT_LANGUAGE_UNKNOWN                   = -1,
02270                 FONT_LANGUAGE_LOCALE                    = 0,
02271                 FONT_LANGUAGE_LATIN                     = 1,
02272                 FONT_LANGUAGE_JAPANESE                  = 2,
02273                 FONT_LANGUAGE_KOREAN                    = 3,
02274                 FONT_LANGUAGE_SIMPLIFIED_CHINESE        = 4,
02275                 FONT_LANGUAGE_TRADITIONAL_CHINESE       = 5,
02276 
02277                 FONT_LANGUAGE_max                       = 6
02278         };
02279 
02280 #define SSWF_FONT_SPACE_INDEX           static_cast<unsigned long>(-1)
02281 
02282         struct font_info_t {
02283                 sswf_ucs4_t             f_glyph;        // the glyph name ('A', 'B', ...)
02284                 unsigned short          f_saved_index;  // index in the SWF file (within the referenced glyphs)
02285                 unsigned long           f_index;        // index in the memory array (of all glyphs)
02286                 unsigned long           f_position;     // closest position or exact position in the list of glyphs
02287                 long                    f_advance;      // the advance in TWIPs
02288                 bool                    f_is_empty;     // if true, it's like a space (i.e. invisible)
02289         };
02290 
02291                                 TagFont(TagBase *parent);
02292 
02293         virtual ErrorManager::error_code_t Save(Data& data);
02294         virtual swf_type_t      TypeFlags(void) const;
02295         void                    GlyphInfo(font_info_t& info) const;
02296         bool                    HasGlyph(void) const;
02297         bool                    FindGlyph(font_info_t& info, bool mark_empty_in_use = false) const;
02298         const char *            FontName(void) const;
02299         long                    DefaultAscent(void) const;
02300         long                    DefaultDescent(void) const;
02301         long                    DefaultLeadingHeight(void) const;
02302         static font_language_t  StringToLanguage(const char *language);
02303         static const char *     LanguageToString(font_language_t language);
02304 
02305 /////////////// SETUP FUNCTIONS
02306         //
02307         // WARNING: The pointers of the shape referenced are kept as is (the shape is not
02308         //          copied in any way)
02309         //
02310         //          So you have to make sure that these shapes still exist at the time
02311         //          the Save() is called.
02312         //
02313         void                    AddGlyph(sswf_ucs4_t name, const TagBase *ref, long advance = LONG_MIN);
02314         void                    SetName(const char *font_name);
02315         void                    SetLayout(long ascent, long descent, long leading_height);
02316         void                    SetDefaultAdvance(long advance);
02317         void                    SetSpaceAdvance(long advance);
02318         void                    SetType(font_type_t type);
02319         void                    SetLanguage(font_language_t language);
02320         void                    SetBold(bool bold);
02321         void                    SetItalic(bool italic);
02322         void                    SetWide(bool wide);
02323         ErrorManager::error_code_t SetUsedGlyphs(const sswf_ucs4_t *used_glyphs, bool mark_empty_in_use = false);
02324         void                    SetUsedByEditText(bool used = true);
02325         void                    AddKern(sswf_ucs4_t code0, sswf_ucs4_t code1, long advance);
02326 
02327 private:
02328         struct font_glyph_t : public ItemBase
02329         {
02330                 sswf_ucs4_t     f_name;         /* "A", "B", "0", "1", etc. */
02331                 unsigned short  f_index;        /* index of this item when saved in the output file */
02332                 const TagShape *f_shape;        /* the shape used for this glyph */
02333                 long            f_advance;      /* the number of TWIPs to advance */
02334                 bool            f_in_use;       /* if true this glyph was referenced at least once */
02335         };
02336         struct font_kern_t : public ItemBase
02337         {
02338                 sswf_ucs4_t     f_code[2];
02339                 long            f_advance;
02340         };
02341 
02342         virtual ErrorManager::error_code_t PreSave(void);
02343         virtual ErrorManager::error_code_t PreSave2ndPass(void);
02344 
02345         static const char *     g_font_language_name[FONT_LANGUAGE_max];
02346         char *                  f_font_name;
02347         font_language_t         f_language;             // v6.x language definition
02348         font_type_t             f_type;                 // unused in v6.x
02349         bool                    f_bold;
02350         bool                    f_italic;
02351         bool                    f_wide;
02352         bool                    f_has_wide_char;        // defined in PreSave2ndPass()
02353         bool                    f_has_wide_offsets;     // defined in PreSave2ndPass()
02354         bool                    f_has_layout;           // defined in PreSave2ndPass()
02355         bool                    f_used_by_edit_text;    // reset in PreSave() used in PreSave2ndPass()
02356         bool                    f_define_font2;         // defined in PreSave2ndPass()
02357         long                    f_ascent;
02358         long                    f_descent;
02359         long                    f_leading_height;
02360         long                    f_default_advance;
02361         long                    f_space_advance;
02362         long                    f_offsets_max;          // size of the current f_offsets buffer
02363         unsigned long *         f_offsets;              // this is a list of unsigned shorts if f_has_wide_offset if false -- defined in PreSave2ndPass()
02364         unsigned long           f_count;                // the number of glyphs saved (defined in PreSave2ndPass())
02365         Data                    f_save_glyphs;          // defined in PreSave2ndPass()
02366         Vectors                 f_glyphs;
02367         Vectors                 f_kerns;
02368 };
02369 
02370 
02371 
02372 class TagEditText : public TagBaseID
02373 {
02374 public:
02375         enum edit_text_alignment_t {
02376                 EDIT_TEXT_ALIGNMENT_LEFT = 0,
02377                 EDIT_TEXT_ALIGNMENT_RIGHT = 1,
02378                 EDIT_TEXT_ALIGNMENT_CENTER = 2,
02379                 EDIT_TEXT_ALIGNMENT_JUSTIFY = 3
02380         };
02381 
02382                                 TagEditText(TagBase *parent);
02383 
02384         virtual ErrorManager::error_code_t Save(Data& data);
02385         virtual swf_type_t      TypeFlags(void) const;
02386 
02387 /////////////// SETUP FUNCTIONS
02388         void                    SetText(const char *text);
02389         void                    SetVariableName(const char *name);
02390         void                    SetFont(const TagFont *font, long height);
02391         void                    SetMargins(long left, long right);
02392         void                    SetBounds(const SRectangle& bounds);
02393         void                    SetAlign(edit_text_alignment_t align);
02394         void                    SetIndent(long indent);
02395         void                    SetLeading(long leading);
02396         void                    SetColor(Color& color);
02397         void                    SetMaxLength(long length);
02398         void                    SetWordWrap(bool status = true);
02399         void                    SetMultiline(bool status = true);
02400         void                    SetPassword(bool status = true);
02401         void                    SetReadOnly(bool status = true);
02402         void                    SetNoSelect(bool status = true);
02403         void                    SetBorder(bool status = true);
02404         void                    SetOutline(bool status = true);
02405         void                    SetHTML(bool status = true);
02406         void                    SetAutoSize(bool status = true);
02407         void                    SetUsedGlyphs(const char *lists);
02408         void                    AddUsedString(const char *string);
02409 
02410 private:
02411         virtual ErrorManager::error_code_t PreSave(void);
02412 
02413         SRectangle              f_bounds;               // where the string is drawn
02414         edit_text_alignment_t   f_align;
02415         long                    f_left_margin;
02416         long                    f_right_margin;
02417         long                    f_indent;
02418         long                    f_leading;
02419         const TagFont *         f_font;
02420         unsigned short          f_font_height;
02421         long                    f_max_length;           // maximum number of character, if <= 0 - undefined
02422         char *                  f_var_name;             // required
02423         char *                  f_text;                 // if 0, no initialization text [SaveString() expects a UTF-8 so we keep it that way]
02424         sswf_ucs4_t *           f_used_glyphs;          // default to "*" if undefined
02425         sswf_ucs4_t *           f_used_strings;         // concatenation of used strings
02426         Color                   f_color;
02427         bool                    f_has_color;            // if this is true then the user defined the color
02428         bool                    f_word_wrap;
02429         bool                    f_multiline;
02430         bool                    f_password;
02431         bool                    f_readonly;
02432         bool                    f_no_select;
02433         bool                    f_border;
02434         bool                    f_outline;
02435         bool                    f_html;
02436         bool                    f_autosize;
02437 };
02438 
02439 
02440 class TagImage : public TagBaseID
02441 {
02442 public:
02443         enum image_format_t {
02444                 IMAGE_FORMAT_UNKNOWN = 0,
02445                 IMAGE_FORMAT_LOSSLESS_BEST,
02446                 IMAGE_FORMAT_LOSSLESS_8,
02447                 IMAGE_FORMAT_LOSSLESS_16,
02448                 IMAGE_FORMAT_LOSSLESS_32,
02449                 IMAGE_FORMAT_JPEG,
02450                 IMAGE_FORMAT_max
02451         };
02452         struct image_t {
02453                 bool            f_alpha;                // whether the source had 4 components (depth = 0x20)
02454                 long            f_width;                // size of the image in pixels
02455                 long            f_height;
02456                 unsigned char * f_data;                 // data of the image
02457         };
02458 
02459                                 TagImage(TagBase *parent);
02460 
02461         virtual ErrorManager::error_code_t Save(Data& data);
02462         virtual swf_type_t      TypeFlags(void) const;
02463         void                    GetImageData(image_t& image_data) { image_data = f_image; }
02464 
02465 /////////////// SETUP FUNCTIONS
02466         void                    SetFormat(image_format_t format) { f_format = format; }
02467         void                    SetQuality(int quality) { f_quality = quality; }
02468         int                     SetFilename(const char *image, const char *mask);
02469         void                    SetImage(long width, long height, unsigned char *data, bool alpha = false, long count = 0, unsigned char *colormap = 0);
02470 
02471         int                     LoadTGA(const char *filename, image_t& im);
02472         int                     LoadJPEG(const char *filename, image_t& im);
02473         ErrorManager::error_code_t SaveJPEG(Data& encoding, Data& image);
02474         int                     SetAlpha(image_t& im, const image_t& mask);
02475 
02476 private:
02477         virtual ErrorManager::error_code_t PreSave(void);
02478 
02479         image_format_t          f_format;               // one of the IMAGE_FORMAT_...
02480         image_t                 f_image;                // the image
02481         int                     f_quality;              // for JPEG, the quality level
02482         long                    f_count;                // number of colors in the colormap
02483         unsigned char *         f_colormap;             // the colormap when it can be generated
02484 };
02485 
02486 
02487 
02488 class TagShape : public TagBaseID
02489 {
02490 public:
02491         enum morph_t {
02492                 MORPH_MODE_SHAPE0 = 0,
02493                 MORPH_MODE_SHAPE1 = 1,
02494                 MORPH_MODE_BOTH_SHAPES = 2
02495         };
02496 
02497                                         TagShape(TagBase *parent);
02498 
02499         virtual ErrorManager::error_code_t Save(Data& data);
02500         virtual swf_type_t              TypeFlags(void) const;
02501         ErrorManager::error_code_t      SaveWithoutStyles(Data& data);
02502         bool                            HasBounds(void) const { return !f_bounds[0].IsEmpty() || !f_bounds[1].IsEmpty(); }
02503         const SRectangle&               Bounds(int index) const { assert(index == 0 || index == 1, "invalid index to query bounds"); return f_bounds[index]; }
02504         bool                            IsGlyph(void) const;
02505         bool                            IsEmpty(void) const;
02506 
02507 
02508 /////////////// SETUP FUNCTIONS
02509         void                            AddMove(morph_t morph_mode, long x, long y);
02510         void                            AddEdge(morph_t morph_mode, long x, long y) { Edges::edge_t edge(x, y); AddEdge(morph_mode, edge); }
02511         void                            AddEdge(morph_t morph_mode, long x, long y, long ctrl_x, long ctrl_y) { Edges::edge_t edge(x, y, ctrl_x, ctrl_y); AddEdge(morph_mode, edge); };
02512         void                            NewStyles(void);
02513         void                            AddStyle(const Style& style, int fill = 0);
02514         void                            SetBounds(int index, const SRectangle& rect, bool show = false);
02515         void                            ShowBounds(bool show = true) { f_show_bounds = show; }
02516         void                            ShowOrigin(bool show = true) { f_show_origin = show; }
02517         void                            Glyph(void);
02518 
02519 public:
02520         void                            AddEdge(morph_t morph_mode, const Edges::edge_t& edge);
02521 
02522 private:
02523         enum what_t {
02524                 SHAPE_EDGES,
02525                 SHAPE_SETUP
02526         };
02527 
02528         struct shape_what_t : public ItemBase
02529         {
02530                 what_t          f_what;
02531                                 shape_what_t(what_t what) { f_what = what; }
02532         };
02533         struct shape_edges_t : public shape_what_t
02534         {
02535                 Edges           f_edges;
02536                                 shape_edges_t(what_t what) : shape_what_t(what) {}
02537         };
02538         struct shape_setup_t : public shape_what_t
02539         {
02540                 int             f_fill_ref[2];
02541                 int             f_line_ref;
02542                 long            f_x;
02543                 long            f_y;
02544 
02545                                 shape_setup_t(what_t what, bool origin = false) : shape_what_t(what)
02546                                 {
02547                                         f_fill_ref[0] = f_fill_ref[1] = f_line_ref = -1;
02548                                         if(origin) {
02549                                                 f_x = f_y = 0;
02550                                         }
02551                                         else {
02552                                                 f_x = f_y = LONG_MIN;
02553                                         }
02554                                 }
02555         };
02556 
02557         struct shape_record_t : public ItemBase {               // used to save in f_shapes
02558                 Vectors *       f_fill_styles;
02559                 Vectors *       f_line_styles;
02560                 Vectors *       f_record;
02561         };
02562 
02563         struct save_info_t {
02564                 shape_record_t  f_sr;
02565                 bool            f_save_alpha;
02566                 bool            f_ext_size;
02567                 bool            f_first;
02568                 bool            f_save_styles;
02569                 Data            f_data;                 // we save it all here (we need to have the size before to create the tag data)
02570                 int             f_fill_bits_count;
02571                 int             f_line_bits_count;
02572         };
02573 
02574         void                            RecordEdges(void);
02575         void                            RecordSetup(void);
02576         void                            NewEdges(void);
02577         void                            NewSetup(void);
02578         void                            SetMorph(void);
02579 
02580         // save sub-functions
02581         ErrorManager::error_code_t      SaveShape(save_info_t& info, shape_setup_t& last_setup);
02582         ErrorManager::error_code_t      SaveMorph(Data& data);
02583         ErrorManager::error_code_t      SaveSetup(save_info_t& info, const shape_setup_t& setup, shape_setup_t& last);
02584         ErrorManager::error_code_t      SaveStyles(save_info_t& info);
02585         ErrorManager::error_code_t      SaveStylesCount(save_info_t& info, long count);
02586 
02587         unsigned char                   f_version;              // the minimum version necessary to save this shape (determines the tag)
02588         bool                            f_morph;                // this is a morph shape
02589         bool                            f_is_glyph;             // used only as a glyph (font character)
02590         bool                            f_show_bounds;          // draw the bounding rectangle around the shape
02591         bool                            f_show_origin;          // draw lines showing the origin
02592         SRectangle                      f_bounds[2];            // where the shape is drawn
02593 
02594         Vectors                         f_shapes;               // each shape saved here has its own set of fill & line style
02595 
02596         shape_edges_t *                 f_edges;                // if not NULL that's the current Edges to fill
02597         shape_edges_t *                 f_morph_edges;          // if not NULL that's the current Edges to fill the morph (2nd shape)
02598         shape_setup_t *                 f_setup;                // if not NULL that's the current Setup to define
02599         Vectors                         f_fill_styles;
02600         Vectors                         f_line_styles;
02601         Vectors                         f_record;               // the current shape being built
02602         Vectors                         f_morph_record;         // the current morph shape being built
02603 };
02604 
02605 
02606 
02607 class TagSound : public TagBaseID
02608 {
02609 public:
02610         enum sound_format_t {
02611                 SOUND_FORMAT_UNKNOWN = -1,
02612                 SOUND_FORMAT_RAW = 0,
02613                 SOUND_FORMAT_ADPCM = 1,
02614                 SOUND_FORMAT_MP3 = 2,
02615                 SOUND_FORMAT_UNCOMPRESSED = 3,
02616                 SOUND_FORMAT_NELLYMOSER = 6
02617         };
02618         enum sound_endian_t {
02619                 SOUND_ENDIAN_LITTLE = 0,        // the user data is in little endian
02620                 SOUND_ENDIAN_BIG,               // the user data is in big endian
02621                 SOUND_ENDIAN_SAME,              // accept processor endianess as the data endianess
02622                 SOUND_ENDIAN_DONTUSE,           // use this for 8bits data
02623                 SOUND_ENDIAN_UNKNOWN            // undefined endianess -- the SetData() will always fail with this value
02624         };
02625 
02626                                 TagSound(TagBase *parent);
02627 
02628         virtual ErrorManager::error_code_t Save(Data& data);
02629         virtual swf_type_t      TypeFlags(void) const;
02630 
02631         size_t                  GetSamplesCount(void) const;
02632 
02633 /////////////// SETUP FUNCTIONS
02634         int                     SetFilename(const char *filename);
02635         void                    SetFormat(sound_format_t format);
02636         int                     SetData(const void *data, size_t size, sound_endian_t endian, int width, unsigned int rate, bool stereo);
02637         void                    SetMono(void);
02638         void                    Set8Bits(void);
02639 
02640 public:
02641         static const int        g_sound_rates[4];
02642 
02643 private:
02644         struct sound_wave_t {
02645                 short           format;                 // the data format (we only support PCM)
02646                 short           channels;               // number of channels (1 - mono, 2 - stereo)
02647                 int             rate;                   // exact sample rate to play the sound at
02648                 int             average_rate;           // average rate for the entire set of samples (this may vary in compressed files)
02649                 short           align;                  // byte alignment of the samples (every char, short, long...)
02650                 /* the following is format dependent, but at this time doesn't vary for us */
02651                 short           width;                  // width of the samples (8 or 16)
02652         };
02653 
02654         virtual ErrorManager::error_code_t PreSave(void);
02655         short                   ReadSample(const unsigned char *data, unsigned short adjust, int in_fmt);
02656         void                    Resample(unsigned char *snd, unsigned int out_bytes, const unsigned char *src, size_t size, unsigned int in_bytes, size_t max, double fix, unsigned short adjust, int in_fmt);
02657         int                     LoadWaveFile(FILE *f);
02658         int                     LoadMP3File(FILE *f);
02659         int                     CheckMP3Header(FILE *f, unsigned char *header, int& frame_size);
02660         int                     ReadMP3Header(FILE *f, unsigned char *header);
02661 
02662         static const int        g_bitrates[2][16];
02663         static const int        g_frequencies[4][4];
02664 
02665         sound_format_t          f_format;
02666         bool                    f_stereo;
02667         int                     f_rate;
02668         int                     f_width;
02669         size_t                  f_samples;
02670         int                     f_data_size;
02671         int                     f_data_maxsize;
02672         unsigned char *         f_data;
02673         int                     f_latency_seek;
02674 };
02675 
02676 
02677 
02678 
02679 
02680 
02681 class TagSprite : public TagBaseID, public TagScalingGrid
02682 {
02683 public:
02684                                 TagSprite(TagBase *parent);
02685 
02686         virtual ErrorManager::error_code_t Save(Data& data);
02687         virtual swf_type_t      TypeFlags(void) const;
02688 
02689 /////////////// SETUP FUNCTIONS
02690         // Add objects to a sprite by defining the sprite tag as
02691         // the parent of these objects.
02692         // The parent of a sprite must be a TagHeader object.
02693 
02694         // We now have one setup function: SetGrid() inherited from
02695         // the TagScalingGrid class
02696 
02697 protected:
02698         virtual ErrorManager::error_code_t OnNewChild(const char *child_name) const;
02699 
02700 private:
02701         virtual ErrorManager::error_code_t PreSave(void);
02702 };
02703 
02704 
02705 
02706 
02707 class TagText : public TagBaseID
02708 {
02709 public:
02710                                 TagText(TagBase *parent);
02711 
02712         virtual ErrorManager::error_code_t Save(Data& data);
02713         virtual swf_type_t      TypeFlags(void) const;
02714 
02715 /////////////// SETUP FUNCTIONS
02716         void                    SetMatrix(const Matrix& matrix);
02717         void                    SetBounds(const SRectangle& bounds);
02718         void                    AddText(const char *string, long advance = LONG_MIN);
02719         void                    AddFont(const TagFont *font, long height);
02720         void                    AddOffsets(long x, long y);
02721         void                    AddColor(Color& color);
02722 
02723 private:
02724         enum text_type_t {
02725                 TEXT_ENTRY_TEXT = 0,
02726                 TEXT_ENTRY_SETUP
02727         };
02728 
02729         struct text_define_t : public ItemBase {                // used to save in f_shapes
02730                 const text_type_t       f_type;
02731 
02732                                         text_define_t(text_type_t type) : f_type(type) {}
02733         };
02734 
02735         struct text_setup_t : public text_define_t {            // used to save in f_shapes
02736                 bool                    f_has_font;
02737                 const TagFont *         f_font;
02738                 unsigned short          f_font_height;
02739                 bool                    f_has_xadjust;
02740                 long                    f_xadjust;
02741                 bool                    f_has_xoffset;
02742                 long                    f_x;
02743                 bool                    f_has_yoffset;
02744                 long                    f_y;
02745                 bool                    f_has_color;
02746                 Color                   f_color;
02747 
02748                                         text_setup_t(void);
02749                                         text_setup_t(const text_setup_t& setup);
02750                 void                    Unused(void);
02751                 bool                    IsUsed(void) const;
02752         };
02753 
02754         struct text_entry_t : public text_define_t {
02755                 sswf_ucs4_t *           f_text;
02756                 long                    f_advance;
02757                 unsigned long           f_length;               // length of the string
02758                 unsigned long           f_exact_length;         // length of string without spaces
02759                 TagFont::font_info_t *  f_entries;              // an array of entries
02760 
02761                                         text_entry_t(sswf_ucs4_t *string, long advance);
02762         };
02763 
02764         virtual ErrorManager::error_code_t PreSave(void);
02765         int                     DefineText(int start, text_setup_t *s, const TagFont *font, int font_height);
02766         void                    RecordSetup(void);
02767         void                    NewSetup(void);
02768 
02769         Matrix                  f_matrix;               // a transformation matrix for this text
02770         SRectangle              f_bounds;               // where the string is drawn
02771         text_setup_t            f_setup;                // current setup definition
02772         bool                    f_new_text;             // if true we need to recompute the text info entries
02773         int                     f_version;              // the PreSave() defines this, Save() uses it
02774         Vectors                 f_records;              // text records
02775 };
02776 
02777 
02778 
02779 
02780 
02781 
02782 
02783 
02784 
02785 };              // namespace sswf
02786 #endif                  /* #ifndef LIBSSWF_H */

Generated on Sun May 13 23:29:38 2007 for libsswf by  doxygen 1.4.7