2012-09-18 29 views
1

我使用DrawString在GDI + GraphicsPath中創建文本,然後將其輸出爲PDF作爲路徑。使用Angus J Clipper庫在vb.net中繪製GraphicsPath文本

這一切都在完美的工作。

我遇到問題的時間是選定字體導致輪廓彼此重疊的時間。我有一個圖像的例子,雖然作爲一個新用戶,我不能上傳它...(似乎毫無意義..?)

我發現了一個library,也有人實現了與我正在尋找在這blog

我已經將代碼片段轉換爲vb.net,雖然我不斷從庫中得到一個空的解決方案。

是否有其他人設法傳入一個包含字符串的graphicsPath並使用這個或類似的庫檢索概要文本?

+0

我設法從博客使用ClipType.ctUnion,而不是最終使用的代碼。非常快的圖書館。 我在下面標記了答案,因爲該代碼也適用;只是博客中的一個更簡單,更符合我的需求。 – Darren

回答

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); 
    } 

enter image description here

+0

謝謝安格斯。 只是試圖轉換代碼,雖然有一點點touble ...任何想法如何在vb中做到這一點? using Polygon = List ; 再次感謝 – Darren

+0

對不起Darren,我從來沒有碰過VB。 –

+0

沒問題,無論如何感謝。 我設法轉換的代碼,但也得到了我的Q的代碼工作 - 也不得不使用ClipType.ctUnion。它工作得太快了!你做了一個很棒的圖書館:) – Darren