1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 14:48:08 +02:00
Commit graph

19983 commits

Author SHA1 Message Date
Jonas Jenwald
b26dc19392 Ensure that serializing of StructTree-data cannot fail during loading
I discovered that doing skip-cache re-reloading of https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf would *intermittently* cause (some of) the AnnotationLayers to break with errors printed in the console (see below).

In hindsight this bug is really obvious, however it took me quite some time to find it, since the `StructTreePage.prototype.serializable` getter will lookup various data and all of those cases can fail during loading when streaming and/or range requests are being used.

Finally, to prevent any future errors, ensure that the viewer won't break in these sort of situations.

```
Uncaught (in promise)
Object { message: "Missing data [19098296, 19098297)", name: "UnknownErrorException", details: "MissingDataException: Missing data [19098296, 19098297)", stack: "BaseExceptionClosure@resource://pdf.js/build/pdf.mjs:453:29\n@resource://pdf.js/build/pdf.mjs:456:2\n" }
viewer.mjs:8801:55

\#renderAnnotationLayer: "UnknownErrorException: Missing data [17552729, 17552730)". viewer.mjs:8737:15

Uncaught (in promise)
Object { message: "Missing data [17552729, 17552730)", name: "UnknownErrorException", details: "MissingDataException: Missing data [17552729, 17552730)", stack: "BaseExceptionClosure@resource://pdf.js/build/pdf.mjs:453:29\n@resource://pdf.js/build/pdf.mjs:456:2\n" }
viewer.mjs:8801:55
```
2024-11-01 17:43:59 +01:00
Jonas Jenwald
4e12906061 Move the various DOM-factories into their own files
- Over time the number and size of these factories have increased, especially the `DOMFilterFactory` class, and this split should thus aid readability/maintainability of the code.

 - By introducing a couple of new import maps we can avoid bundling the `DOMCMapReaderFactory`/`DOMStandardFontDataFactory` classes in the Firefox PDF Viewer, since they are dead code there given that worker-thread fetching is always being used.

 - This patch has been successfully tested, by running `$ ./mach test toolkit/components/pdfjs/`, in a local Firefox artifact-build.

*Note:* This patch reduces the size of the `gulp mozcentral` output by `1.3` kilo-bytes, which isn't a lot but still cannot hurt.
2024-11-01 13:31:28 +01:00
Tim van der Meij
06f3b2d0a6
Merge pull request #18983 from Snuffleupagus/api-FetchBuiltInCMap-FetchStandardFontData-async
Change the "FetchBuiltInCMap"/"FetchStandardFontData" message-handlers to be asynchronous
2024-10-31 20:30:11 +01:00
Jonas Jenwald
3ed438aef5
Merge pull request #18979 from Snuffleupagus/L10n-#elements-lazy-init
Don't initialize `L10n.#elements` eagerly since it's unused in MOZCENTRAL builds
2024-10-31 11:03:24 +01:00
Jonas Jenwald
7572382c7a Change the "FetchBuiltInCMap"/"FetchStandardFontData" message-handlers to be asynchronous
This way we can directly throw Errors, rather than having to "manually" return rejected Promises, which is ever so slightly shorter.

Also, since `useWorkerFetch` is always true in MOZCENTRAL builds these message-handlers should not be invoked there.
2024-10-31 09:29:11 +01:00
Jonas Jenwald
cdd4b052f9 Don't initialize L10n.#elements eagerly since it's unused in MOZCENTRAL builds
It's not necessary to manually start translation in the Firefox PDF Viewer, and doing so would even cause problems there (see issue 17142).
2024-10-30 15:20:44 +01:00
Jonas Jenwald
f013c39b9f
Merge pull request #18978 from Snuffleupagus/toHexUtil-simplify
Re-factor the `toHexUtil` helper (PR 17862 follow-up)
2024-10-29 17:10:36 +01:00
calixteman
f142fb8c28
Merge pull request #18972 from calixteman/refactor_highlight
[Editor] Refactor the free highlight stuff in order to be able to use the code for more general drawing
2024-10-29 17:09:03 +01:00
Jonas Jenwald
db1238aae3 Re-factor the toHexUtil helper (PR 17862 follow-up)
We can re-use the `hexNumbers` structure, since that allows us to directly lookup the hexadecimal values and shortens the code.
2024-10-29 16:35:44 +01:00
Jonas Jenwald
9870099e90
Merge pull request #18977 from Snuffleupagus/api-ReaderHeadersReady-simplify
Simplify the "ReaderHeadersReady" message-handler in the API
2024-10-29 15:46:31 +01:00
Calixte Denizet
5a9607b2ad [Editor] Refactor the free highlight stuff in order to be able to use the code for more general drawing
One goal is to make the code for drawing with the Ink tool similar to the one to free highlighting:
it doesn't really make sense to have so different ways to do almost the same thing.

