private IShape ParseDefineShape4(SWFDataTypeReader shapeReader) { Rect bounds = shapeReader.ReadRect(); shapeReader.Align8(); Rect edgeBounds = shapeReader.ReadRect(); shapeReader.Align8(); shapeReader.ReadUBits(5); /* Reserved: 0 */ bool usesFillWinding = shapeReader.ReadBit(); bool usesNonScalingStrokes = shapeReader.ReadBit(); bool usesScalingStrokes = shapeReader.ReadBit(); ShapeDef sws = this.ReadShapeDef(shapeReader, Tag.DefineShape4, true, null, null); return(new Shape() { ShapeDef = sws, Bounds = bounds, UsesScalingStrokes = usesScalingStrokes, UsesNonScalingStrokes = usesNonScalingStrokes, UsesFillWinding = usesFillWinding }); }
private ShapeDef ReadShapeDef(SWFDataTypeReader shapeReader, Tag format, bool withStyle, IFillStyle[] fillStyles, ILineStyle[] lineStyles) { ShapeDef shapeDef = new ShapeDef(); /* Shapes either don't have fill styles (Font glyphs), they come with a bunch of fill styles * (Regular shapes) or are preceeded by fill styles which are passed into this method * (Morph shapes). Could probably be tidier... */ if (fillStyles != null) { shapeDef.FillStyles.AddRange(fillStyles); } if (lineStyles != null) { shapeDef.LineStyles.AddRange(lineStyles); } if (withStyle) { shapeDef.FillStyles.AddRange(this.ReadFillStyleArray(shapeReader, format)); shapeReader.Align8(); shapeDef.LineStyles.AddRange(this.ReadLineStyleArray(shapeReader, format)); shapeReader.Align8(); } /* Read the shape stuff... */ int fillBits = (int)shapeReader.ReadUBits(4); int lineBits = (int)shapeReader.ReadUBits(4); this.ReadShapeRecordsInto(shapeDef, shapeReader, ref fillBits, ref lineBits, format); return(shapeDef); }
private FillStyle ReadFillStyle(SWFDataTypeReader shapeReader, Tag format) { FillStyle style = new FillStyle(); style.Type = (FillType)shapeReader.ReadUI8(); if (style.Type == FillType.Solid) { if (format == Tag.DefineShape3 || format == Tag.DefineShape4) /* Assuming shape4 goes here. Spec is ambiguous. */ { style.Colour = shapeReader.ReadRGBA(); } else if (format == Tag.DefineShape || format == Tag.DefineShape2) { style.Colour = shapeReader.ReadRGB(); } else { throw new SWFModellerException(SWFModellerError.SWFParsing, "Bad tag format for fill style"); } } if (style.Type == FillType.LinearGradient || style.Type == FillType.RadialGradient || style.Type == FillType.FocalGradient) { style.FillMatrix = shapeReader.ReadMatrix(); shapeReader.Align8(); if (style.Type == FillType.LinearGradient || style.Type == FillType.RadialGradient) { style.Gradient = this.ReadGradient(shapeReader, format); } else /* FocalGradient */ { style.Gradient = this.ReadFocalGradient(shapeReader); } } if (FillTypes.IsBitmap(style.Type)) { int cid = shapeReader.ReadUI16(); /* Some fills have this magic number in them which seems to deliberately not * reference a bitmap. The spec is silent on the matter. Oh flash, you * stammering ape. */ if (cid != 0x0000FFFF) { style.Bitmap = this.ImageFinder.FindImage(cid); } style.FillMatrix = shapeReader.ReadMatrix(); shapeReader.Align8(); } return(style); }
private MorphFillStyle ReadMorphFillStyle(SWFDataTypeReader shapeReader) { MorphFillStyle style = new MorphFillStyle(); style.Type = (FillType)shapeReader.ReadUI8(); if (style.Type == FillType.Solid) { style.StartColour = shapeReader.ReadRGBA(); style.EndColour = shapeReader.ReadRGBA(); } if (style.Type == FillType.LinearGradient || style.Type == FillType.RadialGradient) { style.StartFillMatrix = shapeReader.ReadMatrix(); shapeReader.Align8(); style.EndFillMatrix = shapeReader.ReadMatrix(); shapeReader.Align8(); if (style.Type == FillType.LinearGradient || style.Type == FillType.RadialGradient) { style.Gradient = this.ReadMorphGradient(shapeReader); } } if (FillTypes.IsBitmap(style.Type)) { int cid = shapeReader.ReadUI16(); /* Some fills have this magic number in them which seems to deliberately not * reference a bitmap. The spec is silent on the matter. Oh flash, you * bumbling simian. */ if (cid != 0x0000FFFF) { style.Bitmap = this.ImageFinder.FindImage(cid); } style.StartFillMatrix = shapeReader.ReadMatrix(); shapeReader.Align8(); style.EndFillMatrix = shapeReader.ReadMatrix(); shapeReader.Align8(); } return(style); }
private IShape ParseDefineMorphShape(SWFDataTypeReader shapeReader, Tag format) { Rect startBounds = shapeReader.ReadRect(); shapeReader.Align8(); Rect endBounds = shapeReader.ReadRect(); shapeReader.Align8(); Rect startEdgeBounds = null; Rect endEdgeBounds = null; bool usesNonScalingStrokes = false; bool usesScalingStrokes = false; if (format == Tag.DefineMorphShape2) { startEdgeBounds = shapeReader.ReadRect(); shapeReader.Align8(); endEdgeBounds = shapeReader.ReadRect(); shapeReader.Align8(); /*(void)*/ shapeReader.ReadUBits(6); /* Reserved. Assume 0 */ usesNonScalingStrokes = shapeReader.ReadBit(); usesScalingStrokes = shapeReader.ReadBit(); } /*(void)*/ shapeReader.ReadUI32(); /* end edges offset. We don't need this */ MorphFillStyle[] mfsa = this.ReadMorphFillStyleArray(shapeReader); MorphLineStyle[] mlsa = this.ReadMorphLineStyleArray(shapeReader, format); ShapeDef startShape = this.ReadShapeDef(shapeReader, format, false, mfsa, mlsa); ShapeDef endShape = this.ReadShapeDef(shapeReader, format, false, mfsa, mlsa); return(new MorphShape() { Bounds = startBounds, EndBounds = endBounds, StartEdgeBounds = startEdgeBounds, EndEdgeBounds = endEdgeBounds, UsesNonScalingStrokes = usesNonScalingStrokes, UsesScalingStrokes = usesScalingStrokes, StartShape = startShape, EndShape = endShape }); }
private IShape ParseDefineMorphShape(SWFDataTypeReader shapeReader, Tag format) { Rect startBounds = shapeReader.ReadRect(); shapeReader.Align8(); Rect endBounds = shapeReader.ReadRect(); shapeReader.Align8(); Rect startEdgeBounds = null; Rect endEdgeBounds = null; bool usesNonScalingStrokes = false; bool usesScalingStrokes = false; if (format == Tag.DefineMorphShape2) { startEdgeBounds = shapeReader.ReadRect(); shapeReader.Align8(); endEdgeBounds = shapeReader.ReadRect(); shapeReader.Align8(); /*(void)*/shapeReader.ReadUBits(6); /* Reserved. Assume 0 */ usesNonScalingStrokes = shapeReader.ReadBit(); usesScalingStrokes = shapeReader.ReadBit(); } /*(void)*/shapeReader.ReadUI32(); /* end edges offset. We don't need this */ MorphFillStyle[] mfsa = this.ReadMorphFillStyleArray(shapeReader); MorphLineStyle[] mlsa = this.ReadMorphLineStyleArray(shapeReader, format); ShapeDef startShape = this.ReadShapeDef(shapeReader, format, false, mfsa, mlsa); ShapeDef endShape = this.ReadShapeDef(shapeReader, format, false, mfsa, mlsa); return new MorphShape() { Bounds = startBounds, EndBounds = endBounds, StartEdgeBounds = startEdgeBounds, EndEdgeBounds = endEdgeBounds, UsesNonScalingStrokes = usesNonScalingStrokes, UsesScalingStrokes = usesScalingStrokes, StartShape = startShape, EndShape = endShape }; }
private IShape ParseDefineShapeN(SWFDataTypeReader shapeReader, Tag format) { Rect bounds = shapeReader.ReadRect(); shapeReader.Align8(); ShapeDef sws = this.ReadShapeDef(shapeReader, format, true, null, null); return(new Shape() { ShapeDef = sws, Bounds = bounds }); }
private void ReadShapeRecordsInto(ShapeDef sws, SWFDataTypeReader shapeReader, ref int fillBits, ref int lineBits, Tag format) { List <IShapeRecord> records = new List <IShapeRecord>(); int currentX = 0; int currentY = 0; while (true) { bool isEdgeRecord = shapeReader.ReadBit(); if (isEdgeRecord) { if (shapeReader.ReadBit()) { /* StraightEdgeRecord */ int bpv = 2 + (int)shapeReader.ReadUBits(4); bool isGeneralLine = shapeReader.ReadBit(); bool isVertical = false; if (!isGeneralLine) { isVertical = shapeReader.ReadBit(); } int dx = 0; int dy = 0; if (isGeneralLine || !isVertical) { dx = shapeReader.ReadSBits(bpv); } if (isGeneralLine || isVertical) { dy = shapeReader.ReadSBits(bpv); } currentX += dx; currentY += dx; records.Add(new StraightEdge() { DX = dx, DY = dy }); } else { /* CurvedEdgeRecord */ int bpv = 2 + (int)shapeReader.ReadUBits(4); int ctrlDX = shapeReader.ReadSBits(bpv); int ctrlDY = shapeReader.ReadSBits(bpv); int anchorDX = shapeReader.ReadSBits(bpv); int anchorDY = shapeReader.ReadSBits(bpv); currentX += ctrlDX + anchorDX; currentY += ctrlDY + anchorDY; records.Add(new CurvedEdge() { AnchorDX = anchorDX, AnchorDY = anchorDY, CtrlDX = ctrlDX, CtrlDY = ctrlDY }); } } else { uint flags = shapeReader.ReadUBits(5); if (flags == 0) { /* EndShapeRecord */ break; } /* StyleChangeRecord */ bool stateMoveTo = (flags & 1) == 1; flags >>= 1; bool stateFillStyle0 = (flags & 1) == 1; flags >>= 1; bool stateFillStyle1 = (flags & 1) == 1; flags >>= 1; bool stateLineStyle = (flags & 1) == 1; flags >>= 1; bool stateNewStyles = (flags & 1) == 1; flags >>= 1; StyleChange sc = new StyleChange(); if (stateMoveTo) { int moveBits = (int)shapeReader.ReadUBits(5); sc.DX = shapeReader.ReadSBits(moveBits); sc.DY = shapeReader.ReadSBits(moveBits); currentX = sc.DX.Value; currentY = sc.DY.Value; } if (stateFillStyle0) { sc.FillStyle0 = sws.FillFromIndex((int)shapeReader.ReadUBits(fillBits)); } if (stateFillStyle1) { sc.FillStyle1 = sws.FillFromIndex((int)shapeReader.ReadUBits(fillBits)); } if (stateLineStyle) { sc.LineStyle = (int)shapeReader.ReadUBits(lineBits); } if (stateNewStyles) { sc.NewFillStyles = this.ReadFillStyleArray(shapeReader, format); sc.NewLineStyles = this.ReadLineStyleArray(shapeReader, format); fillBits = (int)shapeReader.ReadUBits(4); lineBits = (int)shapeReader.ReadUBits(4); /* ISSUE 21: We're storing new styles defined in shape records in two places and * in such a way that we can't figure out where we got them from. This makes * it impossible to reconstruct the SWF data. Kinda need to work out how to * find styles. */ sws.FillStyles.AddRange(sc.NewFillStyles); sws.LineStyles.AddRange(sc.NewLineStyles); } records.Add(sc); } } shapeReader.Align8(); sws.Records = records.ToArray(); }
private void ReadShapeRecordsInto(ShapeDef sws, SWFDataTypeReader shapeReader, ref int fillBits, ref int lineBits, Tag format) { List<IShapeRecord> records = new List<IShapeRecord>(); int currentX = 0; int currentY = 0; while (true) { bool isEdgeRecord = shapeReader.ReadBit(); if (isEdgeRecord) { if (shapeReader.ReadBit()) { /* StraightEdgeRecord */ int bpv = 2 + (int)shapeReader.ReadUBits(4); bool isGeneralLine = shapeReader.ReadBit(); bool isVertical = false; if (!isGeneralLine) { isVertical = shapeReader.ReadBit(); } int dx = 0; int dy = 0; if (isGeneralLine || !isVertical) { dx = shapeReader.ReadSBits(bpv); } if (isGeneralLine || isVertical) { dy = shapeReader.ReadSBits(bpv); } currentX += dx; currentY += dx; records.Add(new StraightEdge() { DX = dx, DY = dy }); } else { /* CurvedEdgeRecord */ int bpv = 2 + (int)shapeReader.ReadUBits(4); int ctrlDX = shapeReader.ReadSBits(bpv); int ctrlDY = shapeReader.ReadSBits(bpv); int anchorDX = shapeReader.ReadSBits(bpv); int anchorDY = shapeReader.ReadSBits(bpv); currentX += ctrlDX + anchorDX; currentY += ctrlDY + anchorDY; records.Add(new CurvedEdge() { AnchorDX = anchorDX, AnchorDY = anchorDY, CtrlDX = ctrlDX, CtrlDY = ctrlDY }); } } else { uint flags = shapeReader.ReadUBits(5); if (flags == 0) { /* EndShapeRecord */ break; } /* StyleChangeRecord */ bool stateMoveTo = (flags & 1) == 1; flags >>= 1; bool stateFillStyle0 = (flags & 1) == 1; flags >>= 1; bool stateFillStyle1 = (flags & 1) == 1; flags >>= 1; bool stateLineStyle = (flags & 1) == 1; flags >>= 1; bool stateNewStyles = (flags & 1) == 1; flags >>= 1; StyleChange sc = new StyleChange(); if (stateMoveTo) { int moveBits = (int)shapeReader.ReadUBits(5); sc.DX = shapeReader.ReadSBits(moveBits); sc.DY = shapeReader.ReadSBits(moveBits); currentX = sc.DX.Value; currentY = sc.DY.Value; } if (stateFillStyle0) { sc.FillStyle0 = sws.FillFromIndex((int)shapeReader.ReadUBits(fillBits)); } if (stateFillStyle1) { sc.FillStyle1 = sws.FillFromIndex((int)shapeReader.ReadUBits(fillBits)); } if (stateLineStyle) { sc.LineStyle = (int)shapeReader.ReadUBits(lineBits); } if (stateNewStyles) { sc.NewFillStyles = this.ReadFillStyleArray(shapeReader, format); sc.NewLineStyles = this.ReadLineStyleArray(shapeReader, format); fillBits = (int)shapeReader.ReadUBits(4); lineBits = (int)shapeReader.ReadUBits(4); /* ISSUE 21: We're storing new styles defined in shape records in two places and * in such a way that we can't figure out where we got them from. This makes * it impossible to reconstruct the SWF data. Kinda need to work out how to * find styles. */ sws.FillStyles.AddRange(sc.NewFillStyles); sws.LineStyles.AddRange(sc.NewLineStyles); } records.Add(sc); } } shapeReader.Align8(); sws.Records = records.ToArray(); }
private ShapeDef ReadShapeDef(SWFDataTypeReader shapeReader, Tag format, bool withStyle, IFillStyle[] fillStyles, ILineStyle[] lineStyles) { ShapeDef shapeDef = new ShapeDef(); /* Shapes either don't have fill styles (Font glyphs), they come with a bunch of fill styles * (Regular shapes) or are preceeded by fill styles which are passed into this method * (Morph shapes). Could probably be tidier... */ if (fillStyles != null) { shapeDef.FillStyles.AddRange(fillStyles); } if (lineStyles != null) { shapeDef.LineStyles.AddRange(lineStyles); } if (withStyle) { shapeDef.FillStyles.AddRange(this.ReadFillStyleArray(shapeReader, format)); shapeReader.Align8(); shapeDef.LineStyles.AddRange(this.ReadLineStyleArray(shapeReader, format)); shapeReader.Align8(); } /* Read the shape stuff... */ int fillBits = (int)shapeReader.ReadUBits(4); int lineBits = (int)shapeReader.ReadUBits(4); this.ReadShapeRecordsInto(shapeDef, shapeReader, ref fillBits, ref lineBits, format); return shapeDef; }
private MorphFillStyle ReadMorphFillStyle(SWFDataTypeReader shapeReader) { MorphFillStyle style = new MorphFillStyle(); style.Type = (FillType)shapeReader.ReadUI8(); if (style.Type == FillType.Solid) { style.StartColour = shapeReader.ReadRGBA(); style.EndColour = shapeReader.ReadRGBA(); } if (style.Type == FillType.LinearGradient || style.Type == FillType.RadialGradient) { style.StartFillMatrix = shapeReader.ReadMatrix(); shapeReader.Align8(); style.EndFillMatrix = shapeReader.ReadMatrix(); shapeReader.Align8(); if (style.Type == FillType.LinearGradient || style.Type == FillType.RadialGradient) { style.Gradient = this.ReadMorphGradient(shapeReader); } } if (FillTypes.IsBitmap(style.Type)) { int cid = shapeReader.ReadUI16(); /* Some fills have this magic number in them which seems to deliberately not * reference a bitmap. The spec is silent on the matter. Oh flash, you * bumbling simian. */ if (cid != 0x0000FFFF) { style.Bitmap = this.ImageFinder.FindImage(cid); } style.StartFillMatrix = shapeReader.ReadMatrix(); shapeReader.Align8(); style.EndFillMatrix = shapeReader.ReadMatrix(); shapeReader.Align8(); } return style; }
private FillStyle ReadFillStyle(SWFDataTypeReader shapeReader, Tag format) { FillStyle style = new FillStyle(); style.Type = (FillType)shapeReader.ReadUI8(); if (style.Type == FillType.Solid) { if (format == Tag.DefineShape3 || format == Tag.DefineShape4) /* Assuming shape4 goes here. Spec is ambiguous. */ { style.Colour = shapeReader.ReadRGBA(); } else if (format == Tag.DefineShape || format == Tag.DefineShape2) { style.Colour = shapeReader.ReadRGB(); } else { throw new SWFModellerException(SWFModellerError.SWFParsing, "Bad tag format for fill style"); } } if (style.Type == FillType.LinearGradient || style.Type == FillType.RadialGradient || style.Type == FillType.FocalGradient) { style.FillMatrix = shapeReader.ReadMatrix(); shapeReader.Align8(); if (style.Type == FillType.LinearGradient || style.Type == FillType.RadialGradient) { style.Gradient = this.ReadGradient(shapeReader, format); } else /* FocalGradient */ { style.Gradient = this.ReadFocalGradient(shapeReader); } } if (FillTypes.IsBitmap(style.Type)) { int cid = shapeReader.ReadUI16(); /* Some fills have this magic number in them which seems to deliberately not * reference a bitmap. The spec is silent on the matter. Oh flash, you * stammering ape. */ if (cid != 0x0000FFFF) { style.Bitmap = this.ImageFinder.FindImage(cid); } style.FillMatrix = shapeReader.ReadMatrix(); shapeReader.Align8(); } return style; }
private IShape ParseDefineShapeN(SWFDataTypeReader shapeReader, Tag format) { Rect bounds = shapeReader.ReadRect(); shapeReader.Align8(); ShapeDef sws = this.ReadShapeDef(shapeReader, format, true, null, null); return new Shape() { ShapeDef = sws, Bounds = bounds }; }
private IShape ParseDefineShape4(SWFDataTypeReader shapeReader) { Rect bounds = shapeReader.ReadRect(); shapeReader.Align8(); Rect edgeBounds = shapeReader.ReadRect(); shapeReader.Align8(); shapeReader.ReadUBits(5); /* Reserved: 0 */ bool usesFillWinding = shapeReader.ReadBit(); bool usesNonScalingStrokes = shapeReader.ReadBit(); bool usesScalingStrokes = shapeReader.ReadBit(); ShapeDef sws = this.ReadShapeDef(shapeReader, Tag.DefineShape4, true, null, null); return new Shape() { ShapeDef = sws, Bounds = bounds, UsesScalingStrokes = usesScalingStrokes, UsesNonScalingStrokes = usesNonScalingStrokes, UsesFillWinding = usesFillWinding }; }