如何定制字体大小(100分)

  • 主题发起人 主题发起人 tmnet
  • 开始时间 开始时间
T

tmnet

Unregistered / Unconfirmed
GUEST, unregistred user!
最近,我在练习文本的绘制(使用API)但是在练习中间碰到了一个问题:<br><br>&nbsp; 1、填充logfont结构。其中的lfwidth为100,lfheight为100。<br>&nbsp; 2、我创建一种字体比如使用createfontindriect函数<br>&nbsp; 3、使用textout函数绘制文本。<br><br>现在,问题就产生了,有些字体比如:“黑体”、“宋体”等可以按照我所要求的大小来绘制。但是<br>有些字体如:“行楷”、“彩云体”等却无法得到正确的大小。不知道这是什么缘故。哪位大侠<br>如果知道,请一定要告诉我。我在这里多谢了!
 
procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; TheFnt :TFont;<br>&nbsp; LogFnt :TLogFont;<br>begin<br>&nbsp; with Canvas do<br>&nbsp; begin<br>&nbsp; &nbsp; TheFnt :=TFont.Create;<br>&nbsp; &nbsp; TheFnt.Assign(Font);<br>&nbsp; &nbsp; GetObject(TheFnt.Handle,SizeOf(LogFnt),@LogFnt);<br>&nbsp; &nbsp; LogFnt.lfHeight :=100;<br>&nbsp; &nbsp; LogFnt.lfWidth :=100;<br>&nbsp; &nbsp; TheFnt.Handle:=CreateFontIndirect(LogFnt);<br>&nbsp; &nbsp; TheFnt.Name :='华文行楷';<br>&nbsp; &nbsp; Font.Assign(TheFnt);<br>&nbsp; &nbsp; TheFnt.Free;<br>&nbsp; &nbsp; TextOut(100,100,'卷起千堆雪');<br>&nbsp; end;<br>end;<br><br>OK!
 
朋友,真的有这么简单吗?我已经去试验了一下,但是事实告诉我你的方案没有通过。<br>具体是这样的。我稍微做了一点点修改。关键就是你的代码不支持我所修改的特性。<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; TheFnt :TFont;<br>&nbsp; LogFnt :TLogFont;<br>begin<br>&nbsp; with Canvas do<br>&nbsp; begin<br>&nbsp; &nbsp; TheFnt :=TFont.Create;<br>&nbsp; &nbsp; TheFnt.Assign(paintbox1.canvas.Font);<br>&nbsp; &nbsp; GetObject(TheFnt.Handle,SizeOf(LogFnt),@LogFnt);<br>&nbsp; &nbsp; LogFnt.lfHeight :=270;<br>&nbsp; &nbsp; LogFnt.lfWidth :=80;<br>&nbsp; &nbsp; TheFnt.Handle:=CreateFontIndirect(LogFnt);<br>&nbsp; &nbsp; TheFnt.Name :='华文行楷';<br>&nbsp; &nbsp; paintbox1.canvas.Font.Assign(TheFnt);<br>&nbsp; &nbsp; TheFnt.Free;<br>&nbsp; &nbsp; paintbox1.canvas.TextOut(0,0,'卷起千堆雪');<br>&nbsp; end;<br>end;<br>按照程序的逻辑,应该在paintbox1的坐标0,0处绘制出高度是270点和宽度是80点的文字,<br>但遗憾的是,事实并不是这样的。它所绘制的文字是正方形的就是270x270。根本不是我所要<br>绘制的文字。<br><br>虽然没有解决问题,我还是非常高兴能看到有人肯回答我的问题。我不会少你的分数的。<br>
 
呵呵,现在好了;一不小心,放错位置了。<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; TheFnt :TFont;<br>&nbsp; LogFnt :TLogFont;<br>begin<br>&nbsp; with Canvas do<br>&nbsp; begin<br>&nbsp; &nbsp; TheFnt :=TFont.Create;<br>&nbsp; &nbsp; TheFnt.Assign(paintbox1.canvas.Font);<br>&nbsp; &nbsp; TheFnt.Name :='华文行楷';<br>&nbsp; &nbsp; GetObject(TheFnt.Handle,SizeOf(LogFnt),@LogFnt);<br>&nbsp; &nbsp; LogFnt.lfHeight :=270;<br>&nbsp; &nbsp; LogFnt.lfWidth :=11;<br>&nbsp; &nbsp; TheFnt.Handle:=CreateFontIndirect(LogFnt);<br>&nbsp; &nbsp; paintbox1.canvas.Font.Assign(TheFnt);<br>&nbsp; &nbsp; TheFnt.Free;<br>&nbsp; &nbsp; paintbox1.canvas.TextOut(0,0,'卷起千堆雪');<br>&nbsp; end;<br>end;
 
“卷起千堆雪”大哥,真是难为你这么热心的帮助我,看到您的代码,我立即去试验了一下,<br>可惜,还是有问题,问题是这样的:<br>&nbsp; &nbsp; 照推断,当我选字体为“华文行楷”和“黑体”时,所绘制的文字应该时一样大小的。但是很可惜,<br>我在DELPHI中实验时,却发现,两种字体绘制的文字大小完全不相同。我也不知道时什么原因。<br>&nbsp; &nbsp; 您能再帮我找以下原因吗?我在这里万分的感谢了!
 
接受答案了.
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
916
SUNSTONE的Delphi笔记
S
后退
顶部