Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

build(pdf): deduplicate fontations via subsetter patch

ldm01c25ae86ba66
diff --git a/Cargo.lock b/Cargo.lock
index e8920c62a..41ce3a7d2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1428,15 +1428,6 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
-[[package]]
-name = "font-types"
-version = "0.11.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5b38ad915f6dadd993ced50848a8291a543bd41ca62bc10740d5e64e2ab4cfd7"
-dependencies = [
- "bytemuck",
-]
-
[[package]]
name = "font-types"
version = "0.12.1"
@@ -1487,7 +1478,7 @@ dependencies = [
"objc2-core-text",
"objc2-foundation",
"parlance",
- "read-fonts 0.41.0",
+ "read-fonts",
"roxmltree 0.21.1",
"smallvec",
"windows",
@@ -1672,7 +1663,7 @@ dependencies = [
"log",
"peniko",
"png",
- "skrifa 0.44.0",
+ "skrifa",
"smallvec",
"vello_common",
]
@@ -1739,7 +1730,7 @@ checksum = "c03d949a14aa089bbb282f7dd76a498a7f684428e4257202efc119ec010376f9"
dependencies = [
"bitflags",
"bytemuck",
- "read-fonts 0.41.0",
+ "read-fonts",
"smallvec",
]
@@ -2290,7 +2281,7 @@ dependencies = [
"png",
"rustc-hash 2.1.1",
"siphasher",
- "skrifa 0.44.0",
+ "skrifa",
"smallvec",
"subsetter",
"tiny-skia-path",
@@ -2988,7 +2979,7 @@ dependencies = [
"moli-image",
"moli-system-fonts",
"parley",
- "read-fonts 0.41.0",
+ "read-fonts",
"stylo",
"stylo_taffy",
"taffy",
@@ -3100,7 +3091,7 @@ dependencies = [
"moli-image",
"moli-layout",
"peniko",
- "skrifa 0.44.0",
+ "skrifa",
]
[[package]]
@@ -4236,7 +4227,7 @@ dependencies = [
"parlance",
"parley_data",
"parley_emoji",
- "skrifa 0.44.0",
+ "skrifa",
]
[[package]]
@@ -4628,16 +4619,6 @@ dependencies = [
"yasna",
]
-[[package]]
-name = "read-fonts"
-version = "0.39.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c4ed38b89c2c77ff968c524145ad65fb010f38af5c7a224b53b81d47ac2daa81"
-dependencies = [
- "bytemuck",
- "font-types 0.11.3",
-]
-
[[package]]
name = "read-fonts"
version = "0.41.0"
@@ -4645,7 +4626,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "046a7d674daf459825b32f5062056d6882db0d2f5a479fbd76ccfc870ac18709"
dependencies = [
"bytemuck",
- "font-types 0.12.1",
+ "font-types",
"once_cell",
]
@@ -5144,16 +5125,6 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2aa850e253778c88a04c3d7323b043aeda9d3e30d5971937c1855769763678e"
-[[package]]
-name = "skrifa"
-version = "0.42.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0c34617370ae968efb7161bb2beb517d9084659aae19e24b89e3db25b46e4564"
-dependencies = [
- "bytemuck",
- "read-fonts 0.39.2",
-]
-
[[package]]
name = "skrifa"
version = "0.44.0"
@@ -5161,7 +5132,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "819ab7d62b1d3e72d9d9dea5650bac30424f9111364bb94928dbf5ecad1baa68"
dependencies = [
"bytemuck",
- "read-fonts 0.41.0",
+ "read-fonts",
]
[[package]]
@@ -5488,12 +5459,11 @@ dependencies = [
[[package]]
name = "subsetter"
version = "0.2.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "38803281d1c23166c5ebcb455439a5d2afe711cc909cf88af72448c297756ad6"
+source = "git+https://github.com/lexmount/subsetter?rev=8d3815245835af309559c3b4a872d6a0a54913a9#8d3815245835af309559c3b4a872d6a0a54913a9"
dependencies = [
"kurbo",
"rustc-hash 2.1.1",
- "skrifa 0.42.1",
+ "skrifa",
"write-fonts",
]
@@ -6153,7 +6123,7 @@ dependencies = [
"roxmltree 0.21.1",
"simplecss",
"siphasher",
- "skrifa 0.44.0",
+ "skrifa",
"strict-num",
"svgtypes",
"tiny-skia-path",
@@ -6705,15 +6675,15 @@ checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5"
[[package]]
name = "write-fonts"
-version = "0.48.1"
+version = "0.50.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cb731d4c4d93eacc69a1ad2f270f905788a98e4a3438267bcafbe08d3431c8d8"
+checksum = "cae90d1d9f6d1d36ef116b0b1e651a6d7c12ba925439d4d06ff9adc94662a3d8"
dependencies = [
- "font-types 0.11.3",
+ "font-types",
"indexmap",
"kurbo",
"log",
- "read-fonts 0.39.2",
+ "read-fonts",
]
[[package]]
diff --git a/Cargo.toml b/Cargo.toml
index 63ec86ac4..94d1d8ead 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -100,6 +100,8 @@ license = "MIT OR Apache-2.0"
[patch.crates-io]
parley = { git = "https://github.com/lexmount/parley", rev = "d0f5452487b872562102fde2c133d445272bcccc" }
fontique = { git = "https://github.com/lexmount/parley", rev = "d0f5452487b872562102fde2c133d445272bcccc" }
+# Share fontations between shaping, raster rendering and PDF font subsetting.
+subsetter = { git = "https://github.com/lexmount/subsetter", rev = "8d3815245835af309559c3b4a872d6a0a54913a9" }
url = { git = "https://github.com/lexmount/rust-url", rev = "ca9fcad2b99f20c30c28a618ad78410f6fd31161" }
xml5ever = { path = "vendor/xml5ever-0.39.0" }
curl = { git = "https://github.com/lexmount/curl-rust", rev = "a0ea59f5ca1b1e4bc8627a28c29463ac96aeb758" }
diff --git a/moli-paint/README.md b/moli-paint/README.md
index b1d9cb868..b559cc4b5 100644
--- a/moli-paint/README.md
+++ b/moli-paint/README.md
@@ -13,10 +13,13 @@ The dependency uses a fixed Git revision with only `raster-images` enabled;
own `pdf-writer` Git pin (`fdf0901`) is recorded in `Cargo.lock`. This revision
requires Rust 1.92; the repository toolchain is 1.96.1. Krilla and the adapter now
share `skrifa` 0.44 with Parley, Vello and usvg. The adapter uses `skrifa::raw`
-instead of declaring a separate `read-fonts` dependency. The `subsetter` 0.2.6
-dependency still brings `skrifa` 0.42, `read-fonts` 0.39 and `font-types` 0.11:
-its upstream `main` also requires those versions, so switching Krilla to Git
-does not remove that older stack. Krilla's `imagesize` 0.14 and `base64` 0.22
+instead of declaring a separate `read-fonts` dependency. Moli's root
+`[patch.crates-io]` also aligns `subsetter` with `skrifa` 0.44 and `write-fonts`
+0.50, so subsetting shares `read-fonts` 0.41 and `font-types` 0.12 with the
+rendering stack. The patch pins our [subsetter dependency update](https://github.com/lexmount/subsetter/commit/8d3815245835af309559c3b4a872d6a0a54913a9)
+and can be removed when upstream publishes compatible fontations dependencies.
+The dependency update preserves the subsetting algorithm, variable fonts and
+CFF2 support. Krilla's `imagesize` 0.14 and `base64` 0.22
also coexist with usvg's 0.15 and 0.23; their version requirements do not overlap.
The PDF adapter embeds and subsets fonts, using Parley's existing glyph positions
@@ -111,13 +114,25 @@ samples differed by at most one 8-bit channel value from the raster screenshot.
The Git revision also passed the real CLI/MuPDF checks and CDP PDF smoke group;
its rendered visual sample was pixel-identical to the crates.io baseline.
-The release measurements below were taken with crates.io Krilla 0.8.2 before
-the Git switch; they have not been remeasured for the pinned revision.
-The repository release profile produced a 158,402,744-byte binary (151.06 MiB,
-not stripped by the profile). Compared with the previous lockfile, the production
-paint dependency closure adds 11 crate versions, plus a bitflags upgrade required
-by the test parser. A same-revision baseline binary was not built, so these
-measurements do not establish the PDF backend's binary-size delta.
+Release sizes measured with Rust 1.96.1 on Linux x86_64, using
+`cargo build -p moli --release --locked` with the repository's unchanged release
+profile and default features. Packaging used `scripts/release.py` with version
+1.1.16, which strips the binary and creates a gzip level-9 archive:
+
+| Revision | Release binary bytes | Stripped binary bytes | Archive bytes |
+| --- | ---: | ---: | ---: |
+| Before native PDF (`d9928760`) | 156,266,960 | 107,667,480 | 43,425,106 |
+| Native PDF, official Krilla Git (`7a52ca98`) | 158,167,208 | 109,363,224 | 44,157,871 |
+| Same Krilla, root `subsetter` patch (`8d38152`) | 157,856,280 | 109,084,696 | 44,031,505 |
+
+The subsetter dependency update removes the duplicate `skrifa`, `read-fonts`
+and `font-types` versions. It saves 272 KiB in the stripped binary and 126,366
+bytes in the archive. The stripped binary's native-PDF increase relative to
+`d9928760` is now 1.35 MiB (1.32%), down from 1.62 MiB. The four CLI reader
+samples below (82 pages total) produced byte-identical PDFs before and after
+the dependency update; their extracted text and rendered pixels also matched.
+The updated subsetter passed all 174 tests, and 14 static, variable, CFF and
+CFF2 font-subset comparisons were byte-identical to the registry version.
One observed release CLI run with local data URLs and fixed fonts: