Commit Graph

122 Commits

Author SHA1 Message Date
Calixte Denizet
bcc95460b6 Revert "Remove the enableStampEditor preference" (bug 1879588)
This reverts commit e820688510.
2024-02-09 18:21:21 +01:00
Calixte Denizet
81466ee039 Implement caret browsing mode (bug 807730)
The users will be able to navigate within the pdf in using the arrows
and they'll be able to select some text, for example in order to
highlight it.
2024-02-07 09:35:22 +01:00
Jonas Jenwald
eb36fd375c Move the debuggerSrc-parameter into the AppOptions
Having this parameter among a list of DOM-elements seems slightly strange now, however this is very old code hence the explanation for why this was done is for historical reasons (as is often the case).
Hence we can simply move this into `AppOptions` instead, which seems more appropriate overall.
2024-01-28 18:47:51 +01:00
Calixte Denizet
17e1519410 [Editor] Init the default highlight color before creating the first editor instance
We want to be able to draw an highlight with the default color but without having an
instance of the HighlightEditor.
2024-01-05 17:52:54 +01:00
Jonas Jenwald
628054ee53 Collect a few non-MOZCENTRAL AppOptions default values together
Ideally we want as few build-specific branches as possible when defining the default values, to improve readability, hence this change cannot hurt.
2023-12-07 16:58:09 +01:00
Calixte Denizet
ff23d37fa2 [Editor] Add a color picker with predefined colors for highlighting text (bug 1866434)
The doorhanger for highlighting has a basic color picker composed of 5 predefined colors
to set the default color to use.
These colors can be changed thanks to a preference for now but it's something which could
be changed in the Firefox settings in the future.
Each highlight has in its own toolbar a color picker to just change its color.
The different color pickers are so similar (modulo few differences in their styles) that
this patch introduces a new class ColorPicker which provides a color picker component
which could be reused in future editors.
All in all, a large part of this patch is dedicated to color picker itself and its style
and the rest is almost a matter of wiring the component.
2023-12-05 23:27:22 +01:00
Calixte Denizet
f7fec8c6d7 [Editor] Don't remove elements from the draw layer after it has been destroyed
Fixes issue #17379.
2023-12-05 22:41:20 +01:00
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
Tim van der Meij
8aa26fad24
Update the code style for the new Prettier version
This patch is automatically generated using `gulp lint --fix`.
2023-11-25 18:15:09 +01:00
Calixte Denizet
53101b379b Restore the option to set light/dark mode for chromium and generic builds 2023-11-18 21:32:25 +01:00
Jonas Jenwald
50f52b43a5
Merge pull request #17222 from Snuffleupagus/rm-viewerCssTheme
Remove the `viewerCssTheme`-option, since it's partially broken
2023-11-04 17:40:03 +01:00
Jonas Jenwald
d46578e959 Remove the viewerCssTheme-option, since it's partially broken
The `viewerCssTheme`-implementation has always been somewhat hacky, and now it's also *partially* broken ever since we've started using CSS nesting.
Trying to support nested media queries would thus require a lot more parsing of the CSS rules, which seems inefficient and thus generally undesirable.[1]

As discussed on Matrix, let's try to remove the `viewerCssTheme`-option and see if there's any (significant) fallout from this.

---
[1] If this option is brought back, it seems to me that it (in Firefox) should probably be set through the platform-code that handles theming.
2023-11-04 09:19:01 +01:00
Jonas Jenwald
8bbfcd3bef Re-factor how the canvasMaxAreaInBytes-option is handled in PDFViewerApplication.open (PR 17208 follow-up)
With the changes in PR 17208, where browser-preferences are now handled as "regular" viewer-options, we can tweak the definition of `canvasMaxAreaInBytes` to slightly simplify things in the `PDFViewerApplication.open` method.
2023-11-03 10:52:27 +01:00
Jonas Jenwald
ce9cfa2d72 Skip the PREFERENCE-branch in AppOptions.getAll in official builds
Given that this branch is only necessary in development mode and *during* building, but is never actually used in the final viewer-bundles, we can utilize the pre-processor to ignore this code.
2023-10-31 20:13:13 +01:00
Jonas Jenwald
eebc230cf1 [Firefox] Fetch browser preferences/options together with the viewer preferences (bug 1862192)
Currently we *synchronously* fetch a number of browser preferences/options, from the platform code, during the viewer respectively PDF document initialization paths.
This seems unnecessary, and we can re-factor the code to instead include the relevant data when fetching the regular viewer preferences.
2023-10-31 15:32:01 +01:00
Jonas Jenwald
e820688510 Remove the enableStampEditor preference 2023-10-19 15:45:07 +02:00
Jonas Jenwald
5ddc949159 Try to make the Preferences/AppOptions initialization slightly more efficient
*Please note:* This patch contains a couple of micro-optimizations, hence I understand if it's deemed unnecessary.

