gpui: Update cosmic-text and resvg dependency

This unifies the rustybuzz dependency to the same version.

Signed-off-by: Niklas Wimmer <mail@nwimmer.me>
This commit is contained in:
Niklas Wimmer 2024-03-19 19:38:22 +01:00 committed by Piotr Osiewicz
parent 97f1d61a4a
commit 007acc4bc2
4 changed files with 168 additions and 182 deletions

View file

@ -286,6 +286,7 @@ impl LinuxTextSystemState {
params.glyph_id.0 as u16,
(params.font_size * params.scale_factor).into(),
(0.0, 0.0),
cosmic_text::CacheKeyFlags::empty(),
)
.0,
)
@ -319,6 +320,7 @@ impl LinuxTextSystemState {
params.glyph_id.0 as u16,
(params.font_size * params.scale_factor).into(),
(0.0, 0.0),
cosmic_text::CacheKeyFlags::empty(),
)
.0,
)
@ -381,6 +383,7 @@ impl LinuxTextSystemState {
font_size.0,
f32::MAX, // We do our own wrapping
cosmic_text::Wrap::None,
None,
);
let mut runs = Vec::new();

View file

@ -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(&params.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
})
}