Move default fonts to new crate `epaint_default_fonts` (#4853)

This allows license checking tools to omit the OFL and UFL licenses when
`default_fonts` are turned off.

There was some discussion of versioning on the original issue; I have
chosen to label this version as `0.28.1` to match the other crates.
Happy to adjust the version as needed.

<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md)
before opening a Pull Request!

* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to test and add commits to your PR.
* Remember to run `cargo fmt` and `cargo clippy`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.

Please be patient! I will review your PR, but my time is limited!
-->

* Closes <https://github.com/emilk/egui/issues/2321>
* [X] I have followed the instructions in the PR template

---------

Co-authored-by: Alex Pinkus <pinkus@amazon.com>
This commit is contained in:
Alex Pinkus 2024-07-31 00:50:02 -07:00 committed by GitHub
parent 6f2f006885
commit ae7672e336
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
22 changed files with 242 additions and 138 deletions

View File

@ -29,4 +29,4 @@ jobs:
with: with:
mode: minimum mode: minimum
count: 1 count: 1
labels: "CI, dependencies, docs and examples, ecolor, eframe, egui_extras, egui_glow, egui-wgpu, egui-winit, egui, epaint, exclude from changelog, typo" labels: "CI, dependencies, docs and examples, ecolor, eframe, egui_extras, egui_glow, egui-wgpu, egui-winit, egui, epaint, epaint_default_fonts, exclude from changelog, typo"

View File

@ -5,7 +5,7 @@ Also see [`CONTRIBUTING.md`](CONTRIBUTING.md) for what to do before opening a PR
## Crate overview ## Crate overview
The crates in this repository are: `egui, emath, epaint, egui_extras, egui-winit, egui_glow, egui_demo_lib, egui_demo_app`. The crates in this repository are: `egui, emath, epaint, epaint_default_fonts, egui_extras, egui-winit, egui_glow, egui_demo_lib, egui_demo_app`.
### `egui`: The main GUI library. ### `egui`: The main GUI library.
Example code: `if ui.button("Click me").clicked() { … }` Example code: `if ui.button("Click me").clicked() { … }`
@ -19,7 +19,12 @@ Examples: `Vec2, Pos2, Rect, lerp, remap`
Example: `Shape::Circle { center, radius, fill, stroke }` Example: `Shape::Circle { center, radius, fill, stroke }`
Depends on `emath`. Depends on `emath`. Also depends on `epaint_default_fonts` when the `default_fonts` feature is enabled.
### `epaint_default_fonts`
Embedded fonts (using `include_bytes!()`) for use by `epaint` in selecting defaults.
Since the font files themselves are licensed differently from the `epaint` source code, this simplifies licenses for callers who disable the default fonts.
### `egui_extras` ### `egui_extras`
This adds additional features on top of `egui`. This adds additional features on top of `egui`.

View File

