4680 Commits

Author SHA1 Message Date
calixteman
c7a32c3db6
Merge pull request #21343 from calixteman/issue9437
Clamp out-of-range BlueScale to Adobe's valid window
2026-05-29 08:58:05 +02:00
Calixte Denizet
600986b51d Allow inserting an image as a new page when editing a PDF
Image files dropped on or selected via the thumbnail viewer's
"add file" picker are now accepted alongside PDFs and inserted
as synthetic pages sized to the document's modal page dimensions.

The image-encoding helper previously embedded in StampAnnotation has
moved to src/core/editor/pdf_images.js so it can be shared between
stamp annotations and page synthesis.
2026-05-28 22:11:13 +02:00
calixteman
389853d473
Merge pull request #21336 from calixteman/issue15292
Parse CID-keyed Type 1 fonts instead of falling back to a system font
2026-05-28 21:45:30 +02:00
Tim van der Meij
7d305ff281
Merge pull request #21335 from calixteman/multiple_merge
Allow merging several PDFs at once via the picker or drag-and-drop
2026-05-28 21:01:05 +02:00
Tim van der Meij
be8a8c4309
Merge pull request #21348 from calixteman/issue21346
Use a black backdrop for Luminosity SMasks when /BC is missing
2026-05-28 20:46:47 +02:00
Titus Wormer
45cdb5d3e8
Add support for encrypted attachments
This PR is related to GH-20732, which is about `AuthEvent` (to delay
promting for a password), but instead adds the actual support for
encrypted attachments.
“Encrypted attachments” means that the main things are plain text.
Note that some PDF viewers, like Preview/QuickLook/Safari or Chrome,
do not support attachments at all.
Note that the file checked into the tests is the same as
`output-no-auth-event.pdf` referenced in
<https://github.com/mozilla/pdf.js/issues/20139#issuecomment-3952462166>.

Closes GH-20139.
2026-05-28 10:30:37 +02:00
Calixte Denizet
a33e06cafb Use a black backdrop for Luminosity SMasks when /BC is missing
It fixes #21346.
2026-05-26 22:36:50 +02:00
calixteman
385b1ca412 Clamp out-of-range BlueScale to Adobe's valid window
Fonts that ship a BlueScale outside the range AFDKO considers valid
for their zone heights (0.5/maxZoneHeight <= BlueScale <= 1/maxZoneHeight)
cause Firefox's CFF rasterizer to misalign overshooting glyphs against
flat-topped ones at body sizes.
Clamp into that window, only apply the lower clamp when BlueScale is
also smaller than the default, so foundry fonts that pair the default
0.039625 with small zones are untouched.

Fixes #9437.
2026-05-26 21:24:51 +02:00
calixteman
e1de5c30b5 Parse CID-keyed Type 1 fonts instead of falling back to a system font
It fixes #15292.

PDFs can embed a CID-keyed Type 1 program (Adobe TechNote 5014,
CIDFontType 0) under /Subtype /CIDFontType0 + /FontFile. Its binary
CIDMap/SubrMap layout has no eexec block, so Type1Font's eexec-only
parser used to fall through and trigger the work-around added in
PR #15397.
Split the constructor and parse the binary CIDMap, SubrMap
and charstrings (encrypted with the standard Type 1 charstring cipher)
through the existing Type1CharString.convert + CFF wrap pipeline.

Only single-FDArray fonts are supported; the StartData length is
clamped to the stream's remaining bytes before allocating.
2026-05-26 17:49:56 +02:00
Calixte Denizet
6b92ad5924 Allow merging several PDFs at once via the picker or drag-and-drop 2026-05-25 21:09:42 +02:00
Tim van der Meij
e7661983f7
Merge pull request #21333 from calixteman/fix_test_timeout
Recover the browser session on test timeout to keep running subsequent tests
2026-05-25 18:27:31 +02:00
Tim van der Meij
d1c85f87f7
Merge pull request #21330 from calixteman/fix_regex
Enable 'eslint-plugin-regexp' and fix existing findings
2026-05-25 18:22:21 +02:00
Calixte Denizet
91ca580f31 Recover the browser session on test timeout to keep running subsequent tests
When a reftest hangs and trips the per-browser timeout, the session was
closed, which left every remaining task in the per-browserType queue with
no consumer and effectively skipped the rest of the manifest. Instead,
mark the in-flight task(s) as failed, reload the page so the driver can
reconnect and request the next task, and only fall back to closing the
session if the reload itself fails.
2026-05-25 16:50:55 +02:00
calixteman
f82382e010
Merge pull request #21331 from calixteman/fix_cjk_file
Load the predefined CMap for composite fonts that omit the FontDescriptor
2026-05-25 16:40:11 +02:00
Calixte Denizet
8f85e3f20b Load the predefined CMap for composite fonts that omit the FontDescriptor
and add font substitutions for the standard Acrobat CJK families.
2026-05-25 14:44:48 +02:00
calixteman
164ffb9042
Merge pull request #21321 from danyalahmed1995/fix/issue-21259-text-layer-spacing
Prevent inherited spacing from affecting text layer
2026-05-25 14:36:22 +02:00
Calixte Denizet
7bda0fc97c Enable 'eslint-plugin-regexp' and fix existing findings
Enable the recommended preset and fix or per-line-disable the 78
findings it surfaces. Most are equivalent rewrites, intentional
patterns (control chars, the whatwg email regex, autolinker URL regex)
keep their behavior via targeted disables.
2026-05-25 14:31:55 +02:00
Calixte Denizet
9391296036 Recover CFF FontBBox with negative coordinates encoded as unsigned 16-bit
It fixes #21312.
2026-05-25 08:36:18 +02:00
Danyal Ahmed
4ee9c39fc8 Prevent inherited spacing from affecting text layer
Fixes #21259.

