allow disabling of embedded fonts

macos-click-through
keith 5 years ago
parent 33feb45696
commit d20027a490

@ -7,8 +7,9 @@ build = "build.rs"
description = "A simple GUI for Neovim." description = "A simple GUI for Neovim."
[features] [features]
default = ["sdl2-static-link"] default = ["sdl2-static-link", "embed-fonts"]
sdl2-static-link = ["skulpin/sdl2-static-link"] sdl2-static-link = ["skulpin/sdl2-static-link"]
embed-fonts = []
[dependencies] [dependencies]
euclid = "0.20.7" euclid = "0.20.7"

@ -2,7 +2,7 @@ use std::collections::HashMap;
use lru::LruCache; use lru::LruCache;
use skulpin::skia_safe::{TextBlob, Font as SkiaFont, Typeface, TextBlobBuilder, Data}; use skulpin::skia_safe::{TextBlob, Font as SkiaFont, Typeface, TextBlobBuilder, Data};
use font_kit::{source::SystemSource, metrics::Metrics, properties::{Properties, Weight, Style, Stretch}, family_name::FamilyName, font::Font, }; use font_kit::{source::SystemSource, metrics::Metrics, properties::{Properties, Weight, Style, Stretch}, family_name::FamilyName, font::Font };
use skribo::{LayoutSession, FontRef as SkriboFont, FontFamily, FontCollection, TextStyle}; use skribo::{LayoutSession, FontRef as SkriboFont, FontFamily, FontCollection, TextStyle};
use log::{trace, info, warn}; use log::{trace, info, warn};
@ -34,7 +34,7 @@ const SYSTEM_EMOJI_FONT: &str = "Apple Color Emoji";
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
const SYSTEM_EMOJI_FONT: &str = "Noto Color Emoji"; const SYSTEM_EMOJI_FONT: &str = "Noto Color Emoji";
#[cfg(feature = "embed-fonts")]
#[derive(RustEmbed)] #[derive(RustEmbed)]
#[folder = "assets/fonts/"] #[folder = "assets/fonts/"]
struct Asset; struct Asset;
@ -61,6 +61,7 @@ pub fn add_font_to_collection_by_name(name: &str, source: &SystemSource, collect
.map(|font| collection.add_family(FontFamily::new_from_font(font))) .map(|font| collection.add_family(FontFamily::new_from_font(font)))
} }
#[cfg(feature = "embed-fonts")]
pub fn add_asset_font_to_collection(name: &str, collection: &mut FontCollection) -> Option<()> { pub fn add_asset_font_to_collection(name: &str, collection: &mut FontCollection) -> Option<()> {
Asset::get(name) Asset::get(name)
.and_then(|font_data| Font::from_bytes(font_data.to_vec().into(), 0).ok()) .and_then(|font_data| Font::from_bytes(font_data.to_vec().into(), 0).ok())
@ -95,6 +96,8 @@ pub fn build_collection_by_font_name(font_name: Option<&str>, bold: bool, italic
} }
} }
#[cfg(feature = "embed-fonts")]
{
let monospace_style = if bold { let monospace_style = if bold {
MONOSPACE_BOLD_FONT MONOSPACE_BOLD_FONT
} else { } else {
@ -103,19 +106,25 @@ pub fn build_collection_by_font_name(font_name: Option<&str>, bold: bool, italic
add_asset_font_to_collection(monospace_style, &mut collection) add_asset_font_to_collection(monospace_style, &mut collection)
.unwrap_or_else(|| warn!("Could not load embedded monospace font")); .unwrap_or_else(|| warn!("Could not load embedded monospace font"));
}
if add_font_to_collection_by_name(SYSTEM_EMOJI_FONT, &source, &mut collection).is_none() { if add_font_to_collection_by_name(SYSTEM_EMOJI_FONT, &source, &mut collection).is_none() {
#[cfg(feature = "embed-fonts")]
{
if cfg!(not(target_os = "macos")) && add_asset_font_to_collection(EMOJI_FONT, &mut collection).is_some() { if cfg!(not(target_os = "macos")) && add_asset_font_to_collection(EMOJI_FONT, &mut collection).is_some() {
info!("Fell back to embedded emoji font"); info!("Fell back to embedded emoji font");
} else { } else {
warn!("Could not load emoji font"); warn!("Could not load emoji font");
} }
} }
}
add_font_to_collection_by_name(SYSTEM_SYMBOL_FONT, &source, &mut collection) add_font_to_collection_by_name(SYSTEM_SYMBOL_FONT, &source, &mut collection)
.unwrap_or_else(|| warn!("Could not load system symbol font")); .unwrap_or_else(|| warn!("Could not load system symbol font"));
#[cfg(feature = "embed-fonts")]
{
let wide_style = if bold { let wide_style = if bold {
WIDE_BOLD_FONT WIDE_BOLD_FONT
} else { } else {
@ -127,6 +136,7 @@ pub fn build_collection_by_font_name(font_name: Option<&str>, bold: bool, italic
add_asset_font_to_collection(SYMBOL_FONT, &mut collection) add_asset_font_to_collection(SYMBOL_FONT, &mut collection)
.unwrap_or_else(|| warn!("Could not load embedded symbol font")); .unwrap_or_else(|| warn!("Could not load embedded symbol font"));
}
collection collection
} }

Loading…
Cancel
Save