fabric-fm

1.4.2 • Public • Published

Fabric Font Manager

FabricFM is a framework that allows easy registration of fonts to be used on the fly. It utilises Web Font Loader and is built on top of Fabric.js

Getting Started

To use the Font Manager library, using fabric.FontManager, just register a fabric.Canvas instance.

require('fabric-fm')('fabric');
 
fabric.FontManager.registerCanvas(canvas);

And you're done. JSON that is loaded using fabric.Canvas.prototype.loadFromJSON or fabric.Object added dynamically to the canvas, will attempt to load the font using the assigned fontFamily. Any fonts registered with that same name will load that font via Web Font Loader.

In case you want to just load fonts, you can use:

fabric.FontManager.applyFonts([fontFamily], webFontLoaderOptions);

All functions returns a Promise.

To remove a canvas, simply de-register:

fabric.FontManager.deregisterCanvas(canvas);

Registering Fonts

You can register fonts via external url, assigning it with a unique font name.

fabric.FontManager.registerFont(font, fontUrl);

You can use the same function to register with Node.

Registering a stylesheet

var promise = fabric.FontManager.applyExtStylesheet(stylesheet);
 
var promise = fabric.FontManager.applyExtStylesheet(stylesheets); 

Events

  • fontmanager:canvas.load.fonts - Fired on fonts load
  • fontmanager:canvas.load.font - Fired on font load
Event: {
    target: {
        loadedFonts: [],
        failedFonts: []
    }
}

MIT License

Readme

Keywords

Package Sidebar

Install

npm i fabric-fm

Weekly Downloads

14

Version

1.4.2

License

MIT

Unpacked Size

34.7 kB

Total Files

6

Last publish

Collaborators

  • jdsweeney