1

我正在使用 DrawString 在 GDI+ GraphicsPath 中创建文本,然后将其作为路径输出到 PDF。

目前这一切都运行良好。

我遇到问题的时间是所选字体导致轮廓相互重叠。我有一个图像示例,虽然是一个新用户,但我无法上传它......(似乎毫无意义......?......)

我找到了一个图书馆,也找到了一个与我在这个博客中寻找的相同的人

尽管我不断从库中获得一个空的解决方案,但我已将代码片段转换为 vb.net。

有没有其他人设法传入一个包含字符串的 graphicsPath 并使用这个或类似的库检索概述的文本?

4

1 回答 1

1

这是一些有效的 C# 代码...

    using ClipperLib;

    static public void PathToPolygon(GraphicsPath path, Polygons polys, Single scale)
    {
        GraphicsPathIterator pathIterator = new GraphicsPathIterator(path);
        pathIterator.Rewind();
        polys.Clear();
        PointF[] points = new PointF[pathIterator.Count];
        byte[] types = new byte[pathIterator.Count];
        pathIterator.Enumerate(ref points, ref types);
        int i = 0;
        while (i < pathIterator.Count)
        {
            Polygon pg = new Polygon();
            polys.Add(pg);
            do {

                IntPoint pt = new IntPoint((int)(points[i].X * scale), (int)(points[i].Y * scale));
                    pg.Add(pt);
                i++;
            }
            while (i < pathIterator.Count && types[i] != 0);
        }
    }


    static private PointF[] PolygonToPointFArray(Polygon pg, float scale)
    {
        PointF[] result = new PointF[pg.Count];
        for (int i = 0; i < pg.Count; ++i)
        {
            result[i].X = (float)pg[i].X / scale;
            result[i].Y = (float)pg[i].Y / scale;
        }
        return result;
    }


    private void DrawBitmap()
    {
        Font f = new Font("Arial", 90);
        Pen myPen = new Pen(Color.FromArgb(196, 0xC3, 0xC9, 0xCF), (float)0.6);
        SolidBrush myBrush = new SolidBrush(Color.FromArgb(127, 0xDD, 0xDD, 0xF0));
        path.Reset();
        Polygons polys;
        path.AddString("ABC", f.FontFamily, (int)f.Style, f.Size, new Point(100, 100), null);
        path.Flatten();
        //scale all points up by 100 because Clipper uses integer coordinates
        PathToPolygon(path, polys, 100);
        path.Reset();
        //offset polys remembering to multiply delta by scaling amount ...
        polys = Clipper.OffsetPolygons(polys, 7 * 100, JoinType.jtRound);
        for (int i = 0; i < polys.Count(); i++)
        {
            //reverses scaling ...
            PointF[] pts2 = PolygonToPointFArray(polys[i], 100);
            path.AddPolygon(pts2);
        }
        newgraphic.FillPath(myBrush, path);
        newgraphic.DrawPath(myPen, path);
    }

在此处输入图像描述

于 2012-09-19T01:58:35.233 回答