Skip to content

Commit 44cfc6d

Browse files
committed
Squashed commit of the following:
commit ccd8345 Author: Shen Yiming <[email protected]> Date: Tue Aug 26 00:50:27 2025 +0800 docs: fix README en version misplaced paragraph about msdfgen commit 649974c Author: Shen Yiming <[email protected]> Date: Tue Aug 26 00:40:39 2025 +0800 chore(release): 2.8.0 commit 3383f3c Author: Shen Yiming <[email protected]> Date: Tue Aug 26 00:38:18 2025 +0800 docs: update README and misc docs commit 48460fb Author: Shen Yiming <[email protected]> Date: Tue Aug 26 00:02:27 2025 +0800 Feat/major dependency updates (#97) * fix(deps): update handlebars and load-bmfont * Update node.js.yml drop old nodejs version 12.x 14.x and 16.x * feat: installation script for `msdfgen` latest binary on all supported platforms * chore: Action now supports all platforms * feat: add multi-stage CI workflow with rate limiting protection - Add 5-stage testing strategy across all platforms - Include Windows, macOS (Intel & Apple Silicon), Linux x64 & ARM64 - Implement rate limiting protection with random delays - Add retry mechanisms for npm installation - Use GitHub Token for authentication - Optimize resource usage with staged execution # Conflicts: # .github/workflows/node.js.yml * fixed: Removed render in npm test * build: include msdfgen binary for all platform & download script use npm run update-msdfgen-all to update msdfgen binaries * ci: simplify test ci * ci: fix free runner label macos-13 instead of macos-latest-large * docs: fix markdown style violation * fix: msdfgen macos-x64 binary arch error * fix: msdfgen binary install script check update logic error running check should only been performed on current platform commit bd28cc0 Author: Shen Yiming <[email protected]> Date: Sat Aug 23 12:07:55 2025 +0800 fix: remove node test.js render in npm run test commit 2c149bd Author: Shen Yiming <[email protected]> Date: Thu Aug 14 23:55:12 2025 +0800 fix(deps): update handlebars and load-bmfont commit eb7bc25 Author: Shen Yiming <[email protected]> Date: Tue Aug 19 10:38:28 2025 +0800 Update node.js.yml drop old nodejs version 12.x 14.x and 16.x commit 22b118d Author: Shen Yiming <[email protected]> Date: Tue Aug 19 10:35:32 2025 +0800 Update node.js.yml commit 3e021c9 Author: albinkong <[email protected]> Date: Thu Aug 14 15:52:55 2025 +0200 Upgrade jimp to 1.6.0 (#96) * Upgrade jimp to 1.6.0 * Bump serve-handler minor version Removes use of deprecated node package commit 3b4cc09 Author: Pete Feltham <[email protected]> Date: Sat Feb 15 16:19:16 2025 +1100 Look for arm64 binaries in _arm64 dirs (#95) commit 523c5e5 Author: h1ve2 <[email protected]> Date: Sat Feb 15 13:18:02 2025 +0800 feat: add an optional logger (#94) * feat: add an optional logger * Create defaultLogger and export it * Import defaultLogger and replace console with logger commit 56adc10 Author: Frank Weindel <[email protected]> Date: Tue Feb 11 09:36:33 2025 -0500 Fix baseline alignment (#93) commit 5a2495a Author: Ari Lotter <[email protected]> Date: Fri Jun 16 09:37:45 2023 -0400 feat: Add arm64 MacOS compatibility (#90) commit 0cb2817 Author: tkwiatek <[email protected]> Date: Sun Jun 4 06:25:11 2023 +0200 feat: Add arm64 linux compatibility (#89) * feat: Add arm64 linux compatibility * chore: Update deps * chore: Update msdfgen.linux binary to newest version --------- Co-authored-by: Leo Bergman <[email protected]> commit 986b9cc Author: Shen Yiming <[email protected]> Date: Sun Jul 24 00:00:01 2022 +0800 chore(release): 2.7.0 commit 2eaa125 Author: Shen Yiming <[email protected]> Date: Sat Jul 23 23:40:28 2022 +0800 docs: update Docs for txt(.fnt) format and BMFont format description commit 30168bb Author: Shen Yiming <[email protected]> Date: Sat Jul 23 23:34:11 2022 +0800 chore: update & cleanup modules commit 34d8976 Author: Shen Yiming <[email protected]> Date: Sat Jul 23 22:53:11 2022 +0800 feat: add new output type: txt an alternative .fnt format other than xml, which is accpetable by Godot & Defold commit 235bce6 Author: Shen Yiming <[email protected]> Date: Tue Feb 15 11:01:04 2022 +0800 Create node.js.yml commit 47cc4f9 Author: Shen Yiming <[email protected]> Date: Tue Feb 1 21:56:06 2022 +0800 Update Readme commit 17a79b9 Author: Shen Yiming <[email protected]> Date: Mon Jan 31 21:36:06 2022 +0800 chore(release): 2.6.0 commit c193d38 Author: Ankush Sharma <[email protected]> Date: Thu May 6 09:28:23 2021 +0530 Upgrade Jimp 0.16.1 (#63) Update package.json commit b6c8f6b Author: Phil <[email protected]> Date: Mon Feb 8 02:05:50 2021 -0700 Fix binary path not working when containing spaces (#59) commit 5209f7c Author: bloodmage <[email protected]> Date: Mon Jun 22 12:42:52 2020 +0800 Using stdin to transfer shapeDesc (#52) For some complex CJK fonts, length of shapeDesc may exceed limitation on Windows (which is 8191 characters for command line & arguments). Using stdin solves this problem. commit 23aace9 Author: Shen Yiming <[email protected]> Date: Sun Feb 9 02:26:53 2020 +0800 feat: Add version update-notifier commit e05c94d Author: Shen Yiming <[email protected]> Date: Sun Feb 9 02:16:09 2020 +0800 chore(release): 2.5.4 commit 3b57562 Author: Shen Yiming <[email protected]> Date: Sun Feb 9 02:03:27 2020 +0800 fix: Re-use cfg settings not applied and re-used atlas file autosizing not applied fix #44 commit c37cc40 Author: Shen Yiming <[email protected]> Date: Sat Feb 8 21:06:02 2020 +0800 fix: CLI&document for SVG debug generation from `-t svg` to `-v` fix #46 commit ae559fd Author: Shen Yiming <[email protected]> Date: Sun Feb 2 15:06:58 2020 +0800 fix: omit path in font-face fix #49 commit 7b1f2a7 Author: Shen Yiming <[email protected]> Date: Sun Jan 26 11:32:38 2020 +0800 chore(release): 2.5.3 commit 12a60e3 Author: Shen Yiming <[email protected]> Date: Sun Jan 26 11:32:20 2020 +0800 refactor: Update arabic-persian-reshaper API & version commit 6b659b4 Author: Don McCurdy <[email protected]> Date: Fri Jan 17 19:37:52 2020 -0800 Support 'fontBuffer' parameter for in-memory generation. (#48) - Fixes #47. commit bbf8286 Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat Jan 18 11:34:45 2020 +0800 Bump handlebars from 4.1.2 to 4.3.0 (#45) Bumps [handlebars](https://github.com/wycats/handlebars.js) from 4.1.2 to 4.3.0. - [Release notes](https://github.com/wycats/handlebars.js/releases) - [Changelog](https://github.com/wycats/handlebars.js/blob/master/release-notes.md) - [Commits](handlebars-lang/handlebars.js@v4.1.2...v4.3.0) Signed-off-by: dependabot[bot] <[email protected]> commit 09b1171 Author: Jo <[email protected]> Date: Sat Jan 18 04:34:01 2020 +0100 output padding info by default (#43) commit ff3669c Author: Shen Yiming <[email protected]> Date: Fri Jul 12 20:46:12 2019 +0800 chore(release): 2.5.2 commit 230d0b3 Author: Shen Yiming <[email protected]> Date: Fri Jul 12 20:45:51 2019 +0800 fix: async texture generation skips fontData stringify fix #39 commit e5c15ee Author: Shen Yiming <[email protected]> Date: Thu Jul 11 20:59:31 2019 +0800 chore(release): 2.5.1 commit 612da74 Author: Shen Yiming <[email protected]> Date: Thu Jul 11 20:59:17 2019 +0800 chore: back to npm commit 007a6c5 Merge: 5d95b32 84732bf Author: Shen Yiming <[email protected]> Date: Thu Jul 11 20:54:12 2019 +0800 Merge branch 'master' of https://github.com/soimy/msdf-bmfont-xml commit 5d95b32 Author: Shen Yiming <[email protected]> Date: Thu Jul 11 20:53:14 2019 +0800 fix: async jimp.read() should be fulfilled before continue packing commit 84732bf Author: Shen Yiming <[email protected]> Date: Tue Jul 2 10:28:38 2019 +0800 fix: package script render changed to yarn commit 16759b3 Author: Shen Yiming <[email protected]> Date: Thu Jun 27 11:54:23 2019 +0800 docs: Update Readme to reflect new `border` option commit 071b016 Author: Shen Yiming <[email protected]> Date: Tue Jun 25 18:18:53 2019 +0800 test: Fix run render by replacing abandoned devtools Now uses pixi.js & pixi-msdf-text to render msdf font files in system default browser fix #38 commit 9fd9aa9 Author: Shen Yiming <[email protected]> Date: Thu Jun 20 00:38:22 2019 +0800 chore(release): 2.5.0 commit 33598b9 Author: Shen Yiming <[email protected]> Date: Thu Jun 20 00:37:26 2019 +0800 feat: new border option to control packing space to atlas edge commit a1494ca Author: Shen Yiming <[email protected]> Date: Thu Jun 20 00:36:10 2019 +0800 chore: npm -> yarn, add some dev toolchain commit 2d853e7 Author: Shen Yiming <[email protected]> Date: Mon Jun 3 19:39:14 2019 +0800 Version 2.4.3 - Fix: json string strict casting commit 5aef27e Author: Shen Yiming <[email protected]> Date: Mon Jun 3 19:37:35 2019 +0800 Fix: #28 json string strict casting commit 24a72ab Author: Shen Yiming <[email protected]> Date: Mon May 13 22:51:30 2019 +0800 README add npm monthly download badge commit bb525ec Author: Shen Yiming <[email protected]> Date: Sat May 11 21:51:50 2019 +0800 Fix -rot in npm test Turns out rot packing is useless in bmfont commit f1e5b6c Author: Shen Yiming <[email protected]> Date: Thu May 9 16:34:33 2019 +0800 Version 2.4.2 - New options: allowRotation commit c2f8ea8 Author: Shen Yiming <[email protected]> Date: Thu May 9 16:34:22 2019 +0800 Update comment & README commit f55d3ef Author: Shen Yiming <[email protected]> Date: Thu May 9 16:22:39 2019 +0800 Cleanup codes commit 16cc94d Author: Shen Yiming <[email protected]> Date: Thu May 9 16:21:04 2019 +0800 Fix vulnerabilities commit 7f68279 Author: Shen Yiming <[email protected]> Date: Thu May 9 16:10:34 2019 +0800 Allow 90-degree rotation in packing commit 90a285a Author: Shen Yiming <[email protected]> Date: Tue May 7 17:06:54 2019 +0800 Version 2.4.1 - Fix cli parameter type casting bug commit 4929a54 Merge: d251e03 d3030e6 Author: Shen Yiming <[email protected]> Date: Tue May 7 17:03:58 2019 +0800 Merge remote-tracking branch 'origin/develop' # Conflicts: # package-lock.json commit d251e03 Author: Damien Mortini <[email protected]> Date: Mon May 6 06:48:00 2019 +0200 force number type on texturePadding to avoid type error in MaxRectsPacker when using cli (#33) Or it will broke the whole process. commit e22589b Author: Shen Yiming <[email protected]> Date: Mon Mar 18 15:21:58 2019 +0800 Version 2.4.0 - Replace Node-Canvas with Jimp commit 5b92447 Merge: 7fbcb77 3911e85 Author: Shen Yiming <[email protected]> Date: Mon Mar 18 15:13:18 2019 +0800 Merge remote-tracking branch 'origin/canvas2jimp' Replace problematic node-canvas with jimp for lightweight image processing commit 7fbcb77 Author: Shen Yiming <[email protected]> Date: Thu Mar 14 15:46:25 2019 +0800 Version 2.3.6 - Json numeric char parse fix & Dep. update commit 4b1ad9b Merge: 6142b5b 67cd028 Author: Shen Yiming <[email protected]> Date: Thu Mar 14 15:39:09 2019 +0800 Merge branch 'develop' - Fixed json numeric charactor parse error via 4f8ab26 - Update dependencies & fixed vulnerabilties via 30d8967 - Update README on outdated textureSize parameter via 67cd028 commit 6142b5b Author: Ignacio Julve <[email protected]> Date: Thu Mar 14 03:28:49 2019 +0100 Solves Issue#30 by updating dependencies (#31) * Solves Issue#30 by updating dependencies Signed-off-by: Ignacio Julve <[email protected]> * Bump version of the library Signed-off-by: Ignacio Julve <[email protected]> commit d05ef86 Author: Shen Yiming <[email protected]> Date: Fri Jun 29 15:01:59 2018 +0800 Version 2.3.5 - Changing CLI default parameters commit a9b05b2 Author: Shen Yiming <[email protected]> Date: Fri Jun 29 14:56:03 2018 +0800 Update dependencies commit 71e08a5 Author: Shen Yiming <[email protected]> Date: Fri Jun 29 14:33:00 2018 +0800 Change Default value for texture size & smart-size Squashed commit d14db9a Author: Shen Yiming <[email protected]> Date: Fri Jun 29 13:23:03 2018 +0800 Change Default value for texture size & smart-size commit 5f8f290 Author: Shen Yiming <[email protected]> Date: Fri Feb 16 22:24:28 2018 +0800 Version 2.3.4 - Fix linux/darwin msdfgen executable permission bug commit 28acaec Author: Shen Yiming <[email protected]> Date: Thu Feb 15 15:32:59 2018 +0800 Version 2.3.3 - Update msdfgen linux binary commit bca20ca Author: Shen Yiming <[email protected]> Date: Thu Feb 15 15:30:09 2018 +0800 Update msdfgen binary to ckohnet's fork and cleanup/reorganized bin folder (#22) * Adapt the maxrects_packer v2 * Fixed bug: omit output filename lead to double path appended. * Fix bugs: 1. Typo "Generating", 2. Ignore control charators in charset, 3. Omit index in filename if only one altas * update npm add yargs cli frontend * WIP: changing cli module * Implemented cli default value, reuse can mannually specify filename. Test needed * Fixed bug with manually assign cfg file * Cleanup & update dependency * repaire msdfgen win32 binary * Update msdfgen executable permission * Update linux binary with local shared libraries. Using `patchelf --set-rpath '$ORIGIN/lib' ./msdfgen.linux * Remove unnessecery shared library * Add missing libstdc++ dependency for msdfgen linux binary * Bump canvas-prebuilt version for libpng12.so.12 issue
1 parent d3030e6 commit 44cfc6d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+12649
-1397
lines changed

.github/workflows/node.js.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Simplified CI workflow for msdf-bmfont-xml
2+
# Tests across all platforms using preloaded binaries
3+
4+
name: Node.js CI
5+
6+
on:
7+
push:
8+
branches: [ master, major-dependency-updates ]
9+
pull_request:
10+
branches: [ master, major-dependency-updates ]
11+
workflow_dispatch:
12+
13+
env:
14+
# Environment variables to disable update notifications
15+
DISABLE_UPDATE_NOTIFIER: true
16+
NO_UPDATE_NOTIFIER: true
17+
CI: true
18+
19+
jobs:
20+
test:
21+
name: Test ${{ matrix.platform }}
22+
runs-on: ${{ matrix.runs-on }}
23+
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
include:
28+
- platform: Windows
29+
runs-on: windows-latest
30+
- platform: macOS Intel
31+
runs-on: macos-13 # only 13 available for free intel mac on OSS project
32+
- platform: macOS ARM64
33+
runs-on: macos-latest
34+
- platform: Linux x64
35+
runs-on: ubuntu-latest
36+
- platform: Linux ARM64
37+
runs-on: ubuntu-24.04-arm
38+
39+
steps:
40+
- name: Checkout code
41+
uses: actions/checkout@v4
42+
43+
- name: Setup Node.js 24.x
44+
uses: actions/setup-node@v4
45+
with:
46+
node-version: 24.x
47+
cache: 'npm'
48+
49+
- name: Install dependencies
50+
run: npm ci --prefer-offline --no-audit --no-fund
51+
52+
- name: Run tests
53+
run: npm test

.gitignore

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
.DS_Store
22
node_modules/
33
npm-debug.log
4-
test/output/*.json
5-
test/output/*.fnt
6-
test/output/*.png
7-
test/output/*.txt
8-
test/output/*.svg
9-
test/output/*.cfg
4+
test/assets/fonts/*.json
5+
test/assets/fonts/*.fnt
6+
test/assets/fonts/*.png
7+
test/assets/fonts/*.txt
8+
test/assets/fonts/*.svg
9+
test/assets/fonts/*.cfg
1010
.vscode/
1111
.eslintrc*
12+
.prettierrc

CHANGELOG.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4+
5+
## [2.8.0](https://github.com/soimy/msdf-bmfont-xml/compare/v2.7.0...v2.8.0) (2025-08-25)
6+
7+
8+
### Features
9+
10+
* add an optional logger ([#94](https://github.com/soimy/msdf-bmfont-xml/issues/94)) ([523c5e5](https://github.com/soimy/msdf-bmfont-xml/commit/523c5e5ef50921669f90c94972a4b30369c9bec9))
11+
* Add arm64 linux compatibility ([#89](https://github.com/soimy/msdf-bmfont-xml/issues/89)) ([0cb2817](https://github.com/soimy/msdf-bmfont-xml/commit/0cb28172a64699f805f6e063bd25c03c5b9a0d54))
12+
* Add arm64 MacOS compatibility ([#90](https://github.com/soimy/msdf-bmfont-xml/issues/90)) ([5a2495a](https://github.com/soimy/msdf-bmfont-xml/commit/5a2495a14a1ebd3170d49350f450b6e3f531a941))
13+
14+
15+
### Bug Fixes
16+
17+
* **deps:** update handlebars and load-bmfont ([2c149bd](https://github.com/soimy/msdf-bmfont-xml/commit/2c149bdd32eddc5bd74b41d36bf303e4b69df3ae))
18+
* remove node test.js render in npm run test ([bd28cc0](https://github.com/soimy/msdf-bmfont-xml/commit/bd28cc06dccc2e5e1e7d2f22db441f290a23f4dc))
19+
20+
## [2.7.0](https://github.com/soimy/msdf-bmfont-xml/compare/v2.6.0...v2.7.0) (2022-07-23)
21+
22+
23+
### Features
24+
25+
* add new output type: txt ([34d8976](https://github.com/soimy/msdf-bmfont-xml/commit/34d8976a8672045534c8c379c967cf16bcbb8cbe))
26+
27+
## [2.6.0](https://github.com/soimy/msdf-bmfont-xml/compare/v2.5.4...v2.6.0) (2022-01-31)
28+
29+
30+
### Features
31+
32+
* Add version update-notifier ([23aace9](https://github.com/soimy/msdf-bmfont-xml/commit/23aace97c8e4af5174f8191133e42b54baafd0b5))
33+
34+
### [2.5.4](https://github.com/soimy/msdf-bmfont-xml/compare/v2.5.3...v2.5.4) (2020-02-08)
35+
36+
37+
### Bug Fixes
38+
39+
* CLI&document for SVG debug generation from `-t svg` to `-v` ([c37cc40](https://github.com/soimy/msdf-bmfont-xml/commit/c37cc40)), closes [#46](https://github.com/soimy/msdf-bmfont-xml/issues/46)
40+
* omit path in font-face ([ae559fd](https://github.com/soimy/msdf-bmfont-xml/commit/ae559fd)), closes [#49](https://github.com/soimy/msdf-bmfont-xml/issues/49)
41+
* Re-use cfg settings not applied ([3b57562](https://github.com/soimy/msdf-bmfont-xml/commit/3b57562)), closes [#44](https://github.com/soimy/msdf-bmfont-xml/issues/44)
42+
43+
44+
45+
### [2.5.3](https://github.com/soimy/msdf-bmfont-xml/compare/v2.5.2...v2.5.3) (2020-01-26)
46+
47+
48+
49+
### [2.5.2](https://github.com/soimy/msdf-bmfont-xml/compare/v2.5.1...v2.5.2) (2019-07-12)
50+
51+
52+
### Bug Fixes
53+
54+
* async texture generation skips fontData stringify ([230d0b3](https://github.com/soimy/msdf-bmfont-xml/commit/230d0b3)), closes [#39](https://github.com/soimy/msdf-bmfont-xml/issues/39)
55+
56+
57+
58+
### [2.5.1](https://github.com/soimy/msdf-bmfont-xml/compare/v2.5.0...v2.5.1) (2019-07-11)
59+
60+
61+
### Bug Fixes
62+
63+
* async jimp.read() should be fulfilled before continue packing ([5d95b32](https://github.com/soimy/msdf-bmfont-xml/commit/5d95b32))
64+
* package script render changed to yarn ([84732bf](https://github.com/soimy/msdf-bmfont-xml/commit/84732bf))
65+
66+
67+
### Tests
68+
69+
* Fix run render by replacing abandoned devtools ([071b016](https://github.com/soimy/msdf-bmfont-xml/commit/071b016)), closes [#38](https://github.com/soimy/msdf-bmfont-xml/issues/38)
70+
71+
72+
73+
## [2.5.0](https://github.com/soimy/msdf-bmfont-xml/compare/v2.4.3...v2.5.0) (2019-06-19)
74+
75+
76+
### Features
77+
78+
* new border option to control packing space to atlas edge ([33598b9](https://github.com/soimy/msdf-bmfont-xml/commit/33598b9))

README.cn.md

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
# msdf-bmfont-xml
2+
3+
[🇺🇸 English Doc](./README.md)
4+
5+
[![GitHub Actions](https://github.com/soimy/msdf-bmfont-xml/actions/workflows/node.js.yml/badge.svg)](https://github.com/soimy/msdf-bmfont-xml/actions)
6+
[![npm version](https://badge.fury.io/js/msdf-bmfont-xml.svg)](https://badge.fury.io/js/msdf-bmfont-xml)
7+
![npm](https://img.shields.io/npm/dm/msdf-bmfont-xml.svg)
8+
9+
`.ttf` 字体文件转换为多通道有符号距离场(MSDF),并输出打包的精灵图和 AngelCode BMFont 格式的 `xml(.fnt)` / `txt(.fnt)``json` 字体数据。
10+
11+
有符号距离场是一种通过纹理重现矢量图形的方法,详见 [Valve 的论文](http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf)。本工具使用 [Chlumsky/msdfgen](https://github.com/Chlumsky/msdfgen) 生成多通道距离场以保留字体边角。距离场由矢量字体生成,并渲染到纹理页。BMFont 对象用于字符排版。(参考 [BMFont 格式](http://www.angelcode.com/products/bmfont/doc/file_format.html)
12+
13+
![预览图](https://raw.githubusercontent.com/soimy/msdf-bmfont-xml/master/assets/msdf-bmfont-xml.png)
14+
15+
## 支持平台
16+
17+
- macOS(Intel & Apple Silicon)
18+
- Linux(x64 & ARM64)
19+
- Windows(x64)
20+
21+
## 使用 pixi.js 在浏览器预览 MSDF 字体
22+
23+
```bash
24+
npm install & npm run render
25+
```
26+
27+
## 作为 CLI 安装
28+
29+
```bash
30+
npm install msdf-bmfont-xml -g
31+
```
32+
33+
> ### msdfgen 多平台可执行程序
34+
>
35+
> 本工具的字符生成msdf贴图依赖于 [msdfgen](https://github.com/Chlumsky/msdfgen) 目前已经支持最新版本(1.12.1)的多平台可执行程序
36+
>
37+
> **✨ 更新**:所有支持平台的 msdfgen 二进制文件现已预置在仓库并通过 npm 分发,避免 GitHub 流量限制和下载失败。安装时不会自动下载。
38+
> 如需要手动下载更新,请参阅 [MSDFGEN_INSTALL.md](./docs/MSDFGEN_INSTALL.cn.md)
39+
>
40+
> 在 macOS 上,安装器会自动处理安全限制(移除隔离属性、代码签名等) 详见 [MACOS_SECURITY.md](./docs/MACOS_SECURITY.cn.md)
41+
>
42+
43+
安装完成后,直接在控制台运行 `msdf-bmfont` 生成字体文件。
44+
输入 `msdf-bmfont --help` 查看详细用法。
45+
46+
![控制台演示](https://raw.githubusercontent.com/soimy/msdf-bmfont-xml/master/assets/console-demo.gif)
47+
48+
### 用法
49+
50+
```bash
51+
Usage: msdf-bmfont [options] <font-file>
52+
53+
Creates a BMFont compatible bitmap font of signed distance fields from a font file
54+
55+
Options:
56+
-V, --version 输出版本号
57+
-f, --output-type <format> 字体文件格式: xml(默认) | json | txt (默认: "xml")
58+
-o, --filename <atlas_path> 字体纹理文件名(默认: 字体名称)
59+
字体文件名始终设为字体名称
60+
-s, --font-size <fontSize> 生成纹理的字体大小(默认: 42)
61+
-i, --charset-file <charset> 从文本文件指定字符集
62+
-m, --texture-size <w,h> 输出纹理图集大小(默认: [2048,2048])
63+
-p, --texture-padding <n> 字形间距(默认: 1)
64+
-b, --border <n> 字形与边缘的空间(默认: 0)
65+
-r, --distance-range <n> SDF 距离范围(默认: 4)
66+
-t, --field-type <type> msdf(默认) | sdf | psdf (默认: "msdf")
67+
-d, --round-decimal <digit> 输出字体文件的小数位数(默认: 0)
68+
-v, --vector 生成 SVG 矢量文件用于调试
69+
-u, --reuse [file.cfg] 保存/创建配置文件以复用设置(默认: false)
70+
--smart-size 图集自动缩小为最小正方形
71+
--pot 图集尺寸为 2 的幂
72+
--square 图集尺寸为正方形
73+
--rot 打包时允许 90 度旋转
74+
--rtl 使用 RTL(阿拉伯/波斯语)字符修正
75+
-h, --help 输出帮助信息
76+
```
77+
78+
### CLI 示例
79+
80+
生成带 ASCII 字符集、字体大小 42、spread 3、最大纹理尺寸 512x256、间距 1,并保存配置文件的多通道距离场字体图集:
81+
82+
```bash
83+
msdf-bmfont --reuse -o path/to/atlas.png -m 512,256 -s 42 -r 3 -p 1 -t msdf path/to/font.ttf
84+
```
85+
86+
将生成三个文件:`atlas.0.png` `atlas.0.cfg``font.fnt`,如下为最小 pot 尺寸(256x256)的图集:
87+
88+
![Atlas0](https://raw.githubusercontent.com/soimy/msdf-bmfont-xml/master/assets/atlas.0.png)
89+
90+
如需用旧配置但更换字体,并生成单通道距离场及 SVG 图集:
91+
92+
```bash
93+
msdf-bmfont -v -u path/to/atlas.0.cfg -t sdf -p 0 -r 8 path/to/anotherfont.ttf
94+
```
95+
96+
将得到新的 `atlas.0.png`,追加了新字体:
97+
98+
![Atlas1](https://raw.githubusercontent.com/soimy/msdf-bmfont-xml/master/assets/atlas.1.jpg)
99+
100+
不满意风格?SVG 图集也可用!
101+
102+
![svg](https://raw.githubusercontent.com/soimy/msdf-bmfont-xml/master/assets/svg.png)
103+
104+
还可以用图形编辑器为输出图集添加特效:
105+
106+
![final](https://raw.githubusercontent.com/soimy/msdf-bmfont-xml/master/assets/atlas.2.jpg)
107+
108+
## 作为模块安装
109+
110+
```bash
111+
npm install msdf-bmfont-xml
112+
```
113+
114+
### 模块用法示例
115+
116+
将距离场和字体数据写入磁盘:
117+
118+
```js
119+
const generateBMFont = require('msdf-bmfont-xml');
120+
const fs = require('fs');
121+
122+
generateBMFont('Some-Font.ttf', (error, textures, font) => {
123+
if (error) throw error;
124+
textures.forEach((texture, index) => {
125+
fs.writeFile(texture.filename, texture.texture, (err) => {
126+
if (err) throw err;
127+
});
128+
});
129+
fs.writeFile(font.filename, font.data, (err) => {
130+
if (err) throw err;
131+
});
132+
});
133+
```
134+
135+
自定义字符集生成单通道距离场:
136+
137+
```js
138+
const generateBMFont = require('msdf-bmfont');
139+
140+
const opt = {
141+
charset: 'ABC.ez_as-123!',
142+
fieldType: 'sdf'
143+
};
144+
generateBMFont('Some-Font.ttf', opt, (error, textures, font) => {
145+
...
146+
});
147+
```
148+
149+
### API
150+
151+
#### `generateBMFont(fontPath | fontBuffer, [opt], callback)`
152+
153+
根据 `fontPath``fontBuffer` 指定的字体渲染位图字体,可选参数 `opt`,完成后触发 `callback`
154+
155+
参数说明:
156+
157+
- `outputType` (String)
158+
- 输出字体文件类型,默认 `xml`
159+
- `xml` 标准 BMFont .fnt 文件,广泛支持
160+
- `json` 兼容 [Hiero](https://github.com/libgdx/libgdx/wiki/Hiero) 的 JSON 文件
161+
- `filename` (String)
162+
- 字体文件和图集文件名,若省略则用字体名称。若字体为 Buffer,必填。
163+
- `charset` (String|Array)
164+
- 包含在位图字体中的字符,默认所有 ASCII 可打印字符
165+
- `fontSize` (Number)
166+
- 生成距离场的字体大小,默认 `42`
167+
- `textureSize` (Array[2])
168+
- 输出纹理尺寸,通常为 2 的幂,默认 `[512, 512]`
169+
- `texturePadding` (Number)
170+
- 字形间距,默认 `2`
171+
- `border` (Number)
172+
- 字形与边缘空间,默认 `0`
173+
- `fieldType` (String)
174+
- 距离场类型,默认 `msdf`,可选:
175+
- `msdf` 多通道距离场
176+
- `sdf` 单通道距离场
177+
- `psdf` 单通道伪距离场
178+
- `distanceRange` (Number)
179+
- 距离场范围宽度,默认 `3`
180+
- `roundDecimal` (Number)
181+
- 输出字体度量的小数位数,推荐 `xml` 输出时用 `0`
182+
- `vector` (Boolean)
183+
- 输出 SVG 矢量文件用于调试,默认 `false`
184+
- `smart-size` (Boolean)
185+
- 图集自动缩小为最小正方形,默认 `false`
186+
- `pot` (Boolean)
187+
- 图集尺寸为 2 的幂,默认 `false`
188+
- `square` (Boolean)
189+
- 图集尺寸为正方形,默认 `false`
190+
- `rot` (Boolean)
191+
- 打包时允许 90 度旋转,默认 `false`
192+
- `rtl` (Boolean)
193+
- 使用 RTL(阿拉伯/波斯语)字符修正,默认 `false`
194+
195+
`callback` 参数为 `(error, textures, font)`
196+
197+
- `error` 成功时为 null/undefined
198+
- `textures` 纹理图集对象数组
199+
- `textures[index].filename` 图集文件名
200+
- `textures[index].texture` PNG 图像 Buffer
201+
- `font` BMFont 数据对象
202+
- `font.filename` 字体文件名
203+
- `font.data` 字体数据字符串(xml/json)
204+
205+
`opt` 可选,第二参数可直接传 `callback`
206+
207+
## License
208+
209+
MIT,详见 [LICENSE.md](http://github.com/Jam3/xhr-request/blob/master/LICENSE.md)

0 commit comments

Comments
 (0)