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

6810 commits

Author SHA1 Message Date
Jonas Jenwald
db43f158dc Inline the default Factory-definitions in getDocument
- Most of the these are only used in the `src/display/api.js` file, and this leads to slightly shorter code.

 - A number of unit-tests need a `BaseCanvasFactory`-instance, however that one is available through the `PDFDocumentProxy`-instance nowadays.

 - For other unit-tests the remaining necessary default Factory-definitions can be moved into the `test/unit/test_utils.js` file.
2025-01-18 14:09:14 +01:00
Tim van der Meij
6d12d2924f
Merge pull request #19331 from Snuffleupagus/api-Factory-JSDoc
Simplify the JSDocs for the various `getDocument` Factory-parameters
2025-01-18 13:38:29 +01:00
Calixte Denizet
0c14d6e2db Handle the case where openjpeg.wasm is missing
It fixes #19336.
2025-01-17 22:11:24 +01:00
Jonas Jenwald
6038b5a992 Handle JPX wasm fetch-response errors correctly (PR 19329 follow-up)
Currently we're not checking that the response is actually OK before getting the data, which means that rather than throwing an error we can get an empty `ArrayBuffer`.

To avoid duplicating code we can move an existing helper into `src/core/core_utils.js` and re-use it when fetching the JPX wasm-file as well.
2025-01-17 10:20:16 +01:00
Jonas Jenwald
1ddce76a8b Simplify the JSDocs for the various getDocument Factory-parameters
Given that we nowadays provide default Node.js versions of these Factory-parameters it no longer seems necessary to mention that environment specifically.
2025-01-16 23:01:36 +01:00
Jonas Jenwald
75cba72ca6 [api-major] Replace MissingPDFException and UnexpectedResponseException with one exception
These old exceptions have a fair amount of overlap given how/where they are being used, which is likely because they were introduced at different points in time, hence we can shorten and simplify the code by replacing them with a more general `ResponseException` instead.

Besides an error message, the new `ResponseException` instances also include:
 - A numeric `status` field containing the server response status, similar to the old `UnexpectedResponseException`.

 - A boolean `missing` field, to allow easily detecting the situations where `MissingPDFException` was previously thrown.
2025-01-16 22:51:05 +01:00
Calixte Denizet
94b4b54ef6 [api-major] Add openjpeg.wasm to pdf.js (bug 1935076)
In order to fix bug 1935076, we'll have to add a pure js fallback in case wasm is disabled
or simd isn't supported. Unfortunately, this fallback will take some space.

So, the main goal of this patch is to reduce the overall size (by ~93k).
As a side effect, it should make easier to use an other wasm file (which must export
_jp2_decode, _malloc and _free).
2025-01-16 21:09:50 +01:00
Jonas Jenwald
e5bc760316 Access the number of components correctly in JPEG 2000 images with color space entries (issue 19326)
This small typo appears to be a regression from PR 18204.
2025-01-15 10:16:06 +01:00
Jonas Jenwald
5e569cade5 Improve performance when reading very large TrueType "cmap" tables (issue 19319)
In the affected font the total number of mapping-entries is `1142348`, and no less than `997473` of them are duplicates.
Given that every duplicate causes a lot of Array elements to be moved this becomes extremely inefficient, which we can avoid by keeping track of seen `charCode`s and directly build the final mappings-Array instead.
2025-01-13 13:09:47 +01:00
Jonas Jenwald
e0be2a02dc Re-use existing helper functions in FontRendererFactory
Currently we re-implement a number of helper functions specifically for this code, which seems completely unnecessary since there's already general purpose ones available in the `src/core/core_utils.js` file.
2025-01-12 13:01:54 +01:00
calixteman
b5218853b4
Merge pull request #19312 from calixteman/improve_touch
[Editor] Improve zooming with a pinch gesture while drawing
2025-01-10 18:30:55 +01:00
Calixte Denizet
8483ae0f88 [Editor] Improve zooming with a pinch gesture while drawing
It lets the user make a pinch gesture with a finger on page with a drawing
and the second finger on an other page.
On mobile, it's pretty easy to be in such a situation.
2025-01-10 16:24:58 +01:00
Calixte Denizet
06f72d5662 [Editor] Don't try to use an non-existing canvas when rendering an invisible existing stamp editor
It fixes #19239.

