Skip to content
Open
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
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Changelog

## 1.3.1

- Fix: removed an outdated baseline/y-offset correction in `adjustFont.ts` that was misaligning generated fonts (affects fonts generated with v1.2.0 through v1.3.0).

## 1.3.0

- Multipage atlas generation fix
- Added `textureSize` override

## 1.2.1

- Pinned `opentype.js` to `1.3.4` to fix a `loadSync` issue in newer versions

## 1.2.0

- Updated `msdf-bmfont-xml` to `^2.8.0`

## 1.1.1

- Made `presets` key optional in `<font>.config.json`

## 1.1.0

- Charset configuration with presets support

## 1.0.2

- Fixed header image URL in README for the npm page

## 1.0.0

- Initial npm publish, library exports added
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lightningjs/msdf-generator",
"version": "1.3.0",
"version": "1.3.1",
"description": "Converts font files (.ttf, .otf, .woff, .woff2) to SDF format for Lightning 3's renderer, with added font metrics generation for SDF and Canvas Web fonts",
"type": "module",
"exports": {
Expand Down
26 changes: 2 additions & 24 deletions src/adjustFont.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,8 @@ import type { SdfFontInfo } from "./genFont.js";
const metricsSubDir = 'metrics';

/**
* Adjusts the font data for the generated fonts.
*
* @remarks
* A bug in the msdf-bmfont-xml package causes both the baseline and y-offsets
* of every character to be incorrect which results in the text being rendered
* out of intended alignment. This function corrects that data.
*
* See the following GitHub issue for more information:
* https://github.com/soimy/msdf-bmfont-xml/pull/93
* Extracts font metrics from the source font and writes them into the
* generated JSON and a separate metrics file.
*
* @param fontInfo
*/
Expand All @@ -46,21 +39,6 @@ export async function adjustFont(fontInfo: SdfFontInfo) {
opentype.load(fontInfo.fontPath),
]);
const json = JSON.parse(jsonFileContents);
const distanceField = json.distanceField.distanceRange;
/**
* `pad` used by msdf-bmfont-xml
*
* (This is really just distanceField / 2 but guarantees a truncated integer result)
*/
const pad = (distanceField >> 1);

// Remove 1x pad from the baseline
json.common.base = json.common.base - pad;

// Remove 2x pad from the y-offset of every character
for (const char of json.chars) {
char.yoffset = char.yoffset - pad - pad;
}

const fontMetrics = {
ascender: font.tables.os2!.sTypoAscender as number,
Expand Down