示例#1
0
        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();
        }