gpui: Update dependencies (second attempt) (#9836)
Updated version of #9741 with fixes for the problems raised in #9774. I only verified that the images no longer look blueish on Linux, because I don't have a Mac. cc @osiewicz Release Notes: - N/A --------- Signed-off-by: Niklas Wimmer <mail@nwimmer.me>
This commit is contained in:
parent
94c51c6ac9
commit
e2d6b0deba
13 changed files with 743 additions and 613 deletions
|
@ -1,6 +1,9 @@
|
|||
use crate::{AssetSource, DevicePixels, IsZero, Result, SharedString, Size};
|
||||
use anyhow::anyhow;
|
||||
use std::{hash::Hash, sync::Arc};
|
||||
use std::{
|
||||
hash::Hash,
|
||||
sync::{Arc, OnceLock},
|
||||
};
|
||||
|
||||
#[derive(Clone, PartialEq, Hash, Eq)]
|
||||
pub(crate) struct RenderSvgParams {
|
||||
|
@ -24,15 +27,19 @@ impl SvgRenderer {
|
|||
|
||||
// Load the tree.
|
||||
let bytes = self.asset_source.load(¶ms.path)?;
|
||||
let tree = usvg::Tree::from_data(&bytes, &usvg::Options::default())?;
|
||||
let tree =
|
||||
resvg::usvg::Tree::from_data(&bytes, &resvg::usvg::Options::default(), svg_fontdb())?;
|
||||
|
||||
// Render the SVG to a pixmap with the specified width and height.
|
||||
let mut pixmap =
|
||||
tiny_skia::Pixmap::new(params.size.width.into(), params.size.height.into()).unwrap();
|
||||
resvg::tiny_skia::Pixmap::new(params.size.width.into(), params.size.height.into())
|
||||
.unwrap();
|
||||
|
||||
let ratio = params.size.width.0 as f32 / tree.size().width();
|
||||
resvg::render(
|
||||
&tree,
|
||||
usvg::FitTo::Width(params.size.width.into()),
|
||||
pixmap.as_mut(),
|
||||
resvg::tiny_skia::Transform::from_scale(ratio, ratio),
|
||||
&mut pixmap.as_mut(),
|
||||
);
|
||||
|
||||
// Convert the pixmap's pixels into an alpha mask.
|
||||
|
@ -44,3 +51,13 @@ impl SvgRenderer {
|
|||
Ok(alpha_mask)
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the global font database used for SVG rendering.
|
||||
fn svg_fontdb() -> &'static resvg::usvg::fontdb::Database {
|
||||
static FONTDB: OnceLock<resvg::usvg::fontdb::Database> = OnceLock::new();
|
||||
FONTDB.get_or_init(|| {
|
||||
let mut fontdb = resvg::usvg::fontdb::Database::new();
|
||||
fontdb.load_system_fonts();
|
||||
fontdb
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue