100 Commits
Author SHA1 Message Date
calixteman 857d643f46 Merge pull request #22622 from calixteman/text_layer_zoom
Zoom the text layer with CSS and only set a transform on the spans which need one
2026-11-30 14:54:29 +01:00
Calixte Denizet 34246a0b6f Zoom the text layer with CSS and only set a transform on the spans which need one
The span font sizes are in page units and the transform is only set when the
span is rotated, skewed or scaled, which makes the layout cheaper.
The free highlight box comes from the editor layer: with the pre-standard CSS
zoom (Chrome < 128, Safari 18), the zoomed text layer client rect is scaled.
2026-11-30 13:45:33 +01:00
calixteman 9e2f31c843 Merge pull request #22620 from calixteman/bug2088921
Keep editors upright when dragging between pages (bug 2088921)
2026-11-29 20:49:48 +01:00
calixteman 31fefbf113 Restore editor page geometry when undoing or redoing a drag
Restore the saved page dimensions, origin, and rotation when the page
layer is absent. Adjust positions for zoom-dependent drawing padding
and replay moves without clamping again.
2026-11-29 18:57:44 +01:00
calixteman 13488cd659 Keep editors upright when dragging between pages (bug 2088921)
Use each editor's current page rotation to convert drag deltas and
remap its position through screen coordinates when switching pages.
Update the page origin, preserve the editor's size, and compensate for
rotation changes where supported. Reject pages that are too small.
2026-11-29 18:52:54 +01:00
calixteman b952a35894 Share editor positioning and ink outline helpers
Reuse rotation and zoom helpers. Build ink SVG updates in one place
and refresh the path transform after translation.
2026-11-29 18:50:45 +01:00
calixteman 62f8448934 Merge pull request #22617 from calixteman/text_layer_kerning
Add the kerning of the PDF glyphs to the text layer fonts
2026-11-29 15:33:20 +01:00
Calixte Denizet b4390e4220 Add an test to check that the text layer font passes OTS 2026-11-29 15:16:35 +01:00
Calixte Denizet 2477bb1aed Add the kerning of the PDF glyphs to the text layer fonts
The pairs adjusted the same way are kerned in the generated font, so the
characters of a span stay at their PDF position. The highlights are painted
with a box shadow to avoid breaking the kerning.
2026-11-29 15:04:20 +01:00
calixteman eb8b817fde Merge pull request #22618 from calixteman/fix-issue-22616
Fix function-based shading scaled by the CTM
2026-11-28 17:09:21 +01:00
Calixte Denizet b29564d94c Fix function-based shading scaled by the CTM
A function-based shading was sampled at one step per user-space unit of
its own matrix, so a unit domain scaled up by the CTM, a form matrix or
a pattern matrix was drawn with a single cell.
The sampling grid is now computed from the transform the shading is
painted with, and the generated meshes are cached per grid size.

The setFillColorN/setStrokeColorN cases are merged so the base transform
is only passed in one place.

The software mesh rasterizer now clamps triangles to the canvas, so
pixels on the right edge no longer wrap into the next row.

It fixes #22616.
2026-11-28 16:36:15 +01:00
calixteman e530237a48 Merge pull request #22607 from calixteman/text_layer_glyph_runs
[api-major] Build the text layer items from the runs of glyphs drawn on the same baseline
2026-11-27 13:54:32 +01:00
Calixte Denizet 86d659b564 [api-major] Replace the getTextContent options with enableMarkedContent and enableNormalization
Both are true by default, which is what the viewer mostly uses.
2026-11-27 13:39:55 +01:00
Calixte Denizet 487aed7102 Use #textLayer=visible to draw the glyph boxes of the text layer fonts
The viewer gets debugTextLayerFonts from the page loading params, and the
"shadow" and "hover" debugging modes are removed.
2026-11-27 13:39:55 +01:00
Calixte Denizet 3c0c300a38 Use the d1 bounds of the Type3 glyphs for the ascent of the text layer fonts
The FontBBox can be a placeholder, e.g. [0 0 1000 1000] with a flipped font
matrix, which put the spans below the glyphs (bug 1245391).
2026-11-27 13:39:55 +01:00
Calixte Denizet 5a21695c4a Remove the old text content extraction
Annotation text and the highlight intersector now use the glyph runs too, so
the old item builder in the evaluator is gone.
Also make debugTextLayerFonts a getDocument option, and copy-all split the
text like the text layer.
2026-11-27 13:39:55 +01:00
Calixte Denizet 2e39fea37e Build the text layer items from the runs of glyphs drawn on the same baseline
Group glyphs with the same baseline, font and transform into runs. Infer
word spaces from the positions and tracking within each run, and split
runs into spans at wide gaps.

