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-25 13:03:57 +01:00
committed by Piotr Osiewicz
parent 97f1d61a4a
commit 007acc4bc2
4 changed files with 168 additions and 182 deletions
+2 -4
View File
@@ -54,7 +54,7 @@ profiling.workspace = true
rand.workspace = true
raw-window-handle = "0.6"
refineable.workspace = true
resvg = "0.14"
resvg = "0.40"
schemars.workspace = true
seahash = "4.1"
serde.workspace = true
@@ -67,8 +67,6 @@ sum_tree.workspace = true
taffy = { git = "https://github.com/DioxusLabs/taffy", rev = "1876f72bee5e376023eaa518aa7b8a34c769bd1b" }
thiserror.workspace = true
time.workspace = true
tiny-skia = "0.5"
usvg = { version = "0.14", features = [] }
util.workspace = true
uuid = { version = "1.1.2", features = ["v4", "v5"] }
waker-fn = "1.1.0"
@@ -101,7 +99,7 @@ blade-graphics.workspace = true
blade-macros.workspace = true
blade-rwh.workspace = true
bytemuck = "1"
cosmic-text = "0.10.0"
cosmic-text = "0.11.2"
copypasta = "0.10.1"
[target.'cfg(target_os = "linux")'.dependencies]
@@ -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();
+22 -5
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
})
}