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

19709 commits

Author SHA1 Message Date
Jonas Jenwald
6ce9f97943 Utilize Fluent to format dates in the AnnotationLayer
The `AnnotationLayer` may not display correctly formatted data in PopupAnnotations, especially in the GENERIC viewer, since it's using native methods[1] that depend on the *browser* locale instead of the viewer locale as intended.
With Fluent we're able to improve things since it's got built-in support for formatting dates. Not only does this simplify the JavaScript code slightly, but it also gives the localizer more fine-grained control of the desired output.

Please find additional information here:
 - https://projectfluent.org/fluent/guide/builtins.html
 - https://projectfluent.org/fluent/guide/functions.html

---

[1] `toLocaleDateString`, and `toLocaleTimeString`.
2024-08-25 12:11:02 +02:00
Jonas Jenwald
d96558836e Utilize Fluent to format numbers and dates in PDFDocumentProperties
The `PDFDocumentProperties` dialog may not display correctly formatted data, especially in the GENERIC viewer, since it's using native methods[1] that depend on the *browser* locale instead of the viewer locale as intended.
At the time when this dialog was introduced that was probably all we could easily do, but with Fluent we're able to improve things since it's got built-in support for formatting numbers and dates. Not only does this simplify the JavaScript code, but it also gives the localizer more fine-grained control of the desired output.

Please find additional information here:
 - https://projectfluent.org/fluent/guide/builtins.html
 - https://projectfluent.org/fluent/guide/functions.html

---

