从 gulp-iconfont 生成的 css 无法正确显示字体符号

Font symbols don't display correctly with css generated from gulp-iconfont

所以,我正在使用 gulp-iconfont 从 svg 图标生成图标字体。我用下一种方式设置了任务:

gulp.task('iconfont', function(){
  gulp.src(['src/assets/icons/*.svg'])
    .pipe($.iconfont({
      fontName: 'material',
      normalize: true
    }))
    .on('codepoints', function(codepoints) {
      console.log(codepoints);
      gulp.src('src/templates/material.styl')
        .pipe($.consolidate('mustache', {
          glyphs: codepoints,
          fontName: 'material',
          fontPath: '../fonts/',
          className: 'md'
        }))
        .pipe(gulp.dest('src/styles/plugins'));
    })
    .pipe(gulp.dest('build/fonts/'));
});

console.log(codepoints) 给我这样的东西:

[ { name: 'notifications', codepoint: 57345 },
  { name: 'offline', codepoint: 57346 },
  { name: 'online', codepoint: 57347 },
...
]

我在我的 css 中使用这个代码点来生成如下内容:

.md-notifications {
  content: "345";
}

它不起作用,有一个空的 space 而不是我的图标。但是,如果我使用直接从生成的 svg 字体中获取的代码点,它就可以工作:

.md-notifications {
  content: "\E001"
}

我做错了什么?

在 JavaScript 中,当反斜杠后跟数字时,您正在创建一个 八进制转义序列。斜杠后的数字需要以 8 为底(八进制)。

代码点 57345 应指定为“\160001”。

您也可以使用“\u”前缀来进行十六进制转义序列。所以 57345 也可以写成 "\uE001".

您声称的第二个正在运行的“\E001”不正确。并且不会按照您的想法去做。它应该只生成字符串 "E001".