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

6675 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
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
2ef3fd2a81 Simplify localization of the "default-content" in FreeText editors
By using "data-l10n-attrs" it's possible to instruct Fluent to localize *custom* attributes, which means that we don't need to manually translate/update the "default-content" in FreeText editors.
2024-10-20 18:46:44 +02:00
Jonas Jenwald
54e00b0104 Catch errors when invoking applyPath2DToCanvasRenderingContext
This way we allow the rest of the packages to be loaded successfully, such that e.g. the Node.js unit-tests work correctly.

Note that this occurred after updating the `node-canvas` package to version `3.0.0-rc2`, however it's not immediately clear to me if it's a problem there or in the `path2d` package; see also nilzona/path2d-polyfill/issues/84.
2024-10-20 12:39:10 +02:00
Jonas Jenwald
c88d3a31cf
Merge pull request #18888 from Snuffleupagus/MessageHandler-AbortSignal
Re-factor the `MessageHandler`-class event handler function
2024-10-18 17:27:14 +02:00
Calixte Denizet
86d1272d1b When changing a property on a radio button then change it for the siblings (bug 1922766) 2024-10-17 18:27:12 +02:00
Jonas Jenwald
788eabc76a Re-factor the MessageHandler-class event handler function
- Change the "message" event handler function to a private method.

 - Remove the "message" event listener with an `AbortSignal`.

 - Extend the `LoopbackPort`-class with `AbortSignal` support.
2024-10-16 10:16:27 +02:00
Jonas Jenwald
805f962181 Reduce duplication when collecting optional content groups
After PR 18825 we can easily "compute" the optional content groups, and can thus avoid tracking them manually.
2024-10-15 13:20:30 +02:00
Jonas Jenwald
424f81c4db
Merge pull request #18825 from agrahn/rbgroups
implementing optional content radiobutton groups
2024-10-15 13:11:19 +02:00
Alexander Grahn
441efe456e Optional Content (OC) radiobutton (RB) groups implemented. Resolves #18823.
The code parses the /RBGroups entry in the OC configuration dict and adds the property `rbGroups' to instances of the OptionalContentGroup class. rbGroups takes an array of Sets, where each Set instance represents an RB group the OptionalContentGroup instance is a member of. Such a Set instance contains all OCG ids within the corresponding RB group. RB groups an OCG is associated with are processed when its visibility is set to true, as required by the PDF spec.
2024-10-15 11:34:45 +02:00
Calixte Denizet
8b7b39f5d6 Some jpx images can have a mask
It fixes #18896.
2024-10-14 21:50:32 +02:00
calixteman
e1f9fa4ea5
Merge pull request #18895 from calixteman/issue18894
Fallback on gray colorspace when there are no colorspace and no name in the scn/SCN arguments
2024-10-13 17:56:52 +02:00
Calixte Denizet
e7ab8cd8c1 Fallback on gray colorspace when there are no colorspace and no name in the scn/SCN arguments
It fixes #18894.
2024-10-13 16:02:07 +02:00
calixteman
1c0c070847
Merge pull request #18890 from calixteman/clamp_indexedcs_hival
Clamp the hival parameter of Indexed color space to the range [0; 255]
2024-10-12 23:53:59 +02:00
calixteman
e28dd8e824
Merge pull request #18889 from calixteman/rm_useless_aria_has_popup
Don't add attribute 'aria-haspopup' when no popup is rendered for an annotation
2024-10-12 23:52:15 +02:00
Calixte Denizet
4dea773c5b Clamp the hival parameter of Indexed color space to the range [0; 255]
Since this value is used to allocate an array, it makes sense to avoid to use too much memory.
From the specs, this value must be in the range [0; 255] (see section 8.6.6.3).
This patch removes the unused property 'highVal'.
2024-10-12 23:50:58 +02:00
Calixte Denizet
7c43cb2dae Don't add attribute 'aria-haspopup' when no popup is rendered for an annotation
and for ink annotations, create the popup after the loop in order to avoid useless
elements creation.
2024-10-12 20:51:40 +02:00
Jonas Jenwald
8afc542ae2 Move the regular expression caching into the PDFDateString class
This code is old enough that it pre-dates availability of private class fields, hence why this wasn't done originally.
2024-10-11 15:34:58 +02:00
Tim van der Meij
0543e9e49c
Merge pull request #18874 from Snuffleupagus/ColorPicker-AbortSignal-any
[Editor] Remove `ColorPicker` event listeners with `AbortSignal.any()` (PR 18586 follow-up)
2024-10-10 19:55:19 +02:00
calixteman
a77bf87c50
Merge pull request #18879 from calixteman/highlight_hover
Don't add the grey outline when hovering a selected highlight
2024-10-10 15:28:59 +02:00
Calixte Denizet
fa7df01568 Don't add the grey outline when hovering a selected highlight
When playing with a pen, I noticed that sometimes a free highlight has still its
gray outline when an other one is drawn: for any reason the pointerleave event isn't
triggered.
2024-10-10 14:12:50 +02:00
Calixte Denizet
f2f56b6464 Avoid exceptions in the console with ill-formed flate streams
It fixes #18876.
2024-10-10 12:07:30 +02:00
Jonas Jenwald
14537d1412 [Editor] Remove ColorPicker event listeners with AbortSignal.any() (PR 18586 follow-up)
Also, removes another "unnecessary" bound-method.
2024-10-09 10:58:35 +02:00
Jonas Jenwald
662bd022ce Reduce duplication in the PDFDocument.calculationOrderIds getter 2024-10-08 12:24:09 +02:00