Skip to content

Commit

Permalink
update to newest phin
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdesl committed Jul 9, 2024
1 parent 2a6ce70 commit 9001c01
Show file tree
Hide file tree
Showing 5 changed files with 4,383 additions and 20 deletions.
36 changes: 19 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
Loads an [AngelCode BMFont](http://www.angelcode.com/products/bmfont/) file in browser (with XHR) and node (with fs and [phin](https://github.com/ethanent/phin)), returning a [JSON representation](json-spec.md).

```js
var load = require('load-bmfont')
var load = require("load-bmfont");

load("fonts/Arial-32.fnt", function (err, font) {
if (err) throw err;

load('fonts/Arial-32.fnt', function(err, font) {
if (err)
throw err

//The BMFont spec in JSON form
console.log(font.common.lineHeight)
console.log(font.info)
console.log(font.chars)
console.log(font.kernings)
})
console.log(font.common.lineHeight);
console.log(font.info);
console.log(font.chars);
console.log(font.kernings);
});
```

Currently supported BMFont formats:
Expand All @@ -40,18 +39,21 @@ Loads a BMFont file with the `opt` settings and fires the callback with `(err, f

- `uri` or `url` the path (in Node) or URI
- `binary` boolean, whether the data should be read as binary, default false
- (in node) options for `fs.readFile` or `phin`
- (in node) options for `fs.readFile` or [phin](https://www.npmjs.com/package/phin)
- (in browser) options for [xhr](https://github.com/Raynos/xhr)

To support binary files in the browser and Node, you should use `binary: true`. Otherwise the XHR request might come in the form of a UTF8 string, which will not work with binary files. This also sets up the XHR object to override mime type in older browsers.

```js
load({
uri: 'fonts/Arial.bin',
binary: true
}, function(err, font) {
console.log(font)
})
load(
{
uri: "fonts/Arial.bin",
binary: true,
},
function (err, font) {
console.log(font);
}
);
```

## License
Expand Down
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ module.exports = function loadFont(opt, cb) {
}

if (url.parse(file).host) {
request(opt, handleData)
request(opt).then(function (res) {
handleData(null, res)
}).catch(function (err) {
handleData(err)
})
} else {
fs.readFile(file, opt, handleData)
}
Expand Down
Loading

0 comments on commit 9001c01

Please sign in to comment.