From 768a589576106a63b0b42af66a5cc4bc1c37dffb Mon Sep 17 00:00:00 2001 From: mforsb Date: Tue, 10 Aug 2021 00:26:59 +0200 Subject: [PATCH] Remove rust-embed as a dependency This is a rather heavy dependency that's easily replaceable using only the standard library. This brings the number of dependencies down from 368 to 362 (on Linux). --- Cargo.toml | 1 - src/main.rs | 2 -- src/renderer/fonts/font_loader.rs | 14 ++++---------- src/window/window_wrapper/mod.rs | 7 ++----- 4 files changed, 6 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 49033b1..0d5250e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,6 @@ euclid = "0.20.7" lru = "0.4.3" derive-new = "0.5" rmpv = "0.4.4" -rust-embed = { version = "5.2.0", features = ["debug-embed"] } image = { version = "0.22.3", default-features = false, features = ["ico"] } nvim-rs = { git = "https://github.com/KillTheMule/nvim-rs", branch = "master", features = ["use_tokio"] } tokio = { version = "1.1.1", features = ["full"] } diff --git a/src/main.rs b/src/main.rs index a2bbd8c..00cc727 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,8 +27,6 @@ pub mod windows_utils; #[macro_use] extern crate derive_new; #[macro_use] -extern crate rust_embed; -#[macro_use] extern crate lazy_static; use std::sync::{atomic::AtomicBool, mpsc::channel, Arc}; diff --git a/src/renderer/fonts/font_loader.rs b/src/renderer/fonts/font_loader.rs index 9021e42..6d35a1f 100644 --- a/src/renderer/fonts/font_loader.rs +++ b/src/renderer/fonts/font_loader.rs @@ -6,12 +6,8 @@ use skia_safe::{font::Edging, Data, Font, FontHinting, FontMgr, FontStyle, Typef use super::font_options::FontOptions; use super::swash_font::SwashFont; -#[derive(RustEmbed)] -#[folder = "assets/fonts/"] -pub struct Asset; - -const DEFAULT_FONT: &str = "FiraCode-Regular.ttf"; -const LAST_RESORT_FONT: &str = "LastResort-Regular.ttf"; +static DEFAULT_FONT: &[u8] = include_bytes!("../../../assets/fonts/FiraCode-Regular.ttf"); +static LAST_RESORT_FONT: &[u8] = include_bytes!("../../../assets/fonts/LastResort-Regular.ttf"); pub struct FontPair { pub skia_font: Font, @@ -141,14 +137,12 @@ impl FontLoader { FontPair::new(Font::from_typeface(typeface, self.font_size)) } FontSelection::Default => { - let default_font_data = Asset::get(DEFAULT_FONT).unwrap(); - let data = Data::new_copy(&default_font_data); + let data = Data::new_copy(DEFAULT_FONT); let typeface = Typeface::from_data(data, 0).unwrap(); FontPair::new(Font::from_typeface(typeface, self.font_size)) } FontSelection::LastResort => { - let default_font_data = Asset::get(LAST_RESORT_FONT).unwrap(); - let data = Data::new_copy(&default_font_data); + let data = Data::new_copy(LAST_RESORT_FONT); let typeface = Typeface::from_data(data, 0).unwrap(); FontPair::new(Font::from_typeface(typeface, self.font_size)) } diff --git a/src/window/window_wrapper/mod.rs b/src/window/window_wrapper/mod.rs index ddb1b54..cd74c49 100644 --- a/src/window/window_wrapper/mod.rs +++ b/src/window/window_wrapper/mod.rs @@ -41,9 +41,7 @@ use keyboard_manager::KeyboardManager; use mouse_manager::MouseManager; use renderer::SkiaRenderer; -#[derive(RustEmbed)] -#[folder = "assets/"] -struct Asset; +static ICON: &[u8] = include_bytes!("../../../assets/neovide.ico"); pub struct GlutinWindowWrapper { windowed_context: WindowedContext, @@ -221,8 +219,7 @@ pub fn create_window( running: Arc, ) { let icon = { - let icon_data = Asset::get("neovide.ico").expect("Failed to read icon data"); - let icon = load_from_memory(&icon_data).expect("Failed to parse icon data"); + let icon = load_from_memory(ICON).expect("Failed to parse icon data"); let (width, height) = icon.dimensions(); let mut rgba = Vec::with_capacity((width * height) as usize * 4); for (_, _, pixel) in icon.pixels() {