{"library":"load-bmfont","title":"load-bmfont","description":"The `load-bmfont` package offers a convenient solution for parsing and loading AngelCode BMFont files into a standardized JSON format. It's designed to operate seamlessly across both Node.js and web browser environments, handling file system reads via `fs` and HTTP requests through `phin` in Node, and utilizing `xhr` for browser-based asset fetching. Supporting ASCII (text), JSON, XML, and binary BMFont data, this library provides a robust foundation for applications requiring bitmap font rendering. Currently at version 1.4.2, it maintains a stable release cycle, primarily focused on reliability and compatibility, rather than frequent new feature introductions, as reflected by its `stable` badge. A key advantage is its consistent API, which abstracts away environmental differences, simplifying the integration of BMFonts regardless of the execution context. This allows developers to write portable code for loading font assets, a crucial aspect for cross-platform game development or graphics-intensive web applications.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install load-bmfont"],"cli":null},"imports":["const load = require('load-bmfont');","load('path/to/font.fnt', function (err, font) { /* ... */ });","load({ uri: 'path/to/font.bin', binary: true }, function (err, font) { /* ... */ });"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const loadBmfont = require('load-bmfont');\nconst path = require('path');\n\n// This example assumes you have 'Arial-32.fnt' and 'Arial.bin'\n// in a 'fonts/' directory relative to your script.\n// In a browser, these would be fetched via HTTP.\n\n// Example 1: Loading an ASCII/XML/JSON BMFont file\nloadBmfont(path.join(__dirname, 'fonts', 'Arial-32.fnt'), function (err, font) {\n  if (err) {\n    console.error('Error loading Arial-32.fnt:', err);\n    return;\n  }\n  console.log('--- Loaded Arial-32.fnt ---');\n  console.log('Font Face:', font.info.face);\n  console.log('Line Height:', font.common.lineHeight);\n  console.log('Number of characters:', font.chars.length);\n});\n\n// Example 2: Loading a binary BMFont file, explicitly setting binary: true\nloadBmfont(\n  {\n    uri: path.join(__dirname, 'fonts', 'Arial.bin'), // Replace with actual path\n    binary: true,\n  },\n  function (err, font) {\n    if (err) {\n      console.error('Error loading Arial.bin (binary):', err);\n      return;\n    }\n    console.log('\\n--- Loaded Arial.bin (binary) ---');\n    console.log('Font Size:', font.info.size);\n    console.log('Common scaleW:', font.common.scaleW);\n    console.log('First Kerning (if exists):', font.kernings.length > 0 ? font.kernings[0] : 'N/A');\n  }\n);\n","lang":"javascript","description":"This quickstart demonstrates how to load both text-based and binary BMFont files using `load-bmfont`, showing the basic callback pattern and necessary `binary` option.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}