00001 
00002 #ifndef LIBSSWF_H
00003 #define LIBSSWF_H
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
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 IRIX
00066 #include        <sys/endian.h>
00067 #endif
00068 
00069 #include        "sswf/libsswf-config.h"
00070 
00071 
00072 #ifndef _MSVC
00073 #ifndef __APPLE_CC__
00074 #ifndef _WINT_T
00075 #define _WINT_T
00076 typedef unsigned int    wint_t;
00077 #endif
00078 #endif
00079 #endif
00080 
00081 #ifndef M_PI
00082 #define M_PI            3.14159265358979323846
00083 #endif
00084 
00085 
00086 #ifdef _MSVC
00087 #define strcasecmp      stricmp
00088 #define rint(x)         ((double) (long) floor(x + 0.5))
00089 #endif
00090 
00091 #ifdef _LIBICONV_H
00092 #define ICONV_INPUT_CAST
00093 #else
00094 
00095 
00096 
00097 
00098 
00099 #define ICONV_INPUT_CAST        (char**)
00100 #endif
00101 
00102 
00103 
00104 
00105 
00106 
00107 
00108 
00109 
00110 
00111 
00112 
00113 #define exposed_class   class
00114 #define invisible       public
00115 
00116 
00117 
00118 
00119 
00120 
00121 
00122 
00123 
00124 
00125 
00126 
00127 
00128 
00129 
00130 
00131 
00132 
00133 
00134 
00135 
00136 
00137 
00138 
00139 
00140 
00141 
00142 
00143 
00144 
00145 namespace sswf
00146 {
00147 
00148 
00149 
00150 
00151 void assert(int cond, const char *format, ...)
00152 #ifndef _MSVC
00153                         __attribute__ ((format (printf, 2, 3)))
00154 #endif
00155                 ;
00156 
00157 
00158 #if DEBUG
00159 inline void assert(int cond, const char *format, ...)
00160 {
00161         va_list         ap;
00162 
00163         
00164         if(cond) {
00165                 return;
00166         }
00167         fflush(stdout);
00168         fflush(stderr);
00169         fprintf(stderr, "\n");
00170         va_start(ap, format);
00171         vfprintf(stderr, format, ap);
00172         va_end(ap);
00173         fprintf(stderr, ".\n");
00174         fflush(stderr);         
00175         abort();
00176 }
00177 #else
00178 inline void assert(int , const char * , ...) {}
00179 #endif
00180 
00181 
00182 typedef unsigned short          sswf_id_t;              
00183 typedef unsigned short          sswf_frame_t;           
00184 typedef int32_t                 sswf_ucs4_t;            
00185 
00186 
00187 #define SSWF_ID_NONE            ((sswf_id_t) -1)        // this is an invalid ID (it seems)
00188 
00189 
00190 extern  void                    swap(void *s1, void *s2, size_t size);
00191 extern  int                     wctomb(const sswf_ucs4_t *wc, size_t wc_len, char *mb, size_t& mb_size);
00192 extern  int                     mbtowc(const char *mb, size_t mb_len, sswf_ucs4_t *& wc, size_t& wc_len);
00193 extern  char *                  wcname(sswf_ucs4_t wc, char *result);
00194 extern  long                    wcslen(sswf_ucs4_t *wcstr);
00195 
00196 inline unsigned short           swap_short(unsigned short s)
00197                                 {
00198                                         return (s >> 8) | (s << 8);
00199                                 }
00200 
00201 inline unsigned int             swap_int(unsigned int l)
00202                                 {
00203                                         return (l >> 24) | (l << 24)
00204                                                 | ((l >> 8) & 0x0000FF00)
00205                                                 | ((l << 8) & 0x00FF0000);
00206                                 }
00207 
00208 extern  const char *            sswf_version(void);
00209 
00210 
00211 
00212 
00213 
00214 
00215 
00216 
00217 
00218 
00219 class ErrorManager
00220 {
00221 public:
00222         enum error_code_t {
00223                 ERROR_CODE_NONE = 0,
00224 
00225                 ERROR_CODE_ACTION_OVERFLOW,
00226                 ERROR_CODE_ALPHA_MISMATCH,
00227                 ERROR_CODE_BAD_STATE_FLAGS,
00228                 ERROR_CODE_BAD_STRING,
00229                 ERROR_CODE_BUTTON_MISSING_STATE,
00230                 ERROR_CODE_CANNOT_CHANGE_STYLE,
00231                 ERROR_CODE_CHILDREN_NOT_SUPPORTED,
00232                 ERROR_CODE_COMPRESSED_SOUND_8BITS,
00233                 ERROR_CODE_EMPTY_POSITION_RANGE,
00234                 ERROR_CODE_ENDED_ACTION_SCRIPT,
00235                 ERROR_CODE_END_OF_STATES,
00236                 ERROR_CODE_ENHANCED_LINE_REQUIRES_ALPHA,
00237                 ERROR_CODE_ENVELOPE_EXISTS,
00238                 ERROR_CODE_ENVELOPE_OVERFLOW,
00239                 ERROR_CODE_ERRONEOUS_FORMAT,
00240                 ERROR_CODE_FILE_NOT_FOUND,
00241                 ERROR_CODE_FORMAT_LOCKED,
00242                 ERROR_CODE_GLYPH_DEFINED_TWICE,
00243                 ERROR_CODE_ICONV_ENCODER_NOT_AVAILABLE,
00244                 ERROR_CODE_ICONV_FAILED,
00245                 ERROR_CODE_IO,
00246                 ERROR_CODE_INCOMPATIBLE_CHILD,
00247                 ERROR_CODE_INCOMPATIBLE_MORPH,
00248                 ERROR_CODE_INTERNAL_ERROR,
00249                 ERROR_CODE_INVALID_DEPTH,
00250                 ERROR_CODE_INVALID_EM_SQUARE,
00251                 ERROR_CODE_INVALID_FILL_PARAMETER,
00252                 ERROR_CODE_INVALID_FOCAL,
00253                 ERROR_CODE_INVALID_GLYPH,
00254                 ERROR_CODE_INVALID_IDENTIFIER,
00255                 ERROR_CODE_INVALID_IMAGE,
00256                 ERROR_CODE_INVALID_INTERPOLATION_MODE,
00257                 ERROR_CODE_INVALID_LINE_INFO,
00258                 ERROR_CODE_INVALID_MORPH_INDEX,
00259                 ERROR_CODE_INVALID_OBJECT_EXPORTED,
00260                 ERROR_CODE_INVALID_POSITION,
00261                 ERROR_CODE_INVALID_SHAPE,
00262                 ERROR_CODE_INVALID_SPREAD_MODE,
00263                 ERROR_CODE_INVALID_SPRITE_DEFINITION,
00264                 ERROR_CODE_INVALID_STYLE,
00265                 ERROR_CODE_INVALID_TEXT_SETUP,
00266                 ERROR_CODE_JPEG,
00267                 ERROR_CODE_LOOP_ZERO,
00268                 ERROR_CODE_MISSING_FRAME_NAME,
00269                 ERROR_CODE_MISSING_SHAPE,
00270                 ERROR_CODE_MORPH_GRADIENT_LIMIT,
00271                 ERROR_CODE_MORPH_REQUIRES_ALPHA,
00272                 ERROR_CODE_NAME_TOO_LONG,
00273                 ERROR_CODE_NEGATIVE_MITER,
00274                 ERROR_CODE_NO_FOCAL_WITH_MORPH,
00275                 ERROR_CODE_NO_HEADER,
00276                 ERROR_CODE_NO_STATES,
00277                 ERROR_CODE_NO_SUCH_GLYPH,
00278                 ERROR_CODE_LABEL_NOT_FOUND,
00279                 ERROR_CODE_LABEL_OVERFLOW,
00280                 ERROR_CODE_MORPH_MISMATCH,
00281                 ERROR_CODE_NOT_ENOUGH_DATA,
00282                 ERROR_CODE_OBJECT_NOT_FOUND,
00283                 ERROR_CODE_REGISTER_OVERFLOW,
00284                 ERROR_CODE_SIZE_MISMATCH,
00285                 ERROR_CODE_START_SOUND_NO_INFO,
00286                 ERROR_CODE_TOO_MANY_STYLES,
00287                 ERROR_CODE_TWO_OR_MORE_JPEGTABLES,
00288                 ERROR_CODE_TWO_OR_MORE_METADATA,
00289                 ERROR_CODE_UNEXPECTED_EVENT_FLAG,
00290                 ERROR_CODE_UNKNOWN_ACTION,
00291                 ERROR_CODE_UNKNOWN_FORMAT,
00292                 ERROR_CODE_UNKNOWN_IMMEDIATE_DATA_TYPE,
00293                 ERROR_CODE_UNKNOWN_OBJECT_EXPORTED,
00294                 ERROR_CODE_UNKNOWN_TAG,
00295                 ERROR_CODE_UNSUPPORTED_IMAGE_FORMAT,
00296                 ERROR_CODE_UNSUPPORTED_SOUND_FORMAT,
00297                 ERROR_CODE_UNSUPPORTED_ZONE_COUNT,
00298                 ERROR_CODE_VERSION_UNSATISFIED,
00299                 ERROR_CODE_VOLUME_OUT_OF_RANGE,
00300 
00301                 ERROR_CODE_max
00302         };
00303 
00304                                 ErrorManager(void);
00305 
00306         void                    Reset(void);
00307         int                     Count(void) const;
00308         static error_code_t     KeepFirst(error_code_t a, error_code_t b);
00309 
00310         error_code_t            OnError(error_code_t errcode, const char *message, va_list ap) const;
00311 
00312 public:
00313         class OutOfBoundsErrorException {};
00314         class InternalErrorException {};
00315 
00316         class ErrorHandler
00317         {
00318         public:
00319                 virtual                 ~ErrorHandler();
00320                 virtual error_code_t    OnError(error_code_t errcode, const char *msg) = 0;
00321         };
00322 
00323         ErrorHandler *          SetErrorHandler(ErrorHandler *error_handler);
00324         error_code_t            OnError(error_code_t errcode, const char *message, ...) const;
00325 
00326 private:
00327         mutable int             f_error_count;
00328         ErrorHandler *          f_error_handler;
00329 };
00330 
00331 
00332 
00333 
00334 
00335 
00336 class Buffer;
00337 class MemBuffer
00338 {
00339 public:
00340                                 MemBuffer(void);
00341         virtual                 ~MemBuffer();
00342 
00343         void                    AttachBuffer(Buffer *buffer);
00344         Buffer *                GetBuffer(void) const;
00345 
00346 private:
00347         Buffer *                f_buffer;
00348 };
00349 
00350 
00351 class Buffer
00352 {
00353 public:
00354                                 Buffer(Buffer **head, size_t size, const char *info);
00355                                 Buffer(Buffer **head, MemBuffer *ptr, size_t size, const char *info);
00356                                 
00357                                 ~Buffer();
00358 
00359         void *                  Realloc(size_t size);
00360         void *                  Data(void) const { return f_data; }
00361         Buffer *                Next(void) const { return (Buffer *) f_next; }
00362         Buffer *                Previous(void) const { return (Buffer *) f_previous; }
00363         size_t                  Size(void) const { return f_size; }
00364         const char *            Info(void) const { return f_info; }
00365 
00366         static Buffer *         FindBuffer(void *ptr);
00367 #if 0
00368 
00369         static bool             IsBuffer(void *ptr);
00370 #endif
00371 
00372 private:
00373 
00374         struct mem_buffer_t {
00375                 unsigned long   f_magic;        
00376                 Buffer *        f_buffer;       
00377         };
00378         enum {
00379                 DMAGIC = (unsigned long) 0x53535746,    
00380                 OMAGIC = (unsigned long) 0x5353574F     
00381         };
00382 #define SSWF_ALIGN(value, modulo)       (((value) + ((modulo) - 1)) & - (long) (modulo))
00383 #define SSWF_SPACE                      SSWF_ALIGN(sizeof(mem_buffer_t), sizeof(double))
00384 #if DEBUG
00385         void                            Test(void);
00386 #define SSWF_SAFE                       (sizeof(double) * 32)
00387 #define SSWF_TEST                       ((long)0xBADC0FFE)
00388 #else
00389 #define SSWF_SAFE                       0
00390 #endif
00391 
00392         Buffer **               f_head;         
00393         Buffer *                f_next;
00394         Buffer *                f_previous;
00395         const char *            f_info;
00396         size_t                  f_size;
00397         mutable void *          f_data;
00398 };
00399 
00400 
00401 class MemoryManager
00402 {
00403 public:
00404                                 MemoryManager(void);
00405         virtual                 ~MemoryManager();
00406 
00407         void                    MemAttach(MemBuffer *ptr, size_t size, const char *info);       
00408         void *                  MemAlloc(size_t size, const char *info);
00409         void *                  MemRealloc(void *ptr, size_t size, const char *info);   
00410         void                    MemFree(void *ptr);
00411         void                    MemClean(void *ptr);
00412         char *                  StrDup(const char *string);
00413         char *                  StrCat(const char *s1, const char *s2);
00414 #if DEBUG
00415         void                    MemTest(void *ptr);
00416 #endif
00417         unsigned long           Size(void *ptr);
00418 
00419 private:
00420         Buffer *                f_head;
00421 };
00422 
00423 
00424 
00425 class ItemBase : public MemBuffer
00426 {
00427 public:
00428                                 ItemBase(void) {}
00429         virtual                 ~ItemBase() {}
00430 };
00431 
00432 
00433 class Vectors : public MemoryManager, public MemBuffer
00434 {
00435 public:
00436                                 Vectors(void);
00437                                 Vectors(const Vectors& vector);
00438                                 ~Vectors();
00439 
00440         ItemBase *              Get(int index) const;
00441         void                    Set(int index, ItemBase *vector);
00442         void                    Insert(int index, ItemBase *vector);
00443         void                    SetSize(int size);
00444         int                     Count(void) const { return f_count; }
00445         void                    Empty(void) { f_count = 0; }    
00446 
00447 public:
00448         Vectors&                operator = (const Vectors& vectors);
00449 
00450 private:
00451         int                     f_count;                
00452         int                     f_max;                  
00453         ItemBase **             f_vectors;              
00454 };
00455 
00456 
00457 
00458 
00459 
00460 
00461 
00462 class Data : public MemoryManager
00463 {
00464 public:
00465                                 Data(void);
00466                                 ~Data();
00467 
00468         void                    Empty(void) { f_pos = 0; f_limit = 0; f_rpos = 0; }     
00469         void                    Align(void);                            
00470         void                    Overwrite(size_t offset, const void *ptr, size_t size);
00471         void                    OverwriteByte(size_t offset, char c);
00472         void                    OverwriteShort(size_t offset, short s);
00473         void                    OverwriteLong(size_t offset, long l);
00474         void                    Write(const void *ptr, size_t size);    
00475         void                    WriteBits(long value, size_t bits);     
00476         void                    PutByte(char c);                        
00477         void                    PutShort(short s);                      
00478         void                    PutLong(long l);                        
00479         void                    PutDLong(int64_t ll);                   
00480         void                    PutShortFloat(float f);                 
00481         void                    PutLongFloat(float f);                  
00482         void                    PutDoubleFloat(double f);               
00483         void                    PutString(const char *string);          
00484         void                    Append(const Data& append);             
00485 
00486         void                    Read(void *& ptr, size_t& size);        
00487         void                    Read(const void *& ptr, size_t& size) const;    
00488                                                                         
00489 
00490         unsigned long           ByteSize(void) const { return (f_pos + CHAR_BIT - 1) / CHAR_BIT; }
00491         unsigned long           GetSize(void) const { return f_pos; }   
00492         void                    SetSize(unsigned long size);
00493 
00494         bool                    IsEndOfData(void) const;
00495         unsigned long           Limit(unsigned long limit, bool offset) const;
00496 
00497 public:
00498         
00499         ErrorManager::error_code_t      ReadAlign(void) const;          
00500         size_t                          GetReadPosition(void) const;            
00501         ErrorManager::error_code_t      SetReadPosition(size_t pos) const;      
00502         ErrorManager::error_code_t      ReadBytes(void *ptr, size_t size) const;
00503         ErrorManager::error_code_t      GetBits(int& value, size_t bits) const; 
00504         ErrorManager::error_code_t      GetByte(int8_t& c) const;
00505         ErrorManager::error_code_t      GetByte(uint8_t& c) const;
00506         ErrorManager::error_code_t      GetShort(int16_t& s) const;
00507         ErrorManager::error_code_t      GetShort(uint16_t& s) const;
00508         ErrorManager::error_code_t      GetLong(int32_t& l) const;
00509         ErrorManager::error_code_t      GetLong(uint32_t& l) const;
00510         ErrorManager::error_code_t      GetDLong(int64_t& ll) const;
00511         ErrorManager::error_code_t      GetDLong(uint64_t& ll) const;
00512         ErrorManager::error_code_t      GetShortFloat(float& f) const;          
00513         ErrorManager::error_code_t      GetLongFloat(float& f) const;           
00514         ErrorManager::error_code_t      GetDoubleFloat(double& f) const;        
00515         ErrorManager::error_code_t      GetString(MemoryManager *mem, int l, char **str) const; 
00516 
00517         class DataLimit
00518         {
00519         public:
00520                                         DataLimit(const Data& data, unsigned long limit, bool offset = true);
00521                                         ~DataLimit();
00522 
00523                 void                    Restore();
00524 
00525         private:
00526                 const Data * const      f_data;
00527                 const unsigned long     f_old_limit;
00528                 bool                    f_restored;
00529         };
00530 
00531 private:
00532         void                    AdjustSize(size_t size);
00533 
00534         unsigned long           f_pos;
00535         unsigned long           f_limit;        
00536         mutable unsigned long   f_rpos;         
00537         unsigned long           f_size;
00538         char *                  f_data;
00539 };
00540 
00541 
00542 
00543 
00544 
00545 
00546 
00547 class SRectangle
00548 {
00549 public:
00550                                 SRectangle(void);
00551 
00552         void                    Reset(void);
00553         void                    Set(long xmin, long xmax, long ymin, long ymax);
00554         void                    SetReorder(long xmin, long xmax, long ymin, long ymax);
00555         long                    XMin(void) const;
00556         long                    XMax(void) const;
00557         long                    YMin(void) const;
00558         long                    YMax(void) const;
00559         bool                    IsEmpty(void) const;
00560 
00561         void                    Save(Data& data) const;
00562         ErrorManager::error_code_t Parse(const Data& data);
00563 
00564 private:
00565         long                    f_xmin;
00566         long                    f_xmax;
00567         long                    f_ymin;
00568         long                    f_ymax;
00569 };
00570 
00571 
00572 class Color
00573 {
00574 public:
00575                                 Color(void) { Reset(); }
00576 
00577         void                    Reset(void);
00578         void                    Set(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha = 255);
00579         unsigned char           Red(void)   const { return f_red;   }
00580         unsigned char           Green(void) const { return f_green; }
00581         unsigned char           Blue(void)  const { return f_blue;  }
00582         unsigned char           Alpha(void) const { return f_alpha; }
00583 
00584         void                    Save(Data& data, bool save_alpha = true) const;
00585         ErrorManager::error_code_t Parse(const Data& data, bool parse_alpha = true);
00586 
00587         bool                    IsSolid(void) const { return f_alpha == 255; }
00588         bool                    IsInvisible(void) const { return f_alpha == 0; }
00589 
00590 public:
00591         bool                    operator == (const Color& color) const;
00592         bool                    operator != (const Color& color) const;
00593 
00594 private:
00595         unsigned char           f_red;
00596         unsigned char           f_green;
00597         unsigned char           f_blue;
00598         unsigned char           f_alpha;
00599 };
00600 
00601 
00602 
00603 class ColorTransform
00604 {
00605 public:
00606                                 ColorTransform(void);
00607 
00608         void                    Reset(void);
00609         void                    SetAdd(double red, double green, double blue, double alpha = 0.0);
00610         void                    SetMult(double red, double green, double blue, double alpha = 1.0);
00611         double                  AddRed(void)    const { return f_add_red;   }
00612         double                  AddGreen(void)  const { return f_add_green; }
00613         double                  AddBlue(void)   const { return f_add_blue;  }
00614         double                  AddAlpha(void)  const { return f_add_alpha; }
00615         double                  MultRed(void)   const { return f_add_red;   }
00616         double                  MultGreen(void) const { return f_add_green; }
00617         double                  MultBlue(void)  const { return f_add_blue;  }
00618         double                  MultAlpha(void) const { return f_add_alpha; }
00619 
00620         void                    Save(Data& data, bool save_alpha = true);
00621         ErrorManager::error_code_t Parse(const Data& data, bool load_alpha = true);
00622 
00623         bool                    IsNull(bool with_alpha) const;          
00624         bool                    IsSolidCompatible(void) const;          
00625 
00626 private:
00627         double                  f_add_red;
00628         double                  f_add_green;
00629         double                  f_add_blue;
00630         double                  f_add_alpha;
00631         double                  f_mult_red;
00632         double                  f_mult_green;
00633         double                  f_mult_blue;
00634         double                  f_mult_alpha;
00635 };
00636 
00637 
00638 
00639 class Matrix
00640 {
00641 public:
00642                                 Matrix(void);
00643 
00644         void                    Reset(void);
00645         void                    SetScale(double x, double y) { f_scale_x = x; f_scale_y = y; }
00646         void                    SetScale(double scale) { f_scale_x = scale; f_scale_y = scale; }
00647         void                    SetRotate(double rotate);
00648         void                    SetSkew(double skew0, double skew1) { f_skew_0 = skew0; f_skew_1 = skew1; }
00649         void                    SetTranslate(long x, long y) { f_translate_x = x; f_translate_y = y; }
00650 
00651         void                    Save(Data& data);
00652         ErrorManager::error_code_t Parse(const Data& data);
00653 
00654         bool                    IsNull(void) const;
00655 
00656 public:
00657         bool                    operator == (const Matrix& matrix) const;
00658         bool                    operator != (const Matrix& matrix) const;
00659 
00660 private:
00661 
00662         struct signed_matrix_t {
00663                 long    m[4];
00664         };
00665 
00666         void                    ComputeMatrix(signed_matrix_t& m) const;
00667         void                    UncomputeMatrix(const signed_matrix_t& m);
00668 
00669         double                  f_scale_x;
00670         double                  f_scale_y;
00671         double                  f_rotate;
00672         long                    f_translate_x;
00673         long                    f_translate_y;
00674         double                  f_skew_0;
00675         double                  f_skew_1;
00676 };
00677 
00678 
00679 
00680 class Envelope : public ItemBase
00681 {
00682 public:
00683                                 Envelope(unsigned long p, unsigned short l, unsigned short r);
00684                                 Envelope(const Envelope& envelope);
00685 
00686         unsigned long           Position(void) const;
00687         unsigned short          Left(void) const;
00688         unsigned short          Right(void) const;
00689         void                    Save(Data& data) const;
00690 
00691 private:
00692         unsigned long           f_position;
00693         unsigned short          f_left;
00694         unsigned short          f_right;
00695 };
00696 
00697 
00698 class SoundInfo : public MemoryManager
00699 {
00700 public:
00701                                 SoundInfo(ErrorManager& error_manager);
00702 
00703         void                    SetSoundID(sswf_id_t id);
00704         void                    StopSound(bool stop = true);
00705         void                    NoMultiple(bool no_multiple = true);
00706         void                    SetRange(unsigned long start, unsigned long end);
00707         void                    SetLoop(unsigned short loop);
00708         void                    AddEnvelope(const Envelope& envelope);
00709 
00710         ErrorManager::error_code_t PreSave(void);               
00711         void                    Save(Data& data) const;
00712 
00713 private:
00714         ErrorManager&           f_error_manager;        
00715         sswf_id_t               f_sound_id;
00716         bool                    f_stop;                 
00717         bool                    f_no_multiple;          
00718         unsigned long           f_start_position;       
00719         unsigned long           f_end_position;         
00720         unsigned short          f_loop;                 
00721         Vectors                 f_envelopes;            
00722 };
00723 
00724 
00725 
00726 
00727 class BlendMode
00728 {
00729 public:
00730         enum blend_mode_t {
00731                 BLEND_MODE_UNDEFINED = -1,
00732                 BLEND_MODE_NORMAL = 1,
00733                 BLEND_MODE_LAYER = 2,
00734                 BLEND_MODE_MULTIPLY = 3,
00735                 BLEND_MODE_SCREEN = 4,
00736                 BLEND_MODE_LIGHTEN = 5,
00737                 BLEND_MODE_DARKEN = 6,
00738                 BLEND_MODE_DIFFERENCE = 7,
00739                 BLEND_MODE_ADD = 8,
00740                 BLEND_MODE_SUBTRACT = 9,
00741                 BLEND_MODE_INVERT = 10,
00742                 BLEND_MODE_ALPHA = 11,
00743                 BLEND_MODE_ERASE = 12,
00744                 BLEND_MODE_OVERLAY = 13,
00745                 BLEND_MODE_HARDLIGHT = 14
00746         };
00747 
00748                                 BlendMode(void);
00749 
00750         bool                    HasBlendMode(void) const;
00751         void                    SetBlendMode(blend_mode_t blend_mode_value);
00752         bool                    SetBlendModeByName(const char *blend_mode_name);
00753         blend_mode_t            GetBlendMode(void) const;
00754 
00755         void                    Save(Data& data);
00756         ErrorManager::error_code_t Parse(const Data& data);
00757 
00758 private:
00759         blend_mode_t            f_blend_mode;
00760 };
00761 
00762 
00763 class State : public ItemBase
00764 {
00765 public:
00766         
00767         enum state_flags_t {
00768                 STATE_FLAG_UP           = 0x01,
00769                 STATE_FLAG_OVER         = 0x02,
00770                 STATE_FLAG_DOWN         = 0x04,
00771                 STATE_FLAG_HIT_TEST     = 0x08,
00772 
00773                 STATE_ALL_FLAGS         = 0x0F
00774         };
00775 
00776         explicit                State(ErrorManager& error_manager);
00777 
00778         void                    Reset(void);
00779         void                    SetObjectID(sswf_id_t id);
00780         bool                    SetFlags(unsigned char flags);
00781         void                    SetLayer(unsigned short layer);
00782         void                    SetMatrix(const Matrix& matrix);
00783         void                    SetColorTransform(const ColorTransform& color_transform);
00784         bool                    HasColorTransform(void) const;
00785         void                    SetBlendMode(const BlendMode& blend_mode);
00786         ErrorManager::error_code_t Save(Data& data, bool color_transform);
00787         ErrorManager::error_code_t Parse(const Data& data, bool color_transform);
00788 
00789         unsigned char           GetFlags(void) const;
00790 
00791 private:
00792         ErrorManager&           f_error_manager;        
00793         sswf_id_t               f_id;
00794         bool                    f_has_color_transform;
00795         unsigned char           f_flags;
00796         unsigned short          f_layer;
00797         Matrix                  f_matrix;
00798         ColorTransform          f_color_transform;
00799         BlendMode               f_blend_mode;
00800 };
00801 
00802 
00803 
00804 
00805 
00806 class Action;
00807 class Event : public MemoryManager, public ItemBase
00808 {
00809 public:
00810                                 Event(void);
00811 
00812         void                    Reset(void);
00813         void                    SetEvents(unsigned long events);
00814         void                    SetConditions(unsigned long events);
00815         void                    SetKey(unsigned char key);
00816         unsigned long           Events(void) const;     
00817         unsigned long           Conditions(void) const; 
00818         unsigned char           Key(void) const;
00819         Vectors&                Actions(void);
00820 
00821         static unsigned long    StringToEvents(const char *s);
00822         static unsigned char    StringToKeyCode(const char *s);
00823 
00824         
00825         
00826         
00827         
00828         enum event_flag_t {
00829                 EVENT_COND_MENU_LEAVE           = 0x80000000,   
00830                 EVENT_COND_MENU_ENTER           = 0x40000000,   
00831 
00832                 EVENT_CONSTRUCT                 = 0x00040000,   
00833                 EVENT_KEY_PRESS                 = 0x00020000,   
00834                 EVENT_POINTER_DRAG_LEAVE        = 0x00010000,   
00835                 EVENT_POINTER_DRAG_ENTER        = 0x00008000,   
00836                 EVENT_POINTER_LEAVE             = 0x00004000,   
00837                 EVENT_POINTER_ENTER             = 0x00002000,   
00838                 EVENT_POINTER_RELEASE_OUTSIDE   = 0x00001000,   
00839                 EVENT_POINTER_RELEASE_INSIDE    = 0x00000800,   
00840                 EVENT_POINTER_PUSH              = 0x00000400,   
00841                 EVENT_INITIALIZE                = 0x00000200,   
00842                 EVENT_DATA                      = 0x00000100,   
00843                 EVENT_KEY_UP                    = 0x00000080,   
00844                 EVENT_KEY_DOWN                  = 0x00000040,   
00845                 EVENT_POINTER_UP                = 0x00000020,   
00846                 EVENT_POINTER_DOWN              = 0x00000010,   
00847                 EVENT_POINTER_MOVE              = 0x00000008,   
00848                 EVENT_UNLOAD                    = 0x00000004,   
00849                 EVENT_ENTER_FRAME               = 0x00000002,   
00850                 EVENT_ONLOAD                    = 0x00000001    
00851         };
00852 #define SSWF_EVENT_V5                   0x0000FF01      // flags present in V5
00853 #define SSWF_EVENT_V6                   0x000300FE      // flags added in V6
00854 #define SSWF_EVENT_V7                   0x00040000      // flag added in V7
00855 #define SSWF_EVENT_CONDITIONS           0xC001FC00      // flags used by conditions in DefineButton2
00856 #define SSWF_EVENT_COUNT                20
00857         struct event_names_t {
00858                 event_flag_t            f_flag;
00859                 const char *            f_name;
00860         };
00861 
00862         enum condition_flag_t {
00863                 CONDITION_KEY_MASK                      = 0xFE00,
00864                 CONDITION_KEY_SHIFT                     = 9,
00865                 CONDITION_MENU_LEAVE                    = 0x0100,       
00866                 CONDITION_MENU_ENTER                    = 0x0080,       
00867                 CONDITION_POINTER_RELEASE_OUTSIDE       = 0x0040,       
00868                 CONDITION_POINTER_DRAG_ENTER            = 0x0020,       
00869                 CONDITION_POINTER_DRAG_LEAVE            = 0x0010,       
00870                 CONDITION_POINTER_RELEASE_INSIDE        = 0x0008,       
00871                 CONDITION_POINTER_PUSH                  = 0x0004,       
00872                 CONDITION_POINTER_LEAVE                 = 0x0002,       
00873                 CONDITION_POINTER_ENTER                 = 0x0001        
00874         };
00875 
00876         enum key_code_t {
00877                 KEY_CODE_NONE = 0,
00878                 KEY_CODE_LEFT_ARROW = 1,
00879                 KEY_CODE_RIGHT_ARROW = 2,
00880                 KEY_CODE_HOME = 3,
00881                 KEY_CODE_END = 4,
00882                 KEY_CODE_INSERT = 5,
00883                 KEY_CODE_DELETE = 6,
00884                 KEY_CODE_BACKSPACE = 8,
00885                 KEY_CODE_ENTER = 13,
00886                 KEY_CODE_UP_ARROW = 14,
00887                 KEY_CODE_DOWN_ARROW = 15,
00888                 KEY_CODE_PAGE_UP = 16,
00889                 KEY_CODE_PAGE_DOWN = 17,
00890                 KEY_CODE_TAB = 18,
00891                 KEY_CODE_ESCAPE = 19,
00892                 KEY_CODE_SPACE = 20,            
00893                 
00894         };
00895 #define SSWF_KEY_COUNT                  15
00896         struct key_names_t {
00897                 key_code_t              f_code;
00898                 const char *            f_name;
00899         };
00900 
00901 public:
00902         static const event_names_t      g_event_names[SSWF_EVENT_COUNT];
00903         static const key_names_t        g_key_names[SSWF_KEY_COUNT];
00904 
00905 private:
00906         unsigned long           f_events;
00907         unsigned char           f_key;
00908         Vectors                 f_actions;
00909 };
00910 
00911 
00912 
00913 
00914 
00915 class Style : public ItemBase
00916 {
00917 public:
00918         enum style_t {
00919                 STYLE_TYPE_UNKNOWN = 0,
00920                 STYLE_TYPE_NO_LINE,
00921                 STYLE_TYPE_NO_FILL,
00922                 STYLE_TYPE_LINE,
00923                 STYLE_TYPE_ENHANCED_LINE,       
00924                 STYLE_TYPE_SOLID,
00925                 STYLE_TYPE_GRADIENT_LINEAR,
00926                 STYLE_TYPE_GRADIENT_RADIAL,
00927                 STYLE_TYPE_GRADIENT_FOCAL,
00928                 STYLE_TYPE_BITMAP_TILLED,
00929                 STYLE_TYPE_BITMAP_CLIPPED,
00930                 STYLE_TYPE_BITMAP_HARDEDGE_TILLED,
00931                 STYLE_TYPE_BITMAP_HARDEDGE_CLIPPED,
00932 
00933                 STYLE_TYPE_MATRIX,              
00934                                                 
00935 
00936                 STYLE_TYPE_max
00937         };
00938 
00939         enum cap_t {
00940                 STYLE_LINE_CAP_SAME   = -1,
00941                 STYLE_LINE_CAP_ROUND  = 0,
00942                 STYLE_LINE_CAP_NONE   = 1,
00943                 STYLE_LINE_CAP_SQUARE = 2
00944         };
00945 
00946         enum join_t {
00947                 STYLE_LINE_JOIN_UNKNOWN = -1,
00948                 STYLE_LINE_JOIN_ROUND   = 0,
00949                 STYLE_LINE_JOIN_BEVEL   = 1,
00950                 STYLE_LINE_JOIN_MITER   = 2
00951         };
00952 
00953         enum spread_t {
00954                 STYLE_GRADIENT_SPREAD_PAD     = 0,
00955                 STYLE_GRADIENT_SPREAD_REFLECT = 1,
00956                 STYLE_GRADIENT_SPREAD_REPEAT  = 2,
00957         };
00958 
00959         enum interpolation_t {
00960                 STYLE_GRADIENT_INTERPOLATION_NORMAL = 0,
00961                 STYLE_GRADIENT_INTERPOLATION_LINEAR = 1
00962         };
00963 
00964         explicit                Style(ErrorManager& error_manager);
00965         virtual                 ~Style();
00966 
00967         void                    Reset(void);
00968         style_t                 Type(void) const { return f_style; }
00969         signed char             Gradients(void) const { return f_gradient; }
00970         bool                    HasMorph(void) const { return f_morph; }
00971         bool                    HasAlpha(void) const { return f_use_alpha; }
00972         bool                    HasHardEdges(void) const { return f_style == STYLE_TYPE_BITMAP_HARDEDGE_TILLED
00973                                                                 || f_style == STYLE_TYPE_BITMAP_HARDEDGE_CLIPPED; }
00974         bool                    SetType(style_t style_type);
00975         bool                    SetLine(int index, unsigned short width, const Color& color);
00976         bool                    SetLineCaps(cap_t start, cap_t end = STYLE_LINE_CAP_SAME);
00977         bool                    SetLineJoin(join_t join, float miter_limit_factor = 0.0f);
00978         bool                    SetLineScale(bool horiz, bool vert);
00979         bool                    SetLinePixelHinting(bool pixel_hinting);
00980         bool                    SetLineNoClose(bool no_close);
00981         bool                    SetLineFillStyle(const Style& fill_style);
00982         bool                    SetColor(int index, const Color& color);
00983         bool                    SetGradient(int index, int pos, const Color& color);
00984         bool                    SetGradientModes(spread_t spread, interpolation_t interpolation);
00985         bool                    SetGradientFocal(float focal);
00986         bool                    SetMatrix(int index, const Matrix& matrix);
00987         bool                    SetBitmap(sswf_id_t id_ref);
00988         bool                    SetClipping(void);
00989 
00990         ErrorManager::error_code_t Save(Data& data, bool save_alpha, bool save_morph);
00991 
00992 public:
00993 
00994 
00995 
00996 
00997 
00998 
00999 
01000         static const signed char MAX_GRADIENTS = 15;
01001 
01002         bool                    operator == (const Style& style) const;
01003 
01004 private:
01005         
01006         ErrorManager&           f_error_manager;
01007 
01008         
01009         style_t                 f_style;
01010 
01011         
01012         bool                    f_morph;
01013 
01014         
01015         bool                    f_use_alpha;
01016 
01017         
01018         unsigned short          f_line_width[2];
01019         cap_t                   f_start_cap_style;
01020         cap_t                   f_end_cap_style;
01021         join_t                  f_join_style;
01022         float                   f_miter_limit_factor;           
01023         bool                    f_no_hscale;
01024         bool                    f_no_vscale;
01025         bool                    f_pixel_hinting;
01026         bool                    f_no_close;
01027         Style *                 f_fill_style;                   
01028 
01029         
01030         Color                   f_color[2];
01031 
01032         
01033         sswf_id_t               f_bitmap_ref;
01034 
01035         
01036         Matrix                  f_matrix[2];
01037 
01038         
01039         signed char             f_gradient;             
01040         unsigned char           f_gradient_pos[MAX_GRADIENTS * 2];
01041         Color                   f_gradient_color[MAX_GRADIENTS * 2];
01042         spread_t                f_gradient_spread;
01043         interpolation_t         f_gradient_interpolation;
01044         signed short            f_gradient_focal;
01045 };
01046 
01047 
01048 
01049 
01050 
01051 class Edges : public MemoryManager, public ItemBase
01052 {
01053 public:
01054         
01055         
01056         struct edge_t {
01057                 long            f_x;
01058                 long            f_y;
01059                 long            f_ctrl_x;               
01060                 long            f_ctrl_y;
01061 
01062                                 edge_t(void)
01063                                 {
01064                                         f_x = 0;
01065                                         f_y = 0;
01066                                         f_ctrl_x = LONG_MIN;
01067                                         f_ctrl_y = LONG_MIN;
01068                                 }
01069                                 edge_t(long x, long y)
01070                                 {
01071                                         f_x = x;
01072                                         f_y = y;
01073                                         f_ctrl_x = LONG_MIN;
01074                                         f_ctrl_y = LONG_MIN;
01075                                 }
01076                                 edge_t(long x, long y, long ctrl_x, long ctrl_y)
01077                                 {
01078                                         f_x = x;
01079                                         f_y = y;
01080                                         f_ctrl_x = ctrl_x;
01081                                         f_ctrl_y = ctrl_y;
01082                                 }
01083                                 edge_t(const edge_t& edge)
01084                                 {
01085                                         f_x = edge.f_x;
01086                                         f_y = edge.f_y;
01087                                         f_ctrl_x = edge.f_ctrl_x;
01088                                         f_ctrl_y = edge.f_ctrl_y;
01089                                 }
01090                 edge_t&         operator = (const edge_t& edge)
01091                                 {
01092                                         if(this != &edge) {
01093                                                 f_x = edge.f_x;
01094                                                 f_y = edge.f_y;
01095                                                 f_ctrl_x = edge.f_ctrl_x;
01096                                                 f_ctrl_y = edge.f_ctrl_y;
01097                                         }
01098                                         return *this;
01099                                 }
01100                 bool            IsLine(void) const { return f_ctrl_x == LONG_MIN || f_ctrl_y == LONG_MIN; }
01101         };
01102 
01103 public:
01104         
01105         
01106         enum {
01107                 
01108                 EDGE_BLOCK = 64
01109         };
01110 
01111                                 Edges(void);
01112         virtual                 ~Edges();
01113 
01114         
01115         void                    Set(long x, long y) { edge_t edge(x, y); Set(-1, edge); }
01116         void                    Set(long x, long y, long ctrl_x, long ctrl_y) { edge_t edge(x, y, ctrl_x, ctrl_y); Set(-1, edge); }
01117         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); }
01118 
01119         void                    Save(Data& data, long& x, long& y);
01120 
01121 public:
01122         void                    Set(const edge_t& edge) { Set(-1, edge); }
01123         void                    Set(int index, const edge_t& edge);
01124 
01125 private:
01126 
01127         struct array_edge_t : public ItemBase {
01128                 edge_t          f_edge[EDGE_BLOCK];
01129         };
01130 
01131                                 
01132                                 Edges(const Edges& edges) {}
01133         Edges&                  operator = (const Edges& edges) { return *this; }
01134 
01135         void                    SaveEdge(Data& data, const edge_t& edge, long& x, long& y);
01136 
01137         Vectors                 f_edges;
01138         int                     f_pos;          
01139         array_edge_t            f_array;        
01140 };
01141 
01142 
01143 
01144 
01145 
01146 
01147 
01148 
01149 
01150 class TagHeader;
01151 class TagBase : public MemoryManager
01152 {
01153 public:
01154         
01155         enum swf_tag_t {
01156                 SWF_TAG_UNKNOWN = -1,           
01157 
01158                 
01159                 SWF_TAG_END = 0,                        
01160                 SWF_TAG_SHOW_FRAME = 1,                 
01161                 SWF_TAG_DEFINE_SHAPE = 2,               
01162                 SWF_TAG_PLACE_OBJECT = 4,               
01163                 SWF_TAG_REMOVE_OBJECT = 5,              
01164                 SWF_TAG_DEFINE_BITS = 6,                
01165                 SWF_TAG_DEFINE_BITS_JPEG = 6,           
01166                 SWF_TAG_DEFINE_BUTTON = 7,              
01167                 SWF_TAG_JPEG_TABLES = 8,                
01168                 SWF_TAG_SET_BACKGROUND_COLOR = 9,       
01169                 SWF_TAG_DEFINE_FONT = 10,               
01170                 SWF_TAG_DEFINE_TEXT = 11,               
01171                 SWF_TAG_DO_ACTION = 12,                 
01172                 SWF_TAG_DEFINE_FONT_INFO = 13,          
01173 
01174                 
01175                 SWF_TAG_DEFINE_SOUND = 14,              
01176                 SWF_TAG_START_SOUND = 15,               
01177                 SWF_TAG_STOP_SOUND = 16,                
01178                 SWF_TAG_DEFINE_BUTTON_SOUND = 17,       
01179                 SWF_TAG_SOUND_STREAM_HEAD = 18,         
01180                 SWF_TAG_SOUND_STREAM_BLOCK = 19,        
01181                 SWF_TAG_DEFINE_BITS_LOSSLESS = 20,      
01182                 SWF_TAG_DEFINE_BITS_JPEG2 = 21,         
01183                 SWF_TAG_DEFINE_SHAPE2 = 22,             
01184                 SWF_TAG_DEFINE_BUTTON_COLOR_TRANSFORM = 23,     
01185                 SWF_TAG_PROTECT = 24,                   
01186 
01187                 
01188                 SWF_TAG_PLACE_OBJECT2 = 26,             
01189                 SWF_TAG_REMOVE_OBJECT2 = 28,            
01190                 SWF_TAG_DEFINE_SHAPE3 = 32,             
01191                 SWF_TAG_DEFINE_TEXT2 = 33,              
01192                 SWF_TAG_DEFINE_BUTTON2 = 34,            
01193                 SWF_TAG_DEFINE_BITS_JPEG3 = 35,         
01194                 SWF_TAG_DEFINE_BITS_LOSSLESS2 = 36,     
01195                 SWF_TAG_DEFINE_SPRITE = 39,             
01196                 SWF_TAG_PRODUCT_INFO = 41,              
01197                 SWF_TAG_FRAME_LABEL = 43,               
01198                 SWF_TAG_DEFINE_BEHAVIOR = 44,           
01199                 SWF_TAG_SOUND_STREAM_HEAD2 = 45,        
01200                 SWF_TAG_DEFINE_MORPH_SHAPE = 46,        
01201                 SWF_TAG_DEFINE_FONT2 = 48,              
01202                 SWF_TAG_DEFINE_INFO = 49,               
01203 
01204                 
01205                 SWF_TAG_TEXT_FIELD = 37,                
01206 
01207                 
01208                 SWF_TAG_DEFINE_FUNCTION = 53,           
01209                 SWF_TAG_PLACE_FUNCTION = 54,            
01210                 SWF_TAG_GENERATE_TAG_OBJECT = 55,       
01211 
01212                 
01213                 SWF_TAG_EXPORT = 56,                    
01214                 SWF_TAG_IMPORT = 57,                    
01215                 SWF_TAG_PROTECT_DEBUG = 58,             
01216 
01217                 
01218                 SWF_TAG_DO_INIT_ACTION = 59,            
01219                 SWF_TAG_DEFINE_VIDEO_STREAM = 60,       
01220                 SWF_TAG_VIDEO_FRAME = 61,               
01221                 SWF_TAG_DEFINE_FONT_INFO2 = 62,         
01222                 SWF_TAG_DEBUG_ID = 63,                  
01223                 SWF_TAG_PROTECT_DEBUG2 = 64,            
01224 
01225                 
01226                 SWF_TAG_SCRIPT_LIMITS = 65,             
01227                 SWF_TAG_SET_TAB_INDEX = 66,             
01228 
01229                 
01230                 SWF_TAG_FILE_ATTRIBUTES = 69,           
01231                 SWF_TAG_PLACE_OBJECT3 = 70,             
01232                 SWF_TAG_IMPORT2 = 71,                   
01233                 SWF_TAG_DEFINE_FONT_ALIGN_ZONES = 73,   
01234                 SWF_TAG_CSM_TEXT_SETTINGS = 74,         
01235                 SWF_TAG_DEFINE_FONT3 = 75,              
01236                 SWF_TAG_METADATA = 77,                  
01237                 SWF_TAG_DEFINE_SCALING_GRID = 78,       
01238                 SWF_TAG_DEFINE_SHAPE4 = 83,             
01239                 SWF_TAG_DEFINE_MORPH_SHAPE2 = 84,       
01240 
01241                 
01242                 SWF_TAG_ACTIONSCRIPT2 = 72,             
01243                 SWF_TAG_ACTIONSCRIPT2_INSTANTIATE = 76, 
01244                 SWF_TAG_ACTIONSCRIPT2_DEFINE = 82,      
01245                 SWF_TAG_SCENE_FRAME_DATA = 86,          
01246                 SWF_TAG_DEFINE_BINARY_DATA = 87,        
01247                 SWF_TAG_DEFINE_FONT_NAME = 88,          
01248 
01249                 
01250                 SWF_TAG_DEFINE_BITS_JPEG4 = 90,         
01251 
01252                 SWF_TAG_max             
01253         };
01254         typedef long                    swf_type_t;
01255 
01256 #define SWF_TYPE_DEFINE                 0x00000001      // a definition tag, must be in the main movie
01257 #define SWF_TYPE_CONTROL                0x00000002      // a control tag, can be in sprites as well
01258 #define SWF_TYPE_UNIQUE                 0x00000004      // a unique tag, can't be duplicated in the movie (merge if possible)
01259 #define SWF_TYPE_START                  0x00000008      // if present, put it near the start of the movie
01260 #define SWF_TYPE_ONE                    0x00000010      // (should) use at most one per frame
01261 #define SWF_TYPE_REFERENCE              0x00000020      // object includes references to other objects
01262 #define SWF_TYPE_HAS_ID                 0x00000040      // this object was derived from TagBaseID and has an ID
01263 
01264 #define SWF_TYPE_SCRIPT                 0x20000000      // object can accept action scripts
01265 #define SWF_TYPE_SPRITE                 0x40000000      // this is a sprite (can include other tags)
01266 #define SWF_TYPE_HEADER                 0x80000000      // the header
01267 
01268         virtual                         ~TagBase();
01269 
01270         ErrorManager::error_code_t      SaveString(Data& data, const char *string);
01271         static int                      SaveTag(Data& data, swf_tag_t tag, size_t size);
01272 
01273         static long                     SIBitSize(long value);          
01274         static long                     UIBitSize(unsigned long value); 
01275         static long                     Double2Signed16(double value);  
01276         static double                   Signed162Double(long value);    
01277         static long                     Double2Signed(double value);    
01278         static double                   Signed2Double(long value);      
01279 
01280         virtual void                    MinimumVersion(unsigned char version);
01281         virtual unsigned char           Version(void) const;
01282 
01283         const char *                    Name(void) const;       
01284         const char *                    Label(void) const;
01285         void                            ResetFrames(void);
01286         void                            ShowFrame(void);
01287         sswf_frame_t                    FrameCount(void) const;
01288 
01289         sswf_frame_t                    WhichFrame(void) const;
01290         void                            SetLabel(const char *label);
01291         TagBase *                       FindLabelledTag(const char *label) const;
01292         TagBase *                       FindTagWithID(sswf_id_t id, bool search_import = true) const;
01293         TagBase *                       Children(void);
01294         TagBase *                       Next(void);
01295         TagBase *                       Previous(void);
01296         TagBase *                       Parent(void);
01297         TagHeader *                     Header(void) const;
01298         virtual ErrorManager::error_code_t OnError(ErrorManager::error_code_t errcode, const char *message, va_list ap) const;
01299 
01300 public:
01301         virtual ErrorManager::error_code_t Save(Data& data) = 0;        
01302         virtual swf_type_t              TypeFlags(void) const = 0;
01303         virtual ErrorManager::error_code_t OnError(ErrorManager::error_code_t errcode, const char *message, ...) const;
01304         virtual ErrorManager::error_code_t ParseTag(swf_tag_t tag, const Data& data) = 0;
01305 
01306 
01307 
01308 
01309 
01310 
01311 
01312 
01313 
01314 
01315         void *                          f_userdata;             
01316 
01317 protected:
01318                                 
01319                                         TagBase(const char *name, TagBase *parent);
01320         virtual ErrorManager::error_code_t PreSave(void);               
01321         virtual ErrorManager::error_code_t PreSave2ndPass(void);        
01322 
01323         virtual ErrorManager::error_code_t OnNewChild(const char *child_name) const;
01324 
01325 private:
01326         TagBase *                       FindLabel(const TagBase *p, const char *label) const;
01327         TagBase *                       FindID(const TagBase *p, sswf_id_t id, bool search_import) const;
01328 
01329         const char *                    f_name;
01330         char *                          f_label;
01331 
01332         TagBase *                       f_parent;
01333         TagBase *                       f_next;
01334         TagBase *                       f_previous;
01335         TagBase *                       f_children;
01336 
01337         sswf_frame_t                    f_frames;               
01338 };
01339 
01340 
01341 
01342 
01343 
01344 
01345 
01346 
01347 
01348 
01349 
01350 
01351 
01352 
01353 
01354 
01355 class TagHeader : public TagBase, public ErrorManager
01356 {
01357 public:
01358         enum load_flag_t {
01359                 LOAD_FLAG_IGNORE_UNKNOWN_TAGS = 0x0001
01360         };
01361 
01362                                         TagHeader(void);
01363         virtual                         ~TagHeader();
01364 
01365         ErrorManager::error_code_t      Load(const Data& data, load_flag_t flags);
01366 
01367         virtual ErrorManager::error_code_t Save(Data& data);
01368         ErrorManager::error_code_t      SaveEncodedString(Data& data, const char *string);
01369         virtual swf_type_t              TypeFlags(void) const;
01370         virtual ErrorManager::error_code_t OnError(ErrorManager::error_code_t errcode, const char *message, va_list ap) const;
01371 
01372         sswf_id_t                       NextID(void);
01373         void                            RemoveID(sswf_id_t id);
01374 
01375 
01376         virtual unsigned char           Version(void) const;                            
01377         void                            SetVersion(unsigned char version);              
01378         void                            SetMinimumVersion(unsigned char version);       
01379         void                            SetMaximumVersion(unsigned char version);       
01380 
01381         void                            SetCompress(bool compress = true);
01382         void                            SetAutoOrder(bool auto_order = true);
01383         void                            SetUseNetwork(bool use_network = true);
01384         void                            SetFrame(const SRectangle& rect);
01385         const SRectangle&               Frame(void) const;
01386 
01387         void                            SetOutputEncoding(const char *encoding);
01388         void                            SetRate(float rate);
01389         float                           Rate(void) const;
01390 
01391 public:
01392         class Factory
01393         {
01394         public:
01395                                                 Factory(swf_tag_t tag, int priority = 0);
01396                 virtual                         ~Factory();
01397 
01398                 swf_tag_t                       GetTag(void) const;
01399                 int                             GetPriority(void) const;
01400                 virtual TagBase *               NewTag(TagBase *parent, const Data& data) const = 0;
01401 
01402         private:
01403                 const swf_tag_t                 f_tag_id;
01404                 const int                       f_priority;
01405         };
01406 
01407         const Factory *                 GetFactory(TagBase::swf_tag_t tag) const;
01408         virtual void                    MinimumVersion(unsigned char version);          
01409         ErrorManager::error_code_t      DefineMinimumVersion(int& min_version);         
01410         virtual ErrorManager::error_code_t OnError(ErrorManager::error_code_t errcode, const char *message, ...) const;
01411 
01412 protected:
01413         virtual ErrorManager::error_code_t PreSave(void);               
01414         virtual ErrorManager::error_code_t ParseTag(TagBase::swf_tag_t tag, const Data& data);  
01415         virtual ErrorManager::error_code_t OnNewChild(const char *child_name) const;
01416 
01417 private:
01418         enum load_status_t {
01419                 HEADER_LOAD_STATUS_RESET = 0,           
01420                 HEADER_LOAD_STATUS_HEADER,              
01421                 HEADER_LOAD_STATUS_TAG,                 
01422                 HEADER_LOAD_STATUS_TAG_SIZE,            
01423                 HEADER_LOAD_STATUS_DATA,                
01424                 HEADER_LOAD_STATUS_DONE,                
01425                 HEADER_LOAD_STATUS_ERROR                
01426         };
01427 
01428         
01429         unsigned char                   f_version;              
01430         unsigned char                   f_min_version;          
01431         unsigned char                   f_minimum_version;      
01432         unsigned char                   f_maximum_version;      
01433         SRectangle                      f_frame;                
01434         float                           f_rate;                 
01435         bool                            f_compress;             
01436         bool                            f_auto_order;           
01437         bool                            f_use_network;          
01438         bool                            f_has_metadata;         
01439         bool                            f_has_jpegtables;       
01440         sswf_id_t                       f_next_id;              
01441         char *                          f_output_encoding;      
01442         bool                            f_iconvertor_open;      
01443         iconv_t                         f_iconvertor;           
01444 #if DEBUG
01445         bool                            f_saving;               
01446 #endif
01447         load_status_t                   f_load_status;          
01448         swf_tag_t                       f_tag;                  
01449         size_t                          f_tag_size;             
01450         bool                            f_compressed_input;     
01451         size_t                          f_file_size;            
01452         size_t                          f_position;             
01453         Data                            f_tag_data;             
01454         z_stream                        f_zstream;              
01455         TagBase *                       f_sprite;               
01456         size_t                          f_sprite_size;          
01457 };
01458 
01459 
01460 
01461 
01462 
01463 
01464 
01465 
01466 
01467 
01468 
01469 
01470 
01471 
01472 
01473 
01474 
01475 
01476 
01477 
01478 
01479 
01480 
01481 
01482 
01483 
01484 
01485 
01486 
01487 class ActionLabel;
01488 class Action : public ItemBase
01489 {
01490 public:
01491         enum action_t {
01492                 ACTION_UNKNOWN                  = -1,   
01493                 ACTION_LABEL                    = -2,   
01494                 ACTION_min                      = 0x00, 
01495 
01496                 
01497                 ACTION_END                      = 0x00, 
01498                 ACTION_NEXT_FRAME               = 0x04,
01499                 ACTION_PREVIOUS_FRAME           = 0x05,
01500                 ACTION_PLAY                     = 0x06,
01501                 ACTION_STOP                     = 0x07,
01502                 ACTION_TOGGLE_QUALITY           = 0x08,
01503                 ACTION_STOP_SOUND               = 0x09,
01504                 ACTION_ADD                      = 0x0A,
01505                 
01506                 ACTION_SUBTRACT                 = 0x0B,
01507                 ACTION_MULTIPLY                 = 0x0C,
01508                 ACTION_DIVIDE                   = 0x0D,
01509                 ACTION_EQUAL                    = 0x0E,
01510                 ACTION_LESS_THAN                = 0x0F,
01511                 ACTION_LOGICAL_AND              = 0x10,
01512                 ACTION_LOGICAL_OR               = 0x11,
01513                 ACTION_LOGICAL_NOT              = 0x12,
01514                 ACTION_STRING_EQUAL             = 0x13,
01515                 ACTION_STRING_LENGTH            = 0x14,
01516                 ACTION_SUB_STRING               = 0x15,
01517                 ACTION_POP                      = 0x17,
01518                 ACTION_INTEGRAL_PART            = 0x18,
01519                 ACTION_GET_VARIABLE             = 0x1C,
01520                 ACTION_SET_VARIABLE             = 0x1D,
01521                 ACTION_SET_TARGET2              = 0x20,
01522                 ACTION_CONCATENATE              = 0x21,
01523                 ACTION_GET_PROPERTY             = 0x22,
01524                 ACTION_SET_PROPERTY             = 0x23,
01525                 ACTION_DUPLICATE_SPRITE         = 0x24,
01526                 ACTION_REMOVE_SPRITE            = 0x25,
01527                 ACTION_TRACE                    = 0x26,
01528                 ACTION_START_DRAG               = 0x27,
01529                 ACTION_STOP_DRAG                = 0x28,
01530                 ACTION_STRING_LESS_THAN         = 0x29,
01531                 ACTION_THROW                    = 0x2A,
01532                 ACTION_CAST_OBJECT              = 0x2B,
01533                 ACTION_IMPLEMENTS               = 0x2C,
01534                 ACTION_FSCOMMAND2               = 0x2D,
01535                 ACTION_RANDOM                   = 0x30,
01536                 ACTION_MBSTRING_LENGTH          = 0x31,
01537                 ACTION_ORD                      = 0x32,
01538                 ACTION_CHR                      = 0x33,
01539                 ACTION_GET_TIMER                = 0x34,
01540                 ACTION_SUB_MBSTRING             = 0x35,
01541                 ACTION_MBORD                    = 0x36,
01542                 ACTION_MBCHR                    = 0x37,
01543                 ACTION_DELETE                   = 0x3A,
01544                 ACTION_SET_LOCAL_VAR            = 0x3C,
01545                 ACTION_SET_LOCAL_VARIABLE       = 0x3C,
01546                 ACTION_CALL_FUNCTION            = 0x3D,
01547                 ACTION_RETURN                   = 0x3E,
01548                 ACTION_MODULO                   = 0x3F,
01549                 ACTION_NEW                      = 0x40,
01550                 ACTION_DECLARE_LOCAL_VAR        = 0x41,
01551                 ACTION_DECLARE_LOCAL_VARIABLE   = 0x41,
01552                 ACTION_DECLARE_ARRAY            = 0x42,
01553                 ACTION_DECLARE_OBJECT           = 0x43,
01554                 ACTION_TYPE_OF                  = 0x44,
01555                 ACTION_GET_TARGET               = 0x45,
01556                 ACTION_ENUMERATE                = 0x46,
01557                 ACTION_ADD_TYPED                = 0x47,
01558                 ACTION_LESS_THAN_TYPED          = 0x48,
01559                 ACTION_EQUAL_TYPED              = 0x49,
01560                 ACTION_NUMBER                   = 0x4A,
01561                 ACTION_STRING                   = 0x4B,
01562                 ACTION_DUPLICATE                = 0x4C,
01563                 ACTION_SWAP                     = 0x4D,
01564                 ACTION_GET_MEMBER               = 0x4E,
01565                 ACTION_SET_MEMBER               = 0x4F,
01566                 ACTION_INCREMENT                = 0x50,
01567                 ACTION_DECREMENT                = 0x51,
01568                 ACTION_CALL_METHOD              = 0x52,
01569                 ACTION_NEW_METHOD               = 0x53,
01570                 ACTION_INSTANCE_OF              = 0x54,
01571                 ACTION_ENUMERATE_OBJECT         = 0x55,
01572                 ACTION_AND                      = 0x60,
01573                 ACTION_OR                       = 0x61,
01574                 ACTION_XOR                      = 0x62,
01575                 ACTION_SHIFT_LEFT               = 0x63,
01576                 ACTION_SHIFT_RIGHT              = 0x64,
01577                 ACTION_SHIFT_RIGHT_UNSIGNED     = 0x65,
01578                 ACTION_STRICT_EQUAL             = 0x66,
01579                 ACTION_GREATER_THAN_TYPED       = 0x67,
01580                 ACTION_STRING_GREATER_THAN      = 0x68,
01581                 ACTION_EXTENDS                  = 0x69,
01582                 ACTION_GOTO_FRAME               = 0x81,
01583                 ACTION_URL                      = 0x83,
01584                 ACTION_STORE_REGISTER           = 0x87,
01585                 ACTION_DECLARE_DICTIONARY       = 0x88,
01586                 ACTION_STRICT_MODE              = 0x89,
01587                 ACTION_WAIT_FOR_FRAME           = 0x8A,
01588                 ACTION_SET_TARGET               = 0x8B,
01589                 ACTION_GOTO_LABEL               = 0x8C,
01590                 ACTION_WAIT_FOR_FRAME2          = 0x8D,
01591                 ACTION_DECLARE_FUNCTION2        = 0x8E,
01592                 ACTION_TRY                      = 0x8F,
01593                 ACTION_WITH                     = 0x94,
01594                 ACTION_PUSH_DATA                = 0x96,
01595                 ACTION_BRANCH_ALWAYS            = 0x99,
01596                 ACTION_URL2                     = 0x9A,
01597                 ACTION_DECLARE_FUNCTION         = 0x9B,
01598                 ACTION_BRANCH_IF_TRUE           = 0x9D,
01599                 ACTION_CALL_FRAME               = 0x9E,
01600                 ACTION_GOTO_EXPRESSION          = 0x9F,
01601 
01602                 ACTION_max              = 0xFF          
01603         };
01604 
01605                                         Action(TagBase *tag, action_t action);
01606         virtual                         ~Action() {}
01607 
01608         virtual Action *                Duplicate(void) const;
01609         unsigned long                   Offset(void) const { return f_offset; }
01610         virtual unsigned char           Version(void) const { return f_min_version; }
01611 
01612         ErrorManager::error_code_t      Save(Data& data);
01613         virtual Vectors *               SubList(void);
01614         ErrorManager::error_code_t      SaveList(const Vectors *list, Data& data, const Vectors *extra = 0);
01615         static int                      MinimumListVersion(const Vectors& list);
01616         static int                      GetMaximumRegister(const Vectors& list);
01617         static ActionLabel *            FindLabel(const Vectors& list, const char *label);
01618         static ActionLabel *            FindLabelAtOffset(Vectors& list, unsigned long offset);
01619         static ErrorManager::error_code_t ParseList(TagBase *tag, const Data& data, Vectors& actions);
01620         static ErrorManager::error_code_t Parse(TagBase *tag, const Data& data, Vectors& actions);
01621         TagBase *                       GetTag(void) const { return f_tag; }
01622 
01623 public:
01624         ErrorManager::error_code_t      OnError(ErrorManager::error_code_t errcode, const char *message, ...) const;
01625 
01626 protected:
01627         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
01628         virtual ErrorManager::error_code_t Save2ndPass(const Vectors& list, Data& data);
01629         virtual ErrorManager::error_code_t ParseData(const Data& data);
01630         virtual ErrorManager::error_code_t Parse2ndPass(Vectors& list);
01631         virtual int                     GetMaxRegister(void) const { return 0; }
01632         ErrorManager::error_code_t      SaveString(Data& data, const char *string);
01633         TagBase *                       Tag(void) const { return const_cast<TagBase *>(f_tag); }
01634 
01635         const action_t                  f_action;
01636         unsigned long                   f_offset;               
01637 
01638 private:
01639 #if DEBUG
01640         
01641 
01642 
01643 
01644                                         Action(const Action& action);
01645         Action&                         operator = (const Action& action);
01646 #endif
01647 
01648         TagBase *                       f_tag;
01649         unsigned char                   f_min_version;          
01650 };
01651 
01652 
01653 class ActionBranch : public Action, public MemoryManager
01654 {
01655 public:
01656         
01657 
01658 
01659 
01660                                         ActionBranch(TagBase *tag, action_t action = ACTION_BRANCH_ALWAYS);
01661 
01662         void                            SetLabel(const char *label);
01663 
01664 private:
01665         virtual Action *                Duplicate(void) const;
01666         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
01667         virtual ErrorManager::error_code_t Save2ndPass(const Vectors& list, Data& data);
01668         virtual ErrorManager::error_code_t ParseData(const Data& data);
01669         virtual ErrorManager::error_code_t Parse2ndPass(Vectors& list);
01670 
01671         char *                          f_label;
01672         unsigned long                   f_goto_offset;  
01673 };
01674 
01675 
01676 
01677 class ActionCallFrame : public Action, public MemoryManager
01678 {
01679 public:
01680         
01681 
01682 
01683                                         ActionCallFrame(TagBase *tag);
01684 
01685 private:
01686         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
01687         virtual ErrorManager::error_code_t ParseData(const Data& data);
01688 };
01689 
01690 
01691 
01692 class ActionDictionary : public Action, public MemoryManager
01693 {
01694 public:
01695         
01696 
01697 
01698                                         ActionDictionary(TagBase *tag);
01699 
01700         void                            AddString(const char *string);
01701 
01702 private:
01703 
01704         struct string_t : public ItemBase
01705         {
01706 
01707                                 string_t(char *str = 0) :
01708                                         f_string(str)
01709                                 {
01710                                 }
01711 
01712 
01713                 char *          f_string;
01714         };
01715 
01716         virtual Action *                Duplicate(void) const;
01717         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
01718         virtual ErrorManager::error_code_t ParseData(const Data& data);
01719 
01720 
01721         Vectors                         f_strings;
01722 };
01723 
01724 
01725 
01726 class ActionFunction : public Action, public MemoryManager
01727 {
01728 public:
01729         
01730 
01731 
01732 
01733                                         ActionFunction(TagBase *tag, action_t action = ACTION_DECLARE_FUNCTION);
01734 
01735         enum action_function_t {
01736                 ACTION_FUNCTION_LOAD_THIS          = 0x0001,
01737                 ACTION_FUNCTION_SUPPRESS_THIS      = 0x0002,
01738                 ACTION_FUNCTION_LOAD_ARGUMENTS     = 0x0004,
01739                 ACTION_FUNCTION_SUPPRESS_ARGUMENTS = 0x0008,
01740                 ACTION_FUNCTION_LOAD_SUPER         = 0x0010,
01741                 ACTION_FUNCTION_SUPPRESS_SUPER     = 0x0020,
01742                 ACTION_FUNCTION_LOAD_ROOT          = 0x0040,
01743                 ACTION_FUNCTION_LOAD_PARENT        = 0x0080,
01744                 ACTION_FUNCTION_LOAD_GLOBAL        = 0x0100
01745         };
01746 
01747         void                            SetName(const char *name);
01748         void                            SetRegistersCount(unsigned int count);
01749         void                            AddParameter(const char *name, int register_number = -1);
01750         void                            AddAction(Action *action);
01751         virtual Vectors *               SubList(void);
01752 
01753         
01754         
01755         enum as_set_prop_flags_t {
01756                 PROP_FLAG_IS_HIDDEN = 1,
01757                 PROP_FLAG_CAN_DELETE = 2,
01758                 PROP_FLAG_CAN_OVERWRITE = 4
01759         };
01760 
01761 private:
01762 
01763         struct parameter_t : public ItemBase
01764         {
01765 
01766                 char *          f_name;
01767 
01768                 int             f_register_number;      
01769         };
01770 
01771         virtual Action *                Duplicate(void) const;
01772         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
01773         virtual ErrorManager::error_code_t ParseData(const Data& data);
01774 
01775         char *                          f_name;
01776         unsigned int                    f_registers_count;
01777         unsigned short                  f_flags;
01778         Vectors                         f_parameters;
01779         Vectors                         f_actions;
01780 };
01781 
01782 
01783 
01784 class ActionGoto : public Action, public MemoryManager
01785 {
01786 public:
01787         
01788 
01789 
01790 
01791 
01792                                         ActionGoto(TagBase *tag, action_t action = ACTION_GOTO_FRAME);
01793 
01794         void                            SetFrameName(const char *frame_name);
01795         void                            SetPlay(bool play) { f_play = play; }
01796 
01797 private:
01798         virtual Action *                Duplicate(void) const;
01799         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
01800         virtual ErrorManager::error_code_t ParseData(const Data& data);
01801 
01802         char *                          f_frame_name;
01803         unsigned long                   f_frame_number;
01804         bool                            f_play;
01805 };
01806 
01807 
01808 
01809 class ActionLabel : public Action, public MemoryManager
01810 {
01811 public:
01812         
01813 
01814 
01815                                         ActionLabel(TagBase *tag);
01816 
01817         void                            SetLabel(const char *label);
01818         const char *                    GetLabel(void) const { return f_label; }
01819 
01820 private:
01821         virtual Action *                Duplicate(void) const;
01822         
01823 
01824         char *                          f_label;
01825 };
01826 
01827 
01828 
01829 
01830 class ActionPushData : public Action, public MemoryManager
01831 {
01832 public:
01833         
01834 
01835 
01836                                         ActionPushData(TagBase *tag);
01837 
01838         void                            AddEmptyString(void) { AddString(0); }
01839         void                            AddString(const char *string);
01840         void                            AddTrue(void) { AddBoolean(true); }
01841         void                            AddFalse(void) { AddBoolean(false); }
01842         void                            AddBoolean(bool value);
01843         void                            AddInteger(long value);
01844         void                            AddFloat(float value);
01845         void                            AddDouble(double value);
01846         void                            AddNull(void);
01847         void                            AddLookup(unsigned short index);
01848         void                            AddRegister(unsigned char reg_index);
01849         void                            AddUndefined(void);
01850 
01851 private:
01852         enum action_immediate_type_t
01853         {
01854                 ACTION_IMMEDIATE_TYPE_UNKNOWN           = -1,
01855                 ACTION_IMMEDIATE_TYPE_STRING            = 0x00,
01856                 ACTION_IMMEDIATE_TYPE_FLOAT             = 0x01,
01857                 ACTION_IMMEDIATE_TYPE_NULL              = 0x02,
01858                 ACTION_IMMEDIATE_TYPE_UNDEFINED         = 0x03,
01859                 ACTION_IMMEDIATE_TYPE_REGISTER          = 0x04,
01860                 ACTION_IMMEDIATE_TYPE_BOOLEAN           = 0x05,
01861                 ACTION_IMMEDIATE_TYPE_DOUBLE            = 0x06,
01862                 ACTION_IMMEDIATE_TYPE_INTEGER           = 0x07,
01863                 ACTION_IMMEDIATE_TYPE_LOOKUP            = 0x08,
01864                 ACTION_IMMEDIATE_TYPE_LOOKUP_LARGE      = 0x09
01865         };
01866 
01867         struct action_immediate_t : public ItemBase
01868         {
01869                 action_immediate_type_t f_type;
01870                 union
01871                 {
01872                         char *          f_string;
01873                         float           f_float32;
01874                         double          f_float64;
01875                         bool            f_boolean;
01876                         long            f_integer32;
01877                         unsigned short  f_lookup;
01878                         unsigned char   f_register;
01879                 } f_data;
01880 
01881                 action_immediate_t(action_immediate_type_t type)
01882                 {
01883                         f_type = type;
01884                         memset(&f_data, 0, sizeof(f_data));
01885                 }
01886         };
01887 
01888         virtual Action *                Duplicate(void) const;
01889         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
01890         virtual ErrorManager::error_code_t ParseData(const Data& data);
01891         virtual int                     GetMaxRegister(void) const;
01892 
01893         Vectors                         f_data;
01894 };
01895 
01896 
01897 
01898 
01899 class ActionSetTarget : public Action, public MemoryManager
01900 {
01901 public:
01902         
01903 
01904 
01905                                         ActionSetTarget(TagBase *tag);
01906 
01907         void                            SetTarget(const char *target);
01908 
01909 private:
01910         virtual Action *                Duplicate(void) const;
01911         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
01912         virtual ErrorManager::error_code_t ParseData(const Data& data);
01913 
01914         char *                          f_target;
01915 };
01916 
01917 
01918 class ActionStoreRegister : public Action, public MemoryManager
01919 {
01920 public:
01921         
01922 
01923 
01924                                         ActionStoreRegister(TagBase *tag);
01925 
01926         void                            SetRegister(unsigned char reg);
01927 
01928 private:
01929         virtual Action *                Duplicate(void) const;
01930         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
01931         virtual ErrorManager::error_code_t ParseData(const Data& data);
01932         virtual int                     GetMaxRegister(void) const;
01933 
01934         unsigned char                   f_reg;
01935 };
01936 
01937 
01938 class ActionStrictMode : public Action, public MemoryManager
01939 {
01940 public:
01941         
01942 
01943 
01944                                         ActionStrictMode(TagBase *tag);
01945 
01946         void                            SetStrict(bool strict);
01947 
01948 private:
01949         virtual Action *                Duplicate(void) const;
01950         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
01951         virtual ErrorManager::error_code_t ParseData(const Data& data);
01952 
01953         bool                            f_strict;
01954 };
01955 
01956 
01957 class ActionTry : public Action, public MemoryManager
01958 {
01959 public:
01960         
01961 
01962 
01963                                         ActionTry(TagBase *tag);
01964                                         
01965         void                            AddTryAction(Action *action);
01966         void                            AddCatchAction(Action *action);
01967         void                            AddFinallyAction(Action *action);
01968         void                            SetIdentifier(int register_number);             
01969         void                            SetIdentifier(const char *variable_name);       
01970                                         
01971         Vectors *                       SubListTry(void);
01972         Vectors *                       SubListCatch(void);
01973         Vectors *                       SubListFinally(void);
01974 
01975 private:
01976         virtual Action *                Duplicate(void) const;
01977         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
01978         virtual ErrorManager::error_code_t ParseData(const Data& data);
01979         virtual int                     GetMaxRegister(void) const;
01980         virtual unsigned char           Version(void) const;
01981 
01982         int                             f_register;
01983         char *                          f_variable_name;
01984         bool                            f_has_catch;
01985         bool                            f_has_finally;
01986         Vectors                         f_actions_try;
01987         Vectors                         f_actions_catch;
01988         Vectors                         f_actions_finally;
01989 };
01990 
01991 
01992 
01993 class ActionURL : public Action, public MemoryManager
01994 {
01995 public:
01996         
01997 
01998 
01999 
02000                                         ActionURL(TagBase *tag, action_t action = ACTION_URL);
02001 
02002         enum url_method_t {
02003                 URL_METHOD_UNDEFINED = -1,
02004                 URL_METHOD_NOVARIABLE = 0,
02005                 URL_METHOD_NOVARIABLES = URL_METHOD_NOVARIABLE,
02006                 URL_METHOD_GET = 1,
02007                 URL_METHOD_POST = 2
02008         };
02009 
02010         void                            SetURL(const char *url, const char *target);
02011         void                            SetMethod(url_method_t method);
02012 
02013 private:
02014         virtual Action *                Duplicate(void) const;
02015         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
02016         virtual ErrorManager::error_code_t ParseData(const Data& data);
02017 
02018         char *                          f_url;
02019         char *                          f_target;
02020         url_method_t                    f_method;
02021 };
02022 
02023 
02024 
02025 class ActionWaitForFrame : public Action, public MemoryManager
02026 {
02027 public:
02028         
02029 
02030 
02031 
02032                                         ActionWaitForFrame(TagBase *tag, action_t action = ACTION_WAIT_FOR_FRAME);
02033 
02034         void                            SetFrameName(const char *name);
02035         void                            AddAction(Action *action);
02036         virtual Vectors *               SubList(void);
02037 
02038 private:
02039         virtual Action *                Duplicate(void) const;
02040         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
02041         virtual ErrorManager::error_code_t ParseData(const Data& data);
02042 
02043         Vectors                         f_actions;      
02044         char *                          f_frame_name;
02045         uint16_t                        f_frame;        
02046 };
02047 
02048 
02049 
02050 class ActionWith : public Action, public MemoryManager
02051 {
02052 public:
02053         
02054 
02055 
02056                                         ActionWith(TagBase *tag);
02057 
02058         void                            AddAction(Action *action);
02059         virtual Vectors *               SubList(void);
02060 
02061 private:
02062         virtual Action *                Duplicate(void) const;
02063         virtual ErrorManager::error_code_t SaveData(Data& data, Data& nested_data);
02064         virtual ErrorManager::error_code_t ParseData(const Data& data);
02065 
02066         Vectors                         f_actions;
02067 };
02068 
02069 
02070 
02071 
02072 
02073 
02074 class TagDoAction : public TagBase
02075 {
02076 public:
02077         
02078 
02079 
02080 
02081                                 TagDoAction(TagBase *parent);
02082 
02083         virtual ErrorManager::error_code_t Save(Data& data);
02084         virtual swf_type_t      TypeFlags(void) const;
02085 
02086 
02087         void                    SetAction(const Action& action);
02088         void                    SetSprite(sswf_id_t sprite);
02089         Vectors&                Actions(void) { return f_actions; }
02090 
02091 private:
02092         virtual ErrorManager::error_code_t PreSave(void);               
02093         virtual ErrorManager::error_code_t ParseTag(swf_tag_t tag, const Data& data);
02094 
02095         sswf_id_t               f_sprite;
02096         Vectors                 f_actions;
02097 };
02098 
02099 
02100 
02101 
02102 
02103 class TagMetadata : public TagBase
02104 {
02105 public:
02106                                 TagMetadata(TagBase *parent);
02107 
02108         virtual ErrorManager::error_code_t Save(Data& data);
02109         virtual swf_type_t      TypeFlags(void) const;
02110 
02111 
02112         
02113         
02114         
02115         
02116         
02117         
02118         
02119         
02120         
02121         
02122         
02123         
02124         
02125         
02126         
02127         
02128         
02129         
02130         
02131         
02132         void                    SetFilename(const char *filename);
02133         void                    SetMetadata(const char *xml);
02134         void                    SetTitle(const char *title);
02135         void                    SetDescription(const char *description);
02136         void                    SetAuthor(const char *description);
02137         void                    SetPublisher(const char *publisher);
02138         void                    SetCopyright(const char *copyright);
02139         void                    SetURL(const char *url);
02140 
02141 private:
02142         virtual ErrorManager::error_code_t PreSave(void);               
02143         virtual ErrorManager::error_code_t ParseTag(swf_tag_t tag, const Data& data);
02144 
02145         char *                  f_xml;
02146         char *                  f_filename;
02147         char *                  f_title;
02148         char *                  f_description;
02149         char *                  f_author;
02150         char *                  f_publisher;
02151         char *                  f_copyright;
02152         char *                  f_url;
02153 };
02154 
02155 
02156 
02157 
02158 
02159 class TagPlace : public TagBase
02160 {
02161 public:
02162                                         TagPlace(TagBase *parent);
02163 
02164         virtual ErrorManager::error_code_t Save(Data& data);
02165         virtual swf_type_t              TypeFlags(void) const;
02166 
02167 
02168         void                            SetObjectID(sswf_id_t id);
02169         void                            SetDepth(int depth);
02170         void                            SetClip(int depth);
02171         void                            SetMatrix(const Matrix& matrix);
02172         void                            SetColorTransform(const ColorTransform& color_transform);
02173         void                            SetName(const char *name);
02174         void                            SetMorphPosition(int position);
02175         void                            SetBlendMode(const BlendMode& blend_mode);
02176         void                            SetBitmapCaching(int bitmap_caching);
02177         void                            Replace(void);
02178         void                            Place(void);
02179         bool                            AddEvent(Event *event);
02180 
02181 private:
02182         virtual ErrorManager::error_code_t PreSave(void);               
02183         virtual ErrorManager::error_code_t ParseTag(swf_tag_t tag, const Data& data);
02184 
02185         bool                            f_id_defined;
02186         sswf_id_t                       f_id;
02187         int                             f_replace;
02188         int                             f_depth;
02189         int                             f_clip_depth;
02190         char *                          f_name;
02191         unsigned long                   f_events_all_flags;
02192         int                             f_position;             
02193         BlendMode                       f_blend_mode;
02194         int                             f_bitmap_caching;
02195         bool                            f_has_matrix;
02196         Matrix                          f_matrix;
02197         ColorTransform                  f_color_transform;
02198         Vectors                         f_events;
02199 };
02200 
02201 
02202 
02203 class TagRemove : public TagBase
02204 {
02205 public:
02206                                 TagRemove(TagBase *parent);
02207 
02208         virtual ErrorManager::error_code_t Save(Data& data);
02209         virtual swf_type_t      TypeFlags(void) const;
02210 
02211 
02212         void                    SetDepth(int depth) { f_depth = depth; }
02213         void                    SetObjectID(sswf_id_t id) { f_id = id; }
02214 
02215 private:
02216         virtual ErrorManager::error_code_t PreSave(void);               
02217         virtual ErrorManager::error_code_t ParseTag(swf_tag_t tag, const Data& data);
02218 
02219         int                     f_depth;
02220         sswf_id_t               f_id;
02221 };
02222 
02223 
02224 
02225 class TagSceneFrameData : public TagBase
02226 {
02227 public:
02228                                 TagSceneFrameData(TagBase *parent);
02229 
02230         virtual ErrorManager::error_code_t Save(Data& data);
02231         virtual swf_type_t      TypeFlags(void) const;
02232 
02233 
02234         bool                    SetFileData(const char *filename);
02235         void                    SetSceneFrameData(const char *data, size_t size);
02236 
02237 private:
02238         virtual ErrorManager::error_code_t PreSave(void);               
02239         virtual ErrorManager::error_code_t ParseTag(swf_tag_t tag, const Data& data);
02240 
02241         char *                  f_data;
02242         size_t                  f_size;
02243 };
02244 
02245 
02246 
02247 
02248 class TagScriptLimits : public TagBase
02249 {
02250 public:
02251                                 TagScriptLimits(TagBase *parent);
02252 
02253         virtual ErrorManager::error_code_t Save(Data& data);
02254         virtual swf_type_t      TypeFlags(void) const;
02255 
02256 
02257         void                    SetMaxRecursionDepth(int depth);
02258         void                    SetTimeoutSeconds(int timeout);
02259         int                     GetMaxRecursionDepth(void) const;
02260         int                     GetTimeoutSeconds(void) const;
02261 
02262 private:
02263         virtual ErrorManager::error_code_t PreSave(void);
02264         virtual ErrorManager::error_code_t ParseTag(swf_tag_t tag, const Data& data);
02265 
02266         int                     f_depth;
02267         int                     f_timeout;
02268 };
02269 
02270 
02271 
02272 class TagSetTabIndex : public TagBase
02273 {
02274 public:
02275                                 TagSetTabIndex(TagBase *parent);
02276 
02277         virtual ErrorManager::error_code_t Save(Data& data);
02278         virtual swf_type_t      TypeFlags(void) const;
02279 
02280 
02281         void                    SetDepth(int depth);
02282         void                    SetIndex(int timeout);
02283         int                     GetDepth(void) const;
02284         int                     GetIndex(void) const;
02285 
02286 private:
02287         virtual ErrorManager::error_code_t PreSave(void);
02288         virtual ErrorManager::error_code_t ParseTag(swf_tag_t tag, const Data& data);
02289 
02290         int                     f_depth;
02291         int                     f_index;
02292 };
02293 
02294 
02295 
02296 class TagSetBackgroundColor : public TagBase
02297 {
02298 public:
02299                                 TagSetBackgroundColor(TagBase *parent);
02300 
02301         virtual ErrorManager::error_code_t Save(Data& data);
02302         virtual swf_type_t      TypeFlags(void) const;
02303 
02304 
02305         void                    SetColor(Color& color);
02306         Color&                  GetColor(void);
02307 
02308 private:
02309         virtual ErrorManager::error_code_t ParseTag(swf_tag_t tag, const Data& data);
02310 
02311         Color                   f_color;
02312 };
02313 
02314 
02315 class TagShowFrame : public TagBase
02316 {
02317 public:
02318                                 TagShowFrame(TagBase *parent);
02319 
02320         virtual ErrorManager::error_code_t Save(Data& data);
02321         virtual swf_type_t      TypeFlags(void) const;
02322 
02323 private:
02324         virtual ErrorManager::error_code_t ParseTag(swf_tag_t tag, const Data& data);
02325 };
02326 
02327 
02328 class TagEnd : public TagBase
02329 {
02330 public:
02331                                 TagEnd(TagBase *parent);
02332 
02333         virtual ErrorManager::error_code_t Save(Data& data);
02334         virtual swf_type_t      TypeFlags(void) const;
02335 
02336 private:
02337         virtual ErrorManager::error_code_t ParseTag(swf_tag_t tag, const Data& data);
02338 };
02339 
02340 
02341 class TagFrameLabel : public TagBase 
02342 {
02343 public:
02344                                 TagFrameLabel(TagBase *parent);
02345 
02346         virtual ErrorManager::error_code_t Save(Data& data);
02347         virtual swf_type_t      TypeFlags(void) const;
02348 
02349 
02350         void                    SetFrameLabel(const char *label);
02351 
02352 private:
02353         virtual ErrorManager::error_code_t PreSave(void);
02354         virtual ErrorManager::error_code_t ParseTag(swf_tag_t tag, const Data& data);
02355 
02356         char *                  f_label;
02357 };
02358 
02359 
02360 
02361 class TagExport : public TagBase 
02362 {
02363 public:
02364                                 TagExport(TagBase *parent);
02365 
02366         virtual ErrorManager::error_code_t Save(Data& data);
02367         virtual swf_type_t      TypeFlags(void) const;
02368 
02369 
02370         void                    SetObject(sswf_id_t id, const char *name, const char *used_glyphs);
02371 
02372 private:
02373 
02374         struct export_t : public ItemBase
02375         {
02376                 sswf_id_t       f_id;
02377                 const char *    f_name;
02378                 const char *    f_used_glyphs;
02379         };
02380 
02381         virtual ErrorManager::error_code_t PreSave(void);
02382         virtual ErrorManager::error_code_t ParseTag(swf_tag_t tag, const Data& data);
02383 
02384         Vectors                 f_objects;
02385 };
02386 
02387 
02388 
02389 class TagImport : public TagBase 
02390 {
02391 public:
02392         
02393 
02394 
02395 
02396                                 TagImport(TagBase *parent);
02397 
02398         virtual ErrorManager::error_code_t Save(Data& data);
02399         virtual swf_type_t      TypeFlags(void) const;
02400         const char *            HasID(sswf_id_t id) const;
02401         sswf_id_t               HasName(const char *name) const;
02402 
02403 
02404         void                    SetURL(const char *url);
02405         void                    SetFilename(const char *filename);
02406         void                    AddName(const char *name, const char *type);
02407 
02408 private:
02409 
02410         struct import_t : public ItemBase
02411         {
02412                 sswf_id_t       f_id;           
02413                 const char *    f_name;         
02414                 const char *    f_type;         
02415         };
02416 
02417         virtual ErrorManager::error_code_t PreSave(void);
02418         virtual ErrorManager::error_code_t ParseTag(swf_tag_t tag, const Data& data);
02419 
02420         char *                  f_url;
02421         char *                  f_filename;
02422         Vectors                 f_objects;
02423 };
02424 
02425 
02426 
02427 class TagProtect : public TagBase 
02428 {
02429 public:
02430         
02431 
02432 
02433 
02434 
02435 
02436                                 TagProtect(TagBase *parent);
02437 
02438         virtual ErrorManager::error_code_t Save(Data& data);
02439         virtual swf_type_t      TypeFlags(void) const;
02440 
02441 
02442         void                    SetPassword(const char *password);
02443         void                    SetEncodedPassword(const char *password);
02444 
02445 private:
02446         virtual ErrorManager::error_code_t PreSave(void);
02447         virtual ErrorManager::error_code_t ParseTag(swf_tag_t tag, const Data& data);
02448 
02449         char *                  f_password;
02450 };
02451 
02452 
02453 
02454 class TagProductInfo : public TagBase
02455 {
02456 public:
02457                                 TagProductInfo(TagBase *parent);
02458 
02459         virtual ErrorManager::error_code_t Save(Data& data);
02460         virtual swf_type_t      TypeFlags(void) const;
02461 
02462 
02463         void                    SetProduct(long product_id);
02464         void                    SetEdition(long edition);
02465         void                    SetVersion(int major, int minor);
02466         void                    SetBuild(int64_t build_number);
02467         void                    SetCompileDate(int64_t date);
02468 
02469 private:
02470         virtual ErrorManager::error_code_t PreSave(void);
02471         virtual ErrorManager::error_code_t ParseTag(swf_tag_t tag, const Data& data);
02472 
02473         long                    f_product_id;
02474         long                    f_edition;
02475         int                     f_major;
02476         int                     f_minor;
02477         int64_t                 f_build_number;
02478         int64_t                 f_date;
02479 };
02480 
02481 
02482 
02483 class TagInfo : public TagBase 
02484 {
02485 public:
02486                                 TagInfo(TagBase *parent);
02487 
02488         virtual ErrorManager::error_code_t Save(Data& data);
02489         virtual swf_type_t      TypeFlags(void) const;
02490 
02491 
02492         void                    SetInfo(const char *info);
02493         void                    SetVersion(long version);
02494 
02495 private:
02496         virtual ErrorManager::error_code_t PreSave(void);
02497         virtual ErrorManager::error_code_t ParseTag(swf_tag_t tag, const Data& data);
02498 
02499         char *                  f_info;
02500         long                    f_version;
02501 };
02502 
02503 
02504 class TagStartSound : public TagBase 
02505 {
02506 public:
02507                                 TagStartSound(TagBase *parent);
02508 
02509         virtual ErrorManager::error_code_t Save(Data& data);
02510         virtual swf_type_t      TypeFlags(void) const;
02511 
02512 
02513         void                    SetInfo(SoundInfo *sound_info);
02514 
02515 private:
02516         virtual ErrorManager::error_code_t PreSave(void);
02517         virtual ErrorManager::error_code_t ParseTag(swf_tag_t tag, const Data& data);
02518 
02519         SoundInfo *             f_sound_info;
02520 };
02521 
02522 
02523 
02524 
02525 
02526 
02527 
02528 
02529 class TagScalingGrid
02530 {
02531 public:
02532         virtual                 ~TagScalingGrid();
02533 
02534         ErrorManager::error_code_t GridSave(Data& data, sswf_id_t id);
02535         ErrorManager::error_code_t GridPreSave(void);
02536 
02537         const SRectangle&       Grid(void) const;
02538 
02539 
02540         void                    SetGrid(const SRectangle& rect);
02541 
02542         ErrorManager::error_code_t ParseGridTag(TagBase::swf_tag_t tag, const Data& data);      
02543 
02544 private:
02545         SRectangle              f_grid;
02546 };
02547 
02548 
02549 
02550 
02551 
02552 
02553 
02554 
02555 
02556 
02557 
02558 
02559 
02560 
02561 
02562 
02563 class TagBaseID : public TagBase
02564 {
02565 public:
02566         virtual                 ~TagBaseID();
02567 
02568         virtual sswf_id_t       Identification(void) const;
02569         void                    NoIdentification(void);
02570         bool                    HasIdentification(void) const;
02571 
02572         int                     SaveID(Data& data) const;
02573         ErrorManager::error_code_t ParseID(const Data& data);
02574 
02575 public:
02576                                 TagBaseID(const char *name, TagBase *parent);
02577 
02578 private:
02579         sswf_id_t               f_id;
02580         bool                    f_identified;
02581 };
02582 
02583 
02584 
02585 
02586 
02587 class TagBinaryData : public TagBaseID
02588 {
02589 public:
02590                                 TagBinaryData(TagBase *parent);
02591         virtual                 ~TagBinaryData();
02592 
02593         virtual ErrorManager::error_code_t Save(Data& data);
02594         virtual swf_type_t      TypeFlags(void) const;
02595 
02596 
02597         void                    GetData(const char *& data, size_t& size) const;
02598         void                    SetData(const char *data, size_t size);
02599 
02600 private:
02601         virtual ErrorManager::error_code_t PreSave(void);
02602         virtual ErrorManager::error_code_t ParseTag(swf_tag_t tag, const Data& data);
02603 
02604         char *                  f_data;
02605         size_t                  f_size;
02606 };
02607 
02608 
02609 
02610 
02611 class TagButton : public TagBaseID, public TagScalingGrid
02612 {
02613 public:
02614                                 TagButton(TagBase *parent);
02615 
02616         virtual ErrorManager::error_code_t Save(Data& data);
02617         virtual swf_type_t      TypeFlags(void) const;
02618 
02619 
02620         bool                    SetState(const State& state);
02621         void                    SetAction(const Action& action);
02622         void                    SetMenu(bool menu = true);
02623         Vectors&                Actions(void);
02624         bool                    AddEvent(Event *event);
02625 
02626 private:
02627         virtual ErrorManager::error_code_t PreSave(void);               
02628         virtual ErrorManager::error_code_t ParseTag(swf_tag_t tag, const Data& data);
02629 
02630         bool                    f_save_button2;
02631         bool                    f_menu;                 
02632         Vectors                 f_states;
02633         Vectors                 f_actions;
02634         Vectors                 f_events;
02635 };
02636 
02637 
02638 
02639 class TagCSMTextSettings
02640 {
02641 public:
02642         enum csm_text_renderer_t {
02643                 CSM_TEXT_RENDERER_NORMAL = 0,
02644                 CSM_TEXT_RENDERER_FLASH = 1
02645         };
02646         enum csm_text_gridfit_t {
02647                 CSM_TEXT_GRIDFIT_NO_GRID = 0,
02648                 CSM_TEXT_GRIDFIT_PIXEL = 1,
02649                 CSM_TEXT_GRIDFIT_SUBPIXEL = 2
02650         };
02651 
02652                                         TagCSMTextSettings(void);
02653         virtual                         ~TagCSMTextSettings(void);
02654 
02655         bool                            IsCSMTextSettingsDefined(void) const;
02656 
02657         void                            SetRenderer(csm_text_renderer_t csm_text_renderer);
02658         void                            SetGridFit(csm_text_gridfit_t csm_text_gridfit);
02659         void                            SetThickness(float thickness);
02660         void                            SetSharpness(float sharpness);
02661 
02662 protected:
02663         
02664         ErrorManager::error_code_t      PreSaveCSMTextSettings(void);
02665         ErrorManager::error_code_t      SaveCSMTextSettings(Data& data);
02666         ErrorManager::error_code_t      ParseTag(TagBase::swf_tag_t tag, const Data& data);
02667 
02668 private:
02669         csm_text_renderer_t             f_csm_text_renderer;
02670         csm_text_gridfit_t              f_csm_text_gridfit;
02671         float                           f_thickness;
02672         float                           f_sharpness;
02673 };
02674 
02675 
02676 class TagShape;
02677 class TagFont : public TagBaseID
02678 {
02679 public:
02680         enum font_type_t {
02681                 FONT_TYPE_BEST = 0,             
02682                 FONT_TYPE_ASCII,
02683                 FONT_TYPE_UNICODE,
02684                 FONT_TYPE_SHIFTJIS,
02685         };
02686         enum font_language_t {
02687                 FONT_LANGUAGE_UNKNOWN                   = -1,
02688                 FONT_LANGUAGE_LOCALE                    = 0,
02689                 FONT_LANGUAGE_LATIN                     = 1,
02690                 FONT_LANGUAGE_JAPANESE                  = 2,
02691                 FONT_LANGUAGE_KOREAN                    = 3,
02692                 FONT_LANGUAGE_SIMPLIFIED_CHINESE        = 4,
02693                 FONT_LANGUAGE_TRADITIONAL_CHINESE       = 5,
02694 
02695                 FONT_LANGUAGE_max                       = 6
02696         };
02697         enum font_thickness_t {
02698                 FONT_THICKNESS_UNKNOWN  = -1,
02699                 FONT_THICKNESS_THIN     =  0,
02700                 FONT_THICKNESS_MEDIUM   =  1,
02701                 FONT_THICKNESS_THICK    =  2,
02702 
02703                 FONT_THICKNESS_max      =  3
02704         };
02705         enum font_em_size_t {
02706                 FONT_EM_SMALL = 0,
02707                 FONT_EM_LARGE = 1
02708         };
02709 
02710 #define SSWF_FONT_SPACE_INDEX           static_cast<unsigned long>(-1)
02711 
02712 
02713         struct font_info_t {
02714                 sswf_ucs4_t             f_glyph;        
02715                 unsigned short          f_saved_index;  
02716                 unsigned long           f_index;        
02717                 unsigned long           f_position;     
02718                 long                    f_advance;      
02719                 bool                    f_is_empty;     
02720         };
02721 
02722                                 TagFont(TagBase *parent);
02723 
02724         virtual ErrorManager::error_code_t Save(Data& data);
02725         virtual swf_type_t              TypeFlags(void) const;
02726         ErrorManager::error_code_t      GlyphInfo(font_info_t& info) const;
02727         bool                            HasGlyph(void) const;
02728         bool                            FindGlyph(font_info_t& info, bool mark_empty_in_use = false) const;
02729         const char *                    FontName(void) const;
02730         long                            DefaultAscent(void) const;
02731         long                            DefaultDescent(void) const;
02732         long                            DefaultLeadingHeight(void) const;
02733         static font_language_t          StringToLanguage(const char *language);
02734         static const char *             LanguageToString(font_language_t language);
02735 
02736 
02737         
02738         
02739         
02740         
02741         
02742         
02743         
02744         ErrorManager::error_code_t      AddGlyph(sswf_ucs4_t name, const TagBase *ref, long advance = LONG_MIN);
02745         void                            SetName(const char *font_name);
02746         void                            SetDisplayName(const char *display_name);
02747         void                            SetCopyright(const char *copyright);
02748         void                            SetLayout(long ascent, long descent, long leading_height);
02749         void                            SetDefaultAdvance(long advance);
02750         void                            SetSpaceAdvance(long advance);
02751         void                            SetType(font_type_t type);
02752         void                            SetLanguage(font_language_t language);
02753         void                            SetBold(bool bold);
02754         void                            SetItalic(bool italic);
02755         void                            SetSmallText(bool small_text = true);
02756         void                            SetThickness(font_thickness_t thickness);
02757         void                            SetEMSize(font_em_size_t font_em_size);
02758         void                            SetWide(bool wide);
02759         ErrorManager::error_code_t      SetUsedGlyphs(const char *used_glyphs, bool mark_empty_in_use = false);
02760         ErrorManager::error_code_t      SetUsedGlyphs(const sswf_ucs4_t *used_glyphs, bool mark_empty_in_use = false);
02761         void                            SetUsedByEditText(bool used = true);
02762         void                            AddKern(sswf_ucs4_t code0, sswf_ucs4_t code1, long advance);
02763 
02764 private:
02765 
02766         struct font_glyph_t : public ItemBase
02767         {
02768                 sswf_ucs4_t     f_name;         
02769                 unsigned short  f_index;        
02770                 const TagShape *f_shape;        
02771                 long            f_advance;      
02772                 bool            f_in_use;       
02773         };
02774 
02775         struct font_kern_t : public ItemBase
02776         {
02777                 sswf_ucs4_t     f_code[2];
02778                 long            f_advance;
02779         };
02780 
02781         virtual ErrorManager::error_code_t PreSave(void);
02782         virtual ErrorManager::error_code_t PreSave2ndPass(void);
02783         virtual ErrorManager::error_code_t ParseTag(swf_tag_t tag, const Data& data);
02784 
02785         static const char *     g_font_language_name[FONT_LANGUAGE_max];
02786         char *                  f_font_name;
02787         char *                  f_display_name;
02788         char *                  f_copyright;
02789         font_language_t         f_language;             
02790         font_type_t             f_type;                 
02791         bool                    f_bold;
02792         bool                    f_italic;
02793         bool                    f_small_text;
02794         bool                    f_wide;
02795         bool                    f_has_wide_char;        
02796         bool                    f_has_wide_offsets;     
02797         bool                    f_has_layout;           
02798         bool                    f_used_by_edit_text;    
02799         bool                    f_define_font2;         
02800         font_thickness_t        f_thickness;
02801         font_em_size_t          f_font_em_size;
02802         long                    f_ascent;
02803         long                    f_descent;
02804         long                    f_leading_height;
02805         long                    f_default_advance;
02806         long                    f_space_advance;
02807         long                    f_offsets_max;          
02808         unsigned long *         f_offsets;              
02809         unsigned long           f_count;                
02810         Data                    f_save_glyphs;          
02811         Vectors                 f_glyphs;
02812         Vectors                 f_kerns;
02813 };
02814 
02815 
02816 
02817 
02818 
02819 class TagEditText : public TagBaseID, public TagCSMTextSettings
02820 {
02821 public:
02822         enum edit_text_alignment_t {
02823                 EDIT_TEXT_ALIGNMENT_LEFT = 0,
02824                 EDIT_TEXT_ALIGNMENT_RIGHT = 1,
02825                 EDIT_TEXT_ALIGNMENT_CENTER = 2,
02826                 EDIT_TEXT_ALIGNMENT_JUSTIFY = 3
02827         };
02828 
02829                                 TagEditText(TagBase *parent);
02830 
02831         virtual ErrorManager::error_code_t Save(Data& data);
02832         virtual swf_type_t      TypeFlags(void) const;
02833 
02834 
02835         void                    SetText(const char *text);
02836         void                    SetVariableName(const char *name);
02837         void                    SetFont(const TagFont *font, long height);
02838         void                    SetMargins(long left, long right);
02839         void                    SetBounds(const SRectangle& bounds);
02840         void                    SetAlign(edit_text_alignment_t align);
02841         void                    SetIndent(long indent);
02842         void                    SetLeading(long leading);
02843         void                    SetColor(Color& color);
02844         void                    SetMaxLength(long length);
02845         void                    SetWordWrap(bool status = true);
02846         void                    SetMultiline(bool status = true);
02847         void                    SetPassword(bool status = true);
02848         void                    SetReadOnly(bool status = true);
02849         void                    SetNoSelect(bool status = true);
02850         void                    SetBorder(bool status = true);
02851         void                    SetOutline(bool status = true);
02852         void                    SetHTML(bool status = true);
02853         void                    SetAutoSize(bool status = true);
02854         void                    SetUsedGlyphs(const char *lists);
02855         void                    AddUsedString(const char *string);
02856 
02857 private:
02858         virtual ErrorManager::error_code_t PreSave(void);
02859         virtual ErrorManager::error_code_t ParseTag(swf_tag_t tag, const Data& data);
02860 
02861         SRectangle              f_bounds;               
02862         edit_text_alignment_t   f_align;
02863         long                    f_left_margin;
02864         long                    f_right_margin;
02865         long                    f_indent;
02866         long                    f_leading;
02867         const TagFont *         f_font;
02868         unsigned short          f_font_height;
02869         long                    f_max_length;           
02870         char *                  f_var_name;             
02871         char *                  f_text;                 
02872         sswf_ucs4_t *           f_used_glyphs;          
02873         sswf_ucs4_t *           f_used_strings;         
02874         Color                   f_color;
02875         bool                    f_has_color;            
02876         bool                    f_word_wrap;
02877         bool                    f_multiline;
02878         bool                    f_password;
02879         bool                    f_readonly;
02880         bool                    f_no_select;
02881         bool                    f_border;
02882         bool                    f_outline;
02883         bool                    f_html;
02884         bool                    f_autosize;
02885 };
02886 
02887 
02888 class TagImage : public TagBaseID
02889 {
02890 public:
02891         enum image_format_t {
02892                 IMAGE_FORMAT_UNKNOWN = 0,
02893                 IMAGE_FORMAT_LOSSLESS_BEST,
02894                 IMAGE_FORMAT_LOSSLESS_8,
02895                 IMAGE_FORMAT_LOSSLESS_16,
02896                 IMAGE_FORMAT_LOSSLESS_32,
02897                 IMAGE_FORMAT_JPEG,
02898                 IMAGE_FORMAT_max
02899         };
02900 
02901         struct image_t {
02902                 bool            f_alpha;                
02903                 long            f_width;                
02904                 long            f_height;
02905                 unsigned char * f_data;                 
02906         };
02907 
02908                                         TagImage(TagBase *parent);
02909         
02910 
02911         virtual ErrorManager::error_code_t Save(Data& data);
02912         virtual swf_type_t              TypeFlags(void) const;
02913         void                            GetImageData(image_t& image_data) { image_data = f_image; }
02914 
02915 
02916         void                            SetFormat(image_format_t format) { f_format = format; }
02917         void                            SetQuality(int quality) { f_quality = quality; }
02918         void                            SetDeblock(int deblock) { f_deblock = deblock; }
02919         ErrorManager::error_code_t      SetFilename(const char *image, const char *mask);
02920         void                            SetImage(long width, long height, unsigned char *data, bool alpha = false, long count = 0, unsigned char *colormap = 0);
02921 
02922         ErrorManager::error_code_t      LoadTGA(const char *filename, image_t& im);
02923         ErrorManager::error_code_t      LoadJPEG(const char *filename, image_t& im);
02924         ErrorManager::error_code_t      SaveJPEG(Data& encoding, Data& image);
02925         ErrorManager::error_code_t      SetAlpha(image_t& im, const image_t& mask);
02926 
02927 private:
02928         virtual ErrorManager::error_code_t PreSave(void);
02929         virtual ErrorManager::error_code_t ParseTag(swf_tag_t tag, const Data& data);
02930 
02931         image_format_t          f_format;               
02932         image_t                 f_image;                
02933         int                     f_quality;              
02934         int                     f_deblock;              
02935         long                    f_count;                
02936         unsigned char *         f_colormap;             
02937 };
02938 
02939 
02940 
02941 class TagShape : public TagBaseID
02942 {
02943 public:
02944         enum morph_t {
02945                 MORPH_MODE_SHAPE0 = 0,
02946                 MORPH_MODE_SHAPE1 = 1,
02947                 MORPH_MODE_BOTH_SHAPES = 2
02948         };
02949         enum fill_t {
02950                 SHAPE_FILL_EVEN = 0,            
02951                 SHAPE_FILL_ODD = 1              
02952         };
02953 
02954                                         TagShape(TagBase *parent);
02955 
02956         virtual ErrorManager::error_code_t Save(Data& data);
02957         virtual swf_type_t              TypeFlags(void) const;
02958         ErrorManager::error_code_t      SaveWithoutStyles(Data& data);
02959         void                            SaveAlignZone(Data& data) const;
02960         bool                            HasAlignZone(void) const;
02961         bool                            HasBounds(void) const { return !f_bounds[0].IsEmpty() || !f_bounds[1].IsEmpty(); }
02962         const SRectangle&               Bounds(int index) const { assert(index == 0 || index == 1, "invalid index to query bounds"); return f_bounds[index]; }
02963         bool                            IsGlyph(void) const;
02964         bool                            IsEmpty(void) const;
02965 
02966 
02967 
02968         ErrorManager::error_code_t      AddMove(morph_t morph_mode, long x, long y);
02969         ErrorManager::error_code_t      AddEdge(morph_t morph_mode, long x, long y) { Edges::edge_t edge(x, y); return AddEdge(morph_mode, edge); }
02970         ErrorManager::error_code_t      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); return AddEdge(morph_mode, edge); };
02971         void                            NewStyles(void);
02972         ErrorManager::error_code_t      AddStyle(const Style& style, fill_t fill = SHAPE_FILL_EVEN);
02973         void                            SetAlignZone(const SRectangle& zone);
02974         ErrorManager::error_code_t      SetBounds(int index, const SRectangle& rect, bool show = false);
02975         ErrorManager::error_code_t      SetStrokesBounds(int index, const SRectangle& rect);
02976         void                            ShowBounds(bool show = true) { f_show_bounds = show; }
02977         void                            ShowOrigin(bool show = true) { f_show_origin = show; }
02978         void                            SetNonScalingStrokes(bool has_non_scaling_strokes) { f_has_non_scaling_strokes = has_non_scaling_strokes; }
02979         void                            SetScalingStrokes(bool has_scaling_strokes) { f_has_scaling_strokes = has_scaling_strokes; }
02980         void                            Glyph(void);
02981 
02982         bool                            HasShowBounds(void) const { return f_show_bounds; }
02983 
02984 public:
02985         ErrorManager::error_code_t      AddEdge(morph_t morph_mode, const Edges::edge_t& edge);
02986 
02987 private:
02988         enum what_t {
02989                 SHAPE_EDGES,
02990                 SHAPE_SETUP
02991         };
02992 
02993 
02994         struct shape_what_t : public ItemBase
02995         {
02996                 what_t          f_what;
02997                                 shape_what_t(what_t what) { f_what = what; }
02998         };
02999 
03000         struct shape_edges_t : public shape_what_t
03001         {
03002                 Edges           f_edges;
03003                                 shape_edges_t(what_t what) : shape_what_t(what) {}
03004         };
03005 
03006         struct shape_setup_t : public shape_what_t
03007         {
03008                 int             f_fill_ref[2];
03009                 int             f_line_ref;
03010                 long            f_x;
03011                 long            f_y;
03012 
03013                                 shape_setup_t(what_t what, bool origin = false) : shape_what_t(what)
03014                                 {
03015                                         f_fill_ref[0] = f_fill_ref[1] = f_line_ref = -1;
03016                                         if(origin) {
03017                                                 f_x = f_y = 0;
03018                                         }
03019                                         else {
03020                                                 f_x = f_y = LONG_MIN;
03021                                         }
03022                                 }
03023         };
03024 
03025 
03026         struct shape_record_t : public ItemBase {               
03027                 Vectors *       f_fill_styles;
03028                 Vectors *       f_line_styles;
03029                 Vectors *       f_record;
03030         };
03031 
03032 
03033         struct save_info_t {
03034                 shape_record_t  f_sr;
03035                 bool            f_save_alpha;
03036                 bool            f_ext_size;
03037                 bool            f_first;
03038                 bool            f_save_styles;
03039                 bool            f_shape4;
03040                 Data            f_data;                 
03041                 int             f_fill_bits_count;
03042                 int             f_line_bits_count;
03043         };
03044 
03045         void                            RecordEdges(void);
03046         void                            RecordSetup(void);
03047         void                            NewEdges(void);
03048         void                            NewSetup(void);
03049         void                            SetMorph(void);
03050 
03051         
03052         virtual ErrorManager::error_code_t PreSave(void);
03053         ErrorManager::error_code_t      SaveShape(save_info_t& info, shape_setup_t& last_setup);
03054         
03055         ErrorManager::error_code_t      SaveSetup(save_info_t& info, const shape_setup_t& setup, shape_setup_t& last);
03056         ErrorManager::error_code_t      SaveStyles(save_info_t& info);
03057         ErrorManager::error_code_t      SaveStylesCount(save_info_t& info, long count);
03058         virtual ErrorManager::error_code_t ParseTag(swf_tag_t tag, const Data& data);
03059         void                            ParseAlignZone(const Data& data);
03060 
03061         unsigned char                   f_version;              
03062         bool                            f_morph;                
03063         bool                            f_is_glyph;             
03064         bool                            f_show_bounds;          
03065         bool                            f_show_origin;          
03066         bool                            f_has_non_scaling_strokes;      
03067         bool                            f_has_scaling_strokes;  
03068         SRectangle                      f_align_zone;           
03069         SRectangle                      f_bounds[2];            
03070         SRectangle                      f_strokes_bounds[2];    
03071 
03072         Vectors                         f_shapes;               
03073 
03074         shape_edges_t *                 f_edges;                
03075         shape_edges_t *                 f_morph_edges;          
03076         shape_setup_t *                 f_setup;                
03077         Vectors                         f_fill_styles;
03078         Vectors                         f_line_styles;
03079         Vectors                         f_record;               
03080         Vectors                         f_morph_record;         
03081 };
03082 
03083 
03084 
03085 class TagSound : public TagBaseID
03086 {
03087 public:
03088         enum sound_format_t {
03089                 SOUND_FORMAT_UNKNOWN = -1,
03090                 SOUND_FORMAT_RAW = 0,
03091                 SOUND_FORMAT_ADPCM = 1,
03092                 SOUND_FORMAT_MP3 = 2,
03093                 SOUND_FORMAT_UNCOMPRESSED = 3,
03094                 SOUND_FORMAT_NELLYMOSER = 6
03095         };
03096         enum sound_endian_t {
03097                 SOUND_ENDIAN_LITTLE = 0,        
03098                 SOUND_ENDIAN_BIG,               
03099                 SOUND_ENDIAN_SAME,              
03100                 SOUND_ENDIAN_DONTUSE,           
03101                 SOUND_ENDIAN_UNKNOWN            
03102         };
03103 
03104                                 TagSound(TagBase *parent);
03105 
03106         virtual ErrorManager::error_code_t Save(Data& data);
03107         virtual swf_type_t      TypeFlags(void) const;
03108 
03109         size_t                  GetSamplesCount(void) const;
03110 
03111 
03112         ErrorManager::error_code_t SetFilename(const char *filename);
03113         void                    SetFormat(sound_format_t format);
03114         int                     SetData(const void *data, size_t size, sound_endian_t endian, int width, unsigned int rate, bool stereo);
03115         void                    SetMono(void);
03116         void                    Set8Bits(void);
03117 
03118 public:
03119         static const int        g_sound_rates[4];
03120 
03121 private:
03122 
03123         struct sound_wave_t {
03124                 short           format;                 
03125                 short           channels;               
03126                 int             rate;                   
03127                 int             average_rate;           
03128                 short           align;                  
03129                 
03130                 short           width;                  
03131         };
03132 
03133         virtual ErrorManager::error_code_t PreSave(void);
03134         short                   ReadSample(const unsigned char *data, unsigned short adjust, int in_fmt);
03135         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);
03136         int                     LoadWaveFile(FILE *f);
03137         int                     LoadMP3File(FILE *f);
03138         int                     CheckMP3Header(FILE *f, unsigned char *header, int& frame_size);
03139         int                     ReadMP3Header(FILE *f, unsigned char *header);
03140         virtual ErrorManager::error_code_t ParseTag(swf_tag_t tag, const Data& data);
03141 
03142         static const int        g_bitrates[2][16];
03143         static const int        g_frequencies[4][4];
03144 
03145         sound_format_t          f_format;
03146         bool                    f_stereo;
03147         int                     f_rate;
03148         int                     f_width;
03149         size_t                  f_samples;
03150         int                     f_data_size;
03151         int                     f_data_maxsize;
03152         unsigned char *         f_data;
03153         int                     f_latency_seek;
03154 };
03155 
03156 
03157 
03158 
03159 
03160 
03161 class TagSprite : public TagBaseID, public TagScalingGrid
03162 {
03163 public:
03164                                 TagSprite(TagBase *parent);
03165 
03166         virtual ErrorManager::error_code_t Save(Data& data);
03167         virtual swf_type_t      TypeFlags(void) const;
03168 
03169 
03170         
03171         
03172         
03173 
03174         
03175         
03176 
03177 protected:
03178         virtual ErrorManager::error_code_t OnNewChild(const char *child_name) const;
03179 
03180 private:
03181         virtual ErrorManager::error_code_t PreSave(void);
03182         virtual ErrorManager::error_code_t ParseTag(swf_tag_t tag, const Data& data);
03183 };
03184 
03185 
03186 
03187 
03188 class TagText : public TagBaseID, public TagCSMTextSettings
03189 {
03190 public:
03191                                         TagText(TagBase *parent);
03192 
03193         virtual ErrorManager::error_code_t Save(Data& data);
03194         virtual swf_type_t              TypeFlags(void) const;
03195 
03196 
03197         void                            SetMatrix(const Matrix& matrix);
03198         void                            SetBounds(const SRectangle& bounds);
03199         ErrorManager::error_code_t      AddText(const char *string, long advance = LONG_MIN);
03200         void                            AddFont(const TagFont *font, long height);
03201         void                            AddOffsets(long x, long y);
03202         void                            AddColor(Color& color);
03203 
03204 private:
03205         enum text_type_t {
03206                 TEXT_ENTRY_TEXT = 0,
03207                 TEXT_ENTRY_SETUP
03208         };
03209 
03210 
03211         struct text_define_t : public ItemBase {                
03212                 const text_type_t       f_type;
03213 
03214                                         text_define_t(text_type_t type) : f_type(type) {}
03215         };
03216 
03217 
03218         struct text_setup_t : public text_define_t {            
03219                 bool                    f_has_font;
03220                 const TagFont *         f_font;
03221                 unsigned short          f_font_height;
03222                 bool                    f_has_xadjust;
03223                 long                    f_xadjust;
03224                 bool                    f_has_xoffset;
03225                 long                    f_x;
03226                 bool                    f_has_yoffset;
03227                 long                    f_y;
03228                 bool                    f_has_color;
03229                 Color                   f_color;
03230 
03231                                         text_setup_t(void);
03232                                         text_setup_t(const text_setup_t& setup);
03233                 void                    Unused(void);
03234                 bool                    IsUsed(void) const;
03235         };
03236 
03237 
03238         struct text_entry_t : public text_define_t {
03239                 sswf_ucs4_t *           f_text;
03240                 long                    f_advance;
03241                 unsigned long           f_length;               
03242                 unsigned long           f_exact_length;         
03243                 TagFont::font_info_t *  f_entries;              
03244 
03245                                         text_entry_t(sswf_ucs4_t *string, long advance);
03246         };
03247 
03248         virtual ErrorManager::error_code_t PreSave(void);
03249         int                             DefineText(int start, text_setup_t *s, const TagFont *font, int font_height);
03250         ErrorManager::error_code_t      RecordSetup(void);
03251         void                            NewSetup(void);
03252         virtual ErrorManager::error_code_t ParseTag(swf_tag_t tag, const Data& data);
03253 
03254         Matrix                  f_matrix;               
03255         SRectangle              f_bounds;               
03256         text_setup_t            f_setup;                
03257         bool                    f_new_text;             
03258         int                     f_version;              
03259         Vectors                 f_records;              
03260 };
03261 
03262 
03263 
03264 
03265 
03266 
03267 
03268 
03269 
03270 };              
03271 #endif