📄 shape.c
字号:
++line; finishSetLine(shape, line, width);}/* * set Linestyle2 introduce with SWF 8. * * set line width in TWIPS * WARNING: this is an internal interface * external use is deprecated! use setLine2 instead ! * set color {r, g, b, a} * * Linestyle2 extends Linestyle1 with some extra flags: * * Line cap style: select one of the following flags (default is round cap style) * SWF_LINESTYLE_CAP_ROUND * SWF_LINESTYLE_CAP_NONE * SWF_LINESTYLE_CAP_SQUARE * * Line join style: select one of the following flags (default is round join style) * SWF_LINESTYLE_JOIN_ROUND * SWF_LINESTYLE_JOIN_BEVEL * SWF_LINESTYLE_JOIN_MITER * * Scaling flags: disable horizontal / vertical scaling * SWF_LINESTYLE_FLAG_NOHSCALE * SWF_LINESTYLE_FLAG_NOVSCALE * * Enable pixel hinting to correct blurry vertical / horizontal lines * -> all anchors will be aligned to full pixels * SWF_LINESTYLE_FLAG_HINTING * * Disable stroke closure: if no-close flag is set caps will be applied * instead of joins * SWF_LINESTYLE_FLAG_NOCLOSE * * End-cap style: default round * SWF_LINESTYLE_FLAG_ENDCAP_ROUND * SWF_LINESTYLE_FLAG_ENDCAP_NONE * SWF_LINESTYLE_FLAG_ENDCAP_SQUARE * * If join style is SWF_LINESTYLE_JOIN_MITER a miter limit factor * must be set. Miter max length is then calculated as: * max miter len = miter limit * width. * If join style is not miter, this value will be ignored. */void SWFShape_setLineStyle2_internal(SWFShape shape, unsigned short width, byte r, byte g, byte b, byte a, int flags, float miterLimit){ int line; if ( shape->isEnded ) return; for ( line=0; line<shape->nLines; ++line ) { if ( SWFLineStyle_equals(shape->lines[line], width, r, g, b, a, flags) ) break; } if ( line == shape->nLines ) line = SWFShape_addLineStyle2(shape, width, r, g, b, a, flags, miterLimit); else ++line; finishSetLine(shape, line, width);}/* * set line width and line color * * set line width in TWIPS * set line color as {r, g, b, a} * * WARNING: this is an internal interface. * external use is deprecated! use setLine instead ! */voidSWFShape_setLineStyle_internal(SWFShape shape, unsigned short width, byte r, byte g, byte b, byte a){ int line; if ( shape->isEnded ) return; for ( line=0; line<shape->nLines; ++line ) { if ( SWFLineStyle_equals(shape->lines[line], width, r, g, b, a, 0) ) break; } if ( line == shape->nLines ) line = SWFShape_addLineStyle(shape, width, r, g, b, a); else ++line; finishSetLine(shape, line, width);}/* fill 0 is no fill, so set idx to one more than the shape's fill index */static int getFillIdx(SWFShape shape, SWFFillStyle fill){ int i; for ( i=0; i<shape->nFills; ++i ) { if ( SWFFillStyle_equals(fill, shape->fills[i]) ) return (i+1); } return 0; // no fill}static int addFillStyle(SWFShape shape, SWFFillStyle fill){ int i; for ( i=0; i<shape->nFills; ++i ) { if ( SWFFillStyle_equals(fill, shape->fills[i]) ) return i; } if ( shape->isEnded ) return -1; if ( shape->nFills%STYLE_INCREMENT == 0 ) { int size = (shape->nFills+STYLE_INCREMENT) * sizeof(SWFFillStyle); shape->fills = (SWFFillStyle*)realloc(shape->fills, size); } shape->fills[shape->nFills] = fill; ++shape->nFills; return shape->nFills;}SWFFillStyleSWFShape_addSolidFillStyle(SWFShape shape, byte r, byte g, byte b, byte a){ int ret; SWFFillStyle fill = newSWFSolidFillStyle(r, g, b, a); ret = addFillStyle(shape, fill); if(ret < 0) /* error */ { destroySWFFillStyle(fill); return NULL; } else if(ret == shape->nFills) /* new fill */ { return fill; } else /* fill is known */ { destroySWFFillStyle(fill); return shape->fills[ret]; }}SWFFillStyleSWFShape_addGradientFillStyle(SWFShape shape, SWFGradient gradient, byte flags){ SWFFillStyle fill = newSWFGradientFillStyle(gradient, flags); if(addFillStyle(shape, fill) < 0) { destroySWFFillStyle(fill); return NULL; } return fill; }SWFFillStyleSWFShape_addBitmapFillStyle(SWFShape shape, SWFBitmap bitmap, byte flags){ SWFFillStyle fill; SWFCharacter_addDependency((SWFCharacter)shape, (SWFCharacter)bitmap); fill = newSWFBitmapFillStyle(bitmap, flags); if(addFillStyle(shape, fill) < 0) { destroySWFFillStyle(fill); return NULL; } return fill;}voidSWFShape_setLeftFillStyle(SWFShape shape, SWFFillStyle fill){ ShapeRecord record; int idx; if ( shape->isEnded || shape->isMorph ) return; if(fill == NOFILL) { record = addStyleRecord(shape); record.record.stateChange->leftFill = 0; record.record.stateChange->flags |= SWF_SHAPE_FILLSTYLE0FLAG; return; } idx = getFillIdx(shape, fill); if(idx == 0) // fill not present in array { SWFFillStyle_addDependency(fill, (SWFCharacter)shape); if(addFillStyle(shape, fill) < 0) return; idx = getFillIdx(shape, fill); } record = addStyleRecord(shape); record.record.stateChange->leftFill = idx; record.record.stateChange->flags |= SWF_SHAPE_FILLSTYLE0FLAG;}voidSWFShape_setRightFillStyle(SWFShape shape, SWFFillStyle fill){ ShapeRecord record; int idx; if ( shape->isEnded || shape->isMorph ) return; if(fill == NOFILL) { record = addStyleRecord(shape); record.record.stateChange->rightFill = 0; record.record.stateChange->flags |= SWF_SHAPE_FILLSTYLE1FLAG; return; } idx = getFillIdx(shape, fill); if(idx == 0) // fill not present in array { SWFFillStyle_addDependency(fill, (SWFCharacter)shape); if(addFillStyle(shape, fill) < 0) return; idx = getFillIdx(shape, fill); } record = addStyleRecord(shape); record.record.stateChange->rightFill = idx; record.record.stateChange->flags |= SWF_SHAPE_FILLSTYLE1FLAG;}/* move pen relative to shape origin */voidSWFShape_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); }}voidSWFShape_moveScaledPen(SWFShape shape, int x, int y){ SWFShape_moveScaledPenTo(shape, shape->xpos+x, shape->ypos+y);}intSWFShape_getScaledPenX(SWFShape shape){ return shape->xpos;}intSWFShape_getScaledPenY(SWFShape shape){ return shape->ypos;}voidSWFShape_drawScaledGlyph(SWFShape shape, SWFFont font, unsigned short c, int size){ int i, vx, vy; if(font == NULL) return; SWFShape glyph = SWFFont_getGlyph(font, c); if(glyph == NULL) { SWF_warn("SWFShape_drawScaledGlyph: no glyph for code %i found \n", c); return; } vx = shape->xpos; vy = shape->ypos; for(i = 0; i < glyph->nRecords; i++) addShapeRecord(shape, glyph->records[i], &vx, &vy, size/1024.0);}/* * set shape version manualy * This function allows to set the shapes version information. The * version is only a hint. if necessary the version is upgraded. * valid values: SWF_SHAPE3 and SWF_SHAPE4 * 3 is default * 4 if linestyle2 is used */void SWFShape_useVersion(SWFShape shape, int version){ if(shape->useVersion >= version) return; if(version > SWF_SHAPE4) return; shape->useVersion = version;}/* * get shape version * possible values SWF_SHAPE3 and SWF_SHAPE4 */int SWFShape_getVersion(SWFShape shape){ return shape->useVersion;}/* * set render hinting flags * possible values: * SWF_SHAPE_USESCALINGSTROKES SWF_SHAPE_USENONSCALINGSTROKES */void SWFShape_setRenderHintingFlags(SWFShape shape, int flags){ flags &= (SWF_SHAPE_USESCALINGSTROKES | SWF_SHAPE_USENONSCALINGSTROKES); shape->flags = flags; SWFShape_useVersion(shape, SWF_SHAPE4);}SWFRect SWFShape_getEdgeBounds(SWFShape shape){ if(shape->useVersion == SWF_SHAPE4) return shape->edgeBounds; else return NULL;}int SWFShape_getFlags(SWFShape shape){ if(shape->useVersion == SWF_SHAPE4) return shape->flags; else return 0;}struct out { char *buf, *ptr; int len; }; static void oprintf(struct out *op, const char *fmt, ...) { va_list ap; char buf[256]; int d, l; va_start(ap, fmt); l = vsprintf(buf, fmt, ap); while((d = op->ptr - op->buf) + l >= op->len-1) { op->buf = (char *) realloc(op->buf, op->len += 100); op->ptr = op->buf + d; } for(d = 0 ; d < l ; d++) *op->ptr++ = buf[d]; }char * SWFShape_dumpOutline(SWFShape s) { struct out o; int i; int x = 0, y = 0; o.len = 0; o.ptr = o.buf = (char *)malloc(1); *o.ptr = 0; for (i = 0; i < s->nRecords; i++) { ShapeRecord *record = s->records + i; switch(record->type) { case SHAPERECORD_STATECHANGE: { if(!record->record.stateChange->flags & SWF_SHAPE_MOVETOFLAG) continue; x = record->record.stateChange->moveToX; y = record->record.stateChange->moveToY; oprintf(&o, "moveto %d,%d\n", x, y); break; } case SHAPERECORD_LINETO: { x += record->record.lineTo->dx; y += record->record.lineTo->dy; oprintf(&o, "lineto %d,%d\n", x, y); 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; oprintf(&o, "curveto %d,%d %d,%d\n", x+controlX, y+controlY, x+controlX+anchorX, y+controlY+anchorY); x += controlX + anchorX; y += controlY + anchorY; break; } default: break; } } *o.ptr = 0; return o.buf; }/* * Local variables: * tab-width: 2 * c-basic-offset: 2 * End: */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -