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

20109 commits

Author SHA1 Message Date
Jonas Jenwald
50a5a15088 Create absolute filter-URLs when needed in DOMFilterFactory (issue 18406)
This functionality is purposely limited to development mode and GENERIC builds, since it's unnecessary in e.g. the *built-in* Firefox PDF Viewer, and will only be used when a `<base>`-element is actually present.

*Please note:* We also have tests in mozilla-central that will *indirectly* ensure that relative filter-URLs work as intended in the Firefox PDF Viewer, see https://searchfox.org/mozilla-central/source/toolkit/components/pdfjs/test/browser_pdfjs_filters.js

---

To test that the issue is fixed, the following code can be used:

```html
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <base href=".">
  <title>base href (issue 18406)</title>
</head>
<body>

<ul>
  <li>Place this code in a file, named `base_href.html`, in the root of the PDF.js repository</li>
  <li>Run <pre>npx gulp dist-install</pre></li>
  <li>Run <pre>npx gulp server</pre></li>
  <li>Open <a href="http://localhost:8888/base_href.html">http://localhost:8888/base_href.html</a> in a browser</li>
  <li>Compare rendering with <a href="http://localhost:8888/web/viewer.html?file=/test/pdfs/issue16287.pdf">http://localhost:8888/web/viewer.html?file=/test/pdfs/issue16287.pdf</a></li>
</ul>

<canvas id="the-canvas" style="border: 1px solid black; direction: ltr;"></canvas>

<script src="/node_modules/pdfjs-dist/build/pdf.mjs" type="module"></script>

<script id="script" type="module">
  //
  // If absolute URL from the remote server is provided, configure the CORS
  // header on that server.
  //
  const url = '/test/pdfs/issue16287.pdf';

  //
  // The workerSrc property shall be specified.
  //
  pdfjsLib.GlobalWorkerOptions.workerSrc =
    '/node_modules/pdfjs-dist/build/pdf.worker.mjs';

  //
  // Asynchronous download PDF
  //
  const loadingTask = pdfjsLib.getDocument(url);
  const pdf = await loadingTask.promise;
  //
  // Fetch the first page
  //
  const page = await pdf.getPage(1);
  const scale = 1.5;
  const viewport = page.getViewport({ scale });
  // Support HiDPI-screens.
  const outputScale = window.devicePixelRatio || 1;

  //
  // Prepare canvas using PDF page dimensions
  //
  const canvas = document.getElementById("the-canvas");
  const context = canvas.getContext("2d");

  canvas.width = Math.floor(viewport.width * outputScale);
  canvas.height = Math.floor(viewport.height * outputScale);
  canvas.style.width = Math.floor(viewport.width) + "px";
  canvas.style.height = Math.floor(viewport.height) + "px";

  const transform = outputScale !== 1
    ? [outputScale, 0, 0, outputScale, 0, 0]
    : null;

  //
  // Render PDF page into canvas context
  //
  const renderContext = {
    canvasContext: context,
    transform,
    viewport,
  };
  page.render(renderContext);
</script>

</body>
</html>
```
2024-07-11 11:30:45 +02:00
calixteman
9b1b5ff7e7
Merge pull request #18419 from calixteman/reuse_old_dict_when_updating
[Editor] Update the freetext annotation dictionary instead of creating a new one when updating an existing freetext
2024-07-11 11:24:15 +02:00
Jonas Jenwald
e8d35c25ee
Merge pull request #18412 from Snuffleupagus/issue-18059
Also update the width/unicode data when replacing missing glyphs in non-embedded Type1 fonts (issue 18059)
2024-07-11 10:52:17 +02:00
Jonas Jenwald
b56e4209a9
Merge pull request #18421 from Snuffleupagus/bug-1907000
Allow e.g. /FitH destinations without additional parameter (bug 1907000)
2024-07-11 10:51:44 +02:00
Calixte Denizet
6711123f68 [Editor] Update the freetext annotation dictionary instead of creating a new one when updating an existing freetext 2024-07-11 10:44:21 +02:00
Jonas Jenwald
403d023617 Allow e.g. /FitH destinations without additional parameter (bug 1907000)
According to the PDF specification these destinations should have a coordinate parameter, which may however be `null`, but it shouldn't be omitted; please see https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf#G11.2095870

Hence we try to work-around bad PDF generators by making the coordinate parameter optional when validating explicit destinations in both the worker and the viewer.
2024-07-11 10:36:44 +02:00
Tim van der Meij
cf58113e8c
Merge pull request #18416 from razh/ensureMinimumFontSize-body-flex
Fix `ensureMinFontSizeComputed` calculation if `<body>` is a flex container
2024-07-10 16:17:26 +02:00
razh
665fff020e Fix ensureMinFontSizeComputed calculation if <body> is a flex container
Given:

```css
html,
body {
  height: 100%;
}

body {
  display: flex;
}
```

The `<div>` appended to the `<body>` will take up the full height of the
viewport due to the implicit `align-items: stretch` of flex containers.

This results in an incorrect computed `minFontSize` value.
2024-07-10 08:41:09 -04:00
calixteman
b1bf8b4979
Merge pull request #18418 from calixteman/wait_for_rendering
[Editor] Wait for 'pagerendered' to switch to editing mode
2024-07-10 12:18:21 +02:00
Calixte Denizet
d27efb43cd [Editor] Wait for 'pagerendered' to switch to editing mode
The focus can potentially be stolen when the DOM is modified when adding
a new canvas element for the page being redrawn.
2024-07-10 11:29:42 +02:00
Tim van der Meij
7ffea2f02a
Merge pull request #18413 from Snuffleupagus/BasePreferences-AppOptions-wrapper
Re-factor `BasePreferences` to essentially be a wrapper around `AppOptions`
2024-07-09 23:09:09 +02:00
Jonas Jenwald
d9f0ec0b87 Re-factor BasePreferences to essentially be a wrapper around AppOptions
In the MOZCENTRAL build the `BasePreferences` class is almost unused, since it's only being used to initialize and update the `AppOptions` which means that theoretically we could move the relevant code there.
However for the other build targets (e.g. GENERIC and CHROME) we still need to keep the `BasePreferences` class, although we can re-factor things to move the necessary validation inside of `AppOptions` and thus simplify the code and reduce duplication.

The patch also moves the event dispatching, for changed preference values, into `AppOptions` instead.
2024-07-09 22:49:59 +02:00
Jonas Jenwald
56653e5770 Also update the width/unicode data when replacing missing glyphs in non-embedded Type1 fonts (issue 18059)
*Please note:* This causes a little bit of movement in the `issue2770` test-case, however this matches the rendering in both Adobe Reader and PDFium.
2024-07-09 09:41:01 +02:00
Jonas Jenwald
f9d63201eb Revert "Remove the unused Font.prototype.spaceWidth getter (PR 13424 follow-up)"
This reverts commit 4aee67227e.
2024-07-09 09:28:10 +02:00
Jonas Jenwald
7ffa9a283d Extend test-coverage for non-embedded Type1 fonts where .notdef glyphs are replaced with spaces 2024-07-09 09:12:09 +02:00
Tim van der Meij
1bdd6920ff
Merge pull request #17962 from calixteman/chrome_bidi
Use BiDi protocol for Chrome tests
2024-07-07 22:07:29 +02:00
Calixte Denizet
5bfe759574 Use BiDi protocol for Chrome tests 2024-07-07 17:12:00 +02:00
calixteman
2a125bd0f0
Merge pull request #18405 from timvandermeij/intermittent-waitforscripting
Introduce a `waitForScripting` helper function and use it in all scripting integration tests
2024-07-07 14:13:32 +02:00
Tim van der Meij
b540b6333f
Introduce a waitForScripting helper function and use it in all scripting integration tests
Code inspection uncovered that quite a few integration tests don't wait
for scripting to be ready before proceeding, which is a source of
intermittent failures, especially on slower machines where e.g. creating
the sandbox takes longer.

This commit fixes the issues by introducing a `waitForScripting` helper
function and calling it consistently in all scripting integration tests.
2024-07-06 19:29:45 +02:00
Jonas Jenwald
5ee61690f3
Merge pull request #18390 from alexcat3/fix-issue-18099
Handle toUnicode cMaps that omit leading zeros in hex encoded UTF-16 (issue 18099)
2024-07-06 18:57:07 +02:00
Tim van der Meij
145951df88
Merge pull request #18404 from timvandermeij/fix-unit-intermittent
Fix the "caches image resources at the document/page level as expected (issue 11878)" unit test
2024-07-06 17:32:55 +02:00
alexcat3
1c364422a6 Handle toUnicode cmaps that omit leading zeros in hex encoded UTF-16 (issue 18099)
Add unit test to check compatability with such cmaps

