コード例 #1
0
ファイル: DefineFont2Tag.cs プロジェクト: kaldap/XnaFlash
        public virtual void Load(SwfStream stream, uint length, byte version)
        {
            CharacterID = stream.ReadUShort();
            Flags = (FontFlags)stream.ReadByte();
            Language = stream.ReadLanguage();
            Name = stream.ReadString(stream.ReadByte());
            ushort count = stream.ReadUShort();
            stream.Skip((count + 1) * (((Flags & FontFlags.WideOffsets) != 0) ? 4 : 2)); // Offsets

            Glyphs = new FontGlyph[count];
            for (int i = 0; i < count; i++)
            {
                var subShapes = new Shape(ShapeInfo.ReadShape(stream, false, false, false, false), true).SubShapes;
                if (subShapes == null || subShapes.Length < 1) continue;

                var shape = subShapes[0];
                if (shape != null && shape.Fills.Count > 0)
                {
                    Glyphs[i] = new FontGlyph
                    {
                        GlyphPath = shape.Fills.Values.First().GetPath(),
                        ReferencePoint = new Vector2(shape.Shape.ReferencePoint.X, shape.Shape.ReferencePoint.Y) * DefineFontTag.EMSquareInv
                    };
                    Glyphs[i].GlyphPath.Scale(DefineFontTag.EMSquareInv);
                }
                else
                    Glyphs[i] = new FontGlyph { GlyphPath = new VGPath(), ReferencePoint = Vector2.Zero };
            }

            if ((Flags & FontFlags.WideCodes) != 0)
                Characters = stream.ReadCharArray((int)count);
            else
            {
                Characters = new char[count];
                for (int i = 0; i < count; i++)
                    Characters[i] = (char)stream.ReadByte();
            }

            if ((Flags & FontFlags.HasLayout) != 0)
            {
                Ascent = stream.ReadShort();
                Descent = stream.ReadShort();
                Leading = stream.ReadShort();
                Advances = stream.ReadShortArray(count);
                Bounds = stream.ReadRectangleArray(count);

                char l, r;
                int adj;
                ushort kerns = stream.ReadUShort();
                Kerning = new VGKerningTable(kerns);
                if ((Flags & FontFlags.WideCodes) != 0)
                {
                    for (int i = 0; i < kerns; i++)
                    {
                        l = (char)stream.ReadUShort();
                        r = (char)stream.ReadUShort();
                        adj = stream.ReadShort();
                        Kerning.Add(l, r, adj);
                    }
                }
                else
                {
                    for (int i = 0; i < kerns; i++)
                    {
                        l = (char)stream.ReadByte();
                        r = (char)stream.ReadByte();
                        adj = stream.ReadShort();
                        Kerning.Add(l, r, adj);
                    }
                }
            }
        }