Compute span advances in the worker from the generated font metrics so
the text layer can lay out simple spans without measuring them. Find
uses the same extracted items as the text layer.
2026-11-27 13:39:55 +01:00
Calixte Denizet 5b1be07686 [api-major] Always include generated fonts in page text content 2026-11-27 13:39:55 +01:00
calixteman a2b1756760 Merge pull request #22611 from mozilla/update-locales
l10n: Update locale files
2026-11-27 08:53:00 +01:00
Calixte Denizet b6dea1c1a6 Use the default value for text fields only on reset
It fixes #22602
2026-11-26 18:35:31 +01:00
calixteman ac7d3717e4 Merge pull request #22601 from calixteman/fix/chrome-marked-content-selection
Allow Chrome text selection to end one character earlier
2026-11-26 10:42:11 +01:00
Calixte Denizet bf490904ba Allow Chrome text selection to end one character earlier 2026-11-26 09:44:35 +01:00
calixteman 808186117c Merge pull request #22589 from calixteman/bug2091402
Don't generate a Hellbox fallback when a system font covers the glyphs (bug 2091402)
2026-11-25 22:43:05 +01:00
calixteman 908c0ffa1a Merge pull request #22598 from calixteman/text-matrix-allocation
[api-minor] Reduce matrix allocations during text extraction
2026-11-25 22:26:36 +01:00
Calixte Denizet f87060e41b [api-minor] Reduce matrix allocations during text extraction
TextItem.transform is now a Float32Array.
2026-11-25 22:20:48 +01:00
Calixte Denizet 11d84b6f5e Don't generate a Hellbox fallback when a system font covers the glyphs (bug 2091402)
Probe the installed substitute in the worker and cache coverage for each requested glyph. Generate the fallback when a glyph is missing or coverage cannot be verified.
2026-11-25 10:26:54 +01:00
calixteman 98100629a8 Merge pull request #22593 from calixteman/bidi_hebrew_presentation_forms
Get the bidi classes and mirroring from the Unicode data
2026-11-25 08:54:49 +01:00
Calixte Denizet c0fe85c05a Mirror the RTL characters in bidi()
The text is in visual order, so e.g. a ')' at an RTL level is a '(' in the
logical text. A glyph is only mirrored when its shape, from the glyph names or
the cmap of the font or else from the encoding, is its ToUnicode character,
since a ToUnicode map can already give the logical one.
Also stop removing '<' and '>', a leftover from 2012.
2026-11-24 22:43:08 +01:00
Calixte Denizet 6dbf5a89aa Get the bidi classes from the Unicode data in bidi()
The hand-written ranges gave a wrong class to many characters (e.g. ₪, €,
punctuation, Hebrew presentation forms, U+FEFF), hence a wrong reordering in
the text layer and in find. The table is generated from DerivedBidiClass.txt,
and surrogate pairs are now kept together.
2026-11-24 22:34:12 +01:00
calixteman 3471ae1691 Merge pull request #22591 from calixteman/text_layer_type3_fonts
Improve the text layer fonts of Type 3 fonts
2026-11-24 18:52:43 +01:00
Calixte Denizet 5ec739bca3 Improve the text layer fonts of Type 3 fonts
- Encode the advances which don't fit in the font with the smallest power of
  two scale, and fit even a single glyph of such a font.
- Express the advances and space gaps of a font sized by its bbox in the em of
  the span, whose height is the bbox height.
- Keep the baseline of a drawing on an edge of the bbox, and don't flip the
  bbox twice when the span height already carries the flip.
- Measure the inferred spaces in the em of the text state which moved the
  text, and skip the gaps whose em is unknown.
