简体   繁体   English

使用gulp-iconfont生成的CSS不能正确显示字体符号

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

So, I'm using gulp-iconfont to generate icon font from svg icons. 因此,我正在使用gulp-iconfont从svg图标生成图标字体。 I've set up task in a next way: 我已经以另一种方式设置了任务:

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) gives me something like: console.log(codepoints)给我类似的东西:

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

I'm using this codepoints in my css to generate something like: 我在CSS中使用此代码点来生成类似以下内容的代码:

.md-notifications {
  content: "\57345";
}

And it doesn't work, there is an empty space instead of my icon. 而且它不起作用,有一个空白而不是我的图标。 But if I use the codepoint that I get directly from generated svg font it works: 但是,如果我使用直接从生成的svg字体获取的代码点,它将起作用:

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

What am I doing wrong? 我究竟做错了什么?

In JavaScript, when you have a backslash followed by digits, you are creating an octal escape sequence . 在JavaScript中,当反斜杠后跟数字时,您将创建一个八进制转义序列 The number after the slash needs to be in base 8 (octal). 斜线后的数字必须以8为底(八进制)。

The codepoint 57345 should be given as "\\160001". 代码点57345应指定为“ \\ 160001”。

You can also do hex escape sequence by using the "\\u\u0026quot; prefix. 您也可以使用“ \\ u”前缀进行十六进制转义序列。 So 57345 can also be given as "\". 因此57345也可以指定为“ \\ uE001”。

The second one you claim is working "\\E001" is not right. 您声称正在工作的第二个“ \\ E001”不正确。 And won't be doing what you think it does. 而且不会按照您的想法去做。 It should just be producing the string "E001". 它应该只产生字符串“ E001”。

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

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