Browse Source

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>
pull/4891/head
Alex Pinkus 3 months ago
committed by GitHub
parent
commit
ae7672e336
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      .github/workflows/labels.yml
  2. 9
      ARCHITECTURE.md
  3. 5
      Cargo.lock
  4. 2
      Cargo.toml
  5. 21
      RELEASES.md
  6. 12
      crates/epaint/Cargo.toml
  7. 40
      crates/epaint/src/text/fonts.rs
  8. 9
      crates/epaint_default_fonts/CHANGELOG.md
  9. 29
      crates/epaint_default_fonts/Cargo.toml
  10. 11
      crates/epaint_default_fonts/README.md
  11. 0
      crates/epaint_default_fonts/fonts/Hack-Regular.ttf
  12. 0
      crates/epaint_default_fonts/fonts/Hack-Regular.txt
  13. 0
      crates/epaint_default_fonts/fonts/NotoEmoji-Regular.ttf
  14. 0
      crates/epaint_default_fonts/fonts/OFL.txt
  15. 0
      crates/epaint_default_fonts/fonts/UFL.txt
  16. 0
      crates/epaint_default_fonts/fonts/Ubuntu-Light.ttf
  17. 0
      crates/epaint_default_fonts/fonts/emoji-icon-font-mit-license.txt
  18. 0
      crates/epaint_default_fonts/fonts/emoji-icon-font.ttf
  19. 0
      crates/epaint_default_fonts/fonts/list_fonts.py
  20. 47
      crates/epaint_default_fonts/src/lib.rs
  21. 2
      examples/custom_font/src/main.rs
  22. 1
      scripts/generate_changelog.py

2
.github/workflows/labels.yml

@ -29,4 +29,4 @@ jobs:
with:
mode: minimum
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"

9
ARCHITECTURE.md

@ -5,7 +5,7 @@ Also see [`CONTRIBUTING.md`](CONTRIBUTING.md) for what to do before opening a PR
## 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.
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 }`
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`
This adds additional features on top of `egui`.

5
Cargo.lock

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

2
Cargo.toml