[1] `toLocaleString`, `toLocaleDateString`, and `toLocaleTimeString`.
2024-08-25 12:11:02 +02:00
Tim van der Meij
bf778b04a8
Update translations to the most recent versions 2024-08-25 11:40:42 +02:00
Tim van der Meij
c26aac013e
Fix vulnerability in the micromatch dependency
This patch is generated automatically using `npm audit fix` and fixes
CVE-2024-4067 (see https://github.com/advisories/GHSA-952p-6rrq-rcjv),
bringing the vulnerability count back to zero.
2024-08-25 11:39:06 +02:00
Tim van der Meij
5d31fda876
Update dependencies to the most recent versions 2024-08-25 11:38:00 +02:00
Tim van der Meij
037c181af6
Merge pull request #18644 from Snuffleupagus/PDFPrintService-unconditional-toBlob
Use `HTMLCanvasElement.toBlob()` unconditionally in `PDFPrintService`
2024-08-23 20:37:46 +02:00
Tim van der Meij
f11baea3e3
Merge pull request #18643 from Snuffleupagus/l10n-translateOnce
Introduce a `L10n`-method to translate an element once, and use that in `PDFLayerViewer`
2024-08-23 20:36:01 +02:00
Tim van der Meij
f025cecace
Merge pull request #18636 from Snuffleupagus/PDFDocumentProperties-#getL10nStr
Introduce a helper method for fetching l10n-data in `PDFDocumentProperties`
2024-08-23 20:13:19 +02:00
Tim van der Meij
5f7637b9ea
Merge pull request #18635 from calixteman/avoid_print_dialog
Don't show the print dialog when printing in some integration tests
2024-08-23 20:08:04 +02:00
Jonas Jenwald
6a1b1ae6a4 Revoke the blob-URLs used during printing in PDFPrintService 2024-08-23 18:39:28 +02:00
Jonas Jenwald
502a429e3e Use HTMLCanvasElement.toBlob() unconditionally in PDFPrintService
The fallback is very old code, and according to the MDN compatibility data `HTMLCanvasElement.toBlob()` should be available in all browsers that we support now: https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob#browser_compatibility
2024-08-23 18:29:42 +02:00
Jonas Jenwald
584fef5823
Merge pull request #18646 from Snuffleupagus/issue-18645
Support an odd number of digits in hexadecimal strings (issue 18645)
2024-08-23 18:24:19 +02:00
Jonas Jenwald
8728f7f134 Support an odd number of digits in hexadecimal strings (issue 18645)
See https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf#G6.1840792
2024-08-23 16:31:43 +02:00
Jonas Jenwald
fabbe544ab Introduce a L10n-method to translate an element once, and use that in PDFLayerViewer
Currently we *manually* fetch the "pdfjs-additional-layers" string and update the DOM-element, which was needed since we want to avoid triggering a bunch of otherwise unnecessary translation when appending the entire layer-tree to the DOM.
By introducing a new helper method in the `L10n`-class we can avoid this, and instead use a "data-l10n-id" attribute on the element (as most other viewer code does nowadays).
2024-08-23 12:31:55 +02:00
Jonas Jenwald
2c34b64415 Introduce a helper method for fetching l10n-data in PDFDocumentProperties
Given the length of the l10n-strings we can slightly reduce verbosity, and thus overall code-size, by introducing a helper method for fetching l10n-data.

While testing this I stumbled upon an issue in the `L10n`-class, where an optional chaining operator was placed incorrectly since the underlying method always return an Array; see 48e2a62ed4/fluent-dom/src/localization.js (L38-L77)
2024-08-21 15:07:46 +02:00
Jonas Jenwald
908f453384
Merge pull request #18627 from richard-smith-preservica/rcs/send-page-dict-requests-in-parallel
Send fetch requests for all page dict lookups in parallel
2024-08-21 13:58:03 +02:00
Richard Smith (smir)
a67b9aec6c Send fetch requests for all page dict lookups in parallel
- When adding page dict candidates to the lookup tree, also initiate fetching them from xref, so if they are not yet loaded at all, the XHR will be sent
 - Only at the top level - assume that if there is a /Pages tree, it is sensibly structured and the number of requests won't be too bad
- We can then await on the cached Promise without making the requests pipeline
- This has a significant performance improvement for load-on-demand (i.e. with auto-fetch turned off) when a PDF has a large number of pages in the top level /Pages collection, and those pages are spread through a file, so every candidate needs to be fetched separately
 - PDFs with many pages where each page is a big image and all the pages are at the top level are quite a common output for digitisation programmes
- I would have liked to do something like "if it's the top level collection and page count = number of kids, then just fetch that page without traversing the tree" but unfortunately I agree with comments on #8088 that there is no good general solution to allow for /Pages nodes with empty /Kids arrays
2024-08-21 11:08:14 +01:00
Calixte Denizet
b0c239a200 Don't show the print dialog when printing in some integration tests 2024-08-20 22:24:08 +01:00
Tim van der Meij
e0fc1a341a
Merge pull request #18628 from Snuffleupagus/issue-18208
Use standard glyph mapping for non-embedded and non-composite Calibri fonts (issue 18208)
2024-08-19 20:26:56 +02:00
Jonas Jenwald
6dd31183be Use standard glyph mapping for non-embedded and non-composite Calibri fonts (issue 18208)
Given that we handle non-embedded Calibri fonts as "mapped to standard font", we really ought to be able to use the same glyph mapping as for an actual standard font.
Note that this actually improves consistency in the code, given how we already handle such fonts if they happen to be of the `CIDFontType2` type; see b47c7eca83/src/core/fonts.js (L1186-L1190)
2024-08-19 19:10:35 +02:00
Tim van der Meij
88ea60dcde
Merge pull request #18624 from timvandermeij/intermittent-scripting-siblings
Fix the "must check that a value is correctly updated on a field and its siblings" scripting integration test
2024-08-19 19:04:34 +02:00
Tim van der Meij
79dce534f5
Merge pull request #18623 from timvandermeij/uimanager-test
[Editor] Move setting `window.uiManager` back to the test code
2024-08-19 19:04:11 +02:00
Tim van der Meij
5cc77d3ebd
Fix the "must check that a value is correctly updated on a field and its siblings" scripting integration test
This integration test fails intermittently because we cache the initial
total value to be able to compare it to the new total value at the end
of the test to check that it's different before doing the assertions.
However, this doesn't work as expected because the second `clearInput`
call triggers an intermediate total value calculation because it clicks
on another input field and that triggers a sandbox event.

This results in the `waitForFunction` calls always resolving immediately
and since we don't use other means of waiting until the calculation is
done (using e.g. `waitForSandboxTrip`) we basically rely on the time
between the final click and the assertions to be enough for the sandbox
to do its work. If it's is not done in that time, we do the assertions
with older values and that makes the test fail.

This commit fixes the issue by simply waiting for the total value to be
what we expect it to be. This requires less code, is more consistent
with the other integration tests and removes the possibility of doing
assertions against older values.
2024-08-18 19:24:51 +02:00
Tim van der Meij
db06011032
[Editor] Move setting window.uiManager back to the test code
In PR #18574 setting `window.uiManager` was moved into the `src` folder
to avoid intermittent integration test failures because at the time we
lacked a way to register event listeners early (before PDF.js loads).
However, in PR #18617 this functionality got introduced, so we can now
use the new way of setting up the event bus in the tests to move this
back to the `test` folder again and to reduce the amount of test-only
code in the main codebase as discussed in PR #18574.

Partially reverts e037c5711d.
2024-08-18 15:45:42 +02:00
Tim van der Meij
b47c7eca83
Merge pull request #18617 from calixteman/early_event_handler
Set the event handlers in the integration tests before any event is triggered
2024-08-18 15:10:23 +02:00
Calixte Denizet
5e4948062c Set the event handlers in the integration tests before any event is triggered
The function evaluateOnNewDocument in Puppeteer allow us to execute some js before the pdf.js one
is loaded.
It allows us to stub some setters before there are used and then set some event handlers very soon.
2024-08-18 09:57:43 +01:00
Tim van der Meij
f7d3add994
Merge pull request #18615 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2024-08-16 19:02:39 +02:00
Tim van der Meij
0aada51568
Update translations to the most recent versions 2024-08-15 19:52:03 +02:00
Tim van der Meij
f6c2860195
Fix the repository URLs in the importl10n script
We introduced quite a few new strings recently, but during the last few
rounds of updates we didn't see new translations updates becoming
available. I only just now recalled the announcement that Mozilla is
moving from Mercurial to Git, and indeed the Mercurial page at
https://hg.mozilla.org/l10n-central hasn't been updated since July
anymore and that's were we used to pull our translations from.

This commit fixes the issue by changing the URLs to the Mozilla Git
repositories hosted on GitHub instead.
2024-08-15 19:51:48 +02:00
Tim van der Meij
44f7e3c002
Fix vulnerability in the axios dependency
This patch is generated automatically using `npm audit fix` and fixes
CVE-2024-39338 (see https://github.com/advisories/GHSA-8hc4-vh64-cxmj),
bringing the vulnerability count back to zero.
2024-08-15 19:37:05 +02:00
Tim van der Meij
140dd3c99f
Update dependencies to the most recent versions 2024-08-15 19:34:02 +02:00
Tim van der Meij
d8d9cff715
Merge pull request #18612 from Snuffleupagus/_parseHashParams-shorten
Shorten the `PDFViewerApplication._parseHashParams` method
2024-08-15 18:39:35 +02:00
Tim van der Meij
73bae55c5d
Merge pull request #18613 from calixteman/enable_tests
Enable disabled integration tests for Firefox
2024-08-15 18:35:10 +02:00
Calixte Denizet
75e52360ad Enable disabled integration tests for Firefox 2024-08-15 13:11:31 +01:00
Jonas Jenwald
ee7441d5bc Shorten the PDFViewerApplication._parseHashParams method
The way that the debugging hash-parameter parsing is implemented leads to a lot of boilerplate code in this method, since *most* of the cases are very similar.[1]
With just a few exceptions most of the options can be handled automatically, by defining an appropriate checker for each option.

---

[1] With the recent introduction of TESTING-only options the size of this method increased a fair bit.
2024-08-15 13:50:35 +02:00
calixteman
b60261e39a
Merge pull request #18611 from calixteman/fix_telemetry
Fix the telemetry for the new alt-text flow
2024-08-15 12:46:55 +01:00
Jonas Jenwald
17f387b460
Merge pull request #18610 from Snuffleupagus/bug-report-version-description
Link to official releases and the demo viewer in the bug report template
2024-08-15 13:31:05 +02:00
Calixte Denizet
9bd00859d3 Fix the telemetry for the new alt-text flow 2024-08-15 11:29:00 +01:00
Jonas Jenwald
4caa309fda Link to official releases and the demo viewer in the bug report template
Hopefully this might lead to *more* users actually testing the latest version before reporting a bug.
2024-08-15 09:25:21 +02:00
Tim van der Meij
8446d3ac03
Merge pull request #18605 from Snuffleupagus/issue-18196
Handle the "switchannotationeditorparams" event in the editor-code (issue 18196)
2024-08-13 19:42:20 +02:00
Jonas Jenwald
9e0c6ef476 Handle the "switchannotationeditorparams" event in the editor-code (issue 18196)
The problem seems to be caused by the browser trying to "restore" editing input-elements, in the various toolbars, to their previous values when the tab is re-opened.

Hence the simplest solution appears to be to move the event handling into the editor-code, which is also less code overall, since the listener thus won't be registered early enough for the problem to appear.
2024-08-13 15:29:55 +02:00
Jonas Jenwald
82735537bf Use the local eventBus in the AnnotationEditorUIManager constructor
This shortens the code ever so slightly, which cannot hurt.
2024-08-13 14:51:16 +02:00
Jonas Jenwald
038e482760
Merge pull request #18601 from timvandermeij/css-cleanup
Improve the viewer CSS after nesting the findbar and secondary toolbar rules
2024-08-13 12:37:17 +02:00
Jonas Jenwald
14f6cbe2b2
Merge pull request #18604 from Snuffleupagus/version-4.6
Bump library version to `4.6`
2024-08-13 12:30:27 +02:00
Jonas Jenwald
af03894764 Bump library version to 4.6 2024-08-13 12:20:52 +02:00
Jonas Jenwald
a999b346d0
Merge pull request #18549 from nicolo-ribaudo/custom-find-matcher-subclass
[api-minor] Allow specifying custom match logic in PDFFindController
2024-08-13 12:17:27 +02:00
Nicolò Ribaudo
f051597e23
Allow specifying custom match logic in PDFFindController
This patch allows embedders of PDF.js to provide custom match
logic for seaching in PDFs. This is done by subclassing the
PDFFindController class and overriding the `match` method.

`match` is called once per PDF page, receives as parameters the
search query, the page contents, and the page index, and returns
an array of { index, length } objects representing the search
results.
2024-08-13 10:45:57 +02:00
Jonas Jenwald
17b24639b9
Merge pull request #18594 from Snuffleupagus/rm-enableHighlightEditor-pref
Remove the `enableHighlightEditor` preference
2024-08-13 08:14:09 +02:00
Tim van der Meij
9fd23d8082
Generalize the CSS rules for labeled toolbar buttons
This commit fixes a regression from #18596 where the "Add image" button
styles broke because it's a labeled toolbar button but the labeled
toolbar button CSS rules were only scoped to the secondary toolbar.
However, nowadays labeled toolbar buttons are also used in e.g. the
editor parameters toolbar, and this highlighted that we didn't clearly
encode the concept of labeled toolbar buttons in the CSS so far.

This patch extracts the CSS rules for labeled toolbar buttons that were
previously limited to the secondary toolbar into a dedicated generic
class that can be applied on top of any unlabeled toolbar button to
convert it to a labeled toolbar button, regardless of its position in
the DOM. This also makes the distinction clearer in the HTML, and the
new CSS scope for the toolbar buttons lays the foundation for combining
the other toolbar buttons rules in there later on.

Co-authored-by: Calixte Denizet <calixte.denizet@gmail.com>
2024-08-12 20:27:33 +02:00
Tim van der Meij
68bda90777
Improve grouping of the secondary toolbar button CSS rules
Using the `:is(a)` selector we can move the previously separate rules
into the main `.toolbarButton` override rules.

Co-authored-by: Calixte Denizet <calixte.denizet@gmail.com>
2024-08-12 20:08:29 +02:00