Commit Graph

3106 Commits

Author SHA1 Message Date
Jonas Jenwald
0650be4641
Merge pull request #16550 from Snuffleupagus/rm-RenderingCancelledException-type
[api-minor] Remove the `type` from `RenderingCancelledException` (PR 16226 follow-up)
2023-06-15 12:26:27 +02:00
Jonas Jenwald
225734dd00 [api-minor] Remove the type from RenderingCancelledException (PR 16226 follow-up)
After PR 16226 we're only using `RenderingCancelledException` together with canvas-rendering, hence the `type`-property is no longer necessary.
2023-06-14 15:40:25 +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
Calixte Denizet
1a047f843c [Editor] Add the possibility to update an existing annotation with some new properties when saving or printing 2023-06-09 17:14:53 +02:00
Calixte Denizet
3d0ce1cff2 Concat data when push fails in the CFF compiler 2023-06-09 15:48:01 +02:00
Calixte Denizet
baebf7b26d [Editor] Fix test failures in m-c because of the new FreeText undo/redo stuff 2023-06-08 13:38:52 +02:00
Calixte Denizet
2f0bb9dc2f [Editor] Allow to undo/redo committed text modifications for FreeText 2023-06-05 21:31:19 +02:00
Calixte Denizet
ba8c996623 [Editor] Guess font size and color from the AS of FreeText annotations 2023-06-05 17:15:17 +02:00
Tim van der Meij
8a5af64749
Merge pull request #16519 from timvandermeij/puppeteer
Improve Puppeteer's `trimCache` API usage
2023-06-04 14:35:30 +02:00
Tim van der Meij
a9093a7f4d
Improve Puppeteer's trimCache API usage
The original `trimCache` functionality was intended to be exposed on the
top-level `puppeteer` module, but due to a bug in Puppeteer this didn't
work correctly and we had to call `trimCache` on the default Puppeteer
node instance instead, which was fortunately exposed. However, since
this didn't feel like intended API usage, this bug was reported and is
now fixed in Puppeteer 20.5.0, so this commits updates Puppeteer to that
version so we can use the intended API.

The full history of this issue can be found at
https://github.com/puppeteer/puppeteer/issues/10174.
2023-06-04 13:49:44 +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
calixteman
63b61ca082
Merge pull request #16508 from calixteman/restore_mk_annotation_layer_an_object
[api-minor] Make the AnnotationLayer an object in order to use it in the AnnotationEditorLayer
2023-06-02 23:12:50 +02:00
Calixte Denizet
4351708ae6 [api-minor] Make the AnnotationLayer an object in order to use it in the AnnotationEditorLayer
It'll be useful to make the Freetext and Ink annotations editable.
2023-06-02 22:44:14 +02:00
Jonas Jenwald
459d26edec Improve handling of mismatching /BaseFont and /FontName entries for non-embedded fonts (issue 7454)
This patch is the result of me going through some old issues regarding non-embedded Wingdings support.

There's a few different things wrong in the referenced PDF document:
 - The /BaseFont and /FontName entries don't agree on the name of the fonts, with one font using `/BaseFont /Wingdings-Regular` and `/FontName /wg09np` which obviously makes no sense.
   To address this we'll compare the font-names against our lists of known ones and ignore /FontName entries that don't make sense iff the /BaseFont entry is a known font-name.
 - The non-embedded Wingdings font also set an incorrect /Encoding, in this case /MacRomanEncoding, which should have been fixed by PR 16465. However this doesn't work since the font has *bogus* font-flags, that fail to categorize the font as Symbolic.
   To address this we'll also compare the font-name against the list of known symbol fonts.
2023-06-02 17:10:25 +02:00
Calixte Denizet
0e610cab04 Try to not omit some values when printing a choice list with several selected items 2023-05-31 21:17:22 +02:00
Calixte Denizet
133d103186 [Editor] Add few more info when saving ink data (thickness, opacity, ...)
Fix the InkList entry: the coordinates were relative to the page and not
to the bounding box of the annotation.
2023-05-31 15:43:07 +02:00
Tim van der Meij
ca620e4cc9
Update Puppeteer to version 20
This commit makes the following required changes:

- Replace custom cache trimming logic in favor of the (per our request)
  newly added `trimCache` method in Puppeteer. Not only does this greatly
  simplify our code and prevents having to import Puppeteer internals,
  it's also necessary because Puppeteer 20 removed the `BrowserFetcher`
  API in favor of the new separate `@puppeteer/browsers` package.
- Start browsers in series instead of in parallel. Parallel browser
  starts broke since Puppetter 19.1.0 and it turns out that it has never
  been supported officially, so it worked more-or-less by accident.
  Starting browsers in series is the supported way, is almost equally
  fast and ensures that we avoid any race conditions during startup.
  Finally, it also allows us to remove the `browserPromise` state on our
  session objects.

