
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
msdf-bmfont
Advanced tools
Converts a .ttf font file into multichannel signed distance fields, then outputs packed spritesheets and a json representation of an AngelCode BMfont.
Signed distance fields are a method of reproducing vector shapes from a texture representation, popularized in this paper by Valve. This tool uses Chlumsky/msdfgen to generate multichannel signed distance fields to preserve corners. The distance fields are created from vector fonts, then rendered into texture pages. A BMFont object is provided for character layout.
$ npm install msdf-bmfont
Unless previously installed you'll need Cairo, since node-canvas depends on it. For system-specific installation view the node-canvas wiki.
You can quickly install the dependencies by using the command for your OS:
| OS | Command |
|---|---|
| OS X | brew install pkg-config cairo libpng jpeg giflib |
| Ubuntu | sudo apt-get install libcairo2-dev libjpeg8-dev libpango1.0-dev libgif-dev build-essential g++ |
| Fedora | sudo yum install cairo cairo-devel cairomm-devel libjpeg-turbo-devel pango pango-devel pangomm pangomm-devel giflib-devel |
| Solaris | pkgin install cairo pkg-config xproto renderproto kbproto xextproto |
| Windows | Instructions on the node-canvas wiki |
El Capitan users: If you have recently updated to El Capitan and are experiencing trouble when compiling, run the following command: xcode-select --install. Read more about the problem on Stack Overflow.
Writing the distance fields and font data to disk:
const generateBMFont = require('msdf-bmfont');
const fs = require('fs');
generateBMFont('Some-Font.ttf', (error, textures, font) => {
if (error) throw error;
textures.forEach((sheet, index) => {
font.pages.push(`sheet${index}.png`);
fs.writeFile(`sheet${index}.png`, sheet, (err) => {
if (err) throw err;
});
});
fs.writeFile('font.json', JSON.stringify(font), (err) => {
if (err) throw err;
});
});
Generating a single channel signed distance field with a custom character set:
const generateBMFont = require('msdf-bmfont');
const opt = {
charset: 'ABC.ez_as-123!',
fieldType: 'sdf'
};
generateBMFont('Some-Font.ttf', opt, (error, textures, font) => {
...
});
generateBMFont(fontPath, [opt], callback)Renders a bitmap font from the font at fontPath with optional opt settings, triggering callback on complete.
Options:
charset (String|Array)
fontSize (Number)
42textureWidth, textureHeight (Number)
512texturePadding (Number)
2transparent (Boolean)
fieldType (String)
msdf. Must be one of:
msdf Multi-channel signed distance fieldsdf Monochrome signed distance fieldpsdf monochrome signed pseudo-distance fielddistanceRange (Number)
3The callback is called with the arguments (error, textures, font)
error on success will be null/undefinedtextures an array of Buffers, each containing the PNG data of one texture sheetfont an object containing the BMFont data, to be used to render the fontSince opt is optional, you can specify callback as the second argument.
MIT, see LICENSE.md for details.
FAQs
Creates a bitmap font of signed distance fields from a font file
The npm package msdf-bmfont receives a total of 11 weekly downloads. As such, msdf-bmfont popularity was classified as not popular.
We found that msdf-bmfont demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.