Skip to content

Commit a366600

Browse files
authored
Merge pull request #669 from hecrj/improvement/update-resvg-and-font-kit
Update `resvg` and `font-kit`
2 parents 86361f0 + 4bbfdef commit a366600

3 files changed

Lines changed: 36 additions & 20 deletions

File tree

graphics/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ version = "0.12"
4444
optional = true
4545

4646
[dependencies.font-kit]
47-
version = "0.8"
47+
version = "0.10"
4848
optional = true
4949

5050
[package.metadata.docs.rs]

wgpu/Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ license = "MIT AND OFL-1.1"
88
repository = "https://github.com/hecrj/iced"
99

1010
[features]
11-
svg = ["resvg"]
11+
svg = ["resvg", "usvg"]
1212
canvas = ["iced_graphics/canvas"]
1313
qr_code = ["iced_graphics/qr_code"]
1414
default_system_font = ["iced_graphics/font-source"]
@@ -40,8 +40,11 @@ version = "0.23"
4040
optional = true
4141

4242
[dependencies.resvg]
43-
version = "0.9"
44-
features = ["raqote-backend"]
43+
version = "0.12"
44+
optional = true
45+
46+
[dependencies.usvg]
47+
version = "0.12"
4548
optional = true
4649

4750
[package.metadata.docs.rs]

wgpu/src/image/vector.rs

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use iced_native::svg;
33
use std::collections::{HashMap, HashSet};
44

55
pub enum Svg {
6-
Loaded(resvg::usvg::Tree),
6+
Loaded(usvg::Tree),
77
NotFound,
88
}
99

@@ -43,17 +43,15 @@ impl Cache {
4343
return self.svgs.get(&handle.id()).unwrap();
4444
}
4545

46-
let opt = resvg::Options::default();
47-
4846
let svg = match handle.data() {
4947
svg::Data::Path(path) => {
50-
match resvg::usvg::Tree::from_file(path, &opt.usvg) {
48+
match usvg::Tree::from_file(path, &Default::default()) {
5149
Ok(tree) => Svg::Loaded(tree),
5250
Err(_) => Svg::NotFound,
5351
}
5452
}
5553
svg::Data::Bytes(bytes) => {
56-
match resvg::usvg::Tree::from_data(&bytes, &opt.usvg) {
54+
match usvg::Tree::from_data(&bytes, &Default::default()) {
5755
Ok(tree) => Svg::Loaded(tree),
5856
Err(_) => Svg::NotFound,
5957
}
@@ -101,23 +99,38 @@ impl Cache {
10199
// We currently rerasterize the SVG when its size changes. This is slow
102100
// as heck. A GPU rasterizer like `pathfinder` may perform better.
103101
// It would be cool to be able to smooth resize the `svg` example.
104-
let screen_size =
105-
resvg::ScreenSize::new(width, height).unwrap();
102+
let img = resvg::render(
103+
tree,
104+
if width > height {
105+
usvg::FitTo::Width(width)
106+
} else {
107+
usvg::FitTo::Height(height)
108+
},
109+
None,
110+
)?;
111+
let width = img.width();
112+
let height = img.height();
106113

107-
let mut canvas =
108-
resvg::raqote::DrawTarget::new(width as i32, height as i32);
114+
let mut rgba = img.take().into_iter();
109115

110-
resvg::backend_raqote::render_to_canvas(
111-
tree,
112-
&resvg::Options::default(),
113-
screen_size,
114-
&mut canvas,
115-
);
116+
// TODO: Perform conversion in the GPU
117+
let bgra: Vec<u8> = std::iter::from_fn(move || {
118+
use std::iter::once;
119+
120+
let r = rgba.next()?;
121+
let g = rgba.next()?;
122+
let b = rgba.next()?;
123+
let a = rgba.next()?;
124+
125+
Some(once(b).chain(once(g)).chain(once(r)).chain(once(a)))
126+
})
127+
.flatten()
128+
.collect();
116129

117130
let allocation = texture_atlas.upload(
118131
width,
119132
height,
120-
bytemuck::cast_slice(canvas.get_data()),
133+
bytemuck::cast_slice(bgra.as_slice()),
121134
device,
122135
encoder,
123136
)?;

0 commit comments

Comments
 (0)