Exemplo n.º 1
0
        public static GlyphEntry ParseGlyphEntry(XElement element)
        {
            var result = new GlyphEntry();

            foreach (var attribute in element.Attributes())
            {
                switch (attribute.Name.LocalName)
                {
                case "glyph":
                    result.GlyphIndex = uint.Parse(attribute.Value);
                    break;

                case "advance":
                    result.GlyphAdvance = int.Parse(attribute.Value);
                    break;

                default:
                    throw new NotSupportedException();
                }
            }
            foreach (var elem in element.Elements())
            {
                switch (elem.Name.LocalName)
                {
                default:
                    throw new NotSupportedException();
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        internal GlyphEntry[] GlyphEntries;     // GLYPHENTRY[GlyphCount]

        internal TextRecord(SwfReader r, uint glyphBits, uint advanceBits, bool hasAlpha)
        {
            _TextRecordType      = r.GetBit();
            _StyleFlagsReserved  = r.GetBits(3);
            StyleFlagsHasFont    = r.GetBit();
            StyleFlagsHasColor   = r.GetBit();
            StyleFlagsHasYOffset = r.GetBit();
            StyleFlagsHasXOffset = r.GetBit();

            if (StyleFlagsHasFont)
            {
                FontID = r.GetUI16();
            }
            if (StyleFlagsHasColor)
            {
                TextColor = new RGBA(r.GetByte(), r.GetByte(), r.GetByte());
                if (hasAlpha)
                {
                    TextColor.A = r.GetByte();
                }
            }
            if (StyleFlagsHasXOffset)
            {
                XOffset = r.GetInt16();
            }
            if (StyleFlagsHasYOffset)
            {
                YOffset = r.GetInt16();
            }
            if (StyleFlagsHasFont)
            {
                TextHeight = r.GetUI16();
            }

            GlyphCount   = (uint)r.GetByte();
            GlyphEntries = new GlyphEntry[GlyphCount];
            for (int i = 0; i < GlyphCount; i++)
            {
                uint index   = r.GetBits(glyphBits);
                int  advance = r.GetSignedNBits(advanceBits);
                GlyphEntries[i] = new GlyphEntry(index, advance);
            }
            r.Align();//
        }
Exemplo n.º 3
0
        private bool TextRecordType; // UB[1]

        #endregion Fields

        #region Constructors

        public TextRecord(SwfReader r,  uint glyphBits, uint advanceBits, bool hasAlpha)
        {
            TextRecordType = r.GetBit();
            StyleFlagsReserved = r.GetBits(3);
            StyleFlagsHasFont = r.GetBit();
            StyleFlagsHasColor = r.GetBit();
            StyleFlagsHasYOffset = r.GetBit();
            StyleFlagsHasXOffset = r.GetBit();

            if(StyleFlagsHasFont)
            {
                FontID = r.GetUI16();
            }
            if(StyleFlagsHasColor)
            {
                TextColor = new RGBA(r.GetByte(), r.GetByte(), r.GetByte());
                if(hasAlpha)
                {
                    TextColor.A = r.GetByte();
                }
            }
            if(StyleFlagsHasXOffset)
            {
                XOffset = r.GetInt16();
            }
            if(StyleFlagsHasYOffset)
            {
                YOffset = r.GetInt16();
            }
            if(StyleFlagsHasFont)
            {
                TextHeight = r.GetUI16();
            }

            GlyphCount = (uint)r.GetByte();
            GlyphEntries = new GlyphEntry[GlyphCount];
            for (int i = 0; i < GlyphCount; i++)
            {
                uint index = r.GetBits(glyphBits);
                int advance = r.GetSignedNBits(advanceBits);
                GlyphEntries[i] = new GlyphEntry(index, advance);
            }
            r.Align();//
        }
Exemplo n.º 4
0
        public void Read(BigEndianReader br)
        {
            Version       = br.ReadInt32();
            Height        = br.ReadSingle();
            TopPadding    = br.ReadSingle();
            BottomPadding = br.ReadSingle();
            YAdvance      = br.ReadSingle();

            TransCount = br.ReadUInt16();

            br.BaseStream.Position += 0x2;

            for (int i = 0; i < TransCount; i++)
            {
                ushort currentchar = br.ReadUInt16();
                TransTable.Add(currentchar);
            }

            GlyphCount = br.ReadInt32();

            for (int i = 0; i < GlyphCount; i++)
            {
                GlyphEntry gly = new GlyphEntry();

                gly.Left   = br.ReadUInt16();
                gly.Top    = br.ReadUInt16();
                gly.Right  = br.ReadUInt16();
                gly.Bottom = br.ReadUInt16();

                gly.Offset  = br.ReadUInt16();
                gly.Width   = br.ReadUInt16();
                gly.Advance = br.ReadUInt16();
                gly.Mask    = br.ReadUInt16();

                GlyphTable.Add(gly);
            }

            //ABC doesn't store actual unicode so we gotta convert them from the Translation Table
            TransToUnicode();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Resolves method.
        /// This method provides the way to update the textrecords glyph indexes
        /// from Font object contained by the Swf Dictionnary.
        /// </summary>
        /// <param name="swf">SWF.</param>
        public override void Resolve(Swf swf)
        {
            IEnumerator records = textRecords.GetEnumerator();

            while (records.MoveNext())
            {
                TextRecord  textRecord = (TextRecord)records.Current;
                IEnumerator glyphs     = textRecord.GlyphEntries.GetEnumerator();
                while (glyphs.MoveNext())
                {
                    GlyphEntry glyph = (GlyphEntry)glyphs.Current;
                    if (glyph.GlyphCharacter != '\0')
                    {
                        object font = swf.Dictionary[textRecord.FontId];
                        if (font != null && font is DefineFont2Tag)
                        {
                            int glyphIndex = ((DefineFont2Tag)font).GlyphShapesTable.GetCharIndex(glyph.GlyphCharacter);
                            glyph.GlyphIndex = (uint)glyphIndex;
                        }
                        //TODO: For DefineFont
                    }
                }
            }
        }
Exemplo n.º 6
0
 public static XElement FormatGlyphEntry(GlyphEntry entry)
 {
     return(new XElement(XName.Get("TextEntry"),
                         new XAttribute(XName.Get("glyph"), entry.GlyphIndex),
                         new XAttribute(XName.Get("advance"), entry.GlyphAdvance)));
 }