Reset letter-spacing and word-spacing on the text layer and hidden measurement canvas so inherited page styles do not affect text layer alignment. Add an integration regression test for inherited spacing.
2026-05-24 23:56:23 +05:00
calixteman
adcde1175e Substitute a system font when an embedded CFF is truncated
It fixes #7625.

If the Top DICT's Private DICT extends past the end of the font data,
the Local Subrs INDEX is unreachable and every CharString that calls
a subr ends up as a blank glyph. Throw from parsePrivateDict so the
existing catch in translateFont triggers fallbackToSystemFont, then
run getFontSubstitution post-construction so we pick a close local
match instead of the generic fallbackName.
2026-05-24 18:10:09 +02:00
calixteman
143a7244a3
Merge pull request #21315 from calixteman/issue18548
Keep the first /Subrs and /CharStrings block
2026-05-24 18:07:20 +02:00
Tim van der Meij
941e17296e
Merge pull request #21313 from Snuffleupagus/Annotation-OC
Add support for Optional Content in the AnnotationLayer (issue 20433)
2026-05-24 15:02:06 +02:00
calixteman
1f8eed020f Keep the first /Subrs and /CharStrings block
Some Type1 fonts (the embedded Optima variants in orw1972.pdf) ship
two /Subrs and /CharStrings blocks wrapped in save/restore frames
gated on an Adobe hires/lores runtime switch.
In such cases, we just use the first /Subrs and /CharStrings block,
which is the one that is actually used by the font renderer in Acrobat.

It fixes #18548.
2026-05-24 15:01:22 +02:00
Jonas Jenwald
057507f6ce Use Uint8Array.fromBase64 in the test/integration/highlight_editor_spec.mjs file 2026-05-24 10:56:51 +02:00
calixteman
ea18e73de2
Merge pull request #20542 from calixteman/fontfile3
Use the CFF program directly for CID fonts wrapped in OpenType FontFile3
2026-05-23 21:39:13 +02:00
Jonas Jenwald
fb9758303b Add support for Optional Content in the AnnotationLayer (issue 20433) 2026-05-23 12:33:56 +02:00
calixteman
98e3a85a44
Merge pull request #21300 from calixteman/issue21298
Sanitize glyf composite cycles, OS/2 length and maxp version mismatches
2026-05-21 21:45:33 +02:00
Calixte Denizet
d6a2b91243 Sanitize glyf composite cycles, OS/2 length and maxp version mismatches
Prune the back-edge components from cyclic composite glyphs in
sanitizeGlyphLocations (leaving non-cyclic siblings intact), reject OS/2
tables whose length is too short for the declared version so a clean
table gets regenerated, and upgrade a version 0.5 maxp table to 1.0 for
TrueType fonts to silence OTS' "wrong maxp version for glyph data".

It fixes #21298.
2026-05-21 21:24:00 +02:00
Tim van der Meij
52d574c539
Merge pull request #21306 from calixteman/dnd_pdf_merging
Allow merging a PDF by dropping it onto the thumbnail viewer
2026-05-21 21:01:42 +02:00
Tim van der Meij
9b5cd3db64
Merge pull request #21304 from Snuffleupagus/PdfTextExtractor-tests
Add basic integration-tests for the `PdfTextExtractor` class
2026-05-21 20:27:53 +02:00
Tim van der Meij
93f01aa412
Merge pull request #21311 from Snuffleupagus/getPdfFilenameFromUrl-test-corrupt-relative
Extend unit-test coverage for the `getPdfFilenameFromUrl` helper function
2026-05-21 20:19:48 +02:00
Tim van der Meij
42db304268
Merge pull request #21305 from Snuffleupagus/integration-test-EventBus-on
Don't use "internal" `EventBus` methods in the integration-tests
2026-05-21 20:17:28 +02:00
Calixte Denizet
0f90987927 Fix 'Select all' after #20981 2026-05-21 16:39:34 +02:00
Jonas Jenwald
74471651c7 Extend unit-test coverage for the getPdfFilenameFromUrl helper function
Currently there's a couple of branches, specifically for dealing with corrupt URLs, that are not covered by tests.
2026-05-21 14:03:32 +02:00
Calixte Denizet
d79043b3af Allow merging a PDF by dropping it onto the thumbnail viewer
Drop an external PDF anywhere in the views-manager thumbnail
sidebar to merge it at the cursor, rather than always inserting
after the current page via the "Add file" button.

