![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
pixi-webfont-loader
Advanced tools
Add support for webfonts to PixiJS's Loader.
This leverages FontFaceObserver to make sure the fonts are ready to go when you need it, avoiding ugly unformatted text.
In the example below, we will load a font from a file and then create two texts in different ways. One manually and one using the created objects in the resource.
(This assumes you are using packages. If you are writing raw js you will need to link FontFaceObserver in your html)
//register the webfont plugin into the Loader
//DO IT ONLY ONCE AND BEFORE EVERYTHING AND YOU ARE GOOD TO GO.
Loader.registerPlugin(WebfontLoaderPlugin);
//add the css file
Loader.shared.add({ name: "My awesome font", url: "./fonts/eng.css" });
//set the callback
Loader.shared.onComplete.once(() => {
// Create it by hand: naming the font by its fontFamily and setting up the right style.
const text1 = new Text("Lorem ipsum", new TextStyle({ fontFamily: "Thickhead", fill: 0x990000 }));
// Create it by reading the resources. This will have the fontFamily + fontStyle + fontWeight in a single object.
const text2 = new Text("dolor sit amet", Loader.shared.resources["My awesome font"].data[0])
//(I don't really recommend this but people seem to like the resources magic bag)
text2.y = 50;
stage.addChild(text1);
stage.addChild(text2);
});
//load!
Loader.load();
$ yarn install
$ yarn build
Loader.registerPlugin(WebfontLoaderPlugin)
DO THIS ONLY ONCE!
Do it before using the loader and you will be fine.
Loader.shared.add({ name: "Japanese Font", url: "./fonts/kana.css", metadata: { testString: "カタカナ", timeout: 10000 } })
How to add a font:
name
that can be whatever you want, doesn't need to be related to the font.url
pointing to the .css file. (The css file will point to the fonts, think of it as a spritesheet atlas for fonts.)testString
: FontFaceObserver will use this string to check if your font was loaded. If your font doesn't have Latin characters you will need it, otherwise you will be fine.timeout
: FontFaceObserver will give up waiting after this many milliseconds to not hang your game. If you ABSOLUTELY. NEED. THEM. FONTS. set it to infinity.Transfonter, FontSquirrel and many other websites can convert a regular font into a fully functional Webfont.
They are there, just trust them! Call upon thee by their family name or font name (check the CSS file you loaded for those) or check the resources object with the name you gave your font in the loader. (When in doubt, console.log()
stuff. That might give you a hint.)
Find a way to host the demo
folder in here, you are a smart person, you can do it!
MIT, see LICENSE.md for details.
0.1.0
FAQs
Font loader plugin for PixiJS
We found that pixi-webfont-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.