Delegate PhotoCraft PDF content writing to craft-pdf

This commit is contained in:
Dylan M. Taylor committed 2026-11-13 07:17:09 -05:00
1 parent 68ec31a114
commit 679bc71c57
6 files changed
+169 -298

No files matched your search

Generated
+33 -33
View File
@@ -1320,7 +1320,7 @@ dependencies = [
[[package]]
name = "craft-affinity"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"crc32fast",
"flate2",
@@ -1331,7 +1331,7 @@ dependencies = [
[[package]]
name = "craft-atomic"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"rustix 1.1.5",
]
@@ -1339,7 +1339,7 @@ dependencies = [
[[package]]
name = "craft-crw"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"thiserror 2.0.21",
]
@@ -1347,17 +1347,17 @@ dependencies = [
[[package]]
name = "craft-docpath"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
[[package]]
name = "craft-eps"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
[[package]]
name = "craft-file-formats"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"craft-eps",
"craft-idml",
@@ -1375,12 +1375,12 @@ dependencies = [
[[package]]
name = "craft-fonts-build"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
[[package]]
name = "craft-heif"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"heic-rs",
"rayon",
@@ -1389,7 +1389,7 @@ dependencies = [
[[package]]
name = "craft-i18n"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"fixed_decimal",
"icu_decimal",
@@ -1412,7 +1412,7 @@ dependencies = [
[[package]]
name = "craft-idml"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"craft-xml",
"craft-zip",
@@ -1422,7 +1422,7 @@ dependencies = [
[[package]]
name = "craft-image-codecs"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"craft-heif",
"craft-jpeg",
@@ -1445,7 +1445,7 @@ dependencies = [
[[package]]
name = "craft-jpeg"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"thiserror 2.0.21",
]
@@ -1453,7 +1453,7 @@ dependencies = [
[[package]]
name = "craft-kra"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"craft-xml",
"craft-zip",
@@ -1463,7 +1463,7 @@ dependencies = [
[[package]]
name = "craft-metadata"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"brotli-decompressor 6.3.1",
"chrono",
@@ -1475,7 +1475,7 @@ dependencies = [
[[package]]
name = "craft-ora"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"craft-xml",
"craft-zip",
@@ -1485,7 +1485,7 @@ dependencies = [
[[package]]
name = "craft-pcraft-bundle"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"blake3",
"craft-atomic",
@@ -1498,7 +1498,7 @@ dependencies = [
[[package]]
name = "craft-pcraft-format"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"serde",
"serde_json",
@@ -1508,7 +1508,7 @@ dependencies = [
[[package]]
name = "craft-pdf"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"bytemuck",
"flate2",
@@ -1522,7 +1522,7 @@ dependencies = [
[[package]]
name = "craft-pdn"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"flate2",
"thiserror 2.0.21",
@@ -1531,7 +1531,7 @@ dependencies = [
[[package]]
name = "craft-print"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"craft-winprint-gdi",
"log",
@@ -1545,7 +1545,7 @@ dependencies = [
[[package]]
name = "craft-psd"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"encoding_rs",
"flate2",
@@ -1556,7 +1556,7 @@ dependencies = [
[[package]]
name = "craft-raw"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"chrono",
"craft-crw",
@@ -1574,7 +1574,7 @@ dependencies = [
[[package]]
name = "craft-svg"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"craft-image-codecs",
"craft-xml",
@@ -1589,7 +1589,7 @@ dependencies = [
[[package]]
name = "craft-tiff"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"serde",
"thiserror 2.0.21",
@@ -1598,7 +1598,7 @@ dependencies = [
[[package]]
name = "craft-ui"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"craft-fonts-build",
"craft-i18n",
@@ -1619,7 +1619,7 @@ dependencies = [
[[package]]
name = "craft-update"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"chrono",
"dunce",
@@ -1654,7 +1654,7 @@ dependencies = [
[[package]]
name = "craft-xcf"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"flate2",
"thiserror 2.0.21",
@@ -1663,7 +1663,7 @@ dependencies = [
[[package]]
name = "craft-xml"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"quick-xml 0.41.0",
"thiserror 2.0.21",
@@ -1672,7 +1672,7 @@ dependencies = [
[[package]]
name = "craft-zip"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"flate2",
"thiserror 2.0.21",
@@ -3078,7 +3078,7 @@ dependencies = [
[[package]]
name = "hayro"
version = "0.7.1"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"bytemuck",
"hayro-interpret",
@@ -3108,7 +3108,7 @@ dependencies = [
[[package]]
name = "hayro-interpret"
version = "0.7.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"bitflags 2.13.2",
"hayro-cmap",
@@ -3126,7 +3126,7 @@ dependencies = [
[[package]]
name = "hayro-jbig2"
version = "0.3.0"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"fearless_simd",
"hayro-ccitt",
@@ -3150,7 +3150,7 @@ checksum = "bc2d80da85f31c3fdc0366431f44cfd645a9da1e242ed1f4a61f213d9765660f"
[[package]]
name = "hayro-syntax"
version = "0.7.2"
source = "git+https://github.com/storytold/craft-libs?rev=7cef561ce#7cef561ce72a84da263d8fd4fe36c8d88525fea9"
source = "git+https://github.com/storytold/craft-libs?rev=80a8ecfe0#80a8ecfe05143ef979d87bccf3d5353cbea828b9"
dependencies = [
"flate2",
"hayro-ccitt",
+25 -25
View File
@@ -10,7 +10,7 @@ license = "MIT OR Apache-2.0"
rust-version = "1.95"
[workspace.dependencies]
craft-ui = { git = "https://github.com/storytold/craft-libs", rev = "7cef561ce", features = ["serde"] }
craft-ui = { git = "https://github.com/storytold/craft-libs", rev = "80a8ecfe0", features = ["serde"] }
# internal
photocraft-geom = { path = "crates/geom" }
photocraft-color = { path = "crates/color" }
@@ -18,11 +18,11 @@ photocraft-cms = { path = "crates/cms" }
photocraft-raster = { path = "crates/raster" }
photocraft-doc = { path = "crates/doc" }
photocraft-ops = { path = "crates/ops" }
photocraft-psd = { package = "craft-psd", git = "https://github.com/storytold/craft-libs", rev = "7cef561ce" }
photocraft-codecs = { package = "craft-image-codecs", git = "https://github.com/storytold/craft-libs", rev = "7cef561ce" }
photocraft-formats = { package = "craft-file-formats", git = "https://github.com/storytold/craft-libs", rev = "7cef561ce", features = ["raster-codecs", "pdf", "svg", "ora", "kra", "xcf", "pdn", "raw", "psd", "affinity", "pcraft"] }
photocraft-psd = { package = "craft-psd", git = "https://github.com/storytold/craft-libs", rev = "80a8ecfe0" }
photocraft-codecs = { package = "craft-image-codecs", git = "https://github.com/storytold/craft-libs", rev = "80a8ecfe0" }
photocraft-formats = { package = "craft-file-formats", git = "https://github.com/storytold/craft-libs", rev = "80a8ecfe0", features = ["raster-codecs", "pdf", "svg", "ora", "kra", "xcf", "pdn", "raw", "psd", "affinity", "pcraft"] }
photocraft-raw = { path = "crates/raw" }
photocraft-affinity = { package = "craft-affinity", git = "https://github.com/storytold/craft-libs", rev = "7cef561ce" }
photocraft-affinity = { package = "craft-affinity", git = "https://github.com/storytold/craft-libs", rev = "80a8ecfe0" }
photocraft-compose = { path = "crates/compose" }
photocraft-gpu = { path = "crates/gpu" }
photocraft-paint = { path = "crates/paint" }
@@ -40,27 +40,27 @@ photocraft-tablet = { path = "crates/tablet" }
photocraft-ipp = { path = "crates/ipp" }
# external
craft-print = { git = "https://github.com/storytold/craft-libs", rev = "7cef561ce" }
craft-print = { git = "https://github.com/storytold/craft-libs", rev = "80a8ecfe0" }
# HEIC/HEIF: the shared decoder (replaces crates/heif; craft-libs#784).
craft-heif = { git = "https://github.com/storytold/craft-libs", rev = "7cef561ce" }
craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "7cef561ce", features = ["raster", "write-raster"] }
craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "7cef561ce" }
craft-jpeg = { git = "https://github.com/storytold/craft-libs", rev = "7cef561ce" }
craft-pcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "7cef561ce" }
craft-pcraft-bundle = { git = "https://github.com/storytold/craft-libs", rev = "7cef561ce" }
craft-ora = { git = "https://github.com/storytold/craft-libs", rev = "7cef561ce" }
craft-kra = { git = "https://github.com/storytold/craft-libs", rev = "7cef561ce" }
craft-xcf = { git = "https://github.com/storytold/craft-libs", rev = "7cef561ce" }
craft-pdn = { git = "https://github.com/storytold/craft-libs", rev = "7cef561ce" }
craft-svg = { git = "https://github.com/storytold/craft-libs", rev = "7cef561ce", features = ["tree-render", "tree-render-system-fonts"] }
craft-raw = { git = "https://github.com/storytold/craft-libs", rev = "7cef561ce" }
craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "7cef561ce" }
craft-heif = { git = "https://github.com/storytold/craft-libs", rev = "80a8ecfe0" }
craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "80a8ecfe0", features = ["raster", "write-raster"] }
craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "80a8ecfe0" }
craft-jpeg = { git = "https://github.com/storytold/craft-libs", rev = "80a8ecfe0" }
craft-pcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "80a8ecfe0" }
craft-pcraft-bundle = { git = "https://github.com/storytold/craft-libs", rev = "80a8ecfe0" }
craft-ora = { git = "https://github.com/storytold/craft-libs", rev = "80a8ecfe0" }
craft-kra = { git = "https://github.com/storytold/craft-libs", rev = "80a8ecfe0" }
craft-xcf = { git = "https://github.com/storytold/craft-libs", rev = "80a8ecfe0" }
craft-pdn = { git = "https://github.com/storytold/craft-libs", rev = "80a8ecfe0" }
craft-svg = { git = "https://github.com/storytold/craft-libs", rev = "80a8ecfe0", features = ["tree-render", "tree-render-system-fonts"] }
craft-raw = { git = "https://github.com/storytold/craft-libs", rev = "80a8ecfe0" }
craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "80a8ecfe0" }
# Interface translations: lookup, fallback, CLDR plurals and language names over the craft-i18n
# catalogs that `crates/ui-egui/build.rs` embeds from `CRAFT_I18N_DIR` (storytold/craft-i18n, at
# the commit in `craft-i18n.rev`). Already in the tree through craft-ui.
craft-i18n = { git = "https://github.com/storytold/craft-libs", rev = "7cef561ce" }
craft-i18n = { git = "https://github.com/storytold/craft-libs", rev = "80a8ecfe0" }
# 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 = "7cef561ce", features = ["egui"] }
craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "80a8ecfe0", features = ["egui"] }
thiserror = "2"
serde = { version = "1", features = ["derive", "rc"] }
serde_json = "1"
@@ -220,7 +220,7 @@ egui_demo_lib = { git = "https://github.com/storytold/egui.git", rev = "6d518fc7
egui_inspection = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
winit = { git = "https://github.com/storytold/winit.git", rev = "a517b3846ee8457d84ee4975110bfda6797c44dc" }
# craft-pdf's vendored Hayro trees: consumers patch the same craft-libs revision (crates/pdf README).
hayro = { git = "https://github.com/storytold/craft-libs", rev = "7cef561ce" }
hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "7cef561ce" }
hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "7cef561ce" }
hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "7cef561ce" }
hayro = { git = "https://github.com/storytold/craft-libs", rev = "80a8ecfe0" }
hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "80a8ecfe0" }
hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "80a8ecfe0" }
hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "80a8ecfe0" }
+17 -14
View File
@@ -13,22 +13,24 @@ mod text;
/// Neutral page records and PDF syntax are owned by craft-pdf; this module only maps the
/// PhotoCraft document to those records and supplies its product-level cancellation policy.
pub use craft_pdf::write_raster::{Image as PrintImage, Marks, Page as PrintPage, SelectionFont, SpotPlate};
pub use craft_pdf::write_raster::{ContentOp, Image as PrintImage, Marks, Page as PrintPage, SelectionFont, SpotPlate, VectorContent};
/// A one-page PDF.
pub fn print_pdf(page: &PrintPage) -> Vec<u8> {
craft_pdf::write_raster::write_pages(std::slice::from_ref(page), &[String::new()], &SelectionFont::default(), None)
craft_pdf::write_raster::write_pages_with_vector_content(std::slice::from_ref(page), &[VectorContent::default()], &SelectionFont::default(), None)
.unwrap_or_default()
}
fn print_pdf_pages(
pages: &[PrintPage],
vectors: &[String],
vectors: &[VectorContent],
selection_font: &SelectionFont,
xmp: Option<&str>,
ctl: &photocraft_raster::Interrupt,
) -> std::result::Result<Vec<u8>, IoError> {
ctl.check().map_err(|_| IoError::Cancelled)?;
Ok(craft_pdf::write_raster::write_pages(pages, vectors, selection_font, xmp))
craft_pdf::write_raster::write_pages_with_vector_content(pages, vectors, selection_font, xmp)
.ok_or_else(|| IoError::Unsupported("PDF vector content contains an invalid number".into()))
}
/// The namespace of the spot-plate description written by the shared PDF metadata encoder.
@@ -80,9 +82,9 @@ fn plates_of(doc: &Document, rect: photocraft_geom::Rect) -> Vec<SpotPlate> {
/// indices of the layers they replace, and the selection font covering their text (plus, when a
/// lower candidate is rejected during emission, that layer's unused characters).
/// Hidden and blocked layers contribute no characters, so they cannot exhaust the font's codes.
fn collect_vectors(doc: &Document) -> (Vec<(usize, String)>, SelectionFont) {
fn collect_vectors(doc: &Document) -> (Vec<(usize, Vec<ContentOp>)>, SelectionFont) {
enum Candidate<'a> {
Ops(String),
Ops(Vec<ContentOp>),
Text(text::PreparedText<'a>),
}
let mut candidates = Vec::new();
@@ -107,8 +109,8 @@ fn collect_vectors(doc: &Document) -> (Vec<(usize, String)>, SelectionFont) {
break;
}
let candidate = match &layer.content {
photocraft_doc::LayerContent::Shape(shape) => match shapes::shape_path(shape, doc.mode) {
Some(ops) => Candidate::Ops(ops),
photocraft_doc::LayerContent::Shape(shape) => match shapes::shape_content(shape, doc.mode) {
Some(path) => Candidate::Ops(vec![ContentOp::Path(path)]),
None => break,
},
photocraft_doc::LayerContent::Text(text_layer) => {
@@ -274,7 +276,7 @@ pub fn export_with(doc: &Document, spot_plates: bool, doc_xmp: Option<&str>, ctl
return Err(IoError::Unsupported("PDF: the document's artboards have no area".into()));
}
warnings.push(format!("PDF exported {} artboards as {} pages; vector/text layers on artboards are rasterised", artboards.len(), pages.len()));
let vectors = vec![String::new(); pages.len()];
let vectors = vec![VectorContent::default(); pages.len()];
(pages, vectors, SelectionFont::default())
} else {
let canvas = photocraft_geom::Rect::new(0, 0, w as i32, h as i32);
@@ -295,17 +297,18 @@ pub fn export_with(doc: &Document, spot_plates: bool, doc_xmp: Option<&str>, ctl
});
// The vector layers, bottom to top, in the document's pixel space (y down), over the
// image and under the plates.
let mut vectors = String::new();
let mut operations = Vec::new();
if !vector_layers.is_empty() {
let scale = 72.0 / dpi;
let ph = f64::from(doc.size.height) * scale;
vectors.push_str(&format!("q {scale} 0 0 -{scale} 0 {ph} cm\n"));
operations.push(ContentOp::Save);
operations.push(ContentOp::Concat([scale, 0.0, 0.0, -scale, 0.0, ph]));
for (_, ops) in vector_layers.iter().rev() {
vectors.push_str(ops);
operations.extend(ops.iter().cloned());
}
vectors.push_str("Q\n");
operations.push(ContentOp::Restore);
}
(vec![page_of(image, canvas, None)], vec![vectors], selection_font)
(vec![page_of(image, canvas, None)], vec![VectorContent { operations }], selection_font)
};
// The plates are the document's: every page has the same ones, over its own region.
let plates = pages.first().map(|p| p.plates.as_slice()).unwrap_or_default();
-111
View File
@@ -1,111 +0,0 @@
//! An embedded, empty Type 3 font for the selection plane. Visible glyphs remain paths.
//! No source font programs are copied into this font; each code has a Unicode mapping.
use std::collections::BTreeSet;
use std::fmt::Write as _;
#[derive(Default)]
pub(super) struct SelectionFont {
chars: BTreeSet<char>,
}
impl SelectionFont {
/// Collect distinct characters until the one-byte code space is exceeded. Stopping there,
/// rather than after a fixed number of characters scanned, keeps a long run of repeated
/// text from hiding later distinct characters.
pub(super) fn new<'a>(texts: impl Iterator<Item = &'a str>) -> Self {
let mut chars = BTreeSet::new();
'texts: for text in texts {
for ch in text.chars() {
chars.insert(ch);
if chars.len() > 255 {
break 'texts;
}
}
}
Self { chars }
}
pub(super) fn encode(&self, text: &str) -> Option<String> {
if self.chars.len() > 255 {
return None;
}
let mut encoded = String::new();
for ch in text.chars() {
let code = self.chars.iter().position(|c| *c == ch)?.checked_add(1)?;
write!(encoded, "{code:02X}").ok()?;
}
Some(encoded)
}
// Object numbers are assigned by the caller, after the optional ICC object.
pub(super) fn objects(&self, base: usize) -> Vec<Vec<u8>> {
let count = self.chars.len().min(255);
let mut differences = String::new();
let mut procs = String::new();
let mut cmap = String::from(
"/CIDInit /ProcSet findresource begin\n12 dict begin\nbegincmap\n/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def\n/CMapName /PhotoCraftUnicode def\n/CMapType 2 def\n1 begincodespacerange\n<00> <FF>\nendcodespacerange\n",
);
// PDF permits at most 100 entries in each bfchar block.
let chars: Vec<_> = self.chars.iter().take(count).collect();
for (block, chunk) in chars.chunks(100).enumerate() {
let _ = writeln!(cmap, "{} beginbfchar", chunk.len());
for (i, ch) in chunk.iter().enumerate() {
let code = block * 100 + i + 1;
let mut buf = [0; 2];
let unicode = ch.encode_utf16(&mut buf).iter().map(|u| format!("{u:04X}")).collect::<String>();
let _ = writeln!(cmap, "<{code:02X}> <{unicode}>");
}
cmap.push_str("endbfchar\n");
}
cmap.push_str("endcmap\nCMapName currentdict /CMap defineresource pop\nend\nend\n");
for code in 1..=count {
let _ = write!(differences, " /c{code}");
let _ = write!(procs, " /c{code} {} 0 R", base + 1);
}
let widths = "1000 ".repeat(count.max(1));
let font = format!(
"<< /Type /Font /Subtype /Type3 /Name /FSelect /FontBBox [0 -250 1000 1000] /FontMatrix [0.001 0 0 0.001 0 0] /CharProcs <<{procs} >> /Encoding << /Type /Encoding /Differences [1{differences}] >> /FirstChar 1 /LastChar {} /Widths [{widths}] /Resources << >> /ToUnicode {} 0 R >>",
count.max(1),
base + 2
);
let stream = |data: &str| format!("<< /Length {} >>\nstream\n{data}endstream", data.len()).into_bytes();
vec![font.into_bytes(), stream("1000 0 0 -250 1000 1000 d1\n"), stream(&cmap)]
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn distinct_characters_after_a_long_repeated_run_still_encode() {
let mut text = "a".repeat(70_000);
text.push('Ω');
let font = SelectionFont::new(std::iter::once(text.as_str()));
assert!(font.encode("aΩ").is_some(), "the distinct tail character must survive the repetition");
}
#[test]
fn the_one_byte_code_space_fits_exactly_255_distinct_characters() {
let fits: String = (0x100u32..0x1FF).filter_map(char::from_u32).collect();
assert_eq!(fits.chars().count(), 255);
let font = SelectionFont::new(std::iter::once(fits.as_str()));
assert!(font.encode(&fits).is_some(), "255 distinct characters fit one-byte codes");
let too_many: String = (0x100u32..0x200).filter_map(char::from_u32).collect();
assert_eq!(too_many.chars().count(), 256);
let font = SelectionFont::new(std::iter::once(too_many.as_str()));
assert!(font.encode("Ā").is_none(), "256 distinct characters exceed the code space");
}
#[test]
fn to_unicode_maps_codes_beyond_the_first_bfchar_block() {
let text: String = (0x100u32..0x196).filter_map(char::from_u32).collect();
let font = SelectionFont::new(std::iter::once(text.as_str()));
let objects = font.objects(0);
let cmap = String::from_utf8_lossy(&objects[2]);
assert!(cmap.contains("100 beginbfchar"));
assert!(cmap.contains("50 beginbfchar"));
assert!(cmap.contains("<65> <0164>"));
}
}
+41 -38
View File
@@ -1,13 +1,11 @@
//! Faithful vector subset for PDF shape export; unsupported shapes use raster fallback.
use std::fmt::Write as _;
use craft_pdf::write_raster::{ContentFillRule, ContentPath, ContentStroke, DeviceColor, PathElement};
use photocraft_color::ColorMode;
use photocraft_doc::{Fill, FillRule, LineCap, LineJoin, PathOp, ShapeLayer, StrokeAlign};
/// Return a PDF path and fill operator for a directly representable shape.
/// Coordinates remain in document pixels with y increasing down; the caller applies transforms.
pub(super) fn shape_path(layer: &ShapeLayer, mode: ColorMode) -> Option<String> {
/// Convert a directly representable PhotoCraft shape to neutral vector geometry.
pub(super) fn shape_content(layer: &ShapeLayer, mode: ColorMode) -> Option<ContentPath> {
if layer.has_soft_mask() || layer.path.inverted || layer.path.subpaths.len() != 1 {
return None;
}
@@ -20,7 +18,7 @@ pub(super) fn shape_path(layer: &ShapeLayer, mode: ColorMode) -> Option<String>
ColorMode::Cmyk => 4,
_ => return None,
};
let mut out = String::new();
let mut fill_color = None;
if let Some(fill) = &layer.fill {
let Fill::Solid(color) = fill else { return None };
if color.mode != mode || !color.alpha.is_finite() || color.alpha != 1.0 || color.c[..channels].iter().any(|v| !v.is_finite()) {
@@ -30,15 +28,10 @@ pub(super) fn shape_path(layer: &ShapeLayer, mode: ColorMode) -> Option<String>
if !(0.0..=1.0).contains(value) {
return None;
}
write!(out, "{value} ").ok()?;
}
out.push_str(match mode {
ColorMode::Rgb => "rg\n",
ColorMode::Grayscale => "g\n",
ColorMode::Cmyk => "k\n",
_ => return None,
});
fill_color = Some((device_color(color.c, mode)?, content_fill_rule(layer.path.fill_rule)));
}
let mut stroke_command = None;
if let Some(stroke) = &layer.stroke {
if stroke.align != StrokeAlign::Center || stroke.opacity != 1.0 || stroke.validate().is_err() || stroke.width <= 0.0 {
return None;
@@ -51,14 +44,7 @@ pub(super) fn shape_path(layer: &ShapeLayer, mode: ColorMode) -> Option<String>
if !value.is_finite() || !(0.0..=1.0).contains(value) {
return None;
}
write!(out, "{value} ").ok()?;
}
out.push_str(match mode {
ColorMode::Rgb => "RG\n",
ColorMode::Grayscale => "G\n",
ColorMode::Cmyk => "K\n",
_ => return None,
});
let cap = match stroke.cap {
LineCap::Butt => 0,
LineCap::Round => 1,
@@ -69,12 +55,15 @@ pub(super) fn shape_path(layer: &ShapeLayer, mode: ColorMode) -> Option<String>
LineJoin::Round => 1,
LineJoin::Bevel => 2,
};
writeln!(out, "{} w {cap} J {join} j {} M", stroke.width, stroke.miter_limit).ok()?;
out.push('[');
for dash in &stroke.dashes {
write!(out, "{} ", dash * stroke.width).ok()?;
}
writeln!(out, "] {} d", stroke.dash_offset * stroke.width).ok()?;
stroke_command = Some(ContentStroke {
color: device_color(stroke_color.c, mode)?,
width: f64::from(stroke.width),
cap,
join,
miter_limit: f64::from(stroke.miter_limit),
dashes: stroke.dashes.iter().map(|dash| f64::from(dash * stroke.width)).collect(),
dash_offset: f64::from(stroke.dash_offset * stroke.width),
});
}
let subpath = layer.path.subpaths.first()?;
if !subpath.closed || subpath.knots.len() < 2 || subpath.op != PathOp::Combine {
@@ -84,23 +73,37 @@ pub(super) fn shape_path(layer: &ShapeLayer, mode: ColorMode) -> Option<String>
if !point_finite(first.anchor) {
return None;
}
writeln!(out, "{} {} m", first.anchor.x, first.anchor.y).ok()?;
let mut elements = vec![PathElement::MoveTo([first.anchor.x, first.anchor.y])];
for segment in subpath.segments() {
if segment.iter().any(|p| !point_finite(*p)) {
return None;
}
writeln!(out, "{} {} {} {} {} {} c", segment[1].x, segment[1].y, segment[2].x, segment[2].y, segment[3].x, segment[3].y).ok()?;
elements.push(PathElement::CubicTo([segment[1].x, segment[1].y], [segment[2].x, segment[2].y], [segment[3].x, segment[3].y]));
}
out.push_str("h\n");
out.push_str(match (layer.fill.is_some(), layer.stroke.is_some(), layer.path.fill_rule) {
(true, false, FillRule::NonZero) => "f\n",
(true, false, FillRule::EvenOdd) => "f*\n",
(false, true, _) => "S\n",
(true, true, FillRule::NonZero) => "B\n",
(true, true, FillRule::EvenOdd) => "B*\n",
(false, false, _) => return None,
});
Some(out)
elements.push(PathElement::Close);
Some(ContentPath { elements, fill: fill_color, stroke: stroke_command })
}
fn device_color(values: [f32; 4], mode: ColorMode) -> Option<DeviceColor> {
Some(match mode {
ColorMode::Grayscale => DeviceColor::Gray(f64::from(values[0])),
ColorMode::Rgb => DeviceColor::Rgb([f64::from(values[0]), f64::from(values[1]), f64::from(values[2])]),
ColorMode::Cmyk => DeviceColor::Cmyk([f64::from(values[0]), f64::from(values[1]), f64::from(values[2]), f64::from(values[3])]),
_ => return None,
})
}
fn content_fill_rule(rule: FillRule) -> ContentFillRule {
match rule {
FillRule::NonZero => ContentFillRule::NonZero,
FillRule::EvenOdd => ContentFillRule::EvenOdd,
}
}
#[cfg(test)]
fn shape_path(layer: &ShapeLayer, mode: ColorMode) -> Option<String> {
let path = shape_content(layer, mode)?;
craft_pdf::write_raster::encode_vector_content(&craft_pdf::write_raster::VectorContent { operations: vec![craft_pdf::write_raster::ContentOp::Path(path)] })
}
fn point_finite(p: photocraft_geom::Point) -> bool {
+53 -77
View File
@@ -1,39 +1,10 @@
//! Faithful vector and selectable text export for PDF.
use std::fmt::Write as _;
use craft_pdf::write_raster::{ContentFillRule, ContentOp, ContentPath, DeviceColor, PathElement};
use photocraft_color::ColorMode;
use photocraft_doc::TextLayer;
fn actual_text_hex(text: &str) -> String {
let mut hex = String::from("FEFF");
for code in text.encode_utf16() {
let _ = write!(hex, "{code:04X}");
}
hex
}
fn write_fill_color(out: &mut String, color: &photocraft_color::Color, mode: ColorMode, channels: usize) -> Option<()> {
for value in color.c.iter().take(channels) {
if !value.is_finite() || !(0.0..=1.0).contains(value) {
return None;
}
write!(out, "{value} ").ok()?;
}
writeln!(
out,
"{}",
match mode {
ColorMode::Rgb => "rg",
ColorMode::Grayscale => "g",
ColorMode::Cmyk => "k",
_ => return None,
}
)
.ok()?;
Some(())
}
/// Whether any glyph is thickened by faux bold or by a face lacking the weight: rendering
/// emboldens those glyphs, but [`photocraft_text::render::glyph_outlines`] gives the regular outline.
fn synthetic_bold(layout: &photocraft_text::TextLayout) -> bool {
@@ -60,7 +31,8 @@ fn straight_horizontal(layer: &TextLayer, dpi: f32) -> bool {
fn text_ops(layer: &TextLayer, mode: ColorMode, dpi: f32) -> Option<String> {
let prepared = prepare(layer, mode, dpi)?;
let font = super::SelectionFont::new(std::iter::once(layer.text.as_str()));
ops(&prepared, mode, &font)
let commands = ops(&prepared, mode, &font)?;
craft_pdf::write_raster::encode_vector_content(&craft_pdf::write_raster::VectorContent { operations: commands })
}
fn channels(mode: ColorMode) -> Option<usize> {
@@ -72,6 +44,15 @@ fn channels(mode: ColorMode) -> Option<usize> {
}
}
fn device_color(color: &photocraft_color::Color, mode: ColorMode) -> Option<DeviceColor> {
Some(match mode {
ColorMode::Grayscale => DeviceColor::Gray(f64::from(color.c[0])),
ColorMode::Rgb => DeviceColor::Rgb([f64::from(color.c[0]), f64::from(color.c[1]), f64::from(color.c[2])]),
ColorMode::Cmyk => DeviceColor::Cmyk([f64::from(color.c[0]), f64::from(color.c[1]), f64::from(color.c[2]), f64::from(color.c[3])]),
_ => return None,
})
}
fn outlines_permitted(bytes: &[u8], index: u32) -> bool {
let Ok(face) = ttf_parser::Face::parse(bytes, index) else { return false };
matches!(face.permissions(), Some(ttf_parser::Permissions::Installable | ttf_parser::Permissions::PreviewAndPrint | ttf_parser::Permissions::Editable))
@@ -146,16 +127,17 @@ fn layout_checks(layer: &TextLayer, mode: ColorMode, layout: &photocraft_text::T
true
}
pub(super) fn ops(prepared: &PreparedText<'_>, mode: ColorMode, selection_font: &super::SelectionFont) -> Option<String> {
let channels = channels(mode)?;
layout_ops(prepared.layer, mode, channels, &prepared.layout, selection_font)
pub(super) fn ops(prepared: &PreparedText<'_>, mode: ColorMode, selection_font: &super::SelectionFont) -> Option<Vec<ContentOp>> {
channels(mode)?;
layout_ops(prepared.layer, mode, &prepared.layout, selection_font)
}
/// Write one glyph outline as PDF path operators, refusing any coordinate or derived Bézier
/// control that is not finite. A quadratic's cubic controls come from finite differences, which
/// can overflow even when the endpoints are finite.
fn write_path_elements(out: &mut String, elements: &[photocraft_text::render::PathEl]) -> Option<()> {
fn path_elements(elements: &[photocraft_text::render::PathEl]) -> Option<Vec<PathElement>> {
let mut cur = [0.0f64, 0.0f64];
let mut out = Vec::with_capacity(elements.len());
for el in elements {
match *el {
photocraft_text::render::PathEl::MoveTo([x, y]) => {
@@ -163,14 +145,14 @@ fn write_path_elements(out: &mut String, elements: &[photocraft_text::render::Pa
return None;
}
cur = [x, y];
writeln!(out, "{x} {y} m").ok()?;
out.push(PathElement::MoveTo([x, y]));
}
photocraft_text::render::PathEl::LineTo([x, y]) => {
if !x.is_finite() || !y.is_finite() {
return None;
}
cur = [x, y];
writeln!(out, "{x} {y} l").ok()?;
out.push(PathElement::LineTo([x, y]));
}
photocraft_text::render::PathEl::QuadTo([cx, cy], [x, y]) => {
if !cx.is_finite() || !cy.is_finite() || !x.is_finite() || !y.is_finite() {
@@ -184,58 +166,50 @@ fn write_path_elements(out: &mut String, elements: &[photocraft_text::render::Pa
return None;
}
cur = [x, y];
writeln!(out, "{c1x} {c1y} {c2x} {c2y} {x} {y} c").ok()?;
out.push(PathElement::CubicTo([c1x, c1y], [c2x, c2y], [x, y]));
}
photocraft_text::render::PathEl::CurveTo([c1x, c1y], [c2x, c2y], [x, y]) => {
if !c1x.is_finite() || !c1y.is_finite() || !c2x.is_finite() || !c2y.is_finite() || !x.is_finite() || !y.is_finite() {
return None;
}
cur = [x, y];
writeln!(out, "{c1x} {c1y} {c2x} {c2y} {x} {y} c").ok()?;
out.push(PathElement::CubicTo([c1x, c1y], [c2x, c2y], [x, y]));
}
photocraft_text::render::PathEl::Close => {
writeln!(out, "h").ok()?;
out.push(PathElement::Close);
}
}
}
Some(out)
}
#[cfg(test)]
fn write_path_elements(out: &mut String, elements: &[photocraft_text::render::PathEl]) -> Option<()> {
let commands = path_elements(elements)?;
let path = ContentPath { elements: commands, ..ContentPath::default() };
let encoded = craft_pdf::write_raster::encode_vector_content(&craft_pdf::write_raster::VectorContent { operations: vec![ContentOp::Path(path)] })?;
out.push_str(&encoded);
Some(())
}
fn layout_ops(
layer: &TextLayer,
mode: ColorMode,
channels: usize,
layout: &photocraft_text::TextLayout,
selection_font: &super::SelectionFont,
) -> Option<String> {
fn layout_ops(layer: &TextLayer, mode: ColorMode, layout: &photocraft_text::TextLayout, selection_font: &super::SelectionFont) -> Option<Vec<ContentOp>> {
if !layout_checks(layer, mode, layout) {
return None;
}
let outlines = photocraft_text::render::glyph_outlines(layout, &layer.transform, None);
let mut out = String::new();
let mut current_color: Option<photocraft_color::Color> = None;
let mut out = Vec::new();
for glyph in &outlines {
let style = layout.styles.get(glyph.style as usize)?;
let color = style.color.in_mode(mode);
if current_color.as_ref() != Some(&color) {
write_fill_color(&mut out, &color, mode, channels)?;
current_color = Some(color);
}
write_path_elements(&mut out, &glyph.elements)?;
writeln!(out, "f*").ok()?;
let fill = device_color(&color, mode)?;
out.push(ContentOp::Path(ContentPath { elements: path_elements(&glyph.elements)?, fill: Some((fill, ContentFillRule::EvenOdd)), stroke: None }));
}
for d in &layout.decorations {
let style = layout.styles.get(d.style as usize)?;
let color = style.color.in_mode(mode);
if current_color.as_ref() != Some(&color) {
write_fill_color(&mut out, &color, mode, channels)?;
current_color = Some(color);
}
let p0 = layer.transform.apply(photocraft_geom::Point::new(f64::from(d.x0), f64::from(d.y0)));
let p1 = layer.transform.apply(photocraft_geom::Point::new(f64::from(d.x1), f64::from(d.y0)));
let p2 = layer.transform.apply(photocraft_geom::Point::new(f64::from(d.x1), f64::from(d.y1)));
@@ -251,12 +225,17 @@ fn layout_ops(
{
return None;
}
writeln!(out, "{} {} m", p0.x, p0.y).ok()?;
writeln!(out, "{} {} l", p1.x, p1.y).ok()?;
writeln!(out, "{} {} l", p2.x, p2.y).ok()?;
writeln!(out, "{} {} l", p3.x, p3.y).ok()?;
writeln!(out, "h").ok()?;
writeln!(out, "f").ok()?;
out.push(ContentOp::Path(ContentPath {
elements: vec![
PathElement::MoveTo([p0.x, p0.y]),
PathElement::LineTo([p1.x, p1.y]),
PathElement::LineTo([p2.x, p2.y]),
PathElement::LineTo([p3.x, p3.y]),
PathElement::Close,
],
fill: Some((device_color(&color, mode)?, ContentFillRule::NonZero)),
stroke: None,
}));
}
selection_ops(&mut out, layer, layout, selection_font)?;
@@ -267,7 +246,7 @@ fn layout_ops(
/// cluster, so paragraph breaks and other whitespace omitted by shaping survive
/// in the selection; the first span also takes leading characters. Without this a multi-line
/// layer extracts as one run of text.
fn selection_ops(out: &mut String, layer: &TextLayer, layout: &photocraft_text::TextLayout, selection_font: &super::SelectionFont) -> Option<()> {
fn selection_ops(out: &mut Vec<ContentOp>, layer: &TextLayer, layout: &photocraft_text::TextLayout, selection_font: &super::SelectionFont) -> Option<()> {
let [a, b, c, d, _, _] = layer.transform.m;
let mut current_line = None;
let mut clusters: Vec<_> = layout.clusters.iter().collect();
@@ -293,9 +272,9 @@ fn selection_ops(out: &mut String, layer: &TextLayer, layout: &photocraft_text::
let line = layout.lines.get(cluster.line)?;
if current_line != Some(cluster.line) {
if current_line.is_some() {
writeln!(out, "ET").ok()?;
out.push(ContentOp::EndSelectionLine);
}
writeln!(out, "BT\n3 Tr\n/FSelect 1 Tf").ok()?;
out.push(ContentOp::BeginSelectionLine);
current_line = Some(cluster.line);
}
let height = (line.ascent + line.descent).max(1.0);
@@ -312,15 +291,12 @@ fn selection_ops(out: &mut String, layer: &TextLayer, layout: &photocraft_text::
if !ta.is_finite() || !tb.is_finite() || !tc.is_finite() || !td.is_finite() {
return None;
}
let hex = actual_text_hex(span);
let encoded = selection_font.encode(span)?;
writeln!(out, "/Span << /ActualText <{hex}> >> BDC").ok()?;
writeln!(out, "{ta} {tb} {tc} {td} {} {} Tm", origin.x, origin.y).ok()?;
writeln!(out, "<{encoded}> Tj\nEMC").ok()?;
out.push(ContentOp::SelectionText { actual_text: span.to_owned(), encoded, matrix: [ta, tb, tc, td, origin.x, origin.y] });
}
if current_line.is_some() {
writeln!(out, "ET").ok()?;
out.push(ContentOp::EndSelectionLine);
}
Some(())
}
@@ -348,7 +324,7 @@ mod tests {
face.font.index = 0;
}
let font = super::super::SelectionFont::new(std::iter::once(layer.text.as_str()));
assert!(layout_ops(&layer, ColorMode::Rgb, 3, &layout, &font).is_none(), "restricted text must remain raster");
assert!(layout_ops(&layer, ColorMode::Rgb, &layout, &font).is_none(), "restricted text must remain raster");
}
assert!(!outlines_permitted(&[], 0));
}
@@ -464,7 +440,7 @@ mod tests {
let origin = layer.transform.apply(photocraft_geom::Point::new(f64::from(cluster.x), f64::from(line.baseline)));
assert!(origin.x.is_finite() && origin.y.is_finite(), "the fixture's origin stays finite");
let font = super::super::SelectionFont::new(std::iter::once(layer.text.as_str()));
assert!(layout_ops(&layer, ColorMode::Rgb, 3, &layout, &font).is_none(), "overflowing Tm coefficients must not be emitted");
assert!(layout_ops(&layer, ColorMode::Rgb, &layout, &font).is_none(), "overflowing Tm coefficients must not be emitted");
assert!(text_ops(&layer, ColorMode::Rgb, 72.0).is_none());
}
}