Browse Source

Add a second emoji font: emoji-icon-font

pull/63/head
Emil Ernerfeldt 4 years ago
parent
commit
891c5d84d7
  1. 7
      README.md
  2. 9
      egui/fonts/emoji-icon-font-mit-license.txt
  3. BIN
      egui/fonts/emoji-icon-font.ttf
  4. 11
      egui/src/paint/font.rs
  5. 13
      egui/src/paint/fonts.rs

7
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. <http://www.proggyfonts.net/>
* 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. <http://www.proggyfonts.net/>
* `Ubuntu-Light.ttf` by [Dalton Maag](http://www.daltonmaag.com/): [Ubuntu font licence](https://ubuntu.com/legal/font-licence)

9
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.

BIN
egui/fonts/emoji-icon-font.ttf

Binary file not shown.

11
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,9 +455,10 @@ 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);
if glyph_width == 0 || glyph_height == 0 {
None
} else {
let glyph_pos = atlas.allocate((glyph_width, glyph_height));
let texture = atlas.texture_mut();
@ -469,7 +470,8 @@ fn allocate_glyph(
}
});
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
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,
@ -482,6 +484,7 @@ fn allocate_glyph(
(glyph_pos.1 + glyph_height) as u16,
),
})
}
} else {
// No bounding box. Maybe a space?
None

13
egui/src/paint/fonts.rs

@ -42,8 +42,8 @@ pub struct FontDefinitions {
/// but you can override them if you like.
pub ttf_data: BTreeMap<FontFamily, &'static [u8]>,
/// 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,

Loading…
Cancel
Save