Home

Awesome

example

With pxxl.js and the included BDF font files you can 'render' a text to an array of pixel coordinates. You can then use the pixel coordinates to do your own rendering. So pxxl.js itself doesn't really render anything to the screen. You might say it's 'as-if' rendering :-)

You can then use the pixel coordinates in any way you can imagine. For example:

Example

example

Download

Install via Bower

You can install Pxxl.js via bower with the following command:

$ bower install pxxl

Quick-start

For simple scenarios, you can use the pxxl() function. It takes care of downloading the font file via ajax, it parses the font, caches the result, and then it 'renders' the text to a 'pixel info' array.

pxxl(<font-url>, <text>, <callback>)

Note that the font file won't be downloaded again on subsequent calls because the parsed font is cached.

Simple example

example

pxxl("fonts/c64d.bdf", "Pxxl.js", function (pixels) {
  var ctx = $('canvas')[0].getContext('2d');

  for (var p=0,hue=0 ; p<pixels.length ; p++,hue++) {
    var pixel = pixels[p],
      x = pixel.x*6,
      y = pixel.y*6;

    ctx.fillStyle = "hsl("+ hue +",100%,50%)";
    ctx.fillRect(x,y,5,5);
  }
});

API

Pxxl.LoadFont(url, callback)

Load and parse a font file and execute the callback afterwards.

Pxxl.LoadFont(fontUrl, function(font) {
  ...
});

The font param that is received by the callback is an instance of Pxxl.Font.

Pxxl.Font.getPixels()

Gets the pixel info based on given font and text. The pixel info reflects how the text would be rendered. You can use the pixel info to do your own rendering.

var pixels = font.getPixels(text);

The array looks like this:

[{ x: 0, y : 0 },
 { x: 1, y : 0 },
 { x: 2, y : 1 },
 { x: 3, y : 1 }
 ..etc..        ]

More examples

Contributing

Any and all feedback is welcome, suggestions, bug reports, pull requests, everything. Notably, I'd really want a WebGL demo for this lib but I haven't found the time to dive into WebGL. Let me know if you can help out! ;-)

Changelog

0.4