Move the `AppOptions` initialization into the `Preferences` constructor, since that allows us to remove a couple of function calls, a bit of asynchronicity and one loop that's currently happening in the early stages of the default viewer initialization.

Finally, move the `Preferences` initialization to occur a *tiny* bit earlier since that cannot hurt given that the entire viewer initialization depends on it being available.
2023-10-19 14:44:55 +02:00
Jonas Jenwald
927e50f5d4 [api-major] Output JavaScript modules in the builds (issue 10317)
At this point in time all browsers, and also Node.js, support standard `import`/`export` statements and we can now finally consider outputting modern JavaScript modules in the builds.[1]

In order for this to work we can *only* use proper `import`/`export` statements throughout the main code-base, and (as expected) our Node.js support made this much more complicated since both the official builds and the GitHub Actions-based tests must keep working.[2]
One remaining issue is that the `pdf.scripting.js` file cannot be built as a JavaScript module, since doing so breaks PDF scripting.

Note that my initial goal was to try and split these changes into a couple of commits, however that unfortunately didn't really work since it turned out to be difficult for smaller patches to work correctly and pass (all) tests that way.[3]
This is a classic case of every change requiring a couple of other changes, with each of those changes requiring further changes in turn and the size/scope quickly increasing as a result.

One possible "issue" with these changes is that we'll now only output JavaScript modules in the builds, which could perhaps be a problem with older tools. However it unfortunately seems far too complicated/time-consuming for us to attempt to support both the old and modern module formats, hence the alternative would be to do "nothing" here and just keep our "old" builds.[4]

---
[1] The final blocker was module support in workers in Firefox, which was implemented in Firefox 114; please see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility

[2] It's probably possible to further improve/simplify especially the Node.js-specific code, but it does appear to work as-is.

[3] Having partially "broken" patches, that fail tests, as part of the commit history is *really not* a good idea in general.

[4] Outputting JavaScript modules was first requested almost five years ago, see issue 10317, and nowadays there *should* be much better support for JavaScript modules in various tools.
2023-10-07 09:31:08 +02:00
Jonas Jenwald
0ee2a352ec [api-minor] Replace the useOnlyCssZoom option with maxCanvasPixels = 0 instead (PR 16729 follow-up)
Given that the `useOnlyCssZoom` option is essentially just a special-case of the `maxCanvasPixels` functionality, we can combine the two options in order to simplify the overall implementation.
Note that the `useOnlyCssZoom` functionality was only ever used, by default, in the PDF Viewer for the B2G/FirefoxOS project (which was abandoned years ago).
2023-07-29 13:58:03 +02:00
Jonas Jenwald
66645d30cc Remove the useOnlyCssZoom preference
*Please note:* This only removes the preference itself, however both the viewer-option and the actual implementation is still available.

The `useOnlyCssZoom` functionality was only ever used, by default, in the PDF Viewer for the B2G/FirefoxOS project (which was abandoned years ago). Given that CSS-only zooming can easily make the document look blurry even at low zoom levels, this functionality was only intended for low-powered mobile devices.
Hence it seems reasonable to remove the `useOnlyCssZoom` preference now, since neither the default viewer nor the GeckoView-specific viewer uses this functionality.
2023-07-23 11:20:36 +02:00
Calixte Denizet
37bd78c707 [Editor] Add a basic stamp editor (bug 1790255)
For now it allows to add a stamp annotation with an image selected from the file system.
2023-07-06 11:27:50 +02:00
Jonas Jenwald
80b4708fa3 [GeckoView] Remove the enableFloatingToolbar preference
Note that we'll now display the toolbar unconditionally in GeckoView.
2023-06-26 15:17:03 +02:00
Calixte Denizet
53134c0c0b [api-minor] Use a local font or fallback on an embedded one (if it exists) for non-embedded fonts (bug 1766039)
- Replace FoxitSans with LiberationSans: LiberationSans is already there (for XFA) and we can use
it as a good replacement of FoxitSans.
- For now we just try to substitue standard fonts, the strategy is the following:
  * we try to find a font locally from a hardcoded list;
  * if it fails then we use Liberation as fallback (only for Helvetica for the moment);
  * else we just fallback on the system serif/sansserif/monospace font.
