如何显示ttf字体的轮廓?(200分)

  • 主题发起人 主题发起人 shxm
  • 开始时间 开始时间
S

shxm

Unregistered / Unconfirmed
GUEST, unregistred user!
我想显示某一汉字的ttf字体(如楷体)的笔画轮廓,苦于不知有关字体的详细说明,更无法编程实现.有哪位高手能指点?最好能有读取并显示字体笔画的程序源码.
 
你的问题就是空心字体的意思~~~<br>另外你说的读取、显示就是存为位图文件进行操作.<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; bmp:tbitmap;<br>begin<br>&nbsp; bmp:=tbitmap.Create;<br>&nbsp; with bmp do<br>&nbsp; begin<br>&nbsp; &nbsp; Width:=image1.Width;<br>&nbsp; &nbsp; Height:=image1.Height;<br>&nbsp; &nbsp; Canvas.Font.Name:='楷体';<br>&nbsp; &nbsp; Canvas.Font.Size:=30;<br>&nbsp; &nbsp; setbkmode(bmp.canvas.handle,0);<br>&nbsp; &nbsp; TransparentColor:=clWhite;<br>&nbsp; &nbsp; Canvas.Font.Color:=clred;<br>&nbsp; &nbsp; canvas.TextOut(9,10,'卷起千堆雪');<br>&nbsp; &nbsp; canvas.TextOut(10,9,'卷起千堆雪');<br>&nbsp; &nbsp; canvas.TextOut(10,11,'卷起千堆雪');<br>&nbsp; &nbsp; canvas.TextOut(11,10,'卷起千堆雪');<br>&nbsp; &nbsp; canvas.Font.Color:=clwhite;<br>&nbsp; &nbsp; canvas.TextOut(10,10,'卷起千堆雪');<br>&nbsp; &nbsp; image1.Canvas.Draw(0,0,bmp);<br>&nbsp; &nbsp; image1.Transparent:=true;<br>&nbsp; &nbsp; free;<br>&nbsp; end;<br>end;
 
感谢您的帮助,但我想要显示的是一个字每一笔画的空心轮廓,而不是整个字的轮廓,尽管显示笔画轮廓可能看起来有点乱。您(或者有谁)[:)]能解决吗?
 
第二位兄弟的做法似乎有电偷懒啊<br>shexm, 你知不知道path, region, 完全可以用这个实现的.<br>首先你用textout书写文字创建path, 然后用这个path生成一个region<br>然后用FrameRgn就可以绘制轮廓了
 
你试一下下面的代码,<br>说明一下, 有一个TImage控件, 名称试image1<br>有一个fontdialog控件,名称是FontDialog1,它的font必须设置为一个矢量字体!!!<br>
代码:
<br>procedure TForm1.BitBtn1Click(Sender: TObject);<br>var<br>&nbsp; dc : HDC;<br>&nbsp; bakClrPen, bakClrBrush : TColor;<br>&nbsp; rgn : HRGN;<br>begin<br>&nbsp; Image1.Canvas.Font := fontdialog1.Font;<br><br>&nbsp; dc := Image1.Canvas.Handle;<br><br>&nbsp; BeginPath(dc);<br><br>&nbsp; &nbsp; Image1.Canvas.TextOut(0, 0, '中国');<br>&nbsp; &nbsp; CloseFigure(dc);<br><br>&nbsp; EndPath(dc);<br><br>&nbsp; // SelectClipPath(dc, RGN_COPY);<br><br>&nbsp; bakClrPen := Image1.Canvas.Brush.Color;<br>&nbsp; bakClrBrush := Image1.Canvas.Pen.Color;<br>&nbsp; Image1.Canvas.Brush.Color := clRed;<br>&nbsp; Image1.Canvas.pen.Color := clBlue;<br><br>&nbsp; rgn := PathToRegion(dc);<br><br>&nbsp; if rgn&lt;&gt;0 then<br>&nbsp; &nbsp; FrameRgn(dc, rgn, Image1.Canvas.Brush.Handle, 1, 1);<br><br>&nbsp; Image1.Canvas.Brush.Color := bakClrBrush;<br>&nbsp; Image1.Canvas.Pen.Color := bakClrPen;<br><br>&nbsp; DeleteObject(rgn);<br>end;<br>
 
