Add a second emoji font: emoji-icon-font

This commit is contained in:
Emil Ernerfeldt 2020-12-12 15:03:12 +01:00
parent cb310676af
commit 891c5d84d7
5 changed files with 48 additions and 34 deletions

View file

@ -209,6 +209,7 @@ Egui is under MIT OR Apache-2.0 license.
Fonts: 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) * `emoji-icon-font.ttf`: [Copyright (c) 2014 John Slegers](https://github.com/jslegers/emoji-icon-font) , MIT License
* ProggyClean.ttf, Copyright (c) 2004, 2005 Tristan Grimmer. MIT License. <http://www.proggyfonts.net/> * `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)
* Ubuntu-Light.ttf by [Dalton Maag](http://www.daltonmaag.com/): [Ubuntu font licence](https://ubuntu.com/legal/font-licence) * `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)

View file

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

Binary file not shown.

View file

@ -203,7 +203,7 @@ impl Font {
let font_index_glyph_info = self.glyph_info_no_cache(c); let font_index_glyph_info = self.glyph_info_no_cache(c);
let font_index_glyph_info = 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 self.glyph_info_cache
.write() .write()
.insert(c, font_index_glyph_info); .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 uv_rect = if let Some(bb) = glyph.pixel_bounding_box() {
let glyph_width = bb.width() as usize; let glyph_width = bb.width() as usize;
let glyph_height = bb.height() 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(); let texture = atlas.texture_mut();
glyph.draw(|x, y, v| { glyph.draw(|x, y, v| {
if v > 0.0 { if v > 0.0 {
let px = glyph_pos.0 + x as usize; let px = glyph_pos.0 + x as usize;
let py = glyph_pos.1 + y as usize; let py = glyph_pos.1 + y as usize;
texture[(px, py)] = (v * 255.0).round() as u8; 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 let offset_y_in_pixels =
Some(UvRect { scale_in_pixels as f32 + bb.min.y as f32 - 4.0 * pixels_per_point; // TODO: use font.v_metrics
offset: vec2( Some(UvRect {
bb.min.x as f32 / pixels_per_point, offset: vec2(
offset_y_in_pixels / pixels_per_point, 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), size: vec2(glyph_width as f32, glyph_height as f32) / pixels_per_point,
max: ( min: (glyph_pos.0 as u16, glyph_pos.1 as u16),
(glyph_pos.0 + glyph_width) as u16, max: (
(glyph_pos.1 + glyph_height) as u16, (glyph_pos.0 + glyph_width) as u16,
), (glyph_pos.1 + glyph_height) as u16,
}) ),
})
}
} else { } else {
// No bounding box. Maybe a space? // No bounding box. Maybe a space?
None None

View file

@ -42,8 +42,8 @@ pub struct FontDefinitions {
/// but you can override them if you like. /// but you can override them if you like.
pub ttf_data: BTreeMap<FontFamily, &'static [u8]>, pub ttf_data: BTreeMap<FontFamily, &'static [u8]>,
/// ttf data for emoji font, if any /// ttf data for emoji font(s), if any, in order of preference
pub emoji_ttf_data: Option<&'static [u8]>, pub emoji_ttf_data: Vec<&'static [u8]>,
} }
impl Default for FontDefinitions { impl Default for FontDefinitions {
@ -69,13 +69,14 @@ impl FontDefinitions {
ttf_data.insert(FontFamily::Monospace, monospace_typeface_data); ttf_data.insert(FontFamily::Monospace, monospace_typeface_data);
ttf_data.insert(FontFamily::VariableWidth, variable_typeface_data); ttf_data.insert(FontFamily::VariableWidth, variable_typeface_data);
let emoji_ttf_data = include_bytes!("../../fonts/NotoEmoji-Regular.ttf");
Self { Self {
pixels_per_point, pixels_per_point,
fonts, fonts,
ttf_data, 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]; 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( let emoji_font_impl = Arc::new(FontImpl::new(
atlas.clone(), atlas.clone(),
emoji_ttf_data, emoji_ttf_data,