From 1788360596c34c5c82c4ecbee179c8bd0cd42b3a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 4 Jun 2024 13:46:07 +0000 Subject: [PATCH 01/10] Bump resvg from 0.41.0 to 0.42.0 Bumps [resvg](https://github.com/RazrFalcon/resvg) from 0.41.0 to 0.42.0. - [Release notes](https://github.com/RazrFalcon/resvg/releases) - [Changelog](https://github.com/RazrFalcon/resvg/blob/master/CHANGELOG.md) - [Commits](https://github.com/RazrFalcon/resvg/compare/v0.41.0...v0.42.0) --- updated-dependencies: - dependency-name: resvg dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Cargo.lock | 31 ++++++++++++++++++------------- Cargo.toml | 2 +- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7a8ed30..8524de4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -108,14 +108,14 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a595cb550439a117696039dfc69830492058211b771a2a165379f2a1a53d84d" dependencies = [ - "roxmltree", + "roxmltree 0.19.0", ] [[package]] name = "fontdb" -version = "0.16.2" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0299020c3ef3f60f526a4f64ab4a3d4ce116b1acbf24cdd22da0068e5d81dc3" +checksum = "e32eac81c1135c1df01d4e6d4233c47ba11f6a6d07f33e0bba09d18797077770" dependencies = [ "fontconfig-parser", "log", @@ -365,15 +365,14 @@ dependencies = [ [[package]] name = "resvg" -version = "0.41.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2327ced609dadeed3e9702fec3e6b2ddd208758a9268d13e06566c6101ba533" +checksum = "944d052815156ac8fa77eaac055220e95ba0b01fa8887108ca710c03805d9051" dependencies = [ "gif", "jpeg-decoder", "log", "pico-args", - "png", "rgb", "svgtypes", "tiny-skia", @@ -405,11 +404,17 @@ version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3cd14fd5e3b777a7422cca79358c57a8f6e3a703d9ac187448d0daf220c2407f" +[[package]] +name = "roxmltree" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c20b6793b5c2fa6553b250154b78d6d0db37e72700ae35fad9387a46f487c97" + [[package]] name = "rustybuzz" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88117946aa1bfb53c2ae0643ceac6506337f44887f8c9fbfb43587b1cc52ba49" +checksum = "7730060ad401b0d1807c904ea56735288af101430aa0d2ab8358b789f5f37002" dependencies = [ "bitflags 2.5.0", "bytemuck", @@ -542,9 +547,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "ttf-parser" -version = "0.20.0" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17f77d76d837a7830fe1d4f12b7b4ba4192c1888001c7164257e4bc6d21d96b4" +checksum = "2c591d83f69777866b9126b24c6dd9a18351f177e49d625920d19f989fd31cf8" [[package]] name = "unicode-bidi" @@ -596,9 +601,9 @@ checksum = "c7de7d73e1754487cb58364ee906a499937a0dfabd86bcb980fa99ec8c8fa2ce" [[package]] name = "usvg" -version = "0.41.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c704361d822337cfc00387672c7b59eaa72a1f0744f62b2a68aa228a0c6927d" +checksum = "b84ea542ae85c715f07b082438a4231c3760539d902e11d093847a0b22963032" dependencies = [ "base64", "data-url", @@ -608,7 +613,7 @@ dependencies = [ "kurbo", "log", "pico-args", - "roxmltree", + "roxmltree 0.20.0", "rustybuzz", "simplecss", "siphasher", diff --git a/Cargo.toml b/Cargo.toml index 2622fe2..0cde560 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ crate-type = ["cdylib"] [dependencies] log = "0.4.21" pyo3 = "0.21.2" -resvg = { version = "0.41.0", features = ["raster-images","text"] } +resvg = { version = "0.42.0", features = ["raster-images","text"] } svgtypes = "0.15.1" From 685afea9223396d01875ea80ad5de8a64b68fc38 Mon Sep 17 00:00:00 2001 From: baseplate-admin <61817579+baseplate-admin@users.noreply.github.com> Date: Mon, 17 Jun 2024 21:33:31 +0600 Subject: [PATCH 02/10] Fix some errors Update lib.rs --- src/rust/lib.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/rust/lib.rs b/src/rust/lib.rs index fdfc4d5..bd09777 100644 --- a/src/rust/lib.rs +++ b/src/rust/lib.rs @@ -4,6 +4,8 @@ Based on * https://github.com/mrdotb/resvg_nif/blob/master/native/resvg/src/lib.rs */ + + use pyo3::prelude::*; use resvg; @@ -77,7 +79,7 @@ impl FitTo { ) } } -struct Opts { +struct Opts<'a> { // font_size: u32, serif_family: Option, sans_serif_family: Option, @@ -89,7 +91,7 @@ struct Opts { font_dirs: Option>, // Abstract Classes fit_to: FitTo, - usvg_opt: resvg::usvg::Options, + usvg_opt: resvg::usvg::Options<'a>, // Renderers skip_system_fonts: bool, } @@ -161,7 +163,7 @@ fn resvg_magic(mut options: Opts, svg_string: String) -> Result, String> } let tree = { - resvg::usvg::Tree::from_xmltree(&xml_tree, &options.usvg_opt, &fontdb) + resvg::usvg::Tree::from_xmltree(&xml_tree, &options.usvg_opt) .map_err(|e| e.to_string()) }?; Ok(render_svg(options, &tree)?.encode_png().unwrap()) @@ -329,6 +331,8 @@ fn svg_to_bytes( image_rendering: _image_rendering, default_size, image_href_resolver: resvg::usvg::ImageHrefResolver::default(), + font_resolver: resvg::usvg::FontResolver::default(), + fontdb: std::sync::Arc::new(resvg::usvg::fontdb::Database::new()), }; From 7c3d21fb12197828b967a10979653ada36780101 Mon Sep 17 00:00:00 2001 From: baseplate-admin <61817579+baseplate-admin@users.noreply.github.com> Date: Thu, 12 Dec 2024 18:14:52 +0600 Subject: [PATCH 03/10] Revert "Fix some errors" This reverts commit 685afea9223396d01875ea80ad5de8a64b68fc38. --- src/rust/lib.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/rust/lib.rs b/src/rust/lib.rs index bd09777..fdfc4d5 100644 --- a/src/rust/lib.rs +++ b/src/rust/lib.rs @@ -4,8 +4,6 @@ Based on * https://github.com/mrdotb/resvg_nif/blob/master/native/resvg/src/lib.rs */ - - use pyo3::prelude::*; use resvg; @@ -79,7 +77,7 @@ impl FitTo { ) } } -struct Opts<'a> { +struct Opts { // font_size: u32, serif_family: Option, sans_serif_family: Option, @@ -91,7 +89,7 @@ struct Opts<'a> { font_dirs: Option>, // Abstract Classes fit_to: FitTo, - usvg_opt: resvg::usvg::Options<'a>, + usvg_opt: resvg::usvg::Options, // Renderers skip_system_fonts: bool, } @@ -163,7 +161,7 @@ fn resvg_magic(mut options: Opts, svg_string: String) -> Result, String> } let tree = { - resvg::usvg::Tree::from_xmltree(&xml_tree, &options.usvg_opt) + resvg::usvg::Tree::from_xmltree(&xml_tree, &options.usvg_opt, &fontdb) .map_err(|e| e.to_string()) }?; Ok(render_svg(options, &tree)?.encode_png().unwrap()) @@ -331,8 +329,6 @@ fn svg_to_bytes( image_rendering: _image_rendering, default_size, image_href_resolver: resvg::usvg::ImageHrefResolver::default(), - font_resolver: resvg::usvg::FontResolver::default(), - fontdb: std::sync::Arc::new(resvg::usvg::fontdb::Database::new()), }; From 48fba972bf9b05c8ab98bb2c3fc054d355b1bd5d Mon Sep 17 00:00:00 2001 From: baseplate-admin <61817579+baseplate-admin@users.noreply.github.com> Date: Thu, 12 Dec 2024 18:28:08 +0600 Subject: [PATCH 04/10] Add --- Cargo.lock | 141 +++++++---------------------------------------------- Cargo.toml | 10 ++-- 2 files changed, 23 insertions(+), 128 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8524de4..6eb925b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "adler" @@ -137,9 +137,9 @@ dependencies = [ [[package]] name = "heck" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "imagesize" @@ -175,16 +175,6 @@ version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" -[[package]] -name = "lock_api" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "log" version = "0.4.21" @@ -225,29 +215,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "parking_lot" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets", -] - [[package]] name = "pico-args" version = "0.5.0" @@ -275,24 +242,24 @@ checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0" [[package]] name = "proc-macro2" -version = "1.0.79" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] [[package]] name = "pyo3" -version = "0.21.2" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e00b96a521718e08e03b1a622f01c8a8deb50719335de3f60b3b3950f069d8" +checksum = "e484fd2c8b4cb67ab05a318f1fd6fa8f199fcc30819f08f07d200809dba26c15" dependencies = [ "cfg-if", "indoc", "libc", "memoffset", - "parking_lot", + "once_cell", "portable-atomic", "pyo3-build-config", "pyo3-ffi", @@ -302,9 +269,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.21.2" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7883df5835fafdad87c0d888b266c8ec0f4c9ca48a5bed6bbb592e8dedee1b50" +checksum = "dc0e0469a84f208e20044b98965e1561028180219e35352a2afaf2b942beff3b" dependencies = [ "once_cell", "target-lexicon", @@ -312,9 +279,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.21.2" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01be5843dc60b916ab4dad1dca6d20b9b4e6ddc8e15f50c47fe6d85f1fb97403" +checksum = "eb1547a7f9966f6f1a0f0227564a9945fe36b90da5a93b3933fc3dc03fae372d" dependencies = [ "libc", "pyo3-build-config", @@ -322,9 +289,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.21.2" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77b34069fc0682e11b31dbd10321cbf94808394c56fd996796ce45217dfac53c" +checksum = "fdb6da8ec6fa5cedd1626c886fc8749bdcbb09424a86461eb8cdf096b7c33257" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -334,9 +301,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.21.2" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08260721f32db5e1a5beae69a55553f56b99bd0e1c3e6e0a5e8851a9d0f5a85c" +checksum = "38a385202ff5a92791168b1136afae5059d3ac118457bb7bc304c197c2d33e7d" dependencies = [ "heck", "proc-macro2", @@ -354,15 +321,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "resvg" version = "0.42.0" @@ -426,12 +384,6 @@ dependencies = [ "unicode-script", ] -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "simd-adler32" version = "0.3.7" @@ -489,9 +441,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.58" +version = "2.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" +checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" dependencies = [ "proc-macro2", "quote", @@ -638,63 +590,6 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - [[package]] name = "xmlwriter" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 0cde560..2dc3bee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,19 +11,19 @@ crate-type = ["cdylib"] [dependencies] log = "0.4.21" -pyo3 = "0.21.2" -resvg = { version = "0.42.0", features = ["raster-images","text"] } +pyo3 = "0.23.2" +resvg = { version = "0.42.0", features = ["raster-images", "text"] } svgtypes = "0.15.1" [profile.release.package."*"] codegen-units = 1 -opt-level ='z' +opt-level = 'z' strip = true [profile.release] panic = "abort" codegen-units = 1 lto = "fat" -opt-level ='z' -strip = true \ No newline at end of file +opt-level = 'z' +strip = true From 191c6c362b07bdb2a12bd44fe43370636702e943 Mon Sep 17 00:00:00 2001 From: baseplate-admin <61817579+baseplate-admin@users.noreply.github.com> Date: Thu, 12 Dec 2024 18:25:31 +0600 Subject: [PATCH 05/10] add --- Cargo.toml | 2 +- src/rust/lib.rs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2dc3bee..7caa1f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ crate-type = ["cdylib"] [dependencies] log = "0.4.21" -pyo3 = "0.23.2" +pyo3 = "0.21.2" resvg = { version = "0.42.0", features = ["raster-images", "text"] } svgtypes = "0.15.1" diff --git a/src/rust/lib.rs b/src/rust/lib.rs index fdfc4d5..30d34ee 100644 --- a/src/rust/lib.rs +++ b/src/rust/lib.rs @@ -5,7 +5,7 @@ Based on */ use pyo3::prelude::*; -use resvg; +use resvg::{self, usvg::FontResolver}; #[derive(Clone, Copy, PartialEq, Debug)] @@ -151,7 +151,6 @@ fn resvg_magic(mut options: Opts, svg_string: String) -> Result, String> .descendants() .any(|n| n.has_tag_name(("http://www.w3.org/2000/svg", "text"))); - let mut fontdb = resvg::usvg::fontdb::Database::new(); if !options.skip_system_fonts { fontdb.load_system_fonts(); } @@ -161,7 +160,7 @@ fn resvg_magic(mut options: Opts, svg_string: String) -> Result, String> } let tree = { - resvg::usvg::Tree::from_xmltree(&xml_tree, &options.usvg_opt, &fontdb) + resvg::usvg::Tree::from_xmltree(&xml_tree, &options.usvg_opt) .map_err(|e| e.to_string()) }?; Ok(render_svg(options, &tree)?.encode_png().unwrap()) @@ -329,6 +328,8 @@ fn svg_to_bytes( image_rendering: _image_rendering, default_size, image_href_resolver: resvg::usvg::ImageHrefResolver::default(), + fontdb: resvg::usvg::fontdb::Database::new(), + font_resolver:FontResolver::default() }; From 70e5dcb5e68a11d762b9c0e8fe5e0484c5dcece5 Mon Sep 17 00:00:00 2001 From: baseplate-admin <61817579+baseplate-admin@users.noreply.github.com> Date: Thu, 12 Dec 2024 18:28:33 +0600 Subject: [PATCH 06/10] add --- Cargo.lock | 138 +++++++++++++++++++++++++++++++++++++++++++----- Cargo.toml | 2 +- src/rust/lib.rs | 7 +-- 3 files changed, 130 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6eb925b..57a8a07 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -137,9 +137,9 @@ dependencies = [ [[package]] name = "heck" -version = "0.5.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "imagesize" @@ -175,6 +175,16 @@ version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.21" @@ -215,6 +225,29 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + [[package]] name = "pico-args" version = "0.5.0" @@ -251,15 +284,15 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.23.3" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e484fd2c8b4cb67ab05a318f1fd6fa8f199fcc30819f08f07d200809dba26c15" +checksum = "a5e00b96a521718e08e03b1a622f01c8a8deb50719335de3f60b3b3950f069d8" dependencies = [ "cfg-if", "indoc", "libc", "memoffset", - "once_cell", + "parking_lot", "portable-atomic", "pyo3-build-config", "pyo3-ffi", @@ -269,9 +302,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.23.3" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc0e0469a84f208e20044b98965e1561028180219e35352a2afaf2b942beff3b" +checksum = "7883df5835fafdad87c0d888b266c8ec0f4c9ca48a5bed6bbb592e8dedee1b50" dependencies = [ "once_cell", "target-lexicon", @@ -279,9 +312,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.23.3" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb1547a7f9966f6f1a0f0227564a9945fe36b90da5a93b3933fc3dc03fae372d" +checksum = "01be5843dc60b916ab4dad1dca6d20b9b4e6ddc8e15f50c47fe6d85f1fb97403" dependencies = [ "libc", "pyo3-build-config", @@ -289,9 +322,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.23.3" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdb6da8ec6fa5cedd1626c886fc8749bdcbb09424a86461eb8cdf096b7c33257" +checksum = "77b34069fc0682e11b31dbd10321cbf94808394c56fd996796ce45217dfac53c" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -301,9 +334,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.23.3" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38a385202ff5a92791168b1136afae5059d3ac118457bb7bc304c197c2d33e7d" +checksum = "08260721f32db5e1a5beae69a55553f56b99bd0e1c3e6e0a5e8851a9d0f5a85c" dependencies = [ "heck", "proc-macro2", @@ -321,6 +354,15 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "redox_syscall" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834" +dependencies = [ + "bitflags 2.5.0", +] + [[package]] name = "resvg" version = "0.42.0" @@ -384,6 +426,12 @@ dependencies = [ "unicode-script", ] +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + [[package]] name = "simd-adler32" version = "0.3.7" @@ -590,6 +638,70 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + [[package]] name = "xmlwriter" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 2dc3bee..7caa1f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ crate-type = ["cdylib"] [dependencies] log = "0.4.21" -pyo3 = "0.23.2" +pyo3 = "0.21.2" resvg = { version = "0.42.0", features = ["raster-images", "text"] } svgtypes = "0.15.1" diff --git a/src/rust/lib.rs b/src/rust/lib.rs index fdfc4d5..30d34ee 100644 --- a/src/rust/lib.rs +++ b/src/rust/lib.rs @@ -5,7 +5,7 @@ Based on */ use pyo3::prelude::*; -use resvg; +use resvg::{self, usvg::FontResolver}; #[derive(Clone, Copy, PartialEq, Debug)] @@ -151,7 +151,6 @@ fn resvg_magic(mut options: Opts, svg_string: String) -> Result, String> .descendants() .any(|n| n.has_tag_name(("http://www.w3.org/2000/svg", "text"))); - let mut fontdb = resvg::usvg::fontdb::Database::new(); if !options.skip_system_fonts { fontdb.load_system_fonts(); } @@ -161,7 +160,7 @@ fn resvg_magic(mut options: Opts, svg_string: String) -> Result, String> } let tree = { - resvg::usvg::Tree::from_xmltree(&xml_tree, &options.usvg_opt, &fontdb) + resvg::usvg::Tree::from_xmltree(&xml_tree, &options.usvg_opt) .map_err(|e| e.to_string()) }?; Ok(render_svg(options, &tree)?.encode_png().unwrap()) @@ -329,6 +328,8 @@ fn svg_to_bytes( image_rendering: _image_rendering, default_size, image_href_resolver: resvg::usvg::ImageHrefResolver::default(), + fontdb: resvg::usvg::fontdb::Database::new(), + font_resolver:FontResolver::default() }; From adbb6ca00f19dcd8f9a321d658de85c65e43bcee Mon Sep 17 00:00:00 2001 From: baseplate-admin <61817579+baseplate-admin@users.noreply.github.com> Date: Thu, 12 Dec 2024 18:35:29 +0600 Subject: [PATCH 07/10] r --- Cargo.lock | 138 +++++------------------------------------------- Cargo.toml | 2 +- src/rust/lib.rs | 8 +-- 3 files changed, 19 insertions(+), 129 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 57a8a07..6eb925b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -137,9 +137,9 @@ dependencies = [ [[package]] name = "heck" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "imagesize" @@ -175,16 +175,6 @@ version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "log" version = "0.4.21" @@ -225,29 +215,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "parking_lot" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets", -] - [[package]] name = "pico-args" version = "0.5.0" @@ -284,15 +251,15 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.21.2" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e00b96a521718e08e03b1a622f01c8a8deb50719335de3f60b3b3950f069d8" +checksum = "e484fd2c8b4cb67ab05a318f1fd6fa8f199fcc30819f08f07d200809dba26c15" dependencies = [ "cfg-if", "indoc", "libc", "memoffset", - "parking_lot", + "once_cell", "portable-atomic", "pyo3-build-config", "pyo3-ffi", @@ -302,9 +269,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.21.2" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7883df5835fafdad87c0d888b266c8ec0f4c9ca48a5bed6bbb592e8dedee1b50" +checksum = "dc0e0469a84f208e20044b98965e1561028180219e35352a2afaf2b942beff3b" dependencies = [ "once_cell", "target-lexicon", @@ -312,9 +279,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.21.2" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01be5843dc60b916ab4dad1dca6d20b9b4e6ddc8e15f50c47fe6d85f1fb97403" +checksum = "eb1547a7f9966f6f1a0f0227564a9945fe36b90da5a93b3933fc3dc03fae372d" dependencies = [ "libc", "pyo3-build-config", @@ -322,9 +289,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.21.2" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77b34069fc0682e11b31dbd10321cbf94808394c56fd996796ce45217dfac53c" +checksum = "fdb6da8ec6fa5cedd1626c886fc8749bdcbb09424a86461eb8cdf096b7c33257" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -334,9 +301,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.21.2" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08260721f32db5e1a5beae69a55553f56b99bd0e1c3e6e0a5e8851a9d0f5a85c" +checksum = "38a385202ff5a92791168b1136afae5059d3ac118457bb7bc304c197c2d33e7d" dependencies = [ "heck", "proc-macro2", @@ -354,15 +321,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834" -dependencies = [ - "bitflags 2.5.0", -] - [[package]] name = "resvg" version = "0.42.0" @@ -426,12 +384,6 @@ dependencies = [ "unicode-script", ] -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "simd-adler32" version = "0.3.7" @@ -638,70 +590,6 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" -[[package]] -name = "windows-targets" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" - [[package]] name = "xmlwriter" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 7caa1f1..9935011 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ crate-type = ["cdylib"] [dependencies] log = "0.4.21" -pyo3 = "0.21.2" +pyo3 = "0.23.0" resvg = { version = "0.42.0", features = ["raster-images", "text"] } svgtypes = "0.15.1" diff --git a/src/rust/lib.rs b/src/rust/lib.rs index 30d34ee..2b40cac 100644 --- a/src/rust/lib.rs +++ b/src/rust/lib.rs @@ -77,7 +77,7 @@ impl FitTo { ) } } -struct Opts { +struct Opts<'a> { // font_size: u32, serif_family: Option, sans_serif_family: Option, @@ -89,7 +89,7 @@ struct Opts { font_dirs: Option>, // Abstract Classes fit_to: FitTo, - usvg_opt: resvg::usvg::Options, + usvg_opt: resvg::usvg::Options<'a>, // Renderers skip_system_fonts: bool, } @@ -226,6 +226,7 @@ fn svg_to_bytes( image_rendering: Option, ) -> PyResult> { + if log_information.unwrap_or(false) { if let Ok(()) = log::set_logger(&LOGGER) { log::set_max_level(log::LevelFilter::Warn); @@ -233,6 +234,7 @@ fn svg_to_bytes( } let mut _svg_string = String::new(); +let fontdb = resvg::usvg::fontdb::Database::new().into(); if let Some(svg_string) = svg_string { _svg_string = svg_string; @@ -328,7 +330,7 @@ fn svg_to_bytes( image_rendering: _image_rendering, default_size, image_href_resolver: resvg::usvg::ImageHrefResolver::default(), - fontdb: resvg::usvg::fontdb::Database::new(), + fontdb:fontdb, font_resolver:FontResolver::default() }; From 1fca098dd0ed782a69a8ddf8de60fc55de8a3779 Mon Sep 17 00:00:00 2001 From: baseplate-admin <61817579+baseplate-admin@users.noreply.github.com> Date: Thu, 12 Dec 2024 18:46:04 +0600 Subject: [PATCH 08/10] d --- src/rust/lib.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/rust/lib.rs b/src/rust/lib.rs index 2b40cac..f8cf132 100644 --- a/src/rust/lib.rs +++ b/src/rust/lib.rs @@ -4,8 +4,10 @@ Based on * https://github.com/mrdotb/resvg_nif/blob/master/native/resvg/src/lib.rs */ +use std::sync::Arc; + use pyo3::prelude::*; -use resvg::{self, usvg::FontResolver}; +use resvg::{self, usvg::{fontdb, FontResolver}}; #[derive(Clone, Copy, PartialEq, Debug)] @@ -94,9 +96,12 @@ struct Opts<'a> { skip_system_fonts: bool, } -fn load_fonts(options: &mut Opts, fontdb: &mut resvg::usvg::fontdb::Database) { + +fn load_fonts(options: &mut Opts,fontdb: resvg::usvg::fontdb::Database) { + if let Some(font_files) = &options.font_files { for path in font_files { + let fontdb = fontdb.unwrap(); // Lock the mutex to access fontdb mutably if let Err(e) = fontdb.load_font_file(path) { log::warn!("Failed to load '{}' cause {}.", path.to_string(), e); } @@ -105,6 +110,7 @@ fn load_fonts(options: &mut Opts, fontdb: &mut resvg::usvg::fontdb::Database) { if let Some(font_dirs) = &options.font_dirs { for path in font_dirs { + let fontdb = fontdb.lock().unwrap(); // Lock the mutex to access fontdb mutably fontdb.load_fonts_dir(path); } } @@ -112,6 +118,8 @@ fn load_fonts(options: &mut Opts, fontdb: &mut resvg::usvg::fontdb::Database) { let take_or = |family: Option, fallback: &str| family.unwrap_or_else(|| fallback.to_string()); + // Use lock to modify the fontdb mutably + let mut fontdb = fontdb.lock().unwrap(); fontdb.set_serif_family(take_or(options.serif_family.take(), "Times New Roman")); fontdb.set_sans_serif_family(take_or(options.sans_serif_family.take(), "Arial")); fontdb.set_cursive_family(take_or(options.cursive_family.take(), "Comic Sans MS")); @@ -150,13 +158,15 @@ fn resvg_magic(mut options: Opts, svg_string: String) -> Result, String> let has_text_nodes = xml_tree .descendants() .any(|n| n.has_tag_name(("http://www.w3.org/2000/svg", "text"))); + let mut fontdb = resvg::usvg::fontdb::Database::new(); + if !options.skip_system_fonts { fontdb.load_system_fonts(); } if has_text_nodes { - load_fonts(&mut options, &mut fontdb); + load_fonts(&mut options,fontdb); } let tree = { @@ -234,8 +244,6 @@ fn svg_to_bytes( } let mut _svg_string = String::new(); -let fontdb = resvg::usvg::fontdb::Database::new().into(); - if let Some(svg_string) = svg_string { _svg_string = svg_string; } @@ -319,6 +327,7 @@ let fontdb = resvg::usvg::fontdb::Database::new().into(); None => None, }; + let usvg_options = resvg::usvg::Options { resources_dir: _resources_dir, dpi: dpi.unwrap_or(0) as f32, @@ -330,7 +339,7 @@ let fontdb = resvg::usvg::fontdb::Database::new().into(); image_rendering: _image_rendering, default_size, image_href_resolver: resvg::usvg::ImageHrefResolver::default(), - fontdb:fontdb, + fontdb:resvg::usvg::fontdb::Database::new().into(), font_resolver:FontResolver::default() }; From 19418146c4626957983d033f256a88f5ff25f974 Mon Sep 17 00:00:00 2001 From: baseplate-admin <61817579+baseplate-admin@users.noreply.github.com> Date: Thu, 12 Dec 2024 18:47:56 +0600 Subject: [PATCH 09/10] Update lib.rs --- src/rust/lib.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/rust/lib.rs b/src/rust/lib.rs index f8cf132..6956b93 100644 --- a/src/rust/lib.rs +++ b/src/rust/lib.rs @@ -4,10 +4,8 @@ Based on * https://github.com/mrdotb/resvg_nif/blob/master/native/resvg/src/lib.rs */ -use std::sync::Arc; - use pyo3::prelude::*; -use resvg::{self, usvg::{fontdb, FontResolver}}; +use resvg::{self, usvg::FontResolver}; #[derive(Clone, Copy, PartialEq, Debug)] @@ -97,11 +95,10 @@ struct Opts<'a> { } -fn load_fonts(options: &mut Opts,fontdb: resvg::usvg::fontdb::Database) { +fn load_fonts(options: &mut Opts,fontdb: &mut resvg::usvg::fontdb::Database) { if let Some(font_files) = &options.font_files { for path in font_files { - let fontdb = fontdb.unwrap(); // Lock the mutex to access fontdb mutably if let Err(e) = fontdb.load_font_file(path) { log::warn!("Failed to load '{}' cause {}.", path.to_string(), e); } @@ -110,7 +107,6 @@ fn load_fonts(options: &mut Opts,fontdb: resvg::usvg::fontdb::Database) { if let Some(font_dirs) = &options.font_dirs { for path in font_dirs { - let fontdb = fontdb.lock().unwrap(); // Lock the mutex to access fontdb mutably fontdb.load_fonts_dir(path); } } @@ -119,7 +115,6 @@ fn load_fonts(options: &mut Opts,fontdb: resvg::usvg::fontdb::Database) { |family: Option, fallback: &str| family.unwrap_or_else(|| fallback.to_string()); // Use lock to modify the fontdb mutably - let mut fontdb = fontdb.lock().unwrap(); fontdb.set_serif_family(take_or(options.serif_family.take(), "Times New Roman")); fontdb.set_sans_serif_family(take_or(options.sans_serif_family.take(), "Arial")); fontdb.set_cursive_family(take_or(options.cursive_family.take(), "Comic Sans MS")); @@ -166,7 +161,7 @@ fn resvg_magic(mut options: Opts, svg_string: String) -> Result, String> } if has_text_nodes { - load_fonts(&mut options,fontdb); + load_fonts(&mut options,&mut fontdb); } let tree = { From b62a234e131da832d42d4dbeb270c035f23a78f0 Mon Sep 17 00:00:00 2001 From: baseplate-admin <61817579+baseplate-admin@users.noreply.github.com> Date: Thu, 12 Dec 2024 18:53:24 +0600 Subject: [PATCH 10/10] Update lib.rs --- src/rust/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/rust/lib.rs b/src/rust/lib.rs index 0e5d002..b8e15b3 100644 --- a/src/rust/lib.rs +++ b/src/rust/lib.rs @@ -5,7 +5,7 @@ Based on */ use pyo3::prelude::*; -use resvg::{self, usvg::FontResolver}; +use resvg::{self, usvg::{FontResolver}}; #[derive(Clone, Copy, PartialEq, Debug)] @@ -141,7 +141,7 @@ fn render_svg(options: Opts, tree: &resvg::usvg::Tree) -> Result Result, String> { +fn resvg_magic(mut options: Opts, svg_string: String,fontdb: &mut resvg::usvg::fontdb::Database ) -> Result, String> { let xml_tree = { let xml_opt = resvg::usvg::roxmltree::ParsingOptions { allow_dtd: true, @@ -153,7 +153,6 @@ fn resvg_magic(mut options: Opts, svg_string: String) -> Result, String> let has_text_nodes = xml_tree .descendants() .any(|n| n.has_tag_name(("http://www.w3.org/2000/svg", "text"))); - let mut fontdb = resvg::usvg::fontdb::Database::new(); if !options.skip_system_fonts { @@ -161,7 +160,7 @@ fn resvg_magic(mut options: Opts, svg_string: String) -> Result, String> } if has_text_nodes { - load_fonts(&mut options,&mut fontdb); + load_fonts(&mut options,fontdb); } let tree = { @@ -322,6 +321,7 @@ fn svg_to_bytes( None => None, }; + let mut fontdb = resvg::usvg::fontdb::Database::new(); let usvg_options = resvg::usvg::Options { resources_dir: _resources_dir, @@ -334,7 +334,7 @@ fn svg_to_bytes( image_rendering: _image_rendering, default_size, image_href_resolver: resvg::usvg::ImageHrefResolver::default(), - fontdb:resvg::usvg::fontdb::Database::new().into(), + fontdb:fontdb.clone().into(), font_resolver:FontResolver::default() }; @@ -353,7 +353,7 @@ fn svg_to_bytes( font_files, font_dirs, }; - let pixmap = resvg_magic(options, _svg_string.trim().to_owned()).unwrap(); + let pixmap = resvg_magic(options, _svg_string.trim().to_owned(),&mut fontdb).unwrap(); Ok(pixmap) }