@ -11,6 +11,7 @@ members = [
"crates/egui",
"crates/emath",
"crates/epaint",
"crates/epaint_default_fonts",
"examples/*",
"tests/*",
@ -56,6 +57,7 @@ opt-level = 2
emath = { version = "0.28.1", path = "crates/emath", 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_default_fonts = { version = "0.28.1", path = "crates/epaint_default_fonts" }
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_extras = { version = "0.28.1", path = "crates/egui_extras", default-features = false }

21
RELEASES.md

@ -73,16 +73,17 @@ I usually do this all on the `master` branch, but doing it in a release branch i
### `cargo publish`:
```
(cd crates/emath && cargo publish --quiet) && echo "✅ emath"
(cd crates/ecolor && cargo publish --quiet) && echo "✅ ecolor"
(cd crates/epaint && cargo publish --quiet) && echo "✅ epaint"
(cd crates/egui && cargo publish --quiet) && echo "✅ egui"
(cd crates/egui-winit && cargo publish --quiet) && echo "✅ egui-winit"
(cd crates/egui_extras && cargo publish --quiet) && echo "✅ egui_extras"
(cd crates/egui-wgpu && cargo publish --quiet) && echo "✅ egui-wgpu"
(cd crates/egui_demo_lib && cargo publish --quiet) && echo "✅ egui_demo_lib"
(cd crates/egui_glow && cargo publish --quiet) && echo "✅ egui_glow"
(cd crates/eframe && cargo publish --quiet) && echo "✅ eframe"
(cd crates/emath && cargo publish --quiet) && echo "✅ emath"
(cd crates/ecolor && cargo publish --quiet) && echo "✅ ecolor"
(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-winit && cargo publish --quiet) && echo "✅ egui-winit"
(cd crates/egui_extras && cargo publish --quiet) && echo "✅ egui_extras"
(cd crates/egui-wgpu && cargo publish --quiet) && echo "✅ egui-wgpu"
(cd crates/egui_demo_lib && cargo publish --quiet) && echo "✅ egui_demo_lib"
(cd crates/egui_glow && cargo publish --quiet) && echo "✅ egui_glow"
(cd crates/eframe && cargo publish --quiet) && echo "✅ eframe"
```
## Announcements

12
crates/epaint/Cargo.toml

@ -6,7 +6,7 @@ description = "Minimal 2D graphics library for GUI work"
edition.workspace = true
rust-version.workspace = true
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"
repository = "https://github.com/emilk/egui/tree/master/crates/epaint"
categories = ["graphics", "gui"]
@ -15,11 +15,7 @@ include = [
"../LICENSE-APACHE",
"../LICENSE-MIT",
"**/*.rs",
"Cargo.toml",
"fonts/*.ttf",
"fonts/*.txt",
"fonts/OFL.txt",
"fonts/UFL.txt",
"Cargo.toml"
]
[lints]
@ -50,7 +46,7 @@ deadlock_detection = ["dep:backtrace"]
## If set, epaint will use `include_bytes!` to bundle some fonts.
## 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.
log = ["dep:log"]
@ -96,6 +92,8 @@ rayon = { version = "1.7", optional = true }
## Allow serialization using [`serde`](https://docs.rs/serde) .
serde = { workspace = true, optional = true, features = ["derive", "rc"] }
epaint_default_fonts = { workspace = true, optional = true }
# native:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
backtrace = { workspace = true, optional = true }

40
crates/epaint/src/text/fonts.rs

@ -10,6 +10,9 @@ use crate::{
};
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.
@ -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):
/// 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):
/// fonts.families.get_mut(&FontFamily::Proportional).unwrap()
@ -263,39 +266,32 @@ impl Default for FontDefinitions {
let mut families = BTreeMap::new();
font_data.insert(
"Hack".to_owned(),
FontData::from_static(include_bytes!("../../fonts/Hack-Regular.ttf")),
);
font_data.insert("Hack".to_owned(), FontData::from_static(HACK_REGULAR));
font_data.insert(
"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:
font_data.insert(
"NotoEmoji-Regular".to_owned(),
FontData::from_static(include_bytes!("../../fonts/NotoEmoji-Regular.ttf")).tweak(
FontTweak {
scale: 0.81, // make it smaller
..Default::default()
},
),
FontData::from_static(NOTO_EMOJI_REGULAR).tweak(FontTweak {
scale: 0.81, // make it smaller
..Default::default()
}),
);
// Bigger emojis, and more. <http://jslegers.github.io/emoji-icon-font/>:
font_data.insert(
"emoji-icon-font".to_owned(),
FontData::from_static(include_bytes!("../../fonts/emoji-icon-font.ttf")).tweak(
FontTweak {
scale: 0.88, // make it smaller
// 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
baseline_offset_factor: -0.11, // ...now the entire row is a bit down so shift it back
..Default::default()
},
),
FontData::from_static(EMOJI_ICON).tweak(FontTweak {
scale: 0.88, // make it smaller
// 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
baseline_offset_factor: -0.11, // ...now the entire row is a bit down so shift it back
..Default::default()
}),
);
families.insert(

9
crates/epaint_default_fonts/CHANGELOG.md

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

29
crates/epaint_default_fonts/Cargo.toml

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

11
crates/epaint_default_fonts/README.md

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

0
crates/epaint/fonts/Hack-Regular.ttf → crates/epaint_default_fonts/fonts/Hack-Regular.ttf

0
crates/epaint/fonts/Hack-Regular.txt → crates/epaint_default_fonts/fonts/Hack-Regular.txt

0
crates/epaint/fonts/NotoEmoji-Regular.ttf → crates/epaint_default_fonts/fonts/NotoEmoji-Regular.ttf

0
crates/epaint/fonts/OFL.txt → crates/epaint_default_fonts/fonts/OFL.txt

0
crates/epaint/fonts/UFL.txt → crates/epaint_default_fonts/fonts/UFL.txt

0
crates/epaint/fonts/Ubuntu-Light.ttf → crates/epaint_default_fonts/fonts/Ubuntu-Light.ttf

0
crates/epaint/fonts/emoji-icon-font-mit-license.txt → crates/epaint_default_fonts/fonts/emoji-icon-font-mit-license.txt

0
crates/epaint/fonts/emoji-icon-font.ttf → crates/epaint_default_fonts/fonts/emoji-icon-font.ttf

0
crates/epaint/fonts/list_fonts.py → crates/epaint_default_fonts/fonts/list_fonts.py

47
crates/epaint_default_fonts/src/lib.rs

@ -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");

2
examples/custom_font/src/main.rs

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

1
scripts/generate_changelog.py

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

Loading…
Cancel
Save