简体   繁体   English

2019年是否有跨浏览器方式将字体包含在Web应用程序中?

[英]Is there a cross browser way to include fonts in web applications in 2019?

My five year old java web application has run into problems with fonts, after some work stations has been upgraded to the combination of windows 10 and IE11. 在将某些工作站升级到Windows 10和IE11的组合之后,我拥有5年历史的Java Web应用程序遇到了字体问题。 The issue is described in detail from Microsofts perspective here . 这里从Microsoft的角度详细描述了该问题。 There are several resources describing how to turn off these settings, but I'd like to know if there are any cross browser solutions to keep using specific fonts, with web fonts blocked. 有几种资源描述了如何关闭这些设置,但是我想知道是否有任何跨浏览器解决方案可以继续使用特定字体,而阻止Web字体。

Microsofts suggestions are these two: 微软的建议是以下两个:

On each computer with the app installed, right-click on the font name and click Install. 在安装了应用程序的每台计算机上,右键单击字体名称,然后单击“安装”。 The font should automatically install into your %windir%/Fonts directory. 字体应自动安装到%windir%/Fonts目录中。 If it doesn't, you'll need to manually copy the font files into the Fonts directory and run the installation from there. 如果不是,则需要手动将字体文件复制到Fonts目录中,然后从那里运行安装。

This refers to a desktop application, and cannot be done with a web application. 这是指桌面应用程序,不能用Web应用程序完成。 It would not have been a satisfactory solution anyway, as it requires active setup action from every user. 无论如何,这都不是令人满意的解决方案,因为它需要每个用户积极地进行设置。

On each computer with the app installed, open regedit.exe... 在安装了应用程序的每台计算机上,打开regedit.exe ...

I'm not even going to include the rest, as it has the same problems as the last solution suggestion. 我什至不打算包括其余部分,因为它与上一个解决方案建议存在相同的问题。

What I have tried: 我尝试过的

<link href='http://netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-
    awesome.css' rel='stylesheet' type='text/css'>

Doesn't work. 不起作用 The css file in reference tries to load the font with the following lines: 参考中的css文件尝试使用以下行加载字体:

@font-face {
  font-family: 'FontAwesome';
  src: url('../fonts/fontawesome-webfont.eot?v=4.7.0');
  src: url('../fonts/fontawesome-webfont.eot?#iefix&v=4.7.0') format('embedded-opentype'), url('../fonts/fontawesome-webfont.woff2?v=4.7.0') format('woff2'), url('../fonts/fontawesome-webfont.woff?v=4.7.0') format('woff'), url('../fonts/fontawesome-webfont.ttf?v=4.7.0') format('truetype'), url('../fonts/fontawesome-webfont.svg?v=4.7.0#fontawesomeregular') format('svg');
  font-weight: normal;
  font-style: normal;
}

it imports the same font in different formats, to support different browsers. 它以不同的格式导入相同的字体,以支持不同的浏览器。 I had hoped that I could continue to use font awesome, simply by downloading the resources, and packing them inside my .war-file. 我希望我可以继续使用很棒的字体,只需下载资源并将其打包到我的.war文件中即可。 But another font I use this approach for, does not work either: 但是我使用这种方法的另一种字体也不起作用:

from my custom-fonts.css: 从我的custom-fonts.css中:

@font-face {
    font-family: 'Trim';
    src: url('../../resources/fonts/TrimCompleteOT/Trim-Bold.woff') format('woff'),
         url('../../resources/fonts/TrimCompleteOT/Trim-Bold.otf') format('opentype');
    font-weight: 700;
}

But even packaged fonts inside my application, will not load or display. 但是,即使我的应用程序内的打包字体也不会加载或显示。

Is there any way to use custom fonts in a java web application, that does not include turning off security settings, or having to apply settings (like install the fonts) to each individual users computer? 有什么方法可以在Java Web应用程序中使用自定义字体,但不包括关闭安全性设置,也不必将设置(如安装字体)应用于每个用户计算机?

Side note: everything still works in chrome on any windows version, and also in IE11 on non-windows10 computers. 旁注:在任何Windows版本上,一切仍然可以在chrome中使用,在非Windows10计算机上,也可以在IE11中使用。

If usage of webfonts is disabled in the security settings, there's no real way around them. 如果在安全设置中禁用了Web字体的使用,则没有真正的解决方法。 If there would be, it'd probably be a nasty hack as you'd deliberately circumvent Windows security settings. 如果有的话,因为您故意绕过Windows安全设置,可能是一个讨厌的黑客。

Time for Plan B, then. 那么,是时候制定计划B了。 I wrote about this specific issue , and in short you'd have to use nice looking system fonts as fallbacks for text, and an image-based system for icons. 写的是关于这个特定问题的 ,简而言之,您必须使用外观漂亮的系统字体作为文本的后备,而使用基于图像的系统作为图标。 Eg use PNG or SVG images. 例如,使用PNG或SVG图像。 But if you're going that route you might as well replace the icon font with proper icons for all browsers. 但是,如果您要沿这条路线前进,则最好为所有浏览器将图标字体替换为适当的图标。

Good luck, and kudos for the nicely written question by the way. 祝您好运,顺便提一句写得很好的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM