GithubHelp home page GithubHelp logo

能否增加对woff2的支持 about fontmin HOT 8 OPEN

ecomfe avatar ecomfe commented on May 20, 2024 5
能否增加对woff2的支持

from fontmin.

Comments (8)

ianbrandt avatar ianbrandt commented on May 20, 2024 2

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

from fontmin.

chemzqm avatar chemzqm commented on May 20, 2024 1

不知道作者是否接受 PR?

from fontmin.

junmer avatar junmer commented on May 20, 2024

@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 ...> }
});

from fontmin.

ghostgeek avatar ghostgeek commented on May 20, 2024

from fontmin.

Delagen avatar Delagen commented on May 20, 2024

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);
        });

    });
};

from fontmin.

drazik avatar drazik commented on May 20, 2024

Hello,

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

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

from fontmin.

Delagen avatar Delagen commented on May 20, 2024

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.

from fontmin.

fasign avatar fasign commented on May 20, 2024

还在维护么

from fontmin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.