In the PDF in issue 18099. the toUnicode cmap had a line to map the glyph char codes from 00 to 7F to the corresponding code points. The syntax to map a range of char codes to a range of unicode code points is
<start_char_code> <end_char_code> <start_unicode_codepoint>
As the unicode code points are supposed to be given in UTF-16 BE, the PDF's line SHOULD have probably read
<00> <7F> <0000>
Instead it omitted two leading zeros from the UTF-16 like this
<00> <7F> <00>
This confused PDF.js into mapping these character codes to the UTF-16 characters with the corresponding HIGH bytes (01 became \u0100, 02 became \u0200, et cetera), which ended up turning latin text in the PDF into chinese when it was copied
I'm not sure if the PDF spec actually allows PDFs to do this, but since there's at least one PDF in the wild that does and other PDF readers read it correctly, PDF.js should probably support this
2024-07-06 11:29:21 -04:00
Tim van der Meij
2a44203d96
Fix the "caches image resources at the document/page level as expected (issue 11878)" unit test
This unit test fails occasionally (albeit much less than before thanks
to PR #17663), so we change the parsing time check's divisor to prevent
it from happening again. If the last page's rendering time is less than
or equal to 50% of the first page's rendering time that should be enough
proof that no worker thread re-parsing occurred while also providing a
wide enough range to avoid intermittents.

Note that the assertion is now equal to the one we already have in the
"caches image resources at the document/page level, with main-thread
copying of complex images (issue 11518)" unit test which seems to work
reliably so far.
2024-07-06 16:30:07 +02:00
Tim van der Meij
bb3e3164e6
Merge pull request #18402 from Snuffleupagus/updatedPreference-move-listener
Move the "updatedPreference" event listener registration
2024-07-06 15:54:14 +02:00
Tim van der Meij
fe692435d3
Merge pull request #18401 from timvandermeij/test-orphaned-browsers
Fix orphaned browser processes due to uncaught exceptions in the tests
2024-07-06 15:43:26 +02:00
Jonas Jenwald
9e352a8bad Move the "updatedPreference" event listener registration
This patch fixes a situation that'll probably never happen, but nonetheless seems like something that we should address.
Currently the "updatedPreference" listener isn't registered *until after* the preferences have been read and initialized, which leaves a very short window of time where a preference change could theoretically be skipped.
2024-07-06 15:28:03 +02:00
Tim van der Meij
3afe2d3048
Fix orphaned browser processes due to uncaught exceptions in the tests
If uncaught exceptions occur in the tests (which happened in #17962 and
can be triggered manually by throwing an error in `integration-boot.js`)
the teardown logic of the tests doesn't get to run and thus spawned
browser processes are not closed properly. Given that `test.mjs` is the
only process that has a reference to them they will become orphaned and
keep running if `test.mjs` exits without explicitly closing them.

This commit fixes the issue by always closing the browsers if uncaught
exceptions occur, and we make sure to log them for debugging purposes.
2024-07-06 15:07:54 +02:00
calixteman
db9115625b
Merge pull request #18398 from calixteman/bug1905923
[Editor] Change the enableML pref for enableAltText (bug 1905923)
2024-07-05 22:51:15 +02:00
Tim van der Meij
7a5f5616f4
Merge pull request #18399 from timvandermeij/intermittent-charlimit
Fix the "must check that charLimit is correctly set" scripting integration test
2024-07-05 21:58:04 +02:00
calixteman
9f001058c3
Merge pull request #18397 from calixteman/toolbar_density
Allow to change the toolbar height when changing the pref toolbar.density in Firefox (bug 1171799)
2024-07-05 21:50:10 +02:00
Tim van der Meij
70b44251ed
Fix the "must check that charLimit is correctly set" scripting integration test
This integration test fails intermittently because we're not (correctly)
awaiting the character limit increase sandbox action.

For the first increase an attempt was made to handle this, but it doesn't
work correctly because the text in the field is `abcdefghijklmnopq` and
it's not be truncated until the sandbox action is completed, so because
we didn't await that we would could pass the `value !== "abcdefgh"` check
because `abcdefghijklmnopq !== abcdefgh` is true. For the second increase
we didn't have a check in place.

This commit fixes the issues by using the `waitForSandboxTrip` and
`waitForSelector` helper functions to make sure that we can only proceed
if the sandbox action is completed and the DOM element is updated.
2024-07-05 21:15:44 +02:00
Calixte Denizet
0fba6e570e [Editor] Change the enableML pref for enableAltText (bug 1905923)
We want to use this pref to make a Nimbus experiment in the next weeks.
2024-07-05 21:01:12 +02:00
Calixte Denizet
0910f17a58 Allow to change the toolbar height when changing the pref toolbar.density in Firefox (bug 1171799)
It's a first step to just dispatch the pref change to the toolbar.
The second one, to effectively use it, will come after PR #18385 is merged.
2024-07-05 18:59:29 +02:00
calixteman
e777ae2258
Merge pull request #18380 from calixteman/avoid_dbl_ml_queries
[Editor] Avoid to query ML engine several times for the same image
2024-07-05 17:44:31 +02:00
Tim van der Meij
ccb141e211
Merge pull request #18393 from Snuffleupagus/mustBeViewedWhenEditing-params
Check the relevant parameters inside of the `mustBeViewedWhenEditing` method
2024-07-05 15:33:45 +02:00
Tim van der Meij
cf9dfbc084
Merge pull request #18394 from Snuffleupagus/rm-annotation-getOperatorList-renderForms
Remove the `renderForms` parameter from the Annotation `getOperatorList` methods
2024-07-05 15:30:52 +02:00
Calixte Denizet
5274bab9f3 [Editor] Avoid to query ML engine several times for the same image 2024-07-05 13:43:11 +02:00
Jonas Jenwald
38528d1116 Remove the renderForms parameter from the Annotation getOperatorList methods
The `renderForms` parameter pre-dates the introduction of the general `intent` parameter, which means that we're now effectively passing the same state twice to these `getOperatorList` methods.
2024-07-05 12:25:18 +02:00
Jonas Jenwald
5f744904ac Check the relevant parameters inside of the mustBeViewedWhenEditing method
Similar to the `mustBeViewed` method, we can check the relevant parameters within the `mustBeViewedWhenEditing` method itself since that (in my opinion) slightly helps readability of the code in the `src/core/document.js` file.
2024-07-05 11:38:55 +02:00
Tim van der Meij
9065ee465b
Merge pull request #18387 from Snuffleupagus/RenderingIntentFlag-IS_EDITING
Move the internal API/Worker `isEditing`-state into `RenderingIntentFlag`
2024-07-04 23:42:44 +02:00
Jonas Jenwald
a4ffc1066c Move the internal API/Worker isEditing-state into RenderingIntentFlag
In *hindsight* this seems like a better idea, since it avoids the need to manually pass `isEditing` around as a boolean value.
Note that `RenderingIntentFlag` is *internal* functionality, not exposed in the official API, which means that it can be extended and modified as necessary.
2024-07-04 23:34:30 +02:00
calixteman
8c5b0191cf
Merge pull request #18389 from calixteman/remove_pref_stamp
[Editor] Remove the option enableStamp
2024-07-04 23:06:42 +02:00
Calixte Denizet
74cbfbd09f [Editor] Remove the option enableStamp 2024-07-04 22:01:35 +02:00
Tim van der Meij
790470c1aa
Merge pull request #18383 from calixteman/fix_print_test
Fix the integration tests related to printing
2024-07-04 11:34:06 +02:00
Tim van der Meij
03a0500dcf
Merge pull request #18374 from calixteman/test_editor_visible
Make sure the editor is visible before getting its rect
2024-07-04 11:14:27 +02:00
Calixte Denizet
53ddfd139f Fix the integration tests related to printing 2024-07-04 11:12:31 +02:00
Tim van der Meij
944f3acecd
Merge pull request #18367 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2024-07-04 11:12:25 +02:00
Jonas Jenwald
396231b90c
Merge pull request #15209 from Snuffleupagus/createDefaultPrefsFile
[Firefox] Generate a PDF.js default-prefs file that can be used directly in mozilla-central (bug 1905864)
2024-07-04 11:06:48 +02:00
calixteman
617f513806
Merge pull request #18369 from calixteman/bug1905623
Use vertical variant of a char when it's in a missing vertical font (bug 1905623)
2024-07-04 09:45:43 +02:00
Calixte Denizet
fd6d0be50f Make sure the editor is visible before getting its rect 2024-07-03 09:57:12 +02:00