2026-11-24 18:05:12 +01:00
calixteman 32fb05b3b7 Merge pull request #22588 from calixteman/perf/document-scoped-image-options
Scope the image options to each document
2026-11-23 17:42:18 +01:00
Calixte Denizet 67b1fd636d Scope the image options to each document
Give each document its own `ImageResizer`, and let `JpegStream` and the
operator-list optimizer read the options from their own document.
2026-11-23 16:43:00 +01:00
calixteman 812dcf65f4 Merge pull request #22587 from calixteman/perf/document-scoped-wasm
Scope the Wasm image decoders and PostScript functions to each document
2026-11-23 16:41:47 +01:00
Calixte Denizet 17b6112f74 Scope the Wasm image decoders and PostScript functions to each document
Cache the decoders per document `binaryDataContext`, as for the ICC color
spaces, instead of using static options and whichever handler is alive.
2026-11-23 16:16:38 +01:00
Calixte Denizet 4381f49c06 Load the qcms glue on demand 2026-11-23 10:21:20 +01:00
Calixte Denizet 8cf87b4403 Load ICC color spaces asynchronously 2026-11-21 18:32:37 +01:00
Calixte Denizet 103d04d586 Create annotations asynchronously 2026-11-21 18:32:37 +01:00
calixteman 62466e5b8f Merge pull request #22562 from calixteman/perf/lazy-parser-worker-modules
Split rarely used code out of the Firefox worker into on-demand chunks
2026-11-20 19:30:44 +01:00
Calixte Denizet ae016c420f Load OpenJPEG and JBIG2 codec glue on demand 2026-11-20 17:28:28 +01:00
Calixte Denizet db22b2c294 Load PostScript calculator functions on demand 2026-11-20 17:28:27 +01:00
Calixte Denizet 74999b6415 Make PDF function and color space parsing asynchronous
Prepare callers for loading calculator functions on demand. Keep
function streams reusable and reject circular stitching functions.
2026-11-20 17:28:27 +01:00
Calixte Denizet bb8f1ce78a Load decryption code only for encrypted PDFs 2026-11-20 17:28:27 +01:00
Calixte Denizet bc4502493f Load PDF writing and flattening code on demand 2026-11-20 17:28:27 +01:00
Calixte Denizet f26eafcae3 Load the JavaScript JPEG decoder only on fallback 2026-11-20 17:28:27 +01:00
Calixte Denizet b48eadaffa Load XFA forms and annotation rich text on demand 2026-11-20 17:28:27 +01:00
Calixte Denizet 20071a3a6e Load the PDF editor on demand in the Firefox worker 2026-11-20 17:28:27 +01:00
Calixte Denizet 5808a188a5 Configure Gulp to emit named Firefox worker chunks 2026-11-20 17:28:27 +01:00
calixteman 87f2fa772d Merge pull request #22571 from mozilla/update-locales
l10n: Update locale files
2026-11-20 09:17:46 +01:00
calixteman 09b9c48c56 Refresh drawing geometry when an editor is rebuilt 2026-11-19 20:55:43 +01:00
calixteman 5c30f30c78 Keep ink strokes stationary when zooming near a page edge 2026-11-19 20:55:42 +01:00
calixteman 2715d468f6 Find the destination page on the last pointer move 2026-11-19 20:55:40 +01:00
calixteman 22d5507352 Merge pull request #22549 from calixteman/text_layer_invisible_fonts
Use fonts with empty glyphs and the PDF advances in the text layer
2026-11-19 17:23:28 +01:00
Calixte Denizet 376f8b3b93 Use fonts with empty glyphs and the PDF advances in the text layer
The worker builds, with `includeTextLayerFonts`, a font per PDF font of the
page from the advances of the drawn glyphs, so that the characters of a span
are where the canvas draws them. The viewer uses them when the
`newTextLayerMode` option is 1, or 2 to draw the glyph boxes in red.
2026-11-19 16:34:20 +01:00
Calixte Denizet f8fe9a715d Ignore the hhea ascent and descent of a font when they're obviously wrong
Some embedded fonts have a positive or huge descent in their hhea table (e.g.
in issue16839.pdf): keep the ascent and descent from the font descriptor in
that case, since they're used to put the text layer spans at the right height.
2026-11-19 16:34:20 +01:00
calixteman 36e19fa637 Merge pull request #22559 from calixteman/preload-ui-icons-earlier
Schedule UI icon preloading during viewer initialization
2026-11-19 13:37:07 +01:00
Calixte Denizet 738f9191ef Schedule UI icon preloading during viewer initialization
It avoids to do it while the first page is rendering on the main thread.
Thanks to this patch, preloading happens while the module is loading in the worker.
2026-11-19 09:32:51 +01:00
calixteman fc0822a07e Merge pull request #22554 from ohall-m/bug-2084998-signature-description
Bug 2084998 - Improve the presentation of signature elements that no longer have an edit toolbar
2026-11-18 20:48:51 +01:00
calixteman 1b510d78ee Merge pull request #22552 from calixteman/issue22550-tricky-font-name
Restore family names for tricky TrueType subsets
2026-11-18 18:57:29 +01:00
calixteman 4e15347578 Restore family names for tricky TrueType subsets
Some old CJK fonts (e.g. DFKai-SB) rely on their glyph programs to position
their components. OTS fixes the glyph bounding boxes unless the font has a
known "tricky" family name, and on macOS this moves the components, hence the
glyphs are garbled.
Subsetted fonts embedded in PDFs have often lost their original name, so
identify them, as FreeType does, either with their name or with the checksums
of their cvt, fpgm and prep tables, and restore a Macintosh family name that
OTS recognizes.

It fixes #22550.
2026-11-18 15:42:35 +01:00
calixteman 041259d4cc Merge pull request #22551 from calixteman/bug2094402
Preserve page edges when rounding page dimensions (bug 2094402)
2026-11-18 15:19:51 +01:00
calixteman 2cd69dbc03 Merge pull request #22543 from calixteman/perf-loca-offsets
Avoid per-offset work when rebuilding the loca table (bug 2093310)
2026-11-18 14:34:48 +01:00
Calixte Denizet 476d8b48e4 Preserve page edges when rounding page dimensions (bug 2094402)
At fractional device pixel ratios, rounding page dimensions can clip the
right and bottom edges. Fit the full viewport into the rounded canvas
to keep it aligned with the text and annotation layers. Preserve the
canvas sizing scale across redraws.
2026-11-18 13:57:09 +01:00
Calixte Denizet 5d658a546a Composite non-isolated blend groups with a group alpha against their backdrop
Such a group was rendered on a transparent canvas, so e.g. /ColorDodge
light rays kept their dark source color instead of brightening the
background. Copy the backdrop, as already done for soft masks, and
interpolate between it and the group result using the group alpha.

It fixes #22547.
2026-11-17 17:27:07 +01:00
Calixte Denizet cb1097d797 Avoid per-offset work when rebuilding the loca table (bug 2093310)
Choose the loca format from the last offset and the glyph lengths, and
write the offsets with plain byte stores. The output is unchanged, but
it removes ~0.8 ms of cold worker time per TrueType font that #22464
added, enough to flip some pdfpaint loads to the next frame.
2026-11-16 21:59:07 +01:00
calixteman 60aefc5b51 Merge pull request #22538 from calixteman/unbalanced_restore
Ignore unmatched restores in content streams
2026-11-16 18:09:17 +01:00
Calixte Denizet 29170a0060 Ignore unmatched restores in content streams
And simplify a bit the tests.
2026-11-16 17:48:29 +01:00
calixteman 3dc920d0da Merge pull request #22542 from calixteman/viewer-preview-pdfs
Link the PR test PDFs in the viewer preview comment
2026-11-16 17:42:56 +01:00
Calixte Denizet 3836a81166 Link the PR test PDFs in the viewer preview comment
Publish the PDFs added or modified in test/pdfs with the viewers, and
list them in the comment with links opening them in the master website
viewer and in the PR viewer, for both modern and legacy builds.

