SWFText newSWFText() { SWFText text = (SWFText)malloc(sizeof(struct SWFText_s)); SWFCharacterInit((SWFCharacter)text); CHARACTERID(text) = ++SWF_gNumCharacters; BLOCK(text)->type = SWF_DEFINETEXT; BLOCK(text)->writeBlock = writeSWFTextToMethod; BLOCK(text)->complete = completeSWFText; BLOCK(text)->dtor = (destroySWFBlockMethod) destroySWFText; CHARACTER(text)->bounds = newSWFRect(0,0,0,0); text->out = newSWFOutput(); text->currentRecord = NULL; text->initialRecord = NULL; text->matrix = NULL; text->nAdvanceBits = 0; #if TRACK_ALLOCS text->gcnode = ming_gc_add_node(text, (dtorfunctype) destroySWFBitmap); #endif return text; }
SWFText newSWFText() { SWFRect temp_rect; SWFText text = (SWFText)malloc(sizeof(struct SWFText_s)); /* If malloc failed, return NULL to signify this */ if (NULL == text) return NULL; SWFCharacterInit((SWFCharacter)text); CHARACTERID(text) = ++SWF_gNumCharacters; BLOCK(text)->type = SWF_DEFINETEXT; BLOCK(text)->writeBlock = writeSWFTextToMethod; BLOCK(text)->complete = completeSWFText; BLOCK(text)->dtor = (destroySWFBlockMethod) destroySWFText; temp_rect = newSWFRect(0,0,0,0); /* If newSWFRect() failed, return NULL to signify this */ if (NULL == temp_rect) { free(text); return NULL; } CHARACTER(text)->bounds = temp_rect; text->out = newSWFOutput(); /* If newSWFOutput() failed, return NULL to signify this */ if (NULL == text->out) { destroySWFRect(temp_rect); free(text); return NULL; } text->currentRecord = NULL; text->initialRecord = NULL; text->matrix = NULL; text->nAdvanceBits = 0; #if TRACK_ALLOCS text->gcnode = ming_gc_add_node(text, (dtorfunctype) destroySWFText); #endif return text; }
SWFPrebuiltClip newSWFPrebuiltClip() { SWFPrebuiltClip clip = (SWFPrebuiltClip)malloc(sizeof(struct SWFPrebuiltClip_s)); SWFCharacterInit((SWFCharacter)clip); BLOCK(clip)->type = SWF_PREBUILTCLIP; BLOCK(clip)->writeBlock = writeSWFPrebuiltClipToMethod; BLOCK(clip)->complete = completeSWFPrebuiltClip; BLOCK(clip)->dtor = (destroySWFBlockMethod) destroySWFPrebuiltClip; clip->frames = 0; clip->display = newSWFOutput(); return clip; }
SWFShape newSWFShape() { SWFShape shape = (SWFShape)malloc(sizeof(struct SWFShape_s)); /* If malloc failed, return NULL to signify this */ if (NULL == shape) return NULL; SWFCharacterInit((SWFCharacter)shape); BLOCK(shape)->writeBlock = writeSWFShapeBlockToMethod; BLOCK(shape)->complete = completeSWFShapeBlock; BLOCK(shape)->dtor = (destroySWFBlockMethod) destroySWFShape; BLOCK(shape)->type = SWF_DEFINESHAPE3; CHARACTERID(shape) = ++SWF_gNumCharacters; shape->out = newSWFOutput(); CHARACTER(shape)->bounds = newSWFRect(0,0,0,0); shape->edgeBounds = newSWFRect(0,0,0,0); shape->records = NULL; shape->lines = NULL; shape->fills = NULL; shape->nRecords = 0; shape->xpos = 0; shape->ypos = 0; shape->nLines = 0; shape->nFills = 0; shape->lineWidth = 0; shape->isMorph = FALSE; shape->isEnded = FALSE; shape->flags = 0; shape->useVersion = SWF_SHAPE3; SWFOutput_writeUInt8(shape->out, 0); /* space for nFillBits, nLineBits */ #if TRACK_ALLOCS shape->gcnode = ming_gc_add_node(shape, (dtorfunctype) destroySWFShape); #endif return shape; }
/** * creates a browser font instance * This Function allows the usage of built in fonts like "_sans". * Takes the name of the font as an argument. */ SWFBrowserFont newSWFBrowserFont(const char *name) { SWFBrowserFont font = (SWFBrowserFont) malloc(sizeof(struct SWFBrowserFont_s)); SWFCharacterInit((SWFCharacter)font); BLOCK(font)->writeBlock = writeSWFBrowserFontToMethod; BLOCK(font)->complete = completeSWFBrowserFont; BLOCK(font)->dtor = (destroySWFBlockMethod) destroySWFBrowserFont; BLOCK(font)->type = SWF_BROWSERFONT; CHARACTERID(font) = ++SWF_gNumCharacters; font->out = NULL; font->name = strdup(name); return font; }
SWFDBLBitmapData newSWFDBLBitmapData_fromData(dblData data) { SWFDBLBitmapData dbl; dbl = (SWFDBLBitmapData)malloc(sizeof(struct SWFDBLBitmapData_s)); /* If malloc failed, return NULL to signify this */ if (NULL == dbl) return NULL; SWFCharacterInit((SWFCharacter)dbl); CHARACTERID(dbl) = ++SWF_gNumCharacters; BLOCK(dbl)->writeBlock = writeSWFDBLBitmapDataToMethod; BLOCK(dbl)->complete = completeSWFDBLBitmap; BLOCK(dbl)->dtor = (destroySWFBlockMethod) destroySWFDBLBitmapData; dbl->width = data->width; dbl->height = data->height; dbl->format = data->format; dbl->format2 = data->format2; dbl->data = data->data; if(data->hasalpha) BLOCK(dbl)->type = SWF_DEFINELOSSLESS2; else BLOCK(dbl)->type = SWF_DEFINELOSSLESS; BLOCK(dbl)->length = data->length; BLOCK(dbl)->length += 7; /* character id, format, width, height */ if(dbl->format == 3) BLOCK(dbl)->length++; CHARACTER(dbl)->bounds = newSWFRect(0, dbl->width, 0, dbl->height); #if TRACK_ALLOCS dbl->gcnode = ming_gc_add_node(dbl, (dtorfunctype)destroySWFDBLBitmapData); #endif return dbl; }
/* * Import a character to the movie * Imports characters from an other movie. filename (URL) points to a SWF * file with exported characters. * * returns a SWFCharacter object */ SWFCharacter SWFMovie_importCharacter(SWFMovie movie, const char *filename /* URL to movie */, const char *name /* idetifier of character */) { SWFCharacter res; SWFImportBlock importer; int id; res = (SWFCharacter) malloc(sizeof(struct SWFCharacter_s)); SWFCharacterInit(res); CHARACTERID(res) = id = ++SWF_gNumCharacters; BLOCK(res)->type = SWF_DEFINESPRITE; BLOCK(res)->writeBlock = NULL; BLOCK(res)->complete = completeSWFImportCharacter; BLOCK(res)->dtor = (destroySWFBlockMethod) destroySWFCharacter; importer = SWFMovie_addImport(movie, filename, name, id); SWFCharacter_addDependency(res, (SWFCharacter) importer); return res; }
SWFSceneData newSWFSceneData() { SWFSceneData sdata= (SWFSceneData)malloc(sizeof(struct SWFSceneData_s)); SWFCharacterInit((SWFCharacter)sdata); BLOCK(sdata)->type = SWF_DEFINESCENEANDFRAMEDATA; BLOCK(sdata)->writeBlock = writeSWFSceneDataToMethod; BLOCK(sdata)->complete = completeSWFSceneData; BLOCK(sdata)->dtor = (destroySWFBlockMethod) destroySWFSceneData; sdata->sceneCount = 0; sdata->sceneOffset = NULL; sdata->sceneName = NULL; sdata->frameLabelCount = 0; sdata->frameNumber = NULL; sdata->frameLabel = NULL; sdata->out = NULL; return sdata; }
SWFTextField newSWFTextField() { SWFRect temp_rect; SWFTextField field = (SWFTextField)malloc(sizeof(struct SWFTextField_s)); /* If malloc failed, return NULL to signify this */ if (NULL == field) return NULL; SWFCharacterInit((SWFCharacter)field); BLOCK(field)->writeBlock = writeSWFTextFieldToMethod; BLOCK(field)->complete = completeSWFTextField; BLOCK(field)->dtor = (destroySWFBlockMethod) destroySWFTextField; BLOCK(field)->type = SWF_DEFINEEDITTEXT; CHARACTERID(field) = ++SWF_gNumCharacters; temp_rect = newSWFRect(-40, 280, -40, 280); /* If newSWFRect() failed, return NULL to signify this */ if (NULL == temp_rect) { free(field); return NULL; } CHARACTER(field)->bounds = temp_rect; field->out = NULL; field->lineSpacing = 40; field->padding = 40; field->fontHeight = 240; field->fieldHeight = 0; field->width = 0; field->a = 0xff; field->nLines = 1; field->flags = 0; field->font.font = NULL; field->fonttype = Unresolved; field->varName = NULL; field->string = NULL; field->r = 0; field->g = 0; field->b = 0; field->a = 0xff; field->length = 0; field->alignment = SWFTEXTFIELD_ALIGN_LEFT; field->leftMargin = 0; field->rightMargin = 0; field->indentation = 0; field->embeds = NULL; field->embedlen = 0; return field; }
SWFDBLBitmap newSWFDBLBitmap_fromInput(SWFInput input) { SWFDBLBitmap dbl; int version; int width, height; dbl = (SWFDBLBitmap)malloc(sizeof(struct SWFDBLBitmap_s)); SWFCharacterInit((SWFCharacter)dbl); CHARACTERID(dbl) = ++SWF_gNumCharacters; BLOCK(dbl)->writeBlock = writeSWFDBLBitmapToMethod; BLOCK(dbl)->complete = completeSWFDBLBitmap; BLOCK(dbl)->dtor = (destroySWFBlockMethod) destroySWFCharacter; dbl->input = input; if ( SWFInput_getChar(input) != 'D' || SWFInput_getChar(input) != 'B' ) { SWF_error("File is not a DBL file!"); } version = SWFInput_getChar(input); if ( version != 'L' && version != 'l' ) SWF_error("File is not a DBL file!"); switch ( SWFInput_getChar(input) ) { case 1: BLOCK(dbl)->type = SWF_DEFINELOSSLESS; break; case 2: BLOCK(dbl)->type = SWF_DEFINELOSSLESS2; break; default: SWF_error("Unexpected DBL type byte!"); } if ( version == 'l' ) { BLOCK(dbl)->length = SWFInput_getUInt32_BE(input); BLOCK(dbl)->length += 2; /* character id */ } else { /* first version used a 2-byte file length.. brilliant, eh? */ BLOCK(dbl)->length = SWFInput_getUInt16_BE(input); BLOCK(dbl)->length += 2; /* character id */ } SWFInput_getChar(input); /* format */ width = SWFInput_getUInt16(input); height = SWFInput_getUInt16(input); /* roll back to beginning of dbl data */ SWFInput_seek(input, -5, SEEK_CUR); CHARACTER(dbl)->bounds = newSWFRect(0, width, 0, height); return dbl; }