@ -1444,6 +1444,7 @@ dependencies = [
"document-features", "document-features",
"ecolor", "ecolor",
"emath", "emath",
"epaint_default_fonts",
"log", "log",
"nohash-hasher", "nohash-hasher",
"parking_lot", "parking_lot",
@ -1452,6 +1453,10 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "epaint_default_fonts"
version = "0.28.1"
[[package]] [[package]]
name = "equivalent" name = "equivalent"
version = "1.0.1" version = "1.0.1"

View File

@ -11,6 +11,7 @@ members = [
"crates/egui", "crates/egui",
"crates/emath", "crates/emath",
"crates/epaint", "crates/epaint",
"crates/epaint_default_fonts",
"examples/*", "examples/*",
"tests/*", "tests/*",
@ -56,6 +57,7 @@ opt-level = 2
emath = { version = "0.28.1", path = "crates/emath", default-features = false } emath = { version = "0.28.1", path = "crates/emath", default-features = false }
ecolor = { version = "0.28.1", path = "crates/ecolor", default-features = false } ecolor = { version = "0.28.1", path = "crates/ecolor", default-features = false }
epaint = { version = "0.28.1", path = "crates/epaint", default-features = false } epaint = { version = "0.28.1", path = "crates/epaint", default-features = false }
epaint_default_fonts = { version = "0.28.1", path = "crates/epaint_default_fonts" }
egui = { version = "0.28.1", path = "crates/egui", default-features = false } egui = { version = "0.28.1", path = "crates/egui", default-features = false }
egui-winit = { version = "0.28.1", path = "crates/egui-winit", default-features = false } egui-winit = { version = "0.28.1", path = "crates/egui-winit", default-features = false }
egui_extras = { version = "0.28.1", path = "crates/egui_extras", default-features = false } egui_extras = { version = "0.28.1", path = "crates/egui_extras", default-features = false }

View File

@ -76,6 +76,7 @@ I usually do this all on the `master` branch, but doing it in a release branch i
(cd crates/emath && cargo publish --quiet) && echo "✅ emath" (cd crates/emath && cargo publish --quiet) && echo "✅ emath"
(cd crates/ecolor && cargo publish --quiet) && echo "✅ ecolor" (cd crates/ecolor && cargo publish --quiet) && echo "✅ ecolor"
(cd crates/epaint && cargo publish --quiet) && echo "✅ epaint" (cd crates/epaint && cargo publish --quiet) && echo "✅ epaint"
(cd crates/epaint_default_fonts && cargo publish --quiet) && echo "✅ epaint_default_fonts"
(cd crates/egui && cargo publish --quiet) && echo "✅ egui" (cd crates/egui && cargo publish --quiet) && echo "✅ egui"
(cd crates/egui-winit && cargo publish --quiet) && echo "✅ egui-winit" (cd crates/egui-winit && cargo publish --quiet) && echo "✅ egui-winit"
(cd crates/egui_extras && cargo publish --quiet) && echo "✅ egui_extras" (cd crates/egui_extras && cargo publish --quiet) && echo "✅ egui_extras"

View File

@ -6,7 +6,7 @@ description = "Minimal 2D graphics library for GUI work"
edition.workspace = true edition.workspace = true
rust-version.workspace = true rust-version.workspace = true
homepage = "https://github.com/emilk/egui/tree/master/crates/epaint" homepage = "https://github.com/emilk/egui/tree/master/crates/epaint"
license = "(MIT OR Apache-2.0) AND OFL-1.1 AND LicenseRef-UFL-1.0" # OFL and UFL used by default_fonts. See https://github.com/emilk/egui/issues/2321 license = "MIT OR Apache-2.0"
readme = "README.md" readme = "README.md"
repository = "https://github.com/emilk/egui/tree/master/crates/epaint" repository = "https://github.com/emilk/egui/tree/master/crates/epaint"
categories = ["graphics", "gui"] categories = ["graphics", "gui"]
@ -15,11 +15,7 @@ include = [
"../LICENSE-APACHE", "../LICENSE-APACHE",
"../LICENSE-MIT", "../LICENSE-MIT",
"**/*.rs", "**/*.rs",
"Cargo.toml", "Cargo.toml"
"fonts/*.ttf",
"fonts/*.txt",
"fonts/OFL.txt",
"fonts/UFL.txt",
] ]
[lints] [lints]
@ -50,7 +46,7 @@ deadlock_detection = ["dep:backtrace"]
## If set, epaint will use `include_bytes!` to bundle some fonts. ## If set, epaint will use `include_bytes!` to bundle some fonts.
## If you plan on specifying your own fonts you may disable this feature. ## If you plan on specifying your own fonts you may disable this feature.
default_fonts = [] default_fonts = ["epaint_default_fonts"]
## Turn on the `log` feature, that makes egui log some errors using the [`log`](https://docs.rs/log) crate. ## Turn on the `log` feature, that makes egui log some errors using the [`log`](https://docs.rs/log) crate.
log = ["dep:log"] log = ["dep:log"]
@ -96,6 +92,8 @@ rayon = { version = "1.7", optional = true }
## Allow serialization using [`serde`](https://docs.rs/serde) . ## Allow serialization using [`serde`](https://docs.rs/serde) .
serde = { workspace = true, optional = true, features = ["derive", "rc"] } serde = { workspace = true, optional = true, features = ["derive", "rc"] }
epaint_default_fonts = { workspace = true, optional = true }
# native: # native:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
backtrace = { workspace = true, optional = true } backtrace = { workspace = true, optional = true }

View File

@ -10,6 +10,9 @@ use crate::{
}; };
use emath::{NumExt as _, OrderedFloat}; use emath::{NumExt as _, OrderedFloat};
#[cfg(feature = "default_fonts")]
use epaint_default_fonts::{EMOJI_ICON, HACK_REGULAR, NOTO_EMOJI_REGULAR, UBUNTU_LIGHT};
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/// How to select a sized font. /// How to select a sized font.
@ -217,7 +220,7 @@ fn ab_glyph_font_from_font_data(name: &str, data: &FontData) -> ab_glyph::FontAr
/// ///
/// // Install my own font (maybe supporting non-latin characters): /// // Install my own font (maybe supporting non-latin characters):
/// fonts.font_data.insert("my_font".to_owned(), /// fonts.font_data.insert("my_font".to_owned(),
/// FontData::from_static(include_bytes!("../../fonts/Ubuntu-Light.ttf"))); // .ttf and .otf supported /// FontData::from_static(include_bytes!("../../../epaint_default_fonts/fonts/Ubuntu-Light.ttf"))); // .ttf and .otf supported
/// ///
/// // Put my font first (highest priority): /// // Put my font first (highest priority):
/// fonts.families.get_mut(&FontFamily::Proportional).unwrap() /// fonts.families.get_mut(&FontFamily::Proportional).unwrap()
@ -263,39 +266,32 @@ impl Default for FontDefinitions {
let mut families = BTreeMap::new(); let mut families = BTreeMap::new();
font_data.insert( font_data.insert("Hack".to_owned(), FontData::from_static(HACK_REGULAR));
"Hack".to_owned(),
FontData::from_static(include_bytes!("../../fonts/Hack-Regular.ttf")),
);
font_data.insert( font_data.insert(
"Ubuntu-Light".to_owned(), "Ubuntu-Light".to_owned(),
FontData::from_static(include_bytes!("../../fonts/Ubuntu-Light.ttf")), FontData::from_static(UBUNTU_LIGHT),
); );
// Some good looking emojis. Use as first priority: // Some good looking emojis. Use as first priority:
font_data.insert( font_data.insert(
"NotoEmoji-Regular".to_owned(), "NotoEmoji-Regular".to_owned(),
FontData::from_static(include_bytes!("../../fonts/NotoEmoji-Regular.ttf")).tweak( FontData::from_static(NOTO_EMOJI_REGULAR).tweak(FontTweak {
FontTweak {
scale: 0.81, // make it smaller scale: 0.81, // make it smaller
..Default::default() ..Default::default()
}, }),
),
); );
// Bigger emojis, and more. <http://jslegers.github.io/emoji-icon-font/>: // Bigger emojis, and more. <http://jslegers.github.io/emoji-icon-font/>:
font_data.insert( font_data.insert(
"emoji-icon-font".to_owned(), "emoji-icon-font".to_owned(),
FontData::from_static(include_bytes!("../../fonts/emoji-icon-font.ttf")).tweak( FontData::from_static(EMOJI_ICON).tweak(FontTweak {
FontTweak {
scale: 0.88, // make it smaller scale: 0.88, // make it smaller
// probably not correct, but this does make texts look better (#2724 for details) // probably not correct, but this does make texts look better (#2724 for details)
y_offset_factor: 0.11, // move glyphs down to better align with common fonts y_offset_factor: 0.11, // move glyphs down to better align with common fonts
baseline_offset_factor: -0.11, // ...now the entire row is a bit down so shift it back baseline_offset_factor: -0.11, // ...now the entire row is a bit down so shift it back
..Default::default() ..Default::default()
}, }),
),
); );
families.insert( families.insert(

View File

@ -0,0 +1,9 @@
# `epaint_default_fonts` changelog
All notable changes to the `epaint_default_fonts` crate will be documented in this file.
This file is updated upon each release.
Changes since the last release can be found at <https://github.com/emilk/egui/compare/latest...HEAD> or by running the `scripts/generate_changelog.py` script.
## 0.28.1 - 2024-07-05
Crate added.

View File

@ -0,0 +1,29 @@
[package]
name = "epaint_default_fonts"
version.workspace = true
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
description = "Default fonts for use in epaint / egui"
edition.workspace = true
rust-version.workspace = true
homepage = "https://github.com/emilk/egui/tree/master/crates/epaint_default_fonts"
license = "(MIT OR Apache-2.0) AND OFL-1.1 AND LicenseRef-UFL-1.0" # OFL and UFL are from the font files themselves.
readme = "README.md"
repository = "https://github.com/emilk/egui/tree/master/crates/epaint_default_fonts"
categories = ["graphics", "gui"]
keywords = ["graphics", "gui", "egui"]
include = [
"../LICENSE-APACHE",
"../LICENSE-MIT",
"**/*.rs",
"Cargo.toml",
"fonts/*.ttf",
"fonts/*.txt",
"fonts/OFL.txt",
"fonts/UFL.txt",
]
[lints]
workspace = true
[package.metadata.docs.rs]
all-features = true

View File

@ -0,0 +1,11 @@
# `epaint_default_fonts` - fonts for epaint and egui
[![Latest version](https://img.shields.io/crates/v/epaint_default_fonts.svg)](https://crates.io/crates/epaint_default_fonts)
[![Documentation](https://docs.rs/epaint_default_fonts/badge.svg)](https://docs.rs/epaint_default_fonts)
[![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/)
![MIT](https://img.shields.io/badge/license-MIT-blue.svg)
![Apache](https://img.shields.io/badge/license-Apache-blue.svg)
Default fonts that are used in `epaint` and `egui`. Not intended for use as a standalone library.
Made for [`egui`](https://github.com/emilk/egui/).

View File

@ -0,0 +1,47 @@
//! A library containing built-in fonts for `epaint`, embedded as bytes.
//!
//! This is intended to be consumed through the `epaint` crate.
/// A typeface designed for source code.
///
/// Hack is designed to be a workhorse typeface for source code. It has deep
/// roots in the free, open source typeface community and expands upon the
/// contributions of the [Bitstream Vera](https://www.gnome.org/fonts/) and
/// [DejaVu](https://dejavu-fonts.github.io/) projects. The large x-height +
/// wide aperture + low contrast design make it legible at commonly used source
/// code text sizes with a sweet spot that runs in the 8 - 14 range.
///
/// See [the Hack repository](https://github.com/source-foundry/Hack) for more
/// information.
pub const HACK_REGULAR: &[u8] = include_bytes!("../fonts/Hack-Regular.ttf");
/// A typeface containing emoji characters as designed for the Noto font family.
///
/// Noto is a collection of high-quality fonts with multiple weights and widths
/// in sans, serif, mono, and other styles, in more than 1,000 languages and
/// over 150 writing systems. Noto Emoji contains black-and-white emoji
/// characters that match Google's emoji designs.
///
/// See [Google Fonts](https://fonts.google.com/noto/specimen/Noto+Emoji) for
/// more information.
pub const NOTO_EMOJI_REGULAR: &[u8] = include_bytes!("../fonts/NotoEmoji-Regular.ttf");
/// A typeface designed for use by Ubuntu.
///
/// The Ubuntu typeface has been specially created to complement the Ubuntu tone
/// of voice. It has a contemporary style and contains characteristics unique to
/// the Ubuntu brand that convey a precise, reliable and free attitude.
///
/// See [Ubuntu design](https://design.ubuntu.com/font) for more information.
pub const UBUNTU_LIGHT: &[u8] = include_bytes!("../fonts/Ubuntu-Light.ttf");
/// An experimental typeface that uses standardized
/// [UNICODE planes](http://en.wikipedia.org/wiki/Plane_(Unicode))
/// for icon fonts.
///
/// The icons in this font are designed to be styled with minimal effort. Each
/// icon is solid, which is useful for changing icon colors.
///
/// See [the `emoji-icon-font` repository](https://github.com/jslegers/emoji-icon-font)
/// for more information.
pub const EMOJI_ICON: &[u8] = include_bytes!("../fonts/emoji-icon-font.ttf");

View File

@ -25,7 +25,7 @@ fn setup_custom_fonts(ctx: &egui::Context) {
fonts.font_data.insert( fonts.font_data.insert(
"my_font".to_owned(), "my_font".to_owned(),
egui::FontData::from_static(include_bytes!( egui::FontData::from_static(include_bytes!(
"../../../crates/epaint/fonts/Hack-Regular.ttf" "../../../crates/epaint_default_fonts/fonts/Hack-Regular.ttf"
)), )),
); );

View File

@ -228,6 +228,7 @@ def main() -> None:
"egui-winit", "egui-winit",
"egui", "egui",
"epaint", "epaint",
"epaint_default_fonts",
] ]
# We read all existing changelogs to remove duplicate entries. # We read all existing changelogs to remove duplicate entries.