Commit Graph

6211 Commits

Author SHA1 Message Date
Calixte Denizet
1ea6293923 [Editor] Add a new editor to highlight some text in a pdf (bug 1866119)
This patch is first big step for the new highlight feature.
Few patches will follow in order to conform to the specs UX/UI gave us.
2023-11-28 14:21:53 +01:00
Calixte Denizet
2be136ab70 [Editor] Avoid to add a new ink editor when we aren't editing anymore 2023-11-27 16:18:31 +01:00
Calixte Denizet
52ea20eda4 Don't throw when there isn't enough data to get block info in flate stream
but just ends the stream.
2023-11-26 18:12:22 +01:00
calixteman
9d863f5180
Merge pull request #17331 from calixteman/lang_marker
Remove language codes from text strings.
2023-11-25 16:43:37 +01:00
Calixte Denizet
eb5f610d18 Remove language codes from text strings.
And take care to have an even number of bytes with utf16 strings.
2023-11-25 15:09:31 +01:00
Jonas Jenwald
3d9f68cb97
Merge pull request #17328 from Snuffleupagus/fetchData-blob
Use the `fetchData` helper function in more cases
2023-11-25 08:31:12 +01:00
Calixte Denizet
42147e8839 [Editor] Only focus the canvas for mouse events when drawing in the canvas
And if we've to focus it, we must prevent scrolling to avoid to draw at an
unexpected position.
2023-11-24 16:00:04 +01:00
Jonas Jenwald
fd7a7e2859 Use the fetchData helper function in more cases
- Extend the `fetchData` helper function to also support fetching of "blob" data.

 - Use the `fetchData` helper function more in the code-base, when fetching non-PDF data. Given that the Fetch API isn't supported for all protocols, this should improve compatibility for the PDF.js library.
2023-11-24 13:05:57 +01:00
Calixte Denizet
1f0f51613a Make sure that only one radio button is checked in its group (bug 1864136)
When the first checked radio is met, the others in the group are set to false.
2023-11-23 17:01:49 +01:00
Calixte Denizet
f8f4432961 [Editor] Add support for saving/printing a newly added Highlight annotation (bug 1865708) 2023-11-22 10:41:55 +01:00
calixteman
02ccdbb2b1
Merge pull request #17291 from calixteman/editor_highlight1
[Editor] Add a way to extract the outlines of a union of rectangles
2023-11-21 10:56:18 +01:00
Calixte Denizet
31d9b9f574 [Editor] Add a way to extract the outlines of a union of rectangles
The goal is to be able to get these outlines to fill the shape corresponding
to a text selection in order to highlight some text contents.
The outlines will be used either to show selected/hovered highlights.
2023-11-20 18:45:19 +01:00
Jonas Jenwald
a6f0609a6e Throw a JpegError when a JPEG image has no frame data (issue 17302)
Given that there's nothing to parse in this case, since we're dealing with an invalid JPEG image, throwing an *explicit* Error makes sense here.
2023-11-20 17:33:49 +01:00
Calixte Denizet
b7d28a3bf6 [Editor] Add a tooltip to the delete button 2023-11-15 10:51:39 +01:00
Jonas Jenwald
709d89420e Re-factor how the GenericL10n class fetches localization-data
- Re-factor the existing `fetchData` helper function such that it can fetch more types of data, and it now supports "arraybuffer", "json", and "text".
   This only needed minor adjustments in the `DOMCMapReaderFactory` and `DOMStandardFontDataFactory` classes.[1]

 - Expose the `fetchData` helper function in the API, such that the viewer is able to access it.

 - Use the `fetchData` helper function in the `GenericL10n` class, since this should allow fetching of localization-data even if the default viewer is run in an environment without support for the Fetch API.