Linked PDFs aren't republished and their hosts don't allow CORS, so only
list their original URLs.
2026-11-16 17:22:17 +01:00
calixteman 00cb9dca5b Merge pull request #22539 from calixteman/hidden_form_state
Save and restore the state of hidden form XObjects
2026-11-16 17:05:00 +01:00
Calixte Denizet 29d883fb5a Save and restore the state of hidden form XObjects
Their operators still change the transform and the clip.
2026-11-15 20:49:46 +01:00
calixteman bb1539a2c9 Merge pull request #22537 from calixteman/update-hellbox
Update Hellbox
2026-11-15 20:48:28 +01:00
Calixte Denizet ae629c08bf Update Hellbox
The Unicode tables are coded with the range coder of Hellbox: unicode.bin is 2,639 bytes instead of 14,262, the Wasm module 131,848 bytes instead of 132,729, and the JS fallback 60,131 bytes with Brotli instead of 59,029.
2026-11-15 17:29:07 +01:00
calixteman d82ed35f1f Merge pull request #22449 from calixteman/flatten-firefox-save
Support flattening in Firefox save events (bug 2075337)
2026-11-15 17:17:01 +01:00
calixteman 0322a85c19 Support flattening in Firefox save events (bug 2075337)
Forward flatten and intent through saving and extraction, including
unedited PDFs. Run WillPrint/DidPrint for print flattening.
2026-11-15 16:41:03 +01:00
calixteman fd74114d14 Merge pull request #22448 from calixteman/flatten-extract-pages
[api-minor] Support annotation flattening in extractPages (bug 2075337)
2026-11-15 16:38:58 +01:00
calixteman bef7c2f025 [api-minor] Support annotation flattening in extractPages (bug 2075337)
Reuse the save path to flatten extracted pages. Remap pending form edits
to copied annotations and reload with the encryption source's password.
Rebuild the PDF to discard the unflattened revision.
2026-11-15 15:55:49 +01:00
calixteman 58262b1cf4 Merge pull request #21381 from calixteman/user_activation_window
Make the viewer's handling of scripting commands more robust
2026-11-15 15:44:21 +01:00
calixteman 9f04474344 Merge pull request #22447 from calixteman/flatten-struct-tree
Update the structure tree when flattening annotations (bug 2075337)
2026-11-15 15:41:13 +01:00
Calixte Denizet cf8aa3c835 Require a user gesture to print, save, download or follow a link
A script can trigger some events on its own, e.g. a timer, or focus an
element under the pointer or the keyboard, hence the viewer has to decide
by itself whether an action comes from the user.

The events caused by a trusted user gesture (Action, Mouse Down and Mouse
Up) and the Open event, which may only print, get a one-time token. The
host keeps it out of the sandbox and attaches it to the commands sent
while the event is handled. The annotation actions which print, save,
download or follow a link are checked the same way, and only one of them
is honored per gesture. A gesture is ignored when the keyboard activates
an element focused by a script, or when it follows a layout change made
by a script too closely.
2026-11-15 15:05:22 +01:00
Calixte Denizet 290290c247 Only show a dialog from the sandbox while handling an event allowed by the viewer
Nothing coming from the sandbox can be trusted: it grants itself a user
activation for any event, and a script can trigger some events on its own
(e.g. a timer calling setFocus).

Hence the host only shows a dialog, once, while handling an event for
which the viewer allows it: the ones caused by the user, Open, and the
print/save ones. A focus change requested by a script no longer counts
as a user activation.
2026-11-15 15:01:19 +01:00
Calixte Denizet ad1c3b7f69 Coalesce repeated SaveAs requests into a single download
A script can request many downloads in a row: start a new one only once
the previous one is done.
2026-11-15 15:01:12 +01:00
Calixte Denizet cbf87af2d6 Update the structure tree when flattening annotations (bug 2075337)
Replace the OBJR of a flattened annotation with a marked-content reference to
its drawing in the page content; a parent tree with kids is rewritten flat.
If the parent tree can't be read, only remove the OBJR.
2026-11-15 14:47:30 +01:00
calixteman 8de5cf6958 Merge pull request #22530 from calixteman/smask_change_blend_mode
Preserve blend modes across soft-mask changes
2026-11-15 11:59:02 +01:00
Calixte Denizet 9eea18756f Preserve blend modes across soft-mask changes
Track the blend mode in the graphics state; the soft-mask scratch
context uses source-over.

