0

所以,我使用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: "\57345";
}

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

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

我究竟做错了什么?

4

1 回答 1

2

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

代码点 57345 应为“\160001”。

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

您声称正在工作的第二个“\E001”是不正确的。并且不会做你认为的那样。它应该只是产生字符串“E001”。

于 2015-05-31T22:52:28.317 回答