Exemplo n.º 1
0
        public static VGFontData Deserialize(ContentReader reader)
        {
            var data = new VGFontData
            {
                FillRule = (VGFillRule)reader.ReadByte(),
                EmSquareSize = reader.ReadSingle(),
                LeadingSize = reader.ReadSingle(),
                Extents = reader.ReadVector4(),
                Vertices = new StencilVertex[reader.ReadInt32()],
                Glyphs = new VGFontData.GlyphInfo[reader.ReadInt32()]
            };

            for (int i = 0; i < data.Vertices.Length; i++)
                data.Vertices[i] = StencilVertex.Deserialize(reader);

            for (int i = 0; i < data.Glyphs.Length; i++)
                data.Glyphs[i] = new VGFontData.GlyphInfo
                {
                    Character = reader.ReadChar(),
                    Offset = reader.ReadInt32(),
                    Triangles = reader.ReadInt32(),
                    Escape = new Vector2
                    {
                        X = reader.ReadSingle(),
                        Y = reader.ReadSingle()
                    }
                };

            data.Kerning = VGKerningTable.Deserialize(reader);
            return data;
        }
Exemplo n.º 2
0
        public static VGFontData FromPaths(VGFillRule fillRule, float emSquareSize, float leadingSize, VGKerningTable kerning, IDictionary<char, VGGlyphInfo> glyphs)
        {
            StencilVertex[] vertices;
            VGFont.CharBuffer[] defs;
            Vector4 extents;
            VGFont.CombineVertices(glyphs, out vertices, out defs, out extents);

            var data = new VGFontData
            {
                FillRule = fillRule,
                EmSquareSize = emSquareSize,
                Extents = extents,
                Vertices = vertices,
                Kerning = kerning,
                LeadingSize = leadingSize,
                Glyphs = new GlyphInfo[defs.Length]
            };

            for (int i = 0; i < defs.Length; i++)
                data.Glyphs[i] = new GlyphInfo
                {
                    Character = defs[i].Character,
                    Offset = defs[i].Offset,
                    Triangles = defs[i].Triangles,
                    Escape = glyphs[defs[i].Character].Advance
                };

            return data;
        }