mirror of
https://github.com/storytold/wordcraft.git
synced 2026-12-04 11:46:53 -06:00
Compare commits
32
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ffbe57ebe | ||
|
|
551463ca51 | ||
|
|
bd69ff6e73 | ||
|
|
c867a329be | ||
|
|
ba68b13b19 | ||
|
|
b0fd8cbfe9 | ||
|
|
c6bceddb93 | ||
|
|
5a71494219 | ||
|
|
b2adf0f456 | ||
|
|
255309155b | ||
|
|
daa74a4fda | ||
|
|
ec687a6876 | ||
|
|
1e2e0cf217 | ||
|
|
ba01027379 | ||
|
|
61953d5fa9 | ||
|
|
ae35ca4fd8 | ||
|
|
c7d2d85a86 | ||
|
|
7c74a5fa93 | ||
|
|
89e336f645 | ||
|
|
18c7cfd8d6 | ||
|
|
8670496a46 | ||
|
|
2895ab88d4 | ||
|
|
5288ef3255 | ||
|
|
8527081bc2 | ||
|
|
342931078a | ||
|
|
6c47d77c19 | ||
|
|
0eed1a0d15 | ||
|
|
820742d5dc | ||
|
|
5cc4702ca8 | ||
|
|
1f73bb9486 | ||
|
|
017af2f3f9 | ||
|
|
72afcbd32d |
Generated
+111
-125
@@ -1173,7 +1173,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-automation",
|
||||
"craft-behavior",
|
||||
@@ -1214,7 +1214,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-appkit"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"block2 0.6.2",
|
||||
"objc2 0.6.5",
|
||||
@@ -1226,7 +1226,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-atomic"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"rustix 1.1.6",
|
||||
]
|
||||
@@ -1234,7 +1234,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-automation"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"base64 0.23.1",
|
||||
"craft-behavior",
|
||||
@@ -1259,7 +1259,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-behavior"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"accesskit",
|
||||
"bitflags 2.13.2",
|
||||
@@ -1277,7 +1277,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-browse"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-docpath",
|
||||
@@ -1295,12 +1295,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-cfb"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
|
||||
[[package]]
|
||||
name = "craft-cloud-ui"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"egui",
|
||||
]
|
||||
@@ -1308,7 +1308,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-cms"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"md-5",
|
||||
"rayon",
|
||||
@@ -1317,12 +1317,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-codepage"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
|
||||
[[package]]
|
||||
name = "craft-color"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
@@ -1330,7 +1330,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-color-ui"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-cms",
|
||||
@@ -1350,7 +1350,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-control"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-control-protocol",
|
||||
"craft-platform",
|
||||
@@ -1361,7 +1361,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-control-protocol"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"getrandom 0.3.4",
|
||||
"serde_json",
|
||||
@@ -1371,7 +1371,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-dds"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"rayon",
|
||||
]
|
||||
@@ -1379,7 +1379,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-dialogs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"block2 0.6.2",
|
||||
"craft-appkit",
|
||||
@@ -1405,7 +1405,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-doc-binary"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"craft-cfb",
|
||||
@@ -1422,7 +1422,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-docpath"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
@@ -1430,7 +1430,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-docx"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"base64 0.23.1",
|
||||
"chrono",
|
||||
@@ -1450,7 +1450,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-draw"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-color-ui",
|
||||
@@ -1469,7 +1469,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-drawingml"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"craft-xml",
|
||||
@@ -1481,7 +1481,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-flow"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-wordmodel",
|
||||
"image",
|
||||
@@ -1491,7 +1491,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-font-catalog"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"fontique",
|
||||
"harfrust 0.13.3",
|
||||
@@ -1506,7 +1506,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-font-manager"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-font-catalog",
|
||||
@@ -1525,7 +1525,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-font-os-windows"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"windows-registry",
|
||||
"windows-sys 0.61.2",
|
||||
@@ -1534,7 +1534,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-font-store"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"cap-primitives",
|
||||
"craft-atomic",
|
||||
@@ -1557,7 +1557,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-font-subset"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"brotli 9.1.3",
|
||||
"harfbuzz-subset-sys",
|
||||
@@ -1570,7 +1570,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-fonts-build"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-font-subset",
|
||||
]
|
||||
@@ -1578,7 +1578,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-gpu"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"egui-wgpu",
|
||||
"log",
|
||||
@@ -1590,7 +1590,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-host"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"craft-i18n",
|
||||
@@ -1603,7 +1603,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-html"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-codepage",
|
||||
"craft-flow",
|
||||
@@ -1616,7 +1616,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-i18n"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"brotli 9.1.3",
|
||||
"brotli-decompressor 6.3.1",
|
||||
@@ -1646,7 +1646,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-image-codecs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-dds",
|
||||
"craft-jpeg",
|
||||
@@ -1673,7 +1673,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-imaging"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-color-ui",
|
||||
@@ -1691,7 +1691,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-jpeg"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
@@ -1699,7 +1699,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-keymap"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-host",
|
||||
"craft-i18n",
|
||||
@@ -1714,7 +1714,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-latex"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-flow",
|
||||
"craft-math",
|
||||
@@ -1725,7 +1725,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-markdown"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-flow",
|
||||
"craft-html",
|
||||
@@ -1735,7 +1735,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-math"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-xml",
|
||||
"roxmltree",
|
||||
@@ -1745,7 +1745,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-mcp-server"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"serde_json",
|
||||
]
|
||||
@@ -1753,7 +1753,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-menu"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -1771,7 +1771,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-metadata"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"brotli-decompressor 6.3.1",
|
||||
"chrono",
|
||||
@@ -1783,7 +1783,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-metafile"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"encoding_rs",
|
||||
"image",
|
||||
@@ -1794,7 +1794,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-mime"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"chardetng",
|
||||
"chrono",
|
||||
@@ -1805,7 +1805,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-nightly"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"uds_windows",
|
||||
"winsafe",
|
||||
@@ -1814,7 +1814,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-odf"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"aes",
|
||||
"base64 0.23.1",
|
||||
@@ -1840,7 +1840,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ods"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-odf",
|
||||
"craft-sheet",
|
||||
@@ -1851,7 +1851,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-offcrypto"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"aes",
|
||||
"base64 0.23.1",
|
||||
@@ -1868,7 +1868,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-opc"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-xml",
|
||||
"craft-zip",
|
||||
@@ -1879,7 +1879,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-pages"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-keymap",
|
||||
@@ -1895,7 +1895,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-pdf"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"krilla",
|
||||
"serde",
|
||||
@@ -1905,7 +1905,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-platform"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"arboard",
|
||||
"async-channel",
|
||||
@@ -1943,7 +1943,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-print"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -1967,7 +1967,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-proof"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"log",
|
||||
"miniz_oxide 0.9.1",
|
||||
@@ -1978,7 +1978,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-quit"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"dispatch2",
|
||||
"egui",
|
||||
@@ -1991,7 +1991,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-review"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"base64 0.23.1",
|
||||
"craft-behavior",
|
||||
@@ -2010,7 +2010,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-rtf"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-codepage",
|
||||
"craft-flow",
|
||||
@@ -2023,7 +2023,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-settings"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-atomic",
|
||||
"craft-host",
|
||||
@@ -2040,17 +2040,17 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-sheet"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
|
||||
[[package]]
|
||||
name = "craft-ssip"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
|
||||
[[package]]
|
||||
name = "craft-svg"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-xml",
|
||||
"flate2",
|
||||
@@ -2067,7 +2067,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-table"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-keymap",
|
||||
@@ -2079,7 +2079,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-text"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -2103,7 +2103,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-theme"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"craft-tracked",
|
||||
@@ -2118,7 +2118,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-theme-store"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-atomic",
|
||||
"craft-behavior",
|
||||
@@ -2133,7 +2133,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-tiff"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"thiserror 2.0.21",
|
||||
@@ -2143,7 +2143,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-time"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"thiserror 2.0.21",
|
||||
@@ -2152,7 +2152,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-timeline"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-keymap",
|
||||
@@ -2167,12 +2167,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-tracked"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
|
||||
[[package]]
|
||||
name = "craft-ui"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-cloud-ui",
|
||||
"craft-ui-canvas",
|
||||
@@ -2186,7 +2186,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-canvas"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-font-catalog",
|
||||
@@ -2203,7 +2203,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-contract"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"accesskit",
|
||||
"craft-behavior",
|
||||
@@ -2241,7 +2241,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-macros"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
@@ -2252,7 +2252,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-panels"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -2270,7 +2270,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-patterns"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -2291,7 +2291,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-shell"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -2312,7 +2312,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-test-kit"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -2323,7 +2323,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-widgets"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -2342,7 +2342,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-update"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"chrono",
|
||||
@@ -2374,7 +2374,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-web-api"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"serde_json",
|
||||
@@ -2385,7 +2385,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-web-host"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-host",
|
||||
"craft-platform",
|
||||
@@ -2397,7 +2397,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-win32"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"winsafe",
|
||||
]
|
||||
@@ -2405,7 +2405,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-window"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-appkit",
|
||||
"craft-atomic",
|
||||
@@ -2437,7 +2437,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-wordmodel"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"base64 0.23.1",
|
||||
"craft-math",
|
||||
@@ -2451,7 +2451,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-xls"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-cfb",
|
||||
"craft-sheet",
|
||||
@@ -2464,7 +2464,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-xlsx"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"craft-drawingml",
|
||||
"craft-opc",
|
||||
@@ -2476,7 +2476,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-xml"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"quick-xml 0.41.0",
|
||||
"serde",
|
||||
@@ -2486,7 +2486,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-zip"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"thiserror 2.0.21",
|
||||
@@ -2842,7 +2842,7 @@ checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813"
|
||||
[[package]]
|
||||
name = "ecolor"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07b014397ff2ff86a3570e472552d527be9e588a#07b014397ff2ff86a3570e472552d527be9e588a"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"emath",
|
||||
@@ -2875,7 +2875,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "eframe"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07b014397ff2ff86a3570e472552d527be9e588a#07b014397ff2ff86a3570e472552d527be9e588a"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytemuck",
|
||||
@@ -2910,7 +2910,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07b014397ff2ff86a3570e472552d527be9e588a#07b014397ff2ff86a3570e472552d527be9e588a"
|
||||
dependencies = [
|
||||
"accesskit",
|
||||
"ahash",
|
||||
@@ -2929,7 +2929,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui-wgpu"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07b014397ff2ff86a3570e472552d527be9e588a#07b014397ff2ff86a3570e472552d527be9e588a"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytemuck",
|
||||
@@ -2948,7 +2948,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui-winit"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07b014397ff2ff86a3570e472552d527be9e588a#07b014397ff2ff86a3570e472552d527be9e588a"
|
||||
dependencies = [
|
||||
"accesskit_winit",
|
||||
"arboard",
|
||||
@@ -2974,7 +2974,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui_extras"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07b014397ff2ff86a3570e472552d527be9e588a#07b014397ff2ff86a3570e472552d527be9e588a"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"egui",
|
||||
@@ -2987,7 +2987,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui_glow"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07b014397ff2ff86a3570e472552d527be9e588a#07b014397ff2ff86a3570e472552d527be9e588a"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"egui",
|
||||
@@ -3000,7 +3000,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui_kittest"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07b014397ff2ff86a3570e472552d527be9e588a#07b014397ff2ff86a3570e472552d527be9e588a"
|
||||
dependencies = [
|
||||
"dify",
|
||||
"eframe",
|
||||
@@ -3026,7 +3026,7 @@ checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be"
|
||||
[[package]]
|
||||
name = "emath"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07b014397ff2ff86a3570e472552d527be9e588a#07b014397ff2ff86a3570e472552d527be9e588a"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
]
|
||||
@@ -3107,7 +3107,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "epaint"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07b014397ff2ff86a3570e472552d527be9e588a#07b014397ff2ff86a3570e472552d527be9e588a"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytemuck",
|
||||
@@ -3133,7 +3133,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "epaint_default_fonts"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07b014397ff2ff86a3570e472552d527be9e588a#07b014397ff2ff86a3570e472552d527be9e588a"
|
||||
dependencies = [
|
||||
"brotli 9.1.3",
|
||||
"brotli-decompressor 6.3.1",
|
||||
@@ -3866,7 +3866,7 @@ checksum = "9f4d0e94ddd48749f06bbe4e5389fb9799a0c45bcaf00495042076ef05e3241a"
|
||||
[[package]]
|
||||
name = "hayro-cmap"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"brotli 8.0.4",
|
||||
"hayro-postscript",
|
||||
@@ -3875,7 +3875,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "hayro-interpret"
|
||||
version = "0.7.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"hayro-cmap",
|
||||
@@ -3893,7 +3893,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "hayro-jbig2"
|
||||
version = "0.3.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"fearless_simd",
|
||||
"hayro-ccitt",
|
||||
@@ -3911,12 +3911,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "hayro-postscript"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
|
||||
[[package]]
|
||||
name = "hayro-syntax"
|
||||
version = "0.7.2"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"hayro-ccitt",
|
||||
@@ -4645,7 +4645,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "krilla"
|
||||
version = "0.8.2"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"bumpalo",
|
||||
@@ -4784,7 +4784,7 @@ checksum = "d4a5ff6bcca6c4867b1c4fd4ef63e4db7436ef363e0ad7531d1558856bae64f4"
|
||||
[[package]]
|
||||
name = "linesweeper"
|
||||
version = "0.5.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"kurbo",
|
||||
@@ -8454,19 +8454,6 @@ dependencies = [
|
||||
"wayland-scanner",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-protocols-plasma"
|
||||
version = "0.3.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b6d8cf1eb2c1c31ed1f5643c88a6e53538129d4af80030c8cabd1f9fa884d91"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-protocols",
|
||||
"wayland-scanner",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-protocols-wlr"
|
||||
version = "0.3.12"
|
||||
@@ -8991,7 +8978,7 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||
[[package]]
|
||||
name = "winit"
|
||||
version = "0.30.13"
|
||||
source = "git+https://github.com/storytold/winit.git?rev=0dfcec0eb62fda5904137a63a6dd0c3d83295f45#0dfcec0eb62fda5904137a63a6dd0c3d83295f45"
|
||||
source = "git+https://github.com/storytold/winit.git?rev=3fd7ae64762f82a73b78bd24f453f82c4291067d#3fd7ae64762f82a73b78bd24f453f82c4291067d"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"android-activity",
|
||||
@@ -9030,7 +9017,6 @@ dependencies = [
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-protocols",
|
||||
"wayland-protocols-plasma",
|
||||
"web-sys",
|
||||
"web-time",
|
||||
"windows-sys 0.52.0",
|
||||
@@ -10051,19 +10037,19 @@ dependencies = [
|
||||
[[patch.unused]]
|
||||
name = "egui_demo_lib"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07b014397ff2ff86a3570e472552d527be9e588a#07b014397ff2ff86a3570e472552d527be9e588a"
|
||||
|
||||
[[patch.unused]]
|
||||
name = "egui_inspection"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07b014397ff2ff86a3570e472552d527be9e588a#07b014397ff2ff86a3570e472552d527be9e588a"
|
||||
|
||||
[[patch.unused]]
|
||||
name = "egui_system_font_provider"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387dd1f9649553f9321#07c20531f89717e461c0f387dd1f9649553f9321"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=07b014397ff2ff86a3570e472552d527be9e588a#07b014397ff2ff86a3570e472552d527be9e588a"
|
||||
|
||||
[[patch.unused]]
|
||||
name = "hayro"
|
||||
version = "0.7.1"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d73e274a01408ef433a291a667e6014937d72165#d73e274a01408ef433a291a667e6014937d72165"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=98a66a56550b027cc8cdcd689ab7d3239c71427e#98a66a56550b027cc8cdcd689ab7d3239c71427e"
|
||||
|
||||
+54
-54
@@ -37,22 +37,22 @@ wordcraft-pdf = { path = "crates/pdf" }
|
||||
# reads the ca-valencia pack), #589 (French elision suggestions first), #497 (flag-based
|
||||
# compounding), #496 (review follow-ups, en-AU) and the merged #482–#490/#495 stack; the font
|
||||
# store's `language-pack` kind is #486 (CP4.1).
|
||||
wordcraft-proof = { package = "craft-proof", git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0" }
|
||||
craft-font-store = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0" }
|
||||
craft-font-catalog = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0" }
|
||||
craft-ssip = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0" }
|
||||
wordcraft-proof = { package = "craft-proof", git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0" }
|
||||
craft-font-store = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0" }
|
||||
craft-font-catalog = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0" }
|
||||
craft-ssip = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0" }
|
||||
wordcraft-engine = { path = "crates/engine" }
|
||||
wordcraft-mcp = { path = "crates/mcp" }
|
||||
wordcraft-zotero = { path = "crates/zotero" }
|
||||
wordcraft-control-key = { path = "crates/control-key" }
|
||||
wordcraft-ui-egui = { path = "crates/ui-egui" }
|
||||
wordcraft-validate = { path = "crates/validate" }
|
||||
craft-codepage = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0" }
|
||||
craft = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0", default-features = false }
|
||||
craft-ui-test-kit = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0" }
|
||||
craft-keymap = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0" }
|
||||
craft-metafile = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0" }
|
||||
craft-nightly = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165" }
|
||||
craft-codepage = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0" }
|
||||
craft = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0", default-features = false }
|
||||
craft-ui-test-kit = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0" }
|
||||
craft-keymap = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0" }
|
||||
craft-metafile = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0" }
|
||||
craft-nightly = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e" }
|
||||
|
||||
# foundation
|
||||
kurbo = { version = "0.13", features = ["serde"] }
|
||||
@@ -85,28 +85,28 @@ wuff = "0.2.9"
|
||||
brotli-decompressor = "5"
|
||||
vello_cpu = "0.2"
|
||||
image = { version = "0.25", default-features = false }
|
||||
craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0" }
|
||||
craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0" }
|
||||
craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0", default-features = false, features = ["write"] }
|
||||
craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0" }
|
||||
craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0" }
|
||||
craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0", default-features = false, features = ["write"] }
|
||||
|
||||
craft-wordmodel = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0" }
|
||||
craft-docx = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0" }
|
||||
craft-mcp-server = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0" }
|
||||
craft-rtf = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0", features = ["doc"] }
|
||||
craft-doc-binary = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0" }
|
||||
craft-flow = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0" }
|
||||
craft-odf = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0", features = ["text"] }
|
||||
craft-markdown = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0" }
|
||||
craft-html = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0", features = ["flow"] }
|
||||
craft-latex = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0" }
|
||||
craft-math = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0" }
|
||||
craft-mime = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0", features = ["detect"] }
|
||||
craft-sheet = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0" }
|
||||
craft-ods = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0" }
|
||||
craft-xls = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0" }
|
||||
craft-xlsx = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0" }
|
||||
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0" }
|
||||
craft-zip = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", version = "=0.1.0" }
|
||||
craft-wordmodel = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0" }
|
||||
craft-docx = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0" }
|
||||
craft-mcp-server = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0" }
|
||||
craft-rtf = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0", features = ["doc"] }
|
||||
craft-doc-binary = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0" }
|
||||
craft-flow = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0" }
|
||||
craft-odf = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0", features = ["text"] }
|
||||
craft-markdown = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0" }
|
||||
craft-html = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0", features = ["flow"] }
|
||||
craft-latex = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0" }
|
||||
craft-math = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0" }
|
||||
craft-mime = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0", features = ["detect"] }
|
||||
craft-sheet = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0" }
|
||||
craft-ods = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0" }
|
||||
craft-xls = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0" }
|
||||
craft-xlsx = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0" }
|
||||
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0" }
|
||||
craft-zip = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", version = "=0.1.0" }
|
||||
# zlib streams (compressed metafile pictures in `.doc` drawings); already in the lock as a dependency of other crates.
|
||||
miniz_oxide = "0.9"
|
||||
cfb = "0.15"
|
||||
@@ -174,27 +174,27 @@ debug = 0
|
||||
# The framework's patches, which Cargo does not carry over to dependents: its vendored crates from craft-libs,
|
||||
# and the egui and winit forks it builds with.
|
||||
[patch.crates-io]
|
||||
krilla = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165" }
|
||||
hayro = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165" }
|
||||
hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165" }
|
||||
hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165" }
|
||||
hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165" }
|
||||
hayro-cmap = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165" }
|
||||
hayro-postscript = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165" }
|
||||
linesweeper = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165" }
|
||||
ecolor = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
emath = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
epaint = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
epaint_default_fonts = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
egui = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
egui-winit = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
egui-wgpu = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
egui_glow = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
egui_extras = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
egui_kittest = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
egui_system_font_provider = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
eframe = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
egui_demo_lib = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
egui_inspection = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
winit = { git = "https://github.com/storytold/winit.git", rev = "0dfcec0eb62fda5904137a63a6dd0c3d83295f45" }
|
||||
krilla = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e" }
|
||||
hayro = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e" }
|
||||
hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e" }
|
||||
hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e" }
|
||||
hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e" }
|
||||
hayro-cmap = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e" }
|
||||
hayro-postscript = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e" }
|
||||
linesweeper = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e" }
|
||||
ecolor = { git = "https://github.com/storytold/egui.git", rev = "07b014397ff2ff86a3570e472552d527be9e588a" }
|
||||
emath = { git = "https://github.com/storytold/egui.git", rev = "07b014397ff2ff86a3570e472552d527be9e588a" }
|
||||
epaint = { git = "https://github.com/storytold/egui.git", rev = "07b014397ff2ff86a3570e472552d527be9e588a" }
|
||||
epaint_default_fonts = { git = "https://github.com/storytold/egui.git", rev = "07b014397ff2ff86a3570e472552d527be9e588a" }
|
||||
egui = { git = "https://github.com/storytold/egui.git", rev = "07b014397ff2ff86a3570e472552d527be9e588a" }
|
||||
egui-winit = { git = "https://github.com/storytold/egui.git", rev = "07b014397ff2ff86a3570e472552d527be9e588a" }
|
||||
egui-wgpu = { git = "https://github.com/storytold/egui.git", rev = "07b014397ff2ff86a3570e472552d527be9e588a" }
|
||||
egui_glow = { git = "https://github.com/storytold/egui.git", rev = "07b014397ff2ff86a3570e472552d527be9e588a" }
|
||||
egui_extras = { git = "https://github.com/storytold/egui.git", rev = "07b014397ff2ff86a3570e472552d527be9e588a" }
|
||||
egui_kittest = { git = "https://github.com/storytold/egui.git", rev = "07b014397ff2ff86a3570e472552d527be9e588a" }
|
||||
egui_system_font_provider = { git = "https://github.com/storytold/egui.git", rev = "07b014397ff2ff86a3570e472552d527be9e588a" }
|
||||
eframe = { git = "https://github.com/storytold/egui.git", rev = "07b014397ff2ff86a3570e472552d527be9e588a" }
|
||||
egui_demo_lib = { git = "https://github.com/storytold/egui.git", rev = "07b014397ff2ff86a3570e472552d527be9e588a" }
|
||||
egui_inspection = { git = "https://github.com/storytold/egui.git", rev = "07b014397ff2ff86a3570e472552d527be9e588a" }
|
||||
winit = { git = "https://github.com/storytold/winit.git", rev = "3fd7ae64762f82a73b78bd24f453f82c4291067d" }
|
||||
|
||||
|
||||
@@ -155,11 +155,6 @@ Ranked, to beta (detail and remaining milestones in [docs/roadmap.md](docs/roadm
|
||||
|
||||
## Progress log
|
||||
|
||||
- 2026-11-21: Page text on the shared page view is sharp again. After the port, pages were rasterised at the view's own scale and rounded up to whole pixels, which left a picture a pixel or two larger than its place on screen (2017 × 2852 for 2016 × 2851); the shared painter fits a picture into its place, so it was squeezed by a twentieth of a percent and the text slid off the pixel grid and back down the page: a reporter's screenshot showed baselines spread over three pixel rows. Pictures are now made exactly as many pixels each way as the place the view last rested at, which the painter draws one pixel for one. A headless test through the real page view and picture store holds this at three zooms and two screen densities. Not yet seen in the running app. Readiness estimates unchanged.
|
||||
- 2026-11-20: The sharper page text, subpixel (LCD) text and the Screen text smoothing option are ported onto the shared page view and Options that the UI port (#7101) brought. Two things changed on the way. The page view asks for page pictures rounded up to a multiple of 16 pixels and scales them into place, which resamples every glyph (A4 at 100 % on a 2x screen: 2256 pixels for 2245), so pages are now rasterised at the view's own scale wherever it accounts for the side asked for, and subpixel text is drawn only on such pictures. And the app no longer reads the system's text settings itself: system access moved to craft-libs' `platform::appearance`, which has none, so pages are drawn each platform's fixed way plus the user's own Screen text smoothing choice until craft-libs reports them (the 2026-11-19 entry on following the system no longer holds). Two shared-API gaps are recorded in `docs/ui-parity.md`: the text settings reader, and drawing a screen-scale page picture at its own pixel size. Run on macOS only; not seen in the running app since the port. Readiness estimates unchanged.
|
||||
- 2026-11-19: Page text can be drawn with subpixel (LCD) antialiasing: File › Options › General › Screen text smoothing offers Use system setting, Grayscale and Subpixel (LCD); `view.textSmoothing` reaches the same setting headlessly. A page is rasterised three times with only its text a third of a pixel apart and each colour channel is taken from the pass that matches its stripe, so drawing order, coloured text, dark pages and rotated text need no special cases and nothing but text gets coloured edges. Once the system settings are read (nothing reads them yet), "Use system setting" will turn it on where the system asks for it (ClearType, or `rgba` antialiasing on a Linux desktop) on screens below 2x; macOS never asks, so there it is the user's choice. Exports are unchanged. Run on macOS only, on headless rasters: not yet seen on a 1x LCD, on Windows or on Linux, and not timed. Readiness estimates unchanged.
|
||||
- 2026-11-19: Page drawing can take the system's text settings (darkening strength, hinting, subpixel order), but nothing reads them from the system yet, so pages are drawn each platform's fixed way and "Use system setting" is greyscale. Readiness estimates unchanged.
|
||||
- 2026-11-19: Page text on macOS and Windows is no longer soft. Baselines sit on whole device pixels, so the feet of the letters fill one pixel row instead of greying two; and the macOS font smoothing we imitate thickens letters sideways only, by widening each outline and filling it once, where a stroke all round added a third of a pixel of grey above and below every letter. Found by comparing 144 dpi screenshots of the same paragraph in WordCraft, Preview and OpenOffice: none of the three used subpixel antialiasing; WordCraft alone had its serifs spread over two rows. Linux and BSD text was already hinted onto the grid; exports are unchanged. Readiness estimates unchanged.
|
||||
- 2026-12-01: Hindi interface language (`hi`): File › Options › Interface language offers हिन्दी, and `hi`, `hi-IN` and `hi_IN.UTF-8` system locales pick it. The catalog is craft-i18n's `locales/hi/wordcraft.tsv` (`craft-i18n.rev` at 217f413); interface text is drawn by the embedded Noto Sans Devanagari face. No Hindi proofing, so the Hindi interface doesn't set the language of new documents. Readiness estimates unchanged.
|
||||
- 2026-11-28: Layout indexes numbering definitions for each list and STYLEREF walk. List labels still follow the document's literal labels, start overrides and nested restart rules (#3615).
|
||||
|
||||
|
||||
@@ -74,6 +74,10 @@ winit = { version = "0.30", default-features = false, features = ["x11", "waylan
|
||||
x11-dl = "2.21"
|
||||
xkbcommon-dl = { version = "0.4.2", features = ["x11"] }
|
||||
|
||||
# Name the window supplied by eframe's attachment hook on targets that otherwise use winit indirectly.
|
||||
[target.'cfg(any(target_os = "macos", windows))'.dependencies]
|
||||
winit = { version = "0.30", default-features = false }
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
# The update helper: a copy of this program started with `--finish-update`
|
||||
# (`craft::update::self_update::finish`).
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
//! Native parent windows for document-owned file pickers in windowless mode.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::num::NonZeroU64;
|
||||
use std::sync::{Arc, Mutex, Weak};
|
||||
|
||||
use craft::dialogs::service::FilePanels;
|
||||
use craft::platform::open::IntakeSender;
|
||||
use craft::ui::dialog::DialogHost;
|
||||
use eframe::{ViewportHooks, ViewportWindowKey};
|
||||
use egui::{Context, RawInput, ViewportId};
|
||||
use winit::window::Window;
|
||||
use wordcraft_ui_egui::file_dialogs::{NativeWindowLookup, OwnerPanels, ParentLease};
|
||||
|
||||
use crate::drop_intake::ChildDrops;
|
||||
|
||||
/// The latest successful attachment for each viewport. The registry does not keep windows alive.
|
||||
#[derive(Clone, Default)]
|
||||
pub(crate) struct DocumentWindows(Arc<Mutex<HashMap<ViewportId, (ViewportWindowKey, Weak<Window>)>>>);
|
||||
|
||||
impl DocumentWindows {
|
||||
pub(crate) fn hooks(&self, drops: IntakeSender) -> Arc<dyn ViewportHooks> {
|
||||
Arc::new(DocumentHooks { windows: self.clone(), drops: ChildDrops(drops) })
|
||||
}
|
||||
}
|
||||
|
||||
struct DocumentHooks {
|
||||
windows: DocumentWindows,
|
||||
drops: ChildDrops,
|
||||
}
|
||||
|
||||
impl ViewportHooks for DocumentHooks {
|
||||
fn window_attached(&self, key: ViewportWindowKey, window: Weak<Window>) {
|
||||
let mut attached = self.windows.0.lock().unwrap_or_else(|e| e.into_inner());
|
||||
attached.insert(key.viewport_id(), (key, window));
|
||||
}
|
||||
|
||||
fn window_detached(&self, key: ViewportWindowKey) {
|
||||
let mut attached = self.windows.0.lock().unwrap_or_else(|e| e.into_inner());
|
||||
if attached.get(&key.viewport_id()).is_some_and(|(current, _)| *current == key) {
|
||||
attached.remove(&key.viewport_id());
|
||||
}
|
||||
}
|
||||
|
||||
fn raw_input(&self, ctx: &Context, raw: &mut RawInput) {
|
||||
self.drops.raw_input(ctx, raw);
|
||||
}
|
||||
}
|
||||
|
||||
impl NativeWindowLookup for DocumentWindows {
|
||||
fn incarnation(&self, viewport: ViewportId) -> Option<NonZeroU64> {
|
||||
let attached = self.0.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let (key, weak) = attached.get(&viewport)?;
|
||||
(weak.strong_count() > 0).then(|| key.incarnation())
|
||||
}
|
||||
}
|
||||
|
||||
impl OwnerPanels for DocumentWindows {
|
||||
fn pump_parented(
|
||||
&mut self,
|
||||
viewport: ViewportId,
|
||||
incarnation: NonZeroU64,
|
||||
panels: &mut FilePanels,
|
||||
host: &mut DialogHost,
|
||||
) -> Option<ParentLease> {
|
||||
// Upgrade only the exact live incarnation, on the event-loop thread. Never hold the
|
||||
// registry lock across the pump (macOS can enter native dialog code here).
|
||||
let parent = {
|
||||
let attached = self.0.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let (key, weak) = attached.get(&viewport)?;
|
||||
if key.incarnation() != incarnation {
|
||||
return None;
|
||||
}
|
||||
weak.upgrade()?
|
||||
};
|
||||
panels.pump_with(host, Some(parent.as_ref()));
|
||||
// rfd can use the copied handles on a later worker callback. The router retains this
|
||||
// lease through backend completion even if the initiating document detached meanwhile.
|
||||
Some(ParentLease::new(parent))
|
||||
}
|
||||
|
||||
fn pump_unparented(&mut self, panels: &mut FilePanels, host: &mut DialogHost) {
|
||||
// The router allows this only for an explicitly in-app request or an already launched
|
||||
// operation with an empty native queue. It cannot open an unowned system dialog here.
|
||||
panels.pump_with::<eframe::Frame>(host, None);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
//! Route desktop drop events to WordCraft's existing file intake.
|
||||
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
use craft::platform::open::{DroppedFile, IntakeSender};
|
||||
use eframe::ViewportHooks;
|
||||
use egui::{Context, RawInput, ViewportId};
|
||||
|
||||
/// The ordinary app input hook leaves files in `raw` for the runtime's own reading.
|
||||
pub(crate) fn forward_app_input(sender: &IntakeSender, raw: &RawInput) {
|
||||
sender.dropped(
|
||||
raw.dropped_files
|
||||
.iter()
|
||||
.map(|file| {
|
||||
dropped_path(file.path()).unwrap_or_else(|| DroppedFile { path: None, name: String::new(), bytes: file.bytes().ok().map(Arc::from) })
|
||||
})
|
||||
.collect(),
|
||||
);
|
||||
}
|
||||
|
||||
fn dropped_path(path: &Path) -> Option<DroppedFile> {
|
||||
if path.as_os_str().is_empty() {
|
||||
return None;
|
||||
}
|
||||
let name = path.file_name().map(|n| n.to_string_lossy().into_owned()).unwrap_or_default();
|
||||
Some(DroppedFile { path: Some(path.to_path_buf()), name, bytes: None })
|
||||
}
|
||||
|
||||
/// Immediate child input in the windowless trial.
|
||||
pub(crate) struct ChildDrops(pub(crate) IntakeSender);
|
||||
|
||||
impl ViewportHooks for ChildDrops {
|
||||
fn raw_input(&self, _ctx: &Context, raw: &mut RawInput) {
|
||||
// Immediate viewports skip App::raw_input_hook. The regular ROOT input still goes there.
|
||||
// Consume this child batch so no later hook or pass feeds it again. Native OS drops carry
|
||||
// paths: pass those through without reading the files on the event loop.
|
||||
if raw.viewport_id != ViewportId::ROOT && !raw.dropped_files.is_empty() {
|
||||
self.0.dropped(raw.dropped_files.drain(..).filter_map(|file| dropped_path(file.path())).collect());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use craft::host::Wake;
|
||||
use craft::platform::open::{FileIntake, Intake};
|
||||
|
||||
#[derive(Debug)]
|
||||
struct NativeDrop(PathBuf);
|
||||
|
||||
impl egui::DroppedFile for NativeDrop {
|
||||
fn path(&self) -> &Path {
|
||||
&self.0
|
||||
}
|
||||
|
||||
fn bytes(&self) -> Result<Vec<u8>, String> {
|
||||
panic!("the raw-input hook must not read native dropped files");
|
||||
}
|
||||
}
|
||||
|
||||
fn raw_drops(viewport_id: ViewportId, paths: &[PathBuf]) -> RawInput {
|
||||
RawInput {
|
||||
viewport_id,
|
||||
dropped_files: paths.iter().map(|path| Arc::new(NativeDrop(path.clone())) as egui::DroppedFileHandle).collect(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn child_drop_enters_intake_once_in_drop_order() {
|
||||
let (intake, sender) = FileIntake::new(Wake::none());
|
||||
let hooks = ChildDrops(sender.clone());
|
||||
let ctx = Context::default();
|
||||
let child = ViewportId::from_hash_of("document");
|
||||
let paths = [std::env::temp_dir().join("second.docx"), std::env::temp_dir().join("first.docx")];
|
||||
let mut raw = raw_drops(child, &paths);
|
||||
|
||||
// The immediate child goes through the viewport hook, not the App hook.
|
||||
hooks.raw_input(&ctx, &mut raw);
|
||||
let batches = intake.take();
|
||||
let [Intake::Dropped { files }] = batches.as_slice() else { panic!("expected one child drop batch, got {batches:?}") };
|
||||
assert!(files.iter().map(|file| file.path.as_ref()).eq(paths.iter().map(Some)));
|
||||
|
||||
// A replay of this input, or another input path seeing it, cannot send it again.
|
||||
hooks.raw_input(&ctx, &mut raw);
|
||||
forward_app_input(&sender, &raw);
|
||||
assert!(intake.take().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn root_drop_still_reaches_intake_only_from_app_input() {
|
||||
let (intake, sender) = FileIntake::new(Wake::none());
|
||||
let hooks = ChildDrops(sender.clone());
|
||||
let ctx = Context::default();
|
||||
let path = std::env::temp_dir().join("document.docx");
|
||||
let mut raw = raw_drops(ViewportId::ROOT, std::slice::from_ref(&path));
|
||||
|
||||
// Pinned eframe calls both hooks on ROOT, in this order.
|
||||
hooks.raw_input(&ctx, &mut raw);
|
||||
assert!(intake.take().is_empty());
|
||||
forward_app_input(&sender, &raw);
|
||||
let batches = intake.take();
|
||||
let [Intake::Dropped { files }] = batches.as_slice() else { panic!("expected one root drop batch, got {batches:?}") };
|
||||
assert!(matches!(files.as_slice(), [file] if file.path.as_ref() == Some(&path)));
|
||||
assert!(matches!(raw.dropped_files.as_slice(), [file] if file.path() == path.as_path()));
|
||||
}
|
||||
}
|
||||
+234
-187
@@ -19,6 +19,8 @@ mod build_channel;
|
||||
mod build_flavor;
|
||||
mod control_server;
|
||||
mod default_apps;
|
||||
mod document_panels;
|
||||
mod drop_intake;
|
||||
mod launch_profile;
|
||||
#[cfg(target_os = "macos")]
|
||||
mod native_menu;
|
||||
@@ -27,6 +29,7 @@ mod prefs;
|
||||
mod process_identity;
|
||||
mod profile_root;
|
||||
mod region;
|
||||
mod startup_mode;
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::sync::{Arc, Mutex, OnceLock};
|
||||
@@ -40,12 +43,12 @@ use craft::platform::appearance::SystemReader;
|
||||
use craft::platform::clipboard::{Clipboard, ClipboardImage, SystemClipboard};
|
||||
use craft::platform::default_app::{DefaultApp, DefaultAppError};
|
||||
use craft::platform::logs::{self, LogNames, crash};
|
||||
use craft::platform::open::{DroppedFile, FileIntake, IntakeSender};
|
||||
use craft::platform::open::{FileIntake, IntakeSender};
|
||||
use craft::print::spool::Spool;
|
||||
use craft::settings::SharedSettings;
|
||||
use craft::ui::InstallSpec;
|
||||
use craft::ui::runtime::windows::{WindowAction, WindowHost};
|
||||
use craft::ui::shell::embed;
|
||||
use craft::ui::shell::embed::{self, CloseDecision};
|
||||
use craft::window::restore::{self, Store};
|
||||
use craft::window::system::SystemWindows;
|
||||
use wordcraft_engine::Session;
|
||||
@@ -60,6 +63,8 @@ struct App {
|
||||
native_menu: Option<craft::menu::NativeMenu>,
|
||||
/// The native panels behind the file service the app reaches through `Host::files`.
|
||||
panels: FilePanels,
|
||||
/// Native parent windows for the owned picker route, populated only in windowless mode.
|
||||
document_windows: document_panels::DocumentWindows,
|
||||
/// Feeds the files dropped on the window into the app's intake (`Services::intake`), the one
|
||||
/// queue the OS's requests are read from.
|
||||
drops: IntakeSender,
|
||||
@@ -86,19 +91,35 @@ impl App {
|
||||
/// One frame's logic: what the OS asked, the app, its file dialogs, then the root window's close
|
||||
/// path. Without `frame` (a test over no window) the dialogs have no parent window.
|
||||
fn logic_pass(&mut self, ctx: &egui::Context, frame: Option<&eframe::Frame>) {
|
||||
// Validate native incarnations before WordApp logic can settle an available answer.
|
||||
// A final Quit from a previous pass takes priority over launching any new pick.
|
||||
if self.app.quit_requested {
|
||||
self.app.quiesce_native_file_panels();
|
||||
}
|
||||
self.app.pump_owned_picks(ctx, &mut self.document_windows);
|
||||
self.app.logic(ctx);
|
||||
#[cfg(target_os = "macos")]
|
||||
if let Some(menu) = &mut self.native_menu {
|
||||
native_menu::update(menu, &mut self.app, ctx);
|
||||
}
|
||||
self.panels.pump_with(self.app.dialog_host_mut(), frame);
|
||||
// A quit that waits for nothing (the documents are answered for) closes the root window.
|
||||
if self.app.quit_requested && !self.app.printing.busy() {
|
||||
// Once the document guards have settled Quit, not even this pass's last pump can open
|
||||
// another picker. Keep the event loop and display alive for handles already in use.
|
||||
if self.app.quit_requested {
|
||||
self.app.quiesce_native_file_panels();
|
||||
}
|
||||
self.pump_file_panels(ctx, frame);
|
||||
if self.app.quit_requested && !self.app.printing.busy() && !self.app.native_file_panels_open() {
|
||||
WindowHost::of(ctx).act(egui::ViewportId::ROOT, WindowAction::Close);
|
||||
}
|
||||
// The decision holds the close while a Save Changes prompt is open; a closure over
|
||||
// `close_requested` would ask again on every frame of the prompt.
|
||||
embed::logic(ctx, || self.app.close_decision());
|
||||
// A platform close can be accepted without setting quit_requested (e.g. no unsaved work).
|
||||
// Shut off new launches only when that final close is accepted, not before a Save prompt.
|
||||
embed::logic(ctx, || {
|
||||
let decision = self.app.close_decision();
|
||||
if matches!(decision, CloseDecision::Close) {
|
||||
self.app.quiesce_native_file_panels();
|
||||
}
|
||||
decision
|
||||
});
|
||||
}
|
||||
|
||||
/// One pass of the root window's UI.
|
||||
@@ -107,7 +128,12 @@ impl App {
|
||||
embed::before_ui(ui.ctx(), frame);
|
||||
}
|
||||
self.app.ui(ui);
|
||||
self.pump_file_panels(ui.ctx(), frame);
|
||||
}
|
||||
|
||||
fn pump_file_panels(&mut self, ctx: &egui::Context, frame: Option<&eframe::Frame>) {
|
||||
self.panels.pump_with(self.app.dialog_host_mut(), frame);
|
||||
self.app.pump_owned_picks(ctx, &mut self.document_windows);
|
||||
}
|
||||
|
||||
/// Everything that must happen before the process ends, whichever way the window closes.
|
||||
@@ -134,11 +160,7 @@ impl eframe::App for App {
|
||||
/// Hands the app what the runtime gathered since the last frame (fired commands) and the
|
||||
/// runtime the input the app gives back, before any pass of the frame runs.
|
||||
fn raw_input_hook(&mut self, ctx: &egui::Context, raw: &mut egui::RawInput) {
|
||||
// Once per frame, before any pass; the files stay in `raw` for the runtime's own reading.
|
||||
let files = dropped_files(raw);
|
||||
if !files.is_empty() {
|
||||
self.drops.dropped(files);
|
||||
}
|
||||
drop_intake::forward_app_input(&self.drops, raw);
|
||||
self.before_input(ctx);
|
||||
}
|
||||
fn logic(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||
@@ -152,21 +174,6 @@ impl eframe::App for App {
|
||||
}
|
||||
}
|
||||
|
||||
/// The files dropped in this frame's input, as the intake carries them: a file with a path by its
|
||||
/// path, a file without one by its bytes.
|
||||
fn dropped_files(raw: &egui::RawInput) -> Vec<DroppedFile> {
|
||||
raw.dropped_files
|
||||
.iter()
|
||||
.map(|file| {
|
||||
let path = Some(file.path().to_path_buf()).filter(|p| !p.as_os_str().is_empty());
|
||||
let name = path.as_ref().and_then(|p| p.file_name()).map(|n| n.to_string_lossy().into_owned()).unwrap_or_default();
|
||||
// A file without a path (the web) carries its bytes; one that cannot be read is dropped as empty.
|
||||
let bytes = if path.is_none() { file.bytes().ok().map(std::sync::Arc::from) } else { None };
|
||||
DroppedFile { path, name, bytes }
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Whether the window runs through XWayland (X11) rather than native Wayland, and the log line
|
||||
/// saying why. `WORDCRAFT_WAYLAND` wins (`0`, `false`, `no` or `off` asks for X11, any other value
|
||||
/// for Wayland), then File › Options › Advanced › Linux display server (#2184). Automatic is X11
|
||||
@@ -616,25 +623,17 @@ fn main() -> eframe::Result {
|
||||
Some(_) => wordcraft_ui_egui::os_window::app_id().to_string(),
|
||||
None => std::env::var("FLATPAK_ID").ok().filter(|id| !id.is_empty()).unwrap_or_else(|| wordcraft_ui_egui::os_window::APP_ID.to_string()),
|
||||
};
|
||||
let mut options = eframe::NativeOptions {
|
||||
viewport: egui::ViewportBuilder::default()
|
||||
.with_title(wordcraft_ui_egui::os_window::name_for(wordcraft_ui_egui::os_window::identity()))
|
||||
.with_app_id(app_id)
|
||||
.with_inner_size([1440.0, 920.0])
|
||||
.with_min_inner_size(wordcraft_ui_egui::window_geometry::MIN_SIZE)
|
||||
.with_drag_and_drop(true)
|
||||
.with_fullsize_content_view(true)
|
||||
.with_titlebar_shown(false)
|
||||
.with_title_shown(false),
|
||||
..Default::default()
|
||||
};
|
||||
let mut viewport = egui::ViewportBuilder::default()
|
||||
.with_title(wordcraft_ui_egui::os_window::name_for(wordcraft_ui_egui::os_window::identity()))
|
||||
.with_app_id(app_id)
|
||||
.with_inner_size([1440.0, 920.0])
|
||||
.with_min_inner_size(wordcraft_ui_egui::window_geometry::MIN_SIZE)
|
||||
.with_drag_and_drop(true)
|
||||
.with_fullsize_content_view(true)
|
||||
.with_titlebar_shown(false)
|
||||
.with_title_shown(false);
|
||||
if let Some(icon) = app_icon() {
|
||||
options.viewport = options.viewport.with_icon(icon);
|
||||
}
|
||||
// Before eframe creates the wgpu instance: the backends, power preference, shader compiler and
|
||||
// the GPU that drives the screen (#603, #2652, #5199).
|
||||
if let eframe::egui_wgpu::WgpuSetup::CreateNew(setup) = &mut options.wgpu_options.wgpu_setup {
|
||||
craft::gpu::configure(setup);
|
||||
viewport = viewport.with_icon(icon);
|
||||
}
|
||||
prefs::load_user_fonts();
|
||||
// Where the root window was last, kept beside the settings; in memory when preferences are off.
|
||||
@@ -653,16 +652,18 @@ fn main() -> eframe::Result {
|
||||
let display_server = settings.lock().get().display_server;
|
||||
let (x11, why) = uses_x11(display_server, |name| std::env::var_os(name), x11_libraries);
|
||||
log::info!("{why}");
|
||||
if x11 {
|
||||
options.event_loop_builder = Some(Box::new(|b| {
|
||||
use winit::platform::x11::EventLoopBuilderExtX11;
|
||||
b.with_x11();
|
||||
}));
|
||||
}
|
||||
x11
|
||||
};
|
||||
#[cfg(not(all(unix, not(target_os = "macos"))))]
|
||||
let x11 = false;
|
||||
// The windowless root by default; windowed when rolled back, or when winit will open X11 or
|
||||
// XWayland, which its bootstrap doesn't support (`startup_mode`).
|
||||
#[cfg(all(unix, not(target_os = "macos")))]
|
||||
let winit_x11 = startup_mode::winit_picks_x11(x11, |name| std::env::var_os(name));
|
||||
#[cfg(not(all(unix, not(target_os = "macos"))))]
|
||||
let winit_x11 = false;
|
||||
let first_mode = startup_mode::first_mode(std::env::var_os(startup_mode::ROLLBACK_VAR).as_deref(), winit_x11);
|
||||
log::info!("root: {first_mode:?} first");
|
||||
// What the OS asks of a running app arrives here; its wake repaints once the window exists.
|
||||
let repaint: Arc<OnceLock<egui::Context>> = Arc::new(OnceLock::new());
|
||||
let (intake, sender) = FileIntake::new(Wake::new({
|
||||
@@ -673,9 +674,39 @@ fn main() -> eframe::Result {
|
||||
}
|
||||
}
|
||||
}));
|
||||
let drops = intake.sender();
|
||||
// Each start's options, from scratch: a fallback start gets the plain windowed ones.
|
||||
let hook_drops = drops.clone();
|
||||
let document_windows = document_panels::DocumentWindows::default();
|
||||
let hook_windows = document_windows.clone();
|
||||
let native_options = move |mode: eframe::RootViewportMode| {
|
||||
let mut options = eframe::NativeOptions {
|
||||
root_viewport_mode: mode,
|
||||
// A refused start must return here, on the thread whose event loop the fallback reuses.
|
||||
run_and_return: true,
|
||||
viewport: viewport.clone(),
|
||||
..Default::default()
|
||||
};
|
||||
// Before eframe creates the wgpu instance: the backends, power preference, shader compiler
|
||||
// and the GPU that drives the screen (#603, #2652, #5199).
|
||||
if let eframe::egui_wgpu::WgpuSetup::CreateNew(setup) = &mut options.wgpu_options.wgpu_setup {
|
||||
craft::gpu::configure(setup);
|
||||
}
|
||||
// Read only when the first start builds the event loop; a fallback reuses that loop.
|
||||
#[cfg(all(unix, not(target_os = "macos")))]
|
||||
if x11 {
|
||||
options.event_loop_builder = Some(Box::new(|b| {
|
||||
use winit::platform::x11::EventLoopBuilderExtX11;
|
||||
b.with_x11();
|
||||
}));
|
||||
}
|
||||
if mode == eframe::RootViewportMode::Windowless {
|
||||
options.viewport_hooks = Some(hook_windows.hooks(hook_drops.clone()));
|
||||
}
|
||||
options
|
||||
};
|
||||
// Registered before the event loop starts, so it catches the Finder event that launched us as
|
||||
// well as later ones. Lives until the event loop returns.
|
||||
let drops = intake.sender();
|
||||
#[cfg(target_os = "macos")]
|
||||
let _apple_events = craft::platform::open::apple_events::install(sender);
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
@@ -705,147 +736,161 @@ fn main() -> eframe::Result {
|
||||
let noticed_for_exit = unclean_notice_shown.clone();
|
||||
let noticed_in_window = unclean_notice_shown.clone();
|
||||
let exit_settings = settings.clone();
|
||||
let result = eframe::run_native(
|
||||
wordcraft_ui_egui::os_window::name_for(wordcraft_ui_egui::os_window::identity()),
|
||||
options,
|
||||
Box::new(move |cc| {
|
||||
let ctx = cc.egui_ctx.clone();
|
||||
let _ = repaint.set(ctx.clone());
|
||||
let wake = {
|
||||
let ctx = ctx.clone();
|
||||
move || ctx.request_repaint()
|
||||
};
|
||||
// The interface language: the saved choice, else the system's.
|
||||
let lang = wordcraft_ui_egui::i18n::Lang::from_pref(&settings.lock().get().language);
|
||||
let (file_service, panels) = FileService::new(Wake::new(wake.clone()));
|
||||
let host = Arc::new(
|
||||
Host::builder(wordcraft_ui_egui::APP)
|
||||
.i18n(wordcraft_ui_egui::i18n::catalogs())
|
||||
.files(Arc::new(file_service))
|
||||
.settings(Arc::new(settings.clone()))
|
||||
.lang(lang.craft_lang())
|
||||
.build(),
|
||||
);
|
||||
let shell = ShellInfo::current().backend(if x11 { Backend::X11 } else { Backend::from_env() });
|
||||
let spec = InstallSpec::new(shell, Arc::new(SystemWindows))
|
||||
.app_id(wordcraft_ui_egui::os_window::app_id())
|
||||
.system(SystemReader::start(wake))
|
||||
.clipboard(Clipboard::new(SystemClipboard::new().decoder(decode_png)))
|
||||
.placement(placement);
|
||||
// PLAN: assumed `wordcraft_ui_egui::ui_fonts` re-exports sh.A10's `app::fonts::ui_fonts` (`mod app` is private; app-hub/shell-w11).
|
||||
embed::install(&ctx, spec, &wordcraft_ui_egui::ui_fonts(lang)).map_err(|e| format!("the runtime could not be installed: {e}"))?;
|
||||
// The system region picks the new document's paper, the units and the decimal
|
||||
// separator (#838).
|
||||
let region = region::system();
|
||||
let doc = if sample { wordcraft_engine::sample::sample_document() } else { wordcraft_engine::blank_document(®ion) };
|
||||
let mut session = Session::new(doc);
|
||||
session.system_region = region;
|
||||
// The custom dictionary's words (#40) count as loaded settings.
|
||||
if prefs::enabled()
|
||||
&& let Some(path) = prefs::user_dict_path()
|
||||
{
|
||||
prefs::load_user_dictionary(&mut session, &settings, path);
|
||||
// Everything a start hands the app, used by the one creator that runs (`startup_mode::run`).
|
||||
let create_app = move |cc: &eframe::CreationContext<'_>,
|
||||
mode: eframe::RootViewportMode|
|
||||
-> Result<Box<dyn eframe::App>, Box<dyn std::error::Error + Send + Sync>> {
|
||||
let ctx = cc.egui_ctx.clone();
|
||||
let _ = repaint.set(ctx.clone());
|
||||
let wake = {
|
||||
let ctx = ctx.clone();
|
||||
move || ctx.request_repaint()
|
||||
};
|
||||
// The interface language: the saved choice, else the system's.
|
||||
let lang = wordcraft_ui_egui::i18n::Lang::from_pref(&settings.lock().get().language);
|
||||
let (file_service, panels) = FileService::new(Wake::new(wake.clone()));
|
||||
let host = Arc::new(
|
||||
Host::builder(wordcraft_ui_egui::APP)
|
||||
.i18n(wordcraft_ui_egui::i18n::catalogs())
|
||||
.files(Arc::new(file_service))
|
||||
.settings(Arc::new(settings.clone()))
|
||||
.lang(lang.craft_lang())
|
||||
.build(),
|
||||
);
|
||||
let shell = ShellInfo::current().backend(if x11 { Backend::X11 } else { Backend::from_env() });
|
||||
let spec = InstallSpec::new(shell, Arc::new(SystemWindows))
|
||||
.app_id(wordcraft_ui_egui::os_window::app_id())
|
||||
.system(SystemReader::start(wake))
|
||||
.clipboard(Clipboard::new(SystemClipboard::new().decoder(decode_png)))
|
||||
.placement(placement);
|
||||
// PLAN: assumed `wordcraft_ui_egui::ui_fonts` re-exports sh.A10's `app::fonts::ui_fonts` (`mod app` is private; app-hub/shell-w11).
|
||||
embed::install(&ctx, spec, &wordcraft_ui_egui::ui_fonts(lang)).map_err(|e| format!("the runtime could not be installed: {e}"))?;
|
||||
// The system region picks the new document's paper, the units and the decimal
|
||||
// separator (#838).
|
||||
let region = region::system();
|
||||
let doc = if sample { wordcraft_engine::sample::sample_document() } else { wordcraft_engine::blank_document(®ion) };
|
||||
let mut session = Session::new(doc);
|
||||
session.system_region = region;
|
||||
// The custom dictionary's words (#40) count as loaded settings.
|
||||
if prefs::enabled()
|
||||
&& let Some(path) = prefs::user_dict_path()
|
||||
{
|
||||
prefs::load_user_dictionary(&mut session, &settings, path);
|
||||
}
|
||||
let spool = Spool::new(host.jobs_shared().clone());
|
||||
let mut app = WordApp::new(session, services(spool.clone(), intake, nightly)).with_host(host).with_settings(settings.clone());
|
||||
let windowless = mode == eframe::RootViewportMode::Windowless;
|
||||
app.enable_windowless_trial(windowless);
|
||||
if windowless {
|
||||
app.set_native_window_lookup(Some(Arc::new(document_windows.clone())));
|
||||
}
|
||||
// Drawn by the processor (WARP, llvmpipe; #2221), animations that follow the system stop.
|
||||
if let Some(state) = &cc.wgpu_render_state {
|
||||
let info = state.adapter.get_info();
|
||||
let software = info.device_type == eframe::wgpu::DeviceType::Cpu;
|
||||
if software {
|
||||
log::warn!("graphics: drawing in software on {} ({:?}): animations that follow the system are off", info.name, info.backend);
|
||||
}
|
||||
let spool = Spool::new(host.jobs_shared().clone());
|
||||
let mut app = WordApp::new(session, services(spool.clone(), intake, nightly)).with_host(host).with_settings(settings.clone());
|
||||
// Drawn by the processor (WARP, llvmpipe; #2221), animations that follow the system stop.
|
||||
if let Some(state) = &cc.wgpu_render_state {
|
||||
let info = state.adapter.get_info();
|
||||
let software = info.device_type == eframe::wgpu::DeviceType::Cpu;
|
||||
if software {
|
||||
log::warn!("graphics: drawing in software on {} ({:?}): animations that follow the system are off", info.name, info.backend);
|
||||
}
|
||||
app.set_software_drawing(software);
|
||||
app.set_software_drawing(software);
|
||||
}
|
||||
// PLAN: writer note 9 puts `with_settings` after `with_control`; it comes first here because
|
||||
// the region check below reads the saved region the settings apply.
|
||||
if std::env::var("WORDCRAFT_FILE_DIALOG").is_ok_and(|v| v.trim().eq_ignore_ascii_case("builtin")) {
|
||||
app = app.with_fallback_chooser(true);
|
||||
}
|
||||
if nightly {
|
||||
// The Launcher installs Nightly; Help › Check for Updates says so instead.
|
||||
app.use_launcher_updates();
|
||||
} else {
|
||||
app.set_startup_update_check(true);
|
||||
// After the preferences, so the reason it gives is in the interface language.
|
||||
if updates_unsafe {
|
||||
app.disable_self_update();
|
||||
}
|
||||
// PLAN: writer note 9 puts `with_settings` after `with_control`; it comes first here because
|
||||
// the region check below reads the saved region the settings apply.
|
||||
if std::env::var("WORDCRAFT_FILE_DIALOG").is_ok_and(|v| v.trim().eq_ignore_ascii_case("builtin")) {
|
||||
app = app.with_fallback_chooser(true);
|
||||
}
|
||||
// Language packs from the suite's font store; an Install click is the person's own.
|
||||
// Nightly keeps its own store in the profile, so a pack installed there is not a
|
||||
// change to the stable apps' shared fonts.
|
||||
match launch_profile::current().root() {
|
||||
Some(root) => wordcraft_engine::packs::use_font_store_in(root.join("FontStore"), true),
|
||||
None => {
|
||||
wordcraft_engine::packs::use_font_store(true);
|
||||
}
|
||||
if nightly {
|
||||
// The Launcher installs Nightly; Help › Check for Updates says so instead.
|
||||
app.use_launcher_updates();
|
||||
} else {
|
||||
app.set_startup_update_check(true);
|
||||
// After the preferences, so the reason it gives is in the interface language.
|
||||
if updates_unsafe {
|
||||
app.disable_self_update();
|
||||
}
|
||||
}
|
||||
// A region chosen in File › Options replaces the system's for the first blank
|
||||
// document too (#838).
|
||||
if !sample && app.session.prefs.region.is_some() {
|
||||
let doc = app.session.blank_document();
|
||||
app.replace_startup_document(doc);
|
||||
}
|
||||
app.tell_about_font_downloads();
|
||||
if prefs::enabled()
|
||||
&& let Some(dir) = wordcraft_control_key::settings_dir()
|
||||
{
|
||||
let ctx = ctx.clone();
|
||||
if let Err(e) = app.session.enable_recovery(dir.join("recovery"), Arc::new(move || ctx.request_repaint())) {
|
||||
log::warn!("local recovery unavailable: {e}");
|
||||
}
|
||||
// Language packs from the suite's font store; an Install click is the person's own.
|
||||
// Nightly keeps its own store in the profile, so a pack installed there is not a
|
||||
// change to the stable apps' shared fonts.
|
||||
match launch_profile::current().root() {
|
||||
Some(root) => wordcraft_engine::packs::use_font_store_in(root.join("FontStore"), true),
|
||||
None => {
|
||||
wordcraft_engine::packs::use_font_store(true);
|
||||
}
|
||||
}
|
||||
let mut control_server = None;
|
||||
if !nightly
|
||||
&& let Some(port) = control.port
|
||||
&& let Some((rx, started)) = control_server::start(&control, port, WindowHost::of(&ctx), wordcraft_control_key::settings_dir().as_deref())
|
||||
{
|
||||
app = app.with_control(ControlChannel::new(rx));
|
||||
control_server = Some(started);
|
||||
}
|
||||
// Nothing to open (no files, no sample, no control channel driving the editor): start
|
||||
// on File › Home, as Word does (#766), unless the Start screen option is off. Files
|
||||
// the OS hands over later open on top of it and close it.
|
||||
if files.is_empty() && other_files.is_empty() && !sample && control.port.is_none() {
|
||||
app.start_screen();
|
||||
}
|
||||
// A Word template named here starts a new document based on it (#3433).
|
||||
for f in files {
|
||||
if let Err(e) = app.open_from_platform(&f, None) {
|
||||
app.report_open_failure(&f, &e);
|
||||
}
|
||||
// A region chosen in File › Options replaces the system's for the first blank
|
||||
// document too (#838).
|
||||
if !sample && app.session.prefs.region.is_some() {
|
||||
let doc = app.session.blank_document();
|
||||
app.replace_startup_document(doc);
|
||||
}
|
||||
app.tell_about_font_downloads();
|
||||
if prefs::enabled()
|
||||
&& let Some(dir) = wordcraft_control_key::settings_dir()
|
||||
{
|
||||
let ctx = ctx.clone();
|
||||
if let Err(e) = app.session.enable_recovery(dir.join("recovery"), Arc::new(move || ctx.request_repaint())) {
|
||||
log::warn!("local recovery unavailable: {e}");
|
||||
}
|
||||
}
|
||||
let mut control_server = None;
|
||||
if !nightly
|
||||
&& let Some(port) = control.port
|
||||
&& let Some((rx, started)) =
|
||||
control_server::start(&control, port, WindowHost::of(&ctx), wordcraft_control_key::settings_dir().as_deref())
|
||||
{
|
||||
app = app.with_control(ControlChannel::new(rx));
|
||||
control_server = Some(started);
|
||||
}
|
||||
// Nothing to open (no files, no sample, no control channel driving the editor): start
|
||||
// on File › Home, as Word does (#766), unless the Start screen option is off. Files
|
||||
// the OS hands over later open on top of it and close it.
|
||||
if files.is_empty() && other_files.is_empty() && !sample && control.port.is_none() {
|
||||
app.start_screen();
|
||||
}
|
||||
// A Word template named here starts a new document based on it (#3433).
|
||||
for f in files {
|
||||
if let Err(e) = app.open_from_platform(&f, None) {
|
||||
app.report_open_failure(&f, &e);
|
||||
}
|
||||
}
|
||||
for f in other_files {
|
||||
open_non_unicode(&mut app, &f);
|
||||
}
|
||||
// The personal agent files, the session record and the control token all live in the
|
||||
// profile; the app's own services are built with the nightly rule in mind.
|
||||
if let Some(warning) = &session_health_warning {
|
||||
app.status_long(warning.clone());
|
||||
}
|
||||
if previous_nightly_unclean {
|
||||
app.status_long(
|
||||
}
|
||||
for f in other_files {
|
||||
open_non_unicode(&mut app, &f);
|
||||
}
|
||||
// The personal agent files, the session record and the control token all live in the
|
||||
// profile; the app's own services are built with the nightly rule in mind.
|
||||
if let Some(warning) = &session_health_warning {
|
||||
app.status_long(warning.clone());
|
||||
}
|
||||
if previous_nightly_unclean {
|
||||
app.status_long(
|
||||
"The previous WordCraft Nightly session did not finish normally. You can report a problem from Help › About. No diagnostics have been sent.",
|
||||
);
|
||||
noticed_in_window.store(true, std::sync::atomic::Ordering::Relaxed);
|
||||
}
|
||||
Ok(Box::new(App {
|
||||
#[cfg(target_os = "macos")]
|
||||
native_menu: native_menu::install(&ctx, &app),
|
||||
app,
|
||||
panels,
|
||||
drops,
|
||||
settings,
|
||||
spool,
|
||||
control: control_server,
|
||||
exit: Some(Box::new(move || {
|
||||
nightly_session::finish_once(&session_for_exit, noticed_for_exit.load(std::sync::atomic::Ordering::Relaxed));
|
||||
})),
|
||||
}))
|
||||
}),
|
||||
);
|
||||
noticed_in_window.store(true, std::sync::atomic::Ordering::Relaxed);
|
||||
}
|
||||
Ok(Box::new(App {
|
||||
#[cfg(target_os = "macos")]
|
||||
native_menu: native_menu::install(&ctx, &app),
|
||||
app,
|
||||
panels,
|
||||
document_windows,
|
||||
drops,
|
||||
settings,
|
||||
spool,
|
||||
control: control_server,
|
||||
exit: Some(Box::new(move || {
|
||||
nightly_session::finish_once(&session_for_exit, noticed_for_exit.load(std::sync::atomic::Ordering::Relaxed));
|
||||
})),
|
||||
}))
|
||||
};
|
||||
let result = startup_mode::run(first_mode, create_app, |mode, inputs| {
|
||||
eframe::run_native(
|
||||
wordcraft_ui_egui::os_window::name_for(wordcraft_ui_egui::os_window::identity()),
|
||||
native_options(mode),
|
||||
Box::new(move |cc| {
|
||||
let create = inputs.take().ok_or("the app was already created")?;
|
||||
create(cc, mode)
|
||||
}),
|
||||
)
|
||||
});
|
||||
// The exit hook has run; this is the no-op fallback for a start that created no window.
|
||||
nightly_session::finish_once(&nightly_watch, unclean_notice_shown.load(std::sync::atomic::Ordering::Relaxed));
|
||||
// The app is dropped by now: whatever it saved on the way out is in the store.
|
||||
@@ -1009,6 +1054,7 @@ mod launch_arg_tests {
|
||||
#[cfg(test)]
|
||||
mod smoke {
|
||||
use super::*;
|
||||
use craft::platform::open::DroppedFile;
|
||||
use craft::ui::testing::Frames;
|
||||
use serde_json::json;
|
||||
|
||||
@@ -1056,6 +1102,7 @@ mod smoke {
|
||||
native_menu: None,
|
||||
app,
|
||||
panels,
|
||||
document_windows: Default::default(),
|
||||
drops,
|
||||
settings,
|
||||
spool,
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
//! Which root WordCraft starts with, and the one fallback to normal windows.
|
||||
//!
|
||||
//! The windowless root is the default. `WORDCRAFT_WINDOWLESS_TRIAL=0` (exactly `0`) rolls back to
|
||||
//! a windowed root; any other value, or none, keeps the default. On Linux and the BSDs the
|
||||
//! windowless bootstrap supports only native Wayland, so a start whose event loop winit will open
|
||||
//! on X11 or XWayland starts windowed from the outset and never retries ([`winit_picks_x11`]).
|
||||
//!
|
||||
//! Everything else is decided by eframe, from the display it actually connected to: its windowless
|
||||
//! bootstrap returns [`eframe::Error::UnsupportedConfiguration`] for an X11 display handle (and,
|
||||
//! on macOS and Windows, for a renderer bootstrap it cannot use) before it calls the app creator
|
||||
//! and before any root window exists. With `run_and_return` that error comes back out of
|
||||
//! `run_native`, the thread's event loop stays cached, and a second `run_native` on this thread
|
||||
//! reuses it. [`run`] then starts once more with normal windows, only when the creator has not
|
||||
//! started. Every other error, a second `UnsupportedConfiguration`, and any error after the
|
||||
//! creator started (including a document window whose surface cannot be attached later, which
|
||||
//! eframe reports per document) is returned unchanged.
|
||||
//!
|
||||
//! Source-only caveat: on a native Wayland display eframe's logical root takes the launcher's
|
||||
//! activation token before the renderer starts, so a fallback window there may open without it.
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
use eframe::RootViewportMode;
|
||||
|
||||
/// The variable that rolls the windowless root back to a windowed one, with the value `0`.
|
||||
pub(crate) const ROLLBACK_VAR: &str = "WORDCRAFT_WINDOWLESS_TRIAL";
|
||||
|
||||
/// The root mode of the first start: windowed when rolled back or when winit opens X11.
|
||||
pub(crate) fn first_mode(rollback: Option<&std::ffi::OsStr>, x11: bool) -> RootViewportMode {
|
||||
if x11 || rollback.is_some_and(|v| v == "0") { RootViewportMode::Windowed } else { RootViewportMode::Windowless }
|
||||
}
|
||||
|
||||
/// Whether winit's event loop opens on X11 (XWayland included): forced by the app, or unforced
|
||||
/// with no Wayland display and an X server. Mirrors the pinned winit's choice exactly: empty and
|
||||
/// non-Unicode values count as unset, and Wayland wins over `DISPLAY` when unforced. Neither set
|
||||
/// means winit fails to start at all, which no mode changes.
|
||||
#[cfg(all(unix, not(target_os = "macos")))]
|
||||
pub(crate) fn winit_picks_x11(forced_x11: bool, env: impl Fn(&str) -> Option<std::ffi::OsString>) -> bool {
|
||||
let set = |name: &str| env(name).is_some_and(|v| v.to_str().is_some_and(|v| !v.is_empty()));
|
||||
forced_x11 || (!set("WAYLAND_DISPLAY") && !set("WAYLAND_SOCKET") && set("DISPLAY"))
|
||||
}
|
||||
|
||||
/// The app's one-shot startup inputs, shared by every start but taken by one app creator only.
|
||||
pub(crate) struct OneShot<T>(Rc<RefCell<Option<T>>>);
|
||||
|
||||
impl<T> Clone for OneShot<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self(Rc::clone(&self.0))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> OneShot<T> {
|
||||
/// The inputs, for the app creator that runs; `None` once any creator has taken them.
|
||||
pub(crate) fn take(&self) -> Option<T> {
|
||||
self.0.borrow_mut().take()
|
||||
}
|
||||
|
||||
fn untouched(&self) -> bool {
|
||||
self.0.borrow().is_some()
|
||||
}
|
||||
}
|
||||
|
||||
/// Starts the app in `first` mode through `launch`, and once more with normal windows when a
|
||||
/// windowless start was refused as unsupported before its app creator took `inputs`.
|
||||
pub(crate) fn run<T>(first: RootViewportMode, inputs: T, mut launch: impl FnMut(RootViewportMode, OneShot<T>) -> eframe::Result) -> eframe::Result {
|
||||
let inputs = OneShot(Rc::new(RefCell::new(Some(inputs))));
|
||||
match launch(first, inputs.clone()) {
|
||||
Err(eframe::Error::UnsupportedConfiguration(reason)) if first == RootViewportMode::Windowless && inputs.untouched() => {
|
||||
log::warn!("windowless start unsupported here ({reason}); opening normal windows instead");
|
||||
launch(RootViewportMode::Windowed, inputs)
|
||||
}
|
||||
other => other,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use RootViewportMode::{Windowed, Windowless};
|
||||
|
||||
fn unsupported() -> eframe::Result {
|
||||
Err(eframe::Error::UnsupportedConfiguration("windowless root: X11".into()))
|
||||
}
|
||||
|
||||
/// Runs the real policy with scripted starts; each step sees whether it may create the app and
|
||||
/// returns that start's result. Returns the modes started, the modes that created the app, and
|
||||
/// the result.
|
||||
fn script(first: RootViewportMode, mut steps: Vec<(bool, eframe::Result)>) -> (Vec<RootViewportMode>, Vec<RootViewportMode>, eframe::Result) {
|
||||
steps.reverse();
|
||||
let mut started = Vec::new();
|
||||
let mut created = Vec::new();
|
||||
let result = run(first, "inputs", |mode, inputs| {
|
||||
started.push(mode);
|
||||
let (creates, result) = steps.pop().unwrap_or((false, Ok(())));
|
||||
if creates && inputs.take().is_some() {
|
||||
created.push(mode);
|
||||
}
|
||||
result
|
||||
});
|
||||
(started, created, result)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_unsupported_windowless_bootstrap_starts_once_more_with_windows() {
|
||||
let (started, created, result) = script(Windowless, vec![(false, unsupported()), (true, Ok(()))]);
|
||||
assert_eq!(started, [Windowless, Windowed]);
|
||||
assert_eq!(created, [Windowed], "the inputs reach the windowed start's creator, once");
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_windowed_start_is_the_last_one() {
|
||||
let (started, created, result) = script(Windowless, vec![(false, unsupported()), (false, unsupported())]);
|
||||
assert_eq!(started, [Windowless, Windowed]);
|
||||
assert!(created.is_empty());
|
||||
assert!(matches!(result, Err(eframe::Error::UnsupportedConfiguration(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_windowed_start_is_never_retried() {
|
||||
let (started, _, result) = script(first_mode(None, true), vec![(false, unsupported())]);
|
||||
assert_eq!(started, [Windowed], "X11 starts windowed, once");
|
||||
assert!(matches!(result, Err(eframe::Error::UnsupportedConfiguration(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn other_errors_come_back_unchanged() {
|
||||
let (started, _, result) = script(Windowless, vec![(false, Err(eframe::Error::AppCreation("no runtime".into())))]);
|
||||
assert_eq!(started, [Windowless]);
|
||||
assert!(matches!(result, Err(eframe::Error::AppCreation(e)) if e.to_string() == "no runtime"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nothing_starts_again_once_the_app_creator_ran() {
|
||||
let (started, created, result) = script(Windowless, vec![(true, unsupported())]);
|
||||
assert_eq!((started, created), (vec![Windowless], vec![Windowless]));
|
||||
assert!(matches!(result, Err(eframe::Error::UnsupportedConfiguration(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_exactly_zero_rolls_back() {
|
||||
let var = |v: &str| Some(std::ffi::OsString::from(v));
|
||||
assert_eq!(first_mode(var("0").as_deref(), false), Windowed);
|
||||
for value in [None, var("1"), var(""), var("off"), var(" 0")] {
|
||||
assert_eq!(first_mode(value.as_deref(), false), Windowless, "{value:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// The pinned winit opens Wayland whenever a Wayland display is named and the app forces
|
||||
/// nothing, even with `DISPLAY` set; X11 only when forced or with no Wayland display.
|
||||
#[cfg(all(unix, not(target_os = "macos")))]
|
||||
#[test]
|
||||
fn x11_is_what_winit_opens_not_what_the_session_says() {
|
||||
use std::os::unix::ffi::OsStringExt;
|
||||
let picks = |forced, vars: &[(&str, &str)]| {
|
||||
winit_picks_x11(forced, |name| vars.iter().find(|(k, _)| *k == name).map(|(_, v)| std::ffi::OsString::from(v)))
|
||||
};
|
||||
let both = [("DISPLAY", ":0"), ("WAYLAND_DISPLAY", "wayland-0")];
|
||||
assert!(picks(true, &both), "forced XWayland");
|
||||
assert!(!picks(false, &both), "unforced, Wayland wins");
|
||||
assert!(!picks(false, &[("DISPLAY", ":0"), ("WAYLAND_SOCKET", "3")]));
|
||||
assert!(picks(false, &[("DISPLAY", ":0"), ("WAYLAND_DISPLAY", "")]), "an empty Wayland display is unset");
|
||||
assert!(!picks(false, &[]));
|
||||
let non_unicode = |name: &str| match name {
|
||||
"DISPLAY" => Some(":0".into()),
|
||||
"WAYLAND_DISPLAY" => Some(std::ffi::OsString::from_vec(b"w\xe9".to_vec())),
|
||||
_ => None,
|
||||
};
|
||||
assert!(winit_picks_x11(false, non_unicode), "winit reads a non-Unicode Wayland display as unset");
|
||||
}
|
||||
}
|
||||
@@ -296,7 +296,6 @@ impl NumFormat {
|
||||
use crate::cjk_numbers as cjk;
|
||||
match self {
|
||||
NumFormat::DecimalZero => format!("{n:02}"),
|
||||
NumFormat::Hex => format!("{n:X}"),
|
||||
NumFormat::ThaiNumbers => thai_digits(n),
|
||||
NumFormat::UpperRoman => roman(n).to_uppercase(),
|
||||
NumFormat::LowerRoman => roman(n),
|
||||
@@ -342,6 +341,7 @@ impl NumFormat {
|
||||
NumFormat::Chosung => cjk::chosung(n),
|
||||
NumFormat::Decimal
|
||||
| NumFormat::DecimalHalfWidth
|
||||
| NumFormat::Hex
|
||||
| NumFormat::VietnameseCounting
|
||||
| NumFormat::Hebrew1
|
||||
| NumFormat::Hebrew2
|
||||
@@ -496,21 +496,13 @@ pub fn cardinal_text(n: u32) -> String {
|
||||
let h = format!("{} hundred", words(n / 100));
|
||||
if n.is_multiple_of(100) { h } else { format!("{h} {}", words(n % 100)) }
|
||||
}
|
||||
1_000..=999_999 => {
|
||||
_ => {
|
||||
let th = format!("{} thousand", words(n / 1000));
|
||||
if n.is_multiple_of(1000) { th } else { format!("{th} {}", words(n % 1000)) }
|
||||
}
|
||||
1_000_000..=999_999_999 => {
|
||||
let m = format!("{} million", words(n / 1_000_000));
|
||||
if n.is_multiple_of(1_000_000) { m } else { format!("{m} {}", words(n % 1_000_000)) }
|
||||
}
|
||||
_ => {
|
||||
let b = format!("{} billion", words(n / 1_000_000_000));
|
||||
if n.is_multiple_of(1_000_000_000) { b } else { format!("{b} {}", words(n % 1_000_000_000)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
capitalize(&words(n))
|
||||
capitalize(&words(n.min(999_999)))
|
||||
}
|
||||
|
||||
/// English ordinal words (`Twenty-First`).
|
||||
@@ -1012,17 +1004,6 @@ mod tests {
|
||||
assert_eq!(NumFormat::from_ooxml("klingon"), NumFormat::Decimal, "unknown formats are decimal");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hex_and_large_number_text() {
|
||||
assert_eq!(NumFormat::Hex.format(10), "A");
|
||||
assert_eq!(NumFormat::Hex.format(15), "F");
|
||||
assert_eq!(NumFormat::Hex.format(16), "10");
|
||||
assert_eq!(NumFormat::Hex.format(255), "FF");
|
||||
assert_eq!(NumFormat::CardinalText.format(1_000_000), "One Million");
|
||||
assert_eq!(NumFormat::OrdinalText.format(1_000_000), "One Millionth");
|
||||
assert_eq!(NumFormat::CardinalText.format(2_000_000_000), "Two Billion");
|
||||
}
|
||||
|
||||
/// #5757: Thai numbers are the decimal number in Thai digits, every digit, at any length.
|
||||
#[test]
|
||||
fn thai_numbers_use_thai_digits() {
|
||||
|
||||
@@ -402,7 +402,7 @@ pub fn update_fields_in(s: &mut Session, all: bool) -> Result<(), CmdError> {
|
||||
}
|
||||
let mut updates: Vec<(usize, String)> = Vec::new();
|
||||
for (k, o) in p.objects.iter().enumerate() {
|
||||
let InlineObject::Field { instr, result, locked: false, .. } = o else { continue };
|
||||
let InlineObject::Field { instr, locked: false, .. } = o else { continue };
|
||||
// A table formula reads the cells around its own cell again.
|
||||
if instr.trim_start().starts_with('=') {
|
||||
if let Some((tp, r, c)) = path.cell()
|
||||
@@ -425,15 +425,12 @@ pub fn update_fields_in(s: &mut Session, all: bool) -> Result<(), CmdError> {
|
||||
let created = s.doc.core.created.trim();
|
||||
// CREATEDATE shows when the document was created (ECMA-376 §17.16.5.11). A new
|
||||
// document, never saved, has no creation date yet and saving stamps now. A
|
||||
// file opened without one, or with one that can't be read, keeps any result
|
||||
// it already has; when inserted with none, it shows today's date (the date
|
||||
// a save would stamp).
|
||||
let text = if name == "CREATEDATE"
|
||||
&& let Some((unix, offset)) = created_at(created)
|
||||
{
|
||||
crate::cmd::insert::format_date_at_in(&pic, lang.as_deref(), unix, offset)
|
||||
} else if name != "CREATEDATE" || result.is_empty() || (created.is_empty() && s.path.is_none()) {
|
||||
// file opened without one, or with one that can't be read, keeps the result
|
||||
// it has.
|
||||
let text = if name != "CREATEDATE" || (created.is_empty() && s.path.is_none()) {
|
||||
crate::cmd::insert::format_date_in(&pic, lang.as_deref())
|
||||
} else if let Some((unix, offset)) = created_at(created) {
|
||||
crate::cmd::insert::format_date_at_in(&pic, lang.as_deref(), unix, offset)
|
||||
} else {
|
||||
continue;
|
||||
};
|
||||
|
||||
@@ -556,26 +556,6 @@ fn createdate_without_a_readable_creation_date() {
|
||||
assert_eq!(fields(&s)[0].1, crate::cmd::insert::format_date("yyyy-MM"));
|
||||
}
|
||||
|
||||
/// Inserting CREATEDATE into an opened file that has no creation date (plain text, Markdown, or a
|
||||
/// DOCX without `dcterms:created`) shows today's date rather than an empty result, while an
|
||||
/// existing field with a cached result keeps it.
|
||||
#[test]
|
||||
fn createdate_inserted_into_opened_file_without_creation_date() {
|
||||
let mut s = Session::new(wordcraft_doc::Document::from_text("Notes"));
|
||||
s.path = Some(std::env::temp_dir().join("notes.txt"));
|
||||
s.doc.core.created.clear();
|
||||
s.run("insert.field", &json!({"instr": r#"CREATEDATE \@ "yyyy-MM""#, "result": "2019-05"})).unwrap();
|
||||
s.run("insert.field", &json!({"instr": r#"CREATEDATE \@ "yyyy-MM""#})).unwrap();
|
||||
let expected = crate::cmd::insert::format_date("yyyy-MM");
|
||||
let results: Vec<String> = fields(&s).into_iter().map(|f| f.1).collect();
|
||||
assert_eq!(results, ["2019-05".to_string(), expected.clone()]);
|
||||
// An unreadable creation date behaves the same way: cached results stay, empty ones fill in.
|
||||
s.doc.core.created = "sometime in May".into();
|
||||
s.run("insert.field", &json!({"instr": r#"CREATEDATE \@ "yyyy-MM""#})).unwrap();
|
||||
let results: Vec<String> = fields(&s).into_iter().map(|f| f.1).collect();
|
||||
assert_eq!(results, ["2019-05".to_string(), expected.clone(), expected]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn toc_tabs_ignore_nonentries() {
|
||||
let mut s = Session::new(wordcraft_doc::Document::from_text("Before\nContents\nOld\t9\nAfter"));
|
||||
|
||||
@@ -136,30 +136,6 @@ fn a_selected_column_is_edited_cell_by_cell() {
|
||||
assert_eq!(s.cell_range().map(|r| r.cols), Some((1, 1)), "undo brings the column selection back");
|
||||
}
|
||||
|
||||
/// Toggling a format on a selected table column follows the first character in document order (#8589).
|
||||
#[test]
|
||||
fn toggle_on_a_selected_table_column_follows_first_character() {
|
||||
let toggled = |bold_row: usize| -> Vec<bool> {
|
||||
let mut s = table_session(3, 3);
|
||||
fill(&mut s);
|
||||
let p = cell_pos(&s, bold_row, 1);
|
||||
s.sel = Selection { anchor: p.clone(), focus: Pos { off: 4, ..p } };
|
||||
s.run("format.bold", &json!({"value": true})).unwrap();
|
||||
// Start from the bottom row so the caret is not on row 0.
|
||||
s.sel = Selection::caret(cell_pos(&s, 2, 1));
|
||||
s.run("table.selectColumn", &json!({})).unwrap();
|
||||
s.run("format.bold", &json!({})).unwrap();
|
||||
for r in 0..3 {
|
||||
assert!(!bold(&s, r, 0) && !bold(&s, r, 2), "row {r}'s other cells stay plain");
|
||||
}
|
||||
(0..3).map(|r| bold(&s, r, 1)).collect()
|
||||
};
|
||||
// First row bold, later rows plain: Bold turns off across the column.
|
||||
assert_eq!(toggled(0), vec![false, false, false]);
|
||||
// First row plain, middle row bold: Bold turns on across the column.
|
||||
assert_eq!(toggled(1), vec![true, true, true]);
|
||||
}
|
||||
|
||||
/// Numbering a column numbers its cells as one list, like Word.
|
||||
#[test]
|
||||
fn numbering_a_column_makes_one_list() {
|
||||
|
||||
@@ -52,15 +52,6 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
}
|
||||
Ok(json!({"paperColor": color}))
|
||||
}).params(r#"{"value": "document" | "green" | "cream" | "gray"}"#).pure(),
|
||||
// How the edges of page text are smoothed on screen. Screen only; never in the document.
|
||||
CommandSpec::new("view.textSmoothing", "Screen Text Smoothing", "View › Display", |s, v| {
|
||||
let smoothing: TextSmoothing = serde_json::from_value(v.get("value").cloned().unwrap_or(Value::Null))
|
||||
.map_err(|_| CmdError::Params("screen text smoothing must be system, grayscale, or subpixel".into()))?;
|
||||
s.prefs.text_smoothing = smoothing;
|
||||
Ok(json!({"textSmoothing": smoothing}))
|
||||
})
|
||||
.params(r#"{"value": "system" | "grayscale" | "subpixel"}"#)
|
||||
.pure(),
|
||||
// Print Layout: hide the white space (margins, headers, footers) between pages. Screen only.
|
||||
CommandSpec::new("view.hideWhiteSpace", "Hide White Space", "View › Show", |s, v| toggle(s, v, |x| &mut x.hide_white_space))
|
||||
.params(r#"{"value"?: bool}"#)
|
||||
@@ -358,35 +349,6 @@ fn read_line_spacing(s: &mut Session, v: &Value) -> CmdResult {
|
||||
Ok(json!({"spacing": spacing}))
|
||||
}
|
||||
|
||||
/// How the edges of page text are smoothed on screen, saved with user preferences, never in the
|
||||
/// document. Exports, prints and PDFs are not affected.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum TextSmoothing {
|
||||
/// As the system is set: subpixel where it asks for it (ClearType on Windows, `rgba`
|
||||
/// antialiasing on a Linux desktop) and the screen is not a high-density one, else
|
||||
/// greyscale. macOS never asks for it.
|
||||
#[default]
|
||||
System,
|
||||
/// Greyscale antialiasing: grey edges, no colour.
|
||||
Grayscale,
|
||||
/// Subpixel (LCD) antialiasing, whatever the system says: edges three times as fine
|
||||
/// sideways, with faint colour in them. In the system's stripe order, RGB when it gives none.
|
||||
Subpixel,
|
||||
}
|
||||
|
||||
impl TextSmoothing {
|
||||
pub const ALL: [Self; 3] = [Self::System, Self::Grayscale, Self::Subpixel];
|
||||
|
||||
pub fn label(self) -> &'static str {
|
||||
match self {
|
||||
Self::System => "Use system setting",
|
||||
Self::Grayscale => "Grayscale",
|
||||
Self::Subpixel => "Subpixel (LCD)",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Screen-only paper presets, saved with user preferences, never in the document.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
|
||||
@@ -10,10 +10,6 @@ pub struct Prefs {
|
||||
/// On-screen paper for pages without a document background; excluded from saved documents.
|
||||
#[serde(deserialize_with = "lenient_paper_color")]
|
||||
pub paper_color: crate::cmd::view::PaperColor,
|
||||
/// How the edges of page text are smoothed on screen (`view.textSmoothing`); excluded from
|
||||
/// saved documents.
|
||||
#[serde(deserialize_with = "lenient_text_smoothing")]
|
||||
pub text_smoothing: crate::cmd::view::TextSmoothing,
|
||||
/// Track Changes Options: what markup shows and how revisions are drawn (per user, as in
|
||||
/// Word).
|
||||
pub markup: wordcraft_layout::display::MarkupOptions,
|
||||
@@ -76,7 +72,6 @@ impl Default for Prefs {
|
||||
fn default() -> Self {
|
||||
Prefs {
|
||||
paper_color: Default::default(),
|
||||
text_smoothing: Default::default(),
|
||||
count_notes: true,
|
||||
markup: Default::default(),
|
||||
print_markup: false,
|
||||
@@ -124,12 +119,6 @@ fn lenient_paper_color<'de, D: serde::Deserializer<'de>>(d: D) -> Result<crate::
|
||||
Ok(serde_json::from_value(value).unwrap_or_default())
|
||||
}
|
||||
|
||||
/// Ignore an invalid saved text smoothing without discarding other preferences.
|
||||
fn lenient_text_smoothing<'de, D: serde::Deserializer<'de>>(d: D) -> Result<crate::cmd::view::TextSmoothing, D::Error> {
|
||||
let value = serde_json::Value::deserialize(d)?;
|
||||
Ok(serde_json::from_value(value).unwrap_or_default())
|
||||
}
|
||||
|
||||
/// Ignore an invalid saved Page Color without discarding other preferences.
|
||||
fn lenient_read_page_color<'de, D: serde::Deserializer<'de>>(d: D) -> Result<crate::cmd::view::ReadPageColor, D::Error> {
|
||||
let value = serde_json::Value::deserialize(d)?;
|
||||
|
||||
@@ -1118,58 +1118,6 @@ fn toggle_on_a_selection_from_an_empty_paragraph_follows_the_first_text() {
|
||||
assert_eq!(toggled(false, true), Some(false));
|
||||
}
|
||||
|
||||
/// Toggling a format on a selected text box follows the first character of its text (#8589).
|
||||
#[test]
|
||||
fn toggle_on_a_selected_text_box_follows_first_character() {
|
||||
let toggled = |first_bold: bool, second_bold: bool, leading_empty_bold: Option<bool>| -> String {
|
||||
let mut s = s();
|
||||
let id = run(&mut s, "insert.textBox", json!({}))["story"].as_u64().unwrap() as u32;
|
||||
let boxed = StoryRef::Part(id);
|
||||
if let Some(mark_bold) = leading_empty_bold {
|
||||
s.doc.para_mut(boxed, &wordcraft_doc::Path::top(0)).unwrap().mark.bold = Some(mark_bold);
|
||||
run(&mut s, "text.newParagraph", json!({}));
|
||||
}
|
||||
let text_block = usize::from(leading_empty_bold.is_some());
|
||||
run(&mut s, "text.insert", json!({"text": "ab"}));
|
||||
let box_pos = |off| Pos { story: boxed, path: wordcraft_doc::Path::top(text_block), off };
|
||||
run(&mut s, "select.range", json!({"anchor": box_pos(0), "focus": box_pos(1)}));
|
||||
run(&mut s, "format.bold", json!({"value": first_bold}));
|
||||
run(&mut s, "select.range", json!({"anchor": box_pos(1), "focus": box_pos(2)}));
|
||||
run(&mut s, "format.bold", json!({"value": second_bold}));
|
||||
let anchor = s.doc.text_box_anchor(id).unwrap();
|
||||
run(&mut s, "select.range", json!({"anchor": Pos { off: anchor.off - "\u{FFFC}".len(), ..anchor.clone() }, "focus": anchor}));
|
||||
run(&mut s, "format.bold", json!({}));
|
||||
let p = s.doc.para(boxed, &wordcraft_doc::Path::top(text_block)).unwrap();
|
||||
(0..2).map(|i| if p.props_of_char(i).bold == Some(true) { 'B' } else { '.' }).collect()
|
||||
};
|
||||
// First character bold, second plain: Bold turns off across the box.
|
||||
assert_eq!(toggled(true, false, None), "..");
|
||||
// First character plain, second bold: Bold turns on across the box.
|
||||
assert_eq!(toggled(false, true, None), "BB");
|
||||
// A bold empty paragraph at the top of the box does not override plain text after it.
|
||||
assert_eq!(toggled(false, true, Some(true)), "BB");
|
||||
}
|
||||
|
||||
/// Toggling a format on a column block follows the first character in document order (#8589).
|
||||
#[test]
|
||||
fn toggle_on_a_column_block_follows_first_character() {
|
||||
let toggled = |bold_row: usize, top_to_bottom: bool| -> Vec<bool> {
|
||||
let mut s = column_doc();
|
||||
run(&mut s, "select.range", json!({"anchor": {"block": bold_row, "off": 2}, "focus": {"block": bold_row, "off": 4}}));
|
||||
run(&mut s, "format.bold", json!({"value": true}));
|
||||
let (a, f) = if top_to_bottom { (Pos::body(0, 2), Pos::body(2, 4)) } else { (Pos::body(2, 4), Pos::body(0, 2)) };
|
||||
run(&mut s, "select.column", json!({"anchor": a, "focus": f}));
|
||||
run(&mut s, "format.bold", json!({}));
|
||||
(0..3).map(|i| s.doc.para_at(&Pos::body(i, 0)).unwrap().props_of_char(2).bold == Some(true)).collect()
|
||||
};
|
||||
// Row 0 bold, rows 1-2 plain: Bold turns off across the block even when selected bottom-to-top.
|
||||
assert_eq!(toggled(0, true), vec![false, false, false]);
|
||||
assert_eq!(toggled(0, false), vec![false, false, false]);
|
||||
// Row 0 plain, row 1 bold: Bold turns on across the block even when selected bottom-to-top.
|
||||
assert_eq!(toggled(1, true), vec![true, true, true]);
|
||||
assert_eq!(toggled(1, false), vec![true, true, true]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bold_at_a_caret_takes_a_word_with_a_typographic_apostrophe() {
|
||||
// Word bolds `don’t` and `dogs’` whole: `’` is part of the word like `'` (#6517).
|
||||
@@ -12675,12 +12623,10 @@ fn outline_level_changes_are_undoable() {
|
||||
assert!(s.run("outline.level", &json!({"level": 12})).is_err());
|
||||
assert!(s.run("outline.level", &json!({})).is_err());
|
||||
// Every outline command survives junk parameters in Outline view.
|
||||
let reg = cmd::registry();
|
||||
for spec in reg.all().iter().filter(|c| c.id.starts_with("outline.")) {
|
||||
for spec in cmd::registry().all().iter().filter(|c| c.id.starts_with("outline.")) {
|
||||
for j in [json!(null), json!({"block": 99999, "level": "x", "value": 5}), json!({"block": -1, "level": 0})] {
|
||||
let mut s = outline_doc();
|
||||
let r = s.run(spec.id, &j);
|
||||
assert!(!caught_panic(®, &r), "{} panicked on {j}: {r:?}", spec.id);
|
||||
let _ = s.run(spec.id, &j);
|
||||
let _ = s.layout();
|
||||
}
|
||||
}
|
||||
@@ -15279,37 +15225,6 @@ fn export_png_rejects_a_page_number_that_does_not_fit() {
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn screen_text_smoothing_is_a_persistent_preference_not_document_formatting() {
|
||||
use crate::cmd::view::TextSmoothing;
|
||||
let mut s = s();
|
||||
run(&mut s, "text.insert", json!({"text": "Screen text test", "raw": true}));
|
||||
let before = serde_json::to_value(&s.doc).unwrap();
|
||||
let docx_before = wordcraft_docx::write(&s.doc).unwrap();
|
||||
s.dirty = false;
|
||||
assert_eq!(s.prefs.text_smoothing, TextSmoothing::System, "follows the system until the user chooses");
|
||||
for (value, expected) in [("subpixel", TextSmoothing::Subpixel), ("grayscale", TextSmoothing::Grayscale), ("system", TextSmoothing::System)] {
|
||||
let r = run(&mut s, "view.textSmoothing", json!({"value": value}));
|
||||
assert_eq!(r["textSmoothing"], value);
|
||||
assert_eq!(s.prefs.text_smoothing, expected);
|
||||
assert_eq!(serde_json::to_value(&s.doc).unwrap(), before);
|
||||
assert!(!s.dirty);
|
||||
assert_eq!(wordcraft_docx::write(&s.doc).unwrap(), docx_before);
|
||||
let restored: crate::Prefs = serde_json::from_value(serde_json::to_value(&s.prefs).unwrap()).unwrap();
|
||||
assert_eq!(restored.text_smoothing, expected);
|
||||
}
|
||||
run(&mut s, "view.textSmoothing", json!({"value": "subpixel"}));
|
||||
for v in [json!({}), json!({"value": "lcd"}), json!({"value": 42}), json!({"value": null}), json!({"value": ["subpixel"]})] {
|
||||
assert!(s.run("view.textSmoothing", &v).is_err(), "{v}");
|
||||
assert_eq!(s.prefs.text_smoothing, TextSmoothing::Subpixel, "a refused value changes nothing");
|
||||
}
|
||||
let legacy: crate::Prefs = serde_json::from_value(json!({})).unwrap();
|
||||
assert_eq!(legacy.text_smoothing, TextSmoothing::System);
|
||||
let future: crate::Prefs = serde_json::from_value(json!({"textSmoothing":"future", "countNotes":false})).unwrap();
|
||||
assert_eq!(future.text_smoothing, TextSmoothing::System);
|
||||
assert!(!future.count_notes);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn screen_paper_color_is_a_persistent_preference_not_document_formatting() {
|
||||
use crate::cmd::view::PaperColor;
|
||||
|
||||
@@ -363,7 +363,7 @@ pub(crate) fn layout_box(ctx: &mut Ctx, input: BoxInput<'_>) -> BoxLayout {
|
||||
}
|
||||
floats.insert(oi, r);
|
||||
}
|
||||
let rel = rel_exclusions(&excl, 0.0, y, applied);
|
||||
let rel = rel_exclusions(&excl, 0.0, y);
|
||||
if !rel.is_empty() {
|
||||
pl = ctx.para_labelled(p, width, table, &rel, applied, label);
|
||||
}
|
||||
|
||||
@@ -219,10 +219,8 @@ pub(crate) fn wrap_area(r: Rect, float: &Float, outline: Option<&[(f32, f32)]>)
|
||||
Some((Rect::new(r.x - side, r.y - top, r.w + side * 2.0, r.h + top + bottom), float.wrap == Wrap::TopAndBottom, None, float.wrap_text, false))
|
||||
}
|
||||
|
||||
/// Wrap areas relative to a paragraph whose column starts at `x0` and whose top is `y0`, with
|
||||
/// `space_before` the space before it that the flow laid out above it.
|
||||
pub(crate) fn rel_exclusions(excl: &[WrapArea], x0: f32, y0: f32, space_before: f32) -> Vec<para::Exclusion> {
|
||||
let before = if space_before > 0.0 { space_before } else { 0.0 };
|
||||
/// Wrap areas relative to a paragraph whose column starts at `x0` and whose top is `y0`.
|
||||
pub(crate) fn rel_exclusions(excl: &[WrapArea], x0: f32, y0: f32) -> Vec<para::Exclusion> {
|
||||
excl.iter()
|
||||
.map(|(r, tb, c, side, table)| para::Exclusion {
|
||||
top: r.y - y0,
|
||||
@@ -234,11 +232,10 @@ pub(crate) fn rel_exclusions(excl: &[WrapArea], x0: f32, y0: f32, space_before:
|
||||
side: *side,
|
||||
table: *table,
|
||||
})
|
||||
// Top-and-Bottom areas ending within the paragraph's applied space before can still take
|
||||
// room, with that space laid out again below them (#7143). Any ending at or above it
|
||||
// (like side-wrapping areas above the first line) cannot reach the paragraph and is
|
||||
// dropped so paragraphs below keep empty exclusions and hit the cache (#8613).
|
||||
.filter(|e| e.bottom > 0.0 || (e.top_bottom && e.bottom > -before))
|
||||
// Top-and-Bottom areas above the first line can still take room: they sit in the
|
||||
// paragraph's space before, which Word lays out again below them (#7143). Side-wrapping
|
||||
// areas there are above the text and take no room, as before.
|
||||
.filter(|e| e.bottom > 0.0 || e.top_bottom)
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -531,7 +528,7 @@ fn anchor_floats_but(
|
||||
}
|
||||
}
|
||||
}
|
||||
let rel = rel_exclusions(&body_wraps(ctx, pb), col_x, y0, before);
|
||||
let rel = rel_exclusions(&body_wraps(ctx, pb), col_x, y0);
|
||||
let pl = ctx.para_labelled(p, width, None, &rel, before, label.clone());
|
||||
(rects, pl, rel)
|
||||
}
|
||||
@@ -867,7 +864,7 @@ pub(crate) fn place_objects(ctx: &mut Ctx, req: &ObjectPlacement) -> (Vec<Placed
|
||||
/// touch its lines and are left out.
|
||||
pub(crate) fn continued_exclusions(rel: &[para::Exclusion], excl: &[WrapArea], x0: f32, y: f32, t: f32, width: f32) -> Vec<para::Exclusion> {
|
||||
let before = rel.iter().filter(|e| e.top < t).map(|e| para::Exclusion { bottom: e.bottom.min(t), ..e.clone() });
|
||||
let here = rel_exclusions(excl, x0, y - t, 0.0)
|
||||
let here = rel_exclusions(excl, x0, y - t)
|
||||
.into_iter()
|
||||
.filter(|e| e.bottom > t && e.right > -width && e.left < 2.0 * width)
|
||||
.map(|e| if e.top < t && e.contour.is_none() { para::Exclusion { top: t, ..e } } else { e });
|
||||
|
||||
@@ -581,13 +581,6 @@ impl<'a> Builder<'a> {
|
||||
}
|
||||
}
|
||||
}
|
||||
// The ligature glyph's kerning pair with the following glyph belongs after its last
|
||||
// letter, not on the head inside the ligature (#8618).
|
||||
if let Some((head, rest)) = self.clusters.get_mut(i..=i + n).and_then(|cs| cs.split_first_mut())
|
||||
&& let Some(last) = rest.last_mut()
|
||||
{
|
||||
last.kern = std::mem::take(&mut head.kern);
|
||||
}
|
||||
i += n + 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,17 +99,14 @@ fn auto_space_room(st: &StyleRun) -> f32 {
|
||||
/// size for Times New Roman, 0.2203 for Arial, 0.2575 for Calibri, 0.2980 for Courier New,
|
||||
/// 0.3041 for Cambria — which is half each face's average character width. With different sizes
|
||||
/// either side, the room after the Latin run takes the Latin size, not the Asian one.
|
||||
///
|
||||
/// `ea_lacks(at, c)`: the run at byte `at` names an installed East Asian font that has no glyph
|
||||
/// for `c`. Word adds no room beside such a character, though a substituted face draws it (#6591).
|
||||
pub(super) fn auto_space(b: &mut Builder, text: &str, de: bool, dn: bool, ea_lacks: impl Fn(usize, char) -> bool) -> Vec<(usize, f32)> {
|
||||
pub(super) fn auto_space(b: &mut Builder, text: &str, de: bool, dn: bool) -> Vec<(usize, f32)> {
|
||||
let mut out = Vec::new();
|
||||
if !de && !dn {
|
||||
return out;
|
||||
}
|
||||
let mut shown = b.shown.iter().map(|s| (s.0, s.1.as_str())).peekable();
|
||||
// The previous text cluster: index, its last character and its start byte.
|
||||
let mut prev: Option<(usize, char, usize)> = None;
|
||||
// The previous text cluster: index and its last character.
|
||||
let mut prev: Option<(usize, char)> = None;
|
||||
for k in 0..b.clusters.len() {
|
||||
let Some(c) = b.clusters.get(k) else { break };
|
||||
match c.kind {
|
||||
@@ -129,13 +126,8 @@ pub(super) fn auto_space(b: &mut Builder, text: &str, de: bool, dn: bool, ea_lac
|
||||
prev = None;
|
||||
continue;
|
||||
};
|
||||
let start = c.start;
|
||||
if let Some((pk, pc, pstart)) = prev
|
||||
if let Some((pk, pc)) = prev
|
||||
&& let Some(side) = crate::kinsoku::auto_space(pc, first, de, dn)
|
||||
&& !match side {
|
||||
crate::kinsoku::AsianSide::Left => ea_lacks(pstart, pc),
|
||||
crate::kinsoku::AsianSide::Right => ea_lacks(start, first),
|
||||
}
|
||||
{
|
||||
let style = b.clusters.get(pk).map(|p| p.style as usize);
|
||||
let st = style.and_then(|i| b.styles.get(i));
|
||||
@@ -150,7 +142,7 @@ pub(super) fn auto_space(b: &mut Builder, text: &str, de: bool, dn: bool, ea_lac
|
||||
out.push((pk, gap));
|
||||
}
|
||||
}
|
||||
prev = Some((k, last, start));
|
||||
prev = Some((k, last));
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
@@ -268,13 +268,13 @@ impl<'e> Breaker<'e> {
|
||||
let lo = self.row_left(pl);
|
||||
// A Top-and-Bottom object ending in the paragraph's space before (or reaching into
|
||||
// its first line) is a block the first line must start below, with that space before
|
||||
// laid out again under it (#7143). Exclusions are relative to the first line's
|
||||
// original top (0), so keep the band anchored there (`[-before, est_h]`) even after
|
||||
// `row_spans` or `skip_row` moves `self.top` down past a side-wrapping object (#8614):
|
||||
// only the space the flow actually laid out above 0 holds a space-before obstruction.
|
||||
// laid out again under it (#7143). Exclusions are relative to the first line, so look
|
||||
// `space_before` above it too: the space the flow actually laid out, so an object
|
||||
// above a gap that collapsing, contextual spacing or a page top removed takes no
|
||||
// room, while the part of a merged gap that was laid out still does.
|
||||
if self.first && self.space_before > 0.0 {
|
||||
let before = self.space_before;
|
||||
let row = (-before, self.est_h + before, self.table_h);
|
||||
let row = (self.top - before, self.est_h + before, self.table_h);
|
||||
if let Some(below) = self
|
||||
.exclusions
|
||||
.iter()
|
||||
|
||||
@@ -663,22 +663,6 @@ fn shown_text(cx: &Cx) -> Option<String> {
|
||||
Some(shown)
|
||||
}
|
||||
|
||||
/// Each run's end byte and the installed East Asian font (`w:eastAsia`) it names, `None` when it
|
||||
/// names none or one that isn't installed. Empty when `wanted` is false or the text is ASCII, which
|
||||
/// has no East Asian characters to look the fonts up for.
|
||||
fn installed_east_asian_fonts(cx: &Cx, wanted: bool) -> Vec<(usize, Option<wordcraft_fonts::FaceRef>)> {
|
||||
if !wanted || cx.p.text.is_ascii() {
|
||||
return Vec::new();
|
||||
}
|
||||
cx.p.run_ranges()
|
||||
.map(|(range, props)| {
|
||||
let rc = cx.res.char(props);
|
||||
let face = rc.font_ea.as_deref().filter(|f| !f.trim().is_empty()).map(|f| wordcraft_fonts::word::resolve(f, rc.bold, rc.italic));
|
||||
(range.end, face.filter(|r| !r.substituted).map(|r| r.face))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Lay out one paragraph.
|
||||
pub fn layout_para(p: &Paragraph, env: &ParaEnv) -> ParaLayout {
|
||||
#[cfg(test)]
|
||||
@@ -714,12 +698,7 @@ pub fn layout_para(p: &Paragraph, env: &ParaEnv) -> ParaLayout {
|
||||
let auto_space = if rp.snap_to_grid && env.grid.snap_all && env.grid.chars.is_some() {
|
||||
Vec::new()
|
||||
} else {
|
||||
let ea = installed_east_asian_fonts(&cx, rp.auto_space_de || rp.auto_space_dn);
|
||||
// Runs come in order, so their ends rise: the run holding `at` is a binary search away.
|
||||
let ea_lacks = |at: usize, c: char| {
|
||||
ea.get(ea.partition_point(|(end, _)| *end <= at)).and_then(|(_, face)| *face).is_some_and(|f: wordcraft_fonts::FaceRef| !f.covers(c))
|
||||
};
|
||||
auto_space(&mut sh.b, &p.text, rp.auto_space_de, rp.auto_space_dn, ea_lacks)
|
||||
auto_space(&mut sh.b, &p.text, rp.auto_space_de, rp.auto_space_dn)
|
||||
};
|
||||
let mut skip = sh.left.clone();
|
||||
skip.extend(sh.bare.iter().cloned());
|
||||
|
||||
+1
-322
@@ -8896,73 +8896,6 @@ fn moved_kept_paragraph_lays_out_no_space_before_under_an_object_at_its_top() {
|
||||
assert!((top - bottom).abs() < 0.01, "the first line {top} starts at the rule's bottom {bottom}, with no space before laid out above it");
|
||||
}
|
||||
|
||||
/// #8614: when a side-wrapping object pushes the first line down before it is placed, the
|
||||
/// space-before Top-and-Bottom band must stay anchored to the first line's original top (0), not
|
||||
/// shift down with `self.top` into the paragraph's area and re-apply `space_before` below a
|
||||
/// Top-and-Bottom object ending there.
|
||||
#[test]
|
||||
fn side_wrapping_push_does_not_shift_space_before_band_into_para_area() {
|
||||
crate::test_fonts();
|
||||
use wordcraft_doc::para::{Anchor, Float, Wrap};
|
||||
use wordcraft_doc::props::LineSpacing;
|
||||
|
||||
const BEFORE: f32 = 12.0;
|
||||
|
||||
let build = |with_top_bottom: bool| {
|
||||
let mut d = Document::from_text("Anchor line.\nProbe line with several words in it.");
|
||||
for block in &mut d.body {
|
||||
if let wordcraft_doc::Block::Para(p) = Arc::make_mut(block) {
|
||||
p.props.space_before = Some(0.0);
|
||||
p.props.space_after = Some(0.0);
|
||||
p.props.line_spacing = Some(LineSpacing::Exactly(14.0));
|
||||
}
|
||||
}
|
||||
if let Some(wordcraft_doc::Block::Para(p)) = d.body.get_mut(1).map(Arc::make_mut) {
|
||||
p.props.space_before = Some(BEFORE);
|
||||
}
|
||||
let plain = lay(&d);
|
||||
let top_of = |l: &DocLayout, block: u32| {
|
||||
l.pages[0]
|
||||
.items
|
||||
.iter()
|
||||
.find_map(|i| match i {
|
||||
Placed::Lines { story: StoryRef::Body, path, y, .. } if path.0 == [block] => Some(*y),
|
||||
_ => None,
|
||||
})
|
||||
.unwrap()
|
||||
};
|
||||
let anchor_y = top_of(&plain, 0);
|
||||
let probe_y = top_of(&plain, 1);
|
||||
|
||||
// Full-width side-wrapping object starting at the probe's original top and extending 30 pt
|
||||
// down, pushing the probe's first line to probe_y + 30.
|
||||
let side = Float { wrap: Wrap::Square, h_rel: Anchor::Column, v_rel: Anchor::Paragraph, y: probe_y - anchor_y, ..Default::default() };
|
||||
d.insert_object(&Pos::body(0, 0), rect_shape(500.0, 30.0, side), &Default::default()).unwrap();
|
||||
|
||||
if with_top_bottom {
|
||||
// Top-and-Bottom object inside the side-wrapped vertical span (18..22 pt below probe_y),
|
||||
// below the original first line [0, 14] and above the Square object's bottom (30).
|
||||
let tb = Float {
|
||||
wrap: Wrap::TopAndBottom,
|
||||
h_rel: Anchor::Column,
|
||||
v_rel: Anchor::Paragraph,
|
||||
y: probe_y + 18.0 - anchor_y,
|
||||
..Default::default()
|
||||
};
|
||||
d.insert_object(&Pos::body(0, 0), rect_shape(144.0, 4.0, tb), &Default::default()).unwrap();
|
||||
}
|
||||
let l = lay(&d);
|
||||
top_of(&l, 1)
|
||||
};
|
||||
|
||||
let plain_wrap_top = build(false);
|
||||
let with_tb_top = build(true);
|
||||
assert!(
|
||||
(with_tb_top - plain_wrap_top).abs() < 0.01,
|
||||
"probe first line {with_tb_top} must stay at plain-wrap position {plain_wrap_top} without re-applying space_before"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn float_follows_its_paragraph_to_the_next_page() {
|
||||
crate::test_fonts();
|
||||
@@ -10239,6 +10172,7 @@ fn a_line_breaks_after_the_space_of_an_opening_bracket() {
|
||||
assert!(lines.iter().any(|l| l.trim_end().ends_with('(')), "no line ends with the bracket: {lines:?}");
|
||||
}
|
||||
|
||||
/// The lines of the body's first paragraph, as text.
|
||||
/// The text of every laid-out line.
|
||||
fn body_lines(l: &DocLayout, text: &str) -> Vec<String> {
|
||||
l.pages
|
||||
@@ -18371,186 +18305,6 @@ fn continuous_section_first_paragraph_running_over_keeps_first_page_header_hidde
|
||||
assert!(l.pages[next..].iter().all(|p| p.hf_slot == crate::HfSlot::Default));
|
||||
}
|
||||
|
||||
/// A continuous section starting mid-page has no first page of its own, so on its second page
|
||||
/// `header_table_areas` checks its default header rather than its first-page header.
|
||||
#[test]
|
||||
fn continuous_section_second_page_ignores_first_page_header_table() {
|
||||
use wordcraft_doc::para::Anchor;
|
||||
use wordcraft_doc::props::{HeightRule, LineSpacing, TableFloat};
|
||||
use wordcraft_doc::section::SectionStart;
|
||||
for start in [SectionStart::Continuous, SectionStart::NextPage] {
|
||||
let mut paras: Vec<String> = (0..10).map(|i| format!("Section 1 {i}")).collect();
|
||||
paras.extend((0..24).map(|i| format!("Section 2 {i}")));
|
||||
let mut d = Document::from_text(¶s.join("\n"));
|
||||
for block in &mut d.body {
|
||||
let Block::Para(p) = Arc::make_mut(block) else { panic!("paragraph") };
|
||||
p.props =
|
||||
ParaProps { space_before: Some(0.0), space_after: Some(0.0), line_spacing: Some(LineSpacing::Exactly(20.0)), ..Default::default() };
|
||||
}
|
||||
d.settings.compat_mode = 15;
|
||||
let make_table = |y, height| {
|
||||
let mut t = Table::new(1, 2, 300.0);
|
||||
t.props.cell_margins = Some([0.0; 4]);
|
||||
t.props.float = Some(TableFloat { h_rel: Anchor::Page, v_rel: Anchor::Page, x: 72.0, y, overlap: false, ..Default::default() });
|
||||
t.rows[0].props.height = Some(height);
|
||||
t.rows[0].props.height_rule = HeightRule::Exact;
|
||||
t
|
||||
};
|
||||
let first_hdr = d.add_part(wordcraft_doc::PartKind::Header, vec![Arc::new(Block::Table(make_table(60.0, 80.0)))]);
|
||||
let s1 = d.last_section.clone();
|
||||
d.para_mut(StoryRef::Body, &Path::top(9)).unwrap().section = Some(Box::new(s1));
|
||||
d.last_section.start = start;
|
||||
d.last_section.title_page = true;
|
||||
d.last_section.headers.first = Some(first_hdr);
|
||||
d.body.push(Arc::new(Block::Table(make_table(100.0, 48.0))));
|
||||
let l = lay(&d);
|
||||
let begins = l.caret(&Pos::body(10, 0)).unwrap().page;
|
||||
let target = match start {
|
||||
SectionStart::Continuous => {
|
||||
assert_eq!(l.caret(&Pos::body(9, 0)).unwrap().page, begins, "section 2 starts mid-page");
|
||||
begins + 1
|
||||
}
|
||||
_ => begins,
|
||||
};
|
||||
let cell_top = l.pages[target]
|
||||
.items
|
||||
.iter()
|
||||
.filter_map(|it| match it {
|
||||
Placed::Cell { rect, .. } => Some(rect.y),
|
||||
_ => None,
|
||||
})
|
||||
.fold(f32::MAX, f32::min);
|
||||
let expected = if start == SectionStart::Continuous { 100.0 } else { 140.0 };
|
||||
assert!((cell_top - expected).abs() < 0.01, "{start:?}: body floating table top {cell_top} on page {target}, expected {expected}");
|
||||
}
|
||||
}
|
||||
|
||||
/// The same for `footer_table_wraps`: body lines on a continuous section's second page do not wrap
|
||||
/// around a floating table in the section's first-page footer.
|
||||
#[test]
|
||||
fn continuous_section_second_page_ignores_first_page_footer_table_wrap() {
|
||||
use wordcraft_doc::para::Anchor;
|
||||
use wordcraft_doc::props::{HeightRule, LineSpacing, TableFloat};
|
||||
use wordcraft_doc::section::SectionStart;
|
||||
const FLOAT_TOP: f32 = 100.0;
|
||||
const TABLE_HEIGHT: f32 = 80.0;
|
||||
const TABLE_WIDTH: f32 = 468.0;
|
||||
for start in [SectionStart::Continuous, SectionStart::NextPage] {
|
||||
let mut paras: Vec<String> = (0..10).map(|i| format!("Section 1 {i}")).collect();
|
||||
let long = "Body wrap word ".repeat(22);
|
||||
paras.extend((0..14).map(|_| long.clone()));
|
||||
let mut d = Document::from_text(¶s.join("\n"));
|
||||
for block in &mut d.body[10..] {
|
||||
let Block::Para(p) = Arc::make_mut(block) else { panic!("paragraph") };
|
||||
p.props =
|
||||
ParaProps { space_before: Some(0.0), space_after: Some(0.0), line_spacing: Some(LineSpacing::Exactly(24.0)), ..Default::default() };
|
||||
}
|
||||
let mut table = Table::new(1, 1, TABLE_WIDTH);
|
||||
table.props.cell_margins = Some([0.0; 4]);
|
||||
table.props.float = Some(TableFloat { y: FLOAT_TOP, h_rel: Anchor::Page, v_rel: Anchor::Page, ..Default::default() });
|
||||
table.rows[0].props.height = Some(TABLE_HEIGHT);
|
||||
table.rows[0].props.height_rule = HeightRule::Exact;
|
||||
let first_ftr = d.add_part(wordcraft_doc::PartKind::Footer, vec![Arc::new(Block::Table(table))]);
|
||||
let s1 = d.last_section.clone();
|
||||
d.para_mut(StoryRef::Body, &Path::top(9)).unwrap().section = Some(Box::new(s1));
|
||||
d.last_section.start = start;
|
||||
d.last_section.title_page = true;
|
||||
d.last_section.footers.first = Some(first_ftr);
|
||||
let l = lay(&d);
|
||||
let begins = l.caret(&Pos::body(10, 0)).unwrap().page;
|
||||
let target = match start {
|
||||
SectionStart::Continuous => {
|
||||
assert_eq!(l.caret(&Pos::body(9, 0)).unwrap().page, begins, "section 2 starts mid-page");
|
||||
begins + 1
|
||||
}
|
||||
_ => begins,
|
||||
};
|
||||
assert!(l.pages.len() > target, "{start:?}: expected page {target}");
|
||||
let margin_left = d.last_section.margin_left;
|
||||
let beside: Vec<_> = (10..d.body.len() as u32)
|
||||
.flat_map(|b| line_boxes(&l, target, b, margin_left))
|
||||
.filter(|(_, top, _, bottom)| *bottom > FLOAT_TOP + 0.01 && *top < FLOAT_TOP + TABLE_HEIGHT - 0.01)
|
||||
.collect();
|
||||
assert!(!beside.is_empty(), "{start:?}: no body lines beside footer table band on page {target}");
|
||||
if start == SectionStart::Continuous {
|
||||
assert!(
|
||||
beside.iter().all(|(left, ..)| (*left - margin_left).abs() < 0.01),
|
||||
"{start:?}: continuous second page wrapped around first-page footer table: {beside:?}"
|
||||
);
|
||||
} else {
|
||||
assert!(
|
||||
beside.iter().all(|(left, ..)| *left >= TABLE_WIDTH - 0.01),
|
||||
"{start:?}: new-page section failed to wrap around first-page footer table: {beside:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The same `begins_section` rule governs `footer_story` (first-page versus default footer), both
|
||||
/// when the continuous section starts mid-page with separate paragraphs and when its first
|
||||
/// paragraph runs over onto the next page.
|
||||
#[test]
|
||||
fn continuous_section_first_page_footer_is_not_shown_on_its_second_page() {
|
||||
use wordcraft_doc::section::SectionStart;
|
||||
for start in [SectionStart::Continuous, SectionStart::NextPage] {
|
||||
let text = (0..140).map(|i| format!("Paragraph {i}")).collect::<Vec<_>>().join("\n");
|
||||
let mut d = Document::from_text(&text);
|
||||
let part = |d: &mut Document, t: &str| {
|
||||
d.add_part(wordcraft_doc::PartKind::Footer, vec![wordcraft_doc::para_block(Paragraph::with_text(t, Default::default()))])
|
||||
};
|
||||
let (one, first, two) = (part(&mut d, "ONE"), part(&mut d, "FIRST"), part(&mut d, "TWO"));
|
||||
let mut s1 = d.last_section.clone();
|
||||
s1.footers.default = Some(one);
|
||||
d.para_mut(StoryRef::Body, &Path::top(19)).unwrap().section = Some(Box::new(s1));
|
||||
d.last_section.start = start;
|
||||
d.last_section.title_page = true;
|
||||
d.last_section.footers.first = Some(first);
|
||||
d.last_section.footers.default = Some(two);
|
||||
let l = lay(&d);
|
||||
let begins = l.caret(&Pos::body(20, 0)).unwrap().page;
|
||||
let shown: Vec<_> = l.pages.iter().map(|p| p.footer_story).collect();
|
||||
assert!(l.pages.len() > begins + 2, "{start:?}: the second section runs over several pages");
|
||||
match start {
|
||||
SectionStart::Continuous => {
|
||||
assert_eq!(l.caret(&Pos::body(19, 0)).unwrap().page, begins, "the second section starts part-way down a page");
|
||||
assert_eq!(shown[begins], Some(one), "{start:?}: the page where it starts keeps the first section's footer");
|
||||
assert!(
|
||||
shown[begins + 1..].iter().all(|f| *f == Some(two)),
|
||||
"{start:?}: then its default footer, never its first-page one: {shown:?}"
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
assert_eq!(shown[begins], Some(first), "{start:?}: a section on a new page shows its first-page footer there");
|
||||
assert!(shown[begins + 1..].iter().all(|f| *f == Some(two)), "{start:?}: {shown:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut paras: Vec<String> = (0..44).map(|i| format!("Paragraph {i}")).collect();
|
||||
paras.push("word ".repeat(1200));
|
||||
paras.extend((0..60).map(|i| format!("After {i}")));
|
||||
let mut d = Document::from_text(¶s.join("\n"));
|
||||
let part = |d: &mut Document, t: &str| {
|
||||
d.add_part(wordcraft_doc::PartKind::Footer, vec![wordcraft_doc::para_block(Paragraph::with_text(t, Default::default()))])
|
||||
};
|
||||
let (one, first, two) = (part(&mut d, "ONE"), part(&mut d, "FIRST"), part(&mut d, "TWO"));
|
||||
let mut s1 = d.last_section.clone();
|
||||
s1.footers.default = Some(one);
|
||||
d.para_mut(StoryRef::Body, &Path::top(43)).unwrap().section = Some(Box::new(s1));
|
||||
d.last_section.start = SectionStart::Continuous;
|
||||
d.last_section.title_page = true;
|
||||
d.last_section.footers.first = Some(first);
|
||||
d.last_section.footers.default = Some(two);
|
||||
let l = lay(&d);
|
||||
let begins = l.caret(&Pos::body(44, 0)).unwrap().page;
|
||||
assert_eq!(l.caret(&Pos::body(43, 0)).unwrap().page, begins, "the second section starts part-way down a page");
|
||||
let next = begins + 1;
|
||||
assert!(l.pages.get(next).is_some_and(|p| p.first_block == 44), "its first paragraph runs over onto the next page");
|
||||
let shown: Vec<_> = l.pages.iter().map(|p| p.footer_story).collect();
|
||||
assert_eq!(shown[begins], Some(one));
|
||||
assert!(shown[next..].iter().all(|f| *f == Some(two)), "{shown:?}");
|
||||
}
|
||||
|
||||
/// Sections starting continuously one after another still go onto new pages: a paragraph that
|
||||
/// doesn't fit below the text above it moves on rather than running off the page (#3907). A
|
||||
/// hundred one-line sections lay out like a hundred plain paragraphs.
|
||||
@@ -19719,78 +19473,3 @@ fn evict_unused_caps_stale_entries_across_repeated_edits() {
|
||||
assert!(c.len() <= base + 1025, "stale cache entries must be bounded (got {}, base {base})", c.len());
|
||||
}
|
||||
}
|
||||
|
||||
/// #8613: a Top-and-Bottom object ending above a paragraph's applied space before cannot affect
|
||||
/// it, so paragraphs below keep empty exclusions and hit the cache when shifted vertically, and
|
||||
/// paragraphs below it in a box are not laid out twice.
|
||||
#[test]
|
||||
fn top_and_bottom_float_above_space_before_keeps_cache_hits_on_shift() {
|
||||
crate::test_fonts();
|
||||
use wordcraft_doc::para::{Anchor, Float, Wrap};
|
||||
use wordcraft_doc::props::LineSpacing;
|
||||
|
||||
let mut d = Document::from_text(&"line\n".repeat(12));
|
||||
for block in &mut d.body {
|
||||
if let wordcraft_doc::Block::Para(p) = Arc::make_mut(block) {
|
||||
p.props.line_spacing = Some(LineSpacing::Exactly(12.0));
|
||||
p.props.space_before = Some(0.0);
|
||||
p.props.space_after = Some(0.0);
|
||||
}
|
||||
}
|
||||
if let Some(wordcraft_doc::Block::Para(p)) = d.body.get_mut(4).map(Arc::make_mut) {
|
||||
p.props.space_before = Some(12.0);
|
||||
}
|
||||
let f = Float { wrap: Wrap::TopAndBottom, h_rel: Anchor::Column, v_rel: Anchor::Paragraph, ..Default::default() };
|
||||
d.insert_object(&Pos::body(0, 0), rect_shape(144.0, 10.0, f), &Default::default()).unwrap();
|
||||
|
||||
let mut c = LayoutCache::new();
|
||||
let before = layout(&d, &mut c, &LayoutOptions::default());
|
||||
let y_before = before.caret(&Pos::body(6, 0)).unwrap().top;
|
||||
let misses = c.misses;
|
||||
|
||||
d.insert_text(&Pos::body(2, 0), &"word ".repeat(30), &Default::default()).unwrap();
|
||||
let after = layout(&d, &mut c, &LayoutOptions::default());
|
||||
let y_after = after.caret(&Pos::body(6, 0)).unwrap().top;
|
||||
assert!(y_after > y_before + 10.0, "paragraphs below shifted down ({y_before} -> {y_after})");
|
||||
assert_eq!(c.misses, misses + 1, "only the edited paragraph should miss the cache");
|
||||
}
|
||||
|
||||
/// #8613: in table cells and other boxes, paragraphs below a Top-and-Bottom float (and clear of
|
||||
/// its space-before band) get empty exclusions, so they are laid out once and hit the cache when
|
||||
/// shifted vertically.
|
||||
#[test]
|
||||
fn top_and_bottom_float_in_cell_keeps_cache_hits_on_shift() {
|
||||
crate::test_fonts();
|
||||
use wordcraft_doc::para::{Anchor, Float, Wrap};
|
||||
use wordcraft_doc::props::LineSpacing;
|
||||
|
||||
let mut d = Document::new();
|
||||
let mut t = Table::new(1, 1, 468.0);
|
||||
t.props.fixed = true;
|
||||
t.rows[0].cells[0].blocks = (0..6)
|
||||
.map(|i| {
|
||||
let mut p = Paragraph::with_text(&format!("cell line {i}"), Default::default());
|
||||
p.props.line_spacing = Some(LineSpacing::Exactly(12.0));
|
||||
p.props.space_before = Some(0.0);
|
||||
p.props.space_after = Some(0.0);
|
||||
wordcraft_doc::para_block(p)
|
||||
})
|
||||
.collect();
|
||||
d.body = vec![Arc::new(wordcraft_doc::Block::Table(t))];
|
||||
let cell_pos = |para: usize| Pos { story: StoryRef::Body, path: Path(vec![0, 0, 0, para as u32]), off: 0 };
|
||||
let f = Float { wrap: Wrap::TopAndBottom, h_rel: Anchor::Column, v_rel: Anchor::Paragraph, ..Default::default() };
|
||||
d.insert_object(&cell_pos(0), rect_shape(100.0, 10.0, f), &Default::default()).unwrap();
|
||||
|
||||
let mut c = LayoutCache::new();
|
||||
let before = layout(&d, &mut c, &LayoutOptions::default());
|
||||
let y_before = before.caret(&cell_pos(4)).unwrap().top;
|
||||
// Paragraph 0 holds the float so it lays out twice; paragraphs 1..6 sit below it and lay out once each.
|
||||
assert_eq!(c.misses, 7, "paragraphs below the float should be laid out only once");
|
||||
let misses = c.misses;
|
||||
|
||||
d.insert_text(&cell_pos(1), &"word ".repeat(30), &Default::default()).unwrap();
|
||||
let after = layout(&d, &mut c, &LayoutOptions::default());
|
||||
let y_after = after.caret(&cell_pos(4)).unwrap().top;
|
||||
assert!(y_after > y_before + 10.0, "cell paragraphs below shifted down ({y_before} -> {y_after})");
|
||||
assert_eq!(c.misses, misses + 1, "only the edited cell paragraph should miss the cache");
|
||||
}
|
||||
|
||||
@@ -133,34 +133,6 @@ fn spaces_punctuation_hangul_and_latin_alone_get_nothing() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Word adds no automatic space, on either side, beside an ideograph whose run names an installed
|
||||
/// East Asian font without ideographs, even though a substituted face draws it (#6591: 0.00 pt
|
||||
/// with `w:eastAsia="Times New Roman"`). A font that isn't installed keeps the space.
|
||||
#[test]
|
||||
fn an_east_asian_font_without_ideographs_turns_it_off() {
|
||||
crate::test_fonts();
|
||||
let with = |latin: Option<&str>, asian: &str| {
|
||||
let mut d = Document::from_text("法院94年A字");
|
||||
let p = para0(&mut d);
|
||||
let len = p.text.len();
|
||||
p.format(0, len, &|c: &mut CharProps| {
|
||||
c.font = latin.map(str::to_string);
|
||||
c.font_ea = Some(asian.to_string());
|
||||
})
|
||||
.unwrap();
|
||||
d
|
||||
};
|
||||
// Source Serif 4 is installed for the tests and has no ideographs.
|
||||
for d in [with(None, "Source Serif 4"), with(Some("Source Serif 4"), "Source Serif 4")] {
|
||||
assert!(gaps(&d).iter().all(|g| *g == 0.0), "{:?}", gaps(&d));
|
||||
}
|
||||
let d = with(None, "No Such East Asian Font 6591");
|
||||
let q = quarter(&d);
|
||||
// The room after each Latin character follows the face that draws it, as without a
|
||||
// `w:eastAsia` font at all (#6583).
|
||||
assert_eq!(gaps(&d), [0.0, q, 0.0, after(&d, 7), q, after(&d, 11), 0.0], "a font that isn't installed");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_field_result_is_classed_by_the_text_it_shows() {
|
||||
crate::test_fonts();
|
||||
|
||||
@@ -112,49 +112,3 @@ fn a_letter_ending_a_line_keeps_its_pair_with_the_letter_before() {
|
||||
let got = body_lines(&lay(&doc(468.0 - six - 0.004)), text);
|
||||
assert_eq!(got.first().map(String::as_str), Some("AVAVAV"), "{got:?}");
|
||||
}
|
||||
|
||||
/// A ligature's kerning pair with the letter after it belongs on the ligature's last cluster, not
|
||||
/// on its head (#8618): a forced character wrap inside the ligature must not subtract the pair
|
||||
/// after the whole ligature, and a line ending after the ligature drops that pair.
|
||||
#[test]
|
||||
fn a_ligatures_kerning_pair_sits_on_its_last_cluster() {
|
||||
crate::test_fonts();
|
||||
let text = "flYflYflYflY";
|
||||
let doc = |indent_right: f32| {
|
||||
let mut d = Document::from_text(text);
|
||||
let st = Arc::make_mut(&mut d.styles);
|
||||
st.default_chr.font = Some("Source Serif 4".into());
|
||||
st.default_chr.size = Some(14.0);
|
||||
st.default_chr.kern = Some(1.0);
|
||||
d.format_paragraphs(&Pos::body(0, 0), &Pos::body(0, 0), &|p| p.indent_right = Some(indent_right)).unwrap();
|
||||
d
|
||||
};
|
||||
let l = lay(&doc(0.0));
|
||||
let para = l.pages[0].items.iter().find_map(|it| if let Placed::Lines { para, .. } = it { Some(para.clone()) } else { None }).unwrap();
|
||||
assert!(para.clusters[0].g1 > para.clusters[0].g0 && para.clusters[1].g1 == para.clusters[1].g0, "fixture forms an \"fl\" ligature");
|
||||
assert_eq!(para.clusters[0].kern, 0.0, "the ligature's head cluster carries no kerning pair");
|
||||
assert!(para.clusters[1].kern < -0.3, "the ligature's last cluster carries its pair with \"Y\": {}", para.clusters[1].kern);
|
||||
assert_eq!(para.clusters[3].kern, 0.0);
|
||||
let paired: f32 = para.clusters[..5].iter().map(|c| c.adv).sum();
|
||||
let alone = paired - para.clusters[4].kern;
|
||||
assert!(alone - paired > 0.3, "Source Serif 4 kerns \"fl\" + \"Y\": {paired} vs {alone}");
|
||||
// Between paired and alone: "flYfl" fits only with its pair with "Y", so "fl" wraps whole.
|
||||
let got = body_lines(&lay(&doc(468.0 - (paired + alone) / 2.0)), text);
|
||||
assert_eq!(got.first().map(String::as_str), Some("flY"), "{got:?}");
|
||||
// Wide enough for "flYfl" without the pair after it.
|
||||
let got = body_lines(&lay(&doc(468.0 - alone - 0.004)), text);
|
||||
assert_eq!(got.first().map(String::as_str), Some("flYfl"), "{got:?}");
|
||||
|
||||
// A three-letter ligature ("ffi") also puts its pair with "V" only on its last cluster.
|
||||
let mut d3 = Document::from_text("ffiV");
|
||||
let st3 = Arc::make_mut(&mut d3.styles);
|
||||
st3.default_chr.font = Some("Source Serif 4".into());
|
||||
st3.default_chr.size = Some(14.0);
|
||||
st3.default_chr.kern = Some(1.0);
|
||||
let l3 = lay(&d3);
|
||||
let p3 = l3.pages[0].items.iter().find_map(|it| if let Placed::Lines { para, .. } = it { Some(para.clone()) } else { None }).unwrap();
|
||||
assert!(p3.clusters[0].g1 > p3.clusters[0].g0 && p3.clusters[1].g1 == p3.clusters[1].g0 && p3.clusters[2].g1 == p3.clusters[2].g0);
|
||||
assert_eq!(p3.clusters[0].kern, 0.0);
|
||||
assert_eq!(p3.clusters[1].kern, 0.0);
|
||||
assert!(p3.clusters[2].kern < -0.2, "last cluster of \"ffi\" carries pair with \"V\": {}", p3.clusters[2].kern);
|
||||
}
|
||||
|
||||
@@ -107,7 +107,6 @@ fn write_attempt(doc: &Document, lay: &DocLayout, opts: &PdfOptions, pages: &[us
|
||||
objects: crate::exporter::ObjectLookup::new(doc),
|
||||
at: (0, 0),
|
||||
links: Vec::new(),
|
||||
last_link: None,
|
||||
bookmarks: std::cell::OnceCell::new(),
|
||||
};
|
||||
if let Some(o) = ex.outline(pages) {
|
||||
@@ -137,15 +136,8 @@ fn write_attempt(doc: &Document, lay: &DocLayout, opts: &PdfOptions, pages: &[us
|
||||
}
|
||||
}
|
||||
surface.finish();
|
||||
for (annotation, tag_slot) in annotations {
|
||||
if opts.tagged
|
||||
&& let Some((para_idx, child_idx)) = tag_slot
|
||||
{
|
||||
let annot_id = kp.add_tagged_annotation(annotation);
|
||||
ex.attach_link_annotation(para_idx, child_idx, annot_id);
|
||||
} else {
|
||||
kp.add_annotation(annotation);
|
||||
}
|
||||
for annotation in annotations {
|
||||
kp.add_annotation(annotation);
|
||||
}
|
||||
kp.finish();
|
||||
}
|
||||
|
||||
@@ -18,16 +18,6 @@ mod objects;
|
||||
pub(crate) use objects::ObjectLookup;
|
||||
mod text;
|
||||
|
||||
pub(crate) struct LinkRect {
|
||||
pub(crate) x0: f32,
|
||||
pub(crate) y0: f32,
|
||||
pub(crate) x1: f32,
|
||||
pub(crate) y1: f32,
|
||||
pub(crate) target: String,
|
||||
/// `(para_idx, child_idx)` in `Exporter::tags` for this link's `Tag::Link` group.
|
||||
pub(crate) tag: Option<(usize, usize)>,
|
||||
}
|
||||
|
||||
pub(crate) struct Exporter<'a> {
|
||||
pub(crate) doc: &'a Document,
|
||||
pub(crate) lay: &'a DocLayout,
|
||||
@@ -52,10 +42,8 @@ pub(crate) struct Exporter<'a> {
|
||||
pub(crate) objects: ObjectLookup<'a>,
|
||||
/// Where the item being drawn is read ([`TagEntry::at`]).
|
||||
pub(crate) at: (usize, usize),
|
||||
/// Link rectangles on the current page.
|
||||
pub(crate) links: Vec<LinkRect>,
|
||||
/// Index in `links` touched by the most recent `Draw::Glyphs` item, if any.
|
||||
pub(crate) last_link: Option<usize>,
|
||||
/// Link rectangles on the current page: (x0, y0, x1, y1, target).
|
||||
pub(crate) links: Vec<(f32, f32, f32, f32, String)>,
|
||||
/// Bookmark positions by name (the first of a name wins), gathered once: looking each internal
|
||||
/// link up by walking the whole document made a long document with a linked table of contents
|
||||
/// take seconds to export.
|
||||
@@ -206,48 +194,10 @@ impl Exporter<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Attach a paragraph's marked-content `id` to its `Tag::Link` group when `draw` recorded a
|
||||
/// link rectangle, or directly to the paragraph entry otherwise.
|
||||
fn attach_para_link(&mut self, idx: usize, id: Identifier) {
|
||||
if let Some(li) = self.last_link.take()
|
||||
&& let Some(link) = self.links.get_mut(li)
|
||||
{
|
||||
if let Some((p_idx, c_idx)) = link.tag
|
||||
&& let Some(Node::Group(g)) = self.tags.get_mut(p_idx).and_then(|e| e.children.get_mut(c_idx))
|
||||
{
|
||||
g.push(Node::Leaf(id));
|
||||
return;
|
||||
}
|
||||
if let Some(e) = self.tags.get_mut(idx) {
|
||||
let c_idx = e.children.len();
|
||||
e.children.push(Node::Group(TagGroup::with_children(Tag::Link, vec![Node::Leaf(id)])));
|
||||
link.tag = Some((idx, c_idx));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if let Some(e) = self.tags.get_mut(idx) {
|
||||
e.children.push(Node::Leaf(id));
|
||||
}
|
||||
}
|
||||
|
||||
/// Insert a link annotation's `OBJR` identifier as the first child of its `Tag::Link` group.
|
||||
pub(crate) fn attach_link_annotation(&mut self, para_idx: usize, child_idx: usize, annot_id: Identifier) {
|
||||
if let Some(Node::Group(g)) = self.tags.get_mut(para_idx).and_then(|e| e.children.get_mut(child_idx)) {
|
||||
g.children.insert(0, Node::Leaf(annot_id));
|
||||
}
|
||||
}
|
||||
|
||||
/// One draw of a paragraph's line, tagged for what it is: text as the paragraph's content
|
||||
/// (structure entry `idx`), pictures and figures on their own, anything else an artifact.
|
||||
fn line_item(&mut self, s: &mut Surface, d: &Draw, idx: usize, story: StoryRef, path: &DocPath) {
|
||||
match d {
|
||||
Draw::Glyphs { link: Some(_), .. } if self.opts.tagged && self.opts.links => {
|
||||
self.last_link = None;
|
||||
let id = s.start_tagged(ContentTag::Span(SpanTag::empty()));
|
||||
self.draw(s, d);
|
||||
s.end_tagged();
|
||||
self.attach_para_link(idx, id);
|
||||
}
|
||||
Draw::Glyphs { .. } | Draw::Turned { .. } => self.tagged(s, Role::Para(idx), None, |me, s| me.draw(s, d)),
|
||||
// A picture marked decorative: an artifact screen readers skip.
|
||||
Draw::Image { decorative: true, .. } => self.tagged(s, Role::Artifact(ArtifactType::Other), None, |me, s| me.draw(s, d)),
|
||||
|
||||
@@ -31,9 +31,7 @@ impl Exporter<'_> {
|
||||
}
|
||||
None => self.glyphs(s, face, *size, glyphs, paint, (text, ranges)),
|
||||
}
|
||||
if self.opts.links
|
||||
&& let Some(l) = link
|
||||
{
|
||||
if let Some(l) = link {
|
||||
self.link_rect(face, *size, glyphs, l);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,22 +53,24 @@ impl Exporter<'_> {
|
||||
None
|
||||
}
|
||||
|
||||
pub(super) fn link_target(&self, target: &str) -> Option<Target> {
|
||||
if let Some(name) = target.strip_prefix('#') {
|
||||
self.bookmark(name).map(|(page, x, y)| Target::Destination(XyzDestination::new(page, Point::from_xy(x, y)).into()))
|
||||
} else {
|
||||
// Unsafe targets (javascript:, file:, shares, other schemes) get no link; the text stays.
|
||||
write::uri_target(target)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn annotations(&self, fit: Fit) -> Vec<(Annotation, Option<(usize, usize)>)> {
|
||||
pub(crate) fn annotations(&self, fit: Fit) -> Vec<Annotation> {
|
||||
let mut v = Vec::new();
|
||||
for link in &self.links {
|
||||
let ((x0, y0), (x1, y1)) = (fit.point(link.x0, link.y0), fit.point(link.x1, link.y1));
|
||||
for (x0, y0, x1, y1, target) in &self.links {
|
||||
let ((x0, y0), (x1, y1)) = (fit.point(*x0, *y0), fit.point(*x1, *y1));
|
||||
let Some(rect) = krilla::geom::Rect::from_ltrb(x0, y0, x1, y1) else { continue };
|
||||
let Some(t) = self.link_target(&link.target) else { continue };
|
||||
v.push((Annotation::new_link(LinkAnnotation::new(rect, t), Some(link.target.clone())), link.tag));
|
||||
let t = if let Some(name) = target.strip_prefix('#') {
|
||||
match self.bookmark(name) {
|
||||
Some((page, x, y)) => Target::Destination(XyzDestination::new(page, Point::from_xy(x, y)).into()),
|
||||
None => continue,
|
||||
}
|
||||
} else {
|
||||
// Unsafe targets (javascript:, file:, shares, other schemes) get no link; the text stays.
|
||||
match write::uri_target(target) {
|
||||
Some(t) => t,
|
||||
None => continue,
|
||||
}
|
||||
};
|
||||
v.push(Annotation::new_link(LinkAnnotation::new(rect, t), Some(target.clone())));
|
||||
}
|
||||
v
|
||||
}
|
||||
|
||||
@@ -158,41 +158,25 @@ impl Exporter<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a link's `Link` group is still the last content of its paragraph, so more linked text
|
||||
/// can join it without being read ahead of unlinked text drawn since. Untagged links always continue.
|
||||
fn link_run_continues(&self, tag: Option<(usize, usize)>) -> bool {
|
||||
match tag {
|
||||
None => true,
|
||||
Some((p, c)) => self.tags.get(p).is_some_and(|e| e.children.len() == c + 1),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn link_rect(&mut self, face: &FaceRef, size: f32, glyphs: &[(u32, f32, f32)], link: &str) {
|
||||
let (Some(first), Some(last)) = (glyphs.first(), glyphs.last()) else { return };
|
||||
let adv = face.advance(last.0) as f32 * size / face.upem.max(1.0) as f32;
|
||||
let (x0, x1) = (first.1.min(last.1), first.1.max(last.1) + adv);
|
||||
let (y0, y1) = (first.2 - size * 0.85, first.2 + size * 0.25);
|
||||
if ![x0, x1, y0, y1].iter().all(|v| ok(*v)) || x0 >= x1 || y0 >= y1 {
|
||||
if ![x0, x1, y0, y1].iter().all(|v| ok(*v)) {
|
||||
return;
|
||||
}
|
||||
if self.link_target(link).is_none() {
|
||||
return;
|
||||
}
|
||||
let continues = self.links.last().is_some_and(|prev| self.link_run_continues(prev.tag));
|
||||
if let Some(prev) = self.links.last_mut()
|
||||
&& prev.target == link
|
||||
&& (prev.y0 - y0).abs() < 0.5
|
||||
&& x0 - prev.x1 < size
|
||||
&& continues
|
||||
&& prev.4 == link
|
||||
&& (prev.1 - y0).abs() < 0.5
|
||||
&& x0 - prev.2 < size
|
||||
{
|
||||
prev.x0 = prev.x0.min(x0);
|
||||
prev.x1 = prev.x1.max(x1);
|
||||
self.last_link = Some(self.links.len() - 1);
|
||||
prev.0 = prev.0.min(x0);
|
||||
prev.2 = prev.2.max(x1);
|
||||
return;
|
||||
}
|
||||
if self.links.len() < 10_000 {
|
||||
self.links.push(super::LinkRect { x0, y0, x1, y1, target: link.to_string(), tag: None });
|
||||
self.last_link = Some(self.links.len() - 1);
|
||||
self.links.push((x0, y0, x1, y1, link.to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1946,7 +1946,6 @@ fn bookmark_destination_is_the_page_of_its_start() {
|
||||
objects: crate::exporter::ObjectLookup::new(&d),
|
||||
at: (0, 0),
|
||||
links: Vec::new(),
|
||||
last_link: None,
|
||||
bookmarks: std::cell::OnceCell::new(),
|
||||
};
|
||||
let (page, x, y) = ex.bookmark("target").unwrap();
|
||||
@@ -3789,97 +3788,3 @@ fn an_all_blank_row_keeps_its_cells() {
|
||||
assert_eq!(count("TR"), 2, "both rows, including the all-blank one");
|
||||
assert_eq!(count("TD"), 4, "every body cell");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn link_annotations_are_tagged_with_link_and_objr() {
|
||||
use hayro_syntax::object::{Array, Dict, Name, Object};
|
||||
|
||||
let mut p = Paragraph::with_text("Visit ", CharProps::default());
|
||||
let link_props = CharProps { link: Some("https://example.com".into()), ..Default::default() };
|
||||
p.insert_text(p.len(), "Example", &link_props).unwrap();
|
||||
p.insert_text(p.len(), " now", &CharProps::default()).unwrap();
|
||||
let mut d = Document::new();
|
||||
d.core.title = "Link test".into();
|
||||
d.body = vec![para_block(p)];
|
||||
|
||||
let bytes = export(&d, &PdfOptions { compress: false, tagged: true, ..Default::default() }).unwrap();
|
||||
let pdf = hayro_syntax::Pdf::new(bytes).unwrap();
|
||||
let page = &pdf.pages()[0];
|
||||
let annots = page.raw().get::<Array>(b"Annots").expect("page Annots");
|
||||
let annot = annots.iter::<Dict>().next().expect("link annotation");
|
||||
assert!(annot.get::<i32>(b"StructParent").is_some(), "link annotation missing /StructParent");
|
||||
let annot_id = format!("{:?}", annot.obj_id().expect("indirect annotation"));
|
||||
|
||||
let root = pdf.xref().get::<Dict>(pdf.xref().root_id()).unwrap();
|
||||
let struct_tree = root.get::<Dict>(b"StructTreeRoot").expect("StructTreeRoot");
|
||||
|
||||
fn find_links(dict: &Dict, out: &mut Vec<(bool, Option<String>)>) {
|
||||
if dict.get::<Name>(b"S").is_some_and(|s| s.as_ref() == b"Link") {
|
||||
let mut has_mcid = false;
|
||||
let mut objr = None;
|
||||
if let Some(k) = dict.get::<Array>(b"K") {
|
||||
for item in k.iter::<Object>() {
|
||||
match item {
|
||||
Object::Number(_) => has_mcid = true,
|
||||
Object::Dict(d) if d.get::<Name>(b"Type").is_some_and(|t| t.as_ref() == b"OBJR") => {
|
||||
objr = d.get::<Dict>(b"Obj").and_then(|o| o.obj_id()).map(|id| format!("{id:?}"));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
out.push((has_mcid, objr));
|
||||
}
|
||||
if let Some(k) = dict.get::<Array>(b"K") {
|
||||
for item in k.iter::<Object>() {
|
||||
if let Object::Dict(child) = item {
|
||||
find_links(&child, out);
|
||||
}
|
||||
}
|
||||
} else if let Some(child) = dict.get::<Dict>(b"K") {
|
||||
find_links(&child, out);
|
||||
}
|
||||
}
|
||||
|
||||
let mut links = Vec::new();
|
||||
find_links(&struct_tree, &mut links);
|
||||
assert!(!links.is_empty(), "StructTreeRoot has no /Link structure element (annot {annot_id})");
|
||||
assert!(
|
||||
links.iter().any(|(mcid, objr)| *mcid && objr.as_deref() == Some(&annot_id)),
|
||||
"Link element missing MCID or OBJR for {annot_id}: {links:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// Linked text split by unlinked text keeps reading order: two Link elements, not one that
|
||||
/// swallows the later run ahead of the text between.
|
||||
#[test]
|
||||
fn separated_link_runs_are_separate_link_elements() {
|
||||
use hayro_syntax::object::{Array, Dict, Name, Object};
|
||||
|
||||
let link_props = CharProps { link: Some("https://example.com".into()), ..Default::default() };
|
||||
let mut p = Paragraph::with_text("A", link_props.clone());
|
||||
p.insert_text(p.len(), ".", &CharProps::default()).unwrap();
|
||||
p.insert_text(p.len(), "B", &link_props).unwrap();
|
||||
let mut d = Document::new();
|
||||
d.body = vec![para_block(p)];
|
||||
|
||||
let bytes = export(&d, &PdfOptions { compress: false, tagged: true, ..Default::default() }).unwrap();
|
||||
let pdf = hayro_syntax::Pdf::new(bytes).unwrap();
|
||||
let root = pdf.xref().get::<Dict>(pdf.xref().root_id()).unwrap();
|
||||
let tree = root.get::<Dict>(b"StructTreeRoot").expect("StructTreeRoot");
|
||||
|
||||
fn count(dict: &Dict) -> usize {
|
||||
let mut n = usize::from(dict.get::<Name>(b"S").is_some_and(|s| s.as_ref() == b"Link"));
|
||||
if let Some(k) = dict.get::<Array>(b"K") {
|
||||
for item in k.iter::<Object>() {
|
||||
if let Object::Dict(c) = item {
|
||||
n += count(&c);
|
||||
}
|
||||
}
|
||||
} else if let Some(c) = dict.get::<Dict>(b"K") {
|
||||
n += count(&c);
|
||||
}
|
||||
n
|
||||
}
|
||||
assert_eq!(count(&tree), 2, "each separated link run needs its own Link element");
|
||||
}
|
||||
|
||||
+53
-259
@@ -159,29 +159,13 @@ pub struct RenderOptions {
|
||||
/// Colour for formatting marks.
|
||||
pub mark_color: Rgb,
|
||||
/// Thicken glyphs slightly the way macOS draws text on screen ("font smoothing"), so pages
|
||||
/// look like they do in other Mac apps: 0 is none, 1 the system's default strength
|
||||
/// ([`stem_darkening`]), and other values scale it, up to twice (the system's own setting
|
||||
/// has a lighter and a stronger step). A value that isn't a number is none. For on-screen
|
||||
/// rasters only: exports stay exact.
|
||||
pub text_darkening: f32,
|
||||
/// Put every glyph's baseline on a whole device pixel, for text that is neither rotated nor
|
||||
/// mirrored. A baseline between two pixel rows spreads the feet of the letters (serifs, the
|
||||
/// bottoms of stems) over both rows as two grey rows instead of one solid one, which reads as
|
||||
/// blur. A glyph moves by half a pixel at most and never sideways, so lines break as without
|
||||
/// it. Hinted text already sits like this. For on-screen rasters only: exports stay exact.
|
||||
pub baseline_snap: bool,
|
||||
/// look like they do in other Mac apps. For on-screen rasters only: exports stay exact.
|
||||
pub text_darkening: bool,
|
||||
/// Hint text for the screen the way FreeType's `hintslight` does on Linux desktops: glyph
|
||||
/// baselines sit on whole pixels and their horizontal edges (x-height, cap height) are moved
|
||||
/// onto the pixel grid, so text looks as crisp as in other apps there. Nothing moves
|
||||
/// sideways, so lines break as without it. For on-screen rasters only: exports stay exact.
|
||||
pub hinting: bool,
|
||||
/// Subpixel (LCD) antialiasing for text, for a screen whose colour stripes run in this order
|
||||
/// (see [`LcdOrder`]); `None` is greyscale antialiasing. Text gets three times the detail
|
||||
/// sideways, where slanted and round strokes need it most, at the price of faint colour at
|
||||
/// its edges, and the page is rasterised three times. Everything but text is drawn as
|
||||
/// without it. For on-screen rasters only, and only where the raster's pixels are the
|
||||
/// screen's own: exports stay exact.
|
||||
pub lcd: Option<LcdOrder>,
|
||||
/// Dark page (View › Switch Modes): every colour but pictures has its lightness inverted, so
|
||||
/// white paper turns black and black text white while hues stay the same. Screen only.
|
||||
pub dark: bool,
|
||||
@@ -192,20 +176,6 @@ pub struct RenderOptions {
|
||||
pub read_paper: Option<Rgb>,
|
||||
}
|
||||
|
||||
/// The order of a screen's red, green and blue stripes, left to right, within each pixel.
|
||||
///
|
||||
/// With [`RenderOptions::lcd`] set, each colour channel of a pixel takes the text's coverage
|
||||
/// around its own stripe, a third of a pixel to one side of the pixel's middle or the other,
|
||||
/// instead of all three taking the coverage of the whole pixel. A pixel's stripes are a pixel
|
||||
/// wide in all, so each channel still averages over one pixel's width: this is the result of
|
||||
/// rasterising text at three times the width and averaging three neighbours (the box filter
|
||||
/// FreeType calls its light LCD filter), with no sharper filter and no fringe reduction.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum LcdOrder {
|
||||
Rgb,
|
||||
Bgr,
|
||||
}
|
||||
|
||||
/// Default grey for a dark page's paper.
|
||||
pub const DARK_PAPER: u8 = 0x33;
|
||||
|
||||
@@ -297,10 +267,8 @@ impl Default for RenderOptions {
|
||||
display: DisplayOptions::default(),
|
||||
paper: Rgb::WHITE,
|
||||
mark_color: Rgb(0x2B, 0x57, 0x9A),
|
||||
text_darkening: 0.0,
|
||||
baseline_snap: false,
|
||||
text_darkening: false,
|
||||
hinting: false,
|
||||
lcd: None,
|
||||
dark: false,
|
||||
dark_paper: DARK_PAPER,
|
||||
read_paper: None,
|
||||
@@ -328,52 +296,6 @@ fn render_region_capped(doc: &Document, page: &Page, w: u32, h: u32, view: Affin
|
||||
// Over the cap the whole picture is drawn smaller, not cropped.
|
||||
let view = if (cw, ch) == (w, h) { view } else { Affine::scale_non_uniform(cw as f64 / w as f64, ch as f64 / h as f64) * view };
|
||||
let (w16, h16) = (cw as u16, ch as u16);
|
||||
let drew_text = std::cell::Cell::new(false);
|
||||
let mut pixels = raster_page(doc, page, (w16, h16), view, opts, Pass { shift: 0.0, drew_text: &drew_text });
|
||||
// Subpixel text: the page twice more, its text a third of a pixel to each side, for the
|
||||
// channels whose stripes sit there. A page without text is the same all three times.
|
||||
if let Some(order) = opts.lcd
|
||||
&& drew_text.get()
|
||||
{
|
||||
let side = |shift: f64| raster_page(doc, page, (w16, h16), view, opts, Pass { shift, drew_text: &drew_text });
|
||||
let (text_right, text_left) = (side(LCD_SHIFT), side(-LCD_SHIFT));
|
||||
let (red, blue) = match order {
|
||||
LcdOrder::Rgb => (&text_right, &text_left),
|
||||
LcdOrder::Bgr => (&text_left, &text_right),
|
||||
};
|
||||
take_lcd_channels(&mut pixels, red, blue);
|
||||
}
|
||||
Rendered { width: w16 as u32, height: h16 as u32, pixels }
|
||||
}
|
||||
|
||||
/// How far, in device pixels, the middle of a pixel's first or last colour stripe is from the
|
||||
/// middle of the pixel.
|
||||
const LCD_SHIFT: f64 = 1.0 / 3.0;
|
||||
|
||||
/// One rasterisation of a page among the one or three that make its raster.
|
||||
#[derive(Clone, Copy)]
|
||||
struct Pass<'a> {
|
||||
/// How far to the right text is drawn from its place, in device pixels (see
|
||||
/// [`RenderOptions::lcd`]). Nothing else moves.
|
||||
shift: f64,
|
||||
/// Set once the pass has drawn text that `shift` moves.
|
||||
drew_text: &'a std::cell::Cell<bool>,
|
||||
}
|
||||
|
||||
/// The red of `pixels` from `red` and its blue from `blue`, two rasters of the same size
|
||||
/// (premultiplied RGBA8). Text shifted right puts under each pixel's middle what lay a third of a
|
||||
/// pixel to its left, where an RGB screen's red stripe is, and so on. The alpha stays, and
|
||||
/// no channel is left above it.
|
||||
fn take_lcd_channels(pixels: &mut [u8], red: &[u8], blue: &[u8]) {
|
||||
for ((px, r), b) in pixels.as_chunks_mut::<4>().0.iter_mut().zip(red.as_chunks::<4>().0).zip(blue.as_chunks::<4>().0) {
|
||||
px[0] = r[0].min(px[3]);
|
||||
px[2] = b[2].min(px[3]);
|
||||
}
|
||||
}
|
||||
|
||||
/// Rasterise a page into `size` pixels (premultiplied RGBA8) with `view` (page points → pixels).
|
||||
fn raster_page(doc: &Document, page: &Page, size: (u16, u16), view: Affine, opts: &RenderOptions, pass: Pass) -> Vec<u8> {
|
||||
let (w16, h16) = size;
|
||||
let mut ctx = context_pool::CONTEXTS.take(w16, h16);
|
||||
ctx.set_transform(Affine::IDENTITY);
|
||||
ctx.set_paint(color(opts.paper_of(doc), 1.0));
|
||||
@@ -392,7 +314,7 @@ fn raster_page(doc: &Document, page: &Page, size: (u16, u16), view: Affine, opts
|
||||
ctx.push_opacity_layer(alpha);
|
||||
}
|
||||
for it in &items {
|
||||
draw(&mut ctx, doc, it, view, &visible, opts, pass);
|
||||
draw(&mut ctx, doc, it, view, &visible, opts);
|
||||
}
|
||||
if faded {
|
||||
ctx.pop_layer();
|
||||
@@ -405,7 +327,7 @@ fn raster_page(doc: &Document, page: &Page, size: (u16, u16), view: Affine, opts
|
||||
ctx.render(pm, &mut res);
|
||||
}
|
||||
context_pool::CONTEXTS.give_back(ctx);
|
||||
pixels
|
||||
Rendered { width: w16 as u32, height: h16 as u32, pixels }
|
||||
}
|
||||
|
||||
/// The on-screen colour behind page point (`x`, `y`): the paper (page colour), then any
|
||||
@@ -573,30 +495,24 @@ fn draw_watermark(ctx: &mut RenderContext, view: Affine, page: &Page, wm: &wordc
|
||||
|
||||
/// Does `view` map page points to device pixels without rotation, skew or mirroring, scaling both
|
||||
/// axes alike? Only then do hinted outlines (made on the pixel grid) line up with the screen.
|
||||
/// "Alike" allows the two axes a fifth of a percent apart: a page raster made to fill a whole
|
||||
/// number of pixels each way ([`render_area_to`]) is scaled that little differently across and
|
||||
/// down (a pixel in some two thousand), and is as upright as any.
|
||||
fn is_upright(view: Affine) -> bool {
|
||||
let [a, b, c, d, e, f] = view.as_coeffs();
|
||||
[a, b, c, d, e, f].iter().all(|v| v.is_finite()) && b == 0.0 && c == 0.0 && a > 0.0 && (a - d).abs() <= a * 2e-3
|
||||
[a, b, c, d, e, f].iter().all(|v| v.is_finite()) && b == 0.0 && c == 0.0 && a > 0.0 && (a - d).abs() <= a * 1e-6
|
||||
}
|
||||
|
||||
/// How far, in device pixels, macOS-style font smoothing pushes each side of a glyph outline out
|
||||
/// sideways at `ppem` device pixels per em. The value is Pathfinder's (MIT/Apache-2.0), which
|
||||
/// measured it against macOS: 1.21% of the pixel size, capped at 0.3 px, and no darkening past
|
||||
/// 72 px per em. Pathfinder also grows glyphs up and down (1.25 times as far). We don't: a third
|
||||
/// of a pixel of grey above and below every letter is what made page text look out of focus
|
||||
/// beside other Mac apps, whose letters end on a clean pixel row. Stems get thicker, which is
|
||||
/// the weight the smoothing is for; the tops and feet of the letters stay where the font puts
|
||||
/// them.
|
||||
/// at `ppem` device pixels per em. Values from Pathfinder (MIT/Apache-2.0), which measured them
|
||||
/// against macOS: 1.21% of the pixel size horizontally and 1.25 times that vertically, each
|
||||
/// capped at 0.3 px, and no darkening past 72 px per em. We stroke the outline, which grows it
|
||||
/// evenly, so this is the mean of the two.
|
||||
pub fn stem_darkening(ppem: f64) -> f64 {
|
||||
const FACTOR: f64 = 0.0121;
|
||||
const FACTOR: [f64; 2] = [0.0121, 0.0121 * 1.25];
|
||||
const MAX_PX: f64 = 0.3;
|
||||
const MAX_PPEM: f64 = 72.0;
|
||||
if !ppem.is_finite() || ppem <= 0.0 || ppem > MAX_PPEM {
|
||||
return 0.0;
|
||||
}
|
||||
(ppem * FACTOR).min(MAX_PX)
|
||||
FACTOR.iter().map(|f| (ppem * f).min(MAX_PX)).sum::<f64>() / 2.0
|
||||
}
|
||||
|
||||
/// A wavy line from `(x0, y0)` to `(x1, y1)`; at most 20 000 units long, so a huge extent can't make it endless.
|
||||
@@ -680,7 +596,6 @@ struct Frame<'a> {
|
||||
opts: &'a RenderOptions,
|
||||
view: Affine,
|
||||
visible: &'a kurbo::Rect,
|
||||
pass: Pass<'a>,
|
||||
}
|
||||
|
||||
/// The rectangle in kurbo's terms.
|
||||
@@ -692,12 +607,12 @@ fn kurbo_rect(rect: &wordcraft_geom::Rect) -> kurbo::Rect {
|
||||
/// `visible` is a culling area in those point coordinates; nested clips intersect it and turns
|
||||
/// transform it into the child's coordinates. Shape and path strokes apply their stored caps,
|
||||
/// while ink uses its tool's round ends and joins.
|
||||
fn draw(ctx: &mut RenderContext, doc: &Document, it: &Draw, view: Affine, visible: &kurbo::Rect, opts: &RenderOptions, pass: Pass) {
|
||||
let fr = Frame { doc, opts, view, visible, pass };
|
||||
fn draw(ctx: &mut RenderContext, doc: &Document, it: &Draw, view: Affine, visible: &kurbo::Rect, opts: &RenderOptions) {
|
||||
let fr = Frame { doc, opts, view, visible };
|
||||
match it {
|
||||
Draw::Figure { draws, .. } => {
|
||||
for d in draws {
|
||||
draw(ctx, doc, d, view, visible, opts, pass);
|
||||
draw(ctx, doc, d, view, visible, opts);
|
||||
}
|
||||
}
|
||||
Draw::Fill { .. } => draw_fill(ctx, &fr, it),
|
||||
@@ -719,7 +634,7 @@ fn draw(ctx: &mut RenderContext, doc: &Document, it: &Draw, view: Affine, visibl
|
||||
ctx.push_clip_layer(&r.to_path(0.1));
|
||||
let local = r.intersect(*visible);
|
||||
for it in items {
|
||||
draw(ctx, doc, it, view, &local, opts, pass);
|
||||
draw(ctx, doc, it, view, &local, opts);
|
||||
}
|
||||
ctx.pop_layer();
|
||||
}
|
||||
@@ -727,14 +642,14 @@ fn draw(ctx: &mut RenderContext, doc: &Document, it: &Draw, view: Affine, visibl
|
||||
let m = Affine::new(Draw::turn_matrix(*turn, *x, *y).map(f64::from));
|
||||
let local = m.inverse().transform_rect_bbox(*visible);
|
||||
for it in items {
|
||||
draw(ctx, doc, it, view * m, &local, opts, pass);
|
||||
draw(ctx, doc, it, view * m, &local, opts);
|
||||
}
|
||||
}
|
||||
Draw::Rotated { cx, cy, spin, items } => {
|
||||
let m = Affine::new(spin.matrix(*cx, *cy).map(f64::from));
|
||||
let local = m.inverse().transform_rect_bbox(*visible);
|
||||
for it in items {
|
||||
draw(ctx, doc, it, view * m, &local, opts, pass);
|
||||
draw(ctx, doc, it, view * m, &local, opts);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -789,8 +704,7 @@ fn draw_line(ctx: &mut RenderContext, fr: &Frame, it: &Draw) {
|
||||
}
|
||||
_ => {
|
||||
let (st, off) = match snap_rule(fr.view, (x0, y0, x1, y1), w) {
|
||||
// The width is across the rule: in points by the scale that way.
|
||||
Some((w_px, off)) => (kurbo::Stroke { width: w_px / rule_scale(fr.view, y0 == y1), ..st }, off),
|
||||
Some((w_px, off)) => (kurbo::Stroke { width: w_px / fr.view.as_coeffs()[0], ..st }, off),
|
||||
None => (st, (0.0, 0.0)),
|
||||
};
|
||||
ctx.set_stroke(st);
|
||||
@@ -807,13 +721,11 @@ fn snap_rule(view: Affine, (x0, y0, x1, y1): (f64, f64, f64, f64), width: f64) -
|
||||
if !is_upright(view) {
|
||||
return None;
|
||||
}
|
||||
let [_, _, _, _, tx, ty] = view.as_coeffs();
|
||||
let [k, _, _, _, tx, ty] = view.as_coeffs();
|
||||
if y0 == y1 && x0 != x1 {
|
||||
let k = rule_scale(view, true);
|
||||
let (w_px, c) = snap_hairline(y0 * k + ty, width * k);
|
||||
Some((w_px, (0.0, (c - ty) / k - y0)))
|
||||
} else if x0 == x1 && y0 != y1 {
|
||||
let k = rule_scale(view, false);
|
||||
let (w_px, c) = snap_hairline(x0 * k + tx, width * k);
|
||||
Some((w_px, ((c - tx) / k - x0, 0.0)))
|
||||
} else {
|
||||
@@ -821,16 +733,6 @@ fn snap_rule(view: Affine, (x0, y0, x1, y1): (f64, f64, f64, f64), width: f64) -
|
||||
}
|
||||
}
|
||||
|
||||
/// Device pixels per point across a rule: down the page for a level rule, across it for an
|
||||
/// upright one. An upright view ([`is_upright`]) may scale the two a little differently (a page
|
||||
/// raster made to fill a whole number of pixels each way), and a rule's place and width are
|
||||
/// measured across it: with the other scale, a level rule low on such a page was snapped up to
|
||||
/// a pixel from where it lies, its edges between pixel rows.
|
||||
fn rule_scale(view: Affine, level: bool) -> f64 {
|
||||
let [across, _, _, down, ..] = view.as_coeffs();
|
||||
if level { down } else { across }
|
||||
}
|
||||
|
||||
/// A line `width_px` wide centred at device coordinate `centre`, moved so both edges fall on whole
|
||||
/// pixels. Returns the width, made a whole number of pixels (at least one), and the new centre.
|
||||
fn snap_hairline(centre: f64, width_px: f64) -> (f64, f64) {
|
||||
@@ -860,25 +762,23 @@ fn draw_glyphs(ctx: &mut RenderContext, fr: &Frame, it: &Draw) {
|
||||
// Scaled letters (`w:w`): each glyph stretched across from its pen position.
|
||||
let sx = if x_scale.is_finite() && *x_scale > 0.0 { f64::from(*x_scale) } else { 1.0 };
|
||||
let skew = Affine::scale_non_uniform(sx, 1.0) * skew;
|
||||
// Synthetic bold strokes the outline, in font units.
|
||||
// Outline strokes, in font units: synthetic bold, then on-screen stem darkening (a
|
||||
// stroke grows the outline by half its width on each side). Darkening is skipped for
|
||||
// translucent text, where the stroke overlapping the fill would show as a darker rim.
|
||||
let px_per_pt = view.determinant().abs().sqrt();
|
||||
let outline_stroke = if *synth_bold { face.upem * 0.03 } else { 0.0 };
|
||||
let darken_px = if opts.text_darkening && *alpha >= 1.0 { stem_darkening(*size as f64 * px_per_pt) } else { 0.0 };
|
||||
let darken = if darken_px > 0.0 && k * px_per_pt > 0.0 { 2.0 * darken_px / (k * px_per_pt) } else { 0.0 };
|
||||
let outline_stroke = if *synth_bold { face.upem * 0.03 } else { 0.0 } + darken;
|
||||
let join = if darken > 0.0 { kurbo::Join::Round } else { kurbo::Join::Miter };
|
||||
if outline_stroke > 0.0 {
|
||||
ctx.set_stroke(kurbo::Stroke::new(outline_stroke).with_join(kurbo::Join::Miter));
|
||||
ctx.set_stroke(kurbo::Stroke::new(outline_stroke).with_join(join));
|
||||
}
|
||||
// Emoji and other colour glyphs (#1269) are drawn from the font's colour data.
|
||||
let colour = face.has_color_glyphs();
|
||||
let ppem = *size as f64 * px_per_pt;
|
||||
// On-screen stem darkening: each outline is widened along its own x axis, in one piece (see
|
||||
// [`stem_darkening`] and [`widened`]). Skipped for translucent text, as it always was.
|
||||
let strength = if opts.text_darkening.is_finite() { f64::from(opts.text_darkening).clamp(0.0, 2.0) } else { 0.0 };
|
||||
let darken_px = if *alpha >= 1.0 { stem_darkening(ppem) * strength } else { 0.0 };
|
||||
// Hinted outlines are in device pixels, and a snapped baseline is a row of them: only for an
|
||||
// upright, unmirrored, evenly scaled view (not rotated text boxes), where the pixel grid
|
||||
// lines up with the glyphs.
|
||||
let upright = is_upright(view);
|
||||
let hint_ppem = (opts.hinting && !colour && upright).then_some(ppem as f32);
|
||||
let snap = opts.baseline_snap && upright;
|
||||
// Hinted outlines are in device pixels: only for an upright, unmirrored, evenly scaled
|
||||
// view (not rotated text boxes), where the pixel grid lines up with the glyphs.
|
||||
let hint_ppem = (opts.hinting && !colour && is_upright(view)).then_some(ppem as f32);
|
||||
// The outline strokes in device pixels, for the hinted outlines.
|
||||
let stroke_px = outline_stroke * k * px_per_pt;
|
||||
let mut hinted_stroke = false;
|
||||
@@ -895,128 +795,37 @@ fn draw_glyphs(ctx: &mut RenderContext, fr: &Frame, it: &Draw) {
|
||||
ctx.set_paint(color(opts.ink(*c), *alpha));
|
||||
continue;
|
||||
}
|
||||
let pen = view * kurbo::Point::new(gx, gy);
|
||||
let hinted = hint_ppem.and_then(|p| db.hinted_outline(face, *gid, p));
|
||||
let hinted_now = hinted.is_some();
|
||||
let (o, at) = if let Some(o) = hinted {
|
||||
if outline_stroke > 0.0 && !hinted_stroke {
|
||||
ctx.set_stroke(kurbo::Stroke::new(stroke_px).with_join(kurbo::Join::Miter));
|
||||
hinted_stroke = true;
|
||||
if let Some(o) = hint_ppem.and_then(|p| db.hinted_outline(face, *gid, p)) {
|
||||
if o.elements().is_empty() {
|
||||
continue;
|
||||
}
|
||||
// The baseline on a whole pixel, as the hinting assumes.
|
||||
(o, Affine::translate((pen.x, pen.y.round())) * skew)
|
||||
} else {
|
||||
if outline_stroke > 0.0 && hinted_stroke {
|
||||
ctx.set_stroke(kurbo::Stroke::new(outline_stroke).with_join(kurbo::Join::Miter));
|
||||
hinted_stroke = false;
|
||||
let at = view * kurbo::Point::new(gx, gy);
|
||||
ctx.set_transform(Affine::translate((at.x, at.y.round())) * skew);
|
||||
ctx.fill_path(&o);
|
||||
if outline_stroke > 0.0 {
|
||||
if !hinted_stroke {
|
||||
ctx.set_stroke(kurbo::Stroke::new(stroke_px).with_join(join));
|
||||
hinted_stroke = true;
|
||||
}
|
||||
ctx.stroke_path(&o);
|
||||
}
|
||||
let at = view * Affine::translate((gx, gy)) * skew * Affine::scale(k);
|
||||
// The same baseline for text drawn from the font's own outlines.
|
||||
let lift = if snap && pen.y.is_finite() { pen.y.round() - pen.y } else { 0.0 };
|
||||
(db.outline(face, *gid), Affine::translate((0.0, lift)) * at)
|
||||
};
|
||||
continue;
|
||||
}
|
||||
let o = db.outline(face, *gid);
|
||||
if o.elements().is_empty() {
|
||||
continue;
|
||||
}
|
||||
// This pass's sideways shift, across the screen whichever way the text is turned.
|
||||
fr.pass.drew_text.set(true);
|
||||
ctx.set_transform(Affine::translate((fr.pass.shift, 0.0)) * at);
|
||||
// The darkened outline is the glyph: synthetic bold strokes it too. Stroking the font's own
|
||||
// outline there would cover the widening (the stroke reaches further than it does) and
|
||||
// leave such text as light as without darkening.
|
||||
let wide = (darken_px > 0.0).then(|| widened(&o, darken_px / widen_unit(hinted_now, k * px_per_pt, sx)));
|
||||
let shape = wide.as_ref().unwrap_or(&o);
|
||||
ctx.fill_path(shape);
|
||||
ctx.set_transform(view * Affine::translate((gx, gy)) * skew * Affine::scale(k));
|
||||
ctx.fill_path(&o);
|
||||
if outline_stroke > 0.0 {
|
||||
ctx.stroke_path(shape);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// How many device pixels one unit of a glyph outline is across the screen, for turning a
|
||||
/// widening in device pixels into the outline's own units: a hinted outline is in device pixels
|
||||
/// already and the font's own in font units (`font_px` device pixels each), and both are then
|
||||
/// stretched `stretch` times across by scaled letters (`w:w`). Without the stretch for hinted
|
||||
/// outlines, text scaled to 400 % was widened four times too far.
|
||||
fn widen_unit(hinted: bool, font_px: f64, stretch: f64) -> f64 {
|
||||
if hinted { stretch } else { font_px * stretch }
|
||||
}
|
||||
|
||||
/// `path` with every edge moved `d` sideways, away from the ink: the shape a glyph makes when it
|
||||
/// is smeared `d` to the left and `d` to the right, so stems get `2 d` thicker while nothing
|
||||
/// grows up or down. One outline, filled once, so partly covered pixels are counted once (the
|
||||
/// outline drawn again beside itself counted them two and three times, which read as bold).
|
||||
///
|
||||
/// Each point moves with the edges it joins: by `d` where both face the same side, or one of
|
||||
/// them is level; not at all at the top or the foot of a curve, where one faces left and the
|
||||
/// other right. Curve control points move by the same rule along the control polygon. Which side
|
||||
/// of an edge is ink follows from the direction the outline runs in, read off its signed area,
|
||||
/// so the holes of letters narrow as their stems widen. An outline with no area, or with
|
||||
/// numbers that aren't finite, is returned as it is.
|
||||
fn widened(path: &BezPath, d: f64) -> BezPath {
|
||||
use kurbo::PathEl;
|
||||
let els = path.elements();
|
||||
// The control polygon of each contour, as (first point index, point count).
|
||||
let mut pts: Vec<kurbo::Point> = Vec::with_capacity(els.len() * 2);
|
||||
let mut contours: Vec<(usize, usize)> = Vec::new();
|
||||
let mut start = 0;
|
||||
for el in els {
|
||||
match el {
|
||||
PathEl::MoveTo(p) => {
|
||||
if pts.len() > start {
|
||||
contours.push((start, pts.len() - start));
|
||||
}
|
||||
start = pts.len();
|
||||
pts.push(*p);
|
||||
if hinted_stroke {
|
||||
ctx.set_stroke(kurbo::Stroke::new(outline_stroke).with_join(join));
|
||||
hinted_stroke = false;
|
||||
}
|
||||
PathEl::LineTo(p) => pts.push(*p),
|
||||
PathEl::QuadTo(c, p) => pts.extend([*c, *p]),
|
||||
PathEl::CurveTo(c1, c2, p) => pts.extend([*c1, *c2, *p]),
|
||||
PathEl::ClosePath => {}
|
||||
ctx.stroke_path(&o);
|
||||
}
|
||||
}
|
||||
if pts.len() > start {
|
||||
contours.push((start, pts.len() - start));
|
||||
}
|
||||
let ring = |first: usize, n: usize, i: usize| pts.get(first + i % n.max(1)).copied().unwrap_or_default();
|
||||
let area: f64 =
|
||||
contours.iter().map(|&(first, n)| (0..n).map(|i| ring(first, n, i).to_vec2().cross(ring(first, n, i + 1).to_vec2())).sum::<f64>()).sum();
|
||||
if !(d.is_finite() && d > 0.0 && area.is_finite() && area != 0.0) {
|
||||
return path.clone();
|
||||
}
|
||||
// Which way the edge from `a` to `b` faces: 1 right, -1 left, 0 for a level edge.
|
||||
let faces = |a: kurbo::Point, b: kurbo::Point| {
|
||||
let (run, rise) = ((b.x - a.x).abs(), b.y - a.y);
|
||||
if rise.abs() <= 1e-6 * (run + rise.abs()) { 0.0 } else { (rise * area).signum() }
|
||||
};
|
||||
let mut moved = pts.clone();
|
||||
for &(first, n) in &contours {
|
||||
for i in 0..n {
|
||||
let at = ring(first, n, i);
|
||||
// The nearest different points before and after: a contour may repeat a point (a
|
||||
// run of more than a few is left where it is).
|
||||
let before = (1..n.min(8)).map(|step| ring(first, n, i + n - step)).find(|p| *p != at);
|
||||
let after = (1..n.min(8)).map(|step| ring(first, n, i + step)).find(|p| *p != at);
|
||||
let (Some(before), Some(after)) = (before, after) else { continue };
|
||||
let push = (faces(before, at) + faces(at, after)).clamp(-1.0, 1.0);
|
||||
if let Some(p) = moved.get_mut(first + i) {
|
||||
p.x += push * d;
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut next = moved.into_iter();
|
||||
let mut take = || next.next().unwrap_or_default();
|
||||
let mut out = BezPath::with_capacity(els.len());
|
||||
for el in els {
|
||||
out.push(match el {
|
||||
PathEl::MoveTo(_) => PathEl::MoveTo(take()),
|
||||
PathEl::LineTo(_) => PathEl::LineTo(take()),
|
||||
PathEl::QuadTo(..) => PathEl::QuadTo(take(), take()),
|
||||
PathEl::CurveTo(..) => PathEl::CurveTo(take(), take(), take()),
|
||||
PathEl::ClosePath => PathEl::ClosePath,
|
||||
});
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
fn draw_mark(ctx: &mut RenderContext, fr: &Frame, it: &Draw) {
|
||||
@@ -1471,19 +1280,6 @@ pub fn render_area(doc: &Document, page: &Page, area: wordcraft_geom::Rect, scal
|
||||
render_region(doc, page, pw, ph, view, opts)
|
||||
}
|
||||
|
||||
/// Render the page `area` (points) into exactly `w`×`h` pixels: the area fills the raster, scaled
|
||||
/// across and down by whatever that takes. For a raster that must be a given number of device
|
||||
/// pixels each way, where [`render_area`]'s single scale gives the next whole pixel up: a picture
|
||||
/// one pixel larger than its place on screen is scaled into it, and every glyph resampled.
|
||||
pub fn render_area_to(doc: &Document, page: &Page, area: wordcraft_geom::Rect, w: u32, h: u32, opts: &RenderOptions) -> Rendered {
|
||||
let (w, h) = (w.clamp(1, MAX_SIDE), h.clamp(1, MAX_SIDE));
|
||||
let (sx, sy) = (f64::from(w) / f64::from(area.w), f64::from(h) / f64::from(area.h));
|
||||
let fine = |v: f64| v.is_finite() && v > 0.0;
|
||||
let (sx, sy) = if fine(sx) && fine(sy) && area.x.is_finite() && area.y.is_finite() { (sx, sy) } else { (1.0, 1.0) };
|
||||
let (x, y) = if area.x.is_finite() && area.y.is_finite() { (f64::from(area.x), f64::from(area.y)) } else { (0.0, 0.0) };
|
||||
render_region(doc, page, w, h, Affine::scale_non_uniform(sx, sy) * Affine::translate((-x, -y)), opts)
|
||||
}
|
||||
|
||||
/// Draw `items` (page points) alone, on nothing, over the page `area` (points) at `scale` px/pt:
|
||||
/// no paper, no watermark. A dragged object's preview.
|
||||
pub fn render_items(doc: &Document, items: &[Draw], area: wordcraft_geom::Rect, scale: f32, opts: &RenderOptions) -> Rendered {
|
||||
@@ -1497,10 +1293,8 @@ pub fn render_items(doc: &Document, items: &[Draw], area: wordcraft_geom::Rect,
|
||||
* Affine::translate((-x as f64, -y as f64));
|
||||
let mut ctx = RenderContext::new_with(w16, h16, vello_cpu::RenderSettings { num_threads: 0, ..Default::default() });
|
||||
let visible = view.inverse().transform_rect_bbox(kurbo::Rect::new(0.0, 0.0, w16 as f64, h16 as f64)).inflate(40.0, 40.0);
|
||||
// One pass, text in its place: an area raster (a preview, a dragged object) is greyscale.
|
||||
let drew_text = std::cell::Cell::new(false);
|
||||
for it in items {
|
||||
draw(&mut ctx, doc, it, view, &visible, opts, Pass { shift: 0.0, drew_text: &drew_text });
|
||||
draw(&mut ctx, doc, it, view, &visible, opts);
|
||||
}
|
||||
ctx.flush();
|
||||
let mut pixels = vec![0u8; w16 as usize * h16 as usize * 4];
|
||||
|
||||
+3
-358
@@ -265,7 +265,7 @@ fn stem_darkening_follows_the_macos_curve() {
|
||||
assert_eq!(stem_darkening(f64::NAN), 0.0);
|
||||
assert_eq!(stem_darkening(-5.0), 0.0);
|
||||
// Small text grows in proportion to its pixel size...
|
||||
assert!((stem_darkening(10.0) - 10.0 * 0.0121).abs() < 1e-9);
|
||||
assert!((stem_darkening(10.0) - 10.0 * 0.0121 * 2.25 / 2.0).abs() < 1e-9);
|
||||
// ...body text on a Retina screen hits the 0.3 px cap...
|
||||
assert_eq!(stem_darkening(30.0), 0.3);
|
||||
assert_eq!(stem_darkening(72.0), 0.3);
|
||||
@@ -283,29 +283,12 @@ fn text_darkening_adds_ink_on_screen_only() {
|
||||
let d = Document::from_text("Marketing analytics lead with twelve years of measurement work.");
|
||||
let l = layout(&d, &mut LayoutCache::new(), &LayoutOptions::default());
|
||||
let plain = render_page(&d, &l.pages[0], 2.0, &RenderOptions::default());
|
||||
let dark = render_page(&d, &l.pages[0], 2.0, &RenderOptions { text_darkening: 1.0, ..Default::default() });
|
||||
let dark = render_page(&d, &l.pages[0], 2.0, &RenderOptions { text_darkening: true, ..Default::default() });
|
||||
let (a, b) = (ink(&plain), ink(&dark));
|
||||
// About 0.3 px more on every edge of an 11 pt line at 2x: clearly more ink, not bold.
|
||||
assert!(b as f64 > a as f64 * 1.08 && (b as f64) < a as f64 * 1.6, "plain {a}, darkened {b}");
|
||||
// Off by default: exports and thumbnails are untouched.
|
||||
assert_eq!(RenderOptions::default().text_darkening, 0.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn text_darkening_is_a_strength() {
|
||||
let d = Document::from_text("Marketing analytics lead with twelve years of measurement work.");
|
||||
let l = layout(&d, &mut LayoutCache::new(), &LayoutOptions::default());
|
||||
let at = |strength: f32| ink(&render_page(&d, &l.pages[0], 2.0, &RenderOptions { text_darkening: strength, ..Default::default() }));
|
||||
// The system's lighter, default and stronger steps each add ink.
|
||||
let (none, light, default, strong) = (at(0.0), at(0.5), at(1.0), at(1.5));
|
||||
assert!(none < light && light < default && default < strong, "{none} {light} {default} {strong}");
|
||||
assert_eq!(none, ink(&render_page(&d, &l.pages[0], 2.0, &RenderOptions::default())));
|
||||
// No more than twice the default, and junk is no darkening at all.
|
||||
assert_eq!(at(2.0), at(50.0));
|
||||
assert_eq!(at(2.0), at(f32::INFINITY.min(f32::MAX)));
|
||||
for junk in [f32::NAN, f32::INFINITY, f32::NEG_INFINITY, -1.0] {
|
||||
assert_eq!(at(junk), none, "{junk}");
|
||||
}
|
||||
assert!(!RenderOptions::default().text_darkening);
|
||||
}
|
||||
|
||||
/// Inked pixels that are only partly covered (grey): an edge between two pixel rows.
|
||||
@@ -320,315 +303,6 @@ fn ink_columns(img: &Rendered) -> (usize, usize) {
|
||||
(inked.iter().copied().min().unwrap_or(0), inked.iter().copied().max().unwrap_or(0))
|
||||
}
|
||||
|
||||
/// The first and last pixel rows with any ink.
|
||||
fn ink_row_span(img: &Rendered) -> (usize, usize) {
|
||||
let w = img.width as usize;
|
||||
let inked: Vec<usize> = img.pixels.as_chunks::<4>().0.iter().enumerate().filter(|(_, p)| p[0] < 250).map(|(i, _)| i / w.max(1)).collect();
|
||||
(inked.iter().copied().min().unwrap_or(0), inked.iter().copied().max().unwrap_or(0))
|
||||
}
|
||||
|
||||
/// One line of flat-footed capitals in a bundled face: no letter dips under the baseline.
|
||||
fn flat_capitals() -> (Document, wordcraft_layout::DocLayout) {
|
||||
let mut d = Document::from_text("THE FELT HILT FILE LIFT HEFT TILT");
|
||||
let styles = std::sync::Arc::make_mut(&mut d.styles);
|
||||
styles.default_chr.font = Some("Source Sans 3".into());
|
||||
styles.default_chr.size = Some(12.0);
|
||||
let l = layout(&d, &mut LayoutCache::new(), &LayoutOptions::default());
|
||||
(d, l)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_snapped_baseline_ends_the_letters_on_a_whole_pixel_row() {
|
||||
let (d, l) = flat_capitals();
|
||||
let snap = RenderOptions { baseline_snap: true, ..Default::default() };
|
||||
// Scales that put the baseline at different places between two pixel rows.
|
||||
let mut sharper = 0;
|
||||
for scale in [1.0, 1.25, 1.45, 96.0 / 72.0 * 1.45, 2.0, 2.3] {
|
||||
let plain = render_page(&d, &l.pages[0], scale, &RenderOptions::default());
|
||||
let snapped = render_page(&d, &l.pages[0], scale, &snap);
|
||||
// The row under the letters' feet: all of it white once the baseline is on a pixel
|
||||
// boundary, where the unsnapped feet leave a grey row or end a row early.
|
||||
let (_, foot) = ink_row_span(&snapped);
|
||||
let w = snapped.width as usize;
|
||||
let foot_row = &snapped.pixels[foot * w * 4..(foot + 1) * w * 4];
|
||||
let darkest = foot_row.as_chunks::<4>().0.iter().map(|p| p[0]).min().unwrap_or(255);
|
||||
assert!(darkest < 16, "scale {scale}: the feet fill their last row (darkest pixel {darkest})");
|
||||
let (g0, g1) = (grey(&plain), grey(&snapped));
|
||||
assert!(g1 <= g0, "scale {scale}: grey pixels: plain {g0}, snapped {g1}");
|
||||
sharper += usize::from(g1 < g0);
|
||||
// The same weight, and nothing moves sideways.
|
||||
let (a, b) = (ink(&plain), ink(&snapped));
|
||||
assert!((b as f64 - a as f64).abs() < a as f64 * 0.02, "scale {scale}: ink: plain {a}, snapped {b}");
|
||||
assert_eq!(ink_columns(&plain), ink_columns(&snapped), "scale {scale}");
|
||||
// No more than half a pixel up or down.
|
||||
let ((t0, b0), (t1, b1)) = (ink_row_span(&plain), ink_row_span(&snapped));
|
||||
assert!(t0.abs_diff(t1) <= 1 && b0.abs_diff(b1) <= 1, "scale {scale}: plain {t0}..{b0}, snapped {t1}..{b1}");
|
||||
}
|
||||
assert!(sharper >= 3, "snapping sharpened {sharper} of 6 scales");
|
||||
// Off by default: exports and thumbnails are untouched.
|
||||
assert!(!RenderOptions::default().baseline_snap);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rotated_views_keep_their_baselines() {
|
||||
let (d, l) = flat_capitals();
|
||||
let snap = RenderOptions { baseline_snap: true, ..Default::default() };
|
||||
let view = Affine::translate((300.0, -50.0)) * Affine::rotate(0.3) * Affine::scale(1.9);
|
||||
let plain = render_region(&d, &l.pages[0], 600, 300, view, &RenderOptions::default());
|
||||
assert!(ink(&plain) > 0);
|
||||
assert_eq!(plain.pixels, render_region(&d, &l.pages[0], 600, 300, view, &snap).pixels);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn darkening_thickens_stems_and_leaves_the_tops_and_feet_of_letters_alone() {
|
||||
let (d, l) = flat_capitals();
|
||||
let snap = RenderOptions { baseline_snap: true, ..Default::default() };
|
||||
let dark = RenderOptions { text_darkening: 1.0, ..snap.clone() };
|
||||
for scale in [1.0, 1.45, 2.0] {
|
||||
let plain = render_page(&d, &l.pages[0], scale, &snap);
|
||||
let darkened = render_page(&d, &l.pages[0], scale, &dark);
|
||||
// More ink, in the same pixel rows: nothing is added above the letters or under them
|
||||
// (the stroke this replaces put a third of a pixel of grey on both).
|
||||
assert!(ink(&darkened) as f64 > ink(&plain) as f64 * 1.05, "scale {scale}");
|
||||
assert_eq!(ink_row_span(&plain), ink_row_span(&darkened), "scale {scale}");
|
||||
// Sideways, less than a pixel each way.
|
||||
let ((l0, r0), (l1, r1)) = (ink_columns(&plain), ink_columns(&darkened));
|
||||
assert!(l1 <= l0 && l0 - l1 <= 1 && r1 >= r0 && r1 - r0 <= 1, "scale {scale}: plain {l0}..{r0}, darkened {l1}..{r1}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn widening_moves_edges_sideways_away_from_the_ink() {
|
||||
// A 10 x 10 square with a 4 x 4 hole, the hole running the other way round.
|
||||
let mut ring = kurbo::Rect::new(0.0, 0.0, 10.0, 10.0).to_path(0.1);
|
||||
ring.move_to((3.0, 3.0));
|
||||
for p in [(3.0, 7.0), (7.0, 7.0), (7.0, 3.0)] {
|
||||
ring.line_to(p);
|
||||
}
|
||||
ring.close_path();
|
||||
for path in [ring.clone(), ring.reverse_subpaths()] {
|
||||
let wide = widened(&path, 0.5);
|
||||
// The square is 1 wider and the hole 1 narrower; neither is any taller.
|
||||
let b = wide.bounding_box();
|
||||
assert_eq!((b.x0, b.x1, b.y0, b.y1), (-0.5, 10.5, 0.0, 10.0));
|
||||
assert!((wide.area().abs() - (11.0 * 10.0 - 3.0 * 4.0)).abs() < 1e-9, "{}", wide.area());
|
||||
assert_eq!(wide.elements().len(), path.elements().len());
|
||||
}
|
||||
// A round shape: wider, no taller, and its top and bottom points stay put.
|
||||
let disc = kurbo::Circle::new((0.0, 0.0), 5.0).to_path(1e-3);
|
||||
let b = widened(&disc, 0.25).bounding_box();
|
||||
assert!((b.width() - 10.5).abs() < 0.02 && (b.height() - 10.0).abs() < 0.02, "{b:?}");
|
||||
// Nothing to widen, or nothing to widen by: the path comes back as it was.
|
||||
let line = BezPath::from_vec(vec![kurbo::PathEl::MoveTo((0.0, 0.0).into()), kurbo::PathEl::LineTo((5.0, 5.0).into())]);
|
||||
for (path, d) in [(&line, 0.5), (&ring, 0.0), (&ring, -1.0), (&ring, f64::NAN), (&ring, f64::INFINITY), (&BezPath::new(), 0.5)] {
|
||||
assert_eq!(widened(path, d).elements(), path.elements(), "{d}");
|
||||
}
|
||||
// Hostile outlines don't panic: points that aren't numbers, and one point repeated.
|
||||
let mut odd = BezPath::new();
|
||||
odd.move_to((f64::NAN, 0.0));
|
||||
odd.line_to((1.0, f64::INFINITY));
|
||||
odd.quad_to((2.0, 2.0), (0.0, 0.0));
|
||||
let _ = widened(&odd, 0.5);
|
||||
let mut same = BezPath::new();
|
||||
same.move_to((1.0, 1.0));
|
||||
for _ in 0..50 {
|
||||
same.line_to((1.0, 1.0));
|
||||
}
|
||||
same.line_to((4.0, 1.0));
|
||||
same.line_to((4.0, 5.0));
|
||||
same.close_path();
|
||||
assert_eq!(widened(&same, 0.5).elements().len(), same.elements().len());
|
||||
}
|
||||
|
||||
/// The sum of one colour channel's distance from white.
|
||||
fn channel_ink(img: &Rendered, channel: usize) -> u64 {
|
||||
img.pixels.as_chunks::<4>().0.iter().map(|p| 255 - p[channel] as u64).sum()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lcd_text_takes_each_channel_from_around_its_own_stripe() {
|
||||
let d = Document::from_text("Nobody has assembled this board yet. Italic and round strokes gain the most.");
|
||||
let l = layout(&d, &mut LayoutCache::new(), &LayoutOptions::default());
|
||||
let (w, h) = (700, 200);
|
||||
let view = Affine::scale(1.25);
|
||||
let lcd = |order| RenderOptions { lcd: Some(order), ..Default::default() };
|
||||
let grey = render_region(&d, &l.pages[0], w, h, view, &RenderOptions::default());
|
||||
let rgb = render_region(&d, &l.pages[0], w, h, view, &lcd(LcdOrder::Rgb));
|
||||
let bgr = render_region(&d, &l.pages[0], w, h, view, &lcd(LcdOrder::Bgr));
|
||||
assert!(ink(&grey) > 0);
|
||||
// The page a third of a pixel to the right and to the left, in greyscale.
|
||||
let moved = |dx: f64| render_region(&d, &l.pages[0], w, h, Affine::translate((dx, 0.0)) * view, &RenderOptions::default());
|
||||
let (right, left) = (moved(1.0 / 3.0), moved(-1.0 / 3.0));
|
||||
let mut coloured = 0;
|
||||
let rasters = [&grey, &rgb, &bgr, &right, &left].map(|r| r.pixels.as_chunks::<4>().0);
|
||||
for i in 0..rasters[0].len() {
|
||||
let [g, c, m, r, l] = rasters.map(|px| px[i]);
|
||||
// Green sits in the middle of the pixel: it and the alpha are the greyscale raster's.
|
||||
assert_eq!((c[1], c[3]), (g[1], g[3]));
|
||||
// Red is what a pixel a third to the left would see, blue a third to the right.
|
||||
assert_eq!((c[0], c[2]), (r[0], l[2]), "pixel {i}");
|
||||
// BGR stripes are the mirror image.
|
||||
assert_eq!((m[0], m[1], m[2], m[3]), (c[2], c[1], c[0], c[3]));
|
||||
coloured += usize::from(c[0] != c[2]);
|
||||
}
|
||||
assert!(coloured > 200, "{coloured} pixels have red and blue apart");
|
||||
// No colour cast: each channel carries the same ink, to within a hundredth.
|
||||
let [r, g, b] = [0, 1, 2].map(|c| channel_ink(&rgb, c) as f64);
|
||||
assert!((r - g).abs() < g * 0.01 && (b - g).abs() < g * 0.01, "{r} {g} {b}");
|
||||
// Off by default: exports and thumbnails are untouched.
|
||||
assert_eq!(RenderOptions::default().lcd, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lcd_changes_nothing_but_text() {
|
||||
let lcd = RenderOptions { lcd: Some(LcdOrder::Rgb), ..Default::default() };
|
||||
// A page with no text: the same raster, from one pass.
|
||||
let mut blank = Document::from_text("");
|
||||
blank.settings.page_color = Some(Rgb(0x20, 0x60, 0xA0));
|
||||
let l = layout(&blank, &mut LayoutCache::new(), &LayoutOptions::default());
|
||||
assert_eq!(render_page(&blank, &l.pages[0], 0.5, &lcd).pixels, render_page(&blank, &l.pages[0], 0.5, &RenderOptions::default()).pixels);
|
||||
// A page with text on a page colour: pixels differ only where the text is.
|
||||
let mut d = Document::from_text("Coloured paper under one line of text.");
|
||||
d.settings.page_color = Some(Rgb(0xFF, 0xF0, 0xC0));
|
||||
let l = layout(&d, &mut LayoutCache::new(), &LayoutOptions::default());
|
||||
let (grey, sub) = (render_page(&d, &l.pages[0], 1.25, &RenderOptions::default()), render_page(&d, &l.pages[0], 1.25, &lcd));
|
||||
let w = grey.width as usize;
|
||||
let paper = grey.pixels[..4].to_vec();
|
||||
let inked: Vec<usize> = grey.pixels.as_chunks::<4>().0.iter().enumerate().filter(|(_, p)| p[..] != paper[..]).map(|(i, _)| i).collect();
|
||||
let (top, bottom) = (inked.iter().map(|i| i / w).min().unwrap(), inked.iter().map(|i| i / w).max().unwrap());
|
||||
let (first, last) = (inked.iter().map(|i| i % w).min().unwrap(), inked.iter().map(|i| i % w).max().unwrap());
|
||||
let mut changed = 0;
|
||||
for (i, (a, b)) in grey.pixels.as_chunks::<4>().0.iter().zip(sub.pixels.as_chunks::<4>().0).enumerate() {
|
||||
if a != b {
|
||||
changed += 1;
|
||||
let (x, y) = (i % w, i / w);
|
||||
assert!((top..=bottom).contains(&y) && x + 1 >= first && x <= last + 1, "pixel {x},{y} is outside the text");
|
||||
}
|
||||
}
|
||||
assert!(changed > 50, "{changed}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lcd_channels_never_exceed_the_alpha() {
|
||||
// Premultiplied pixels: a colour above its alpha would be brighter than white.
|
||||
let mut px = vec![10, 20, 30, 40, 200, 200, 200, 255];
|
||||
take_lcd_channels(&mut px, &[90, 0, 0, 255, 7, 0, 0, 255], &[0, 0, 80, 255, 0, 0, 9, 255]);
|
||||
assert_eq!(px, [40, 20, 40, 40, 7, 200, 9, 255]);
|
||||
// Rasters of other sizes leave the rest alone and don't panic.
|
||||
let mut px = vec![1, 2, 3, 255, 4, 5, 6, 255, 9];
|
||||
take_lcd_channels(&mut px, &[50, 0, 0, 255], &[]);
|
||||
assert_eq!(px, [1, 2, 3, 255, 4, 5, 6, 255, 9]);
|
||||
}
|
||||
|
||||
/// The glyph runs of `text` in a bundled face at 12 pt, as the page draws them, each changed by
|
||||
/// `change`; and the area they are in.
|
||||
fn glyph_runs(text: &str, change: impl Fn(&mut Draw)) -> (Document, Vec<Draw>, wordcraft_geom::Rect) {
|
||||
let mut d = Document::from_text(text);
|
||||
let styles = std::sync::Arc::make_mut(&mut d.styles);
|
||||
styles.default_chr.font = Some("Source Sans 3".into());
|
||||
styles.default_chr.size = Some(12.0);
|
||||
let l = layout(&d, &mut LayoutCache::new(), &LayoutOptions::default());
|
||||
let page = &l.pages[0];
|
||||
let mut runs: Vec<Draw> = page_layers(&d, page, &DisplayOptions::default())
|
||||
.into_iter()
|
||||
.flat_map(|(_, items)| items)
|
||||
.filter(|it| matches!(it, Draw::Glyphs { .. }))
|
||||
.collect();
|
||||
assert!(!runs.is_empty());
|
||||
runs.iter_mut().for_each(change);
|
||||
(d, runs, wordcraft_geom::Rect::new(0.0, 0.0, page.w, 200.0))
|
||||
}
|
||||
|
||||
/// How much is drawn on nothing: the sum of the pixels' opacity.
|
||||
fn opacity(img: &Rendered) -> u64 {
|
||||
img.pixels.as_chunks::<4>().0.iter().map(|p| p[3] as u64).sum()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn synthetic_bold_is_darkened_too() {
|
||||
// A face with no bold of its own is made bold by stroking its outlines. The stroke reaches
|
||||
// further than the darkening does, so it has to stroke the darkened outline: the darkening
|
||||
// then moves the bold text's edges as far as the regular text's, and adds about as much ink.
|
||||
let added = |bold: bool, scale: f32| {
|
||||
let (d, runs, area) = glyph_runs("Bold made by stroking the outline", |run| {
|
||||
if let Draw::Glyphs { synth_bold, .. } = run {
|
||||
*synth_bold = bold;
|
||||
}
|
||||
});
|
||||
let dark = RenderOptions { text_darkening: 1.0, ..Default::default() };
|
||||
let (plain, darkened) =
|
||||
(opacity(&render_items(&d, &runs, area, scale, &RenderOptions::default())), opacity(&render_items(&d, &runs, area, scale, &dark)));
|
||||
assert!(plain > 0 && darkened > plain, "bold {bold}: plain {plain}, darkened {darkened}");
|
||||
(darkened - plain) as f64
|
||||
};
|
||||
for scale in [1.0, 2.0] {
|
||||
let (regular, bold) = (added(false, scale), added(true, scale));
|
||||
assert!(bold > regular * 0.75, "scale {scale}: ink added: {regular} regular, {bold} bold");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stretched_hinted_text_is_darkened_as_far_as_unstretched() {
|
||||
// One letter, hinted, at its own width and scaled to 400 % (`w:w`): the darkening moves each
|
||||
// edge the same distance on screen, so it adds about the same ink to both.
|
||||
let added = |stretch: f32| {
|
||||
let (d, runs, area) = glyph_runs("H", |run| {
|
||||
if let Draw::Glyphs { x_scale, .. } = run {
|
||||
*x_scale = stretch;
|
||||
}
|
||||
});
|
||||
let hint = RenderOptions { hinting: true, ..Default::default() };
|
||||
let dark = RenderOptions { text_darkening: 1.0, ..hint.clone() };
|
||||
let (plain, darkened) = (opacity(&render_items(&d, &runs, area, 2.0, &hint)), opacity(&render_items(&d, &runs, area, 2.0, &dark)));
|
||||
assert!(darkened > plain, "stretch {stretch}: plain {plain}, darkened {darkened}");
|
||||
(darkened - plain) as f64
|
||||
};
|
||||
let (own, stretched) = (added(1.0), added(4.0));
|
||||
assert!(stretched < own * 1.5 && stretched > own * 0.6, "ink added: {own} unstretched, {stretched} stretched");
|
||||
// The conversion itself: a widening of `px` device pixels, in outline units, is `px` again
|
||||
// once the outline is on screen.
|
||||
for (hinted, font_px, stretch) in [(true, 0.02, 1.0), (true, 0.02, 4.0), (false, 0.02, 1.0), (false, 0.02, 4.0)] {
|
||||
let on_screen = if hinted { stretch } else { font_px * stretch };
|
||||
assert!((0.25 / widen_unit(hinted, font_px, stretch) * on_screen - 0.25).abs() < 1e-12, "{hinted} {stretch}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_area_rendered_to_a_pixel_size_fills_it_and_keeps_its_text_on_the_grid() {
|
||||
let (d, l) = flat_capitals();
|
||||
let page = &l.pages[0];
|
||||
let area = wordcraft_geom::Rect::new(0.0, 0.0, page.w, page.h);
|
||||
let snap = RenderOptions { baseline_snap: true, ..Default::default() };
|
||||
// A page 1746.155 × 2469.544 pixels at its scale, made 1746 × 2470: a pixel in two thousand off each way.
|
||||
let scale = 1746.155 / page.w;
|
||||
let (w, h) = (1746, (page.h * scale).round() as u32 + 1);
|
||||
let exact = render_area_to(&d, page, area, w, h, &snap);
|
||||
assert_eq!((exact.width, exact.height), (w, h));
|
||||
// One scale gives the next whole pixel up each way: not the size asked for.
|
||||
let up = render_area(&d, page, area, scale, &snap);
|
||||
assert_eq!(up.width, 1747);
|
||||
// The text is as it is at the page's own scale, feet on a whole pixel row: scaled that little differently
|
||||
// across and down, the page is still upright.
|
||||
let foot_is_dark = |img: &Rendered| {
|
||||
let (_, foot) = ink_row_span(img);
|
||||
let w = img.width as usize;
|
||||
img.pixels[foot * w * 4..(foot + 1) * w * 4].as_chunks::<4>().0.iter().map(|p| p[0]).min().unwrap_or(255) < 16
|
||||
};
|
||||
assert!(foot_is_dark(&exact) && foot_is_dark(&up));
|
||||
assert!(is_upright(Affine::scale_non_uniform(2.0, 2.002)) && is_upright(Affine::scale_non_uniform(2.933, 2.9334)));
|
||||
assert!(!is_upright(Affine::scale_non_uniform(2.0, 2.01)));
|
||||
// Hostile sizes and areas: clamped, never a panic.
|
||||
for (area, w, h) in [
|
||||
(wordcraft_geom::Rect::new(0.0, 0.0, 0.0, 0.0), 10, 10),
|
||||
(wordcraft_geom::Rect::new(f32::NAN, f32::INFINITY, f32::NAN, -5.0), 10, 10),
|
||||
(area, 0, 0),
|
||||
(area, u32::MAX, 3),
|
||||
] {
|
||||
let img = render_area_to(&d, page, area, w, h, &snap);
|
||||
assert!(img.width >= 1 && img.height >= 1 && img.pixels.len() == img.width as usize * img.height as usize * 4);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hinting_sharpens_screen_text_without_making_it_bolder_or_moving_it() {
|
||||
let mut d =
|
||||
@@ -2379,35 +2053,6 @@ fn rules_of_one_width_cover_the_same_whole_pixels_at_every_zoom() {
|
||||
assert!(snap_rule(Affine::scale(2.0), (0.0, 0.0, 9.0, 4.0), 0.5).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rules_snap_by_the_scale_across_them_on_a_page_scaled_a_little_differently_each_way() {
|
||||
// A page raster made to fill a whole number of pixels is scaled a pixel in a thousand or two
|
||||
// differently across and down. A level rule lies where the scale down the page puts it, and
|
||||
// an upright one where the scale across does.
|
||||
for (kx, ky) in [(2.0, 2.002), (2.002, 2.0), (2.933, 2.9334), (1.3333, 1.3329)] {
|
||||
let view = Affine::new([kx, 0.0, 0.0, ky, 37.3, 12.9]);
|
||||
assert!(is_upright(view));
|
||||
for i in 0..40 {
|
||||
let pos = 10.0 + f64::from(i) * 17.37;
|
||||
let (w_h, (_, oy)) = snap_rule(view, (5.0, pos, 400.0, pos), 0.5).unwrap();
|
||||
let (w_v, (ox, _)) = snap_rule(view, (pos, 5.0, pos, 400.0), 0.5).unwrap();
|
||||
for (w, centre, lies) in [(w_h, (pos + oy) * ky + 12.9, pos * ky + 12.9), (w_v, (pos + ox) * kx + 37.3, pos * kx + 37.3)] {
|
||||
let edge = centre - w / 2.0;
|
||||
assert!((edge - edge.round()).abs() < 1e-9, "scales {kx} {ky}: edge {edge} is off the pixel grid");
|
||||
// Snapped onto the grid from where it lies: never further than its own width and half a pixel.
|
||||
assert!((centre - lies).abs() <= w / 2.0 + 0.5 + 1e-9, "scales {kx} {ky}: moved {} px", centre - lies);
|
||||
}
|
||||
}
|
||||
}
|
||||
// The case from review: a level rule at 250 pt, half a point wide, at 2.0 across and 2.002 down, is a pixel
|
||||
// wide and centred on 500.5 already. It stays there.
|
||||
let view = Affine::scale_non_uniform(2.0, 2.002);
|
||||
let (w, (_, oy)) = snap_rule(view, (5.0, 250.0, 400.0, 250.0), 0.5).unwrap();
|
||||
assert_eq!(w, 1.0);
|
||||
assert!(((250.0 + oy) * 2.002 - 500.5).abs() < 1e-9, "centre {}", (250.0 + oy) * 2.002);
|
||||
assert_eq!((rule_scale(view, true), rule_scale(view, false)), (2.002, 2.0));
|
||||
}
|
||||
|
||||
/// The same three pictures that don't draw as in the PDF test: each stays a grey box, and the page's
|
||||
/// pixels are what they were before strict export existed (#6005).
|
||||
#[test]
|
||||
|
||||
@@ -16,7 +16,7 @@ craft = { workspace = true, features = [
|
||||
"color", "color-ui", "control", "draw", "font-manager", "gpu", "menu", "pages", "print", "review", "table", "text",
|
||||
"text-find", "web-api", "web-host", "window",
|
||||
] }
|
||||
craft-fonts-build = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165" }
|
||||
craft-fonts-build = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e" }
|
||||
wordcraft-geom = { workspace = true, features = ["image"] }
|
||||
wordcraft-doc = { workspace = true }
|
||||
wordcraft-fonts = { workspace = true }
|
||||
@@ -76,7 +76,7 @@ craft-ui-test-kit = { workspace = true }
|
||||
craft = { workspace = true, features = ["ui-testing"] }
|
||||
|
||||
[build-dependencies]
|
||||
craft-fonts-build = { git = "https://github.com/storytold/craft-libs", rev = "d73e274a01408ef433a291a667e6014937d72165", features = ["subset"] }
|
||||
craft-fonts-build = { git = "https://github.com/storytold/craft-libs", rev = "98a66a56550b027cc8cdcd689ab7d3239c71427e", features = ["subset"] }
|
||||
serde_json = { workspace = true }
|
||||
toml = "1"
|
||||
|
||||
|
||||
@@ -133,8 +133,13 @@ impl WordApp {
|
||||
user_origin: false,
|
||||
read_aloud_error: None,
|
||||
autosave_path: None,
|
||||
read_from: None,
|
||||
saves_in_flight: Vec::new(),
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
windowless_save_folders: Default::default(),
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
owned_picks: Default::default(),
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
native_windows: None,
|
||||
fallback_chooser: false,
|
||||
font_generation: wordcraft_fonts::FontDb::global().generation(),
|
||||
recovery_seen: false,
|
||||
@@ -281,7 +286,12 @@ impl WordApp {
|
||||
self.host = std::sync::Arc::new(self.host.with_lang(lang.craft_lang()));
|
||||
}
|
||||
let commands: CommandInput = self.command_input();
|
||||
FrameInput::new(self.root_env()).commands(commands).host(self.host.clone())
|
||||
// The windowless trial's host routes `PathRow` picks to the window that files them (`file_dialogs::path_rows`).
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
let host = self.frame_host();
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
let host = self.host.clone();
|
||||
FrameInput::new(self.root_env()).commands(commands).host(host)
|
||||
}
|
||||
|
||||
/// Start-up with no document to open (#766): show File › Home (Blank document, the templates
|
||||
|
||||
@@ -39,10 +39,23 @@ impl WordApp {
|
||||
/// Close, Envelopes, Labels and Finish & Merge on a document with unsaved changes first ask
|
||||
/// Save / Don't Save / Cancel, and the command runs once that is answered (`ui.saveChanges`).
|
||||
pub fn run(&mut self, id: &str, params: Value) -> Result<Value, String> {
|
||||
if id == "file.close"
|
||||
&& let Some(result) = self.raise_closing()
|
||||
{
|
||||
return Ok(result);
|
||||
if id == "file.close" {
|
||||
if let Some(result) = self.raise_closing() {
|
||||
return Ok(result);
|
||||
}
|
||||
// Before any Save Changes prompt: this window's own system file dialog may still use it,
|
||||
// so the close (or the quit it continues) waits for that dialog and then runs as asked.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if params.get("quit").and_then(Value::as_bool) == Some(true) {
|
||||
if self.defer_quit_for_native_panels() {
|
||||
return Ok(json!({"closed": false, "deferred": true}));
|
||||
}
|
||||
} else if self.defer_close_for_native_panel(self.windows.shown()) {
|
||||
return Ok(json!({"closed": false, "deferred": true}));
|
||||
}
|
||||
if let Some(error) = self.rejected_draft_blocks_last_surface_close() {
|
||||
return Err(error);
|
||||
}
|
||||
}
|
||||
// Undo and Redo act on whole steps: a SmartArt typing run still open is folded into its one step first,
|
||||
// or Undo would take back only the last keystroke of it.
|
||||
@@ -176,11 +189,7 @@ impl WordApp {
|
||||
return Err(e.into());
|
||||
}
|
||||
if id == "file.autosave" {
|
||||
let r = self.set_autosave(¶ms);
|
||||
if let Err(e) = &r {
|
||||
self.status(e.clone());
|
||||
}
|
||||
return r;
|
||||
return self.set_autosave(¶ms);
|
||||
}
|
||||
if let Some(r) = table_pen::toggle(self, id, ¶ms) {
|
||||
return r;
|
||||
@@ -330,8 +339,13 @@ impl WordApp {
|
||||
self.recovery_seen = true;
|
||||
self.sync_document();
|
||||
}
|
||||
if let Ok(v) = &r {
|
||||
self.note_file_on_disk(id, ¶ms, v);
|
||||
// An explicit save to the document's own file lets AutoSave keep writing there.
|
||||
if let Ok(v) = &r
|
||||
&& matches!(id, "file.save" | "file.saveAs")
|
||||
&& v.get("saved").and_then(Value::as_bool) == Some(true)
|
||||
&& v.get("path").and_then(Value::as_str).map(std::path::Path::new) == self.session.path.as_deref()
|
||||
{
|
||||
self.autosave_path = self.session.path.clone();
|
||||
}
|
||||
// A Markdown file edited in the formatted view was written out again, not kept as it was.
|
||||
if let Ok(v) = &r
|
||||
@@ -348,9 +362,6 @@ impl WordApp {
|
||||
if self.autosave_path.as_ref() == Some(&old) {
|
||||
self.autosave_path = self.session.path.clone();
|
||||
}
|
||||
if self.read_from.as_ref() == Some(&old) {
|
||||
self.read_from = self.session.path.clone();
|
||||
}
|
||||
let old = old.to_string_lossy();
|
||||
self.ui.recent.retain(|r| *r != old);
|
||||
}
|
||||
@@ -436,25 +447,6 @@ impl WordApp {
|
||||
r
|
||||
}
|
||||
|
||||
/// Which file on disk the document is in, after `file.save`, `file.saveAs` or `file.open`.
|
||||
fn note_file_on_disk(&mut self, id: &str, params: &Value, v: &Value) {
|
||||
// An explicit save to the document's own file lets AutoSave keep writing there.
|
||||
if matches!(id, "file.save" | "file.saveAs")
|
||||
&& v.get("saved").and_then(Value::as_bool) == Some(true)
|
||||
&& v.get("path").and_then(Value::as_str).map(std::path::Path::new) == self.session.path.as_deref()
|
||||
{
|
||||
self.autosave_path = self.session.path.clone();
|
||||
self.read_from = self.session.path.clone();
|
||||
}
|
||||
// A file read from disk may have AutoSave turned on for it; one opened from bytes only
|
||||
// names a file it never read.
|
||||
// `file.open` without a path only asks for the picker, and `data` that isn't a string is
|
||||
// ignored (the file is read from disk).
|
||||
if id == "file.open" && params.get("path").and_then(Value::as_str).is_some() && v.get("alreadyOpen").and_then(Value::as_bool) == Some(false) {
|
||||
self.read_from = if params.get("data").and_then(Value::as_str).is_some() { None } else { self.session.path.clone() };
|
||||
}
|
||||
}
|
||||
|
||||
fn after_command(&mut self, id: &str) {
|
||||
self.canvas.glide.restart(craft::platform::clock::monotonic_ms());
|
||||
if id == "view.outline" {
|
||||
@@ -1302,7 +1294,6 @@ pub(crate) fn works_without_document(id: &str) -> bool {
|
||||
| "tools.customizeRibbon"
|
||||
| "view.darkMode"
|
||||
| "view.paperColor"
|
||||
| "view.textSmoothing"
|
||||
| "view.marks"
|
||||
| "view.ruler"
|
||||
| "view.numeral"
|
||||
|
||||
@@ -229,7 +229,7 @@ impl WordApp {
|
||||
}
|
||||
|
||||
/// End the operation without running anything; its owning window's prompt closes with it.
|
||||
fn cancel_closing(&mut self) {
|
||||
pub(crate) fn cancel_closing(&mut self) {
|
||||
if let Some(closing) = self.closing.take()
|
||||
&& let Some(id) = closing.prompt
|
||||
{
|
||||
@@ -508,6 +508,12 @@ impl WordApp {
|
||||
self.status(tl!("Wait for the print job to finish submitting before closing."));
|
||||
return false;
|
||||
}
|
||||
// A system file dialog may still use its window's handles until it answers: the loop keeps
|
||||
// running (and closes what it can), and the quit goes on by itself once they have ended.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if self.defer_quit_for_native_panels() {
|
||||
return false;
|
||||
}
|
||||
if self.quit_requested {
|
||||
return true;
|
||||
}
|
||||
@@ -541,7 +547,17 @@ impl WordApp {
|
||||
if let Some(result) = self.raise_closing() {
|
||||
return Ok(result);
|
||||
}
|
||||
if self.closes_only_its_window("file.close", params) && self.close_window_only() {
|
||||
// This window's own system file dialog may still use it: close (or go on quitting) once
|
||||
// that has ended.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if params.get("quit").and_then(Value::as_bool) == Some(true) {
|
||||
if self.defer_quit_for_native_panels() {
|
||||
return Ok(json!({"closed": false, "deferred": true}));
|
||||
}
|
||||
} else if self.defer_close_for_native_panel(self.windows.shown()) {
|
||||
return Ok(json!({"closed": false, "deferred": true}));
|
||||
}
|
||||
if self.closes_only_its_window("file.close", params) && self.close_window_only()? {
|
||||
return Ok(json!({"closed": true, "window": true}));
|
||||
}
|
||||
if let Some(e) = crate::control::close_refused(self, "file.close", params) {
|
||||
@@ -684,31 +700,13 @@ impl WordApp {
|
||||
self.autosave && self.autosave_block().is_none()
|
||||
}
|
||||
|
||||
/// What the AutoSave switch can't lift: [`Self::autosave_block`], less a file read from disk
|
||||
/// here, which the switch turns on (#3307). A document opened from bytes stays blocked.
|
||||
pub fn autosave_switch_block(&self) -> Option<AutoSaveBlock> {
|
||||
self.autosave_block().filter(|b| *b != AutoSaveBlock::NotSavedHere || self.read_from != self.session.path)
|
||||
}
|
||||
|
||||
/// `file.autosave` (the AutoSave switch, and scripts): `value` turns AutoSave on or off;
|
||||
/// without it, it toggles what the switch shows. Turning it on for a document AutoSave can't
|
||||
/// cover is an error that says why, instead of a switch that is on but saves nothing (#196).
|
||||
/// Turning it on for a file only opened here is the go-ahead a save gives (#3307), when the
|
||||
/// document was read from that file; turning it off withdraws the go-ahead for this document.
|
||||
pub(super) fn set_autosave(&mut self, params: &Value) -> Result<Value, String> {
|
||||
let on = match params.get("value") {
|
||||
None => !self.autosaves(),
|
||||
Some(Value::Bool(on)) => *on,
|
||||
Some(_) => return Err("`value` must be true or false".into()),
|
||||
};
|
||||
if on && self.autosave_block().is_some() {
|
||||
if let Some(block) = self.autosave_switch_block() {
|
||||
return Err(block.reason());
|
||||
}
|
||||
self.autosave_path = self.session.path.clone();
|
||||
}
|
||||
if !on {
|
||||
self.autosave_path = None;
|
||||
let on = params.get("value").and_then(Value::as_bool).unwrap_or(!self.autosaves());
|
||||
if on && let Some(block) = self.autosave_block() {
|
||||
return Err(block.reason());
|
||||
}
|
||||
self.autosave = on;
|
||||
self.session.autosave = on;
|
||||
|
||||
@@ -167,7 +167,12 @@ impl WordApp {
|
||||
updates_ui::run(self);
|
||||
crate::dialogs::host::prepare(self);
|
||||
let had_dialogs = !self.dialog_host.is_empty();
|
||||
// A `PathRow` pick filed in the run is bound to the exact dialog opening running it (windowless trial).
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
self.begin_row_forms();
|
||||
self.dialog_host.run(ui);
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
self.end_row_forms();
|
||||
crate::dialogs::host::settle(self, ctx);
|
||||
crate::dialogs::chrome::apply_modal_nudge(self, ui);
|
||||
if moved(self) {
|
||||
|
||||
@@ -60,7 +60,7 @@ impl ThumbSource<ThumbKey> for TemplateThumbs {
|
||||
let Some(page) = layout.pages.first() else { return ThumbRender::Blank };
|
||||
// The longest side of the page is `request.side` pixels; the store never asks for zero.
|
||||
let scale = request.side as f32 / page.w.max(page.h).max(1.0);
|
||||
let image = wordcraft_render::render_page(&session.doc, page, scale, &crate::canvas::thumbnail_render_options());
|
||||
let image = wordcraft_render::render_page(&session.doc, page, scale, &crate::canvas::screen_render_options());
|
||||
let pixels = image.to_straight();
|
||||
ThumbRender::Ready(egui::ColorImage::from_rgba_unmultiplied([image.width as usize, image.height as usize], &pixels))
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ pub(crate) use links::follow_link;
|
||||
use links::{field_link, is_followable_link, is_generated_bookmark_link};
|
||||
pub use navigation::page_to_screen;
|
||||
use navigation::viewed_page;
|
||||
pub(crate) use pages::{PageKeys, dark_page, page_doc, page_screen_scale, preview_sel, screen_render_options, thumbnail_render_options};
|
||||
pub(crate) use pages::{PageKeys, dark_page, page_doc, page_screen_scale, preview_sel, screen_render_options};
|
||||
use pages::{page_render_options, shown_layout};
|
||||
use reading::{reading_anchor_page, reading_page_start, web_layout_width};
|
||||
use story::dims_body;
|
||||
@@ -111,11 +111,6 @@ pub struct CanvasState {
|
||||
/// The page asks for the keyboard between this pass and the next ([`CanvasState::focus_page_after_pass`]): always
|
||||
/// (no ids), or only while focus is still on one of the ids.
|
||||
focus_after_pass: Option<Vec<egui::Id>>,
|
||||
/// Where the page view put its pages (page, place in screen points) the last time two passes running put
|
||||
/// them in the same places: the view at rest. Page pictures are made to fill these places exactly
|
||||
/// (`source::WordPages`); while the view moves they stay as they were, so a scroll or a zoom under way makes
|
||||
/// no picture again for a place it is only passing through.
|
||||
pub(crate) settled_pages: Vec<(usize, Rect)>,
|
||||
/// How many page pictures the page view kept resident after the last pass (S-L352).
|
||||
pub(crate) resident_pictures: usize,
|
||||
/// The caret's glide and blink.
|
||||
@@ -426,7 +421,6 @@ impl Default for CanvasState {
|
||||
shown: ShownPages::default(),
|
||||
focus_pending: true,
|
||||
focus_after_pass: None,
|
||||
settled_pages: Vec::new(),
|
||||
resident_pictures: 0,
|
||||
glide: crate::caret_glide::CaretGlide::default(),
|
||||
comments: Default::default(),
|
||||
@@ -757,8 +751,7 @@ fn show_reading(app: &mut WordApp, ui: &mut Ui, layout: &Arc<DocLayout>, full: R
|
||||
let columns = Rect::from_min_max(full.min, pos2(full.max.x, (full.max.y - metrics.nav_bar).max(full.min.y)));
|
||||
let footer = Rect::from_min_max(pos2(full.min.x, columns.max.y), full.max);
|
||||
let mut state = std::mem::take(&mut app.canvas.reading);
|
||||
// Read Mode sizes its columns itself: no view scale to rasterise at.
|
||||
let source = source::WordPages::new(app, layout, false, None, None);
|
||||
let source = source::WordPages::new(app, layout, false, None);
|
||||
let out = ReadingView::new(tl!("Document"), &source, &mut state, paper).zoom(zoom).show_at(ui, columns);
|
||||
// The page-turn row sits at the bottom right, as in v0.19.1 (the far end, so the bottom left in a right-to-left UI),
|
||||
// the page view's side margin in from the edge.
|
||||
@@ -847,7 +840,7 @@ fn show_pages(app: &mut WordApp, ui: &mut Ui, layout: &Arc<DocLayout>, full: Rec
|
||||
let options =
|
||||
LayoutOptions { markup: f64::from(markup_width(app)), min_columns: if app.session.view.multi_page { 2 } else { 1 }, ..LayoutOptions::WORD };
|
||||
let paper = DataColor::new(paper_color(app));
|
||||
let source = source::WordPages::new(app, layout, dim_body, hidden, Some(scale as f32));
|
||||
let source = source::WordPages::new(app, layout, dim_body, hidden);
|
||||
// The describer owns its snapshot, as the source does, so the page view can hold it while the body edits the app.
|
||||
let described = preview_sel(app).unwrap_or(app.session.sel_ends()).clone();
|
||||
let describer = crate::a11y::DocumentDescriber::new(source.doc(), layout.clone(), (described.anchor.clone(), described.focus.clone()));
|
||||
@@ -1040,14 +1033,6 @@ fn show_pages(app: &mut WordApp, ui: &mut Ui, layout: &Arc<DocLayout>, full: Rec
|
||||
// A window's page has the keyboard from its first pass (production's `want_focus` started on), so typing lands
|
||||
// without a click; a modal dialog keeps the keyboard until it closes.
|
||||
let view_rect = body_view.map_or(body_rect, |v| v.rect);
|
||||
// The same places two passes running: the view is at rest, and these are the places pictures are made for.
|
||||
let placed = |pages: &[PlacedPage]| pages.iter().map(|p| (p.page, p.rect)).collect::<Vec<_>>();
|
||||
let now = placed(&out.pages);
|
||||
if now == placed(&app.canvas.shown.pages) && now != app.canvas.settled_pages {
|
||||
app.canvas.settled_pages = now;
|
||||
// The pictures of the places just settled are made on the next pass.
|
||||
ui.ctx().request_repaint();
|
||||
}
|
||||
app.canvas.shown =
|
||||
ShownPages { rect: body_rect, pages: out.pages.clone(), laid: laid_rects(&out), view: view_rect, canvas: Some(out.canvas.response.id) };
|
||||
if app.canvas.focus_pending && !app.modal_open() {
|
||||
|
||||
@@ -7,29 +7,10 @@ use super::{Pos2, WordApp};
|
||||
/// coordinates) while any of it is inside the window (`top` .. `top + height`, `top` the layout's y at the window's
|
||||
/// top edge), else the page at the window's top: the first whose shown band ends below it (with Hide White Space the
|
||||
/// rects overlap in the hidden margins, and the next page's text already shows there), the last page past the end.
|
||||
/// A page whose shown part at the top is no more than the gap to the page below it (the next row down) does not count: Go To leaves the
|
||||
/// pages' margin above a page, which is more than that gap, so a sliver of the page above still shows (#7149).
|
||||
pub(super) fn viewed_page(caret: Option<(usize, f64, f64)>, top: f64, layout: &PagedLayout, height: f64) -> usize {
|
||||
match caret {
|
||||
Some((page, from, to)) if to >= top && from <= top + height => page,
|
||||
_ => (0..layout.rects.len())
|
||||
.position(|i| {
|
||||
let end = layout.rects[i].y0 + layout.bands.get(i).map_or(0.0, |band| band.1);
|
||||
// The gap to the first later page whose shown part starts at or below this one's end: the page below,
|
||||
// whatever the column (an incomplete last row, a Two Up cover) and with Hide White Space (a seam).
|
||||
let below = |j: &usize| layout.rects.get(*j).is_some_and(|r| r.y0 + layout.bands.get(*j).map_or(0.0, |b| b.0) >= end);
|
||||
// Measured from the bottom of the row (the tallest page between this one and that page): pages of different
|
||||
// heights share a row, and the next row starts below the tallest.
|
||||
let gap = ((i + 1)..layout.rects.len()).find(below).and_then(|j| layout.rects.get(j).map(|next| (j, next))).map_or(0.0, |(j, _)| {
|
||||
let row_end = (i..j).map(|k| layout.rects[k].y0 + layout.bands.get(k).map_or(0.0, |b| b.1)).fold(end, f64::max);
|
||||
// The next row's real top: its shorter pages are centred lower, so not `next`'s own top.
|
||||
let shown = |k: usize| layout.rects[k].y0 + layout.bands.get(k).map_or(0.0, |b| b.0);
|
||||
let next_top = (j..(j + layout.columns.max(1)).min(layout.rects.len())).map(shown).fold(shown(j), f64::min);
|
||||
(next_top - row_end).max(0.0)
|
||||
});
|
||||
end > top + gap
|
||||
})
|
||||
.unwrap_or(layout.rects.len().saturating_sub(1)),
|
||||
_ => layout.rects.iter().zip(&layout.bands).position(|(r, band)| r.y0 + band.1 > top).unwrap_or(layout.rects.len().saturating_sub(1)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use std::fmt::Write as _;
|
||||
|
||||
use craft::ui::primitives::textures::MAX_TEXTURE;
|
||||
|
||||
use super::{DocLayout, Hash, Hasher, Page, Placed, Pos, Rect, WordApp, json};
|
||||
|
||||
/// Streams `Debug` formatting directly into a [`Hasher`] without intermediate `String` allocations.
|
||||
@@ -22,9 +20,6 @@ impl std::fmt::Write for HashFmt<'_> {
|
||||
// revision that the pages' pictures key on directly.
|
||||
pub(super) fn view_key(app: &WordApp, dim_body: bool, hidden: Option<&Pos>) -> u64 {
|
||||
let mut h = std::collections::hash_map::DefaultHasher::new();
|
||||
// A page drawn under the system's earlier text settings, or the user's earlier smoothing choice, must not pass
|
||||
// for one drawn under these.
|
||||
(crate::screen_text::current().key(), app.session.prefs.text_smoothing).hash(&mut h);
|
||||
let v = &app.session.view;
|
||||
(v.marks, app.session.prefs.marks, v.show_markup, v.dark_mode, wordcraft_render::DARK_PAPER, v.hide_ink, v.draw.replay).hash(&mut h);
|
||||
(v.read_mode, v.read_page_color, app.session.prefs.paper_color).hash(&mut h);
|
||||
@@ -185,9 +180,6 @@ pub(crate) fn dark_page(app: &WordApp) -> bool {
|
||||
/// Render options for this view's page rasters: marks, markup, dark page, header/body dimming.
|
||||
pub(super) fn page_render_options(app: &WordApp, dim_body: bool) -> wordcraft_render::RenderOptions {
|
||||
let mut opts = screen_render_options();
|
||||
// Pages, and only pages, follow the system's own text settings once they are known ([`crate::screen_text`]);
|
||||
// `view_key` has them, so a change redraws the pages.
|
||||
crate::screen_text::current().apply(&mut opts);
|
||||
opts.display.marks = app.session.view.marks;
|
||||
opts.display.always = app.session.prefs.marks;
|
||||
opts.display.placeholders = true;
|
||||
@@ -216,107 +208,15 @@ pub(super) fn page_render_options(app: &WordApp, dim_body: bool) -> wordcraft_re
|
||||
opts
|
||||
}
|
||||
|
||||
/// Subpixel (LCD) text for the page rasters of a screen with `ppp` device pixels per point, as File › Options ›
|
||||
/// General › Screen text smoothing says. "Use system setting" draws it where the system asks for it
|
||||
/// ([`crate::screen_text`]) and the screen is below two device pixels per point: on a denser screen the stripes are
|
||||
/// too fine to gain from, and a page has four times the pixels to rasterise three times. "Subpixel (LCD)" draws it
|
||||
/// on any screen, in the system's stripe order, RGB when it names none (macOS never does).
|
||||
pub(super) fn lcd_for(
|
||||
choice: wordcraft_engine::cmd::view::TextSmoothing,
|
||||
asked: Option<crate::screen_text::SubpixelOrder>,
|
||||
stripes: Option<crate::screen_text::SubpixelOrder>,
|
||||
ppp: f32,
|
||||
) -> Option<wordcraft_render::LcdOrder> {
|
||||
use crate::screen_text::SubpixelOrder;
|
||||
use wordcraft_engine::cmd::view::TextSmoothing;
|
||||
use wordcraft_render::LcdOrder;
|
||||
let order = |stripes: SubpixelOrder| match stripes {
|
||||
SubpixelOrder::Rgb => LcdOrder::Rgb,
|
||||
SubpixelOrder::Bgr => LcdOrder::Bgr,
|
||||
};
|
||||
match choice {
|
||||
TextSmoothing::Grayscale => None,
|
||||
// The user's own choice, in the order of their screen even where the system has smoothing off (a BGR panel
|
||||
// with ClearType off must not get RGB edges).
|
||||
TextSmoothing::Subpixel => Some(asked.or(stripes).map(order).unwrap_or(LcdOrder::Rgb)),
|
||||
// Written so a density that isn't a number is greyscale too.
|
||||
TextSmoothing::System => asked.map(order).filter(|_| ppp < 2.0),
|
||||
}
|
||||
}
|
||||
|
||||
/// The scale (pixels per document point) to rasterise a page picture at, and whether that is the screen's own.
|
||||
///
|
||||
/// The page view asks for a picture by its longest side in pixels, `side`, rounded up to a multiple of `step`, and
|
||||
/// scales what it gets to the page's place on screen. Rasterised at `side`, a page is up to `step` pixels larger
|
||||
/// than it shows and every glyph is resampled on the way to the screen, which undoes baselines put on whole pixels
|
||||
/// and makes subpixel text wrong (each colour's edge off its stripe). `native` is the view's own scale, device
|
||||
/// pixels per document point, when it is known: where it accounts for the side asked for (the page's `longest`
|
||||
/// side, in points, at that scale rounds up to `side`), the picture is rasterised at exactly that scale, one raster
|
||||
/// pixel per device pixel. Otherwise (another view's request, a fit zoom not settled yet, a part of a page shown
|
||||
/// reduced) it is rasterised at the side asked for, as before, and is not the screen's own.
|
||||
pub(super) fn raster_scale(side: u32, step: u32, longest: f32, native: Option<f32>) -> (f32, bool) {
|
||||
let largest = MAX_TEXTURE as f32;
|
||||
// `side / longest * longest` can come out a hair over `side`, which rounds up to a pixel too many for a texture.
|
||||
let mut asked = side as f32 / longest;
|
||||
if side <= MAX_TEXTURE && (longest * asked).ceil() > largest {
|
||||
asked = asked.next_down().next_down();
|
||||
}
|
||||
let fits = |scale: f32| {
|
||||
let pixels = longest * scale;
|
||||
scale.is_finite() && scale > 0.0 && pixels.is_finite() && pixels <= side as f32 + 0.5 && pixels > side as f32 - step as f32 - 0.5
|
||||
// A pixel over the largest texture and the store halves the whole picture.
|
||||
&& pixels.ceil() <= largest
|
||||
};
|
||||
match native.filter(|scale| longest.is_finite() && longest > 0.0 && step > 0 && fits(*scale)) {
|
||||
Some(scale) => (scale, true),
|
||||
None => (asked, false),
|
||||
}
|
||||
}
|
||||
|
||||
/// The size in device pixels of the place on screen a page's picture is drawn in, when a picture of about
|
||||
/// `expected` pixels (its size at the view's scale) is that place's own.
|
||||
///
|
||||
/// The page view draws a picture as its painter does every picture: the place (`page`, in screen points, or the
|
||||
/// part `region` of it, in fractions) is rounded to whole pixels, and the picture is fitted inside it by its own
|
||||
/// proportions. A picture of exactly the rounded place's size is drawn one pixel for one. Any other is scaled:
|
||||
/// rasterised a whole pixel up each way, as a single scale gives, a 2016 × 2851 pixel place gets a 2017 × 2852
|
||||
/// picture squeezed by a twentieth of a percent, and the text slides off the pixel grid and back down the page.
|
||||
/// The rounded size depends on where the place starts, so it comes from where the view last put the page, not
|
||||
/// from the page's size. `None` where the place is not within a pixel and a half of `expected` each way: a
|
||||
/// place left over from another zoom, or numbers that aren't.
|
||||
pub(super) fn picture_pixels(page: egui::Rect, region: Option<egui::Rect>, ppp: f32, expected: (f32, f32)) -> Option<(u32, u32)> {
|
||||
let place = match region {
|
||||
Some(part) => {
|
||||
let at = |f: egui::Pos2| egui::pos2(page.min.x + f.x * page.width(), page.min.y + f.y * page.height());
|
||||
egui::Rect::from_min_max(at(part.min), at(part.max))
|
||||
}
|
||||
None => page,
|
||||
};
|
||||
let side = |lo: f32, hi: f32, expected: f32| {
|
||||
let pixels = (hi * ppp).round() - (lo * ppp).round();
|
||||
(pixels.is_finite() && expected.is_finite() && pixels >= 1.0 && (pixels - expected).abs() <= 1.5).then_some(pixels as u32)
|
||||
};
|
||||
Some((side(place.min.x, place.max.x, expected.0)?, side(place.min.y, place.max.y, expected.1)?))
|
||||
}
|
||||
|
||||
/// Render options for rasters shown on screen other than the pages themselves (style and font previews, a dragged
|
||||
/// object), so their text looks as it does in the platform's other apps (exports never change): on macOS it is
|
||||
/// darkened the way the system draws it; on Linux and the BSDs it is hinted lightly, as FreeType's `hintslight`
|
||||
/// draws it there (not darkened: hinted text already has FreeType's weight, and darkening made it look semi-bold).
|
||||
/// Baselines sit on whole device pixels (hinting does that; unhinted text is moved there). These are fixed per
|
||||
/// platform: such rasters are cached without the system's text settings in their keys, so they must not follow
|
||||
/// them. Pages do ([`page_render_options`]).
|
||||
/// Render options for page rasters shown on screen, so a page looks as text does in the
|
||||
/// platform's other apps (exports never change): on macOS, text is darkened the way the system
|
||||
/// draws it; on Linux and the BSDs it is hinted lightly, as FreeType's `hintslight` draws it
|
||||
/// there (not darkened: hinted text already has FreeType's weight, and darkening made it
|
||||
/// look semi-bold).
|
||||
pub(crate) fn screen_render_options() -> wordcraft_render::RenderOptions {
|
||||
let mut opts = wordcraft_render::RenderOptions { baseline_snap: true, ..Default::default() };
|
||||
crate::screen_text::ScreenText::PLATFORM.apply(&mut opts);
|
||||
opts
|
||||
}
|
||||
|
||||
/// Render options for the template thumbnails of File › New: the platform's text, as [`screen_render_options`],
|
||||
/// without the baseline snapping. A thumbnail is a page shrunk to a tile, drawn as it was before pages were
|
||||
/// sharpened.
|
||||
pub(crate) fn thumbnail_render_options() -> wordcraft_render::RenderOptions {
|
||||
let mut opts = wordcraft_render::RenderOptions::default();
|
||||
crate::screen_text::ScreenText::PLATFORM.apply(&mut opts);
|
||||
opts
|
||||
wordcraft_render::RenderOptions {
|
||||
text_darkening: cfg!(target_os = "macos"),
|
||||
hinting: cfg!(all(unix, not(target_os = "macos"))),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,12 @@ use std::sync::Arc;
|
||||
|
||||
use craft::behavior::kurbo::Size;
|
||||
use craft::pages::ui::PageSource;
|
||||
use craft::ui::primitives::textures::{LoadedPicture, MAX_TEXTURE, Revision, ThumbRender, ThumbRequest, ThumbSource};
|
||||
use craft::ui::primitives::textures::{LoadedPicture, Revision, ThumbRender, ThumbRequest, ThumbSource};
|
||||
use wordcraft_doc::{Document, Pos};
|
||||
use wordcraft_layout::DocLayout;
|
||||
|
||||
use super::WordApp;
|
||||
use super::pages::{PageKeys, lcd_for, page_render_options, page_shows, picture_pixels, raster_scale, view_key};
|
||||
use super::pages::{PageKeys, page_render_options, page_shows, view_key};
|
||||
|
||||
/// A page dimension (points) safe to lay out: finite, at least 1 pt, at most `cap`.
|
||||
fn dim(v: f32, cap: f32) -> f64 {
|
||||
@@ -30,38 +30,13 @@ pub(super) struct WordPages {
|
||||
options: wordcraft_render::RenderOptions,
|
||||
/// The page a drag took an object off, and the object: rendered without it.
|
||||
hidden: Option<(usize, Pos)>,
|
||||
/// Screen points per document point in the view these pages show in, when it is one whose pages are drawn at
|
||||
/// that scale (the page view); `None` where the view sizes its pages itself (Read Mode's columns). With the
|
||||
/// screen's density it gives the scale at which a picture is the screen's own ([`raster_scale`]).
|
||||
view_scale: Option<f32>,
|
||||
/// Where the page view put each page (page, its place in screen points) the last time the view was at rest;
|
||||
/// empty for a view that sizes its pages itself. A picture is made exactly as many pixels each way as its
|
||||
/// place is ([`picture_pixels`]).
|
||||
placed: Vec<(usize, egui::Rect)>,
|
||||
/// File › Options › General › Screen text smoothing, and what the system says of the screen's text.
|
||||
smoothing: wordcraft_engine::cmd::view::TextSmoothing,
|
||||
screen_text: crate::screen_text::ScreenText,
|
||||
}
|
||||
|
||||
/// The page view asks for pictures whose longest side is a multiple of this many pixels
|
||||
/// (`ThumbRequest::side`).
|
||||
const SIDE_STEP: u32 = 16;
|
||||
|
||||
impl WordPages {
|
||||
/// The source of `layout` for this pass. The page fingerprints move out of the app for the pass; give them back
|
||||
/// with [`WordPages::into_keys`].
|
||||
/// `view_scale` is the view's screen points per document point where its pages are drawn at exactly that scale,
|
||||
/// so that their pictures can be rasterised one pixel per device pixel.
|
||||
pub(super) fn new(app: &mut WordApp, layout: &Arc<DocLayout>, dim_body: bool, hidden: Option<(usize, Pos)>, view_scale: Option<f32>) -> Self {
|
||||
let view_scale = view_scale.filter(|scale| scale.is_finite() && *scale > 0.0);
|
||||
let placed = if view_scale.is_some() { app.canvas.settled_pages.clone() } else { Vec::new() };
|
||||
let view = {
|
||||
// A picture rasterised for another zoom is not this zoom's, even where the side asked for is the same.
|
||||
let mut h = DefaultHasher::new();
|
||||
(view_key(app, dim_body, hidden.as_ref().map(|(_, p)| p)), view_scale.map(f32::to_bits)).hash(&mut h);
|
||||
h.finish()
|
||||
};
|
||||
let (smoothing, screen_text) = (app.session.prefs.text_smoothing, crate::screen_text::current());
|
||||
pub(super) fn new(app: &mut WordApp, layout: &Arc<DocLayout>, dim_body: bool, hidden: Option<(usize, Pos)>) -> Self {
|
||||
let view = view_key(app, dim_body, hidden.as_ref().map(|(_, p)| p));
|
||||
let options = page_render_options(app, dim_body);
|
||||
let doc = if let Some((_, preview, _, _)) = &app.canvas.table_preview_layout {
|
||||
Arc::new(preview.clone())
|
||||
@@ -76,8 +51,7 @@ impl WordPages {
|
||||
}
|
||||
}
|
||||
};
|
||||
let keys = RefCell::new(std::mem::take(&mut app.canvas.page_keys));
|
||||
WordPages { doc, layout: layout.clone(), keys, view, options, hidden, view_scale, placed, smoothing, screen_text }
|
||||
WordPages { doc, layout: layout.clone(), keys: RefCell::new(std::mem::take(&mut app.canvas.page_keys)), view, options, hidden }
|
||||
}
|
||||
|
||||
/// The pass's document snapshot, shared with the accessibility describer so the pass holds one copy.
|
||||
@@ -91,26 +65,16 @@ impl WordPages {
|
||||
}
|
||||
}
|
||||
|
||||
/// What a request for a page's picture is rasterised as.
|
||||
pub(super) struct RasterPlan {
|
||||
/// The whole page, or only `area` of it.
|
||||
pub(super) whole: bool,
|
||||
/// The part of the page to rasterise, in document points.
|
||||
pub(super) area: wordcraft_geom::Rect,
|
||||
/// Pixels per document point.
|
||||
pub(super) scale: f32,
|
||||
/// The picture's size in pixels where it is made to fill its place on screen exactly; `None` for one made at
|
||||
/// `scale`, a whole pixel up each way.
|
||||
pub(super) pixels: Option<(u32, u32)>,
|
||||
pub(super) options: wordcraft_render::RenderOptions,
|
||||
}
|
||||
impl ThumbSource<usize> for WordPages {
|
||||
fn revision(&self, page: &usize, _request: &ThumbRequest) -> Revision {
|
||||
let mut h = DefaultHasher::new();
|
||||
page_shows(&mut self.keys.borrow_mut(), &self.layout, *page, self.view).hash(&mut h);
|
||||
Revision::new(h.finish())
|
||||
}
|
||||
|
||||
impl WordPages {
|
||||
/// What of page `index` a picture for `request` shows and how large it is made: whether it is the whole page,
|
||||
/// the area in document points, the pixels per point, whether that is the screen's own scale, and the picture's
|
||||
/// size in pixels where it is made to fill its place exactly. `None` for a page the layout doesn't have.
|
||||
fn geometry(&self, index: usize, request: &ThumbRequest) -> Option<(bool, wordcraft_geom::Rect, f32, bool, Option<(u32, u32)>)> {
|
||||
let p = self.layout.pages.get(index)?;
|
||||
fn render(&self, page: &usize, request: &ThumbRequest) -> ThumbRender {
|
||||
let index = *page;
|
||||
let Some(p) = self.layout.pages.get(index) else { return ThumbRender::Blank };
|
||||
let (pw, ph) = (dim(p.w, 1e5) as f32, dim(p.h, 1e6) as f32);
|
||||
let whole = request.region.is_none();
|
||||
let (x0, y0, x1, y1) = match request.region {
|
||||
@@ -120,51 +84,14 @@ impl WordPages {
|
||||
let area = wordcraft_geom::Rect::new(x0 * pw, y0 * ph, ((x1 - x0) * pw).max(0.01), ((y1 - y0) * ph).max(0.01));
|
||||
let longest = area.w.max(area.h);
|
||||
let cap = wordcraft_render::MAX_SIDE as f32 / longest;
|
||||
// At the screen's own scale where the view's zoom accounts for the side asked for, so no glyph is resampled
|
||||
// on its way to the screen; else at the side asked for.
|
||||
let (scale, own) = raster_scale(request.side, SIDE_STEP, longest, self.view_scale.map(|s| s * request.pixels_per_point));
|
||||
let own = own && scale <= cap;
|
||||
let scale = request.side as f32 / longest;
|
||||
let scale = if scale.is_finite() { scale.clamp(0.01, cap.max(0.01)) } else { 1.0 };
|
||||
// Exactly as many pixels each way as the picture's place on screen has, where that is known and is this
|
||||
// scale's: a pixel more and the page view scales the picture into its place.
|
||||
let place = self.placed.iter().find(|(page, _)| *page == index).map(|(_, rect)| *rect);
|
||||
let pixels = place
|
||||
.filter(|_| own)
|
||||
.and_then(|place| picture_pixels(place, request.region, request.pixels_per_point, (area.w * scale, area.h * scale)))
|
||||
// A place can round to a pixel more than the largest texture, and a larger picture is halved.
|
||||
.filter(|(w, h)| *w.max(h) <= MAX_TEXTURE);
|
||||
Some((whole, area, scale, own, pixels))
|
||||
}
|
||||
|
||||
/// How page `index` is rasterised for `request`; `None` for a page the layout doesn't have.
|
||||
pub(super) fn plan(&self, index: usize, request: &ThumbRequest) -> Option<RasterPlan> {
|
||||
let (whole, area, scale, own, pixels) = self.geometry(index, request)?;
|
||||
let (doc, layout) = (Arc::clone(&self.doc), Arc::clone(&self.layout));
|
||||
let mut options = self.options.clone();
|
||||
options.display.hide_object = self.hidden.as_ref().filter(|(hidden, _)| *hidden == index).map(|(_, pos)| pos.clone());
|
||||
// Subpixel text only on a picture that is the screen's own: scaled, each colour's edge would miss its stripe.
|
||||
options.lcd = lcd_for(self.smoothing, self.screen_text.subpixel, self.screen_text.stripes, request.pixels_per_point).filter(|_| own);
|
||||
Some(RasterPlan { whole, area, scale, pixels, options })
|
||||
}
|
||||
}
|
||||
|
||||
impl ThumbSource<usize> for WordPages {
|
||||
fn revision(&self, page: &usize, request: &ThumbRequest) -> Revision {
|
||||
let mut h = DefaultHasher::new();
|
||||
page_shows(&mut self.keys.borrow_mut(), &self.layout, *page, self.view).hash(&mut h);
|
||||
// A picture made for another place's pixel size is not this place's.
|
||||
self.geometry(*page, request).and_then(|(.., pixels)| pixels).hash(&mut h);
|
||||
Revision::new(h.finish())
|
||||
}
|
||||
|
||||
fn render(&self, page: &usize, request: &ThumbRequest) -> ThumbRender {
|
||||
let index = *page;
|
||||
let Some(RasterPlan { whole, area, scale, pixels, options }) = self.plan(index, request) else { return ThumbRender::Blank };
|
||||
let (doc, layout) = (Arc::clone(&self.doc), Arc::clone(&self.layout));
|
||||
ThumbRender::Later(Box::new(move |_cancel| {
|
||||
let Some(page) = layout.pages.get(index) else { return Ok(LoadedPicture::Blank) };
|
||||
let img = if let Some((w, h)) = pixels {
|
||||
wordcraft_render::render_area_to(&doc, page, area, w, h, &options)
|
||||
} else if whole {
|
||||
let img = if whole {
|
||||
wordcraft_render::render_page(&doc, page, scale, &options)
|
||||
} else {
|
||||
wordcraft_render::render_area(&doc, page, area, scale, &options)
|
||||
|
||||
@@ -518,24 +518,6 @@ fn the_page_in_view_follows_the_caret_while_it_is_on_screen() {
|
||||
assert_eq!(viewed_page(caret(2, 90.0), scrolled(330.0), &layout, 100.0), 3, "a caret just above the window is not in view");
|
||||
}
|
||||
|
||||
/// Two Up centres the shorter page of a spread: the next spread's shorter first page starts lower than its row, and
|
||||
/// the gap to the page above is measured to the row's top, so a visible sliver of page 0 still counts (#7149).
|
||||
#[test]
|
||||
fn the_page_in_view_measures_to_the_next_spreads_top() {
|
||||
use craft::behavior::kurbo::Size;
|
||||
use craft::pages::layout::{LayoutOptions, PageDisplay, PageSpacing, place_pages};
|
||||
// Heights 100,100 | 100,200: the taller page of the second spread sits higher than its shorter neighbour.
|
||||
let sizes = [Size::new(80.0, 100.0), Size::new(80.0, 100.0), Size::new(80.0, 100.0), Size::new(80.0, 200.0)];
|
||||
let spacing = PageSpacing { gap: 10.0, margin: 0.0, side: 0.0, white_space_pad: 0.0, seam: 1.0 };
|
||||
let options = LayoutOptions { display: PageDisplay::TwoUp, cover: false, ..LayoutOptions::WORD };
|
||||
let layout = place_pages(&sizes, 1.0, Size::new(400.0, 400.0), &options, &spacing);
|
||||
assert!(layout.rects[2].y0 > layout.rects[3].y0, "the shorter page is centred below the row's top");
|
||||
let row_end = layout.rects[0].y1;
|
||||
let at = |shown: f64| row_end - shown;
|
||||
assert_eq!(viewed_page(None, at(spacing.gap * 2.0), &layout, 100.0), 0, "more than the gap of the first spread shows");
|
||||
assert_eq!(viewed_page(None, at(spacing.gap / 2.0), &layout, 100.0), 2, "less than the gap is a sliver");
|
||||
}
|
||||
|
||||
/// #856: the left margin beside body text is Word's selection bar. A click selects the line,
|
||||
/// a double-click the paragraph, a triple-click (or Ctrl/⌘+click) the document; dragging
|
||||
/// selects whole lines and Shift+click extends by lines.
|
||||
@@ -2291,209 +2273,6 @@ fn the_view_key_changes_when_a_drag_takes_an_object_off_the_page() {
|
||||
assert_eq!(hidden, view_key(&app, false, Some(&object)), "the same drag keeps the key: no re-render every frame");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_pages_follow_the_systems_text_settings() {
|
||||
use crate::screen_text::ScreenText;
|
||||
// Previews and thumbnails are cached without the system's settings in their keys: they are
|
||||
// drawn the platform's fixed way. Thumbnails are not baseline-snapped either.
|
||||
let (screen, thumb) = (screen_render_options(), thumbnail_render_options());
|
||||
for opts in [&screen, &thumb] {
|
||||
assert_eq!((opts.text_darkening, opts.hinting, opts.lcd), (ScreenText::PLATFORM.darkening, ScreenText::PLATFORM.hinting, None));
|
||||
}
|
||||
assert!(screen.baseline_snap && !thumb.baseline_snap);
|
||||
// A page takes the same until the app has asked the system (tests never do).
|
||||
let a = WordApp::new(wordcraft_engine::Session::new(wordcraft_doc::Document::new()), Default::default());
|
||||
let page = page_render_options(&a, false);
|
||||
assert_eq!((page.text_darkening, page.hinting, page.baseline_snap), (screen.text_darkening, screen.hinting, true));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn subpixel_text_follows_the_choice_the_system_and_the_screen() {
|
||||
use super::pages::lcd_for;
|
||||
use crate::screen_text::SubpixelOrder::{Bgr, Rgb};
|
||||
use wordcraft_engine::cmd::view::TextSmoothing::{Grayscale, Subpixel, System};
|
||||
use wordcraft_render::LcdOrder;
|
||||
// Use system setting: where the system asks for it, in its order, below 2x only.
|
||||
assert_eq!(lcd_for(System, Some(Rgb), Some(Rgb), 1.0), Some(LcdOrder::Rgb));
|
||||
assert_eq!(lcd_for(System, Some(Bgr), Some(Bgr), 1.5), Some(LcdOrder::Bgr));
|
||||
assert_eq!(lcd_for(System, Some(Rgb), Some(Rgb), 2.0), None, "a high-density screen");
|
||||
assert_eq!(lcd_for(System, Some(Rgb), Some(Rgb), f32::NAN), None);
|
||||
assert_eq!(lcd_for(System, None, None, 1.0), None, "the system asks for greyscale, or says nothing");
|
||||
assert_eq!(lcd_for(System, None, Some(Bgr), 1.0), None, "a known stripe order is not a request");
|
||||
// The user's own choice wins on any screen; RGB when the system names no order.
|
||||
assert_eq!(lcd_for(Subpixel, None, None, 2.0), Some(LcdOrder::Rgb));
|
||||
assert_eq!(lcd_for(Subpixel, Some(Bgr), Some(Bgr), 3.0), Some(LcdOrder::Bgr));
|
||||
// A BGR panel whose system has smoothing off (ClearType off on Windows, greyscale on a
|
||||
// Linux desktop) still gets BGR edges, not RGB ones.
|
||||
assert_eq!(lcd_for(Subpixel, None, Some(Bgr), 1.0), Some(LcdOrder::Bgr));
|
||||
let cleartype_off = crate::screen_text::ScreenText::from_windows(Some("0"), Some(2), Some(0));
|
||||
assert_eq!(lcd_for(Subpixel, cleartype_off.subpixel, cleartype_off.stripes, 1.0), Some(LcdOrder::Bgr));
|
||||
assert_eq!(lcd_for(System, cleartype_off.subpixel, cleartype_off.stripes, 1.0), None);
|
||||
for (asked, stripes) in [(None, None), (Some(Rgb), Some(Rgb)), (None, Some(Bgr))] {
|
||||
assert_eq!(lcd_for(Grayscale, asked, stripes, 1.0), None);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_page_picture_is_rasterised_at_the_screens_own_scale_where_the_view_accounts_for_it() {
|
||||
use super::pages::raster_scale;
|
||||
// An A4 page (841.89 pt) at 100 % on a 2x screen: 2245.04 device pixels, asked for as 2256 (the next multiple
|
||||
// of 16). At 2256 every glyph would be shrunk by half a percent on its way to the screen.
|
||||
let longest = 841.89_f32;
|
||||
let native = 96.0 / 72.0 * 2.0;
|
||||
assert_eq!(raster_scale(2256, 16, longest, Some(native)), (native, true));
|
||||
assert_eq!(raster_scale(2256, 16, longest, None), (2256.0 / longest, false), "a view with no scale of its own");
|
||||
// US Letter (792 pt) at the same zoom is 2112 pixels, a multiple of 16: the same either way.
|
||||
let (scale, own) = raster_scale(2112, 16, 792.0, Some(native));
|
||||
assert!(own && (scale - 2112.0 / 792.0).abs() < 1e-6);
|
||||
// A side the view's scale doesn't account for: another zoom's request, a side lowered to the largest texture,
|
||||
// a part of the page shown reduced. Rasterised as asked for, and not the screen's own.
|
||||
for side in [2240, 2272, 1024, 16] {
|
||||
assert_eq!(raster_scale(side, 16, longest, Some(native)), (side as f32 / longest, false), "{side}");
|
||||
}
|
||||
// Numbers that aren't: as asked for.
|
||||
for (longest, native, step) in
|
||||
[(longest, f32::NAN, 16), (longest, f32::INFINITY, 16), (longest, -1.0, 16), (longest, 0.0, 16), (longest, native, 0)]
|
||||
{
|
||||
assert!(!raster_scale(2256, step, longest, Some(native)).1, "{longest} {native} {step}");
|
||||
}
|
||||
assert!(!raster_scale(2256, 16, f32::NAN, Some(native)).1 && !raster_scale(2256, 16, 0.0, Some(native)).1);
|
||||
}
|
||||
|
||||
/// A page a fraction of a pixel longer than the largest texture is made no larger than it: a picture one pixel over
|
||||
/// is halved on upload, and the page stays blurry at rest.
|
||||
#[test]
|
||||
fn a_page_picture_never_outgrows_the_largest_texture() {
|
||||
use super::source::WordPages;
|
||||
use craft::ui::primitives::textures::{MAX_TEXTURE, ThumbRequest};
|
||||
let mut a = WordApp::new(wordcraft_engine::Session::new(wordcraft_doc::Document::new()), Default::default());
|
||||
let layout = a.session.layout();
|
||||
let (w, h) = (layout.pages[0].w, layout.pages[0].h);
|
||||
let longest = w.max(h);
|
||||
for over in [-0.6, -0.1, 0.0, 0.1, 0.3, 0.5] {
|
||||
for y in [0.0, 0.3, 0.49, 0.6] {
|
||||
let scale = (MAX_TEXTURE as f32 + over) / longest;
|
||||
a.canvas.settled_pages = vec![(0, Rect::from_min_size(egui::pos2(10.0, y), egui::vec2(w * scale, h * scale)))];
|
||||
let pages = WordPages::new(&mut a, &layout, false, None, Some(scale));
|
||||
let plan = pages.plan(0, &ThumbRequest::for_cell(longest * scale, 1.0)).unwrap();
|
||||
let side = plan.pixels.map_or((longest * plan.scale).ceil() as u32, |(w, h)| w.max(h));
|
||||
assert!(side <= MAX_TEXTURE, "{over} at {y}: {side}");
|
||||
assert!(side + 2 >= MAX_TEXTURE, "not reduced either: {over} at {y}: {side}");
|
||||
if over < -0.5 {
|
||||
assert!(plan.pixels.is_some(), "a page below the limit keeps its own pixels: {over} at {y}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_page_picture_is_made_as_many_pixels_as_its_place_on_screen() {
|
||||
use super::pages::picture_pixels;
|
||||
use egui::{pos2, vec2};
|
||||
// An A4 page at 110 % on a 2x screen, centred in a window: 1746.155 × 2469.544 pixels starting at 642.923.
|
||||
// Its place rounds to 643..2389 across and 356..2826 down.
|
||||
let page = Rect::from_min_size(pos2(321.4615, 178.0), vec2(873.0775, 1234.772));
|
||||
let expected = (1746.155, 2469.544);
|
||||
assert_eq!(picture_pixels(page, None, 2.0, expected), Some((1746, 2470)));
|
||||
// The same page half a pixel further right ends on the next pixel and starts on the same one: 1747 across.
|
||||
assert_eq!(picture_pixels(page.translate(vec2(0.25, 0.0)), None, 2.0, expected), Some((1747, 2470)));
|
||||
// The upper half of it, as the page view asks for a part: the part's own place, rounded the same way.
|
||||
let half = Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 0.5));
|
||||
assert_eq!(picture_pixels(page, Some(half), 2.0, (1746.155, 1234.772)), Some((1746, 1235)));
|
||||
// A place left from another zoom, or a part shown reduced, is not this picture's: no size.
|
||||
assert_eq!(picture_pixels(page, None, 2.0, (1587.4, 2245.0)), None);
|
||||
assert_eq!(picture_pixels(page, Some(half), 2.0, (873.0, 617.0)), None);
|
||||
// Numbers that aren't.
|
||||
for (page, ppp, expected) in [
|
||||
(Rect::from_min_size(pos2(f32::NAN, 0.0), vec2(800.0, 1100.0)), 2.0, expected),
|
||||
(Rect::from_min_size(pos2(0.0, 0.0), vec2(f32::INFINITY, 1100.0)), 2.0, expected),
|
||||
(page, f32::NAN, expected),
|
||||
(page, 0.0, expected),
|
||||
(page, 2.0, (f32::NAN, 2469.5)),
|
||||
(Rect::NOTHING, 2.0, expected),
|
||||
] {
|
||||
assert_eq!(picture_pixels(page, None, ppp, expected), None, "{page:?} {ppp} {expected:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn page_pictures_fill_the_place_the_view_last_rested_at() {
|
||||
use super::source::WordPages;
|
||||
use craft::ui::primitives::textures::{ThumbRequest, ThumbSource};
|
||||
use egui::{pos2, vec2};
|
||||
let mut a = WordApp::new(wordcraft_engine::Session::new(wordcraft_doc::Document::new()), Default::default());
|
||||
let layout = a.session.layout();
|
||||
let (pw, ph) = (layout.pages[0].w, layout.pages[0].h);
|
||||
let view_scale = 96.0 / 72.0 * 1.1;
|
||||
let request = ThumbRequest::for_cell(pw.max(ph) * view_scale, 2.0);
|
||||
// Before the view has rested anywhere: one scale, a whole pixel up each way.
|
||||
let fresh = WordPages::new(&mut a, &layout, false, None, Some(view_scale));
|
||||
let plan = fresh.plan(0, &request).unwrap();
|
||||
assert_eq!((plan.pixels, plan.scale), (None, view_scale * 2.0));
|
||||
let fresh_revision = fresh.revision(&0, &request);
|
||||
a.canvas.page_keys = fresh.into_keys();
|
||||
// At rest, a third of a pixel into a pixel: the picture is its place's size, and another picture than before.
|
||||
let place = Rect::from_min_size(pos2(321.4615, 178.0), vec2(pw * view_scale, ph * view_scale));
|
||||
a.canvas.settled_pages = vec![(0, place)];
|
||||
let rested = WordPages::new(&mut a, &layout, false, None, Some(view_scale));
|
||||
let plan = rested.plan(0, &request).unwrap();
|
||||
let (w, h) = plan.pixels.expect("a place to fill");
|
||||
assert_eq!(w as f32, (place.max.x * 2.0).round() - (place.min.x * 2.0).round());
|
||||
assert_eq!(h as f32, (place.max.y * 2.0).round() - (place.min.y * 2.0).round());
|
||||
assert_ne!(rested.revision(&0, &request), fresh_revision);
|
||||
assert!(rested.plan(1, &request).is_none_or(|plan| plan.pixels.is_none()), "a page with no place");
|
||||
a.canvas.page_keys = rested.into_keys();
|
||||
// A place from another zoom is not this zoom's; Read Mode's columns use none.
|
||||
let zoomed = WordPages::new(&mut a, &layout, false, None, Some(view_scale * 1.3));
|
||||
assert_eq!(zoomed.plan(0, &ThumbRequest::for_cell(pw.max(ph) * view_scale * 1.3, 2.0)).unwrap().pixels, None);
|
||||
a.canvas.page_keys = zoomed.into_keys();
|
||||
let reading = WordPages::new(&mut a, &layout, false, None, None);
|
||||
assert_eq!(reading.plan(0, &request).unwrap().pixels, None);
|
||||
a.canvas.page_keys = reading.into_keys();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn page_pictures_take_subpixel_text_only_at_the_screens_own_scale() {
|
||||
use super::source::WordPages;
|
||||
use craft::ui::primitives::textures::{ThumbRequest, ThumbSource};
|
||||
use wordcraft_render::LcdOrder;
|
||||
let mut a = WordApp::new(wordcraft_engine::Session::new(wordcraft_doc::Document::new()), Default::default());
|
||||
let layout = a.session.layout();
|
||||
let longest = layout.pages[0].w.max(layout.pages[0].h);
|
||||
let view_scale = 96.0 / 72.0 * 1.1;
|
||||
let request = |ppp: f32| ThumbRequest::for_cell(longest * view_scale, ppp);
|
||||
let pages = |a: &mut WordApp, scale: Option<f32>| WordPages::new(a, &layout, false, None, scale);
|
||||
// Greyscale until chosen (tests never ask the system), at the screen's own scale.
|
||||
let grey = pages(&mut a, Some(view_scale));
|
||||
let plan = grey.plan(0, &request(2.0)).unwrap();
|
||||
assert_eq!((plan.scale, plan.options.lcd), (view_scale * 2.0, None));
|
||||
assert!(plan.options.baseline_snap);
|
||||
let grey_revision = grey.revision(&0, &request(2.0));
|
||||
a.canvas.page_keys = grey.into_keys();
|
||||
// The user's choice, a command: subpixel text on the picture that is the screen's own...
|
||||
a.run("view.textSmoothing", json!({"value": "subpixel"})).unwrap();
|
||||
let sub = pages(&mut a, Some(view_scale));
|
||||
assert_eq!(sub.plan(0, &request(2.0)).unwrap().options.lcd, Some(LcdOrder::Rgb));
|
||||
assert_eq!(sub.plan(0, &request(1.0)).unwrap().options.lcd, Some(LcdOrder::Rgb));
|
||||
assert_ne!(sub.revision(&0, &request(2.0)), grey_revision, "a page drawn the other way is another picture");
|
||||
let sub_revision = sub.revision(&0, &request(2.0));
|
||||
// ...and not on one that will be scaled: a request the view's zoom doesn't account for, a part shown reduced.
|
||||
let other = ThumbRequest::for_cell(longest * view_scale * 1.3, 2.0);
|
||||
let plan = sub.plan(0, &other).unwrap();
|
||||
assert_eq!((plan.scale, plan.options.lcd), (other.side as f32 / longest, None));
|
||||
a.canvas.page_keys = sub.into_keys();
|
||||
// Read Mode's columns size their pages themselves: as asked for, greyscale.
|
||||
let reading = pages(&mut a, None);
|
||||
let plan = reading.plan(0, &request(2.0)).unwrap();
|
||||
assert_eq!((plan.scale, plan.options.lcd), (request(2.0).side as f32 / longest, None));
|
||||
a.canvas.page_keys = reading.into_keys();
|
||||
// Another zoom is another picture, even where the side asked for is the same.
|
||||
let nudged = pages(&mut a, Some(view_scale * 1.0005));
|
||||
assert_eq!(ThumbRequest::for_cell(longest * view_scale * 1.0005, 2.0).side, request(2.0).side);
|
||||
assert_ne!(nudged.revision(&0, &request(2.0)), sub_revision);
|
||||
assert!(nudged.plan(99, &request(2.0)).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn screen_paper_color_changes_raster_and_cache_without_changing_export_paper() {
|
||||
use wordcraft_doc::props::Rgb;
|
||||
@@ -2825,72 +2604,6 @@ fn hostile_numbers_are_ignored() {
|
||||
assert!(h.state().canvas.view.offset.0.is_finite() && h.state().canvas.view.offset.1.is_finite());
|
||||
}
|
||||
|
||||
/// `viewed_page` with the sliver of the page above that Go To leaves at the top of the window: it is not the page in view.
|
||||
#[test]
|
||||
fn a_sliver_of_the_page_above_is_not_the_page_in_view() {
|
||||
let rects: Vec<craft::behavior::kurbo::Rect> =
|
||||
(0..4).map(|i| craft::behavior::kurbo::Rect::new(0.0, f64::from(i) * 110.0, 80.0, f64::from(i) * 110.0 + 100.0)).collect();
|
||||
let layout = craft::pages::layout::PagedLayout { rects, size: Default::default(), columns: 1, bands: vec![(0.0, 100.0); 4] };
|
||||
// The gap between pages is 10; page 2 ends at 320. A window top 4 above its end shows 4 of it: a sliver.
|
||||
assert_eq!(viewed_page(None, 316.0, &layout, 100.0), 3, "4 points of page 2 is a sliver");
|
||||
assert_eq!(viewed_page(None, 310.0, &layout, 100.0), 3, "as much as the gap is still a sliver");
|
||||
assert_eq!(viewed_page(None, 300.0, &layout, 100.0), 2, "20 points of page 2 is the page in view");
|
||||
}
|
||||
|
||||
/// In Columns and Two Up the pages are stored row by row: the gap to measure is the one to the page below, not to the
|
||||
/// page beside.
|
||||
#[test]
|
||||
fn a_sliver_of_a_row_above_is_not_the_page_in_view_with_columns() {
|
||||
let rects: Vec<craft::behavior::kurbo::Rect> = [(0.0, 0.0), (90.0, 0.0), (0.0, 110.0), (90.0, 110.0)]
|
||||
.iter()
|
||||
.map(|&(x, y)| craft::behavior::kurbo::Rect::new(x, y, x + 80.0, y + 100.0))
|
||||
.collect();
|
||||
let layout = craft::pages::layout::PagedLayout { rects, size: Default::default(), columns: 2, bands: vec![(0.0, 100.0); 4] };
|
||||
// The first row ends at 100 and the next starts at 110: a window top at 96 shows 4 points of it, a sliver.
|
||||
assert_eq!(viewed_page(None, 96.0, &layout, 100.0), 2, "4 points of the row above is a sliver");
|
||||
assert_eq!(viewed_page(None, 80.0, &layout, 100.0), 0, "20 points of the first row is the page in view");
|
||||
}
|
||||
|
||||
/// A last row that is not full has no page below the one above it: the gap is still the one to the next row.
|
||||
#[test]
|
||||
fn a_sliver_of_a_row_above_is_not_the_page_in_view_with_an_incomplete_last_row() {
|
||||
let rects: Vec<craft::behavior::kurbo::Rect> =
|
||||
[(0.0, 0.0), (90.0, 0.0), (0.0, 110.0)].iter().map(|&(x, y)| craft::behavior::kurbo::Rect::new(x, y, x + 80.0, y + 100.0)).collect();
|
||||
let layout = craft::pages::layout::PagedLayout { rects, size: Default::default(), columns: 2, bands: vec![(0.0, 100.0); 3] };
|
||||
assert_eq!(viewed_page(None, 96.0, &layout, 100.0), 2, "4 points of the row above is a sliver");
|
||||
assert_eq!(viewed_page(None, 80.0, &layout, 100.0), 0, "20 points of the first row is the page in view");
|
||||
}
|
||||
|
||||
/// Pages of different heights share a row and the next row starts below the tallest: the gap is measured from the row's bottom.
|
||||
#[test]
|
||||
fn a_shorter_page_in_a_taller_row_is_still_the_page_in_view() {
|
||||
let rects: Vec<craft::behavior::kurbo::Rect> = [(0.0, 0.0, 100.0), (90.0, 0.0, 200.0), (0.0, 210.0, 100.0), (90.0, 210.0, 100.0)]
|
||||
.iter()
|
||||
.map(|&(x, y, h)| craft::behavior::kurbo::Rect::new(x, y, x + 80.0, y + h))
|
||||
.collect();
|
||||
let layout = craft::pages::layout::PagedLayout {
|
||||
rects,
|
||||
size: Default::default(),
|
||||
columns: 2,
|
||||
bands: vec![(0.0, 100.0), (0.0, 200.0), (0.0, 100.0), (0.0, 100.0)],
|
||||
};
|
||||
assert_eq!(viewed_page(None, 50.0, &layout, 100.0), 0, "the short page is fully visible, the row gap is 10 not 110");
|
||||
assert_eq!(viewed_page(None, 196.0, &layout, 100.0), 2, "4 points of the tall page's row is a sliver");
|
||||
}
|
||||
|
||||
/// Two Up with a cover: page 0 is a row of its own, so there is no page `columns` after it.
|
||||
#[test]
|
||||
fn a_sliver_of_the_cover_is_not_the_page_in_view() {
|
||||
let rects: Vec<craft::behavior::kurbo::Rect> = [(90.0, 0.0), (0.0, 110.0), (90.0, 110.0), (0.0, 220.0)]
|
||||
.iter()
|
||||
.map(|&(x, y)| craft::behavior::kurbo::Rect::new(x, y, x + 80.0, y + 100.0))
|
||||
.collect();
|
||||
let layout = craft::pages::layout::PagedLayout { rects, size: Default::default(), columns: 2, bands: vec![(0.0, 100.0); 4] };
|
||||
assert_eq!(viewed_page(None, 96.0, &layout, 100.0), 1, "4 points of the cover is a sliver");
|
||||
assert_eq!(viewed_page(None, 80.0, &layout, 100.0), 0, "20 points of the cover is the page in view");
|
||||
assert_eq!(viewed_page(None, 206.0, &layout, 100.0), 3, "4 points of the spread is a sliver");
|
||||
}
|
||||
|
||||
/// A window in the background shows no caret and asks for no frames to blink one (#7674). The page keeps the keyboard
|
||||
/// focus, so the caret blinks again once the window is active again.
|
||||
#[test]
|
||||
@@ -2955,18 +2668,18 @@ fn the_caret_blinks_only_while_the_window_is_active() {
|
||||
fn word_pages_reuses_doc_snapshot_across_unchanged_frames_and_invalidates_on_edit() {
|
||||
let mut app = WordApp::new(wordcraft_engine::Session::new(wordcraft_doc::Document::from_text("hello")), Default::default());
|
||||
let layout = app.session.layout();
|
||||
let first = super::source::WordPages::new(&mut app, &layout, false, None, None);
|
||||
let first = super::source::WordPages::new(&mut app, &layout, false, None);
|
||||
let doc1 = first.doc();
|
||||
app.canvas.page_keys = first.into_keys();
|
||||
|
||||
let second = super::source::WordPages::new(&mut app, &layout, false, None, None);
|
||||
let second = super::source::WordPages::new(&mut app, &layout, false, None);
|
||||
let doc2 = second.doc();
|
||||
app.canvas.page_keys = second.into_keys();
|
||||
assert!(std::sync::Arc::ptr_eq(&doc1, &doc2), "unchanged frame reuses cached Arc<Document> snapshot");
|
||||
|
||||
app.run("text.insert", json!({"text": " world"})).unwrap();
|
||||
let layout2 = app.session.layout();
|
||||
let third = super::source::WordPages::new(&mut app, &layout2, false, None, None);
|
||||
let third = super::source::WordPages::new(&mut app, &layout2, false, None);
|
||||
let doc3 = third.doc();
|
||||
app.canvas.page_keys = third.into_keys();
|
||||
assert!(!std::sync::Arc::ptr_eq(&doc1, &doc3), "editing document invalidates cached snapshot");
|
||||
@@ -3084,97 +2797,3 @@ fn shift_clicking_a_picture_does_not_scroll_the_view() {
|
||||
assert!(picked.contains(&first) && picked.contains(&second), "both pictures are selected: {picked:?} {:?} at {at:?}", h.state().session.sel);
|
||||
assert_eq!(h.state().canvas.view.offset, before, "the view stayed where it was");
|
||||
}
|
||||
|
||||
/// The pictures drawn in the last pass that are at least 300 texels wide (a page's, not an icon's or the font
|
||||
/// atlas's glyphs): how many device pixels each is drawn across and down, and how many texels it shows.
|
||||
fn drawn_pictures(
|
||||
shapes: &[egui::epaint::ClippedShape],
|
||||
sizes: &std::collections::HashMap<egui::TextureId, [usize; 2]>,
|
||||
ppp: f32,
|
||||
) -> Vec<([f32; 2], [f32; 2])> {
|
||||
fn walk(shape: &egui::Shape, found: &mut Vec<(egui::TextureId, Rect, Rect)>) {
|
||||
match shape {
|
||||
egui::Shape::Vec(shapes) => shapes.iter().for_each(|s| walk(s, found)),
|
||||
egui::Shape::Mesh(mesh) if mesh.texture_id != egui::TextureId::default() => {
|
||||
let (mut at, mut uv) = (Rect::NOTHING, Rect::NOTHING);
|
||||
for v in &mesh.vertices {
|
||||
at.extend_with(v.pos);
|
||||
uv.extend_with(v.uv);
|
||||
}
|
||||
found.push((mesh.texture_id, at, uv));
|
||||
}
|
||||
egui::Shape::Rect(rect) => {
|
||||
if let Some(brush) = &rect.brush
|
||||
&& brush.fill_texture_id != egui::TextureId::default()
|
||||
{
|
||||
found.push((brush.fill_texture_id, rect.rect, brush.uv));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let mut found = Vec::new();
|
||||
shapes.iter().for_each(|clipped| walk(&clipped.shape, &mut found));
|
||||
found
|
||||
.into_iter()
|
||||
.filter_map(|(id, at, uv)| {
|
||||
let size = sizes.get(&id).filter(|size| size[0] >= 300)?;
|
||||
let texels = [uv.width() * size[0] as f32, uv.height() * size[1] as f32];
|
||||
(texels[0] >= 300.0).then_some(([at.width() * ppp, at.height() * ppp], texels))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The page view scales a picture into its place, so a page's picture has to be exactly as many pixels each way
|
||||
/// as that place: a pixel more (what one scale and rounding up give) squeezes it by a twentieth of a percent and
|
||||
/// the text slides off the pixel grid and back down the page, which reads as blur. Run through the real page view
|
||||
/// and its picture store, at several zooms and screen densities, on the passes a renderer would draw.
|
||||
#[test]
|
||||
fn a_page_at_rest_is_drawn_one_texel_per_device_pixel() {
|
||||
for ppp in [1.0_f32, 2.0] {
|
||||
let ctx = crate::test_harness::context();
|
||||
crate::test_harness::cjk_stand_in(&ctx);
|
||||
ctx.set_pixels_per_point(ppp);
|
||||
let mut app = WordApp::new(wordcraft_engine::Session::new(wordcraft_doc::Document::new()), Default::default());
|
||||
app.run("document.setText", json!({"text": "The quick brown fox jumps over the lazy dog."})).unwrap();
|
||||
app.run("layout.size", json!({"name": "A4"})).unwrap();
|
||||
let mut sizes = std::collections::HashMap::new();
|
||||
for (step, zoom) in [100, 110, 137].into_iter().enumerate() {
|
||||
app.run("view.zoom", json!({"value": zoom})).unwrap();
|
||||
// Until the view has come to rest and the worker has made the picture for where it rests.
|
||||
let mut seen = Vec::new();
|
||||
let exact = |pictures: &[([f32; 2], [f32; 2])]| {
|
||||
!pictures.is_empty()
|
||||
&& pictures.iter().all(|(drawn, texels)| (drawn[0] - texels[0]).abs() < 0.01 && (drawn[1] - texels[1]).abs() < 0.01)
|
||||
};
|
||||
for frame in 0..600 {
|
||||
let mut input = egui::RawInput {
|
||||
screen_rect: Some(Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1500.0, 950.0))),
|
||||
time: Some(step as f64 * 100.0 + frame as f64 * 0.05),
|
||||
max_texture_side: Some(8192),
|
||||
..Default::default()
|
||||
};
|
||||
if let Some(viewport) = input.viewports.get_mut(&egui::ViewportId::ROOT) {
|
||||
viewport.native_pixels_per_point = Some(ppp);
|
||||
}
|
||||
craft::ui::shell::embed::before_input(&ctx, |out| app.frame_input(out));
|
||||
let mut out = ctx.run_ui(input, |ui| {
|
||||
crate::test_harness::logic(ui.ctx(), &mut app);
|
||||
app.ui(ui);
|
||||
});
|
||||
for (id, deltas) in &out.textures_delta.set {
|
||||
for delta in deltas.iter().filter(|delta| delta.pos.is_none()) {
|
||||
sizes.insert(*id, delta.image.size());
|
||||
}
|
||||
}
|
||||
seen = drawn_pictures(&out.shapes, &sizes, ppp);
|
||||
out.textures_delta.clear();
|
||||
if frame > 3 && exact(&seen) {
|
||||
break;
|
||||
}
|
||||
std::thread::sleep(std::time::Duration::from_millis(10));
|
||||
}
|
||||
assert!(exact(&seen), "{zoom} % at {ppp}x: (pixels drawn, texels shown) {seen:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,11 +51,8 @@ pub(crate) fn help_entries(app: &WordApp) -> Vec<HelpEntry> {
|
||||
.iter()
|
||||
.filter(|c| !crate::dialogs::NOT_IN_SEARCH.contains(&c.id))
|
||||
.map(|c| {
|
||||
let command = if c.id == "view.paperColor" || c.id == "view.textSmoothing" {
|
||||
CommandRef::with_params("file.options", json!({"pane": "general"}))
|
||||
} else {
|
||||
CommandRef::new(c.id)
|
||||
};
|
||||
let command =
|
||||
if c.id == "view.paperColor" { CommandRef::with_params("file.options", json!({"pane": "general"})) } else { CommandRef::new(c.id) };
|
||||
let entry = HelpEntry::new(command, tl!(c.label).to_string()).with_english(c.label.to_string());
|
||||
match crate::app::command_board::location_path(c.location) {
|
||||
Some(path) => entry.with_path(path.into_iter().map(|part| tl!(part).to_string())),
|
||||
|
||||
@@ -76,43 +76,16 @@ fn new_app() -> WordApp {
|
||||
WordApp::new(wordcraft_engine::Session::new(wordcraft_doc::Document::new()), crate::Services::default())
|
||||
}
|
||||
|
||||
/// How [`autosave_harness`] has the saved file in its window.
|
||||
#[derive(Debug, PartialEq)]
|
||||
enum Reopen {
|
||||
/// The window that saved it.
|
||||
No,
|
||||
/// Opened in a fresh window, read from disk.
|
||||
FromDisk,
|
||||
/// Opened in a fresh window from its bytes, which only names the file.
|
||||
FromBytes,
|
||||
}
|
||||
|
||||
/// A saved .docx (so AutoSave can cover it), or the same file opened in a fresh window as
|
||||
/// `reopen` says, with the title bar drawn over it. `files` answers a later Save As pick.
|
||||
fn autosave_harness(
|
||||
reopen: Reopen,
|
||||
files: &std::sync::Arc<craft::host::ScriptedFiles>,
|
||||
) -> (egui_kittest::Harness<'static, WordApp>, std::path::PathBuf) {
|
||||
let dir = std::env::temp_dir().join(format!("wordcraft-ui-autosave-label-{}-{reopen:?}", std::process::id()));
|
||||
/// A saved .docx (so AutoSave can cover it) in the harness.
|
||||
fn autosave_harness() -> (egui_kittest::Harness<'static, WordApp>, std::path::PathBuf) {
|
||||
let dir = std::env::temp_dir().join(format!("wordcraft-ui-autosave-label-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let path = dir.join("draft.docx");
|
||||
let mut a = WordApp::new(wordcraft_engine::Session::new(wordcraft_doc::Document::new()), crate::Services::default())
|
||||
.with_host(std::sync::Arc::new(craft::host::Host::builder(crate::APP).files(files.clone()).build()));
|
||||
let mut a = new_app();
|
||||
a.run("text.insert", json!({"text": "Hello"})).unwrap();
|
||||
a.run("file.save", json!({"path": path.to_string_lossy()})).unwrap();
|
||||
assert!(a.autosaves(), "a saved .docx is covered by AutoSave");
|
||||
if reopen != Reopen::No {
|
||||
a = WordApp::new(wordcraft_engine::Session::new(wordcraft_doc::Document::new()), crate::Services::default())
|
||||
.with_host(std::sync::Arc::new(craft::host::Host::builder(crate::APP).files(files.clone()).build()));
|
||||
if reopen == Reopen::FromBytes {
|
||||
let data = wordcraft_engine::cmd::insert::base64_encode(&std::fs::read(&path).unwrap());
|
||||
a.execute("file.open", json!({"path": path.to_string_lossy(), "data": data})).unwrap();
|
||||
} else {
|
||||
a.run("file.open", json!({"path": path.to_string_lossy()})).unwrap();
|
||||
}
|
||||
assert!(!a.autosaves(), "an opened file waits for the user's go-ahead");
|
||||
}
|
||||
let h = harness(a);
|
||||
(h, dir)
|
||||
}
|
||||
@@ -120,8 +93,7 @@ fn autosave_harness(
|
||||
/// #3370: clicking the AutoSave switch label toggles AutoSave on and off.
|
||||
#[test]
|
||||
fn clicking_the_autosave_label_toggles_autosave() {
|
||||
let files = std::sync::Arc::new(craft::host::ScriptedFiles::new());
|
||||
let (mut h, dir) = autosave_harness(Reopen::No, &files);
|
||||
let (mut h, dir) = autosave_harness();
|
||||
assert!(h.state().autosaves());
|
||||
h.get_by_label("AutoSave").click();
|
||||
crate::test_harness::frames(&mut h, 2);
|
||||
@@ -132,35 +104,6 @@ fn clicking_the_autosave_label_toggles_autosave() {
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// #3307: a file opened, not saved, in this window had the switch greyed out, and clicking it
|
||||
/// asked for Save As. Clicking it now turns AutoSave on for that file.
|
||||
#[test]
|
||||
fn clicking_autosave_on_an_opened_file_turns_it_on() {
|
||||
let files = std::sync::Arc::new(craft::host::ScriptedFiles::new());
|
||||
let (mut h, dir) = autosave_harness(Reopen::FromDisk, &files);
|
||||
h.get_by_label("AutoSave").click();
|
||||
crate::test_harness::frames(&mut h, 2);
|
||||
assert!(h.state().autosaves(), "the switch turned AutoSave on");
|
||||
assert!(h.state().dialog_host.is_empty() && h.state().file_dialog.is_none(), "without Save As");
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// A document opened from bytes only names its file, so the switch can't hand that file to
|
||||
/// AutoSave: it shows the block and clicking it asks for Save As, after which AutoSave is on.
|
||||
#[test]
|
||||
fn clicking_autosave_on_a_document_opened_from_bytes_asks_for_save_as() {
|
||||
let files = std::sync::Arc::new(craft::host::ScriptedFiles::new());
|
||||
let (mut h, dir) = autosave_harness(Reopen::FromBytes, &files);
|
||||
assert_eq!(h.state().autosave_switch_block(), Some(crate::AutoSaveBlock::NotSavedHere));
|
||||
let copy = dir.join("copy.docx");
|
||||
files.queue(craft::host::Picked::Paths(vec![copy.clone()]));
|
||||
h.get_by_label("AutoSave").click();
|
||||
crate::test_harness::frames(&mut h, 2);
|
||||
assert!(copy.is_file(), "Save As saved a copy");
|
||||
assert!(h.state().autosaves(), "AutoSave covers the copy");
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// #701: the arrow beside Undo lists the session's undo steps, newest first; clicking the third
|
||||
/// row undoes three steps at once.
|
||||
#[test]
|
||||
@@ -801,11 +744,8 @@ fn the_autosave_knob_sits_right_when_on_and_mirrors_right_to_left() {
|
||||
a.ui.language = "en".into();
|
||||
// Mark the document as saved here without touching disk (`session.dirty` stays false).
|
||||
let path = std::path::PathBuf::from("draft.docx");
|
||||
// A save to the document's own file records both (`note_file_on_disk`): the file is read
|
||||
// from disk, so the switch can be turned on again after it has been turned off.
|
||||
a.session.path = Some(path.clone());
|
||||
a.autosave_path = Some(path.clone());
|
||||
a.read_from = Some(path);
|
||||
a.autosave_path = Some(path);
|
||||
|
||||
let mut h = harness(a);
|
||||
// Arabic UI labels draw even when built without `CRAFT_FONTS_DIR` (embedded Arabic faces).
|
||||
|
||||
@@ -104,8 +104,7 @@ fn leading(app: &mut WordApp, ui: &mut Ui) -> Option<egui::Rect> {
|
||||
/// The AutoSave switch: off and with the reason as its tooltip when AutoSave can't cover the document (#196,
|
||||
/// #176); a click then offers Save As where that helps. Returns the rect it took.
|
||||
fn autosave(app: &mut WordApp, ui: &mut Ui) -> egui::Rect {
|
||||
// A file read from disk here is off, not blocked: the switch turns it on (#3307).
|
||||
let block = app.autosave_switch_block();
|
||||
let block = app.autosave_block();
|
||||
let on = app.autosaves() && block.is_none();
|
||||
let tip = block.as_ref().map_or_else(|| tl!("AutoSave saves every change to the file (needs a saved document)").to_string(), |b| b.reason());
|
||||
// The small switch, as the old title bar drew it.
|
||||
|
||||
@@ -248,7 +248,20 @@ fn library_method(app: &mut WordApp, ctx: &egui::Context, req: &ControlRequest)
|
||||
return Some(Reply::from_result(r));
|
||||
}
|
||||
let host = WindowHost::of(ctx);
|
||||
let viewport = app.active_viewport();
|
||||
let viewport = match app.control_viewport() {
|
||||
Ok(viewport) => viewport,
|
||||
// Caps Lock is runtime-wide. Leave non-input methods to the rest of the dispatcher.
|
||||
Err(_) if req.method == "ui.capsLock" => egui::ViewportId::ROOT,
|
||||
Err(e)
|
||||
if matches!(
|
||||
req.method.as_str(),
|
||||
"ui.click" | "ui.focus" | "ui.drop" | "ui.move" | "ui.drag" | "ui.wheel" | "ui.key" | "ui.release" | "ui.type" | "ui.ime"
|
||||
) =>
|
||||
{
|
||||
return Some(err(e));
|
||||
}
|
||||
Err(_) => return None,
|
||||
};
|
||||
let canvas = &app.canvas;
|
||||
let map = |page: usize, p: egui::Pos2| page_point_on_screen(canvas, page, p);
|
||||
match input_method(&req.method, &req.params, &host, viewport, &map)? {
|
||||
@@ -260,6 +273,10 @@ fn library_method(app: &mut WordApp, ctx: &egui::Context, req: &ControlRequest)
|
||||
/// `ui.clickText {page, x, y, ..}`: a click at a point of a page, as the library's `ui.click`
|
||||
/// would deliver it at the screen point the page point is shown at.
|
||||
fn click_text(app: &mut WordApp, ctx: &egui::Context, p: &Value) -> Reply {
|
||||
let viewport = match app.control_viewport() {
|
||||
Ok(viewport) => viewport,
|
||||
Err(e) => return err(e),
|
||||
};
|
||||
let page = p.get("page").and_then(Value::as_u64).map_or(0, |v| usize::try_from(v).unwrap_or(usize::MAX));
|
||||
let num = |k: &str| p.get(k).and_then(Value::as_f64).map(|v| v as f32);
|
||||
let (Some(x), Some(y)) = (num("x"), num("y")) else { return err("missing x/y") };
|
||||
@@ -270,7 +287,7 @@ fn click_text(app: &mut WordApp, ctx: &egui::Context, p: &Value) -> Reply {
|
||||
click.insert("x".into(), json!(pos.x));
|
||||
click.insert("y".into(), json!(pos.y));
|
||||
click.insert("coordinates".into(), json!("screen"));
|
||||
match input_method("ui.click", &Value::Object(click), &WindowHost::of(ctx), app.active_viewport(), &|_: usize, _: egui::Pos2| None) {
|
||||
match input_method("ui.click", &Value::Object(click), &WindowHost::of(ctx), viewport, &|_: usize, _: egui::Pos2| None) {
|
||||
Some(Ok(())) => ok(json!({"screen": [pos.x, pos.y]})),
|
||||
Some(Err(e)) => err(e),
|
||||
None => err("ui.click is not available"),
|
||||
@@ -286,7 +303,11 @@ fn resize(app: &mut WordApp, ctx: &egui::Context, p: &Value) -> Reply {
|
||||
let Some(size) = crate::window_geometry::requested_size(egui::vec2(w, h), max_side) else {
|
||||
return err("width and height must be positive numbers no larger than 3.4e38");
|
||||
};
|
||||
WindowHost::of(ctx).act(app.active_viewport(), WindowAction::SetInnerSize(size));
|
||||
let viewport = match app.control_viewport() {
|
||||
Ok(viewport) => viewport,
|
||||
Err(e) => return err(e),
|
||||
};
|
||||
WindowHost::of(ctx).act(viewport, WindowAction::SetInnerSize(size));
|
||||
ok(json!({"width": size.x, "height": size.y}))
|
||||
}
|
||||
|
||||
@@ -377,10 +398,10 @@ fn handle_request(app: &mut WordApp, ctx: &egui::Context, req: &ControlRequest)
|
||||
"ui.parity" => ok(wordcraft_engine::catalog::parity(&app.session.registry)),
|
||||
"ui.clickText" => click_text(app, ctx, p),
|
||||
"ui.screenshot" => match craft::automation::screenshot::ScreenshotParams::from_params(p) {
|
||||
Ok(params) => {
|
||||
let token = app.next_capture_token();
|
||||
Reply::screenshot(token, params, app.active_viewport())
|
||||
}
|
||||
Ok(params) => match app.control_viewport() {
|
||||
Ok(viewport) => Reply::screenshot(app.next_capture_token(), params, viewport),
|
||||
Err(e) => err(e),
|
||||
},
|
||||
Err(e) => err(e),
|
||||
},
|
||||
"ui.render" => {
|
||||
@@ -401,12 +422,19 @@ fn handle_request(app: &mut WordApp, ctx: &egui::Context, req: &ControlRequest)
|
||||
}
|
||||
"ui.resize" => resize(app, ctx, p),
|
||||
"ui.focus" => {
|
||||
WindowHost::of(ctx).act(app.active_viewport(), WindowAction::Focus);
|
||||
let viewport = match app.control_viewport() {
|
||||
Ok(viewport) => viewport,
|
||||
Err(e) => return err(e),
|
||||
};
|
||||
WindowHost::of(ctx).act(viewport, WindowAction::Focus);
|
||||
app.canvas.focus_page(ctx);
|
||||
ok(json!({}))
|
||||
}
|
||||
// Close the active window through the same guard as its OS close button.
|
||||
"ui.closeWindow" => ok(json!({"requested": WindowHost::of(ctx).act(app.active_viewport(), WindowAction::Close)})),
|
||||
"ui.closeWindow" => match app.control_viewport() {
|
||||
Ok(viewport) => ok(json!({"requested": WindowHost::of(ctx).act(viewport, WindowAction::Close)})),
|
||||
Err(e) => err(e),
|
||||
},
|
||||
"ui.clipboard" => clipboard(ctx, p),
|
||||
"ui.replayAt" => {
|
||||
let Some(at) = p.get("at").and_then(Value::as_f64) else { return err("missing `at`") };
|
||||
|
||||
@@ -20,8 +20,6 @@ use crate::{WordApp, panes};
|
||||
pub(crate) struct Parked {
|
||||
/// [`WordApp`]'s `autosave_path`: the file AutoSave writes this document to.
|
||||
autosave_path: Option<std::path::PathBuf>,
|
||||
/// [`WordApp`]'s `read_from`: the file on disk this document was read from or saved to.
|
||||
read_from: Option<std::path::PathBuf>,
|
||||
/// The comment panel's selection and the comment and reply text typed in this document and not
|
||||
/// yet written to it.
|
||||
comments: craft::review::ui::CommentsPanelState,
|
||||
@@ -104,11 +102,7 @@ impl WordApp {
|
||||
if from == to {
|
||||
return false;
|
||||
}
|
||||
let leaving = Parked {
|
||||
autosave_path: self.autosave_path.take(),
|
||||
read_from: self.read_from.take(),
|
||||
comments: std::mem::take(&mut self.canvas.comments),
|
||||
};
|
||||
let leaving = Parked { autosave_path: self.autosave_path.take(), comments: std::mem::take(&mut self.canvas.comments) };
|
||||
if self.session.is_open(from) {
|
||||
self.parked.insert(from, leaving);
|
||||
}
|
||||
@@ -116,7 +110,6 @@ impl WordApp {
|
||||
let seen = back.is_some();
|
||||
let back = back.unwrap_or_default();
|
||||
self.autosave_path = back.autosave_path;
|
||||
self.read_from = back.read_from;
|
||||
self.canvas.comments = back.comments;
|
||||
let session = &self.session;
|
||||
self.parked.retain(|d, _| session.is_open(*d));
|
||||
@@ -213,6 +206,12 @@ impl WordApp {
|
||||
/// turn and asks Save / Don't Save / Cancel about it. A guard already running keeps its open
|
||||
/// prompt. With none left, the app quits.
|
||||
pub(crate) fn ask_before_quit(&mut self) -> Value {
|
||||
// Every way to quit comes here (the updater too): while a system file dialog may still use
|
||||
// a window, no prompt starts; the quit goes on by itself once the dialogs have ended.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if self.defer_quit_for_native_panels() {
|
||||
return json!({"quit": false, "deferred": true});
|
||||
}
|
||||
let documents = self.unsaved_documents();
|
||||
if documents.is_empty() {
|
||||
self.quit_requested = true;
|
||||
@@ -221,6 +220,9 @@ impl WordApp {
|
||||
if self.closing.is_some() {
|
||||
return json!({"quit": false});
|
||||
}
|
||||
if let Some(error) = self.rejected_draft_blocks_quit() {
|
||||
return json!({"quit": false, "error": error});
|
||||
}
|
||||
self.ui.backstage = false;
|
||||
match self.begin_closing(craft::quit::CloseScope::Quit, documents, "file.close".into(), json!({"quit": true})) {
|
||||
Ok(_) => json!({"quit": self.quit_requested}),
|
||||
|
||||
@@ -9,12 +9,38 @@
|
||||
//! When no system dialog can open (a Linux desktop with neither a file chooser portal nor
|
||||
//! zenity, #576) the service opens the framework's fallback chooser itself; the app only asks
|
||||
//! for it by name with [`PickRequest::fallback`].
|
||||
//!
|
||||
//! The windowless trial binds each pick to the window that asked and the document it showed
|
||||
//! ([`WordApp::pump_owned_picks`]). Each pick gets a private file service, so its panel never joins
|
||||
//! another window's queue. The system dialog launches only with that window's own live native
|
||||
//! window as its parent (the same panels: AppKit's Save sheet with its Format menu, rfd, or the
|
||||
//! desktop portal, which on native Wayland is still asked without a parent as before). Its
|
||||
//! answer settles in that window. The in-app chooser is used when asked for (`ui.fileBrowser`,
|
||||
//! `WORDCRAFT_FILE_DIALOG=builtin`), when the system dialog answers that it can't show, or when
|
||||
//! the desktop can't find the window's native window. A pick whose window closes, is rejected
|
||||
//! or changes is cancelled, and nothing else; a system dialog it already launched is never
|
||||
//! cancelled (nothing confirms it stopped using its parent): it finishes, its answer is dropped,
|
||||
//! and its parent window is kept alive until then. Close and quit wait for such dialogs.
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use craft::dialogs::{
|
||||
service::{FilePanels, FileService},
|
||||
ui::FileChooser,
|
||||
};
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use craft::host::{Files, Wake};
|
||||
use craft::host::{PickId, PickRequest, Picked};
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use craft::ui::dialog::{DialogHost, StackDialog, StandardPrompt};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::WordApp;
|
||||
|
||||
/// The SDK `PathRow`'s own picks in the windowless trial: the frame host's file service binds them to the drawn window
|
||||
/// and hands them to the owned route below ([`path_rows`]).
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) mod path_rows;
|
||||
|
||||
/// Most font files one Add Font pick tries; the rest of a bigger selection is skipped.
|
||||
const MAX_FONTS_PER_PICK: usize = 2000;
|
||||
|
||||
@@ -74,6 +100,10 @@ pub(crate) enum AfterPick {
|
||||
/// document through Manage Sources (#2640).
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
Sources,
|
||||
/// Windowless trial: hand the answer back to the `PathRow` that filed ticket `id` from that dialog opening
|
||||
/// ([`path_rows`]); the row writes it into its own form field.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
Row(path_rows::RowTarget),
|
||||
}
|
||||
|
||||
/// What to do once Save As has written the document.
|
||||
@@ -92,6 +122,201 @@ pub(crate) struct PendingDialog {
|
||||
after: AfterPick,
|
||||
}
|
||||
|
||||
/// How many distinct passes an attached owner may have no live native window before its pick
|
||||
/// falls back to the in-app chooser, and how often those passes are scheduled.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
const MISSING_PASSES: u32 = 5;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
const MISSING_RETRY: std::time::Duration = std::time::Duration::from_millis(100);
|
||||
/// Most system file dialogs that may use a window's handles at once: launched and not answered,
|
||||
/// plus cancelled ones not yet settled. A native pick beyond it waits, holding nothing.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
const MAX_NATIVE_OPERATIONS: usize = 2;
|
||||
|
||||
/// The desktop's read-only view of its native windows: the incarnation of the live native window a
|
||||
/// document viewport has now, `None` while it has none (not attached yet, or gone). A window
|
||||
/// recreated under the same viewport has a new incarnation. Injected with
|
||||
/// [`WordApp::set_native_window_lookup`]; without one, picks use the in-app chooser and say why.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub trait NativeWindowLookup {
|
||||
fn incarnation(&self, viewport: egui::ViewportId) -> Option<std::num::NonZeroU64>;
|
||||
}
|
||||
|
||||
/// The desktop's panel pumps for owned picks. The window is borrowed or leased only through these
|
||||
/// calls; nothing here keeps a window or a raw handle.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub trait OwnerPanels {
|
||||
/// Pump `panels` with exactly that window (`viewport` at `incarnation`) as the parent, and
|
||||
/// return what keeps that window alive while the launched panel may still use its handles.
|
||||
/// `None`, without pumping, when that window is no longer live.
|
||||
fn pump_parented(
|
||||
&mut self,
|
||||
viewport: egui::ViewportId,
|
||||
incarnation: std::num::NonZeroU64,
|
||||
panels: &mut FilePanels,
|
||||
host: &mut DialogHost,
|
||||
) -> Option<ParentLease>;
|
||||
/// Pump `panels` without a parent. The router calls it only when nothing can show natively:
|
||||
/// the pick asked for the in-app chooser, or its one native panel already launched (later
|
||||
/// pumps collect its answer, also for a cancelled pick whose dialog is left to finish).
|
||||
fn pump_unparented(&mut self, panels: &mut FilePanels, host: &mut DialogHost);
|
||||
}
|
||||
|
||||
/// What the desktop hands back for a native panel it launched on a window: it keeps that window
|
||||
/// alive (on the desktop, a strong reference to it) because the platform's dialog backend may use
|
||||
/// the parent's handles after the launching call returns, until the panel answers. The router
|
||||
/// holds it with the ticket and drops it, on the loop's thread, only once the panel has answered,
|
||||
/// or, for a cancelled pick, once its dialog (left to finish) has answered. Opaque here.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub struct ParentLease {
|
||||
_keep: Box<dyn std::any::Any + Send>,
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
impl ParentLease {
|
||||
/// A lease over `keep`, dropped with the lease.
|
||||
pub fn new(keep: impl std::any::Any + Send) -> Self {
|
||||
Self { _keep: Box::new(keep) }
|
||||
}
|
||||
}
|
||||
|
||||
/// A desktop that only pumps without a parent: an intermediate stage and a test adapter.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
struct NoWindowLookup<F>(F);
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
impl<F: FnMut(&mut FilePanels, &mut DialogHost)> OwnerPanels for NoWindowLookup<F> {
|
||||
fn pump_parented(&mut self, _: egui::ViewportId, _: std::num::NonZeroU64, _: &mut FilePanels, _: &mut DialogHost) -> Option<ParentLease> {
|
||||
None
|
||||
}
|
||||
fn pump_unparented(&mut self, panels: &mut FilePanels, host: &mut DialogHost) {
|
||||
(self.0)(panels, host);
|
||||
}
|
||||
}
|
||||
|
||||
/// The windowless trial's picks, each bound to the window that asked, cancelled native panels
|
||||
/// still settling, and the close or quit that waits for them. App-wide: focusing another window
|
||||
/// never moves a pick.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[derive(Default)]
|
||||
pub(crate) struct OwnedPicks {
|
||||
/// At most one per window.
|
||||
jobs: Vec<OwnedPick>,
|
||||
/// Forgotten native panels, each pumped until it settles and kept with its parent's lease till
|
||||
/// then. Bounded with the live ones by [`MAX_NATIVE_OPERATIONS`].
|
||||
retired: Vec<Retired>,
|
||||
/// Closes and a quit asked for while a system dialog still used a window, replayed once it ended.
|
||||
deferred: Vec<ExitIntent>,
|
||||
/// The app is exiting: no pick is admitted or launched; launched panels only drain.
|
||||
quiescing: bool,
|
||||
/// The `PathRow` picks' draw scope, staged picks and answers, shared with the frame host's [`path_rows::RowFiles`].
|
||||
rows: path_rows::RowRoute,
|
||||
/// The frame host carrying [`path_rows::RowFiles`], and the generation of the app host it wraps.
|
||||
env_host: Option<(u64, std::sync::Arc<craft::host::Host>)>,
|
||||
}
|
||||
|
||||
/// A close or quit waiting for system dialogs to end.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
enum ExitIntent {
|
||||
/// Quit (the app menu, the OS, the last window's close): waits for every system dialog.
|
||||
Quit,
|
||||
/// Close `window` (its close button, File › Close in it) while it shows `document`: waits for
|
||||
/// that window's own dialogs, and is dropped if the window shows another document by then.
|
||||
Close { window: u64, document: u64 },
|
||||
}
|
||||
|
||||
/// A cancelled pick whose system dialog launched. The dialog is never cancelled from here (the
|
||||
/// SDK cannot confirm a dialog has stopped using its parent): it finishes as the user answers it,
|
||||
/// and its answer is taken and dropped.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
struct Retired {
|
||||
/// The window its panel launched on (it may have closed since).
|
||||
window: u64,
|
||||
id: PickId,
|
||||
files: FileService,
|
||||
panels: FilePanels,
|
||||
_lease: Option<ParentLease>,
|
||||
}
|
||||
|
||||
/// A pick and its owner: the window that asked and the document it showed then.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
struct OwnedPick {
|
||||
window: u64,
|
||||
document: u64,
|
||||
after: AfterPick,
|
||||
/// Held until the route is settled; the private service gets it right before its first pump.
|
||||
request: PickRequest,
|
||||
/// The in-app chooser answers it: asked for, preferred, no lookup, or no native window found.
|
||||
in_app: bool,
|
||||
/// The exact native window the pick belongs to: taken at the gesture from an attached owner,
|
||||
/// or at its first attachment from an owner that was still mounting. Never taken again.
|
||||
pin: Option<NativeOwner>,
|
||||
/// The owner was still mounting at the gesture, so its first attachment may be pinned.
|
||||
bind_on_attach: bool,
|
||||
/// Scheduled passes counted without a live native window, and the pass counted last.
|
||||
missing: u32,
|
||||
missing_pass: Option<u64>,
|
||||
ticket: Option<Ticket>,
|
||||
/// Taken by a pump that had just checked the owner; settled by [`WordApp::poll_file_dialog`]
|
||||
/// after checking it again.
|
||||
answer: Option<Picked>,
|
||||
}
|
||||
|
||||
/// One private file service for one pick, so its panel never joins another window's queue and
|
||||
/// its answer cannot be taken by another pick (each service counts its tickets anew).
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
struct Ticket {
|
||||
id: PickId,
|
||||
files: FileService,
|
||||
panels: FilePanels,
|
||||
/// Whether its panel launches on `pin` (else the in-app chooser answers it).
|
||||
native: bool,
|
||||
/// Keeps the pinned window alive until the panel answers.
|
||||
lease: Option<ParentLease>,
|
||||
/// Whether the panels have been pumped: an unpumped ticket never reached a panel.
|
||||
pumped: bool,
|
||||
/// One chooser instance on the owner host; do not cancel a later one with the same ID.
|
||||
chooser: Option<(craft::ui::dialog::DialogId, u64)>,
|
||||
/// Replace IDs can recur because each private file service starts its ticket count anew.
|
||||
replace: Option<(craft::ui::dialog::DialogId, u64)>,
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
struct NativeOwner {
|
||||
viewport: egui::ViewportId,
|
||||
/// The owner's mount attempt: a remount is another surface.
|
||||
attempt: u64,
|
||||
incarnation: std::num::NonZeroU64,
|
||||
}
|
||||
|
||||
/// Why an owned pick ended without its answer.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
enum PickEnd {
|
||||
/// Its window or document closed, or the window's surface was rejected.
|
||||
Gone,
|
||||
/// The native window it was pinned to is no longer the owner's.
|
||||
Changed,
|
||||
/// Another prompt took the Replace confirmation's place.
|
||||
Replaced,
|
||||
/// The window's close or quit prompt asked for its Save As in place of this unlaunched pick.
|
||||
Superseded,
|
||||
/// The dialog opening a `PathRow` pick was filed from closed or was replaced.
|
||||
FormClosed,
|
||||
/// The `PathRow` that filed it forgot its ticket.
|
||||
Forgotten,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
thread_local! {
|
||||
/// Tests: the answers each new private file service's panels give instead of native panels, one
|
||||
/// list per service in order; the last list serves every later one.
|
||||
pub(crate) static SCRIPTED_PANELS: std::cell::RefCell<Option<std::collections::VecDeque<Vec<craft::dialogs::Answer>>>> =
|
||||
const { std::cell::RefCell::new(None) };
|
||||
}
|
||||
|
||||
/// How asking for a file went.
|
||||
pub(crate) enum Asked {
|
||||
/// Another file dialog is still open; nothing happened.
|
||||
@@ -103,8 +328,12 @@ pub(crate) enum Asked {
|
||||
}
|
||||
|
||||
impl WordApp {
|
||||
/// Whether a file dialog is open (its answer hasn't arrived yet).
|
||||
/// Whether a file dialog is open for the drawn window (its answer hasn't arrived yet).
|
||||
pub fn file_dialog_open(&self) -> bool {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if self.owned_picks.jobs.iter().any(|job| job.window == self.windows.shown()) || self.owned_picks.rows.staged_for(self.windows.shown()) {
|
||||
return true;
|
||||
}
|
||||
self.file_dialog.is_some()
|
||||
}
|
||||
|
||||
@@ -114,15 +343,31 @@ impl WordApp {
|
||||
self
|
||||
}
|
||||
|
||||
/// The desktop's view of its native windows, for the windowless trial's system file dialogs.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn set_native_window_lookup(&mut self, lookup: Option<std::sync::Arc<dyn NativeWindowLookup + Send + Sync>>) {
|
||||
self.native_windows = lookup;
|
||||
}
|
||||
|
||||
/// Ask the file service for a file and do `after` with the answer. Called in the pass of the
|
||||
/// user's gesture, since the browser's picker needs its activation. Ignored while another
|
||||
/// dialog is open.
|
||||
pub(crate) fn ask_file(&mut self, req: PickRequest, after: AfterPick) -> Asked {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if self.windows.windowless_trial() {
|
||||
self.supersede_for_guard_save_as(&after);
|
||||
}
|
||||
if self.file_dialog_open() {
|
||||
log::debug!("file dialog already open; ignoring {req:?}");
|
||||
self.status(tl!("A file dialog is already open."));
|
||||
return Asked::Busy;
|
||||
}
|
||||
// The windowless trial binds every pick to the window that asked and the document it
|
||||
// shows (the Start screen's placeholder included); see `pump_owned_picks`.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if self.windows.windowless_trial() {
|
||||
return self.push_owned_pick(self.windows.shown(), self.shown_document, req, after);
|
||||
}
|
||||
let fallback = req.fallback || self.fallback_chooser;
|
||||
let id = self.host.files().pick(req.fallback(fallback));
|
||||
self.file_dialog = Some(PendingDialog { id, after });
|
||||
@@ -130,43 +375,564 @@ impl WordApp {
|
||||
self.poll_file_dialog().map_or(Asked::Pending, Asked::Done)
|
||||
}
|
||||
|
||||
/// Admit a pick owned by window `window` showing `document`: the one admission point. An owner
|
||||
/// already attached is pinned to its live native window now, at the gesture.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) fn push_owned_pick(&mut self, window: u64, document: u64, request: PickRequest, after: AfterPick) -> Asked {
|
||||
if self.owned_picks.quiescing {
|
||||
return Asked::Busy;
|
||||
}
|
||||
if self.owned_picks.jobs.iter().any(|job| job.window == window) {
|
||||
self.status(tl!("A file dialog is already open."));
|
||||
return Asked::Busy;
|
||||
}
|
||||
let mut in_app = request.fallback || self.fallback_chooser;
|
||||
if !in_app && self.native_windows.is_none() {
|
||||
in_app = true;
|
||||
self.status(tl!("System file dialogs can't open over separate document windows here, so WordCraft's file chooser is used."));
|
||||
}
|
||||
let (mut pin, mut bind_on_attach) = (None, false);
|
||||
if !in_app {
|
||||
// Before the first frame no window has attached: the owner is still mounting.
|
||||
match self.ctx.clone().map(|ctx| self.pick_owner_surface(&ctx, window, document)) {
|
||||
None | Some(crate::windows::OwnerSurface::Pending) => bind_on_attach = true,
|
||||
Some(crate::windows::OwnerSurface::Attached { viewport, attempt }) => pin = self.live_native_owner(viewport, attempt),
|
||||
Some(crate::windows::OwnerSurface::Gone) => {}
|
||||
}
|
||||
}
|
||||
self.owned_picks.jobs.push(OwnedPick {
|
||||
window,
|
||||
document,
|
||||
after,
|
||||
request,
|
||||
in_app,
|
||||
pin,
|
||||
bind_on_attach,
|
||||
missing: 0,
|
||||
missing_pass: None,
|
||||
ticket: None,
|
||||
answer: None,
|
||||
});
|
||||
if let Some(ctx) = &self.ctx {
|
||||
ctx.request_repaint_of(egui::ViewportId::ROOT);
|
||||
}
|
||||
Asked::Pending
|
||||
}
|
||||
|
||||
/// The Save As that a close or quit prompt's Save asks for, in the prompt's own window for its
|
||||
/// own document, takes the place of a pick that window has queued but not launched (a quit
|
||||
/// paused it). Nothing else is superseded: a launched or answered pick, a retired dialog and
|
||||
/// another window's pick all stay, and the Save As is then Busy as before.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn supersede_for_guard_save_as(&mut self, after: &AfterPick) {
|
||||
let AfterPick::SaveAs { after: AfterSave::Closing, document } = after else { return };
|
||||
let window = self.windows.shown();
|
||||
if !self.closing.as_ref().is_some_and(|c| c.window == window && c.document == *document) {
|
||||
return;
|
||||
}
|
||||
let Some(at) = self.owned_picks.jobs.iter().position(|job| {
|
||||
job.window == window
|
||||
&& job.document == *document
|
||||
&& job.ticket.is_none()
|
||||
&& job.answer.is_none()
|
||||
&& !matches!(job.after, AfterPick::SaveAs { after: AfterSave::Closing, .. })
|
||||
}) else {
|
||||
return;
|
||||
};
|
||||
let job = self.owned_picks.jobs.remove(at);
|
||||
let ctx = self.ctx.clone().unwrap_or_default();
|
||||
self.cancel_owned_pick(&ctx, job, PickEnd::Superseded);
|
||||
}
|
||||
|
||||
/// The live native window of an attached owner at `viewport`, from the desktop's lookup.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn live_native_owner(&self, viewport: Option<egui::ViewportId>, attempt: u64) -> Option<NativeOwner> {
|
||||
let viewport = viewport?;
|
||||
let incarnation = self.native_windows.as_ref()?.incarnation(viewport)?;
|
||||
Some(NativeOwner { viewport, attempt, incarnation })
|
||||
}
|
||||
|
||||
/// Whether `pin` is still exactly the owner's live native window.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn pin_is_live(&self, window: u64, pin: NativeOwner) -> bool {
|
||||
self.attached_attempt(window) == Some(pin.attempt)
|
||||
&& self.native_windows.as_ref().and_then(|l| l.incarnation(pin.viewport)) == Some(pin.incarnation)
|
||||
}
|
||||
|
||||
/// [`WordApp::pump_owned_picks`] for a desktop whose pump has no parent to give: picks it
|
||||
/// cannot launch natively wait and then use the in-app chooser. An intermediate stage until the
|
||||
/// desktop passes its [`OwnerPanels`].
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn pump_windowless_save_as(&mut self, ctx: &egui::Context, pump: impl FnMut(&mut FilePanels, &mut DialogHost)) {
|
||||
self.pump_owned_picks(ctx, &mut NoWindowLookup(pump));
|
||||
}
|
||||
|
||||
/// Pump every owned pick on its own window's host, from the root pass: launch, collect, cancel,
|
||||
/// clean up, then replay a close or quit that waited for system dialogs.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn pump_owned_picks(&mut self, ctx: &egui::Context, desk: &mut impl OwnerPanels) {
|
||||
// `PathRow` picks whose owner's drawing did not hand them over (it ended early) join here, bound to the owner
|
||||
// they were filed in, never to the window drawn now.
|
||||
self.admit_row_picks(None);
|
||||
// Cancelled after their one panel launched: nothing is queued, so this launches nothing; it
|
||||
// collects the dialog's late answer and drops it. If that answer would open the in-app
|
||||
// chooser or a Replace question, they open on this throwaway host and the next pump finds
|
||||
// them gone, which settles the pick as cancelled. A settled one releases its lease.
|
||||
self.owned_picks.retired.retain_mut(|retired| {
|
||||
desk.pump_unparented(&mut retired.panels, &mut DialogHost::new());
|
||||
let _ = retired.files.take_answer(retired.id);
|
||||
retired.files.pending_pick().is_some()
|
||||
});
|
||||
// A quit whose dialogs have ended goes on before any new launch is scheduled.
|
||||
self.replay_deferred_exits();
|
||||
// One pick at a time is out of the list, so admission counts every other one, visited or not.
|
||||
// Only a pick without a launched panel launches, so the one out holds no lease then.
|
||||
let mut at = 0;
|
||||
while at < self.owned_picks.jobs.len() {
|
||||
let mut job = self.owned_picks.jobs.remove(at);
|
||||
match self.advance_owned_pick(ctx, &mut job, desk) {
|
||||
Ok(()) => {
|
||||
self.owned_picks.jobs.insert(at, job);
|
||||
at += 1;
|
||||
}
|
||||
Err(end) => self.cancel_owned_pick(ctx, job, end),
|
||||
}
|
||||
}
|
||||
if !self.owned_picks.retired.is_empty() {
|
||||
// A portal Save's close arrives as an answer; look again soon even if nothing wakes.
|
||||
ctx.request_repaint_after(MISSING_RETRY);
|
||||
}
|
||||
self.replay_deferred_exits();
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn advance_owned_pick(&mut self, ctx: &egui::Context, job: &mut OwnedPick, desk: &mut impl OwnerPanels) -> Result<(), PickEnd> {
|
||||
let surface = self.pick_owner_surface(ctx, job.window, job.document);
|
||||
if surface == crate::windows::OwnerSurface::Gone {
|
||||
return Err(PickEnd::Gone);
|
||||
}
|
||||
// A pinned pick checks its exact window at every pump, launched or not, also while its
|
||||
// answer waits: a pick never moves to a recreated window.
|
||||
if let Some(pin) = job.pin
|
||||
&& !self.pin_is_live(job.window, pin)
|
||||
{
|
||||
return Err(PickEnd::Changed);
|
||||
}
|
||||
if let AfterPick::Row(row) = &job.after
|
||||
&& !self.row_form_live(job.window, job.document, row.form)
|
||||
{
|
||||
return Err(PickEnd::FormClosed);
|
||||
}
|
||||
if job.answer.is_some() {
|
||||
return Ok(());
|
||||
}
|
||||
if job.ticket.is_none() && !job.in_app {
|
||||
if job.pin.is_none() && job.bind_on_attach {
|
||||
match surface {
|
||||
crate::windows::OwnerSurface::Attached { viewport, attempt } => {
|
||||
job.pin = self.live_native_owner(viewport, attempt);
|
||||
job.bind_on_attach = false;
|
||||
}
|
||||
_ => {
|
||||
// Still mounting: its mount pass attaches or rejects it; look again soon.
|
||||
ctx.request_repaint_after(MISSING_RETRY);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
match job.pin {
|
||||
Some(pin) => {
|
||||
if self.owned_picks.quiescing || self.native_operations() >= MAX_NATIVE_OPERATIONS || self.quit_pauses_launch(&job.after) {
|
||||
// Earlier system dialogs still use their windows: wait, holding nothing.
|
||||
ctx.request_repaint_after(MISSING_RETRY);
|
||||
return Ok(());
|
||||
}
|
||||
let (files, panels) = self.private_file_service();
|
||||
let id = files.pick(job.request.clone());
|
||||
job.ticket = Some(Ticket { id, files, panels, native: true, lease: None, pumped: false, chooser: None, replace: None });
|
||||
let Some(host) = self.window_dialog_host_mut(job.window) else { return Err(PickEnd::Gone) };
|
||||
let Some(ticket) = job.ticket.as_mut() else { return Ok(()) };
|
||||
match desk.pump_parented(pin.viewport, pin.incarnation, &mut ticket.panels, host) {
|
||||
Some(lease) => ticket.lease = Some(lease),
|
||||
// The pinned window went between the lookup and the pump. The request
|
||||
// never reached a panel: drop it unpumped, and the pick with it.
|
||||
None => {
|
||||
job.ticket = None;
|
||||
return Err(PickEnd::Changed);
|
||||
}
|
||||
}
|
||||
ticket.pumped = true;
|
||||
return self.observe_ticket(ctx, job);
|
||||
}
|
||||
None => {
|
||||
let pass = ctx.cumulative_pass_nr();
|
||||
if job.missing_pass != Some(pass) {
|
||||
job.missing_pass = Some(pass);
|
||||
job.missing += 1;
|
||||
}
|
||||
if job.missing < MISSING_PASSES {
|
||||
ctx.request_repaint_after(MISSING_RETRY);
|
||||
return Ok(());
|
||||
}
|
||||
job.in_app = true;
|
||||
self.status(tl!("The system file dialog couldn't attach to this window, so WordCraft's file chooser is used."));
|
||||
}
|
||||
}
|
||||
}
|
||||
if job.ticket.is_none() {
|
||||
let (files, panels) = self.private_file_service();
|
||||
let id = files.pick(job.request.clone().fallback(true));
|
||||
job.ticket = Some(Ticket { id, files, panels, native: false, lease: None, pumped: false, chooser: None, replace: None });
|
||||
}
|
||||
let Some(host) = self.window_dialog_host_mut(job.window) else { return Err(PickEnd::Gone) };
|
||||
let Some(ticket) = job.ticket.as_mut() else { return Ok(()) };
|
||||
if ticket.replace.is_some_and(|(id, serial)| host.open_serial(id).is_some_and(|open| open != serial)) {
|
||||
return Err(PickEnd::Replaced);
|
||||
}
|
||||
// The in-app chooser, or a launched panel (its pin checked above) whose queue is empty.
|
||||
desk.pump_unparented(&mut ticket.panels, host);
|
||||
ticket.pumped = true;
|
||||
self.observe_ticket(ctx, job)
|
||||
}
|
||||
|
||||
/// After a pump of `job`'s panels on its owner's host: note the chooser and Replace prompt it
|
||||
/// opened there, and take its answer (releasing the lease: the panel is done with the parent).
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn observe_ticket(&mut self, ctx: &egui::Context, job: &mut OwnedPick) -> Result<(), PickEnd> {
|
||||
let Some(host) = self.window_dialog_host_mut(job.window) else { return Err(PickEnd::Gone) };
|
||||
let Some(ticket) = job.ticket.as_mut() else { return Ok(()) };
|
||||
if ticket.chooser.is_none()
|
||||
&& let Some(chooser) = host.get::<FileChooser>()
|
||||
{
|
||||
let id = chooser.id();
|
||||
ticket.chooser = host.open_serial(id).map(|serial| (id, serial));
|
||||
// The root pump can run after the owner was drawn; show the chooser next frame.
|
||||
ctx.request_repaint_of(egui::ViewportId::ROOT);
|
||||
}
|
||||
let now = ticket.panels.open_questions().next();
|
||||
let known = ticket.replace.map(|(id, _)| id);
|
||||
if now != known {
|
||||
ticket.replace = now.and_then(|id| host.open_serial_by_id::<StandardPrompt>(id).map(|serial| (id, serial)));
|
||||
ctx.request_repaint_of(egui::ViewportId::ROOT);
|
||||
}
|
||||
job.answer = ticket.files.take_answer(ticket.id);
|
||||
if job.answer.is_some() {
|
||||
ticket.lease = None;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// System file dialogs that may still use a window's handles: launched and unanswered, plus
|
||||
/// cancelled ones not settled.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn native_operations(&self) -> usize {
|
||||
self.owned_picks.retired.len() + self.owned_picks.jobs.iter().filter(|job| job.ticket.as_ref().is_some_and(|t| t.lease.is_some())).count()
|
||||
}
|
||||
|
||||
/// Whether a quit holds back launching a pick's system dialog: while the quit waits for earlier
|
||||
/// dialogs, or asks about unsaved documents, no new one opens, except the Save As that a
|
||||
/// close or quit prompt's Save asks for.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn quit_pauses_launch(&self, after: &AfterPick) -> bool {
|
||||
// Quit decided (a replay in this pump may have just set it): nothing launches any more.
|
||||
if self.quit_requested {
|
||||
return true;
|
||||
}
|
||||
let quitting = self.owned_picks.deferred.contains(&ExitIntent::Quit)
|
||||
|| self.closing.as_ref().is_some_and(|c| c.params.get("quit").and_then(Value::as_bool) == Some(true));
|
||||
quitting && !matches!(after, AfterPick::SaveAs { after: AfterSave::Closing, .. })
|
||||
}
|
||||
|
||||
/// Whether any system file dialog launched by an owned pick may still use its parent window's
|
||||
/// handles. Their parent leases must outlive that, so quit waits while this is true.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn native_file_panels_open(&self) -> bool {
|
||||
self.native_operations() > 0
|
||||
}
|
||||
|
||||
/// Whether window `key`'s own pick has a system dialog that may still use it, or an answer not
|
||||
/// yet settled in it.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn window_native_pick_unsettled(&self, key: u64) -> bool {
|
||||
self.owned_picks.retired.iter().any(|retired| retired.window == key)
|
||||
|| self
|
||||
.owned_picks
|
||||
.jobs
|
||||
.iter()
|
||||
.any(|job| job.window == key && (job.answer.is_some() || job.ticket.as_ref().is_some_and(|t| t.lease.is_some())))
|
||||
}
|
||||
|
||||
/// The app is exiting: call once the desktop has accepted the quit or the root window's close,
|
||||
/// before its last passes. From then on no pick is admitted or launches a system dialog (so a
|
||||
/// final draw cannot start one); picks not launched are dropped without being pumped; launched
|
||||
/// panels are left to finish and keep their leases while [`WordApp::pump_owned_picks`] drains them,
|
||||
/// a pass every 100 ms, until [`WordApp::native_file_panels_open`] is false. Deferred closes are
|
||||
/// dropped. Idempotent.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn quiesce_native_file_panels(&mut self) {
|
||||
self.owned_picks.quiescing = true;
|
||||
self.owned_picks.deferred.clear();
|
||||
let ctx = self.ctx.clone().unwrap_or_default();
|
||||
for job in std::mem::take(&mut self.owned_picks.jobs) {
|
||||
if let Some(ticket) = job.ticket {
|
||||
// An in-app chooser (asked for, or a system dialog's fallback) or Replace question
|
||||
// would stay on screen with nothing to answer it.
|
||||
self.close_pick_dialogs(&ctx, job.window, &ticket);
|
||||
self.retire_ticket(job.window, ticket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Quit while system dialogs still use their windows: remember it (once) and say so; it goes on
|
||||
/// by itself once they have ended. A pick that never launched does not hold it.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) fn defer_quit_for_native_panels(&mut self) -> bool {
|
||||
if !self.native_file_panels_open() {
|
||||
return false;
|
||||
}
|
||||
if !self.owned_picks.deferred.contains(&ExitIntent::Quit) {
|
||||
self.owned_picks.deferred.push(ExitIntent::Quit);
|
||||
}
|
||||
self.status(tl!("WordCraft will quit once the open file dialog is closed."));
|
||||
true
|
||||
}
|
||||
|
||||
/// Closing window `key` while its own system dialog still uses it: remember it (once) and say
|
||||
/// so; other windows close as usual.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) fn defer_close_for_native_panel(&mut self, key: u64) -> bool {
|
||||
if !self.window_native_pick_unsettled(key) {
|
||||
return false;
|
||||
}
|
||||
let Some(document) = self.window_document(key) else { return false };
|
||||
let intent = ExitIntent::Close { window: key, document };
|
||||
if !self.owned_picks.deferred.contains(&intent) {
|
||||
self.owned_picks.deferred.push(intent);
|
||||
}
|
||||
self.status(tl!("This window will close once its file dialog is closed."));
|
||||
true
|
||||
}
|
||||
|
||||
/// Replay a deferred close or quit whose dialogs have ended, through the usual guards. One that
|
||||
/// would meet a close prompt already asking waits for it, so no prompt is replaced.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn replay_deferred_exits(&mut self) {
|
||||
if self.owned_picks.deferred.is_empty() || self.closing.is_some() || self.owned_picks.quiescing {
|
||||
return;
|
||||
}
|
||||
let deferred = std::mem::take(&mut self.owned_picks.deferred);
|
||||
let mut waiting = Vec::new();
|
||||
for intent in deferred {
|
||||
match intent {
|
||||
ExitIntent::Quit
|
||||
if !self.native_file_panels_open() && !self.owned_picks.jobs.iter().any(|job| job.answer.is_some()) && self.closing.is_none() =>
|
||||
{
|
||||
self.quit();
|
||||
}
|
||||
// The window shows another document now: the close was for the one it showed.
|
||||
ExitIntent::Close { window, document } if !self.window_shows_document(window, document) => {}
|
||||
ExitIntent::Close { window, .. } if !self.window_native_pick_unsettled(window) && self.closing.is_none() => {
|
||||
self.close_window(window);
|
||||
}
|
||||
intent => waiting.push(intent),
|
||||
}
|
||||
}
|
||||
waiting.append(&mut self.owned_picks.deferred);
|
||||
self.owned_picks.deferred = waiting;
|
||||
}
|
||||
|
||||
/// A private file service seeded with the trial's remembered folders.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn private_file_service(&self) -> (FileService, FilePanels) {
|
||||
let ctx = self.ctx.clone();
|
||||
let wake = Wake::new(move || {
|
||||
if let Some(ctx) = &ctx {
|
||||
ctx.request_repaint_of(egui::ViewportId::ROOT);
|
||||
}
|
||||
});
|
||||
#[cfg(test)]
|
||||
{
|
||||
let scripted = SCRIPTED_PANELS.with(|s| {
|
||||
let mut lists = s.borrow_mut();
|
||||
let lists = lists.as_mut()?;
|
||||
if lists.len() > 1 { lists.pop_front() } else { lists.front().cloned() }
|
||||
});
|
||||
if let Some(answers) = scripted {
|
||||
let (files, panels) = FileService::scripted(wake, answers);
|
||||
return (files.with_last_folders(self.windowless_save_folders.clone()), panels);
|
||||
}
|
||||
}
|
||||
let (files, panels) = FileService::new(wake);
|
||||
(files.with_last_folders(self.windowless_save_folders.clone()), panels)
|
||||
}
|
||||
|
||||
/// A failed native attachment parks the logical window but makes its picks unusable.
|
||||
/// Cancel only that window's, before another viewport can settle them or the user retries it.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) fn cancel_windowless_save_as_for_mount_failure(&mut self, ctx: &egui::Context, window: u64) {
|
||||
let (gone, kept): (Vec<_>, Vec<_>) = std::mem::take(&mut self.owned_picks.jobs).into_iter().partition(|job| job.window == window);
|
||||
self.owned_picks.jobs = kept;
|
||||
for job in gone {
|
||||
self.cancel_owned_pick(ctx, job, PickEnd::Gone);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn cancel_owned_pick(&mut self, ctx: &egui::Context, job: OwnedPick, end: PickEnd) {
|
||||
if let Some(ticket) = job.ticket {
|
||||
self.close_pick_dialogs(ctx, job.window, &ticket);
|
||||
self.retire_ticket(job.window, ticket);
|
||||
}
|
||||
// What the pick left pending in its window, if that window is still there: nothing else's.
|
||||
self.clear_window_pick_state(job.window, matches!(job.after, AfterPick::Picture), matches!(job.after, AfterPick::Recipients));
|
||||
if matches!(job.after, AfterPick::SaveAs { after: AfterSave::Closing, .. })
|
||||
&& self.closing.as_ref().is_some_and(|c| c.window == job.window && c.document == job.document)
|
||||
{
|
||||
self.cancel_closing();
|
||||
}
|
||||
if end == PickEnd::Superseded {
|
||||
// Its row still waits for the pick: it learns it did not open.
|
||||
if let AfterPick::Row(row) = job.after {
|
||||
self.cancel_row_pick(job.window, job.document, row);
|
||||
}
|
||||
return;
|
||||
}
|
||||
self.status(match end {
|
||||
PickEnd::Replaced => tl!("The Replace confirmation changed. Try saving again."),
|
||||
PickEnd::Changed => tl!("The document window for this file dialog changed. Try again."),
|
||||
PickEnd::Gone | PickEnd::Superseded => tl!("The document window for this Save As is no longer available."),
|
||||
PickEnd::FormClosed => tl!("The dialog that asked for this file has closed."),
|
||||
// Its row let go of it; there is nothing to say.
|
||||
PickEnd::Forgotten => return,
|
||||
});
|
||||
}
|
||||
|
||||
/// Remove from window `window`'s host the in-app chooser and Replace question `ticket` opened
|
||||
/// there, exactly those instances (a later dialog with the same ID stays). Every place a
|
||||
/// ticket is cancelled or retired calls this first, so no chooser or prompt is left showing for
|
||||
/// a pick that no longer answers. A closed window already lost its host.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn close_pick_dialogs(&mut self, ctx: &egui::Context, window: u64, ticket: &Ticket) {
|
||||
let Some(host) = self.window_dialog_host_mut(window) else { return };
|
||||
if let Some((id, serial)) = ticket.chooser
|
||||
&& host.open_serial(id) == Some(serial)
|
||||
{
|
||||
host.cancel_by_id(ctx, id);
|
||||
let _ = host.take_by_id::<FileChooser>(id);
|
||||
}
|
||||
if let Some((id, serial)) = ticket.replace
|
||||
&& host.open_serial(id) == Some(serial)
|
||||
&& host.open_dialogs().iter().filter(|dialog| dialog.id == id).count() == 1
|
||||
{
|
||||
host.cancel_by_id(ctx, id);
|
||||
}
|
||||
if let Some((_, serial)) = ticket.replace {
|
||||
let _ = host.take_by_open_serial::<StandardPrompt>(serial);
|
||||
}
|
||||
}
|
||||
|
||||
/// Drop a ticket. A system dialog that launched and has not answered is left to finish and kept,
|
||||
/// with its lease, for cleanup pumps; the next pass is scheduled. An in-app chooser or an
|
||||
/// unpumped ticket has no system panel.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn retire_ticket(&mut self, window: u64, ticket: Ticket) {
|
||||
if ticket.pumped && ticket.native && ticket.files.pending_pick().is_some() {
|
||||
self.owned_picks.retired.push(Retired { window, id: ticket.id, files: ticket.files, panels: ticket.panels, _lease: ticket.lease });
|
||||
if let Some(ctx) = &self.ctx {
|
||||
ctx.request_repaint_of(egui::ViewportId::ROOT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether `job`'s answer may be settled now: its owner still shows its document and, for a
|
||||
/// pinned pick, the desktop still has exactly the native window it was pinned to.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn owned_answer_current(&self, job: &OwnedPick) -> bool {
|
||||
self.window_shows_document(job.window, job.document)
|
||||
&& job.pin.is_none_or(|pin| self.pin_is_live(job.window, pin))
|
||||
&& match &job.after {
|
||||
AfterPick::Row(row) => self.row_form_live(job.window, job.document, row.form),
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
/// Settle an owned pick's answer in its own window, then draw the window that was drawn.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn settle_owned_pick(&mut self, job: OwnedPick, picked: Picked) -> Result<Value, String> {
|
||||
if let AfterPick::Row(row) = job.after {
|
||||
// Nothing runs here: the row that filed the ticket takes the answer on its owner's next draw.
|
||||
if let Some(ticket) = &job.ticket {
|
||||
self.windowless_save_folders = ticket.files.last_folders();
|
||||
}
|
||||
return Ok(self.settle_row_pick(job.window, job.document, row, job.pin, picked));
|
||||
}
|
||||
let previous = self.windows.shown();
|
||||
if !self.enter_window(job.window) || self.session.switch_document(job.document).is_err() {
|
||||
if matches!(job.after, AfterPick::SaveAs { after: AfterSave::Closing, .. }) {
|
||||
self.cancel_closing();
|
||||
}
|
||||
return Err(tl!("The document window for this Save As is no longer available.").into());
|
||||
}
|
||||
if let Some(ticket) = &job.ticket {
|
||||
self.windowless_save_folders = ticket.files.last_folders();
|
||||
}
|
||||
let result = self.finish_file_answer(job.after, picked);
|
||||
self.enter_window(previous);
|
||||
result
|
||||
}
|
||||
|
||||
/// Pick up the answer of an open file dialog, if it has arrived (every frame, from `logic`),
|
||||
/// and finish what it was for. `None` while there is nothing to finish.
|
||||
pub(crate) fn poll_file_dialog(&mut self) -> Option<Result<Value, String>> {
|
||||
let id = self.file_dialog.as_ref()?.id;
|
||||
let picked = self.host.files().take_answer(id)?;
|
||||
// Checked again here, at its last use; an obsolete pick is left for the pump to remove
|
||||
// from its original host.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if let Some(at) = self.owned_picks.jobs.iter().position(|job| job.answer.is_some() && self.owned_answer_current(job)) {
|
||||
let mut job = self.owned_picks.jobs.remove(at);
|
||||
if let Some(picked) = job.answer.take() {
|
||||
return Some(self.settle_owned_pick(job, picked));
|
||||
}
|
||||
self.owned_picks.jobs.push(job);
|
||||
}
|
||||
let pending = self.file_dialog.as_ref()?;
|
||||
let picked = self.host.files().take_answer(pending.id)?;
|
||||
let d = self.file_dialog.take()?;
|
||||
if matches!(d.after, AfterPick::Recipients) {
|
||||
Some(self.finish_file_answer(d.after, picked))
|
||||
}
|
||||
|
||||
/// Settle the selected answer in the window it belongs to.
|
||||
fn finish_file_answer(&mut self, after: AfterPick, picked: Picked) -> Result<Value, String> {
|
||||
if matches!(after, AfterPick::Recipients) {
|
||||
self.recipient_list_pending = false;
|
||||
}
|
||||
match picked {
|
||||
Picked::Cancelled => Some(self.finish_pick(d.after, None)),
|
||||
Picked::Cancelled => self.finish_pick(after, None),
|
||||
Picked::Unavailable(cause) => {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
self.status(craft::dialogs::ui::UnavailableWords::default().sentence(&cause));
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
self.status(format!("No file dialog can open: {cause}"));
|
||||
Some(self.finish_pick(d.after, None))
|
||||
self.finish_pick(after, None)
|
||||
}
|
||||
Picked::Failed(reason) => {
|
||||
// A plain Save As has no prompt to carry the reason to and Backstage hides the
|
||||
// status bar, so the Save As page says it too.
|
||||
if matches!(d.after, AfterPick::SaveAs { after: AfterSave::Nothing, .. }) {
|
||||
if matches!(after, AfterPick::SaveAs { after: AfterSave::Nothing, .. }) {
|
||||
self.fail_save_as(&reason);
|
||||
} else {
|
||||
self.status(reason);
|
||||
}
|
||||
Some(self.finish_pick(d.after, None))
|
||||
self.finish_pick(after, None)
|
||||
}
|
||||
Picked::Paths(paths) => {
|
||||
let paths = paths.iter().map(|p| p.to_string_lossy().into_owned()).collect();
|
||||
Some(self.finish_picks(d.after, paths))
|
||||
self.finish_picks(after, paths)
|
||||
}
|
||||
Picked::Saved { path, .. } => Some(self.finish_picks(d.after, vec![path.to_string_lossy().into_owned()])),
|
||||
Picked::Contents(files) => Some(self.finish_contents(d.after, files)),
|
||||
Picked::Saved { path, .. } => self.finish_picks(after, vec![path.to_string_lossy().into_owned()]),
|
||||
Picked::Contents(files) => self.finish_contents(after, files),
|
||||
// The page handed the save over as a download: the save finishes under that name, which
|
||||
// the engine answers with `downloaded`, and the document keeps the file it had.
|
||||
Picked::Downloaded(name) => Some(self.finish_pick(d.after, Some(name))),
|
||||
Picked::Downloaded(name) => self.finish_pick(after, Some(name)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,6 +940,34 @@ impl WordApp {
|
||||
/// returns the format of the export it was for, if any. `ui.fileBrowser` reuses it.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) fn give_up_file_dialog(&mut self) -> Option<String> {
|
||||
let shown = self.windows.shown();
|
||||
if let Some(at) = self.owned_picks.jobs.iter().position(|job| job.window == shown) {
|
||||
// An in-app chooser or Replace question already shows (asked for, or the system
|
||||
// dialog's fallback): do not replace it or an in-progress close with the browser
|
||||
// recovery command, nor leave it showing for a pick that no longer answers.
|
||||
let job = &self.owned_picks.jobs[at];
|
||||
if job.in_app || job.answer.is_some() || job.ticket.as_ref().is_some_and(|t| t.chooser.is_some() || t.replace.is_some()) {
|
||||
return None;
|
||||
}
|
||||
if matches!(job.after, AfterPick::Row(_)) {
|
||||
// A `PathRow` pick keeps its row as its completion: its system dialog is given up for the in-app
|
||||
// chooser on the same window, which answers the same row.
|
||||
let job = &mut self.owned_picks.jobs[at];
|
||||
job.in_app = true;
|
||||
let window = job.window;
|
||||
if let Some(ticket) = job.ticket.take() {
|
||||
self.retire_ticket(window, ticket);
|
||||
}
|
||||
return None;
|
||||
}
|
||||
let job = self.owned_picks.jobs.remove(at);
|
||||
if let Some(ticket) = job.ticket {
|
||||
self.retire_ticket(job.window, ticket);
|
||||
}
|
||||
let export = if let AfterPick::Export { ext } = &job.after { Some(ext.clone()) } else { None };
|
||||
let _ = self.finish_pick(job.after, None);
|
||||
return export;
|
||||
}
|
||||
let d = self.file_dialog.take()?;
|
||||
self.host.files().forget(d.id);
|
||||
let export = if let AfterPick::Export { ext } = &d.after { Some(ext.clone()) } else { None };
|
||||
@@ -278,6 +1072,9 @@ impl WordApp {
|
||||
let Some(path) = picked else { return Ok(json!({"cancelled": true})) };
|
||||
self.add_fonts(vec![(path.clone(), json!({"path": path}))])
|
||||
}
|
||||
// Settled by `settle_owned_pick` into the row's own ticket; no command runs for it.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
AfterPick::Row(_) => Ok(json!({"cancelled": picked.is_none()})),
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
AfterPick::Sources => {
|
||||
let Some(path) = picked else { return Ok(json!({"cancelled": true})) };
|
||||
|
||||
@@ -0,0 +1,465 @@
|
||||
//! The windowless trial's route for the SDK `PathRow`'s own picks (Compare and Combine, Templates and Add-ins, the
|
||||
//! Organizer). A `PathRow` with `.pick(..)` files its Browse request through the `Env` host itself
|
||||
//! (`host.files().pick`) and keeps the ticket in its row's memory, so `WordApp::ask_file` never sees it. The `Env` host
|
||||
//! comes from the frame input, one for every viewport, so in the trial the frame's host carries [`RowFiles`], an
|
||||
//! app-owned wrapper over the app's own host:
|
||||
//!
|
||||
//! - `WordApp` sets a draw scope around each window's drawing: the logical window, the document it shows and its exact
|
||||
//! native window (viewport, mount attempt, incarnation) when it has one. Around the window's dialog run it adds the
|
||||
//! openings of its dialogs (id and open serial), read before the run: a dialog opened during a run shows only from
|
||||
//! the next pass, so every dialog that runs is in it.
|
||||
//! - A pick is bound when it is filed: to that scope and to the dialog running it (`overlay::running_dialog`) at the
|
||||
//! serial of that opening. It is staged under a ticket of the wrapper's own numbering.
|
||||
//! - After the owner's drawing, `WordApp::admit_row_picks` hands it to the owned route (`push_owned_pick`, the one
|
||||
//! admission point), which pins the native window and launches the system dialog only there, under its lease.
|
||||
//! - The settled answer is posted here under the row's exact ticket. The row takes it only from a drawing of the same
|
||||
//! window, document, native window and dialog opening; otherwise it is dropped. A pick whose window, document,
|
||||
//! native window or dialog goes before then is cancelled by the route and posts nothing.
|
||||
//!
|
||||
//! A pick filed outside any window's drawing, or from a dialog whose opening cannot be told apart, answers Cancelled at
|
||||
//! once: nothing launches without an exact owner. Every other file-service call goes straight to the app's own host,
|
||||
//! and outside the trial the frame gets that host unchanged.
|
||||
|
||||
use std::num::NonZeroU64;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::{Arc, Mutex, MutexGuard};
|
||||
|
||||
use craft::host::{FileError, Files, Host, PendingPick, PickId, PickRequest, Picked, WriteIntent};
|
||||
use craft::ui::dialog::DialogId;
|
||||
|
||||
use super::{AfterPick, Asked, NativeOwner, PickEnd};
|
||||
use crate::WordApp;
|
||||
|
||||
/// The wrapper's tickets have this bit set; the app's own service counts up from 1 and never reaches it, so every
|
||||
/// ticket names one side.
|
||||
const ROW_TICKETS: u64 = 1 << 63;
|
||||
|
||||
/// Answers kept for picks filed outside any window's drawing (each answered Cancelled at once) until their row takes
|
||||
/// them; the oldest goes first.
|
||||
const MAX_OWNERLESS: usize = 4;
|
||||
|
||||
/// Answers kept for one window's rows until they take them: the newest for each dialog opening, and at most this many
|
||||
/// in all; the oldest goes first.
|
||||
const MAX_PER_WINDOW: usize = 2;
|
||||
|
||||
/// The logical window being drawn and the document it shows: who a row pick belongs to.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
pub(crate) struct RowOwner {
|
||||
pub(crate) window: u64,
|
||||
pub(crate) document: u64,
|
||||
}
|
||||
|
||||
/// The exact native window a window draws in: viewport, mount attempt and incarnation. `None` while it has none the
|
||||
/// desktop can name (still mounting, or no window lookup).
|
||||
pub(crate) type RowSurface = Option<(egui::ViewportId, u64, NonZeroU64)>;
|
||||
|
||||
/// The dialog opening a row pick was filed from on its owner's host: its id and that opening's serial. `None` for a
|
||||
/// row outside any hosted dialog.
|
||||
pub(crate) type RowForm = Option<(DialogId, u64)>;
|
||||
|
||||
/// Where an owned row pick's answer goes: the row's ticket, the dialog opening it was filed from, and the native
|
||||
/// window its owner drew in then.
|
||||
#[derive(Clone, Copy)]
|
||||
pub(crate) struct RowTarget {
|
||||
pub(crate) id: PickId,
|
||||
pub(crate) form: RowForm,
|
||||
pub(crate) surface: RowSurface,
|
||||
}
|
||||
|
||||
/// A window's drawing, while it runs.
|
||||
#[derive(Clone)]
|
||||
struct Scope {
|
||||
owner: RowOwner,
|
||||
surface: RowSurface,
|
||||
ctx: egui::Context,
|
||||
/// The window's dialog openings, read right before its dialog run; empty outside the run.
|
||||
forms: Vec<(DialogId, u64)>,
|
||||
}
|
||||
|
||||
impl Scope {
|
||||
/// The opening of the dialog running now, as the scope knows it. `Ok(None)` outside any hosted dialog; `Err`
|
||||
/// when the dialog running is not one opening of this window's host (two openings of one id, or another host).
|
||||
fn running_form(&self) -> Result<RowForm, ()> {
|
||||
let Some(id) = craft::ui::runtime::overlay::running_dialog(&self.ctx) else { return Ok(None) };
|
||||
let mut openings = self.forms.iter().filter(|(open, _)| *open == id);
|
||||
match (openings.next(), openings.next()) {
|
||||
(Some(&opening), None) => Ok(Some(opening)),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A row pick filed in a window's drawing, not yet handed to the owned route.
|
||||
pub(crate) struct Staged {
|
||||
pub(crate) id: PickId,
|
||||
pub(crate) owner: RowOwner,
|
||||
pub(crate) form: RowForm,
|
||||
pub(crate) surface: RowSurface,
|
||||
pub(crate) request: PickRequest,
|
||||
}
|
||||
|
||||
/// An answer waiting for its row.
|
||||
struct Answer {
|
||||
id: PickId,
|
||||
owner: Option<RowOwner>,
|
||||
form: RowForm,
|
||||
surface: RowSurface,
|
||||
picked: Picked,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct RowState {
|
||||
/// The window being drawn, while it is.
|
||||
scope: Option<Scope>,
|
||||
next: u64,
|
||||
/// At most one per window: a second Browse in the same drawing answers Cancelled.
|
||||
staged: Vec<Staged>,
|
||||
/// At most [`MAX_PER_WINDOW`] per owner window, and [`MAX_OWNERLESS`] without one.
|
||||
answers: Vec<Answer>,
|
||||
/// Row tickets forgotten after they were handed to the owned route; that route cancels them.
|
||||
forgotten: Vec<PickId>,
|
||||
}
|
||||
|
||||
impl RowState {
|
||||
/// Post `picked` for ticket `id`. An older answer for the same window and dialog opening is dropped (its row has
|
||||
/// either taken it already or is no longer shown), and the bounds above hold.
|
||||
fn post(&mut self, id: PickId, owner: Option<RowOwner>, form: RowForm, surface: RowSurface, picked: Picked) {
|
||||
if owner.is_some() {
|
||||
self.answers.retain(|a| a.owner != owner || a.form != form);
|
||||
}
|
||||
let window = owner.map(|o| o.window);
|
||||
let same = |a: &Answer| a.owner.map(|o| o.window) == window;
|
||||
let bound = if owner.is_some() { MAX_PER_WINDOW } else { MAX_OWNERLESS };
|
||||
while self.answers.iter().filter(|a| same(a)).count() >= bound
|
||||
&& let Some(at) = self.answers.iter().position(same)
|
||||
{
|
||||
self.answers.remove(at);
|
||||
}
|
||||
self.answers.push(Answer { id, owner, form, surface, picked });
|
||||
}
|
||||
}
|
||||
|
||||
/// The state the router and the wrapper share. Kept in `OwnedPicks`, app-wide, so a window swap never moves it.
|
||||
#[derive(Clone, Default)]
|
||||
pub(crate) struct RowRoute(Arc<Mutex<RowState>>);
|
||||
|
||||
/// What [`WordApp::enter_row_scope`] replaced, for [`WordApp::leave_row_scope`] to put back.
|
||||
pub(crate) struct Entered {
|
||||
window: u64,
|
||||
previous: Option<Scope>,
|
||||
}
|
||||
|
||||
impl RowRoute {
|
||||
fn lock(&self) -> MutexGuard<'_, RowState> {
|
||||
self.0.lock().unwrap_or_else(|e| e.into_inner())
|
||||
}
|
||||
|
||||
/// Whether window `window` has a row pick staged and not yet handed to the owned route.
|
||||
pub(crate) fn staged_for(&self, window: u64) -> bool {
|
||||
self.lock().staged.iter().any(|s| s.owner.window == window)
|
||||
}
|
||||
|
||||
/// The staged picks, `window`'s only when given, in filing order.
|
||||
fn take_staged(&self, window: Option<u64>) -> Vec<Staged> {
|
||||
let mut state = self.lock();
|
||||
let (taken, kept): (Vec<Staged>, Vec<Staged>) =
|
||||
std::mem::take(&mut state.staged).into_iter().partition(|s| window.is_none_or(|w| s.owner.window == w));
|
||||
state.staged = kept;
|
||||
taken
|
||||
}
|
||||
|
||||
/// Post the answer of row ticket `id`.
|
||||
fn answer(&self, id: PickId, owner: RowOwner, form: RowForm, surface: RowSurface, picked: Picked) {
|
||||
self.lock().post(id, Some(owner), form, surface, picked);
|
||||
}
|
||||
|
||||
/// Drop the answers whose owner window, document or dialog opening `live` says is gone, Cancelled ones included.
|
||||
fn prune(&self, mut live: impl FnMut(RowOwner, RowForm) -> bool) {
|
||||
self.lock().answers.retain(|a| a.owner.is_none_or(|owner| live(owner, a.form)));
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether `id` is one of the wrapper's tickets.
|
||||
pub(crate) fn is_row_ticket(id: PickId) -> bool {
|
||||
id.0 & ROW_TICKETS != 0
|
||||
}
|
||||
|
||||
/// The frame host's file service in the windowless trial: row picks go to the owned route, everything else to the app's
|
||||
/// own host's service.
|
||||
pub(crate) struct RowFiles {
|
||||
inner: Arc<Host>,
|
||||
route: RowRoute,
|
||||
}
|
||||
|
||||
impl RowFiles {
|
||||
pub(crate) fn new(inner: Arc<Host>, route: RowRoute) -> Self {
|
||||
RowFiles { inner, route }
|
||||
}
|
||||
}
|
||||
|
||||
impl Files for RowFiles {
|
||||
fn pick(&self, request: PickRequest) -> PickId {
|
||||
let mut state = self.route.lock();
|
||||
state.next += 1;
|
||||
let id = PickId(ROW_TICKETS | state.next);
|
||||
let Some(scope) = state.scope.clone() else {
|
||||
log::warn!("a file pick was filed outside any window's drawing; nothing opens for it ({request:?})");
|
||||
state.post(id, None, None, None, Picked::Cancelled);
|
||||
return id;
|
||||
};
|
||||
let (owner, surface) = (scope.owner, scope.surface);
|
||||
match scope.running_form() {
|
||||
Err(()) => {
|
||||
// Not one opening of this window's dialogs: no exact owner to bind to, and no answer can reach it.
|
||||
log::warn!("a file pick was filed from a dialog WordCraft cannot tell apart; nothing opens for it ({request:?})");
|
||||
}
|
||||
// One pick per window: the route admits the first; this one answers Cancelled to its own row.
|
||||
Ok(form) if state.staged.iter().any(|s| s.owner.window == owner.window) => state.post(id, Some(owner), form, surface, Picked::Cancelled),
|
||||
Ok(form) => state.staged.push(Staged { id, owner, form, surface, request }),
|
||||
}
|
||||
id
|
||||
}
|
||||
|
||||
fn take_answer(&self, id: PickId) -> Option<Picked> {
|
||||
if !is_row_ticket(id) {
|
||||
return self.inner.files().take_answer(id);
|
||||
}
|
||||
let mut state = self.route.lock();
|
||||
let at = state.answers.iter().position(|a| a.id == id)?;
|
||||
let answer = state.answers.remove(at);
|
||||
let Some(owner) = answer.owner else { return Some(answer.picked) };
|
||||
// Read only from a drawing of the window, document, native window and dialog opening it was filed from; a row
|
||||
// reading it anywhere else (its window detached or remounted since, say) gets nothing, and the answer is gone.
|
||||
let current = state
|
||||
.scope
|
||||
.as_ref()
|
||||
.is_some_and(|scope| scope.owner == owner && scope.surface == answer.surface && scope.running_form() == Ok(answer.form));
|
||||
if current {
|
||||
Some(answer.picked)
|
||||
} else {
|
||||
log::debug!("dropped a file pick's answer read outside the drawing it was filed from");
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn forget(&self, id: PickId) {
|
||||
if !is_row_ticket(id) {
|
||||
self.inner.files().forget(id);
|
||||
return;
|
||||
}
|
||||
let mut state = self.route.lock();
|
||||
let staged = state.staged.len();
|
||||
state.staged.retain(|s| s.id != id);
|
||||
let answered = state.answers.len();
|
||||
state.answers.retain(|a| a.id != id);
|
||||
if state.staged.len() == staged && state.answers.len() == answered {
|
||||
// Neither staged nor answered: it may be with the owned route, which cancels it.
|
||||
state.forgotten.push(id);
|
||||
}
|
||||
}
|
||||
|
||||
fn pending_pick(&self) -> Option<PendingPick> {
|
||||
self.inner.files().pending_pick()
|
||||
}
|
||||
|
||||
fn read_metadata(&self, path: &Path) -> Result<(bool, u64), FileError> {
|
||||
self.inner.files().read_metadata(path)
|
||||
}
|
||||
|
||||
fn read(&self, path: &Path) -> Result<Vec<u8>, FileError> {
|
||||
self.inner.files().read(path)
|
||||
}
|
||||
|
||||
fn write(&self, path: &Path, bytes: &[u8], intent: WriteIntent) -> Result<bool, FileError> {
|
||||
self.inner.files().write(path, bytes, intent)
|
||||
}
|
||||
|
||||
fn exists(&self, path: &Path) -> bool {
|
||||
self.inner.files().exists(path)
|
||||
}
|
||||
|
||||
fn last_folder(&self, purpose: &str) -> Option<PathBuf> {
|
||||
self.inner.files().last_folder(purpose)
|
||||
}
|
||||
|
||||
fn save(&self, request: PickRequest, bytes: Vec<u8>) -> PickId {
|
||||
self.inner.files().save(request, bytes)
|
||||
}
|
||||
|
||||
fn can_pick(&self) -> bool {
|
||||
self.inner.files().can_pick()
|
||||
}
|
||||
|
||||
fn browser_saves(&self) -> bool {
|
||||
self.inner.files().browser_saves()
|
||||
}
|
||||
|
||||
fn saves_to_page(&self) -> bool {
|
||||
self.inner.files().saves_to_page()
|
||||
}
|
||||
|
||||
fn answer_next(&self, picked: Picked) -> Result<(), FileError> {
|
||||
self.inner.files().answer_next(picked)
|
||||
}
|
||||
}
|
||||
|
||||
impl WordApp {
|
||||
/// The host the frame hands every viewport's `Env`. In the windowless trial it carries [`RowFiles`] over the app's
|
||||
/// own host, built again only when that host is (a language change); otherwise the app's own host, unchanged.
|
||||
pub(crate) fn frame_host(&mut self) -> Arc<Host> {
|
||||
if !self.windows.windowless_trial() {
|
||||
return self.host.clone();
|
||||
}
|
||||
let generation = self.host.generation();
|
||||
if let Some((built, host)) = &self.owned_picks.env_host
|
||||
&& *built == generation
|
||||
{
|
||||
return host.clone();
|
||||
}
|
||||
let files = RowFiles::new(self.host.clone(), self.owned_picks.rows.clone());
|
||||
let host = Arc::new(self.host.with_files(Arc::new(files)));
|
||||
self.owned_picks.env_host = Some((generation, host.clone()));
|
||||
host
|
||||
}
|
||||
|
||||
/// The exact native window window `window` showing `document` draws in now, from the desktop's lookup.
|
||||
fn row_surface(&self, ctx: &egui::Context, window: u64, document: u64) -> RowSurface {
|
||||
match self.pick_owner_surface(ctx, window, document) {
|
||||
crate::windows::OwnerSurface::Attached { viewport, attempt } => {
|
||||
self.live_native_owner(viewport, attempt).map(|native| (native.viewport, native.attempt, native.incarnation))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Start drawing the shown window: `PathRow` picks filed until [`leave_row_scope`](Self::leave_row_scope) belong
|
||||
/// to it, the document it shows and the native window it draws in now. `None` outside the trial, where nothing
|
||||
/// changes.
|
||||
pub(crate) fn enter_row_scope(&mut self, ctx: &egui::Context) -> Option<Entered> {
|
||||
if !self.windows.windowless_trial() {
|
||||
return None;
|
||||
}
|
||||
let owner = RowOwner { window: self.windows.shown(), document: self.shown_document };
|
||||
let surface = self.row_surface(ctx, owner.window, owner.document);
|
||||
let scope = Scope { owner, surface, ctx: ctx.clone(), forms: Vec::new() };
|
||||
let previous = self.owned_picks.rows.lock().scope.replace(scope);
|
||||
Some(Entered { window: owner.window, previous })
|
||||
}
|
||||
|
||||
/// End the drawing [`enter_row_scope`](Self::enter_row_scope) began, putting back the scope it replaced (a nested
|
||||
/// drawing's caller's, else none), then hand that window's picks to the owned route. Runs however the drawing
|
||||
/// ended, also when it brought another window's state in.
|
||||
pub(crate) fn leave_row_scope(&mut self, entered: Option<Entered>) {
|
||||
let Some(Entered { window, previous }) = entered else { return };
|
||||
self.owned_picks.rows.lock().scope = previous;
|
||||
self.admit_row_picks(Some(window));
|
||||
}
|
||||
|
||||
/// Right before the drawn window's dialog run: its dialog openings, so a pick filed in the run is bound to the
|
||||
/// exact opening running it. Every dialog the run shows is open before it starts.
|
||||
pub(crate) fn begin_row_forms(&mut self) {
|
||||
if !self.windows.windowless_trial() {
|
||||
return;
|
||||
}
|
||||
let forms: Vec<(DialogId, u64)> =
|
||||
self.dialog_host.open_dialogs().iter().filter_map(|dialog| Some((dialog.id, self.dialog_host.open_serial(dialog.id)?))).collect();
|
||||
if let Some(scope) = self.owned_picks.rows.lock().scope.as_mut() {
|
||||
scope.forms = forms;
|
||||
}
|
||||
}
|
||||
|
||||
/// Right after the drawn window's dialog run: a pick filed after it is outside every dialog.
|
||||
pub(crate) fn end_row_forms(&mut self) {
|
||||
if !self.windows.windowless_trial() {
|
||||
return;
|
||||
}
|
||||
if let Some(scope) = self.owned_picks.rows.lock().scope.as_mut() {
|
||||
scope.forms.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// Hand staged `PathRow` picks (`window`'s, or every window's) to the owned route, bound to the window, document,
|
||||
/// native window and dialog opening they were filed from. A pick whose window no longer stands so, or whose
|
||||
/// window already has a pick, answers its row Cancelled. Then cancel forgotten row tickets and drop answers whose
|
||||
/// window, document or dialog opening is gone.
|
||||
pub(crate) fn admit_row_picks(&mut self, window: Option<u64>) {
|
||||
let rows = self.owned_picks.rows.clone();
|
||||
let ctx = self.ctx.clone().unwrap_or_default();
|
||||
for Staged { id, owner, form, surface, request } in rows.take_staged(window) {
|
||||
let current = self.row_form_live(owner.window, owner.document, form)
|
||||
&& (surface.is_none() || self.row_surface(&ctx, owner.window, owner.document) == surface);
|
||||
if !current {
|
||||
self.status(tl!("The document window for this file dialog changed. Try again."));
|
||||
rows.answer(id, owner, form, surface, Picked::Cancelled);
|
||||
continue;
|
||||
}
|
||||
let target = RowTarget { id, form, surface };
|
||||
// Busy (the window has a pick) says so in its status line.
|
||||
if let Asked::Busy = self.push_owned_pick(owner.window, owner.document, request, AfterPick::Row(target)) {
|
||||
rows.answer(id, owner, form, surface, Picked::Cancelled);
|
||||
}
|
||||
}
|
||||
let forgotten = std::mem::take(&mut rows.lock().forgotten);
|
||||
if !forgotten.is_empty() {
|
||||
let (gone, kept): (Vec<_>, Vec<_>) = std::mem::take(&mut self.owned_picks.jobs)
|
||||
.into_iter()
|
||||
.partition(|job| matches!(&job.after, AfterPick::Row(row) if forgotten.contains(&row.id)));
|
||||
self.owned_picks.jobs = kept;
|
||||
for job in gone {
|
||||
self.cancel_owned_pick(&ctx, job, PickEnd::Forgotten);
|
||||
}
|
||||
}
|
||||
rows.prune(|owner, form| self.row_form_live(owner.window, owner.document, form));
|
||||
}
|
||||
|
||||
/// Whether window `window` still shows open `document` and, for a pick filed from a dialog, that same opening of it
|
||||
/// is still open on the window's own host (a closed and reopened dialog is another opening).
|
||||
pub(crate) fn row_form_live(&self, window: u64, document: u64, form: RowForm) -> bool {
|
||||
self.window_shows_document(window, document)
|
||||
&& form.is_none_or(|(id, serial)| self.window_dialog_host(window).is_some_and(|host| host.open_serial(id) == Some(serial)))
|
||||
}
|
||||
|
||||
/// Tell a row its pick will not open (the window's close or quit prompt took its place): Cancelled under its
|
||||
/// ticket, bound as it was filed, so only that row reads it.
|
||||
pub(super) fn cancel_row_pick(&mut self, window: u64, document: u64, row: RowTarget) {
|
||||
self.owned_picks.rows.answer(row.id, RowOwner { window, document }, row.form, row.surface, Picked::Cancelled);
|
||||
}
|
||||
|
||||
/// Post a settled row pick's answer under its exact ticket, bound to the native window it was pinned to (or, for
|
||||
/// an owner that had none at filing, the one it has now); its row takes it on the owner's next draw. A system
|
||||
/// dialog that could not show, or failed, says so in the owner window.
|
||||
pub(super) fn settle_row_pick(
|
||||
&mut self,
|
||||
window: u64,
|
||||
document: u64,
|
||||
row: RowTarget,
|
||||
pin: Option<NativeOwner>,
|
||||
picked: Picked,
|
||||
) -> serde_json::Value {
|
||||
let note = match &picked {
|
||||
Picked::Unavailable(cause) => Some(craft::dialogs::ui::UnavailableWords::default().sentence(cause)),
|
||||
Picked::Failed(reason) => Some(reason.clone()),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(note) = note {
|
||||
let previous = self.windows.shown();
|
||||
if self.enter_window(window) {
|
||||
self.status(note);
|
||||
self.enter_window(previous);
|
||||
}
|
||||
}
|
||||
let ctx = self.ctx.clone().unwrap_or_default();
|
||||
let surface = pin
|
||||
.map(|native| (native.viewport, native.attempt, native.incarnation))
|
||||
.or(row.surface)
|
||||
.or_else(|| self.row_surface(&ctx, window, document));
|
||||
let cancelled = picked.first_path().is_none();
|
||||
self.owned_picks.rows.answer(row.id, RowOwner { window, document }, row.form, surface, picked);
|
||||
// The owner draws in its own viewport; every viewport is asked, as the owner's is not known here.
|
||||
ctx.request_repaint();
|
||||
serde_json::json!({"cancelled": cancelled})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
@@ -0,0 +1,238 @@
|
||||
//! The `PathRow` route in the windowless trial, driven through real frames: each window draws (`draw_entry`, its dialog
|
||||
//! run), and a dialog files and reads picks through the `Env` host exactly as `PathRow::show` does with `.pick(..)`
|
||||
//! (`host.files().pick` on Browse, `take_answer` for its ticket on later passes). The in-app chooser stands in for the
|
||||
//! system dialog (`fallback_chooser`); which native window parents a panel is the owned route's own tests.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use craft::dialogs::ui::FileChooser;
|
||||
use craft::host::{PickId, PickRequest, Picked, ScriptedFiles};
|
||||
use craft::ui::dialog::{DialogId, DialogResult, DialogStack, StackDialog, dialog_id};
|
||||
use craft::ui::runtime::env::Env;
|
||||
use serde_json::json;
|
||||
|
||||
use super::super::{AfterPick, NativeWindowLookup};
|
||||
use crate::{Services, WordApp};
|
||||
use wordcraft_engine::Session;
|
||||
|
||||
/// What a path row holds: its ticket, the answers it took, and a Browse press for its next pass.
|
||||
#[derive(Default)]
|
||||
struct Row {
|
||||
browse: bool,
|
||||
ticket: Option<PickId>,
|
||||
got: Vec<Picked>,
|
||||
}
|
||||
|
||||
/// A dialog with one path row, doing what `PathRow::show` does through the `Env` host: take its ticket's answer,
|
||||
/// then file a pick when Browse was pressed.
|
||||
struct RowDialog {
|
||||
row: Arc<Mutex<Row>>,
|
||||
}
|
||||
|
||||
impl StackDialog for RowDialog {
|
||||
type Result = ();
|
||||
|
||||
fn id(&self) -> DialogId {
|
||||
dialog_id("pathRowFixture")
|
||||
}
|
||||
|
||||
fn show(&mut self, ui: &mut egui::Ui, _: &DialogStack) -> Option<DialogResult<()>> {
|
||||
let host = Env::of(ui).view().host().cloned()?;
|
||||
let mut row = self.row.lock().unwrap();
|
||||
if let Some(ticket) = row.ticket
|
||||
&& let Some(picked) = host.files().take_answer(ticket)
|
||||
{
|
||||
row.ticket = None;
|
||||
row.got.push(picked);
|
||||
}
|
||||
if std::mem::take(&mut row.browse) {
|
||||
row.ticket = Some(host.files().pick(PickRequest::open("template")));
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Another dialog, opened over the row's.
|
||||
struct Cover;
|
||||
|
||||
impl StackDialog for Cover {
|
||||
type Result = ();
|
||||
|
||||
fn id(&self) -> DialogId {
|
||||
dialog_id("pathRowCover")
|
||||
}
|
||||
|
||||
fn show(&mut self, _: &mut egui::Ui, _: &DialogStack) -> Option<DialogResult<()>> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// The desktop's native windows: viewport to the incarnation of its live window.
|
||||
#[derive(Default)]
|
||||
struct Natives(Mutex<HashMap<egui::ViewportId, std::num::NonZeroU64>>);
|
||||
|
||||
impl NativeWindowLookup for Natives {
|
||||
fn incarnation(&self, viewport: egui::ViewportId) -> Option<std::num::NonZeroU64> {
|
||||
self.0.lock().unwrap().get(&viewport).copied()
|
||||
}
|
||||
}
|
||||
|
||||
/// Two windows in the windowless trial, each on its own unsaved document, using the in-app chooser.
|
||||
fn two_windows() -> (WordApp, Arc<ScriptedFiles>, egui::Context, u64, u64) {
|
||||
let files = Arc::new(ScriptedFiles::held());
|
||||
let host =
|
||||
craft::host::Host::builder(craft::host::AppInfo { id: "wordcraft-test", name: "WordCraft", version: "0" }).files(files.clone()).build();
|
||||
let mut app = WordApp::new(Session::new(wordcraft_doc::Document::new()), Services::default()).with_host(Arc::new(host));
|
||||
app.enable_windowless_trial(true);
|
||||
app.fallback_chooser = true;
|
||||
app.run("text.insert", json!({"text": "First"})).unwrap();
|
||||
let first = app.windows.shown();
|
||||
app.run("file.new", json!({})).unwrap();
|
||||
app.run("text.insert", json!({"text": "Peer"})).unwrap();
|
||||
let peer = app.windows.shown();
|
||||
assert_ne!(first, peer);
|
||||
(app, files, crate::test_harness::context(), first, peer)
|
||||
}
|
||||
|
||||
/// Open a row dialog on window `window`'s host.
|
||||
fn row_dialog(app: &mut WordApp, window: u64) -> (DialogId, Arc<Mutex<Row>>) {
|
||||
let row = Arc::new(Mutex::new(Row::default()));
|
||||
assert!(app.enter_window(window));
|
||||
(app.dialog_host_mut().open(RowDialog { row: row.clone() }), row)
|
||||
}
|
||||
|
||||
/// One frame drawing window `window`.
|
||||
fn draw(app: &mut WordApp, ctx: &egui::Context, window: u64) {
|
||||
app.show_window(window);
|
||||
crate::test_harness::pass(ctx, app, egui::RawInput::default());
|
||||
}
|
||||
|
||||
/// Press Browse in window `window`'s row and draw the frame that files it.
|
||||
fn browse(app: &mut WordApp, ctx: &egui::Context, window: u64, row: &Arc<Mutex<Row>>) -> PickId {
|
||||
row.lock().unwrap().browse = true;
|
||||
draw(app, ctx, window);
|
||||
row.lock().unwrap().ticket.expect("the row filed its pick")
|
||||
}
|
||||
|
||||
fn pump(app: &mut WordApp, ctx: &egui::Context) {
|
||||
app.pump_windowless_save_as(ctx, |panels, host| panels.pump_with::<eframe::Frame>(host, None));
|
||||
}
|
||||
|
||||
fn row_target(app: &WordApp) -> super::RowTarget {
|
||||
match &app.owned_picks.jobs[..] {
|
||||
[job] => match &job.after {
|
||||
AfterPick::Row(target) => *target,
|
||||
_ => panic!("the pick is the row's"),
|
||||
},
|
||||
jobs => panic!("one owned pick, not {}", jobs.len()),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_row_pick_is_bound_to_the_dialog_running_it_not_the_top_one() {
|
||||
let (mut app, _, ctx, first, _) = two_windows();
|
||||
let (form, row) = row_dialog(&mut app, first);
|
||||
app.dialog_host_mut().open(Cover);
|
||||
let top = app.dialog_host_mut().open_dialogs().last().unwrap().id;
|
||||
assert_ne!(top, form, "the fixture covers the row's dialog");
|
||||
browse(&mut app, &ctx, first, &row);
|
||||
let serial = app.window_dialog_host(first).unwrap().open_serial(form);
|
||||
assert_eq!(row_target(&app).form, Some((form, serial.unwrap())), "bound to the row's own opening when it was filed");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_row_answer_reaches_only_its_row_in_its_own_window() {
|
||||
let (mut app, files, ctx, first, peer) = two_windows();
|
||||
let dir = std::env::temp_dir().join(format!("wordcraft-path-rows-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let template = dir.join("letter.dotx");
|
||||
std::fs::write(&template, b"template").unwrap();
|
||||
let (_, row) = row_dialog(&mut app, first);
|
||||
let (_, peer_row) = row_dialog(&mut app, peer);
|
||||
browse(&mut app, &ctx, first, &row);
|
||||
draw(&mut app, &ctx, peer);
|
||||
pump(&mut app, &ctx);
|
||||
assert!(!app.window_dialog_host_mut(peer).unwrap().is_open::<FileChooser>(), "nothing opens on the focused peer");
|
||||
let host = app.window_dialog_host_mut(first).unwrap();
|
||||
let chooser = host.get::<FileChooser>().expect("the chooser opens on the row's window").id();
|
||||
host.set_json_field(&ctx, chooser, "folder", json!(dir)).unwrap();
|
||||
host.set_json_field(&ctx, chooser, "name", json!("letter.dotx")).unwrap();
|
||||
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(5);
|
||||
while !app.window_dialog_host_mut(first).unwrap().confirm_by_id(&ctx, chooser) {
|
||||
assert!(std::time::Instant::now() < deadline, "the chooser lists the folder");
|
||||
std::thread::sleep(std::time::Duration::from_millis(5));
|
||||
}
|
||||
pump(&mut app, &ctx);
|
||||
// The peer draws while the answer settles: it is not the peer's.
|
||||
draw(&mut app, &ctx, peer);
|
||||
assert!(app.owned_picks.jobs.is_empty(), "settled");
|
||||
assert!(row.lock().unwrap().got.is_empty() && peer_row.lock().unwrap().got.is_empty());
|
||||
draw(&mut app, &ctx, first);
|
||||
let got = row.lock().unwrap().got.iter().map(|picked| picked.first_path().and_then(|p| p.file_name().map(|n| n.to_owned()))).collect::<Vec<_>>();
|
||||
assert_eq!(got, vec![template.file_name().map(|n| n.to_owned())], "its own row takes the chosen file, once");
|
||||
draw(&mut app, &ctx, first);
|
||||
assert_eq!(row.lock().unwrap().got.len(), 1);
|
||||
assert!(peer_row.lock().unwrap().got.is_empty());
|
||||
assert!(files.requests().is_empty(), "the app's shared file service never saw the pick");
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_row_answer_is_not_read_after_its_native_window_is_recreated() {
|
||||
let (mut app, _, ctx, first, peer) = two_windows();
|
||||
let natives = Arc::new(Natives::default());
|
||||
let viewport = egui::ViewportId::from_hash_of("first");
|
||||
app.attach_window_for_test(first, viewport);
|
||||
natives.0.lock().unwrap().insert(viewport, std::num::NonZeroU64::new(1).unwrap());
|
||||
app.set_native_window_lookup(Some(natives.clone() as Arc<dyn NativeWindowLookup + Send + Sync>));
|
||||
let (_, row) = row_dialog(&mut app, first);
|
||||
browse(&mut app, &ctx, first, &row);
|
||||
assert!(row_target(&app).surface.is_some(), "filed on a named native window");
|
||||
pump(&mut app, &ctx);
|
||||
assert!(app.window_dialog_host_mut(first).unwrap().cancel::<FileChooser>(&ctx));
|
||||
pump(&mut app, &ctx);
|
||||
draw(&mut app, &ctx, peer);
|
||||
assert!(app.owned_picks.jobs.is_empty(), "posted for the row");
|
||||
// The OS window is recreated under the same viewport after the answer was posted, before the row reads it.
|
||||
natives.0.lock().unwrap().insert(viewport, std::num::NonZeroU64::new(2).unwrap());
|
||||
draw(&mut app, &ctx, first);
|
||||
draw(&mut app, &ctx, first);
|
||||
assert!(row.lock().unwrap().got.is_empty(), "an answer for the earlier native window is never read");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_reopened_dialog_never_reads_the_earlier_openings_answer() {
|
||||
let (mut app, _, ctx, first, peer) = two_windows();
|
||||
let (form, row) = row_dialog(&mut app, first);
|
||||
let ticket = browse(&mut app, &ctx, first, &row);
|
||||
pump(&mut app, &ctx);
|
||||
assert!(app.window_dialog_host_mut(first).unwrap().cancel::<FileChooser>(&ctx));
|
||||
pump(&mut app, &ctx);
|
||||
draw(&mut app, &ctx, peer);
|
||||
assert!(app.owned_picks.jobs.is_empty(), "posted for the row");
|
||||
// The same dialog closes and opens again before its row draws; the new row even holds the old ticket.
|
||||
assert!(app.enter_window(first));
|
||||
assert!(app.dialog_host_mut().cancel_by_id(&ctx, form));
|
||||
let reopened = Arc::new(Mutex::new(Row { ticket: Some(ticket), ..Row::default() }));
|
||||
assert_eq!(app.dialog_host_mut().open(RowDialog { row: reopened.clone() }), form);
|
||||
draw(&mut app, &ctx, first);
|
||||
draw(&mut app, &ctx, first);
|
||||
assert!(reopened.lock().unwrap().got.is_empty(), "another opening of the same dialog gets nothing");
|
||||
assert!(row.lock().unwrap().got.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn picks_outside_a_window_drawing_open_nothing_and_outside_the_trial_the_host_is_the_apps() {
|
||||
let (mut app, files, _, _, _) = two_windows();
|
||||
let host = app.frame_host();
|
||||
let ticket = host.files().pick(PickRequest::open("document"));
|
||||
app.admit_row_picks(None);
|
||||
assert!(app.owned_picks.jobs.is_empty(), "no window is made the owner of a pick filed outside every drawing");
|
||||
assert_eq!(host.files().take_answer(ticket), Some(Picked::Cancelled));
|
||||
assert!(files.requests().is_empty(), "nothing went to the shared service either");
|
||||
|
||||
let plain = Arc::new(craft::host::Host::builder(craft::host::AppInfo { id: "wordcraft-test", name: "WordCraft", version: "0" }).build());
|
||||
let mut ordinary = WordApp::new(Session::new(wordcraft_doc::Document::new()), Services::default()).with_host(plain.clone());
|
||||
assert!(Arc::ptr_eq(&ordinary.frame_host(), &plain), "ordinary windows and the web keep the app's own host");
|
||||
}
|
||||
@@ -1041,3 +1041,884 @@ fn web_export_downloads_a_copy_and_keeps_unsaved_changes() {
|
||||
assert_eq!(a.session.doc.core.revision, revision, "{ext}: the document's save stamps are untouched");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn two_windowless_drafts() -> (WordApp, Arc<ScriptedFiles>, u64, u64, u64, u64) {
|
||||
let (mut app, files) = async_app();
|
||||
app.enable_windowless_trial(true);
|
||||
app.run("text.insert", json!({"text": "First unsaved draft"})).unwrap();
|
||||
let (first, first_doc) = (app.windows.shown(), app.session.document_id());
|
||||
app.run("file.new", json!({})).unwrap();
|
||||
app.run("text.insert", json!({"text": "Peer unsaved draft"})).unwrap();
|
||||
let (peer, peer_doc) = (app.windows.shown(), app.session.document_id());
|
||||
assert_ne!(first, peer);
|
||||
assert_ne!(first_doc, peer_doc);
|
||||
assert!(app.session.path.is_none() && app.session.document_dirty(first_doc) && app.session.document_dirty(peer_doc));
|
||||
(app, files, first, first_doc, peer, peer_doc)
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn begin_trial_save(app: &mut WordApp, first: u64, peer: u64) {
|
||||
app.close_window(first);
|
||||
assert_eq!(app.run("ui.saveChanges", json!({"answer": "save"})).unwrap()["pending"], "saveAs");
|
||||
app.show_window(peer);
|
||||
assert_eq!(app.windows.shown(), peer, "the peer takes focus before the next panel pump");
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn pump_trial_save(app: &mut WordApp, ctx: &egui::Context) {
|
||||
app.pump_windowless_save_as(ctx, |panels, host| panels.pump_with::<eframe::Frame>(host, None));
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn choose_trial_save_path(app: &mut WordApp, ctx: &egui::Context, window: u64, path: &std::path::Path) {
|
||||
let host = app.window_dialog_host_mut(window).unwrap();
|
||||
let chooser = host.get::<FileChooser>().unwrap().id();
|
||||
host.set_json_field(ctx, chooser, "folder", json!(path.parent().unwrap())).unwrap();
|
||||
host.set_json_field(ctx, chooser, "name", json!(path.file_name().unwrap().to_string_lossy())).unwrap();
|
||||
// The real chooser waits for its background folder listing before accepting a new path.
|
||||
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(5);
|
||||
loop {
|
||||
if host.confirm_by_id(ctx, chooser) {
|
||||
break;
|
||||
}
|
||||
assert!(std::time::Instant::now() < deadline, "the temporary folder should become available to the chooser");
|
||||
std::thread::sleep(std::time::Duration::from_millis(5));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn windowless_untitled_close_save_as_stays_with_its_document_after_peer_focus() {
|
||||
let (mut app, files, first, first_doc, peer, peer_doc) = two_windowless_drafts();
|
||||
let dir = scratch("windowless-save-as");
|
||||
let destination = dir.join("draft.docx");
|
||||
let ctx = egui::Context::default();
|
||||
|
||||
begin_trial_save(&mut app, first, peer);
|
||||
pump_trial_save(&mut app, &ctx);
|
||||
assert_eq!(app.session.document_id(), peer_doc);
|
||||
assert!(!app.dialog_host_mut().is_open::<FileChooser>(), "the chooser is not on the focused peer's host");
|
||||
assert!(app.window_dialog_host_mut(first).unwrap().cancel::<FileChooser>(&ctx), "the initiating window owns the in-app chooser");
|
||||
pump_trial_save(&mut app, &ctx);
|
||||
assert_eq!(app.poll_file_dialog().unwrap().unwrap()["done"], false);
|
||||
assert!(!destination.exists() && !app.quit_requested);
|
||||
assert_eq!(app.window_count(), 2);
|
||||
assert!(app.session.document_dirty(first_doc) && app.session.document_dirty(peer_doc));
|
||||
assert!(app.enter_window(first));
|
||||
assert!(app.session.path.is_none());
|
||||
assert_eq!(body_text(&app).trim(), "First unsaved draft");
|
||||
assert!(app.enter_window(peer));
|
||||
assert!(app.session.path.is_none());
|
||||
assert_eq!(body_text(&app).trim(), "Peer unsaved draft");
|
||||
|
||||
let sentinel = b"Existing file stays until Replace is answered";
|
||||
std::fs::write(&destination, sentinel).unwrap();
|
||||
begin_trial_save(&mut app, first, peer);
|
||||
pump_trial_save(&mut app, &ctx);
|
||||
// The chooser answers the bare name; adding .docx produces a collision the panels must ask about.
|
||||
choose_trial_save_path(&mut app, &ctx, first, &destination.with_extension(""));
|
||||
pump_trial_save(&mut app, &ctx);
|
||||
assert!(app.poll_file_dialog().is_none());
|
||||
assert_eq!(std::fs::read(&destination).unwrap(), sentinel);
|
||||
assert!(!app.dialog_host_mut().is_open::<StandardPrompt>());
|
||||
assert!(app.window_dialog_host_mut(first).unwrap().confirm::<StandardPrompt>(&ctx), "the initiating window also owns Replace");
|
||||
pump_trial_save(&mut app, &ctx);
|
||||
assert_eq!(app.poll_file_dialog().unwrap().unwrap()["done"], true);
|
||||
let saved = saved_text(&destination);
|
||||
assert!(saved.contains("First unsaved draft"));
|
||||
assert!(!saved.contains("Peer unsaved draft"));
|
||||
assert!(!app.session.is_open(first_doc) && !app.quit_requested);
|
||||
assert_eq!(app.window_count(), 1);
|
||||
assert_eq!(app.session.document_id(), peer_doc);
|
||||
assert!(app.session.dirty && app.session.path.is_none());
|
||||
assert_eq!(body_text(&app).trim(), "Peer unsaved draft");
|
||||
assert!(files.requests().is_empty(), "the shared native file service never received the request");
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn windowless_save_as_discards_its_late_answer_when_the_owner_closes() {
|
||||
let (mut app, files, first, first_doc, peer, peer_doc) = two_windowless_drafts();
|
||||
let dir = scratch("windowless-stale-save-as");
|
||||
let destination = dir.join("stale.docx");
|
||||
let ctx = egui::Context::default();
|
||||
begin_trial_save(&mut app, first, peer);
|
||||
pump_trial_save(&mut app, &ctx);
|
||||
choose_trial_save_path(&mut app, &ctx, first, &destination);
|
||||
pump_trial_save(&mut app, &ctx);
|
||||
// Put the answer in the service, then invalidate the owner before WordApp sees it.
|
||||
app.session.close_document(first_doc).unwrap();
|
||||
app.prune_windows();
|
||||
assert!(app.poll_file_dialog().is_none());
|
||||
app.pump_windowless_save_as(&ctx, |_, _| panic!("a stale job must not be pumped on the survivor"));
|
||||
assert!(!destination.exists() && !app.quit_requested);
|
||||
assert_eq!(app.session.document_id(), peer_doc);
|
||||
assert!(app.session.dirty && app.session.path.is_none());
|
||||
assert_eq!(body_text(&app).trim(), "Peer unsaved draft");
|
||||
app.close_window(peer);
|
||||
assert_eq!(app.run("ui.saveChanges", json!({"answer": "save"})).unwrap()["pending"], "saveAs");
|
||||
pump_trial_save(&mut app, &ctx);
|
||||
assert!(app.dialog_host_mut().is_open::<FileChooser>(), "a fresh ticket can open on the survivor's own host");
|
||||
assert!(files.requests().is_empty(), "no routed ticket leaked into the shared file service");
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn windowless_save_as_does_not_cancel_a_later_replace_prompt_with_the_same_id() {
|
||||
let (mut app, _, first, first_doc, peer, peer_doc) = two_windowless_drafts();
|
||||
let dir = scratch("windowless-reused-replace");
|
||||
let destination = dir.join("existing.docx");
|
||||
let sentinel = b"Existing file";
|
||||
std::fs::write(&destination, sentinel).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
|
||||
begin_trial_save(&mut app, first, peer);
|
||||
pump_trial_save(&mut app, &ctx);
|
||||
choose_trial_save_path(&mut app, &ctx, first, &destination.with_extension(""));
|
||||
pump_trial_save(&mut app, &ctx);
|
||||
let ticket = app.owned_picks.jobs[0].ticket.as_ref().unwrap().id.0;
|
||||
let host = app.window_dialog_host_mut(first).unwrap();
|
||||
let first_prompt = host.get::<StandardPrompt>().unwrap().id();
|
||||
let first_serial = host.open_serial(first_prompt).unwrap();
|
||||
// Another panel service can produce the same instance key from its own local ticket count.
|
||||
let unrelated = host.open(StandardPrompt::replace_file("other.docx", None).instance(("craft-dialogs.replace", ticket)));
|
||||
assert_eq!(unrelated, first_prompt, "the fixture must reuse the framework's Replace ID");
|
||||
let unrelated_serial = host.open_serial(unrelated).unwrap();
|
||||
assert_ne!(unrelated_serial, first_serial);
|
||||
|
||||
app.pump_windowless_save_as(&ctx, |_, _| panic!("a displaced job must not collect the later prompt's answer"));
|
||||
assert!(!app.file_dialog_open() && app.closing.is_none());
|
||||
assert_eq!(app.window_dialog_host_mut(first).unwrap().open_serial(unrelated), Some(unrelated_serial));
|
||||
assert_eq!(std::fs::read(&destination).unwrap(), sentinel);
|
||||
assert!(app.session.document_dirty(first_doc) && app.session.document_dirty(peer_doc));
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn windowless_save_as_cancels_when_its_own_surface_is_rejected() {
|
||||
let (mut app, files, first, first_doc, peer, peer_doc) = two_windowless_drafts();
|
||||
let ctx = egui::Context::default();
|
||||
begin_trial_save(&mut app, first, peer);
|
||||
pump_trial_save(&mut app, &ctx);
|
||||
app.cancel_windowless_save_as_for_mount_failure(&ctx, peer);
|
||||
assert_eq!(app.owned_picks.jobs.len(), 1, "a rejected peer is not the picker's owner");
|
||||
assert!(app.window_dialog_host_mut(first).unwrap().is_open::<FileChooser>());
|
||||
|
||||
app.cancel_windowless_save_as_for_mount_failure(&ctx, first);
|
||||
assert!(app.owned_picks.jobs.is_empty() && app.closing.is_none());
|
||||
assert!(!app.window_dialog_host_mut(first).unwrap().is_open::<FileChooser>());
|
||||
assert!(app.session.document_dirty(first_doc) && app.session.document_dirty(peer_doc));
|
||||
assert_eq!(app.session.document_id(), peer_doc);
|
||||
assert!(files.requests().is_empty());
|
||||
assert!(!app.quit_requested);
|
||||
}
|
||||
|
||||
/// The desktop's native windows, for routing tests: viewport to the incarnation of its live
|
||||
/// native window, changed by the test to model attach, detach and recreation.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[derive(Default)]
|
||||
struct TestWindows(std::sync::Mutex<std::collections::HashMap<egui::ViewportId, std::num::NonZeroU64>>);
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
impl TestWindows {
|
||||
fn set(&self, viewport: egui::ViewportId, incarnation: Option<u64>) {
|
||||
let mut map = self.0.lock().unwrap();
|
||||
match incarnation {
|
||||
Some(n) => map.insert(viewport, nz(n)),
|
||||
None => map.remove(&viewport),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
impl NativeWindowLookup for TestWindows {
|
||||
fn incarnation(&self, viewport: egui::ViewportId) -> Option<std::num::NonZeroU64> {
|
||||
self.0.lock().unwrap().get(&viewport).copied()
|
||||
}
|
||||
}
|
||||
|
||||
/// The desktop's panel pumps, for routing tests. Its panels are scripted (`SCRIPTED_PANELS`),
|
||||
/// so a test never shows a system dialog: this checks routing, ownership and lease bookkeeping,
|
||||
/// not that a native panel looks or parents right, nor native window lifetime.
|
||||
///
|
||||
/// `pending` models a system dialog whose backend has not answered yet. The pinned SDK has no
|
||||
/// public panel that stays open after its queue drains (its scripted panels answer at once), so
|
||||
/// while pending the double pumps nothing at all, neither the launch nor later pumps; the first
|
||||
/// pump after release drains, shows and answers in one go. The launch itself is still exact: it
|
||||
/// happens only through `pump_parented` on the pinned window, and returns its lease.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[derive(Default)]
|
||||
struct Desk {
|
||||
lookup: Arc<TestWindows>,
|
||||
parented: Vec<(egui::ViewportId, std::num::NonZeroU64)>,
|
||||
unparented: usize,
|
||||
/// Each viewport's stand-in for its window; a lease holds a clone.
|
||||
windows: std::collections::HashMap<egui::ViewportId, Arc<()>>,
|
||||
pending: bool,
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
impl Desk {
|
||||
fn leases(&self, viewport: egui::ViewportId) -> usize {
|
||||
self.windows.get(&viewport).map_or(0, |w| Arc::strong_count(w) - 1)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
impl OwnerPanels for Desk {
|
||||
fn pump_parented(
|
||||
&mut self,
|
||||
viewport: egui::ViewportId,
|
||||
incarnation: std::num::NonZeroU64,
|
||||
panels: &mut FilePanels,
|
||||
host: &mut DialogHost,
|
||||
) -> Option<ParentLease> {
|
||||
if self.lookup.incarnation(viewport) != Some(incarnation) {
|
||||
return None;
|
||||
}
|
||||
assert!(SCRIPTED_PANELS.with(|s| s.borrow().is_some()), "a routing test never shows a real system dialog");
|
||||
self.parented.push((viewport, incarnation));
|
||||
if !self.pending {
|
||||
panels.pump_with::<eframe::Frame>(host, None);
|
||||
}
|
||||
Some(ParentLease::new(self.windows.entry(viewport).or_default().clone()))
|
||||
}
|
||||
fn pump_unparented(&mut self, panels: &mut FilePanels, host: &mut DialogHost) {
|
||||
self.unparented += 1;
|
||||
if !self.pending {
|
||||
panels.pump_with::<eframe::Frame>(host, None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn nz(n: u64) -> std::num::NonZeroU64 {
|
||||
std::num::NonZeroU64::new(n).unwrap()
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn script_panels(answers: Vec<craft::dialogs::Answer>) {
|
||||
script_each_panel(vec![answers]);
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn script_each_panel(lists: Vec<Vec<craft::dialogs::Answer>>) {
|
||||
SCRIPTED_PANELS.with(|s| *s.borrow_mut() = Some(lists.into()));
|
||||
}
|
||||
|
||||
/// A desk whose lookup the app reads, and a context the app knows (the gesture reads surfaces).
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn connect_desk(app: &mut WordApp) -> (Desk, egui::Context) {
|
||||
let desk = Desk::default();
|
||||
app.set_native_window_lookup(Some(desk.lookup.clone()));
|
||||
let ctx = egui::Context::default();
|
||||
app.ctx = Some(ctx.clone());
|
||||
(desk, ctx)
|
||||
}
|
||||
|
||||
/// Two drafts whose windows are attached at their own viewports, both with live native windows.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn attached_drafts() -> (WordApp, Arc<ScriptedFiles>, u64, u64, u64, u64, Desk, egui::Context) {
|
||||
let (mut app, files, first, first_doc, peer, peer_doc) = two_windowless_drafts();
|
||||
let (desk, ctx) = connect_desk(&mut app);
|
||||
app.attach_window_for_test(first, va());
|
||||
app.attach_window_for_test(peer, vb());
|
||||
desk.lookup.set(va(), Some(1));
|
||||
desk.lookup.set(vb(), Some(2));
|
||||
(app, files, first, first_doc, peer, peer_doc, desk, ctx)
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn va() -> egui::ViewportId {
|
||||
egui::ViewportId::from_hash_of("first")
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn vb() -> egui::ViewportId {
|
||||
egui::ViewportId::from_hash_of("peer")
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn next_pass(ctx: &egui::Context) {
|
||||
ctx.run_ui(Default::default(), |_| {}).drop_without_applying_deltas();
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn windowless_save_as_opens_the_system_dialog_on_its_own_window_after_peer_focus() {
|
||||
let (mut app, files, first, first_doc, peer, peer_doc, mut desk, ctx) = attached_drafts();
|
||||
let dir = scratch("windowless-native-save-as");
|
||||
let destination = dir.join("draft.docx");
|
||||
script_panels(vec![craft::dialogs::Answer::Saved { path: destination.clone(), filter: None }]);
|
||||
|
||||
begin_trial_save(&mut app, first, peer);
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert_eq!(desk.parented, vec![(va(), nz(1))], "only the initiating window's live native window parents the dialog");
|
||||
assert_eq!(desk.unparented, 0);
|
||||
assert!(!app.dialog_host_mut().is_open::<FileChooser>() && !app.window_dialog_host_mut(first).unwrap().is_open::<FileChooser>());
|
||||
assert_eq!(desk.leases(va()), 0, "an answered panel no longer holds its window");
|
||||
assert_eq!(app.poll_file_dialog().unwrap().unwrap()["done"], true);
|
||||
let saved = saved_text(&destination);
|
||||
assert!(saved.contains("First unsaved draft") && !saved.contains("Peer unsaved draft"));
|
||||
assert!(!app.session.is_open(first_doc) && !app.quit_requested);
|
||||
assert_eq!(app.session.document_id(), peer_doc);
|
||||
assert!(app.session.dirty && app.session.path.is_none());
|
||||
assert!(files.requests().is_empty(), "the shared file service never received the request");
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn windowless_save_as_pinned_at_the_gesture_ends_if_its_window_is_recreated_before_launch() {
|
||||
let (mut app, _, first, first_doc, peer, peer_doc, mut desk, ctx) = attached_drafts();
|
||||
script_panels(vec![craft::dialogs::Answer::Cancelled]);
|
||||
begin_trial_save(&mut app, first, peer);
|
||||
// Recreated between the gesture and the first pump: the pick must not move to the new window.
|
||||
desk.lookup.set(va(), Some(3));
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert!(desk.parented.is_empty() && app.owned_picks.jobs.is_empty());
|
||||
assert!(app.closing.is_none() && !app.quit_requested);
|
||||
assert!(app.session.document_dirty(first_doc) && app.session.document_dirty(peer_doc));
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn windowless_save_as_does_not_settle_an_answer_after_its_window_is_recreated() {
|
||||
let (mut app, _, first, first_doc, peer, peer_doc, mut desk, ctx) = attached_drafts();
|
||||
let dir = scratch("windowless-native-replaced");
|
||||
let destination = dir.join("stale.docx");
|
||||
script_panels(vec![craft::dialogs::Answer::Saved { path: destination.clone(), filter: None }]);
|
||||
begin_trial_save(&mut app, first, peer);
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert!(app.owned_picks.jobs[0].answer.is_some(), "the answer is in");
|
||||
// Recreated after the answer and before its consumption, with no pump in between.
|
||||
desk.lookup.set(va(), Some(3));
|
||||
assert!(app.poll_file_dialog().is_none(), "the last use checks the exact window itself");
|
||||
assert!(!destination.exists());
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert!(app.owned_picks.jobs.is_empty() && app.closing.is_none() && !app.quit_requested);
|
||||
assert!(app.owned_picks.retired.is_empty(), "an answered panel needs no cleanup");
|
||||
assert_eq!(desk.leases(va()), 0);
|
||||
assert!(app.session.document_dirty(first_doc) && app.session.document_dirty(peer_doc));
|
||||
|
||||
begin_trial_save(&mut app, first, peer);
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert_eq!(desk.parented.last(), Some(&(va(), nz(3))), "a new gesture pins the new window");
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn windowless_save_as_does_not_settle_an_answer_after_its_surface_remounts() {
|
||||
let (mut app, _, first, first_doc, peer, peer_doc, mut desk, ctx) = attached_drafts();
|
||||
let dir = scratch("windowless-native-remount");
|
||||
let destination = dir.join("stale.docx");
|
||||
script_panels(vec![craft::dialogs::Answer::Saved { path: destination.clone(), filter: None }]);
|
||||
begin_trial_save(&mut app, first, peer);
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
app.remount_window_for_test(first);
|
||||
assert!(app.poll_file_dialog().is_none(), "an answer for the earlier surface is not settled");
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert!(app.owned_picks.jobs.is_empty() && !destination.exists());
|
||||
assert!(app.session.document_dirty(first_doc) && app.session.document_dirty(peer_doc));
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn windowless_save_as_binds_a_mounting_owner_on_its_first_attachment() {
|
||||
let (mut app, _, first, _, peer, _) = two_windowless_drafts();
|
||||
let (mut desk, ctx) = connect_desk(&mut app);
|
||||
app.attach_window_for_test(peer, vb());
|
||||
desk.lookup.set(vb(), Some(2));
|
||||
script_panels(vec![craft::dialogs::Answer::Cancelled]);
|
||||
|
||||
begin_trial_save(&mut app, first, peer);
|
||||
for _ in 0..2 * super::MISSING_PASSES {
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
next_pass(&ctx);
|
||||
}
|
||||
assert!(desk.parented.is_empty() && desk.unparented == 0, "nothing shows before the owner's surface exists");
|
||||
assert!(!app.window_dialog_host_mut(first).unwrap().is_open::<FileChooser>(), "mounting is not a failure");
|
||||
assert_eq!(app.owned_picks.jobs.len(), 1);
|
||||
|
||||
app.attach_window_for_test(first, va());
|
||||
desk.lookup.set(va(), Some(1));
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert_eq!(desk.parented, vec![(va(), nz(1))], "its own first window, never the peer's");
|
||||
assert_eq!(app.poll_file_dialog().unwrap().unwrap()["done"], false);
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn windowless_save_as_uses_the_owner_chooser_after_its_native_window_stays_missing() {
|
||||
let (mut app, files, first, first_doc, peer, peer_doc, mut desk, ctx) = attached_drafts();
|
||||
desk.lookup.set(va(), None);
|
||||
begin_trial_save(&mut app, first, peer);
|
||||
for _ in 1..super::MISSING_PASSES {
|
||||
// Two pumps a frame, as the desktop runs them: only scheduled passes count.
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
next_pass(&ctx);
|
||||
}
|
||||
assert!(!app.window_dialog_host_mut(first).unwrap().is_open::<FileChooser>(), "a missing window is retried before falling back");
|
||||
// Attached-but-missing at the gesture never binds later: the window that appears is not pinned.
|
||||
desk.lookup.set(va(), Some(4));
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert!(desk.parented.is_empty(), "no other or later window stands in for the missing one");
|
||||
assert!(desk.unparented > 0);
|
||||
assert!(app.window_dialog_host_mut(first).unwrap().cancel::<FileChooser>(&ctx), "the chooser opens on the initiating window");
|
||||
assert!(!app.dialog_host_mut().is_open::<FileChooser>());
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert_eq!(app.poll_file_dialog().unwrap().unwrap()["done"], false);
|
||||
assert!(app.session.document_dirty(first_doc) && app.session.document_dirty(peer_doc));
|
||||
assert!(files.requests().is_empty());
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn windowless_save_as_keeps_the_built_in_chooser_preference() {
|
||||
let (mut app, _, first, _, peer, _, mut desk, ctx) = attached_drafts();
|
||||
app.fallback_chooser = true;
|
||||
begin_trial_save(&mut app, first, peer);
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert!(desk.parented.is_empty(), "the preference bypasses the system dialog");
|
||||
assert!(app.window_dialog_host_mut(first).unwrap().is_open::<FileChooser>());
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn windowless_save_as_falls_back_on_its_own_window_when_the_system_dialog_cannot_show() {
|
||||
let (mut app, _, first, first_doc, peer, peer_doc, mut desk, ctx) = attached_drafts();
|
||||
script_panels(vec![craft::dialogs::Answer::Unavailable("no file chooser portal".into())]);
|
||||
begin_trial_save(&mut app, first, peer);
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert_eq!(desk.parented, vec![(va(), nz(1))]);
|
||||
assert!(!app.dialog_host_mut().is_open::<FileChooser>());
|
||||
assert!(app.window_dialog_host_mut(first).unwrap().cancel::<FileChooser>(&ctx), "the shared fallback opens on the owner");
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert_eq!(app.poll_file_dialog().unwrap().unwrap()["done"], false);
|
||||
assert!(app.closing.is_none() && app.session.document_dirty(first_doc) && app.session.document_dirty(peer_doc));
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn windowless_picks_belong_to_their_windows_and_end_only_with_them() {
|
||||
let (mut app, files, first, first_doc, peer, _) = two_windowless_drafts();
|
||||
let (mut desk, ctx) = connect_desk(&mut app);
|
||||
begin_trial_save(&mut app, first, peer);
|
||||
app.pick_picture();
|
||||
assert_eq!(app.owned_picks.jobs.len(), 2, "the peer window has its own pick");
|
||||
app.open_dialog();
|
||||
assert_eq!(app.owned_picks.jobs.len(), 2, "one pick per window");
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert!(desk.parented.is_empty(), "mounting owners wait");
|
||||
|
||||
app.session.close_document(first_doc).unwrap();
|
||||
app.prune_windows();
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert_eq!(app.owned_picks.jobs.len(), 1);
|
||||
assert_eq!(app.owned_picks.jobs[0].window, peer, "closing one window cancels only its pick");
|
||||
assert!(app.file_dialog_open());
|
||||
assert!(files.requests().is_empty());
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn a_cancelled_picture_pick_clears_only_its_own_windows_change_picture_target() {
|
||||
let (mut app, _, first, _, peer, _, mut desk, ctx) = attached_drafts();
|
||||
assert!(app.enter_window(first));
|
||||
app.change_picture_target = Some("first-picture".into());
|
||||
app.pick_picture();
|
||||
app.show_window(peer);
|
||||
app.change_picture_target = Some("peer-picture".into());
|
||||
// The owner's window is recreated before launch: its pick ends.
|
||||
desk.lookup.set(va(), Some(3));
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert!(app.owned_picks.jobs.is_empty());
|
||||
assert_eq!(app.change_picture_target.as_deref(), Some("peer-picture"), "the drawn peer's target is not touched");
|
||||
assert!(app.enter_window(first));
|
||||
assert_eq!(app.change_picture_target, None, "the owner's pending Change Picture is cleared");
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn a_home_window_open_ends_when_its_start_screen_placeholder_is_replaced() {
|
||||
let (mut app, files) = async_app();
|
||||
app.enable_windowless_trial(true);
|
||||
let (mut desk, ctx) = connect_desk(&mut app);
|
||||
app.run("file.close", json!({})).unwrap();
|
||||
assert!(!app.has_document(), "the Start screen's window shows no document");
|
||||
let (home, placeholder) = (app.windows.shown(), app.shown_document);
|
||||
app.open_dialog();
|
||||
assert_eq!((app.owned_picks.jobs[0].window, app.owned_picks.jobs[0].document), (home, placeholder), "Home's Open is owned by Home");
|
||||
app.run("file.new", json!({})).unwrap();
|
||||
assert!(!app.window_shows_document(home, placeholder), "the placeholder was replaced");
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert!(app.owned_picks.jobs.is_empty(), "a replaced Home placeholder ends its Open");
|
||||
assert!(desk.parented.is_empty() && files.requests().is_empty());
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn windowless_export_opens_the_system_dialog_on_its_own_window() {
|
||||
let (mut app, files, first, first_doc, peer, peer_doc, mut desk, ctx) = attached_drafts();
|
||||
let dir = scratch("windowless-native-export");
|
||||
let destination = dir.join("first.html");
|
||||
script_panels(vec![craft::dialogs::Answer::Saved { path: destination.clone(), filter: None }]);
|
||||
assert!(app.enter_window(first));
|
||||
app.export_dialog("html");
|
||||
app.show_window(peer);
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert_eq!(desk.parented, vec![(va(), nz(1))]);
|
||||
app.poll_file_dialog().unwrap().unwrap();
|
||||
let exported = std::fs::read_to_string(&destination).unwrap();
|
||||
assert!(exported.contains("First unsaved draft") && !exported.contains("Peer unsaved draft"));
|
||||
assert_eq!(app.session.document_id(), peer_doc);
|
||||
assert!(app.session.document_dirty(first_doc), "an export is a copy");
|
||||
assert!(files.requests().is_empty());
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn a_document_closed_under_its_pending_system_dialog_keeps_that_window_leased_until_the_dialog_settles() {
|
||||
let (mut app, _, first, first_doc, peer, peer_doc, mut desk, ctx) = attached_drafts();
|
||||
let dir = scratch("windowless-native-close-while-open");
|
||||
let destination = dir.join("late.docx");
|
||||
// The first window's dialog answers late; the peer's Open is cancelled.
|
||||
script_each_panel(vec![vec![craft::dialogs::Answer::Saved { path: destination.clone(), filter: None }], vec![craft::dialogs::Answer::Cancelled]]);
|
||||
desk.pending = true;
|
||||
begin_trial_save(&mut app, first, peer);
|
||||
app.open_dialog();
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert_eq!(desk.parented, vec![(va(), nz(1)), (vb(), nz(2))], "each window's pick launched on its own window");
|
||||
assert_eq!((desk.leases(va()), desk.leases(vb())), (1, 1));
|
||||
|
||||
// An agent closes the document under its open dialog (no app Close entry point is involved).
|
||||
app.session.close_document(first_doc).unwrap();
|
||||
app.prune_windows();
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert_eq!(app.owned_picks.jobs.len(), 1);
|
||||
assert_eq!(app.owned_picks.jobs[0].window, peer, "only the closed window's pick ends");
|
||||
assert_eq!(app.owned_picks.retired.len(), 1, "its pending dialog is left to finish, not cancelled");
|
||||
assert_eq!(desk.leases(va()), 1, "so its parent stays leased");
|
||||
assert_eq!(desk.leases(vb()), 1, "the peer's lease is untouched");
|
||||
assert!(app.native_file_panels_open());
|
||||
|
||||
// The dialog finishes: its late answer is dropped, then the parent is released.
|
||||
desk.pending = false;
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert!(app.owned_picks.retired.is_empty());
|
||||
assert_eq!(desk.leases(va()), 0);
|
||||
assert_eq!(app.poll_file_dialog().unwrap().unwrap(), json!({"cancelled": true}), "the peer's own pick settles in its window");
|
||||
assert_eq!(desk.leases(vb()), 0);
|
||||
assert!(!destination.exists(), "the closed document's late answer saves nothing");
|
||||
assert!(app.session.is_open(peer_doc) && !app.quit_requested);
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn native_dialogs_are_admitted_within_a_bound_that_counts_settling_ones() {
|
||||
let (mut app, _, first, first_doc, peer, _, mut desk, ctx) = attached_drafts();
|
||||
script_panels(vec![craft::dialogs::Answer::Cancelled]);
|
||||
desk.pending = true;
|
||||
begin_trial_save(&mut app, first, peer);
|
||||
app.open_dialog();
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert_eq!(desk.parented.len(), super::MAX_NATIVE_OPERATIONS);
|
||||
app.session.close_document(first_doc).unwrap();
|
||||
app.prune_windows();
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert_eq!(app.owned_picks.retired.len(), 1);
|
||||
|
||||
// A third window asks while one dialog settles and one is live: it waits, holding nothing.
|
||||
app.run("file.new", json!({})).unwrap();
|
||||
let third = app.windows.shown();
|
||||
let vc = egui::ViewportId::from_hash_of("third");
|
||||
app.attach_window_for_test(third, vc);
|
||||
desk.lookup.set(vc, Some(5));
|
||||
app.open_dialog();
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert_eq!(desk.parented.len(), super::MAX_NATIVE_OPERATIONS, "no third system dialog while two may use their windows");
|
||||
assert_eq!(desk.leases(vc), 0);
|
||||
|
||||
desk.pending = false;
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert_eq!(desk.parented.last(), Some(&(vc, nz(5))), "it launches once the earlier ones have ended");
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn quit_waits_for_a_pending_system_dialog_then_goes_on_through_the_unsaved_prompt() {
|
||||
let (mut app, _, _, first_doc, _, peer_doc, mut desk, ctx) = attached_drafts();
|
||||
script_panels(vec![craft::dialogs::Answer::Cancelled]);
|
||||
desk.pending = true;
|
||||
app.save_as_dialog();
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert_eq!(desk.leases(vb()), 1);
|
||||
|
||||
// The entry point the app menu, the OS Quit intake and the last window's close all use.
|
||||
assert!(!app.quit());
|
||||
assert_eq!(app.close_decision(), craft::ui::shell::embed::CloseDecision::Hold, "the platform's close is held too");
|
||||
assert!(!app.quit_requested && app.closing.is_none(), "no unsaved-changes prompt was started or answered");
|
||||
assert!(app.session.document_dirty(first_doc) && app.session.document_dirty(peer_doc));
|
||||
|
||||
desk.pending = false;
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert_eq!(desk.leases(vb()), 0, "the lease ends with the dialog's answer");
|
||||
assert_eq!(app.poll_file_dialog().unwrap().unwrap()["saved"], false);
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert!(app.closing.is_some(), "the quit goes on by itself and asks about the drafts as usual");
|
||||
assert!(!app.quit_requested);
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn closing_a_window_waits_for_its_own_pending_system_dialog_but_not_for_others() {
|
||||
let (mut app, _, first, first_doc, peer, peer_doc, mut desk, ctx) = attached_drafts();
|
||||
script_panels(vec![craft::dialogs::Answer::Cancelled]);
|
||||
desk.pending = true;
|
||||
app.save_as_dialog();
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert_eq!(desk.leases(vb()), 1);
|
||||
|
||||
app.close_window(peer);
|
||||
assert!(app.closing.is_none() && app.window_shows_document(peer, peer_doc), "the peer's close waits for its dialog");
|
||||
assert_eq!(app.run("file.close", json!({})).unwrap()["deferred"], true, "File › Close in it waits too");
|
||||
app.close_window(first);
|
||||
assert!(app.closing.as_ref().is_some_and(|c| c.window == first), "an unrelated window closes as usual");
|
||||
app.cancel_closing();
|
||||
|
||||
desk.pending = false;
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert_eq!(app.poll_file_dialog().unwrap().unwrap()["saved"], false);
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert!(app.closing.as_ref().is_some_and(|c| c.window == peer), "the deferred close goes on through its unsaved prompt");
|
||||
assert!(app.session.document_dirty(first_doc) && app.session.document_dirty(peer_doc));
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn no_more_than_two_system_dialogs_launch_in_one_pass() {
|
||||
let (mut app, _, first, _, peer, _, mut desk, ctx) = attached_drafts();
|
||||
script_panels(vec![craft::dialogs::Answer::Cancelled]);
|
||||
desk.pending = true;
|
||||
begin_trial_save(&mut app, first, peer);
|
||||
app.open_dialog();
|
||||
app.run("file.new", json!({})).unwrap();
|
||||
let third = app.windows.shown();
|
||||
let vc = egui::ViewportId::from_hash_of("third");
|
||||
app.attach_window_for_test(third, vc);
|
||||
desk.lookup.set(vc, Some(5));
|
||||
app.open_dialog();
|
||||
assert_eq!(app.owned_picks.jobs.len(), 3);
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert_eq!(desk.parented.len(), super::MAX_NATIVE_OPERATIONS, "three picks in one pass launch two dialogs");
|
||||
assert_eq!(desk.leases(vc), 0, "the third waits, holding nothing");
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn a_given_up_system_dialog_still_holds_its_windows_close() {
|
||||
let (mut app, _, _, _, peer, peer_doc, mut desk, ctx) = attached_drafts();
|
||||
script_panels(vec![craft::dialogs::Answer::Cancelled]);
|
||||
desk.pending = true;
|
||||
app.save_as_dialog();
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
// `ui.fileBrowser` gives the system dialog up: it is not cancelled, and its window stays leased.
|
||||
let _ = app.give_up_file_dialog();
|
||||
assert!(app.owned_picks.jobs.is_empty());
|
||||
assert_eq!(app.owned_picks.retired.len(), 1);
|
||||
assert_eq!(desk.leases(vb()), 1);
|
||||
app.close_window(peer);
|
||||
assert!(app.closing.is_none() && app.window_shows_document(peer, peer_doc), "its window's close waits for it");
|
||||
|
||||
desk.pending = false;
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert!(app.owned_picks.retired.is_empty());
|
||||
assert_eq!(desk.leases(vb()), 0);
|
||||
assert!(app.closing.as_ref().is_some_and(|c| c.window == peer), "the close goes on once the dialog has finished");
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn quiescing_admits_and_launches_nothing_and_drains_launched_dialogs() {
|
||||
let (mut app, _, first, _, peer, _, mut desk, ctx) = attached_drafts();
|
||||
script_panels(vec![craft::dialogs::Answer::Cancelled]);
|
||||
desk.pending = true;
|
||||
desk.lookup.set(va(), None);
|
||||
assert!(app.enter_window(first));
|
||||
app.open_dialog();
|
||||
app.show_window(peer);
|
||||
app.save_as_dialog();
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert_eq!(desk.parented, vec![(vb(), nz(2))]);
|
||||
|
||||
app.quiesce_native_file_panels();
|
||||
assert!(app.owned_picks.jobs.is_empty(), "the waiting pick is dropped unpumped");
|
||||
assert!(app.native_file_panels_open(), "the launched dialog still uses its window");
|
||||
app.open_dialog();
|
||||
assert!(app.owned_picks.jobs.is_empty(), "nothing is admitted while exiting");
|
||||
desk.lookup.set(va(), Some(1));
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert_eq!(desk.parented.len(), 1, "a final pass launches nothing");
|
||||
assert!(!app.window_dialog_host_mut(first).unwrap().is_open::<FileChooser>());
|
||||
|
||||
desk.pending = false;
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert!(!app.native_file_panels_open(), "the drain ends once the dialog has finished");
|
||||
assert_eq!(desk.leases(vb()), 0);
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn the_updaters_quit_waits_for_a_pending_system_dialog_without_prompting() {
|
||||
let (mut app, _, _, _, _, _, mut desk, ctx) = attached_drafts();
|
||||
script_panels(vec![craft::dialogs::Answer::Cancelled]);
|
||||
desk.pending = true;
|
||||
app.save_as_dialog();
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert_eq!(app.ask_before_quit(), json!({"quit": false, "deferred": true}));
|
||||
assert!(app.closing.is_none() && !app.quit_requested);
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn quiescing_leaves_no_chooser_showing_for_a_system_dialogs_fallback() {
|
||||
let (mut app, _, _, _, peer, _, mut desk, ctx) = attached_drafts();
|
||||
script_panels(vec![craft::dialogs::Answer::Unavailable("no file chooser portal".into())]);
|
||||
app.save_as_dialog();
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert!(app.window_dialog_host_mut(peer).unwrap().is_open::<FileChooser>(), "the fallback shows on the owner");
|
||||
app.quiesce_native_file_panels();
|
||||
assert!(!app.window_dialog_host_mut(peer).unwrap().is_open::<FileChooser>(), "no chooser is left with nothing to answer it");
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert!(!app.native_file_panels_open(), "its retired pick settles on the cleanup host");
|
||||
assert_eq!(desk.leases(vb()), 0);
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn a_waiting_quit_launches_no_queued_dialog_but_its_own_save_as() {
|
||||
let (mut app, _, first, _, peer, _, mut desk, ctx) = attached_drafts();
|
||||
script_panels(vec![craft::dialogs::Answer::Cancelled]);
|
||||
desk.pending = true;
|
||||
assert!(app.enter_window(first));
|
||||
app.save_as_dialog();
|
||||
app.show_window(peer);
|
||||
app.open_dialog();
|
||||
app.run("file.new", json!({})).unwrap();
|
||||
let third = app.windows.shown();
|
||||
let vc = egui::ViewportId::from_hash_of("third");
|
||||
app.attach_window_for_test(third, vc);
|
||||
desk.lookup.set(vc, Some(5));
|
||||
app.open_dialog();
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert_eq!(desk.parented.len(), 2, "two open, the third queued");
|
||||
|
||||
assert!(!app.quit(), "quit waits for the two open dialogs");
|
||||
desk.pending = false;
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert!(!app.native_file_panels_open(), "both dialogs have answered");
|
||||
assert_eq!(desk.parented.len(), 2, "the queued third does not launch while the quit waits");
|
||||
while app.poll_file_dialog().is_some() {}
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert!(app.closing.is_some(), "the quit goes on, asking about the drafts");
|
||||
assert_eq!(desk.parented.len(), 2, "still nothing new while the quit asks");
|
||||
assert_eq!(desk.leases(vc), 0);
|
||||
|
||||
// Save in the quit's prompt asks where: that Save As opens, on the prompt's own window.
|
||||
let prompt_window = app.closing.as_ref().unwrap().window;
|
||||
assert_eq!(app.run("ui.saveChanges", json!({"answer": "save"})).unwrap()["pending"], "saveAs");
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert_eq!(desk.parented.len(), 3);
|
||||
let expected = if prompt_window == first { va() } else { vb() };
|
||||
assert_eq!(desk.parented.last().map(|p| p.0), Some(expected));
|
||||
assert_eq!(desk.leases(vc), 0, "the queued third is still not launched");
|
||||
}
|
||||
|
||||
/// Three windows with their own clean documents and live native attachments; the third is drawn.
|
||||
/// If `third_untitled` is set, the third is still a new blank document awaiting its first edit.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn three_attached_windows(third_untitled: bool) -> (WordApp, [u64; 3], [egui::ViewportId; 3], Desk, egui::Context) {
|
||||
let (mut app, _) = async_app();
|
||||
app.enable_windowless_trial(true);
|
||||
let dir = scratch("windowless-three-windows");
|
||||
let mut windows = Vec::new();
|
||||
for n in 0..3 {
|
||||
if n > 0 {
|
||||
app.run("file.new", json!({})).unwrap();
|
||||
}
|
||||
if n != 2 || !third_untitled {
|
||||
app.run("text.insert", json!({"text": format!("Saved document {n}")})).unwrap();
|
||||
app.run("file.save", json!({"path": dir.join(format!("saved-{n}.docx"))})).unwrap();
|
||||
}
|
||||
assert!(!app.session.document_dirty(app.session.document_id()));
|
||||
windows.push(app.windows.shown());
|
||||
}
|
||||
let [one, two, three] = [windows[0], windows[1], windows[2]];
|
||||
assert!(one != two && two != three && one != three);
|
||||
let (desk, ctx) = connect_desk(&mut app);
|
||||
let viewports = [va(), vb(), egui::ViewportId::from_hash_of("third")];
|
||||
for (n, (window, viewport)) in [one, two, three].into_iter().zip(viewports).enumerate() {
|
||||
app.attach_window_for_test(window, viewport);
|
||||
desk.lookup.set(viewport, Some(n as u64 + 1));
|
||||
}
|
||||
(app, [one, two, three], viewports, desk, ctx)
|
||||
}
|
||||
|
||||
/// Each window asks to open a file; two dialogs launch and the third queues; quit waits; both answer.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn quit_after_two_dialogs_with_a_third_queued(app: &mut WordApp, windows: [u64; 3], desk: &mut Desk, ctx: &egui::Context) {
|
||||
script_panels(vec![craft::dialogs::Answer::Cancelled]);
|
||||
desk.pending = true;
|
||||
for window in windows {
|
||||
assert!(app.enter_window(window));
|
||||
app.open_dialog();
|
||||
}
|
||||
app.pump_owned_picks(ctx, desk);
|
||||
assert_eq!(desk.parented.len(), 2);
|
||||
assert!(!app.quit());
|
||||
desk.pending = false;
|
||||
app.pump_owned_picks(ctx, desk);
|
||||
while app.poll_file_dialog().is_some() {}
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn a_clean_quit_replayed_in_a_pump_launches_nothing_after_it() {
|
||||
let (mut app, windows, viewports, mut desk, ctx) = three_attached_windows(false);
|
||||
quit_after_two_dialogs_with_a_third_queued(&mut app, windows, &mut desk, &ctx);
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert!(app.quit_requested, "nothing unsaved: the replayed quit is decided in this pump");
|
||||
assert_eq!(desk.parented.len(), 2, "the queued third does not launch after it");
|
||||
assert_eq!(desk.leases(viewports[2]), 0);
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn the_quit_prompts_save_as_takes_the_place_of_its_windows_queued_pick() {
|
||||
let (mut app, windows, viewports, mut desk, ctx) = three_attached_windows(true);
|
||||
assert!(app.enter_window(windows[2]));
|
||||
assert!(app.session.path.is_none(), "the quit guard's Save must use Save As");
|
||||
app.run("text.insert", json!({"text": "Third unsaved draft"})).unwrap();
|
||||
let third_doc = app.session.document_id();
|
||||
quit_after_two_dialogs_with_a_third_queued(&mut app, windows, &mut desk, &ctx);
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert!(app.closing.as_ref().is_some_and(|c| c.window == windows[2] && c.document == third_doc), "the third window owns the quit's prompt");
|
||||
assert_eq!(desk.parented.len(), 2);
|
||||
|
||||
assert_eq!(app.run("ui.saveChanges", json!({"answer": "save"})).unwrap()["pending"], "saveAs");
|
||||
assert_eq!(app.owned_picks.jobs.len(), 1, "the queued Open gave way to the prompt's Save As");
|
||||
assert!(matches!(app.owned_picks.jobs[0].after, AfterPick::SaveAs { after: AfterSave::Closing, .. }));
|
||||
app.pump_owned_picks(&ctx, &mut desk);
|
||||
assert_eq!(desk.parented.last(), Some(&(viewports[2], nz(3))), "the Save As opens on the prompt's window");
|
||||
assert!(app.closing.is_some(), "the guard still waits for that Save As");
|
||||
}
|
||||
|
||||
@@ -68,7 +68,6 @@ pub mod read_aloud;
|
||||
mod restrict_pane;
|
||||
pub mod ribbon;
|
||||
mod save_types;
|
||||
pub mod screen_text;
|
||||
pub mod scroll;
|
||||
pub use scroll::ScrollSpeed;
|
||||
pub mod desktop_theme; // owed by ribbon batch 2 (S-L348)
|
||||
@@ -510,15 +509,22 @@ pub struct WordApp {
|
||||
/// there. A file that was merely opened isn't rewritten until the user saves it: saving drops
|
||||
/// whatever WordCraft can't represent (content controls, charts, macros…).
|
||||
autosave_path: Option<std::path::PathBuf>,
|
||||
/// The file on disk the document was read from or saved to. A document opened from bytes
|
||||
/// (`file.open` with `data`) only names a file, so the AutoSave switch can't cover it.
|
||||
read_from: Option<std::path::PathBuf>,
|
||||
/// Web: saves the browser's picker hasn't finished yet (#1315).
|
||||
saves_in_flight: Vec<SaveInFlight>,
|
||||
/// The Save Changes prompt this window is running and the command it holds back.
|
||||
pub(crate) closing: Option<app::Closing>,
|
||||
/// The file dialog the host is showing, and what its answer is for ([`file_dialogs`]).
|
||||
file_dialog: Option<file_dialogs::PendingDialog>,
|
||||
/// Remember the folder for each purpose served by the isolated windowless chooser.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
windowless_save_folders: std::collections::HashMap<String, std::path::PathBuf>,
|
||||
/// Windowless trial: the file picks bound to the window that asked, and the cleanup of a cancelled one. App-wide,
|
||||
/// so focusing another window never moves it ([`file_dialogs`]).
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
owned_picks: file_dialogs::OwnedPicks,
|
||||
/// The desktop's read-only view of document viewports' native windows; `None` where it has none.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
native_windows: Option<std::sync::Arc<dyn file_dialogs::NativeWindowLookup + Send + Sync>>,
|
||||
/// Whether the in-app file chooser is forced in place of the system one.
|
||||
pub(crate) fallback_chooser: bool,
|
||||
/// File › Info: the property field being typed in and the document revision after its last
|
||||
|
||||
@@ -125,8 +125,6 @@ struct Strings {
|
||||
region_id: String,
|
||||
paper: Vec<(String, String)>,
|
||||
paper_id: String,
|
||||
smoothing: Vec<(String, String)>,
|
||||
smoothing_id: String,
|
||||
numerals: Vec<(String, String)>,
|
||||
numeral_id: String,
|
||||
proofing_language: String,
|
||||
@@ -173,8 +171,6 @@ impl Strings {
|
||||
|
||||
let paper = PaperColor::ALL.iter().map(|c| (id_of(c), tl!(c.label()).to_string())).collect();
|
||||
let paper_id = id_of(&app.session.prefs.paper_color);
|
||||
let smoothing = wordcraft_engine::cmd::view::TextSmoothing::ALL.iter().map(|c| (id_of(c), tl!(c.label()).to_string())).collect();
|
||||
let smoothing_id = id_of(&app.session.prefs.text_smoothing);
|
||||
let numerals = [NumeralMode::Arabic, NumeralMode::Hindi, NumeralMode::Context, NumeralMode::System]
|
||||
.iter()
|
||||
.map(|m| (id_of(m), tl!(m.label()).to_string()))
|
||||
@@ -201,8 +197,6 @@ impl Strings {
|
||||
region_id,
|
||||
paper,
|
||||
paper_id,
|
||||
smoothing,
|
||||
smoothing_id,
|
||||
numerals,
|
||||
numeral_id,
|
||||
proofing_language,
|
||||
@@ -252,7 +246,6 @@ impl<'a> OptionsModel<'a> {
|
||||
("general.theme", Choice(ui.theme.code().to_string())),
|
||||
("general.interfaceSize", Choice(size)),
|
||||
("general.paperColor", Choice(id_of(&prefs.paper_color))),
|
||||
("general.textSmoothing", Choice(id_of(&prefs.text_smoothing))),
|
||||
("general.miniToolbar", Bool(ui.mini_toolbar)),
|
||||
("general.darkPage", Bool(view.dark_mode)),
|
||||
("general.showCommunity", Bool(ui.show_discord)),
|
||||
@@ -344,9 +337,6 @@ impl PreferencesModel for OptionsModel<'_> {
|
||||
RowSpec::new("general.paperColor", tl!("Screen paper color:"), RowKind::choice(&s.paper_id, owned(&s.paper))).help(tl!(
|
||||
"Screen only. Document backgrounds, printing and exports keep their colours. Dark page and explicit Read Mode colours take precedence."
|
||||
)),
|
||||
RowSpec::new("general.textSmoothing", tl!("Screen text smoothing:"), RowKind::choice(&s.smoothing_id, owned(&s.smoothing))).help(tl!(
|
||||
"Screen only. Subpixel smoothing makes the edges of page text finer sideways, with faint colour in them, and takes longer to draw. Printing and exports are unchanged."
|
||||
)),
|
||||
b("general.miniToolbar", tl!("Show the mini toolbar when text is selected"), app.ui.mini_toolbar),
|
||||
b("general.darkPage", tl!("Dark page (white text on black)"), app.session.view.dark_mode)
|
||||
.help(tl!("Show documents with their colours inverted, like View › Switch Modes. Saving, printing and PDFs are unchanged.")),
|
||||
@@ -643,7 +633,6 @@ impl PreferencesModel for OptionsModel<'_> {
|
||||
Err(_) => self.run("ui.interfaceSize", json!({"value": "auto"})),
|
||||
},
|
||||
("general.paperColor", Choice(c)) => self.run("view.paperColor", json!({"value": c})),
|
||||
("general.textSmoothing", Choice(c)) => self.run("view.textSmoothing", json!({"value": c})),
|
||||
("general.miniToolbar", Bool(v)) => self.app.ui.mini_toolbar = v,
|
||||
("general.showCommunity", Bool(v)) => self.app.ui.show_discord = v,
|
||||
("general.fontDownloadNotice", Bool(v)) => self.app.ui.font_download_notice = v,
|
||||
|
||||
@@ -301,23 +301,6 @@ fn length_units_follow_the_interface_language() {
|
||||
assert_eq!(unit_suffix(Unit::Millimeters), " mm", "English keeps the English names");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn screen_text_smoothing_options_round_trip_and_work_without_a_document() {
|
||||
use wordcraft_engine::cmd::view::TextSmoothing;
|
||||
let mut a = app();
|
||||
a.start_screen();
|
||||
a.run("view.textSmoothing", json!({"value":"grayscale"})).unwrap();
|
||||
let saved = serde_json::to_vec(&a.prefs()).unwrap();
|
||||
let mut b = app();
|
||||
b.apply_prefs(serde_json::from_slice::<Prefs>(&saved).unwrap());
|
||||
assert_eq!(b.session.prefs.text_smoothing, TextSmoothing::Grayscale);
|
||||
with_model(&mut b, true, |m| m.set("general.textSmoothing", PrefValue::Choice("subpixel".into())));
|
||||
assert_eq!(b.session.prefs.text_smoothing, TextSmoothing::Subpixel);
|
||||
// A value the option doesn't have changes nothing.
|
||||
with_model(&mut b, true, |m| m.set("general.textSmoothing", PrefValue::Choice("lcd".into())));
|
||||
assert_eq!(b.session.prefs.text_smoothing, TextSmoothing::Subpixel);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn screen_paper_color_options_round_trip_and_work_without_a_document() {
|
||||
use wordcraft_engine::cmd::view::PaperColor;
|
||||
|
||||
@@ -1,294 +0,0 @@
|
||||
//! How the desktop draws text, so pages look like the text in the platform's other apps.
|
||||
//!
|
||||
//! Each system keeps the user's choice somewhere else, and says different things:
|
||||
//!
|
||||
//! - macOS: the `AppleFontSmoothing` default, the strength of its font smoothing (0 to 3).
|
||||
//! - Windows: `FontSmoothing`, `FontSmoothingType` and `FontSmoothingOrientation` under
|
||||
//! `HKCU\Control Panel\Desktop`: smoothing on or off, ClearType or greyscale, RGB or BGR stripes.
|
||||
//! - Linux and the BSDs: the desktop's antialiasing, hinting and subpixel order, as GNOME
|
||||
//! (`org.gnome.desktop.interface`) or KDE Plasma (`kdeglobals`) keeps them.
|
||||
//!
|
||||
//! This module turns those values into one [`ScreenText`] and keeps the latest one for the page rasters to read.
|
||||
//! It never asks the system itself, and for now nothing does: the app reads the system through craft-libs'
|
||||
//! `platform::appearance`, which reports theme, contrast and reduced motion and no text settings yet. Until a
|
||||
//! reader there hands an answer to [`set_system`] (and always in tests and headless screenshots)
|
||||
//! [`ScreenText::PLATFORM`] stands, so pages are drawn each platform's fixed way. The constructors below are what
|
||||
//! that reader's values go through.
|
||||
|
||||
use std::sync::Mutex;
|
||||
|
||||
/// The order of a screen's colour stripes, left to right.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum SubpixelOrder {
|
||||
Rgb,
|
||||
Bgr,
|
||||
}
|
||||
|
||||
/// How page text is drawn on screen.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct ScreenText {
|
||||
/// The strength of macOS-style font smoothing (glyphs thickened sideways): 0 is none, 1 the
|
||||
/// system's default. See `wordcraft_render::RenderOptions::text_darkening`.
|
||||
pub darkening: f32,
|
||||
/// Light hinting, as FreeType's `hintslight` draws text.
|
||||
pub hinting: bool,
|
||||
/// The system asks for subpixel (LCD) antialiasing, in this stripe order; `None` when it asks
|
||||
/// for greyscale antialiasing or says nothing.
|
||||
pub subpixel: Option<SubpixelOrder>,
|
||||
/// The screen's stripe order, where the system names one, whether or not it asks for
|
||||
/// subpixel antialiasing: a user who chooses subpixel text themselves gets it in the order
|
||||
/// of their screen. `None` when the system names no side-by-side order.
|
||||
pub stripes: Option<SubpixelOrder>,
|
||||
}
|
||||
|
||||
impl ScreenText {
|
||||
/// What each platform's apps do when the user has changed nothing, and what pages are drawn
|
||||
/// with until the system has been asked: macOS smooths (thickens) text and never hints it;
|
||||
/// Linux and the BSDs hint lightly; Windows gets neither. All greyscale: a subpixel order is
|
||||
/// only ever taken from the system.
|
||||
pub const PLATFORM: ScreenText = ScreenText {
|
||||
darkening: if cfg!(target_os = "macos") { 1.0 } else { 0.0 },
|
||||
hinting: cfg!(all(unix, not(target_os = "macos"))),
|
||||
subpixel: None,
|
||||
stripes: None,
|
||||
};
|
||||
|
||||
/// macOS, from the `AppleFontSmoothing` default (`None` when it isn't set). 0 turns the
|
||||
/// smoothing off; 1, 2 and 3 are light, medium and strong, and unset is medium. The three
|
||||
/// strengths as half, one and one and a half times our darkening are our own choice: Apple
|
||||
/// publishes no numbers for them. macOS has no hinting and no subpixel antialiasing to ask
|
||||
/// for (it dropped the latter in 10.14).
|
||||
pub fn from_macos(font_smoothing: Option<i64>) -> Self {
|
||||
let darkening = match font_smoothing {
|
||||
Some(level) if level <= 0 => 0.0,
|
||||
Some(1) => 0.5,
|
||||
Some(2) | None => 1.0,
|
||||
Some(_) => 1.5,
|
||||
};
|
||||
ScreenText { darkening, hinting: false, subpixel: None, stripes: None }
|
||||
}
|
||||
|
||||
/// Windows, from the values under `HKCU\Control Panel\Desktop` (`None` for one that isn't
|
||||
/// there): `FontSmoothing` is the text "2" when edges are smoothed and "0" when not,
|
||||
/// `FontSmoothingType` is 2 for ClearType (1 is greyscale), `FontSmoothingOrientation` is 1
|
||||
/// for RGB stripes and 0 for BGR. ClearType gives subpixel edges, RGB unless the system
|
||||
/// says BGR; the stripe order itself is kept even with ClearType off. Text with smoothing off is still drawn antialiased, in greyscale: this
|
||||
/// rasteriser has no aliased text.
|
||||
pub fn from_windows(smoothing: Option<&str>, kind: Option<u32>, orientation: Option<u32>) -> Self {
|
||||
let smoothed = smoothing.map(str::trim) != Some("0");
|
||||
// The orientation is the screen's, and is kept whatever the smoothing is set to.
|
||||
let stripes = match orientation {
|
||||
Some(0) => Some(SubpixelOrder::Bgr),
|
||||
Some(1) => Some(SubpixelOrder::Rgb),
|
||||
_ => None,
|
||||
};
|
||||
let subpixel = (smoothed && kind == Some(2)).then_some(stripes.unwrap_or(SubpixelOrder::Rgb));
|
||||
ScreenText { darkening: 0.0, hinting: false, subpixel, stripes }
|
||||
}
|
||||
|
||||
/// GNOME (and the desktops that keep its settings), from `org.gnome.desktop.interface`:
|
||||
/// `font-antialiasing` is `none`, `grayscale` or `rgba`; `font-hinting` is `none`, `slight`,
|
||||
/// `medium` or `full`; `font-rgba-order` is `rgba`, `rgb`, `bgr`, `vrgb` or `vbgr`. `None`
|
||||
/// when the desktop has none of the three. Any hinting but `none` is our one light hinting.
|
||||
/// Stripes that run across the screen (`vrgb`, `vbgr`) get greyscale edges: only side by
|
||||
/// side stripes are drawn.
|
||||
pub fn from_gnome(antialiasing: Option<&str>, hinting: Option<&str>, rgba_order: Option<&str>) -> Option<Self> {
|
||||
if antialiasing.is_none() && hinting.is_none() && rgba_order.is_none() {
|
||||
return None;
|
||||
}
|
||||
let order = match rgba_order.map(str::trim) {
|
||||
Some("bgr") => Some(SubpixelOrder::Bgr),
|
||||
Some("vrgb" | "vbgr") => None,
|
||||
// `rgba` is the schema's first value and its default; it and no answer mean RGB.
|
||||
_ => Some(SubpixelOrder::Rgb),
|
||||
};
|
||||
let subpixel = if antialiasing.map(str::trim) == Some("rgba") { order } else { None };
|
||||
// The order the desktop names, kept when it asks for greyscale.
|
||||
let stripes = order.filter(|_| rgba_order.is_some());
|
||||
Some(ScreenText { darkening: 0.0, hinting: hinting.map(str::trim) != Some("none"), subpixel, stripes })
|
||||
}
|
||||
|
||||
/// KDE Plasma, from the `[General]` group of `kdeglobals`: `XftAntialias` is `true` or
|
||||
/// `false`; `XftHintStyle` is `hintnone`, `hintslight`, `hintmedium` or `hintfull`;
|
||||
/// `XftSubPixel` is `none`, `rgb`, `bgr`, `vrgb` or `vbgr`. `None` when it has none of the
|
||||
/// three (Plasma writes them only once the user has changed the font settings).
|
||||
pub fn from_kde(antialias: Option<&str>, hint_style: Option<&str>, sub_pixel: Option<&str>) -> Option<Self> {
|
||||
if antialias.is_none() && hint_style.is_none() && sub_pixel.is_none() {
|
||||
return None;
|
||||
}
|
||||
let antialiased = !matches!(antialias.map(|v| v.trim().to_ascii_lowercase()).as_deref(), Some("false" | "0"));
|
||||
let order = match sub_pixel.map(str::trim) {
|
||||
Some("rgb") => Some(SubpixelOrder::Rgb),
|
||||
Some("bgr") => Some(SubpixelOrder::Bgr),
|
||||
_ => None,
|
||||
};
|
||||
Some(ScreenText {
|
||||
darkening: 0.0,
|
||||
hinting: hint_style.map(str::trim) != Some("hintnone"),
|
||||
subpixel: order.filter(|_| antialiased),
|
||||
stripes: order,
|
||||
})
|
||||
}
|
||||
|
||||
/// The same settings with numbers a raster can take: a darkening that isn't a number, or is
|
||||
/// negative, is none, and the strongest is twice the default.
|
||||
pub fn sanitized(self) -> Self {
|
||||
let darkening = if self.darkening.is_finite() { self.darkening.clamp(0.0, 2.0) } else { 0.0 };
|
||||
ScreenText { darkening, ..self }
|
||||
}
|
||||
|
||||
/// Put these settings into a page raster's options.
|
||||
pub fn apply(self, opts: &mut wordcraft_render::RenderOptions) {
|
||||
let text = self.sanitized();
|
||||
opts.text_darkening = text.darkening;
|
||||
opts.hinting = text.hinting;
|
||||
}
|
||||
|
||||
/// A value to hash into a page's cache key: a page drawn under other settings is another
|
||||
/// raster.
|
||||
pub fn key(self) -> (u32, bool, Option<SubpixelOrder>, Option<SubpixelOrder>) {
|
||||
let text = self.sanitized();
|
||||
(text.darkening.to_bits(), text.hinting, text.subpixel, text.stripes)
|
||||
}
|
||||
}
|
||||
|
||||
/// What the system said last; `None` until the app has asked, and when the system said nothing.
|
||||
static SYSTEM: Mutex<Option<ScreenText>> = Mutex::new(None);
|
||||
|
||||
/// How page text is drawn now: the system's settings once they are known ([`set_system`]), else
|
||||
/// [`ScreenText::PLATFORM`].
|
||||
pub fn current() -> ScreenText {
|
||||
SYSTEM.lock().unwrap_or_else(std::sync::PoisonError::into_inner).unwrap_or(ScreenText::PLATFORM)
|
||||
}
|
||||
|
||||
/// Record the system's answer (`None`: it has none, so the platform's own way stands). Returns
|
||||
/// whether that changes how text is drawn, so the caller can ask for a repaint.
|
||||
pub fn set_system(answer: Option<ScreenText>) -> bool {
|
||||
let answer = answer.map(ScreenText::sanitized);
|
||||
let before = current();
|
||||
*SYSTEM.lock().unwrap_or_else(std::sync::PoisonError::into_inner) = answer;
|
||||
current() != before
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{ScreenText, SubpixelOrder};
|
||||
|
||||
#[test]
|
||||
fn the_platform_default_is_what_was_built_in() {
|
||||
let p = ScreenText::PLATFORM;
|
||||
assert_eq!(p.darkening > 0.0, cfg!(target_os = "macos"));
|
||||
assert_eq!(p.hinting, cfg!(all(unix, not(target_os = "macos"))));
|
||||
assert_eq!((p.subpixel, p.stripes), (None, None), "a stripe order only ever comes from the system");
|
||||
// Tests and headless screenshots never ask the system, so this is what they draw with.
|
||||
assert_eq!(super::current(), p);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn macos_font_smoothing_sets_the_darkening() {
|
||||
let strength = |level| ScreenText::from_macos(level).darkening;
|
||||
assert_eq!(strength(None), 1.0, "unset is the system's medium");
|
||||
assert_eq!((strength(Some(0)), strength(Some(1)), strength(Some(2)), strength(Some(3))), (0.0, 0.5, 1.0, 1.5));
|
||||
// Values Apple doesn't define: below the range is off, above it the strongest.
|
||||
assert_eq!((strength(Some(-4)), strength(Some(i64::MIN)), strength(Some(9)), strength(Some(i64::MAX))), (0.0, 0.0, 1.5, 1.5));
|
||||
let text = ScreenText::from_macos(None);
|
||||
assert!(!text.hinting && text.subpixel.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn windows_cleartype_gives_subpixel_edges_in_the_screens_order() {
|
||||
let order = |smoothing, kind, orientation| ScreenText::from_windows(smoothing, kind, orientation).subpixel;
|
||||
assert_eq!(order(Some("2"), Some(2), Some(1)), Some(SubpixelOrder::Rgb));
|
||||
assert_eq!(order(Some("2"), Some(2), Some(0)), Some(SubpixelOrder::Bgr));
|
||||
assert_eq!(order(Some("2"), Some(2), None), Some(SubpixelOrder::Rgb), "no orientation: RGB, as nearly every panel is");
|
||||
assert_eq!(order(None, Some(2), Some(1)), Some(SubpixelOrder::Rgb), "no on/off value: on, as Windows starts");
|
||||
// Greyscale smoothing, smoothing off, and a machine that says nothing.
|
||||
assert_eq!(order(Some("2"), Some(1), Some(1)), None);
|
||||
assert_eq!(order(Some("0"), Some(2), Some(1)), None);
|
||||
assert_eq!(order(Some(" 0 "), Some(2), Some(1)), None);
|
||||
assert_eq!(order(None, None, None), None);
|
||||
assert_eq!(order(Some("junk"), Some(u32::MAX), Some(u32::MAX)), None);
|
||||
let text = ScreenText::from_windows(Some("2"), Some(2), Some(1));
|
||||
assert!(!text.hinting && text.darkening == 0.0);
|
||||
// The screen's stripe order survives ClearType being off or greyscale, for a user who
|
||||
// chooses subpixel text themselves; no orientation value is no known order.
|
||||
let stripes = |smoothing, kind, orientation| ScreenText::from_windows(smoothing, kind, orientation).stripes;
|
||||
assert_eq!(stripes(Some("0"), Some(2), Some(0)), Some(SubpixelOrder::Bgr));
|
||||
assert_eq!(stripes(Some("2"), Some(1), Some(0)), Some(SubpixelOrder::Bgr));
|
||||
assert_eq!(stripes(Some("0"), None, Some(1)), Some(SubpixelOrder::Rgb));
|
||||
assert_eq!(stripes(Some("2"), Some(2), None), None);
|
||||
assert_eq!(stripes(Some("2"), Some(2), Some(7)), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gnome_settings_set_hinting_and_subpixel_edges() {
|
||||
assert_eq!(ScreenText::from_gnome(None, None, None), None, "a desktop without these settings says nothing");
|
||||
let text = |a, h, o| ScreenText::from_gnome(a, h, o).unwrap();
|
||||
// GNOME's own defaults: greyscale, slight hinting.
|
||||
assert_eq!(
|
||||
text(Some("grayscale"), Some("slight"), Some("rgb")),
|
||||
ScreenText { darkening: 0.0, hinting: true, subpixel: None, stripes: Some(SubpixelOrder::Rgb) }
|
||||
);
|
||||
assert_eq!(text(Some("rgba"), Some("slight"), Some("rgb")).subpixel, Some(SubpixelOrder::Rgb));
|
||||
assert_eq!(text(Some("rgba"), Some("slight"), Some("rgba")).subpixel, Some(SubpixelOrder::Rgb));
|
||||
assert_eq!(text(Some("rgba"), Some("slight"), Some("bgr")).subpixel, Some(SubpixelOrder::Bgr));
|
||||
assert_eq!(text(Some("rgba"), None, None).subpixel, Some(SubpixelOrder::Rgb));
|
||||
// Stripes across the screen, and no antialiasing: greyscale edges.
|
||||
assert_eq!(text(Some("rgba"), Some("slight"), Some("vrgb")).subpixel, None);
|
||||
assert_eq!(text(Some("rgba"), Some("slight"), Some("vbgr")).subpixel, None);
|
||||
assert_eq!(text(Some("none"), Some("slight"), Some("rgb")).subpixel, None);
|
||||
// Hinting: off only when the desktop says none.
|
||||
assert!(!text(Some("grayscale"), Some("none"), None).hinting);
|
||||
for style in ["slight", "medium", "full", "something new"] {
|
||||
assert!(text(None, Some(style), None).hinting, "{style}");
|
||||
}
|
||||
assert!(text(Some("grayscale"), None, None).hinting);
|
||||
// The stripe order is kept when the desktop asks for greyscale or no antialiasing.
|
||||
assert_eq!(text(Some("grayscale"), None, Some("bgr")).stripes, Some(SubpixelOrder::Bgr));
|
||||
assert_eq!(text(Some("none"), None, Some("rgb")).stripes, Some(SubpixelOrder::Rgb));
|
||||
assert_eq!(text(Some("rgba"), None, None).stripes, None, "no order named");
|
||||
assert_eq!(text(Some("grayscale"), None, Some("vbgr")).stripes, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn kde_settings_set_hinting_and_subpixel_edges() {
|
||||
assert_eq!(ScreenText::from_kde(None, None, None), None, "Plasma writes nothing until the font settings change");
|
||||
let text = |a, h, s| ScreenText::from_kde(a, h, s).unwrap();
|
||||
assert_eq!(
|
||||
text(Some("true"), Some("hintslight"), Some("rgb")),
|
||||
ScreenText { darkening: 0.0, hinting: true, subpixel: Some(SubpixelOrder::Rgb), stripes: Some(SubpixelOrder::Rgb) }
|
||||
);
|
||||
assert_eq!(text(Some("true"), Some("hintslight"), Some("bgr")).subpixel, Some(SubpixelOrder::Bgr));
|
||||
assert_eq!(text(None, None, Some("rgb")).subpixel, Some(SubpixelOrder::Rgb));
|
||||
for none in ["none", "vrgb", "vbgr", "junk"] {
|
||||
assert_eq!(text(Some("true"), None, Some(none)).subpixel, None, "{none}");
|
||||
}
|
||||
assert_eq!(text(Some("false"), None, Some("rgb")).subpixel, None, "antialiasing off");
|
||||
assert_eq!(text(Some(" False "), None, Some("rgb")).subpixel, None);
|
||||
assert!(!text(None, Some("hintnone"), None).hinting);
|
||||
assert!(text(None, Some("hintfull"), None).hinting && text(Some("true"), None, None).hinting);
|
||||
// The stripe order is kept with antialiasing off.
|
||||
assert_eq!(text(Some("false"), None, Some("bgr")).stripes, Some(SubpixelOrder::Bgr));
|
||||
assert_eq!(text(Some("true"), None, Some("none")).stripes, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn settings_go_into_the_page_options_as_numbers_a_raster_can_take() {
|
||||
let mut opts = wordcraft_render::RenderOptions::default();
|
||||
ScreenText { darkening: 1.5, hinting: true, subpixel: None, stripes: None }.apply(&mut opts);
|
||||
assert_eq!((opts.text_darkening, opts.hinting), (1.5, true));
|
||||
for (given, taken) in [(f32::NAN, 0.0), (f32::INFINITY, 0.0), (-3.0, 0.0), (40.0, 2.0), (0.5, 0.5)] {
|
||||
let text = ScreenText { darkening: given, hinting: false, subpixel: None, stripes: None };
|
||||
text.apply(&mut opts);
|
||||
assert_eq!((opts.text_darkening, opts.hinting), (taken, false), "{given}");
|
||||
assert_eq!(text.key(), ScreenText { darkening: taken, ..text }.key());
|
||||
}
|
||||
// Each setting changes the cache key.
|
||||
let base = ScreenText { darkening: 1.0, hinting: false, subpixel: None, stripes: None };
|
||||
assert_ne!(base.key(), ScreenText { darkening: 0.5, ..base }.key());
|
||||
assert_ne!(base.key(), ScreenText { hinting: true, ..base }.key());
|
||||
assert_ne!(base.key(), ScreenText { subpixel: Some(SubpixelOrder::Rgb), ..base }.key());
|
||||
assert_ne!(base.key(), ScreenText { stripes: Some(SubpixelOrder::Bgr), ..base }.key());
|
||||
assert_ne!(ScreenText { subpixel: Some(SubpixelOrder::Bgr), ..base }.key(), ScreenText { subpixel: Some(SubpixelOrder::Rgb), ..base }.key());
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ pub enum AutoSaveBlock {
|
||||
Unsaved,
|
||||
/// A file in a format that can't keep everything (Markdown, plain text, HTML…), by file name.
|
||||
Format { name: String },
|
||||
/// A file that was opened but not yet saved in this session; the switch shows off and lifts it.
|
||||
/// A file that was opened but not yet saved in this session.
|
||||
NotSavedHere,
|
||||
}
|
||||
|
||||
|
||||
@@ -3247,99 +3247,6 @@ fn autosave_is_unavailable_in_the_browser() {
|
||||
assert!(err.contains("browser"), "{err}");
|
||||
}
|
||||
|
||||
/// #3307: an opened file isn't rewritten until the user says so, but the switch says so
|
||||
/// without Save As: turning it on lets AutoSave write the file.
|
||||
#[test]
|
||||
fn turning_autosave_on_covers_a_file_only_opened_here() {
|
||||
let dir = scratch("autosave-opened");
|
||||
let path = dir.join("report.docx");
|
||||
let mut a = typed();
|
||||
a.run("file.save", json!({"path": path.to_string_lossy()})).unwrap();
|
||||
let mut b = app();
|
||||
b.run("file.open", json!({"path": path.to_string_lossy()})).unwrap();
|
||||
assert_eq!(b.autosave_block(), Some(AutoSaveBlock::NotSavedHere));
|
||||
assert_eq!(b.autosave_switch_block(), None, "the switch lifts it itself");
|
||||
b.run("text.insert", json!({"text": "Opened "})).unwrap();
|
||||
b.autosave_tick(monotonic_ms() + 10_000.0);
|
||||
assert!(b.session.dirty, "opening alone never rewrites the file");
|
||||
assert!(b.run("file.autosave", json!({"value": "false"})).is_err());
|
||||
assert!(!b.autosaves(), "a value that isn't a bool grants nothing");
|
||||
assert_eq!(b.run("file.autosave", json!({})).unwrap(), json!({"value": true}));
|
||||
assert!(b.autosaves());
|
||||
b.autosave_tick(monotonic_ms() + 20_000.0);
|
||||
assert!(!b.session.dirty, "AutoSave wrote the opened file");
|
||||
assert!(b.run("file.autosave", json!({"value": false})).is_ok());
|
||||
assert!(!b.autosaves());
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// `file.open` with `data` only names the file: the switch mustn't let AutoSave write a file of
|
||||
/// that name, which may hold something else entirely.
|
||||
#[test]
|
||||
fn the_autosave_switch_refuses_a_document_opened_from_bytes() {
|
||||
let dir = scratch("autosave-bytes");
|
||||
let path = dir.join("other.docx");
|
||||
let mut a = typed();
|
||||
a.run("file.save", json!({"path": path.to_string_lossy()})).unwrap();
|
||||
let on_disk = std::fs::read(&path).unwrap();
|
||||
let files = Arc::new(ScriptedFiles::new());
|
||||
let mut b = app_with_files(files.clone());
|
||||
let data = wordcraft_engine::cmd::insert::base64_encode(&on_disk);
|
||||
b.execute("file.open", json!({"path": path.to_string_lossy(), "data": data})).unwrap();
|
||||
assert_eq!(b.autosave_block(), Some(AutoSaveBlock::NotSavedHere));
|
||||
assert_eq!(b.autosave_switch_block(), Some(AutoSaveBlock::NotSavedHere), "the switch shows the block");
|
||||
assert!(b.run("file.autosave", json!({"value": true})).is_err());
|
||||
b.status = None;
|
||||
let err = b.run("file.autosave", json!({})).unwrap_err();
|
||||
assert_eq!(status_text(&b), Some(err.as_str()), "the status bar says why");
|
||||
b.run("text.insert", json!({"text": "Bytes "})).unwrap();
|
||||
b.autosave_tick(monotonic_ms() + 10_000.0);
|
||||
assert!(b.session.dirty);
|
||||
assert_eq!(std::fs::read(&path).unwrap(), on_disk, "the named file is untouched");
|
||||
// Open without a path only asks for the picker: it isn't a read of the shown file.
|
||||
script_pick(&files, None);
|
||||
b.run("file.open", json!({"path": null})).unwrap();
|
||||
assert!(b.run("file.autosave", json!({"value": true})).is_err(), "the picker request grants nothing");
|
||||
// A `data` that isn't a string is ignored and the file is read from disk.
|
||||
let mut c = app();
|
||||
c.run("file.open", json!({"path": path.to_string_lossy(), "data": null})).unwrap();
|
||||
assert!(c.run("file.autosave", json!({"value": true})).is_ok(), "read from disk");
|
||||
// Saving is still the way: then AutoSave covers the file.
|
||||
b.run("file.save", json!({})).unwrap();
|
||||
assert!(b.autosaves());
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// AutoSave turned off in one document stays off there when another document turns it on: the
|
||||
/// preference is shared, but each document's go-ahead is its own.
|
||||
#[test]
|
||||
fn autosave_turned_off_stays_off_when_another_document_turns_it_on() {
|
||||
let dir = scratch("autosave-two");
|
||||
let (first_path, second_path) = (dir.join("first.docx"), dir.join("second.docx"));
|
||||
let mut c = typed();
|
||||
c.run("file.save", json!({"path": second_path.to_string_lossy()})).unwrap();
|
||||
let mut a = typed();
|
||||
a.run("file.save", json!({"path": first_path.to_string_lossy()})).unwrap();
|
||||
let first = a.session.document_id();
|
||||
let saved = std::fs::read(&first_path).unwrap();
|
||||
assert!(a.autosaves());
|
||||
a.run("file.autosave", json!({"value": false})).unwrap();
|
||||
a.run("file.open", json!({"path": second_path.to_string_lossy()})).unwrap();
|
||||
assert_ne!(a.session.document_id(), first, "the second file opens beside the first");
|
||||
a.run("file.autosave", json!({"value": true})).unwrap();
|
||||
assert!(a.autosaves());
|
||||
a.show_document(first).unwrap();
|
||||
assert!(!a.autosaves(), "the first document's switch is still off");
|
||||
a.run("text.insert", json!({"text": "Later "})).unwrap();
|
||||
a.autosave_tick(monotonic_ms() + 10_000.0);
|
||||
assert!(a.session.dirty);
|
||||
assert_eq!(std::fs::read(&first_path).unwrap(), saved, "the first file is untouched");
|
||||
// Turned back on, it covers the file it was saved to without another save.
|
||||
a.run("file.autosave", json!({"value": true})).unwrap();
|
||||
assert!(a.autosaves());
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// Cancelling the Open picker (Mod+O) left the document as it was but turned AutoSave off.
|
||||
#[test]
|
||||
fn cancelling_open_keeps_autosave() {
|
||||
|
||||
@@ -179,6 +179,12 @@ impl WordApp {
|
||||
ctx: _,
|
||||
read_aloud_error: _,
|
||||
saves_in_flight: _,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
windowless_save_folders: _,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
owned_picks: _,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
native_windows: _,
|
||||
recovery_seen: _,
|
||||
no_document: _,
|
||||
windows: _,
|
||||
@@ -186,7 +192,6 @@ impl WordApp {
|
||||
clipboard_published: _,
|
||||
// Per document: the shown document's, swapped with `parked` on a document switch.
|
||||
autosave_path: _,
|
||||
read_from: _,
|
||||
parked: _,
|
||||
// Per window.
|
||||
ui,
|
||||
|
||||
+338
-39
@@ -1,6 +1,6 @@
|
||||
//! One native window per open document. The app's windows are a [`craft_window::WindowList`]: one
|
||||
//! entry is the root OS window (drawn by the app's own shell), every other entry is shown as a
|
||||
//! [`DocumentWindow`] in an OS window of its own. Each draws the whole interface (title bar,
|
||||
//! entry normally uses the root OS window. Other entries (or all entries in the windowless trial)
|
||||
//! use [`DocumentWindow`] in OS windows of their own. Each draws the whole interface (title bar,
|
||||
//! ribbon, page, status bar, dialogs) for its own document. [`WordApp`]'s fields hold the drawn
|
||||
//! window's state ([`crate::window_ui`]); the other windows keep theirs in their [`Window`].
|
||||
//! Between frames the fields hold the active window's (the one focused last), so the control
|
||||
@@ -71,6 +71,25 @@ fn window_container_id(id: WindowId) -> egui::Id {
|
||||
egui::Id::unique(("wordcraft.window", id.get()))
|
||||
}
|
||||
|
||||
/// The native surface of a window in the windowless trial.
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
enum NativeMount {
|
||||
Pending,
|
||||
Attached,
|
||||
Rejected,
|
||||
}
|
||||
|
||||
/// Where an owned file pick's window stands ([`crate::file_dialogs`]).
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
pub(crate) enum OwnerSurface {
|
||||
/// The window closed, shows another document, its document closed, or its surface was rejected.
|
||||
Gone,
|
||||
/// Live, its native surface not attached yet.
|
||||
Pending,
|
||||
/// Attached: the viewport its host names for it (if any) and the mount attempt that attached.
|
||||
Attached { viewport: Option<ViewportId>, attempt: u64 },
|
||||
}
|
||||
|
||||
/// An open window.
|
||||
pub(crate) struct Window {
|
||||
/// The document it shows.
|
||||
@@ -88,12 +107,34 @@ pub(crate) struct Window {
|
||||
raise: bool,
|
||||
/// Its OS window opens cascaded from the window before it; used once, when it first shows.
|
||||
place: bool,
|
||||
mount: NativeMount,
|
||||
/// A retry uses a fresh declaration: eframe blocks a rejected id until it has seen a full pass without it.
|
||||
mount_attempt: u64,
|
||||
/// Tests: the viewport an attached window reports without a window host.
|
||||
#[cfg(test)]
|
||||
test_viewport: Option<ViewportId>,
|
||||
}
|
||||
|
||||
impl Window {
|
||||
/// A window on `doc`; `place` cascades its OS window from the others when it first shows.
|
||||
fn new(doc: u64, ui: Option<Box<WindowUi>>, view: Option<WindowView>, place: bool) -> Window {
|
||||
Window { doc, ui, requests: Vec::new(), view, raise: false, place }
|
||||
Window {
|
||||
doc,
|
||||
ui,
|
||||
requests: Vec::new(),
|
||||
view,
|
||||
raise: false,
|
||||
place,
|
||||
mount: NativeMount::Pending,
|
||||
mount_attempt: 0,
|
||||
#[cfg(test)]
|
||||
test_viewport: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn container_id(&self, id: WindowId) -> egui::Id {
|
||||
let base = window_container_id(id);
|
||||
if self.mount_attempt == 0 { base } else { base.with(self.mount_attempt) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,8 +144,9 @@ pub struct Windows {
|
||||
native: bool,
|
||||
/// Every window, in opening and focus order.
|
||||
list: WindowList<Window>,
|
||||
/// The entry the root OS window shows.
|
||||
/// The entry the root OS window shows in the ordinary windowed mode.
|
||||
root: WindowId,
|
||||
windowless_trial: bool,
|
||||
/// The window whose state is in [`WordApp`]'s fields.
|
||||
shown: WindowId,
|
||||
/// View › Window: Side by Side and Synchronous Scrolling (#322).
|
||||
@@ -119,7 +161,21 @@ impl Windows {
|
||||
pub(crate) fn new(doc: u64) -> Windows {
|
||||
let mut list = WindowList::new();
|
||||
let id = list.open(Window::new(doc, None, None, false));
|
||||
Windows { native: cfg!(not(target_arch = "wasm32")), list, root: id, shown: id, arranged: arrange::State::default(), root_focused: false }
|
||||
Windows {
|
||||
native: cfg!(not(target_arch = "wasm32")),
|
||||
list,
|
||||
root: id,
|
||||
windowless_trial: false,
|
||||
shown: id,
|
||||
arranged: arrange::State::default(),
|
||||
root_focused: false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether every native document is drawn in a child viewport.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) fn windowless_trial(&self) -> bool {
|
||||
self.windowless_trial
|
||||
}
|
||||
|
||||
/// Whether documents get native windows of their own.
|
||||
@@ -151,7 +207,7 @@ impl Windows {
|
||||
/// The key of the window drawn now: `main` for the root entry, else one of its own, so two
|
||||
/// windows never share a placement or shell key.
|
||||
pub(crate) fn window_key(&self) -> WindowKey {
|
||||
if self.shown == self.root { WindowKey::main() } else { WindowKey::new(format!("window-{}", self.shown.get())) }
|
||||
if !self.windowless_trial && self.shown == self.root { WindowKey::main() } else { WindowKey::new(format!("window-{}", self.shown.get())) }
|
||||
}
|
||||
|
||||
/// The viewports whose OS window is open: the root's and every other window's.
|
||||
@@ -176,9 +232,17 @@ impl Windows {
|
||||
self.list.get_mut(id)
|
||||
}
|
||||
|
||||
/// The window showing document `doc`, the most recently focused if several do.
|
||||
/// The most recently focused window showing document `doc`, preferring an attached view.
|
||||
fn of_doc(&self, doc: u64) -> Option<u64> {
|
||||
self.list.recent().find(|&id| self.list.get(id).is_some_and(|w| w.doc == doc)).map(WindowId::get)
|
||||
let mut fallback = None;
|
||||
for id in self.list.recent() {
|
||||
let Some(w) = self.list.get(id).filter(|w| w.doc == doc) else { continue };
|
||||
if !self.windowless_trial || w.mount == NativeMount::Attached {
|
||||
return Some(id.get());
|
||||
}
|
||||
fallback.get_or_insert(id.get());
|
||||
}
|
||||
fallback
|
||||
}
|
||||
|
||||
/// The document of the window focused last before `key`'s, if any.
|
||||
@@ -192,10 +256,18 @@ impl Windows {
|
||||
/// The viewport window `id` draws in, while its OS window is open: the root's for the root
|
||||
/// entry, else the one the window host names for the window's container.
|
||||
fn viewport_of(&self, ctx: &egui::Context, id: WindowId) -> Option<ViewportId> {
|
||||
if id == self.root {
|
||||
if !self.windowless_trial && id == self.root {
|
||||
return Some(ViewportId::ROOT);
|
||||
}
|
||||
WindowHost::of(ctx).viewport_of(window_container_id(id))
|
||||
let window = self.list.get(id)?;
|
||||
if self.windowless_trial && window.mount != NativeMount::Attached {
|
||||
return None;
|
||||
}
|
||||
#[cfg(test)]
|
||||
if let Some(viewport) = window.test_viewport {
|
||||
return Some(viewport);
|
||||
}
|
||||
WindowHost::of(ctx).viewport_of(window.container_id(id))
|
||||
}
|
||||
|
||||
/// [`Windows::viewport_of`] for the window with the app's key `key`.
|
||||
@@ -205,25 +277,46 @@ impl Windows {
|
||||
}
|
||||
|
||||
impl WordApp {
|
||||
/// How many windows are open.
|
||||
pub fn window_count(&self) -> usize {
|
||||
if self.windows.native { self.windows.list.len() } else { 1 }
|
||||
/// Match the private native trial's logical root. Call only at startup.
|
||||
pub fn enable_windowless_trial(&mut self, enabled: bool) {
|
||||
self.windows.windowless_trial = enabled && self.windows.native;
|
||||
}
|
||||
|
||||
/// The egui viewport of the active window, the one focused last: control input,
|
||||
/// `ui.screenshot` and `ui.resize` are its. The root viewport when the windows don't have
|
||||
/// viewports of their own (the web app, embedded viewports) or the window has none yet.
|
||||
/// How many windows are open.
|
||||
pub fn window_count(&self) -> usize {
|
||||
if self.windows.windowless_trial {
|
||||
self.windows.list.iter().filter(|(_, w)| w.mount != NativeMount::Rejected).count()
|
||||
} else if self.windows.native {
|
||||
self.windows.list.len()
|
||||
} else {
|
||||
1
|
||||
}
|
||||
}
|
||||
|
||||
/// The egui viewport of the active window, the one focused last. Returns ROOT when there is
|
||||
/// no viewport yet, or in a host without separate windows. Use `control_viewport` for effects.
|
||||
pub fn active_viewport(&self) -> ViewportId {
|
||||
let Some(ctx) = self.ctx.as_ref().filter(|ctx| self.windows.native && WindowHost::of(ctx).opens_windows()) else { return ViewportId::ROOT };
|
||||
let id = self.windows.list.active().unwrap_or(self.windows.shown);
|
||||
self.windows.viewport_of(ctx, id).unwrap_or(ViewportId::ROOT)
|
||||
}
|
||||
|
||||
/// A target for control input and native effects. In the trial, an unregistered child cannot
|
||||
/// fall back to logical ROOT: sending Close there means Quit, and other effects are discarded.
|
||||
pub(crate) fn control_viewport(&self) -> Result<ViewportId, &'static str> {
|
||||
let viewport = self.active_viewport();
|
||||
if self.windows.windowless_trial && viewport == ViewportId::ROOT {
|
||||
Err("the active document window is not ready; retry once it opens")
|
||||
} else {
|
||||
Ok(viewport)
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a close request for the root viewport closes only the window drawn there: true
|
||||
/// while other windows are open. The root adopts another entry then, and the host keeps the
|
||||
/// app running.
|
||||
pub fn closes_a_window(&self) -> bool {
|
||||
self.window_count() > 1 && !self.quit_requested
|
||||
!self.windows.windowless_trial && self.window_count() > 1 && !self.quit_requested
|
||||
}
|
||||
|
||||
/// Quit the app (the app menu's Quit): ask about every document with unsaved work, each in
|
||||
@@ -242,6 +335,79 @@ impl WordApp {
|
||||
self.windows.get(key).is_some_and(|w| w.doc == document)
|
||||
}
|
||||
|
||||
/// Where window `key`, owning a pick for `document`, stands (windowless trial).
|
||||
pub(crate) fn pick_owner_surface(&self, ctx: &egui::Context, key: u64, document: u64) -> OwnerSurface {
|
||||
if !self.window_shows_document(key, document) {
|
||||
return OwnerSurface::Gone;
|
||||
}
|
||||
let Some(w) = self.windows.get(key) else { return OwnerSurface::Gone };
|
||||
match w.mount {
|
||||
NativeMount::Rejected => OwnerSurface::Gone,
|
||||
NativeMount::Pending => OwnerSurface::Pending,
|
||||
NativeMount::Attached => OwnerSurface::Attached { viewport: self.windows.viewport(ctx, key), attempt: w.mount_attempt },
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether window `key` shows open document `document` now. The drawn window's entry is updated
|
||||
/// only when another window is drawn, so its document is read from the drawn state.
|
||||
pub(crate) fn window_shows_document(&self, key: u64, document: u64) -> bool {
|
||||
self.window_document(key) == Some(document) && self.session.is_open(document)
|
||||
}
|
||||
|
||||
/// The document window `key` shows, read from the drawn state for the drawn window.
|
||||
pub(crate) fn window_document(&self, key: u64) -> Option<u64> {
|
||||
if key == self.windows.shown() { Some(self.shown_document) } else { self.windows.get(key).map(|w| w.doc) }
|
||||
}
|
||||
|
||||
/// Clear the per-window state a pick of window `key` left pending (Change Picture's target, a
|
||||
/// recipient list being chosen), in its parked state when another window is drawn.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) fn clear_window_pick_state(&mut self, key: u64, picture: bool, recipients: bool) {
|
||||
if key == self.windows.shown() {
|
||||
if picture {
|
||||
self.change_picture_target = None;
|
||||
}
|
||||
if recipients {
|
||||
self.recipient_list_pending = false;
|
||||
}
|
||||
} else if let Some(ui) = self.windows.get_mut(key).and_then(|w| w.ui.as_mut()) {
|
||||
if picture {
|
||||
ui.change_picture_target = None;
|
||||
}
|
||||
if recipients {
|
||||
ui.recipient_list_pending = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The mount attempt window `key` is attached with, if it is attached.
|
||||
pub(crate) fn attached_attempt(&self, key: u64) -> Option<u64> {
|
||||
self.windows.get(key).filter(|w| w.mount == NativeMount::Attached).map(|w| w.mount_attempt)
|
||||
}
|
||||
|
||||
/// Tests: window `key`'s surface attached, its host naming `viewport` for it.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn attach_window_for_test(&mut self, key: u64, viewport: ViewportId) {
|
||||
if let Some(w) = self.windows.get_mut(key) {
|
||||
w.mount = NativeMount::Attached;
|
||||
w.test_viewport = Some(viewport);
|
||||
}
|
||||
}
|
||||
|
||||
/// Tests: window `key`'s surface rejected and mounted again, as a retry after a failed attach does.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn remount_window_for_test(&mut self, key: u64) {
|
||||
if let Some(w) = self.windows.get_mut(key) {
|
||||
w.mount = NativeMount::Rejected;
|
||||
}
|
||||
self.focus_window(key);
|
||||
}
|
||||
|
||||
/// Window `key`'s dialog host, wherever its state is.
|
||||
pub(crate) fn window_dialog_host(&self, key: u64) -> Option<&craft::ui::dialog::DialogHost> {
|
||||
if key == self.windows.shown() { Some(&self.dialog_host) } else { self.windows.get(key)?.ui.as_ref().map(|ui| &ui.dialog_host) }
|
||||
}
|
||||
|
||||
pub(crate) fn window_dialog_host_mut(&mut self, key: u64) -> Option<&mut craft::ui::dialog::DialogHost> {
|
||||
if key == self.windows.shown() { Some(&mut self.dialog_host) } else { self.windows.get_mut(key)?.ui.as_mut().map(|ui| &mut ui.dialog_host) }
|
||||
}
|
||||
@@ -331,10 +497,13 @@ impl WordApp {
|
||||
}
|
||||
|
||||
/// Close the drawn window alone: other windows show its document, which stays open as it is.
|
||||
pub(crate) fn close_window_only(&mut self) -> bool {
|
||||
let Some(next) = self.other_window_on_document() else { return false };
|
||||
pub(crate) fn close_window_only(&mut self) -> Result<bool, String> {
|
||||
let Some(next) = self.other_window_on_document() else { return Ok(false) };
|
||||
if let Some(error) = self.rejected_draft_blocks_last_surface_close() {
|
||||
return Err(error);
|
||||
}
|
||||
self.close_shown_window(next);
|
||||
true
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// The drawn window's document has closed: draw window `to` and close this one.
|
||||
@@ -353,6 +522,14 @@ impl WordApp {
|
||||
self.windows.list.focus(id);
|
||||
if let Some(w) = self.windows.list.get_mut(id) {
|
||||
w.raise = true;
|
||||
if w.mount == NativeMount::Rejected {
|
||||
w.mount = NativeMount::Pending;
|
||||
w.mount_attempt = w.mount_attempt.wrapping_add(1);
|
||||
w.place = true;
|
||||
if let Some(ctx) = &self.ctx {
|
||||
ctx.request_repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
self.settle_windows();
|
||||
@@ -361,7 +538,8 @@ impl WordApp {
|
||||
/// The root OS window shows an entry that is open: when its own closed, the active one moves
|
||||
/// in. Each window's page state is its own, so the page keeps its place.
|
||||
fn settle_windows(&mut self) {
|
||||
if !self.windows.list.contains(self.windows.root)
|
||||
if !self.windows.windowless_trial
|
||||
&& !self.windows.list.contains(self.windows.root)
|
||||
&& let Some(next) = self.windows.list.active()
|
||||
{
|
||||
self.windows.root = next;
|
||||
@@ -436,6 +614,9 @@ impl WordApp {
|
||||
/// it comes forward; else the window shows the next document. The session leaves a new blank
|
||||
/// document when it was the last.
|
||||
pub(crate) fn close_shown_document(&mut self) -> Result<(), String> {
|
||||
if let Some(error) = self.rejected_draft_blocks_last_surface_close() {
|
||||
return Err(error);
|
||||
}
|
||||
let doc = self.session.document_id();
|
||||
let next = self.windows.next_doc(self.windows.shown());
|
||||
self.session.close_document(doc).map_err(|e| e.to_string())?;
|
||||
@@ -535,27 +716,32 @@ impl WordApp {
|
||||
self.after_windows();
|
||||
return;
|
||||
}
|
||||
let raise_root = self.windows.list.get_mut(self.windows.root).is_some_and(|w| std::mem::take(&mut w.raise));
|
||||
if raise_root {
|
||||
WindowHost::of(&ctx).act(ViewportId::ROOT, WindowAction::Focus);
|
||||
if !self.windows.windowless_trial {
|
||||
let raise_root = self.windows.list.get_mut(self.windows.root).is_some_and(|w| std::mem::take(&mut w.raise));
|
||||
if raise_root {
|
||||
WindowHost::of(&ctx).act(ViewportId::ROOT, WindowAction::Focus);
|
||||
}
|
||||
self.draw_entry(ui, self.windows.root.get());
|
||||
// The root window gaining OS focus makes its entry the active one, as a child's `focus_gained` does.
|
||||
let root_focused = WindowHost::of(&ctx).facts(ViewportId::ROOT).is_some_and(|facts| facts.focused);
|
||||
if root_focused && !std::mem::replace(&mut self.windows.root_focused, root_focused) {
|
||||
self.windows.list.focus(self.windows.root);
|
||||
}
|
||||
self.windows.root_focused = root_focused;
|
||||
}
|
||||
self.draw_entry(ui, self.windows.root.get());
|
||||
let root = self.windows.root;
|
||||
// The root window gaining OS focus makes its entry the active one, as a child's `focus_gained` does.
|
||||
let root_focused = WindowHost::of(&ctx).facts(ViewportId::ROOT).is_some_and(|facts| facts.focused);
|
||||
if root_focused && !std::mem::replace(&mut self.windows.root_focused, root_focused) {
|
||||
self.windows.list.focus(root);
|
||||
}
|
||||
self.windows.root_focused = root_focused;
|
||||
let menu = self.window_menu();
|
||||
let step = StyleCx::with_root(&ctx, |cx| cx.tokens.size.window.cascade);
|
||||
let ids: Vec<WindowId> = self.windows.list.ids().filter(|&id| id != root).collect();
|
||||
let ids: Vec<WindowId> = self.windows.list.ids().filter(|&id| self.windows.windowless_trial || id != self.windows.root).collect();
|
||||
let mut closes = Vec::new();
|
||||
let mut rejected = Vec::new();
|
||||
for id in ids {
|
||||
let Some(w) = self.windows.list.get_mut(id) else { continue };
|
||||
if w.mount == NativeMount::Rejected {
|
||||
continue;
|
||||
}
|
||||
let (raise, place) = (std::mem::take(&mut w.raise), std::mem::take(&mut w.place));
|
||||
let mut window = DocumentWindow::new(Self::title_in(&menu, id))
|
||||
.id(window_container_id(id))
|
||||
.id(w.container_id(id))
|
||||
.overlay(|overlay| overlay.size_limits(SizeLimits::at_least(MIN_SIZE)));
|
||||
if raise {
|
||||
window = window.raise();
|
||||
@@ -563,7 +749,29 @@ impl WordApp {
|
||||
if place && let Some(rect) = self.cascade_from(ui, id, step) {
|
||||
window = window.first_placed(rect);
|
||||
}
|
||||
let out = window.show(ui, |ui, cx| self.draw_window(ui, cx, id)).output;
|
||||
let shown = if self.windows.windowless_trial {
|
||||
match window.try_show(ui, |ui, cx| self.draw_window(ui, cx, id)) {
|
||||
Ok(shown) => shown,
|
||||
Err(_) => {
|
||||
if let Some(w) = self.windows.list.get_mut(id) {
|
||||
w.mount = NativeMount::Rejected;
|
||||
rejected.push(id);
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
self.cancel_windowless_save_as_for_mount_failure(&ctx, id.get());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
window.show(ui, |ui, cx| self.draw_window(ui, cx, id))
|
||||
};
|
||||
if self.windows.windowless_trial
|
||||
&& shown.inner.is_some()
|
||||
&& let Some(w) = self.windows.list.get_mut(id)
|
||||
{
|
||||
w.mount = NativeMount::Attached;
|
||||
}
|
||||
let out = shown.output;
|
||||
if out.focus_gained {
|
||||
self.windows.list.focus(id);
|
||||
}
|
||||
@@ -571,10 +779,84 @@ impl WordApp {
|
||||
closes.push(id);
|
||||
}
|
||||
}
|
||||
self.window_events(&closes);
|
||||
self.recover_rejected_mounts(&rejected, &ctx);
|
||||
self.window_events(&closes, &ctx);
|
||||
self.after_windows();
|
||||
}
|
||||
|
||||
/// Quit cannot ask about a draft while every view of it lacks a native surface.
|
||||
pub(crate) fn rejected_draft_blocks_quit(&mut self) -> Option<String> {
|
||||
self.report_unavailable_draft(None)
|
||||
}
|
||||
|
||||
/// Closing a document or its view must not retire the last surface if another unsaved
|
||||
/// document may still be inaccessible. The user can retry its view first.
|
||||
pub(crate) fn rejected_draft_blocks_last_surface_close(&mut self) -> Option<String> {
|
||||
let shown = self.windows.shown;
|
||||
if !self.windows.windowless_trial
|
||||
|| self.windows.list.get(shown).is_none_or(|w| w.mount != NativeMount::Attached)
|
||||
|| self.windows.list.iter().any(|(id, w)| id != shown && w.mount == NativeMount::Attached)
|
||||
{
|
||||
return None;
|
||||
}
|
||||
self.report_unavailable_draft(Some(shown))
|
||||
}
|
||||
|
||||
fn report_unavailable_draft(&mut self, without: Option<WindowId>) -> Option<String> {
|
||||
if !self.windows.windowless_trial {
|
||||
return None;
|
||||
}
|
||||
let blocked = self.windows.list.iter().any(|(_, window)| {
|
||||
window.mount != NativeMount::Attached
|
||||
&& (window.mount_attempt > 0 || window.mount == NativeMount::Rejected)
|
||||
&& (self.document_unsaved_by_id(window.doc) || self.document_has_comment_drafts(window.doc))
|
||||
&& !self.windows.list.iter().any(|(id, other)| Some(id) != without && other.doc == window.doc && other.mount == NativeMount::Attached)
|
||||
});
|
||||
if !blocked {
|
||||
return None;
|
||||
}
|
||||
let message = tl!("An unsaved document's window did not open. Use View > Switch Windows to retry before closing.").to_string();
|
||||
self.status_long(message.clone());
|
||||
if let Some(ctx) = &self.ctx {
|
||||
ctx.request_repaint_of(ViewportId::ROOT);
|
||||
}
|
||||
Some(message)
|
||||
}
|
||||
|
||||
/// Stop declaring failed surfaces without closing their documents or taking down other windows.
|
||||
fn recover_rejected_mounts(&mut self, rejected: &[WindowId], ctx: &egui::Context) {
|
||||
if rejected.is_empty() {
|
||||
return;
|
||||
}
|
||||
for id in rejected {
|
||||
log::warn!("native document window {} could not be opened", id.get());
|
||||
}
|
||||
if self.closing.as_ref().is_some_and(|c| rejected.iter().any(|id| id.get() == c.window)) {
|
||||
// Its dialog cannot be answered. End the close operation without deciding for the user.
|
||||
self.cancel_closing();
|
||||
}
|
||||
let survivor = self
|
||||
.windows
|
||||
.list
|
||||
.recent()
|
||||
.find(|&id| self.windows.list.get(id).is_some_and(|w| w.mount == NativeMount::Attached && self.session.is_open(w.doc)));
|
||||
if let Some(survivor) = survivor {
|
||||
self.enter_window(survivor.get());
|
||||
self.windows.list.focus(survivor);
|
||||
self.status_long(tl!("A document window could not open. Use View > Switch Windows to try again."));
|
||||
} else if self.window_count() == 0 {
|
||||
// All native declarations failed. A clean startup can exit normally rather than wait
|
||||
// on an invisible window; never discard work that automation has already changed.
|
||||
if self.has_unsaved_documents() {
|
||||
log::error!("no native document window opened; WordCraft is keeping unsaved documents open");
|
||||
} else {
|
||||
log::error!("no native document window opened; restart WordCraft without the windowless trial");
|
||||
self.quit();
|
||||
}
|
||||
}
|
||||
ctx.request_repaint();
|
||||
}
|
||||
|
||||
/// After the frame's drawing: windows opened or closed meanwhile settle, and the active
|
||||
/// window's state comes back.
|
||||
fn after_windows(&mut self) {
|
||||
@@ -614,19 +896,31 @@ impl WordApp {
|
||||
if self.windows.shown() != key {
|
||||
return;
|
||||
}
|
||||
// `PathRow` picks filed while this window draws belong to it and its document (windowless trial).
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
let rows = self.enter_row_scope(&ctx);
|
||||
self.window_ui(ui);
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
self.leave_row_scope(rows);
|
||||
arrange::forward_scroll(self, &ctx);
|
||||
}
|
||||
|
||||
/// The close requests of the windows' close buttons from this frame: File › Close in that
|
||||
/// window, which asks about unsaved changes first. The last window's close quits, which the
|
||||
/// host asks about ([`WordApp::close_requested`]).
|
||||
fn window_events(&mut self, closes: &[WindowId]) {
|
||||
fn window_events(&mut self, closes: &[WindowId], ctx: &egui::Context) {
|
||||
for &id in closes {
|
||||
if self.quit_requested || self.windows.list.len() <= 1 || !self.windows.list.contains(id) {
|
||||
if self.quit_requested || !self.windows.list.contains(id) {
|
||||
continue;
|
||||
}
|
||||
self.close_window(id.get());
|
||||
if self.window_count() > 1 {
|
||||
self.close_window(id.get());
|
||||
} else if self.windows.windowless_trial && self.closing.is_none() && self.enter_window(id.get()) {
|
||||
// No native root close will follow. Quit through the existing guard, then let
|
||||
// the host's next logic pass send Close to the logical root.
|
||||
self.quit();
|
||||
ctx.request_repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -636,6 +930,11 @@ impl WordApp {
|
||||
if self.raise_closing().is_some() {
|
||||
return;
|
||||
}
|
||||
// Its own system file dialog may still use this window: close it once that has ended.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if self.defer_close_for_native_panel(key) {
|
||||
return;
|
||||
}
|
||||
if !self.enter_window(key) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -119,6 +119,155 @@ fn text(a: &WordApp) -> String {
|
||||
a.session.doc.plain_text(StoryRef::Body).trim().to_string()
|
||||
}
|
||||
|
||||
/// Run through the real immediate viewport declaration with a renderer that declines one
|
||||
/// attachment as eframe does: it returns without calling that viewport's body.
|
||||
fn rejecting_frame(kit: &Kit, a: &mut WordApp, rejected: Option<ViewportId>) -> (Vec<ViewportId>, Vec<ViewportId>) {
|
||||
mount_frame(kit, a, rejected, None)
|
||||
}
|
||||
|
||||
fn mount_frame(kit: &Kit, a: &mut WordApp, rejected: Option<ViewportId>, closing: Option<ViewportId>) -> (Vec<ViewportId>, Vec<ViewportId>) {
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
let calls = Rc::new(RefCell::new((Vec::new(), Vec::new())));
|
||||
// egui's renderer is thread-local and libtest runs each case on its own thread. The
|
||||
// weak reference also disarms rejection and close injection after this frame returns.
|
||||
let rendered = Rc::downgrade(&calls);
|
||||
let rect = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(800.0, 600.0));
|
||||
egui::Context::set_immediate_viewport_renderer(move |ctx, mut viewport| {
|
||||
let id = viewport.ids.this;
|
||||
let frame = rendered.upgrade();
|
||||
if let Some(frame) = &frame {
|
||||
frame.borrow_mut().0.push(id);
|
||||
if rejected == Some(id) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
let events = if frame.is_some() && closing == Some(id) { vec![ViewportEvent::Close] } else { Vec::new() };
|
||||
let info = ViewportInfo { parent: Some(viewport.ids.parent), inner_rect: Some(rect), outer_rect: Some(rect), events, ..Default::default() };
|
||||
let mut input = egui::RawInput { viewport_id: id, screen_rect: Some(rect), ..Default::default() };
|
||||
input.viewports.insert(id, info);
|
||||
ctx.run_ui(input, |ui| (viewport.viewport_ui_cb)(ui)).drop_without_applying_deltas();
|
||||
if let Some(frame) = frame {
|
||||
frame.borrow_mut().1.push(id);
|
||||
}
|
||||
});
|
||||
craft::ui::shell::embed::before_input(&kit.ctx, |out| a.frame_input(out));
|
||||
// Both passes discard texture deltas: don't mix this fake renderer with Kit's backing
|
||||
// texture store, which would then see root updates for allocations discarded by the child.
|
||||
let input = egui::RawInput { screen_rect: Some(rect), ..Default::default() };
|
||||
kit.ctx
|
||||
.run_ui(input, |ui| {
|
||||
a.logic(ui.ctx());
|
||||
a.ui(ui);
|
||||
})
|
||||
.drop_without_applying_deltas();
|
||||
std::mem::take(&mut *calls.borrow_mut())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejected_child_keeps_its_draft_and_the_survivor_can_edit_and_retry() {
|
||||
let kit = Kit::new();
|
||||
let mut a = app("Survivor draft");
|
||||
a.enable_windowless_trial(true);
|
||||
let survivor = a.windows.shown();
|
||||
let survivor_doc = a.session.document_id();
|
||||
let (_, drawn) = rejecting_frame(&kit, &mut a, None);
|
||||
let survivor_view = a.windows.viewport(&kit.ctx, survivor).unwrap();
|
||||
assert!(drawn.contains(&survivor_view));
|
||||
|
||||
a.run("file.new", json!({})).unwrap();
|
||||
a.run("text.insert", json!({"text": "Parked draft"})).unwrap();
|
||||
let parked = a.windows.shown();
|
||||
let parked_doc = a.session.document_id();
|
||||
let rejected = ViewportId::from_hash_of(super::window_container_id(a.windows.id_of(parked).unwrap()));
|
||||
let (attempted, drawn) = rejecting_frame(&kit, &mut a, Some(rejected));
|
||||
assert!(attempted.contains(&rejected) && !drawn.contains(&rejected));
|
||||
assert!(drawn.contains(&survivor_view));
|
||||
assert_eq!((a.windows.shown(), a.session.document_id()), (survivor, survivor_doc));
|
||||
assert_eq!(a.windows.viewport(&kit.ctx, survivor), Some(survivor_view));
|
||||
assert_eq!(a.windows.viewport(&kit.ctx, parked), None);
|
||||
assert!(a.status_message().is_some(), "the surviving window is warned");
|
||||
assert!(!a.quit_requested && a.closing.is_none());
|
||||
assert!(a.session.document_dirty(parked_doc));
|
||||
a.run("text.insert", json!({"text": " continues"})).unwrap();
|
||||
assert_eq!(text(&a), "Survivor draft continues");
|
||||
let (attempted, _) = rejecting_frame(&kit, &mut a, Some(rejected));
|
||||
assert!(!attempted.contains(&rejected), "an unrelated repaint cannot retry the failed declaration");
|
||||
|
||||
mount_frame(&kit, &mut a, Some(rejected), Some(survivor_view));
|
||||
assert!(!a.quit_requested && a.closing.is_none(), "native Close cannot consume the only attached surface or start an invisible guard");
|
||||
assert_eq!(a.windows.viewport(&kit.ctx, survivor), Some(survivor_view));
|
||||
assert!(a.run("file.close", json!({})).is_err(), "interactive File Close cannot open an unrelated Save Changes prompt");
|
||||
assert!(a.closing.is_none());
|
||||
let quit = a.ask_before_quit();
|
||||
assert_eq!(quit["quit"], false);
|
||||
assert!(quit["error"].is_string() && a.closing.is_none(), "explicit Quit reports why it is refused");
|
||||
assert!(a.session.document_dirty(survivor_doc) && a.session.document_dirty(parked_doc));
|
||||
|
||||
a.show_window(parked);
|
||||
let (_, drawn) = rejecting_frame(&kit, &mut a, Some(rejected));
|
||||
let new_view = a.windows.viewport(&kit.ctx, parked).unwrap();
|
||||
assert_ne!(new_view, rejected);
|
||||
assert!(drawn.contains(&new_view) && drawn.contains(&survivor_view));
|
||||
assert_eq!(a.session.document_id(), parked_doc);
|
||||
assert_eq!(text(&a), "Parked draft");
|
||||
assert!(!a.quit());
|
||||
assert!(a.closing.is_some(), "after a successful retry, Quit can ask in the document's own window");
|
||||
a.run("ui.saveChanges", json!({"answer": "cancel"})).unwrap();
|
||||
assert!(!a.quit_requested && a.closing.is_none());
|
||||
assert!(a.session.document_dirty(survivor_doc) && a.session.document_dirty(parked_doc));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn closing_an_attached_view_does_not_close_the_dirty_document_behind_its_rejected_peer() {
|
||||
let kit = Kit::new();
|
||||
let mut a = app("Shared unsaved draft");
|
||||
a.enable_windowless_trial(true);
|
||||
let doc = a.session.document_id();
|
||||
let survivor = a.windows.shown();
|
||||
rejecting_frame(&kit, &mut a, None);
|
||||
|
||||
a.new_window();
|
||||
let peer = a.windows.id_of(a.windows.shown()).unwrap();
|
||||
let rejected = ViewportId::from_hash_of(super::window_container_id(peer));
|
||||
rejecting_frame(&kit, &mut a, Some(rejected));
|
||||
assert!(a.closes_only_its_window("file.close", &json!({})));
|
||||
assert!(a.execute("file.close", json!({})).is_err(), "the rejected view-only close is not retried as a document close");
|
||||
assert_eq!(a.windows.shown(), survivor);
|
||||
assert_eq!(a.session.document_id(), doc);
|
||||
assert!(a.session.dirty && a.closing.is_none());
|
||||
assert_eq!(text(&a), "Shared unsaved draft");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_clean_start_with_no_attached_document_window_requests_shutdown() {
|
||||
let kit = Kit::new();
|
||||
let mut a = WordApp::new(Session::new(wordcraft_doc::Document::new()), Services::default());
|
||||
a.enable_windowless_trial(true);
|
||||
let first = a.windows.id_of(a.windows.shown()).unwrap();
|
||||
let rejected = ViewportId::from_hash_of(super::window_container_id(first));
|
||||
let (attempted, drawn) = rejecting_frame(&kit, &mut a, Some(rejected));
|
||||
assert!(attempted.contains(&rejected) && drawn.is_empty());
|
||||
assert!(a.quit_requested && a.closing.is_none(), "a clean invisible app shouldn't wait for input");
|
||||
assert!(a.windows.viewports(&kit.ctx).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_rejected_first_window_does_not_discard_preexisting_edits() {
|
||||
let kit = Kit::new();
|
||||
let mut a = app("Unsaved before attach");
|
||||
a.enable_windowless_trial(true);
|
||||
let first = a.windows.id_of(a.windows.shown()).unwrap();
|
||||
let rejected = ViewportId::from_hash_of(super::window_container_id(first));
|
||||
let (_, drawn) = rejecting_frame(&kit, &mut a, Some(rejected));
|
||||
assert!(drawn.is_empty());
|
||||
assert!(!a.quit_requested && a.closing.is_none());
|
||||
assert!(a.session.dirty);
|
||||
assert_eq!(text(&a), "Unsaved before attach");
|
||||
let (attempted, _) = rejecting_frame(&kit, &mut a, Some(rejected));
|
||||
assert!(attempted.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn closing_a_shared_document_window_returns_to_its_peer_not_an_unrelated_document() {
|
||||
let mut a = app("Shared draft");
|
||||
@@ -287,6 +436,52 @@ fn replacing_a_guarded_document_does_not_leave_a_permanent_close_hold() {
|
||||
assert_eq!(text(&a), "Replacement");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn control_waits_for_the_windowless_target_and_never_closes_root() {
|
||||
let mut rig = Rig::new();
|
||||
let mut a = app("Untouched draft");
|
||||
a.enable_windowless_trial(true);
|
||||
let survivor = a.session.document_id();
|
||||
rig.frames(&mut a, 2);
|
||||
let survivor_viewport = a.control_viewport().unwrap();
|
||||
assert_ne!(survivor_viewport, ViewportId::ROOT);
|
||||
|
||||
// A second automation request can arrive before this new active window gets its first draw.
|
||||
a.run("file.new", json!({})).unwrap();
|
||||
a.run("text.insert", json!({"text": "New draft"})).unwrap();
|
||||
let target = a.session.document_id();
|
||||
assert_ne!(target, survivor);
|
||||
for (method, params) in [
|
||||
("ui.closeWindow", json!({})),
|
||||
("ui.resize", json!({"width": 400, "height": 300})),
|
||||
("ui.focus", json!({"label": "Find"})),
|
||||
("ui.screenshot", json!({})),
|
||||
("ui.type", json!({"text": "must not be queued"})),
|
||||
] {
|
||||
let (req, _) = ControlRequest::new(method, params);
|
||||
let Reply::Done(result) = crate::control::handle(&mut a, &rig.ctx(), &req) else { panic!("{method} was queued") };
|
||||
assert_eq!(result["ok"], false, "{method}: {result}");
|
||||
assert!(result["error"].as_str().unwrap_or_default().contains("retry once it opens"), "{method}: {result}");
|
||||
}
|
||||
rig.frames(&mut a, 2);
|
||||
assert!(!rig.sent(ViewportId::ROOT, &ViewportCommand::Close));
|
||||
assert!(!a.quit_requested && a.closing.is_none());
|
||||
assert_eq!(text(&a), "New draft");
|
||||
let target_viewport = a.control_viewport().unwrap();
|
||||
assert_ne!(target_viewport, ViewportId::ROOT);
|
||||
assert_ne!(target_viewport, survivor_viewport);
|
||||
|
||||
let (req, _) = ControlRequest::new("ui.closeWindow", json!({}));
|
||||
let Reply::Done(result) = crate::control::handle(&mut a, &rig.ctx(), &req) else { panic!("close did not answer") };
|
||||
assert_eq!(result["result"]["requested"], true);
|
||||
rig.frame(&mut a);
|
||||
assert!(rig.sent(target_viewport, &ViewportCommand::Close));
|
||||
assert!(!rig.sent(ViewportId::ROOT, &ViewportCommand::Close));
|
||||
rig.frames(&mut a, 2);
|
||||
assert_eq!(a.closing.as_ref().and_then(|c| c.guard.current()), Some(&target));
|
||||
assert!(a.session.is_open(survivor) && a.session.document_dirty(survivor) && !a.quit_requested);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_queued_request_wakes_the_window_that_must_handle_it() {
|
||||
let mut rig = Rig::new();
|
||||
|
||||
File diff suppressed because one or more lines are too long
+1
-10
@@ -58,11 +58,7 @@ Document title opens Rename Document; the account badge opens Options › Genera
|
||||
| Vertical scrollbar track paging | ✅ clicking the vertical scrollbar track above the elevator moves one screen up, and below it moves one screen down, as in Word (#5853, `canvas::tests::clicking_vertical_scrollbar_track_advances_one_screen`); it previously jumped to the clicked position | moves one screen | 90% | — |
|
||||
| Scrollbar drag page tip | ✅ while the vertical scrollbar is dragged, a tip beside the pointer names the page at the top of the window in the status bar's words ("Page 7 of 10"), on one line however long the number (#2551, #3341, `canvas::tests::dragging_the_scrollbar_names_the_page_at_the_top`); its look and wording not yet compared with Word's | not compared | 70% | 0.5 |
|
||||
| Interface text on screen (Linux, BSD) | Drawn by egui with Inter's ttfautohint hints, which match FreeType's light autohinting: measured against headless Firefox (Inter, 18.1 and 15.2 px at 1.45x), the same rows of pixels and weight (ink within 1 %) in the light theme. The dark theme no longer looks semi-bold: egui's dark default thickened light-on-dark text (about 21 % more ink than Firefox); it now adds a light 7 % (plain coverage, Firefox's weight, looked soft on the dark tab row; chosen side by side on a 145 % desktop). Not yet: subpixel (LCD) edges | sharp interface text | 90% | — |
|
||||
| Page text on screen (Linux, BSD) | Lightly hinted as FreeType's `hintslight` draws it (Firefox and other apps there): FreeType's autohinter puts baselines, x-heights and cap heights on whole pixels, nothing moves sideways, so lines break as before. Measured against headless Firefox (Arial, 21.27 px): the same rows of pixels and weight. Subpixel (LCD) edges are their own row below; the interface text (egui) is hinted separately. Exports are unchanged | sharp document text | 90% | — |
|
||||
| Page text on screen (macOS, Windows) | Drawn from the fonts' own outlines, unhinted, as macOS draws text. Every baseline sits on a whole device pixel (upright text only; a glyph moves half a pixel at most, never sideways, so lines break as before), so the feet of the letters fill one pixel row; between two rows they were two grey ones, which read as blur beside Preview and OpenOffice on the same screen. On macOS, text is also thickened as the system's font smoothing does it, sideways only (1.21 % of the pixel size on each side, 0.3 px at most, none past 72 px per em): stems gain weight and no grey is added above or below the letters. The outline itself is widened and filled once. The softness was found by comparing 144 dpi screenshots of one paragraph (Times New Roman) in WordCraft, Preview and OpenOffice; the fix is checked on headless rasters, not yet side by side in the running app, and not measured against CoreText's own output. Subpixel (LCD) edges are their own row below. Not yet: Windows text has no ClearType-style hinting | sharp document text | 80% | 4–8 (hinting on Windows) |
|
||||
| Page text and the system's text settings | **Not followed yet.** What each system's values mean is in place (`screen_text.rs`: macOS `AppleFontSmoothing` as a darkening strength; Windows ClearType and stripe orientation; GNOME's and KDE Plasma's antialiasing, hinting and stripe order), and pages are drawn with those settings, and redrawn when they change, once one is recorded. Nothing records one: the app reads the system only through craft-libs' `platform::appearance`, which reports theme, contrast and reduced motion and no text settings. So pages are drawn each platform's fixed way (macOS darkened; Linux and BSD lightly hinted) plus the user's own Screen text smoothing choice. Shared-API gap: craft-libs needs to report the font smoothing strength, antialiasing kind, hinting and stripe order; an earlier version of this work read them in the app itself (macOS only run), which the move of system access to craft-libs rules out. Previews, dragged objects and File › New thumbnails keep the fixed defaults in any case (thumbnails without baseline snapping) | follows system settings | 20% | 4–8 (the craft-libs reader, then the wiring) |
|
||||
| Subpixel (LCD) page text | File › Options › General › Screen text smoothing (`view.textSmoothing`): Use system setting, Grayscale, Subpixel (LCD). A WordCraft extension, saved per user, never in the document. With subpixel smoothing each colour channel of a pixel takes the text's coverage around its own stripe: the page is rasterised three times, its text a third of a pixel to the left, in place and to the right, and red, green and blue are taken from the matching pass (RGB or BGR stripes). That equals text rasterised three times as wide and averaged over three neighbours (the box filter FreeType calls its light LCD filter); there is no sharper filter and no fringe reduction, so edges show more colour than ClearType's or FreeType's default. Everything but text is drawn as without it. "Subpixel (LCD)" draws it on any screen, in the screen's stripe order where the system names one, else RGB. "Use system setting" is greyscale until the system's settings are read (row above); it then draws subpixel text where the system asks for it on screens below 2 device pixels per point. Only on a page picture rasterised at the screen's own scale or size (next row): Read Mode's columns, and a part of a page shown reduced, stay greyscale. Costs up to three rasters per page with text; not timed. Formatting marks, watermarks, previews and thumbnails stay greyscale. Vertical stripe orders are not drawn. **Run on macOS only**, on headless rasters; not yet seen on a 1x LCD or on Windows or Linux | subpixel text | 50% | 6–12 (check on real screens, timing, a 5-tap filter) |
|
||||
| Page pictures at the screen's own size | The shared page view asks for each page's picture by its longest side in pixels, rounded up to a multiple of 16, and draws what it gets as its painter draws every picture: the page's place is rounded to whole pixels and the picture fitted inside it by its own proportions. Only a picture of exactly the rounded place's size is drawn one pixel for one. Rasterised at the side asked for, a page is up to 16 pixels too large (A4 at 100 % on a 2x screen: 2256 pixels for 2245); rasterised at the view's own scale and rounded up, as a first version of this did, it is still a pixel or two too large (2017 × 2852 for a 2016 × 2851 place), squeezed by a twentieth of a percent, and the text slides off the pixel grid and back down the page, which reads as blur. Now: once the view is at rest (two passes running put the pages in the same places), each picture is made exactly as many pixels each way as its place, scaled across and down by whatever that takes (a pixel in two thousand apart). While the view moves, pictures stay as they were; a page that comes into view is first made at the view's scale and again, exactly, when the view rests. Read Mode's columns, and a part of a page shown reduced, are rasterised as asked for, as before. Checked through the real page view and its picture store, headless: one texel per device pixel at 100, 110 and 137 % on 1x and 2x screens. The reporter's blurry screenshot was of the first version; **the fix has not been seen in the running app yet**. The rounding lives in the shared painter, so this follows it from outside: a shared-API gap remains (the page view could say what size it wants, or draw a screen-scale picture at its own size) | sharp document text | 80% | 2–4 (craft-libs page view) |
|
||||
| Page text on screen (Linux, BSD) | Lightly hinted as FreeType's `hintslight` draws it (Firefox and other apps there): FreeType's autohinter puts baselines, x-heights and cap heights on whole pixels, nothing moves sideways, so lines break as before. Measured against headless Firefox (Arial, 21.27 px): the same rows of pixels and weight. Not yet: subpixel (LCD) edges; the interface text (egui) is hinted separately. macOS keeps its darkened unhinted text; Windows and exports are unchanged | sharp document text | 90% | 4–8 (subpixel edges) |
|
||||
| Web and Draft Layout rendering | Very long pages render only visible full-resolution raster tiles instead of shrinking one huge texture to the GPU size limit; nearby tiles are cached for scrolling | sharp document text | 95% | — |
|
||||
| Reading Mode | Existing Read Mode ribbon button opens a read-only, viewport-column layout with animated horizontal paging, transient width/text/spacing controls, heading navigation (Navigation pane) and resize anchoring; print/export layout unchanged. The arrows, Page Up/Down and Escape work straight after entering it; only whole columns show, centred, at any width, text size or window size; the columns end above the page-turn bar (#1772); Page color: None (white, the document's page color and page picture not shown), Sepia or Inverse (a dark page with light text), as Word's View › Page Color in Read Mode, starting at None and kept between Read Mode entries, documents and runs (`view.readPageColor`); ink, object drag previews and table drag arrows drawn over the pages follow it; Read Mode's View menu: Column Width and Page Color work, Layout is missing ([parity-checklist.md](parity-checklist.md), Read Mode 2/3) | reading-optimized view and navigation | 75% | 1–2 |
|
||||
| Status bar (page x of y, words, language, view buttons, zoom slider) | ✅ (the page is the caret's while the caret is on screen, else the page at the top of the window, so scrolling updates it (#3880); the language is the caret's, by name; a click sets the proofing language, or opens Set Proofing Language… for any other). The count at the right is what it shows in Word: words (default), characters (with spaces) or characters (no spaces), chosen from a right-click menu on it or File › Options › Display (Status bar count, `ui.statusCount`), kept between runs; a selection shows "selected of total" as the Word Count dialog counts them (#2797) | ✅ | 90% | — |
|
||||
@@ -129,11 +125,6 @@ Page Setup's margin, paper-size and document-grid number boxes scroll long text
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-11-21 | minor | Page pictures are made exactly as many pixels each way as their place on screen once the view rests (the row "Page pictures at the screen's own scale" is now "…own size"): the first version, a pixel or two too large, was scaled by the shared painter and looked blurry. Also: stretched hinted text and synthetic bold are darkened correctly |
|
||||
| 2026-11-20 | minor | Ported onto the shared page view and Options (after #7101): page pictures are rasterised at the screen's own scale where the view's zoom accounts for the side asked for, and subpixel text is drawn only there; the Screen text smoothing row is in the shared Options; the app no longer reads the system's text settings itself, so the row "Page text follows the system's text settings" became "Page text and the system's text settings" (not followed yet: craft-libs gap). New row "Page pictures at the screen's own scale" |
|
||||
| 2026-11-19 | minor | Subpixel (LCD) page text: three rasters with the text a third of a pixel apart, one per colour stripe; File › Options › General › Screen text smoothing (`view.textSmoothing`). New row "Subpixel (LCD) page text"; run on macOS only |
|
||||
| 2026-11-19 | minor | Page drawing can take the system's text settings; nothing reads them from the system yet (see the row "Page text and the system's text settings") |
|
||||
| 2026-11-19 | minor | Page text on macOS and Windows: baselines on whole device pixels; macOS stem darkening widens outlines sideways only, in one fill, instead of stroking them all round. New row "Page text on screen (macOS, Windows)" |
|
||||
| 2026-11-25 | trivial | Review › Comments › Delete is a split button: Delete, Delete All Comments in Document and Delete All Resolved Comments. The last deletes each resolved comment with its replies and keeps the open ones, in one undo step (#7818) |
|
||||
| 2026-11-17 | trivial | Format Shape pane adds Line section (No line, Solid line with color, width, dash type, and cap type) and Layout & Properties section (size, rotation, and text box direction and vertical alignment), routes active canvas text-box edits to the member while leaving grouped text boxes disabled, rejects unknown outline `dash`/`cap` values, and applies Line and Layout edits across multi-shape selections (#5896) |
|
||||
| 2026-11-15 | trivial | Paste: a copied table pasted with the caret in a table cell inserts its rows above (caret in the first column, same width) or overwrites the cells from the caret's, adding rows and columns, as Word's Paste does; `edit.pasteNestedTable` (Paste as Nested Table) nests it (#6739). Pasted cells take the destination's cell formatting (Word keeps the source's: not done). Left as before: copies with merged cells, pictures or ragged rows, merged destinations, a one-column destination, Track Changes, PasteAppendTable. Paste into selected cells overwrites from the top-left for plain grids, even when the copied table is wider than the selection (#6742). |
|
||||
|
||||
Reference in New Issue
Block a user