# gpui: Fix drawing rotated SVGs \(\#33288\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/ccfc1ce387f0078979798137fff286a32160e454)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: ccfc1ce387f0078979798137fff286a32160e454

Requested commit: ccfc1ce387f0078979798137fff286a32160e454

Commit: ccfc1ce387f0078979798137fff286a32160e454

Tree: a40a3b21f62c3bbc25f93481abeb30e27604786d

Author: Sunli

Committer: GitHub

## Message

```
gpui: Fix drawing rotated SVGs (#33288)

Fixes: https://github.com/longbridge/gpui-component/issues/994

1. When SVG is rotated, incorrect graphics are drawn.

For example: the original aspect ratio of the SVG is 1:1, if the bounds
used to render the SVG are 400x200 (aspect ratio 2:1),
[here](https://github.com/zed-industries/zed/blob/21f985a018f7cca9c0fb7f5b7a87555486ab9db5/crates/gpui/src/svg_renderer.rs#L91)
the width is used as the scaling factor, causing the rendered SVG to
only have half the height. This PR ensures the complete SVG image is
always rendered.

2. The clipping region has no transformation applied, I added a function
called `distance_from_clip_rect_transformed` in the shader.

3. Fixed `monochrome_sprite_fragment` in `shader.metal` not applying
clipping region.

### Before:


https://github.com/user-attachments/assets/8f93ac36-281e-4837-96cd-c308bfbf92d1

### After:


https://github.com/user-attachments/assets/f52b67a6-4cb9-4d6c-b759-bbb91b59c1cf

Release Notes:

- N/A

---------

Co-authored-by: Jason Lee <huacnlee@gmail.com>
```

## Parents

- [3d4f488d46d45ee7ec99f1038b804d476586a8e4](https://git.cafe/gitcafe/zed/commit/3d4f488d46d45ee7ec99f1038b804d476586a8e4?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/ccfc1ce387f0078979798137fff286a32160e454?format=markdown)
