为什么 Material 图标在 phantom js 中不呈现?

Why don't Material Icons render in phantom js?

最近我正在用 phantom js 做一些实验来截取 html 代码的屏幕截图,但是我遇到了 materialize 图标字体的错误。

我做了一个这样的演示html

<!DOCTYPE html>
<html lang='en'>
  <head>
    <title>Demo</title>
    <link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet'>
    <link href='https://fonts.googleapis.com/icon?family=Material+Icons' rel='stylesheet'> 
    <style>
         html {
            font-family: 'Roboto', sans-serif;
         }
    </style>
  </head>
  <body>
      Hello this is using roboto
      <i class='material-icons'>favorite_border</i>
  </body>
</html>

Roboto 运行良好,但 material 图标不起作用。下图是我得到的结果:

这应该是我得到的:

我认为这是因为 material 图标使用

-webkit-font-feature-settings: 'liga'

而且 phantomjs 不支持它,我说的对吗?。很棒的字体效果很好。 有什么线索吗?

我在 ubuntu 服务器 16.04 lts 中运行它,而 phantom js 是 2.1.1 感谢您的帮助

你的例子没问题!!!

<!DOCTYPE html>
<html lang='en'>
  <head>
    <title>Demo</title>
    <link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet'>
    <link href='https://fonts.googleapis.com/icon?family=Material+Icons' rel='stylesheet'> 
    <style>
         html {
            font-family: 'Roboto', sans-serif;
         }
    </style>
  </head>
  <body>
      Hello this is using roboto
      <i class='material-icons'>favorite_border</i>
  </body>
</html>

这似乎已在最新的 phantomjs beta 2.5 版本中得到修复,请参阅 https://github.com/ariya/phantomjs/issues/14885

另一种解决方案是自行托管 Web 前端。如果您从自己的服务器提供字体,phantomjs 渲染它没有问题。