Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request - use pages as font weights #10

Open
eddywashere opened this issue Dec 29, 2014 · 1 comment
Open

Feature request - use pages as font weights #10

eddywashere opened this issue Dec 29, 2014 · 1 comment

Comments

@eddywashere
Copy link

It would be really awesome if multiple pages could be interpreted as font weights. This way, an optimized icon could be served for different sizes, ex: sm, md, lg.

Another example is in the iconic docs https://useiconic.com/guides/how-to-use-the-icon-font/

@cognitom
Copy link
Owner

Hi @eddywashere!

Seems nice, but the name of the glyph may conflict. sketchtool uses the layer name as the file name exported. This could be a problem when we specify the same name to the layer in each pages in Sketch.app.

Solution A

Use different suffix in each pages like sm md lg or w4 w6 w8. No change for the template is needed.

<i class="s s-home-sm"></i>
<i class="s s-home-md"></i>
<i class="s s-home-lg"></i>

Solution B

Make separated Sketch files for each font weights, like 'yourfont-w4.sketch', 'yourfont-w8.sketch'. Then define multiple @font-face sections with different font-weight in CSS.

var gulp = require("gulp");
var rename = require("gulp-rename");
var sketch = require("gulp-sketch");
var iconfont = require('gulp-iconfont');
var consolidate = require('gulp-consolidate');
var foreach = require('gulp-foreach');
var path = require('path');

var fontname = 'yourfont';
var css_created = false;

gulp.task('symbols', function(){
  gulp.src(fontname + '-w*.sketch') // ex. 'yourfont-w4.sketch', 'yourfont-w8.sketch'
    .pipe(foreach(function(stream, file){
      var fontname_w = path.basename(file.path); // ex. 'yourfont-w4' or 'yourfont-w8'
      return stream
        .pipe(sketch({
          export: 'artboards',
          formats: 'svg'
        }))
        .pipe(iconfont({ fontName: fontname_w }))
        .on('codepoints', function(codepoints) {
          if (css_created) {
            return; // CSS file should be created just once
          }
          var options = {
            glyphs: codepoints,
            fontName: fontname,
            fontPath: '../fonts/', // set path to font (from your CSS file if relative)
            className: 's' // set class name in your CSS
          };
          gulp.src('templates/yourtemplate.css')
            .pipe(consolidate('lodash', options))
            .pipe(rename({ basename: fontname }))
            .pipe(gulp.dest('dist/css/')); // set path to export your CSS
          css_created = true;
        })
        .pipe(gulp.dest('dist/fonts/')); // set path to export your fonts
    })
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants