diff --git a/assets/fonts/DejaVuSansMono.ttf b/assets/fonts/DejaVuSansMono.ttf new file mode 100644 index 0000000..f578602 Binary files /dev/null and b/assets/fonts/DejaVuSansMono.ttf differ diff --git a/assets/fonts/Fira Code Bold Nerd Font Complete.otf b/assets/fonts/Fira Code Bold Nerd Font Complete.otf new file mode 100644 index 0000000..98c4353 Binary files /dev/null and b/assets/fonts/Fira Code Bold Nerd Font Complete.otf differ diff --git a/assets/fonts/Fira Code Regular Nerd Font Complete.otf b/assets/fonts/Fira Code Regular Nerd Font Complete.otf new file mode 100644 index 0000000..20f5847 Binary files /dev/null and b/assets/fonts/Fira Code Regular Nerd Font Complete.otf differ diff --git a/assets/fonts/LICENSE b/assets/fonts/LICENSE new file mode 100644 index 0000000..40f856f --- /dev/null +++ b/assets/fonts/LICENSE @@ -0,0 +1,94 @@ +Copyright (c) 2019 - Present, Microsoft Corporation, +with Reserved Font Name Cascadia Code. + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/assets/fonts/NotoColorEmoji.ttf b/assets/fonts/NotoColorEmoji.ttf new file mode 100644 index 0000000..69cf21a Binary files /dev/null and b/assets/fonts/NotoColorEmoji.ttf differ diff --git a/assets/fonts/NotoSansMonoCJKjp-Bold.otf b/assets/fonts/NotoSansMonoCJKjp-Bold.otf new file mode 100644 index 0000000..3ac7b28 Binary files /dev/null and b/assets/fonts/NotoSansMonoCJKjp-Bold.otf differ diff --git a/assets/fonts/NotoSansMonoCJKjp-Regular.otf b/assets/fonts/NotoSansMonoCJKjp-Regular.otf new file mode 100644 index 0000000..8732e8c Binary files /dev/null and b/assets/fonts/NotoSansMonoCJKjp-Regular.otf differ diff --git a/src/renderer/caching_shaper.rs b/src/renderer/caching_shaper.rs index 15be69f..f8c8144 100644 --- a/src/renderer/caching_shaper.rs +++ b/src/renderer/caching_shaper.rs @@ -2,19 +2,19 @@ use std::collections::HashMap; use lru::LruCache; use skulpin::skia_safe::{TextBlob, Font as SkiaFont, Typeface, TextBlobBuilder, Data}; -use font_kit::{source::SystemSource, metrics::Metrics, properties::Properties, family_name::FamilyName}; +use font_kit::{source::SystemSource, metrics::Metrics, properties::Properties, family_name::FamilyName, font::Font}; use skribo::{LayoutSession, FontRef as SkriboFont, FontFamily, FontCollection, TextStyle}; const STANDARD_CHARACTER_STRING: &'static str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; -#[cfg(target_os = "windows")] -const EMOJI_FONT: &str = "Segoe UI Emoji"; +const MONOSPACE_FONT: &'static str = "Fira Code Regular Nerd Font Complete.otf"; +const SYMBOL_FONT: &'static str = "DejaVuSansMono.ttf"; +const EMOJI_FONT: &'static str = "NotoColorEmoji.ttf"; +const WIDE_FONT: &'static str = "NotoSansMonoCJKjp-Regular.otf"; -#[cfg(target_os = "macos")] -const EMOJI_FONT: &str = "Apple COlor Emoji"; - -#[cfg(target_os = "linux")] -const EMOJI_FONT: &str = "Noto Color Emoji"; +#[derive(RustEmbed)] +#[folder = "assets/fonts/"] +struct Asset; const DEFAULT_FONT_SIZE: f32 = 14.0; @@ -45,15 +45,21 @@ fn build_collection_by_font_name(font_name: Option<&str>) -> FontCollection { } } - if let Ok(monospace) = source.select_best_match(&[FamilyName::Monospace], &Properties::new()) { - let font = monospace.load().unwrap(); - collection.add_family(FontFamily::new_from_font(font)); - } + let monospace_data = Asset::get(MONOSPACE_FONT).expect("Failed to read monospace font data"); + let monospace_font = Font::from_bytes(monospace_data.to_vec().into(), 0).expect("Failed to parse monospace font data"); + collection.add_family(FontFamily::new_from_font(monospace_font)); - if let Ok(emoji) = source.select_family_by_name(EMOJI_FONT) { - let font = emoji.fonts()[0].load().unwrap(); - collection.add_family(FontFamily::new_from_font(font)); - } + let emoji_data = Asset::get(EMOJI_FONT).expect("Failed to read emoji font data"); + let emoji_font = Font::from_bytes(emoji_data.to_vec().into(), 0).expect("Failed to parse emoji font data"); + collection.add_family(FontFamily::new_from_font(emoji_font)); + + let wide_data = Asset::get(WIDE_FONT).expect("Failed to read wide font data"); + let wide_font = Font::from_bytes(wide_data.to_vec().into(), 0).expect("Failed to parse wide font data"); + collection.add_family(FontFamily::new_from_font(wide_font)); + + let symbol_data = Asset::get(SYMBOL_FONT).expect("Failed to read symbol font data"); + let symbol_font = Font::from_bytes(symbol_data.to_vec().into(), 0).expect("Failed to parse symbol font data"); + collection.add_family(FontFamily::new_from_font(symbol_font)); collection }