Skip to content

Commit

Permalink
Update resvg and related dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ogoffart committed Jan 22, 2024
1 parent 5a43f3b commit c7aae4b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ slint-macros = { version = "=1.4.0", path = "api/rs/macros", default-features =
bytemuck = { version = "1.13.1" }
cbindgen = { version = "0.26", default-features = false }
css-color-parser2 = { version = "1.0.1" }
fontdb = { version = "0.15.0", default-features = false }
fontdb = { version = "0.16.0", default-features = false }
fontdue = { version = "0.8.0" }
glutin = { version = "0.31.1", default-features = false }
itertools = { version = "0.12" }
resvg = { version= "0.36.0", default-features = false, features = ["text"] }
resvg = { version= "0.38.0", default-features = false, features = ["text"] }
send_wrapper = { version = "0.6.0" }
softbuffer = { version = "0.3.3", default-features = false }
toml_edit = { version = "0.21" }
Expand Down
13 changes: 8 additions & 5 deletions internal/compiler/passes/embed_images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,15 @@ fn load_image(
) -> image::ImageResult<(image::RgbaImage, SourceFormat, Size)> {
use resvg::{tiny_skia, usvg};
use std::ffi::OsStr;
use usvg::TreeParsing;
use usvg::{TreeParsing, TreePostProc as _};
if file.canon_path.extension() == Some(OsStr::new("svg"))
|| file.canon_path.extension() == Some(OsStr::new("svgz"))
{
let options = usvg::Options::default();
let tree = match file.builtin_contents {
let mut tree = match file.builtin_contents {
Some(data) => usvg::Tree::from_data(data, &options),
None => usvg::Tree::from_data(
std::fs::read(file.canon_path).map_err(image::ImageError::IoError)?.as_slice(),
std::fs::read(&file.canon_path).map_err(image::ImageError::IoError)?.as_slice(),
&options,
),
}
Expand All @@ -380,6 +380,9 @@ fn load_image(
e,
))
})?;
i_slint_common::sharedfontdb::FONT_DB.with(|db| {
tree.postprocess(Default::default(), &db.borrow());
});
let scale_factor = scale_factor as f32;
// TODO: ideally we should find the size used for that `Image`
let original_size = tree.size;
Expand All @@ -395,8 +398,8 @@ fn load_image(
let mut skia_buffer =
tiny_skia::PixmapMut::from_bytes(buffer.as_mut_slice(), width as u32, height as u32)
.ok_or_else(size_error)?;
let rtree = resvg::Tree::from_usvg(&tree);
rtree.render(
resvg::render(
&tree,
tiny_skia::Transform::from_scale(scale_factor as _, scale_factor as _),
&mut skia_buffer,
);
Expand Down
9 changes: 3 additions & 6 deletions internal/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,14 @@ web-sys = { version = "0.3", features = [ "HtmlImageElement" ] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
fontdb = { workspace = true, optional = true, default-features = true }
rustybuzz = { version = "0.11.0", optional = true }
rustybuzz = { version = "0.12.0", optional = true }
fontdue = { workspace = true, optional = true }

[dev-dependencies]
slint = { path = "../../api/rs/slint", default-features = false, features = ["std", "compat-1-2"] }
i-slint-backend-testing = { path="../backends/testing" }
rustybuzz = "0.11.0"
rustybuzz = "0.12.0"
ttf-parser = "0.20.0"
fontdb = { workspace = true, default-features = true }
serde_json = "1.0.96"

image = { version = "0.24.0", default-features = false, features = [ "png" ] }
pin-weak = "1"
tiny-skia = "0.9.0"
tiny-skia = "0.11.0"
15 changes: 5 additions & 10 deletions internal/core/graphics/image/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ use super::{ImageCacheKey, SharedImageBuffer, SharedPixelBuffer};
use crate::lengths::PhysicalPx;
#[cfg(not(target_arch = "wasm32"))]
use crate::SharedString;
use resvg::{
tiny_skia,
usvg::{self, TreeTextToPath},
};
use usvg::TreeParsing;
use resvg::{tiny_skia, usvg};
use usvg::{TreeParsing, TreePostProc};

pub struct ParsedSVG {
svg_tree: resvg::Tree,
svg_tree: usvg::Tree,
cache_key: ImageCacheKey,
}

Expand Down Expand Up @@ -75,7 +72,7 @@ impl ParsedSVG {
)
.ok_or(usvg::Error::InvalidSize)?;

tree.render(transform, &mut skia_buffer);
resvg::render(&tree, transform, &mut skia_buffer);
Ok(SharedImageBuffer::RGBA8Premultiplied(buffer))
}
}
Expand All @@ -88,7 +85,7 @@ fn with_svg_options<T>(callback: impl FnOnce(&usvg::Options) -> T) -> T {
fn fixup_text(mut tree: usvg::Tree) -> usvg::Tree {
if tree.has_text_nodes() {
i_slint_common::sharedfontdb::FONT_DB.with(|db| {
tree.convert_text(&db.borrow());
tree.postprocess(Default::default(), &db.borrow());
})
}
tree
Expand All @@ -104,7 +101,6 @@ pub fn load_from_path(
with_svg_options(|options| {
usvg::Tree::from_data(&svg_data, options)
.map(fixup_text)
.map(|usvg_tree| resvg::Tree::from_usvg(&usvg_tree))
.map(|svg| ParsedSVG { svg_tree: svg, cache_key })
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))
})
Expand All @@ -114,7 +110,6 @@ pub fn load_from_data(slice: &[u8], cache_key: ImageCacheKey) -> Result<ParsedSV
with_svg_options(|options| {
usvg::Tree::from_data(slice, options)
.map(fixup_text)
.map(|usvg_tree| resvg::Tree::from_usvg(&usvg_tree))
.map(|svg| ParsedSVG { svg_tree: svg, cache_key })
})
}

0 comments on commit c7aae4b

Please sign in to comment.