Jonas Jenwald
374f524c29
Remove unnecessary Map.prototype.entries() usage
...
A `Map` instance can be iterated directly with a `for...of` loop, hence using its `entries` method is not actually necessary.
2026-02-20 13:44:00 +01:00
Jonas Jenwald
5b368dd58a
Remove the Uint8Array.prototype.toHex(), Uint8Array.prototype.toBase64(), and Uint8Array.fromBase64() polyfills
...
(During rebasing of the previous patches I happened to look at the polyfills and noticed that this one could be removed now.)
See:
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toHex#browser_compatibility
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toBase64#browser_compatibility
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromBase64#browser_compatibility
Note that technically this functionality can still be disabled via a preference in Firefox, however that's slated for removal in [bug 1985120](https://bugzilla.mozilla.org/show_bug.cgi?id=1985120 ).
Looking at the Firefox source-code, see https://searchfox.org/firefox-main/search?q=array.tobase64%28%29&path=&case=false®exp=false , you can see that it's already being used *unconditionally* elsewhere in the browser hence removing the polyfills ought to be fine (since toggling the preference would break other parts of the browser).
2026-01-29 17:27:43 +01:00
Calixte Denizet
516aea5562
[XFA] Set default max value in occur tag to -1 (bug 1998843)
2025-11-21 17:53:38 +01:00
Noritaka Kobayashi
fa568e826d
Fix typos across the codebase
2025-07-07 09:59:36 +09:00
Jonas Jenwald
2979e23f3c
Ensure that XFAFactory.prototype.isValid returns a boolean value
...
Considering the name of the method, and how it's actually being used, you'd expect it to return a boolean value.
Given how it's currently being used this inconsistency doesn't cause any issues, however we should still fix this.
2025-05-04 13:42:17 +02:00
Jonas Jenwald
122822a750
Simplify the loadXfaImages method and related code
...
Currently we create an intermediate `Dict` during parsing, however that seems unnecessary since (note especially the second point):
- The `NameOrNumberTree.prototype.getAll` method will already resolve any references, as needed, during parsing.
- The `Catalog.prototype.xfaImages` getter is invoked, via the `BasePdfManager`-instance, such that any `MissingDataException`s are already handled correctly.
2025-05-02 11:53:41 +02:00
calixteman
91bfe12f38
Merge pull request #19883 from gpanakkal/checkbutton-tostyle
...
Fix arguments in `toStyle` call in `CheckButton`
2025-05-01 22:08:03 +02:00
Gautam Panakkal
7bba3bd4ad
Add missing this arg to toStyle in CheckButton.prototype.[$toHTML]
2025-05-01 10:19:28 -07:00
Jonas Jenwald
834423b51d
Add more logical assignment in the src/ folder
...
This patch uses nullish coalescing assignment in cases where it's immediately obvious from surrounding code that doing so is safe, and logical OR assignment elsewhere (mostly the changes in XFA code).
2025-04-12 17:28:33 +02:00
Jonas Jenwald
9456b88f6b
Remove Array.prototype.reduce usage from the src/core/xfa/template.js file
...
Using `Array.prototype.reduce` often leads to less readable code, and in these cases we can replace that with other Array-methods instead.
2025-03-24 16:40:41 +01:00
Jonas Jenwald
e73224ded7
Introduce Math.sumPrecise usage in the code-base
...
This is a new JavaScript feature that makes it easy to compute the sum of list of values; see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sumPrecise
This allows us to remove most cases of `Array.prototype.reduce`, which helps improve readability since that (in my opinion) often isn't the most intuitive code.
2025-03-23 13:03:56 +01:00
Jonas Jenwald
8a24c1907a
Replace a few simple regular expressions in the XFA-code with string parsing
...
- Add a couple of `limit` parameters in cases where those were "missing", for `String.prototype.split()` calls, to avoid unnecessary parsing.
- Remove some "pointless" initial trimming of leading/trailing spaces, since that's already done at a later parsing step in many cases.
2025-03-15 17:25:26 +01:00
Jonas Jenwald
1b5151f969
Remove pointless Math.min usage in the XFA parsing
...
When creating the `StyleMapping` for the "xfa-font-horizontal-scale" and "xfa-font-vertical-scale" properties there's currently pointless `Math.min` usage, since we're not actually comparing with anything.
2025-03-08 12:22:33 +01:00
Jonas Jenwald
bee0f53c65
Use the MathClamp helper function more (PR 19617 follow-up)
...
There's a few spots that I accidentally missed in PR 19617.
2025-03-08 12:19:56 +01:00
Jonas Jenwald
07bbbf75a5
Introduce a helper function for clamping a value to a range
...
Currently we have a number of spots in the code-base where we need to clamp a value to a [min, max] range. This is either implemented using `Math.min`/`Math.max` or with a local helper function, which leads to some unnecessary duplication.
Hence this patch adds and re-uses a single helper function for this, which we'll hopefully be able to remove in the future once https://github.com/tc39/proposal-math-clamp/ becomes generally available.
2025-03-06 14:05:26 +01:00
Jonas Jenwald
bd05b255fa
[api-major] Apply the userUnit using CSS, to fix the text/annotation layers (bug 1947248)
...
Rather than modifying the "raw" dimensions of the page, we'll instead apply the `userUnit` as an *additional* scale-factor via CSS.
*Please note:* It's not clear to me if this solution is fully correct either, or if there's other problems with it, but it at least *appears* to work.
---
With these changes, the following CSS variables are now assumed to be available/set as necessary: `--total-scale-factor`, `--scale-factor`, `--user-unit`, `--scale-round-x`, and `--scale-round-y`.
2025-02-11 14:36: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
Pascal Maximilian Bremer
6d7157a875
Fix Typo:XFATemplate class Para Styling paddingight => paddingRight
2024-11-06 12:04:55 +01:00
Jonas Jenwald
8f47d06d07
Add helper functions to allow using new Uint8Array methods
...
This allows using the new methods in browsers that support them, e.g. Firefox 133+, while still providing fallbacks where necessary; see https://github.com/tc39/proposal-arraybuffer-base64
*Please note:* These are not actual polyfills, but only implements what we need in the PDF.js code-base. Eventually this patch should be reverted, once support is generally available.
2024-10-29 10:22:35 +01:00
Jonas Jenwald
bfc645bab1
Introduce some Uint8Array.fromBase64 and Uint8Array.prototype.toBase64 usage in the main code-base
...
See https://github.com/tc39/proposal-arraybuffer-base64
2024-10-29 10:22:35 +01:00
Jonas Jenwald
f9a384d711
Enable the arrow-body-style ESLint rule
...
This manually ignores some cases where the resulting auto-formatting would not, as far as I'm concerned, constitute a readability improvement or where we'd just end up with more overall indentation.
Please see https://eslint.org/docs/latest/rules/arrow-body-style
2024-01-21 16:20:55 +01:00
Jonas Jenwald
c0fe96b8fe
Additional *manual* unicorn/prefer-ternary changes
...
Not all cases could be automatically fixed, and the changes also triggered a number of `prefer-const` errors that needed to be handled manually.
2023-07-27 09:48:24 +02:00
Jonas Jenwald
674e7ee381
Enable the unicorn/prefer-ternary ESLint plugin rule
...
To limit the readability impact of these changes, the `only-single-line` option was used; please find additional details at https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-ternary.md
These changes were done automatically, using the `gulp lint --fix` command.
2023-07-27 09:18:26 +02:00
Jonas Jenwald
c018070e80
Enable the no-lonely-if ESLint rule
...
These changes were mostly done automatically, using `gulp lint --fix`, and only a few spots with comments needed manual tweaking; please see https://eslint.org/docs/latest/rules/no-lonely-if
2023-07-21 20:10:44 +02:00
Jonas Jenwald
fee850737b
Enable the unicorn/prefer-optional-catch-binding ESLint plugin rule
...
According to MDN this format is available in all browsers/environments that we currently support, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch#browser_compatibility
Please also see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-optional-catch-binding.md
2023-06-12 11:46:11 +02:00
Jonas Jenwald
cf3a35e9da
Enable the import/no-cycle ESLint plugin rule
...
Having cyclical imports is obviously not a good idea, and this ESLint plugin rule can help detect those; please see https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-cycle.md
2023-06-04 13:44:15 +02:00
Jonas Jenwald
e8030752f3
Introduce even more modern JavaScript features in the code-base
...
After PR 12563 we're now free to use e.g. logical OR assignment, nullish coalescing, and optional chaining in the entire code-base.
2023-05-18 18:55:41 +02:00
Jonas Jenwald
1b4a7c5965
Introduce more optional chaining in the src/core/ folder
...
After PR 12563 we're now free to use optional chaining in the worker-thread as well. (This patch also fixes one previously "missed" case in the `web/` folder.)
For the MOZCENTRAL build-target this patch reduces the total bundle-size by `1.6` kilobytes.
2023-05-15 12:38:28 +02:00
Jonas Jenwald
89f768322d
Introduce some optional chaining in the src/core/xfa/ folder
...
After PR 12563 we're now free to use optional chaining in the worker-thread as well.
2023-05-07 12:49:07 +02:00
Jonas Jenwald
d950b91c4e
Introduce some logical assignment in the src/core/ folder
2023-04-29 13:49:37 +02:00
Jonas Jenwald
96e34fbb7d
Enable the unicorn/prefer-negative-index ESLint plugin rule
...
Please see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-negative-index.md
2023-03-24 10:18:32 +01:00
Jonas Jenwald
1fc09f0235
Enable the unicorn/prefer-string-replace-all ESLint plugin rule
...
Note that the `replaceAll` method still requires that a *global* regular expression is used, however by using this method it's immediately obvious when looking at the code that all occurrences will be replaced; please see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll#parameters
Please find additional details at https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-string-replace-all.md
2023-03-23 12:57:10 +01:00
nmtigor
22cc9b7dc7
Fix property chain orders of Operators in isDotExpression and isSomPredicate
2022-09-21 17:20:23 +02:00
Calixte Denizet
f5b835157b
[XFA] Fix an hidden issue in the FormCalc lexer
...
Since there are no script engine with XFA, the FormCalc parser is not used irl.
The bug @nmtigor noticed was hidden by another one (the wrong check on `match`).
2022-09-20 13:53:55 +02:00
Jonas Jenwald
20b9887476
Enable the unicorn/prefer-regexp-test ESLint plugin rule
...
Please see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-regexp-test.md
2022-09-19 16:34:01 +02:00
Jonas Jenwald
dcc73423e5
Enable the unicorn/prefer-logical-operator-over-ternary ESLint plugin rule
...
This leads to ever so slightly more compact code, and can in some cases remove the need for a temporary variable.
Please find additional information here:
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-logical-operator-over-ternary.md
2022-07-12 10:52:37 +02:00
Jonas Jenwald
1c9a702f73
Enable the prefer-array-index-of ESLint plugin rule
...
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-array-index-of.md
2022-06-21 16:54:32 +02:00
Calixte Denizet
e2db9bacef
Get rid of CSS transform on each annotation in the annotation layer
...
- each annotation has its coordinates/dimensions expressed in percentage,
hence it's correctly positioned whatever the scale factor is;
- the font sizes are expressed in percentage too and the main font size
is scaled thanks a css var (--scale-factor);
- the rotation is now applied on the div annotationLayer;
- this patch improve the rendering of some strings where the glyph spacing
was not correct (it's a Firefox bug);
- it helps to simplify the code and it should slightly improve the update of
page (on zoom or rotation).
2022-06-18 17:54:59 +02:00
Jonas Jenwald
010d996b74
Enable the unicorn/prefer-array-flat and unicorn/prefer-array-flat-map ESLint plugin rules
...
These rules will help enforce shorter and more readable code, and according to MDN these Array-methods are available in all browsers/environments that we currently support:
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat#browser_compatibility
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap#browser_compatibility
Please find additional information about these ESLint rules here:
- https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-array-flat.md
- https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-array-flat-map.md
2022-06-11 11:33:43 +02:00
Jonas Jenwald
9ac4536693
Enable the unicorn/prefer-at ESLint plugin rule (PR 15008 follow-up)
...
Please find additional information here:
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at
- https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-at.md
2022-06-09 21:21:19 +02:00
Calixte Denizet
2dd0c861bf
Outline fields which are required (bug 1724918)
...
- it aims to fix https://bugzilla.mozilla.org/show_bug.cgi?id=1724918 ;
- it applies for both Acroform and XFA.
2022-06-07 17:02:11 +02:00
Sean Wei
6bf978404e
Use correct case for JavaScript
2022-04-21 23:56:28 +08:00
apeltop
a97dd26389
Correct typos
2022-04-09 09:43:18 +09:00
calixteman
bbd8b5ce9f
Merge pull request #14319 from calixteman/xfa_arc
...
XFA - Draw arcs correctly
2021-11-27 11:32:32 -08:00
Calixte Denizet
31e13515f5
XFA - Draw arcs correctly
...
- it aims to fix #14315 ;
- take into account the startAngle to compute the coordinates of the final point.
2021-11-27 19:30:12 +01:00
Calixte Denizet
cfdaa57353
Handle sub/super-scripts in rich text
...
- it aims to fix #14317 ;
- change the fontSize and the verticalAlign properties according to the position of the text.
2021-11-27 16:06:09 +01:00
Calixte Denizet
5b7e1f5232
XFA - Avoid an exception when looking for a font in a parent node
...
- it aims to fix issue https://github.com/mozilla/pdf.js/issues/14150 ;
- a parent can be null in case the root has been reached, so just add a check.
2021-11-12 16:27:08 +01:00
calixteman
4bb9de4b00
Merge pull request #14239 from calixteman/1739502
...
XFA - Fix a breakBefore issue when target is a contentArea and startNew is 1 (bug 1739502)
2021-11-08 03:14:42 -08:00
Calixte Denizet
13ae6d493a
XFA - Encode tag names in UTF-8 when saving ( fix #14249 )
2021-11-07 21:41:37 +01:00
Calixte Denizet
1681e25008
XFA - Get each page asynchronously in order to avoid blocking the event loop ( #14014 )
2021-11-06 13:25:03 +01:00