📄 movie.c
字号:
/* Ming, an SWF output library Copyright (C) 2002 Opaque Industries - http://www.opaque.net/ This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*//* $Id: movie.c,v 1.28 2004/01/18 19:29:18 whamann Exp $ */#include <stdlib.h>#include <string.h>#include <math.h>#include <zlib.h>#include "ming.h"#include "movie.h"#include "shape_util.h"#include "blocklist.h"#include "displaylist.h"#include "blocks/block.h"#include "blocks/method.h"#include "blocks/browserfont.h"#include "blocks/character.h"#include "blocks/outputblock.h"#include "blocks/soundstream.h"#include "blocks/exports.h"#include "blocks/imports.h"#include "blocks/rect.h"#include "blocks/font.h"#include "blocks/textfield.h"#include "blocks/shape.h"#include "blocks/soundinstance.h"struct SWFMovie_s{ SWFBlockList blockList; SWFDisplayList displayList; /* frame rate */ float rate; /* movie bounds */ SWFRect bounds; /* number of frames currently assigned */ unsigned short nFrames; /* total number of frames, if requested by user */ unsigned short totalFrames; /* version number of this movie */ byte version; /* export items */ int nExports; struct SWFExport_s *exports; /* import items */ int nImports; struct SWFImportBlock_s **imports; /* list of fonts used in this movie */ int nFonts; SWFFontCharacter* fonts; /* background color */ byte r; byte g; byte b;};static voiddestroySWFExports(SWFMovie movie){ int n; for ( n=0; n<movie->nExports; ++n ) free(movie->exports[n].name); free(movie->exports); movie->nExports = 0; movie->exports = NULL;}voiddestroySWFMovie(SWFMovie movie){ destroySWFBlockList(movie->blockList); destroySWFDisplayList(movie->displayList); destroySWFRect(movie->bounds); if ( movie->nExports > 0 ) destroySWFExports(movie); if ( movie->fonts != NULL ) free(movie->fonts); if (movie->imports) free(movie->imports); free(movie);}SWFMovienewSWFMovieWithVersion(int version){ SWFMovie movie = (SWFMovie) malloc(sizeof(struct SWFMovie_s)); movie->version = version; movie->blockList = newSWFBlockList(); movie->displayList = newSWFDisplayList(); movie->bounds = newSWFRect(0, 320*20, 0, 240*20); movie->rate = 12.0; movie->totalFrames = 1; movie->nFrames = 0; movie->nExports = 0; movie->exports = NULL; movie->nImports = 0; movie->imports = NULL; movie->nFonts = 0; movie->fonts = NULL; movie->r = 0xff; movie->g = 0xff; movie->b = 0xff; return movie;}SWFMovienewSWFMovie(){ return newSWFMovieWithVersion(SWF_versionNum);}voidSWFMovie_setRate(SWFMovie movie, float rate){ movie->rate = rate;}voidSWFMovie_setDimension(SWFMovie movie, float width, float height){ if ( movie->bounds != NULL ) free(movie->bounds); movie->bounds = newSWFRect(0, (int)rint(Ming_scale*width), 0, (int)rint(Ming_scale*height));}voidSWFMovie_setNumberOfFrames(SWFMovie movie, int totalFrames){ movie->totalFrames = totalFrames;}voidSWFMovie_setBackground(SWFMovie movie, byte r, byte g, byte b){ movie->r = r; movie->g = g; movie->b = b;}voidSWFMovie_protect(SWFMovie movie){ SWFMovie_addBlock(movie, newSWFProtectBlock());}SWFFontCharacterSWFMovie_addFont(SWFMovie movie, SWFFont font){ SWFFontCharacter fontchar; int i; for( i = 0 ; i < movie->nFonts ; i++ ) { fontchar = movie->fonts[i]; if ( SWFFontCharacter_getFont(fontchar) == font ) return fontchar; } movie->fonts = (SWFFontCharacter*)realloc(movie->fonts, sizeof(SWFFontCharacter) * (movie->nFonts + 1)); fontchar = newSWFFontCharacter(font); movie->fonts[movie->nFonts++] = fontchar; SWFMovie_addBlock(movie, (SWFBlock)fontchar); return fontchar;}static voidSWFMovie_resolveTextFonts(SWFMovie movie, SWFText text){ // translate text object font references to movie-specific fontchars SWFTextRecord record = SWFText_getInitialRecord(text); SWFFontCharacter fontchar; while ( record != NULL ) { SWFFont font = SWFTextRecord_getUnresolvedFont(record); if ( font != NULL ) { fontchar = SWFMovie_addFont(movie, font); SWFTextRecord_setFontCharacter(record, fontchar); } record = SWFTextRecord_getNextRecord(record); }}static voidSWFMovie_resolveTextfieldFont(SWFMovie movie, SWFTextField field){ // given a font used for a text field, add it to the movie SWFFontCharacter fontchar; SWFFont font = SWFTextField_getUnresolvedFont(field); if ( font != NULL ) { fontchar = SWFMovie_addFont(movie, font); SWFTextField_setFontCharacter(field, fontchar); }}voidSWFMovie_addBlock(SWFMovie movie, SWFBlock block){ if ( SWFBlock_getType(block) == SWF_SHOWFRAME ) ++movie->nFrames; SWFBlockList_addBlock(movie->blockList, block);}voidSWFMovie_addExport(SWFMovie movie, SWFBlock block, const char *name){ switch( SWFBlock_getType(block)) { case SWF_DEFINESPRITE: case SWF_DEFINEFONT2: movie->exports = (struct SWFExport_s*)realloc(movie->exports, (movie->nExports+1) * sizeof(struct SWFExport_s)); movie->exports[movie->nExports].block = block; movie->exports[movie->nExports].name = strdup(name); ++movie->nExports; default: break; }}static voidSWFMovie_addCharacterDependencies(SWFMovie movie, SWFCharacter character);static voidSWFMovie_addDependency(SWFMovie movie, SWFCharacter character){ if ( SWFBlock_getType((SWFBlock)character) == SWF_DEFINETEXT || SWFBlock_getType((SWFBlock)character) == SWF_DEFINETEXT2 ) { SWFMovie_resolveTextFonts(movie, (SWFText)character); } else if ( SWFBlock_getType((SWFBlock)character) == SWF_DEFINEEDITTEXT) { SWFMovie_resolveTextfieldFont(movie, (SWFTextField)character); } else if ( SWFBlock_getType((SWFBlock)character) == SWF_DEFINEFONT) { SWFMovie_addCharacterDependencies(movie, character); } SWFMovie_addBlock(movie, (SWFBlock)character);}static voidSWFMovie_addCharacterDependencies(SWFMovie movie, SWFCharacter character){ SWFCharacter* deps = NULL; int nDeps = 0; if ( SWFCharacter_getDependencies(character, &deps, &nDeps) ) { int i; for ( i = 0; i < nDeps; ++i ) SWFMovie_addDependency(movie, deps[i]); free(deps); }}voidSWFMovie_writeExports(SWFMovie movie){ int n; SWFBlock exports; if ( movie->nExports == 0 ) return; for ( n=0; n<movie->nExports; ++n ) { SWFBlock b = movie->exports[n].block; if ( SWFBlock_isCharacter(b) && !SWFBlock_isDefined(b) ) { SWFMovie_addCharacterDependencies(movie, (SWFCharacter)b); completeSWFBlock(b); SWFMovie_addBlock(movie, b); } } exports = (SWFBlock)newSWFExportBlock(movie->exports, movie->nExports); SWFMovie_addBlock(movie, exports); destroySWFExports(movie);}SWFDisplayItemSWFMovie_add(SWFMovie movie, SWFBlock block)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -