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

Windows 10: PDF is not rendered correctly #16839

Closed
mikhailbartashevich opened this issue Aug 16, 2023 · 5 comments · Fixed by #17253
Closed

Windows 10: PDF is not rendered correctly #16839

mikhailbartashevich opened this issue Aug 16, 2023 · 5 comments · Fixed by #17253

Comments

@mikhailbartashevich
Copy link

mikhailbartashevich commented Aug 16, 2023

Attach (recommended) or Link to PDF file here:
250125_010823.pdf

Configuration:

  • Web browser and its version:
    Chrome/Firefox
  • Operating system and its version:
    Windows 10
  • PDF.js version:
    Actually used react-pdf, so tested 3.6 and demo version
  • Is a browser extension:
    No

Steps to reproduce the problem:

  1. Upload the file to https://mozilla.github.io/pdf.js/web/viewer.html using Windows 10
  2. PDF is rendered partially

What is the expected behavior? (add screenshot)
Screenshot 2023-08-16 at 08 25 42

What went wrong? (add screenshot)
250125_010823 (1) pdf 2023-08-16 08-26-52

Link to a viewer (if hosted on a site other than mozilla.github.io/pdf.js or as Firefox/Chrome extension):
https://mozilla.github.io/pdf.js/web/viewer.html

@Snuffleupagus Snuffleupagus changed the title Windows 10: PDF is not rendered correctly in demo https://mozilla.github.io/pdf.js/web/viewer.html Windows 10: PDF is not rendered correctly Aug 16, 2023
@Snuffleupagus
Copy link
Collaborator

Snuffleupagus commented Aug 16, 2023

There seems to be something wrong with the F0 (dict) [id: 4, gen: 0] font, given the console log:

PDF 335087d4e029494fb286566728537342 [1.5 FastReport.NET / FastReport] (PDF.js: 3.10.80 [690b87389]) [viewer.js:1518:13](resource://pdf.js/web/viewer.js)
Warning: TT: more functions defined than expected [pdf.worker.js:970:13](resource://pdf.js/build/pdf.worker.js)

Here both maxFunctionDefs and maxSizeOfInstructions become zero, which might be related to the problem:

pdf.js/src/core/fonts.js

Lines 2696 to 2711 in c72cb54

let maxFunctionDefs = 0;
let maxSizeOfInstructions = 0;
if (version >= 0x00010000 && tables.maxp.length >= 22) {
// maxZones can be invalid
font.pos += 8;
const maxZones = font.getUint16();
if (maxZones > 2) {
// reset to 2 if font has invalid maxZones
tables.maxp.data[14] = 0;
tables.maxp.data[15] = 2;
}
font.pos += 4;
maxFunctionDefs = font.getUint16();
font.pos += 4;
maxSizeOfInstructions = font.getUint16();
}


Configuration:
* Web browser and its version:
* Operating system and its version:
* PDF.js version:
* Is a browser extension:

Please actually fill out this part of the ISSUE_TEMPLATE when reporting an issue!

@calixteman
Copy link
Contributor

I can't reproduce the issue on mac with either Firefox or Chrome.

@griZZZly8
Copy link

griZZZly8 commented Oct 18, 2023

Same for me. Provided pdf is not rendered correctly on Win 10. Any updates regarding this issue?

@Lyumih

This comment was marked as duplicate.

@calixteman
Copy link
Contributor

The maxp table for the non-rendered font has a version number equals to 0x100 which is very likely wrong:
https://learn.microsoft.com/en-us/typography/opentype/spec/maxp
There is no issue on Mac or Linux.

@calixteman calixteman self-assigned this Nov 10, 2023
jfkthame added a commit to jfkthame/ots that referenced this issue Nov 10, 2023
If the version number is less than 0x00010000 (e.g. an example reported at
mozilla/pdf.js#16839 apparently has 0x0100),
it will be treated as version 0.5 and only the num_glyphs field is kept.

However, this can prevent the font working on Windows, which apparently
requires the full maxp table for truetype fonts.

So if the version number was bad, but there is in fact enough data to
parse as version 1.0, let's try correcting it to 1.0 rather than 0.5.
jfkthame added a commit to jfkthame/ots that referenced this issue Nov 10, 2023
If the version number is less than 0x00010000 (e.g. an example reported at
mozilla/pdf.js#16839 apparently has 0x0100),
it will be treated as version 0.5 and only the num_glyphs field is kept.

However, this can prevent the font working on Windows, which apparently
requires the full maxp table for truetype fonts.

So if the version number was bad, but there is in fact enough data to
parse as version 1.0, let's try correcting it to 1.0 rather than 0.5.
jfkthame added a commit to jfkthame/ots that referenced this issue Nov 10, 2023
If the version number is less than 0x00010000 (e.g. an example reported at
mozilla/pdf.js#16839 apparently has 0x0100),
it will be treated as version 0.5 and only the num_glyphs field is kept.

However, this can prevent the font working on Windows, which apparently
requires the full maxp table for truetype fonts.

So if the version number was bad, but there is in fact enough data to
parse as version 1.0, let's try correcting it to 1.0 rather than 0.5.

Also make the max_zones fixup more general, as the example font from the
above issue has max_zones=512(!). Correcting it to 2 should be harmless.
jfkthame added a commit to jfkthame/ots that referenced this issue Nov 10, 2023
If the version number is less than 0x00010000 (e.g. an example reported at
mozilla/pdf.js#16839 apparently has 0x0100),
it will be treated as version 0.5 and only the num_glyphs field is kept.

However, this can prevent the font working on Windows, which apparently
requires the full maxp table for truetype fonts.

So if the version number was bad, but there is in fact enough data to
parse as version 1.0, let's try correcting it to 1.0 rather than 0.5.

Also make the max_zones fixup more general, as the example font from the
above issue has max_zones=512(!). Correcting it to 2 should be harmless.
jfkthame added a commit to jfkthame/ots that referenced this issue Nov 11, 2023
If the version number is not explicitly v0.5 (0x00005000), try to read
it as v1.0. (The version field will be corrected to one of the valid
versions during serialization.)

This handles cases where the table was intended to be v1.0 (for a font
with TrueType data), but the version field was set incorrectly (e.g. to
0x00000100, as seen in mozilla/pdf.js#16839).

Also make the max_zones fixup more general, as the example font from the
above issue has max_zones=512(!). Correcting it to 2 should be harmless.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants