Commit Graph
532 Commits
Author SHA1 Message Date
FredApps 53b12279a9 Merge pull request #3523 from storytold/fix/3511-prune-image-resources
fix(edit): unlink unused image resources on delete
2026-11-26 19:37:22 +01:00
FredApps 814e19b00d Merge pull request #6590 from eliets2/fix/issue-3147-image-arrange-and-remove-crop-report-suc
Refuse image arrange and crop removal that change nothing
2026-11-26 16:49:51 +01:00
FredApps bb4df817aa Merge pull request #3539 from KnottyDyes/squad/paragraph-grouping-breaks
Text: paragraphs respect typography and filled panels
2026-11-26 16:45:08 +01:00
FredApps 47a79c01e3 Merge pull request #3836 from jonathanwxh-cell/fix/glyphless-ocr-font-edit
fix(edit): substitute a visible font when editing glyphless OCR text
2026-11-26 16:36:54 +01:00
FredApps 8856cb2753 Merge main into #3539 2026-11-26 21:55:31 +07:00
FredApps 8022b70ec2 edit: a Form drawn in Tr 3 still counts as paint when arranging an image
Text rendering mode 3 hides the text a Form shows, not its paths and images,
so a Form XObject after Tr 3 can still paint over or under the image. Counting
it as no paint refused moves that change what is visible. The unit test now
checks that such a Form counts.
2026-11-26 21:03:11 +07:00
FredApps 7fbdc5418a Merge main into #6590 2026-11-26 21:01:02 +07:00
FredApps 6fece518dd Merge main into #3836 2026-11-26 20:53:16 +07:00
FredApps d59d17d086 Merge main into #3523 2026-11-26 20:52:12 +07:00
FredApps cd554c8252 Merge main into #2744 2026-11-26 20:46:06 +07:00
rangoDJ 1525507180 fix(edit): clean /CO and /SigFlags for deep fields and orphans under kept parents (#2670)
The fields left after pruning are now found by walking the kept tree from /Fields, each node once, so a field below the pruning depth cutoff keeps its /CO entry and still counts for /SigFlags. Pruning also cleans /CO and /SigFlags when it only took a field out of a kept parent's /Kids, which left /Fields as long as it was.
2026-11-23 09:07:14 -05:00
rangoDJ 27a86ca28b fix(edit): give the form its own shortened /CO on flatten (#2670)
A calculation order that loses some fields but not all was written back into its indirect array, so any other reference to that array saw the shorter list. The form now gets a direct array with the fields that are left, and the shared object is untouched.
2026-11-23 08:55:20 -05:00
Dylan M. Taylor 333b287a8b Production merge skeleton: upstream/main 9b3e6d6f3 into area/app-1 6cfe35235, conflict markers left in (42 files; 4 modify/delete keep the port's deletion) 2026-11-22 22:39:00 -05:00
skylartaylor bc11efdc8b edit: preserve images when remaining consumers cannot be proved absent 2026-11-21 02:33:15 +01:00
skylartaylor eaf01feb9c Merge current main into image cleanup fix 2026-11-21 00:10:53 +01:00
eliets2 afac05bc7e Format the files this pull request changes 2026-11-20 04:21:12 +02:00
eliets2 4df6f52162 Address review for pull request 6590 2026-11-20 04:21:12 +02:00
eliets2 410f56b13b Refuse image arrange and crop removal that change nothing 2026-11-20 04:21:12 +02:00
jonathanwxh-cell e4d21be49f Merge remote-tracking branch 'upstream/main' into fix/glyphless-ocr-font-edit
# Conflicts:
#	crates/fonts/src/pdf.rs
2026-11-20 08:32:19 +08:00
Dylan M. Taylor 5727e93321 compile fix 8 (all): paragraph painted through ContentPainter components (L-222), comments overlay on PageSession, CanvasAction CopyText/ColourRequest, crates/fonts emits EmbeddedFace (L-221) (swarm/cfix8); committed by the lead 2026-11-18 18:42:29 -05:00
rangoDJ a11775c486 fix(edit): drop the /CO and /SigFlags keys on flatten without freeing shared objects (#2670)
An indirect /CO or /SigFlags object may also be referenced elsewhere, such as
a surviving field's /Ff. Freeing it nulled those references after save.
2026-11-18 16:17:14 -05:00
rangoDJ 59622884ce Merge main into fix/cli-engine-minor-issues and port #2670 onto it
Main rewrote prune_fields to remember each visited node, and moved the
watermark and background tools to documents.rs and the integration tests
to tests/it. The fix now sits on that code:

- prune_fields drops removed fields from /AcroForm /CO, and /CO once it is
  empty, using the nodes the traversal kept. /SigFlags goes when no
  surviving field is a signature field, its /FT read through /Parent.
- doc_watermark and doc_background reject an opacity outside 0..1.
- The opacity assertions move to tests/it/automation.rs.
- The flatten test's surviving signature field is now signed: since #4017
  flattening removes an undrawable field with no value.
2026-11-18 13:24:41 -05:00
chamber074 79b76e609b fix(forms): draw field text the field font cannot hold from the bundled face instead of ?
Fixes #3913 (also reported as #6822, closed as its duplicate).

## What was wrong

The field value was never lost: `/V` is stored losslessly as UTF-16BE, and PdfCraft sets `/NeedAppearances`, which is why other viewers show the Greek correctly. The `?` is only in the appearance PdfCraft draws itself: when the field's `/DR` font can't encode the text, `field_appearance_fit` falls back to Helvetica/WinAnsi, and every character outside WinAnsi is drawn as `?` (and reported through the "This field's font can't draw…" notice).

## The fix

At that fallback decision, characters that neither the field's font nor Helvetica holds but the bundled Inter face does (Latin, Greek, Cyrillic) are now drawn as Type 3 glyphs built from Inter — the same mechanism Thai text already uses in field appearances. Characters no available face holds (e.g. CJK in a Helvetica field) are still drawn as `?` and reported, exactly as before. Text the field's font holds is byte-for-byte unchanged, and no font resource is added in that case.

## Behaviour change to be aware of

Date names in Russian, Czech, Greek, etc. in Helvetica fields (#5303) are now drawn in the date language rather than falling back to English — the "a font that holds them keeps them" rule applied to the bundled face. Japanese still falls back to English. Push-button captions are unchanged (still `?`); same mechanism, possible follow-up.

## Tests

- New forms test `greek_a_field_font_cannot_hold_is_drawn_from_the_bundled_face`: Greek, mixed Latin+Greek (multiline), and exact-WinAnsi strings in a `/Helv` field; asserts the `/V` bytes, no `?` in the appearance, a `PCLa` Type 3 font with ToUnicode, and no undrawn report; a CJK character is still reported. It fails on unmodified code and passes with this change.
- New fonts unit test for splitting a line between the standard font and Inter.
- Updated the engine signature test and the #5303 `form_date_language` tests where they pinned the old `?` behaviour.

Verified locally: `cargo test` for fonts, forms, edit and engine — 1,813 passed, 0 failed; `cargo fmt --check` clean; clippy clean on the touched crates.

*Disclosure: this change was drafted with AI assistance (Claude) under my direction; the diff was reviewed and the verification above was run before opening this PR.*
2026-11-18 16:37:14 +07:00
Perchenko Anton cc0edc29d1 fix(edit): preserve source fonts in mixed-script paragraphs
## Follow-up after #6806

The main mixed-script font change landed in #6806. This PR covers the remaining case where the source font lacks only a variation selector (U+FE00–U+FE0F). A visible letter now selects the fallback face. The regression compares implicit and explicit fallback in two source fonts, including character spacing, alignment, and save/reopen.

Verified locally on macOS arm64 with the CI-pinned craft-fonts input: `cargo test --locked -p pdfcraft-edit` and `cargo test --locked -p pdfcraft-automation --test it mixed_script` passed, as did formatting, scoped Clippy, the layer and asset checks, and the UI WebAssembly build.

<!-- evening-module-refresh-20261027:start -->
**Latest compatibility update (2026-10-27):** [d10080eb](https://github.com/PerchAnton/pdfcraft/commit/d10080eb060d112d75bbcfd0a74e4e0bab38af61) includes main `1dd2737b` through a normal merge.

Source/fallback helpers follow the extracted text modules. The original per-rewrite advance cache, source spaces and batched missing-glyph fallback are preserved. The cache regressions were run with the pinned optional OFL font input.

Local macOS arm64 / Rust 1.99.1: focused regression tests, formatting, scoped all-target Clippy with `-D warnings`, layering and scoped WebAssembly checks pass. Assets and parity checks also pass. Hosted CI is tracked separately on this head. Temporary build outputs and fixtures are cleaned after validation.
<!-- evening-module-refresh-20261027:end -->

<!-- integration-refresh-20261025:start -->
**Latest integration checks (2026-10-25):** head `54423364bba795cff0b56e7c8f168f355062e3bb` includes main `418ac6a2af49b7ac2fed44ca2cae8d5d1d2cec0d` through a normal merge. On macOS arm64 with Rust 1.99.1, 980 scoped tests pass (0 failed, 5 ignored). Formatting, scoped all-target Clippy with `-D warnings`, layers, assets, parity, and the scoped wasm check pass. Test executables and fixtures were removed after each target. Full-workspace and other-platform checks belong to CI on this head. Six permitted OFL craft-fonts faces at release pin `3d9ab3a1` were SHA-256 verified for the font-dependent regressions.
<!-- integration-refresh-20261025:end -->

## What this changes

Fixes #2750.

Adding `шалом` to an upright, single-style Helvetica paragraph used to redraw the Latin text in the fallback face. Keep source fonts now preserves characters with actual source glyphs and batches only missing glyphs in Type 3 fallback fonts. Unencodable boundary spaces remain real, extractable fallback glyphs; source spaces with glyphs keep their face. Original font dictionaries stay intact.

Mixed-run classification and width measurement share a per-character cache within one paragraph rewrite. It stores both source advances and missing-glyph results for that rewrite's metrics, size and character spacing. Wrapping, alignment, justification and underline measurements reuse these widths; the normalized `Tw = 0` state, scaling and summation order stay consistent with drawing. The cache never survives into another rewrite.

## How you verified it

<!-- pdfcraft-conflict-refresh-20261019:start -->
**Current integration verification (2026-10-19):** main `43550c44` is included through a normal merge, preserving published history. Current head [5ea12797](https://github.com/PerchAnton/pdfcraft/commit/5ea127978fce56e64b93e70e7172cda5a193c41c).

Both roadmaps retain every current-main record and estimate, with only this PR's own status, progress and single milestone-row additions. Automatically merged hunks in the touched modules were reviewed.

**732 scoped tests passed, 0 failed, 4 ignored** (edit, engine and automation). Formatting, strict scoped all-target Clippy, scoped WebAssembly and layers/assets/parity pass; whitespace and both roadmap MD028 scans pass. Checks ran on macOS with Rust 1.95, the existing low-disk profile, two Cargo jobs, locked offline dependencies and command timeouts. Optional fonts use the verified release pin `3d9ab3a1`; no new assets or persistent build settings.

These are the checks of the refreshed branch. Broader/native UI observations below are historical; full-workspace and other operating-system checks belong to current-head hosted CI and are tracked separately.
<!-- pdfcraft-conflict-refresh-20261019:end -->

The deterministic work-budget regression was actually RED before caching: 32 source-character measurements for eight distinct characters. It now passes eight cases across two fonts, short/repeated drafts, narrow/maximum-width frames, justification and underlines. A separate saved-document test checks cache isolation across fonts, sizes, spacing and scale against the saved font metrics, wrapped baselines and underline endpoints. Existing extraction, font preservation, fallback batching and refusal regressions pass.

### Reproducible performance probe

`cargo test -p pdfcraft-edit --lib mixed_script_paragraph_rewrite_timing_probe --profile low-disk --locked --offline -j 2 -- --ignored --nocapture`

macOS arm64, Rust 1.95.0, the same existing optimized development profile and release-pinned craft-fonts `3d9ab3a132ed0eff457e424226a435a901da30d3`. Medians of three full `rewrite_block` calls, excluding fixture open, Cargo and extraction. Input repeats `The quick brown fox шалом ` with centre alignment, underline, `Tc = 1.25` and `Tz = 80`.

| UTF-8 bytes | Frame width (pt) | Before (ms) | Cached (ms) | Speedup |
|---|---|---|---|---|
| 992 | 480 | 3.845 | 0.730 | 5.27x |
| 15872 | 480 | 26.913 | 5.333 | 5.05x |
| 63488 | 480 | 103.914 | 19.830 | 5.24x |
| 15872 | 14400 | 418.305 | 28.449 | 14.7x |

Baseline production code is head `7de05471`. These are synthetic measurements, not release-build or 4 MB draft results. Normal tests enforce a deterministic measurement budget rather than a wall-clock threshold. Greedy wrapping still scans candidates, and final run encoding remains necessary.

## Never-crash, provenance and security

- [x] No new production panic paths, input-derived slicing or unsafe code. UTF-8 encoding uses a fixed four-byte buffer; cache keys are distinct input characters.
- [x] Contributor-original synthetic fixtures only; no Adobe assets, font binaries or copied copyleft implementation.
- [x] Existing atomic refusal, root confinement and opt-in MCP/control behaviour are retained; no new network or permission surface.

## Parity and reach

Existing `text_edit`, `text_edit_layout`, CLI and MCP reach this path. Both roadmaps retain one product note with unchanged estimates; text-editing parity remains partial.

## Anything a reviewer should look at first

This applies to upright single-style paragraphs in Keep source fonts mode. Explicit family/weight changes and turned/RTL/visual-order text retain their selection paths. The separate styled-path one-font-per-character issue (#2592), wider glyph coverage (#2593), unused-resource cleanup (#2487) and a different wrapping algorithm remain outside this PR.
2026-11-18 16:30:26 +07:00
regendorf-ux 3516508589 Edit text: space between paragraphs
## What this changes

`edit.line-paragraph-spacing` was partial: line spacing existed, the space between paragraphs did
not. Now a line break in the edited text starts a paragraph, and the paragraphs are set apart:

- `BlockStyle.paragraph_spacing: Option<f64>` (points, beyond the line spacing). `rewrite_block`
  splits the text at line breaks, wraps and justifies each paragraph on its own (the last line of
  each paragraph is never stretched), and steps down by the line spacing plus the gap before a
  paragraph's first line; underlines follow. `None` is half the font size when the text has
  several paragraphs, so a plain Enter already reads as a paragraph; a non-finite value is refused.
- The row-model rewrite (`text_regions`) keeps the rows a line break started apart from wrapped
  ones: the gap goes before those, and a row the page already had sits where it was, shifted by
  the spacing added above it.
- Format text panel: a Paragraph spacing field (points) next to the line spacing; the tool
  `text_edit` takes `paragraph_spacing`.
- Rows for the two labels in all 21 languages; `parity/acrobat-features.toml`
  `edit.line-paragraph-spacing` → shipped (notes: space before and after as separate values are
  still missing).

## How you verified it

Re-run on 2026-10-15 after merging `main` into the branch (41809cf7, then afa8e184). The merge needed the language catalogs (upstream's rows and this PR's kept), ATTRIBUTION.toml's checksums and the tests both sides had appended at the same place; the new Vietnamese catalog got this PR's 2 labels (written by an AI model, like the other languages' rows, so a native speaker's review is welcome). Reconciled with #1486 (line breaks kept when editing a multi-line paragraph): the default gap between paragraphs applies to upright text only; turned text keeps its rows where they were unless a spacing is set. #1539 merged without conflict. A needless borrow clippy found on Windows is fixed.

Full run on Windows (Rust 1.98) at the branch merged with `main` 41809cf7; after `main` afa8e184 was merged, re-checked on macOS (this PR's tests, the `i18n` tests, `cargo clippy --all-targets -- -D warnings` on the changed crates and their dependents (automation, edit, engine, ui-egui, audit, redact, the apps), `cargo xtask assets`):

- [x] `cargo fmt --all --check`, `cargo xtask assets`, `cargo xtask layers`, doctests: exit 0
- [x] `cargo clippy --workspace --all-targets -- -D warnings`: clean on Windows; on macOS the only warnings are `main`'s own (`crates/ui-egui/tests/view.rs`: two helpers used only by a non-macOS test)
- [x] This PR's tests pass: `paragraph_breaks_get_their_own_spacing`, `the_format_panel_has_a_paragraph_spacing_field`, and `main`'s `turned_paragraph_keeps_its_line_breaks_when_a_word_is_added`
- [ ] `cargo nextest run --workspace`: 3422 of 3433 passed on Windows. The 11 failures fail the same way on `main` without this change: the parity file's duplicate keys (also `cargo xtask parity`; #2419 / #2473), the zh-hant duplicates and the Vietnamese coverage tests in `i18n` (none lists this PR's labels), `signing_with_translated_labels_through_tools` (#2429), `canvas::tests::explicit_search_jumps_record_history_and_keep_match_destination`, `view::single_page_swipe_that_reaches_the_edge_does_not_turn_but_a_fresh_one_does`, `editing::files_dropped_beside_the_pages_panel_still_open_as_documents` (intermittent)

**Tests.** `paragraph_breaks_get_their_own_spacing` (edit): a one-line source rewritten as
"First one\nSecond one" gets the row step alone (15 pt for a 10 pt one-liner), 35 pt with a 20 pt
spacing, 15 pt with 0, and a wrapped single paragraph keeps the ordinary 12 pt step.
`the_format_panel_has_a_paragraph_spacing_field` (ui-egui): the field is in the panel while a
paragraph is being edited.

## Anything a reviewer should look at first

- The labels in the 20 non-English language files were written by an AI model from the English
  wording; a native speaker's review of those rows would be welcome.
- Justification now stops at each paragraph's last line (before, only the block's last line was
  left unstretched); with a single paragraph nothing changes.
- **Overlap with #1487** ("M7: line and paragraph spacing", opened the day before this one): it adds the
  same `BlockStyle.paragraph_spacing`, a spacing field in the Format panel and the `text_edit` argument.
  On top of that, this PR stops justification at each paragraph's last line, adds a UI test beside the
  edit-crate test, and carries the label in all 21 catalogs. Whichever you prefer is fine: if #1487
  lands first I'll rebase this down to what it adds on top of it, or close it.
- **Fits #2249** ("lay out Format text as Acrobat's panel"): that redesign shows paragraph spacing
  disabled as *Planned* and replaces `edit_text_ui::extras_panel`, where this PR's field lives. This PR
  supplies what the control would drive (`BlockStyle.paragraph_spacing` applied by `text_regions.rs`);
  if #2249 lands first I'll move the field into its panel and enable it there.

## Never-crash

- [x] No new `unwrap`/`expect`/`panic!` outside tests
- [x] The spacing is validated (finite, clamped to 0–14 400 pt); rows are indexed with `get`
- [x] No `unsafe`

## Provenance

- [x] No asset added; no code from another implementation

## Security

- [x] No network access

## Parity and reach

- [x] `parity/acrobat-features.toml` updated with what is still missing
- [x] Headless through `text_edit` (`paragraph_spacing`)
- [x] No documented behaviour changed (`docs/` has no entry for it)

- **Merged with main dc41044b** (2026-10-15): #2510's Vietnamese and Lithuanian catalogs added rows beside this branch's in `vi.tsv` and `lt.tsv` (and `ATTRIBUTION.toml`'s sha256 lines), nothing else. Main's rows kept, this branch's rows main lacks after them, hashes recomputed. Re-checked after the merge: `cargo xtask assets` ok, `i18n::tests` 117/117.
- **Merged with main 5fdd820b** (2026-10-15): #1895's catalog rows conflicted with this branch's in `es.tsv` and `vi.tsv` (and `ATTRIBUTION.toml`'s sha256 lines), nothing else. Main's rows kept, this branch's rows main lacks after them, hashes recomputed. Re-checked after the merge: `cargo xtask assets` ok, clippy -D warnings on this branch's crates ok, `i18n::tests` 117/117.
- **Merged with main bc7a12b9** (2026-10-17): only the translation catalogs' new rows and `ATTRIBUTION.toml`'s hashes met this branch (both sides kept, hashes recomputed). Re-checked on macOS: `cargo check --workspace --all-targets`, `cargo xtask assets`, `i18n::tests` 115/115.
- **Merged with main 3f5a784c** (2026-10-17): tests and docs both sides added kept (upstream's first), translation rows and `ATTRIBUTION.toml`'s hashes by key. Re-checked on macOS: `cargo check --workspace --all-targets`, `cargo xtask assets`, `i18n::tests` 115/115.
- **Merged with main dab31491** (2026-10-18, in two steps: 932bf9c6, then dab31491 without conflicts): main and this branch both added tests at the end of `crates/edit/src/tests.rs` and `crates/ui-egui/tests/editing.rs`; both kept, each with its own closing brace (this branch's first), no test lost: the `#[test]` count is main's plus this branch's; and `ATTRIBUTION.toml`'s sha256 lines (main's file kept, every hash recomputed from the merged tree). Re-checked after the merge: `cargo check --workspace --all-targets` ok, `cargo xtask assets` ok, `i18n::tests` 119/119, this branch's tests 2/2.
- **CodeRabbit fixes** (2026-10-21): choosing a font family no longer spreads rows apart when no spacing is set, and applying a spacing replaces the gap a paragraph already had instead of adding to it, so repeating it gives the same result. Each has a test in its own file that fails without the fix.
- **Merged with main 6dec57bf** (2026-10-21): upstream rebuilt the Format text panel and deleted the function this PR's Paragraph spacing row lived in, so the row moved into the new panel, replacing its disabled placeholder; upstream already had the "Paragraph spacing" label in every catalog, so this PR's duplicate rows were dropped, and ATTRIBUTION.toml took main's copy with the hashes recomputed.
- **Merged with main 6898094e** (2026-10-21): only the translation-catalog hashes in ATTRIBUTION.toml met this branch.
- **Round-2 CodeRabbit fixes** (2026-10-21): the draft's line breaks are matched to the source rows by where they came from instead of by position, so a break inserted inside a source row puts the spacing before the new paragraph and later rows keep their source steps. Each has a test in its own file.
- **Merged with main dbc7130b** (2026-10-21): only the translation-catalog hashes in ATTRIBUTION.toml met this branch.
- **Merged with main ffaf3123** (2026-10-21): only the translation-catalog hashes in ATTRIBUTION.toml met this branch.
- **Merged with main adea2c90** (2026-10-23): the parity row both sides changed keeps upstream's evidence with this PR's entries on top; this PR's test moved into upstream's new tests/it layout.
- **Merged with main 57e531cc** (2026-10-23): only the translation-catalog hashes in ATTRIBUTION.toml met this branch.
- **Merged with main a2ec27b4** (2026-10-23): upstream's changes met this PR in pdfcraft-automation, pdfcraft-edit, pdfcraft-ui-egui; checked.
- **Merged with main 6718f1f3** (2026-10-24): upstream's changes met this PR in pdfcraft-automation, pdfcraft-edit, pdfcraft-ui-egui; checked.
- **Merged with main 418ac6a2** (2026-10-25): upstream's changes met this PR in pdfcraft-automation, pdfcraft-edit, pdfcraft-ui-egui; checked.
- **Merged with main 1dd2737b4** (2026-10-27): upstream's changes met this PR in pdfcraft-automation, pdfcraft-edit, pdfcraft-ui-egui; checked.
- **Merged with main 0cba87ae** (2026-11-01): upstream's changes met this PR in pdfcraft-automation, pdfcraft-edit, pdfcraft-ui-egui; checked.
- **Merged with main 3936f93a** (2026-11-02): upstream's changes met this PR in pdfcraft-automation, pdfcraft-edit, pdfcraft-ui-egui; checked.
2026-11-18 16:29:06 +07:00
skylartaylor 5a6a7541e2 edit: negative controls for annotation appearances, alternates and Type3 programs
Four more fixtures for the census branches the first batch could not reach:
  annotation_appearances_are_walked_and_the_unreadable_ones_keep_the_image
    (a form appearance reached through a state dictionary and an array; an appearance
     dictionary naming its own /Resources; appearance states that come back to it)
  alternate_arrays_naming_the_image_are_rewritten_through_references
    (the rewrite drops the target's entries from a direct and an indirect /Alternates
     array and keeps the entry naming another image)
  type3_glyph_programs_are_walked_and_a_broken_one_keeps_the_image
    (a glyph program that draws the image, and one that is not a stream)
  another_page_with_contents_that_are_not_a_stream_keeps_the_image

Two shapes I first wrote turned out not to be uncertain at all and are not claimed as
such: an appearance array holding a number is simply followed, and a damaged Flate
content stream decodes tolerantly, so both leave the image prunable. The fixtures above
are the shapes the census really refuses.
2026-11-15 08:23:38 +01:00
skylar taylor-barrick e5478a10e6 edit: negative controls for the image-use census
The census keeps an image whenever it cannot prove the image unused, and that
"uncertain" outcome is what most of its code decides. These fixtures pin it:
a form that draws itself, a form chain past the depth limit, soft masks and
alternates that are malformed (against the benign null/None/array-of-null
spellings, which still let an unused image go), gs/Tf naming a font or mask the
census cannot read, a Do naming something that is not a stream, /Annots that is
not an array, and more aliases than the rewrite will stage.

Two positive controls sit beside them: an unused alias inside an indirect
/XObject dictionary is still pruned, and a shading painted through scn is no
consumer at all, so that image still goes.

Each asserts a full save: the marker bytes are present when the census was
uncertain, absent when it proved nonuse. With the "uncertain means unused"
mutation (treating `census.incomplete` as no reason to stop) six of these fail.
2026-11-15 07:21:28 +01:00
skylar taylor-barrick 4d42b1fba9 edit: follow the glyph's image alias to its payload in the Type3 test
A full save renumbers the objects it keeps, so comparing the alias with the
object number the image had before the save fails once the save compacts. The
test now checks what the alias keeps: the image carrying the marker bytes.
2026-11-15 05:55:31 +01:00
skylar taylor-barrick 3dba8b0456 Merge origin/main into fix/3511-prune-image-resources
Resolutions:
- crates/edit/src/images.rs: take main's file, which it rewrote around this branch's
  insertions, and re-apply the branch's three additions (the image-use census and the
  two call sites in change_image). No behaviour of main's is reverted.
- crates/automation/tests/automation.rs: main deleted it and moved the tests to
  tests/it/automation.rs, so the one hunk (the relaxed unused_xobjects assertion in
  a_deleted_image_is_not_kept_by_reduce_or_optimize) is applied there and the old file
  stays deleted.
- One ported test compared an image's object number before and after write_full, which
  renumbers the objects it keeps; it now follows the alias to the payload instead.
2026-11-15 05:04:06 +01:00
358e33a307 M7: replacing a line keeps the source font for the words it can show (#2378, re-lands #2955) (#6842)
* M7: replacing a line keeps the source font for the words it can show (#2378) (#2955)

* Fit #2955's line edit to #4514's /ActualText spaces

Since #4514, source_show wraps a run whose spaces the subset lacks in a
/Span /ActualText BDC ... EMC, so the moves standing in for those spaces
read back. #2955's two-font /PCEdLine path writes its source runs through
source_show, so they now carry that span too. Three of its tests were
written against the operator stream from before that:

- replacing_a_mixed_font_line_again_replaces_its_sequence counted BMC and
  EMC as the /PCEdLine sequences alone. It now also counts each edit's
  own /ActualText spans (BDC, and EMC = sequences + spans), so a sequence
  that nests or survives a re-edit still fails it.
- a_leading_space_does_not_make_a_source_font_run looked for the leading
  move right after the Tf; it now sits inside the run's span.
- a_row_replaced_inside_a_shared_sequence_starts_in_its_own_font put its
  second row before the first EMC, which is now the span's: the row was
  read as part of the span's text. It now goes before the EMC that closes
  /PCEdLine, the case the test describes. A paragraph rewrite drops an
  /ActualText span with its line (the span's BDC and EMC are among the
  line's operators), so it never leaves a row inside one.

The code needs no change: re-editing drops the spans inside a /PCEdLine
sequence with it (BDC/EMC are in the dropped set), and a span's merged
run keeps the sequence it is in, so the line still reads back as one.
Also drops the same_font import lines.rs no longer uses.

* Tests: fit #2955's three line-edit tests to #4514's /ActualText spans

* Tests: the replaced sequence's check allows the new text's own /ActualText span

---------

Co-authored-by: mtlcl410 <2368091+mtlcl410@users.noreply.github.com>
Co-authored-by: FredApps <FredApps@users.noreply.github.com>
2026-11-14 13:25:27 +01:00
Dylan M. Taylor 1d7a9f9ffe fix(edit,a11y): font aliases share the metrics built for their font (#5998)
* fix(edit,a11y): font aliases share the metrics built for their font

Text extraction and heading extraction built and kept font metrics per resource name, so
many names for one font object each held a copy of its Unicode and width tables.

* fmt

* address review: font metrics are cached by the object at the end of the reference chain
2026-11-11 15:51:22 -05:00
Dylan M. Taylor d46d9daea5 fix(edit): editor font enumeration reads a face name without building font metrics (#6086) 2026-11-11 14:46:47 -05:00
FredApps 22974ca874 Merge pull request #6813 from Piohrun/fix/fonts-refusal-counted
M7: a font's metrics are past their allowance only when it refused a read
2026-11-11 14:34:48 +01:00
mtlcl410 41d959d94c M7: replacing a line keeps both of two dropped quote copies' line move and spacing (edit.text-edit) (#2961) 2026-11-11 11:04:56 +07:00
regendorf-ux b7cfbd3980 Find and replace text in Edit text mode: a Replace row in the Find box, Replace all as one undo step (#2467) 2026-11-10 15:19:55 +07:00
BFlat f48cf6eeba Merge pull request #6806 from storytold/merge/mixed-script-2778
fix(edit): preserve source fonts in mixed-script paragraphs (#2778, merged with main)
2026-11-10 14:22:36 +07:00
mtlcl410 67cd69050e M7: paragraph edits keep the advance of the text they drop (edit.text-edit) (#2968) 2026-11-10 14:21:29 +07:00
Grzegorz MartensandClaude Opus 5.5 7cea6dfead M7: a font's metrics are past their allowance only when it refused a read
`Reads::decode` and the Type 3 glyph-box read took any failed read, with
nothing left of the allowance after it, for one the allowance refused. The
Thai edit refuses on what the allowance itself counts
(`DecodeBudget::refused`), so the two could disagree: once the edit's
allowance was spent to the byte, an empty stream behind a filter nothing
decodes, which is unread with any allowance, made a font's metrics read
past it with no refusal counted. The edit then skipped that font of the
face and went through without it, which its refusal is there to prevent.

Both now take a read as refused only when `DecodeBudget::refused` grew
during it, so `Metrics::past_allowance` is set exactly when the allowance
counted a refusal, as its doc now says.

Tests:
- `an_empty_stream_reads_with_nothing_left` adds such a stream: it isn't
  past the allowance, and the flag agrees with the count in each case.
- `a_type3_description_unread_on_its_own_is_not_past_the_allowance`: the
  same for a glyph description after one that spends the allowance to the
  byte; a description with data after it is still refused.
- `a_font_of_the_face_unread_on_its_own_once_the_allowance_is_spent_still_refuses_the_edit`:
  the edit above is refused, where it went through.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AmsdeUCdTaD72jkDw2pJKY
2026-11-10 06:19:08 +01:00
bflatastic 10755a9da9 Merge remote-tracking branch 'origin/main' into merge/mixed-script-2778
# Conflicts:
#	parity/acrobat-features.toml
2026-11-10 10:45:45 +07:00
bflatastic f6fd408419 Merge remote-tracking branch 'origin/main' into merge/fonts-budget-6239
# Conflicts:
#	crates/edit/src/tests.rs
2026-11-10 10:09:08 +07:00
jonathanwxh-cell c6d9c13002 fix(ui): keep added image corner resize responsive and clip out-of-bounds drag preview (#4477, #3938) (#4625) 2026-11-10 10:00:18 +07:00
PerchAnton 8dfa52c9b5 Merge main into PR #2778 preserving feature behavior 2026-11-10 01:16:46 +02:00
Grzegorz MartensandClaude Opus 5.5 4fca5783a7 M7: a Thai edit refuses only a read past its allowance, and reads its subsets' metrics within it
CodeRabbit's review of 674a20899:

- The Thai edit refused when nothing was left of its allowance, so an
  edit whose reads spent it to the byte was refused. It now refuses when
  a read was refused for want of it (`DecodeBudget::refused`).
- `LegacyThaiFont::from_pdf` read its metrics with `from_dict`, outside
  the edit's allowance, and so did the edit for each subset it measures.
  Both now read them within it (`from_dict_within`), and metrics read
  past it adapt nothing: `from_pdf` refuses the font before reading its
  program, and the edit leaves the subset unread and is refused. The
  edit's scan of every font on the page for its face name stays outside
  the allowance, as on `main`: charged, each alias of a font would pay
  again, and other faces would spend what the face's subsets need.
  `MAX_THAI_PROGRAMS` says what it pays for.
- When the `/CIDToGIDMap` a THSarabunPSK subset's Thai mappings are
  rebuilt from was left unread for want of the editor's allowance,
  `composite_glyph_maps` gave nothing, and a subset with a Latin-only
  cmap of its own was listed as it was, without its Thai mappings. The
  editor now lists no copy of it, as for metrics read past the
  allowance.

Tests: `a_thai_edit_that_spends_its_allowance_to_the_byte_goes_through`
(`pdfcraft-edit`: a subset costing exactly the 64 MiB is edited, and
one three bytes past it is refused),
`a_legacy_fonts_metrics_are_paid_for_from_the_edits_allowance` and
`a_map_left_unread_for_the_allowance_lists_no_copy` (`pdfcraft-fonts`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AmsdeUCdTaD72jkDw2pJKY
2026-11-09 21:45:29 +01:00
Grzegorz MartensandClaude Opus 5.5 4d6ff291d7 M7: Reads::decode says what a stage past its limit is charged
The Claims review of the description at b7224cbc9. `Reads::decode` said a
stream past its limit is unread, not refused, "when what is left can pay
for its stages". What `DecodeBudget::decode_stages_within` does, and
`a_stage_past_its_limit_charges_what_came_before_and_the_limit` pins:
with more left than what the stages before the stopped one made and the
limit, it is charged those two; otherwise, with more left than the
stages' total (behind one filter, the limit), it is charged that total;
with no more left than that total, it spends all of it and counts as
refused.

`MAX_THAI_PROGRAMS` also names the second read of a subset's program,
for which of its glyphs have outlines, among what it pays for.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AmsdeUCdTaD72jkDw2pJKY
2026-11-09 16:52:47 +01:00
Grzegorz MartensandClaude Opus 5.5 92e8e6eff0 M7: Repair Thai maps reads a /CIDToGIDMap given by reference, and takes a missing one as Identity
The Consumers review of ba28458ad..b7224cbc9:

- `recovered_thai_map` read the descendant's /CIDToGIDMap with
  `Dict::name`, on the line after e9142b03b's /Encoding check, so a map
  given by reference made Repair Thai maps pass the font over, and so
  did a missing one, which is Identity (ISO 32000-2 Table 115), as
  `composite_glyph_maps`, `LegacyThaiFont` and the renderer read it. It
  now resolves the map and takes a missing one as Identity.
- `MAX_THAI_PROGRAMS` says what it pays for: the programs, and the CMaps
  and glyph maps read to adapt their cmaps. The metrics read to find and
  measure the subsets aren't charged to it. Its refusal ("MiB of font
  data") still says what it counts.

Test: `recovered_thai_map_checks_every_kept_glyph_against_the_font_program`
recovers the same map with the font's /CIDToGIDMap given by reference and
with none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AmsdeUCdTaD72jkDw2pJKY
2026-11-09 16:48:01 +01:00
Grzegorz MartensandClaude Opus 5.5 b7224cbc9a Merge main again into fix/fonts-decode-budget
A third merge, of ba28458ad, with nothing to resolve. main's commits since
b6cbf9bb3 add no font program, metrics or CMap read in pdfcraft-fonts or
the editor's font code for this PR's allowance to cover.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AmsdeUCdTaD72jkDw2pJKY
2026-11-09 16:31:54 +01:00
jonathanwxh-cell cec8c83843 Ignore choice-only builtin fonts when asserting glyphless font is not loaded 2026-11-09 23:08:02 +08:00
bflatastic 2ce2d3cf81 Merge main into merge/ui-print-optimize2
# Conflicts:
#	crates/automation/src/redact.rs
#	crates/automation/src/tools.rs
#	crates/print/src/lib.rs
#	crates/render/src/inspect.rs
#	crates/render/src/lib.rs
2026-11-09 20:56:15 +07:00
Grzegorz MartensandClaude Opus 5.5 509cf9f9fd M7: the editor reads no metrics for a composite font it can't adapt
The Resources review of 8eead8ecd:

- `embedded_sfnt_within` read a composite font's metrics within the
  editor's allowance before `composite_glyph_maps` refused any `/Encoding`
  but Identity-H, so an Identity-V or UniJIS font spent its ToUnicode and
  `/CIDToGIDMap` for nothing. Its `/Encoding` is now checked first; a
  program with a cmap of its own is kept as it is, as when the rebuild
  finds nothing.
- The Thai edit's allowance, `MAX_THAI_PROGRAMS`, now also pays for the
  CMaps and glyph maps its subsets' metrics and codes are read from: its
  doc and its refusal say "font data", not "font programs".
- `a_symbolic_truetype_font_without_an_encoding_reads_its_glyph_names`
  also reads its font, whose `post` table names its glyphs, within an
  allowance: the program is paid for by the glyph-name reading, by the
  Mac OS Roman one and for the widths, and a byte short of the first the
  names go unread.

Tests: `a_composite_font_that_cant_be_adapted_spends_only_its_program`,
and `adapting_a_programs_cmap_is_paid_for` again expects a composite font
whose codes aren't Identity-H to pay for its program only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AmsdeUCdTaD72jkDw2pJKY
2026-11-09 13:36:44 +01:00
jonathanwxh-cell 492c1bf0e9 Merge remote-tracking branch 'upstream/main' into fix/glyphless-ocr-font-edit 2026-11-09 20:10:20 +08:00