From af9ad78b71cfacb34ebe7b94833979c3ea9012b2 Mon Sep 17 00:00:00 2001 From: Bogdan Arabadzhi <8407846+barabadzhi@users.noreply.github.com> Date: Fri, 15 Nov 2024 11:51:55 +0100 Subject: [PATCH 1/3] Update svg2pdf Signed-off-by: Bogdan Arabadzhi <8407846+barabadzhi@users.noreply.github.com> --- Cargo.lock | 211 +++++++++++++++++++++-------------------------------- Cargo.toml | 36 ++++++--- src/svg.rs | 43 ++++++----- 3 files changed, 133 insertions(+), 157 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1246b67..94d4335 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -172,7 +172,7 @@ dependencies = [ "azul-css", "azul-css-parser", "azul-layout", - "base64 0.22.1", + "base64", "geo", "geo-booleanop", "gl-context-loader", @@ -182,12 +182,6 @@ dependencies = [ "xmlwriter", ] -[[package]] -name = "base64" -version = "0.21.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" - [[package]] name = "base64" version = "0.22.1" @@ -281,6 +275,15 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" +[[package]] +name = "core_maths" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3b02505ccb8c50b0aa21ace0fc08c3e53adebd4e58caa18a36152803c7709a3" +dependencies = [ + "libm", +] + [[package]] name = "crc32fast" version = "1.4.2" @@ -430,16 +433,16 @@ dependencies = [ [[package]] name = "fontdb" -version = "0.16.2" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0299020c3ef3f60f526a4f64ab4a3d4ce116b1acbf24cdd22da0068e5d81dc3" +checksum = "37be9fc20d966be438cd57a45767f73349477fb0f85ce86e000557f787298afb" dependencies = [ "fontconfig-parser", "log", "memmap2", "slotmap", "tinyvec", - "ttf-parser 0.20.0", + "ttf-parser 0.24.1", ] [[package]] @@ -509,16 +512,6 @@ dependencies = [ "libm", ] -[[package]] -name = "gif" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80792593675e051cf94a4b111980da2ba60d4a83e43e0048c5693baab3977045" -dependencies = [ - "color_quant", - "weezl", -] - [[package]] name = "gif" version = "0.13.1" @@ -581,21 +574,6 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1489f81ead4b71a09ddeab6850c0356c0932587637d753f21ee1010ab875b013" -[[package]] -name = "image" -version = "0.24.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5690139d2f55868e080017335e4b94cb7414274c74f1669c84fb5feba2c9f69d" -dependencies = [ - "bytemuck", - "byteorder", - "color_quant", - "gif 0.13.1", - "jpeg-decoder", - "num-traits", - "png", -] - [[package]] name = "image" version = "0.25.4" @@ -605,8 +583,8 @@ dependencies = [ "bytemuck", "byteorder-lite", "color_quant", - "gif 0.13.1", - "image-webp", + "gif", + "image-webp 0.2.0", "num-traits", "png", "rayon", @@ -615,6 +593,16 @@ dependencies = [ "zune-jpeg", ] +[[package]] +name = "image-webp" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f79afb8cbee2ef20f59ccd477a218c12a93943d075b492015ecb1bb81f8ee904" +dependencies = [ + "byteorder-lite", + "quick-error", +] + [[package]] name = "image-webp" version = "0.2.0" @@ -627,9 +615,9 @@ dependencies = [ [[package]] name = "imagesize" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "029d73f573d8e8d63e6d5020011d3255b28c3ba85d6cf870a07184ed23de9284" +checksum = "edcd27d72f2f071c64249075f42e205ff93c9a4c5f6c6da53e79ed9f9832c285" [[package]] name = "indexmap" @@ -673,11 +661,12 @@ dependencies = [ [[package]] name = "kurbo" -version = "0.9.5" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd85a5776cd9500c2e2059c8c76c3b01528566b7fcbaf8098b55a33fc298849b" +checksum = "89234b2cc610a7dd927ebde6b41dd1a5d4214cffaef4cf1fb2195d592f92518f" dependencies = [ "arrayvec", + "smallvec", ] [[package]] @@ -772,15 +761,6 @@ dependencies = [ "adler", ] -[[package]] -name = "miniz_oxide" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" -dependencies = [ - "adler", -] - [[package]] name = "miniz_oxide" version = "0.8.0" @@ -868,11 +848,11 @@ dependencies = [ [[package]] name = "pdf-writer" -version = "0.9.3" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24e9127455063c816e661caac9ecd9043ad2871f55be93014e6838a8ced2332b" +checksum = "be17f48d7fbbd22c6efedb58af5d409aa578e407f40b29a0bcb4e66ed84c5c98" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.6.0", "itoa", "memchr", "ryu", @@ -923,9 +903,9 @@ dependencies = [ "azul-layout", "azul-text-layout", "azulc", - "base64 0.22.1", + "base64", "flate2", - "image 0.25.4", + "image", "js-sys", "lopdf", "pdf-writer", @@ -1015,19 +995,19 @@ checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" [[package]] name = "resvg" -version = "0.38.0" +version = "0.43.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c34501046959e06470ba62a2dc7f31c15f94ac250d842a45f9e012f4ee40c1e" +checksum = "c7314563c59c7ce31c18e23ad3dd092c37b928a0fa4e1c0a1a6504351ab411d1" dependencies = [ - "gif 0.12.0", - "jpeg-decoder", + "gif", + "image-webp 0.1.3", "log", "pico-args", - "png", "rgb", "svgtypes", "tiny-skia", "usvg", + "zune-jpeg", ] [[package]] @@ -1060,12 +1040,6 @@ dependencies = [ "xmlparser", ] -[[package]] -name = "roxmltree" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cd14fd5e3b777a7422cca79358c57a8f6e3a703d9ac187448d0daf220c2407f" - [[package]] name = "roxmltree" version = "0.20.0" @@ -1089,7 +1063,7 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34f79014d061d4b959d842bc1a09c41f752fff163e25dfdde68552859fed1bd0" dependencies = [ - "base64 0.22.1", + "base64", "mmapio", "xmlparser", ] @@ -1111,14 +1085,16 @@ dependencies = [ [[package]] name = "rustybuzz" -version = "0.12.1" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0ae5692c5beaad6a9e22830deeed7874eae8a4e3ba4076fb48e12c56856222c" +checksum = "c85d1ccd519e61834798eb52c4e886e8c2d7d698dd3d6ce0b1b47eb8557f1181" dependencies = [ "bitflags 2.6.0", "bytemuck", + "core_maths", + "log", "smallvec", - "ttf-parser 0.20.0", + "ttf-parser 0.24.1", "unicode-bidi-mirroring", "unicode-ccc", "unicode-properties", @@ -1192,9 +1168,9 @@ dependencies = [ [[package]] name = "siphasher" -version = "0.3.11" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" +checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" [[package]] name = "slotmap" @@ -1241,26 +1217,37 @@ dependencies = [ "float-cmp", ] +[[package]] +name = "subsetter" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74f98178f34057d4d4de93d68104007c6dea4dfac930204a69ab4622daefa648" + [[package]] name = "svg2pdf" -version = "0.10.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba36b330062be8497fd96597227a757b621b86c4d24d164b06e4522b52b3693e" +checksum = "5014c9dadcf318fb7ef8c16438e95abcc9de1ae24d60d5bccc64c55100c50364" dependencies = [ - "image 0.24.9", - "miniz_oxide 0.7.4", + "fontdb", + "image", + "log", + "miniz_oxide 0.8.0", "once_cell", "pdf-writer", "resvg", + "siphasher", + "subsetter", "tiny-skia", + "ttf-parser 0.24.1", "usvg", ] [[package]] name = "svgtypes" -version = "0.13.0" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e44e288cd960318917cbd540340968b90becc8bc81f171345d706e7a89d9d70" +checksum = "794de53cc48eaabeed0ab6a3404a65f40b3e38c067e4435883a65d2aa4ca000e" dependencies = [ "kurbo", "siphasher", @@ -1378,9 +1365,12 @@ checksum = "7b3e06c9b9d80ed6b745c7159c40b311ad2916abb34a49e9be2653b90db0d8dd" [[package]] name = "ttf-parser" -version = "0.20.0" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17f77d76d837a7830fe1d4f12b7b4ba4192c1888001c7164257e4bc6d21d96b4" +checksum = "5be21190ff5d38e8b4a2d3b6a3ae57f612cc39c96e83cedeaf7abc338a8bac4a" +dependencies = [ + "core_maths", +] [[package]] name = "typenum" @@ -1402,9 +1392,9 @@ checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" [[package]] name = "unicode-bidi-mirroring" -version = "0.1.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56d12260fb92d52f9008be7e4bca09f584780eb2266dc8fecc6a192bec561694" +checksum = "64af057ad7466495ca113126be61838d8af947f41d93a949980b2389a118082f" [[package]] name = "unicode-canonical-combining-class" @@ -1414,9 +1404,9 @@ checksum = "6925586af9268182c711e47c0853ed84131049efaca41776d0ca97f983865c32" [[package]] name = "unicode-ccc" -version = "0.1.2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc2520efa644f8268dce4dcd3050eaa7fc044fca03961e9998ac7e2e92b77cf1" +checksum = "260bc6647b3893a9a90668360803a15f96b85a5257b1c3a0c3daf6ae2496de42" [[package]] name = "unicode-general-category" @@ -1465,62 +1455,29 @@ checksum = "b1d386ff53b415b7fe27b50bb44679e2cc4660272694b7b6f3326d8480823a94" [[package]] name = "usvg" -version = "0.38.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "377f62b4a3c173de8654c1aa80ab1dac1154e6f13a779a9943e53780120d1625" -dependencies = [ - "base64 0.21.7", - "log", - "pico-args", - "usvg-parser", - "usvg-text-layout", - "usvg-tree", - "xmlwriter", -] - -[[package]] -name = "usvg-parser" -version = "0.38.0" +version = "0.43.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "351a05e6f2023d6b4e946f734240a3927aefdcf930d7d42587a2c8a8869814b0" +checksum = "6803057b5cbb426e9fb8ce2216f3a9b4ca1dd2c705ba3cbebc13006e437735fd" dependencies = [ + "base64", "data-url", "flate2", + "fontdb", "imagesize", "kurbo", "log", - "roxmltree 0.19.0", + "pico-args", + "roxmltree 0.20.0", + "rustybuzz", "simplecss", "siphasher", + "strict-num", "svgtypes", - "usvg-tree", -] - -[[package]] -name = "usvg-text-layout" -version = "0.38.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c41888b9d5cf431fe852eaf9d047bbde83251b98f1749c2f08b1071e6db46e2" -dependencies = [ - "fontdb", - "kurbo", - "log", - "rustybuzz", + "tiny-skia-path", "unicode-bidi", "unicode-script", "unicode-vo", - "usvg-tree", -] - -[[package]] -name = "usvg-tree" -version = "0.38.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18863e0404ed153d6e56362c5b1146db9f4f262a3244e3cf2dbe7d8a85909f05" -dependencies = [ - "strict-num", - "svgtypes", - "tiny-skia-path", + "xmlwriter", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 52ab090..70dbad7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,19 +17,33 @@ autoexamples = false edition = "2021" [dependencies] -lopdf = { version = "0.33.0", default-features = false, features = ["pom_parser"] } +lopdf = { version = "0.33.0", default-features = false, features = [ + "pom_parser", +] } time = { version = "0.3.25", default-features = false, features = ["std"] } -allsorts = { version = "0.15", default-features = false, features = ["flate2_rust"] } -pdf-writer = { version = "0.9" } -image = { version = "0.25", default-features = false} -svg2pdf = { version = "0.10" } +allsorts = { version = "0.15", default-features = false, features = [ + "flate2_rust", +] } +pdf-writer = { version = "0.12.0" } +image = { version = "0.25", default-features = false } +svg2pdf = { version = "0.12.0" } # dependencies for wasm demo azul-css = { git = "https://github.com/fschutt/azul", rev = "646b5e3030041aaebe06d2344a36bbed000c8674", default-features = false } -azul-css-parser = { git = "https://github.com/fschutt/azul", rev = "646b5e3030041aaebe06d2344a36bbed000c8674", default-features = false } -azul-core = { git = "https://github.com/fschutt/azul", rev = "646b5e3030041aaebe06d2344a36bbed000c8674", default-features = false, features = ["std"] } -azul-layout = { git = "https://github.com/fschutt/azul", rev = "646b5e3030041aaebe06d2344a36bbed000c8674", default-features = false, features = ["std", "text_layout"] } -azul-text-layout = { git = "https://github.com/fschutt/azul", rev = "646b5e3030041aaebe06d2344a36bbed000c8674", default-features = false } -azulc = { git = "https://github.com/fschutt/azul", rev = "646b5e3030041aaebe06d2344a36bbed000c8674", default-features = false, features = ["std", "xml", "text_layout", "font_loading"] } +azul-css-parser = { git = "https://github.com/fschutt/azul", rev = "646b5e3030041aaebe06d2344a36bbed000c8674", default-features = false } +azul-core = { git = "https://github.com/fschutt/azul", rev = "646b5e3030041aaebe06d2344a36bbed000c8674", default-features = false, features = [ + "std", +] } +azul-layout = { git = "https://github.com/fschutt/azul", rev = "646b5e3030041aaebe06d2344a36bbed000c8674", default-features = false, features = [ + "std", + "text_layout", +] } +azul-text-layout = { git = "https://github.com/fschutt/azul", rev = "646b5e3030041aaebe06d2344a36bbed000c8674", default-features = false } +azulc = { git = "https://github.com/fschutt/azul", rev = "646b5e3030041aaebe06d2344a36bbed000c8674", default-features = false, features = [ + "std", + "xml", + "text_layout", + "font_loading", +] } rust-fontconfig = { version = "0.1.13", default-features = false } xmlparser = { version = "0.13.6", default-features = false } serde = { version = "1" } @@ -52,7 +66,7 @@ tga = ["image/tga"] hdr = ["image/hdr"] dds = ["image/dds"] webp = ["image/webp"] -rayon = ["image/rayon"] # enables multithreading for decoding images +rayon = ["image/rayon"] # enables multithreading for decoding images js-sys = ["dep:js-sys"] # enables js-sys features on wasm [package.metadata.docs.rs] diff --git a/src/svg.rs b/src/svg.rs index fd5c816..8f74d44 100644 --- a/src/svg.rs +++ b/src/svg.rs @@ -1,7 +1,8 @@ +use std::collections::HashMap; + use crate::units::Px; use crate::xobject::ExternalXObject; -use svg2pdf::usvg; -use svg2pdf::usvg::TreeParsing; +use svg2pdf::{usvg, ConversionOptions}; /// SVG - wrapper around an `XObject` to allow for more /// control within the library. @@ -25,11 +26,11 @@ impl Svg { // I wish there was a more direct way, but handling SVG is very tricky. // Allocate the indirect reference IDs and names. - let catalog_id = Ref::new(1); - let page_tree_id = Ref::new(2); - let page_id = Ref::new(3); - let content_id = Ref::new(4); - let svg_id = Ref::new(5); + let mut alloc = Ref::new(1); + let catalog_id = alloc.bump(); + let page_tree_id = alloc.bump(); + let page_id = alloc.bump(); + let content_id = alloc.bump(); let svg_name = Name(b"S1"); // Start writing a PDF. @@ -43,6 +44,20 @@ impl Svg { page.parent(page_tree_id); page.contents(content_id); + // Let's first convert the SVG into an independent chunk. + let mut options = usvg::Options::default(); + options.fontdb_mut().load_system_fonts(); + let tree = usvg::Tree::from_str(&svg_string, &options) + .map_err(|err| format!("usvg parse: {err}"))?; + let (mut svg_chunk, svg_id) = svg2pdf::to_chunk(&tree, ConversionOptions::default()) + .map_err(|err| format!("convert svg tree to chunk: {err}"))?; + + // Renumber the chunk so that we can embed it into our existing workflow, and also make sure + // to update `svg_id`. + let mut map = HashMap::new(); + svg_chunk = svg_chunk.renumber(|old| *map.entry(old).or_insert_with(|| alloc.bump())); + let svg_id = map.get(&svg_id).unwrap(); + // Add the font and, more importantly, the SVG to the resource dictionary // so that it can be referenced in the content stream. let mut resources = page.resources(); @@ -50,21 +65,11 @@ impl Svg { resources.finish(); page.finish(); - // Let's add an SVG graphic to this file. - // We need to load its source first and manually parse it into a usvg Tree. - let tree = usvg::Tree::from_str(svg_string, &usvg::Options::default()) - .map_err(|err| format!("usvg parse: {err}"))?; - - // Then, we will write it to the page as the 6th indirect object. - // - // This call allocates some indirect object reference IDs for itself. If we - // wanted to write some more indirect objects afterwards, we could use the - // return value as the next unused reference ID. - svg2pdf::convert_tree_into(&tree, svg2pdf::Options::default(), &mut writer, svg_id); - // Write a content stream let content = Content::new(); writer.stream(content_id, &content.finish()); + // Write the SVG chunk into the PDF page. + writer.extend(&svg_chunk); let bytes = writer.finish(); let document = lopdf::Document::load_mem(&bytes) From 6be1a47d7e88811e8d1e75fe4ac1f5cd40cb9238 Mon Sep 17 00:00:00 2001 From: Bogdan Arabadzhi <8407846+barabadzhi@users.noreply.github.com> Date: Fri, 15 Nov 2024 12:32:11 +0100 Subject: [PATCH 2/3] Update lopdf Signed-off-by: Bogdan Arabadzhi <8407846+barabadzhi@users.noreply.github.com> --- Cargo.lock | 591 +++++++++++++++++++++++++++++++++++++++++++---- Cargo.toml | 4 +- src/serialize.rs | 5 +- 3 files changed, 546 insertions(+), 54 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 94d4335..cfcf25a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,12 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +version = 4 [[package]] name = "adler2" @@ -20,6 +14,12 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd" +[[package]] +name = "aligned-vec" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4aa90d7ce82d4be67b64039a3d588d38dbcc6736577de4a847025ce5b0c468d1" + [[package]] name = "alloc-no-stdlib" version = "2.0.4" @@ -49,7 +49,7 @@ dependencies = [ "encoding_rs", "flate2", "glyph-names", - "itertools", + "itertools 0.10.5", "lazy_static", "libc", "log", @@ -64,6 +64,12 @@ dependencies = [ "unicode-joining-type", ] +[[package]] +name = "anyhow" +version = "1.0.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" + [[package]] name = "approx" version = "0.5.1" @@ -73,6 +79,23 @@ dependencies = [ "num-traits", ] +[[package]] +name = "arbitrary" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dde20b3d026af13f561bdd0f15edf01fc734f0dafcedbaf42bba506a9517f223" + +[[package]] +name = "arg_enum_proc_macro" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ae92a5119aa49cdbcf6b9f893fe4e1d98b04ccbf82ee0584ad948a44a734dea" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "arrayref" version = "0.3.9" @@ -100,6 +123,29 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +[[package]] +name = "av1-grain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6678909d8c5d46a42abcf571271e15fdbc0a225e3646cf23762cd415046c78bf" +dependencies = [ + "anyhow", + "arrayvec", + "log", + "nom", + "num-rational", + "v_frame", +] + +[[package]] +name = "avif-serialize" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e335041290c43101ca215eed6f43ec437eb5a42125573f600fc3fa42b9bddd62" +dependencies = [ + "arrayvec", +] + [[package]] name = "azul-core" version = "0.0.2" @@ -209,6 +255,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "bitstream-io" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6099cdc01846bc367c4e7dd630dc5966dccf36b652fae7a74e17b640411a91b2" + [[package]] name = "block-buffer" version = "0.10.4" @@ -230,15 +282,21 @@ dependencies = [ [[package]] name = "bstr" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40723b8fb387abc38f4f4a37c09073622e41dd12327033091ef8950659e6dc0c" +checksum = "1a68f1f47cdf0ec8ee4b941b2eee2a80cb796db73118c0dd09ac63fbe405be22" dependencies = [ "memchr", "regex-automata", "serde", ] +[[package]] +name = "built" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c360505aed52b7ec96a3636c3f039d99103c37d1d9b4f7a8c743d3ea9ffcd03b" + [[package]] name = "bumpalo" version = "3.16.0" @@ -263,6 +321,27 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495" +[[package]] +name = "cc" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd9de9f2205d5ef3fd67e685b0df337994ddd4495e2a28d185500d0e1edfea47" +dependencies = [ + "jobserver", + "libc", + "shlex", +] + +[[package]] +name = "cfg-expr" +version = "0.15.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d067ad48b8650848b989a59a86c6c36a995d02d2bf778d45c3c5d57bc2718f02" +dependencies = [ + "smallvec", + "target-lexicon", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -391,14 +470,12 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b39522e96686d38f4bc984b9198e3a0613264abaebaff2c5c918bfa6b6da09af" +checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c" dependencies = [ - "cfg-if", "crc32fast", - "libc", - "miniz_oxide 0.5.4", + "miniz_oxide", ] [[package]] @@ -512,6 +589,17 @@ dependencies = [ "libm", ] +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gif" version = "0.13.1" @@ -545,9 +633,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.15.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3" [[package]] name = "heapless" @@ -568,6 +656,12 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "highway" version = "0.8.1" @@ -576,9 +670,9 @@ checksum = "1489f81ead4b71a09ddeab6850c0356c0932587637d753f21ee1010ab875b013" [[package]] name = "image" -version = "0.25.4" +version = "0.25.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc144d44a31d753b02ce64093d532f55ff8dc4ebf2ffb8a63c0dda691385acae" +checksum = "cd6f44aed642f18953a158afeb30206f4d50da59fbc66ecb53c66488de73563b" dependencies = [ "bytemuck", "byteorder-lite", @@ -587,6 +681,7 @@ dependencies = [ "image-webp 0.2.0", "num-traits", "png", + "ravif", "rayon", "tiff", "zune-core", @@ -619,6 +714,12 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "edcd27d72f2f071c64249075f42e205ff93c9a4c5f6c6da53e79ed9f9832c285" +[[package]] +name = "imgref" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0263a3d970d5c054ed9312c0057b4f3bde9c0b33836d3637361d4a9e6e7a408" + [[package]] name = "indexmap" version = "2.6.0" @@ -629,6 +730,17 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "interpolate_name" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34819042dc3d3971c46c2190835914dfbe0c3c13f61449b2997f4e9722dfa60" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "itertools" version = "0.10.5" @@ -638,12 +750,30 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "jobserver" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" +dependencies = [ + "libc", +] + [[package]] name = "jpeg-decoder" version = "0.3.1" @@ -677,21 +807,25 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.161" +version = "0.2.162" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" +checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398" [[package]] -name = "libm" -version = "0.2.11" +name = "libfuzzer-sys" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" +checksum = "9b9569d2f74e257076d8c6bfa73fb505b46b851e51ddaecc825944aa3bed17fa" +dependencies = [ + "arbitrary", + "cc", +] [[package]] -name = "linked-hash-map" -version = "0.5.6" +name = "libm" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" +checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" [[package]] name = "lock_api" @@ -709,24 +843,43 @@ version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +[[package]] +name = "loop9" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fae87c125b03c1d2c0150c90365d7d6bcc53fb73a9acaef207d2d065860f062" +dependencies = [ + "imgref", +] + [[package]] name = "lopdf" -version = "0.33.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5c14afa083a906d49e1bda105ddbf8175016e2658954e6d0c3e612f886df3db" +checksum = "c5c8ecfc6c72051981c0459f75ccc585e7ff67c70829560cda8e647882a9abff" dependencies = [ "encoding_rs", "flate2", "indexmap", "itoa", - "linked-hash-map", "log", "md-5", "pom", + "rangemap", "time", "weezl", ] +[[package]] +name = "maybe-rayon" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea1f30cedd69f0a2954655f7188c6a834246d2bcf1e315e2ac40c4b24dc9519" +dependencies = [ + "cfg-if", + "rayon", +] + [[package]] name = "md-5" version = "0.10.6" @@ -753,13 +906,10 @@ dependencies = [ ] [[package]] -name = "miniz_oxide" -version = "0.5.4" +name = "minimal-lexical" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34" -dependencies = [ - "adler", -] +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" @@ -781,12 +931,75 @@ dependencies = [ "winapi", ] +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "noop_proc_macro" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0676bb32a98c1a483ce53e500a81ad9c3d5b3f7c920c28c24e9cb0980d0b5bc8" + +[[package]] +name = "num-bigint" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +dependencies = [ + "num-integer", + "num-traits", +] + [[package]] name = "num-conv" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" +[[package]] +name = "num-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" +dependencies = [ + "num-bigint", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -820,13 +1033,19 @@ version = "0.17.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec4c6225c69b4ca778c0aea097321a64c421cf4577b331c61b229267edabb6f8" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + [[package]] name = "pathfinder_geometry" version = "0.5.1" @@ -864,6 +1083,12 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315" +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + [[package]] name = "png" version = "0.17.14" @@ -874,7 +1099,7 @@ dependencies = [ "crc32fast", "fdeflate", "flate2", - "miniz_oxide 0.8.0", + "miniz_oxide", ] [[package]] @@ -892,6 +1117,15 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + [[package]] name = "printpdf" version = "0.7.0" @@ -952,6 +1186,25 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "profiling" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afbdc74edc00b6f6a218ca6a5364d6226a259d4b8ea1af4a0ea063f27e179f4d" +dependencies = [ + "profiling-procmacros", +] + +[[package]] +name = "profiling-procmacros" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a65f2e60fbf1063868558d69c6beacf412dc755f9fc020f514b7955fc914fe30" +dependencies = [ + "quote", + "syn 2.0.87", +] + [[package]] name = "quick-error" version = "2.0.1" @@ -967,6 +1220,92 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rangemap" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f60fcc7d6849342eff22c4350c8b9a989ee8ceabc4b481253e8946b9fe83d684" + +[[package]] +name = "rav1e" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd87ce80a7665b1cce111f8a16c1f3929f6547ce91ade6addf4ec86a8dda5ce9" +dependencies = [ + "arbitrary", + "arg_enum_proc_macro", + "arrayvec", + "av1-grain", + "bitstream-io", + "built", + "cfg-if", + "interpolate_name", + "itertools 0.12.1", + "libc", + "libfuzzer-sys", + "log", + "maybe-rayon", + "new_debug_unreachable", + "noop_proc_macro", + "num-derive", + "num-traits", + "once_cell", + "paste", + "profiling", + "rand", + "rand_chacha", + "simd_helpers", + "system-deps", + "thiserror", + "v_frame", + "wasm-bindgen", +] + +[[package]] +name = "ravif" +version = "0.11.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2413fd96bd0ea5cdeeb37eaf446a22e6ed7b981d792828721e74ded1980a45c6" +dependencies = [ + "avif-serialize", + "imgref", + "loop9", + "quick-error", + "rav1e", + "rayon", + "rgb", +] + [[package]] name = "rayon" version = "1.10.0" @@ -989,9 +1328,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" [[package]] name = "resvg" @@ -1121,22 +1460,22 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.214" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5" +checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.214" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" +checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -1151,12 +1490,36 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_spanned" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" +dependencies = [ + "serde", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "simd-adler32" version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" +[[package]] +name = "simd_helpers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95890f873bec569a0362c235787f3aca6e1e887302ba4840839bcc6459c42da6" +dependencies = [ + "quote", +] + [[package]] name = "simplecss" version = "0.2.1" @@ -1232,7 +1595,7 @@ dependencies = [ "fontdb", "image", "log", - "miniz_oxide 0.8.0", + "miniz_oxide", "once_cell", "pdf-writer", "resvg", @@ -1265,15 +1628,54 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.85" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5023162dfcd14ef8f32034d8bcd4cc5ddc61ef7a247c024a33e24e1f24d21b56" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] +[[package]] +name = "system-deps" +version = "6.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e535eb8dded36d55ec13eddacd30dec501792ff23a0b1682c38601b8cf2349" +dependencies = [ + "cfg-expr", + "heck 0.5.0", + "pkg-config", + "toml", + "version-compare", +] + +[[package]] +name = "target-lexicon" +version = "0.12.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "tiff" version = "0.9.1" @@ -1357,6 +1759,40 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" +[[package]] +name = "toml" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + [[package]] name = "ttf-parser" version = "0.15.2" @@ -1480,12 +1916,35 @@ dependencies = [ "xmlwriter", ] +[[package]] +name = "v_frame" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6f32aaa24bacd11e488aa9ba66369c7cd514885742c9fe08cfe85884db3e92b" +dependencies = [ + "aligned-vec", + "num-traits", + "wasm-bindgen", +] + +[[package]] +name = "version-compare" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852e951cb7832cb45cb1169900d19760cfa39b82bc0ea9c0e5a14ae88411c98b" + [[package]] name = "version_check" version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + [[package]] name = "wasm-bindgen" version = "0.2.95" @@ -1508,7 +1967,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", "wasm-bindgen-shared", ] @@ -1530,7 +1989,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1569,6 +2028,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "winnow" +version = "0.6.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" +dependencies = [ + "memchr", +] + [[package]] name = "xmlparser" version = "0.13.6" @@ -1581,6 +2049,27 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec7a2a501ed189703dba8b08142f057e887dfc4b2cc4db2d343ac6376ba3e0b9" +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "zune-core" version = "0.4.12" diff --git a/Cargo.toml b/Cargo.toml index 70dbad7..9486813 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ autoexamples = false edition = "2021" [dependencies] -lopdf = { version = "0.33.0", default-features = false, features = [ +lopdf = { version = "0.34.0", default-features = false, features = [ "pom_parser", ] } time = { version = "0.3.25", default-features = false, features = ["std"] } @@ -51,7 +51,7 @@ serde_derive = { version = "1" } serde_json = { version = "1" } wasm-bindgen = { version = "0.2" } base64 = "0.22.1" -flate2 = "1.0.23" +flate2 = "1.0.35" [features] default = ["js-sys"] diff --git a/src/serialize.rs b/src/serialize.rs index 5e5864d..8c9e685 100644 --- a/src/serialize.rs +++ b/src/serialize.rs @@ -492,7 +492,10 @@ fn translate_operations( "Tf", vec![font.get_pdf_id().into(), (size.0).into()], )); - let bytes = lopdf::Document::encode_text(Some("WinAnsiEncoding"), &text); + let bytes = lopdf::Document::encode_text( + &lopdf::Encoding::SimpleEncoding("WinAnsiEncoding"), + &text, + ); content.push(LoOp::new("Tj", vec![LoString(bytes, Hexadecimal)])); } Op::WriteCodepoints { font, cp, size } => { From 7da696b0e2388238cde8487695fce06de3c831b0 Mon Sep 17 00:00:00 2001 From: Bogdan Arabadzhi <8407846+barabadzhi@users.noreply.github.com> Date: Fri, 15 Nov 2024 13:06:50 +0100 Subject: [PATCH 3/3] Refactor and format the code Signed-off-by: Bogdan Arabadzhi <8407846+barabadzhi@users.noreply.github.com> --- Cargo.lock | 121 +++++++++++++------ Cargo.toml | 16 +-- defaultfonts/mapping.rs | 22 ++-- examples/html.rs | 2 +- examples/simple.rs | 6 +- examples/subset.rs | 2 +- src/annotation.rs | 9 +- src/font.rs | 58 ++++------ src/graphics.rs | 7 +- src/html.rs | 250 ++++++++++++++++++++-------------------- src/image.rs | 21 ++-- src/serialize.rs | 40 +++---- src/svg.rs | 2 +- src/units.rs | 18 +-- src/utils.rs | 2 +- src/wasm.rs | 2 +- src/xobject.rs | 11 +- 17 files changed, 306 insertions(+), 283 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cfcf25a..9b5fa28 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,6 +8,17 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" +[[package]] +name = "aes" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + [[package]] name = "aliasable" version = "0.1.3" @@ -149,7 +160,7 @@ dependencies = [ [[package]] name = "azul-core" version = "0.0.2" -source = "git+https://github.com/fschutt/azul?rev=646b5e3030041aaebe06d2344a36bbed000c8674#646b5e3030041aaebe06d2344a36bbed000c8674" +source = "git+https://github.com/fschutt/azul?rev=6a69b69994d1b4cda89b61922233de88498878ef#6a69b69994d1b4cda89b61922233de88498878ef" dependencies = [ "azul-css", "azul-css-parser", @@ -163,7 +174,7 @@ dependencies = [ [[package]] name = "azul-css" version = "0.0.1" -source = "git+https://github.com/fschutt/azul?rev=646b5e3030041aaebe06d2344a36bbed000c8674#646b5e3030041aaebe06d2344a36bbed000c8674" +source = "git+https://github.com/fschutt/azul?rev=6a69b69994d1b4cda89b61922233de88498878ef#6a69b69994d1b4cda89b61922233de88498878ef" dependencies = [ "libm", ] @@ -171,7 +182,7 @@ dependencies = [ [[package]] name = "azul-css-parser" version = "0.0.1" -source = "git+https://github.com/fschutt/azul?rev=646b5e3030041aaebe06d2344a36bbed000c8674#646b5e3030041aaebe06d2344a36bbed000c8674" +source = "git+https://github.com/fschutt/azul?rev=6a69b69994d1b4cda89b61922233de88498878ef#6a69b69994d1b4cda89b61922233de88498878ef" dependencies = [ "azul-css", "azul-simplecss", @@ -180,7 +191,7 @@ dependencies = [ [[package]] name = "azul-layout" version = "0.0.4" -source = "git+https://github.com/fschutt/azul?rev=646b5e3030041aaebe06d2344a36bbed000c8674#646b5e3030041aaebe06d2344a36bbed000c8674" +source = "git+https://github.com/fschutt/azul?rev=6a69b69994d1b4cda89b61922233de88498878ef#6a69b69994d1b4cda89b61922233de88498878ef" dependencies = [ "azul-core", "azul-css", @@ -198,7 +209,7 @@ checksum = "c303bfdf857413adbd19d9b15dddd9b4adb8e2be7e493c8a38d9fc6179a074ac" [[package]] name = "azul-text-layout" version = "0.0.5" -source = "git+https://github.com/fschutt/azul?rev=646b5e3030041aaebe06d2344a36bbed000c8674#646b5e3030041aaebe06d2344a36bbed000c8674" +source = "git+https://github.com/fschutt/azul?rev=6a69b69994d1b4cda89b61922233de88498878ef#6a69b69994d1b4cda89b61922233de88498878ef" dependencies = [ "allsorts", "azul-core", @@ -212,7 +223,7 @@ dependencies = [ [[package]] name = "azulc" version = "0.0.3" -source = "git+https://github.com/fschutt/azul?rev=646b5e3030041aaebe06d2344a36bbed000c8674#646b5e3030041aaebe06d2344a36bbed000c8674" +source = "git+https://github.com/fschutt/azul?rev=6a69b69994d1b4cda89b61922233de88498878ef#6a69b69994d1b4cda89b61922233de88498878ef" dependencies = [ "azul-core", "azul-css", @@ -271,24 +282,22 @@ dependencies = [ ] [[package]] -name = "brotli-decompressor" -version = "2.5.1" +name = "block-padding" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e2e4afe60d7dd600fdd3de8d0f08c2b7ec039712e3b6137ff98b7004e82de4f" +checksum = "a8894febbff9f758034a5b8e12d87918f56dfc64a8e1fe757d65e29041538d93" dependencies = [ - "alloc-no-stdlib", - "alloc-stdlib", + "generic-array", ] [[package]] -name = "bstr" -version = "1.11.0" +name = "brotli-decompressor" +version = "2.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a68f1f47cdf0ec8ee4b941b2eee2a80cb796db73118c0dd09ac63fbe405be22" +checksum = "4e2e4afe60d7dd600fdd3de8d0f08c2b7ec039712e3b6137ff98b7004e82de4f" dependencies = [ - "memchr", - "regex-automata", - "serde", + "alloc-no-stdlib", + "alloc-stdlib", ] [[package]] @@ -303,6 +312,12 @@ version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" +[[package]] +name = "bytecount" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ce89b21cab1437276d2650d57e971f9d548a2d9037cc231abdc0562b97498ce" + [[package]] name = "bytemuck" version = "1.19.0" @@ -321,6 +336,15 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495" +[[package]] +name = "cbc" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b52a9543ae338f279b96b0b9fed9c8093744685043739079ce85cd58f289a6" +dependencies = [ + "cipher", +] + [[package]] name = "cc" version = "1.2.1" @@ -348,6 +372,16 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + [[package]] name = "color_quant" version = "1.1.0" @@ -363,6 +397,15 @@ dependencies = [ "libm", ] +[[package]] +name = "cpufeatures" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ca741a962e1b0bff6d724a1a0958b686406e853bb14061f218562e1896f95e6" +dependencies = [ + "libc", +] + [[package]] name = "crc32fast" version = "1.4.2" @@ -730,6 +773,16 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "inout" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" +dependencies = [ + "block-padding", + "generic-array", +] + [[package]] name = "interpolate_name" version = "0.2.4" @@ -855,16 +908,18 @@ dependencies = [ [[package]] name = "lopdf" version = "0.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5c8ecfc6c72051981c0459f75ccc585e7ff67c70829560cda8e647882a9abff" +source = "git+https://github.com/J-F-Liu/lopdf?rev=ea838e2252201bf0efe648b8954100b13835dae0#ea838e2252201bf0efe648b8954100b13835dae0" dependencies = [ + "aes", + "cbc", "encoding_rs", "flate2", "indexmap", "itoa", "log", "md-5", - "pom", + "nom", + "nom_locate", "rangemap", "time", "weezl", @@ -947,6 +1002,17 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "nom_locate" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e3c83c053b0713da60c5b8de47fe8e494fe3ece5267b2f23090a07a053ba8f3" +dependencies = [ + "bytecount", + "memchr", + "nom", +] + [[package]] name = "noop_proc_macro" version = "0.3.0" @@ -1102,15 +1168,6 @@ dependencies = [ "miniz_oxide", ] -[[package]] -name = "pom" -version = "3.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c972d8f86e943ad532d0b04e8965a749ad1d18bb981a9c7b3ae72fe7fd7744b" -dependencies = [ - "bstr", -] - [[package]] name = "powerfmt" version = "0.2.0" @@ -1326,12 +1383,6 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "regex-automata" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" - [[package]] name = "resvg" version = "0.43.0" diff --git a/Cargo.toml b/Cargo.toml index 9486813..5ecfa72 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,8 +17,8 @@ autoexamples = false edition = "2021" [dependencies] -lopdf = { version = "0.34.0", default-features = false, features = [ - "pom_parser", +lopdf = { git = "https://github.com/J-F-Liu/lopdf", rev = "ea838e2252201bf0efe648b8954100b13835dae0", default-features = false, features = [ + "nom_parser", ] } time = { version = "0.3.25", default-features = false, features = ["std"] } allsorts = { version = "0.15", default-features = false, features = [ @@ -28,17 +28,17 @@ pdf-writer = { version = "0.12.0" } image = { version = "0.25", default-features = false } svg2pdf = { version = "0.12.0" } # dependencies for wasm demo -azul-css = { git = "https://github.com/fschutt/azul", rev = "646b5e3030041aaebe06d2344a36bbed000c8674", default-features = false } -azul-css-parser = { git = "https://github.com/fschutt/azul", rev = "646b5e3030041aaebe06d2344a36bbed000c8674", default-features = false } -azul-core = { git = "https://github.com/fschutt/azul", rev = "646b5e3030041aaebe06d2344a36bbed000c8674", default-features = false, features = [ +azul-css = { git = "https://github.com/fschutt/azul", rev = "6a69b69994d1b4cda89b61922233de88498878ef", default-features = false } +azul-css-parser = { git = "https://github.com/fschutt/azul", rev = "6a69b69994d1b4cda89b61922233de88498878ef", default-features = false } +azul-core = { git = "https://github.com/fschutt/azul", rev = "6a69b69994d1b4cda89b61922233de88498878ef", default-features = false, features = [ "std", ] } -azul-layout = { git = "https://github.com/fschutt/azul", rev = "646b5e3030041aaebe06d2344a36bbed000c8674", default-features = false, features = [ +azul-layout = { git = "https://github.com/fschutt/azul", rev = "6a69b69994d1b4cda89b61922233de88498878ef", default-features = false, features = [ "std", "text_layout", ] } -azul-text-layout = { git = "https://github.com/fschutt/azul", rev = "646b5e3030041aaebe06d2344a36bbed000c8674", default-features = false } -azulc = { git = "https://github.com/fschutt/azul", rev = "646b5e3030041aaebe06d2344a36bbed000c8674", default-features = false, features = [ +azul-text-layout = { git = "https://github.com/fschutt/azul", rev = "6a69b69994d1b4cda89b61922233de88498878ef", default-features = false } +azulc = { git = "https://github.com/fschutt/azul", rev = "6a69b69994d1b4cda89b61922233de88498878ef", default-features = false, features = [ "std", "xml", "text_layout", diff --git a/defaultfonts/mapping.rs b/defaultfonts/mapping.rs index 5360a76..d21de36 100644 --- a/defaultfonts/mapping.rs +++ b/defaultfonts/mapping.rs @@ -1,6 +1,6 @@ const FONTS: &[(usize, u16, u16, char);1483] = &[ (8, 3, 0, ' '), - (8, 16, 1, '­'), + (8, 16, 1, '\u{AD}'), (8, 98, 2, 'Ä'), (8, 99, 3, 'Å'), (8, 100, 4, 'Ç'), @@ -123,7 +123,7 @@ const FONTS: &[(usize, u16, u16, char);1483] = &[ (8, 257, 121, '·'), (8, 1127, 122, '¤'), (9, 3, 0, ' '), - (9, 16, 1, '­'), + (9, 16, 1, '\u{AD}'), (9, 98, 2, 'Ä'), (9, 99, 3, 'Å'), (9, 100, 4, 'Ç'), @@ -246,7 +246,7 @@ const FONTS: &[(usize, u16, u16, char);1483] = &[ (9, 256, 121, '¯'), (9, 750, 122, '¤'), (10, 3, 0, ' '), - (10, 16, 1, '­'), + (10, 16, 1, '\u{AD}'), (10, 98, 2, 'Ä'), (10, 99, 3, 'Å'), (10, 100, 4, 'Ç'), @@ -499,7 +499,7 @@ const FONTS: &[(usize, u16, u16, char);1483] = &[ (4, 108, 10, 'ª'), (4, 109, 11, '«'), (4, 110, 12, '¬'), - (4, 111, 13, '­'), + (4, 111, 13, '\u{AD}'), (4, 112, 14, '®'), (4, 113, 15, '¯'), (4, 114, 16, '°'), @@ -622,7 +622,7 @@ const FONTS: &[(usize, u16, u16, char);1483] = &[ (5, 108, 10, 'ª'), (5, 109, 11, '«'), (5, 110, 12, '¬'), - (5, 111, 13, '­'), + (5, 111, 13, '\u{AD}'), (5, 112, 14, '®'), (5, 113, 15, '¯'), (5, 114, 16, '°'), @@ -745,7 +745,7 @@ const FONTS: &[(usize, u16, u16, char);1483] = &[ (6, 108, 10, 'ª'), (6, 109, 11, '«'), (6, 110, 12, '¬'), - (6, 111, 13, '­'), + (6, 111, 13, '\u{AD}'), (6, 112, 14, '®'), (6, 113, 15, '¯'), (6, 114, 16, '°'), @@ -868,7 +868,7 @@ const FONTS: &[(usize, u16, u16, char);1483] = &[ (7, 108, 10, 'ª'), (7, 109, 11, '«'), (7, 110, 12, '¬'), - (7, 111, 13, '­'), + (7, 111, 13, '\u{AD}'), (7, 112, 14, '®'), (7, 113, 15, '¯'), (7, 114, 16, '°'), @@ -992,7 +992,7 @@ const FONTS: &[(usize, u16, u16, char);1483] = &[ (12, 147, 17, '™'), (12, 151, 18, '¬'), (0, 3, 0, ' '), - (0, 16, 1, '­'), + (0, 16, 1, '\u{AD}'), (0, 98, 2, 'Ä'), (0, 99, 3, 'Å'), (0, 100, 4, 'Ç'), @@ -1115,7 +1115,7 @@ const FONTS: &[(usize, u16, u16, char);1483] = &[ (0, 256, 121, '¯'), (0, 862, 122, '¤'), (1, 3, 0, ' '), - (1, 16, 1, '­'), + (1, 16, 1, '\u{AD}'), (1, 98, 2, 'Ä'), (1, 99, 3, 'Å'), (1, 100, 4, 'Ç'), @@ -1238,7 +1238,7 @@ const FONTS: &[(usize, u16, u16, char);1483] = &[ (1, 256, 121, '¯'), (1, 862, 122, '¤'), (2, 3, 0, ' '), - (2, 16, 1, '­'), + (2, 16, 1, '\u{AD}'), (2, 98, 2, 'Ä'), (2, 99, 3, 'Å'), (2, 100, 4, 'Ç'), @@ -1358,7 +1358,7 @@ const FONTS: &[(usize, u16, u16, char);1483] = &[ (2, 218, 118, '¯'), (2, 219, 119, '·'), (3, 3, 0, ' '), - (3, 16, 1, '­'), + (3, 16, 1, '\u{AD}'), (3, 98, 2, 'Ä'), (3, 99, 3, 'Å'), (3, 100, 4, 'Ç'), diff --git a/examples/html.rs b/examples/html.rs index 91437b8..327ffa9 100644 --- a/examples/html.rs +++ b/examples/html.rs @@ -1,6 +1,6 @@ use printpdf::*; -const HTML_STRINGS: &[&str;1] = &[ +const HTML_STRINGS: &[&str; 1] = &[ // "
", "

Hello!

", ]; diff --git a/examples/simple.rs b/examples/simple.rs index 57a9db2..368c6f3 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -143,8 +143,8 @@ fn main() { let transform = XObjectTransform { rotate: Some(XObjectRotation { angle_ccw_degrees: i as f32 * 36.0, - rotation_center_x: rotation_center_x, - rotation_center_y: rotation_center_y, + rotation_center_x, + rotation_center_y, }), translate_x: Some(Mm(i as f32 * 20.0 % 50.0).into()), translate_y: Some(Mm(i as f32 * 30.0).into()), @@ -155,7 +155,7 @@ fn main() { ops.extend_from_slice(&[Op::UseXObject { id: xobject_id.clone(), - transform: transform, + transform, }]); } diff --git a/examples/subset.rs b/examples/subset.rs index 3ae6ac7..3576b8e 100644 --- a/examples/subset.rs +++ b/examples/subset.rs @@ -91,7 +91,7 @@ fn main() { env!("CARGO_MANIFEST_DIR"), name.get_id() ), - &printpdf::compress(&subset.bytes), + printpdf::compress(&subset.bytes), ); for (old_gid, (new_gid, char)) in subset.glyph_mapping.iter() { target_map.push(format!( diff --git a/src/annotation.rs b/src/annotation.rs index 8fa6165..d97b104 100644 --- a/src/annotation.rs +++ b/src/annotation.rs @@ -158,20 +158,15 @@ impl Actions { } } -#[derive(Debug, PartialEq, Clone, Copy)] +#[derive(Debug, PartialEq, Clone, Copy, Default)] pub enum HighlightingMode { None, + #[default] Invert, Outline, Push, } -impl Default for HighlightingMode { - fn default() -> Self { - HighlightingMode::Invert - } -} - impl HighlightingMode { pub fn get_id(&self) -> &'static str { use self::HighlightingMode::*; diff --git a/src/font.rs b/src/font.rs index 434dc50..a877a36 100644 --- a/src/font.rs +++ b/src/font.rs @@ -390,10 +390,10 @@ impl ParsedFont { for (glyph_id, unicode) in glyph_ids.iter() { // end the current (beginbfchar endbfchar) block if necessary - if (*glyph_id >> 8) as u16 != cur_first_bit || current_cmap_block.len() >= 100 { + if (*glyph_id >> 8) != cur_first_bit || current_cmap_block.len() >= 100 { all_cmap_blocks.push(current_cmap_block.clone()); current_cmap_block = Vec::new(); - cur_first_bit = (*glyph_id >> 8) as u16; + cur_first_bit = *glyph_id >> 8; } current_cmap_block.push((*glyph_id, *unicode as u32)); @@ -429,7 +429,7 @@ impl ParsedFont { } else { // non-subsequent GID widths_list.push(Integer(current_low_gid as i64)); - widths_list.push(Array(current_width_vec.drain(..).collect())); + widths_list.push(Array(std::mem::take(&mut current_width_vec))); current_width_vec.push(Integer((width as f32 * percentage_font_scaling) as i64)); current_low_gid = *gid; @@ -439,7 +439,7 @@ impl ParsedFont { // push the last widths, because the loop is delayed by one iteration widths_list.push(Integer(current_low_gid as i64)); - widths_list.push(Array(current_width_vec.drain(..).collect())); + widths_list.push(Array(std::mem::take(&mut current_width_vec))); widths_list /* @@ -534,14 +534,6 @@ struct GlyphOutlineBuilder { operations: Vec, } -impl Default for GlyphOutlineBuilder { - fn default() -> Self { - GlyphOutlineBuilder { - operations: Vec::new(), - } - } -} - /* impl ttf_parser::OutlineBuilder for GlyphOutlineBuilder { fn move_to(&mut self, x: f32, y: f32) { self.operations.push(GlyphOutlineOperation::MoveTo(OutlineMoveTo { x, y })); } @@ -569,7 +561,7 @@ pub struct OwnedGlyph { } impl OwnedGlyph { - fn from_glyph_data<'a>(glyph: &Glyph<'a>, horz_advance: u16) -> Option { + fn from_glyph_data(glyph: &Glyph<'_>, horz_advance: u16) -> Option { let bbox = glyph.bounding_box()?; Some(Self { bounding_box: OwnedGlyphBoundingBox { @@ -615,7 +607,7 @@ impl ParsedFont { let loca_table = loca_table .as_ref() .and_then(|loca_data| { - ReadScope::new(&loca_data.as_ref()?) + ReadScope::new(loca_data.as_ref()?) .read_dep::>((num_glyphs, index_to_loc)) .ok() }) @@ -627,7 +619,7 @@ impl ParsedFont { let mut glyf_table = glyf_table .as_ref() .and_then(|glyf_data| { - ReadScope::new(&glyf_data.as_ref()?) + ReadScope::new(glyf_data.as_ref()?) .read_dep::>(&loca_table) .ok() }) @@ -656,7 +648,7 @@ impl ParsedFont { // not parsing glyph outlines can save lots of memory let glyph_records_decoded = glyf_table .records_mut() - .into_iter() + .iter_mut() .enumerate() .filter_map(|(glyph_index, glyph_record)| { if glyph_index > (u16::MAX as usize) { @@ -1096,20 +1088,20 @@ impl FontMetrics { fs_selection: os2_table.fs_selection, us_first_char_index: os2_table.us_first_char_index, us_last_char_index: os2_table.us_last_char_index, - s_typo_ascender: os2_table.s_typo_ascender.into(), - s_typo_descender: os2_table.s_typo_descender.into(), - s_typo_line_gap: os2_table.s_typo_line_gap.into(), - us_win_ascent: os2_table.us_win_ascent.into(), - us_win_descent: os2_table.us_win_descent.into(), - ul_code_page_range1: os2_table.ul_code_page_range1.into(), - ul_code_page_range2: os2_table.ul_code_page_range2.into(), - sx_height: os2_table.sx_height.into(), - s_cap_height: os2_table.s_cap_height.into(), - us_default_char: os2_table.us_default_char.into(), - us_break_char: os2_table.us_break_char.into(), - us_max_context: os2_table.us_max_context.into(), - us_lower_optical_point_size: os2_table.us_lower_optical_point_size.into(), - us_upper_optical_point_size: os2_table.us_upper_optical_point_size.into(), + s_typo_ascender: os2_table.s_typo_ascender, + s_typo_descender: os2_table.s_typo_descender, + s_typo_line_gap: os2_table.s_typo_line_gap, + us_win_ascent: os2_table.us_win_ascent, + us_win_descent: os2_table.us_win_descent, + ul_code_page_range1: os2_table.ul_code_page_range1, + ul_code_page_range2: os2_table.ul_code_page_range2, + sx_height: os2_table.sx_height, + s_cap_height: os2_table.s_cap_height, + us_default_char: os2_table.us_default_char, + us_break_char: os2_table.us_break_char, + us_max_context: os2_table.us_max_context, + us_lower_optical_point_size: os2_table.us_lower_optical_point_size, + us_upper_optical_point_size: os2_table.us_upper_optical_point_size, } } @@ -1124,7 +1116,7 @@ impl FontMetrics { let use_typo = if !self.use_typo_metrics() { None } else { - self.s_typo_ascender.into() + self.s_typo_ascender }; match use_typo { Some(s) => s, @@ -1137,7 +1129,7 @@ impl FontMetrics { let use_typo = if !self.use_typo_metrics() { None } else { - self.s_typo_descender.into() + self.s_typo_descender }; match use_typo { Some(s) => s, @@ -1149,7 +1141,7 @@ impl FontMetrics { let use_typo = if !self.use_typo_metrics() { None } else { - self.s_typo_line_gap.into() + self.s_typo_line_gap }; match use_typo { Some(s) => s, diff --git a/src/graphics.rs b/src/graphics.rs index 14068fb..7aa3c1c 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -100,9 +100,9 @@ impl Rect { /// This is meaningful in the following cases: /// /// - When a path uses one of the _fill_ paint operations, this will determine the rule used to -/// fill the paths. +/// fill the paths. /// - When a path uses a [clip] painting mode, this will determine the rule used to limit the -/// regions of the page affected by painting operators. +/// regions of the page affected by painting operators. /// /// Most of the time, `NonZero` is the appropriate option. /// @@ -963,7 +963,6 @@ impl ExtendedGraphicsStateBuilder { /// Consumes the builder and returns an actual ExtendedGraphicsState #[inline] - pub fn build(self) -> ExtendedGraphicsState { self.gs } @@ -1085,7 +1084,6 @@ pub enum TransferExtraFunction {} /// by streams are specifically identified as such in the descriptions /// of particular halftone types; unless otherwise stated, they are /// understood to be defined by simple dictionaries instead.) - /* << /Type /Halftone @@ -1096,7 +1094,6 @@ pub enum TransferExtraFunction {} /TransferFunction /Identity >> */ - /// Deserialized into Integer: 1, 5, 6, 10 or 16 #[derive(Debug, PartialEq, Clone)] pub enum HalftoneType { diff --git a/src/html.rs b/src/html.rs index 16e58e2..7a493d2 100644 --- a/src/html.rs +++ b/src/html.rs @@ -1,7 +1,8 @@ -use crate::{translate_to_internal_rawimage, BuiltinFont, Mm, Op, PdfDocument, PdfPage, PdfResources, Pt}; +use crate::{BuiltinFont, Mm, Op, PdfDocument, PdfPage, PdfResources, Pt}; use azul_core::{ app_resources::{ - self, AddFontMsg, DpiScaleFactor, Epoch, IdNamespace, ImageCache, ImageDescriptor, ImageRef, ImageRefHash, RawImageData, RendererResources, ResolvedImage + DpiScaleFactor, Epoch, IdNamespace, ImageCache, ImageDescriptor, ImageRef, ImageRefHash, + RendererResources, }, callbacks::DocumentId, display_list::{ @@ -9,13 +10,12 @@ use azul_core::{ StyleBorderStyles, StyleBorderWidths, }, dom::{NodeData, NodeId}, - styled_dom::{ContentGroup, DomId, StyleFontFamiliesHash, StyleFontFamilyHash, StyledDom, StyledNode}, + styled_dom::{ContentGroup, DomId, StyledDom, StyledNode}, ui_solver::LayoutResult, window::{FullWindowState, LogicalSize}, xml::{XmlComponentMap, XmlNode}, }; use azul_css::{CssPropertyValue, FloatValue, LayoutDisplay, StyleTextColor, U8Vec}; -use azul_text_layout::text_layout::ParsedFont; use base64::Engine; use rust_fontconfig::{FcFont, FcFontCache, FcPattern}; use std::collections::BTreeMap; @@ -62,12 +62,12 @@ pub(crate) fn xml_to_pages( }; let root_nodes = azulc_lib::xml::parse_xml_string(&fixup_xml(file_contents)) - .map_err(|e| format!("Error parsing XML: {}", e.to_string()))?; + .map_err(|e| format!("Error parsing XML: {}", e))?; let fixup = fixup_xml_nodes(&root_nodes); - let styled_dom = azul_core::xml::str_to_dom(fixup.as_ref(), &mut XmlComponentMap::default()) - .map_err(|e| format!("Error constructing DOM: {}", e.to_string()))?; + let styled_dom = azul_core::xml::str_to_dom(&fixup, &mut XmlComponentMap::default()) + .map_err(|e| format!("Error constructing DOM: {e}"))?; let dom_id = DomId { inner: 0 }; let mut fake_window_state = FullWindowState::default(); @@ -120,7 +120,7 @@ pub(crate) fn xml_to_pages( ..Default::default() }; let font = FcFont { - bytes: bytes, + bytes, font_index: 0, }; Some((pat, font)) @@ -171,6 +171,8 @@ pub(crate) fn xml_to_pages( &mut ops, config.page_height.into_pt(), ); + + dbg!(&ops); Ok(vec![PdfPage::new( config.page_width, config.page_height, @@ -179,7 +181,7 @@ pub(crate) fn xml_to_pages( } fn get_system_fonts() -> Vec<(FcPattern, FcFont)> { - let f = vec![ + let f = [ ("serif", BuiltinFont::TimesRoman), ("sans-serif", BuiltinFont::Helvetica), ("cursive", BuiltinFont::TimesItalic), @@ -245,7 +247,7 @@ fn layout_result_to_ops( ) { let rects_in_rendering_order = layout_result.styled_dom.get_rects_in_rendering_order(); - // TODO: break layoutresult into pages + // TODO: break layout result into pages // let root_width = layout_result.width_calculated_rects.as_ref()[NodeId::ZERO].overflow_width(); // let root_height = layout_result.height_calculated_rects.as_ref()[NodeId::ZERO].overflow_height(); // let root_size = LogicalSize::new(root_width, root_height); @@ -271,11 +273,11 @@ fn layout_result_to_ops( } } -fn push_rectangles_into_displaylist<'a>( +fn push_rectangles_into_displaylist( doc: &mut PdfDocument, ops: &mut Vec, layout_result: &LayoutResult, - renderer_resources: &'a RendererResources, + renderer_resources: &RendererResources, root_content_group: &ContentGroup, page_height: Pt, ) -> Option<()> { @@ -310,7 +312,7 @@ fn displaylist_handle_rect( rect_idx: NodeId, page_height: Pt, ) -> Option<()> { - use crate::units::{Px, Pt}; + use crate::units::Pt; let mut newops = Vec::new(); @@ -328,33 +330,34 @@ fn displaylist_handle_rect( let opt_border = get_opt_border(layout_result, html_node, rect_idx, styled_node); let opt_image = get_image_node(html_node); let opt_text = get_text_node( - layout_result, rect_idx, html_node, - styled_node, &renderer_resources, &mut doc.resources + layout_result, + rect_idx, + html_node, + styled_node, + renderer_resources, + &mut doc.resources, ); for b in background_content.iter() { - match &b.content { - RectBackground::Color(c) => { - let staticoffset = positioned_rect.position.get_static_offset(); - let rect = crate::graphics::Rect { - x: Pt(staticoffset.x), - y: Pt(page_height.0 - staticoffset.y), - width: Pt(positioned_rect.size.width), - height: Pt(positioned_rect.size.height), - }; - newops.push(Op::SetFillColor { - col: crate::Color::Rgb(crate::Rgb { - r: c.r as f32 / 255.0, - g: c.g as f32 / 255.0, - b: c.b as f32 / 255.0, - icc_profile: None, - }), - }); - newops.push(Op::DrawPolygon { - polygon: rect.to_polygon(), - }); - } - _ => {} + if let RectBackground::Color(c) = &b.content { + let staticoffset = positioned_rect.position.get_static_offset(); + let rect = crate::graphics::Rect { + x: Pt(staticoffset.x), + y: Pt(page_height.0 - staticoffset.y), + width: Pt(positioned_rect.size.width), + height: Pt(positioned_rect.size.height), + }; + newops.push(Op::SetFillColor { + col: crate::Color::Rgb(crate::Rgb { + r: c.r as f32 / 255.0, + g: c.g as f32 / 255.0, + b: c.b as f32 / 255.0, + icc_profile: None, + }), + }); + newops.push(Op::DrawPolygon { + polygon: rect.to_polygon(), + }); } } @@ -436,62 +439,68 @@ fn displaylist_handle_rect( if let Some((desc, data, hash, size)) = opt_image { let image_id = format!("im_azul_layout_{h:032}", h = hash.0); let xobject_id = crate::XObjectId(image_id.clone()); - let image = crate::XObject::Image(crate::image::translate_from_internal_rawimage(desc, data.as_slice())); + let image = crate::XObject::Image(crate::image::translate_from_internal_rawimage( + desc, + data.as_slice(), + )); doc.resources.xobjects.map.insert(xobject_id, image); } if let Some((text, id, color)) = opt_text { - println!("writing text {text:#?} {id:?}"); ops.push(Op::StartTextSection); - ops.push(Op::SetFillColor { - col: crate::Color::Rgb(crate::Rgb { - r: color.inner.r as f32 / 255.0, - g: color.inner.g as f32 / 255.0, - b: color.inner.b as f32 / 255.0, + ops.push(Op::SetFillColor { + col: crate::Color::Rgb(crate::Rgb { + r: color.inner.r as f32 / 255.0, + g: color.inner.g as f32 / 255.0, + b: color.inner.b as f32 / 255.0, icc_profile: None, - }) + }), + }); + ops.push(Op::SetTextRenderingMode { + mode: crate::TextRenderingMode::Fill, }); - ops.push(Op::SetTextRenderingMode { mode: crate::TextRenderingMode::Fill }); for line in text.lines.as_slice() { - ops.push(Op::SetTextCursor { - pos: crate::Point { - x: Pt(line.bounds.origin.x), // TODO: px / pt ! - y: Pt(line.bounds.origin.y), // TODO: px / pt ! - } + ops.push(Op::SetTextCursor { + pos: crate::Point { + x: Pt(line.bounds.origin.x), // TODO: px / pt ! + y: Pt(line.bounds.origin.y), // TODO: px / pt ! + }, }); - + for word in line.words.as_slice().iter() { use azul_core::callbacks::InlineWord::*; match word { Tab => { - ops.push(Op::WriteText { - text: " ".to_string(), - size: Pt(text.font_size_px), // TODO: px / pt ! + ops.push(Op::WriteText { + text: " ".to_string(), + size: Pt(text.font_size_px), // TODO: px / pt ! font: id.clone(), }); - }, + } Return => { // TODO? - }, + } Space => { - ops.push(Op::WriteText { - text: " ".to_string(), - size: Pt(text.font_size_px), // TODO: px / pt ! + ops.push(Op::WriteText { + text: " ".to_string(), + size: Pt(text.font_size_px), // TODO: px / pt ! font: id.clone(), }); - }, + } Word(itc) => { - let chars = itc.glyphs.iter().filter_map(|s| { - char::from_u32(*s.unicode_codepoint.as_option()?) - }).collect::(); - - ops.push(Op::WriteText { - text: chars, - size: Pt(text.font_size_px), // TODO: px / pt ! + let chars = itc + .glyphs + .iter() + .filter_map(|s| char::from_u32(*s.unicode_codepoint.as_option()?)) + .collect::(); + + ops.push(Op::WriteText { + text: chars, + size: Pt(text.font_size_px), // TODO: px / pt ! font: id.clone(), }); - }, + } } } } @@ -530,7 +539,7 @@ fn solve_layout( styled_dom, epoch, &document_id, - &fake_window_state, + fake_window_state, &mut resource_updates, ID_NAMESPACE, &image_cache, @@ -553,7 +562,7 @@ fn is_display_none( let display = layout_result .styled_dom .get_css_property_cache() - .get_display(&html_node, &rect_idx, &styled_node.state) + .get_display(html_node, &rect_idx, &styled_node.state) .cloned() .unwrap_or_default(); @@ -570,22 +579,22 @@ fn get_border_radius( top_left: layout_result .styled_dom .get_css_property_cache() - .get_border_top_left_radius(&html_node, &rect_idx, &styled_node.state) + .get_border_top_left_radius(html_node, &rect_idx, &styled_node.state) .cloned(), top_right: layout_result .styled_dom .get_css_property_cache() - .get_border_top_right_radius(&html_node, &rect_idx, &styled_node.state) + .get_border_top_right_radius(html_node, &rect_idx, &styled_node.state) .cloned(), bottom_left: layout_result .styled_dom .get_css_property_cache() - .get_border_bottom_left_radius(&html_node, &rect_idx, &styled_node.state) + .get_border_bottom_left_radius(html_node, &rect_idx, &styled_node.state) .cloned(), bottom_right: layout_result .styled_dom .get_css_property_cache() - .get_border_bottom_right_radius(&html_node, &rect_idx, &styled_node.state) + .get_border_bottom_right_radius(html_node, &rect_idx, &styled_node.state) .cloned(), } } @@ -609,7 +618,7 @@ fn get_background_content( let bg_opt = layout_result .styled_dom .get_css_property_cache() - .get_background_content(&html_node, &rect_idx, &styled_node.state); + .get_background_content(html_node, &rect_idx, &styled_node.state); let mut v = Vec::new(); @@ -621,15 +630,15 @@ fn get_background_content( let bg_sizes_opt = layout_result .styled_dom .get_css_property_cache() - .get_background_size(&html_node, &rect_idx, &styled_node.state); + .get_background_size(html_node, &rect_idx, &styled_node.state); let bg_positions_opt = layout_result .styled_dom .get_css_property_cache() - .get_background_position(&html_node, &rect_idx, &styled_node.state); + .get_background_position(html_node, &rect_idx, &styled_node.state); let bg_repeats_opt = layout_result .styled_dom .get_css_property_cache() - .get_background_repeat(&html_node, &rect_idx, &styled_node.state); + .get_background_repeat(html_node, &rect_idx, &styled_node.state); let bg_sizes = bg_sizes_opt .as_ref() @@ -662,9 +671,9 @@ fn get_background_content( if let Some(background_content) = background_content { v.push(LayoutRectContentBackground { content: background_content, - size: bg_size.clone(), - offset: bg_position.clone(), - repeat: bg_repeat.clone(), + size: bg_size, + offset: bg_position, + repeat: bg_repeat, }); } } @@ -673,9 +682,9 @@ fn get_background_content( v } -fn get_image_node<'a>(html_node: &'a NodeData) --> Option<(&'a ImageDescriptor, &'a U8Vec, ImageRefHash, LogicalSize)> { - +fn get_image_node( + html_node: &NodeData, +) -> Option<(&ImageDescriptor, &U8Vec, ImageRefHash, LogicalSize)> { use azul_core::app_resources::DecodedImage; use azul_core::app_resources::ImageData; use azul_core::dom::NodeType; @@ -689,14 +698,9 @@ fn get_image_node<'a>(html_node: &'a NodeData) let image_size = image_ref.get_size(); let (descriptor, data) = match image_ref.get_data() { - DecodedImage::Raw((descriptor, data)) => { - match data { - ImageData::Raw(vec) => Some((descriptor, vec)), - _ => None, - } - }, - _ => None, - }?; + DecodedImage::Raw((descriptor, ImageData::Raw(vec))) => (descriptor, vec), + _ => return None, + }; Some((descriptor, data, image_hash, image_size)) } @@ -708,28 +712,30 @@ fn get_text_node( styled_node: &StyledNode, app_resources: &azul_core::app_resources::RendererResources, res: &mut PdfResources, -) -> Option<(azul_core::callbacks::InlineText, crate::FontId, StyleTextColor)> { - +) -> Option<( + azul_core::callbacks::InlineText, + crate::FontId, + StyleTextColor, +)> { use azul_core::styled_dom::StyleFontFamiliesHash; - + if !html_node.is_text_node() { return None; } let font_families = layout_result - .styled_dom - .get_css_property_cache() - .get_font_id_or_default(&html_node, &rect_idx, &styled_node.state); + .styled_dom + .get_css_property_cache() + .get_font_id_or_default(html_node, &rect_idx, &styled_node.state); - let sffh = app_resources - .get_font_family(&StyleFontFamiliesHash::new(&font_families.as_slice()))?; + let sffh = + app_resources.get_font_family(&StyleFontFamiliesHash::new(font_families.as_slice()))?; - let font_key = app_resources - .get_font_key(&sffh)?; + let font_key = app_resources.get_font_key(sffh)?; - let fd = app_resources.get_registered_font(&font_key)?; + let fd = app_resources.get_registered_font(font_key)?; let font_ref = &fd.0; - + let rects = layout_result.rects.as_ref(); let words = layout_result.words_cache.get(&rect_idx)?; let shaped_words = layout_result.shaped_words_cache.get(&rect_idx)?; @@ -737,15 +743,15 @@ fn get_text_node( let positioned_rect = rects.get(rect_idx)?; let (_, inline_text_layout) = positioned_rect.resolved_text_layout_options.as_ref()?; let inline_text = azul_core::app_resources::get_inline_text( - &words, - &shaped_words, + words, + shaped_words, &word_positions.0, - &inline_text_layout, + inline_text_layout, ); let text_color = layout_result .styled_dom .get_css_property_cache() - .get_text_color_or_default(&html_node, &rect_idx, &styled_node.state); + .get_text_color_or_default(html_node, &rect_idx, &styled_node.state); // add font to resources if not existent let id = crate::FontId(format!("azul_font_family_{:032}", sffh.0)); @@ -775,7 +781,7 @@ fn get_opt_border( if !layout_result .styled_dom .get_css_property_cache() - .has_border(&html_node, &rect_idx, &styled_node.state) + .has_border(html_node, &rect_idx, &styled_node.state) { return None; } @@ -785,66 +791,66 @@ fn get_opt_border( top: layout_result .styled_dom .get_css_property_cache() - .get_border_top_width(&html_node, &rect_idx, &styled_node.state) + .get_border_top_width(html_node, &rect_idx, &styled_node.state) .cloned(), left: layout_result .styled_dom .get_css_property_cache() - .get_border_left_width(&html_node, &rect_idx, &styled_node.state) + .get_border_left_width(html_node, &rect_idx, &styled_node.state) .cloned(), bottom: layout_result .styled_dom .get_css_property_cache() - .get_border_bottom_width(&html_node, &rect_idx, &styled_node.state) + .get_border_bottom_width(html_node, &rect_idx, &styled_node.state) .cloned(), right: layout_result .styled_dom .get_css_property_cache() - .get_border_right_width(&html_node, &rect_idx, &styled_node.state) + .get_border_right_width(html_node, &rect_idx, &styled_node.state) .cloned(), }, colors: StyleBorderColors { top: layout_result .styled_dom .get_css_property_cache() - .get_border_top_color(&html_node, &rect_idx, &styled_node.state) + .get_border_top_color(html_node, &rect_idx, &styled_node.state) .cloned(), left: layout_result .styled_dom .get_css_property_cache() - .get_border_left_color(&html_node, &rect_idx, &styled_node.state) + .get_border_left_color(html_node, &rect_idx, &styled_node.state) .cloned(), bottom: layout_result .styled_dom .get_css_property_cache() - .get_border_bottom_color(&html_node, &rect_idx, &styled_node.state) + .get_border_bottom_color(html_node, &rect_idx, &styled_node.state) .cloned(), right: layout_result .styled_dom .get_css_property_cache() - .get_border_right_color(&html_node, &rect_idx, &styled_node.state) + .get_border_right_color(html_node, &rect_idx, &styled_node.state) .cloned(), }, styles: StyleBorderStyles { top: layout_result .styled_dom .get_css_property_cache() - .get_border_top_style(&html_node, &rect_idx, &styled_node.state) + .get_border_top_style(html_node, &rect_idx, &styled_node.state) .cloned(), left: layout_result .styled_dom .get_css_property_cache() - .get_border_left_style(&html_node, &rect_idx, &styled_node.state) + .get_border_left_style(html_node, &rect_idx, &styled_node.state) .cloned(), bottom: layout_result .styled_dom .get_css_property_cache() - .get_border_bottom_style(&html_node, &rect_idx, &styled_node.state) + .get_border_bottom_style(html_node, &rect_idx, &styled_node.state) .cloned(), right: layout_result .styled_dom .get_css_property_cache() - .get_border_right_style(&html_node, &rect_idx, &styled_node.state) + .get_border_right_style(html_node, &rect_idx, &styled_node.state) .cloned(), }, }) diff --git a/src/image.rs b/src/image.rs index e649285..7ebfcc8 100644 --- a/src/image.rs +++ b/src/image.rs @@ -1,6 +1,5 @@ use crate::{ColorBits, ColorSpace}; use core::fmt; -use azul_core::app_resources::ImageDescriptor; use image::GenericImageView; use serde_derive::{Deserialize, Serialize}; use std::io::Cursor; @@ -62,12 +61,7 @@ impl RawImageFormat { pub fn has_alpha(&self) -> bool { use self::RawImageFormat::*; - match self { - RGBA8 => true, - RGBA16 => true, - RGBAF32 => true, - _ => false, - } + matches!(self, RGBA8 | RGBA16 | RGBAF32) } pub fn get_color_bits_and_space(&self) -> (ColorBits, ColorSpace) { @@ -123,7 +117,7 @@ impl RawImage { image::ColorType::Rgba16 => RawImageFormat::RGBA16, image::ColorType::Rgb32F => RawImageFormat::RGBF32, image::ColorType::Rgba32F => RawImageFormat::RGBAF32, - _ => return Err(format!("invalid raw image format")), + _ => return Err("invalid raw image format".to_string()), }; let pixels = match im { @@ -137,7 +131,7 @@ impl RawImage { ImageRgba16(image_buffer) => RawImageData::U16(image_buffer.into_raw()), ImageRgb32F(image_buffer) => RawImageData::F32(image_buffer.into_raw()), ImageRgba32F(image_buffer) => RawImageData::F32(image_buffer.into_raw()), - _ => return Err(format!("invalid pixel format")), + _ => return Err("invalid pixel format".to_string()), }; Ok(RawImage { @@ -249,16 +243,15 @@ fn split_rawimage_into_rgb_plus_alpha(im: RawImage) -> (RawImageU8, Option RawImage { - use azul_core::app_resources::RawImageFormat; - RawImage { + RawImage { pixels: crate::RawImageData::U8(data.to_vec()), width: im.width, - height: im.height, + height: im.height, data_format: match im.format { RawImageFormat::R8 => crate::RawImageFormat::R8, RawImageFormat::RG8 => crate::RawImageFormat::RG8, @@ -272,7 +265,7 @@ pub(crate) fn translate_from_internal_rawimage( RawImageFormat::BGRA8 => crate::RawImageFormat::BGRA8, RawImageFormat::RGBF32 => crate::RawImageFormat::RGBF32, RawImageFormat::RGBAF32 => crate::RawImageFormat::RGBAF32, - } + }, } } diff --git a/src/serialize.rs b/src/serialize.rs index 8c9e685..233d16a 100644 --- a/src/serialize.rs +++ b/src/serialize.rs @@ -41,7 +41,8 @@ pub struct PdfSaveOptions { impl Default for PdfSaveOptions { fn default() -> Self { Self { - optimize: !(std::cfg!(debug_assertions)), + #[cfg(debug_assertions)] + optimize: std::cfg!(not(debug_assertions)), subset_fonts: true, } } @@ -135,7 +136,7 @@ pub fn serialize_pdf_into_bytes(pdf: &PdfDocument, opts: &PdfSaveOptions) -> Vec let flattened_ocg_list = layer_ids .values() - .map(|s| Reference(s.clone())) + .map(|s| Reference(*s)) .collect::>(); catalog.set( @@ -161,7 +162,7 @@ pub fn serialize_pdf_into_bytes(pdf: &PdfDocument, opts: &PdfSaveOptions) -> Vec let mut global_font_dict = LoDictionary::new(); let prepared_fonts = prepare_fonts(&pdf.resources, &pdf.pages); for (font_id, prepared) in prepared_fonts.iter() { - let font_dict = add_font_to_pdf(&mut doc, &font_id, &prepared); + let font_dict = add_font_to_pdf(&mut doc, font_id, prepared); let font_dict_id = doc.add_object(font_dict); global_font_dict.set(font_id.0.clone(), Reference(font_dict_id)); } @@ -328,16 +329,10 @@ pub fn serialize_pdf_into_bytes(pdf: &PdfDocument, opts: &PdfSaveOptions) -> Vec let prev = if i == 0 { None } else { - bookmark_ids.get(i - 1).map(|s| s.3.clone()) + bookmark_ids.get(i - 1).map(|s| s.3) }; - let next = bookmark_ids.get(i + 1).map(|s| s.3.clone()); - let dest = Array(vec![ - Reference((*pageid).clone()), - "XYZ".into(), - Null, - Null, - Null, - ]); + let next = bookmark_ids.get(i + 1).map(|s| s.3); + let dest = Array(vec![Reference(*(*pageid)), "XYZ".into(), Null, Null, Null]); let mut dict = LoDictionary::from_iter(vec![ ("Parent", Reference(bookmarks_id)), ("Title", LoString(name.to_string().into(), Literal)), @@ -371,12 +366,7 @@ pub fn serialize_pdf_into_bytes(pdf: &PdfDocument, opts: &PdfSaveOptions) -> Vec ("Count", Integer(page_ids.len() as i64)), ( "Kids", - Array( - page_ids - .iter() - .map(|q| Reference(q.clone())) - .collect::>(), - ), + Array(page_ids.iter().map(|q| Reference(*q)).collect::>()), ), ]), ); @@ -468,7 +458,7 @@ fn translate_operations( content.push(LoOp::new("ET", vec![])); } Op::WriteText { text, font, size } => { - if let Some(prepared_font) = fonts.get(&font) { + if let Some(prepared_font) = fonts.get(font) { content.push(LoOp::new( "Tf", vec![font.0.clone().into(), (size.0).into()], @@ -494,12 +484,12 @@ fn translate_operations( )); let bytes = lopdf::Document::encode_text( &lopdf::Encoding::SimpleEncoding("WinAnsiEncoding"), - &text, + text, ); content.push(LoOp::new("Tj", vec![LoString(bytes, Hexadecimal)])); } Op::WriteCodepoints { font, cp, size } => { - if let Some(prepared_font) = fonts.get(&font) { + if let Some(prepared_font) = fonts.get(font) { content.push(LoOp::new( "Tf", vec![font.0.clone().into(), (size.0).into()], @@ -528,7 +518,7 @@ fn translate_operations( } } Op::WriteCodepointsWithKerning { font, cpk, size } => { - if let Some(font) = fonts.get(&font) { + if let Some(font) = fonts.get(font) { let subset_codepoints = cpk .iter() .filter_map(|(kern, gid, ch)| { @@ -919,7 +909,7 @@ fn prepare_fonts(resources: &PdfResources, pages: &[PdfPage]) -> BTreeMap Vec { pub fn uncompress(bytes: &[u8]) -> Vec { use flate2::read::GzDecoder; - let mut gz = GzDecoder::new(&bytes[..]); + let mut gz = GzDecoder::new(bytes); let mut s = Vec::::new(); let _ = gz.read_to_end(&mut s); s diff --git a/src/wasm.rs b/src/wasm.rs index f5f208e..4f0d5e7 100644 --- a/src/wasm.rs +++ b/src/wasm.rs @@ -56,7 +56,7 @@ pub fn PrintPdfFromXml(input: String) -> String { Err(e) => PrintPdfApiReturn { pdf: String::new(), status: 1, - error: format!("failed to parse input parameters: {}", e.to_string()), + error: format!("failed to parse input parameters: {e}"), }, }; serde_json::to_string(&init).unwrap_or_default() diff --git a/src/xobject.rs b/src/xobject.rs index a4e649f..80e5742 100644 --- a/src/xobject.rs +++ b/src/xobject.rs @@ -16,7 +16,7 @@ pub enum XObject { Image(RawImage), /// Form XObject, NOT A PDF FORM, this just allows repeatable content /// on a page - Form(FormXObject), + Form(Box), /// XObject embedded from an external stream /// /// This is mainly used to add XObjects to the resources that the library @@ -33,11 +33,10 @@ impl XObject { pub fn get_width_height(&self) -> Option<(Px, Px)> { match self { XObject::Image(raw_image) => Some((Px(raw_image.width), Px(raw_image.height))), - XObject::Form(form_xobject) => form_xobject.size.clone(), - XObject::External(external_xobject) => Some(( - external_xobject.width.clone()?, - external_xobject.height.clone()?, - )), + XObject::Form(form_xobject) => form_xobject.size, + XObject::External(external_xobject) => { + Some((external_xobject.width?, external_xobject.height?)) + } } } }