It fixes #22489.
2026-11-14 23:17:00 +01:00
calixteman 34d902ede2 Merge pull request #22446 from calixteman/flatten-forms
[api-minor] Support form field flattening in saveDocument (bug 2075337)
2026-11-14 21:38:56 +01:00
Calixte Denizet 0b230df276 [api-minor] Support form field flattening in saveDocument (bug 2075337)
With `flatten: true`, also draw the widgets, generating their appearances
from the stored values, and remove the ones hidden for the intent. Prune
the removed fields from the AcroForm, and remove it when no page widget
remains, unless it declares signatures. Add a "non-forms" value to keep the
form fields.
2026-11-14 21:14:58 +01:00
calixteman 070445eef7 Merge pull request #22342 from calixteman/flatten-annotations-2075337
[api-minor] Support annotation flattening in saveDocument (bug 2075337)
2026-11-14 21:12:09 +01:00
calixteman 4bbb1840aa [api-minor] Support annotation flattening in saveDocument (bug 2075337)
Add flatten and intent options to draw supported annotation appearances
into page content. Use print or display visibility. Keep the widgets and
the interactive annotations.

Android 14's PdfRenderer calls PDFium without FPDF_ANNOT [1].

[1] https://android.googlesource.com/platform/frameworks/base/+/refs/tags/android-14.0.0_r1/libs/hwui/jni/pdf/PdfRenderer.cpp
2026-11-14 20:27:15 +01:00
calixteman d4da7f6542 Merge pull request #22526 from calixteman/issue16754-mirrored-text
Fix the text content of mirrored text (e.g. RTL text from Tesseract)
2026-11-14 18:50:43 +01:00
calixteman 06e73c1b8d Merge pull request #22525 from calixteman/issue22433-bidi-nsm
Type the non-spacing marks outside of the Hebrew/Arabic blocks as NSM in bidi()
2026-11-14 17:47:29 +01:00
Calixte Denizet effe259abc Fix the text content of mirrored text (e.g. RTL text from Tesseract)
Tesseract draws the RTL words with a mirrored text matrix, hence the glyphs
are in logical order and drawn from right to left. So reverse them in order to
have them in visual order before running bidi(), and give the item a transform
starting at its left end to avoid having the span rotated in the text layer.
Some invisible format marks (e.g. LRM) can have a width, which mustn't be
ignored when computing the item position and width.

It fixes #16754 and #6509.
2026-11-14 17:10:10 +01:00
Calixte Denizet 571843eed8 Type the non-spacing marks outside of the Hebrew/Arabic blocks as NSM in bidi()
Such marks (e.g. U+034F or U+0300-U+036F) were typed as L, hence they were
creating their own LTR run in RTL text and the following marks were reordered.

It fixes #22433.
2026-11-14 16:51:52 +01:00
Calixte Denizet 7a99223b1e Don't add link attributes to an XFA rich text link with an invalid URL
An invalid URL (e.g. javascript:) is replaced by an empty string in the worker,
and passing it to addLinkAttributes threw.
2026-11-14 15:06:38 +01:00
calixteman 5f2d7186f7 Merge pull request #22521 from calixteman/issue16880-rtl-ligatures
Keep together the chars of a glyph when reordering the text content
2026-11-13 22:16:35 +01:00
Calixte Denizet 4dfe24fc43 Keep together the chars of a glyph when reordering the text content
When a glyph maps to several chars (e.g. a lam-alef ligature), they're in
logical order but bidi() was reversing them with the rest of the RTL run.
So now bidi() gets the glyphs and reorders them as a whole when all their
chars have the same level. The normalization is done per glyph in order to
handle the presentation forms expanded into several chars.

It fixes #16880.
2026-11-13 19:57:07 +01:00
calixteman caa4c311ae Merge pull request #22520 from calixteman/fix-geckoview-integration-tests
Enable the `enableAndroidEditing` option in the GeckoView integration tests
2026-11-13 19:53:55 +01:00
Calixte Denizet 41d6710e54 Enable the enableAndroidEditing option in the GeckoView integration tests
Since #22515, the annotation editor is disabled in GeckoView unless the `enableAndroidEditing` preference is set.
2026-11-13 16:19:25 +01:00
calixteman 5430213a11 Merge pull request #22515 from ohall-m/bug-2061833-android-editing
Bug 2061833 - Begin using `enableAndroidEditing` Preference for GeckoView
2026-11-13 14:03:40 +01:00
calixteman 211e9a25aa Merge pull request #22519 from Snuffleupagus/issue-22518
[api-minor] Enable the `enableHWA` and `enableWebGPU` options by default
2026-11-13 14:02:05 +01:00