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; }
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; }
/* * set the dimensions of a movie * This function sets the dimensions for the movie. */ void SWFMovie_setDimension(SWFMovie movie /* movie to adjust */, float width /* new width of the movie */, float height /* new height of the movie */) { if ( movie->bounds != NULL ) free(movie->bounds); /*printf("Ming_scale: %g, with: %g, height: %g\n", Ming_scale, width, height);*/ movie->bounds = newSWFRect(0, (int)rint(Ming_scale*width), 0, (int)rint(Ming_scale*height)); }
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; }
/* * create a new SWFMovie * This function creates a new SWFMovie with the specified version. */ SWFMovie newSWFMovieWithVersion(int version /* Flash version */) { SWFMovie movie; Ming_useSWFVersion(version); movie = (SWFMovie) malloc(sizeof(struct SWFMovie_s)); /* If malloc failed, return NULL to signify this */ if (movie == NULL) return NULL; movie->version = version; movie->blockList = newSWFBlockList(); movie->displayList = newSWFDisplayList(); /* Default movie dimension is hard-coded to 320x240 pixels */ movie->bounds = newSWFRect(0, 320*20, 0, 240*20); movie->rate = 12.0; movie->totalFrames = 0; movie->nFrames = 0; movie->nExports = 0; movie->exports = NULL; movie->nImports = 0; movie->imports = NULL; movie->nFonts = 0; movie->fonts = NULL; movie->backgroundBlock = NULL; if(version >= 8) movie->fattrs = newSWFFileAttributes(); else movie->fattrs = NULL; movie->metadata = NULL; movie->limits = NULL; movie->symbolClass = NULL; movie->sceneData = NULL; #if TRACK_ALLOCS movie->gcnode = ming_gc_add_node(movie, (dtorfunctype) destroySWFMovie); #endif return movie; }
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; }
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; }
void SWFText_resolveCodes(SWFText text) { SWFTextRecord textRecord, oldRecord; SWFOutput out = text->out; int nGlyphBits = 0; int len, i; int curX = 0, curY = 0, curH = 0; textRecord = text->initialRecord; while ( textRecord != NULL ) { SWFTextRecord_computeAdvances(textRecord); text->nAdvanceBits = max(text->nAdvanceBits, textRecord->nAdvanceBits); if ( textRecord->flags & SWF_TEXT_HAS_FONT ) { int fontGlyphs = SWFFontCharacter_getNGlyphs(textRecord->font.fontchar); nGlyphBits = max(nGlyphBits, SWFOutput_numBits(fontGlyphs-1)); } textRecord = textRecord->next; } textRecord = text->initialRecord; while ( textRecord != NULL ) { SWFFontCharacter fontchar = NULL; SWFFont font = NULL; oldRecord = textRecord; if ( textRecord->string == NULL || textRecord->strlen == 0 ) { textRecord = textRecord->next; destroySWFTextRecord(oldRecord); continue; } SWFOutput_byteAlign(out); /* Raff says the spec lies- there's always a change record, even if it's empty, and the string record length is the full 8 bits. */ SWFOutput_writeUInt8(out, textRecord->flags | SWF_TEXT_STATE_CHANGE); if ( textRecord->flags & SWF_TEXT_HAS_FONT ) SWFOutput_writeUInt16(out, CHARACTERID(textRecord->font.fontchar)); if ( textRecord->flags & SWF_TEXT_HAS_COLOR ) { SWFOutput_writeUInt8(out, textRecord->r); SWFOutput_writeUInt8(out, textRecord->g); SWFOutput_writeUInt8(out, textRecord->b); if ( BLOCK(text)->type == SWF_DEFINETEXT2 ) SWFOutput_writeUInt8(out, textRecord->a); } if ( textRecord->flags & SWF_TEXT_HAS_X ) { SWFOutput_writeUInt16(out, textRecord->x); curX = textRecord->x; } if ( textRecord->flags & SWF_TEXT_HAS_Y ) { SWFOutput_writeUInt16(out, textRecord->y); curY = textRecord->y; } if ( textRecord->flags & SWF_TEXT_HAS_FONT ) { SWFOutput_writeUInt16(out, textRecord->height); curH = textRecord->height; } /* record type 0: string data */ len = textRecord->strlen; if ( len >= 256 ) SWF_error("Found text record >= 256 characters!"); SWFOutput_writeUInt8(out, len); fontchar = textRecord->font.fontchar; font = SWFFontCharacter_getFont(fontchar); if ( font == NULL ) SWF_error("Couldn't find font"); for ( i=0; i<len; ++i ) { SWFRect glyphBounds; int minX, maxX, minY, maxY; unsigned short font_glyphcode = SWFFont_findGlyphCode(font, textRecord->string[i]); glyphBounds = SWFFont_getGlyphBounds(font,font_glyphcode); SWFRect_getBounds(glyphBounds, &minX, &maxX, &minY, &maxY); int fontchar_glyphcode = SWFFontCharacter_findGlyphCode(fontchar, textRecord->string[i]); if (fontchar_glyphcode < 0) { SWF_error("SWFText_resolveCodes: no suitable glyph available (in dumped font)"); } SWFOutput_writeBits(out, (unsigned short) fontchar_glyphcode, nGlyphBits); SWFOutput_writeBits(out, textRecord->advance[i], text->nAdvanceBits); if ( CHARACTER(text)->bounds ) { SWFRect_includePoint(CHARACTER(text)->bounds, curX + minX * curH / 1024, curY + minY * curH / 1024, 0); SWFRect_includePoint(CHARACTER(text)->bounds, curX + maxX * curH / 1024, curY + maxY * curH / 1024, 0); } else { CHARACTER(text)->bounds = newSWFRect(curX + minX * curH /1024, curX + maxX * curH /1024, curY + minY * curH /1024, curY + maxY * curH /1024); } if ( textRecord->advance != NULL ) curX += textRecord->advance[i]; } textRecord = textRecord->next; destroySWFTextRecord(oldRecord); } SWFOutput_writeUInt8(out, 0); /* end text records */ text->nGlyphBits = nGlyphBits; text->initialRecord = NULL; text->currentRecord = NULL; }
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; }
void SWFText_resolveCodes(SWFText text) { SWFTextRecord textRecord, oldRecord; SWFOutput out = text->out; int nGlyphBits = 0; int len, i; int curX = 0, curY = 0, curH = 0; textRecord = text->initialRecord; while ( textRecord != NULL ) { SWFTextRecord_computeAdvances(textRecord); text->nAdvanceBits = max(text->nAdvanceBits, textRecord->nAdvanceBits); if ( textRecord->flags & SWF_TEXT_HAS_FONT ) { if ( textRecord->isBrowserFont ) { /* XXX - assume browser fonts have 8bit glyph table? */ nGlyphBits = max(nGlyphBits, 8); } else { int fontGlyphs = SWFFontCharacter_getNGlyphs(textRecord->font.fontchar); nGlyphBits = max(nGlyphBits, SWFOutput_numBits(fontGlyphs-1)); } } textRecord = textRecord->next; } textRecord = text->initialRecord; while ( textRecord != NULL ) { oldRecord = textRecord; if ( textRecord->string == NULL || textRecord->strlen == 0 ) { textRecord = textRecord->next; destroySWFTextRecord(oldRecord); continue; } SWFOutput_byteAlign(out); /* Raff says the spec lies- there's always a change record, even if it's empty, and the string record length is the full 8 bits. */ SWFOutput_writeUInt8(out, textRecord->flags | SWF_TEXT_STATE_CHANGE); if ( textRecord->flags & SWF_TEXT_HAS_FONT ) { if ( textRecord->isBrowserFont ) SWFOutput_writeUInt16(out, CHARACTERID(textRecord->font.browserFont)); else SWFOutput_writeUInt16(out, CHARACTERID(textRecord->font.fontchar)); } if ( textRecord->flags & SWF_TEXT_HAS_COLOR ) { SWFOutput_writeUInt8(out, textRecord->r); SWFOutput_writeUInt8(out, textRecord->g); SWFOutput_writeUInt8(out, textRecord->b); if ( BLOCK(text)->type == SWF_DEFINETEXT2 ) SWFOutput_writeUInt8(out, textRecord->a); } if ( textRecord->flags & SWF_TEXT_HAS_X ) { SWFOutput_writeUInt16(out, textRecord->x); curX = textRecord->x; } if ( textRecord->flags & SWF_TEXT_HAS_Y ) { SWFOutput_writeUInt16(out, textRecord->y); curY = textRecord->y; } if ( textRecord->flags & SWF_TEXT_HAS_FONT ) { SWFOutput_writeUInt16(out, textRecord->height); curH = textRecord->height; } /* record type 0: string data */ len = textRecord->strlen; if ( len >= 256 ) SWF_error("Found text record >= 256 characters!"); SWFOutput_writeUInt8(out, len); /* XXX - er, browser fonts in text objects crash the player.. Maybe because there's no definefontinfo block? */ if ( textRecord->isBrowserFont ) { for ( i=0; i<len; ++i ) { SWFOutput_writeBits(out, textRecord->string[i], nGlyphBits); SWFOutput_writeBits(out, textRecord->advance[i], text->nAdvanceBits); /* XXX - fudging the text character bounds since we don't have font metrics */ if ( CHARACTER(text)->bounds ) { SWFRect_includePoint(CHARACTER(text)->bounds, curX, curY, 0); SWFRect_includePoint(CHARACTER(text)->bounds, curX + curH, curY + curH, 0); } else { CHARACTER(text)->bounds = newSWFRect(curX, curX + curH, curY, curY + curH); } curX += curH; } } else { SWFFontCharacter fontchar = textRecord->font.fontchar; SWFFont font = SWFFontCharacter_getFont(fontchar); if ( font == NULL ) SWF_error("Couldn't find font"); for ( i=0; i<len; ++i ) { SWFRect glyphBounds; int minX, maxX, minY, maxY; unsigned short code = SWFFontCharacter_getGlyphCode(fontchar, textRecord->string[i]); glyphBounds = SWFFont_getGlyphBounds(font, code); SWFRect_getBounds(glyphBounds, &minX, &maxX, &minY, &maxY); SWFOutput_writeBits(out, textRecord->string[i], nGlyphBits); SWFOutput_writeBits(out, textRecord->advance[i], text->nAdvanceBits); if ( CHARACTER(text)->bounds ) { SWFRect_includePoint(CHARACTER(text)->bounds, curX + minX * curH / 1024, curY + minY * curH / 1024, 0); SWFRect_includePoint(CHARACTER(text)->bounds, curX + maxX * curH / 1024, curY + maxY * curH / 1024, 0); } else { CHARACTER(text)->bounds = newSWFRect(curX + minX * curH /1024, curX + maxX * curH /1024, curY + minY * curH /1024, curY + maxY * curH /1024); } if ( textRecord->advance != NULL ) curX += textRecord->advance[i]; } } textRecord = textRecord->next; destroySWFTextRecord(oldRecord); } SWFOutput_writeUInt8(out, 0); /* end text records */ text->nGlyphBits = nGlyphBits; text->initialRecord = NULL; text->currentRecord = NULL; }
SWFRect SWFRect_copy(SWFRect rect) { return newSWFRect(rect->minX, rect->maxX, rect->minY, rect->maxY); }