代码:
procedure TForm1.BitBtn1Click(Sender: TObject);<br>var<br>&nbsp; dc : HDC;<br>&nbsp; bakClrPen, bakClrBrush : TColor;<br>&nbsp; tmpRgn : HRGN;<br>&nbsp; rgn : HRGN;<br>&nbsp; rgnRect : TRect;<br>begin<br>&nbsp; Image1.Canvas.Font := fontdialog1.Font;<br><br>&nbsp; dc := Image1.Canvas.Handle;<br><br>&nbsp; BeginPath(dc);<br><br>&nbsp; &nbsp; Image1.Canvas.TextOut(0, 0, '中国');<br>&nbsp; &nbsp; CloseFigure(dc);<br><br>&nbsp; EndPath(dc);<br><br>&nbsp; bakClrPen := Image1.Canvas.Brush.Color;<br>&nbsp; bakClrBrush := Image1.Canvas.Pen.Color;<br>&nbsp; Image1.Canvas.Brush.Color := clRed;<br>&nbsp; Image1.Canvas.pen.Color := clBlue;<br><br>&nbsp; rgn := PathToRegion(dc);<br>&nbsp; GetRgnBox(rgn, rgnRect);<br>&nbsp; tmpRgn := CreateRectRgn(rgnRect.left, rgnRect.top, rgnRect.Right, rgnRect.Bottom);<br>&nbsp; CombineRgn(rgn, tmpRgn, rgn, RGN_DIFF);<br><br>&nbsp; if rgn&lt;&gt;0 then<br>&nbsp; &nbsp; FrameRgn(dc, rgn, Image1.Canvas.Brush.Handle, 1, 1);<br><br>&nbsp; Image1.Canvas.Brush.Color := bakClrBrush;<br>&nbsp; Image1.Canvas.Pen.Color := bakClrPen;<br>&nbsp; SelectClipRgn(dc, 0);<br><br>&nbsp; DeleteObject(rgn);<br>&nbsp; DeleteObject(tmpRgn);<br>end;
 
你从path中能获得字体的信息,<br>包括点, 该点的类型等等,具体请看msdn
 
很好很好!这个问题无意中帮我解决了另一个问题! 字体轮廓好东西!^_^
 
YB_unique, 给你解决了什么问题, ^_^
 
多人接受答案了。
 
huiyugan,我对这方面不熟,能否多介绍些path方面的情况?<br>msdn我没看过,是E文的吧?我以前怕看,现在有兴趣了,到哪里找?谢谢.
 
GetPath<br>The GetPath function retrieves the coordinates defining the endpoints of lines and the control points of curves found in the path that is selected into the specified device context. <br><br>int GetPath(<br>&nbsp; HDC hdc, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // handle to DC<br>&nbsp; LPPOINT lpPoints, &nbsp;// path vertices<br>&nbsp; LPBYTE lpTypes, &nbsp; &nbsp;// array of path vertex types<br>&nbsp; int nSize &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// count of points defining path<br>);<br>当你使用BeginPath时, 你的当前DC上的path就被抛弃了<br>然后你在上面的绘图操作就形成path,当使用endpath时<br><br>msdn是开发windows程序的必备参考资料, 是微软的帮助文档,<br>你可以在卖光盘的地方找到.<br>里面有非常丰富的文档<br>
 
to huiyugan:<br>按你的方法能显示空心笔画,但还有一点问题能否解决?<br>当两个笔画交叉时(例如横和竖)如果部分轮廓正好重叠,则重叠部分不能显示,能否让重叠部分也显示?<br>另外,能否显示一个字中某一部分笔画轮廓?
 
to shxm。<br>这与字体信息有关系。<br>在矢量字体里面并不是记录横竖这样的信息,它记录的是字体的轮廓信息。也许你可以<br>找到一种字体能够满足你的要求。
 
后退
顶部