Ejemplo n.º 1
0
        static Msdfgen.Shape CreateMsdfShape(List <Contour> contours)
        {
            var shape = new Msdfgen.Shape();
            int j     = contours.Count;

            for (int i = 0; i < j; ++i)
            {
                var cnt = new Msdfgen.Contour();
                shape.contours.Add(cnt);

                Contour            contour = contours[i];
                List <ContourPart> parts   = contour.parts;
                int m = parts.Count;
                for (int n = 0; n < m; ++n)
                {
                    ContourPart p = parts[n];
                    switch (p.Kind)
                    {
                    default: throw new NotSupportedException();

                    case PartKind.Curve3:
                    {
                        Curve3 curve3 = (Curve3)p;
                        cnt.AddQuadraticSegment(
                            curve3.FirstPoint.X, curve3.FirstPoint.Y,
                            curve3.x1, curve3.y1,
                            curve3.x2, curve3.y2
                            );
                    }
                    break;

                    case PartKind.Curve4:
                    {
                        Curve4 curve4 = (Curve4)p;
                        cnt.AddCubicSegment(
                            curve4.FirstPoint.X, curve4.FirstPoint.Y,
                            curve4.x1, curve4.y1,
                            curve4.x2, curve4.y2,
                            curve4.x3, curve4.y3);
                    }
                    break;

                    case PartKind.Line:
                    {
                        Line line = (Line)p;
                        cnt.AddLine(
                            line.FirstPoint.X, line.FirstPoint.Y,
                            line.x1, line.y1);
                    }
                    break;
                    }
                }
            }
            return(shape);
        }
Ejemplo n.º 2
0
        static Contour CreateFitContour(Contour contour, float pixelScale, bool x_axis, bool y_axis)
        {
            Contour            newc  = new Contour();
            List <ContourPart> parts = contour.parts;
            int m = parts.Count;

            for (int n = 0; n < m; ++n)
            {
                ContourPart p = parts[n];
                switch (p.Kind)
                {
                default: throw new NotSupportedException();

                case PartKind.Curve3:
                {
                    Curve3 curve3 = (Curve3)p;
                    newc.AddPart(new Curve3(
                                     curve3.FirstPoint.X * pixelScale, curve3.FirstPoint.Y * pixelScale,
                                     curve3.x1 * pixelScale, curve3.y1 * pixelScale,
                                     curve3.x2 * pixelScale, curve3.y2 * pixelScale));
                }
                break;

                case PartKind.Curve4:
                {
                    Curve4 curve4 = (Curve4)p;
                    newc.AddPart(new Curve4(
                                     curve4.FirstPoint.X * pixelScale, curve4.FirstPoint.Y * pixelScale,
                                     curve4.x1 * pixelScale, curve4.y1 * pixelScale,
                                     curve4.x2 * pixelScale, curve4.y2 * pixelScale,
                                     curve4.x3 * pixelScale, curve4.y3 * pixelScale
                                     ));
                }
                break;

                case PartKind.Line:
                {
                    Line line = (Line)p;
                    newc.AddPart(new Line(
                                     line.FirstPoint.X * pixelScale, line.FirstPoint.Y * pixelScale,
                                     line.x1 * pixelScale, line.y1 * pixelScale
                                     ));
                }
                break;
                }
            }
            return(newc);
        }