Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
0
 internal VGFont(VGDevice device, VGFillRule fillRule, float emSquareSize, float leadingSize)
 {
     Device = device;
     FillRule = fillRule;
     EmSquareSize = emSquareSize;
     LeadingSize = leadingSize;
     FontMode = VGFontMode.CPU;
 }
Ejemplo n.º 3
0
        internal void BeginCPUTextStenciling(VGFillRule rule)
        {
            // Setup stenciling
            _device.BlendState = Device.BlendStates.NoColor;
            _device.DepthStencilState = (rule == VGFillRule.NonZero) ? State.Stencils.NonZero : State.Stencils.EvenOdd;

            Device.EffectManager.StencilFill.SetParameters(State.Projection.Matrix, State.GlyphToSurface.Matrix);
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
        public void ResetDefaultValues()
        {
            PathToSurface.Clear();
            ImageToSurface.Clear();
            GlyphToSurface.Clear();
            PathToFillPaint.Clear();
            PathToTextPaint.Clear();
            PathToStrokePaint.Clear();
            ColorTransformation.Clear();

            NonScalingStroke = false;
            ColorTransformationEnabled = false;
            MaskingEnabled = false;
            StrokeThickness = 1f;
            StrokeMiterLimit = 4f;
            ClearColor = Color.Transparent;
            StrokeStartCap = StrokeEndCap = VGLineCap.Butt;
            StrokeJoin = VGLineJoin.Miter;
            BlendMode = VGBlendMode.SrcOver;
            Mask = null;
            Font = null;
            MaskChannels = Vector4.UnitW;
            ColorChannels = ColorWriteChannels.All;
            TabSize = Vector2.One;
            FillPaint = StrokePaint = GlyphPaint = new VGColorPaint(Device, Color.White);

            // Not create states twice
            _fillRule = VGFillRule.EvenOdd;
            _readMask = VGStencilMasks.None;
            WriteStencilMask = VGStencilMasks.None;
        }
Ejemplo n.º 6
0
        internal void StencilInstancedGlyphs(VGFillRule rule, GPUBufferedString text)
        {
            var effect = Device.EffectManager.StencilText;

            // Setup stenciling
            _device.BlendState = Device.BlendStates.NoColor;
            _device.DepthStencilState = (rule == VGFillRule.NonZero) ? State.Stencils.NonZero : State.Stencils.EvenOdd;

            // Render mesh
            if (State.Antialiasing == VGAntialiasing.None)
            {
                effect.Apply(State.Projection.Matrix, State.GlyphToSurface.Matrix, Vector2.Zero, text.Font.Vertices, text.Glyphs);
                text.Render();
            }
            else
                for (int samples = (int)State.Antialiasing - 1, MSAAMask = _msaaMasks[State.Antialiasing]; samples >= 0; samples--, MSAAMask <<= 1)
                {
                    _device.MultiSampleMask = MSAAMask;
                    effect.Apply(State.Projection.Matrix, State.GlyphToSurface.Matrix, Surface.MSAAPattern[samples], text.Font.Vertices, text.Glyphs);
                    text.Render();
                }
        }