When the zoom level is high, it'll avoid to create a too big canvas covering all the page which consume
more memory, makes the drawing very slow and the overall user xp pretty bad.

A second goal is to be able to easily implement more drawing tools where we would just have to implement
how to draw from the pointer coordinates.
2024-10-29 15:41:08 +01:00
Jonas Jenwald
25cf4add05
Merge pull request #17862 from Snuffleupagus/fingerprints-toHex
Improve the implementation of the `PDFDocument.fingerprints`-getter
2024-10-29 15:34:02 +01:00
Jonas Jenwald
afb4813d1c Simplify the "ReaderHeadersReady" message-handler in the API
We can convert the handler to an `async` function, which removes the need to create a temporary Promise here.
Given the age of this code it shouldn't hurt to simplify it a little bit.
2024-10-29 14:59:39 +01:00
Jonas Jenwald
8f47d06d07 Add helper functions to allow using new Uint8Array methods
This allows using the new methods in browsers that support them, e.g. Firefox 133+, while still providing fallbacks where necessary; see https://github.com/tc39/proposal-arraybuffer-base64

*Please note:* These are not actual polyfills, but only implements what we need in the PDF.js code-base. Eventually this patch should be reverted, once support is generally available.
2024-10-29 10:22:35 +01:00
Jonas Jenwald
bfc645bab1 Introduce some Uint8Array.fromBase64 and Uint8Array.prototype.toBase64 usage in the main code-base
See https://github.com/tc39/proposal-arraybuffer-base64
2024-10-29 10:22:35 +01:00
Jonas Jenwald
f9fc477080 Improve the implementation of the PDFDocument.fingerprints-getter
- Add explicit `length` validation of the /ID entries. Given the `EMPTY_FINGERPRINT` constant we're already *implicitly* assuming a particular length.

 - Move the constants into the `fingerprints`-getter, since they're not used anywhere else.

 - Replace the `hexString` helper function with the standard `Uint8Array.prototype.toHex` method; see https://github.com/tc39/proposal-arraybuffer-base64
2024-10-29 10:22:35 +01:00
Jonas Jenwald
3a85479c67
Merge pull request #18974 from Snuffleupagus/issue-18973
Allow `StreamsSequenceStream` to skip sub-streams that are not actual Streams (issue 18973)
2024-10-29 10:21:35 +01:00
Jonas Jenwald
48a18585f2 Allow StreamsSequenceStream to skip sub-streams that are not actual Streams (issue 18973)
This extends PR 13796 to also handle the case where sub-streams contain invalid data, i.e. anything that isn't a Stream, however please note that in these cases there's no guarantee that we'll render the page "correctly".

Note that Adobe Reader, i.e. the PDF reference implementation, cannot render the last page of the referenced PDF document.
2024-10-29 09:36:08 +01:00
Jonas Jenwald
93961e2802
Merge pull request #18971 from Snuffleupagus/AltText-fluent
[Editor] Utilize Fluent "better" when localizing the AltText
2024-10-28 20:53:06 +01:00
Jonas Jenwald
ee812b5df2 [Editor] Utilize Fluent "better" when localizing the AltText
Currently we manually localize and update the DOM-elements of the AltText-button, and it seems nicer to utilize Fluent "properly" for that task.
This can be achieved by introducing an explicit `span`-element on the AltText-button (similar to e.g. the regular toolbar-buttons), and adding a few more l10n-strings, since that allows just setting the `data-l10n-id`-attribute on all the relevant DOM-elements.

