Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update resvg and fontdb versions #2913

Merged
merged 2 commits into from
Jun 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ resolver="2"
rust-version = "1.66"

[workspace.dependencies]
resvg = { version= "0.32.0", default-features = false, features = ["text"] }
fontdb = { version = "0.13.1", default-features = false }
resvg = { version= "0.34.0", default-features = false, features = ["text"] }
fontdb = { version = "0.14.1", default-features = false }
yeslogic-fontconfig-sys = { version = "3.2.0", features = ["dlopen"] }
send_wrapper = { version = "0.6.0" }

Expand Down
13 changes: 6 additions & 7 deletions internal/compiler/passes/embed_images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ fn load_image(
e,
))
})?;
let scale_factor = scale_factor as f32;
// TODO: ideally we should find the size used for that `Image`
let original_size = tree.size;
let width = original_size.width() * scale_factor;
Expand All @@ -302,16 +303,14 @@ fn load_image(
image::error::LimitErrorKind::DimensionError,
))
};
let skia_buffer =
let mut skia_buffer =
tiny_skia::PixmapMut::from_bytes(buffer.as_mut_slice(), width as u32, height as u32)
.ok_or_else(size_error)?;
resvg::render(
&tree,
resvg::FitTo::Original,
let rtree = resvg::Tree::from_usvg(&tree);
rtree.render(
tiny_skia::Transform::from_scale(scale_factor as _, scale_factor as _),
skia_buffer,
)
.ok_or_else(size_error)?;
&mut skia_buffer,
);
return image::RgbaImage::from_raw(width as u32, height as u32, buffer)
.ok_or_else(size_error)
.map(|img| {
Expand Down
33 changes: 23 additions & 10 deletions internal/core/graphics/image/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use resvg::{
use usvg::TreeParsing;

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

Expand All @@ -35,7 +35,7 @@ impl core::fmt::Debug for ParsedSVG {

impl ParsedSVG {
pub fn size(&self) -> crate::graphics::IntSize {
let size = self.svg_tree.size.to_screen_size();
let size = self.svg_tree.size.to_int_size();
[size.width(), size.height()].into()
}

Expand All @@ -49,14 +49,25 @@ impl ParsedSVG {
size: euclid::Size2D<u32, PhysicalPx>,
) -> Result<SharedImageBuffer, usvg::Error> {
let tree = &self.svg_tree;
let fit = resvg::FitTo::Size(size.width, size.height);
let size = fit.fit_to(tree.size.to_screen_size()).ok_or(usvg::Error::InvalidSize)?;
let mut buffer = SharedPixelBuffer::new(size.width(), size.height());
let skia_buffer =
tiny_skia::PixmapMut::from_bytes(buffer.make_mut_bytes(), size.width(), size.height())
.ok_or(usvg::Error::InvalidSize)?;
resvg::render(tree, fit, Default::default(), skia_buffer)
.ok_or(usvg::Error::InvalidSize)?;
let target_size = tiny_skia::IntSize::from_wh(size.width, size.height)
.ok_or(usvg::Error::InvalidSize)?
.scale_to(tree.size.to_int_size());
let target_size_f = target_size.to_size();

let transform = tiny_skia::Transform::from_scale(
target_size_f.width() as f32 / tree.size.width() as f32,
target_size_f.height() as f32 / tree.size.height() as f32,
);

let mut buffer = SharedPixelBuffer::new(target_size.width(), target_size.height());
let mut skia_buffer = tiny_skia::PixmapMut::from_bytes(
buffer.make_mut_bytes(),
target_size.width(),
target_size.height(),
)
.ok_or(usvg::Error::InvalidSize)?;

tree.render(transform, &mut skia_buffer);
Ok(SharedImageBuffer::RGBA8Premultiplied(buffer))
}
}
Expand Down Expand Up @@ -85,6 +96,7 @@ 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 @@ -94,6 +106,7 @@ 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 })
})
}