Exemplo n.º 1
0
        internal VGFont(VGDevice device, VGFillRule fillRule, float emSquareSize, float leadingSize, IDictionary<char, VGGlyphInfo> glyphs, VGFontMode mode)
            : this(device, fillRule, emSquareSize, leadingSize)
        {
            StencilVertex[] vertices;
            CharBuffer[] defs;
            CombineVertices(glyphs, out vertices, out defs, out _maxGlyphExtents);

            FontMode = mode;
            if (mode == VGFontMode.CPU)
            {
                _bufferedGlyphs = new VertexBuffer(device.GraphicsDevice, StencilVertex.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly);
                _bufferedGlyphs.SetData(vertices);
            }
            else
            {
                int h = vertices.Length / device.MaxTextureSize;
                int s = device.MaxTextureSize * h;
                if (h > 0)
                {
                    Vertices = new Texture2D(device.GraphicsDevice, device.MaxTextureSize, 1 + h, false, SurfaceFormat.Vector4);
                    Vertices.SetData(0, new Rectangle(0, 0, device.MaxTextureSize, h), vertices, 0, s);
                    Vertices.SetData(0, new Rectangle(0, h, vertices.Length - s, 1), vertices, s, vertices.Length - s);
                }
                else
                {
                    Vertices = new Texture2D(device.GraphicsDevice, vertices.Length, 1, false, SurfaceFormat.Vector4);
                    Vertices.SetData(vertices);
                }
            }

            for (int i = 0; i < defs.Length; i++)
            {
                var def = defs[i];
                var info = glyphs[def.Character];
                _glyphs[def.Character] = new BufferGlyph(_bufferedGlyphs, def.Offset, def.Triangles, info.Advance);
            }
        }
Exemplo n.º 2
0
        internal VGFont(VGDevice device, Loaders.VGFontData fontData, VGFontMode mode)
            : this(device, fontData.FillRule, fontData.EmSquareSize, fontData.LeadingSize)
        {
            _maxGlyphExtents = fontData.Extents;

            KerningTable = fontData.Kerning;
            FontMode = mode;
            if (mode == VGFontMode.CPU)
            {
                _bufferedGlyphs = new VertexBuffer(device.GraphicsDevice, StencilVertex.VertexDeclaration, fontData.Vertices.Length, BufferUsage.WriteOnly);
                _bufferedGlyphs.SetData(fontData.Vertices);
            }
            else
            {
                int h = fontData.Vertices.Length / device.MaxTextureSize;
                int s = device.MaxTextureSize * h;
                Vertices = new Texture2D(device.GraphicsDevice, device.MaxTextureSize, 1 + h, false, SurfaceFormat.Vector4);
                if (h > 0) Vertices.SetData(0, new Rectangle(0, 0, device.MaxTextureSize, h), fontData.Vertices, 0, s);
                Vertices.SetData(0, new Rectangle(0, h, fontData.Vertices.Length - s, 1), fontData.Vertices, s, fontData.Vertices.Length - s);
            }

            foreach(var def in fontData.Glyphs)
                _glyphs[def.Character] = new BufferGlyph(_bufferedGlyphs, def.Offset, def.Triangles, def.Escape);
        }