void SWFShape_drawScaledLine(SWFShape shape, int dx, int dy) { ShapeRecord record; if ( shape->isEnded ) return; if ( dx == 0 && dy == 0 ) return; record = newShapeRecord(shape, SHAPERECORD_LINETO); SWF_assert(SWFOutput_numSBits(dx) < 18); SWF_assert(SWFOutput_numSBits(dy) < 18); record.record.lineTo->dx = dx; record.record.lineTo->dy = dy; shape->xpos += dx; shape->ypos += dy; SWFRect_includePoint(SWFCharacter_getBounds(CHARACTER(shape)), shape->xpos, shape->ypos, shape->lineWidth); SWFRect_includePoint(shape->edgeBounds, shape->xpos, shape->ypos, 0); }
void SWFShape_drawScaledCurve(SWFShape shape, int controldx, int controldy, int anchordx, int anchordy) { ShapeRecord record; if ( shape->isEnded ) return; if ( controldx == 0 && controldy == 0 && anchordx == 0 && anchordy == 0 ) return; // printf("curve %i,%i, %i, %i\n", controldx, controldy, anchordx, anchordy); record = newShapeRecord(shape, SHAPERECORD_CURVETO); record.record.curveTo->controlx = controldx; record.record.curveTo->controly = controldy; record.record.curveTo->anchorx = anchordx; record.record.curveTo->anchory = anchordy; if ( SWFOutput_numSBits(controldx) >= 18 || SWFOutput_numSBits(controldy) >= 18 || SWFOutput_numSBits(anchordx) >= 18 || SWFOutput_numSBits(anchordy) >= 18 ) SWF_error("Curve parameters too large"); /* including the control point is sloppy, but safe.. */ shape->xpos += controldx; shape->ypos += controldy; SWFRect_includePoint(SWFCharacter_getBounds(CHARACTER(shape)), shape->xpos, shape->ypos, shape->lineWidth); SWFRect_includePoint(shape->edgeBounds, shape->xpos, shape->ypos, 0); shape->xpos += anchordx; shape->ypos += anchordy; SWFRect_includePoint(SWFCharacter_getBounds(CHARACTER(shape)), shape->xpos, shape->ypos, shape->lineWidth); SWFRect_includePoint(shape->edgeBounds, shape->xpos, shape->ypos, 0); }
void SWFShape_addStyleHeader(SWFShape shape) { SWFOutput out = newSWFOutput(); SWFOutput_writeUInt16(out, CHARACTERID(shape)); SWFOutput_writeRect(out, SWFCharacter_getBounds(CHARACTER(shape))); if(shape->useVersion == SWF_SHAPE4) { SWFOutput_writeRect(out, shape->edgeBounds); SWFOutput_writeUInt8(out, shape->flags); } SWFOutput_writeFillStyles(out, shape->fills, shape->nFills, BLOCK(shape)->type, shape->edgeBounds); SWFOutput_writeLineStyles(out, shape->lines, shape->nLines, BLOCK(shape)->type); /* prepend shape->out w/ shape header */ SWFOutput_setNext(out, shape->out); shape->out = out; }
void SWFShape_addStyleHeader(SWFShape shape) { SWFOutput out = newSWFOutput(); SWFOutput_writeUInt16(out, CHARACTERID(shape)); SWFOutput_writeRect(out, SWFCharacter_getBounds(CHARACTER(shape))); if (shape->isUsingNewStyles) { shape->nFills2 = 0; shape->nLines2 = 0; } SWFOutput_writeFillStyles(out, shape->fills2, shape->nFills2, BLOCK(shape)->type); SWFOutput_writeLineStyles(out, shape->lines2, shape->nLines2, BLOCK(shape)->type); /* prepend shape->out w/ shape header */ SWFOutput_setNext(out, shape->out); shape->out = out; }
/* move pen relative to shape origin */ void SWFShape_moveScaledPenTo(SWFShape shape, int x, int y) { ShapeRecord record; if ( shape->isEnded ) return; record = addStyleRecord(shape); record.record.stateChange->moveToX = shape->xpos = x; record.record.stateChange->moveToY = shape->ypos = y; record.record.stateChange->flags |= SWF_SHAPE_MOVETOFLAG; if ( shape->nRecords == 0 || (shape->nRecords == 1 && shape->records[0].type == SHAPERECORD_STATECHANGE) ) { SWFRect_setBounds(SWFCharacter_getBounds(CHARACTER(shape)), x, x, y, y); SWFRect_setBounds(shape->edgeBounds, x, x, y, y); } }
/* copy shaperecord from other shape */ static ShapeRecord addShapeRecord(SWFShape shape, ShapeRecord record, int *vx, int *vy, float scale) { if ( shape->nRecords % SHAPERECORD_INCREMENT == 0 ) { shape->records = (ShapeRecord*) realloc(shape->records, sizeof(ShapeRecord) * (shape->nRecords + SHAPERECORD_INCREMENT)); } switch ( record.type ) { case SHAPERECORD_STATECHANGE: { StateChangeRecord change = (StateChangeRecord) calloc(1,sizeof(struct stateChangeRecord)); *change = *record.record.stateChange; shape->records[shape->nRecords].record.stateChange = change; change->moveToX += shape->xpos; change->moveToY += shape->ypos; change->moveToX *= scale; change->moveToY *= scale; *vx = change->moveToX; *vy = change->moveToY; break; } case SHAPERECORD_LINETO: { LineToRecord lineTo = (LineToRecord) calloc(1,sizeof(struct lineToRecord)); *lineTo = *record.record.lineTo; lineTo->dx *= scale; lineTo->dy *= scale; shape->records[shape->nRecords].record.lineTo = lineTo; *vx += lineTo->dx; *vy += lineTo->dy; SWFRect_includePoint(SWFCharacter_getBounds(CHARACTER(shape)), *vx, *vy, shape->lineWidth); SWFRect_includePoint(shape->edgeBounds, *vx, *vy, 0); break; } case SHAPERECORD_CURVETO: { CurveToRecord curveTo = (CurveToRecord) calloc(1,sizeof(struct curveToRecord)); *curveTo = *record.record.curveTo; curveTo->controlx *= scale; curveTo->controly *= scale; curveTo->anchorx *= scale; curveTo->anchory *= scale; shape->records[shape->nRecords].record.curveTo = curveTo; *vx += curveTo->controlx; *vy += curveTo->controly; SWFRect_includePoint(SWFCharacter_getBounds(CHARACTER(shape)), *vx, *vy, shape->lineWidth); SWFRect_includePoint(shape->edgeBounds, *vx, *vy, 0); *vx += curveTo->anchorx; *vy += curveTo->anchory; SWFRect_includePoint(SWFCharacter_getBounds(CHARACTER(shape)), *vx, *vy, shape->lineWidth); SWFRect_includePoint(shape->edgeBounds, *vx, *vy, 0); break; } } shape->records[shape->nRecords].type = record.type; shape->nRecords++; return shape->records[shape->nRecords-1]; }