Exemplo n.º 1
0
        public static void WriteTextRecordRGB(this ISwfStreamWriter writer, TextRecordRGB 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.WriteRGB(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();
        }
Exemplo n.º 2
0
        public static IList <TextRecordRGB> ReadTextRecordsRGB(this ISwfStreamReader reader, uint glyphBits, uint advanceBits)
        {
            var  res = new List <TextRecordRGB>();
            bool isEnd;

            do
            {
                var record = new TextRecordRGB();
                record.Type     = reader.ReadBit();
                record.Reserved = (byte)reader.ReadUnsignedBits(3);
                var hasFont    = reader.ReadBit();
                var hasColor   = reader.ReadBit();
                var hasYOffset = reader.ReadBit();
                var hasXOffset = reader.ReadBit();

                isEnd = !record.Type && record.Reserved == 0 && !hasFont && !hasColor && !hasYOffset && !hasXOffset;

                if (!isEnd)
                {
                    record.FontID = hasFont ? (ushort?)reader.ReadUInt16() : null;
                    if (hasColor)
                    {
                        record.TextColor = reader.ReadRGB();
                    }
                    if (hasXOffset)
                    {
                        record.XOffset = reader.ReadSInt16();
                    }
                    if (hasYOffset)
                    {
                        record.YOffset = reader.ReadSInt16();
                    }
                    if (hasFont)
                    {
                        record.TextHeight = reader.ReadUInt16();
                    }
                    var count = reader.ReadByte();
                    for (var i = 0; i < count; i++)
                    {
                        var entry = reader.ReadGlyphEntry(glyphBits, advanceBits);
                        record.Glyphs.Add(entry);
                    }
                    reader.AlignToByte();
                }
                res.Add(record);
            } while (!isEnd);
            return(res);
        }
Exemplo n.º 3
0
        public static TextRecordRGB FromXmlRGB(XElement element)
        {
            var result = new TextRecordRGB();
            foreach (var attribute in element.Attributes()) {
                switch (attribute.Name.LocalName) {
                    case "objectID":
                        result.FontID = ushort.Parse(attribute.Value);
                        break;
                    case "isSetup":
                        result.Type = CommonFormatter.ParseBool(attribute.Value);
                        break;
                    case "reserved":
                        result.Reserved = byte.Parse(attribute.Value);
                        break;
                    case "x":
                        result.XOffset = short.Parse(attribute.Value);
                        break;
                    case "y":
                        result.YOffset = short.Parse(attribute.Value);
                        break;
                    case "fontHeight":
                        result.TextHeight = ushort.Parse(attribute.Value);
                        break;
                    default:
                        throw new NotSupportedException();

                }
            }
            foreach (var elem in element.Elements()) {
                switch (elem.Name.LocalName) {
                    case "color":
                        var color = XColorRGB.FromXml(elem.Element("Color"));
                        result.TextColor = color;
                        break;
                    case "glyphs":
                        foreach (var glyphElem in elem.Elements()) {
                            result.Glyphs.Add(ParseGlyphEntry(glyphElem));
                        }
                        break;
                    default:
                        throw new NotSupportedException();
                }
            }
            return result;
        }
Exemplo n.º 4
0
        public static IList<TextRecordRGB> ReadTextRecordsRGB(this ISwfStreamReader reader, uint glyphBits, uint advanceBits)
        {
            var res = new List<TextRecordRGB>();
            bool isEnd;
            do {
                var record = new TextRecordRGB();
                record.Type = reader.ReadBit();
                record.Reserved = (byte)reader.ReadUnsignedBits(3);
                var hasFont = reader.ReadBit();
                var hasColor = reader.ReadBit();
                var hasYOffset = reader.ReadBit();
                var hasXOffset = reader.ReadBit();

                isEnd = !record.Type && record.Reserved == 0 && !hasFont && !hasColor && !hasYOffset && !hasXOffset;

                if (!isEnd) {
                    record.FontID = hasFont ? (ushort?)reader.ReadUInt16() : null;
                    if (hasColor) {
                        record.TextColor = reader.ReadRGB();
                    }
                    if (hasXOffset) {
                        record.XOffset = reader.ReadSInt16();
                    }
                    if (hasYOffset) {
                        record.YOffset = reader.ReadSInt16();
                    }
                    if (hasFont) {
                        record.TextHeight = reader.ReadUInt16();
                    }
                    var count = reader.ReadByte();
                    for (var i = 0; i < count; i++) {
                        var entry = reader.ReadGlyphEntry(glyphBits, advanceBits);
                        record.Glyphs.Add(entry);
                    }
                    reader.AlignToByte();
                }
                res.Add(record);
            } while (!isEnd);
            return res;
        }
Exemplo n.º 5
0
 public static XElement ToXmlRGB(TextRecordRGB entry)
 {
     var res = new XElement(XName.Get("TextRecord6"));
     res.Add(new XAttribute("isSetup", CommonFormatter.Format(entry.Type)));
     if (entry.FontID.HasValue) {
         res.Add(new XAttribute("objectID", entry.FontID.Value));
     }
     if (entry.Reserved != 0) {
         res.Add(new XAttribute("reserved", entry.Reserved));
     }
     if (entry.XOffset.HasValue) {
         res.Add(new XAttribute("x", entry.XOffset.Value));
     }
     if (entry.YOffset.HasValue) {
         res.Add(new XAttribute("y", entry.YOffset.Value));
     }
     if (entry.FontID.HasValue) {
         if (!entry.TextHeight.HasValue) throw new InvalidOperationException("Text Height must be specified");
         res.Add(new XAttribute("fontHeight", entry.TextHeight.Value));
     }
     if (entry.TextColor.HasValue) {
         var color = entry.TextColor.Value;
         res.Add(new XElement("color", XColorRGB.ToXml(color)));
     }
     res.Add(new XElement(XName.Get("glyphs"), entry.Glyphs.Select(FormatGlyphEntry)));
     return res;
 }
Exemplo n.º 6
0
        public static void WriteTextRecordRGB(this ISwfStreamWriter writer, TextRecordRGB 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.WriteRGB(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();
        }