Esempio n. 1
0
        protected override Vector2 SetString(string text)
        {
            int len = text.Length;
            List<Glyph> glyphs = new List<Glyph>(len);
            List<Vector2> offsets = new List<Vector2>(len);
            var gpi = new GlyphPositionInfo { Offset = Vector2.Zero, Size = Vector2.Zero };
            gpi.TabSize = ((Font.Device.ActiveContext != null) ? Font.Device.ActiveContext.State : Font.Device.State).TabSize * Font.EmSquareSize;

            foreach (var g in ProcessString<Glyph>(Font, text, gpi))
            {
                glyphs.Add(g);
                offsets.Add(gpi.Offset);
            }

            _glyphs = glyphs.ToArray();
            _offsets = offsets.ToArray();
            return gpi.Size;
        }
Esempio n. 2
0
        protected override Vector2 SetString(string text)
        {
            int i = 0, len = text.Length;
            List<Vector2> indices = new List<Vector2>(256 * len);
            List<Vector2> offsets = new List<Vector2>(len);
            var gpi = new GlyphPositionInfo { Offset = Vector2.Zero, Size = Vector2.Zero };
            gpi.TabSize = ((Font.Device.ActiveContext != null) ? Font.Device.ActiveContext.State : Font.Device.State).TabSize * Font.EmSquareSize;

            _triangles = 0;
            foreach (var g in ProcessString<BufferGlyph>(Font, text, gpi))
            {
                indices.AddRange(Enumerable.Range(g.VertexOffset, 3 * g.TriangleCount).Select(j => new Vector2(j, i)));
                offsets.Add(gpi.Offset);

                _triangles += g.TriangleCount;
                i++;
            }

            if (_vertices != null) _vertices.Dispose();
            if (Glyphs != null) Glyphs.Dispose();

            if (_triangles == 0)
            {
                _vertices = null;
                Glyphs = null;
                return gpi.Size;
            }

            if (_preferVRAM)
                _vertices = new VertexBuffer(Font.Device.GraphicsDevice, VertexDeclaration, indices.Count, BufferUsage.WriteOnly);
            else
               _vertices = new DynamicVertexBuffer(Font.Device.GraphicsDevice, VertexDeclaration, indices.Count, BufferUsage.WriteOnly);

            int h = offsets.Count / Font.Device.MaxTextureSize;
            int s = Font.Device.MaxTextureSize * h;
            var d = offsets.ToArray();

            if (h > 0)
            {
                Glyphs = new Texture2D(Font.Device.GraphicsDevice, Font.Device.MaxTextureSize, 1 + h, false, SurfaceFormat.Vector2);
                Glyphs.SetData(0, new Rectangle(0, 0, Font.Device.MaxTextureSize, h), d, 0, s);
                Glyphs.SetData(0, new Rectangle(0, h, d.Length - s, 1), d, s, d.Length - s);
            }
            else
            {
                Glyphs = new Texture2D(Font.Device.GraphicsDevice, d.Length, 1, false, SurfaceFormat.Vector2);
                Glyphs.SetData(d);
            }

            _vertices.SetData(indices.ToArray());
            return gpi.Size;
        }