Skip to content

能否增加对woff2的支持 #30

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

Open
ghostgeek opened this issue Apr 25, 2016 · 8 comments
Open

能否增加对woff2的支持 #30

ghostgeek opened this issue Apr 25, 2016 · 8 comments

Comments

@ghostgeek
Copy link

WOFF File Format 2.0 已经发布了一段时间,是否在项目里面考虑增加对这一标准的支持

@junmer
Copy link
Contributor

junmer commented Apr 26, 2016

@ghostgeek 是的 有这个考虑
但是目前并没有时间,也可以试试用 gulp-ttf2woff2 来搞定这个需求

var Fontmin = require('fontmin');
var ttf2woff2 = require('gulp-ttf2woff2');

var fontmin = new Fontmin()
    .src('fonts/*.ttf')
    .use(Fontmin.glyph({
        text: '对woff2的支持'
    }))
    .use(ttf2woff2({clone: true}))
    .dest('build/fonts');


fontmin.run(function (err, files) {
    if (err) {
        throw err;
    }

    console.log(files[0]);
    // => { contents: <Buffer 00 01 00 ...> }
});

@ghostgeek
Copy link
Author

@Delagen
Copy link

Delagen commented Jun 2, 2016

based on plugin ttf2woff.js

var ttf2woff2=require("ttf2woff2");

var FontMinTtf2Woff2 = function(opts) {
    opts = _.extend({clone: true}, opts);

    function compileTtf(buffer, options, cb) {
        var output;
        var ttf2woffOpts = {};

        if (options.deflate) {
            ttf2woffOpts.deflate = deflate;
        }

        try {
            output = ttf2woff2(buffer);
        }
        catch (ex) {
            cb(ex);
        }

        output && cb(null, output);
    }

    return through.ctor({
                            objectMode: true
                        }, function(file, enc, cb) {

        // check null
        if (file.isNull()) {
            cb(null, file);
            return;
        }

        // check stream
        if (file.isStream()) {
            cb(new Error('Streaming is not supported'));
            return;
        }

        // check ttf
        if (!isTtf(file.contents)) {
            cb(null, file);
            return;
        }

        // clone
        if (opts.clone) {
            this.push(file.clone(false));
        }

        // replace ext
        file.path = path.join(path.dirname(file.path), path.basename(file.path, path.extname(file.path)) + ".woff2");

        compileTtf(file.contents, opts, function(err, buffer) {

            if (err) {
                cb(err);
                return;
            }

            file.contents = buffer;
            cb(null, file);
        });

    });
};

@drazik
Copy link

drazik commented Jun 27, 2016

Hello,

Do you plan to embed ttf2woff2 in fontmin in a future release ?

Thanks for the workaround using gulp-ttf2woff2 as a plugin 👍

@Delagen
Copy link

Delagen commented Jun 27, 2016

I preferred to write own implementation of svgs2ttf using fontforge basic scripting to produce svg font and ttf2* modules because svg font rendering issues does not fixed in such projects for years. Own implementation is smaller and more tunable. I understand people that prefer to use native project api instead of such wrappers now.

@ianbrandt
Copy link

As fonteditor-core is the basis of all the other fontmin plugins, I submitted a request for ttf2woff2 support there: kekee000/fonteditor-core#3.

@chemzqm
Copy link

chemzqm commented Nov 6, 2017

不知道作者是否接受 PR?

@fasign
Copy link

fasign commented Nov 3, 2020

还在维护么

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

No branches or pull requests

7 participants