2023-05-10 14:10:23 +02:00
Jonas Jenwald
95bf9fc17f Remove SystemJS usage, in development mode, from the worker
Now that https://bugzilla.mozilla.org/show_bug.cgi?id=1247687 has landed in Firefox, we're able to use worker-modules during development :-)

This removes the final piece of SystemJS usage from the PDF.js library, thus allowing a fair bit of clean-up, and we now use *only* native `import`/`export` statements everywhere in development mode.
2023-04-29 13:43:24 +02:00
Jonas Jenwald
804aa896a7 Stop using the PRODUCTION build-target in the JavaScript code
This *special* build-target is very old, and was introduced with the first pre-processor that only uses comments to enable/disable code.
When the new pre-processor was added `PRODUCTION` effectively became redundant, at least in JavaScript code, since `typeof PDFJSDev === "undefined"` checks now do the same thing.

This patch proposes that we remove `PRODUCTION` from the JavaScript code, since that simplifies the conditions and thus improves readability in many cases.
*Please note:* There's not, nor has there ever been, any gulp-task that set `PRODUCTION = false` during building.
2023-04-17 12:04:34 +02:00
Calixte Denizet
7f0d45ce47 [GeckoView] Show the download button by default and add a pref to disable it (bug 1827963)
For the moment there is no real consensus on how we should download a pdf on Android.
Hence we keep this solution for the moment but behind a pref (which will be true on
nightly only).
2023-04-13 20:33:03 +02:00
Jonas Jenwald
c2f1e65cc3 [api-minor] Remove SVG-rendering from the viewer (PR 15173 follow-up) 2023-04-02 15:23:45 +02:00
Jonas Jenwald
e0e56e9e9c [Firefox] Set the imageResourcesPath correctly (PR 16153 follow-up)
We missed updating this path in PR 16153, which breaks loading of annotation-icons in the Firefox PDF Viewer.
2023-03-29 14:33:08 +02:00
Calixte Denizet
ea1d090109 Remove <base> tag from the Firefox built-in viewer (bug 1821408)
The tag <base> is used to resolve relative URIs within the document.
Newly added SVG filters use a relative URI which then use the URI in base
but this one mismatches with the document URI and consequently filters are
not found in the Firefox viewer.
So this patch just removes <base> and replace few relative URLs by absolute
ones.
2023-03-14 10:12:42 +01:00
Jonas Jenwald
6c158da5a8 Limit AppOptions._hasUserOptions to only GENERIC builds
It's completely unused elsewhere, e.g. in the Firefox PDF Viewer.
2023-02-10 15:37:51 +01:00
Jonas Jenwald
397f943ca3 [api-minor] Enable transferring of TypedArray PDF data by default (PR 15908 follow-up)
This patch removes the recently introduced `transferPdfData` API-option, and simply enables transferring of TypedArray data *by default* instead of copying it. This will help reduce main-thread memory usage, however it will take ownership of the TypedArrays. Currently this only applies to the following cases:
 - TypedArrays passed to the `getDocument`-function in the API, in order to open PDF documents from binary data.
 - TypedArrays passed to a `PDFDataRangeTransport`-instance, used to support custom PDF document fetching/loading (see e.g. the Firefox PDF Viewer).

*PLEASE NOTE:* To avoid being affected by this, please simply *copy* any TypedArray data before passing it to either of the functions/methods mentioned above.

Now that we transfer TypedArray data that we previously only copied, we need to be more careful with input validation. Given how the `{IPDFStreamReader, IPDFStreamRangeReader}.read` methods will always return ArrayBuffer data, which is then transferred to the worker-thread[1], the actual TypedArray data passed to the API thus need to have the same exact size as its underlying ArrayBuffer to prevent issues.
Hence we'll check for this and only allow transferring of *safe* TypedArray data, and fallback to simply copying the data just as before. This obviously shouldn't be an issue in the Firefox PDF Viewer, but for the general PDF.js library we need to be more careful here.