Fixes #15865.
2023-05-29 15:45:24 +02:00
Calixte Denizet
78e6020a6e [OTS] Remove cntrmask instruction with no stem in charstring (bug 1529502) 2023-05-28 19:03:37 +02:00
Calixte Denizet
be5db13005 Reset the formatted value when after a text field has been modified 2023-05-26 10:17:14 +02:00
Calixte Denizet
35a58ed987 Extract all the text of text annotations 2023-05-25 23:11:42 +02:00
Jonas Jenwald
5a7beb9f30 Attempt to improve non-embedded Wingdings font support (bug 1652224)
Now that font-substitution has been implemented, we should be able to do much a better job at supporting non-embedded Wingdings fonts.
Given that this is a Windows-specific font, see https://en.wikipedia.org/wiki/Wingdings, this is however not guaranteed to work (well) on other platforms.
2023-05-24 14:59:13 +02:00
Jonas Jenwald
aeed6f2b67 Ignore named encoding for non-embedded symbol fonts (issue 16464)
The affected font is non-embedded ZapfDingbats, however the PDF document for some inexplicable reason specifies the encoding as "WinAnsiEncoding" (which is obviously wrong).
To work-around this bug in the PDF generator, we'll simply ignore any explicitly specified named encoding for non-embedded symbol fonts.
2023-05-24 10:48:47 +02:00
Jonas Jenwald
a6f9505a39
Merge pull request #16461 from Snuffleupagus/issue-16454
Improve "EI" detection in inline images (PR 12028 follow-up, issue 16454)
2023-05-23 22:23:22 +02:00
calixteman
1886012874
Merge pull request #16462 from calixteman/last_elem_TJ
Take into account the final space if any in the TJ command
2023-05-23 21:26:58 +02:00
Calixte Denizet
d2b4ed3cea [Editor] Improve curve smoothing for Ink tool (bug 1789443)
- Remove the dependency on fit-curve;
- Improve the way to draw the current line in using a Path2D and
  in clearing only the last part of the curve instead of clearing
  all the canvas;
- Smooth the curve when drawing to avoid to have some changes after
  the drawing ends;