---
[1] While testing this I also noticed a minor inconsistency when handling standard font-data on the worker-thread.
2023-11-14 13:45:14 +01:00
Calixte Denizet
09b4fe6a30 Get the field name from its parent when it doesn't have one when collecting fields (bug 1864136)
Some fields, somewhere under the Fields entry in Acroform, could have no name (in T)
but with a parent which has a name but which isn't somewhere under Fields.
As a side-effect, this patch prevents infinite loops because of potential cycles
under Fields.
2023-11-13 14:41:14 +01:00
Jonas Jenwald
ade692ff2e Set a type for the Blob used in createCDNWrapper (issue 17259)
Hopefully this is enough to address the problem of initializing the Worker in Chromium-based browsers.
Locally I've tried to *force* use of `createCDNWrapper` in development mode, by commenting out the `isSameOrigin` checks, and worker-loading fails against `master` and works with this patch.
2023-11-12 09:30:26 +01:00
calixteman
17213062cc
Merge pull request #17253 from calixteman/issue16839
Fix the maxp table version in font to make it visible on Windows
2023-11-10 17:57:33 +01:00
Calixte Denizet
334f0eb060 [Editor] Add a toolbar to selected editors with a button to delete it (bug 1863763) 2023-11-10 15:19:43 +01:00
Calixte Denizet
59ce1a4a3f Fix the maxp table version in font to make it visible on Windows 2023-11-10 14:16:20 +01:00
Calixte Denizet
ec396c2150 Don't avoid to execute the Blur callback when blurring a text field (bug 1863910) 2023-11-09 13:50:33 +01:00
Jonas Jenwald
ff62fc8e2c Skip fieldObjects that are not actually References
The `fieldObjects`-getter is implemented in the `PDFDocument` class, which means that the `this._localIdFactory`-property that we pass to `AnnotationFactory.create` doesn't actually exist.
The reason that this hasn't caused any bugs, that I'm aware of, is that all /Fields-entries need to be References to actually make sense.
2023-11-08 14:39:13 +01:00
Jonas Jenwald
65c827b0eb Ensure that fieldObjects and #collectFieldObjects handles References correctly
The `fieldObjects`-getter itself is called, from `src/core/worker.js`, in a way that'll ensure that any `MissingDataException`s are handled. However the problem is that the actual data-lookups in `fieldObjects` and `#collectFieldObjects` are done inside of a Promise, which means that `MissingDataException`s won't be handled and parsing could thus break.

To address this we change all data-lookups to be asynchronous instead.
2023-11-08 14:38:57 +01:00
Calixte Denizet
acc62f80de Don't try to collect a nonexistent field because of an invalid ref 2023-11-07 19:58:29 +01:00
Jonas Jenwald
155a302e74 Use even more optional chaining in the code-base 2023-11-02 16:47:33 +01:00
Calixte Denizet
085aa4207d Render rich text with only one text element 2023-11-02 15:35:52 +01:00
Calixte Denizet
77475ac610 [Editor] Don't steal the keyboard events when editing mode is enabled 2023-10-30 10:03:44 +01:00
Tim van der Meij
0329b5e130
Merge pull request #17153 from Snuffleupagus/src-navigator-checks
Guard `navigator`-object accesses in `src/`-files (issue 15728)
2023-10-29 11:59:32 +01:00
Jonas Jenwald
b798415147
Merge pull request #17081 from Snuffleupagus/examples-modules
Update the `examples/`-folder to account for outputting of JavaScript modules (PR 17055 follow-up)
2023-10-28 22:08:45 +02:00
Jonas Jenwald
c1fef7d2f2 Guard navigator-object accesses in src/-files (issue 15728)
There are environments that include *incomplete* polyfills for the `navigator`-object, which may thus cause the PDF.js library to break.
Despite that clearly not being our fault, it may still result in bug reports filed against the PDF.js project; see e.g. 15728.

Currently this even seem to affect *the latest* version of Node.js; see e.g. [here].

