Skip to content

Commit

Permalink
Migrate default fonts to a new crate
Browse files Browse the repository at this point in the history
This allows license checking tools to omit the OFL and UFL licenses when
`default_fonts` are turned off.

Fixes emilk#2321
  • Loading branch information
Alex Pinkus committed Jul 20, 2024
1 parent 56df31a commit 2606b9a
Show file tree
Hide file tree
Showing 20 changed files with 201 additions and 137 deletions.
9 changes: 7 additions & 2 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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() { … }`
Expand All @@ -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`.
Expand Down
5 changes: 5 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1460,6 +1460,7 @@ dependencies = [
"document-features",
"ecolor",
"emath",
"epaint_default_fonts",
"log",
"nohash-hasher",
"parking_lot",
Expand All @@ -1468,6 +1469,10 @@ dependencies = [
"serde",
]

[[package]]
name = "epaint_default_fonts"
version = "0.28.1"

[[package]]
name = "equivalent"
version = "1.0.1"
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ members = [
"crates/egui",
"crates/emath",
"crates/epaint",
"crates/epaint_default_fonts",

"examples/*",
"tests/*",
Expand Down Expand Up @@ -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 }
Expand Down
21 changes: 11 additions & 10 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions crates/epaint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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]
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -100,6 +96,8 @@ serde = { workspace = true, optional = true, features = ["derive", "rc"] }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
backtrace = { workspace = true, optional = true }

epaint_default_fonts = { workspace = true, optional = true }


[dev-dependencies]
criterion.workspace = true
Expand Down
38 changes: 17 additions & 21 deletions crates/epaint/src/text/fonts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand Down
9 changes: 9 additions & 0 deletions crates/epaint_default_fonts/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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 changes: 29 additions & 0 deletions crates/epaint_default_fonts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 changes: 11 additions & 0 deletions crates/epaint_default_fonts/README.md
Original file line number Diff line number Diff line change
@@ -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/).
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 2606b9a

Please sign in to comment.