public static IEnumerable<ShapeRecord> ReadShape(SwfStream swf, bool hasAlpha, bool isExtended, bool hasStyle, bool extendedStyles) { ShapeState state = new ShapeState(); swf.Align(); if (hasStyle) { state.FillStyles = new FillStyleArray(swf, hasAlpha); state.LineStyles = new LineStyleArray(swf, hasAlpha, isExtended); } else { state.FillStyles = new FillStyleArray(); state.LineStyles = new LineStyleArray(); } state.FillBits = (int)swf.ReadBitUInt(4); state.LineBits = (int)swf.ReadBitUInt(4); ShapeRecord rec; while (true) { rec = new ShapeRecord(swf, hasAlpha, isExtended, extendedStyles, state); if (rec.Type == ShapeRecord.ShapeRecordType.EndOfShape) break; yield return rec; } }
public GradientInfo(SwfStream swf, bool hasAlpha) { swf.Align(); PadMode = (Padding)swf.ReadBitUInt(2); InterpolationMode = (Interpolation)swf.ReadBitUInt(2); GradientStops = new GradRecord[swf.ReadBitUInt(4)]; for (int i = 0; i < GradientStops.Length; i++) GradientStops[i] = new GradRecord(swf, hasAlpha); }
public ShapeRecord(SwfStream swf, bool hasAlpha, bool isExtended, bool extendedStyles, ShapeState state) { int f0 = 0, f1 = 0, l = 0; mFlags = swf.ReadBitUInt(6); Type = ConvertType(mFlags); switch (Type) { case ShapeRecordType.StyleChange: { if (NewMoveTo) { int bits = (int)swf.ReadBitUInt(5); MoveDeltaX = swf.ReadBitInt(bits); MoveDeltaY = swf.ReadBitInt(bits); } if (NewFillStyle0) f0 = ((int)swf.ReadBitUInt(state.FillBits)); if (NewFillStyle1) f1 = ((int)swf.ReadBitUInt(state.FillBits)); if (NewLineStyle) l = ((int)swf.ReadBitUInt(state.LineBits)); if (NewStyles && extendedStyles) { state.FillStyles = new FillStyleArray(swf, hasAlpha); state.LineStyles = new LineStyleArray(swf, hasAlpha, isExtended); state.FillBits = (int)swf.ReadBitUInt(4); state.LineBits = (int)swf.ReadBitUInt(4); } if (NewFillStyle0) FillStyle0 = state.GetFill(f0); if (NewFillStyle1) FillStyle1 = state.GetFill(f1); if (NewLineStyle) LineStyle = state.GetLine(l); } break; case ShapeRecordType.StraightEdge: { int bits = 2 + (int)(mFlags & 0x0F); bool general = swf.ReadBit(); bool vert = general || swf.ReadBit(); DrawDeltaX = (general || !vert) ? swf.ReadBitInt(bits) : 0; DrawDeltaY = (general || vert) ? swf.ReadBitInt(bits) : 0; } break; case ShapeRecordType.CurvedEdge: { int bits = 2 + (int)(mFlags & 0x0F); DrawControlX = swf.ReadBitInt(bits); DrawControlY = swf.ReadBitInt(bits); DrawDeltaX = swf.ReadBitInt(bits); DrawDeltaY = swf.ReadBitInt(bits); } break; } }
public LineStyle(SwfStream swf, bool hasAlpha, bool isExtended, int index) { Index = index; if (isExtended) { Width = swf.ReadUShort(); StartCapStyle = ReadCap(swf); JoinStyle = ReadJoin(swf); HasFill = swf.ReadBit(); NoHScale = swf.ReadBit(); NoVScale = swf.ReadBit(); PixelHinting = swf.ReadBit(); swf.ReadBitUInt(5); // Reserved NoClose = swf.ReadBit(); EndCapStyle = ReadCap(swf); if (JoinStyle == VGLineJoin.Miter) MiterLimit = swf.ReadFixedHalf(); if (HasFill) Fill = new FillStyle(swf, hasAlpha, -1); else Color = swf.ReadRGBA(); } else { Width = swf.ReadUShort(); Color = hasAlpha ? swf.ReadRGBA() : swf.ReadRGB(); StartCapStyle = VGLineCap.Round; EndCapStyle = VGLineCap.Round; JoinStyle = VGLineJoin.Round; HasFill = false; NoHScale = false; NoVScale = false; PixelHinting = false; NoClose = false; MiterLimit = 1m; Fill = null; } if (Width < 1) Width = 1; }
private VGLineJoin ReadJoin(SwfStream swf) { switch (swf.ReadBitUInt(2)) { case 0: return VGLineJoin.Round; case 1: return VGLineJoin.Bevel; case 2: return VGLineJoin.Miter; } throw new SwfCorruptedException("Inavlid line join value!"); }
private VGLineCap ReadCap(SwfStream swf) { switch (swf.ReadBitUInt(2)) { case 0: return VGLineCap.Round; case 1: return VGLineCap.Butt; case 2: return VGLineCap.Square; } throw new SwfCorruptedException("Inavlid line cap value!"); }
public GlyphEntry(SwfStream stream, int glyphBits, int advanceBits) { GlyphIndex = stream.ReadBitUInt(glyphBits); GlyphAdvance = stream.ReadBitInt(advanceBits); }