npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bdf

v1.0.1

Published

Simple library for reading Adobe Glyph Bitmap Distribution font files

Downloads

6

Readme

BDF.js

Simple library for reading Adobe Glyph Bitmap Distribution font files. Read more about this format on Wikipedia.

How to use

var font = new BDF();
font.load("c64.bfd", function() {
  console.log(font);
});

An example Commodore 64 8x8 point font is included.

API

  • Constructor BDF()

Initializes a BDF font instance.

  • load(path, callback)

Loads font data from a file. The first path argument specifies the path to the BDF font file. The callback function is invoked once the font is loaded. A single error argument is passed if there was an error finding the file.

  • loadSync(path)

Similar to load, but synchronous.

  • meta (property)

An object containing metadata about the font once loaded. This includes the font version, name, size and several other properties.

Example meta object:

{
  version: '2.1',
  name: 'c64',
  size: { points: 8, resolutionX: 75, resolutionY: 75 },
  boundingBox: { width: 8, height: 8, x: 0, y: -2 },
  properties: { fontDescent: 2, fontAscent: 6, defaultChar: 0 },
  totalChars: 95
}
  • glyphs (property)

An object containing data for every glyph in the font. Each key in this object represents the character encoding.

Example glyphs object:

{
  ...
  '64': { ... }
  '65': {
    name: 'C0001',
    bytes: [Object],
    bitmap: [Object],
    code: 65,
    char: 'A',
    scalableWidthX: 666,
    scalableWidthY: 0,
    deviceWidthX: 8,
    deviceWidthY: 0,
    boundingBox: { x: 0, y: -2, width: 8, height: 8 }
  }
  '66': { ... }
  ...
}

The bitmap object corresponding to each glyph contains a matrix of 1s and 0s defining the shape of the glyph in the bounding box. Example bitmap object, for the character 'A' with code 65: (the spaces are 0s, left out in the example below to make it clearer)

[
  [       1 1       ],
  [     1 1 1 1     ],
  [   1 1     1 1   ],
  [   1 1 1 1 1 1   ],
  [   1 1     1 1   ],
  [   1 1     1 1   ],
  [   1 1     1 1   ],
  [                 ]
]

The bytes object corresponding to each glyph is similar to the bitmap object, but each series of eight 1s and 0s on a row is encoded in a byte, instead of being laid out as 1s and 0s in an array. Example bytes object, for the character 'A' with code 65: [ 24, 60, 102, 126, 102, 102, 102, 0 ]

  • toString()

Creates and returns a string containing all the characters in this font.

  • writeText(text, options)

Convenient way of creating a matrix concatenating bitmap information for several glyphs in this font. The first parameter, text is a string containing the text to convert to a bitmap. The optional options object contains a couple of flags for writing the text: textRepeat (a number specifying how many times the text repeats) and kerningBias (a number consistently added to the glyph width when building the bitmap).

This method returns an object containing bitmap information. Number keys like 0, 1, 2... correspond to bitmap rows, which are arrays of bits. The width and height properties define the bitmap bounds.