The drop reuses the blue separator from page-move drag so the
user can see exactly where the inserted pages will land, and the
merge path is shared with the existing picker so post-merge
selection/current-page behavior stays consistent.
2026-05-20 18:06:55 +02:00
Jonas Jenwald
429b469ecb Add basic integration-tests for the PdfTextExtractor class 2026-05-20 17:26:50 +02:00
Jonas Jenwald
abe8b564a3 Don't use "internal" EventBus methods in the integration-tests
This way *guarantees* that any and all internal viewer state has been updated first, before any test-specific code runs.
2026-05-20 16:39:21 +02:00
calixteman
5a4d93a238
Merge pull request #20981 from wooorm/wooorm/hcm
Make text selection more visible (bug 1879559)
2026-05-20 15:49:01 +02:00
Titus Wormer
957e004e38
Make text selection more visible (bug 1879559)
References <https://bugzilla.mozilla.org/show_bug.cgi?id=1879559>
(“In HCM, the text selection is barely visible”).

Continues work from @calixteman who had a partial patch.

This PR improves viewer text-selection highlighting by rendering
selection shapes in the draw layer.

* add selection overlay rendering in the draw layer
  * significant code relates to selections spanning multiple text
    layers/pages, and edges/end-of-content boundaries
* clear selection on rotate/scale/scroll/spread changes

My main question is: how should it appear?
I don’t have access to the Figma file linked on bugzilla.

In the CSS (`draw_layer-builder.css`) there are 3 blocks:

* default
* `@supports` for browsers supporting `backdrop-filter`
* `forced-colors` mode

So it’s possible to design for those (or more).
Personally, the `backdrop-filter: invert(1)` is the most contrast,
so perhaps it’s better to use something else as the default,
and to use `invert(1)` if high contrast mode is used (maybe with a
`prefers-contrast` media query instead)?
2026-05-19 21:10:12 +02:00
Tim van der Meij
60591388a8
Disable hardware acceleration for Chrome tests
This commit fixes the rendering issue that makes the "must update an
existing annotation" ink editor integration test permafail locally in
Chrome. Note that we already do this for Firefox tests, so this also
improves consistency between the two browsers.

Moreover, improve how we define Chrome options to (similar to their
Firefox counterparts) provide them in a single array, and document the
reasoning for why these options are being set more explicitly.

Fixes #21272.
2026-05-19 21:07:26 +02:00
Tim van der Meij
0d69cc4dcf
Introduce integration tests for the presentation mode functionality
This commit provides coverage for the happy flows of basic operations
like entering/exiting and changing pages.
2026-05-18 20:52:00 +02:00
Tim van der Meij
00af75905f
Merge pull request #21295 from Snuffleupagus/PDFDocumentProperties-more-tests
Add more integration-tests, with multi-page documents, for the `PDFDocumentProperties` dialog
2026-05-18 20:24:41 +02:00
calixteman
abb8e31408
Merge pull request #21261 from calixteman/bug1960363
Add a Content-Security-Policy to pdf.js' viewer.html (bug 1960363)
2026-05-18 18:24:38 +02:00
Jonas Jenwald
1e62f01773 Improve handling of corrupt pages in the PDFDocumentProperties dialog
If the active page is corrupt that currently results in the entire dialog being "blank", thus providing no information, which seems unfortunate and it's easy enough to only skip `pageSizeField` in that rare case.
2026-05-18 17:38:43 +02:00
Jonas Jenwald
e05b6d6f59 Add more integration-tests, with multi-page documents, for the PDFDocumentProperties dialog
Improve test coverage for multi-page documents, to ensure that:
 - Unnecessary re-parsing is avoided where possible.
 - Rotation, in the viewer, is handled correctly.
 - Different page sizes are handled correctly.
2026-05-18 14:24:05 +02:00
Jonas Jenwald
1e9e8fad7e Add helper functions for opening/closing the document properties dialog during testing
This reduces duplication in the various integration-tests.
2026-05-18 13:31:26 +02:00
calixteman
deb532334f
Merge pull request #21290 from calixteman/issue20633
Recover CFF private dict defaults zeroed by Ghostscript
2026-05-17 21:57:16 +02:00
calixteman
cd8a78c4e2
Recover CFF private dict defaults zeroed by Ghostscript
It fixes the issue #20633.
2026-05-17 20:51:35 +02:00
Tim van der Meij
2fb2bc13e0
Merge pull request #21275 from timvandermeij/integration-tests-optimize
Optimize runtime and memory usage of the integration tests
2026-05-17 20:41:43 +02:00
Tim van der Meij
f2bf57f444
Merge pull request #21288 from timvandermeij/unskip-test
Enable the `must check that an existing highlight is ignored on hovering` integration test on Windows
2026-05-17 20:19:42 +02:00