字体的简单问题(200分)

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

Tomorrows

Unregistered / Unconfirmed
GUEST, unregistred user!
怎么通过字体文件名取得字体名称?<br>字体文件在某一个目录中(不是系统的默认字体目录),我知道字体文件名,我怎么才能取得字体名称(就是font.name,比如宋体、黑体这样的)<br>谢谢!
 
最好把文件名改成字体名就行了
 
这有这种方法了吗?<br>那工作量可大了。<br>谢谢你
 
AddFontResource(fontfilename);<br>增加字体<br>&nbsp;RemoveFontResource();<br>移除字体<br>WM_FONTCHANGE 通知其他窗口<br>增加前保存Screen.fonts的内容<br>增加后screen.fonts中多出来的那个字体就是你要找的,<br>办法笨点,但是可行
 
学习啊,呵呵
 
给你一个函数,你试试:<br>function GetFontNameFromFotFile(const ttf: string): string;<br>var<br>&nbsp; FHd: integer;<br>&nbsp; FotFile: string;<br>&nbsp; FontName: string;<br>&nbsp; ch:char;<br>begin<br>&nbsp; FontName:='';<br>&nbsp; try<br>&nbsp; &nbsp; FotFile := ChangeFileExt(ttf, '.fot');<br>&nbsp; &nbsp; CreateScalableFontResource(0, PChar(FotFile), PChar(ttf), nil);<br>&nbsp; &nbsp; if fileexists(FotFile) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp;try<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FHd := FileOpen(FotFile,fmShareExclusive OR fmOpenRead);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if FHd &gt;0<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if FileSeek(FHd, 1270, 0)=-1<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;then ShowMessage('Error: FileSeek operation with file'+FotFile)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FileRead(FHd,ch,1);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while ch&lt;&gt;#0 do begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FileRead(FHd,ch,1);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FileRead(FHd,ch,1);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while ch&lt;&gt;#0 do begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FontName:=FontName+ch;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FileRead(FHd,ch,1);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ShowMessage('Error: File '+FotFile+' not opened');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp;finally<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if FHd&gt;0 then FileClose(FHd);<br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; end<br>&nbsp; &nbsp; else showmessage('FOT-file not created');<br>&nbsp; finally<br>&nbsp; &nbsp; if FileExists(FotFile) then DeleteFile(FotFile);<br>&nbsp; end;<br>&nbsp; Result := FontName;<br>end;<br>
 
多人接受答案了。
 
后退
顶部