Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ jobs:
permissions:
contents: write
steps:
- uses: actions/checkout@v4

- name: Download artifacts
uses: actions/download-artifact@v4
with:
Expand All @@ -89,13 +91,42 @@ jobs:
mkdir -p release
find dist -maxdepth 3 -type f -print -exec cp {} release/ \;

- name: Package release archives
run: |
set -euo pipefail

version="${GITHUB_REF_NAME}"
mkdir -p packaged

for file in release/*; do
base="$(basename "${file}")"
stem="${base%.exe}"
stage_dir="$(mktemp -d)"

cp "${file}" "${stage_dir}/"
cp README.md LICENSE THIRD_PARTY_NOTICES.md "${stage_dir}/"

if [[ "${base}" == *.exe ]]; then
asset="packaged/${stem}-${version}.zip"
(
cd "${stage_dir}"
zip -q -r "${GITHUB_WORKSPACE}/${asset}" .
)
else
asset="packaged/${stem}-${version}.tar.gz"
tar -C "${stage_dir}" -czf "${asset}" .
fi

rm -rf "${stage_dir}"
done

- name: Publish GitHub release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: ${{ github.ref_name }}
generate_release_notes: true
fail_on_unmatched_files: true
files: release/*
files: packaged/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.vscode/*
out_font/*
*.xnb
*.fnt
/ra2fnt
/ra2fnt.exe
Expand Down
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ scripts\build-release.bat v1.0.0

## Usage

Export `.fnt` to PNG set:
Export `.fnt` or `.xnb` to PNG set:

```bash
./ra2fnt export -in game.fnt -out out_font
```

```bash
./ra2fnt export -in SpriteFont.xnb -out out_font
```

Export with integer pixel scaling (for easier editing):

```bash
Expand All @@ -53,6 +57,12 @@ Create `.fnt` from PNG set:
./ra2fnt create -in out_font -out rebuilt.fnt
```

Create an experimental LZ4-compressed `SpriteFont XNB v5` font file for [`xna-cncnet-client`](https://github.com/CnCNet/xna-cncnet-client) from PNG set:

```bash
./ra2fnt create -in out_font -out SpriteFont.xnb --format cncnet-spritefont
```

Create without glyph deduplication:

```bash
Expand All @@ -78,7 +88,7 @@ If `out` directory already exists, `export` asks for confirmation before deletin

## Export format

`export` writes only PNG files grouped by Unicode ranges:
`export` reads `.fnt` and `cncnet-spritefont` `.xnb` files, and writes only PNG files grouped by Unicode ranges:

```text
out_font/
Expand Down Expand Up @@ -107,7 +117,7 @@ Zero-width glyphs are listed only in `metadata.json` (`symbol_width`).

## Create behavior

`create` reconstructs a `.fnt` from PNG files in the input directory:
`create` reconstructs a font file from PNG files in the input directory:

- PNG files are discovered recursively (subdirectory names are ignored by parser).
- Files must be named as fixed-length hex codepoints (for example `0x0041.png`, `0x30A1.png`).
Expand All @@ -120,6 +130,9 @@ Zero-width glyphs are listed only in `metadata.json` (`symbol_width`).
- `ideograph_width` is taken from `metadata.json`.
- `scale` is taken from `metadata.json`; when `scale > 1`, PNG dimensions are downscaled by this factor during `create` (back to normal font size).
- Identical glyphs are deduplicated, so multiple codepoints can reference the same symbol index.
- Output format is selected by `--format`:
- `fnt` (default): writes Westwood Unicode BitFont `.fnt`
- `cncnet-spritefont`: writes an experimental LZ4-compressed `SpriteFont XNB v5` `.xnb` font file for [`xna-cncnet-client`](https://github.com/CnCNet/xna-cncnet-client)
- Use `--no-dedup` to disable deduplication.
- Unicode table is rebuilt from filenames (`0xXXXX` -> symbol index in sorted codepoint order).

Expand All @@ -141,3 +154,12 @@ Because unicode mapping order/tail bytes are rebuilt, the resulting `.fnt` is no
- At least one non-zero-width PNG is required to infer `symbol_height`.
- Zero-width glyphs are represented only in `metadata.json` and have no PNG files.
- Unicode table order is rebuilt from sorted codepoints.
- `cncnet-spritefont` always writes LZ4-compressed `SpriteFont XNB v5`.
- `cncnet-spritefont` is an experimental feature.
- When `?` is present, `cncnet-spritefont` writes it as `defaultChar` fallback.
- `export` preserves PNG glyph images exactly when round-tripping `out_font -> .xnb -> out_font`.

## License

- Project license: `MIT` (see `LICENSE`)
- Third-party notices: `THIRD_PARTY_NOTICES.md`
73 changes: 73 additions & 0 deletions THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Third-Party Notices

This project is licensed under the MIT License. It also includes or depends on third-party components under their own licenses.

## `github.com/pierrec/lz4/v4`

- Project: `github.com/pierrec/lz4/v4`
- License: `BSD-3-Clause`
- Source: `https://github.com/pierrec/lz4`

License text:

```text
Copyright (c) 2015, Pierre Curto
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of xxHash nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```

## `github.com/secDre4mer/lzx`

- Project: `github.com/secDre4mer/lzx`
- License: `MIT`
- Source: `https://github.com/secDre4mer/lzx`

License text:

```text
MIT License

Copyright (c) 2025 secDre4mer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
5 changes: 4 additions & 1 deletion cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"language": "en",
"allowCompoundWords": true,
"useGitignore": true,
"words": []
"words": [
"cncnet",
"dedup"
]
}
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
module ra2fnt

go 1.22

require (
github.com/pierrec/lz4/v4 v4.1.26
github.com/secDre4mer/lzx v0.0.0-20250826110518-fedea00d45a5
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github.com/pierrec/lz4/v4 v4.1.26 h1:GrpZw1gZttORinvzBdXPUXATeqlJjqUG/D87TKMnhjY=
github.com/pierrec/lz4/v4 v4.1.26/go.mod h1:EoQMVJgeeEOMsCqCzqFm2O0cJvljX2nGZjcRIPL34O4=
github.com/secDre4mer/lzx v0.0.0-20250826110518-fedea00d45a5 h1:kmHE1qapEHsBpWXyeWR+UCdtZHvSPgYX7VmMeGqnVQI=
github.com/secDre4mer/lzx v0.0.0-20250826110518-fedea00d45a5/go.mod h1:oJAzpWn0j/MLx5UEIq5h9eyWfkk0KEnJ2/Js1oviEzQ=
Loading