public static void WriteLineStyleEx(this ISwfStreamWriter writer, LineStyleEx lineStyle) { writer.WriteUInt16(lineStyle.Width); writer.WriteUnsignedBits((uint)lineStyle.StartCapStyle, 2); writer.WriteUnsignedBits((uint)lineStyle.JoinStyle, 2); writer.WriteBit(lineStyle.HasFill); writer.WriteBit(lineStyle.NoHScale); writer.WriteBit(lineStyle.NoVScale); writer.WriteBit(lineStyle.PixelHinting); writer.WriteUnsignedBits(lineStyle.Reserved, 5); writer.WriteBit(lineStyle.NoClose); writer.WriteUnsignedBits((uint)lineStyle.EndCapStyle, 2); if (lineStyle.JoinStyle == JoinStyle.Miter) { writer.WriteFixedPoint8(lineStyle.MilterLimitFactor); } if (lineStyle.HasFill) { writer.WriteFillStyleRGBA(lineStyle.FillStyle); } else { writer.WriteRGBA(lineStyle.Color); } }
public static void WriteColorTransformRGB(this ISwfStreamWriter writer, ref ColorTransformRGB tranform) { var bitsCounter = new SignedBitsCount(0); if (tranform.HasAddTerms) { bitsCounter.AddValue(tranform.RedAddTerm); bitsCounter.AddValue(tranform.GreenAddTerm); bitsCounter.AddValue(tranform.BlueAddTerm); } if (tranform.HasMultTerms) { bitsCounter.AddValue(tranform.RedMultTerm); bitsCounter.AddValue(tranform.GreenMultTerm); bitsCounter.AddValue(tranform.BlueMultTerm); } writer.WriteBit(tranform.HasAddTerms); writer.WriteBit(tranform.HasMultTerms); var bits = bitsCounter.GetBits(); writer.WriteUnsignedBits(bits, 4); if (tranform.HasMultTerms) { writer.WriteSignedBits(tranform.RedMultTerm, bits); writer.WriteSignedBits(tranform.GreenMultTerm, bits); writer.WriteSignedBits(tranform.BlueMultTerm, bits); } if (tranform.HasAddTerms) { writer.WriteSignedBits(tranform.RedAddTerm, bits); writer.WriteSignedBits(tranform.GreenAddTerm, bits); writer.WriteSignedBits(tranform.BlueAddTerm, bits); } writer.FlushBits(); }
public static void WriteTextRecordRGBA(this ISwfStreamWriter writer, TextRecordRGBA record, uint glyphBits, uint advanceBits) { if (record == null) { throw new ArgumentNullException("record"); } writer.WriteBit(record.Type); writer.WriteUnsignedBits(record.Reserved, 3); writer.WriteBit(record.FontID.HasValue); writer.WriteBit(record.TextColor.HasValue); writer.WriteBit(record.YOffset.HasValue); writer.WriteBit(record.XOffset.HasValue); var isEnd = !record.Type && record.Reserved == 0 && !record.FontID.HasValue && !record.TextColor.HasValue && !record.YOffset.HasValue && !record.XOffset.HasValue; if (!isEnd) { if (record.FontID.HasValue) { writer.WriteUInt16(record.FontID.Value); } if (record.TextColor.HasValue) { var color = record.TextColor.Value; writer.WriteRGBA(ref color); } if (record.XOffset.HasValue) { writer.WriteSInt16(record.XOffset.Value); } if (record.YOffset.HasValue) { writer.WriteSInt16(record.YOffset.Value); } if (record.FontID.HasValue) { if (!record.TextHeight.HasValue) { throw new InvalidOperationException("Font height must be specified when font is specified"); } writer.WriteUInt16(record.TextHeight.Value); } if (record.Glyphs.Count > 255) { throw new InvalidOperationException("Text record has too much glyphs specified"); } writer.WriteByte((byte)record.Glyphs.Count); foreach (var glyph in record.Glyphs) { writer.WriteGlyphEntry(glyph, glyphBits, advanceBits); } } writer.FlushBits(); }
public static void WriteMatrix(this ISwfStreamWriter writer, ref SwfMatrix matrix) { var hasScale = matrix.HasScale; writer.WriteBit(hasScale); if (hasScale) { var sx = (int)(matrix.ScaleX * 65536.0); var sy = (int)(matrix.ScaleY * 65536.0); var scaleBits = new SignedBitsCount(sx, sy).GetBits(); if (scaleBits < 1) { scaleBits = 1; } writer.WriteUnsignedBits(scaleBits, 5); writer.WriteFixedPoint16(matrix.ScaleX, scaleBits); writer.WriteFixedPoint16(matrix.ScaleY, scaleBits); } var hasRotate = matrix.HasRotate; writer.WriteBit(hasRotate); if (hasRotate) { var rx = (int)(matrix.RotateSkew0 * 65536.0); var ry = (int)(matrix.RotateSkew1 * 65536.0); var rotateBits = new SignedBitsCount(rx, ry).GetBits(); if (rotateBits < 1) { rotateBits = 1; } writer.WriteUnsignedBits(rotateBits, 5); writer.WriteFixedPoint16(matrix.RotateSkew0, rotateBits); writer.WriteFixedPoint16(matrix.RotateSkew1, rotateBits); } var translateBits = new SignedBitsCount(matrix.TranslateX, matrix.TranslateY).GetBits(); writer.WriteUnsignedBits(translateBits, 5); writer.WriteSignedBits(matrix.TranslateX, translateBits); writer.WriteSignedBits(matrix.TranslateY, translateBits); writer.FlushBits(); }
private static void WriteStyleChangeShapeRecord(ISwfStreamWriter writer, StyleChangeShapeRecord record, ref uint fillStylesBits, ref uint lineStylesBits) { writer.WriteBit(false); var stateNewStyles = record.StateNewStyles; var stateFillStyle0 = record.FillStyle0.HasValue; var stateFillStyle1 = record.FillStyle1.HasValue; var stateLineStyle = record.LineStyle.HasValue; var stateMoveTo = record.StateMoveTo; writer.WriteBit(stateNewStyles); writer.WriteBit(stateLineStyle); writer.WriteBit(stateFillStyle1); writer.WriteBit(stateFillStyle0); writer.WriteBit(stateMoveTo); if (stateMoveTo) { var cnt = new SignedBitsCount(record.MoveDeltaX, record.MoveDeltaY); var moveBits = cnt.GetBits(); writer.WriteUnsignedBits(moveBits, 5); writer.WriteSignedBits(record.MoveDeltaX, moveBits); writer.WriteSignedBits(record.MoveDeltaY, moveBits); } if (stateFillStyle0) { writer.WriteUnsignedBits(record.FillStyle0.Value, fillStylesBits); } if (stateFillStyle1) { writer.WriteUnsignedBits(record.FillStyle1.Value, fillStylesBits); } if (stateLineStyle) { writer.WriteUnsignedBits(record.LineStyle.Value, lineStylesBits); } }
public static void WriteButtonRecordEx(this ISwfStreamWriter writer, ButtonRecordEx button) { writer.WriteUnsignedBits(button.Reserved, 2); writer.WriteBit(button.BlendMode.HasValue); writer.WriteBit(button.Filters.Count > 0); writer.WriteBit(button.StateHitTest); writer.WriteBit(button.StateDown); writer.WriteBit(button.StateOver); writer.WriteBit(button.StateUp); if (!button.IsEndButton) { writer.WriteUInt16(button.CharacterID); writer.WriteUInt16(button.PlaceDepth); writer.WriteMatrix(ref button.PlaceMatrix); writer.WriteColorTransformRGBA(button.ColorTransform); writer.FlushBits(); if (button.Filters.Count > 0) { writer.WriteFilterList(button.Filters); } if (button.BlendMode.HasValue) { writer.WriteByte((byte)button.BlendMode.Value); } } }
public static void WriteButtonCondition(this ISwfStreamWriter writer, ButtonCondition cond) { writer.WriteBit(cond.IdleToOverDown); writer.WriteBit(cond.OutDownToIdle); writer.WriteBit(cond.OutDownToOverDown); writer.WriteBit(cond.OverDownToOutDown); writer.WriteBit(cond.OverDownToOverUp); writer.WriteBit(cond.OverUpToOverDown); writer.WriteBit(cond.OverUpToIdle); writer.WriteBit(cond.IdleToOverUp); writer.WriteUnsignedBits(cond.KeyPress, 7); writer.WriteBit(cond.OverDownToIdle); var aw = new ActionWriter(writer); foreach (var action in cond.Actions) { aw.WriteAction(action); } }
public static void WriteClipEventFlags(this ISwfStreamWriter writer, byte swfVersion, ClipEventFlags flags) { writer.WriteBit(flags.ClipEventKeyUp); writer.WriteBit(flags.ClipEventKeyDown); writer.WriteBit(flags.ClipEventMouseUp); writer.WriteBit(flags.ClipEventMouseDown); writer.WriteBit(flags.ClipEventMouseMove); writer.WriteBit(flags.ClipEventUnload); writer.WriteBit(flags.ClipEventEnterFrame); writer.WriteBit(flags.ClipEventLoad); writer.WriteBit(flags.ClipEventDragOver); writer.WriteBit(flags.ClipEventRollOut); writer.WriteBit(flags.ClipEventRollOver); writer.WriteBit(flags.ClipEventReleaseOutside); writer.WriteBit(flags.ClipEventRelease); writer.WriteBit(flags.ClipEventPress); writer.WriteBit(flags.ClipEventInitialize); writer.WriteBit(flags.ClipEventData); if (swfVersion >= 6) { writer.WriteUnsignedBits(flags.Reserved, 5); writer.WriteBit(flags.ClipEventConstruct); writer.WriteBit(flags.ClipEventKeyPress); writer.WriteBit(flags.ClipEventDragOut); writer.WriteByte(flags.Reserved2); } }