mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-16 20:06:41 +00:00
refactor(pdf): use shared PostScript reader for EPS
This commit is contained in:
Generated
+195
-37
@@ -138,6 +138,21 @@ dependencies = [
|
||||
"equator",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "alloc-no-stdlib"
|
||||
version = "3.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2fb6cfd47bf496ff64095c20eaba0c201404ee38714d4142fcfa1dc334fcc7a"
|
||||
|
||||
[[package]]
|
||||
name = "alloc-stdlib"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b5c1865780388bfa186411ab5f247819487fc4864c6e9c3106611fa347586e1"
|
||||
dependencies = [
|
||||
"alloc-no-stdlib",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "allocator-api2"
|
||||
version = "0.2.21"
|
||||
@@ -697,6 +712,16 @@ dependencies = [
|
||||
"syn 3.0.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "brotli-decompressor"
|
||||
version = "6.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "75c74c9c51b9140663e196b5fb88bc94c334d7a497c8311cb759d8557874747f"
|
||||
dependencies = [
|
||||
"alloc-no-stdlib",
|
||||
"alloc-stdlib",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.20.3"
|
||||
@@ -1092,26 +1117,26 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-aep"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
|
||||
[[package]]
|
||||
name = "craft-audio"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
dependencies = [
|
||||
"craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef)",
|
||||
"craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c)",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-docpath"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
|
||||
[[package]]
|
||||
name = "craft-dpx"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
@@ -1119,7 +1144,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ecproj-format"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -1129,12 +1154,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-eps"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
|
||||
[[package]]
|
||||
name = "craft-exr"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
dependencies = [
|
||||
"serde_json",
|
||||
]
|
||||
@@ -1142,17 +1167,20 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-fonts-build"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
|
||||
[[package]]
|
||||
name = "craft-gif"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
dependencies = [
|
||||
"gif",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-i18n"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
dependencies = [
|
||||
"fixed_decimal",
|
||||
"icu_decimal",
|
||||
@@ -1172,10 +1200,41 @@ dependencies = [
|
||||
"writeable",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-image-codecs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
dependencies = [
|
||||
"craft-jpeg",
|
||||
"craft-metadata",
|
||||
"exr",
|
||||
"flate2",
|
||||
"half",
|
||||
"image",
|
||||
"image-webp",
|
||||
"jpeg-encoder",
|
||||
"png",
|
||||
"rayon",
|
||||
"serde_json",
|
||||
"thiserror 2.0.21",
|
||||
"tiff",
|
||||
"zune-core",
|
||||
"zune-jpeg",
|
||||
"zune-jpegxl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-jpeg"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-lottie"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
dependencies = [
|
||||
"craft-zip",
|
||||
"serde_json",
|
||||
@@ -1185,7 +1244,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-media"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
@@ -1201,25 +1260,50 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-mesh"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
dependencies = [
|
||||
"miniz_oxide 0.9.1",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-metadata"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
dependencies = [
|
||||
"brotli-decompressor",
|
||||
"chrono",
|
||||
"craft-tiff",
|
||||
"quick-xml 0.41.0",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-pdf"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
dependencies = [
|
||||
"hayro-syntax",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-ps"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
dependencies = [
|
||||
"craft-eps",
|
||||
"kurbo",
|
||||
"miniz_oxide 0.8.9",
|
||||
"pdf-writer",
|
||||
"skrifa 0.47.0",
|
||||
"weezl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-psd"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
dependencies = [
|
||||
"encoding_rs",
|
||||
"flate2",
|
||||
@@ -1230,7 +1314,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-quit"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
dependencies = [
|
||||
"dispatch2",
|
||||
"egui",
|
||||
@@ -1241,8 +1325,9 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-svg"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
dependencies = [
|
||||
"craft-image-codecs",
|
||||
"craft-xml",
|
||||
"flate2",
|
||||
"kurbo",
|
||||
@@ -1252,10 +1337,19 @@ dependencies = [
|
||||
"vectorcraft-pathops",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-tiff"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-ui"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
dependencies = [
|
||||
"craft-fonts-build",
|
||||
"craft-i18n",
|
||||
@@ -1267,7 +1361,7 @@ dependencies = [
|
||||
"objc2-app-kit 0.3.2",
|
||||
"objc2-foundation 0.3.2",
|
||||
"serde",
|
||||
"skrifa",
|
||||
"skrifa 0.44.0",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"web-sys",
|
||||
@@ -1276,7 +1370,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-update"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"dunce",
|
||||
@@ -1303,9 +1397,9 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-video"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
dependencies = [
|
||||
"craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef)",
|
||||
"craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c)",
|
||||
"rayon",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
@@ -1313,7 +1407,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-webp"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
@@ -1321,7 +1415,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-xml"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
dependencies = [
|
||||
"quick-xml 0.41.0",
|
||||
"thiserror 2.0.21",
|
||||
@@ -1330,7 +1424,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-zip"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"thiserror 2.0.21",
|
||||
@@ -1696,7 +1790,7 @@ name = "effectcraft-export"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"craft-audio",
|
||||
"craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef)",
|
||||
"craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c)",
|
||||
"craft-video",
|
||||
"effectcraft-color",
|
||||
"effectcraft-effects",
|
||||
@@ -1865,7 +1959,7 @@ dependencies = [
|
||||
"craft-dpx",
|
||||
"craft-exr",
|
||||
"craft-gif",
|
||||
"craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef)",
|
||||
"craft-media 0.1.0 (git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c)",
|
||||
"craft-webp",
|
||||
"effectcraft-color",
|
||||
"effectcraft-effects",
|
||||
@@ -1928,15 +2022,15 @@ dependencies = [
|
||||
name = "effectcraft-pdf"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"craft-eps",
|
||||
"craft-pdf",
|
||||
"craft-ps",
|
||||
"effectcraft-raster",
|
||||
"effectcraft-svg",
|
||||
"effectcraft-text",
|
||||
"image",
|
||||
"kurbo",
|
||||
"miniz_oxide 0.9.1",
|
||||
"skrifa",
|
||||
"skrifa 0.44.0",
|
||||
"wasm-bindgen-test",
|
||||
"zune-jpeg",
|
||||
]
|
||||
@@ -2072,7 +2166,7 @@ dependencies = [
|
||||
"effectcraft-keyframe",
|
||||
"harfrust",
|
||||
"kurbo",
|
||||
"skrifa",
|
||||
"skrifa 0.44.0",
|
||||
"unicode-bidi",
|
||||
"unicode-linebreak",
|
||||
]
|
||||
@@ -2407,7 +2501,7 @@ dependencies = [
|
||||
"parking_lot",
|
||||
"profiling",
|
||||
"self_cell",
|
||||
"skrifa",
|
||||
"skrifa 0.44.0",
|
||||
"smallvec",
|
||||
"unicode-bidi",
|
||||
"unicode-general-category",
|
||||
@@ -3254,7 +3348,7 @@ dependencies = [
|
||||
"hashbrown 0.17.1",
|
||||
"log",
|
||||
"peniko",
|
||||
"skrifa",
|
||||
"skrifa 0.44.0",
|
||||
"smallvec",
|
||||
"vello_common",
|
||||
]
|
||||
@@ -3383,7 +3477,7 @@ checksum = "c03d949a14aa089bbb282f7dd76a498a7f684428e4257202efc119ec010376f9"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"bytemuck",
|
||||
"read-fonts",
|
||||
"read-fonts 0.41.0",
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
@@ -3435,7 +3529,7 @@ checksum = "9f4d0e94ddd48749f06bbe4e5389fb9799a0c45bcaf00495042076ef05e3241a"
|
||||
[[package]]
|
||||
name = "hayro-jbig2"
|
||||
version = "0.3.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
dependencies = [
|
||||
"hayro-ccitt",
|
||||
]
|
||||
@@ -3449,7 +3543,7 @@ checksum = "c75ab947623ef4ccaa7acf0579edf7cbb5a73838e3839a7be73335e522f433a1"
|
||||
[[package]]
|
||||
name = "hayro-syntax"
|
||||
version = "0.7.2"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=2fea4b4ce28678e30bd546885a323aaa8fa243ef#2fea4b4ce28678e30bd546885a323aaa8fa243ef"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c#41fb227542efb8a7748caa1c659f271d8605303c"
|
||||
dependencies = [
|
||||
"hayro-jbig2",
|
||||
"hayro-jpeg2000",
|
||||
@@ -3706,6 +3800,7 @@ dependencies = [
|
||||
"moxcms",
|
||||
"num-traits",
|
||||
"png",
|
||||
"qoi",
|
||||
"tiff",
|
||||
"zune-core",
|
||||
"zune-jpeg",
|
||||
@@ -3836,6 +3931,12 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jpeg-encoder"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b454d911ac55068f53495488d8ccd0646eaa540c033a28ee15b07838afafb01f"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.106"
|
||||
@@ -4812,6 +4913,18 @@ version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2ee67f1008b1ba2321834326597b8e186293b049a023cdef258527550b9935b4"
|
||||
|
||||
[[package]]
|
||||
name = "pdf-writer"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f5e456864a7a304047bff84977dc6fb162bd956475d40ba50b2dcecaada7f753"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"itoa",
|
||||
"memchr",
|
||||
"ryu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "peniko"
|
||||
version = "0.6.1"
|
||||
@@ -5125,6 +5238,15 @@ version = "0.1.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d55d956fa96f5ec02be2e13af0e20391a5aa83d6a074e3ad368959d0fab299ea"
|
||||
|
||||
[[package]]
|
||||
name = "qoi"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f6d64c71eb498fe9eae14ce4ec935c555749aef511cca85b5568910d6e48001"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quick-error"
|
||||
version = "1.2.3"
|
||||
@@ -5311,6 +5433,17 @@ dependencies = [
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "read-fonts"
|
||||
version = "0.44.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d5a0cf4bb6cbce4c29756270d189a5e400ac05e91192161d83a0bcb6e68492e8"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"font-types",
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "reborrow"
|
||||
version = "0.5.5"
|
||||
@@ -5554,6 +5687,12 @@ dependencies = [
|
||||
"wait-timeout",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f"
|
||||
|
||||
[[package]]
|
||||
name = "ryu-js"
|
||||
version = "1.0.3"
|
||||
@@ -5788,7 +5927,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "819ab7d62b1d3e72d9d9dea5650bac30424f9111364bb94928dbf5ecad1baa68"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"read-fonts",
|
||||
"read-fonts 0.41.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "skrifa"
|
||||
version = "0.47.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "526e654b303ff4ad73a5a40b25de2b3ce3d039c5e3b6da5f89ae6e57004cb40f"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"read-fonts 0.44.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -8254,6 +8403,15 @@ dependencies = [
|
||||
"zune-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zune-jpegxl"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cba11ecd07cc23351500e840ae03841b7e4997923ec8e4832ee3ae199ea0b6b4"
|
||||
dependencies = [
|
||||
"zune-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zvariant"
|
||||
version = "5.15.0"
|
||||
|
||||
+22
-21
@@ -11,22 +11,23 @@ rust-version = "1.95"
|
||||
repository = "https://github.com/storytold/effectcraft"
|
||||
|
||||
[workspace.dependencies]
|
||||
craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef", version = "=0.1.0", default-features = false, features = ["read"] }
|
||||
craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" }
|
||||
craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" }
|
||||
craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" }
|
||||
craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" }
|
||||
craft-eps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" }
|
||||
craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" }
|
||||
craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" }
|
||||
craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" }
|
||||
craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" }
|
||||
craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" }
|
||||
craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" }
|
||||
craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef", default-features = false, features = ["stl", "obj", "gltf", "fbx"] }
|
||||
craft-aep = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef" }
|
||||
craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c", version = "=0.1.0", default-features = false, features = ["read"] }
|
||||
craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c" }
|
||||
craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c" }
|
||||
craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c" }
|
||||
craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c" }
|
||||
craft-eps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c" }
|
||||
craft-ps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c", default-features = false, features = ["read"] }
|
||||
craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c" }
|
||||
craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c" }
|
||||
craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c" }
|
||||
craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c" }
|
||||
craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c" }
|
||||
craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c" }
|
||||
craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c", default-features = false, features = ["stl", "obj", "gltf", "fbx"] }
|
||||
craft-aep = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c" }
|
||||
# craft-update: app-specific pretend versions apply to startup and manual checks.
|
||||
craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef", features = ["egui"] }
|
||||
craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "41fb227542efb8a7748caa1c659f271d8605303c", features = ["egui"] }
|
||||
# internal
|
||||
effectcraft-time = { path = "crates/time" }
|
||||
effectcraft-geom = { path = "crates/geom" }
|
||||
@@ -90,9 +91,9 @@ same-file = "1.0"
|
||||
tempfile = "3.27"
|
||||
|
||||
# codecs + containers shared by the Craft apps (crates/media, crates/export); keep all three on one rev.
|
||||
craft-media = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef", default-features = false, features = ["isobmff", "matroska"] }
|
||||
craft-audio = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef", default-features = false, features = ["aac-decode", "aac-encode", "opus-decode"] }
|
||||
craft-video = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef", features = ["h264-encode", "prores", "hevc-encode", "vp9-encode", "av1", "threads"] }
|
||||
craft-media = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c", default-features = false, features = ["isobmff", "matroska"] }
|
||||
craft-audio = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c", default-features = false, features = ["aac-decode", "aac-encode", "opus-decode"] }
|
||||
craft-video = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c", features = ["h264-encode", "prores", "hevc-encode", "vp9-encode", "av1", "threads"] }
|
||||
|
||||
# footage decoding: FilmCraft's pure-Rust crates, pinned to a revision (plan/adr/0001).
|
||||
# Only `crates/media`, `crates/export` and `crates/interchange` may depend on these.
|
||||
@@ -122,7 +123,7 @@ half = "2.7"
|
||||
# ui
|
||||
# Shared frontend components; keep this dependency above the engine boundary.
|
||||
# Shared UI and the complete egui family select reviewed immutable commits below.
|
||||
craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef", features = ["serde"] }
|
||||
craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c", features = ["serde"] }
|
||||
# `default_fonts` and `monochrome_emoji_fonts` are explicit: the app's `FontDefinitions::default()`
|
||||
# and its `✔`/`▣` chrome glyphs need both, and kittest's own dev-dependencies do not propagate.
|
||||
egui = { version = "0.37", default-features = false, features = ["default_fonts", "monochrome_emoji_fonts"] }
|
||||
@@ -231,8 +232,8 @@ lto = "thin"
|
||||
codegen-units = 1
|
||||
|
||||
[patch.crates-io]
|
||||
hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef", version = "=0.7.2" }
|
||||
hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "2fea4b4ce28678e30bd546885a323aaa8fa243ef", version = "=0.3.0" }
|
||||
hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c", version = "=0.7.2" }
|
||||
hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c", version = "=0.3.0" }
|
||||
ecolor = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
emath = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
epaint = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
|
||||
@@ -10,7 +10,7 @@ rust-version.workspace = true
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
craft-eps = { workspace = true }
|
||||
craft-ps = { workspace = true }
|
||||
craft-pdf.workspace = true
|
||||
effectcraft-svg = { workspace = true }
|
||||
kurbo = { workspace = true }
|
||||
|
||||
@@ -366,14 +366,6 @@ pub struct Cff {
|
||||
pub encoding: [u16; 256],
|
||||
}
|
||||
|
||||
/// The first font name in a CFF program's Name INDEX.
|
||||
pub fn font_name(data: &[u8]) -> Option<String> {
|
||||
let hdr = *data.get(2)? as usize;
|
||||
let (names, _) = index(data, hdr)?;
|
||||
let r = names.first()?.clone();
|
||||
Some(String::from_utf8_lossy(data.get(r)?).into_owned())
|
||||
}
|
||||
|
||||
impl Cff {
|
||||
pub fn parse(data: &[u8]) -> Option<Cff> {
|
||||
let d = data;
|
||||
|
||||
@@ -350,36 +350,6 @@ impl Font {
|
||||
}
|
||||
}
|
||||
|
||||
/// A simple font outside a PDF (EPS text): `program` is an embedded font program (CFF when
|
||||
/// the flag is set, else Type 1), otherwise the bundled stand-in for `name` is used;
|
||||
/// `names` is the encoding (code → glyph name), else the program's built-in encoding or
|
||||
/// StandardEncoding. Advances are the program's.
|
||||
pub fn standalone(name: &str, program: Option<(&[u8], bool)>, names: Option<Vec<Option<String>>>) -> Font {
|
||||
let mut f = Font::blank(name, false);
|
||||
f.program = match program {
|
||||
Some((data, true)) => Cff::parse(data).map(|c| Program::Cff(Box::new(c))),
|
||||
Some((data, false)) => Type1::parse(data).map(|t| Program::Type1(Box::new(t))),
|
||||
None => None,
|
||||
}
|
||||
.unwrap_or_else(|| Program::Fallback(fallback(name)));
|
||||
match &f.program {
|
||||
Program::Cff(c) => f.matrix = Affine::new(c.font_matrix),
|
||||
Program::Type1(t) => f.matrix = t.font_matrix.map(Affine::new).unwrap_or(f.matrix),
|
||||
_ => {}
|
||||
}
|
||||
let symbol = matches!(f.program, Program::Fallback(_)) && (name.contains("Symbol") || name.contains("Dingbats"));
|
||||
f.names = match names {
|
||||
// Unencoded codes draw .notdef (not the built-in encoding).
|
||||
Some(n) => (0..256).map(|c| Some(n.get(c).cloned().flatten().unwrap_or_else(|| ".notdef".into()))).collect(),
|
||||
None => match &f.program {
|
||||
Program::Type1(t) if !t.encoding.is_empty() => (0..256).map(|c| t.encoding.get(&(c as u8)).cloned()).collect(),
|
||||
_ if symbol => vec![None; 256],
|
||||
_ => (0..256).map(|c| Base::Standard.name(c as u8)).collect(),
|
||||
},
|
||||
};
|
||||
f
|
||||
}
|
||||
|
||||
pub fn load(file: &File, d: &Dict, skipped: &mut Vec<String>) -> Font {
|
||||
let subtype = file.get(d, "Subtype").and_then(Obj::name).unwrap_or("Type1").to_string();
|
||||
let base_name = file.get(d, "BaseFont").and_then(Obj::name).unwrap_or("").to_string();
|
||||
|
||||
+51
-7
@@ -18,7 +18,6 @@ mod font;
|
||||
mod image;
|
||||
mod object;
|
||||
mod page;
|
||||
mod ps;
|
||||
mod read;
|
||||
mod shading;
|
||||
mod type1;
|
||||
@@ -188,13 +187,58 @@ fn parse_pdf(bytes: &[u8], index: usize, framing: Framing) -> Result<Doc, Error>
|
||||
Ok(finish(nodes, flags, skipped, dw.max(1.0), dh.max(1.0), to_doc))
|
||||
}
|
||||
|
||||
fn eps_fallback_font(name: &[u8]) -> Option<&'static [u8]> {
|
||||
use effectcraft_text::fonts::{INTER_BOLD, INTER_ITALIC, INTER_REGULAR, INTER_SEMIBOLD, JETBRAINS_MONO_REGULAR, NOTO_SERIF_REGULAR};
|
||||
let name = String::from_utf8_lossy(name).to_ascii_lowercase();
|
||||
Some(if name.contains("courier") || name.contains("mono") || name.contains("consol") {
|
||||
JETBRAINS_MONO_REGULAR
|
||||
} else if name.contains("times")
|
||||
|| name.contains("serif") && !name.contains("sans")
|
||||
|| name.contains("georgia")
|
||||
|| name.contains("garamond")
|
||||
|| name.contains("minion")
|
||||
|| name.contains("roman")
|
||||
{
|
||||
NOTO_SERIF_REGULAR
|
||||
} else if name.contains("bold") || name.contains("black") || name.contains("heavy") {
|
||||
INTER_BOLD
|
||||
} else if name.contains("semibold") || name.contains("demi") {
|
||||
INTER_SEMIBOLD
|
||||
} else if name.contains("italic") || name.contains("oblique") {
|
||||
INTER_ITALIC
|
||||
} else {
|
||||
INTER_REGULAR
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_eps(bytes: &[u8]) -> Result<Doc, Error> {
|
||||
let (ps, bb) = ps::eps_parts(bytes).ok_or(Error::NoBoundingBox)?;
|
||||
let mut it = ps::Interp::new(bb);
|
||||
it.run(ps);
|
||||
let (nodes, flags, skipped) = it.b.finish();
|
||||
let to_doc = Affine::new([1.0, 0.0, 0.0, -1.0, -bb[0], bb[3]]);
|
||||
Ok(finish(nodes, flags, skipped, (bb[2] - bb[0]).max(1.0), (bb[3] - bb[1]).max(1.0), to_doc))
|
||||
let limits = craft_ps::read::Limits {
|
||||
// Preserve EffectCraft's established 8,000,000-unit PostScript execution budget.
|
||||
steps: 8_000_000,
|
||||
stack_overflow_noop: true,
|
||||
skip_images: true,
|
||||
keep_unpainted: true,
|
||||
zero_division_zero: true,
|
||||
fallback_font: Some(eps_fallback_font),
|
||||
..Default::default()
|
||||
};
|
||||
let converted = craft_ps::read::eps_to_pdf(bytes, limits).map_err(|message| match message.as_str() {
|
||||
"not PostScript" | "the EPS has no bounding box" => Error::NoBoundingBox,
|
||||
_ => Error::Read(message),
|
||||
})?;
|
||||
let mut doc = parse_pdf(&converted.pdf, 0, Framing::Placed)?;
|
||||
for skipped in &mut doc.skipped {
|
||||
if skipped == "content (path limit)" {
|
||||
*skipped = "PostScript (path limit)".to_string();
|
||||
}
|
||||
}
|
||||
doc.skipped.extend(converted.warnings.into_iter().map(|warning| match warning.as_str() {
|
||||
"the program runs too long" | "out of memory" => "PostScript (operation limit)".to_string(),
|
||||
"executable name resolution limit" => "PostScript (recursion limit)".to_string(),
|
||||
"content (path limit)" => "PostScript (path limit)".to_string(),
|
||||
_ => warning,
|
||||
}));
|
||||
Ok(doc)
|
||||
}
|
||||
|
||||
/// The document's layer names (the root's children), bottom first.
|
||||
|
||||
@@ -516,6 +516,7 @@ fn ascii_hex(data: &[u8], max: usize) -> Option<Vec<u8>> {
|
||||
Some(out)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn ascii85(data: &[u8]) -> Vec<u8> {
|
||||
// The PostScript reader uses this unbounded entry point. No Vec can hold more
|
||||
// than usize::MAX bytes, so its output cannot exceed this bound.
|
||||
|
||||
+14
-3
@@ -499,12 +499,23 @@ impl<'a> Interp<'a> {
|
||||
(Some("OC"), Some(Obj::Dict(ocg))) => self.ocg_name(ocg),
|
||||
_ => None,
|
||||
};
|
||||
match layer {
|
||||
Some(name) => {
|
||||
let actual_text = match (args.first().and_then(Obj::name), args.get(1)) {
|
||||
(Some("Span"), Some(Obj::Dict(props))) => props.get("ActualText").and_then(|v| match self.file.resolve(v) {
|
||||
Obj::Str(bytes) => Some(crate::color::text_string(bytes)),
|
||||
_ => None,
|
||||
}),
|
||||
_ => None,
|
||||
};
|
||||
match (layer, actual_text) {
|
||||
(Some(name), _) => {
|
||||
self.marked.push(Some(self.b.depth()));
|
||||
self.b.open(&name, true);
|
||||
}
|
||||
None => self.marked.push(None),
|
||||
(None, Some(text)) => {
|
||||
self.marked.push(Some(self.b.depth()));
|
||||
self.b.open(&format!("Text: {text}"), false);
|
||||
}
|
||||
(None, None) => self.marked.push(None),
|
||||
}
|
||||
}
|
||||
"EMC" => {
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
//! Encapsulated PostScript: a small PostScript interpreter (PostScript Language Reference, 3rd
|
||||
//! edition, and the EPSF 3.0 specification) covering what exported vector EPS files use: the
|
||||
//! operand and dictionary stacks, procedures and `def`, arithmetic, control flow, arrays and
|
||||
//! dictionaries, the graphics state, path construction (including arcs) and painting, clipping
|
||||
//! and device colours, and text (`findfont` / `selectfont`, `show` and its variants, `charpath`,
|
||||
//! `stringwidth`, re-encoded fonts) with embedded Type 1 and CFF programs or the bundled
|
||||
//! stand-in fonts. Images are skipped (their inline data is stepped over), as is
|
||||
//! Level 3 smooth shading (`shfill`).
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
|
||||
use effectcraft_svg::{Affine, BezPath, Cap, FillRule, Join, Paint, Stroke};
|
||||
use kurbo::{PathEl, Point};
|
||||
|
||||
use crate::build::{Builder, MAX_PATH};
|
||||
use crate::font::Font;
|
||||
use crate::object::{ascii85, is_white, parse_num};
|
||||
|
||||
mod builtin;
|
||||
mod eps;
|
||||
mod exec;
|
||||
mod paths;
|
||||
mod scanner;
|
||||
mod text;
|
||||
mod value;
|
||||
|
||||
pub use eps::eps_parts;
|
||||
use value::{DictRef, GState, V};
|
||||
|
||||
pub(crate) struct Interp {
|
||||
pub b: Builder,
|
||||
st: Vec<V>,
|
||||
dicts: Vec<DictRef>,
|
||||
gs: GState,
|
||||
saved: Vec<GState>,
|
||||
budget: usize,
|
||||
/// Nested procedure calls (recursion is cut off at [`MAX_CALL_DEPTH`]).
|
||||
calls: usize,
|
||||
/// Fonts by name: `definefont`d dictionaries.
|
||||
font_dir: HashMap<String, DictRef>,
|
||||
/// Embedded font programs found in the file (name → (program, CFF)).
|
||||
embedded: HashMap<String, (Rc<Vec<u8>>, bool)>,
|
||||
/// Fonts built for drawing, by base font and encoding.
|
||||
font_cache: HashMap<String, Rc<Font>>,
|
||||
page: [f64; 4],
|
||||
pub unknown: Vec<String>,
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,53 +0,0 @@
|
||||
use super::{HashMap, Rc};
|
||||
|
||||
/// The PostScript section of an EPS file (DOS EPS binary header handled) and its bounding box
|
||||
/// (`%%HiResBoundingBox` preferred), read with `craft-eps`: the header comments, and the trailer
|
||||
/// for a box deferred with `(atend)`. A binary header that points outside the file is refused.
|
||||
pub fn eps_parts(bytes: &[u8]) -> Option<(&[u8], [f64; 4])> {
|
||||
let ps = craft_eps::sections(bytes).ok()?.postscript;
|
||||
Some((ps, craft_eps::Comments::read(ps).page_box()?))
|
||||
}
|
||||
|
||||
pub(super) fn find_from(hay: &[u8], needle: &[u8], from: usize) -> Option<usize> {
|
||||
hay.get(from..)?.windows(needle.len()).position(|w| w == needle).map(|p| p + from)
|
||||
}
|
||||
|
||||
/// Embedded font programs of an EPS file: Type 1 fonts (`… /FontName /X … currentfile eexec
|
||||
/// … cleartomark`, hexadecimal or binary) and CFF font sets (`… <length> StartData <bytes>`).
|
||||
pub(super) fn embedded_fonts(ps: &[u8]) -> HashMap<String, (Rc<Vec<u8>>, bool)> {
|
||||
let mut out = HashMap::new();
|
||||
for font in craft_eps::embedded_font_programs(ps) {
|
||||
let name = if font.cff { crate::cff::font_name(&font.program) } else { font.name };
|
||||
if let Some(name) = name {
|
||||
out.insert(name, (Rc::new(font.program), font.cff));
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::embedded_fonts;
|
||||
|
||||
#[test]
|
||||
fn font_discovery_looks_back_once_per_header() {
|
||||
// 20,000 `eexec` words before any font header: each used to search the whole prefix
|
||||
// for a header again. The font after them is still found.
|
||||
let mut ps = b"%!PS-Adobe-3.0 EPSF-3.0\n".to_vec();
|
||||
ps.extend_from_slice("eexec ".repeat(20_000).as_bytes());
|
||||
ps.extend_from_slice(b"\n%!PS-AdobeFont-1.0: Real\n/FontName /Real def\ncurrentfile eexec\n0000\ncleartomark\n");
|
||||
let fonts = embedded_fonts(&ps);
|
||||
assert_eq!(fonts.len(), 1);
|
||||
assert!(fonts.contains_key("Real"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn header_less_font_after_a_short_one_does_not_take_its_header() {
|
||||
let a = "%!PS-AdobeFont-1.0: A\n/FontName /A def\ncurrentfile eexec\n0000\ncleartomark\n";
|
||||
let b = "/FontName /B def\ncurrentfile eexec\n0000\ncleartomark\n";
|
||||
let ps = format!("%!PS-Adobe-3.0 EPSF-3.0\n{a}{b}");
|
||||
let fonts = embedded_fonts(ps.as_bytes());
|
||||
let (data, _) = fonts.get("B").expect("second font found");
|
||||
assert!(!String::from_utf8_lossy(data).contains("AdobeFont"), "{}", String::from_utf8_lossy(data));
|
||||
}
|
||||
}
|
||||
@@ -1,182 +0,0 @@
|
||||
use super::eps::embedded_fonts;
|
||||
use super::scanner::Src;
|
||||
use super::value::{Flow, GState, V, new_dict};
|
||||
use super::{Affine, BezPath, Builder, Cap, HashMap, Interp, Join};
|
||||
|
||||
/// The deepest procedure nesting run (deeper recursion stops the program).
|
||||
const MAX_CALL_DEPTH: usize = 256;
|
||||
|
||||
/// The most values the operand stack holds: a push past it is dropped, and `copy` copies
|
||||
/// nothing rather than grow the stack past it.
|
||||
pub(super) const MAX_STACK: usize = 100_000;
|
||||
|
||||
impl Interp {
|
||||
pub fn new(page: [f64; 4]) -> Interp {
|
||||
Interp {
|
||||
b: Builder::new(),
|
||||
st: vec![],
|
||||
dicts: vec![new_dict()],
|
||||
gs: GState {
|
||||
ctm: Affine::IDENTITY,
|
||||
color: [0.0; 3],
|
||||
lw: 1.0,
|
||||
cap: Cap::Butt,
|
||||
join: Join::Miter,
|
||||
miter: 10.0,
|
||||
dash: None,
|
||||
path: BezPath::new(),
|
||||
cur: None,
|
||||
start: None,
|
||||
depth: 1,
|
||||
font: None,
|
||||
},
|
||||
saved: vec![],
|
||||
budget: 8_000_000,
|
||||
calls: 0,
|
||||
font_dir: HashMap::new(),
|
||||
embedded: HashMap::new(),
|
||||
font_cache: HashMap::new(),
|
||||
page,
|
||||
unknown: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run(&mut self, data: &[u8]) {
|
||||
self.embedded = embedded_fonts(data);
|
||||
let mut src = Src { d: data, pos: 0 };
|
||||
while let Some(t) = src.token(0) {
|
||||
if let Err(Flow::Quit) = self.exec_token(t, &mut src) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn pop(&mut self) -> V {
|
||||
self.st.pop().unwrap_or(V::Null)
|
||||
}
|
||||
|
||||
pub(super) fn popn(&mut self) -> f64 {
|
||||
self.pop().num().unwrap_or(0.0)
|
||||
}
|
||||
|
||||
pub(super) fn push(&mut self, v: V) {
|
||||
if self.st.len() < MAX_STACK {
|
||||
self.st.push(v);
|
||||
}
|
||||
}
|
||||
|
||||
/// Count `n` units of work (values copied, storage allocated) against the budget without
|
||||
/// stopping the program here: once it is spent, the next operator stops it.
|
||||
pub(super) fn charge(&mut self, n: usize) {
|
||||
self.budget = self.budget.saturating_sub(n);
|
||||
}
|
||||
|
||||
pub(super) fn lookup(&self, k: &str) -> Option<V> {
|
||||
self.dicts.iter().rev().find_map(|d| d.borrow().get(k).cloned())
|
||||
}
|
||||
|
||||
/// A token read from the file: procedures are pushed, names executed.
|
||||
fn exec_token(&mut self, t: V, src: &mut Src) -> Result<(), Flow> {
|
||||
match t {
|
||||
V::Name(n) => self.exec_name(&n, src),
|
||||
other => {
|
||||
self.push(other);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Execute a value as an object (procedures run).
|
||||
pub(super) fn exec_obj(&mut self, v: V, src: &mut Src) -> Result<(), Flow> {
|
||||
match v {
|
||||
V::Proc(p) => {
|
||||
if self.calls >= MAX_CALL_DEPTH {
|
||||
self.b.skip("PostScript (recursion limit)");
|
||||
return Err(Flow::Quit);
|
||||
}
|
||||
self.calls += 1;
|
||||
let mut r = Ok(());
|
||||
for x in p.iter() {
|
||||
match x {
|
||||
V::Name(n) => {
|
||||
r = self.exec_name(n, src);
|
||||
if r.is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
V::Op(op) => {
|
||||
r = self.spend(1).and_then(|()| self.builtin(op, src));
|
||||
if r.is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Other items count against the budget as names do.
|
||||
other => {
|
||||
r = self.spend(1);
|
||||
if r.is_err() {
|
||||
break;
|
||||
}
|
||||
self.push(other.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
self.calls -= 1;
|
||||
r
|
||||
}
|
||||
// An executable name can run another (`exec` of `/exec cvx`), so names count too.
|
||||
V::Name(n) => {
|
||||
if self.calls >= MAX_CALL_DEPTH {
|
||||
self.b.skip("PostScript (recursion limit)");
|
||||
return Err(Flow::Quit);
|
||||
}
|
||||
self.calls += 1;
|
||||
let r = self.exec_name(&n, src);
|
||||
self.calls -= 1;
|
||||
r
|
||||
}
|
||||
V::Op(op) => {
|
||||
self.spend(1)?;
|
||||
self.builtin(&op, src)
|
||||
}
|
||||
other => {
|
||||
self.push(other);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn exec_name(&mut self, n: &str, src: &mut Src) -> Result<(), Flow> {
|
||||
self.spend(1)?;
|
||||
if let Some(v) = self.lookup(n) {
|
||||
return match v {
|
||||
V::Proc(_) => self.exec_obj(v, src),
|
||||
// An operator stored under another name (`/mo /moveto load def`, as Illustrator's
|
||||
// EPS prolog does for every path operator) runs that operator. It pushed the
|
||||
// operator's name instead, so such files drew nothing (#955).
|
||||
V::Op(op) => self.builtin(&op, src),
|
||||
// An executable name (`/y /x cvx def`) runs what that name is bound to.
|
||||
V::Name(_) => self.exec_obj(v, src),
|
||||
other => {
|
||||
self.push(other);
|
||||
Ok(())
|
||||
}
|
||||
};
|
||||
}
|
||||
self.builtin(n, src)
|
||||
}
|
||||
|
||||
/// Count `n` operations against the budget, and stop the program when fewer are left. An
|
||||
/// operator that makes, reads or copies path elements counts each one as an operation.
|
||||
pub(super) fn spend(&mut self, n: usize) -> Result<(), Flow> {
|
||||
match self.budget.checked_sub(n) {
|
||||
Some(left) => {
|
||||
self.budget = left;
|
||||
Ok(())
|
||||
}
|
||||
None => {
|
||||
self.b.skip("PostScript (operation limit)");
|
||||
Err(Flow::Quit)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,187 +0,0 @@
|
||||
use super::value::{Flow, V};
|
||||
use super::{Affine, BezPath, FillRule, Interp, MAX_PATH, Paint, PathEl, Point, Stroke};
|
||||
|
||||
/// The angle from `a` counterclockwise to `b` (degrees, 0 to 360), worked out from what is left
|
||||
/// of each after whole turns.
|
||||
fn ccw_turn(a: f64, b: f64) -> f64 {
|
||||
(b % 360.0 - a % 360.0).rem_euclid(360.0)
|
||||
}
|
||||
|
||||
/// The most turns one `arc` or `arcn` draws.
|
||||
const MAX_ARC_TURNS: f64 = 1024.0;
|
||||
|
||||
impl Interp {
|
||||
fn device_scale(&self) -> f64 {
|
||||
self.gs.ctm.determinant().abs().sqrt()
|
||||
}
|
||||
|
||||
pub(super) fn user_point(&mut self) -> Point {
|
||||
let y = self.popn();
|
||||
let x = self.popn();
|
||||
Point::new(x, y)
|
||||
}
|
||||
|
||||
/// Stop the program when a path of `len` elements would be longer than [`MAX_PATH`].
|
||||
pub(super) fn path_fits(&mut self, len: usize) -> Result<(), Flow> {
|
||||
if len <= MAX_PATH {
|
||||
return Ok(());
|
||||
}
|
||||
self.b.skip("PostScript (path limit)");
|
||||
Err(Flow::Quit)
|
||||
}
|
||||
|
||||
/// [`Self::path_fits`] for the current path with `n` more elements.
|
||||
pub(super) fn room(&mut self, n: usize) -> Result<(), Flow> {
|
||||
self.path_fits(self.gs.path.elements().len().saturating_add(n))
|
||||
}
|
||||
|
||||
pub(super) fn move_to(&mut self, p: Point) -> Result<(), Flow> {
|
||||
// A moveto right after a moveto replaces it (PostScript Language Reference §8.2, `moveto`).
|
||||
if matches!(self.gs.path.elements().last(), Some(PathEl::MoveTo(_))) {
|
||||
self.gs.path.pop();
|
||||
}
|
||||
self.room(1)?;
|
||||
let q = self.gs.ctm * p;
|
||||
self.gs.path.move_to(q);
|
||||
self.gs.cur = Some(q);
|
||||
self.gs.start = Some(q);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn line_to(&mut self, p: Point) -> Result<(), Flow> {
|
||||
self.room(1 + usize::from(self.gs.cur.is_none()))?;
|
||||
let q = self.gs.ctm * p;
|
||||
if self.gs.cur.is_none() {
|
||||
self.gs.path.move_to(q);
|
||||
self.gs.start = Some(q);
|
||||
}
|
||||
self.gs.path.line_to(q);
|
||||
self.gs.cur = Some(q);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn curve_to(&mut self, a: Point, b: Point, c: Point) -> Result<(), Flow> {
|
||||
self.room(1 + usize::from(self.gs.cur.is_none()))?;
|
||||
let m = self.gs.ctm;
|
||||
if self.gs.cur.is_none() {
|
||||
self.gs.path.move_to(m * a);
|
||||
}
|
||||
self.gs.path.curve_to(m * a, m * b, m * c);
|
||||
self.gs.cur = Some(m * c);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn current_user(&self) -> Point {
|
||||
self.gs.ctm.inverse() * self.gs.cur.unwrap_or_default()
|
||||
}
|
||||
|
||||
pub(super) fn arc(&mut self, neg: bool) -> Result<(), Flow> {
|
||||
let a2 = self.popn();
|
||||
let a1 = self.popn();
|
||||
let r = self.popn();
|
||||
let c = self.user_point();
|
||||
// `arc` raises `a2` by multiples of 360 until it is at least `a1`, and `arcn` lowers it
|
||||
// until it is at most `a1` (PostScript Language Reference §8.2, `arc` and `arcn`). Those
|
||||
// sweeps, and the first endpoint, are worked out from what is left of each angle after
|
||||
// whole turns.
|
||||
let sweep = if !neg && a2 < a1 {
|
||||
ccw_turn(a1, a2)
|
||||
} else if neg && a2 > a1 {
|
||||
-ccw_turn(a2, a1)
|
||||
} else {
|
||||
a2 - a1
|
||||
};
|
||||
// A sweep of more than `MAX_ARC_TURNS` turns is shortened by whole pairs of turns to
|
||||
// between `MAX_ARC_TURNS - 2` and `MAX_ARC_TURNS` turns, with a skip note. The arc still
|
||||
// ends at `a2`, and an even-odd fill or clip of it covers the same area as the full sweep.
|
||||
let max = MAX_ARC_TURNS * 360.0;
|
||||
let sweep = if sweep.abs() > max {
|
||||
self.b.skip("arc (too many turns)");
|
||||
let s = sweep.signum();
|
||||
s * (max - 720.0 + (s * (a2 % 720.0 - a1 % 720.0)).rem_euclid(720.0))
|
||||
} else {
|
||||
sweep
|
||||
};
|
||||
let (a1, sweep) = ((a1 % 360.0).to_radians(), sweep.to_radians());
|
||||
let start = Point::new(c.x + r * a1.cos(), c.y + r * a1.sin());
|
||||
if self.gs.cur.is_some() {
|
||||
self.line_to(start)?;
|
||||
} else {
|
||||
self.move_to(start)?;
|
||||
}
|
||||
let arc = kurbo::Arc::new(c, (r, r), a1, sweep, 0.0);
|
||||
let m = self.gs.ctm;
|
||||
// kurbo divides an arc into more curves the larger the radius (about 3.7 × 10^49 for a
|
||||
// quarter turn at a radius of 10^300, more than a usize can count), so each one counts
|
||||
// against the budget and the path limit.
|
||||
let mut curves = arc.append_iter(0.1);
|
||||
while let Some(PathEl::CurveTo(p1, p2, p3)) = curves.next() {
|
||||
self.room(1)?;
|
||||
self.spend(1)?;
|
||||
self.gs.path.curve_to(m * p1, m * p2, m * p3);
|
||||
self.gs.cur = Some(m * p3);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn paint(&mut self, fill: Option<FillRule>, stroke: bool) {
|
||||
let path = std::mem::take(&mut self.gs.path);
|
||||
self.gs.cur = None;
|
||||
self.gs.start = None;
|
||||
let s = self.device_scale();
|
||||
let st = stroke.then(|| Stroke {
|
||||
paint: Paint::Color(self.gs.color),
|
||||
opacity: 1.0,
|
||||
width: if self.gs.lw <= 0.0 { 1.0 } else { self.gs.lw * s },
|
||||
cap: self.gs.cap,
|
||||
join: self.gs.join,
|
||||
miter: self.gs.miter.max(1.0),
|
||||
dash: self.gs.dash.as_ref().map(|(a, o)| (a.iter().map(|v| v * s).collect(), o * s)),
|
||||
});
|
||||
self.b.fill_stroke(path, Affine::IDENTITY, fill.map(|r| (Paint::Color(self.gs.color), 1.0, r)), st);
|
||||
}
|
||||
|
||||
pub(super) fn rect_path(&mut self) -> Result<Vec<BezPath>, Flow> {
|
||||
// x y w h, or an array / string of numbers.
|
||||
let top = self.pop();
|
||||
let nums: Vec<f64> = match &top {
|
||||
V::Array(_) | V::Proc(_) => {
|
||||
let items = top.items().unwrap_or_default();
|
||||
// An array's rectangles count against the budget, five path elements each.
|
||||
self.spend(items.len() / 4 * 5)?;
|
||||
items.iter().filter_map(V::num).collect()
|
||||
}
|
||||
V::Num(h) => {
|
||||
let w = self.popn();
|
||||
let y = self.popn();
|
||||
let x = self.popn();
|
||||
vec![x, y, w, *h]
|
||||
}
|
||||
_ => vec![],
|
||||
};
|
||||
self.path_fits(nums.len() / 4 * 5)?;
|
||||
let m = self.gs.ctm;
|
||||
Ok(nums
|
||||
.as_chunks::<4>()
|
||||
.0
|
||||
.iter()
|
||||
.map(|r| {
|
||||
let mut p = BezPath::new();
|
||||
p.move_to(m * Point::new(r[0], r[1]));
|
||||
p.line_to(m * Point::new(r[0] + r[2], r[1]));
|
||||
p.line_to(m * Point::new(r[0] + r[2], r[1] + r[3]));
|
||||
p.line_to(m * Point::new(r[0], r[1] + r[3]));
|
||||
p.close_path();
|
||||
p
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
|
||||
pub(super) fn grestore(&mut self) {
|
||||
if let Some(g) = self.saved.pop() {
|
||||
let d = g.depth;
|
||||
self.gs = g;
|
||||
self.b.close_to(d);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,223 +0,0 @@
|
||||
use super::value::V;
|
||||
use super::{Rc, RefCell, ascii85, is_white, parse_num};
|
||||
|
||||
/// Source tokenizer (the data source for `currentfile`).
|
||||
pub(super) struct Src<'a> {
|
||||
pub(super) d: &'a [u8],
|
||||
pub(crate) pos: usize,
|
||||
}
|
||||
|
||||
impl Src<'_> {
|
||||
fn skip_ws(&mut self) {
|
||||
while self.pos < self.d.len() {
|
||||
let c = self.d[self.pos];
|
||||
if is_white(c) {
|
||||
self.pos += 1;
|
||||
} else if c == b'%' {
|
||||
let s = self.pos;
|
||||
while self.pos < self.d.len() && !matches!(self.d[self.pos], b'\n' | b'\r') {
|
||||
self.pos += 1;
|
||||
}
|
||||
// DSC: skip embedded binary / data sections.
|
||||
let line = &self.d[s..self.pos];
|
||||
if line.starts_with(b"%%BeginData:") || line.starts_with(b"%%BeginBinary:") || line.starts_with(b"%%BeginPreview") {
|
||||
let end: &[u8] = if line.starts_with(b"%%BeginData:") {
|
||||
b"%%EndData"
|
||||
} else if line.starts_with(b"%%BeginBinary:") {
|
||||
b"%%EndBinary"
|
||||
} else {
|
||||
b"%%EndPreview"
|
||||
};
|
||||
match self.d[self.pos..].windows(end.len()).position(|w| w == end) {
|
||||
Some(p) => self.pos += p,
|
||||
None => self.pos = self.d.len(),
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn word(&mut self) -> &[u8] {
|
||||
let s = self.pos;
|
||||
while self.pos < self.d.len() {
|
||||
let c = self.d[self.pos];
|
||||
if is_white(c) || matches!(c, b'(' | b')' | b'<' | b'>' | b'[' | b']' | b'{' | b'}' | b'/' | b'%') {
|
||||
break;
|
||||
}
|
||||
self.pos += 1;
|
||||
}
|
||||
&self.d[s..self.pos]
|
||||
}
|
||||
|
||||
/// The next token; `{ … }` comes back as a whole procedure.
|
||||
pub(super) fn token(&mut self, depth: usize) -> Option<V> {
|
||||
self.skip_ws();
|
||||
let c = *self.d.get(self.pos)?;
|
||||
Some(match c {
|
||||
b'{' => {
|
||||
self.pos += 1;
|
||||
let mut body = vec![];
|
||||
loop {
|
||||
self.skip_ws();
|
||||
match self.d.get(self.pos) {
|
||||
None => break,
|
||||
Some(b'}') => {
|
||||
self.pos += 1;
|
||||
break;
|
||||
}
|
||||
_ => {
|
||||
if depth > 100 {
|
||||
return None;
|
||||
}
|
||||
match self.token(depth + 1) {
|
||||
Some(t) => body.push(t),
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
V::Proc(Rc::new(body))
|
||||
}
|
||||
b'}' => {
|
||||
self.pos += 1;
|
||||
V::Null
|
||||
}
|
||||
b'/' => {
|
||||
self.pos += 1;
|
||||
let imm = self.d.get(self.pos) == Some(&b'/');
|
||||
if imm {
|
||||
self.pos += 1;
|
||||
}
|
||||
let w = String::from_utf8_lossy(self.word()).into_owned();
|
||||
// `//name` (immediately evaluated) is treated like a plain name.
|
||||
if imm { V::Name(w.into()) } else { V::Lit(w.into()) }
|
||||
}
|
||||
b'(' => {
|
||||
self.pos += 1;
|
||||
let mut out = vec![];
|
||||
let mut depth = 1;
|
||||
while self.pos < self.d.len() {
|
||||
let c = self.d[self.pos];
|
||||
self.pos += 1;
|
||||
match c {
|
||||
b'\\' => {
|
||||
let e = self.d.get(self.pos).copied().unwrap_or(b'\\');
|
||||
self.pos += 1;
|
||||
match e {
|
||||
b'n' => out.push(b'\n'),
|
||||
b'r' => out.push(b'\r'),
|
||||
b't' => out.push(b'\t'),
|
||||
b'0'..=b'7' => {
|
||||
let mut v = (e - b'0') as u32;
|
||||
for _ in 0..2 {
|
||||
match self.d.get(self.pos) {
|
||||
Some(d @ b'0'..=b'7') => {
|
||||
v = v * 8 + (d - b'0') as u32;
|
||||
self.pos += 1;
|
||||
}
|
||||
_ => break,
|
||||
}
|
||||
}
|
||||
out.push(v as u8);
|
||||
}
|
||||
b'\n' | b'\r' => {}
|
||||
o => out.push(o),
|
||||
}
|
||||
}
|
||||
b'(' => {
|
||||
depth += 1;
|
||||
out.push(c);
|
||||
}
|
||||
b')' => {
|
||||
depth -= 1;
|
||||
if depth == 0 {
|
||||
break;
|
||||
}
|
||||
out.push(c);
|
||||
}
|
||||
_ => out.push(c),
|
||||
}
|
||||
}
|
||||
V::Str(Rc::new(RefCell::new(out)))
|
||||
}
|
||||
b'<' if self.d.get(self.pos + 1) == Some(&b'<') => {
|
||||
self.pos += 2;
|
||||
V::Name("<<".into())
|
||||
}
|
||||
b'>' if self.d.get(self.pos + 1) == Some(&b'>') => {
|
||||
self.pos += 2;
|
||||
V::Name(">>".into())
|
||||
}
|
||||
b'<' if self.d.get(self.pos + 1) == Some(&b'~') => {
|
||||
let s = self.pos;
|
||||
while self.pos + 1 < self.d.len() && !(self.d[self.pos] == b'~' && self.d[self.pos + 1] == b'>') {
|
||||
self.pos += 1;
|
||||
}
|
||||
self.pos = (self.pos + 2).min(self.d.len());
|
||||
V::Str(Rc::new(RefCell::new(ascii85(&self.d[s..self.pos]))))
|
||||
}
|
||||
b'<' => {
|
||||
self.pos += 1;
|
||||
let mut hex = vec![];
|
||||
while self.pos < self.d.len() && self.d[self.pos] != b'>' {
|
||||
if self.d[self.pos].is_ascii_hexdigit() {
|
||||
hex.push(self.d[self.pos]);
|
||||
}
|
||||
self.pos += 1;
|
||||
}
|
||||
self.pos += 1;
|
||||
if hex.len() % 2 == 1 {
|
||||
hex.push(b'0');
|
||||
}
|
||||
let h = |c: u8| (c as char).to_digit(16).unwrap_or(0) as u8;
|
||||
V::Str(Rc::new(RefCell::new(hex.chunks(2).map(|p| (h(p[0]) << 4) | h(p[1])).collect())))
|
||||
}
|
||||
b'[' | b']' => {
|
||||
self.pos += 1;
|
||||
V::Name(if c == b'[' { "[" } else { "]" }.into())
|
||||
}
|
||||
b')' | b'>' => {
|
||||
self.pos += 1;
|
||||
V::Null
|
||||
}
|
||||
_ => {
|
||||
let w = self.word();
|
||||
if w.is_empty() {
|
||||
self.pos += 1;
|
||||
return Some(V::Null);
|
||||
}
|
||||
match parse_num(w) {
|
||||
Some(n) => V::Num(n),
|
||||
None => {
|
||||
// Radix numbers (16#FF).
|
||||
let s = String::from_utf8_lossy(w).into_owned();
|
||||
match s.split_once('#').and_then(|(r, v)| i64::from_str_radix(v, r.parse::<u32>().ok().filter(|r| (2..=36).contains(r))?).ok()) {
|
||||
Some(n) => V::Num(n as f64),
|
||||
None => V::Name(s.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Step over inline image data that follows an `image` operator reading `currentfile`.
|
||||
pub(super) fn skip_image_data(&mut self) {
|
||||
self.skip_ws();
|
||||
if self.d[self.pos..].starts_with(b"<~") || self.d.get(self.pos).is_some_and(|c| (b'!'..=b'u').contains(c) && !c.is_ascii_hexdigit()) {
|
||||
match self.d[self.pos..].windows(2).position(|w| w == b"~>") {
|
||||
Some(p) => self.pos += p + 2,
|
||||
None => self.pos = self.d.len(),
|
||||
}
|
||||
return;
|
||||
}
|
||||
while self.pos < self.d.len() && (self.d[self.pos].is_ascii_hexdigit() || is_white(self.d[self.pos])) {
|
||||
self.pos += 1;
|
||||
}
|
||||
if self.d.get(self.pos) == Some(&b'>') {
|
||||
self.pos += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,329 +0,0 @@
|
||||
use super::scanner::Src;
|
||||
use super::value::{DictRef, Flow, V, array, matrix_of, matrix_val, new_dict};
|
||||
use super::{Affine, BezPath, FillRule, Font, HashMap, Interp, Paint, Point, Rc, RefCell};
|
||||
|
||||
// ------------------------------------------------------------------ text
|
||||
|
||||
/// An encoding array of glyph names (`StandardEncoding`; `ISOLatin1Encoding` and others are
|
||||
/// approximated by WinAnsi, which agrees with ISO Latin-1 on the printable codes).
|
||||
pub(super) fn encoding_array(name: &str) -> V {
|
||||
let base = if name == "StandardEncoding" { crate::encoding::Base::Standard } else { crate::encoding::Base::WinAnsi };
|
||||
array((0..256).map(|c| V::Lit(base.name(c as u8).unwrap_or_else(|| ".notdef".into()).into())).collect())
|
||||
}
|
||||
|
||||
fn dict_matrix(d: &DictRef, key: &str) -> Affine {
|
||||
d.borrow().get(key).and_then(matrix_of).unwrap_or(Affine::IDENTITY)
|
||||
}
|
||||
|
||||
/// A copy of a font dictionary with `m` applied after its matrix (`scalefont`, `makefont`).
|
||||
fn transformed(font: &DictRef, m: Affine) -> DictRef {
|
||||
let copy: HashMap<String, V> = font.borrow().clone();
|
||||
let d = Rc::new(RefCell::new(copy));
|
||||
let old = dict_matrix(&d, "__m");
|
||||
d.borrow_mut().insert("__m".into(), matrix_val(m * old));
|
||||
d
|
||||
}
|
||||
|
||||
impl Interp {
|
||||
/// A font dictionary by name: one `definefont` made, else a new dictionary for an
|
||||
/// embedded program or a bundled stand-in.
|
||||
pub(super) fn find_font(&mut self, key: &str) -> DictRef {
|
||||
if let Some(d) = self.font_dir.get(key) {
|
||||
return d.clone();
|
||||
}
|
||||
let d = new_dict();
|
||||
{
|
||||
let mut m = d.borrow_mut();
|
||||
m.insert("FontName".into(), V::Lit(key.into()));
|
||||
m.insert("FontType".into(), V::Num(1.0));
|
||||
m.insert("FontMatrix".into(), matrix_val(Affine::scale(0.001)));
|
||||
m.insert("FID".into(), V::Null);
|
||||
m.insert("__base".into(), V::Lit(key.into()));
|
||||
m.insert("__m".into(), matrix_val(Affine::IDENTITY));
|
||||
}
|
||||
self.font_dir.insert(key.to_string(), d.clone());
|
||||
d
|
||||
}
|
||||
|
||||
/// The drawable font of a font dictionary (its base program and encoding) and the matrix
|
||||
/// from text space (font size 1) to user space.
|
||||
fn font_of(&mut self, d: &DictRef) -> Option<(Rc<Font>, Affine)> {
|
||||
if matches!(d.borrow().get("FontType"), Some(V::Num(t)) if *t == 3.0) {
|
||||
// Type 3 fonts (glyph procedures) are not run.
|
||||
self.b.skip("EPS Type 3 font");
|
||||
return None;
|
||||
}
|
||||
let (base, names) = {
|
||||
let m = d.borrow();
|
||||
let base = m.get("__base").or_else(|| m.get("FontName")).map(V::key)?;
|
||||
let names: Option<Vec<Option<String>>> = m.get("Encoding").and_then(V::items).map(|a| {
|
||||
a.iter()
|
||||
.map(|v| match v {
|
||||
V::Lit(n) | V::Name(n) if &**n != ".notdef" => Some(n.to_string()),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
});
|
||||
(base, names)
|
||||
};
|
||||
let key = match &names {
|
||||
Some(n) => format!("{base}\u{0}{}", n.iter().map(|x| x.as_deref().unwrap_or("")).collect::<Vec<_>>().join(" ")),
|
||||
None => base.clone(),
|
||||
};
|
||||
let font = match self.font_cache.get(&key) {
|
||||
Some(f) => f.clone(),
|
||||
None => {
|
||||
// Not embedded: a bundled stand-in, as for PDF.
|
||||
let prog = self.embedded.get(&base).cloned();
|
||||
let f = Rc::new(Font::standalone(&base, prog.as_ref().map(|(d, cff)| (d.as_slice(), *cff)), names));
|
||||
self.font_cache.insert(key, f.clone());
|
||||
f
|
||||
}
|
||||
};
|
||||
Some((font, dict_matrix(d, "__m")))
|
||||
}
|
||||
|
||||
/// A string's glyph outlines (device space) from the current point, with an extra
|
||||
/// displacement `extra(index, code)` (user space) after each glyph; moves the current
|
||||
/// point.
|
||||
fn text_path(&mut self, bytes: &[u8], mut extra: impl FnMut(usize, u32) -> (f64, f64)) -> Result<Option<(BezPath, String)>, Flow> {
|
||||
let Some(d) = self.gs.font.clone() else { return Ok(None) };
|
||||
let Some((font, m)) = self.font_of(&d) else { return Ok(None) };
|
||||
let mut p = self.current_user();
|
||||
let mut path = BezPath::new();
|
||||
let mut text = String::new();
|
||||
let ctm = self.gs.ctm;
|
||||
for (i, &code) in bytes.iter().enumerate() {
|
||||
let code = code as u32;
|
||||
// Every input character costs at least one unit, so empty outlines are not free.
|
||||
self.spend(1)?;
|
||||
if let Some(g) = font.glyph(code) {
|
||||
// Each outline element counts against the path limit and the budget before it
|
||||
// is copied, so a long string cannot expand into unbounded geometry.
|
||||
let n = g.elements().len();
|
||||
self.path_fits(path.elements().len().saturating_add(n))?;
|
||||
self.spend(n)?;
|
||||
path.extend(ctm * Affine::translate(p.to_vec2()) * m * (*g).clone());
|
||||
}
|
||||
text.push_str(&font.unicode(code));
|
||||
let adv = m * Point::new(font.width(code), 0.0) - m * Point::ZERO;
|
||||
let (ex, ey) = extra(i, code);
|
||||
p += adv + kurbo::Vec2::new(ex, ey);
|
||||
}
|
||||
self.move_to(p)?;
|
||||
Ok(Some((path, text)))
|
||||
}
|
||||
|
||||
fn fill_text(&mut self, path: BezPath, text: &str) {
|
||||
let label: String = text.chars().filter(|c| !c.is_control()).take(40).collect();
|
||||
let name = if label.trim().is_empty() { "Text".to_string() } else { format!("Text: {}", label.trim()) };
|
||||
self.b.fill_stroke_named(&name, path, Affine::IDENTITY, Some((Paint::Color(self.gs.color), 1.0, FillRule::NonZero)), None);
|
||||
}
|
||||
|
||||
fn pop_string(&mut self) -> Vec<u8> {
|
||||
match self.pop() {
|
||||
V::Str(s) => s.borrow().clone(),
|
||||
_ => vec![],
|
||||
}
|
||||
}
|
||||
|
||||
fn show_with(&mut self, s: &[u8], extra: impl FnMut(usize, u32) -> (f64, f64)) -> Result<(), Flow> {
|
||||
match self.text_path(s, extra)? {
|
||||
Some((path, text)) => self.fill_text(path, &text),
|
||||
None => self.b.skip("text (no font)"),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Text and font operators (PostScript Language Reference §5.1, §8.2).
|
||||
pub(super) fn text_op(&mut self, n: &str, src: &mut Src) -> Result<(), Flow> {
|
||||
match n {
|
||||
"scalefont" | "makefont" => {
|
||||
let m = if n == "scalefont" {
|
||||
Affine::scale(self.popn())
|
||||
} else {
|
||||
let v = self.pop();
|
||||
matrix_of(&v).unwrap_or(Affine::IDENTITY)
|
||||
};
|
||||
let font = match self.pop() {
|
||||
V::Dict(d) => d,
|
||||
_ => self.find_font("Helvetica"),
|
||||
};
|
||||
self.push(V::Dict(transformed(&font, m)));
|
||||
}
|
||||
"selectfont" => {
|
||||
let size = self.pop();
|
||||
let key = self.pop().key();
|
||||
let font = self.find_font(&key);
|
||||
let m = match &size {
|
||||
V::Num(s) => Affine::scale(*s),
|
||||
other => matrix_of(other).unwrap_or(Affine::IDENTITY),
|
||||
};
|
||||
self.gs.font = Some(transformed(&font, m));
|
||||
}
|
||||
"setfont" => {
|
||||
if let V::Dict(d) = self.pop() {
|
||||
self.gs.font = Some(d);
|
||||
}
|
||||
}
|
||||
"currentfont" | "rootfont" => {
|
||||
let d = self.gs.font.clone().unwrap_or_else(new_dict);
|
||||
self.push(V::Dict(d));
|
||||
}
|
||||
"definefont" => {
|
||||
let v = self.pop();
|
||||
let key = self.pop().key();
|
||||
if let V::Dict(d) = &v {
|
||||
if !d.borrow().contains_key("__base") {
|
||||
// A font the file defines itself: its embedded program, by name.
|
||||
d.borrow_mut().insert("__base".into(), V::Lit(key.as_str().into()));
|
||||
d.borrow_mut().insert("__m".into(), matrix_val(Affine::IDENTITY));
|
||||
}
|
||||
self.font_dir.insert(key, d.clone());
|
||||
}
|
||||
self.push(v);
|
||||
}
|
||||
"undefinefont" => {
|
||||
let key = self.pop().key();
|
||||
self.font_dir.remove(&key);
|
||||
}
|
||||
"StandardEncoding" | "ISOLatin1Encoding" => self.push(encoding_array(n)),
|
||||
"show" => {
|
||||
let s = self.pop_string();
|
||||
self.show_with(&s, |_, _| (0.0, 0.0))?;
|
||||
}
|
||||
"ashow" => {
|
||||
let s = self.pop_string();
|
||||
let ay = self.popn();
|
||||
let ax = self.popn();
|
||||
self.show_with(&s, |_, _| (ax, ay))?;
|
||||
}
|
||||
"widthshow" => {
|
||||
let s = self.pop_string();
|
||||
let ch = self.popn() as u32;
|
||||
let cy = self.popn();
|
||||
let cx = self.popn();
|
||||
self.show_with(&s, |_, c| if c == ch { (cx, cy) } else { (0.0, 0.0) })?;
|
||||
}
|
||||
"awidthshow" => {
|
||||
let s = self.pop_string();
|
||||
let ay = self.popn();
|
||||
let ax = self.popn();
|
||||
let ch = self.popn() as u32;
|
||||
let cy = self.popn();
|
||||
let cx = self.popn();
|
||||
self.show_with(&s, |_, c| if c == ch { (cx + ax, cy + ay) } else { (ax, ay) })?;
|
||||
}
|
||||
"kshow" | "cshow" => {
|
||||
// The procedure between characters is not run.
|
||||
let s = self.pop_string();
|
||||
self.pop();
|
||||
self.show_with(&s, |_, _| (0.0, 0.0))?;
|
||||
}
|
||||
"xshow" | "yshow" | "xyshow" => {
|
||||
let disp: Vec<f64> = self.pop().items().unwrap_or_default().iter().filter_map(V::num).collect();
|
||||
let s = self.pop_string();
|
||||
self.explicit_show(&s, &disp, n)?;
|
||||
}
|
||||
"glyphshow" => {
|
||||
let name = self.pop().key();
|
||||
let Some(d) = self.gs.font.clone() else { return Ok(()) };
|
||||
// Drawn through a one-glyph encoding.
|
||||
let mut e: Vec<V> = (0..256).map(|_| V::Lit(".notdef".into())).collect();
|
||||
e[65] = V::Lit(name.as_str().into());
|
||||
let tmp = transformed(&d, Affine::IDENTITY);
|
||||
tmp.borrow_mut().insert("Encoding".into(), array(e));
|
||||
self.gs.font = Some(tmp);
|
||||
self.show_with(b"A", |_, _| (0.0, 0.0))?;
|
||||
self.gs.font = Some(d);
|
||||
}
|
||||
"charpath" => {
|
||||
self.pop();
|
||||
let s = self.pop_string();
|
||||
let saved = std::mem::take(&mut self.gs.path);
|
||||
let start = self.gs.start;
|
||||
match self.text_path(&s, |_, _| (0.0, 0.0))? {
|
||||
Some((glyphs, _)) => {
|
||||
// The outlines join the path: each element counts against the budget and
|
||||
// the path limit.
|
||||
self.gs.path = saved;
|
||||
self.room(glyphs.elements().len() + 1)?;
|
||||
self.spend(glyphs.elements().len())?;
|
||||
self.gs.path.extend(glyphs);
|
||||
if let Some(c) = self.gs.cur {
|
||||
self.gs.path.move_to(c);
|
||||
}
|
||||
self.gs.start = start;
|
||||
}
|
||||
None => self.gs.path = saved,
|
||||
}
|
||||
}
|
||||
"stringwidth" => {
|
||||
let s = self.pop_string();
|
||||
let (mut w, mut h) = (0.0, 0.0);
|
||||
if let Some(d) = self.gs.font.clone()
|
||||
&& let Some((font, m)) = self.font_of(&d)
|
||||
{
|
||||
for &c in &s {
|
||||
let v = m * Point::new(font.width(c as u32), 0.0) - m * Point::ZERO;
|
||||
w += v.x;
|
||||
h += v.y;
|
||||
}
|
||||
}
|
||||
self.push(V::Num(w));
|
||||
self.push(V::Num(h));
|
||||
}
|
||||
"setcachedevice" => {
|
||||
for _ in 0..6 {
|
||||
self.pop();
|
||||
}
|
||||
}
|
||||
"setcharwidth" => {
|
||||
self.pop();
|
||||
self.pop();
|
||||
}
|
||||
// An embedded Type 1 program's encrypted part (read by `embedded_fonts`).
|
||||
"eexec" => {
|
||||
if matches!(self.pop(), V::File) {
|
||||
let rest = &src.d[src.pos.min(src.d.len())..];
|
||||
src.pos += rest.windows(11).position(|w| w == b"cleartomark").map_or(rest.len(), |p| p + 11);
|
||||
}
|
||||
}
|
||||
// A CFF font set's binary data (read by `embedded_fonts`).
|
||||
"StartData" => {
|
||||
let len = self.popn().max(0.0) as usize;
|
||||
self.pop();
|
||||
src.pos = src.pos.saturating_add(1).saturating_add(len).min(src.d.len());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// `xshow` / `yshow` / `xyshow`: glyph displacements from a number array instead of the
|
||||
/// advances.
|
||||
fn explicit_show(&mut self, s: &[u8], disp: &[f64], n: &str) -> Result<(), Flow> {
|
||||
let step = if n == "xyshow" { 2 } else { 1 };
|
||||
let d: Vec<(f64, f64)> = (0..s.len())
|
||||
.map(|k| {
|
||||
let i = k * step;
|
||||
let v = |j: usize| disp.get(j).copied().unwrap_or(0.0);
|
||||
match n {
|
||||
"xshow" => (v(i), 0.0),
|
||||
"yshow" => (0.0, v(i)),
|
||||
_ => (v(i), v(i + 1)),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
let Some(fd) = self.gs.font.clone() else {
|
||||
self.b.skip("text (no font)");
|
||||
return Ok(());
|
||||
};
|
||||
let Some((font, m)) = self.font_of(&fd) else { return Ok(()) };
|
||||
self.show_with(s, move |k, c| {
|
||||
let adv = m * Point::new(font.width(c), 0.0) - m * Point::ZERO;
|
||||
let (dx, dy) = d.get(k).copied().unwrap_or((0.0, 0.0));
|
||||
(dx - adv.x, dy - adv.y)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
use super::{Affine, BezPath, Cap, HashMap, Join, Point, Rc, RefCell};
|
||||
|
||||
pub(crate) type DictRef = Rc<RefCell<HashMap<String, V>>>;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) enum V {
|
||||
Num(f64),
|
||||
Bool(bool),
|
||||
/// An executable name.
|
||||
Name(Rc<str>),
|
||||
/// A literal name (`/name`).
|
||||
Lit(Rc<str>),
|
||||
/// A built-in operator, as `load` returns it for a name no dictionary defines.
|
||||
Op(Rc<str>),
|
||||
Str(Rc<RefCell<Vec<u8>>>),
|
||||
Proc(Rc<Vec<V>>),
|
||||
Array(Rc<RefCell<Vec<V>>>),
|
||||
Dict(DictRef),
|
||||
Mark,
|
||||
Null,
|
||||
/// `currentfile`.
|
||||
File,
|
||||
}
|
||||
|
||||
impl V {
|
||||
pub(super) fn num(&self) -> Option<f64> {
|
||||
match self {
|
||||
V::Num(n) => Some(*n),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
pub(super) fn key(&self) -> String {
|
||||
match self {
|
||||
V::Name(n) | V::Lit(n) | V::Op(n) => n.to_string(),
|
||||
V::Str(s) => String::from_utf8_lossy(&s.borrow()).into_owned(),
|
||||
V::Num(n) => format!("{n}"),
|
||||
V::Bool(b) => format!("{b}"),
|
||||
_ => String::new(),
|
||||
}
|
||||
}
|
||||
pub(super) fn items(&self) -> Option<Vec<V>> {
|
||||
match self {
|
||||
V::Array(a) => Some(a.borrow().clone()),
|
||||
V::Proc(p) => Some(p.as_ref().clone()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) enum Flow {
|
||||
Exit,
|
||||
Stop,
|
||||
Quit,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(super) struct GState {
|
||||
pub(crate) ctm: Affine,
|
||||
pub(crate) color: [f64; 3],
|
||||
pub(crate) lw: f64,
|
||||
pub(crate) cap: Cap,
|
||||
pub(crate) join: Join,
|
||||
pub(crate) miter: f64,
|
||||
pub(crate) dash: Option<(Vec<f64>, f64)>,
|
||||
pub(crate) path: BezPath,
|
||||
pub(crate) cur: Option<Point>,
|
||||
pub(crate) start: Option<Point>,
|
||||
pub(crate) depth: usize,
|
||||
/// The current font dictionary.
|
||||
pub(crate) font: Option<DictRef>,
|
||||
}
|
||||
|
||||
pub(super) fn new_dict() -> DictRef {
|
||||
Rc::new(RefCell::new(HashMap::new()))
|
||||
}
|
||||
|
||||
pub(super) fn array(v: Vec<V>) -> V {
|
||||
V::Array(Rc::new(RefCell::new(v)))
|
||||
}
|
||||
|
||||
pub(super) fn matrix_of(v: &V) -> Option<Affine> {
|
||||
let a: Vec<f64> = v.items()?.iter().filter_map(V::num).collect();
|
||||
(a.len() == 6).then(|| Affine::new([a[0], a[1], a[2], a[3], a[4], a[5]]))
|
||||
}
|
||||
|
||||
pub(super) fn matrix_val(m: Affine) -> V {
|
||||
array(m.as_coeffs().iter().map(|c| V::Num(*c)).collect())
|
||||
}
|
||||
@@ -82,6 +82,21 @@ fn pdf_paths_clip_gradient_and_layers() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pdf_actual_text_is_exposed_as_a_logical_group() {
|
||||
let content = "/Span << /ActualText (Logical text) >> BDC\n1 0 0 rg 10 10 20 20 re f\nEMC";
|
||||
let objs = vec![
|
||||
(1, "<< /Type /Catalog /Pages 2 0 R >>".to_string(), None),
|
||||
(2, "<< /Type /Pages /Kids [3 0 R] /Count 1 >>".to_string(), None),
|
||||
(3, "<< /Type /Page /Parent 2 0 R /MediaBox [0 0 100 100] /Resources << >> /Contents 4 0 R >>".to_string(), None),
|
||||
(4, "<< >>".to_string(), Some(content.as_bytes().to_vec())),
|
||||
];
|
||||
|
||||
let doc = parse(&pdf(&objs, 1)).unwrap();
|
||||
|
||||
assert_eq!(shape_names(&doc), vec!["Text: Logical text"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pdf_forms_rotation_cmyk_and_alpha() {
|
||||
let content = "q 2 0 0 2 0 0 cm /Fm0 Do Q\n/GS0 gs 0 0 0 1 k 0 0 10 10 re f\n";
|
||||
@@ -231,6 +246,12 @@ fn eps_postscript_subset() {
|
||||
assert_eq!(parse(b"hello"), Err(Error::NotVector));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn eps_without_a_bounding_box_keeps_the_public_error_variant() {
|
||||
let eps = b"%!PS-Adobe-3.0 EPSF-3.0\n%%EndComments\n0 0 10 10 rectfill\n";
|
||||
assert_eq!(parse(eps), Err(Error::NoBoundingBox));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filters_decode() {
|
||||
assert_eq!(object::ascii85(b"<~87cURD]i,\"Ebo80~>"), b"Hello World!".to_vec());
|
||||
@@ -450,6 +471,9 @@ pub(crate) fn shape_names(doc: &Doc) -> Vec<String> {
|
||||
fn walk(g: &effectcraft_svg::Group, out: &mut Vec<String>) {
|
||||
for c in &g.children {
|
||||
match c {
|
||||
// Marked text from the shared PostScript adapter is a logical text object whose
|
||||
// outlined glyph paths remain children for rendering and editing.
|
||||
Node::Group(s) if s.name.starts_with("Text: ") => out.push(s.name.clone()),
|
||||
Node::Group(s) => walk(s, out),
|
||||
Node::Shape(s) => out.push(s.name.clone()),
|
||||
Node::Image(i) => out.push(i.name.clone()),
|
||||
|
||||
@@ -5,8 +5,9 @@ use std::process::Command;
|
||||
|
||||
use serde_json::Value;
|
||||
|
||||
const REV: &str = "2fea4b4ce28678e30bd546885a323aaa8fa243ef";
|
||||
const PACKAGES: &[(&str, &str)] = &[("craft-pdf", "0.1.0"), ("hayro-syntax", "0.7.2"), ("hayro-jbig2", "0.3.0")];
|
||||
const REV: &str = "41fb227542efb8a7748caa1c659f271d8605303c";
|
||||
const PACKAGES: &[(&str, &str)] =
|
||||
&[("craft-pdf", "0.1.0"), ("craft-ps", "0.1.0"), ("hayro-syntax", "0.7.2"), ("hayro-jbig2", "0.3.0")];
|
||||
|
||||
pub fn run(root: &Path) -> Result<(), String> {
|
||||
let output = Command::new(std::env::var_os("CARGO").unwrap_or_else(|| "cargo".into()))
|
||||
@@ -33,7 +34,7 @@ fn validate(metadata: &Value) -> Result<(), String> {
|
||||
return Err(format!("{name}: expected exactly {version} from {source}"));
|
||||
}
|
||||
}
|
||||
for (name, allowed) in [("craft-pdf", "read"), ("hayro-syntax", "std")] {
|
||||
for (name, allowed) in [("craft-pdf", "read"), ("craft-ps", "read"), ("hayro-syntax", "std")] {
|
||||
let package = packages.iter().find(|p| p["name"] == name).ok_or_else(|| format!("missing {name}"))?;
|
||||
let node = nodes.iter().find(|n| n["id"] == package["id"]).ok_or_else(|| format!("{name}: missing resolved node"))?;
|
||||
let features = node["features"].as_array().ok_or_else(|| format!("{name}: missing resolved features"))?;
|
||||
@@ -61,7 +62,8 @@ mod tests {
|
||||
json!({"id": name, "name": name, "version": version, "source": format!("git+https://github.com/storytold/craft-libs?rev={REV}#{REV}")})
|
||||
}).collect();
|
||||
json!({"packages": packages, "resolve": {"nodes": [
|
||||
{"id": "hayro-syntax", "features": ["std"]}, {"id": "craft-pdf", "features": ["read"]}
|
||||
{"id": "hayro-syntax", "features": ["std"]}, {"id": "craft-pdf", "features": ["read"]},
|
||||
{"id": "craft-ps", "features": ["read"]}
|
||||
]}})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user