Windows 字体在安装后不能立即在应用程序中使用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2964117/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:34:55  来源:igfitidea点击:

Windows fonts not immediately useable in application after installing?

asp.netwindowsfontsgdi

提问by Carvellis

Whenever I install a new font on a Windows 2003 server, I can't use it immediately in my asp.net web application. The application gets the font through the CreateFontIndirectgdi32.dll win api, and then use this font to create a dynamic text image in my asp.net application. It seems like fonts get cached somewhere, because I will just get the default font returned.

每当我在 Windows 2003 服务器上安装新字体时,我无法立即在我的 asp.net Web 应用程序中使用它。应用程序通过CreateFontIndirectgdi32.dll win api获取字体,然后在我的asp.net应用程序中使用该字体创建动态文本图像。似乎字体被缓存在某处,因为我只会返回默认字体。

The font cache gets updated after a reboot, and then I get the correct font, but obviously I wouldn't like to do a reboot on a production server just for getting a new font to work.

重新启动后字体缓存会更新,然后我得到正确的字体,但显然我不想在生产服务器上重新启动只是为了让新字体工作。

Is there a way to flush the font cache?

有没有办法刷新字体缓存?

回答by Dean Harding

By default, when you install a new font, only the current sessionis notified of the change. So if you're logging into the server in a terminal services session (which seems likely) then the ASP.NET application (which will be running in a different session) will not see the change.

默认情况下,当您安装新字体时,只有当前会话会收到更改通知。因此,如果您在终端服务会话中登录服务器(这似乎很可能),那么 ASP.NET 应用程序(将在不同的会话中运行)将看不到更改。

When you reboot, the system automatically scans the font directory and "registers" all of the fonts in there into the current session.

当您重新启动时,系统会自动扫描字体目录并将其中的所有字体“注册”到当前会话中。

To "manually" register a new font, you will need to call AddFontResourceand pass in the path to the font.

要“手动”注册新字体,您需要调用AddFontResource并传入字体的路径。

To make it slightly easier, you could make it so that your app scans the Fonts folder and calls AddFontResourceon each file it finds there in it's Application_Startevent. That way, when you install a new font, you can just recycle the site (e.g. edit the web.config file) and it'll re-scan all of the files.

为了让它更容易一些,你可以让你的应用程序扫描 Fonts 文件夹并调用AddFontResource它在它的Application_Start事件中找到的每个文件。这样,当您安装新字体时,您只需回收该站点(例如编辑 web.config 文件),它就会重新扫描所有文件。

Another option would be to put a directory watch (via FileSystemWatcher) on the Fonts folder and automatically re-scan it.

另一种选择是在 Fonts 文件夹上放置一个目录监视(通过FileSystemWatcher)并自动重新扫描它。

I guess it just depends how often you'll be installing new fonts...

我想这取决于您安装新字体的频率......

回答by user1923248

Restart IIS. that should do the trick. rub iisreset from command line or use IIS manager.

重新启动 IIS。这应该够了吧。从命令行 rub iisreset 或使用 IIS 管理器。

回答by Mahdi Jannati

I recycle the application pool that use the fonts and it fixed.

我回收了使用字体的应用程序池并修复了它。