Skip to content

Commit

Permalink
gpui: Bump crates resvg and usvg to 0.44.0 (zed-industries#20067)
Browse files Browse the repository at this point in the history
Closes zed-industries#17388

Release Notes:

- N/A

We are using gpui to build a project, and we want to render SVGs with
the `<text>` 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:
<img width="620" alt="image"
src="https://github.com/user-attachments/assets/7c71f8b1-e5fe-4e60-8f21-bb3bd9924e03">

## After:
<img width="620" alt="image"
src="https://github.com/user-attachments/assets/4b0a0602-928f-4017-b5df-859eeb5f6b4a">
  • Loading branch information
madcodelife authored Nov 6, 2024
1 parent 608addf commit e16d5c3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
22 changes: 8 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/gpui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions crates/gpui/src/svg_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down

0 comments on commit e16d5c3

Please sign in to comment.