Пример #1
0
        internal static bool Make(VGPath path, out StencilVertex[] vertices, out int tris)
        {
            vertices = null;
            // Count triangles
            tris =
                path.GetCount(VGPath.SegmentType.CurveTo) * 2 +
                path.GetCount(VGPath.SegmentType.LineTo) +
                path.GetCount(VGPath.SegmentType._Tesselated);

            if (tris == 0)
                return false;

            // Tesselate
            vertices = new StencilVertex[tris * 3];
            StencilVertex start = new StencilVertex();
            Vector2 last = new Vector2();
            int index = 0;

            start.Set(0, 0, Constants.Coef_Solid);
            for (var s = path.FirstSegment; s != null; s = s.Next)
            {
                switch (s.Value.Type)
                {
                    case VGPath.SegmentType.CurveTo:
                        {
                            vertices[index++].Set(last.X, last.Y, Constants.Coef_Solid);
                            vertices[index++].Set(s.Value.Target.X, s.Value.Target.Y, Constants.Coef_Solid);
                            vertices[index++] = start;

                            vertices[index++].Set(last.X, last.Y, Constants.Coef_BezierStart);
                            vertices[index++].Set(s.Value.Controls[0].X, s.Value.Controls[0].Y, Constants.Coef_BezierControl);
                            vertices[index++].Set(s.Value.Target.X, s.Value.Target.Y, Constants.Coef_BezierEnd);
                        }
                        break;
                    case VGPath.SegmentType.LineTo:
                    case VGPath.SegmentType._Tesselated:
                        {
                            vertices[index++].Set(last.X, last.Y, Constants.Coef_Solid);
                            vertices[index++].Set(s.Value.Target.X, s.Value.Target.Y, Constants.Coef_Solid);
                            vertices[index++] = start;
                        }
                        break;
                    case VGPath.SegmentType.MoveTo:
                        {
                            start.Set(s.Value.Target.X, s.Value.Target.Y, Constants.Coef_Solid);
                        }
                        break;
                    default:
                        continue;
                }

                last = s.Value.Target;
            }

            return true;
        }
Пример #2
0
        internal static void CombineVertices(IDictionary<char, VGGlyphInfo> glyphs, out StencilVertex[] vertices, out CharBuffer[] definitions, out Vector4 extents)
        {
            int tris;
            int count = glyphs.Count;
            var verts = new List<StencilVertex>(256 * count);
            var defs = new List<CharBuffer>(count);
            extents = new Vector4();

            foreach (var glyph in glyphs)
            {
                var path = glyph.Value.Path;
                if (path == null)
                    continue;

                if (!path.IsEmpty)
                {
                    if (!FillMesh.Make(path, out vertices, out tris))
                        continue;

                    defs.Add(new CharBuffer { Character = glyph.Key, Offset = verts.Count, Triangles = tris });
                    verts.AddRange(vertices);
                    path.ExpandExtents(ref extents);
                }
                else
                    defs.Add(new CharBuffer { Character = glyph.Key, Offset = 0, Triangles = 0 });
            }

            definitions = defs.ToArray();
            vertices = verts.ToArray();
        }