Finally, note how we no longer need to localize any strings eagerly when initializing the various editors.
2024-10-28 17:19:02 +01:00
calixteman
9108848743
Merge pull request #18918 from calixteman/bmp_decoder
Use a BMP decoder when resizing an image
2024-10-28 16:30:20 +01:00
Calixte Denizet
b649b6f8dd Use a BMP decoder when resizing an image
The image decoding won't block the main thread any more.
For now, it isn't enabled for Chrome because issue6741.pdf leads to a crash.
2024-10-28 14:09:52 +01:00
calixteman
07a1d30fad
Merge pull request #18968 from calixteman/bug1903588
[Editor] Split the long words when showing the alt-text tooltip (bug 1903588)
2024-10-28 14:07:48 +01:00
Calixte Denizet
8fbb9e2f16 [Editor] Split the long words when showing the alt-text tooltip (bug 1903588) 2024-10-28 11:08:30 +01:00
calixteman
2bee3af0ee
Merge pull request #18967 from calixteman/bug1910431
Make util.scand a bit more flexible with dates which don't match the given format (bug 1910431)
2024-10-28 09:36:34 +01:00
Calixte Denizet
230d7f9229 Make util.scand a bit more flexible with dates which don't match the given format (bug 1910431) 2024-10-27 19:19:06 +01:00
Tim van der Meij
5418060bbc
Merge pull request #18951 from Snuffleupagus/CMap-isCompressed
[api-minor] Remove the `CMapCompressionType` enumeration
2024-10-27 14:42:00 +01:00
Tim van der Meij
b5805caacd
Merge pull request #18965 from Snuffleupagus/_goodSquareLength-static
Re-factor the `ImageResizer._goodSquareLength` definition
2024-10-27 14:38:43 +01:00
Jonas Jenwald
8a2b95418a Re-factor the ImageResizer._goodSquareLength definition
Move the `ImageResizer._goodSquareLength` definition into the class itself, since the current position shouldn't be necessary, and also convert it into an actually private field.
2024-10-27 11:03:04 +01:00
calixteman
0d42e56cab
Merge pull request #18960 from calixteman/issue18956
Always fill the mask with the backdrop color
2024-10-26 15:16:06 +02:00
Calixte Denizet
d114f71feb Always fill the mask with the backdrop color
It fixes #18956.

