/* THAGA */ void SWFShape_newStyles(SWFShape shape) { ShapeRecord record; shape->isUsingNewStyles = TRUE; if (shape->isNewStylesLast == TRUE) { int i; record = shape->records[shape->nRecords-1]; for ( i=0; i<*shape->nFills; ++i ) { SWFMatrix matrix = SWFFillStyle_getMatrix((*shape->fills)[i]); if ( matrix != NULL ) destroySWFMatrix(matrix); /* gradients and bitmaps are destroyed separately */ free((*shape->fills)[i]); } if ( *shape->fills != NULL ) free(*shape->fills); for ( i=0; i<*shape->nLines; ++i ) free((*shape->lines)[i]); if ( *shape->lines != NULL ) free(*shape->lines); } else { record = newShapeRecord(shape, SHAPERECORD_STATECHANGE); } record.record.stateChange->flags |= SWF_SHAPE_FILLSTYLE0FLAG; record.record.stateChange->flags |= SWF_SHAPE_FILLSTYLE1FLAG; record.record.stateChange->flags |= SWF_SHAPE_LINESTYLEFLAG; record.record.stateChange->flags |= SWF_SHAPE_NEWSTYLEFLAG; shape->lines = &record.record.stateChange->lines; shape->fills = &record.record.stateChange->fills; shape->nLines = &record.record.stateChange->nLines; shape->nFills = &record.record.stateChange->nFills; shape->isNewStylesLast = TRUE; *shape->lines = NULL; *shape->fills = NULL; *shape->nLines = 0; *shape->nFills = 0; }
SWFFill newSWFFill(SWFFillStyle fillstyle) { SWFFill fill = (SWFFill)malloc(sizeof(struct SWFFill_s)); fill->fillstyle = fillstyle; fill->position = newSWFPosition(SWFFillStyle_getMatrix(fill->fillstyle)); #if TRACK_ALLOCS fill->gcnode = ming_gc_add_node(fill, (dtorfunctype) destroySWFFill); #endif return fill; }
void SWFShape_writeShapeRecord(SWFShape shape, ShapeRecord record) { SWFOutput out = shape->out; switch(record.type) { case SHAPERECORD_STATECHANGE: { int flags = record.record.stateChange->flags; if(flags == 0) return; SWFOutput_writeBits(out, flags, 6); if(flags & SWF_SHAPE_MOVETOFLAG) { int x = record.record.stateChange->moveToX; int y = record.record.stateChange->moveToY; int nBits = max(SWFOutput_numSBits(x), SWFOutput_numSBits(y)); SWF_assert(nBits<32); SWFOutput_writeBits(out, nBits, 5); SWFOutput_writeSBits(out, x, nBits); SWFOutput_writeSBits(out, y, nBits); } if(flags & SWF_SHAPE_FILLSTYLE0FLAG) { SWFOutput_writeBits(out, record.record.stateChange->leftFill, SWFOutput_numBits(shape->nFills2)); } if(flags & SWF_SHAPE_FILLSTYLE1FLAG) { SWFOutput_writeBits(out, record.record.stateChange->rightFill, SWFOutput_numBits(shape->nFills2)); } if(flags & SWF_SHAPE_LINESTYLEFLAG) { SWFOutput_writeBits(out, record.record.stateChange->line, SWFOutput_numBits(shape->nLines2)); } /* newstyle's never used. But this is what it looks like: */ if ( flags & SWF_SHAPE_NEWSTYLEFLAG ) { int i; shape->lines = &record.record.stateChange->lines; shape->fills = &record.record.stateChange->fills; shape->nLines = &record.record.stateChange->nLines; shape->nFills = &record.record.stateChange->nFills; shape->nFills2 = *shape->nFills; shape->nLines2 = *shape->nLines; SWFOutput_writeFillStyles(shape->out, *shape->fills, *shape->nFills, BLOCK(shape)->type); SWFOutput_writeLineStyles(shape->out, *shape->lines, *shape->nLines, BLOCK(shape)->type); SWFOutput_writeBits(shape->out, SWFOutput_numBits(*shape->nFills), 4); SWFOutput_writeBits(shape->out, SWFOutput_numBits(*shape->nLines), 4); for ( i=0; i<*shape->nFills; ++i ) { SWFMatrix matrix = SWFFillStyle_getMatrix((*shape->fills)[i]); if ( matrix != NULL ) destroySWFMatrix(matrix); /* gradients and bitmaps are destroyed separately */ free((*shape->fills)[i]); } if ( *shape->fills != NULL ) free(*shape->fills); for ( i=0; i<*shape->nLines; ++i ) free((*shape->lines)[i]); if ( *shape->lines != NULL ) free(*shape->lines); } break; } case SHAPERECORD_LINETO: { int nBits; int dx = record.record.lineTo->dx; int dy = record.record.lineTo->dy; SWFOutput_writeBits(out, 3, 2); /* straight edge */ if(dx==0 && dy!=0) { nBits = SWFOutput_numSBits(dy); SWF_assert(nBits<18); SWFOutput_writeBits(out, nBits-2, 4); SWFOutput_writeBits(out, 1, 2); /* vertical line */ SWFOutput_writeSBits(out, dy, nBits); } else if(dy==0 && dx!=0) { nBits = SWFOutput_numSBits(dx); SWF_assert(nBits<18); SWFOutput_writeBits(out, nBits-2, 4); SWFOutput_writeBits(out, 0, 2); /* horizontal line */ SWFOutput_writeSBits(out, dx, nBits); } else { nBits = max(SWFOutput_numSBits(dx), SWFOutput_numSBits(dy)); nBits = max(nBits, 2); SWF_assert(nBits<18); SWFOutput_writeBits(out, nBits-2, 4); SWFOutput_writeBits(out, 1, 1); /* general line */ SWFOutput_writeSBits(out, dx, nBits); SWFOutput_writeSBits(out, dy, nBits); } break; } case SHAPERECORD_CURVETO: { int controlx = record.record.curveTo->controlx; int controly = record.record.curveTo->controly; int anchorx = record.record.curveTo->anchorx; int anchory = record.record.curveTo->anchory; int nBits = max(max(SWFOutput_numSBits(controlx), SWFOutput_numSBits(controly)), max(SWFOutput_numSBits(anchorx), SWFOutput_numSBits(anchory))); if ( nBits < 2 ) nBits = 2; SWF_assert(nBits < 18); SWFOutput_writeBits(out, 2, 2); /* curved edge */ SWFOutput_writeBits(out, nBits-2, 4); SWFOutput_writeSBits(out, controlx, nBits); SWFOutput_writeSBits(out, controly, nBits); SWFOutput_writeSBits(out, anchorx, nBits); SWFOutput_writeSBits(out, anchory, nBits); break; } default: SWF_error("Unknown shapeRecordType"); } }
void destroySWFShape(SWFShape shape) { int i, j; destroySWFOutput(shape->out); if (shape->isUsingNewStyles != TRUE) { for ( i=0; i<*shape->nFills; ++i ) { SWFMatrix matrix = SWFFillStyle_getMatrix((*shape->fills)[i]); if ( matrix != NULL ) destroySWFMatrix(matrix); /* gradients and bitmaps are destroyed separately */ free((*shape->fills)[i]); } if ( *shape->fills != NULL ) free(*shape->fills); for ( i=0; i<*shape->nLines; ++i ) free((*shape->lines)[i]); if ( *shape->lines != NULL ) free(*shape->lines); } if (shape->isEnded != TRUE) { for ( i=0; i<shape->nRecords; ++i ) { ShapeRecord record = shape->records[i]; if (record.type == SHAPERECORD_STATECHANGE && record.record.stateChange->flags & SWF_SHAPE_NEWSTYLEFLAG) { for ( j=0; i<record.record.stateChange->nFills; ++j ) { SWFMatrix matrix = SWFFillStyle_getMatrix(record.record.stateChange->fills[j]); if ( matrix != NULL ) destroySWFMatrix(matrix); /* gradients and bitmaps are destroyed separately */ free(record.record.stateChange->fills[j]); } if ( record.record.stateChange->fills != NULL ) free(record.record.stateChange->fills); for ( j=0; j<record.record.stateChange->nLines; ++j ) free(record.record.stateChange->lines[j]); if ( record.record.stateChange->lines != NULL ) free(record.record.stateChange->lines); } free(record.record.stateChange); /* all in union are pointers */ } free(shape->records); } #if TRACK_ALLOCS ming_gc_remove_node(shape->gcnode); #endif destroySWFCharacter((SWFCharacter) shape); }