Fonts – extract geometry from font

I want to be able to extract the geometry of each letter in the TrueType font file Each letter has a set of coordinates, assuming that each letter is in its own grid

As shown in the figure, thousands of words – I want to get the letter vertex similar to the figure below (by http://polymaps.org/ (provided)

to update

As prompted to use GDI, it has now been integrated into NET System. Drawing. In drawing2d, I got the following code to create wkt polygons No Bezier curve is possible Even after flipping and rotating letters, some paths still cannot be connected correctly

// C# Visual Studio

        GraphicsPath gp = new GraphicsPath();

        Point origin = new Point(0,0);
        StringFormat format = new StringFormat();
        FontFamily ff = new FontFamily("Arial");
        //enter letter here
        gp.AddString("T",ff,12,origin,format); //ABCDEFGHIJKLMNOPQRSTUVWXYZ

        StringBuilder sb = new StringBuilder();
        sb.AppendLine("DECLARE @g geometry;");
        sb.Append("SET @g = geometry::STGeomFromText('POLYGON ((");


        Matrix flipmatrix = new Matrix(-1,1,0);
        gp.Transform(flipmatrix);
        Matrix rotationtransform = new Matrix();

        RectangleF r = gp.GetBounds();

        // Get center point
        PointF rotationPoint = new PointF(r.Left + (r.Width / 2),r.Top + (r.Height / 2));
        rotationtransform.RotateAt(180,rotationPoint);
        gp.Transform(rotationtransform);
        //gp.CloseAllfigures(); //make sure the polygon is closed - does not work

        foreach (PointF pt in gp.PathData.Points)
        {
            sb.AppendFormat("{0} {1},",pt.X,pt.Y);

        }
        PointF firstpoint = gp.PathData.Points[0];

        sb.AppendFormat("{0} {1}",firstpoint.X,firstpoint.Y); //make last point same as first
        sb.Append("))',0);");
        sb.AppendLine("");
        sb.AppendLine("SELECT @g");
        System.Diagnostics.Debug.WriteLine(sb.ToString());

Solution

For windows, you can use gdiplus Create a GraphicsPath and call addstring () on it

Then check the pathdata or pathpoints

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>