Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fonts sometimes have an incorrect cmap subtable #1252

Closed
eiswind opened this issue Apr 27, 2023 · 12 comments · Fixed by #1356
Closed

Fonts sometimes have an incorrect cmap subtable #1252

eiswind opened this issue Apr 27, 2023 · 12 comments · Fixed by #1356
Assignees

Comments

@eiswind
Copy link

eiswind commented Apr 27, 2023

I found that when fonts are embedded, they are not always embedded the same way.
Sometimes the font is correct, sometimes it has an incorrect cmap subtable.

Browsers seem to ignore that but other tools I use to render the svg cannot handle that.

I'll attach two files, one (injection) has the font correctly, the other (boot) one is broken.

01_boot_d2
01_injection_d2

@cyborg-ts cyborg-ts added this to D2 Apr 27, 2023
@mikeday
Copy link

mikeday commented Apr 27, 2023

The issue here appears to be that the cmap subtable (format 4) has an odd length count?

@alixander
Copy link
Collaborator

oh interestingg, we do roll out own cmap font thing for optimized subsetting. very possible to have missed something.

will test with the "Allsorts" that @mikeday mentioned in his other issue.

other tools I use to render the svg cannot handle that

@eiswind what's a tool we can test on to confirm we have the right fix?

@mikeday
Copy link

mikeday commented Apr 28, 2023

I think it might be this line 611 of generateCMAPTable in utf8fontfile.go in gofpdf:

length := 16 + (8 * segCount) + (numSymbols + 1)

The length field is the size in bytes of the cmap format 4 subtable as defined here:

https://learn.microsoft.com/en-us/typography/opentype/spec/cmap#format-4-segment-mapping-to-delta-values

Since this subtable is entirely comprised of 16-bit values it is impossible for it to be odd; the 16 + (8 * segCount) part is correct but the numSymbols + 1 is highly suspect!

@mikeday
Copy link

mikeday commented Apr 28, 2023

It appears that the original PHP fpdf does not have this bug, it just takes the length of the subtable in bytes directly:

$data .= pack('nnn', 4, 6+strlen($cmap), 0); // format, length, language

@eiswind
Copy link
Author

eiswind commented Apr 28, 2023

@alixander please try prince xml https://www.princexml.com/
@mikeday thanks for your assistance!

@eiswind
Copy link
Author

eiswind commented May 28, 2023

Are there chances that this will get fixed? Sadly I don't get what going on there, so I can't provide a patch.

@alixander
Copy link
Collaborator

@berniexie can you look into this on Tuesday please?

@berniexie
Copy link
Contributor

@eiswind can you give me the exact d2 code of the failed Spring Boot example

@alixander
Copy link
Collaborator

can you not reproduce with some simple "asdf" text? @berniexie

@berniexie
Copy link
Contributor

@alixander not with the latest version of d2. I suspect the issue may already fixed but I wanted to confirm with the exact case that can generate an invalid subset.

@alixander
Copy link
Collaborator

how would it have been fixed? i don't think there's any PR that touched this part since the issue was created

@berniexie
Copy link
Contributor

Nevermind. I was able to reproduce the issue with an example.

@berniexie berniexie linked a pull request Jun 1, 2023 that will close this issue
@github-project-automation github-project-automation bot moved this to Done in D2 Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

5 participants
@mikeday @eiswind @alixander @berniexie and others