In the patch #18029, for performance reasons and because I thought it was useless, I deliberately chose to not fill the mask
with the backdrop color when it's full black: it was a bad idea.
So in this patch we always add the backdrop color to the mask.
2024-10-26 14:14:51 +02:00
Jonas Jenwald
b048420d21 [api-minor] Remove the CMapCompressionType enumeration
After the binary CMap format had been added there were also some ideas about *maybe* providing other formats, see [here](https://github.com/mozilla/pdf.js/pull/8064#issuecomment-279730182), however that was over seven years ago and we still only use binary CMaps.
Hence it now seems reasonable to simplify the relevant code by removing `CMapCompressionType` and instead just use a boolean to indicate the type of the built-in CMaps.
2024-10-24 11:08:16 +02:00
Jonas Jenwald
50c291eb33 Unconditionally cache built-in CMaps on the worker-thread
Given that we've not shipped, nor used, anything except binary CMaps for years let's just cache them unconditionally (since that's a tiny bit less code).
2024-10-24 10:15:09 +02:00
calixteman
bde36f28be
Merge pull request #18947 from calixteman/add_comment_ftl
Add a comment in l10n file for the non-standard attribute default-content
2024-10-23 15:16:18 +02:00
Calixte Denizet
c0c527266d Add a comment in l10n file for the non-standard attribute default-content 2024-10-23 15:12:52 +02:00
calixteman
1ad09779f1
Merge pull request #18910 from calixteman/image_decoder1
Use ImageDecoder in order to decode jpeg images (bug 1901223)
2024-10-23 13:54:07 +02:00
Calixte Denizet
b6c4f0b69e Use ImageDecoder in order to decode jpeg images (bug 1901223) 2024-10-23 10:42:01 +02:00
Tim van der Meij
1e07b87bb6
Merge pull request #18933 from Snuffleupagus/base-factory-fetchData
Change the `BaseCMapReaderFactory` fetch-helper to return a `Uint8Array`
2024-10-22 20:03:50 +02:00
Tim van der Meij
54a77d24eb
Merge pull request #18940 from Snuffleupagus/bug-report-PDF-placeholder
Try to discourage "unrelated" information under `Attach (recommended) or Link to PDF file` in the bug report template (PR 18535 follow-up)
2024-10-22 19:53:33 +02:00
Jonas Jenwald
49c3dc9c5f
Merge pull request #18942 from Snuffleupagus/issue-18941
Fallback to a standard font if a font-file entry doesn't contain a Stream (issue 18941)
2024-10-22 18:18:44 +02:00
Jonas Jenwald
236c8d862e Re-factor how we handle missing, corrupt, or empty font-file entries
This improves the fixes for e.g. issue 9462 and 18941 slightly and allows better fallback behaviour for non-standard fonts.
2024-10-22 17:07:12 +02:00
Jonas Jenwald
63b34114b1 Fallback to a standard font if a font-file entry doesn't contain a Stream (issue 18941)
The PDF document is clearly corrupt, since it has /FontFile2 entries that are Dictionaries which obviously isn't correct.
While there's obviously no guarantee that things will look perfect this way, actually rendering the text at all should be an improvement in general.
2024-10-22 11:51:28 +02:00
Jonas Jenwald
a809461738 Try to discourage "unrelated" information under Attach (recommended) or Link to PDF file in the bug report template (PR 18535 follow-up)
Unfortunately it turns out to be somewhat common for users to provide a bunch of "unrelated" information in this field, or even stating their entire problem there, rather than placing it under the appropriate headings further down in the template.
2024-10-22 09:23:32 +02:00
Jonas Jenwald
6c3336f04f Re-factor the DefaultFileReaderFactory unit-test helper
We can re-use the existing helpers from `src/display/` rather than re-implementing the functionality here.
2024-10-21 13:20:31 +02:00
Jonas Jenwald
df696063b9 Change the BaseCMapReaderFactory fetch-helper to return a Uint8Array
This moves more functionality into the base-class, rather than having to duplicate that in the extending classes.
For consistency, also updates the `BaseStandardFontDataFactory` and introduces more `async`/`await` in various relevant code.
2024-10-21 13:20:18 +02:00
Jonas Jenwald
d37e4b08e4
Merge pull request #18930 from Snuffleupagus/rm-duplicate-print-download-mask-image
Remove `mask-image` duplication for the print/download buttons
2024-10-21 08:31:16 +02:00
Jonas Jenwald
65b38f24ff Remove mask-image duplication for the print/download buttons
With the recent re-factoring of the viewer CSS rules we now have some duplication of the `mask-image` definitions for the print/download buttons in the secondaryToolbar; note 17419de157/web/viewer.css (L1204-L1210)
2024-10-20 21:15:09 +02:00
Tim van der Meij
17419de157
Merge pull request #18923 from timvandermeij/integration-test-text-layer
Fix the "Text selection using mouse doesn't jump when hovering on an empty area in a single page" integration test
2024-10-20 19:49:49 +02:00
Tim van der Meij
24b8393bfe
Fix the "Text selection using mouse doesn't jump when hovering on an empty area in a single page" integration test
The `getSpanRectFromText` helper function returns the location as float
values. This could be desirable in cases where the exact values matter
(for example during comparisons), but in the text layer tests we don't
need this precision. Moreover, the Puppeteer `page.mouse.move` API
apparently doesn't work correctly if float values are given as input.

Note that this test only failed because it couldn't move to the initial
selection position; any subsequent moves actually worked because the
`moveInSteps` helper function already rounded all values correctly.

This commit fixes the issue by consistently rounding all values that we
pass to Puppeteer's `page.mouse.move` API.
2024-10-20 19:42:40 +02:00
Tim van der Meij
b94ab46be5
Merge pull request #18929 from timvandermeij/eslint-perfectionist
Replace `eslint-plugin-sort-exports` by `eslint-plugin-perfectionist`
2024-10-20 19:41:37 +02:00