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

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

在一些工作站升级到 windows 10 和 IE11 的组合之后,我已经使用了 5 年的 java 网络应用程序 运行 出现了字体问题。从微软的角度here详细描述了这个问题。有几个资源描述了如何关闭这些设置,但我想知道是否有任何跨浏览器解决方案可以继续使用特定字体,并阻止网络字体。

微软的建议是这两个:

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. If it doesn’t, you’ll need to manually copy the font files into the Fonts directory and run the installation from there.

这是指桌面应用程序,无法通过网络应用程序完成。无论如何,这都不是一个令人满意的解决方案,因为它需要每个用户的主动设置操作。

On each computer with the app installed, open regedit.exe...

我什至不打算包括其余部分,因为它与上一个解决方案建议存在相同的问题。

我试过的:

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

无效。参考中的 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;
}

相同字体导入不同格式,支持不同浏览器。 我曾希望我可以继续使用 font awesome,只需下载资源并将它们打包到我的 .war 文件中即可。但是我使用这种方法的另一种字体也不起作用:

来自我的习惯-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;
}

但即使是我的应用程序中的打包字体,也不会加载或显示。

有没有什么方法可以在 java 网络应用程序中使用自定义字体,而不包括关闭安全设置或必须将设置(如安装字体)应用到每个用户的计算机?

旁注:在任何 windows 版本的 chrome 中,以及在非 windows10 台计算机上的 IE11 中,一切仍然有效。

如果在安全设置中禁用了 webfonts,则没有真正的解决方法。如果有的话,它可能是一个令人讨厌的黑客攻击,因为您会故意规避 Windows 安全设置。

然后是 B 计划的时间。我 wrote about this specific issue,简而言之,您必须使用漂亮的系统字体作为文本的后备,并使用基于图像的系统作为图标。例如。使用 PNG 或 SVG 图像。但是,如果您要走那条路,您不妨将图标字体替换为适用于 所有 浏览器的适当图标。

祝你好运,顺便问一下写得很好的问题。