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 MorphLineStyle ReadMorphLineStyle2(SWFDataTypeReader shapeReader) { int startwidth = shapeReader.ReadUI16(); int endwidth = shapeReader.ReadUI16(); CapStyle startCap = (CapStyle)shapeReader.ReadUBits(2); JoinStyle join = (JoinStyle)shapeReader.ReadUBits(2); bool hasFill = shapeReader.ReadBit(); bool noHScaling = shapeReader.ReadBit(); bool noVScaling = shapeReader.ReadBit(); bool hasPixelHints = shapeReader.ReadBit(); shapeReader.ReadUBits(5); // Reserved: 0 bool noClose = shapeReader.ReadBit(); CapStyle endCap = (CapStyle)shapeReader.ReadUBits(2); int?miterLimit = null; if (join == JoinStyle.Miter) { miterLimit = shapeReader.ReadUI16(); } Color? startColour = null; Color? endColour = null; MorphFillStyle fs = null; if (hasFill) { fs = this.ReadMorphFillStyle(shapeReader); } else { startColour = shapeReader.ReadRGBA(); endColour = shapeReader.ReadRGBA(); } return(new MorphLineStyle() { StartWidth = startwidth, EndWidth = endwidth, StartColour = startColour, EndColour = endColour, StartCap = startCap, EndCap = endCap, Join = join, HasFill = hasFill, NoHScaling = noHScaling, NoVScaling = noVScaling, HasPixelHints = hasPixelHints, FillStyle = fs, MiterLimit = miterLimit }); }
private LineStyle ReadLineStyle2(SWFDataTypeReader shapeReader, Tag format) { int width = shapeReader.ReadUI16(); CapStyle startCap = (CapStyle)shapeReader.ReadUBits(2); JoinStyle join = (JoinStyle)shapeReader.ReadUBits(2); bool hasFill = shapeReader.ReadBit(); bool noHScaling = shapeReader.ReadBit(); bool noVScaling = shapeReader.ReadBit(); bool hasPixelHints = shapeReader.ReadBit(); shapeReader.ReadUBits(5); /* Reserved: 0 */ bool noClose = shapeReader.ReadBit(); CapStyle endCap = (CapStyle)shapeReader.ReadUBits(2); int?miterLimit = null; if (join == JoinStyle.Miter) { miterLimit = shapeReader.ReadUI16(); } Color? c = null; FillStyle fs = null; if (hasFill) { fs = this.ReadFillStyle(shapeReader, format); } else { c = shapeReader.ReadRGBA(); } return(new LineStyle() { Width = width, StartCap = startCap, EndCap = endCap, Join = join, HasFill = hasFill, NoHScaling = noHScaling, NoVScaling = noVScaling, HasPixelHints = hasPixelHints, Colour = c, FillStyle = fs, MiterLimit = miterLimit }); }
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 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 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 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 MorphLineStyle ReadMorphLineStyle2(SWFDataTypeReader shapeReader) { int startwidth = shapeReader.ReadUI16(); int endwidth = shapeReader.ReadUI16(); CapStyle startCap = (CapStyle)shapeReader.ReadUBits(2); JoinStyle join = (JoinStyle)shapeReader.ReadUBits(2); bool hasFill = shapeReader.ReadBit(); bool noHScaling = shapeReader.ReadBit(); bool noVScaling = shapeReader.ReadBit(); bool hasPixelHints = shapeReader.ReadBit(); shapeReader.ReadUBits(5); // Reserved: 0 bool noClose = shapeReader.ReadBit(); CapStyle endCap = (CapStyle)shapeReader.ReadUBits(2); int? miterLimit = null; if (join == JoinStyle.Miter) { miterLimit = shapeReader.ReadUI16(); } Color? startColour = null; Color? endColour = null; MorphFillStyle fs = null; if (hasFill) { fs = this.ReadMorphFillStyle(shapeReader); } else { startColour = shapeReader.ReadRGBA(); endColour = shapeReader.ReadRGBA(); } return new MorphLineStyle() { StartWidth = startwidth, EndWidth = endwidth, StartColour = startColour, EndColour = endColour, StartCap = startCap, EndCap = endCap, Join = join, HasFill = hasFill, NoHScaling = noHScaling, NoVScaling = noVScaling, HasPixelHints = hasPixelHints, FillStyle = fs, MiterLimit = miterLimit }; }
private LineStyle ReadLineStyle2(SWFDataTypeReader shapeReader, Tag format) { int width = shapeReader.ReadUI16(); CapStyle startCap = (CapStyle)shapeReader.ReadUBits(2); JoinStyle join = (JoinStyle)shapeReader.ReadUBits(2); bool hasFill = shapeReader.ReadBit(); bool noHScaling = shapeReader.ReadBit(); bool noVScaling = shapeReader.ReadBit(); bool hasPixelHints = shapeReader.ReadBit(); shapeReader.ReadUBits(5); /* Reserved: 0 */ bool noClose = shapeReader.ReadBit(); CapStyle endCap = (CapStyle)shapeReader.ReadUBits(2); int? miterLimit = null; if (join == JoinStyle.Miter) { miterLimit = shapeReader.ReadUI16(); } Color? c = null; FillStyle fs = null; if (hasFill) { fs = this.ReadFillStyle(shapeReader, format); } else { c = shapeReader.ReadRGBA(); } return new LineStyle() { Width = width, StartCap = startCap, EndCap = endCap, Join = join, HasFill = hasFill, NoHScaling = noHScaling, NoVScaling = noVScaling, HasPixelHints = hasPixelHints, Colour = c, FillStyle = fs, MiterLimit = miterLimit }; }
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 }; }