diff --git a/build.rs b/build.rs index fdccca8..83de341 100644 --- a/build.rs +++ b/build.rs @@ -15,7 +15,12 @@ use run_script::ScriptOptions; include!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/data.rs")); -fn font_stripper(from: &str, out: &str, unicodes: &[&str]) -> Result, String> { +include!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/src/unicode_helper.rs" +)); + +fn font_stripper(from: &str, out: &str, unicodes: Vec) -> Result, String> { let new_path = [&env::var("OUT_DIR").unwrap(), out].concat(); let unicodes_formatted = unicodes .iter() @@ -57,18 +62,32 @@ fn main() { shadow_rs::new().expect("Could not initialize shadow_rs"); - let font_ubuntu_light = FontData::from_static(include_bytes!("assets/Ubuntu-Light.ttf")); + let mut main_chars: Vec = + b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzsu0123456789?.,!(){}[]-_=+-/<>'\\ :^*`@#$%&|~" + .into_iter() + .map(|c| *c as char) + .collect(); + + main_chars.append(&mut vec!['π']); + + let processed_normal: Vec = main_chars.iter().map(|a| to_unicode_hash(*a)).collect(); let fonts = FontDefinitions { font_data: BTreeMap::from([ - ("Ubuntu-Light".to_owned(), font_ubuntu_light), + ( + "Ubuntu-Light".to_owned(), + FontData::from_owned( + font_stripper("Ubuntu-Light.ttf", "ubuntu-light.ttf", processed_normal) + .unwrap(), + ), + ), ( "NotoEmoji-Regular".to_owned(), FontData::from_owned( font_stripper( "NotoEmoji-Regular.ttf", "noto-emoji.ttf", - &["1F31E", "1F319", "2716"], + vec!["1F31E".to_owned(), "1F319".to_owned(), "2716".to_owned()], ) .unwrap(), ), @@ -76,7 +95,12 @@ fn main() { ( "emoji-icon-font".to_owned(), FontData::from_owned( - font_stripper("emoji-icon-font.ttf", "emoji-icon.ttf", &["2699"]).unwrap(), + font_stripper( + "emoji-icon-font.ttf", + "emoji-icon.ttf", + vec!["2699".to_owned()], + ) + .unwrap(), ) .tweak(FontTweak { scale: 0.8, diff --git a/src/lib.rs b/src/lib.rs index f2a0e01..9bdbf05 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,6 +21,7 @@ mod function_manager; mod math_app; mod misc; mod style; +mod unicode_helper; mod widgets; pub use crate::{ @@ -35,6 +36,7 @@ pub use crate::{ step_helper, EguiHelper, }, + unicode_helper::to_unicode_hash, }; cfg_if::cfg_if! { diff --git a/src/main.rs b/src/main.rs index b15c292..76c9c56 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,7 @@ mod function_manager; mod math_app; mod misc; mod style; +mod unicode_helper; mod widgets; // For running the program natively! (Because why not?) diff --git a/src/unicode_helper.rs b/src/unicode_helper.rs new file mode 100644 index 0000000..3e1aef5 --- /dev/null +++ b/src/unicode_helper.rs @@ -0,0 +1,9 @@ +#[allow(dead_code)] +pub fn to_unicode_hash(c: char) -> String { + c.escape_unicode() + .to_string() + .replace(r#"\\u{"#, "") + .replace("{", "") + .replace("}", "") + .to_uppercase() +} diff --git a/tests/misc.rs b/tests/misc.rs index b9401cb..7be3862 100644 --- a/tests/misc.rs +++ b/tests/misc.rs @@ -195,3 +195,9 @@ fn newtons_method() { ); assert_eq!(data, None); } + +#[test] +fn to_unicode_hash() { + use ytbn_graphing_software::to_unicode_hash; + assert_eq!(to_unicode_hash('\u{1f31e}'), "\\U1F31E"); +}