Skip to content

Fix CID Mac cmap: suppress empty stub, fix -cl off-by-one - #1848

Open
skef wants to merge 3 commits into
adobe-type-tools:developfrom
skef:fix-cid-mac-cmap
Open

Fix CID Mac cmap: suppress empty stub, fix -cl off-by-one#1848
skef wants to merge 3 commits into
adobe-type-tools:developfrom
skef:fix-cid-mac-cmap

Conversation

@skef

@skef skef commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

Two fixes for the Macintosh cmap subtable in CID-keyed font builds:

  • Suppress empty Mac cmap stub when no Mac CMap resource is provided via -cm. Previously makeCIDMaccmap() was called unconditionally, emitting a useless platform-1 subtable mapping only .notdef. Now the subtable is only created when -cm data is available.
  • Fix -cl off-by-one: apply the spec-required +1 to the user's value at parse time. The internal API convention (documented in hotconv.h:380-381) is "language ID + 1, or 0 if unspecific." All other paths honor this, but -cl passed through raw. So -cl 33 (Simplified Chinese) produced language=33 (decodes as ID 32 per spec); correct value is 34.
  • Fix comment typo: -cl case said "script id", should be "language id".

Fixes #1842

Questions for reviewer

  1. Backwards compatibility of suppression: Could any existing CID workflow depend on the empty platform-1 stub being present? The spec discourages Mac cmap subtables and the stub maps nothing useful, but it's a behavior change. The warning message is retained (with updated text) so users will know what changed.

  2. Should the warning be downgraded to INFO? The reporter notes it's confusing to warn about a missing resource for a subtable the user never asked for. Now that we suppress the subtable, the warning is purely informational ("we didn't make a Mac cmap because you didn't give us Mac CMap data").

  3. Should -cl document the change? The fix means existing scripts passing -cl values will now get different (correct) output. Anyone who was compensating by passing the already-incremented value will now be off by one in the other direction. Probably fine since the old behavior was simply wrong, but worth noting.

Test plan

  • Verified the change compiles
  • Existing test suite
  • Manual test with a CID font build with/without -cm

🤖 Generated with Claude Code

Two fixes for the Macintosh cmap subtable in CID-keyed font builds:

1. Suppress the empty Mac cmap subtable when no Mac CMap resource is
   provided via -cm. Previously makeCIDMaccmap() was called
   unconditionally, emitting a useless platform-1 subtable that mapped
   only .notdef. The OT spec discourages platform-1 subtables, and
   emitting an empty one just generates a confusing warning. Now the
   subtable is only created when -cm data is actually available.

2. Apply the spec-required +1 to the -cl value. The internal API
   convention (documented in hotconv.h) stores the Mac language field
   as "language ID + 1, or 0 if unspecific." All internal paths
   (codepage heuristics, CID fallback) honor this, but -cl passed the
   user's value through verbatim. So -cl 33 (Simplified Chinese)
   produced language=33 (which decodes as ID 32 per spec); the correct
   value is 34. The fix applies +1 at parse time for values >= 0,
   preserving -1 as the HOT_CMAP_UNKNOWN sentinel.

Also fixes comment typo: -cl case said "script id", should be
"language id".

Fixes adobe-type-tools#1842

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@skef
skef force-pushed the fix-cid-mac-cmap branch from 53a0071 to 20fd6e4 Compare July 7, 2026 02:20
skef and others added 2 commits July 6, 2026 19:48
The four expected TTX files that test -cl all had the old (wrong)
language values. Now that -cl applies the spec-required +1, bump each:
  - t1pfa-cmap_cl2.ttx: language 2 → 3
  - ufo2-cmap_cl5.ttx: language 5 → 6
  - ufo3-cmap_cl5.ttx: language 5 → 6
  - cidfont-cmap_cl3.ttx: language 3 → 4

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@skef
skef requested a review from frankrolf July 7, 2026 03:07
@skef

skef commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

@frankrolf what do you think of this?

@frankrolf

Copy link
Copy Markdown
Member

Perhaps @hatchzo is more qualified to make an assessment here?

@hatchzo

hatchzo commented Jul 8, 2026

Copy link
Copy Markdown

Regarding -cl, I do not think this option is used very often in Adobe’s CJK fonts or in Japanese CID-keyed fonts.

For Adobe-Japan1 ROS-based fonts, an actual Macintosh cmap subtable is included. However, for fonts with the Adobe-Identity-0 ROS, the -cs option creates a stub subtable. This has continued from Kazuraki, Adobe’s first Adobe-Identity-0 font, through today’s Source Han Sans and Momochidori. At the time, Ken Lunde wrote in a blog post that although he recognized that the Macintosh cmap subtable was no longer needed on OS X, he included a stub table for heuristic reasons.

https://ccjktype.fonts.adobe.com/2013/06/ai0-and-heuristics.html

I assume this may have been done with legacy compatibility in mind, such as environments that check for the presence of Macintosh cmap subtable, but I am not sure what the specific impact is.

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.

[addfeatures] Macintosh cmap subtable: unconditional empty stub for CID fonts; -cl value is written without the spec-required +1

3 participants