swfstreams.int
上传用户:raido2005
上传日期:2022-06-22
资源大小:5044k
文件大小:5k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. //*******************************************************//
  2. //                                                       //
  3. //                      DelphiFlash.com                  //
  4. //        Copyright (c) 2004-2008 FeatherySoft, Inc.     //
  5. //                    info@delphiflash.com               //
  6. //                                                       //
  7. //*******************************************************//
  8. //  Description:  Streams for reading and writing of SWF file
  9. //  Last update:  12 mar 2008
  10. {$I defines.inc}
  11. unit SWFStreams;
  12. interface
  13. Uses Windows, Classes, SysUtils,
  14.  {$IFDEF XMLSupport}
  15.   SWFStrings, XMLDoc, XMLIntf, SWFXMLTools,
  16.  {$ENDIF}
  17.   SWFConst, Contnrs, SWFObjects;
  18. type
  19.   TSWFTagInfo = class (TObject)
  20.     BodySize: LongInt;
  21.     FramePlace: Word;
  22.     isLongSize: Boolean;
  23.     Position: LongInt;
  24.     SubTags: TObjectList;
  25.     selfDestroy: boolean;
  26.     SWFObject: TSWFObject;
  27.     TagID: Word;
  28.     constructor Create(ID: word; automake: boolean = true);
  29.     destructor Destroy; override;
  30.     function GetFullSize: LongInt;
  31.   end;
  32.   TBasedSWFStream = class;
  33.   TProgressWorkType = (pwtReadStream, pwtMakeStream, pwtCompressStream, pwtLoadXML, pwtParseXML, pwtSaveXML);
  34.   TSWFProgressEvent = procedure (sender: TBasedSWFStream; Percent: byte; WT: TProgressWorkType) of object;
  35.   TSWFParseTagBodyEvent = procedure (sender: TSWFTagInfo; var Parse: boolean) of object;
  36.   TSWFProcessTagEvent = procedure (sender: TSWFObject; var Process: boolean) of object;
  37.   TSWFRenameObjectEvent = procedure (sender: TSWFObject; var newname: string) of object;
  38. // ================== TBasedSWFStream =========================
  39.   TBasedSWFStream = class (TObject)
  40.   public
  41.     SWFHeader: TSWFHeader;
  42.     constructor Create; overload; virtual;
  43.     constructor Create(XMin, YMin, XMax, YMax: integer; fps: single; sc: TSWFSystemCoord = scTwips); overload; virtual;
  44.     destructor Destroy; override;
  45.     function FramePos(num: word): longint; virtual; abstract;
  46.     function GetHeaderSize: Integer;
  47.     procedure MakeStream; virtual; abstract;
  48.     procedure MoveResource(ToFrame, StartFrom, EndFrom: integer); virtual; abstract;
  49.     procedure SaveToFile(fn: string);
  50.     procedure SaveToStream(Stream: TStream);
  51.     procedure SetSWFRect(v: TRect);
  52.     procedure WriteHeader(stream: TStream; part: TSWFHeaderPart = hpAll);
  53. {$IFDEF XMLSupport}
  54.     function LoadFromXML(XML: IXMLDocument; asNew: boolean): boolean; virtual; abstract;
  55.     function LoadFromXMLFile(fname: string; asNew: boolean): boolean;
  56.     function LoadFromXMLString(const source: string; asNew: boolean): boolean;
  57.     property XMLReadWriteSettings: TXMLReadWriteSettings read FXMLReadWriteSettings write FXMLReadWriteSettings;
  58. {$ENDIF}
  59.     property BodyStream: TStream read GetBodyStream write SetBodyStream;
  60.     property Compressed: Boolean read FCompressed write SetCompressed;
  61.     property FPS: Single read GetFPS write SetFPS;
  62.     property FramesCount: Word read SWFHeader.FramesCount;
  63.     property Height: Integer read GetHeight write SetHeight;
  64.     property MovieRect: TRect read GetSWFRect write SWFHeader.MovieRect;
  65.     property MultCoord: Byte read FMultCoord write FMultCoord;
  66.     property SystemCoord: TSWFSystemCoord read FSystemCoord write SetSystemCoord;
  67.     property Version: Byte read SWFHeader.Version write SetVersion;
  68.     property Width: Integer read GetWidth write SetWidth;
  69.     property OnProgress: TSWFProgressEvent read FOnProgress write FOnProgress;
  70.   end;
  71.   TSWFStreamReader = class (TBasedSWFStream)
  72.   public
  73.     constructor Create(fn: string); overload;
  74.     constructor Create(stream: TStream); overload;
  75.     destructor Destroy; override;
  76.     function CheckSWF(stest: TStream): Boolean;
  77.     procedure DeleteTagByID(Place, Obj: boolean; ID: word);
  78.     procedure DeleteTagByName(Place, Obj: boolean; name: string);
  79.     function FindIDFromName(name: string): word;
  80.     function FindObjectFromID(ID: word): TSWFObject;
  81.     function FindObjectFromName(name: string): TSWFObject;
  82.     function FindPlaceFromID(ID: word): TSWFPlaceObject;
  83.     function FindPlaceFromName(name: string): TSWFPlaceObject2;
  84.     function FindTagFromID(ID: word): longint;
  85.     function FindTagFromObject(Obj: TSWFObject): longint;
  86.     function FindTagFromName(name: string): longint;
  87.     function FramePos(num: word): longint; override;
  88.     function GetMinVersion: Byte;
  89.     procedure LoadFromFile(fn: string);
  90.     procedure LoadFromStream(stream: TStream);
  91.     function LoadHeader(src: TStream; part: TSWFHeaderPart = hpAll): Integer;
  92.     procedure MakeStream; override;
  93.     procedure MoveResource(ToFrame, StartFrom, EndFrom: integer); override;
  94.     procedure ReadBody(ParseTagData, ParseActionData: boolean);
  95.     procedure Rename(prefix: string);
  96.     function Renumber(start: word): Word;
  97. {$IFDEF XMLSupport}
  98.     procedure SaveToXML(XML: IXMLDocument);
  99.     procedure SaveToXMLFile(fname: string);
  100.     function LoadFromXML(XML: IXMLDocument; asNew: boolean): boolean; override;
  101. {$ENDIF}
  102.     property IsSWF: Boolean read FIsSWF;
  103.     property OnParseTagBody: TSWFParseTagBodyEvent read FOnParseTagBody write FOnParseTagBody;
  104.     property OnRenameObject: TSWFRenameObjectEvent read FOnRenameObject write FOnRenameObject;
  105.     property OnRenumberTag: TSWFProcessTagEvent read FOnRenumberTag write FOnRenumberTag;
  106.     property TagInfo[index: word]: TSWFTagInfo read GetTagInfo;
  107.     property TagList: TObjectList read FTagList;
  108.   end;
  109. implementation