如何 调用 字体文件变成资源文件 ?

amnoone 2011-04-09 07:03:37
如何字体文件变成资源文件, 调用它,这样即便系统里面没有该字体,也能在程序中显示。



请各位帮帮忙!
...全文
218 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
amnoone 2011-04-12
  • 打赏
  • 举报
回复
Ali 啊

字体可以改变了,可是退出后字体文件没有被删除掉,望您赐教啊!

procedure TForm1.FormDestroy(Sender: TObject; var Action: TCloseAction) ;
中 var Action: TCloseAction 部分 通不过 。
amnoone 2011-04-12
  • 打赏
  • 举报
回复
mwy654321

o 这样啊,下次我随便问个问题看到你就算一个字的回复,就给你很高的分,希望你不要食言呦。我不会的。
无条件为你 2011-04-12
  • 打赏
  • 举报
回复
楼主给这点分真够吝啬的,本来想给你写出完整好用的代码的心情全没了。
amnoone 2011-04-12
  • 打赏
  • 举报
回复
thank you very much !

I think the name of the font is so long, it is not the font name.

but, it is.

thanks!
Ali 2011-04-11
  • 打赏
  • 举报
回复
It is working :). Please change the font of label1 at design time to something different like "Arial". Run the application and you will see font is changed to Trana.ttf font (Transponder AOE).

You will have to write the actual Font name instead of providing the ttf file name.


Label1.Font.Size:=24;
Label1.Font.Name:='Transponder AOE';


amnoone 2011-04-11
  • 打赏
  • 举报
回复
Ali 啊

procedure TForm1.FormDestroy(Sender: TObject; var Action: TCloseAction) ;
中 var Action: TCloseAction 部分 通不过 。屏蔽后 字体没有变化啊

http://ishare.iask.sina.com.cn/f/14569194.html?w=' target='_blank'>字体资源.rar

我把工程文件传到网上了。 是 D7的
amnoone 2011-04-10
  • 打赏
  • 举报
回复

三块肉!


对你的国际主义精神表示感谢!哈哈!
Ali 2011-04-09
  • 打赏
  • 举报
回复
Correction:

Remember Font's can be SHOULD be read as Font's CAN'T be
Ali 2011-04-09
  • 打赏
  • 举报
回复
1. Create RC file (e.g MY.RC)
MYFONT RCDATA "FONT_FILE_NAME"
2. Compile RC file using BRCC32 MY.RC
3. Add compiler directive {$R MY.RES}
4. Use below code in OnCreate and OnDestroy events


procedure TForm1.FormCreate(Sender: TObject);
var
res: TResourceStream;
begin
res := TResourceStream.Create(hInstance, 'MYFONT', RT_RCDATA);
try
res.SavetoFile('myfont.ttf');
finally
res.Free;
end;
AddFontResource(PChar('myfont.ttf'));
SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0);
//Now you use your own font
Label1.Font.Size:=24;
Label1.Font.Name:='myfont';
end;

//We don't want this font to be available after our application is closed

procedure TForm1.FormDestroy(Sender: TObject; var Action: TCloseAction) ;
begin
RemoveFontResource('PATH_TO_MyFont.TTF') ;
SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) ;
end;




Remeber Font's can be directly used from memory. We have to save them to file and call AddFontResource API function. The AddFontResource function adds the font resource from the specified file to the system font table. We need to fake this font adding and we should broadcast WM_FONTCHANGE message.When we don't need this font we must call RemoveFontResource function to remove this resource.

Hope it helps

Thanks,

Ali

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi GAME,图形处理/多媒体
社区管理员
  • GAME,图形处理/多媒体社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