- Make the smoothing a bit less agressive.
2023-05-23 17:15:21 +02:00
Calixte Denizet
a76a69e1ed Take into account the final space if any in the TJ command
The final space was just ignored and that led to wrongly position
the next chunk of text.
2023-05-23 17:09:32 +02:00
Jonas Jenwald
dfbbb8c0ac Improve "EI" detection in inline images (PR 12028 follow-up, issue 16454)
Given that inline images may contain "EI"-sequences in the image-data itself, actually finding the end-of-image operator isn't always straightforward.
Here we extend the implementation from PR 12028 to potentially check all of the following bytes, rather than stopping immediately. While we have fairly decent test-coverage for this code, whenever you're changing it there's unfortunately a slightly higher than normal risk of regressions. (You'd really wish that PDF generators just stop using inline images.)
2023-05-23 17:04:51 +02:00
Calixte Denizet
ca12bca276 Sanitize the glyph bounding box
- if the contours count is lower than -1, the glyph is really likely wrong
so just remove it from the font;
- if a contour has the repeat flag then repeats count mustn't be 0.
2023-05-21 16:24:41 +02:00
Jonas Jenwald
f657de7de2 Extend getNonStdFontMap for non-embedded Impact fonts (bug 1365930)
According to https://en.wikipedia.org/wiki/Impact_(typeface) this font should be available on all current versions of Windows, and with the recently added font-substitution we should actually be able to render it correctly (at least on Windows).
2023-05-19 18:40:03 +02:00
Jonas Jenwald
8c4821ceda [api-minor] Slightly shorten the marked-content ids used in the textLayer
Generally we try to keep the ids that we create short, hence we can slightly shorten the "static" parts of them.
2023-05-18 22:32:10 +02:00
Jonas Jenwald
04de155aaa Slightly shorten the loadedName-ids used with font-substitutions
Generally we try to keep the ids that we create short, hence we can slightly shorten the "static" part of them.
2023-05-18 22:27:11 +02:00
Calixte Denizet
3091e70aad Flush the current chunk when the font changed because of a restore op (issue #14755) 2023-05-18 19:37:16 +02:00
calixteman
839be801a0
Merge pull request #16433 from calixteman/bug1825002
For text widgets, get the text from the AP stream instead of from the format callback (bug 1825002)
2023-05-17 16:48:59 +02:00
Calixte Denizet
177036e6ae For text widgets, get the text from the AP stream instead of from the format callback (bug 1825002)
When fixing bug 1766987, I thought the field formatted value came from
the result of the format callback: I was wrong. The format callback is ran
but the value is unused (maybe it's useful to set some global vars... or
it's just a bug in Acrobat). Anyway the value to display is the one rendered
in the AP stream.
The field value setter has been simplified and that fixes issue #16409.
2023-05-17 14:07:28 +02:00
Jonas Jenwald
bfb374dbf6 Attempt to fallback to a default font, for non-available ones, in more cases (issue 16432)
This essentially extends PR 11218 to also apply when looking up the final font-reference, via the XRef-table, fails because the font isn't available.

This patch also changes `PartialEvaluator.fallbackFontDict` to simply use "Helvetica" as the default font-name, since that seems generally reasonable given the now existing font-substitution code.
2023-05-17 11:41:08 +02:00
Calixte Denizet
385f275ad9 Warn when pdf.js can't load an OS font 2023-05-16 14:58:38 +02:00
Jonas Jenwald
cb1a10e358 Check the css property in the getFontSubstitution unit-tests
Given that the `css` property isn't constant, since it contains document/font ids, we cannot just check it directly. However, we can make use of regular expressions to ensure that the format is generally correct.
2023-05-14 19:11:35 +02:00
calixteman
4101128c09
Merge pull request #16421 from calixteman/font_subst_test
Add tests for the font substitution
2023-05-14 18:23:12 +02:00
Calixte Denizet
89140fcd98 Add tests for the font substitution 2023-05-14 18:07:03 +02:00
Jonas Jenwald
8fbd6755eb Enable the unicorn/no-useless-promise-resolve-reject ESLint plugin rule
Please see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-useless-promise-resolve-reject.md

Note that this patch also re-sorts the existing `unicorn`-rules in proper alphabetical order.
2023-05-13 11:30:25 +02:00
Jonas Jenwald
8f3940fbf3 Move the sidebar-resizing handling into the PDFSidebar class
Originally the `PDFSidebarResizer` class was slightly larger, since the code used to contain e.g. feature testing for older (and no longer supported) browsers.
Given that there's some amount of overlap, when it comes to what DOM-elements and state that these classes need, it now seems reasonable to simply move the sidebar-resizing into the `PDFSidebar` class.

For the MOZCENTRAL build-target this patch reduces the size of the *built* `web/viewer.js` file by just over `1.1` kilobytes.
2023-05-12 10:00:12 +02:00
Calixte Denizet
cfb908c999 Add a cache to avoid to load several times a local font
On my computer, it takes few tenths of a second to load a local font.
Since a font can be used several times in a document, the cache will
improve performances.
2023-05-10 20:01:21 +02:00
Calixte Denizet
2486536843 Compress the data when saving annotions
CompressionStream API has been added in Firefox 113
(see https://bugzilla.mozilla.org/show_bug.cgi?id=1823619)
hence we can use it to compress the streams with added/modified
annotations.
2023-05-09 14:46:50 +02:00
calixteman
8f2d8f62f3
Merge pull request #16397 from calixteman/issue14565
Make something similar to Acrobat when Underline annotation has no appearance
2023-05-08 21:16:49 +02:00
Jonas Jenwald
dcd55a7164 Enable unicorn/prefer-at unconditionally (PR 15014 follow-up)
Now that Node.js version 18 is required, we should be able to use `Array.prototype.at()` everywhere in the code-base.
2023-05-07 13:43:19 +02:00
Calixte Denizet
6c0fdc6ec2 Make something similar to Acrobat when Underline annotation has no appearance 2023-05-06 21:19:25 +02:00
Jonas Jenwald
722e5910e1 Improve handling of JPEG images with non-standard /Decode-entries (issue 16395)
The /Decode-implementation in the our JPEG decoder, i.e. `src/core/jpg.js`, seems to only handle *inverting* of images properly. To support arbitrary /Decode-entries correctly we'll always use the `PDFImage.decodeBuffer` method, even for "simple" JPEG images, which should be fine since non-default /Decode-entries aren't a very common occurrence.

*Please note:* This patch will lead to a little bit of movement in some existing test-cases, however it should be virtually imperceivable to the naked eye.
2023-05-06 13:55:39 +02:00
calixteman
f151a39d14
Merge pull request #16387 from calixteman/issue16384
[Annotations] Draw readonly annotations on their own canvas and show the HTML elements when there is a JS interaction (issue #16384)
2023-05-04 21:49:08 +02:00
Calixte Denizet
72da14f005 [Annotations] Draw readonly annotations on their own canvas and show the HTML elements when there is a JS interaction (issue #16384) 2023-05-04 20:08:32 +02:00
calixteman
a24e11a91c
Merge pull request #16106 from bungeman/improve_color_stop_detection
Better approximate gradient color stops
2023-05-04 19:48:57 +02:00