Firemonkey:将资源添加到内存并使用它 [英] Firemonkey: Adding a font from resource to memory and using it

查看:293
本文介绍了Firemonkey:将资源添加到内存并使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VCL 中,我可以从资源加载字体,而不保存它可以从内存中使用它。



这是我使用的代码,它在 VCL 中有效:

  procedure TForm1.Button1Click(Sender:TObject); 
var
ResStream:tResourceStream;
FontsCount:DWORD;
begin
ResStream:= tResourceStream.Create(hInstance,'MyResourceName',RT_RCDATA);
winapi.windows.AddFontMemResourceEx(ResStream.Memory,ResStream.Size,nil,@FontsCount);
ResStream.Free();
button1.Font.name:='MySavedFontNameInResource';
结束

在Firemonkey中,我刚刚更改了 button1.Font.name button1.Font.family 但不幸的是,字体没有改变。所以我认为这个代码与firemonkey不兼容。



所以在Firemonkey中,我如何从资源中加载一个字体并将其临时保存到内存并直接从那里使用?



更新:



我看到这些页面:在firemonkey中安装字体如何使用外部字体?



根据 Mr Ed 的回答,似乎FMX中没有解决这个问题的办法。但是,如果我们在运行应用程序之前安装它,也许我们可以加载该字体。我尝试了几乎所有的东西,但我仍然无法加载字体。

解决方案

这可能或可能不会有帮助。 >

免责声明



这需要额外的研究,我还没有到,但是相信这是一个很好的起点。



MSDN页面的链接: - 自定义字体集合



您需要使用WinAPI.D2D1单元(您也可能需要FMX.TextLayout和FMX.Canvas.D2D)才能访问DirectWrite API。您可以使用它来获取DirectWrite工厂,这将允许您从磁盘定义和加载字体。



一旦您的字体加载了AFAIK,它应该可用到整个应用程序,并希望所有的firemonkey控件。完全可能的是,firemonkey只是在应用程序加载时枚举字体,所以这可能都是无效的。



正如我所说,这需要我还没有研究,所以只有在你也定制画你的控制(我将是)和可能因此不合适。


In VCL, I could load a font from resource and without saving it I could use it from memory.

Here is the code I use and it works in VCL:

procedure TForm1.Button1Click(Sender: TObject);
var
   ResStream  : tResourceStream;
   FontsCount : DWORD;
begin
   ResStream  := tResourceStream.Create(hInstance, 'MyResourceName', RT_RCDATA);
   winapi.windows.AddFontMemResourceEx(ResStream.Memory, ResStream.Size, nil, @FontsCount);
   ResStream.Free();
   button1.Font.name := 'MySavedFontNameInResource';
end;

In Firemonkey I just changed button1.Font.name to button1.Font.family but unfortunately the font didn't change. So I think this code is not compatible with firemonkey.

So in Firemonkey, how can I load a font from resource and save it temporary to memory and use it directly from there?

Update:

I saw these pages: Install font in firemonkey, How to use external fonts?

According to Mr Ed 's answer, it seems that there is no solution for this problem in FMX. But maybe we could load the font if we install it before running the app. I tried almost everything but I still can't load the the font.

解决方案

This may or may not help.

Disclaimer

This requires extra researching that I have not gotten around to yet, but I believe this to be a good starting point.

Link for the MSDN page :- Custom Font Collections

You need to use the WinAPI.D2D1 unit (you may need FMX.TextLayout and FMX.Canvas.D2D as well) to gain access to the DirectWrite API. You can use this to get at the DirectWrite factories which will allow you to define and load a font from disk.

Once you have the font loaded AFAIK it should then be available to the entire application and hopefully all of the firemonkey controls. Its entirely possible that firemonkey only enumerates fonts at application load though, so this may all be for naught.

As I said, this requires research that I have not gotten to yet, so may only work if you are also custom painting your control (which I will be) and might not be suitable as a result.

这篇关于Firemonkey:将资源添加到内存并使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