Skip to content

Read hdmx device records at their padded size - #396

Open
Likheet wants to merge 1 commit into
foliojs:masterfrom
Likheet:hdmx-record-padding
Open

Likheet wants to merge 1 commit into
foliojs:masterfrom
Likheet:hdmx-record-padding

Conversation

@Likheet

@Likheet Likheet commented Oct 11, 2026

Copy link
Copy Markdown

Each hdmx device record is padded to sizeDeviceRecord bytes (a multiple of four), but the struct only read 2 + numGlyphs bytes per record. When numGlyphs + 2 is not a multiple of four, every record after the first was read from the wrong offset.

With Arial (4651 glyphs, 3 bytes of padding), font.hdmx.records.map(r => r.pixelSize) gave 11, 0, 6, 9, 6, 15, ... instead of 11, 12, 13, 15, 16, 17, ....

This skips the padding after each record. Spec: https://learn.microsoft.com/typography/opentype/spec/hdmx

None of the fonts in test/data has an hdmx table, so the test builds a small font in memory. npm test passes and the changed files are Prettier-clean.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused parser fix matches the record format and includes adequate regression coverage.

0 open findings

What changed in this PR

Fixes hdmx parsing so padded device records remain correctly aligned.

Changes:

  • Skips per-record padding using sizeDeviceRecord.
  • Adds an in-memory regression test.
  • Documents the fix in the changelog.
File Description
src/​tables/​hdmx.js Consumes record padding.
test/​device_metrics.js Tests padded records.
CHANGELOG.md Records the fix.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

2 participants