How to use the fontmin.glyph function in fontmin

To help you get started, we’ve selected a few fontmin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github edmondyip / ChineseFonts / index.js View on Github external
};

// word count
function wordCount(str) {
  var text = removeDupicateText(str)
  var matches = text.match(/[\u00ff-\uffff]|\S+/g);
  return matches ? matches.length : 0;
}

// print all text
console.log('Converted words : ' + removeDupicateText(allText),'(' + wordCount(allText) + ')');

// convert file type
var fontmin = new Fontmin()
  .src(fontsSource)
  .use(Fontmin.glyph({
    text: allText
  }))
  .use(ttf2woff2({
    clone: true
  })) // add woff2
  .dest(outputPath)
  .use(Fontmin.ttf2eot())
  .use(Fontmin.ttf2woff({
    deflate: true
  }))
  .use(Fontmin.ttf2svg());
imagemin([outputPath + '*.svg'], outputPath + 'optimize', {
  use: [svgo()]
}).then(() => {
  console.log('Convert finished'); // Finished
});
github codexa / firetext / builder / build.js View on Github external
}, function(err, css) {
			// Remove unused glyphs from icon font
			var rIconFontUrl = /(url\(".*?materialdesignicons-webfont.woff.*?base64,)(.*?)("\))/;
			var rIconRuleMatch = /\.icon-.*?:before {\n  content: "\\([\da-f]+)";\n}/g;
			var rIconRuleExtract = /\.icon-.*?:before {\n  content: "\\([\da-f]+)";\n}/; // not global
			
			window.language = 'en-US'; // Since there is a window, fontmin expects window.language
			
			var Fontmin = require('fontmin');
			var fontmin = new Fontmin()
				.src(argv._[0].replace(/[^\/]*\.html/, 'style/fonts/materialdesignicons-webfont.ttf'))
				.use(Fontmin.glyph({
					text: css.match(rIconRuleMatch).map(function(iconRule) {
						return String.fromCharCode(parseInt(iconRule.match(rIconRuleExtract)[1], 16));
					}).join(''),
				}))
				.use(Fontmin.ttf2woff({
					deflate: true // Does nothing but shouldn't hurt
				}));
			fontmin.run(function(err, files) {
				if(err) {
					throw err;
				}
				
				css = css.replace(rIconFontUrl,
					'$1' +
					files[0].contents.toString('base64') +
					'$3'
github ecomfe / echarts-builder-web / css / font / build.js View on Github external
var Fontmin = require('fontmin');
var htmlToText = require('html-to-text');
var path = require('path');
var fs = require('fs');
var text = ['index', 'echarts3', 'map3'].map(function (name) {
    return htmlToText.fromString(fs.readFileSync(path.join(__dirname, '../../' + name + '.html'), 'utf-8'));
}).join('');
// htmlToText.fromString(html, {}, function (err, text) {
new Fontmin()
    .src('./noto-thin.ttf')
    .use(Fontmin.glyph({
        text: text
    }))
    .run(function (err, files) {
        if (err) {
            throw new Error(err);
        }
        require('fs').writeFileSync('./noto-thin.min.ttf', files[0]._contents);
    });
// });
github junmer / serve-fontmin / index.js View on Github external
function fontmin(font, opts, callback) {

        var fmOpts = extend({}, opts);

        // for css font path
        fmOpts.fontPath = ['.', opts.dest, ''].join('/');

        // font css font family
        fmOpts.fontFamily = font.name || font.basename;

        var stream = storage.src(font.srcPath)
            .pipe(Fontmin.glyph({
                text: font.text
            })())
            .pipe(streamRename({
                basename: font.hash
            }))
            .pipe(Fontmin.ttf2eot(fmOpts)())
            .pipe(Fontmin.ttf2woff(fmOpts)())
            .pipe(Fontmin.ttf2svg(fmOpts)())
            .pipe(Fontmin.css(fmOpts)())
            .pipe(storage.dest(opts.dest));

        stream.on('error', callback);
        stream.pipe(concat(callback.bind(null, null)));

    }
github zoomla / CMS-Source-code / Zoomla逐浪CMS2_x3.8源码 / Extend.WebFont / font-spider-master / src / compress / index.js View on Github external
var webFont = this.webFont;
        var files = this.files;
        var source = this.source;
        var dirname = this.dirname;
        var basename = this.basename;

        var originalSize = fs.statSync(source).size;


        var fontmin = new Fontmin().src(source);
        var temp = path.join(dirname, TEMP + number);

        // 有些 webfont 使用 content 属性加字体继承,查询不到 chars
        // 不压缩,避免意外将 fonticon 干掉了
        if (webFont.chars) {
            fontmin.use(Fontmin.glyph({
                text: webFont.chars
            }));
        }


        Object.keys(files).forEach(function (key) {
            key = key.toLocaleLowerCase();
            if (typeof Fontmin['ttf2' + key] === 'function') {
                fontmin.use(Fontmin['ttf2' + key]({clone: true}));
            }
        });


        fontmin.dest(temp);

        fontmin.run(function (errors /*, buffer*/) {
github aui / font-spider / src / compressor / index.js View on Github external
if (!fs.existsSync(source.url)) {
            return callback(new Error('"' + source.url + '" file not found'));
        }

        var originalSize = fs.statSync(source.url).size;
        var fontmin = new Fontmin().src(source.url);
        var paths = {};
        var types = {
            'embedded-opentype': 'ttf2eot',
            'woff': 'ttf2woff',
            'woff2': 'ttf2woff2',
            'svg': 'ttf2svg'
        };


        fontmin.use(Fontmin.glyph({
            trim: false,
            text: webFont.chars || '#' // 传入任意字符避免 fontmin@0.9.5 BUG
        }));


        if (source.format === 'opentype') {
            fontmin.use(Fontmin.otf2ttf());
        }


        webFont.files.forEach(function(file) {
            var format = file.format;
            var fn = types[format];
            var extname = path.extname(file.url);
            var basename = path.basename(file.url, extname);
            var relative = path.relative(dirname, file.url);
github biuuu / ShinyColors / script / fontmin.js View on Github external
const start = (src, txt, removeJa = false) => {
  if (removeJa) {
    txt = txt.replace(/[\u3040-\u30ff\uff66-\uff9f]/g, '')
  }
  const fontmin = new Fontmin()
  .src(src)
  .use(Fontmin.glyph({
      text: txt,
      hinting: false
  }))
  .use(ttf2woff2({ clone: false }))
  .dest(destPath)

  fontmin.run(function (err, files, stream) {
    if (err) {
      console.error(err)
    }
  })
}
github patrickhulce / fontmin-webpack / lib / index.js View on Github external
setupFontmin(extensions, usedGlyphs = []) {
    usedGlyphs = _.isArray(usedGlyphs) ? usedGlyphs : [usedGlyphs]
    let fontmin = new Fontmin().use(Fontmin.glyph({text: usedGlyphs.join(' ')}))
    FONTMIN_EXTENSIONS.forEach(ext => {
      if (extensions.includes('.' + ext)) {
        fontmin = fontmin.use(Fontmin[`ttf2${ext}`]())
      }
    })

    return fontmin
  }
github ecomfe / gulp-fontmin / index.js View on Github external
}

        var text = opts.text || '';

        if (text && opts.chineseOnly) {
            text = text.replace(/[^\u4e00-\u9fa5]/g, '');
        }

        opts.text = text;

        var fontmin = new Fontmin()
            .src(file.contents)
            .use(rename({
                path: file.path
            }))
            .use(Fontmin.glyph(opts))
            .use(Fontmin.ttf2eot())
            .use(Fontmin.ttf2woff())
            .use(Fontmin.ttf2svg())
            .use(Fontmin.css(opts));

        if (opts.use) {
            opts.use.forEach(fontmin.use.bind(fontmin));
        }

        var fileStream = this;

        fontmin.run(function (err, files) {
            if (err) {
                cb(new gutil.PluginError('gulp-fontmin:', err, {fileName: file.path}));
                return;
            }

fontmin

Minify font seamlessly, font subsetter, webfont (eot, woff, svg) converter.

MIT
Latest version published 1 month ago

Package Health Score

71 / 100
Full package analysis