From e16d5c3a683b055bbc2cce2948781a519d060389 Mon Sep 17 00:00:00 2001 From: Floyd Wang Date: Thu, 7 Nov 2024 03:40:22 +0800 Subject: [PATCH] gpui: Bump crates resvg and usvg to 0.44.0 (#20067) Closes #17388 Release Notes: - N/A We are using gpui to build a project, and we want to render SVGs with the `` tag. We use `resvg` and `usvg` with the same version as gpui, like `0.41.0`. However, when we enable the feature `text`, we get an error from `usvg`. ```shell error[E0061]: this function takes 3 arguments but 2 arguments were supplied --> /Users/madcodelife/.cargo/git/checkouts/zed-23e65a6dff445450/e681a4b/crates/gpui/src/svg_renderer.rs:49:20 | 49 | let tree = usvg::Tree::from_data(bytes, &usvg::Options::default())?; | ^^^^^^^^^^^^^^^^^^^^^---------------------------------- argument #3 of type `&Database` is missing | ``` This error occurs because when the `text` feature is enabled, the `form_data` function needs an extra argument, `fontdb`. [The code is here](https://github.com/linebender/resvg/blob/fb7e28513f561ed847acbf4a6fb8b743474837a0/crates/usvg/src/parser/mod.rs#L98). They changed the API in version [`0.42.0`](https://github.com/linebender/resvg/blob/b1d06e9463a3b089fbd70e7c38aebbfc811311ff/crates/usvg/src/parser/mod.rs#L98). So, I updated the versions to the latest (0.44.0). This is our demo: ## Before: image ## After: image --- Cargo.lock | 22 ++++++++-------------- crates/gpui/Cargo.toml | 4 ++-- crates/gpui/src/svg_renderer.rs | 6 ++---- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a526be8c8f6aa6..89c38a10f3eb9c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4474,7 +4474,7 @@ version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1fcfcd44ca6e90c921fee9fa665d530b21ef1327a4c1a6c5250ea44b776ada7" dependencies = [ - "roxmltree 0.20.0", + "roxmltree", ] [[package]] @@ -5814,9 +5814,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 = "imgref" @@ -9793,9 +9793,9 @@ dependencies = [ [[package]] name = "resvg" -version = "0.41.0" +version = "0.44.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2327ced609dadeed3e9702fec3e6b2ddd208758a9268d13e06566c6101ba533" +checksum = "4a325d5e8d1cebddd070b13f44cec8071594ab67d1012797c121f27a669b7958" dependencies = [ "log", "pico-args", @@ -9948,12 +9948,6 @@ dependencies = [ "util", ] -[[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" @@ -13210,9 +13204,9 @@ checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" [[package]] name = "usvg" -version = "0.41.0" +version = "0.44.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c704361d822337cfc00387672c7b59eaa72a1f0744f62b2a68aa228a0c6927d" +checksum = "7447e703d7223b067607655e625e0dbca80822880248937da65966194c4864e6" dependencies = [ "base64 0.22.1", "data-url", @@ -13221,7 +13215,7 @@ dependencies = [ "kurbo", "log", "pico-args", - "roxmltree 0.19.0", + "roxmltree", "simplecss", "siphasher 1.0.1", "strict-num", diff --git a/crates/gpui/Cargo.toml b/crates/gpui/Cargo.toml index b7fafb805809d1..3a4fdd5014107e 100644 --- a/crates/gpui/Cargo.toml +++ b/crates/gpui/Cargo.toml @@ -90,8 +90,8 @@ profiling.workspace = true rand = { optional = true, workspace = true } raw-window-handle = "0.6" refineable.workspace = true -resvg = { version = "0.41.0", default-features = false } -usvg = { version = "0.41.0", default-features = false } +resvg = { version = "0.44.0", default-features = false } +usvg = { version = "0.44.0", default-features = false } schemars.workspace = true seahash = "4.1" semantic_version.workspace = true diff --git a/crates/gpui/src/svg_renderer.rs b/crates/gpui/src/svg_renderer.rs index c465eec7848fa3..a5cbb6737280de 100644 --- a/crates/gpui/src/svg_renderer.rs +++ b/crates/gpui/src/svg_renderer.rs @@ -60,10 +60,8 @@ impl SvgRenderer { let mut pixmap = resvg::tiny_skia::Pixmap::new(size.width.into(), size.height.into()) .ok_or(usvg::Error::InvalidSize)?; - let transform = tree.view_box().to_transform( - resvg::tiny_skia::Size::from_wh(size.width.0 as f32, size.height.0 as f32) - .ok_or(usvg::Error::InvalidSize)?, - ); + let scale = size.width.0 as f32 / tree.size().width(); + let transform = resvg::tiny_skia::Transform::from_scale(scale, scale); resvg::render(&tree, transform, &mut pixmap.as_mut());