---
[1] See e09ad99973/src/display/api.js (L2492-L2506) respectively e09ad99973/src/display/api.js (L2578-L2590)
2023-01-14 10:39:36 +01:00
Jonas Jenwald
bbe629018d [api-minor] Add a new transferPdfData option to allow transferring more data to the worker-thread (bug 1809164)
Also, removes the `initialData`-parameter JSDocs for the `getDocument`-function given that this parameter has been completely unused since PR 8982 (over five years ago). Note that the `initialData`-parameter is, and always was, intended to be provided when initializing a `PDFDataRangeTransport`-instance.
2023-01-10 21:03:44 +01:00
Jonas Jenwald
9f50b0af37 Enable the defaultZoomDelay option/preference unconditionally (PR 15812 follow-up)
This option/preference was disabled in GENERIC builds, see PR 15812, to avoid landing it *just before* a new release. Hence it should be fine to enable this now.
2023-01-02 14:00:16 +01:00
Calixte Denizet
663007a5c7 Only redraw after zooming is finished (bug 1661253)
Right now, the visible pages are redrawn for each scale change.
Consequently, zooming with mouse wheel or in pinching can be pretty janky
(even on a desktop machine but with a hdpi screen).
So the main idea in this patch is to draw the visible pages only once zooming
is finished.
2022-12-26 18:13:17 +01:00
Jonas Jenwald
1ea4c4b519 [api-minor] Make isOffscreenCanvasSupported configurable via the API (issue 14952)
This patch first of all makes `isOffscreenCanvasSupported` configurable, defaulting to `true` in browsers and `false` in Node.js environments, with a new `getDocument` parameter. While you normally want to use this, in order to improve performance, it should still be possible for users to control it (similar to e.g. `isEvalSupported`).

The specific problem, as reported in issue 14952, is that the SVG back-end doesn't support the new ImageMask data-format that's introduced in PR 14754. In particular:
 - When the SVG back-end is used in Node.js environments, this patch will "just work" without the user needing to make any code changes.
 - If the SVG back-end is used in browsers, this patch will require that `isOffscreenCanvasSupported: false` is added to the `getDocument`-call.
2022-10-07 00:10:46 +02:00
Jonas Jenwald
3e8394ee33 [api-major] Enable editing by default
Note that this patch *at least* shouldn't land until both [bug 1784272](https://bugzilla.mozilla.org/show_bug.cgi?id=1784272) and [bug 1785248](https://bugzilla.mozilla.org/show_bug.cgi?id=1785248) are fixed.
2022-09-12 14:58:31 +02:00
Jonas Jenwald
ad11cea33c [api-minor] Update the minimum supported Safari version
The Ink-editor uses `ResizeObserver`, which is supported in all reasonably modern browsers; see https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver#browser_compatibility

With the exception of Safari, `ResizeObserver` is thus available in all of the browsers that the PDF.js library currently support. Rather than trying to e.g. add a polyfill, let's just bump the compatibility (slightly) to Safari 13.1 instead; see https://en.wikipedia.org/wiki/Safari_version_history#Safari_13
2022-07-31 17:40:26 +02:00
Calixte Denizet
fe93742c8f Use default colors only in forced-colors mode (bug 1778068) 2022-07-07 19:36:03 +02:00
Jonas Jenwald
63f2d0bb64 Fix the annotationEditorMode-compatibility for older browsers (PR 15113 follow-up) 2022-06-29 16:16:48 +02:00
Jonas Jenwald
4a4c6b9851 [editor] Introduce a proper annotationEditorMode option/preference (PR 15075 follow-up)
This replaces the boolean `annotationEditorEnabled` option/preference with a "proper" `annotationEditorMode` one. This way it's not only possible for the user to control if Editing is enabled/disabled, but also which *specific* Editing-mode should become enabled upon PDF document load.

Given that Editing is not enabled/released yet, I cannot imagine that changing the name and type of the option/preference should be an issue.
2022-06-29 11:35:58 +02:00
Jonas Jenwald
35a6a508ee [editor] Support disabling of editing when pdfjs.enablePermissions is set (issue 15049)
For encrypted PDF documents without the required permissions set, this patch adds support for disabling of Annotation-editing. However, please note that it also requires that the `pdfjs.enablePermissions` preference is set to `true` (since PDF document permissions could be seen as user hostile).[1]

