wezterm: bundle JetBrains Mono and Noto Color Emoji fonts
These serve two purposes: * Provide a consistent default font for new installations, that happens to show off ligature and color emoji support out of the box. * Provide a reasonable fallback in case the configuration is broken Both fonts are distributed under the terms of the OFL 1.1. refs: https://github.com/wez/wezterm/issues/263
This commit is contained in:
1 parent
42e135e5b0
commit
3413bd97b9
19 files changed
+193
-31
No files matched your search
+5
-1
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Wez Furlong
|
||||
Copyright (c) 2018-Present Wez Furlong
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -19,3 +19,7 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
WezTerm bundles `JetBrains Mono` and `Noto Color Emoji` fonts.
|
||||
Those are distributed under the terms of the OFL 1.1, the text of which
|
||||
can be found in the assets/fonts directory.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,92 @@
|
||||
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.
|
||||
Binary file not shown.
+9
-15
@@ -1,13 +1,6 @@
|
||||
use crate::config::*;
|
||||
use termwiz::color::RgbColor;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
const FONT_FAMILY: &str = "Andale Mono";
|
||||
#[cfg(windows)]
|
||||
const FONT_FAMILY: &str = "Consolas";
|
||||
#[cfg(all(not(target_os = "macos"), not(windows)))]
|
||||
const FONT_FAMILY: &str = "monospace";
|
||||
|
||||
#[derive(Debug, Copy, Deserialize, Serialize, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum FontHinting {
|
||||
/// No hinting is performed
|
||||
@@ -69,7 +62,7 @@ impl FontAttributes {
|
||||
impl Default for FontAttributes {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
family: FONT_FAMILY.into(),
|
||||
family: "JetBrains Mono".into(),
|
||||
bold: false,
|
||||
italic: false,
|
||||
}
|
||||
@@ -134,14 +127,15 @@ impl TextStyle {
|
||||
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(clippy::let_and_return))]
|
||||
pub fn font_with_fallback(&self) -> Vec<FontAttributes> {
|
||||
#[allow(unused_mut)]
|
||||
let mut font = self.font.clone();
|
||||
|
||||
if font.is_empty() {
|
||||
// This can happen when migratin from the old fontconfig_pattern
|
||||
// configuration syntax; ensure that we have something likely
|
||||
// sane in the font configuration
|
||||
font.push(FontAttributes::default());
|
||||
let default_font = FontAttributes::default();
|
||||
|
||||
// Insert our bundled default JetBrainsMono as a fallback
|
||||
// in case their preference doesn't match anything.
|
||||
// But don't add it if it is already their preference.
|
||||
if font.iter().position(|f| *f == default_font).is_none() {
|
||||
font.push(default_font);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
@@ -161,7 +155,7 @@ impl TextStyle {
|
||||
#[cfg(windows)]
|
||||
font.push(FontAttributes::new("Segoe UI Symbol"));
|
||||
|
||||
#[cfg(all(unix, not(target_os = "macos")))]
|
||||
// We bundle this emoji font as an in-memory fallback
|
||||
font.push(FontAttributes::new("Noto Color Emoji"));
|
||||
|
||||
font
|
||||
|
||||
+87
-15
@@ -92,6 +92,9 @@ impl ParsedFont {
|
||||
parse_and_collect_font_info(path, &mut font_info).ok();
|
||||
}
|
||||
}
|
||||
|
||||
load_built_in_fonts(&mut font_info).ok();
|
||||
|
||||
font_info.sort_by_key(|(names, _, _)| names.full_name.clone());
|
||||
for (names, _, _) in &font_info {
|
||||
log::warn!("available font: {}", names.full_name);
|
||||
@@ -104,18 +107,10 @@ impl ParsedFont {
|
||||
let mut handles = vec![];
|
||||
for attr in fonts_selection {
|
||||
let mut found = false;
|
||||
for (names, path, index) in &font_info {
|
||||
if font_info_matches(attr, names) {
|
||||
log::warn!(
|
||||
"Using {} from {} index {}",
|
||||
names.full_name,
|
||||
path.display(),
|
||||
index
|
||||
);
|
||||
handles.push(FontDataHandle::OnDisk {
|
||||
path: path.clone(),
|
||||
index: (*index).try_into()?,
|
||||
});
|
||||
for (names, path, handle) in &font_info {
|
||||
if font_info_matches(attr, &names) {
|
||||
log::warn!("Using {} from {}", names.full_name, path.display(),);
|
||||
handles.push(handle.clone());
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
@@ -444,10 +439,17 @@ fn collect_font_info(
|
||||
name_table_data: &[u8],
|
||||
path: &Path,
|
||||
index: usize,
|
||||
infos: &mut Vec<(Names, PathBuf, usize)>,
|
||||
infos: &mut Vec<(Names, PathBuf, FontDataHandle)>,
|
||||
) -> anyhow::Result<()> {
|
||||
let names = Names::from_name_table_data(name_table_data)?;
|
||||
infos.push((names, path.to_path_buf(), index));
|
||||
infos.push((
|
||||
names,
|
||||
path.to_path_buf(),
|
||||
FontDataHandle::OnDisk {
|
||||
path: path.to_path_buf(),
|
||||
index: index.try_into()?,
|
||||
},
|
||||
));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -472,9 +474,79 @@ fn font_info_matches(attr: &FontAttributes, names: &Names) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
/// In case the user has a broken configuration, or no configuration,
|
||||
/// we bundle JetBrains Mono and Noto Color Emoji to act as reasonably
|
||||
/// sane fallback fonts.
|
||||
/// This function loads those.
|
||||
fn load_built_in_fonts(
|
||||
font_info: &mut Vec<(Names, PathBuf, FontDataHandle)>,
|
||||
) -> anyhow::Result<()> {
|
||||
for data in &[
|
||||
include_bytes!("../../assets/fonts/JetBrainsMono-Bold-Italic.ttf") as &'static [u8],
|
||||
include_bytes!("../../assets/fonts/JetBrainsMono-Bold.ttf"),
|
||||
include_bytes!("../../assets/fonts/JetBrainsMono-ExtraBold-Italic.ttf"),
|
||||
include_bytes!("../../assets/fonts/JetBrainsMono-ExtraBold.ttf"),
|
||||
include_bytes!("../../assets/fonts/JetBrainsMono-ExtraLight-Italic.ttf"),
|
||||
include_bytes!("../../assets/fonts/JetBrainsMono-ExtraLight.ttf"),
|
||||
include_bytes!("../../assets/fonts/JetBrainsMono-Italic.ttf"),
|
||||
include_bytes!("../../assets/fonts/JetBrainsMono-Light-Italic.ttf"),
|
||||
include_bytes!("../../assets/fonts/JetBrainsMono-Light.ttf"),
|
||||
include_bytes!("../../assets/fonts/JetBrainsMono-Medium-Italic.ttf"),
|
||||
include_bytes!("../../assets/fonts/JetBrainsMono-Medium.ttf"),
|
||||
include_bytes!("../../assets/fonts/JetBrainsMono-Regular.ttf"),
|
||||
include_bytes!("../../assets/fonts/JetBrainsMono-SemiLight-Italic.ttf"),
|
||||
include_bytes!("../../assets/fonts/JetBrainsMono-SemiLight.ttf"),
|
||||
include_bytes!("../../assets/fonts/NotoColorEmoji.ttf"),
|
||||
] {
|
||||
let scope = allsorts::binary::read::ReadScope::new(&data);
|
||||
let file = scope.read::<OpenTypeFile>()?;
|
||||
let path = Path::new("memory");
|
||||
|
||||
match &file.font {
|
||||
OpenTypeFont::Single(ttf) => {
|
||||
let name_table_data = ttf
|
||||
.read_table(&file.scope, allsorts::tag::NAME)?
|
||||
.ok_or_else(|| anyhow!("name table is not present"))?;
|
||||
|
||||
let names = Names::from_name_table_data(name_table_data.data())?;
|
||||
font_info.push((
|
||||
names,
|
||||
path.to_path_buf(),
|
||||
FontDataHandle::Memory {
|
||||
data: data.to_vec(),
|
||||
index: 0,
|
||||
},
|
||||
));
|
||||
}
|
||||
OpenTypeFont::Collection(ttc) => {
|
||||
for (index, offset_table_offset) in ttc.offset_tables.iter().enumerate() {
|
||||
let ttf = file
|
||||
.scope
|
||||
.offset(offset_table_offset as usize)
|
||||
.read::<OffsetTable>()?;
|
||||
let name_table_data = ttf
|
||||
.read_table(&file.scope, allsorts::tag::NAME)?
|
||||
.ok_or_else(|| anyhow!("name table is not present"))?;
|
||||
let names = Names::from_name_table_data(name_table_data.data())?;
|
||||
font_info.push((
|
||||
names,
|
||||
path.to_path_buf(),
|
||||
FontDataHandle::Memory {
|
||||
data: data.to_vec(),
|
||||
index: index.try_into()?,
|
||||
},
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn parse_and_collect_font_info(
|
||||
path: &Path,
|
||||
font_info: &mut Vec<(Names, PathBuf, usize)>,
|
||||
font_info: &mut Vec<(Names, PathBuf, FontDataHandle)>,
|
||||
) -> anyhow::Result<()> {
|
||||
let data = std::fs::read(path)?;
|
||||
let scope = allsorts::binary::read::ReadScope::new(&data);
|
||||
|
||||
Reference in new issue
Block a user