Skip to content

Reverse for CMAP - #159

Merged
Pomax merged 3 commits into
mainfrom
reverse
Jul 20, 2026
Merged

Pomax merged 3 commits into
mainfrom
reverse

Conversation

@RoelN

@RoelN RoelN commented Jul 14, 2026 •

Copy link
Copy Markdown
Collaborator

I figured I'd give this a shot, in order to move #92 along. But I'm scratching my head checking the current implementations. @Pomax the format 6 test is failing. It looks it's returning different data than the format 4 test. I think the format 4 one is correct. Could you verify?

RoelN added 2 commits July 12, 2026 22:00
The unicode value is not a string here -- figure out if this is expected
or what happens for glpyh 3 in format 6
@Pomax

Pomax commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Quick check:

result (4) is: { code: 65, unicode: 'A' }
  ✔ reverse works for format 4 (1.9911ms)
result (6) is: 65
  ✖ reverse works for format 6 (4.2614ms)

Format 4 has the following code:

  reverse(glyphID) {
    let s = this.segments.find((v) => v.glyphIDs.includes(glyphID));
    if (!s) return {};
    const code = s.startCode + s.glyphIDs.indexOf(glyphID);
    return { code, unicode: String.fromCodePoint(code) };
  }

Format 6 has this, instead:

  reverse(glyphID) {
    let pos = this.glyphIdArray.indexOf(glyphID);
    if (pos > -1) return this.firstCode + pos;
  }

Checking the other tables:

0: not implemented
2: not implemented
4: returns { code:number, unicode:string }
6: returns a number
8: not implemented
10: not implemented
12: returns { code:number, unicode:string }
13: not implemented
14: not implemented

So we probably just want to update the code for subtable 6 to yield the same output as 4/12

@RoelN

RoelN commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator Author

Right, so we do want { code:number, unicode:string } everywhere, starting with 6. Then I know what to do.

Thanks for the sanity check!

@Pomax

Pomax commented Jul 15, 2026

Copy link
Copy Markdown
Owner

The only question is whether we want to keep calling it unicode, since not all tables are unicody, or keep it that anyway since ultimate all text in JS context is unicode text.

@RoelN
RoelN marked this pull request as ready for review July 18, 2026 09:13
@RoelN

RoelN commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator Author

@Pomax I'm fine with unicode! I updated the reverse lookup for format 6 and it now returns the data in the same format. I figure if this gets your seal of approval, we merge this, and tackle the others in a separate PR.

How do you figure the urgency? Anecdotal, I only ever see format 4 and 6 in the wild.

@RoelN
RoelN requested a review from Pomax July 18, 2026 09:17
@Pomax

Pomax commented Jul 20, 2026 •

Copy link
Copy Markdown
Owner

I've seen plenty of 12 but that's really just "4, with more bits". There were some special fonts that used 13 (adobe's blank font I believe uses 13 to say "yeah, no everything resolves to this exact same id" but it's a been a while) and 14 (can't remember which one though O_O)

@Pomax
Pomax merged commit 3cdda48 into main Jul 20, 2026
1 check passed
@Pomax
Pomax deleted the reverse branch July 20, 2026 21:08
@Pomax

Pomax commented Jul 20, 2026

Copy link
Copy Markdown
Owner

merged, we can tackle the rest in a separate PR but low urgency I would say: if there's some time, cool, if not, also cool =)

@Pomax

Pomax commented Jul 20, 2026

Copy link
Copy Markdown
Owner

v3.0.3 published

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