Skip to content

Preserve BDF/PCF FONT_VERSION in bitmap font metadata - #5935

Merged
iorsh merged 8 commits into
fontforge:masterfrom
snowyukitty:fix/preserve-bdf-font-version
Oct 27, 2026
Merged

iorsh merged 8 commits into
fontforge:masterfrom
snowyukitty:fix/preserve-bdf-font-version

Conversation

@snowyukitty

@snowyukitty snowyukitty commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1045

Opening a standalone BDF or PCF preserves a nonempty string FONT_VERSION in the font's version metadata. Importing a bitmap strike into an existing font leaves its version unchanged. Missing, empty, or line-breaking values retain the existing default.

The shared TTF and WOFF export code is unchanged. For an imported label whose parsed numeric value cannot fit a signed 16.16 revision, the importer keeps the previous SFNT revision of 1.0 using the existing explicit sfntRevision field. The label itself is preserved, including through SFD saves. If the label is later edited, the explicit revision can be cleared with font.sfntRevision = None. WOFF retains its existing numeric-label conversion and 16-bit major/minor representation; no WOFF version override is added. Type 1 output streams long version strings and quotes parentheses and backslashes.

Regression tests cover BDF/PCF opening, SFD round-trips, existing-font import, default/atom/Latin-1 values, PCF CR/LF values, long quoted Type 1 output, SFNT boundary/date/exponent/hex values, editing an explicit revision, and a UTF-8-prefixed WOFF version.

Updated to the current master CI fixes with a merge that preserves the branch history. Validation: a headless Linux build and complete CTest suite (129 passed, 23 skipped, zero failures). Targeted UBSan checks also passed in C and German numeric locales. Unrelated existing signed-reader shifts were excluded only in the diagnostic build. No Windows or GUI validation is claimed.

@iorsh

iorsh commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

This PR has too much useless code. Please limit it to fixing the actual bug.

@iorsh

iorsh commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Binary blob tests/fonts/font-version.pcf recreated on my machine and verified with MD5 checksum f446741f201cd7c90cbd49887e5c3e0a, can be trusted.

Comment thread fontforge/tottf.c Outdated
double dval;
int val, mant;
while ( *pt && !isdigit(*pt) && *pt!='.' ) ++pt;
while ( *pt && !isdigit((unsigned char) *pt) && *pt!='.' ) ++pt;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the cast of *pt to unsigned char?

Comment thread fontforge/tottf.c Outdated
val = floor(dval);
mant = floor(65536.*(dval-val));
head->revision = (val<<16) | mant;
/* Keep the default if the version does not fit a signed 16.16 value. */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break reproducible builds for no good reason. Please revert.

Comment thread fontforge/woff.c Outdated
char *pt=sf->version;
char *end;
while ( *pt && !isdigit(*pt) && *pt!='.' ) ++pt;
while ( *pt && !isdigit((unsigned char) *pt) && *pt!='.' ) ++pt;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

@iorsh

iorsh commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Please rebase to the latest master to fix CI failures.

@snowyukitty

Copy link
Copy Markdown
Contributor Author

Updated in ca46887. I merged the current master for the CI fixes and reverted the sethead range guard and both isdigit casts. The SFNT fallback is now limited to standalone BDF/PCF import, while preserving the version label; tottf.c and woff.c match upstream. The local headless CTest suite passed: 129 passed, 23 skipped.

Comment thread fontforge/fvimportbdf.c
setlocale(LC_NUMERIC,oldlocale);
free(oldlocale);
#else
locale_t tmplocale = NULL, oldlocale = NULL;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need only this branch of #ifdef. switch_to_c_locale() and switch_to_old_locale() already contain the hack, it will act as appropriate in both cases.

@iorsh iorsh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@snowyukitty

Copy link
Copy Markdown
Contributor Author

Updated to use the shared locale helpers in 97721c6. All eight CI checks have passed. Thanks for reviewing!

@iorsh
iorsh merged commit 2d25103 into fontforge:master Oct 27, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BDF FONT_VERSION XLFD Property Not Preserved in SBIT Conversion

2 participants