As I started looking at the issue, it soon became clear that *only* trying to fix the issue without slightly re-factor the surrounding code would be somewhat difficult.
The following is an overview of the changes in this patch; sorry about the size/scope of this!

 - Use a new `AnnotationEditorUIManager`-instance *for each* PDF document opened in the GENERIC viewer, to prevent user-added Annotations from "leaking" from one document into the next.

 - Re-factor the `BaseViewer.#initializePermissions`-method, to simplify handling of temporarily disabled modes (e.g. for both Annotation-rendering and Annotation-editing).

 - When editing is enabled, let the Editor-buttons be `disabled` until the document has loaded. This way we avoid the buttons becoming clickable temporarily, for PDF documents that use permissions.

 - Slightly re-factor how the Editor-buttons are shown/hidden in the viewer, and reset the toolbar-state when a new PDF document is opened.

 - Flip the order of the Editor-buttons and the pre-exising toolbarButtons in the "toolbarViewerRight"-div. (To help reduce the size, a little bit, for the PR that adds new Editor-toolbars.)

 - Enable editing by default in the development viewer, i.e. `gulp server`, since having to (repeatedly) do that manually becomes annoying after a while.

 - Finally, support disabling of editing when `pdfjs.enablePermissions` is set; fixes issue 15049.

---

[1] Either manually with `about:config`, or using e.g. a [Group Policy](https://github.com/mozilla/policy-templates).
2022-06-21 11:54:09 +02:00
Tim van der Meij
3ca8d2c4f9
Merge pull request #15052 from Snuffleupagus/mv-defaultUrl-option
Simplify setting the `defaultUrl`-option in the CHROME viewer (PR 12470 follow-up)
2022-06-18 11:29:21 +02:00
Jonas Jenwald
77aa86e275 Stop defining the defaultUrl-option in the MOZCENTRAL viewer
This option is not used, nor has it ever been used, in the *built-in* Firefox PDF Viewer. Hence we can define it only for the environments where it makes sense instead.
2022-06-18 09:43:35 +02:00
Jonas Jenwald
a19feac217 Reduce some duplication for AppOptions that use compatibilityParams
We can check for a relevant `compatibilityParams`-entry directly in `AppOptions.{get, getAll}` instead, which removes some unnecessary duplication.
2022-06-16 16:51:33 +02:00
Jonas Jenwald
df79b18a31 Only define the renderer-option in the GENERIC viewer
Given that the SVG back-end is not defined anywhere except in GENERIC builds, we can remove a little bit of unnecessary code in e.g. the Firefox PDF Viewer.
2022-06-16 16:11:47 +02:00
Calixte Denizet
c161a86ba1 [editor] Add an Ink editor
- Approximate the drawn curve by a set of Bezier curves in using
  js code from https://github.com/soswow/fit-curves.
  The code has been slightly modified in order to make the linter
  happy.
2022-06-09 19:35:59 +02:00
Jonas Jenwald
d34e7fff01 [editor] Disable the editor-buttons in XFA documents
Given the differences between XFA documents and "normal" PDF documents, we don't support editing of the former ones. Hence, when a XFA-document is opened, we temporarily disable the editor-buttons.
2022-06-05 10:00:08 +02:00
Calixte Denizet
be1aa11986 [edition] Add a FreeText editor (#14970)
- add a basic UI to edit some text in a pdf;
- an editor can be moved, suppressed, cut, copied, pasted, selected;
- add an undo/redo manager.
2022-06-04 18:20:11 +02:00
Jonas Jenwald
39251c5789 Re-order the names of the new pageColors options/preferences (PR 14874 follow-up)
Given that the new API-option is an Object named `pageColors`, with `background`/`foreground` keys, it occurred to me that it'd be slightly more consistent if the options/preferences names fully reflected that.
2022-05-08 11:15:04 +02:00
Calixte Denizet
c8afd6ce8c [api-minor] Improve pdf reading in high contrast mode
- Use Canvas & CanvasText color when they don't have their default value
  as background and foreground colors.
- The colors used to draw (stroke/fill) in a pdf are replaced by the bg/fg
  ones according to their luminance.
2022-05-05 16:34:51 +02:00