diff --git a/README.md b/README.md index 5af7f5b7..7c60f9b5 100644 --- a/README.md +++ b/README.md @@ -209,6 +209,7 @@ Egui is under MIT OR Apache-2.0 license. Fonts: -* NotoEmoji-Regular.ttf, [google.com/get/noto](https://google.com/get/noto), [SIL Open Font License](https://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=OFL) -* ProggyClean.ttf, Copyright (c) 2004, 2005 Tristan Grimmer. MIT License. -* Ubuntu-Light.ttf by [Dalton Maag](http://www.daltonmaag.com/): [Ubuntu font licence](https://ubuntu.com/legal/font-licence) +* `emoji-icon-font.ttf`: [Copyright (c) 2014 John Slegers](https://github.com/jslegers/emoji-icon-font) , MIT License +* `NotoEmoji-Regular.ttf`: [google.com/get/noto](https://google.com/get/noto), [SIL Open Font License](https://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=OFL) +* `ProggyClean.ttf`: Copyright (c) 2004, 2005 Tristan Grimmer. MIT License. +* `Ubuntu-Light.ttf` by [Dalton Maag](http://www.daltonmaag.com/): [Ubuntu font licence](https://ubuntu.com/legal/font-licence) diff --git a/egui/fonts/emoji-icon-font-mit-license.txt b/egui/fonts/emoji-icon-font-mit-license.txt new file mode 100644 index 00000000..99016e12 --- /dev/null +++ b/egui/fonts/emoji-icon-font-mit-license.txt @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2014 John Slegers + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 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. diff --git a/egui/fonts/emoji-icon-font.ttf b/egui/fonts/emoji-icon-font.ttf new file mode 100644 index 00000000..80640832 Binary files /dev/null and b/egui/fonts/emoji-icon-font.ttf differ diff --git a/egui/src/paint/font.rs b/egui/src/paint/font.rs index 1065ee5d..c7484445 100644 --- a/egui/src/paint/font.rs +++ b/egui/src/paint/font.rs @@ -203,7 +203,7 @@ impl Font { let font_index_glyph_info = self.glyph_info_no_cache(c); let font_index_glyph_info = - font_index_glyph_info.unwrap_or_else(|| self.replacement_font_index_glyph_info); + font_index_glyph_info.unwrap_or(self.replacement_font_index_glyph_info); self.glyph_info_cache .write() .insert(c, font_index_glyph_info); @@ -455,33 +455,36 @@ fn allocate_glyph( let uv_rect = if let Some(bb) = glyph.pixel_bounding_box() { let glyph_width = bb.width() as usize; let glyph_height = bb.height() as usize; - assert!(glyph_width >= 1); - assert!(glyph_height >= 1); - let glyph_pos = atlas.allocate((glyph_width, glyph_height)); + if glyph_width == 0 || glyph_height == 0 { + None + } else { + let glyph_pos = atlas.allocate((glyph_width, glyph_height)); - let texture = atlas.texture_mut(); - glyph.draw(|x, y, v| { - if v > 0.0 { - let px = glyph_pos.0 + x as usize; - let py = glyph_pos.1 + y as usize; - texture[(px, py)] = (v * 255.0).round() as u8; - } - }); + let texture = atlas.texture_mut(); + glyph.draw(|x, y, v| { + if v > 0.0 { + let px = glyph_pos.0 + x as usize; + let py = glyph_pos.1 + y as usize; + texture[(px, py)] = (v * 255.0).round() as u8; + } + }); - let offset_y_in_pixels = scale_in_pixels as f32 + bb.min.y as f32 - 4.0 * pixels_per_point; // TODO: use font.v_metrics - Some(UvRect { - offset: vec2( - bb.min.x as f32 / pixels_per_point, - offset_y_in_pixels / pixels_per_point, - ), - size: vec2(glyph_width as f32, glyph_height as f32) / pixels_per_point, - min: (glyph_pos.0 as u16, glyph_pos.1 as u16), - max: ( - (glyph_pos.0 + glyph_width) as u16, - (glyph_pos.1 + glyph_height) as u16, - ), - }) + let offset_y_in_pixels = + scale_in_pixels as f32 + bb.min.y as f32 - 4.0 * pixels_per_point; // TODO: use font.v_metrics + Some(UvRect { + offset: vec2( + bb.min.x as f32 / pixels_per_point, + offset_y_in_pixels / pixels_per_point, + ), + size: vec2(glyph_width as f32, glyph_height as f32) / pixels_per_point, + min: (glyph_pos.0 as u16, glyph_pos.1 as u16), + max: ( + (glyph_pos.0 + glyph_width) as u16, + (glyph_pos.1 + glyph_height) as u16, + ), + }) + } } else { // No bounding box. Maybe a space? None diff --git a/egui/src/paint/fonts.rs b/egui/src/paint/fonts.rs index 67101368..33e4e06f 100644 --- a/egui/src/paint/fonts.rs +++ b/egui/src/paint/fonts.rs @@ -42,8 +42,8 @@ pub struct FontDefinitions { /// but you can override them if you like. pub ttf_data: BTreeMap, - /// ttf data for emoji font, if any - pub emoji_ttf_data: Option<&'static [u8]>, + /// ttf data for emoji font(s), if any, in order of preference + pub emoji_ttf_data: Vec<&'static [u8]>, } impl Default for FontDefinitions { @@ -69,13 +69,14 @@ impl FontDefinitions { ttf_data.insert(FontFamily::Monospace, monospace_typeface_data); ttf_data.insert(FontFamily::VariableWidth, variable_typeface_data); - let emoji_ttf_data = include_bytes!("../../fonts/NotoEmoji-Regular.ttf"); - Self { pixels_per_point, fonts, ttf_data, - emoji_ttf_data: Some(emoji_ttf_data), + emoji_ttf_data: vec![ + include_bytes!("../../fonts/NotoEmoji-Regular.ttf"), // few, but good looking. Use as first priority + include_bytes!("../../fonts/emoji-icon-font.ttf"), // bigger and more: http://jslegers.github.io/emoji-icon-font/ + ], } } } @@ -142,7 +143,7 @@ impl Fonts { let mut fonts = vec![font_impl]; - if let Some(emoji_ttf_data) = emoji_ttf_data { + for &emoji_ttf_data in &emoji_ttf_data { let emoji_font_impl = Arc::new(FontImpl::new( atlas.clone(), emoji_ttf_data,