servo/components/shared/net
Mukilan Thiyagarajan 8a20e42de4
Add support for static SVG images using resvg crate (#36721)
This change adds support for rendering static SVG images using the
`resvg` crate, allowing svg sources in the `img` tag and in CSS
`background` and `content` properties. There are some limitations in
using resvg:

1. There is no support for animations or interactivity as these would
require implementing the full DOM layer of SVG specification.
2. Only system fonts can be used for text rendering. There is some
mechanism to provide a custom font resolver to usvg, but that is not
explored in this change.
3. resvg's handling of certain edge cases involving lack of explicit
`width` and `height` on the root svg element deviates from what the
specification expects from browsers. For example, resvg uses the values
in `viewBox` to derive the missing width or height dimension, but
without scaling that dimension to preserve the aspect ratio. It also
doesn't allow overriding this behavior.

Demo screenshot:
![servo - resvg
img](https://github.com/user-attachments/assets/8ecb2de2-ab7c-48e2-9f08-2d09d2cb8791)

<details>
<summary>Source</summary>

```
<style>
 #svg1 {
   border: 1px solid red;
 }

 #svg2 {
   border: 1px solid red;
   width: 300px;
 }
 #svg3 {
   border: 1px solid red;
   width: 300px;
   height: 200px;
   object-fit: contain;
 }
 #svg4 {
   border: 1px solid red;
   width: 300px;
   height: 200px;
   object-fit: cover;
 }
 #svg5 {
   border: 1px solid red;
   width: 300px;
   height: 200px;
   object-fit: fill;
 }
 #svg6 {
   border: 1px solid red;
   width: 300px;
   height: 200px;
   object-fit: none;
 }
</style>
</head>
<body>
        <div>
          <img id="svg1" src="https://raw.githubusercontent.com/servo/servo/refs/heads/main/resources/servo.svg" alt="Servo logo">
        </div>
        <div>
          <img id="svg2" src="https://raw.githubusercontent.com/servo/servo/refs/heads/main/resources/servo.svg" alt="Servo logo">
          <img id="svg3" src="https://raw.githubusercontent.com/servo/servo/refs/heads/main/resources/servo.svg" alt="Servo logo">
          <img id="svg4" src="https://raw.githubusercontent.com/servo/servo/refs/heads/main/resources/servo.svg" alt="Servo logo">
        </div>
        <div>
          <img id="svg5" src="https://raw.githubusercontent.com/servo/servo/refs/heads/main/resources/servo.svg" alt="Servo logo">
          <img id="svg6" src="https://raw.githubusercontent.com/servo/servo/refs/heads/main/resources/servo.svg" alt="Servo logo">
        </div>
</body>
```

</details>

---------

Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2025-05-27 11:02:40 +00:00
..
fetch Use spec compliant content-type extraction in more places and enable a <stylesheet> quirk (#28321) 2025-05-19 11:38:01 +00:00
tests [#34767] - Range header is missing from CORS header safelist (#35138) 2025-01-24 17:31:27 +00:00
blob_url_store.rs Fix more clippy warnings in components/shared/net (#31548) 2024-03-10 17:47:38 +00:00
Cargo.toml Add support for static SVG images using resvg crate (#36721) 2025-05-27 11:02:40 +00:00
filemanager_thread.rs Don't slice a sliced blob (#36866) 2025-05-06 07:25:11 +00:00
http_status.rs Update to rust 1.85 (#35628) 2025-02-24 17:44:35 +00:00
image_cache.rs Add support for static SVG images using resvg crate (#36721) 2025-05-27 11:02:40 +00:00
lib.rs Remove CoreResourceMsg::Synchronize (#37019) 2025-05-15 20:20:55 +00:00
policy_container.rs Remove referrer policy from document (#34263) 2024-11-19 12:45:10 +00:00
pub_domains.rs Add memory reporting for public suffix list (#37049) 2025-05-19 18:50:22 +00:00
quality.rs Fixes for HTTP header compliance. (#32024) 2024-04-11 21:51:23 +00:00
request.rs fix: ReadableStream::get_in_memory_bytes too large (#36914) 2025-05-12 16:00:14 +00:00
response.rs Use spec compliant content-type extraction in more places and enable a <stylesheet> quirk (#28321) 2025-05-19 11:38:01 +00:00
storage_thread.rs net: Measure memory usage of storage thread. (#37053) 2025-05-20 14:50:02 +00:00