selective font inclusion for emojis
Selectively include fonts for emojis that are used in the interface. This is done instead of including both the entirety of `NotoEmoji-Regular` and `emoji-icon-font`. This now requires the `pyftsubset` utility to be installed (under arch, this can be done with the package `python-fonttools`) TODO: need to fix github workflows
This commit is contained in:
parent
94041774c6
commit
542fd9caba
37
Cargo.lock
generated
37
Cargo.lock
generated
@ -650,6 +650,12 @@ version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
|
||||
|
||||
[[package]]
|
||||
name = "dunce"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "453440c271cf5577fd2a40e4942540cb7d0d2f85e27c8d07dd0023c925a67541"
|
||||
|
||||
[[package]]
|
||||
name = "eframe"
|
||||
version = "0.18.0"
|
||||
@ -818,6 +824,17 @@ dependencies = [
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fsio"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09e87827efaf94c7a44b562ff57de06930712fe21b530c3797cdede26e6377eb"
|
||||
dependencies = [
|
||||
"dunce",
|
||||
"rand",
|
||||
"users",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gethostname"
|
||||
version = "0.2.3"
|
||||
@ -1890,6 +1907,15 @@ dependencies = [
|
||||
"bytemuck",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "run_script"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5dd85213e37f76b40186ee781cf3a689b05c518c3102c987acf679c573d8e4ef"
|
||||
dependencies = [
|
||||
"fsio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.21"
|
||||
@ -2371,6 +2397,16 @@ dependencies = [
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "users"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "24cc0f6d6f267b73e5a2cadf007ba8f9bc39c6a6f9666f8cf25ea809a153b032"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "0.8.2"
|
||||
@ -2791,6 +2827,7 @@ dependencies = [
|
||||
"lazy_static",
|
||||
"parsing",
|
||||
"rayon",
|
||||
"run_script",
|
||||
"ruzstd",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
||||
@ -70,6 +70,7 @@ bincode = "1.3"
|
||||
serde = "1"
|
||||
serde_json = "1"
|
||||
zstd = "0.11"
|
||||
run_script = "0.9.0"
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
instant = "0.1"
|
||||
|
||||
59
build.rs
59
build.rs
@ -7,10 +7,12 @@ use std::{
|
||||
};
|
||||
|
||||
use epaint::{
|
||||
text::{FontData, FontDefinitions},
|
||||
text::{FontData, FontDefinitions, FontTweak},
|
||||
FontFamily,
|
||||
};
|
||||
|
||||
use run_script::ScriptOptions;
|
||||
|
||||
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/data.rs"));
|
||||
|
||||
fn main() {
|
||||
@ -22,15 +24,62 @@ fn main() {
|
||||
|
||||
// let font_hack = FontData::from_static(include_bytes!("assets/Hack-Regular.ttf"));
|
||||
let font_ubuntu_light = FontData::from_static(include_bytes!("assets/Ubuntu-Light.ttf"));
|
||||
let font_notoemoji = FontData::from_static(include_bytes!("assets/NotoEmoji-Regular.ttf"));
|
||||
let font_emoji_icon = FontData::from_static(include_bytes!("assets/emoji-icon-font.ttf"));
|
||||
let new_noto_path = [&env::var("OUT_DIR").unwrap(), "/noto-emoji.ttf"].concat();
|
||||
let new_emoji_icon_path = [&env::var("OUT_DIR").unwrap(), "/emoji-icon.ttf"].concat();
|
||||
|
||||
let (_code, _output, error) = run_script::run(
|
||||
&format!(
|
||||
"
|
||||
pyftsubset {}/assets/NotoEmoji-Regular.ttf --unicodes=U+1F31E,U+1F319,U+2716
|
||||
mv {}/assets/NotoEmoji-Regular.subset.ttf {}
|
||||
",
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
new_noto_path
|
||||
),
|
||||
&(vec![]),
|
||||
&ScriptOptions::new(),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(error, String::new());
|
||||
|
||||
let (_code, _output, error) = run_script::run(
|
||||
&format!(
|
||||
"
|
||||
pyftsubset {}/assets/emoji-icon-font.ttf --unicodes=U+2699
|
||||
mv {}/assets/emoji-icon-font.subset.ttf {}
|
||||
",
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
new_emoji_icon_path
|
||||
),
|
||||
&(vec![]),
|
||||
&ScriptOptions::new(),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(error, String::new());
|
||||
|
||||
let fonts = FontDefinitions {
|
||||
font_data: BTreeMap::from([
|
||||
// ("Hack".to_owned(), font_hack),
|
||||
("Ubuntu-Light".to_owned(), font_ubuntu_light),
|
||||
("NotoEmoji-Regular".to_owned(), font_notoemoji),
|
||||
("emoji-icon-font".to_owned(), font_emoji_icon),
|
||||
(
|
||||
"NotoEmoji-Regular".to_owned(),
|
||||
FontData::from_owned(
|
||||
std::fs::read(new_noto_path).expect("unable to read noto emoji font"),
|
||||
),
|
||||
),
|
||||
(
|
||||
"emoji-icon-font".to_owned(),
|
||||
FontData::from_owned(
|
||||
std::fs::read(new_emoji_icon_path).expect("unable to read emoji icon font"),
|
||||
)
|
||||
.tweak(FontTweak {
|
||||
scale: 0.8,
|
||||
y_offset_factor: 0.07,
|
||||
y_offset: 0.0,
|
||||
}),
|
||||
),
|
||||
]),
|
||||
families: BTreeMap::from([
|
||||
(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user