From ae3c7b7592dc4d838654b37c030f4318fa471e55 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Fri, 4 Dec 2026 16:12:23 +0100 Subject: [PATCH 1/8] chore(deps): pin craft-libs to the rev the 0.23.2 release builds against (9888a5855) (#9308) Release has built against craft-libs 9888a585 since 0.23.2; main stayed on 6afe03f5b, so main could not take the release-only UI fixes that use the newer craft-libs APIs (centred TextField, tab wheel browsing, bounded document preview width, wheel messages for fitted page spreads). This moves main to the same rev; Cargo.lock only changes the craft-libs source. The 12 craft-libs commits behind this rev are being put on craft-libs main in https://github.com/storytold/craft-libs/pull/5306. Co-authored-by: FredApps Co-authored-by: Claude Sonnet 5.5 --- Cargo.lock | 174 +++++++++++++++++------------------ Cargo.toml | 78 ++++++++-------- apps/pdfcraft-web/Cargo.toml | 4 +- crates/export/Cargo.toml | 2 +- crates/preflight/Cargo.toml | 2 +- crates/sign/Cargo.toml | 2 +- crates/xfa/Cargo.toml | 2 +- crates/xfdf/Cargo.toml | 2 +- xtask/src/pdf_deps.rs | 2 +- 9 files changed, 134 insertions(+), 134 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1c15e7ec8b..f9d5de635f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1365,7 +1365,7 @@ dependencies = [ [[package]] name = "craft" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-atomic", "craft-automation", @@ -1405,7 +1405,7 @@ dependencies = [ [[package]] name = "craft-atomic" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "rustix 1.1.6", ] @@ -1413,7 +1413,7 @@ dependencies = [ [[package]] name = "craft-automation" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "base64 0.23.1", "craft-behavior", @@ -1438,7 +1438,7 @@ dependencies = [ [[package]] name = "craft-behavior" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "accesskit", "bitflags 2.13.2", @@ -1456,7 +1456,7 @@ dependencies = [ [[package]] name = "craft-browse" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-behavior", "craft-docpath", @@ -1474,12 +1474,12 @@ dependencies = [ [[package]] name = "craft-cfb" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" [[package]] name = "craft-cloud-ui" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "egui", ] @@ -1487,7 +1487,7 @@ dependencies = [ [[package]] name = "craft-cms" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "md-5 0.10.6", "rayon", @@ -1496,12 +1496,12 @@ dependencies = [ [[package]] name = "craft-codepage" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" [[package]] name = "craft-color-ui" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-behavior", "craft-cms", @@ -1521,7 +1521,7 @@ dependencies = [ [[package]] name = "craft-control" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "getrandom 0.3.4", "serde", @@ -1531,7 +1531,7 @@ dependencies = [ [[package]] name = "craft-csv" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "thiserror 2.0.21", ] @@ -1539,7 +1539,7 @@ dependencies = [ [[package]] name = "craft-dds" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "rayon", ] @@ -1547,7 +1547,7 @@ dependencies = [ [[package]] name = "craft-dialogs" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "block2 0.6.2", "craft-atomic", @@ -1572,7 +1572,7 @@ dependencies = [ [[package]] name = "craft-docpath" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "serde", ] @@ -1580,7 +1580,7 @@ dependencies = [ [[package]] name = "craft-docx" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "base64 0.23.1", "chrono", @@ -1600,7 +1600,7 @@ dependencies = [ [[package]] name = "craft-draw" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-behavior", "craft-color-ui", @@ -1619,7 +1619,7 @@ dependencies = [ [[package]] name = "craft-drawingml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "chrono", "craft-xml", @@ -1631,7 +1631,7 @@ dependencies = [ [[package]] name = "craft-flow" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-wordmodel", "image", @@ -1641,7 +1641,7 @@ dependencies = [ [[package]] name = "craft-font-catalog" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "fontique", "harfrust 0.13.3", @@ -1656,7 +1656,7 @@ dependencies = [ [[package]] name = "craft-font-manager" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-behavior", "craft-font-catalog", @@ -1675,7 +1675,7 @@ dependencies = [ [[package]] name = "craft-font-store" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "cap-primitives", "craft-atomic", @@ -1696,12 +1696,12 @@ dependencies = [ [[package]] name = "craft-fonts-build" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" [[package]] name = "craft-host" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "bitflags 2.13.2", "craft-i18n", @@ -1714,7 +1714,7 @@ dependencies = [ [[package]] name = "craft-html" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-mime", ] @@ -1722,7 +1722,7 @@ dependencies = [ [[package]] name = "craft-i18n" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "chrono", "fixed_decimal", @@ -1750,7 +1750,7 @@ dependencies = [ [[package]] name = "craft-image-codecs" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-dds", "craft-jpeg", @@ -1777,7 +1777,7 @@ dependencies = [ [[package]] name = "craft-imaging" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-behavior", "craft-color-ui", @@ -1795,7 +1795,7 @@ dependencies = [ [[package]] name = "craft-jpeg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "thiserror 2.0.21", ] @@ -1803,7 +1803,7 @@ dependencies = [ [[package]] name = "craft-jsonrpc" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "serde_json", ] @@ -1811,7 +1811,7 @@ dependencies = [ [[package]] name = "craft-keymap" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-host", "craft-i18n", @@ -1826,7 +1826,7 @@ dependencies = [ [[package]] name = "craft-markdown" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-flow", "craft-html", @@ -1836,7 +1836,7 @@ dependencies = [ [[package]] name = "craft-math" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-xml", "roxmltree 0.21.2", @@ -1846,7 +1846,7 @@ dependencies = [ [[package]] name = "craft-mcp-server" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "serde_json", ] @@ -1854,7 +1854,7 @@ dependencies = [ [[package]] name = "craft-menu" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-behavior", "craft-host", @@ -1872,7 +1872,7 @@ dependencies = [ [[package]] name = "craft-metadata" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "brotli-decompressor 6.3.2", "chrono", @@ -1884,7 +1884,7 @@ dependencies = [ [[package]] name = "craft-metafile" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "encoding_rs", "image", @@ -1895,7 +1895,7 @@ dependencies = [ [[package]] name = "craft-mime" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "chardetng", "chrono", @@ -1915,7 +1915,7 @@ dependencies = [ [[package]] name = "craft-offcrypto" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "aes", "base64 0.23.1", @@ -1932,7 +1932,7 @@ dependencies = [ [[package]] name = "craft-opc" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-xml", "craft-zip", @@ -1943,7 +1943,7 @@ dependencies = [ [[package]] name = "craft-pages" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-behavior", "craft-keymap", @@ -1959,7 +1959,7 @@ dependencies = [ [[package]] name = "craft-pdf" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "aes", "bytemuck", @@ -1982,7 +1982,7 @@ dependencies = [ [[package]] name = "craft-pkcs7" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "aes", "aws-lc-rs", @@ -2014,7 +2014,7 @@ dependencies = [ [[package]] name = "craft-platform" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "arboard", "async-channel", @@ -2049,7 +2049,7 @@ dependencies = [ [[package]] name = "craft-pptx" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-drawingml", "craft-opc", @@ -2064,7 +2064,7 @@ dependencies = [ [[package]] name = "craft-prc" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "flate2", "thiserror 2.0.21", @@ -2073,7 +2073,7 @@ dependencies = [ [[package]] name = "craft-print" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-behavior", "craft-host", @@ -2097,7 +2097,7 @@ dependencies = [ [[package]] name = "craft-quit" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "dispatch2", "egui", @@ -2110,7 +2110,7 @@ dependencies = [ [[package]] name = "craft-review" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "base64 0.23.1", "craft-behavior", @@ -2129,7 +2129,7 @@ dependencies = [ [[package]] name = "craft-rtf" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-codepage", "craft-flow", @@ -2142,7 +2142,7 @@ dependencies = [ [[package]] name = "craft-settings" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-atomic", "craft-host", @@ -2159,7 +2159,7 @@ dependencies = [ [[package]] name = "craft-stream-codecs" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "fax", "hayro-ccitt", @@ -2170,7 +2170,7 @@ dependencies = [ [[package]] name = "craft-svg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-xml", "flate2", @@ -2187,7 +2187,7 @@ dependencies = [ [[package]] name = "craft-table" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-behavior", "craft-keymap", @@ -2199,7 +2199,7 @@ dependencies = [ [[package]] name = "craft-text" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-behavior", "craft-font-manager", @@ -2224,7 +2224,7 @@ dependencies = [ [[package]] name = "craft-theme" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "bitflags 2.13.2", "craft-tracked", @@ -2239,7 +2239,7 @@ dependencies = [ [[package]] name = "craft-theme-store" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-atomic", "craft-behavior", @@ -2254,7 +2254,7 @@ dependencies = [ [[package]] name = "craft-tiff" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "serde", "thiserror 2.0.21", @@ -2264,7 +2264,7 @@ dependencies = [ [[package]] name = "craft-time" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "serde", "thiserror 2.0.21", @@ -2273,7 +2273,7 @@ dependencies = [ [[package]] name = "craft-timeline" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-behavior", "craft-keymap", @@ -2288,12 +2288,12 @@ dependencies = [ [[package]] name = "craft-tracked" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" [[package]] name = "craft-ui" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-cloud-ui", "craft-ui-canvas", @@ -2307,7 +2307,7 @@ dependencies = [ [[package]] name = "craft-ui-canvas" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-behavior", "craft-i18n", @@ -2323,7 +2323,7 @@ dependencies = [ [[package]] name = "craft-ui-contract" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "accesskit", "craft-behavior", @@ -2361,7 +2361,7 @@ dependencies = [ [[package]] name = "craft-ui-macros" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -2372,7 +2372,7 @@ dependencies = [ [[package]] name = "craft-ui-panels" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-behavior", "craft-host", @@ -2390,7 +2390,7 @@ dependencies = [ [[package]] name = "craft-ui-patterns" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-behavior", "craft-host", @@ -2411,7 +2411,7 @@ dependencies = [ [[package]] name = "craft-ui-shell" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-behavior", "craft-host", @@ -2432,7 +2432,7 @@ dependencies = [ [[package]] name = "craft-ui-widgets" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-behavior", "craft-host", @@ -2451,7 +2451,7 @@ dependencies = [ [[package]] name = "craft-update" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "chrono", "craft-host", @@ -2480,7 +2480,7 @@ dependencies = [ [[package]] name = "craft-web-api" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "js-sys", "serde_json", @@ -2491,7 +2491,7 @@ dependencies = [ [[package]] name = "craft-web-host" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-host", "craft-platform", @@ -2503,7 +2503,7 @@ dependencies = [ [[package]] name = "craft-win32" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "winsafe", ] @@ -2511,7 +2511,7 @@ dependencies = [ [[package]] name = "craft-window" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-atomic", "craft-behavior", @@ -2541,7 +2541,7 @@ dependencies = [ [[package]] name = "craft-wordmodel" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "base64 0.23.1", "craft-math", @@ -2555,7 +2555,7 @@ dependencies = [ [[package]] name = "craft-xfa" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-xml", ] @@ -2563,7 +2563,7 @@ dependencies = [ [[package]] name = "craft-xfdf" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "craft-xml", "thiserror 2.0.21", @@ -2572,7 +2572,7 @@ dependencies = [ [[package]] name = "craft-xml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "quick-xml 0.41.0", "serde", @@ -2582,7 +2582,7 @@ dependencies = [ [[package]] name = "craft-zip" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "flate2", "thiserror 2.0.21", @@ -4151,7 +4151,7 @@ dependencies = [ [[package]] name = "hayro" version = "0.7.1" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "bytemuck", "hayro-interpret", @@ -4171,7 +4171,7 @@ checksum = "9f4d0e94ddd48749f06bbe4e5389fb9799a0c45bcaf00495042076ef05e3241a" [[package]] name = "hayro-cmap" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "brotli", "hayro-postscript", @@ -4180,7 +4180,7 @@ dependencies = [ [[package]] name = "hayro-interpret" version = "0.7.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "bitflags 2.13.2", "hayro-cmap", @@ -4198,7 +4198,7 @@ dependencies = [ [[package]] name = "hayro-jbig2" version = "0.3.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "fearless_simd", "hayro-ccitt", @@ -4216,12 +4216,12 @@ dependencies = [ [[package]] name = "hayro-postscript" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" [[package]] name = "hayro-syntax" version = "0.7.2" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "flate2", "hayro-ccitt", @@ -5090,7 +5090,7 @@ checksum = "d4a5ff6bcca6c4867b1c4fd4ef63e4db7436ef363e0ad7531d1558856bae64f4" [[package]] name = "linesweeper" version = "0.5.0" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" dependencies = [ "arrayvec", "kurbo 0.13.1", @@ -11132,4 +11132,4 @@ source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d9 [[patch.unused]] name = "krilla" version = "0.8.2" -source = "git+https://github.com/storytold/craft-libs?rev=6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8#6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" +source = "git+https://github.com/storytold/craft-libs?rev=9888a585552d872ec94734daf064f96a0a25c41e#9888a585552d872ec94734daf064f96a0a25c41e" diff --git a/Cargo.toml b/Cargo.toml index 77d52682f8..91efe0f5dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,55 +13,55 @@ repository = "https://github.com/storytold/pdfcraft" [workspace.dependencies] # The framework facade: every framework crate is reached through it (contract head); its features pick the crates. -craft = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8", default-features = false } -craft-markdown = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } +craft = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "9888a585552d872ec94734daf064f96a0a25c41e", default-features = false } +craft-markdown = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } # Small, revision-bound UI drafts; the existing engine remains the owner of PDF edits/history. edit-session = { path = "vendor/edit-session", version = "=0.1.0-alpha.2" } # Shared frontend components; engines remain independent of egui. -craft-ui = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } +craft-ui = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } # Quit the macOS way (#1136): ⌘Q asks about unsaved changes, and closing quits through `terminate:`. -craft-quit = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } +craft-quit = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } # One menu definition for the native macOS menu bar and the in-window bar elsewhere. -craft-menu = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } -craft-keymap = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8", default-features = false } +craft-menu = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } +craft-keymap = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "9888a585552d872ec94734daf064f96a0a25c41e", default-features = false } # Interface translations: lookup, fallback, CLDR plurals and language names over the craft-i18n # catalogs that `crates/ui-egui/build.rs` embeds from `CRAFT_I18N_DIR` (storytold/craft-i18n, at # the commit in `craft-i18n.rev`). Already in the tree through craft-ui. -craft-i18n = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } +craft-i18n = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } # Shared system spooler; document composition remains in pdfcraft-print. -craft-print = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } +craft-print = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } # ICC transforms for app-managed print colour; at craft-print's commit, so one craft-libs checkout. -craft-cms = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } -craft-zip = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } +craft-cms = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } +craft-zip = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } # Whether a path stored in a document may be opened (GoToR link targets). -craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } +craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } # The installed-font catalog the engine reads faces from (Edit ▸ Add text, font embedding). -craft-font-catalog = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8", default-features = false } +craft-font-catalog = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "9888a585552d872ec94734daf064f96a0a25c41e", default-features = false } # The craft-fonts manifest parser and `EmbeddedFace`, the face table the interface font stack takes; already in the # tree through craft-ui. -craft-fonts-build = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } +craft-fonts-build = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } # craft-update: app-specific pretend versions apply to startup and manual checks. -craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8", features = ["ui"] } -craft-pdf = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8", features = ["cos", "crypt", "filters", "fonts"] } +craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "9888a585552d872ec94734daf064f96a0a25c41e", features = ["ui"] } +craft-pdf = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "9888a585552d872ec94734daf064f96a0a25c41e", features = ["cos", "crypt", "filters", "fonts"] } # The writers the Word and RTF exports map onto (storytold/craft-libs#793), at storytold/craft-libs#1467: # its font and colour lookups take constant time, as PdfCraft's own writer did. craft-rtf, craft-wordmodel and # craft-docx move together: craft_rtf::doc::export takes its own revision's Document. -craft-rtf = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } +craft-rtf = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } # Shared Base64 encoder; use the existing RTF revision to reuse its codepage dependency. -craft-mime = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } -craft-csv = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } -craft-xml = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } -craft-image-codecs = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } -craft-tiff = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } -craft-jpeg = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } -craft-docx = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } -craft-wordmodel = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } -craft-pptx = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } -craft-drawingml = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } -craft-opc = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } +craft-mime = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } +craft-csv = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } +craft-xml = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } +craft-image-codecs = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } +craft-tiff = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } +craft-jpeg = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } +craft-docx = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } +craft-wordmodel = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } +craft-pptx = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } +craft-drawingml = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } +craft-opc = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } # Shared MCP stdio framing and JSON-RPC 2.0 envelopes (storytold/craft-libs#778). -craft-mcp-server = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } -craft-jsonrpc = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } +craft-mcp-server = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } +craft-jsonrpc = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } # Nightly profile isolation, launch protocol, and security fence. craft-nightly = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "8945bdb09b36245a1d442438ce8876377ef430d0" } # internal @@ -98,8 +98,8 @@ pdfcraft-engine = { path = "crates/engine", version = "0.23.1" } pdfcraft-platform = { path = "crates/platform", version = "0.23.1" } pdfcraft-ui-egui = { path = "crates/ui-egui", version = "0.23.1" } pdfcraft-automation = { path = "crates/automation", version = "0.23.1", default-features = false } -pdfcraft-prc = { package = "craft-prc", git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } -craft-prc = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } +pdfcraft-prc = { package = "craft-prc", git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } +craft-prc = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } pdfcraft-prc-render = { path = "crates/prc-render", version = "0.23.1" } # pdf @@ -182,14 +182,14 @@ unset_env = ["CRAFT_FONTS_DIR", "CRAFT_FONTS_REQUIRED", "CRAFT_I18N_DIR", "CRAFT # BEGIN port-kit framework patch [patch.crates-io] -krilla = { git = "https://github.com/storytold/craft-libs", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } -hayro = { git = "https://github.com/storytold/craft-libs", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } -hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } -hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } -hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } -hayro-cmap = { git = "https://github.com/storytold/craft-libs", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } -hayro-postscript = { git = "https://github.com/storytold/craft-libs", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } -linesweeper = { git = "https://github.com/storytold/craft-libs", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } +krilla = { git = "https://github.com/storytold/craft-libs", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } +hayro = { git = "https://github.com/storytold/craft-libs", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } +hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } +hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } +hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } +hayro-cmap = { git = "https://github.com/storytold/craft-libs", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } +hayro-postscript = { git = "https://github.com/storytold/craft-libs", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } +linesweeper = { git = "https://github.com/storytold/craft-libs", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } ecolor = { git = "https://github.com/storytold/egui.git", rev = "f5025284445ea19c35f746d96fc0b75468b3f560" } emath = { git = "https://github.com/storytold/egui.git", rev = "f5025284445ea19c35f746d96fc0b75468b3f560" } epaint = { git = "https://github.com/storytold/egui.git", rev = "f5025284445ea19c35f746d96fc0b75468b3f560" } diff --git a/apps/pdfcraft-web/Cargo.toml b/apps/pdfcraft-web/Cargo.toml index 171bc0f43b..bf4b463d94 100644 --- a/apps/pdfcraft-web/Cargo.toml +++ b/apps/pdfcraft-web/Cargo.toml @@ -15,8 +15,8 @@ pdfcraft-ui-egui = { workspace = true } craft = { workspace = true, features = ["automation", "platform-browser", "ui", "window"] } # The host messages (storytold/craft-libs): one contract and one bridge for the web builds. # The page command API (storytold/craft-libs#413): window.pdfcraft over the UI control channel. -craft-web-api = { git = "https://github.com/storytold/craft-libs", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8", version = "0.1.0" } -craft-web-host = { git = "https://github.com/storytold/craft-libs", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8", version = "0.1.0" } +craft-web-api = { git = "https://github.com/storytold/craft-libs", rev = "9888a585552d872ec94734daf064f96a0a25c41e", version = "0.1.0" } +craft-web-host = { git = "https://github.com/storytold/craft-libs", rev = "9888a585552d872ec94734daf064f96a0a25c41e", version = "0.1.0" } eframe = { workspace = true, features = ["default_fonts", "glow", "persistence", "accesskit"] } egui = { workspace = true, features = ["default_fonts", "monochrome_emoji_fonts"] } serde_json = { workspace = true } diff --git a/crates/export/Cargo.toml b/crates/export/Cargo.toml index bbc76266b3..0607f1811f 100644 --- a/crates/export/Cargo.toml +++ b/crates/export/Cargo.toml @@ -16,7 +16,7 @@ craft-mime.workspace = true craft-rtf = { workspace = true, features = ["doc"] } craft-wordmodel.workspace = true craft-docx.workspace = true -craft-html = { git = "https://github.com/storytold/craft-libs", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8", version = "0.1.0", features = ["standalone"] } +craft-html = { git = "https://github.com/storytold/craft-libs", rev = "9888a585552d872ec94734daf064f96a0a25c41e", version = "0.1.0", features = ["standalone"] } image = { version = "0.25", default-features = false, features = ["png", "jpeg"] } craft-pptx.workspace = true craft-xml.workspace = true diff --git a/crates/preflight/Cargo.toml b/crates/preflight/Cargo.toml index 6cf3ac467f..d3e41924fc 100644 --- a/crates/preflight/Cargo.toml +++ b/crates/preflight/Cargo.toml @@ -11,7 +11,7 @@ repository.workspace = true workspace = true [dependencies] -craft-cms-v2 = { package = "craft-cms", version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } +craft-cms-v2 = { package = "craft-cms", version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } craft-xml = { workspace = true } pdfcraft-content = { workspace = true } pdfcraft-cos = { workspace = true } diff --git a/crates/sign/Cargo.toml b/crates/sign/Cargo.toml index 56332ed3bd..80076527f4 100644 --- a/crates/sign/Cargo.toml +++ b/crates/sign/Cargo.toml @@ -12,7 +12,7 @@ workspace = true [dependencies] # Existing shared ASN.1 codec; PDF signature policy remains local. -craft-pkcs7 = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } +craft-pkcs7 = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } pdfcraft-cos = { workspace = true } pdfcraft-annot = { workspace = true } pdfcraft-content = { workspace = true } diff --git a/crates/xfa/Cargo.toml b/crates/xfa/Cargo.toml index 967040f8f4..7b073f617f 100644 --- a/crates/xfa/Cargo.toml +++ b/crates/xfa/Cargo.toml @@ -11,7 +11,7 @@ repository.workspace = true workspace = true [dependencies] -craft-xfa = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8" } +craft-xfa = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "9888a585552d872ec94734daf064f96a0a25c41e" } pdfcraft-cos = { workspace = true } pdfcraft-fonts = { workspace = true } craft-xml = { workspace = true } diff --git a/crates/xfdf/Cargo.toml b/crates/xfdf/Cargo.toml index e9a7b672df..d08729219a 100644 --- a/crates/xfdf/Cargo.toml +++ b/crates/xfdf/Cargo.toml @@ -9,7 +9,7 @@ license.workspace = true workspace = true [dependencies] -craft-xfdf = { git = "https://github.com/storytold/craft-libs", rev = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8", version = "0.1.0" } +craft-xfdf = { git = "https://github.com/storytold/craft-libs", rev = "9888a585552d872ec94734daf064f96a0a25c41e", version = "0.1.0" } pdfcraft-cos = { workspace = true } pdfcraft-annot = { workspace = true } pdfcraft-forms = { workspace = true } diff --git a/xtask/src/pdf_deps.rs b/xtask/src/pdf_deps.rs index 2def901f9a..dd8accc3da 100644 --- a/xtask/src/pdf_deps.rs +++ b/xtask/src/pdf_deps.rs @@ -6,7 +6,7 @@ use std::process::Command; use serde_json::Value; -const SHARED_REV: &str = "6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8"; +const SHARED_REV: &str = "9888a585552d872ec94734daf064f96a0a25c41e"; const PACKAGES: &[(&str, &str)] = &[ ("craft-pdf", "0.1.0"), ("hayro", "0.7.1"), From 86db88e6305c2638e42ba36d799a8d8ad9ffe53b Mon Sep 17 00:00:00 2001 From: Sandip Patel <55301948+SAPHemlock@users.noreply.github.com> Date: Fri, 4 Dec 2026 07:12:30 -0800 Subject: [PATCH 2/8] Fix #9016: draw added Greek and Cyrillic text with the bundled Inter face (#9078) * Fix #9016: draw added Greek and Cyrillic text with the bundled Inter face The Add-text path only accepted WinAnsi-encodable text (plus Arabic/Hebrew/ Thai via their shaped faces), so Greek and Cyrillic were refused even though the bundled Inter face draws them. first_undrawable now uses undrawable_char (a char is undrawable only if WinAnsi lacks it AND the Inter face can't draw it), and draw now sets the embedded Inter face for such text, mirroring doc_create and text_edit. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix mixed-script added text and the Greek drawing test Address the CodeRabbit review findings on the #9016 fix: - draw_laid_shaped: a run the shaped layout leaves as a Piece::Latin but that WinAnsi cannot encode (Greek or Cyrillic) is now drawn with the bundled Inter face, embedded, instead of being silently lost to WinAnsi '?'. The face is added only when a run needs it, so pure Hebrew (or Arabic/Thai) text is unchanged. - tests: the Greek drawing test now selects the added item's content stream by its /PCMark /Added tag (the page's own "Hi" stream also has a Tj, so the first Tj stream was the wrong one) and verifies the embedded face (Type0, FontFile, ToUnicode to Greek). A new test covers mixed Hebrew + Greek text, asserting the Greek run uses the embedded face and the Hebrew run the shaped face. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(edit): a second Greek item no longer takes the first item's font name (#9016) draw_inter_face and the mixed-script path embedded the bundled face into a dict that held none of the page's fonts, so the resource was always PCFull0 and `write` set it over any other PCFull0 the page already had. Seed the dict with the page's PCFull* entries first, so embedding picks a free name or reuses an identical face. The mixed-script Latin branch now draws a soft hyphen as a hyphen, as draw_inter_face does. Review: https://github.com/storytold/pdfcraft/pull/9078#pullrequestreview-6187655188 Co-Authored-By: Claude Sonnet 5.5 * test(ui): Greek added text is drawable with the default font (#9016) Two UI tests still asserted that a standard font refuses Greek phi, which this change makes drawable through the bundled Inter face. Assert the new behaviour; an explicit document font keeps working and keeps its resource. Matches the updates the 0.23.2 release branch made to the same tests. Co-Authored-By: Claude Sonnet 5.5 --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: FredApps Co-authored-by: Claude Sonnet 5.5 --- crates/edit/src/added/draw.rs | 133 +++++++++++++++++- crates/edit/src/added/layout.rs | 29 ++-- crates/edit/src/tests.rs | 147 ++++++++++++++++++++ crates/ui-egui/src/panels/format_text_ui.rs | 7 +- crates/ui-egui/tests/it/edit.rs | 4 +- 5 files changed, 302 insertions(+), 18 deletions(-) diff --git a/crates/edit/src/added/draw.rs b/crates/edit/src/added/draw.rs index b9ddace4b3..4551ea46f2 100644 --- a/crates/edit/src/added/draw.rs +++ b/crates/edit/src/added/draw.rs @@ -95,6 +95,26 @@ pub(super) fn draw_laid_shaped( ShapedScript::Thai => thai_error(e, &c.text), ShapedScript::Latin => EditError::Invalid(pdfcraft_fonts::shaped_text::latin_message(e, &c.text)), })?; + // A run the shaped layout leaves as a `Piece::Latin` but that WinAnsi cannot encode (Greek or + // Cyrillic) is drawn with the bundled Inter face, embedded, so it is not silently lost to + // WinAnsi `?`. The face is added only when a run needs it, so pure Hebrew stays as before. + const HEX_DIGITS: &[u8; 16] = b"0123456789ABCDEF"; + let needs = laid.iter().any(|(_, _, _, pieces, _)| pieces.iter().any(|p| matches!(p, Piece::Latin(s) if piece_needs_inter_face(s)))); + let inter: Option<(String, pdfcraft_fonts::pdf::Metrics)> = if needs { + match pdfcraft_fonts::document_latin_fonts(t.bold).into_iter().next() { + Some(face) => { + seed_full_fonts(fonts, taken); + let name = pdfcraft_fonts::embedding::embed(doc, fonts, face.bytes, face.family).map_err(EditError::Invalid)?; + let font = fonts.reference(name.as_bytes()).ok_or_else(|| EditError::Invalid("the bundled face could not be added".into()))?; + let dict = doc.dict(&Object::Ref(font)).ok_or_else(|| EditError::Invalid("the bundled face could not be read".into()))?; + let metrics = pdfcraft_fonts::pdf::Metrics::from_dict(doc, &dict); + Some((name, metrics)) + } + None => None, + } + } else { + None + }; out.extend(format!("BT {}\n", t.fill_op()).bytes()); if t.char_spacing != 0.0 { out.extend(format!("{} Tc\n", n(t.char_spacing)).bytes()); @@ -113,11 +133,28 @@ pub(super) fn draw_laid_shaped( for piece in pieces { match piece { Piece::Latin(s) => { - out.extend(format!("/{latin} {} Tf {} Tw 1 0 0 1 {} {} Tm ", n(t.size), n(tw), n(pen), n(y)).bytes()); - out.extend(literal(&win_ansi(s))); - out.extend_from_slice(b" Tj\n"); - current = None; - pen += latin_width(t, s) + tw * s.matches(' ').count() as f64; + // A run WinAnsi cannot encode (Greek or Cyrillic) is drawn with the bundled Inter + // face; every other run stays on the standard font as before. + let inter_pick = inter.as_ref().filter(|_| piece_needs_inter_face(s)); + // The face has no soft hyphen: draw it as a hyphen, as `draw_inter_face` does. + let encoded = inter_pick.as_ref().and_then(|(_, m)| m.encode(&s.replace('\u{ad}', "-"))); + if let (Some((name, metrics)), Some(encoded)) = (inter_pick, encoded) { + out.extend(format!("/{name} {} Tf {} Tw 1 0 0 1 {} {} Tm <", n(t.size), n(tw), n(pen), n(y)).bytes()); + for &b in &encoded { + out.push(HEX_DIGITS[(b >> 4) as usize]); + out.push(HEX_DIGITS[(b & 0x0F) as usize]); + } + out.extend_from_slice(b"> Tj\n"); + let glyph_w: f64 = metrics.codes(&encoded).iter().map(|(c, _)| metrics.width(*c) * t.size).sum(); + pen += glyph_w + t.char_spacing * s.chars().count() as f64 + tw * s.matches(' ').count() as f64; + current = None; + } else { + out.extend(format!("/{latin} {} Tf {} Tw 1 0 0 1 {} {} Tm ", n(t.size), n(tw), n(pen), n(y)).bytes()); + out.extend(literal(&win_ansi(s))); + out.extend_from_slice(b" Tj\n"); + current = None; + pen += latin_width(t, s) + tw * s.matches(' ').count() as f64; + } } Piece::Shaped(clusters) => pen = shaped.show(out, clusters, pen, y, t.size, t.char_spacing, tw, &mut current), } @@ -213,6 +250,89 @@ pub(super) struct DrawnItem { pub custom_rect: Option<[f64; 4]>, } +/// Whether `t` has a character the standard font (WinAnsi) can't draw, which the bundled Inter +/// face draws: the text is set in the embedded face, as `doc_create` does. Arabic, Hebrew and +/// Thai go to their own shaped face (or are drawn as `?` when it's missing), not the Inter face. +fn needs_inter_face(t: &AddedText) -> bool { + t.text.chars().any(|c| !matches!(c, '\n' | '\r') && !pdfcraft_fonts::win_ansi_encodable(c) && !is_arabic(c) && !is_hebrew(c) && !is_thai(c)) +} + +/// Whether a run the shaped layout leaves as a `Piece::Latin` must be drawn with the bundled Inter +/// face instead of WinAnsi: it holds a character WinAnsi cannot encode that the shaped face does +/// not shape (Greek or Cyrillic). WinAnsi-encodable and shaped-script runs stay on WinAnsi. +fn piece_needs_inter_face(s: &str) -> bool { + s.chars().any(|c| !matches!(c, '\n' | '\r') && !pdfcraft_fonts::win_ansi_encodable(c) && !is_arabic(c) && !is_hebrew(c) && !is_thai(c)) +} + +/// Copy the page's own `PCFull*` fonts into `fonts` before the bundled face is embedded. `embed` +/// names a new resource by looking only at the dict it is given, so an empty dict always yields +/// `PCFull0`, which `write` would then set over a different font the page already has under that +/// name. Seeded, it picks a free name, or reuses an identical face already on the page. +fn seed_full_fonts(fonts: &mut Dict, taken: &Dict) { + for (key, value) in taken.iter().filter(|(key, _)| key.starts_with(b"PCFull")) { + fonts.set(key.to_vec(), value.clone()); + } +} + +/// Draw `t` with the bundled Inter face, embedded: its real outlines, for the Latin, Greek and +/// Cyrillic letters WinAnsiEncoding lacks. A soft hyphen is drawn as a hyphen, as the face has +/// no glyph for it. +fn draw_inter_face(doc: &mut Document, t: &AddedText, taken: &Dict, mut out: Vec) -> Result { + let face = pdfcraft_fonts::document_latin_fonts(t.bold) + .into_iter() + .next() + .ok_or_else(|| EditError::Invalid("this build has no bundled Latin, Greek and Cyrillic face".into()))?; + let mut fonts = Dict::new(); + seed_full_fonts(&mut fonts, taken); + let name = pdfcraft_fonts::embedding::embed(doc, &mut fonts, face.bytes, face.family).map_err(EditError::Invalid)?; + let font = fonts.reference(name.as_bytes()).ok_or_else(|| EditError::Invalid("the bundled face could not be added".into()))?; + let dict = doc.dict(&Object::Ref(font)).ok_or_else(|| EditError::Invalid("the bundled face could not be read".into()))?; + let metrics = pdfcraft_fonts::pdf::Metrics::from_dict(doc, &dict); + let mut res = Dict::new(); + res.set(b"Font".to_vec(), Object::Dict(fonts)); + // A soft hyphen is drawn as a hyphen: the face has no glyph for it. + let show = |s: &str| s.chars().map(|c| if c == '\u{ad}' { '-' } else { c }).collect::(); + let all = wrap_measured(t, |s| { + let encoded = metrics.encode(&show(s)).ok_or_else(|| { + let missing = s.chars().find(|c| metrics.encode(&show(&c.to_string())).is_none()).unwrap_or('?'); + EditError::Invalid(format!("the bundled Inter face can't show U+{:04X}", u32::from(missing))) + })?; + Ok(metrics.codes(&encoded).iter().map(|(code, _)| metrics.width(*code) * t.size).sum::() + t.char_spacing * s.chars().count() as f64) + })?; + let norm_r = norm(t.rect); + let h = all.len().max(1) as f64 * t.size * 1.2; + let r = [norm_r[0], norm_r[3] - h, norm_r[2], norm_r[3]]; + // Painted like standard-font text: its gray or CMYK ink when it has one, else RGB. + out.extend_from_slice(b"BT "); + out.extend(pdfcraft_content::serialize_ops(&[pdfcraft_content::Op::new("Tf", vec![Object::name(name.as_str()), Object::Real(t.size)])])); + out.extend(format!("{}\n", t.fill_op()).bytes()); + if t.char_spacing != 0.0 { + out.extend(format!("{} Tc\n", n(t.char_spacing)).bytes()); + } + let paragraphs: Vec = all.iter().map(|(_, p)| *p).collect(); + const HEX_DIGITS: &[u8; 16] = b"0123456789ABCDEF"; + for (i, (line, _)) in all.iter().enumerate() { + let encoded = metrics.encode(&show(line)).ok_or_else(|| { + let unencodable = line.chars().find(|c| metrics.encode(&show(&c.to_string())).is_none()).unwrap_or('?'); + EditError::Invalid(format!("the bundled Inter face cannot show '{unencodable}' (U+{:04X})", u32::from(unencodable))) + })?; + let glyph_w: f64 = metrics.codes(&encoded).iter().map(|(c, _)| metrics.width(*c) * t.size).sum(); + let w = glyph_w + t.char_spacing * line.chars().count() as f64; + let spaces = line.matches(' ').count(); + let (x, tw) = placed(t, r, ¶graphs, i, w, spaces, false); + let y = r[3] - (i as f64 * 1.2 + 0.95) * t.size; + out.extend(format!("1 0 0 1 {} {} Tm {} Tw <", n(x), n(y), n(tw)).bytes()); + for &b in &encoded { + out.push(HEX_DIGITS[(b >> 4) as usize]); + out.push(HEX_DIGITS[(b & 0x0F) as usize]); + } + out.extend_from_slice(b"> Tj\n"); + } + out.extend_from_slice(b"ET\n"); + out.extend_from_slice(b"Q\n"); + Ok(DrawnItem { stream: out, resources: res, custom_rect: Some(r) }) +} + /// Content and resources for an item; `view` maps display space to user space. `taken` holds the /// page's font names. `existing`: the item is being replaced, so a build without the Arabic or /// Hebrew face keeps drawing that text as `?`, as before it was supported, rather than refusing to @@ -313,6 +433,9 @@ pub(super) fn draw(doc: &mut Document, c: &Content, view: [f64; 6], taken: &Dict out.extend_from_slice(b"Q\n"); return Ok(DrawnItem { stream: out, resources: res, custom_rect: None }); } + if needs_inter_face(t) { + return draw_inter_face(doc, t, taken, out); + } res.set(b"Font".to_vec(), Object::Dict(fonts)); let r = text_rect(t); out.extend(format!("BT /{name} {} Tf {}\n", n(t.size), t.fill_op()).bytes()); diff --git a/crates/edit/src/added/layout.rs b/crates/edit/src/added/layout.rs index cbc9826f8d..d6b30b2787 100644 --- a/crates/edit/src/added/layout.rs +++ b/crates/edit/src/added/layout.rs @@ -189,10 +189,21 @@ pub(super) fn is_hebrew(c: char) -> bool { matches!(u32::from(c), 0x0591..=0x05F4 | 0xFB1D..=0xFB4F) } +/// Whether `c` is drawn by neither the standard font (WinAnsi) nor the bundled Inter face: +/// the character the Add-text path can't show. `\n` splits lines; other control characters +/// (a lone `\r`, `\t`'s non-tab siblings) are drawn as `?` and don't count as face coverage. +fn undrawable_char(c: char) -> bool { + if !pdfcraft_fonts::win_ansi_encodable(c) && (0..=0x1f).contains(&u32::from(c)) && c != '\n' { + return true; + } + !pdfcraft_fonts::win_ansi_encodable(c) + && !pdfcraft_fonts::document_latin_fonts(false).into_iter().next().is_some_and(|f| pdfcraft_fonts::embedding::covers(f.bytes, &c.to_string())) +} + /// The first character of `t` that would be drawn as `?`: outside WinAnsiEncoding and not drawn -/// with the craft-fonts Arabic (#125) or Hebrew (#128) face, or Arabic or Hebrew that the face can't -/// draw (or that has no face to draw it). Page-content tools refuse such text; the Add-text editor -/// keeps it open. +/// with the bundled Inter face (Greek, Cyrillic), or not drawn with the craft-fonts Arabic (#125) +/// or Hebrew (#128) face, or Arabic or Hebrew that the face can't draw (or that has no face to +/// draw it). Page-content tools refuse such text; the Add-text editor keeps it open. pub fn first_undrawable(t: &AddedText) -> Option { if t.font_resource.is_some() { return None; @@ -211,15 +222,17 @@ pub fn first_undrawable(t: &AddedText) -> Option { return Some(c); } if !shaped_by_a_face(t) { - // Drawn line by line in the item's standard font (`\n` splits lines). Without the face - // that is also how `draw` redraws an existing item, so it's checked that way. - return t.text.split('\n').find_map(pdfcraft_fonts::first_non_win_ansi); + // Drawn line by line in the item's standard font or the bundled Inter face (`\n` splits + // lines). Without the face that is also how `draw` redraws an existing item, so it's + // checked that way. + return t.text.split('\n').find_map(|line| line.chars().find(|c| undrawable_char(*c))); } - // What `shaped_layout` leaves to the standard font, exactly as `draw_shaped` splits it. + // What `shaped_layout` leaves to the standard font or the bundled Inter face, exactly as + // `draw_shaped` splits it. wrapped(t).into_iter().find_map(|(line, rtl, _)| { let (pieces, _) = shaped_layout(t, &line, rtl).ok()?; pieces.iter().find_map(|p| match p { - Piece::Latin(s) => pdfcraft_fonts::first_non_win_ansi(s), + Piece::Latin(s) => s.chars().find(|c| undrawable_char(*c)), Piece::Shaped(_) => None, }) }) diff --git a/crates/edit/src/tests.rs b/crates/edit/src/tests.rs index 8b7bf33834..b058b4846f 100644 --- a/crates/edit/src/tests.rs +++ b/crates/edit/src/tests.rs @@ -2210,6 +2210,128 @@ fn added_hebrew_text_is_drawn_right_to_left_and_stays_searchable() { assert!(mapped.contains("<05E905"), "{mapped}"); } +/// #9016: Greek text is drawn with the bundled Inter face (embedded), not the WinAnsi +/// standard font. Without the face, it's refused with a clear message. +#[test] +fn added_greek_text_is_drawn_with_the_embedded_face() { + let mut doc = fixture(); + let text = AddedText { rect: [72.0, 600.0, 400.0, 700.0], text: "Καλημέρα".into(), size: 14.0, ..AddedText::default() }; + if pdfcraft_fonts::document_latin_fonts(false).is_empty() { + eprintln!("skipping the Greek drawing checks: built without a craft-fonts Latin face (set CRAFT_FONTS_DIR)"); + let err = add_content(&mut doc, 0, &Content::Text(text)).unwrap_err(); + assert!(err.to_string().contains("U+039A"), "{err}"); + assert!(!doc.is_modified(), "nothing is written when the font is missing"); + return; + } + assert_eq!(first_undrawable(&text), None); + add_content(&mut doc, 0, &Content::Text(text.clone())).unwrap(); + let doc = reopen(&doc); + let added = list_added(&doc); + let Content::Text(t) = &added[0].content else { panic!() }; + assert_eq!(t.text, "Καλημέρα", "the logical text is kept for editing"); + // The Greek glyphs come from the embedded face, not the WinAnsi standard font. Select the + // added item's stream by its /PCMark /Added tag: the page's own "Hi" stream also has a Tj, + // so the first Tj stream is not the added one. + let item = added_stream(&doc, 0).expect("the added item's stream"); + assert!(item.contains("PCFull"), "the Greek is drawn with the embedded face: {item}"); + assert!(item.contains("Tf"), "the embedded face is set: {item}"); + // The embedded face is a real embedded font (a FontFile in its descriptor) that maps its + // codes to Greek — not the WinAnsi standard font (Type 1). + let p = &pdfcraft_model::pages(&doc)[0]; + let res = doc.resolve(p.dict.get(b"Resources").unwrap()); + let fonts = doc.resolve(res.as_dict().unwrap().get(b"Font").unwrap()).as_dict().unwrap().clone(); + let font = fonts + .iter() + .find(|(k, _)| k.starts_with(b"PCFull")) + .map(|(_, v)| doc.resolve(v).as_dict().unwrap().clone()) + .expect("the embedded face is a resource"); + assert_eq!(font.name(b"Subtype"), Some(&b"Type0"[..]), "the embedded face is a composite font, not WinAnsi"); + assert!(font_has_font_file(&doc, &font), "the embedded face carries a FontFile"); + let tounicode_bytes = stream_bytes(&doc, font.get(b"ToUnicode").unwrap()).unwrap(); + let tounicode = String::from_utf8_lossy(&tounicode_bytes); + assert!(tounicode.contains("039A") || tounicode.contains("03B1"), "the face maps its codes to Greek: {tounicode}"); +} + +/// #9016: mixed Hebrew + Greek text is drawn with the Hebrew shaped face and the Greek with the +/// bundled Inter face (embedded), not WinAnsi `?` (which the pre-fix code produced for the Greek). +#[test] +fn added_mixed_hebrew_greek_text_draws_greek_with_the_embedded_face() { + let mut doc = fixture(); + let text = AddedText { rect: [72.0, 600.0, 400.0, 700.0], text: "שלום Καλημέρα".into(), size: 14.0, ..AddedText::default() }; + let hebrew = pdfcraft_fonts::document_hebrew_font(false).is_some(); + let latin = !pdfcraft_fonts::document_latin_fonts(false).is_empty(); + if !hebrew || !latin { + eprintln!("skipping the mixed Hebrew+Greek drawing checks: built without a Hebrew ({hebrew}) or Inter ({latin}) face"); + return; + } + assert_eq!(first_undrawable(&text), None); + add_content(&mut doc, 0, &Content::Text(text.clone())).unwrap(); + let doc = reopen(&doc); + let added = list_added(&doc); + let Content::Text(t) = &added[0].content else { panic!() }; + assert_eq!(t.text, "שלום Καλημέρα", "the logical text is kept for editing"); + // The Greek run is drawn with the embedded Inter face (PCFull), the Hebrew run with the + // shaped face (PCAr): both appear in the added item's stream. + let item = added_stream(&doc, 0).expect("the added item's stream"); + assert!(item.contains("PCFull"), "the Greek is drawn with the embedded face: {item}"); + assert!(item.contains("PCAr"), "the Hebrew is drawn with the shaped face: {item}"); + assert!(!item.contains("(??????"), "the Greek is not WinAnsi placeholders: {item}"); + // The embedded face maps its codes to Greek. + let p = &pdfcraft_model::pages(&doc)[0]; + let res = doc.resolve(p.dict.get(b"Resources").unwrap()); + let fonts = doc.resolve(res.as_dict().unwrap().get(b"Font").unwrap()).as_dict().unwrap().clone(); + let font = fonts + .iter() + .find(|(k, _)| k.starts_with(b"PCFull")) + .map(|(_, v)| doc.resolve(v).as_dict().unwrap().clone()) + .expect("the embedded face is a resource"); + assert_eq!(font.name(b"Subtype"), Some(&b"Type0"[..]), "the embedded face is a composite font"); + let tounicode_bytes = stream_bytes(&doc, font.get(b"ToUnicode").unwrap()).unwrap(); + let tounicode = String::from_utf8_lossy(&tounicode_bytes); + assert!(tounicode.contains("039A") || tounicode.contains("03B1"), "the face maps its codes to Greek: {tounicode}"); +} + +/// The base font of each `PCFull*` resource on page 0, by resource name. +fn embedded_faces_by_resource(doc: &Document) -> std::collections::BTreeMap { + let p = &pdfcraft_model::pages(doc)[0]; + let res = doc.resolve(p.dict.get(b"Resources").unwrap()); + let fonts = doc.resolve(res.as_dict().unwrap().get(b"Font").unwrap()).as_dict().unwrap().clone(); + fonts + .iter() + .filter(|(k, _)| k.starts_with(b"PCFull")) + .map(|(k, v)| { + let font = doc.resolve(v).as_dict().unwrap().clone(); + (String::from_utf8_lossy(k).into_owned(), String::from_utf8_lossy(font.name(b"BaseFont").unwrap_or(b"")).into_owned()) + }) + .collect() +} + +/// #9016 review: a second added item that needs the embedded face must not take the resource name +/// of the first one's face and repoint it, so the first item keeps its own glyphs. +#[test] +fn a_second_greek_item_does_not_repoint_the_first_items_embedded_face() { + let mut doc = fixture(); + if pdfcraft_fonts::document_latin_fonts(false).is_empty() { + eprintln!("skipping: built without a craft-fonts Latin face (set CRAFT_FONTS_DIR)"); + return; + } + let first = AddedText { rect: [72.0, 600.0, 400.0, 700.0], text: "Καλημέρα".into(), size: 14.0, ..AddedText::default() }; + add_content(&mut doc, 0, &Content::Text(first)).unwrap(); + let before = embedded_faces_by_resource(&reopen(&doc)); + assert!(!before.is_empty(), "the first item embeds a face"); + let second = AddedText { rect: [72.0, 400.0, 400.0, 500.0], text: "Привет".into(), size: 14.0, bold: true, ..AddedText::default() }; + add_content(&mut doc, 0, &Content::Text(second)).unwrap(); + let after = embedded_faces_by_resource(&reopen(&doc)); + for (name, base) in &before { + assert_eq!(after.get(name), Some(base), "the first item's /{name} still resolves to its own face: {before:?} -> {after:?}"); + } + let regular = pdfcraft_fonts::document_latin_fonts(false).into_iter().next().map(|f| f.bytes); + let bold = pdfcraft_fonts::document_latin_fonts(true).into_iter().next().map(|f| f.bytes); + if regular != bold { + assert_eq!(after.len(), before.len() + 1, "a different face gets its own resource: {before:?} -> {after:?}"); + } +} + #[test] fn odd_hebrew_text_never_panics() { let mut doc = fixture(); @@ -2228,6 +2350,31 @@ fn arabic_font_names(doc: &Document, page: usize) -> Vec { fonts.as_dict().unwrap().iter().map(|(k, _)| String::from_utf8_lossy(k).into_owned()).filter(|k| k.starts_with("PCAr")).collect() } +/// The decoded content stream of the added item on `page` (by its `/PCMark /Added` tag), if any. +/// The page's own content stream also has a `Tj`, so the added stream is found by tag, not by +/// searching for `Tj`. +fn added_stream(doc: &Document, page: usize) -> Option { + let p = &pdfcraft_model::pages(doc)[page]; + let c = p.dict.get(b"Contents").cloned()?; + let resolved = doc.resolve(&c); + let list = match resolved.as_ref() { + Object::Array(a) => a.clone(), + other => vec![other.clone()], + }; + list.iter().find(|o| stream_tag(doc, o).as_deref() == Some("Added")).map(|o| String::from_utf8_lossy(&stream_bytes(doc, o).unwrap()).into_owned()) +} + +/// Whether a font's descriptor carries an embedded program (`FontFile2`/`FontFile3`). +fn font_has_font_file(doc: &Document, font: &Dict) -> bool { + let Some(desc_ref) = font.get(b"DescendantFonts") else { return false }; + let descendant = doc.resolve(desc_ref); + let Some(cid_ref) = descendant.as_array().and_then(|a| a.first()) else { return false }; + let cid = doc.resolve(cid_ref); + let Some(desc_ref2) = cid.as_dict().and_then(|d| d.get(b"FontDescriptor")) else { return false }; + let descriptor = doc.resolve(desc_ref2); + descriptor.as_dict().is_some_and(|d| d.get(b"FontFile2").is_some() || d.get(b"FontFile3").is_some()) +} + #[test] fn arabic_items_keep_their_own_fonts_through_saves_updates_and_deletes() { let mut doc = fixture(); diff --git a/crates/ui-egui/src/panels/format_text_ui.rs b/crates/ui-egui/src/panels/format_text_ui.rs index 775254cd20..a5a02c6fe3 100644 --- a/crates/ui-egui/src/panels/format_text_ui.rs +++ b/crates/ui-egui/src/panels/format_text_ui.rs @@ -1039,13 +1039,14 @@ mod tests { assert_eq!(item(&app).font_resource, None); assert_eq!(item(&app).family, FontFamily::Times); - // Picking a document font on an open draft with Greek text unblocks and applies it. + // Greek text on an open draft is drawn with bundled Inter by default (#9016), so it is not blocked; picking a document font + // still applies it. let mut draft = open_draft(&mut app); draft.text = "γραφή φ".into(); app.views[0].session.content.draft = Some(draft.clone()); - assert!(app.views[0].session.content.blocked().is_some(), "standard font blocks Greek phi"); + assert_eq!(app.views[0].session.content.blocked(), None, "the default font draws Greek phi with bundled Inter"); apply(&ctx, &mut app, 0, Target::Draft(Box::new(draft)), &pick); - assert_eq!(app.views[0].session.content.blocked(), None, "custom font unblocks Greek phi"); + assert_eq!(app.views[0].session.content.blocked(), None, "custom font keeps Greek phi unblocked"); assert_eq!(item(&app).text, "γραφή φ"); assert_eq!(item(&app).font_resource.as_deref(), Some(font.resource.as_str())); diff --git a/crates/ui-egui/tests/it/edit.rs b/crates/ui-egui/tests/it/edit.rs index e7ae037ec3..ca1f6ae0e9 100644 --- a/crates/ui-egui/tests/it/edit.rs +++ b/crates/ui-egui/tests/it/edit.rs @@ -49,9 +49,9 @@ fn add_text_with_custom_unicode_font_succeeds_and_roundtrips() { // Greek text containing phi (U+03C6) reported in issue #4978 ("γραφή"). let greek_text = "γραφή (Greek text with φ)"; - // Standard text without font_resource would be flagged as undrawable by first_undrawable. + // The default path draws Greek with bundled Inter (#9016); an explicit custom font still keeps its resource. let standard_attempt = AddedText { rect: [40.0, 195.0, 240.0, 220.0], text: greek_text.to_string(), ..Default::default() }; - assert!(pdfcraft_engine::first_undrawable(&standard_attempt).is_some(), "standard font must refuse Greek phi"); + assert_eq!(pdfcraft_engine::first_undrawable(&standard_attempt), None, "the default font draws Greek with bundled Inter"); // With custom font_resource, first_undrawable returns None. let custom_added = From 00c357ac717b46ddcde71a00a39ef6ed54836196 Mon Sep 17 00:00:00 2001 From: Sandip Patel <55301948+SAPHemlock@users.noreply.github.com> Date: Fri, 4 Dec 2026 07:12:36 -0800 Subject: [PATCH 3/8] fix(xfa): remap bookmarks and named destinations to the pages a relayout writes (#9027) (#9080) * fix(xfa): remap bookmarks and named destinations to the pages a relayout writes (#9027) After an XFA form is laid out again, the document's pages are replaced, so bookmarks and named destinations that named the old pages pointed at orphaned objects. Remap them to the replacements by page position (a destination naming a page the layout dropped goes to the last page written); destinations naming untouched pages or non-page targets are left alone. - xfa/pdf.rs: page_list (the pages a layout replaces, in reading order); write_form captures the old pages before page creation and remaps destinations after the new pages are written; remap_destinations handles /Dests, /Outlines (bookmark items, /Next chains and /Kids), and /Names (Dests and Pages categories); remap_dest / remap_action / remap_name_tree update indirect objects in place. - xfa/fixtures.rs: dests_shell, a shell with /Dests, /Names and two /Outlines items (a /Dest and a GoTo action) naming the placeholder page. - engine/tests.rs: xfa_relayout_keeps_bookmarks_and_named_destinations_on_the_pages_it_writes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(xfa): bound the destination remap's walks and remap what they omit (#9027 review) The remap that points bookmarks and named destinations at the pages a relayout writes could walk a malformed document forever, and silently left a destination stale when a search hit its bound: - xfa/pdf.rs: page_list errors on a page tree that lists a node twice, and on one past MAX_PAGES_SEARCHED, before any page is replaced; the outline walk follows each item's /First child (the spec's way) and errors at the bound instead of truncating; /Names categories are handled per category, the Pages one's values being page references remapped through the map directly (remap_page_ref); remap_dest, remap_action and remap_name_tree take a visited set, a /D chain or /Kids chain that repeats being an error before the recursion continues. - xfa/fixtures.rs: the name-tree key is the string (end), as the spec requires. - xfa/pdf.rs tests: each fix is guarded by a test that fails without it; automation hostile_args: the cyclic page tree, destination, and name tree are in the hostile-input sweep. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(xfa): count pages and bookmarks at acceptance, pin the position remap (#9027 review) - page_list: the 10,000-page bound is checked when a leaf is accepted, so a tree of exactly the bound followed by an empty /Pages node is still walked. - the bookmark walk checks `seen` before the item bound, so a repeat of an item already counted is not a new item. - tests for 3 old pages onto 2 and 2 onto 3, each with a bookmark, a /Dests entry and a /Names entry, plus one for each bound case above. - remap_destinations' doc says what an error leaves behind: the walks after the bookmark walk can fail once earlier ones were written. Co-Authored-By: Claude Sonnet 5.5 * fix(xfa): a page tree the remap cannot list is a warning, not a failed layout (#9027) Main's relayout tests (cyclic page trees, a shared-reference page subtree past the walk bound) expect the layout to be written. The destination remap now reports what it could not do as a warning and keeps the layout, instead of failing the whole relayout. Co-Authored-By: Claude Sonnet 5.5 --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: FredApps Co-authored-by: Claude Sonnet 5.5 --- crates/automation/tests/it/hostile_args.rs | 93 ++++ crates/engine/src/tests.rs | 100 ++++ crates/xfa/src/fixtures.rs | 24 + crates/xfa/src/pdf.rs | 608 +++++++++++++++++++++ 4 files changed, 825 insertions(+) diff --git a/crates/automation/tests/it/hostile_args.rs b/crates/automation/tests/it/hostile_args.rs index fe30268b39..c772d8ffa0 100644 --- a/crates/automation/tests/it/hostile_args.rs +++ b/crates/automation/tests/it/hostile_args.rs @@ -563,6 +563,99 @@ fn no_tool_panics_when_the_viewer_sees_fewer_pages_than_the_file_has() { assert!(failures.is_empty(), "{} failure(s); the first is: {}", failures.len(), failures.first().map_or("", String::as_str)); } +/// Which structure of the form refers to itself: the page tree, the named destinations, or the +/// name tree. +#[derive(Clone, Copy, Debug, PartialEq)] +enum CyclicXfa { + Pages, + Dests, + Names, +} + +/// A dynamic XFA form (#9027) in which `cyclic` refers to itself: the relayout run on open used +/// to walk that cycle forever. The other structures are normal. The layout fails with a note and +/// the document opens anyway; the point is that it answers at all. +fn cyclic_xfa_pdf(cyclic: CyclicXfa) -> Vec { + let xdp = pdfcraft_xfa::fixtures::template(1); + let (page_kids, dests_key, names_key) = match cyclic { + CyclicXfa::Pages => ("3 0 R 2 0 R", "", ""), + CyclicXfa::Dests => ("3 0 R", " /Dests 6 0 R", ""), + CyclicXfa::Names => ("3 0 R", "", " /Names 7 0 R"), + }; + let objs: Vec<(u32, String)> = vec![ + (1, format!("<< /Type /Catalog /Pages 2 0 R /NeedsRendering true /AcroForm << /XFA 5 0 R /Fields [] >>{dests_key}{names_key} >>")), + (2, format!("<< /Type /Pages /Kids [{page_kids}] /Count 1 >>")), + (3, "<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Contents 4 0 R >>".into()), + (4, "<< /Length 44 >>\nstream\nBT /F1 12 Tf 72 700 Td (Please wait...) Tj ET\nendstream".into()), + (5, format!("<< /Length {} >>\nstream\n{xdp}\nendstream", xdp.len())), + (6, "<< /cyc 8 0 R >>".into()), + (7, "<< /Dests 9 0 R >>".into()), + (8, "<< /D 8 0 R >>".into()), + (9, "<< /Names [(end) 3 0 R] /Kids [9 0 R] >>".into()), + ]; + let size = 10; + let mut out = b"%PDF-1.7\n".to_vec(); + let mut offsets = vec![None; size]; + for (num, body) in &objs { + if let Some(slot) = offsets.get_mut(*num as usize) { + *slot = Some(out.len()); + } + out.extend_from_slice(format!("{num} 0 obj\n{body}\nendobj\n").as_bytes()); + } + let xref = out.len(); + out.extend_from_slice(format!("xref\n0 {size}\n0000000000 65535 f \n").as_bytes()); + for offset in offsets.iter().skip(1) { + out.extend_from_slice( + match offset { + Some(o) => format!("{o:010} 00000 n \n"), + None => "0000000000 65535 f \n".to_string(), + } + .as_bytes(), + ); + } + out.extend_from_slice(format!("trailer << /Size {size} /Root 1 0 R >>\nstartxref\n{xref}\n%%EOF\n").as_bytes()); + out +} + +#[test] +fn no_tool_hangs_on_a_cyclic_xfa_form() { + // #9027: a dynamic form whose page tree, destination, or name tree refers to itself used to + // make the relayout run on open walk the cycle forever. Opening must answer (the layout + // fails with a note and the document opens anyway), and every tool must answer with a + // result or an error. + for cyclic in [CyclicXfa::Pages, CyclicXfa::Dests, CyclicXfa::Names] { + let root = tmp(&format!("cyclic-xfa-{cyclic:?}")); + let pdf = cyclic_xfa_pdf(cyclic); + let mut failures = Vec::new(); + for def in tools() { + // Written again for every tool: tools that save write to `in.pdf`, the plausible path. + std::fs::write(root.join("in.pdf"), &pdf).expect("fixture"); + let mut a = Automation::new().with_root(&root).expect("root"); + let opened = a.call("doc_open", &json!({ "path": "in.pdf" })).expect("open the cyclic form"); + let doc = opened + .into_iter() + .find_map(|c| match c { + pdfcraft_automation::Content::Json(v) => v["doc"].as_u64(), + pdfcraft_automation::Content::Png { .. } => None, + }) + .expect("the opened document has an id"); + if let Err(e) = guarded(&mut a, def.name, &Value::Object(plausible_with(&def, Some(doc)))) { + failures.push(e); + } + } + for f in &failures { + eprintln!(" {f}"); + } + let _ = std::fs::remove_dir_all(&root); + assert!( + failures.is_empty(), + "on a cyclic {cyclic:?} form: {} failure(s); the first is: {}", + failures.len(), + failures.first().map_or("", String::as_str) + ); + } +} + /// `source_widget` is 1-based and counted against the source's widgets: no value of it but the /// source's one widget (or null, which is the default), nor the key without `source_field`, /// panics or adds a field. diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 43d0a248ce..10f0e8cb02 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -9854,6 +9854,106 @@ fn xfa_text_growth_then_a_script_relayout_both_add_pages() { saves_and_reopens(&mut s, id, 3); } +/// Bookmarks and named destinations that name a dynamic form's page follow the pages a +/// re-layout replaces them with: the placeholder page is laid out onto a real one, and +/// typing into a growable field lays the form out onto a second; each time, the bookmarks +/// and the named destinations resolve to the first of the pages the layout wrote, not the +/// page it replaced. +#[test] +fn xfa_relayout_keeps_bookmarks_and_named_destinations_on_the_pages_it_writes() { + let before = r#""#; + let template = pdfcraft_xfa::fixtures::presence_growth_template(false, before, "", ""); + let mut s = Session::new().with_clock(|| 1_700_000_000); + let id = s.open("dests.pdf", None, Arc::new(pdfcraft_xfa::fixtures::dests_shell(&template)), None).unwrap(); + assert_eq!(s.get(id).unwrap().info.pages.len(), 1, "{:?}", s.take_js_output(id).errors); + let pages = dest_pages(&s, id); + assert_eq!(pages, vec![Some(0); 4], "the bookmarks and named destinations are on the first page the layout wrote"); + let notes: String = (1..=60).map(|i| format!("line {i}\n")).collect(); + s.apply(id, Edit::SetFieldValue { name: "notes".into(), value: FieldValue::Text(notes) }).unwrap(); + assert_eq!(s.get(id).unwrap().info.pages.len(), 2); + let pages = dest_pages(&s, id); + assert_eq!(pages, vec![Some(0); 4], "the bookmarks and named destinations follow the first page to the second layout"); + saves_and_reopens(&mut s, id, 2); +} + +/// The position, in the page tree, of the page each of the document's bookmarks and named +/// destinations names: the `/Dests` entry, the `/Names` tree entry, and the two `/Outlines` +/// items (one with a `/Dest`, one with a `GoTo` action). `None` when one names a page the +/// page tree does not hold. +fn dest_pages(s: &Session, id: DocId) -> Vec> { + use pdfcraft_cos::{ObjRef, Object}; + let doc = s.get(id).unwrap(); + let cos = pdfcraft_cos::Document::open(doc.bytes.clone()).unwrap(); + let catalog = cos.get(cos.root().unwrap()).as_dict().cloned().unwrap(); + let pages = catalog + .get(b"Pages") + .and_then(Object::as_ref) + .map(|r| cos.get(r)) + .and_then(|p| p.as_dict().and_then(|d| d.get(b"Kids")).map(|k| cos.resolve(k))) + .and_then(|k| k.as_array().cloned()) + .unwrap_or_default(); + let pages: Vec = pages.iter().filter_map(Object::as_ref).collect(); + let pos = |v: &Object| { + let resolved = cos.resolve(v); + let page_ref = match resolved.as_array() { + Some(arr) => arr.first().and_then(Object::as_ref), + None => Object::as_ref(&resolved), + }; + page_ref.and_then(|p| pages.iter().position(|x| *x == p)) + }; + let mut out = Vec::new(); + if let Some(dests) = catalog.get(b"Dests").map(|d| cos.resolve(d)).and_then(|d| d.as_dict().cloned()) { + for (_, v) in dests.iter() { + out.push(pos(v)); + } + } + if let Some(names) = catalog.get(b"Names").map(|n| cos.resolve(n)).and_then(|n| n.as_dict().cloned()) { + for (cat, node) in names.iter() { + if cat.as_slice() == b"Dests" || cat.as_slice() == b"Pages" { + let Some(entries) = + cos.resolve(node).as_dict().and_then(|d| d.get(b"Names")).map(|n| cos.resolve(n)).and_then(|n| n.as_array().cloned()) + else { + continue; + }; + for i in (0..entries.len() / 2 * 2).step_by(2) { + if let Some(v) = entries.get(i + 1) { + out.push(pos(v)); + } + } + } + } + } + let Some(first) = + catalog.get(b"Outlines").map(|o| cos.resolve(o)).and_then(|o| o.as_dict().and_then(|d| d.get(b"First")).and_then(Object::as_ref)) + else { + return out; + }; + let mut stack = vec![first]; + while let Some(r) = stack.pop() { + let Some(d) = cos.get(r).as_dict().cloned() else { + continue; + }; + if let Some(dest) = d.get(b"Dest") { + out.push(pos(dest)); + } + if let Some(a) = d.get(b"A") + && cos.resolve(a).as_dict().is_some_and(|d| d.name(b"S") == Some(b"GoTo")) + && let Some(dest) = cos.resolve(a).as_dict().and_then(|d| d.get(b"D")) + { + out.push(pos(dest)); + } + if let Some(next) = d.get(b"Next").and_then(Object::as_ref) { + stack.push(next); + } + if let Some(kids) = d.get(b"Kids").map(|k| cos.resolve(k)).and_then(|k| k.as_array().cloned()) { + for k in kids.iter().filter_map(Object::as_ref).rev() { + stack.push(k); + } + } + } + out +} + #[test] fn xfa_text_growth_refreshes_widget_geometry_but_fixed_height_fields_keep_their_widgets() { for fixed in [false, true] { diff --git a/crates/xfa/src/fixtures.rs b/crates/xfa/src/fixtures.rs index fb7d2228b8..f1506cbf65 100644 --- a/crates/xfa/src/fixtures.rs +++ b/crates/xfa/src/fixtures.rs @@ -987,6 +987,30 @@ pub fn shell(xdp: &str) -> Vec { assemble(objs) } +/// [`shell`] with bookmarks and named destinations that name the placeholder page: a +/// `/Outlines` item with a `/Dest`, one with a `GoTo` action, a `/Dests` entry, and a +/// `/Names` tree entry, all at the page. +pub fn dests_shell(xdp: &str) -> Vec { + let objs: Vec> = vec![ + b"<< /Type /Catalog /Pages 2 0 R /NeedsRendering true /AcroForm << /XFA 5 0 R /Fields [] >> /Outlines 6 0 R /Dests 7 0 R /Names 8 0 R >>" + .to_vec(), + b"<< /Type /Pages /Kids [3 0 R] /Count 1 >>".to_vec(), + b"<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Contents 4 0 R >>".to_vec(), + b"<< /Length 44 >>\nstream\nBT /F1 12 Tf 72 700 Td (Please wait...) Tj ET\nendstream".to_vec(), + format!("<< /Length {} >>\nstream\n{xdp}\nendstream", xdp.len()).into_bytes(), + b"<< /Type /Outlines /Count 2 /First 9 0 R /Last 10 0 R >>".to_vec(), + b"<< /top 11 0 R >>".to_vec(), + b"<< /Dests 12 0 R >>".to_vec(), + b"<< /Title (Top) /Parent 6 0 R /Next 10 0 R /Dest [3 0 R /Fit] >>".to_vec(), + b"<< /Title (Go) /Parent 6 0 R /Prev 9 0 R /A 13 0 R >>".to_vec(), + b"[3 0 R /Fit]".to_vec(), + b"<< /Names [(end) 14 0 R] >>".to_vec(), + b"<< /S /GoTo /D [3 0 R /Fit] >>".to_vec(), + b"[3 0 R /Fit]".to_vec(), + ]; + assemble(objs) +} + /// [`shell`] with usage rights: the catalog's `/Perms` holds a `/UR3` signature (a stand-in /// dictionary, nothing verifies it), beside `others` (`/DocMDP 6 0 R`, say: object 6 is a /// signature dictionary too). `indirect` puts `/Perms` in an object of its own. diff --git a/crates/xfa/src/pdf.rs b/crates/xfa/src/pdf.rs index b597cbd85d..74627c5135 100644 --- a/crates/xfa/src/pdf.rs +++ b/crates/xfa/src/pdf.rs @@ -1121,6 +1121,41 @@ fn earlier_images(doc: &Document, pages: ObjRef) -> HashMap<[u8; 32], ObjRef> { out } +/// The pages under `pages`, in reading order: a `/Pages` node's kids, nested ones descended, +/// up to the bound the other page searches here use. A tree that lists a node twice (a cycle) +/// or holds more than [`MAX_PAGES_SEARCHED`] pages is an error: the list would be short, and a +/// destination naming a page it omits would keep a stale reference. +fn page_list(doc: &Document, pages: ObjRef) -> Result, XfaError> { + let mut out = Vec::new(); + let mut seen: HashSet = HashSet::new(); + let mut stack = vec![pages]; + while let Some(r) = stack.pop() { + if !seen.insert(r) { + return Err(XfaError::Malformed("the document's page tree lists a node twice".into())); + } + let obj = doc.get(r); + let Some(d) = obj.as_dict() else { + continue; + }; + if d.name(b"Type") == Some(b"Pages") || d.get(b"Kids").is_some() { + let kids = d.get(b"Kids").map(|k| doc.resolve(k)).and_then(|k| k.as_array().cloned()).unwrap_or_default(); + for k in kids.iter().filter_map(Object::as_ref).rev() { + stack.push(k); + } + } else { + // The bound counts pages accepted, so a tree of exactly the bound followed by an + // empty node is still walked. + if out.len() >= MAX_PAGES_SEARCHED { + return Err(XfaError::TooLarge(format!( + "the document's page tree holds more than {MAX_PAGES_SEARCHED} pages; its bookmarks and named destinations would not be remapped" + ))); + } + out.push(r); + } + } + Ok(out) +} + /// Write laid-out `form` into `doc`: its pages replace the document's, its widgets join the /// AcroForm's fields (a box the file holds a signature for keeps it), and the AcroForm is marked /// laid out. What was written, with any warnings, comes back. @@ -1142,6 +1177,14 @@ pub fn write_form(doc: &mut Document, form: &Form) -> Result let kept_widgets = widgets::capture(doc, &catalog, pages_ref); // Pictures embedded by earlier passes, from the pages this pass replaces. let images = earlier_images(doc, pages_ref); + // The pages this pass replaces, in order: bookmarks and named destinations that name them + // are pointed at the replacements, by page position, after the new pages are written. + // A page tree the walk cannot list (a cycle, a node listed twice, past the bound) is + // reported, not fatal: the layout is written and its destinations are left as they were. + let (old_pages, remap_skipped) = match page_list(doc, pages_ref) { + Ok(pages) => (pages, None), + Err(why) => (Vec::new(), Some(why.to_string())), + }; let (signed, taken) = existing_fields(doc, &catalog); let groups = earlier_groups(doc, &catalog); let mut em = Emitter { @@ -1191,12 +1234,25 @@ pub fn write_form(doc: &mut Document, form: &Form) -> Result catalog_changed |= register_groups(doc, &mut catalog, &groups, used)?; } let count = kids.len(); + // Bookmarks and named destinations that named the pages above are pointed at the + // replacements, by page position (one the layout dropped goes to the last page). + let new_pages: Vec = kids.iter().filter_map(Object::as_ref).collect(); doc.update_dict(pages_ref, |d| { d.set(b"Type".to_vec(), Object::name("Pages")); d.set(b"Kids".to_vec(), Object::Array(kids)); d.set(b"Count".to_vec(), Object::Int(count as i64)); d.remove(b"Parent"); })?; + let remap_skipped = match remap_destinations(doc, &mut catalog, &old_pages, &new_pages) { + Ok(changed) => { + catalog_changed |= changed; + remap_skipped + } + Err(why) => Some(why.to_string()), + }; + if let Some(why) = remap_skipped { + warnings.push(format!("bookmarks and named destinations were not all pointed at the new pages: {why}")); + } // AcroForm: keep what is there (the XFA packets above all), add our fields and fonts. let acro_ref = catalog.get(b"AcroForm").and_then(Object::as_ref); let mut acro = match catalog.get(b"AcroForm") { @@ -1252,6 +1308,285 @@ pub fn write_form(doc: &mut Document, form: &Form) -> Result Ok(Written { pages: count, fields: field_count, warnings, usage_rights }) } +/// Point bookmarks and named destinations at the pages a layout wrote: `old` (what the +/// document had) maps to `new` by page position, and a destination that named a page the +/// layout dropped is pointed at the last page written (the form shrank). A destination that +/// named a page the layout left alone, or a target that is not a page, is left alone. +/// A bookmark list or name tree past [`MAX_PAGES_SEARCHED`], or a destination or name tree +/// that refers to itself, is an error. The bookmark walk is checked before anything is written, +/// but a name or destination walk can fail after earlier ones were written, so the document may +/// be partly remapped: `write_form` reports that as a warning and keeps the layout. +/// Returns whether `catalog` itself changed (a direct `/Dests` or `/Names`). +fn remap_destinations(doc: &mut Document, catalog: &mut Dict, old: &[ObjRef], new: &[ObjRef]) -> Result { + if old.is_empty() { + return Ok(false); + } + let Some(&last) = new.last() else { + return Ok(false); + }; + let map: HashMap = old.iter().enumerate().map(|(i, o)| (*o, if i < new.len() { new[i] } else { last })).collect(); + let mut catalog_changed = false; + // /Dests: the named destinations, direct or indirect. + let dests_at = catalog.get(b"Dests").and_then(Object::as_ref); + if let Some(mut dests) = catalog.get(b"Dests").map(|d| doc.resolve(d)).and_then(|d| d.as_dict().cloned()) { + let mut updates: Vec<(Vec, Object)> = Vec::new(); + for (name, v) in dests.iter() { + let mut seen = HashSet::new(); + if let Some(new) = remap_dest(doc, v, &map, &mut seen)? { + updates.push((name.clone(), new)); + } + } + if !updates.is_empty() { + for (name, new) in updates { + dests.set(name, new); + } + match dests_at { + Some(r) => doc.set(r, Object::Dict(dests)), + None => { + catalog.set(b"Dests".to_vec(), Object::Dict(dests)); + catalog_changed = true; + } + } + } + } + // /Outlines: the bookmark items, from /First (each item's /Next, /First and /Kids too). + let first = catalog.get(b"Outlines").map(|o| doc.resolve(o)).and_then(|o| o.as_dict().and_then(|d| d.get(b"First")).and_then(Object::as_ref)); + if let Some(first) = first { + let mut items = Vec::new(); + let mut seen: HashSet = HashSet::new(); + let mut stack = vec![first]; + while let Some(r) = stack.pop() { + // Listed twice (its /Kids and /First both name it): remapped once, and not + // counted against the bound again. + if !seen.insert(r) { + continue; + } + if items.len() >= MAX_PAGES_SEARCHED { + return Err(XfaError::TooLarge(format!( + "the document's bookmarks hold more than {MAX_PAGES_SEARCHED} items; they would not all be remapped" + ))); + } + items.push(r); + if let Some(next) = doc.get(r).as_dict().and_then(|d| d.get(b"Next")).and_then(Object::as_ref) { + stack.push(next); + } + // A child, the spec's way: the item's /First. + if let Some(child) = doc.get(r).as_dict().and_then(|d| d.get(b"First")).and_then(Object::as_ref) { + stack.push(child); + } + let kids = + doc.get(r).as_dict().and_then(|d| d.get(b"Kids")).map(|k| doc.resolve(k)).and_then(|k| k.as_array().cloned()).unwrap_or_default(); + for k in kids.iter().filter_map(Object::as_ref).rev() { + stack.push(k); + } + } + for r in items { + let Some(mut d) = doc.get(r).as_dict().cloned() else { + continue; + }; + let mut changed = false; + if let Some(dest) = d.get(b"Dest") { + let mut seen = HashSet::new(); + if let Some(new) = remap_dest(doc, dest, &map, &mut seen)? { + d.set(b"Dest".to_vec(), new); + changed = true; + } + } + if let Some(a) = d.get(b"A") { + let mut seen = HashSet::new(); + if let Some(new) = remap_action(doc, a, &map, &mut seen)? { + d.set(b"A".to_vec(), new); + changed = true; + } + } + if changed { + doc.set(r, Object::Dict(d)); + } + } + } + // /Names: the Dests and Pages categories, a tree each: the Dests one's values are + // destinations, the Pages one's are page references. + let names_at = catalog.get(b"Names").and_then(Object::as_ref); + if let Some(mut names) = catalog.get(b"Names").map(|o| doc.resolve(o)).and_then(|o| o.as_dict().cloned()) { + let mut updates: Vec<(Vec, Object)> = Vec::new(); + for (cat, node) in names.iter() { + let pages = cat.as_slice() == b"Pages"; + if cat.as_slice() == b"Dests" || pages { + let mut seen = HashSet::new(); + if let Some(new) = remap_name_tree(doc, node, &map, &mut seen, pages)? { + updates.push((cat.clone(), new)); + } + } + } + if !updates.is_empty() { + for (cat, new) in updates { + names.set(cat, new); + } + match names_at { + Some(r) => doc.set(r, Object::Dict(names)), + None => { + catalog.set(b"Names".to_vec(), Object::Dict(names)); + catalog_changed = true; + } + } + } + } + Ok(catalog_changed) +} + +/// Remap the page a destination value names through `map`: an array whose first element +/// names a page, a dictionary with `/D`, or an indirect reference to either. An indirect one +/// is updated where it is, so nothing comes back for the caller to put back. A string is a +/// name in the document's `/Dests` (remapped there first), so it is left alone. `seen` +/// holds the references this value's `/D` chain has followed: a repeat is a cycle, an error. +fn remap_dest(doc: &mut Document, v: &Object, map: &HashMap, seen: &mut HashSet) -> Result, XfaError> { + match v { + Object::Array(a) => { + let mut a = a.clone(); + let changed = a.first().and_then(Object::as_ref).and_then(|r| map.get(&r)).is_some_and(|t| { + a[0] = Object::Ref(*t); + true + }); + Ok(changed.then_some(Object::Array(a))) + } + Object::Dict(d) => { + let Some(dest) = d.get(b"D") else { + return Ok(None); + }; + let Some(new) = remap_dest(doc, dest, map, seen)? else { + return Ok(None); + }; + let mut d = d.clone(); + d.set(b"D".to_vec(), new); + Ok(Some(Object::Dict(d))) + } + Object::Ref(r) => { + if !seen.insert(*r) { + return Err(XfaError::Malformed("a destination's /D chain is cyclic".into())); + } + let resolved = doc.resolve(v); + match &*resolved { + Object::Array(_) | Object::Dict(_) => { + if let Some(new) = remap_dest(doc, &resolved, map, seen)? { + doc.set(*r, new); + } + } + _ => {} + } + Ok(None) + } + _ => Ok(None), + } +} + +/// Remap the page a `/Pages` name tree value names through `map`: it is a page reference, +/// remapped where it is. +fn remap_page_ref(v: &Object, map: &HashMap) -> Option { + v.as_ref().and_then(|r| map.get(&r)).map(|t| Object::Ref(*t)) +} + +/// Remap the `/D` of a `GoTo` action through `map`; an indirect action is updated where it +/// is, so nothing comes back for the caller to put back. +fn remap_action(doc: &mut Document, a: &Object, map: &HashMap, seen: &mut HashSet) -> Result, XfaError> { + let resolved = doc.resolve(a); + let Some(d) = resolved.as_dict() else { + return Ok(None); + }; + let mut d = d.clone(); + if d.name(b"S") != Some(b"GoTo") { + return Ok(None); + } + let Some(dest) = d.get(b"D") else { + return Ok(None); + }; + let Some(new) = remap_dest(doc, dest, map, seen)? else { + return Ok(None); + }; + d.set(b"D".to_vec(), new); + match a.as_ref() { + Some(r) => { + doc.set(r, Object::Dict(d)); + Ok(None) + } + None => Ok(Some(Object::Dict(d))), + } +} + +/// Remap the values in a name tree node through `map` (destinations, or page references +/// where `pages`); an indirect node is updated where it is, so nothing comes back for the +/// caller to put back. A direct one comes back for the caller (the `/Names` dictionary) to +/// put back. `seen` holds the nodes this walk has reached: a repeat is a `/Kids` cycle, an +/// error. +fn remap_name_tree( + doc: &mut Document, + node: &Object, + map: &HashMap, + seen: &mut HashSet, + pages: bool, +) -> Result, XfaError> { + if let Some(r) = node.as_ref() + && !seen.insert(r) + { + return Err(XfaError::Malformed("a name tree's /Kids chain is cyclic".into())); + } + let resolved = doc.resolve(node); + let Some(d) = resolved.as_dict() else { + return Ok(None); + }; + let mut d = d.clone(); + let mut changed = false; + if let Some(names) = d.get(b"Names").map(|n| doc.resolve(n)).and_then(|n| n.as_array().cloned()) { + let mut names = names; + for i in (0..names.len() / 2 * 2).step_by(2) { + if let Some(v) = names.get(i + 1) { + let new = if pages { + remap_page_ref(v, map) + } else { + let mut value_seen = HashSet::new(); + remap_dest(doc, v, map, &mut value_seen)? + }; + if let Some(new) = new { + names[i + 1] = new; + changed = true; + } + } + } + if changed { + match d.get(b"Names").and_then(Object::as_ref) { + Some(r) => doc.set(r, Object::Array(names)), + None => d.set(b"Names".to_vec(), Object::Array(names)), + } + } + } + if let Some(kids) = d.get(b"Kids").map(|k| doc.resolve(k)).and_then(|k| k.as_array().cloned()) { + let mut kids = kids; + let mut kids_changed = false; + for k in kids.iter_mut() { + if let Some(new) = remap_name_tree(doc, k, map, seen, pages)? { + *k = new; + kids_changed = true; + } + } + if kids_changed { + match d.get(b"Kids").and_then(Object::as_ref) { + Some(r) => doc.set(r, Object::Array(kids)), + None => d.set(b"Kids".to_vec(), Object::Array(kids)), + } + changed = true; + } + } + if !changed { + return Ok(None); + } + match node.as_ref() { + Some(r) => { + doc.set(r, Object::Dict(d)); + Ok(None) + } + None => Ok(Some(Object::Dict(d))), + } +} + /// Add the screen-only and print-only `groups` this layout drew in (`used`) to the document's /// optional content properties, keeping its own layers as they are: each goes in `/OCGs`; in the /// default configuration the print-only one starts off (the screen-only one starts on when the @@ -1547,4 +1882,277 @@ mod tests { assert_eq!(em.doc.object_numbers().len(), before, "no new object for a repeated picture"); assert_eq!(em.image_xobject(&picture(last), "image/png"), Some(again)); } + + /// A document with `pages` page objects (empty dictionaries) under one `/Pages` node, + /// which also lists itself when `cyclic`. + fn page_tree(doc: &mut Document, pages: usize, cyclic: bool) -> ObjRef { + let mut kids = (0..pages).map(|_| Object::Ref(doc.add(Object::Dict(Dict::new())))).collect::>(); + let node = doc.add(Object::Null); + if cyclic { + kids.push(Object::Ref(node)); + } + let mut d = Dict::new(); + d.set(b"Type".to_vec(), Object::name("Pages")); + d.set(b"Kids".to_vec(), Object::Array(kids)); + doc.set(node, Object::Dict(d)); + node + } + + #[test] + fn a_cyclic_page_tree_terminates_with_an_error() { + // #9027: a `/Pages` node that lists itself walked forever; the search now stops with + // an error, before any destination is remapped. + let mut doc = Document::new_empty(); + let pages = page_tree(&mut doc, 1, true); + let err = page_list(&doc, pages).unwrap_err(); + assert!(matches!(err, XfaError::Malformed(_)), "{err:?}"); + } + + #[test] + fn a_page_tree_past_the_search_limit_errors_before_replacement() { + // A destination naming a page the search omits would keep a stale reference; the + // search errors instead, and exactly the bound is still walked. + let mut doc = Document::new_empty(); + let pages = page_tree(&mut doc, MAX_PAGES_SEARCHED + 1, false); + let err = page_list(&doc, pages).unwrap_err(); + assert!(matches!(err, XfaError::TooLarge(_)), "{err:?}"); + let mut doc = Document::new_empty(); + let pages = page_tree(&mut doc, MAX_PAGES_SEARCHED, false); + assert_eq!(page_list(&doc, pages).unwrap().len(), MAX_PAGES_SEARCHED); + } + + /// A document whose catalog's `/Dests` entry `cyc` is a dictionary whose `/D` is itself. + fn cyclic_dests(doc: &mut Document) -> Dict { + let dest = doc.add(Object::Null); + let mut d = Dict::new(); + d.set(b"D".to_vec(), Object::Ref(dest)); + doc.set(dest, Object::Dict(d)); + let mut dests = Dict::new(); + dests.set(b"cyc".to_vec(), Object::Ref(dest)); + let mut catalog = Dict::new(); + catalog.set(b"Dests".to_vec(), Object::Dict(dests)); + catalog + } + + #[test] + fn a_cyclic_destination_terminates_with_an_error() { + // #9027: a destination whose `/D` chain is a cycle walked forever; the remap now + // stops with an error, before any destination is replaced. + let mut doc = Document::new_empty(); + let old = doc.add(Object::Dict(Dict::new())); + let new = doc.add(Object::Dict(Dict::new())); + let mut catalog = cyclic_dests(&mut doc); + let err = remap_destinations(&mut doc, &mut catalog, &[old], &[new]).unwrap_err(); + assert!(matches!(err, XfaError::Malformed(_)), "{err:?}"); + } + + /// A document whose catalog's `/Names` `Dests` tree is a node whose `/Kids` is itself. + fn cyclic_name_tree(doc: &mut Document, value: Object) -> Dict { + let node = doc.add(Object::Null); + let mut d = Dict::new(); + d.set(b"Names".to_vec(), Object::Array(vec![Object::String(PdfString::literal("end")), value])); + d.set(b"Kids".to_vec(), Object::Array(vec![Object::Ref(node)])); + doc.set(node, Object::Dict(d)); + let mut names = Dict::new(); + names.set(b"Dests".to_vec(), Object::Ref(node)); + let mut catalog = Dict::new(); + catalog.set(b"Names".to_vec(), Object::Dict(names)); + catalog + } + + #[test] + fn a_cyclic_name_tree_terminates_with_an_error() { + // #9027: a name tree whose `/Kids` is a cycle walked forever; the remap now stops + // with an error, before any destination is replaced. + let mut doc = Document::new_empty(); + let old = doc.add(Object::Dict(Dict::new())); + let new = doc.add(Object::Dict(Dict::new())); + let mut catalog = cyclic_name_tree(&mut doc, Object::Ref(old)); + let err = remap_destinations(&mut doc, &mut catalog, &[old], &[new]).unwrap_err(); + assert!(matches!(err, XfaError::Malformed(_)), "{err:?}"); + } + + /// A document whose catalog's `/Outlines` is a `/Next` chain of `count` items. + fn bookmark_chain(doc: &mut Document, count: usize) -> Dict { + let items: Vec = (0..count).map(|_| doc.add(Object::Dict(Dict::new()))).collect(); + for (a, b) in items.iter().zip(items.iter().skip(1)) { + let mut d = doc.get(*a).as_dict().cloned().unwrap(); + d.set(b"Next".to_vec(), Object::Ref(*b)); + doc.set(*a, Object::Dict(d)); + } + let mut outlines = Dict::new(); + outlines.set(b"First".to_vec(), Object::Ref(items[0])); + let mut catalog = Dict::new(); + catalog.set(b"Outlines".to_vec(), Object::Dict(outlines)); + catalog + } + + #[test] + fn a_bookmark_list_past_the_search_limit_errors_before_replacement() { + // A bookmark the search omits would not be remapped; the search errors instead, and + // exactly the bound is still walked. + let mut doc = Document::new_empty(); + let old = doc.add(Object::Dict(Dict::new())); + let new = doc.add(Object::Dict(Dict::new())); + let mut catalog = bookmark_chain(&mut doc, MAX_PAGES_SEARCHED + 1); + let err = remap_destinations(&mut doc, &mut catalog, &[old], &[new]).unwrap_err(); + assert!(matches!(err, XfaError::TooLarge(_)), "{err:?}"); + let mut doc = Document::new_empty(); + let old = doc.add(Object::Dict(Dict::new())); + let new = doc.add(Object::Dict(Dict::new())); + let mut catalog = bookmark_chain(&mut doc, MAX_PAGES_SEARCHED); + assert!(!remap_destinations(&mut doc, &mut catalog, &[old], &[new]).unwrap()); + } + + #[test] + fn an_outline_item_reaches_its_first_child() { + // #9027: a child is the parent's /First (the spec's way); the walk follows it, so + // the child's destination is remapped too. + let mut doc = Document::new_empty(); + let old = doc.add(Object::Dict(Dict::new())); + let new = doc.add(Object::Dict(Dict::new())); + let child = doc.add({ + let mut d = Dict::new(); + d.set(b"Dest".to_vec(), Object::Array(vec![Object::Ref(old), Object::name("Fit")])); + d + }); + let parent = doc.add({ + let mut d = Dict::new(); + d.set(b"First".to_vec(), Object::Ref(child)); + d + }); + let mut catalog = Dict::new(); + let mut outlines = Dict::new(); + outlines.set(b"First".to_vec(), Object::Ref(parent)); + catalog.set(b"Outlines".to_vec(), Object::Dict(outlines)); + remap_destinations(&mut doc, &mut catalog, &[old], &[new]).unwrap(); + let obj = doc.get(child); + let dest = obj.as_dict().unwrap().get(b"Dest").unwrap(); + assert_eq!(dest.as_array().unwrap().first().and_then(Object::as_ref), Some(new), "the child's destination follows the page"); + } + + #[test] + fn a_pages_name_tree_entry_points_at_the_replacement() { + // #9027: a `/Pages` name tree value is a page reference, not a destination; it is + // remapped through the map directly. + let mut doc = Document::new_empty(); + let old = doc.add(Object::Dict(Dict::new())); + let new = doc.add(Object::Dict(Dict::new())); + let names = doc.add(Object::Array(vec![Object::String(PdfString::literal("end")), Object::Ref(old)])); + let node = doc.add({ + let mut d = Dict::new(); + d.set(b"Names".to_vec(), Object::Ref(names)); + d + }); + let mut catalog = Dict::new(); + let mut names_cat = Dict::new(); + names_cat.set(b"Pages".to_vec(), Object::Ref(node)); + catalog.set(b"Names".to_vec(), Object::Dict(names_cat)); + remap_destinations(&mut doc, &mut catalog, &[old], &[new]).unwrap(); + let obj = doc.get(names); + let arr = obj.as_array().unwrap(); + assert_eq!(arr.get(1).and_then(Object::as_ref), Some(new), "the /Pages entry follows the page"); + } + + /// `old_n` old pages mapped onto `new_n` new ones, each old page named by a bookmark, a + /// `/Dests` entry and a `/Names` `Dests` entry; returns the page each of the three ended up on. + fn remap_every_kind(old_n: usize, new_n: usize) -> (Vec, Vec<[Option; 3]>) { + let mut doc = Document::new_empty(); + let old: Vec = (0..old_n).map(|_| doc.add(Object::Dict(Dict::new()))).collect(); + let new: Vec = (0..new_n).map(|_| doc.add(Object::Dict(Dict::new()))).collect(); + let dest = |page: ObjRef| Object::Array(vec![Object::Ref(page), Object::name("Fit")]); + let items: Vec = old + .iter() + .map(|o| { + let mut d = Dict::new(); + d.set(b"Dest".to_vec(), dest(*o)); + doc.add(Object::Dict(d)) + }) + .collect(); + for (a, b) in items.iter().zip(items.iter().skip(1)) { + let mut d = doc.get(*a).as_dict().cloned().unwrap(); + d.set(b"Next".to_vec(), Object::Ref(*b)); + doc.set(*a, Object::Dict(d)); + } + let mut outlines = Dict::new(); + outlines.set(b"First".to_vec(), Object::Ref(items[0])); + let mut dests = Dict::new(); + let mut names = Vec::new(); + for (i, o) in old.iter().enumerate() { + dests.set(format!("d{i}").into_bytes(), dest(*o)); + names.push(Object::String(PdfString::literal(format!("n{i}")))); + names.push(dest(*o)); + } + let mut tree = Dict::new(); + tree.set(b"Names".to_vec(), Object::Array(names)); + let mut names_cat = Dict::new(); + names_cat.set(b"Dests".to_vec(), Object::Dict(tree)); + let mut catalog = Dict::new(); + catalog.set(b"Outlines".to_vec(), Object::Dict(outlines)); + catalog.set(b"Dests".to_vec(), Object::Dict(dests)); + catalog.set(b"Names".to_vec(), Object::Dict(names_cat)); + remap_destinations(&mut doc, &mut catalog, &old, &new).unwrap(); + let first = |o: &Object| o.as_array().and_then(|a| a.first()).and_then(Object::as_ref); + let got = (0..old_n) + .map(|i| { + let bookmark = doc.get(items[i]).as_dict().and_then(|d| d.get(b"Dest")).and_then(first); + let named = catalog.get(b"Dests").and_then(Object::as_dict).and_then(|d| d.get(format!("d{i}").as_bytes())).and_then(first); + let tree = catalog.get(b"Names").and_then(Object::as_dict).and_then(|d| d.get(b"Dests")).and_then(Object::as_dict); + let in_tree = tree.and_then(|t| t.get(b"Names")).and_then(Object::as_array).and_then(|a| a.get(i * 2 + 1)).and_then(first); + [bookmark, named, in_tree] + }) + .collect(); + (new, got) + } + + #[test] + fn a_shrinking_layout_sends_the_dropped_pages_destinations_to_the_last_page() { + // #9027: 3 old pages, 2 new: page 0 and 1 follow by position, and page 2 (dropped) + // lands on the last new page, for a bookmark, a /Dests entry and a /Names entry alike. + let (new, got) = remap_every_kind(3, 2); + assert_eq!(got[0], [Some(new[0]); 3]); + assert_eq!(got[1], [Some(new[1]); 3]); + assert_eq!(got[2], [Some(new[1]); 3]); + } + + #[test] + fn a_growing_layout_keeps_each_destination_on_its_own_position() { + // #9027: 2 old pages, 3 new: each follows its position; the extra new page is unnamed. + let (new, got) = remap_every_kind(2, 3); + assert_eq!(got[0], [Some(new[0]); 3]); + assert_eq!(got[1], [Some(new[1]); 3]); + } + + #[test] + fn a_page_tree_of_exactly_the_bound_then_an_empty_node_is_still_walked() { + // The bound counts pages accepted, not nodes popped: an empty /Pages node after a + // full tree is not a page. + let mut doc = Document::new_empty(); + let full = page_tree(&mut doc, MAX_PAGES_SEARCHED, false); + let empty = page_tree(&mut doc, 0, false); + let mut root = Dict::new(); + root.set(b"Type".to_vec(), Object::name("Pages")); + root.set(b"Kids".to_vec(), Object::Array(vec![Object::Ref(full), Object::Ref(empty)])); + let root = doc.add(Object::Dict(root)); + assert_eq!(page_list(&doc, root).unwrap().len(), MAX_PAGES_SEARCHED); + } + + #[test] + fn a_bookmark_listed_twice_at_the_bound_is_not_a_new_item() { + // The item bound is for distinct items: with exactly the bound of them, the first + // named again by the last item's /Kids is a repeat and does not make the list too large. + let mut doc = Document::new_empty(); + let old = doc.add(Object::Dict(Dict::new())); + let new = doc.add(Object::Dict(Dict::new())); + let mut catalog = bookmark_chain(&mut doc, MAX_PAGES_SEARCHED); + let first = catalog.get(b"Outlines").and_then(Object::as_dict).and_then(|o| o.get(b"First")).and_then(Object::as_ref).unwrap(); + let mut last = first; + while let Some(next) = doc.get(last).as_dict().and_then(|d| d.get(b"Next")).and_then(Object::as_ref) { + last = next; + } + let mut d = doc.get(last).as_dict().cloned().unwrap(); + d.set(b"Kids".to_vec(), Object::Array(vec![Object::Ref(first)])); + doc.set(last, Object::Dict(d)); + assert!(remap_destinations(&mut doc, &mut catalog, &[old], &[new]).is_ok()); + } } From 55bb74cd1adb36f01463cb285eb5d194c58ab6e8 Mon Sep 17 00:00:00 2001 From: Siguret Audric <65806455+Audr1c@users.noreply.github.com> Date: Fri, 4 Dec 2026 16:12:48 +0100 Subject: [PATCH 4/8] Scale Wayland touchpad scrolling with the scroll speed preference (#8870) * Scale Wayland touchpad scrolling with the scroll speed preference Co-authored-by: Leonid Co-Authored-By: Claude Opus 5.5 * Expect the touchpad gain in the held point-scroll test The Linux touchpad gain (#1904) scales a point wheel delta once, in the runtime, so a 30-point delta moves the page 90 points at Normal speed there. selection_point_scroll_is_not_applied_twice compared the held-drag motion with the raw 30; compare it with 30 times the gain instead, which still fails if the held drag scales the delta a second time. Co-Authored-By: Claude Sonnet 5.5 --------- Co-authored-by: Audr1c Co-authored-by: Leonid Co-authored-by: Claude Opus 5.5 Co-authored-by: FredApps --- crates/ui-egui/src/app.rs | 6 ++++-- crates/ui-egui/src/canvas/scroll_speed.rs | 17 +++++++++++++++++ crates/ui-egui/tests/it/viewer.rs | 14 +++++++++++--- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index 83411900e4..4c1808d8cb 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -20,7 +20,7 @@ use craft::platform::autosave::Autosave; use craft::platform::autosave::RecoveryStore; use craft::platform::clipboard::Clipboard; use craft::platform::open::FileIntake; -use craft::ui::runtime::env::{RootEnv, Scale}; +use craft::ui::runtime::env::{RootEnv, Scale, WheelSpeed}; #[cfg(not(target_arch = "wasm32"))] use craft::ui::shell::embed; @@ -593,7 +593,9 @@ impl PdfCraftApp { .mode(self.theme_preference) .density(craft::theme::Size::Comfortable) .direction(direction) - .scale(Scale::new(crate::ui_scale::zoom(self.ui_scale, system, native))); + .scale(Scale::new(crate::ui_scale::zoom(self.ui_scale, system, native))) + // Wheel notches scale through the canvas's wheel line; touchpad points through this gain (#1904). + .wheel_speed(WheelSpeed::new(1.0, self.scroll_speed.touchpad_gain())); if let Ok(theme) = craft::theme::ThemeId::parse("craft.graphite") { root.set_theme(theme); } diff --git a/crates/ui-egui/src/canvas/scroll_speed.rs b/crates/ui-egui/src/canvas/scroll_speed.rs index 02d26389ac..2ebe5780a2 100644 --- a/crates/ui-egui/src/canvas/scroll_speed.rs +++ b/crates/ui-egui/src/canvas/scroll_speed.rs @@ -4,6 +4,12 @@ //! but on Windows and Linux winit reports one line per notch, where browsers scroll about //! 100 pixels, so the desktop default is larger than a text line. The canvas reads the two //! distances through its navigation options. +//! +//! Touchpad motion reported in points scrolls as the system sends it, except on Linux (#1904): a +//! Wayland compositor sends the raw finger distance, which winit passes on 1:1, where X11 sends the +//! same swipe as wheel lines that the wheel line scales. The Wayland window then crawled, and the +//! preference did nothing for it. There the motion gets a gain that follows the same choice, through +//! the runtime's wheel speed, which leaves ⌘/Ctrl zooming alone. /// The user's choice, relative to the platform's normal speed. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] @@ -28,6 +34,11 @@ const NORMAL_LINE_POINTS: f32 = if cfg!(target_arch = "wasm32") { /// Points one arrow-key step scrolls at Normal speed. const KEY_LINE_POINTS: f32 = 40.0; +/// What touchpad motion reported in points is multiplied by at Normal speed. Windows and macOS +/// already deliver touchpad deltas that feel right; Linux under Wayland sends the raw finger +/// distance. +const NORMAL_TOUCHPAD_GAIN: f32 = if cfg!(target_os = "linux") { 3.0 } else { 1.0 }; + impl ScrollSpeed { pub const ALL: [Self; 3] = [Self::Slow, Self::Normal, Self::Fast]; @@ -58,6 +69,12 @@ impl ScrollSpeed { KEY_LINE_POINTS * self.factor() } + /// What touchpad motion reported in points is multiplied by: 1 everywhere but Linux, where it + /// follows the choice. + pub fn touchpad_gain(self) -> f32 { + if cfg!(target_os = "linux") { NORMAL_TOUCHPAD_GAIN * self.factor() } else { 1.0 } + } + pub fn parse(value: &str) -> Option { Self::ALL.into_iter().find(|s| s.label().eq_ignore_ascii_case(value)) } diff --git a/crates/ui-egui/tests/it/viewer.rs b/crates/ui-egui/tests/it/viewer.rs index 32863aa52b..7483a65f96 100644 --- a/crates/ui-egui/tests/it/viewer.rs +++ b/crates/ui-egui/tests/it/viewer.rs @@ -2339,8 +2339,14 @@ fn the_scroll_speed_preference_scales_mouse_wheel_notches() { let (slow, fast) = (scrolled(ScrollSpeed::Slow, line, 1.0), scrolled(ScrollSpeed::Fast, line, 1.0)); assert!((slow * 2.0 - normal).abs() < 1.0 && (fast - normal * 2.0).abs() < 1.0, "slow {slow}, normal {normal}, fast {fast}"); let point = egui::MouseWheelUnit::Point; - let (normal_points, fast_points) = (scrolled(ScrollSpeed::Normal, point, 30.0), scrolled(ScrollSpeed::Fast, point, 30.0)); - assert!(normal_points > 0.0 && (normal_points - fast_points).abs() < 1.0, "trackpad: {normal_points} vs {fast_points}"); + let (slow_points, fast_points) = (scrolled(ScrollSpeed::Slow, point, 30.0), scrolled(ScrollSpeed::Fast, point, 30.0)); + assert!(slow_points > 0.0, "trackpad: {slow_points}"); + // Linux touchpads (Wayland's raw finger distance) follow the choice (#1904); elsewhere the system's deltas stand. + if cfg!(target_os = "linux") { + assert!(fast_points > slow_points * 2.0, "trackpad: slow {slow_points}, fast {fast_points}"); + } else { + assert!((slow_points - fast_points).abs() < 1.0, "trackpad: slow {slow_points}, fast {fast_points}"); + } let mut app = crate::control::new_app(); app.set_option(&egui::Context::default(), "scroll_speed", "fast").unwrap(); assert!(app.set_option(&egui::Context::default(), "scroll_speed", "warp").unwrap_err().contains("slow, normal, or fast")); @@ -2730,7 +2736,9 @@ fn selection_point_scroll_is_not_applied_twice() { let held = selection_wheel_delta(egui::MouseWheelUnit::Point, 30.0, true, animated); eprintln!("Point animated={animated}: released={normal}, held={held}"); assert!(normal > 1.0, "point wheel must scroll: {normal}"); - assert!((held - 30.0).abs() < 1.0, "animated={animated}: held precision motion={held}, normal={normal}"); + // The touchpad gain (Linux, #1904) scales the delta once, in the runtime; the held drag must not scale it again. + let expected = 30.0 * pdfcraft_ui_egui::scroll_speed::ScrollSpeed::default().touchpad_gain(); + assert!((held - expected).abs() < 1.0, "animated={animated}: held precision motion={held}, expected={expected}, normal={normal}"); } } From 2845f072fb20dbe8bd5345b59379d3f80831fa47 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Fri, 4 Dec 2026 16:12:56 +0100 Subject: [PATCH 5/8] fix(windows): keep the integrated title bar's window borderless (#8845, #8793, #9040) (#9297) winit 0.30 gives an undecorated window WS_CAPTION | WS_BORDER. On some Windows systems the compositor still reserves that frame, so the content is drawn below a black bar while the pointer keeps the client coordinates, and a click lands above the control. PhotoCraft, VectorCraft, FigCraft and DesignCraft fixed the same symptom by stripping WS_CAPTION/WS_BORDER and having Windows recalculate the frame; winit puts them back on every flag change, so the guard runs once per frame and only reads the style once they are gone. WS_THICKFRAME stays, so edge resizing and snap keep working. Only the integrated (undecorated) title bar is guarded; the system title bar is untouched. Ports storytold/photocraft#2401. Not yet verified on affected hardware. Co-authored-by: FredApps Co-authored-by: Claude Sonnet 5.5 --- apps/pdfcraft/src/main.rs | 10 ++++ apps/pdfcraft/src/window_frame.rs | 86 +++++++++++++++++++++++++++++++ crates/ui-egui/src/app.rs | 2 + crates/ui-egui/src/app/frame.rs | 6 +++ crates/ui-egui/src/lib.rs | 4 ++ 5 files changed, 108 insertions(+) create mode 100644 apps/pdfcraft/src/window_frame.rs diff --git a/apps/pdfcraft/src/main.rs b/apps/pdfcraft/src/main.rs index 1f5e859ba4..cd68d32977 100644 --- a/apps/pdfcraft/src/main.rs +++ b/apps/pdfcraft/src/main.rs @@ -52,6 +52,8 @@ mod reopen; mod single_instance; mod startup; #[cfg(target_os = "windows")] +mod window_frame; +#[cfg(target_os = "windows")] mod window_placement; #[cfg(test)] #[path = "windows_manifest.rs"] @@ -640,6 +642,9 @@ fn app_creator<'a>( #[cfg(target_os = "macos")] apple_events: &'a apple_events::AppleEvents, ) -> eframe::AppCreator<'a> { let Launch { startup_time, files, options, control, create_images, combine, frame, lang, two_paged, nightly_watch } = launch; + // Whether the app's own bar is the title bar, so the window is undecorated. + #[cfg(target_os = "windows")] + let integrated = !matches!(frame.frame, craft::window::policy::Frame::Native); Box::new(move |cc| { started.set(true); startup_stage(startup_time, "renderer ready, installing fonts and runtime"); @@ -688,6 +693,11 @@ fn app_creator<'a>( window_placement::save(&window, storage); } })); + // The undecorated window must stay borderless, or the caption and border the toolkit gives it + // offset the drawn content from the pointer on some systems (#8845, #8793). + if integrated { + app.window_frame = window_frame::guard(window); + } set_taskbar_icon(window); } app.set_startup_update_check(!is_nightly()); diff --git a/apps/pdfcraft/src/window_frame.rs b/apps/pdfcraft/src/window_frame.rs new file mode 100644 index 0000000000..44d68c9e22 --- /dev/null +++ b/apps/pdfcraft/src/window_frame.rs @@ -0,0 +1,86 @@ +//! Keeps the custom (integrated) title bar's undecorated window truly borderless on Windows +//! (#8845, #8793, #9040). +//! +//! winit 0.30 gives an undecorated window the `WS_CAPTION | WS_BORDER` styles and hides the +//! non-client area by spreading the client rect over it (`WM_NCCALCSIZE`). On some systems the +//! desktop compositor still reserves that frame for the window surface: the content is drawn +//! offset by the caption and border, leaving a black bar at the top, while the pointer keeps the +//! un-offset client coordinates, so a click lands above the control that is drawn under it. +//! +//! PhotoCraft (storytold/photocraft#2401, #2246), VectorCraft, FigCraft and DesignCraft fixed the +//! same symptom the same way: strip `WS_CAPTION`/`WS_BORDER` and have Windows recalculate the +//! frame. winit puts the styles back whenever it changes the window flags (maximize, restore, +//! ...), so the guard runs every frame; once they are gone it only reads the style. +//! +//! The Windows calls go through safe `winsafe` wrappers; the workspace forbids `unsafe`, and +//! winsafe cannot wrap a raw handle without it, so the window is found among the UI thread's +//! windows by its handle, as `window_placement` does. + +use std::sync::Weak; + +use winit::raw_window_handle::{HasWindowHandle as _, RawWindowHandle}; +use winsafe::{HWND, HwndPlace, POINT, SIZE, co}; + +/// A guard that keeps `window` borderless; call it once per frame on the UI thread. `None` when +/// the window's handle is not a Win32 one. +pub(super) fn guard(window: &std::sync::Arc) -> Option> { + let RawWindowHandle::Win32(raw) = window.window_handle().ok()?.as_raw() else { return None }; + let target = raw.hwnd.get(); + let root: Weak = std::sync::Arc::downgrade(window); + let guard = move || { + // The window is gone once the app is closing. + if root.upgrade().is_none() { + return; + } + let _ = winsafe::EnumThreadWindows(winsafe::GetCurrentThreadId(), |hwnd| { + if hwnd.ptr() as isize == target { + strip(&hwnd); + } + true + }); + }; + guard(); + Some(Box::new(guard)) +} + +/// Removes `WS_CAPTION`/`WS_BORDER` and has Windows recalculate the frame. A no-op once they are +/// gone, so it is cheap to call every frame. +fn strip(hwnd: &HWND) { + let style = hwnd.style(); + let without = borderless(style); + if without.raw() == style.raw() { + return; + } + hwnd.set_style(without); + let _ = hwnd.SetWindowPos( + HwndPlace::None, + POINT::new(), + SIZE::new(), + co::SWP::FRAMECHANGED | co::SWP::NOMOVE | co::SWP::NOSIZE | co::SWP::NOZORDER | co::SWP::NOACTIVATE, + ); +} + +/// `style` without the OS title bar and frame (`WS_CAPTION`, which already includes `WS_BORDER`). +/// The sizing border (`WS_THICKFRAME`) stays, so edge resizing and Aero snap keep working. +fn borderless(style: co::WS) -> co::WS { + style & !(co::WS::CAPTION | co::WS::BORDER) +} + +#[cfg(test)] +mod tests { + use super::borderless; + use winsafe::co; + + #[test] + fn the_borderless_style_drops_the_caption_and_border_only() { + // `WS_CAPTION` is 0x00c0_0000 and already contains `WS_BORDER` (0x0080_0000). + let decorated = co::WS::CAPTION | co::WS::BORDER | co::WS::SYSMENU | co::WS::THICKFRAME | co::WS::MAXIMIZEBOX | co::WS::MINIMIZEBOX; + let bare = borderless(decorated); + assert!(!bare.has(co::WS::CAPTION), "caption gone"); + assert!(!bare.has(co::WS::BORDER), "border gone"); + assert!(bare.has(co::WS::THICKFRAME), "edge resizing kept"); + assert!(bare.has(co::WS::MAXIMIZEBOX) && bare.has(co::WS::SYSMENU), "window buttons kept"); + // Already borderless: unchanged, so the per-frame call does nothing. + assert_eq!(bare.raw(), borderless(bare).raw()); + } +} diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index 4c1808d8cb..b119e391d7 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -377,6 +377,8 @@ impl PdfCraftApp { at_exit: None, #[cfg(target_os = "windows")] save_window_placement: None, + #[cfg(target_os = "windows")] + window_frame: None, startup_time: None, show_secured_notice: true, text_links: true, diff --git a/crates/ui-egui/src/app/frame.rs b/crates/ui-egui/src/app/frame.rs index a88a10c2a1..6d43665c62 100644 --- a/crates/ui-egui/src/app/frame.rs +++ b/crates/ui-egui/src/app/frame.rs @@ -9,6 +9,12 @@ impl PdfCraftApp { /// command states and host. eframe calls the hook once per frame, before the first pass, so /// a second pass of the same frame runs on what this call set and fires nothing twice. pub(super) fn prepare_raw_input(&mut self, ctx: &egui::Context, _raw: &mut egui::RawInput) { + // The toolkit gives the undecorated window its caption back whenever it changes the window's flags (maximize, + // restore, ...): take it off again before the frame is laid out. + #[cfg(target_os = "windows")] + if let Some(window_frame) = self.window_frame.as_mut() { + window_frame(); + } // Preferences and the control channel only change `title_bar_choice`; the window follows on the // next frame. Asking the policy again when nothing changed would re-read the platform each frame. if self.applied_title_bar != Some(self.title_bar_choice) { diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 9819c53597..f7eb738d3e 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -464,6 +464,10 @@ pub struct PdfCraftApp { /// Preserve the normal Win32 placement if eframe saved a minimized window. #[cfg(target_os = "windows")] pub save_window_placement: Option>, + /// Keeps the undecorated window's OS frame from offsetting its content and pointer (Windows, + /// integrated title bar). Called once per frame, before the frame's input is read. + #[cfg(target_os = "windows")] + pub window_frame: Option>, /// Native launch time, consumed after the first UI pass for startup diagnostics. pub startup_time: Option, /// Preferences: tell the user, above the pages, that a document is secured (its security From 67e328876975a7e7f8b86f674817efc68e476df0 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Fri, 4 Dec 2026 16:13:04 +0100 Subject: [PATCH 6/8] Port release fixes to main: reader-web (#9306) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Return keyboard to reader on blank page view click (cherry picked from commit b12d744c3a23d19b0b2d4b417cf68fd0028dcf5d) * Check field draft survives background focus handoff (cherry picked from commit 82abf52b1a34b886f442ee93b3310ebf34b79da9) * Preserve the OCR text drag anchor over a scanned page (cherry picked from commit a28bdd3db1fd5723736b038a16bf7ac13795baf6) (cherry picked from commit bbb0c61a1c3051c62e8788b27291bc4ff0972966) * Restore saves to the embedding web page (cherry picked from commit 24702af7e6a9afa9801283c813514b51b11fe032) * Keep host copy saves from marking the open document saved (cherry picked from commit 2624b9b9d2c2eafaa5c1ec07db8ec3d026bb2799) * Use pinned APIs in Space Audit and host save checks Port of the host save test half only; the Space Audit half is covered by another open PR. (cherry picked from commit bbde94e74387648ca11ccaac6ebc3220e4c0e1cf) * Read the browser clock when painting comment and file timestamps (cherry picked from commit cbda2fd3ffc1a0e3955301c9c3f0e498898572b0) (cherry picked from commit c5984569d183504f8051371f62515e354acc3868) * Web: give the document session a browser wall clock (#8957) (cherry picked from commit b90c6de6e0d696c11484d0f12d0728ba84c667f1) * Test organize thumbnails after moving a page (cherry picked from commit 0230ac0fc752d3f86e26e81fea2e8de70a8d03a0) * Test organize deletion of selected and tile pages (cherry picked from commit 9a12b9b1fb4853c1f1d90a77865ea8e6c74e17f8) * feat(view): rulers along the page area (view.rulers) View ▸ Show/Hide ▸ Rulers (Ctrl+R / ⌘R) reserves a strip along the top and left of the document area and draws rulers in the measurement units preference, from the top-left of the page under the pointer (or the current page) in its displayed orientation. Major ticks use the 1/2/5 interval that keeps labels apart at the current zoom, the tick count is capped, and a marker follows the pointer. The choice persists, and the control channel takes `rulers=on|off` and reports `rulers`. Co-Authored-By: Claude Opus 5.5 (cherry picked from commit c8a854134f963c6373865313628214619bea59e5) (cherry picked from commit dcb941b3f9bbcce02d15b9963d97cf0deee2485e) --------- Co-authored-by: FredApps Co-authored-by: Codex Co-authored-by: Terra854 Co-authored-by: yusufmntm Co-authored-by: Claude Opus 5.5 --- apps/pdfcraft-web/src/main.rs | 15 +- crates/engine/src/commands.rs | 1 + crates/ui-egui/src/app.rs | 2 + crates/ui-egui/src/app/control.rs | 7 + crates/ui-egui/src/app/prefs.rs | 4 + crates/ui-egui/src/app/settings.rs | 2 + crates/ui-egui/src/canvas.rs | 35 +- crates/ui-egui/src/canvas/rulers.rs | 541 ++++++++++++++++++ crates/ui-egui/src/commands.rs | 1 + crates/ui-egui/src/commands/catalog.rs | 3 +- crates/ui-egui/src/control.rs | 1 + crates/ui-egui/src/control/host.rs | 2 + crates/ui-egui/src/editing/save.rs | 23 + crates/ui-egui/src/editing/tests.rs | 35 ++ crates/ui-egui/src/hooks.rs | 3 + crates/ui-egui/src/lib.rs | 6 +- crates/ui-egui/src/menus.rs | 3 + crates/ui-egui/src/panels/comments_panel.rs | 5 +- crates/ui-egui/src/platform.rs | 13 + .../ui-egui/src/workflows/combine_ui/table.rs | 3 +- crates/ui-egui/tests/it/editing.rs | 121 ++++ crates/ui-egui/tests/it/forms.rs | 15 + crates/ui-egui/tests/it/pointer.rs | 26 + crates/ui-egui/tests/it/ui.rs | 34 ++ crates/ui-egui/tests/it/viewer.rs | 49 ++ parity/acrobat-features.toml | 15 +- 26 files changed, 951 insertions(+), 14 deletions(-) create mode 100644 crates/ui-egui/src/canvas/rulers.rs diff --git a/apps/pdfcraft-web/src/main.rs b/apps/pdfcraft-web/src/main.rs index 6f61567e4d..3460f21546 100644 --- a/apps/pdfcraft-web/src/main.rs +++ b/apps/pdfcraft-web/src/main.rs @@ -43,6 +43,11 @@ fn main() { .i18n(pdfcraft_ui_egui::i18n::host_catalogs()) .build(); let mut app = PdfCraftApp::with_host(Arc::new(app_host), AppServices::system(&cc.egui_ctx, intake)); + app.session = std::mem::take(&mut app.session).with_wall_clock( + || (js_sys::Date::now() / 1000.0).floor() as i64, + // JavaScript reports minutes west of UTC; the session uses seconds east. + || (-js_sys::Date::new_0().get_timezone_offset() * 60.0) as i64, + ); app.apply_settings(&settings.get()); app.attach_settings(settings); // `?embedded`: hide external community links when framed without `allow-popups` (#2490). @@ -82,6 +87,7 @@ fn main() { app.comment_prefs.author = author.chars().take(200).collect(); } bridge.listen(opens.clone()); + app.host_save = Some(bridge.save_fn()); app.host_dirty = Some(bridge.dirty_fn()); bridge.post_ready(); } else if query_param("host").as_deref() == Some("parent") { @@ -178,8 +184,8 @@ fn app_canvas() -> Option { /// says `file: false` and a host sends `bytes`. /// - `pdfcraft:open` (from the host): `{ name, bytes }` holding a PDF. It opens in a tab, like a /// `?file=` URL; a file over [`host::MAX_OPEN_BYTES`] is refused before it is copied. -/// - `pdfcraft:save` (to the host): `{ name, saveAs, bytes }` when the user saves, posted by the -/// browser file service. The host stores the file (and reports its own errors). +/// - `pdfcraft:save` (to the host): `{ name, saveAs, bytes }` when the user saves through the +/// connected bridge. The host stores the file and reports its own errors. /// - `pdfcraft:dirty` whenever unsaved work appears or goes away, `pdfcraft:failed` when the app /// couldn't start. #[cfg(target_arch = "wasm32")] @@ -231,6 +237,11 @@ mod host { }); } + pub fn save_fn(&self) -> pdfcraft_ui_egui::HostSaveFn { + let host = self.host.clone(); + Box::new(move |name, bytes, save_as| host.post_save(name, bytes, None, save_as)) + } + pub fn dirty_fn(&self) -> pdfcraft_ui_egui::HostDirtyFn { let host = self.host.clone(); // A host starts out clean: the first report is a change only when it is dirty. diff --git a/crates/engine/src/commands.rs b/crates/engine/src/commands.rs index a19dde0c39..14fe9b4ce6 100644 --- a/crates/engine/src/commands.rs +++ b/crates/engine/src/commands.rs @@ -293,6 +293,7 @@ pub const COMMANDS: &[CommandSpec] = &[ Nothing, "panel-left", ), + c("view.rulers", "Rulers", VIEW, Some(Shortcut::cmd("R")), Document, "ruler"), c("ui.dock.reset", "Reset side panels", VIEW, None, Nothing, "settings"), c("view.theme", "Switch light / dark theme", None, None, Nothing, "moon"), c("view.theme.system", "Use system setting", None, None, Nothing, "settings"), diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index b119e391d7..1038a13ec1 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -328,6 +328,7 @@ impl PdfCraftApp { suite: craft::theme_store::SuiteClient::memory(), reading_colors: Default::default(), show_page_edge_shadows: true, + show_rulers: false, scroll_speed: scroll_speed::ScrollSpeed::default(), invert_middle_drag: false, animation_effects: craft::theme::MotionChoice::System, @@ -416,6 +417,7 @@ impl PdfCraftApp { password_prompt: None, unlock_prompt: None, screen_mode: Default::default(), + host_save: None, host_dirty: None, os_events: None, close_guard: None, diff --git a/crates/ui-egui/src/app/control.rs b/crates/ui-egui/src/app/control.rs index d57552bc98..8f676c3508 100644 --- a/crates/ui-egui/src/app/control.rs +++ b/crates/ui-egui/src/app/control.rs @@ -45,6 +45,13 @@ impl PdfCraftApp { ("show_page_edge_shadows", _) => { self.show_page_edge_shadows = value.parse::().map_err(|_| "show_page_edge_shadows must be true or false")?; } + ("rulers", _) => { + self.show_rulers = match value { + "on" => true, + "off" => false, + _ => return Err("rulers must be on or off".into()), + }; + } ("update_check_at_start", _) => { self.update_check_at_start = value.parse::().map_err(|_| "update_check_at_start must be true or false")?; } diff --git a/crates/ui-egui/src/app/prefs.rs b/crates/ui-egui/src/app/prefs.rs index 28542ddbfc..c9e9650e7e 100644 --- a/crates/ui-egui/src/app/prefs.rs +++ b/crates/ui-egui/src/app/prefs.rs @@ -193,6 +193,7 @@ impl PdfCraftApp { fill_text_size: Some(self.fill_text_size), fill_text_color: Some(self.fill_text_color), show_page_edge_shadows: Some(self.show_page_edge_shadows), + show_rulers: Some(self.show_rulers), fill_text_border: Some(self.fill_text_default.width), fill_text_border_shape: Some(self.fill_text_default.shape.name().to_string()), // Absent is "the text's colour": TOML has no null. @@ -520,6 +521,9 @@ impl PdfCraftApp { if let Some(show) = b.show_page_edge_shadows { self.show_page_edge_shadows = show; } + if let Some(show) = b.show_rulers { + self.show_rulers = show; + } if let Some(width) = b.fill_text_border.and_then(fill_sign::valid_text_border) { self.fill_text_default.width = width; } diff --git a/crates/ui-egui/src/app/settings.rs b/crates/ui-egui/src/app/settings.rs index 35f304e744..74aeea56ad 100644 --- a/crates/ui-egui/src/app/settings.rs +++ b/crates/ui-egui/src/app/settings.rs @@ -99,6 +99,7 @@ pub struct Behavior { pub fill_text_size: Option, pub fill_text_color: Option<[f64; 3]>, pub show_page_edge_shadows: Option, + pub show_rulers: Option, pub fill_text_border: Option, pub fill_text_border_shape: Option, /// Absent is "the text's colour": TOML has no null. @@ -676,6 +677,7 @@ pub fn import_json(text: &str) -> (PdfCraftSettings, Vec) { fill_text_size: r.f64("fill_text_size"), fill_text_color: r.typed("fill_text_color"), show_page_edge_shadows: r.bool("show_page_edge_shadows"), + show_rulers: r.bool("show_rulers"), fill_text_border: r.f64("fill_text_border"), fill_text_border_shape: r.string("fill_text_border_shape"), fill_text_border_color: r.typed("fill_text_border_color"), diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 13768cb37b..13707d4d5a 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -45,6 +45,7 @@ pub(crate) mod page_parts; pub(crate) mod page_tools; pub(crate) mod pictures; mod presenter; +pub mod rulers; pub mod scroll_speed; mod selection; pub(super) mod signature_drag; @@ -1588,7 +1589,11 @@ fn page_body(ui: &mut egui::Ui, body: &PageBody<'_>, callbacks: &mut PageCallbac }; marks.show_at(ui, body.rect); image_pick::drop_stale(cx.doc, session); - image_pick::resolve_pending(session, cx.geometry(body), cx.doc, cx.info, cx.tools.host.jobs_shared(), cx.tools.wake); + // Until release the press may become a text drag. Picking the scan underneath now would erase + // the text selection's anchor before the first drag event can extend it. + if !ui.input(|i| i.pointer.primary_down()) { + image_pick::resolve_pending(session, cx.geometry(body), cx.doc, cx.info, cx.tools.host.jobs_shared(), cx.tools.wake); + } image_pick::show_picked(ui, body, session, cx.rotation, cx.info); if let Some(at) = cx.present_at { let (now, pointer) = ui.input(|i| (i.time, i.pointer.hover_pos())); @@ -1724,6 +1729,8 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu } // The room under the notice bars, inside the rect the caller gave. let rect = rect.intersect(ui.available_rect_before_wrap()); + let (ruler_outer, rect) = + if app.show_rulers && !app.views[index].presenting() && !app.full_screen() { rulers::reserve(rect) } else { (None, rect) }; let preparing = app.is_preparing(); // Prepare a form ▸ Calculation order: the order's steps and links on the page. @@ -1892,6 +1899,16 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu .show_at_with(ui, rect, &mut callbacks, page_before, page_body) }) .inner; + // A primary click on the unclaimed pasteboard gives the reader its keyboard back. In + // particular, a focused zoom editor must not keep the arrow keys after the reader clicks + // beside a page. Canvas controls and page parts handle their own focus and are excluded. + // An open form editor has its own focus handoff; leave it to that path. + if view.session.forms.focus.is_none() + && let Some(pos) = out.canvas.click_at() + && !out.pages.iter().any(|page| page.rect.contains(pos)) + { + focus::request(ui.ctx(), FocusTarget::Id(out.canvas.response.id)); + } if view.view.continuous && let Some(page) = body_out.pressed_page { @@ -1956,6 +1973,22 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu view.viewport = rect; view.canvas = body_out.shown; view.middle_scrolling = out.canvas.auto_scrolling; + if let Some(outer) = ruler_outer { + let pointer = + if unobstructed && ui.rect_contains_pointer(rect) { ui.input(|i| i.pointer.hover_pos()).filter(|p| rect.contains(*p)) } else { None }; + rulers::show( + ui, + outer, + rect, + &view.session.placed, + &view.page_sizes, + view.view.current, + view.view.rotation, + view.view.zoom, + app.units, + pointer, + ); + } // Addresses written as plain text are found once per text layer that has arrived; the link parts read them. if app.text_links { for page in out.visible.clone() { diff --git a/crates/ui-egui/src/canvas/rulers.rs b/crates/ui-egui/src/canvas/rulers.rs new file mode 100644 index 0000000000..3f5351b7f2 --- /dev/null +++ b/crates/ui-egui/src/canvas/rulers.rs @@ -0,0 +1,541 @@ +//! Horizontal and vertical rulers along the top and left edges of the document area (`view.rulers`). +//! +//! The rulers reserve a thin strip along the top and left of the page area so pages are never covered. +//! Origin `(0, 0)` is the top-left corner of the page under the pointer (or the current page when the +//! pointer is elsewhere), in the page's displayed orientation. Units follow the app's measurement-units +//! preference (`crate::units::Unit`). Ticks use nice 1 / 2 / 5 × 10^n intervals chosen from the active +//! zoom so labels never overlap, and are hard-capped per frame so degenerate inputs cannot stall rendering. + +use craft::pages::ui::PlacedPage; +use craft::ui::runtime::env::Env; +use egui::{Align2, Color32, CornerRadius, FontId, Pos2, Rect, Stroke, pos2}; + +use crate::units::Unit; + +/// Thickness in logical points reserved for each ruler strip (and the corner unit square). +pub const RULER_THICKNESS: f32 = 20.0; + +/// Minimum screen spacing in logical points between consecutive major tick labels. +pub const MIN_MAJOR_SPACING_PX: f64 = 56.0; + +/// Maximum number of ticks (major + minor) emitted per ruler per frame. +pub const MAX_TICKS: usize = 512; + +/// Minimum screen spacing in logical points between minor ticks before minor ticks are omitted. +const MIN_MINOR_SPACING_PX: f64 = 3.0; + +/// Whether a tick is a major labelled tick, a half-way subdivision, or a regular minor tick. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum TickKind { + Major, + Half, + Minor, +} + +/// One positioned tick along a ruler axis. +#[derive(Clone, Copy, Debug, PartialEq)] +pub struct Tick { + /// Coordinate in logical screen points along the ruler's axis. + pub screen: f32, + /// Coordinate in the active measurement unit relative to the page origin. + pub value: f64, + pub kind: TickKind, +} + +/// Reserves space for the top and left ruler strips inside `area`. +/// +/// Returns `(Some(area), page_rect)` when `area` is finite and larger than [`RULER_THICKNESS`] on +/// both axes; otherwise returns `(None, area)` without producing an inverted rectangle. +pub fn reserve(area: Rect) -> (Option, Rect) { + if !area.is_finite() || area.width() <= RULER_THICKNESS || area.height() <= RULER_THICKNESS { + return (None, area); + } + let page_rect = Rect::from_min_max(pos2(area.min.x + RULER_THICKNESS, area.min.y + RULER_THICKNESS), area.max); + (Some(area), page_rect) +} + +/// Chooses a "nice" major interval (`1`, `2`, or `5` × `10^n`) and minor subdivision count +/// given `px_per_unit` (logical screen pixels per 1 unit) and `min_major_px` (minimum screen +/// pixels between adjacent major labels). +/// +/// Returns `None` for non-finite or non-positive inputs, or if the resulting step underflows/overflows. +pub fn nice_interval(px_per_unit: f64, min_major_px: f64) -> Option<(f64, usize)> { + if !px_per_unit.is_finite() || px_per_unit <= 0.0 || !min_major_px.is_finite() || min_major_px <= 0.0 { + return None; + } + let target = min_major_px / px_per_unit; + if !target.is_finite() || target <= 0.0 { + return None; + } + let exp = target.log10().floor(); + if !exp.is_finite() { + return None; + } + let base = 10.0_f64.powf(exp); + if !base.is_finite() || base <= 0.0 { + return None; + } + let frac = target / base; + let (step, subdivisions) = if frac <= 1.0 { + (1.0 * base, 10) + } else if frac <= 2.0 { + (2.0 * base, 4) + } else if frac <= 5.0 { + (5.0 * base, 5) + } else { + (10.0 * base, 10) + }; + if !step.is_finite() || step <= 0.0 { + return None; + } + Some((step, subdivisions)) +} + +/// Chooses `(major_step, minor_subdivisions)` in `unit` for a scale of `px_per_pt` logical screen +/// pixels per PDF point. +pub fn ruler_step(px_per_pt: f64, unit: Unit) -> Option<(f64, usize)> { + if !px_per_pt.is_finite() || px_per_pt <= 0.0 { + return None; + } + let per_point = unit.per_point(); + if !per_point.is_finite() || per_point <= 0.0 { + return None; + } + let px_per_unit = px_per_pt / per_point; + let (step, subdivisions) = nice_interval(px_per_unit, MIN_MAJOR_SPACING_PX)?; + // Eighths of an inch at 1 in major intervals match standard inch rulers. + let subdivisions = if unit == Unit::Inches && (step - 1.0).abs() < 1e-6 { 8 } else { subdivisions }; + Some((step, subdivisions)) +} + +/// Computes major and minor ticks along one ruler axis over `[range_min, range_max]`. +/// +/// `origin` is the screen coordinate of unit `0`, `px_per_unit` is logical screen pixels per unit, +/// `major_step` is the distance between major ticks in units, and `subdivisions` is the number of +/// equal segments between major ticks. At most `max_ticks` ticks are returned; degenerate or +/// non-finite inputs yield an empty list without panicking or looping. +pub fn compute_ticks( + range_min: f32, + range_max: f32, + origin: f32, + px_per_unit: f64, + major_step: f64, + subdivisions: usize, + max_ticks: usize, +) -> Vec { + if !range_min.is_finite() + || !range_max.is_finite() + || range_max <= range_min + || !origin.is_finite() + || !px_per_unit.is_finite() + || px_per_unit <= 0.0 + || !major_step.is_finite() + || major_step <= 0.0 + || subdivisions == 0 + || max_ticks == 0 + { + return Vec::new(); + } + + let r_min = f64::from(range_min); + let r_max = f64::from(range_max); + let orig = f64::from(origin); + + let u_min = (r_min - orig) / px_per_unit; + let u_max = (r_max - orig) / px_per_unit; + if !u_min.is_finite() || !u_max.is_finite() { + return Vec::new(); + } + + let first_k = (u_min / major_step).floor(); + let last_k = (u_max / major_step).ceil(); + if !first_k.is_finite() || !last_k.is_finite() || first_k < -1e12 || last_k > 1e12 { + return Vec::new(); + } + + let k_start = first_k as i64; + let k_end = last_k as i64; + if k_end < k_start { + return Vec::new(); + } + + let major_px = major_step * px_per_unit; + let draw_minor = subdivisions > 1 && (major_px / (subdivisions as f64)) >= MIN_MINOR_SPACING_PX; + let sub_step = major_step / (subdivisions as f64); + + let mut out = Vec::new(); + // Bound major-loop iterations independently so pathological inputs can never spin. + let max_major_iters = max_ticks.saturating_add(2); + for (iters, k) in (k_start..=k_end).enumerate() { + if iters >= max_major_iters || out.len() >= max_ticks { + break; + } + let val = (k as f64) * major_step; + let screen = orig + val * px_per_unit; + if screen.is_finite() && screen >= r_min - 0.5 && screen <= r_max + 0.5 { + out.push(Tick { screen: screen as f32, value: val, kind: TickKind::Major }); + } + if draw_minor { + for sub in 1..subdivisions { + if out.len() >= max_ticks { + break; + } + let sub_val = val + (sub as f64) * sub_step; + let sub_screen = orig + sub_val * px_per_unit; + if sub_screen.is_finite() && sub_screen >= r_min && sub_screen <= r_max { + let kind = if subdivisions.is_multiple_of(2) && sub * 2 == subdivisions { TickKind::Half } else { TickKind::Minor }; + out.push(Tick { screen: sub_screen as f32, value: sub_val, kind }); + } + } + } + } + out +} + +/// Formats a major tick value concisely without trailing zeroes or `-0`. +pub fn format_label(value: f64, step: f64) -> String { + if !value.is_finite() { + return String::new(); + } + let eps = if step.is_finite() && step > 0.0 { (step * 1e-6).max(1e-9) } else { 1e-9 }; + if value.abs() < eps { + return "0".to_string(); + } + let decimals = if step.is_finite() && step > 0.0 && step < 1.0 { + let d = (-step.log10().floor()).clamp(0.0, 4.0) as usize; + // e.g. step = 0.25 needs 2 decimals even though floor(log10(0.25)) == -1. + if ((step * 10.0_f64.powi(d as i32)).fract()).abs() > 1e-4 && d < 4 { d + 1 } else { d } + } else if (value - value.round()).abs() < 1e-4 { + 0 + } else { + 2 + }; + let mut s = format!("{value:.decimals$}"); + if decimals > 0 && s.contains('.') { + while s.ends_with('0') { + s.pop(); + } + if s.ends_with('.') { + s.pop(); + } + } + if s == "-0" { "0".to_string() } else { s } +} + +/// Computes the displayed top-left origin and `(px_per_pt_x, px_per_pt_y)` for a placed page. +/// +/// The page is measured in its displayed orientation (swapping width and height under 90°/270° +/// view rotation). Returns `None` if `page_rect` is zero-sized or non-finite, or if no positive +/// finite scale can be determined. +pub fn page_origin_and_scale(page_rect: Rect, page_size_pt: (f32, f32), view_rotation: u16, fallback_zoom: f64) -> Option<(Pos2, f64, f64)> { + if !page_rect.is_finite() || page_rect.width() <= 0.0 || page_rect.height() <= 0.0 { + return None; + } + let (disp_w, disp_h) = if view_rotation % 180 == 90 { (page_size_pt.1, page_size_pt.0) } else { page_size_pt }; + if disp_w.is_finite() && disp_w > 0.0 && disp_h.is_finite() && disp_h > 0.0 { + let sx = f64::from(page_rect.width()) / f64::from(disp_w); + let sy = f64::from(page_rect.height()) / f64::from(disp_h); + if sx.is_finite() && sx > 0.0 && sy.is_finite() && sy > 0.0 { + return Some((page_rect.left_top(), sx, sy)); + } + } + if fallback_zoom.is_finite() && fallback_zoom > 0.0 { + let s = fallback_zoom * f64::from(super::PT); + if s.is_finite() && s > 0.0 { + return Some((page_rect.left_top(), s, s)); + } + } + None +} + +/// Converts an RGBA theme token value (`craft::theme::Rgba.0`) into an `egui::Color32`. +fn token_color([r, g, b, a]: [u8; 4]) -> Color32 { + Color32::from_rgba_unmultiplied(r, g, b, a) +} + +/// Draws the top and left rulers and corner unit indicator inside the reserved strips of `outer` +/// outside `page_rect`. +/// +/// Never claims the cursor or takes presses. Draws short cursor marks on both rulers only while +/// `pointer` is over a placed page. +#[allow(clippy::too_many_arguments)] +pub(super) fn show( + ui: &egui::Ui, + outer: Rect, + page_rect: Rect, + placed: &[PlacedPage], + page_sizes: &[(f32, f32)], + current_page: usize, + view_rotation: u16, + view_zoom: f64, + units: Unit, + pointer: Option, +) { + if !outer.is_finite() || !page_rect.is_finite() || !outer.is_positive() { + return; + } + + let env = Env::of(ui); + let colors = &env.tokens.color; + let bg = token_color(colors.surface.raised.0); + let border = token_color(colors.line.control_edge.0); + let tick_major = token_color(colors.text.muted.0); + let tick_minor = token_color(colors.line.control_edge.0); + let label_ink = token_color(colors.text.normal.0); + let accent = token_color(colors.accent.solid.0); + let thin = env.tokens.stroke.thin.max(1.0); + + let mut font: FontId = egui::TextStyle::Small.resolve(ui.style()); + font.size = font.size.min(9.5); + + let corner_rect = Rect::from_min_max(outer.min, page_rect.min); + let top_rect = Rect::from_min_max(pos2(page_rect.min.x, outer.min.y), pos2(outer.max.x, page_rect.min.y)); + let left_rect = Rect::from_min_max(pos2(outer.min.x, page_rect.min.y), pos2(page_rect.min.x, outer.max.y)); + + // Anchor page: page under the pointer if any, otherwise the current page, otherwise the first placed page. + let pointer_page = pointer.and_then(|pos| placed.iter().find(|p| p.rect.is_finite() && p.rect.contains(pos))); + let cursor_on_page = pointer.filter(|_| pointer_page.is_some()); + let anchor = pointer_page.or_else(|| placed.iter().find(|p| p.page == current_page)).or_else(|| placed.first()); + + let origin_scale = anchor + .and_then(|p| { + let size = page_sizes.get(p.page).copied().unwrap_or((0.0, 0.0)); + page_origin_and_scale(p.rect, size, view_rotation, view_zoom) + }) + .or_else(|| { + if view_zoom.is_finite() && view_zoom > 0.0 { + let s = view_zoom * f64::from(super::PT); + (s.is_finite() && s > 0.0).then_some((page_rect.min, s, s)) + } else { + None + } + }); + + let per_point = units.per_point(); + let per_point_ok = per_point.is_finite() && per_point > 0.0; + + // Corner unit badge (display only; does not take clicks or claim the cursor). + { + let painter = ui.painter().with_clip_rect(corner_rect); + painter.rect_filled(corner_rect, CornerRadius::ZERO, bg); + painter.line_segment([corner_rect.right_top(), corner_rect.right_bottom()], Stroke::new(thin, border)); + painter.line_segment([corner_rect.left_bottom(), corner_rect.right_bottom()], Stroke::new(thin, border)); + painter.text(corner_rect.center(), Align2::CENTER_CENTER, units.label(), font.clone(), label_ink); + } + + // Top horizontal ruler. + if top_rect.width() > 0.0 && top_rect.height() > 0.0 { + let painter = ui.painter().with_clip_rect(top_rect); + painter.rect_filled(top_rect, CornerRadius::ZERO, bg); + painter.line_segment([top_rect.left_bottom(), top_rect.right_bottom()], Stroke::new(thin, border)); + + if per_point_ok + && let Some((origin, sx, _)) = origin_scale + && let Some((step, subs)) = ruler_step(sx, units) + { + let px_per_unit = sx / per_point; + let ticks = compute_ticks(top_rect.min.x, top_rect.max.x, origin.x, px_per_unit, step, subs, MAX_TICKS); + for tick in ticks { + match tick.kind { + TickKind::Major => { + painter.line_segment( + [pos2(tick.screen, top_rect.max.y - 7.0), pos2(tick.screen, top_rect.max.y)], + Stroke::new(thin, tick_major), + ); + let label = format_label(tick.value, step); + painter.text(pos2(tick.screen + 2.0, top_rect.min.y + 1.5), Align2::LEFT_TOP, label, font.clone(), label_ink); + } + TickKind::Half => { + painter.line_segment( + [pos2(tick.screen, top_rect.max.y - 5.0), pos2(tick.screen, top_rect.max.y)], + Stroke::new(thin, tick_minor), + ); + } + TickKind::Minor => { + painter.line_segment( + [pos2(tick.screen, top_rect.max.y - 3.5), pos2(tick.screen, top_rect.max.y)], + Stroke::new(thin, tick_minor), + ); + } + } + } + } + + if let Some(pos) = cursor_on_page + && pos.x >= top_rect.min.x + && pos.x <= top_rect.max.x + { + painter.line_segment([pos2(pos.x, top_rect.min.y), pos2(pos.x, top_rect.max.y)], Stroke::new(1.5, accent)); + let tip = vec![pos2(pos.x - 3.0, top_rect.max.y - 4.0), pos2(pos.x + 3.0, top_rect.max.y - 4.0), pos2(pos.x, top_rect.max.y)]; + painter.add(egui::epaint::PathShape::convex_polygon(tip, accent, Stroke::NONE)); + } + } + + // Left vertical ruler. + if left_rect.width() > 0.0 && left_rect.height() > 0.0 { + let painter = ui.painter().with_clip_rect(left_rect); + painter.rect_filled(left_rect, CornerRadius::ZERO, bg); + painter.line_segment([left_rect.right_top(), left_rect.right_bottom()], Stroke::new(thin, border)); + + if per_point_ok + && let Some((origin, _, sy)) = origin_scale + && let Some((step, subs)) = ruler_step(sy, units) + { + let px_per_unit = sy / per_point; + let ticks = compute_ticks(left_rect.min.y, left_rect.max.y, origin.y, px_per_unit, step, subs, MAX_TICKS); + for tick in ticks { + match tick.kind { + TickKind::Major => { + painter.line_segment( + [pos2(left_rect.max.x - 7.0, tick.screen), pos2(left_rect.max.x, tick.screen)], + Stroke::new(thin, tick_major), + ); + let label = format_label(tick.value, step); + let galley = painter.layout_no_wrap(label, font.clone(), label_ink); + let pos = pos2(left_rect.min.x + 2.0, tick.screen + 2.0 + galley.size().x); + painter.add(egui::epaint::TextShape::new(pos, galley, label_ink).with_angle(-std::f32::consts::FRAC_PI_2)); + } + TickKind::Half => { + painter.line_segment( + [pos2(left_rect.max.x - 5.0, tick.screen), pos2(left_rect.max.x, tick.screen)], + Stroke::new(thin, tick_minor), + ); + } + TickKind::Minor => { + painter.line_segment( + [pos2(left_rect.max.x - 3.5, tick.screen), pos2(left_rect.max.x, tick.screen)], + Stroke::new(thin, tick_minor), + ); + } + } + } + } + + if let Some(pos) = cursor_on_page + && pos.y >= left_rect.min.y + && pos.y <= left_rect.max.y + { + painter.line_segment([pos2(left_rect.min.x, pos.y), pos2(left_rect.max.x, pos.y)], Stroke::new(1.5, accent)); + let tip = vec![pos2(left_rect.max.x - 4.0, pos.y - 3.0), pos2(left_rect.max.x - 4.0, pos.y + 3.0), pos2(left_rect.max.x, pos.y)]; + painter.add(egui::epaint::PathShape::convex_polygon(tip, accent, Stroke::NONE)); + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::canvas::PT; + use egui::vec2; + + #[test] + fn nice_interval_picks_1_2_5_multiples_across_zooms_and_units() { + for unit in Unit::ALL { + for zoom in [0.1, 0.25, 0.5, 1.0, 2.0, 4.0, 16.0, 64.0] { + let px_per_pt = zoom * f64::from(PT); + let (step, subs) = ruler_step(px_per_pt, unit).expect("finite positive zoom yields a step"); + assert!(step > 0.0 && step.is_finite()); + assert!(subs >= 4); + let px_per_unit = px_per_pt / unit.per_point(); + let major_px = step * px_per_unit; + // Labels never overlap (at least MIN_MAJOR_SPACING_PX apart) and never get absurdly sparse. + assert!(major_px >= MIN_MAJOR_SPACING_PX - 1e-6, "unit={unit:?} zoom={zoom} major_px={major_px}"); + assert!(major_px <= MIN_MAJOR_SPACING_PX * 2.51, "unit={unit:?} zoom={zoom} major_px={major_px}"); + // Leading digit of step is 1, 2, or 5. + let mantissa = step / 10.0_f64.powf(step.log10().floor()); + assert!( + (mantissa - 1.0).abs() < 1e-6 || (mantissa - 2.0).abs() < 1e-6 || (mantissa - 5.0).abs() < 1e-6, + "step {step} mantissa {mantissa} is not 1/2/5" + ); + } + } + // Higher zoom yields smaller or equal major interval. + for unit in Unit::ALL { + let (far, _) = ruler_step(0.25 * f64::from(PT), unit).unwrap(); + let (near, _) = ruler_step(4.0 * f64::from(PT), unit).unwrap(); + assert!(near < far, "{unit:?}: zoomed in ({near}) should have finer step than zoomed out ({far})"); + } + } + + #[test] + fn tick_positions_anchor_to_page_offset() { + let origin = 120.0_f32; + let px_per_unit = 10.0_f64; + let ticks = compute_ticks(20.0, 320.0, origin, px_per_unit, 10.0, 5, MAX_TICKS); + let majors: Vec = ticks.iter().copied().filter(|t| t.kind == TickKind::Major).collect(); + // Origin 0 lands exactly at screen coordinate 120.0. + let zero = majors.iter().find(|t| t.value.abs() < 1e-9).expect("zero tick present"); + assert!((zero.screen - origin).abs() < 1e-4); + // Every major tick satisfies screen == origin + value * px_per_unit and stays inside the ruler strip. + assert!(majors.len() >= 3); + for t in &majors { + let expected = origin + (t.value * px_per_unit) as f32; + assert!((t.screen - expected).abs() < 1e-3, "tick {t:?} expected {expected}"); + assert!(t.screen >= 19.5 && t.screen <= 320.5); + } + // Shifting origin right by 35 px shifts every tick's screen position by +35 px for the same value. + let shifted = compute_ticks(20.0, 320.0, origin + 35.0, px_per_unit, 10.0, 5, MAX_TICKS); + let shifted_zero = shifted.iter().find(|t| t.kind == TickKind::Major && t.value.abs() < 1e-9).unwrap(); + assert!((shifted_zero.screen - (origin + 35.0)).abs() < 1e-4); + } + + #[test] + fn label_formatting_is_clean_and_has_no_negative_zero() { + assert_eq!(format_label(0.0, 10.0), "0"); + assert_eq!(format_label(-0.0, 10.0), "0"); + assert_eq!(format_label(-1e-12, 1.0), "0"); + assert_eq!(format_label(100.0, 50.0), "100"); + assert_eq!(format_label(-50.0, 50.0), "-50"); + assert_eq!(format_label(0.5, 0.5), "0.5"); + assert_eq!(format_label(1.0, 0.5), "1"); + assert_eq!(format_label(1.25, 0.25), "1.25"); + assert_eq!(format_label(0.05, 0.05), "0.05"); + assert_eq!(format_label(f64::NAN, 1.0), ""); + assert_eq!(format_label(f64::INFINITY, 1.0), ""); + } + + #[test] + fn tick_cap_bounds_output_on_dense_ranges() { + let cap = 32; + let ticks = compute_ticks(0.0, 100_000.0, 0.0, 10.0, 1.0, 10, cap); + assert_eq!(ticks.len(), cap); + let ticks_default = compute_ticks(0.0, 1_000_000.0, 0.0, 10.0, 1.0, 10, MAX_TICKS); + assert!(ticks_default.len() <= MAX_TICKS); + } + + #[test] + fn degenerate_inputs_do_not_panic_or_loop() { + // Bad zooms: 0, negative, NaN, infinity, huge. + for bad in [0.0, -1.0, f64::NAN, f64::INFINITY, f64::NEG_INFINITY, 1e308, 1e-308] { + let _ = nice_interval(bad, MIN_MAJOR_SPACING_PX); + let _ = ruler_step(bad, Unit::Points); + let ticks = compute_ticks(0.0, 500.0, 10.0, bad, 10.0, 5, MAX_TICKS); + assert!(ticks.len() <= MAX_TICKS); + } + // Bad ranges and steps. + assert!(compute_ticks(100.0, 100.0, 0.0, 1.0, 10.0, 5, MAX_TICKS).is_empty()); + assert!(compute_ticks(200.0, 100.0, 0.0, 1.0, 10.0, 5, MAX_TICKS).is_empty()); + assert!(compute_ticks(f32::NAN, 100.0, 0.0, 1.0, 10.0, 5, MAX_TICKS).is_empty()); + assert!(compute_ticks(0.0, 100.0, f32::NAN, 1.0, 10.0, 5, MAX_TICKS).is_empty()); + assert!(compute_ticks(0.0, 100.0, 0.0, 1.0, 0.0, 5, MAX_TICKS).is_empty()); + assert!(compute_ticks(0.0, 100.0, 0.0, 1.0, f64::NAN, 5, MAX_TICKS).is_empty()); + assert!(compute_ticks(0.0, 100.0, 0.0, 1.0, 10.0, 0, MAX_TICKS).is_empty()); + + // Zero-size and tiny areas for reserve(). + let zero = Rect::from_min_size(pos2(10.0, 20.0), vec2(0.0, 0.0)); + assert_eq!(reserve(zero), (None, zero)); + let tiny = Rect::from_min_size(pos2(0.0, 0.0), vec2(RULER_THICKNESS, 200.0)); + assert_eq!(reserve(tiny), (None, tiny)); + + // Zero-size page and rotated pages for page_origin_and_scale(). + assert!(page_origin_and_scale(zero, (0.0, 0.0), 0, 1.0).is_none()); + let page = Rect::from_min_size(pos2(40.0, 50.0), vec2(400.0, 200.0)); + assert!(page_origin_and_scale(page, (0.0, 0.0), 0, 0.0).is_none()); + assert!(page_origin_and_scale(page, (f32::NAN, 100.0), 0, f64::NAN).is_none()); + // Rotated 90°: displayed width is ph (800), displayed height is pw (400). + let (origin, sx, sy) = page_origin_and_scale(page, (400.0, 800.0), 90, 1.0).unwrap(); + assert_eq!(origin, page.left_top()); + assert!((sx - 0.5).abs() < 1e-6); + assert!((sy - 0.5).abs() < 1e-6); + } +} diff --git a/crates/ui-egui/src/commands.rs b/crates/ui-egui/src/commands.rs index 0ffbc813e1..1f36fe0458 100644 --- a/crates/ui-egui/src/commands.rs +++ b/crates/ui-egui/src/commands.rs @@ -614,6 +614,7 @@ impl PdfCraftApp { self.set_full_screen(on); } "view.read_mode" => self.switch_mode(ctx, if self.mode == Mode::Read { Mode::AllTools } else { Mode::Read }, false), + "view.rulers" => self.show_rulers = !self.show_rulers, "view.split" => self.toggle_split(ctx), crate::viewer_prefs::TOGGLE => self.toggle_interface(), "view.previous_view" | "view.next_view" => { diff --git a/crates/ui-egui/src/commands/catalog.rs b/crates/ui-egui/src/commands/catalog.rs index edb21a05b0..79e8058a54 100644 --- a/crates/ui-egui/src/commands/catalog.rs +++ b/crates/ui-egui/src/commands/catalog.rs @@ -53,7 +53,7 @@ fn kind_of(id: &str) -> CommandKind { "view.theme.system" | "view.theme.light" | "view.theme.dark" => CommandKind::Radio { group: Some("theme".into()) }, PANEL => CommandKind::Radio { group: Some("panel".into()) }, "view.continuous" | "view.page_gaps" | "view.layout.cover" | "view.full_screen" | "view.read_mode" | "view.side_panel" - | "view.tools_pane" | "view.split" => CommandKind::Toggle, + | "view.tools_pane" | "view.split" | "view.rulers" => CommandKind::Toggle, _ => CommandKind::Command, } } @@ -240,6 +240,7 @@ fn checked(app: &PdfCraftApp, command: &CommandRef) -> Option { "view.layout.cover" => view.is_some_and(|v| v.cover), "view.full_screen" => app.full_screen(), "view.read_mode" => app.mode == Mode::Read, + "view.rulers" => app.show_rulers, "view.side_panel" => app.right().is_some(), "view.tools_pane" => app.left_open(), "view.split" => app.panes.split.is_some(), diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs index f79d2a1729..651a92f9e0 100644 --- a/crates/ui-egui/src/control.rs +++ b/crates/ui-egui/src/control.rs @@ -37,6 +37,7 @@ //! reports the choice and `ui.state.theme` reports the resolved light/dark colours. //! `form-reminder=on|off` persists ordinary form reminders. `ui.state.show_form_field_reminder` reports the setting. //! `show_page_edge_shadows=true|false` controls page decoration app-wide. +//! `rulers=on|off` shows or hides horizontal and vertical canvas rulers; `ui.state.rulers` reports it. //! `comment-tool-pinned=true|false` remembers the annotation quick bar's pin across restarts. //! `folder-collapsed==on|off` folds a pinned folder on Home down to its heading or //! opens it again; `ui.state.pinned_folders` lists each pinned folder and whether it is. diff --git a/crates/ui-egui/src/control/host.rs b/crates/ui-egui/src/control/host.rs index 39f04746e3..0dde19a2c9 100644 --- a/crates/ui-egui/src/control/host.rs +++ b/crates/ui-egui/src/control/host.rs @@ -94,6 +94,7 @@ impl crate::PdfCraftApp { }), "viewport": [v.viewport_rect().min.x, v.viewport_rect().min.y, v.viewport_rect().max.x, v.viewport_rect().max.y], "find_open": v.find.is_some(), + "rulers": self.show_rulers, "page_errors": v.page_errors().iter().map(|(p, e)| json!({ "page": p + 1, "error": e })).collect::>(), // Pages cut at the renderer's limits (#623), 1-based. "cut_pages": v.cut_pages().iter().map(|p| p + 1).collect::>(), @@ -161,6 +162,7 @@ impl crate::PdfCraftApp { "theme": format!("{:?}", self.root_env(ctx).resolved(ctx).mode), "theme_preference": format!("{:?}", self.theme_preference), "show_page_edge_shadows": self.show_page_edge_shadows, + "rulers": self.show_rulers, "language": self.language, "notice": notice, "progress": progress, diff --git a/crates/ui-egui/src/editing/save.rs b/crates/ui-egui/src/editing/save.rs index 28ca005e00..ccf5d4073a 100644 --- a/crates/ui-egui/src/editing/save.rs +++ b/crates/ui-egui/src/editing/save.rs @@ -229,6 +229,13 @@ impl PdfCraftApp { } return false; } + if let Some(saved) = self.save_to_host(ctx, id, &name, target) { + let then = if saved { pending.after.take() } else { pending.failed.take() }; + if let Some(then) = then { + then(self, ctx); + } + return saved; + } if target == SaveTarget::InPlace && let Some(path) = path { @@ -254,6 +261,22 @@ impl PdfCraftApp { false } + /// Deliver through a connected embedding page; `None` leaves an unhosted save to the picker. + #[cfg(any(target_arch = "wasm32", test))] + pub(super) fn save_to_host(&mut self, ctx: &egui::Context, id: DocId, name: &str, target: SaveTarget) -> Option { + self.host_save.as_ref()?; + let Some((_, bytes)) = self.document_bytes(ctx, id, target, None) else { return Some(false) }; + let result = self.host_save.as_ref()?(name, &bytes, target != SaveTarget::InPlace); + match result { + Ok(()) if target == SaveTarget::Copy => Some(true), + Ok(()) => Some(self.finish_save(ctx, id, bytes, None)), + Err(e) => { + self.notify_fmt("Couldn't save {name}: {e}", &[("name", name), ("e", &e)]); + Some(false) + } + } + } + /// The browser's save picker answered: where the bytes went, a failure or a cancel. #[cfg(target_arch = "wasm32")] pub(crate) fn save_flow_pass(&mut self, ctx: &egui::Context) { diff --git a/crates/ui-egui/src/editing/tests.rs b/crates/ui-egui/src/editing/tests.rs index 0160040ddd..7c2a0eaf2c 100644 --- a/crates/ui-egui/src/editing/tests.rs +++ b/crates/ui-egui/src/editing/tests.rs @@ -74,6 +74,41 @@ fn one_page_pdf() -> Vec { out } +/// #9005: a pathless host document sends the changed PDF to the page and keeps no invented path. +#[test] +fn host_save_delivers_pathless_document_and_preserves_failures() { + use std::sync::Mutex; + let mut app = crate::PdfCraftApp::for_unit_tests(); + let ctx = egui::Context::default(); + app.open_bytes(&ctx, "sample.pdf", None, one_page_pdf()).unwrap(); + let id = app.views[0].id; + app.apply_edit(&ctx, pdfcraft_engine::Edit::RotatePages { pages: vec![0], degrees: 90 }); + assert!(app.session.get(id).unwrap().dirty); + assert_eq!(app.save_to_host(&ctx, id, "sample.pdf", SaveTarget::InPlace), None, "unhosted saves still use the browser picker"); + app.host_save = Some(Box::new(|_, _, _| Err("host rejected".into()))); + assert_eq!(app.save_to_host(&ctx, id, "sample.pdf", SaveTarget::InPlace), Some(false)); + assert!(app.session.get(id).unwrap().dirty, "a failed delivery does not mark the document saved"); + let received = Arc::new(Mutex::new(Vec::<(String, Vec, bool)>::new())); + let sink = received.clone(); + app.host_save = Some(Box::new(move |name, bytes, as_copy| { + sink.lock().unwrap().push((name.to_owned(), bytes.to_vec(), as_copy)); + Ok(()) + })); + assert_eq!(app.save_to_host(&ctx, id, "sample.pdf", SaveTarget::InPlace), Some(true)); + assert!(!app.session.get(id).unwrap().dirty); + assert!(app.session.get(id).unwrap().path.is_none(), "host delivery does not create a filesystem path"); + assert_eq!(app.save_to_host(&ctx, id, "sample.pdf", SaveTarget::As), Some(true)); + app.apply_edit(&ctx, pdfcraft_engine::Edit::RotatePages { pages: vec![0], degrees: 90 }); + assert_eq!(app.save_to_host(&ctx, id, "sample.pdf", SaveTarget::Copy), Some(true)); + assert!(app.session.get(id).unwrap().dirty, "saving a copy does not mark the original saved"); + let saved = received.lock().unwrap(); + assert_eq!(saved.len(), 3); + assert_eq!((saved[0].0.as_str(), saved[0].2, saved[1].2, saved[2].2), ("sample.pdf", false, true, true)); + let mut reopened = pdfcraft_engine::Session::new(); + let opened = reopened.open("saved.pdf", None, Arc::new(saved[0].1.clone()), None).unwrap(); + assert_eq!(reopened.get(opened).unwrap().info.pages[0].rotation, 90); +} + /// `one_page_pdf`, opening without a password, whose permissions refuse changes. fn no_changes_pdf() -> Vec { let mut doc = pdfcraft_cos::Document::open(std::sync::Arc::new(one_page_pdf())).unwrap(); diff --git a/crates/ui-egui/src/hooks.rs b/crates/ui-egui/src/hooks.rs index e1ecfff371..4b80f087ee 100644 --- a/crates/ui-egui/src/hooks.rs +++ b/crates/ui-egui/src/hooks.rs @@ -1,3 +1,6 @@ /// Told every frame whether any tab has unsaved work, or an OCR review is not yet accepted or /// rejected, so a host page can warn before leaving. pub type HostDirtyFn = Box; + +/// Delivers a saved document to an embedding web page: name, bytes, and whether Save As was requested. +pub type HostSaveFn = Box Result<(), String>>; diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index f7eb738d3e..224bfbd2fa 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -123,7 +123,7 @@ use dialogs::rename_ui; use dialogs::standards_ui; use dialogs::word_count_ui; pub use home::folders_ui; -pub use hooks::HostDirtyFn; +pub use hooks::{HostDirtyFn, HostSaveFn}; use menus::tab_context; use panels::all_tools_ui; use panels::comments_panel; @@ -353,6 +353,8 @@ pub struct PdfCraftApp { pub reading_colors: pdfcraft_render::ReadingColors, /// App-wide page decoration only; never part of a PDF edit or render request. pub show_page_edge_shadows: bool, + /// View ▸ Show/Hide ▸ Rulers: horizontal and vertical rulers around the page area. + pub show_rulers: bool, /// How far a mouse-wheel notch scrolls. pub scroll_speed: scroll_speed::ScrollSpeed, /// Preferences ▸ Invert middle-button drag: the middle button's pan or auto-scroll moves the @@ -552,6 +554,8 @@ pub struct PdfCraftApp { pub unlock_prompt: Option, /// Standard, full screen with the menu bar, or full screen. pub screen_mode: craft::ui::shell::ScreenMode, + /// Saves documents through a connected embedding page instead of the browser picker. + pub host_save: Option, /// Reports unsaved work, or an open OCR review, to the embedding page (web, see [`HostDirtyFn`]). pub host_dirty: Option, /// Requests from the operating system, polled at the start of every frame's logic (macOS Apple diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs index 835bbc37a0..d1f18ddba8 100644 --- a/crates/ui-egui/src/menus.rs +++ b/crates/ui-egui/src/menus.rs @@ -85,6 +85,7 @@ const TITLES: &[&str] = &[ "Rotate view", "Page navigation", "Page display", + "Show/Hide", "Side panels", "Display theme", "Tools", @@ -161,6 +162,7 @@ const DISPLAY: &[&str] = &[ "view.fit_one_page", ]; const THEMES: &[&str] = &["view.theme.system", "view.theme.light", "view.theme.dark"]; +const SHOW_HIDE: &[&str] = &["view.rulers"]; const PANES: &[&str] = &["view.side_panel", "view.tools_pane", "view.split"]; const PANE_COMMANDS: &[&str] = &["comment.list", "form.fields", "ui.dock.reset"]; const MODES: &[&str] = &["view.full_screen", "view.read_mode", crate::viewer_prefs::TOGGLE]; @@ -387,6 +389,7 @@ impl PdfCraftApp { Node::submenu(tl!("Rotate view"), list(&[ROTATE_CW, ROTATE_CCW], &mut used)), Node::submenu(tl!("Page navigation"), list(NAVIGATION, &mut used)), Node::submenu(tl!("Page display"), list(DISPLAY, &mut used)), + Node::submenu(tl!("Show/Hide"), list(SHOW_HIDE, &mut used)), Node::Separator, ]; view.extend(list(PANES, &mut used)); diff --git a/crates/ui-egui/src/panels/comments_panel.rs b/crates/ui-egui/src/panels/comments_panel.rs index a2a051993c..303981acb4 100644 --- a/crates/ui-egui/src/panels/comments_panel.rs +++ b/crates/ui-egui/src/panels/comments_panel.rs @@ -5,7 +5,7 @@ //! back to engine edits, and draws the header's filter and "…" buttons for the chrome. use std::collections::HashMap; -use std::time::{SystemTime, UNIX_EPOCH}; +use std::time::UNIX_EPOCH; use craft::behavior::IconId; use craft::review::ui::comments::{CommentEdit, CommentsHeader, CommentsPanel, comments_filter_menu, comments_more_menu}; @@ -241,9 +241,8 @@ fn card_rows(doc: &pdfcraft_engine::Document, map: &ThreadMap, thread: &CommentT rows } -// PLAN: the comments area has no shared clock yet (w10's note popups read one too); this is the only read here. fn now_seconds() -> i64 { - SystemTime::now().duration_since(UNIX_EPOCH).ok().and_then(|d| i64::try_from(d.as_secs()).ok()).unwrap_or(0) + crate::platform::wall_time().duration_since(UNIX_EPOCH).ok().and_then(|d| i64::try_from(d.as_secs()).ok()).unwrap_or(0) } /// Draw the panel. Returns an edit to apply (posting, replying, deleting…). diff --git a/crates/ui-egui/src/platform.rs b/crates/ui-egui/src/platform.rs index 7b6b654104..b2bd2e9781 100644 --- a/crates/ui-egui/src/platform.rs +++ b/crates/ui-egui/src/platform.rs @@ -4,3 +4,16 @@ pub(super) mod macos_association; pub(super) mod open_worker; pub mod ui_scale; pub mod updates; + +/// Wall time for comparing PDF and filesystem timestamps on desktop and in the browser. +pub(super) fn wall_time() -> std::time::SystemTime { + #[cfg(not(target_arch = "wasm32"))] + return std::time::SystemTime::now(); + + #[cfg(target_arch = "wasm32")] + { + // File metadata uses std's timestamp type. Only the clock read needs the browser. + let since_epoch = web_time::UNIX_EPOCH.elapsed().unwrap_or_default(); + std::time::UNIX_EPOCH + since_epoch + } +} diff --git a/crates/ui-egui/src/workflows/combine_ui/table.rs b/crates/ui-egui/src/workflows/combine_ui/table.rs index c55b79961d..9a6b294d70 100644 --- a/crates/ui-egui/src/workflows/combine_ui/table.rs +++ b/crates/ui-egui/src/workflows/combine_ui/table.rs @@ -1,5 +1,4 @@ use std::cell::RefCell; -use std::time::SystemTime; use craft::behavior::{ColumnKey, ColumnWidth, DisplayOrder, EditEvent, IconId, ItemSource, ReorderKeys}; use craft::theme::variant::Tone; @@ -112,7 +111,7 @@ struct RowData { fn row_data(app: &mut PdfCraftApp, checks: &[Result]) -> Vec { let conflicts = app.combine_conflicts.per_file.clone(); let twice = app.combine_tab.duplicate_warnings(&app.combine_draft); - let now = SystemTime::now(); + let now = crate::platform::wall_time(); app.combine_draft .iter() .enumerate() diff --git a/crates/ui-egui/tests/it/editing.rs b/crates/ui-egui/tests/it/editing.rs index f2429b91d1..171ae9c2e3 100644 --- a/crates/ui-egui/tests/it/editing.rs +++ b/crates/ui-egui/tests/it/editing.rs @@ -470,6 +470,38 @@ fn command_click_toggles_and_rotation_applies_to_selection() { assert_eq!(rot, [90, 0, 90]); } +/// #8983: each Organize delete path removes the intended original pages, not merely the +/// thumbnail that happens to occupy their old positions after the page tree changes. +#[test] +fn organize_delete_targets_selected_range_and_the_clicked_tile() { + let expected = + |deleted: &[usize]| -> Vec { (1..=28).filter(|page| !deleted.contains(page)).map(|page| format!("Page {page}")).collect() }; + + let mut range = organize(28); + type_selection(&mut range, "19-23"); + range.key_press(Key::Enter); + range.run_steps(2); + assert_eq!(range.state().views[0].target_pages(), [18, 19, 20, 21, 22]); + range.get_by_label("Delete pages (Delete)").click(); + range.run_steps(3); + assert_eq!(page_texts(range.state()), expected(&[19, 20, 21, 22, 23]), "sidebar deletes the selected originals in order"); + + // Open the grid on page 20 so its virtualized tile is already in view; a different + // selection must not redirect that tile's own delete action. + let mut tile = harness(28, |app| { + app.views[0].go_to_page(19); + app.set_option(&egui::Context::default(), "organize", "on").unwrap(); + }); + tile.state_mut().views[0].select_pages(&[0, 1]); + tile.run_steps(2); + assert_eq!(tile.state().views[0].target_pages(), [0, 1]); + tile.get_by_label("Page 20").hover(); + tile.run_steps(2); + tile.get_by_label("Delete page 20").click(); + tile.run_steps(3); + assert_eq!(page_texts(tile.state()), expected(&[20]), "tile deletes its own original, not the selection"); +} + #[test] fn delete_is_refused_when_it_would_remove_every_page() { let mut h = organize(2); @@ -3287,6 +3319,95 @@ fn dragging_thumbnails_reorders_pages() { assert_eq!(sel, vec![2], "the moved page stays selected"); } +/// Retain the actual textures painted by the thumbnail grid, including those replaced after an edit. +#[derive(Clone, Default)] +struct OrganizeUploads(std::sync::Arc>>>); + +impl egui_kittest::TestRenderer for OrganizeUploads { + fn handle_delta(&mut self, delta: &mut egui::TexturesDelta) { + let mut images = self.0.lock().unwrap(); + for (id, changes) in delta.set.drain() { + for change in changes.into_iter().filter(|c| c.pos.is_none()) { + let egui::ImageData::Color(image) = change.image; + images.insert(id, image); + } + } + delta.free.clear(); + } + + fn render(&mut self, _: &egui::Context, _: &egui::FullOutput) -> Result { + Err("this renderer records texture uploads".into()) + } +} + +/// The largest uploaded picture actually drawn inside a named Organize tile. +fn organize_tile_image(h: &Harness<'static, PdfCraftApp>, uploads: &OrganizeUploads, label: &str) -> Option> { + fn collect<'a>(shape: &'a egui::Shape, out: &mut Vec<&'a egui::Shape>) { + match shape { + egui::Shape::Vec(children) => children.iter().for_each(|s| collect(s, out)), + _ => out.push(shape), + } + } + let tile = h.query_by_label(label)?.rect(); + let images = uploads.0.lock().unwrap(); + let mut shapes = Vec::new(); + h.output().shapes.iter().for_each(|s| collect(&s.shape, &mut shapes)); + shapes + .into_iter() + .filter_map(|s| { + let egui::Shape::Mesh(mesh) = s else { return None }; + let bounds = mesh.calc_bounds(); + let image = images.get(&mesh.texture_id)?; + (bounds.width() > 30.0 && bounds.height() > 30.0 && tile.contains(bounds.center()) && image.size[0] > 30 && image.size[1] > 30) + .then(|| (bounds.area(), image.clone())) + }) + .max_by(|a, b| a.0.total_cmp(&b.0)) + .map(|(_, image)| image) +} + +#[test] +fn moved_organize_page_updates_the_painted_thumbnail_in_the_same_session() { + use std::sync::Arc; + let jobs = Arc::new(craft::host::ManualJobs::new()); + let uploads = OrganizeUploads::default(); + let on = jobs.clone(); + let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).renderer(uploads.clone()).build_eframe(move |cc| { + support::install_runtime(&cc.egui_ctx); + let mut app = support::test_app(support::host_with(on.clone(), Arc::new(craft::host::ScriptedFiles::new()))); + app.set_option(&egui::Context::default(), "language", "en").unwrap(); + app.open_bytes(&egui::Context::default(), "doc.pdf", None, fixture(4)).unwrap(); + app.set_option(&egui::Context::default(), "organize", "on").unwrap(); + app + }); + let mut before_images = None; + for _ in 0..200 { + jobs.run_all(); + h.run_steps(1); + let pictures: Option> = ["Page 1", "Page 2", "Page 3"].iter().map(|label| organize_tile_image(&h, &uploads, label)).collect(); + if let Some(p) = pictures.filter(|p| p[0].pixels != p[1].pixels && p[1].pixels != p[2].pixels && p[0].pixels != p[2].pixels) { + before_images = Some(p); + break; + } + } + let before_images = before_images.expect("three visibly distinct page thumbnails are painted"); + let before = page_texts(h.state()); + let from = h.get_by_label("Page 1").rect().center(); + let to = h.get_by_label("Page 3").rect().right_center() - egui::vec2(10.0, 0.0); + page_drag(&mut h, from, to, Modifiers::NONE); + assert_eq!(page_texts(h.state()), vec![before[1].clone(), before[2].clone(), before[0].clone(), before[3].clone()]); + for _ in 0..200 { + jobs.run_all(); + h.run_steps(1); + let after: Option> = ["Page 1", "Page 2", "Page 3"].iter().map(|label| organize_tile_image(&h, &uploads, label)).collect(); + if after.is_some_and(|p| { + p[0].pixels == before_images[1].pixels && p[1].pixels == before_images[2].pixels && p[2].pixels == before_images[0].pixels + }) { + return; + } + } + panic!("the painted thumbnails did not follow the committed reorder"); +} + /// A page drag with the copy modifier held — Ctrl (Option on macOS) — instead of none. /// Modifiers are input state: `ModifiersChanged` once, as the column-select drag does. fn copy_drag(h: &mut Harness<'static, PdfCraftApp>, from: egui::Pos2, to: egui::Pos2) { diff --git a/crates/ui-egui/tests/it/forms.rs b/crates/ui-egui/tests/it/forms.rs index 862b601f20..295c2d22b3 100644 --- a/crates/ui-egui/tests/it/forms.rs +++ b/crates/ui-egui/tests/it/forms.rs @@ -396,6 +396,21 @@ fn an_open_form_editor_preserves_intentional_focus_in_another_control() { h.get_by_role_and_label(egui::accesskit::Role::SpinButton, "Zoom").focus(); h.run_steps(4); assert!(h.get_by_role_and_label(egui::accesskit::Role::SpinButton, "Zoom").is_focused()); + let (area, pages) = { + let app = h.state(); + (app.views[0].viewport_rect(), app.views[0].visible_page_rects()) + }; + let blank = [area.left_center() + egui::vec2(12.0, 0.0), area.right_center() - egui::vec2(12.0, 0.0)] + .into_iter() + .find(|p| pages.iter().all(|(_, rect)| !rect.contains(*p))) + .expect("a blank point beside the page"); + click_at(&mut h, blank); + let saved = value(&h, "first"); + let draft = h.state().views[0].session.forms.focus.as_ref().map(|f| (f.name.clone(), f.text.clone())); + assert!( + saved == ["alpha"] || draft == Some(("first".into(), "alpha".into())), + "clicking the background must preserve the dirty field: saved {saved:?}, draft {draft:?}" + ); } #[test] diff --git a/crates/ui-egui/tests/it/pointer.rs b/crates/ui-egui/tests/it/pointer.rs index 06fafa552e..e29cf4a480 100644 --- a/crates/ui-egui/tests/it/pointer.rs +++ b/crates/ui-egui/tests/it/pointer.rs @@ -385,6 +385,32 @@ fn a_drag_from_text_onto_a_link_selects_the_text() { assert!(selected.contains("example.org"), "the drag selected across the link: {selected:?}"); } +/// A scanned page can have a page-sized image plus recognized text drawn in invisible rendering mode. +#[test] +fn dragging_across_invisible_ocr_text_selects_the_words_instead_of_the_scan() { + let image = "<< /Type /XObject /Subtype /Image /Width 1 /Height 1 /ColorSpace /DeviceGray /BitsPerComponent 8 /Length 1 >>\nstream\nA\nendstream"; + let content = stream("q 300 0 0 400 0 0 cm /Scan Do Q BT /F1 12 Tf 3 Tr 40 300 Td (ONE TWO SIX END) Tj ET"); + let bytes = pdf(&[ + CATALOG, + PAGES, + "<< /Type /Page /Parent 2 0 R /Resources << /XObject << /Scan 4 0 R >> /Font << /F1 5 0 R >> >> /Contents 6 0 R >>", + image, + "<< /Type /Font /Subtype /Type1 /BaseFont /Courier /Encoding /WinAnsiEncoding >>", + &content, + ]); + let mut h = open(bytes, "150", false); + let background = at(&h, 150.0, 180.0); + mouse_click(&mut h, background); + assert!(h.state().views[0].session.picked_image.is_some(), "a click on the scan still picks its image"); + + // In 12 pt Courier each glyph is 7.2 points wide. Start inside the T and release inside the X. + let start = at(&h, 40.0 + 4.5 * 7.2, 304.0); + let end = at(&h, 40.0 + 10.5 * 7.2, 304.0); + mouse_drag(&mut h, start, end - start); + assert_eq!(h.state().views[0].selected_text().as_deref(), Some("TWO SIX")); + assert!(h.state().views[0].session.picked_image.is_none(), "the underlying image stays unselected after the drag"); +} + /// With the Select tool a click on a link over a picture follows the link and picks no picture; one /// on the picture beside the link picks it. The link's click used to pick the picture under it too. #[test] diff --git a/crates/ui-egui/tests/it/ui.rs b/crates/ui-egui/tests/it/ui.rs index cab97e322a..1627c36616 100644 --- a/crates/ui-egui/tests/it/ui.rs +++ b/crates/ui-egui/tests/it/ui.rs @@ -2263,3 +2263,37 @@ fn unused_document_tab_space_moves_and_zooms_the_window(os: craft::window::polic support::input::one_frame(&mut h, [egui::Event::PointerMoved(empty + egui::vec2(20.0, 0.0))]); assert!(h.output().viewport_output[&egui::ViewportId::ROOT].commands.contains(&egui::ViewportCommand::StartDrag)); } + +/// #8999: the reader, rather than the zoom spin button, gets keys after a click beside a page. +#[test] +fn clicking_blank_page_view_returns_keyboard_from_zoom() { + let mut h = harness(|app| { + app.open_bytes(&egui::Context::default(), "rail.pdf", None, FIXTURE.to_vec()).unwrap(); + app.set_option(&egui::Context::default(), "zoom", "50").unwrap(); + }); + h.get_by_role_and_label(egui::accesskit::Role::SpinButton, "Zoom").focus(); + h.run_steps(3); + assert!(h.get_by_role_and_label(egui::accesskit::Role::SpinButton, "Zoom").is_focused(), "zoom keeps intentional focus without a click"); + let (area, pages) = { + let app = h.state(); + (app.views[0].viewport_rect(), app.views[0].visible_page_rects()) + }; + let p = [area.left_center() + egui::vec2(12.0, 0.0), area.right_center() - egui::vec2(12.0, 0.0)] + .into_iter() + .find(|p| pages.iter().all(|(_, rect)| !rect.contains(*p))) + .expect("a blank point beside the page"); + h.hover_at(p); + h.run_steps(1); + h.drag_at(p); + h.run_steps(1); + h.drop_at(p); + h.run_steps(3); + assert!(!h.get_by_role_and_label(egui::accesskit::Role::SpinButton, "Zoom").is_focused(), "the pasteboard click leaves the zoom editor"); + let before = h.state().views[0].view.zoom; + h.key_press(egui::Key::ArrowDown); + h.run_steps(3); + assert_eq!(h.state().views[0].view.zoom, before, "reader keys do not edit zoom"); + h.get_by_role_and_label(egui::accesskit::Role::TextInput, "Current page").focus(); + h.run_steps(3); + assert!(h.get_by_role_and_label(egui::accesskit::Role::TextInput, "Current page").is_focused(), "other controls retain intentional focus"); +} diff --git a/crates/ui-egui/tests/it/viewer.rs b/crates/ui-egui/tests/it/viewer.rs index 7483a65f96..c817b803ea 100644 --- a/crates/ui-egui/tests/it/viewer.rs +++ b/crates/ui-egui/tests/it/viewer.rs @@ -2941,3 +2941,52 @@ fn the_accessible_window_has_the_window_title_as_its_name() { assert_eq!(name(&h).as_deref(), Some("Quarterly report • — PdfCraft")); assert_eq!(name(&h), Some(h.state().window_title.clone())); } + +/// View ▸ Show/Hide ▸ Rulers (`view.rulers`, `Ctrl+R` / `⌘R`): toggles the top and left rulers, +/// reports the state through the control channel, reserves `RULER_THICKNESS` so pages are not +/// covered, and restores the full page area when turned off. +#[test] +fn rulers_toggle_reserves_space_and_reports_state() { + use pdfcraft_ui_egui::canvas::rulers::RULER_THICKNESS; + let (tx, rx) = std::sync::mpsc::channel(); + let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |cc| { + crate::support::install_runtime(&cc.egui_ctx); + let mut app = crate::control::new_app(); + app.set_option(&egui::Context::default(), "language", "en").unwrap(); + app.attach_control(craft::automation::ControlChannel::new(rx), None); + app.open_bytes(&egui::Context::default(), "a.pdf", None, fixture(2)).unwrap(); + app + }); + h.run_steps(4); + + let initial = crate::control::ok(&mut h, &tx, "ui.state", json!({})); + assert_eq!(initial["rulers"], false); + assert_eq!(initial["active"]["rulers"], false); + let before = h.state().views[0].viewport_rect(); + + // Toggle rulers on: state reports it and page viewport shrinks by RULER_THICKNESS on top and left. + assert!(h.execute("view.rulers")); + h.run_steps(3); + let shown = crate::control::ok(&mut h, &tx, "ui.state", json!({})); + assert_eq!(shown["rulers"], true); + assert_eq!(shown["active"]["rulers"], true); + let after = h.state().views[0].viewport_rect(); + assert!((after.min.x - before.min.x - RULER_THICKNESS).abs() < 0.5, "left edge reserved: before={before:?} after={after:?}"); + assert!((after.min.y - before.min.y - RULER_THICKNESS).abs() < 0.5, "top edge reserved: before={before:?} after={after:?}"); + assert!((before.width() - after.width() - RULER_THICKNESS).abs() < 0.5, "width shrunk by ruler thickness"); + assert!((before.height() - after.height() - RULER_THICKNESS).abs() < 0.5, "height shrunk by ruler thickness"); + + // Control option rejects invalid values with an error naming the allowed ones. + let err = h.set_option("rulers", "maybe").unwrap_err(); + assert!(err.contains("on") && err.contains("off"), "unexpected error: {err}"); + + // Toggle rulers off: state reports false and viewport returns to its full area. + assert!(h.execute("view.rulers")); + h.run_steps(3); + let hidden = crate::control::ok(&mut h, &tx, "ui.state", json!({})); + assert_eq!(hidden["rulers"], false); + assert_eq!(hidden["active"]["rulers"], false); + let restored = h.state().views[0].viewport_rect(); + assert!((restored.min.x - before.min.x).abs() < 0.5 && (restored.min.y - before.min.y).abs() < 0.5); + assert!((restored.width() - before.width()).abs() < 0.5 && (restored.height() - before.height()).abs() < 0.5); +} diff --git a/parity/acrobat-features.toml b/parity/acrobat-features.toml index 753fdc4154..7fef04635b 100644 --- a/parity/acrobat-features.toml +++ b/parity/acrobat-features.toml @@ -1630,11 +1630,18 @@ title = "Rulers" area = "B" tier = "P2" milestone = "M12" -status = "planned" -commands = [] +status = "shipped" +commands = ["view.rulers"] tools = [] -evidence = [] -notes = "" +evidence = [ + "crates/ui-egui/src/canvas/rulers.rs::nice_interval_picks_1_2_5_multiples_across_zooms_and_units", + "crates/ui-egui/src/canvas/rulers.rs::tick_positions_anchor_to_page_offset", + "crates/ui-egui/src/canvas/rulers.rs::label_formatting_is_clean_and_has_no_negative_zero", + "crates/ui-egui/src/canvas/rulers.rs::tick_cap_bounds_output_on_dense_ranges", + "crates/ui-egui/src/canvas/rulers.rs::degenerate_inputs_do_not_panic_or_loop", + "crates/ui-egui/tests/it/viewer.rs::rulers_toggle_reserves_space_and_reports_state", +] +notes = "View ▸ Show/Hide ▸ Rulers (Ctrl+R / ⌘R): horizontal and vertical rulers reserved along the top and left of the page area in the configured measurement units, anchored to the page under the pointer (or current page) in its displayed orientation, with zoom-adaptive 1/2/5 intervals, capped ticks, cursor marks while hovering a page, persistence, and control channel support" [[feature]] id = "view.grid" From 6d1677e887cd450ae0ed53f9e0ce3cbfcee6fe12 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Fri, 4 Dec 2026 16:41:30 +0100 Subject: [PATCH 7/8] Port release fixes to main: libs-api (#9312) * chore(deps): pin craft-libs to the rev the 0.23.2 release builds against (9888a5855) Release has built against craft-libs 9888a585 since 0.23.2; main stayed on 6afe03f5b, so main could not take the release-only UI fixes that use the newer craft-libs APIs (centred TextField, tab wheel browsing, bounded document preview width, wheel messages for fitted page spreads). This moves main to the same rev; Cargo.lock only changes the craft-libs source. The 12 craft-libs commits behind this rev are being put on craft-libs main in https://github.com/storytold/craft-libs/pull/5306. Co-Authored-By: Claude Sonnet 5.5 * Let the mouse wheel browse overflowing PDF tabs in either pane (cherry picked from commit ba286d585a4691b98ec1eb98a4c99b9df5de8149) (cherry picked from commit 3827fe059a92818e84f3257c55fabeae34b938db) * Exercise wheel browsing on real overflowing PdfCraft document tabs (cherry picked from commit 021c744c0dff19e070a926190368d0612db11af6) (cherry picked from commit 18284fee734420e1413cde1d021c68789a15ebff) * Enlarge header and footer page preview (cherry picked from commit f90e3d1c83b23dea32cdb75d2e9638e594409b92) (cherry picked from commit a0f1f51c06c111b96e5cc8bbd6b8137890edb919) * Place page content on physical pixels for sharp text at normal zoom (cherry picked from commit a2d040ce0836d6cc3a4174e954b412197044d902) Ported without the craft-libs rev bumps the release commit also carried: the pin is already 9888a5855 (stacked on #9308). * Restore Windows wheel flicks across fitted document spreads (cherry picked from commit c40a2683f820470dd3e9f1a6067223c1498ac7ac) Ported without the craft-libs rev bumps the release commit also carried: the pin is already 9888a5855 (stacked on #9308). * Keep the Windows caption cursor as an arrow (cherry picked from commit 53a014bf1d4368e6fbd3f97ca5a5ae08019f5a05) * Center page navigation and fit page size hint (#8989) (cherry picked from commit 04c0aa7c73f9f9ffeb8cda90645a571a05c19afa) --------- Co-authored-by: FredApps Co-authored-by: Claude Sonnet 5.5 Co-authored-by: Codex --- crates/ui-egui/src/app.rs | 3 + crates/ui-egui/src/canvas.rs | 2 + crates/ui-egui/src/canvas/bars.rs | 13 ++--- crates/ui-egui/src/chrome/doc_tabs.rs | 2 + crates/ui-egui/src/chrome/view_rail.rs | 1 + crates/ui-egui/src/dialogs/marks_ui.rs | 4 ++ crates/ui-egui/tests/it/marks.rs | 18 ++++++ crates/ui-egui/tests/it/ui.rs | 81 ++++++++++++++++++++++++++ 8 files changed, 116 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index 1038a13ec1..9310c3cc35 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -604,6 +604,9 @@ impl PdfCraftApp { root.set_theme(theme); } root.sizes = Arc::clone(sizes); + // Windows caption buttons and the free title band keep the normal arrow while remaining draggable. + #[cfg(windows)] + root.values.set(craft::ui::contract::MoveBandCursor::Arrow); // Every parameter dialog lays out as a document dialog: inline captions, shaded groups, buttons across the foot. root.values.set(craft::ui::patterns::form_dialogs::DialogLayout(craft::ui::patterns::form_dialogs::ParamLayout::Document)); // PdfCraft's looks, opt-in over the framework's defaults: the filled dropdown triangle, shrinking document diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 13707d4d5a..eab3f48d9b 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -1893,6 +1893,8 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu .border(border) .pasteboard(surround) .keep(&keep) + .pixel_aligned_pages() + .turn_per_line_event(cfg!(target_os = "windows")) // Production's Go To: the page gap above the page's top. .go_to_place(GoToPlace::GapAbove) .fill_screen(fill_screen) diff --git a/crates/ui-egui/src/canvas/bars.rs b/crates/ui-egui/src/canvas/bars.rs index d309b6f7c7..7c233b2694 100644 --- a/crates/ui-egui/src/canvas/bars.rs +++ b/crates/ui-egui/src/canvas/bars.rs @@ -21,14 +21,11 @@ pub(super) fn page_size_hint(ui: &mut egui::Ui, body: &PageBody<'_>, page: &pdfc return; } let text = units.size(f64::from(page.width), f64::from(page.height)); - // PLAN: a card notice is the framework's floating label with no interaction; its own surface padding is the inset. - // Shrink-wrapped to its text, a little in from the corner, as production's pill sits. - let font = egui::TextStyle::Body.resolve(ui.style()); - let wide = ui.painter().layout_no_wrap(text.to_string(), font, egui::Color32::WHITE).size().x + 40.0; - let corner = egui::Rect::from_min_max( - egui::pos2(body.rect.min.x + 10.0, body.rect.min.y), - egui::pos2(body.rect.min.x + 10.0 + wide, body.rect.max.y - 10.0), - ); + // The card measures its own text and surface padding in the active theme. Give it the + // available document width instead of guessing that width with egui's unrelated Body font. + let left = (body.rect.min.x + 10.0).min(body.rect.max.x); + let right = (body.rect.max.x - 10.0).max(left); + let corner = egui::Rect::from_min_max(egui::pos2(left, body.rect.min.y), egui::pos2(right, (body.rect.max.y - 10.0).max(body.rect.min.y))); let builder = egui::UiBuilder::new().max_rect(corner).layout(egui::Layout::bottom_up(egui::Align::Min)).sense(egui::Sense::hover()); ui.scope_builder(builder, |ui| { Bar::new(Tone::Neutral, text).layout(NoticeLayout::Card).icon(NoticeIcon::None).show(ui); diff --git a/crates/ui-egui/src/chrome/doc_tabs.rs b/crates/ui-egui/src/chrome/doc_tabs.rs index f4af6c470e..6c5aa66c5d 100644 --- a/crates/ui-egui/src/chrome/doc_tabs.rs +++ b/crates/ui-egui/src/chrome/doc_tabs.rs @@ -58,8 +58,10 @@ pub(crate) fn strip(app: &mut PdfCraftApp, ui: &mut egui::Ui, place: Place) { let source = keyed(&entries, |entry: &StripEntry| entry.key.clone()).with_text(|entry: &StripEntry| Cow::Borrowed(entry.label.as_str())); let item_count = entries.len(); let entries_ref = &entries; + let wheel_viewport = ui.scope_id().with(("document tab wheel viewport", place)); let make_strip = || { let mut strip = TabStrip::new(strip_label.clone()) + .wheel_browse(wheel_viewport) .takes_drop(DropKind::new(DropPlace::Between, |_: &ListDrag, _| true)) .can_close(move |key: &StripTab| entries_ref.iter().any(|entry| &entry.key == key && entry.closable)) .reorder(ReorderRule::new()) diff --git a/crates/ui-egui/src/chrome/view_rail.rs b/crates/ui-egui/src/chrome/view_rail.rs index 2c5114f8ec..ca4c6ce792 100644 --- a/crates/ui-egui/src/chrome/view_rail.rs +++ b/crates/ui-egui/src/chrome/view_rail.rs @@ -39,6 +39,7 @@ pub(crate) fn show(app: &mut PdfCraftApp, ui: &mut Ui) { let (field_rect, _) = ui.allocate_exact_size(field_size, egui::Sense::hover()); let edit = TextField::new("Current page", Bind::bound(&mut view.page_input)) .id(input_id) + .centred() .select_on_focus() .select_all(reselect) .submits() diff --git a/crates/ui-egui/src/dialogs/marks_ui.rs b/crates/ui-egui/src/dialogs/marks_ui.rs index 6544ee85ff..919a15f43a 100644 --- a/crates/ui-egui/src/dialogs/marks_ui.rs +++ b/crates/ui-egui/src/dialogs/marks_ui.rs @@ -1327,6 +1327,10 @@ impl PdfCraftApp { Text::new(tl!("Replaces the existing one on those pages.")).show(ui); } }); + if kind == MarkKind::HeaderFooter { + // Restore a readable page sample without enlarging other document dialogs. + dialog = dialog.document_preview_width(142.5); + } if let Some(reason) = ¬es.reason { dialog = dialog.ok_reason(reason.clone().into()); } diff --git a/crates/ui-egui/tests/it/marks.rs b/crates/ui-egui/tests/it/marks.rs index 6286a662ab..218e5abea1 100644 --- a/crates/ui-egui/tests/it/marks.rs +++ b/crates/ui-egui/tests/it/marks.rs @@ -715,6 +715,24 @@ fn the_preview_shows_the_page_the_range_selects_under_the_marks() { assert_eq!(tint, egui::Color32::from_rgb(red, green, blue), "the default background colour, opaque"); } +/// #9009: the page sample is large enough to inspect placement and keeps its page geometry. +#[test] +fn header_footer_preview_is_larger_and_keeps_its_overlay_and_pager() { + let mut h = harness(); + assert!(h.execute("edit.header_footer")); + h.steps(3); + type_into(&mut h, BOX_LABELS[1], "TOP"); + let Picture { at, rect: page, .. } = wait_for_preview(&mut h, "header page", |_| true); + assert!(page.height() >= 170.0, "the page is readable at the normal window size: {page:?}"); + assert!((page.width() / page.height() - 0.75).abs() < 0.02, "the whole page keeps its aspect: {page:?}"); + let (text_at, top) = painted(&h, "TOP", page); + assert!(at < text_at, "the header is drawn above the page picture"); + near(top.center().x, page.center().x, "centre header, across"); + near(top.center().y, page.top() + 36.0 * page.width() / 300.0, "centre header, down"); + show_page(&mut h, 1); + assert_eq!(pager(&h).0, 2, "the enlarged preview still steps pages"); +} + #[test] fn the_preview_steps_through_the_pages_and_starts_at_the_current_one() { let mut h = harness(); diff --git a/crates/ui-egui/tests/it/ui.rs b/crates/ui-egui/tests/it/ui.rs index 1627c36616..f24b1b6b8f 100644 --- a/crates/ui-egui/tests/it/ui.rs +++ b/crates/ui-egui/tests/it/ui.rs @@ -761,6 +761,52 @@ fn tabs_shrink_to_fit_then_arrows_step_through_them_and_open_stays_in_sight() { assert!(open.left() > 0.0 && open.right() <= discord.left(), "Open {open:?} stays in sight left of Discord {discord:?}"); } +#[test] +fn the_wheel_reveals_overflowing_document_tabs_without_switching_documents() { + use egui::accesskit::Role; + const COUNT: usize = 20; + let name = |i: usize| format!("Statement {i:02} for the office records, scanned.pdf"); + let mut h = harness(move |app| { + for i in 0..COUNT { + app.open_bytes(&egui::Context::default(), &name(i), None, FIXTURE.to_vec()).unwrap(); + } + }); + h.get_by_role_and_label(Role::Tab, &name(0)).click(); + h.run_steps(4); + let active = h.state().views[0].id; + let visible = |h: &Harness<'static, PdfCraftApp>| -> Vec { + (0..COUNT).filter(|&i| h.query_by_role_and_label(Role::Tab, &name(i)).is_some()).collect() + }; + let before = visible(&h); + assert!(before.contains(&0) && before.len() < COUNT); + assert_eq!(h.state().active_ids().map(|(_, id)| id), Some(active)); + h.get_by_label("More tabs"); + let over = h.get_by_role_and_label(Role::Tab, &name(0)).rect().center(); + h.hover_at(over); + h.run_steps(1); + h.event(egui::Event::MouseWheel { + unit: egui::MouseWheelUnit::Line, + delta: egui::vec2(0.0, -1.0), + phase: egui::TouchPhase::Move, + modifiers: egui::Modifiers::NONE, + source: egui::MouseWheelSource::Wheel, + }); + h.run_steps(4); + let after = visible(&h); + assert!(!after.contains(&0), "the active document's tab can move out of sight"); + let revealed = after.into_iter().find(|i| !before.contains(i)).expect("a previously hidden tab is visible"); + assert_eq!(h.state().active_ids().map(|(_, id)| id), Some(active)); + h.get_by_label("More tabs").click(); + h.run_steps(3); + h.get_by_label(&name(0)); // The active document still appears in the overflow menu. + h.key_press(egui::Key::Escape); + h.run_steps(3); + let expected = h.state().views[revealed].id; + h.get_by_role_and_label(Role::Tab, &name(revealed)).click(); + h.run_steps(3); + assert_eq!(h.state().active_ids().map(|(_, id)| id), Some(expected)); +} + #[test] fn garbage_input_is_rejected_without_panicking() { let mut app = crate::control::new_app(); @@ -1967,6 +2013,41 @@ fn the_edit_panel_keeps_the_add_update_remove_menu() { h.get_by_label("Cancel"); } +/// #8989: the editable page label is centred in its rail field without changing navigation, +/// and the page-size hint has room for its whole text inside the document area. +#[test] +fn page_rail_value_is_centred_and_page_size_hint_fits() { + let mut h = harness(|app| { + app.open_bytes(&egui::Context::default(), "rail.pdf", None, FIXTURE.to_vec()).unwrap(); + }); + let page_field = |h: &Harness<'static, PdfCraftApp>| h.get(By::new().role(egui::accesskit::Role::TextInput).label("Current page")).rect(); + let check = |h: &Harness<'static, PdfCraftApp>, value: &str| { + let field = page_field(h); + let text = painted_text(h).into_iter().find(|(s, _, r)| s == value && field.contains_rect(*r)).expect("the page value is painted"); + assert!(!text.1 && (text.2.center().x - field.center().x).abs() <= 3.0, "{text:?} in {field:?}"); + assert!((text.2.center().y - field.center().y).abs() <= 2.0, "{text:?} in {field:?}"); + }; + check(&h, "1"); + h.get(By::new().role(egui::accesskit::Role::TextInput).label("Current page")).focus(); + h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A); + h.get(By::new().role(egui::accesskit::Role::TextInput).label("Current page")).type_text("2"); + h.key_press(egui::Key::Enter); + h.run_steps(3); + assert_eq!(h.state().views[0].current(), 1, "the centred field still navigates"); + check(&h, "2"); + + let area = h.state().views[0].viewport_rect(); + let size = { + let app = h.state(); + let p = &app.session.get(app.views[0].id).unwrap().info.pages[1]; + app.units.size(f64::from(p.width), f64::from(p.height)) + }; + h.event(egui::Event::PointerMoved(area.left_bottom() + egui::vec2(80.0, -80.0))); + h.run_steps(3); + let text = painted_text(&h).into_iter().find(|(s, _, _)| s == &size).expect("the page size is painted"); + assert!(!text.1 && area.contains_rect(text.2), "whole size {text:?} inside {area:?}"); +} + /// #3282: in a short window the rail's panel buttons scroll above the page navigation instead of /// being drawn under the page number field. #[test] From bfc45e43840fdcea05793c94691f02bcbe006a9d Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Fri, 4 Dec 2026 16:42:05 +0100 Subject: [PATCH 8/8] Port release fixes to main: dock-layout (#9311) * chore(deps): pin craft-libs to the rev the 0.23.2 release builds against (9888a5855) Release has built against craft-libs 9888a585 since 0.23.2; main stayed on 6afe03f5b, so main could not take the release-only UI fixes that use the newer craft-libs APIs (centred TextField, tab wheel browsing, bounded document preview width, wheel messages for fitted page spreads). This moves main to the same rev; Cargo.lock only changes the craft-libs source. The 12 craft-libs commits behind this rev are being put on craft-libs main in https://github.com/storytold/craft-libs/pull/5306. Co-Authored-By: Claude Sonnet 5.5 * fix(ui): align navigation and menu controls and fit the All tools dock (cherry picked from commit 9877f32c7e21b44224b0592b6b56d7d9c6b525c3) * test(ui): cover the docked toolbar gear and chrome alignment (cherry picked from commit db0a90bbae746d13d9571021a32c518ee2b1f7e3) * fix(ui): preserve fitted tool widths across launch and list expansion (cherry picked from commit ab290c34aebc6e0313d75dffc18e5a742082af9d) * Keep the menu and mode controls aligned and maintain page width when editing (cherry picked from commit 57ff1524a4018bda05da446f43776c1733dd3d65) * Keep room for document tools while sizing the Home list to its labels (cherry picked from commit 1dfd996c5c163c5b0e13e0264128ca1a5b457c20) * Check that the All tools heading aligns with its list on Home (cherry picked from commit 42ab49f7f197d34f508bb43bc877ca38b246effe) * Fit horizontally docked toolbar to its wrapped controls (cherry picked from commit c97b8120b816f20dbbdaf6bb1201b52519d2d5ba) * Exercise top and bottom toolbar docking at two window widths (cherry picked from commit 5cc98a8448967509d7e4c47095458904e46eeaa7) * Account for the themed minimum pane height in toolbar layout checks (cherry picked from commit ce7f8548b723be20a69b02bc2b71c7fe3fa9241a) * Measure unused space on both sides of the bottom toolbar (cherry picked from commit 91eb17547e4d25ea0afc850f8fbd3bf9ee476e1d) * Exercise protected document controls and localized prompts after layout settles (cherry picked from commit 04bf3e7e252f62005d0d5aa2e0c2ec342045409a) * Check notice text and dismiss geometry in both announcement layouts (cherry picked from commit 854a60ad131b9f611495c9b3073e38351d24b48e) Adapted: card.children().next().is_some() replaces the unstable ExactSizeIterator::is_empty, which does not compile on stable. --------- Co-authored-by: FredApps Co-authored-by: Claude Sonnet 5.5 Co-authored-by: Codex --- crates/ui-egui/src/app.rs | 2 +- crates/ui-egui/src/chrome/mode_bar.rs | 8 +- crates/ui-egui/src/chrome/view_rail.rs | 4 + crates/ui-egui/src/frame_guard.rs | 2 +- crates/ui-egui/src/hotbar.rs | 3 + crates/ui-egui/src/lib.rs | 5 +- crates/ui-egui/src/panels/side_panels.rs | 96 ++++++++++++------- crates/ui-egui/src/panels/tools.rs | 25 ++++- .../ui-egui/src/platform/open_worker/tests.rs | 6 +- crates/ui-egui/tests/it/control.rs | 51 ++++++++++ crates/ui-egui/tests/it/editing.rs | 33 ++++--- crates/ui-egui/tests/it/javascript.rs | 3 + crates/ui-egui/tests/it/min_window.rs | 10 ++ 13 files changed, 191 insertions(+), 57 deletions(-) diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index 9310c3cc35..a4af306d9a 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -309,7 +309,7 @@ impl PdfCraftApp { last_right: RightPanel::Comments, notice_inset: 0.0, toolbar_tools_open: true, - window_narrow: false, + default_tools_width: crate::panels::side_panels::TOOLS_WIDTH, right_before_read: None, comments_panel_closed: false, right_panel_closed: false, diff --git a/crates/ui-egui/src/chrome/mode_bar.rs b/crates/ui-egui/src/chrome/mode_bar.rs index 4134cf7f7d..8940a5e9a7 100644 --- a/crates/ui-egui/src/chrome/mode_bar.rs +++ b/crates/ui-egui/src/chrome/mode_bar.rs @@ -6,7 +6,7 @@ use craft::behavior::{DisplayOrder, IconId, ItemSource, SelectionChange}; use craft::keymap::CommandRef; use craft::ui::bars::{Bar, BarKind}; use craft::ui::buttons::{CommandSearch, IconButton}; -use craft::ui::contract::{Bind, CollectionEvent, Props as _, Show as _, ShowCollection as _, ShowContainer as _}; +use craft::ui::contract::{Bind, CollectionEvent, Pad, Props as _, Show as _, ShowCollection as _, ShowContainer as _}; use craft::ui::layout_components::Row; use craft::ui::menu::HelpEntry; use craft::ui::patterns::panels::CommandPalette; @@ -48,7 +48,8 @@ pub(super) fn show(app: &mut PdfCraftApp, ui: &mut egui::Ui) { let menus = app.native_menu.is_none() && !hidden.menubar; Row::new().show(ui, |ui, _| { if menus { - app.menu_bar_ui(ui); + // The mode bar insets its controls by the control pad. Give the menu titles the same inset. + Row::new().pad(Pad::Control).show(ui, |ui, _| app.menu_bar_ui(ui)); } // Production replaces the search field with its icon when the field cannot keep its minimum width. let compact_search = ui.available_width() < 140.0 + 116.0; @@ -84,7 +85,8 @@ pub(super) fn show(app: &mut PdfCraftApp, ui: &mut egui::Ui) { Some(at) => strip.shown(at), None => strip, }; - let out = strip.show_items(ui, &ModeTabs, &mut |key, _| Tab::new(tl!(MODES[*key % MODES.len()].1))); + let out = strip + .show_items(ui, &ModeTabs, &mut |key, _| Tab::new(tl!(MODES[*key % MODES.len()].1)).text_role(craft::theme::TypeRole::Label)); for event in out.response.events { if let CollectionEvent::Selection(SelectionChange::Set(keys)) = event && let Some((mode, _)) = keys.last().and_then(|at| MODES.get(*at)) diff --git a/crates/ui-egui/src/chrome/view_rail.rs b/crates/ui-egui/src/chrome/view_rail.rs index ca4c6ce792..f0dd5c06a6 100644 --- a/crates/ui-egui/src/chrome/view_rail.rs +++ b/crates/ui-egui/src/chrome/view_rail.rs @@ -17,6 +17,10 @@ use crate::PdfCraftApp; /// Shows the rail's view cluster; nothing without an active document or a current page to view. pub(crate) fn show(app: &mut PdfCraftApp, ui: &mut Ui) { + ui.with_layout(egui::Layout::top_down(egui::Align::Center), |ui| controls(app, ui)); +} + +fn controls(app: &mut PdfCraftApp, ui: &mut Ui) { let Some((index, id)) = app.active_ids() else { return }; let Some(doc) = app.session.get(id) else { return }; let page_count = doc.info.pages.len(); diff --git a/crates/ui-egui/src/frame_guard.rs b/crates/ui-egui/src/frame_guard.rs index f63ab257ca..b0386361ee 100644 --- a/crates/ui-egui/src/frame_guard.rs +++ b/crates/ui-egui/src/frame_guard.rs @@ -193,7 +193,7 @@ mod tests { h.state_mut().panic_next = None; h.run_steps(2); assert_eq!(h.state().views.len(), 2); - h.get_by_label_contains("injected Logic panic"); + assert!(h.query_all_by_label_contains("injected Logic panic").next().is_some(), "the logic panic is reported"); assert_eq!(snapshots(&store), 1); let ctx = h.ctx.clone(); diff --git a/crates/ui-egui/src/hotbar.rs b/crates/ui-egui/src/hotbar.rs index 1616324c36..f55f9d957a 100644 --- a/crates/ui-egui/src/hotbar.rs +++ b/crates/ui-egui/src/hotbar.rs @@ -39,6 +39,9 @@ const SLOT_USER: SlotId = 100; #[derive(Clone, Debug, Default, Serialize, Deserialize)] #[serde(default)] pub(crate) struct Hotbar { + /// The width offered by the dock for laying out the toolbar on the last pass. + #[serde(skip)] + pub(crate) layout_width: Option, /// The commands the user put on the toolbar, in order. pub tools: Vec, /// The tool each slot showed last. diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 224bfbd2fa..8a8fb58386 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -309,9 +309,8 @@ pub struct PdfCraftApp { /// Whether the Tools pane was in the dock when the floating toolbar was last placed: the toolbar follows the page area's /// left edge as the pane closes and opens. pub(crate) toolbar_tools_open: bool, - /// Whether the window was narrow (under [`panels::side_panels::NARROW_WINDOW`]) when the Tools pane's width was last set: a - /// narrow window keeps the pane at production's width, a wide one gives it the width Format text needs. - pub(crate) window_narrow: bool, + /// The last automatic Tools width, for preserving a user-resized dock. + pub(crate) default_tools_width: f32, /// The right panel that was open when the user switched to Read mode, which starts with the /// panes closed; leaving Read mode brings it back unless the user opened or closed a pane in /// Read mode meanwhile. diff --git a/crates/ui-egui/src/panels/side_panels.rs b/crates/ui-egui/src/panels/side_panels.rs index 467c28d5a7..c804f5249d 100644 --- a/crates/ui-egui/src/panels/side_panels.rs +++ b/crates/ui-egui/src/panels/side_panels.rs @@ -10,13 +10,14 @@ use std::sync::Arc; #[cfg(not(target_arch = "wasm32"))] use craft::automation::dock as dock_rpc; use craft::behavior::dock::{ - Action, Column, DockEdge, DockError, DockPlacement, Floating, Group, Layout, Node, PanelState, Permissions, SplitSize, Target, Workspace, + Action, Column, DockEdge, DockError, DockPlacement, Floating, Group, Layout, Node, PanelPlace, PanelState, Permissions, SplitSize, Target, + Workspace, node_at, }; use craft::behavior::{Axis, DockSide, IconId}; use craft::keymap::CommandRef; use craft::ui::buttons::IconButton; -use craft::ui::contract::{Bind, BodyCx, PlainData, Props as _, Show as _}; -use craft::ui::docking::{DockConfig, DockPanels, GroupAt, HidePanels, IconicMode, PanelKey, PanelSpec, PanelSpecs}; +use craft::ui::contract::{Bind, BodyCx, PlainData, Props as _, Show as _, SizeLimits}; +use craft::ui::docking::{DockConfig, DockPanels, DockSizes, GroupAt, HidePanels, IconicMode, PanelKey, PanelSpec, PanelSpecs}; use craft::ui::menu::PanelRow; use craft::ui::patterns::dock::DockArea; use craft::ui::primitives::IconSpec; @@ -171,18 +172,13 @@ const PAGE_SHARE: f32 = 0.8; /// The Tools pane's default width: production's 272 points at every window width (the framework's Format text row keeps the /// size field readable in it). -const TOOLS_WIDTH: f32 = 272.0; -/// The Tools pane's width in a narrow window, as production opened it. -const TOOLS_WIDTH_NARROW: f32 = 272.0; +pub(crate) const TOOLS_WIDTH: f32 = 272.0; /// How far past the Tools pane the floating toolbar starts. Production's quick bar stood 14 points into a narrow margin /// and was 46 points wide, so its page-side edge was 60 points into the page area (which starts 3 points past the pane, /// after the splitter); the rail is 52 points wide, so it starts 10 points past the pane to end just inside that edge /// and leave the page's margin beyond it to the page. const TOOLBAR_INSET: f32 = 10.0; -/// Windows narrower than this keep the Tools pane at [`TOOLS_WIDTH_NARROW`]: a wider pane would leave the page area too little. -pub(crate) const NARROW_WINDOW: f32 = 900.0; - /// The arrangement of a new install: Tools at the start edge, the side-panel rail at the window edge, /// and the toolbar floating at the start of the page area. The side panels form one collapsed group. pub fn default_workspace(rail_side: DockSide) -> Workspace { @@ -210,7 +206,11 @@ fn keep_toolbar_in_the_margin(app: &mut PdfCraftApp) { app.toolbar_tools_open = open; let Some(rect) = toolbar_rect(&app.dock) else { return }; let x = rect.min.x; - let target = if open { (x < TOOLS_WIDTH).then_some(x + TOOLS_WIDTH) } else { (x >= TOOLS_WIDTH).then_some((x - TOOLS_WIDTH).max(0.0)) }; + let target = if open { + (x < app.default_tools_width).then_some(x + app.default_tools_width) + } else { + (x >= app.default_tools_width).then_some((x - app.default_tools_width).max(0.0)) + }; if let Some(x) = target.filter(|x| x.is_finite()) { move_toolbar(app, rect.translate(egui::vec2(x - rect.min.x, 0.0))); } @@ -226,29 +226,32 @@ fn move_toolbar(app: &mut PdfCraftApp, rect: egui::Rect) { drop(Arc::make_mut(&mut app.dock).apply(Action::move_floating(PanelId::Toolbar, rect), false, permissions)); } -/// The Tools pane's width follows the window across [`NARROW_WINDOW`]: production's narrower pane in a small window, the -/// wider default in a large one. Only the crossing changes it, so a width the user dragged to is kept. -fn fit_tools_to_window(app: &mut PdfCraftApp, window_width: f32) { - let narrow = window_width.is_finite() && window_width < NARROW_WINDOW; - if narrow == app.window_narrow { +/// Home fits the localized tool list. An open document also needs room for the editing controls +/// that share this dock, so switching tools keeps both the controls and the page in place. +fn fit_tools_to_window(app: &mut PdfCraftApp, ui: &Ui) { + let list_width = super::tools::all_tools_width(ui, app.all_tools_expanded); + let width = if app.active.is_some() { list_width.max(TOOLS_WIDTH) } else { list_width }; + let previous = app.default_tools_width; + if (width - previous).abs() < 1.0 { return; } - app.window_narrow = narrow; - if !app.dock.layout().contains(&PanelId::Tools) { + let Some(edge) = edge_of(&app.dock, PanelId::Tools) else { return }; + let column_width = dock_columns(&app.dock, edge).iter().find(|col| col.panels().any(|p| *p == PanelId::Tools)).and_then(|col| col.width); + if column_width.is_some_and(|current| (current - width).abs() < 1.0) { + app.default_tools_width = width; return; } - let width = if narrow { TOOLS_WIDTH_NARROW } else { TOOLS_WIDTH }; - // A refused resize (a locked layout) leaves the width as it is. - if Arc::make_mut(&mut app.dock).apply(Action::resize_column(PanelId::Tools, width), false, permissions).is_err() { + if column_width.is_some_and(|current| (current - previous).abs() >= 1.0) { return; } - // The floating toolbar sits in the page area's margin, which moved with the pane's edge. - let shift = if narrow { TOOLS_WIDTH_NARROW - TOOLS_WIDTH } else { TOOLS_WIDTH - TOOLS_WIDTH_NARROW }; - if app.toolbar_tools_open - && let Some(rect) = toolbar_rect(&app.dock) - && rect.min.x >= TOOLS_WIDTH_NARROW - { - move_toolbar(app, rect.translate(egui::vec2(shift, 0.0))); + if Arc::make_mut(&mut app.dock).apply(Action::resize_column(PanelId::Tools, width), false, permissions).is_ok() { + app.default_tools_width = width; + if app.toolbar_tools_open + && let Some(rect) = toolbar_rect(&app.dock) + && (rect.left() - previous - TOOLBAR_INSET).abs() <= 1.0 + { + move_toolbar(app, rect.translate(egui::vec2(width - previous, 0.0))); + } } } @@ -368,6 +371,8 @@ pub(crate) struct DockSpecs { toolbar_title: String, /// The number of cells of the toolbar's rail. toolbar_cells: usize, + /// Maximum body height for a toolbar docked across the page. The dock adds its strip allowance. + toolbar_body_height: Option, /// The page area's title. document_title: String, } @@ -395,6 +400,7 @@ impl DockSpecs { tools_footer: !calc_order && super::tools::has_footer(app), toolbar_title: tl!("Toolbar").to_string(), toolbar_cells: crate::hotbar::rail_cells(app), + toolbar_body_height: None, document_title: crate::i18n::t("Document").to_owned(), } } @@ -404,7 +410,13 @@ impl PanelSpecs for DockSpecs { fn spec(&self, panel: &PanelId) -> PanelSpec { let command = CommandRef::with_params("view.panel", json!({ "panel": panel.name() })); match panel { - PanelId::Toolbar => crate::hotbar::panel_spec(&self.toolbar_title, self.toolbar_cells), + PanelId::Toolbar => { + let spec = crate::hotbar::panel_spec(&self.toolbar_title, self.toolbar_cells); + match self.toolbar_body_height { + Some(height) => spec.limits(SizeLimits::at_most(egui::vec2(SizeLimits::BOUND, height))), + None => spec, + } + } PanelId::Document => PanelSpec::new(self.document_title.clone()).canvas(), PanelId::Tools => { let spec = PanelSpec::new(self.tools_title.clone()).command(command); @@ -433,8 +445,20 @@ impl PanelSpecs for DockSpecs { } /// Reads the specs' inputs from the app, moving the specs' revision only when one changed. -fn refresh_specs(app: &mut PdfCraftApp) { - let specs = DockSpecs::of(app); +fn refresh_specs(app: &mut PdfCraftApp, ui: &Ui) { + let mut specs = DockSpecs::of(app); + let layout = app.dock.layout(); + if let Some(PanelPlace::Node(path)) = layout.place(&PanelId::Toolbar) + && let Some((_, parent)) = path.split_last() + && let Some(Node::Split { axis: Axis::Y, .. }) = layout.root.as_ref().and_then(|root| node_at(root, parent)) + { + // A top/bottom edge drop starts with a quarter of the page. Cap that frame at the + // height of the wrapped tools, footer and grip, including for already saved layouts. + let width = app.hotbar.layout_width.unwrap_or(ui.available_width()).max(1.0); + let sizes = DockSizes::of_scope(ui); + let measured = crate::hotbar::measure_rail(app, ui, width); + specs.toolbar_body_height = Some((measured + sizes.grip - sizes.strip).max(0.0)); + } if *app.dock_specs != specs { *app.dock_specs = specs; } @@ -473,6 +497,10 @@ impl DockPanels for Panels<'_> { match at { GroupAt::Measure(width) if panels.contains(&PanelId::Toolbar) => Some(crate::hotbar::measure_rail(self.app, ui, width)), GroupAt::Show(rect) if panels.contains(&PanelId::Toolbar) => { + if self.app.hotbar.layout_width != Some(rect.width()) { + self.app.hotbar.layout_width = Some(rect.width()); + ui.ctx().request_repaint(); + } crate::hotbar::show_rail(self.app, ui); Some(rect.height()) } @@ -591,8 +619,8 @@ pub fn dock(app: &mut PdfCraftApp, ui: &mut Ui) { let toolbar = active && !app.hotbar_hidden() && !organizing && !expanded; let anchor = rail_anchor(app); keep_toolbar_in_the_margin(app); - fit_tools_to_window(app, ui.ctx().content_rect().width()); - refresh_specs(app); + fit_tools_to_window(app, ui); + refresh_specs(app, ui); let workspace = Arc::clone(&app.dock); // The rail lists the Accessibility Checker once the document has a report, and Search and Compare only while // they show; their commands open them. @@ -1223,9 +1251,9 @@ mod tests { assert!(toolbar_x(&closed) < TOOLS_WIDTH * 0.5, "left closed: the toolbar at {}", toolbar_x(&closed)); closed.state_mut().set_left_open(true); closed.run_steps(4); - assert!(toolbar_x(&closed) > TOOLS_WIDTH, "left open again: the toolbar at {}", toolbar_x(&closed)); + assert!(toolbar_x(&closed) > closed.state().default_tools_width, "left open again: the toolbar at {}", toolbar_x(&closed)); let open = harness(|_| {}); - assert!(toolbar_x(&open) > TOOLS_WIDTH, "the default arrangement keeps the toolbar beside the Tools pane"); + assert!(toolbar_x(&open) > open.state().default_tools_width, "the default arrangement keeps the toolbar beside the Tools pane"); } fn tools_x(h: &Harness<'static, PdfCraftApp>) -> f32 { diff --git a/crates/ui-egui/src/panels/tools.rs b/crates/ui-egui/src/panels/tools.rs index ac876426a8..211b101982 100644 --- a/crates/ui-egui/src/panels/tools.rs +++ b/crates/ui-egui/src/panels/tools.rs @@ -98,17 +98,36 @@ fn tool_row(g: &'static ToolGroup, pinned: bool) -> ListRow<'static> { row.tooltip(tip) } +fn visible_tools(expanded: bool) -> &'static [ToolGroup] { + if expanded { TOOL_GROUPS } else { &TOOL_GROUPS[..COLLAPSED_TOOLS.min(TOOL_GROUPS.len())] } +} + +/// The natural sidebar width of all localized rows, including icons, badges, pins and the dock body's two insets. +pub(super) fn all_tools_width(ui: &egui::Ui, expanded: bool) -> f32 { + let env = craft::ui::runtime::env::Env::of(ui); + let cache = egui::Id::unique(("all-tools-width", crate::i18n::current().code(), expanded)); + if let Some((tokens, width)) = ui.data(|data| data.get_temp::<(std::sync::Arc<_>, f32)>(cache)) + && std::sync::Arc::ptr_eq(&tokens, &env.tokens) + { + return width; + } + let rows = visible_tools(expanded).iter().map(|group| tool_row(group, true).measure_in(ui, craft::behavior::Proposal::Ideal).x); + let width = (rows.fold(0.0, f32::max) + 2.0 * env.tokens.space.pad.regular).ceil(); + ui.data_mut(|data| data.insert_temp(cache, (std::sync::Arc::clone(&env.tokens), width))); + width +} + /// The All tools sidebar body: the tool list, the first few tools until View more shows them all. Its Expand and /// Close belong to the dock's group header. fn all_tools(app: &mut PdfCraftApp, ui: &mut egui::Ui) { - let shown = if app.all_tools_expanded { TOOL_GROUPS.len() } else { COLLAPSED_TOOLS.min(TOOL_GROUPS.len()) }; - let pins: Vec = TOOL_GROUPS[..shown].iter().map(|g| app.is_tool_pinned(g.id)).collect(); + let shown = visible_tools(app.all_tools_expanded); + let pins: Vec = shown.iter().map(|g| app.is_tool_pinned(g.id)).collect(); let out = List::::new(tl!("All tools").to_owned()) .natural_height(true) .select(SelectMode::Single) .activate(ActivateOn::Click) .selection(Bind::given(Selection::default())) - .show_items(ui, &Rows(shown), &mut |at, _| match (TOOL_GROUPS.get(*at), pins.get(*at)) { + .show_items(ui, &Rows(shown.len()), &mut |at, _| match (shown.get(*at), pins.get(*at)) { (Some(g), Some(pinned)) => tool_row(g, *pinned), _ => ListRow::spacer(), }); diff --git a/crates/ui-egui/src/platform/open_worker/tests.rs b/crates/ui-egui/src/platform/open_worker/tests.rs index 1e0dcba7d5..d4faa843a6 100644 --- a/crates/ui-egui/src/platform/open_worker/tests.rs +++ b/crates/ui-egui/src/platform/open_worker/tests.rs @@ -178,7 +178,11 @@ impl Rig { /// Whether a notice on screen says `text`. fn notice_says(&self, text: &str) -> bool { use egui_kittest::kittest::NodeT as _; - self.h.query_all_by_label_contains(text).any(|node| node.accesskit_node().role() == egui::accesskit::Role::Status) + self.h.query_all_by_label_contains(text).any(|node| { + let card = node.accesskit_node(); + matches!(card.role(), egui::accesskit::Role::Label | egui::accesskit::Role::Status | egui::accesskit::Role::Alert) + && card.children().next().is_some() + }) } fn password_dialog(&self) -> bool { diff --git a/crates/ui-egui/tests/it/control.rs b/crates/ui-egui/tests/it/control.rs index 06ca77e77e..75baad31c1 100644 --- a/crates/ui-egui/tests/it/control.rs +++ b/crates/ui-egui/tests/it/control.rs @@ -1308,6 +1308,31 @@ fn ctrl_dragging_a_thumbnail_through_the_control_channel_copies_the_page() { assert_eq!(page_texts(h.state()), ["Page 1", "Page 2", "Page 3", "Page 1"], "the copy landed at the drop gap, after page 3"); } +#[test] +fn a_docked_toolbar_opens_the_editor_from_its_gear() { + let (mut h, c) = harness(); + ok(&mut h, &c, "ui.panel", json!({"panel":"tools","open":false})); + ok(&mut h, &c, "ui.panel", json!({"panel":"toolbar","edge":"left"})); + h.run_steps(3); + let widgets = ok(&mut h, &c, "ui.inspect", json!({})); + let gear = widgets["widgets"].as_array().unwrap().iter().find(|w| w["label"] == "Edit toolbar").unwrap(); + click_center(&mut h, &c, gear); + assert!(h.query_by_role_and_label(egui::accesskit::Role::TextInput, "Search Tools").is_some(), "the editor opens beside the docked rail"); +} + +#[test] +fn the_navigation_rail_and_modes_align_with_neighboring_controls() { + use egui::accesskit::Role; + let (h, _) = harness(); + let midpoint = |role, name| h.get_by_role_and_label(role, name).rect().center(); + let menu = midpoint(Role::MenuItem, "File"); + let mode = midpoint(Role::Tab, "All tools"); + assert!((menu.y - mode.y).abs() <= 2.0, "the modes and menus share a line: {menu:?}, {mode:?}"); + let pages = midpoint(Role::Button, "Page thumbnails"); + let zoom = midpoint(Role::Button, "Zoom in"); + assert!((pages.x - zoom.x).abs() <= 1.0, "the view controls align with the panel icons: {pages:?}, {zoom:?}"); +} + #[test] fn organize_overview_is_reachable_through_the_control_channel() { let (mut h, c) = harness(); @@ -1551,6 +1576,32 @@ fn dock(h: &mut Harness<'static, PdfCraftApp>, c: &ControlClient) -> Value { ok(h, c, "ui.panel", json!({"panel": "side"}))["side_panels"].clone() } +/// Dropping the toolbar on the page's top or bottom edge reserves its controls and grip. +#[test] +fn a_horizontal_toolbar_fits_its_controls_above_or_below_the_page() { + use egui::accesskit::Role; + for edge in ["Top", "Bottom"] { + let (mut h, c) = harness(); + ok(&mut h, &c, "ui.set", json!({"key":"mode","value":"edit"})); + h.run_steps(3); + let dock_bottom = h.get_by_role_and_label(Role::Canvas, "Pages").rect().bottom(); + ok(&mut h, &c, "ui.dock.apply", json!({"action":{"Move":{"panel":"toolbar","anchor":"document","placement":{"Edge":edge}}}})); + for width in [1400.0, 820.0, 1400.0] { + h.set_size(egui::vec2(width, 900.0)); + h.run_steps(6); + let rail = h.get_by_role_and_label(Role::Toolbar, "Toolbar").rect(); + let pages = h.get_by_role_and_label(Role::Canvas, "Pages").rect(); + let grip = h.get_by_role_and_label(Role::Button, "Toolbar").rect(); + let gap = if edge == "Top" { pages.top() - rail.bottom() } else { grip.top() - pages.bottom() + dock_bottom - rail.bottom() }; + let sizes = craft::ui::docking::DockSizes::of(&h.ctx); + // The dock also enforces its theme's minimum panel body and strip height. + let floor = (sizes.least_pane + sizes.strip - grip.height() - rail.height()).max(0.0); + assert!((-1.0..=floor + sizes.gap + 1.0).contains(&gap), "{edge}, width {width}: {gap} blank points between the toolbar and the pages"); + assert!(rail.contains(h.get_by_role_and_label(Role::Button, "Edit toolbar").rect().center())); + } + } +} + #[test] fn ui_panel_opens_closes_and_sizes_panes_and_survives_restore() { let (mut h, c) = harness(); diff --git a/crates/ui-egui/tests/it/editing.rs b/crates/ui-egui/tests/it/editing.rs index 171ae9c2e3..cc64e9d6f3 100644 --- a/crates/ui-egui/tests/it/editing.rs +++ b/crates/ui-egui/tests/it/editing.rs @@ -2838,7 +2838,8 @@ fn the_security_notice_wraps_beside_its_buttons_and_lines_up_with_them() { } } // Wide: one line. Narrower: wrapped. Narrowest: actions stack below the message. - for (width, wraps) in [(1700.0, false), (1550.0, true), (1250.0, false), (900.0, false)] { + let (mut single, mut wrapped, mut stacked) = (false, false, false); + for width in [1800.0, 1650.0, 1550.0, 1500.0, 1450.0, 1400.0, 1350.0, 1300.0, 1250.0, 900.0] { let mut h = Harness::builder().with_size(egui::vec2(width, 800.0)).build_eframe(|cc| { crate::support::install_runtime(&cc.egui_ctx); { @@ -2854,8 +2855,10 @@ fn the_security_notice_wraps_beside_its_buttons_and_lines_up_with_them() { h.output().shapes.iter().find_map(|shape| message_rect(&shape.shape)).expect("the security message is painted"); let button = h.get_by_label("Security settings").rect(); let dismiss = h.get_by_label("Dismiss").rect(); - if width <= 1250.0 { - assert!(button.top() >= msg.bottom(), "{width}: stacked actions stay below the message: {msg:?} vs {button:?}"); + if button.top() >= msg.bottom() { + stacked = true; + // The dismiss control stays at the end of the message line; only the action moves below it. + assert!(!msg.intersects(dismiss), "{width}: the message leaves room for dismiss: {msg:?} vs {dismiss:?}"); assert!(!button.intersects(dismiss), "{width}: the actions stay apart: {button:?} vs {dismiss:?}"); continue; } @@ -2865,8 +2868,13 @@ fn the_security_notice_wraps_beside_its_buttons_and_lines_up_with_them() { assert!(msg.top() >= button.top(), "{width}: the message stays inside the bar: {msg:?} vs {button:?}"); let first_line = msg.top() + first_line_offset; assert!((first_line - button.center().y).abs() <= 1.5, "{width}: first line centred on the buttons: {msg:?} vs {button:?}"); - assert_eq!(msg.height() > button.height(), wraps, "{width}: {msg:?}"); + if msg.height() > button.height() { + wrapped = true; + } else { + single = true; + } } + assert!(single && wrapped && stacked, "the notice handles single-line, wrapped and stacked layouts"); } /// #995, #1077: a file with only a permissions password opens without asking, restricted. Its @@ -5059,14 +5067,17 @@ fn page_context_menu_items_disabled_on_protected_pdf() { assert!(!doc.allows_assembly()); assert!(!doc.allows_annotation()); - let r = h.state().views[0].page_screen_rect(0).expect("on screen"); - let c = r.center(); - // Right click on page in Select mode - h.hover_at(c); + let view = &h.state().views[0]; + let visible_page = view.page_screen_rect(0).expect("on screen").intersect(view.viewport_rect()); + assert!(visible_page.is_positive()); + let at = visible_page.center(); + h.hover_at(at); h.run_steps(1); - h.event(egui::Event::PointerButton { pos: c, button: egui::PointerButton::Secondary, pressed: true, modifiers: Default::default() }); - h.event(egui::Event::PointerButton { pos: c, button: egui::PointerButton::Secondary, pressed: false, modifiers: Default::default() }); - h.run_steps(2); + h.event(egui::Event::PointerButton { pos: at, button: egui::PointerButton::Secondary, pressed: true, modifiers: Default::default() }); + h.run_steps(1); + h.event(egui::Event::PointerButton { pos: at, button: egui::PointerButton::Secondary, pressed: false, modifiers: Default::default() }); + h.run_steps(3); + h.get_by_label("Take a snapshot"); let is_disabled = |h: &mut Harness<'static, PdfCraftApp>, label: &str| h.query_by(|n| n.label().as_deref() == Some(label) && n.is_disabled()).is_some(); diff --git a/crates/ui-egui/tests/it/javascript.rs b/crates/ui-egui/tests/it/javascript.rs index 5227f6136d..ae2bb81412 100644 --- a/crates/ui-egui/tests/it/javascript.rs +++ b/crates/ui-egui/tests/it/javascript.rs @@ -386,6 +386,9 @@ fn native_script_prompt_uses_the_german_catalog_when_available() { assert_eq!(tr(german, source), heading); let mut h = harness(); h.set_option("language", "de").unwrap(); + // The translated tools change the fitted page width. A script started before that layout + // settles would correctly be discarded when its recorded page zoom becomes stale. + h.run_steps(5); let id = h.state().active_ids().unwrap().1; h.run_button_script(id, "hello", "app.response({cQuestion:'Test',bPassword:true});"); wait_for_prompt(&mut h, heading, |h| h.query_by_role_and_label(egui::accesskit::Role::Dialog, heading).is_some()); diff --git a/crates/ui-egui/tests/it/min_window.rs b/crates/ui-egui/tests/it/min_window.rs index 29c4c7ab6a..25ba8776c7 100644 --- a/crates/ui-egui/tests/it/min_window.rs +++ b/crates/ui-egui/tests/it/min_window.rs @@ -19,6 +19,16 @@ fn harness(size: egui::Vec2) -> Harness<'static, PdfCraftApp> { h } +#[test] +fn the_all_tools_heading_aligns_with_its_list_on_home() { + let h = harness(egui::vec2(1400.0, 900.0)); + let panel = h.get_by_role_and_label(Role::TabPanel, "All tools").rect(); + let title = h.get_by_role_and_label(Role::Label, "All tools").rect(); + let list = h.get_by_role_and_label(Role::List, "All tools").rect(); + assert!(title.left() > panel.left(), "the heading touches the panel edge: {title:?}, {panel:?}"); + assert!((title.left() - list.left()).abs() <= 1.0, "the heading and list have different insets: {title:?}, {list:?}"); +} + #[test] fn at_the_minimum_width_the_menus_the_modes_and_search_stay_reachable() { let h = harness(egui::vec2(MIN_WINDOW_SIZE[0], MIN_WINDOW_SIZE[1]));