When the canvas isn't existing the editor has no image: it's fine because the editor is invisible.
Once it's made visible, the canvas is set when the annotation layer has been rendered.
2025-01-10 16:05:59 +01:00
calixteman
f1166f480f
Merge pull request #19309 from calixteman/make_unique_id_draw_layer
[Editor] Set a unique id for each element in the draw layer
2025-01-08 21:56:52 +01:00
Calixte Denizet
586f45b7b8 [Editor] Set a unique id for each element in the draw layer
It avoids any conflict with existing elements when an elment is moved from a page
to an other.
2025-01-08 20:44:15 +01:00
Jonas Jenwald
916fff0e42 Access the bbox/background data correctly in the MeshShadingPattern class (issue 18816)
This appears to have regressed in PR 13808, since it removed the `matrix`-entry from array returned by the `MeshShading.prototype.getIR` method *without* also updating the indexes in the `MeshShadingPattern` constructor.
2025-01-08 15:57:56 +01:00
Calixte Denizet
3dd8752283 Let be more tolerant with predefined phone number format
The long US phone number format should be '(999) 999-9999' but the parenthesis
can be omitted or the space replaced with a dash, ...
2025-01-06 15:24:19 +01:00
Tim van der Meij
4d4e1befeb
Merge pull request #19289 from Snuffleupagus/issue-19281
Skip LinkAnnotations when collecting field objects (issue 19281)
2025-01-04 13:32:18 +01:00
Jonas Jenwald
6f062abb76 Skip LinkAnnotations when collecting field objects (issue 19281)
The `/Root/AcroForm/Fields` array contains a "ridiculous" number of LinkAnnotations, which obviously makes no sense since those are not form fields.
To improve performance we'll thus ignore those when collecting the field objects.
2025-01-04 11:54:45 +01:00
Jonas Jenwald
74c1795c9f Use Dict iteration more (PR 19051 follow-up)
There's a few cases where we're looping through the result of `Dict.prototype.getKeys` and then manually look-up the values, which after PR 19051 can be replaced with direct iteration instead.
2025-01-02 15:09:19 +01:00
Jonas Jenwald
01240fda89 Remove the requestRange/requestFull methods from the NetworkManager class
Originally the code in this file was used in both the GENERIC and MOZCENTRAL builds, however that's no longer the case.
Hence we can now directly call `NetworkManager.prototype.request` and remove these old "helper" methods that only had a single call-site each.
2024-12-31 15:57:26 +01:00
Jonas Jenwald
20d5332009 For images that include SMask/Mask entries, ignore an SMask defined in the current graphics state
From section [11.6.4.3 Mask Shape and Opacity](https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf#G10.4848628) in the PDF specification:
 - An image XObject may contain its own *soft-mask image* in the form of a subsidiary image XObject in the `SMask` entry of the image dictionary (see "Image Dictionaries"). This mask, if present, shall override any explicit or colour key mask specified by the image dictionary's `Mask` entry. Either form of mask in the image dictionary shall override the current soft mask in the graphics state.
2024-12-30 14:25:07 +01:00
Tim van der Meij
8a50d2d302
Merge pull request #19259 from Snuffleupagus/more-wrapReason
Reduce duplication when handling "DocException" and "PasswordRequest" messages
2024-12-29 15:47:11 +01:00
Tim van der Meij
91d801728d
Merge pull request #19262 from Snuffleupagus/CompiledFont-assert-fontMatrix
Assert that the `fontMatrix` is always valid in `compileGlyph`
2024-12-29 15:41:04 +01:00
Tim van der Meij
5b94c865e7
Merge pull request #19263 from Snuffleupagus/Type2Compiled-fix-glyphNameMap
Remove the unused `glyphNameMap` parameter from `Type2Compiled`
2024-12-29 15:39:58 +01:00
Jonas Jenwald
aba6369638 Remove the unused glyphNameMap parameter from Type2Compiled
As part of the changes in PR 4259, which landed over ten years ago, the `glyphNameMap` property on `Font`-instances was removed.
The reason that this didn't cause any bugs is that we always fallback on `getGlyphsUnicode`, and when using that data we also rely on `StandardEncoding`, hence we should just remove the unused parameter from the `Type2Compiled` constructor.
2024-12-27 14:31:39 +01:00
Jonas Jenwald
2ae5aa08cc Assert that the fontMatrix is always valid in compileGlyph
While [bug 1893645](https://bugzilla.mozilla.org/show_bug.cgi?id=1893645) was fixed some time ago now, it still shouldn't hurt to also assert that the `fontMatrix` is always valid when invoking the `compileGlyph` method.
2024-12-27 11:41:49 +01:00
Jonas Jenwald
3a797317c8 Shorten some if-statements in the src/core/ folder
Thanks to modern JavaScript there's some existing code that can be shortened slightly.
2024-12-26 18:37:25 +01:00
Jonas Jenwald
6bde49a606 Reduce duplication when handling "DocException" and "PasswordRequest" messages
Rather than having to manually implement the exception-handling for the "DocException" message, we can instead re-use (and slightly extend) the existing `wrapReason` function since that one already does what we need.

Furthermore, we can also simplify handling of the "PasswordRequest" message a little bit and again re-use the `wrapReason` function.

Finally, the patch makes the following smaller changes:
 - Avoid needlessly re-creating exceptions in the `wrapReason` function.
 - Use a slightly shorter parameter name in the `wrapReason` function.
 - Remove the unused entries in the `CallbackKind`/`StreamKind` enumerations.
2024-12-26 12:55:49 +01:00
Jonas Jenwald
ec1a05c104 Add missing startWorkerTask calls in the "SaveDocument" handler
Without these calls we'll not actually wait for saving to complete when document destruction runs; compare with other `WorkerTask`-usage in this file.
While I cannot imagine that this has caused any problems for library users, the code is however not technically correct as-is.
2024-12-21 14:22:18 +01:00
calixteman
2df5d8f3ef
Merge pull request #19238 from calixteman/bug1938087
Take the absolute value of the font size when the annotation contents is in xhtml (bug 1938087)
2024-12-18 17:34:06 +01:00
Calixte Denizet
723ee9bc8c Take the absolute value of the font size when the annotation contents is in xhtml (bug 1938087) 2024-12-18 17:00:45 +01:00
Jonas Jenwald
189183aa1a Add basic support for non-embedded HelveticaLTStd-Bold fonts (issue 19234) 2024-12-18 09:39:22 +01:00
Tim van der Meij
ac81de6ab4
Merge pull request #19224 from Snuffleupagus/pr-18776-followup
[api-minor] Remove deprecated `getDocument` options (PR 18776 follow-up)
2024-12-15 15:52:34 +01:00
Tim van der Meij
322616988e
Merge pull request #19214 from Snuffleupagus/issue-19205
Don't remove trailing regular spaces from the "raw" response headers (issue 19205)
2024-12-15 15:51:20 +01:00
Jonas Jenwald
490e740365 [api-minor] Remove deprecated getDocument options (PR 18776 follow-up) 2024-12-15 14:13:44 +01:00
Calixte Denizet
4ed7f7f1ee [Editor] Add the ability to resize an editor in using a pinch gesture 2024-12-14 19:39:51 +01:00
Calixte Denizet
e0b63ecd03 Move the pinch stuff in its own file in order to use for editors 2024-12-11 23:20:01 +01:00
Calixte Denizet
d61b882888 [Editor] Avoid to focus an existing editor when enabling the layer
It fixes #18911.
2024-12-11 15:06:56 +01:00
Jonas Jenwald
08e54053ff Don't remove trailing regular spaces from the "raw" response headers (issue 19205)
This bug only seems to reproduce in Google Chrome, since browsers apparently sort response headers differently.
When the issue occurs the "raw" response headers string looks like this:
```
content-length: 525404\r\ncontent-type: \r\n
```
and since we trim *any* leading/trailing white-space characters the "content-type" header isn't detected correctly, which thus leads to `new Headers(...)` throwing.

Hence we'll keep regular spaces at the end of the "raw" response headers string, while still removing all other kinds of trailing white-space characters.

*Note:* The response headers parsing was based on https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/getAllResponseHeaders#examples
2024-12-11 12:16:31 +01:00
Calixte Denizet
89f61b4262 [Editor] Improve drawing on a touch screen.
- it's now possible to start a drawing with a pen and use fingers to zoom
  or scroll without interacting with the current drawing;
- it's now possible to draw with a finger and them zoom with two fingers.
2024-12-10 21:54:29 +01:00
calixteman
b35999d837
Merge pull request #19198 from calixteman/fix_intermittent_itest_chrome
Fix intermittent failures when moving a freetext annotation in integration tests
2024-12-10 16:56:58 +01:00
Calixte Denizet
74a377f72f Fix intermittent failures when moving a freetext annotation in integration tests
When an editor is moved with the keyboard or in dragging it, it is moved in the DOM in order
to make screen readers happy. But this move is slightly postponed thanks to a setTimeout(..., 0).
The failures were very likely due to the fact that intermittently the DOM move was done in
the middle of the next key sequence which was making the move on screen failing.
2024-12-10 16:14:26 +01:00
calixteman
44421d36f6
Merge pull request #19201 from calixteman/fix_resize_stamp
[Editor] When resizing a stamp annotation, the opposite corner must stay fixed
2024-12-10 11:00:01 +01:00
calixteman
898be9ef5e
Merge pull request #19202 from calixteman/avoid_to_lose_focus
[Editor] Don't commit the current drawing while zooming
2024-12-09 19:00:26 +01:00
Calixte Denizet
166a529ddd [Editor] Don't commit the current drawing while zooming 2024-12-09 17:25:36 +01:00
Calixte Denizet
99f3e6b4ec [Editor] When resizing a stamp annotation, the opposite corner must stay fixed
It was due the resize observer which is removed thanks to this patch.
In order to reuse the dragAndDrop function in test, this patch slighty refactors it
in order to make it easier to use.
2024-12-09 16:07:43 +01:00
Jonas Jenwald
6153b15231 Remove the raw path-strings after creating the actual Path2D glyph-objects
The `Path2D` glyph-objects are cached on the `FontFaceObject`-instance, so we can save a little bit of memory by removing the raw path-strings once they're no longer needed.
2024-12-09 15:09:18 +01:00
calixteman
99eefb7b71
Merge pull request #19189 from calixteman/improve_font_drawer
Improve perfs of the font renderer
2024-12-09 14:15:15 +01:00
Calixte Denizet
2b05924504 Improve perfs of the font renderer
Some SVG paths are generated from the font and used in the main thread
to render the glyphs.
2024-12-08 17:12:10 +01:00