*Please note:* Thanks to the pre-processor none of these changes affect the Firefox PDF Viewer, however it does add "overhead" when working with and reviewing the affected code (which is why I'm not crazy about this).
2023-10-28 14:41:46 +02:00
Jonas Jenwald
d7b39fe696 Update the webpack example to account for outputting of JavaScript modules (PR 17055 follow-up)
*Please note:* While following the steps in the README still works with this patch, in the sense that the example runs and successfully renders a PDF document, I unfortunately cannot tell if it illustrates Webpack best practices.
2023-10-28 10:26:34 +02:00
Jonas Jenwald
069096e78f Fix WidgetAnnotationElement._getKeyModifier to account for Linux
Currently the `WidgetAnnotationElement._getKeyModifier` method will always be falsy on Linux, which seems like a simple oversight. Looking at all the other `FeatureTest.platform` accesses we only handle the `isMac`-case specially, and it seems reasonable to do the same thing here.
The reason that this hasn't led to any bug reports is most likely that the `modifier`-property seems completely unused in the scripting-implementation.

Finally, with these changes we can (slightly) simplify the `FeatureTest.platform` implementation.
2023-10-26 13:36:42 +02:00
Calixte Denizet
0c38c6e103 Improve performance of optional content parsing 2023-10-25 17:50:53 +02:00
Calixte Denizet
133ed96f8f Don't take into account the INVISIBLE flag for well-known annotations 2023-10-25 10:16:14 +02:00
Calixte Denizet
2f3797db34 [Annotation] Use the field V entry when there is no Parent one for a radio button (bug 1860602) 2023-10-23 22:11:30 +02:00
Jonas Jenwald
17af706070 [api-minor] Use "data-l10n-id"/"data-l10n-args", rather than manually updating DOM-elements, to trigger translation (PR 17146 follow-up)
This patch changes almost all viewer-components[1] to use "data-l10n-id"/"data-l10n-args" for localization, which means that in many cases we no longer need to pass around the `L10n`-instance any more.

One part of the code-base where the `L10n`-instance is still being used "directly" is the AnnotationEditors, however while it might be possible to convert (most of) that code as well that's not attempted in this patch.

---
[1] The one exception is the `PDFDocumentProperties` dialog, since the way it's currently implemented makes that less straightforward to fix without a lot of code changes.
2023-10-22 14:17:47 +02:00
Jonas Jenwald
f07675a6a8 [api-minor] Re-factor NullL10n and remove the hard-coded l10n strings (PR 17115 follow-up)
*Please note:* These changes only affect the GENERIC build, since `NullL10n` is only a stub elsewhere (see PR 17135).

After the changes in PR 17115, which modernized and improved l10n-handling, the `NullL10n`-implementation is no longer a good fallback for the "proper" `L10n`-classes.
To improve this situation, especially for the *standalone* viewer-components, this patch makes the following changes:
 - Let the `NullL10n`-implementation extend an actual `L10n`-class, which is constant and lazily initialized, to ensure that it works *exactly* like the "proper" ones.

 - Automatically bundle the "en-US" l10n-strings in the build, via the pre-processor, such that we don't need to remember to manually update them.

 - Ensure that the *standalone* viewer-components register their DOM-elements for translation, similar to the default viewer, since this will allow future code improvements by using "data-l10n-id"/"data-l10n-args" in most (if not all) parts of the viewer.

 - Remove the `NullL10n` from the `AnnotationLayer`, to avoid affecting bundle size too much.
   For third-party users that access the `AnnotationLayer`, as exposed in the main PDF.js library, they'll now need to *manually* register it for translation. (However, the *standalone* viewer-components still works given the point above.)
2023-10-20 21:49:33 +02:00
Jonas Jenwald
a4cd2ef1db
Merge pull request #17148 from JT-External/support-rotated-imagemask
Fix size of maskCanvas to draw image masks correctly
2023-10-20 17:25:55 +02:00
JT-External
0eacd5c107 Fix size of maskCanvas to draw image masks correctly
Use existing helper to calculate the Box

Co-authored-by: Jonas Jenwald <jonas.jenwald@gmail.com>

Ensure that there are non-zero

Co-authored-by: Jonas Jenwald <jonas.jenwald@gmail.com>

Add a reference test for #17147
2023-10-20 23:46:24 +09:00
calixteman
5d8be99782
Merge pull request #17115 from calixteman/mv_to_fluent
[api-minor] Move to Fluent for the localization (bug 1858715)
2023-10-19 13:40:50 +02:00
Jonas Jenwald
6a6f6f122c
Merge pull request #17131 from Snuffleupagus/openOrDownloadData-caching
Re-factor the blob-URL caching in `DownloadManager.openOrDownloadData`
2023-10-19 11:25:47 +02:00
Calixte Denizet
66982a2a11 [api-minor] Move to Fluent for the localization (bug 1858715)
- For the generic viewer we use @fluent/dom and @fluent/bundle
- For the builtin pdf viewer in Firefox, we set a localization url
  and then we rely on document.l10n which is a DOMLocalization object.
2023-10-19 11:20:41 +02:00
Jonas Jenwald
25a1a9d28f Reduce unnecessary type conversion in writeStream
Currently we're unnecessarily converting data between strings and typed-arrays, when dealing with compressible data, in the `writeStream` function.
Note how we're *first* getting a string-representation of the stream, which involves converting the underlying typed-array into a string, only to immediately convert this back into a typed-array. This seems completely unnecessary, and is easy enough to avoid, and we'll now only do a *single* type-conversion in this function.
2023-10-18 15:39:01 +02:00
Jonas Jenwald
674052d3fc Re-factor the blob-URL caching in DownloadManager.openOrDownloadData
Cache blob-URLs on the actual data, rather than DOM elements, to reduce potential duplicates (note the updated unit-test).
2023-10-17 10:18:34 +02:00
Jonas Jenwald
93f24dd5d7 Remove the ESLint "amd" environment (PR 17055 follow-up)
Please see https://eslint.org/docs/latest/use/configure/language-options#specifying-environments
2023-10-15 11:50:57 +02:00
Jonas Jenwald
d5acbbccd3 Update the ESLint globals list (PR 17055 follow-up)
Given that we only use standard `import`/`export` statements now, after recent PRs, the "exports" global is unused.
Instead we add "__non_webpack_import__" to the `globals` to avoid having to sprinkle disable statements throughout the code.

Finally, the way that `globals` are defined has changed in ESLint and we should thus explicitly specify them as "readonly"; please find additional details at https://eslint.org/docs/latest/use/configure/language-options#specifying-globals
2023-10-15 11:38:10 +02:00
Tim van der Meij
d53e166538
Merge pull request #17120 from timvandermeij/code-scanning-alerts
Remove obsolete `src/shared/{cffStandardStrings,fonts_utils}.js` files
2023-10-14 14:26:35 +02:00
Tim van der Meij
58e4fcdc6f
Remove obsolete src/shared/{cffStandardStrings,fonts_utils}.js files
Those files only contain old debugging code that is not used/imported
anywhere anymore, which is generating code scanning alerts. Moreover,
they rely on globals/platform-specific code and don't import/export
logic properly.
2023-10-14 14:07:49 +02:00
Jonas Jenwald
d53093045a Enable the import/no-commonjs ESLint plugin rule
Given the amount of work put into removing `require`-calls from the code-base, let's ensure that new ones aren't accidentally added in the future.

Note that we still have a couple of files where `require` is being used, in particular:
 - The Node.js examples, however those will be updated to use `import` in PR 17081.
 - The Webpack examples, and related support files, however I unfortunately don't know enough about Webpack to be able to update those. (Hopefully users of that code will help out here, once version `4` is released.)
 - The `statcmp`-tool, since *some* of those `require`-calls cannot be converted to `import` without other code changes (and that file is only used during benchmarking).

Please find additional details at https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-commonjs.md
2023-10-14 12:49:17 +02:00
Jonas Jenwald
af9a7b0003 Tweak PDFWorkerUtil.createCDNWrapper to account for JavaScript modules (PR 17055 follow-up) 2023-10-14 11:34:40 +02:00