fix(viewer): every font the viewer ships is named, with its licence beside it
egui's default font set (the crate epaint_default_fonts, switched on by the `default_fonts` feature) includes Ubuntu Light under the Ubuntu Font Licence 1.0. Debian and Fedora class that licence as non-free, so a package of wanderbooks carrying it could not go into either. The viewer never drew a letter with it (all text is Inter), but the file was compiled into the program all the same. The feature is now off, on eframe and on egui, and epaint_default_fonts leaves the lock file. The viewer names its whole font set in theme.rs: - Inter (InterTab, as before) for all text: SIL OFL 1.1. - Hack for fixed-width text: MIT, with the Bitstream Vera licence. - Noto Emoji for symbols: SIL OFL 1.1. - emoji-icon-font for the few symbols Noto Emoji lacks: MIT. The last three are the files egui's set held, copied byte for byte (SHA-256 in assets/fonts/README.md), each now beside its licence text. They are files in this repository, not new dependencies. The OFL stays: it is Inter's own licence, it allows bundling with software under any licence, and Debian, Fedora, the FSF and the OSI accept it. Without the default set a missing glyph is an empty box, and nothing said so. A new test lays out every symbol the viewer's source draws and fails on one no bundled font has. It compares what is drawn with what is drawn for a code point no font has, since egui's `has_glyph` answers no for every character of the font that holds the replacement glyph. The test checks itself on a Cherokee letter, which no bundled font covers. Shown: `cargo test -p ledger-gui --lib theme` 2 passed; the side navigation's snapshot is unchanged (12 passed); the 33 screenshots of the demo books (tests/screens.rs) show Inter, Hack in the journal's hashes and JSON, and every arrow, check mark and icon drawn. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
fe3b10e2d1
commit
b66dff899d
10 files changed
+368
-50
No files matched your search
Generated
-7
@@ -2076,7 +2076,6 @@ dependencies = [
|
||||
"bytemuck",
|
||||
"ecolor",
|
||||
"emath",
|
||||
"epaint_default_fonts",
|
||||
"font-types 0.12.6",
|
||||
"harfrust",
|
||||
"log",
|
||||
@@ -2092,12 +2091,6 @@ dependencies = [
|
||||
"vello_cpu 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "epaint_default_fonts"
|
||||
version = "0.36.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "773fa9c96dd0dbef887e39d0ed6177f141cce4d68e6041df77570aa3702dfa13"
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.2"
|
||||
|
||||
@@ -17,8 +17,12 @@ ledger-config = { path = "../ledger-config" }
|
||||
ledger-import = { path = "../ledger-import" }
|
||||
ledger-vault = { path = "../ledger-vault" }
|
||||
ledger-package = { path = "../ledger-package" }
|
||||
eframe = { version = "0.36", default-features = false, features = ["default_fonts", "wgpu", "wayland", "x11", "persistence"] }
|
||||
egui = "0.36"
|
||||
# No `default_fonts`, on eframe or on egui: egui's own font set includes
|
||||
# Ubuntu Light, under the Ubuntu Font Licence, which Debian and Fedora class
|
||||
# as non-free. The viewer names every font it draws with (theme.rs,
|
||||
# assets/fonts/README.md), and `just deny` refuses that licence.
|
||||
eframe = { version = "0.36", default-features = false, features = ["wgpu", "wayland", "x11", "persistence"] }
|
||||
egui = { version = "0.36", default-features = false }
|
||||
egui_extras = { version = "0.36", features = ["image", "datepicker", "serde"] }
|
||||
egui-phosphor = "0.14"
|
||||
# Markdown documents, drawn as text. No image loading (no `load-images`,
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
The work in the Hack project is Copyright 2018 Source Foundry Authors and licensed under the MIT License
|
||||
|
||||
The work in the DejaVu project was committed to the public domain.
|
||||
|
||||
Bitstream Vera Sans Mono Copyright 2003 Bitstream Inc. and licensed under the Bitstream Vera License with Reserved Font Names "Bitstream" and "Vera"
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Source Foundry Authors
|
||||
|
||||
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.
|
||||
BITSTREAM VERA LICENSE
|
||||
|
||||
Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera is a trademark of Bitstream, Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of the fonts accompanying this license ("Fonts") and associated documentation files (the "Font Software"), to reproduce and distribute the Font Software, including without limitation the rights to use, copy, merge, publish, distribute, and/or sell copies of the Font Software, and to permit persons to whom the Font Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright and trademark notices and this permission notice shall be included in all copies of one or more of the Font Software typefaces.
|
||||
|
||||
The Font Software may be modified, altered, or added to, and in particular the designs of glyphs or characters in the Fonts may be modified and additional glyphs or characters may be added to the Fonts, only if the fonts are renamed to names not containing either the words "Bitstream" or the word "Vera".
|
||||
|
||||
This License becomes null and void to the extent applicable to Fonts or Font Software that has been modified and is distributed under the "Bitstream Vera" names.
|
||||
|
||||
The Font Software may be sold as part of a larger software package but no copy of one or more of the Font Software typefaces may be sold by itself.
|
||||
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the names of Gnome, the Gnome Foundation, and Bitstream Inc., shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Font Software without prior written authorization from the Gnome Foundation or Bitstream Inc., respectively. For further information, contact: fonts at gnome dot org.
|
||||
Binary file not shown.
@@ -0,0 +1,92 @@
|
||||
This Font Software is licensed under the SIL Open Font License,
|
||||
Version 1.1.
|
||||
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
http://scripts.sil.org/OFL
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font
|
||||
creation efforts of academic and linguistic communities, and to
|
||||
provide a free and open framework in which fonts may be shared and
|
||||
improved in partnership with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply to
|
||||
any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software
|
||||
components as distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to,
|
||||
deleting, or substituting -- in part or in whole -- any of the
|
||||
components of the Original Version, by changing formats or by porting
|
||||
the Font Software to a new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed,
|
||||
modify, redistribute, and sell modified and unmodified copies of the
|
||||
Font Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components, in
|
||||
Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the
|
||||
corresponding Copyright Holder. This restriction only applies to the
|
||||
primary font name as presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created using
|
||||
the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
Binary file not shown.
@@ -0,0 +1,38 @@
|
||||
# The viewer's fonts
|
||||
|
||||
Every font the viewer draws with is in this folder or in
|
||||
`crates/ledger-import/fonts/` (the PDFs' fonts, which the viewer shares),
|
||||
each beside its licence. `theme.rs` (`font_definitions`) names them all;
|
||||
egui's own default font set is switched off, since it includes Ubuntu
|
||||
Light under the Ubuntu Font Licence 1.0, which Debian and Fedora class as
|
||||
non-free. `deny.toml` does not allow that licence, so the crate that
|
||||
carries it (`epaint_default_fonts`) cannot come back unnoticed.
|
||||
|
||||
| File | What it draws | Licence | From |
|
||||
|---|---|---|---|
|
||||
| `InterTab-Regular.ttf`, `InterTab-SemiBold.ttf`, `InterTab-Bold.ttf` | All text. Inter with tabular figures made the default and the private-use glyphs removed; named "InterTab" as a modified version | SIL OFL 1.1 (`Inter-LICENSE.txt`); Copyright 2016 The Inter Project Authors, no reserved font name | https://github.com/rsms/inter |
|
||||
| `Hack-Regular.ttf` | Fixed-width text: identifiers, hashes, JSON | MIT, and the Bitstream Vera licence for the Vera outlines it descends from (`Hack-LICENSE.txt`) | `epaint_default_fonts` 0.36.2, unchanged |
|
||||
| `NotoEmoji-Regular.ttf` | Symbols and emoji, one colour | SIL OFL 1.1 (`NotoEmoji-LICENSE.txt`); Copyright 2013 Google Inc. | `epaint_default_fonts` 0.36.2, unchanged |
|
||||
| `emoji-icon-font.ttf` | Symbols Noto Emoji lacks (arrows on a menu, the date picker) | MIT (`emoji-icon-font-LICENSE.txt`); Copyright 2014 John Slegers | `epaint_default_fonts` 0.36.2, unchanged |
|
||||
|
||||
Phosphor's icons come from the `egui-phosphor` crate (MIT).
|
||||
|
||||
Why these licences fit a program under MIT OR Apache-2.0: the SIL Open
|
||||
Font License lets a font be bundled, embedded and shipped with any
|
||||
software, sold or free. It asks that the font not be sold by itself, that
|
||||
its copyright and licence travel with it, and that a changed font stay
|
||||
under the OFL without a name the authors reserved. It is the licence of
|
||||
Inter itself and of the Noto fonts, and Debian, Fedora, the FSF and the
|
||||
OSI all accept it. The Bitstream Vera licence asks the same things. None
|
||||
of them reaches the program's own code.
|
||||
|
||||
SHA-256 of each file, so a changed font is a seen change:
|
||||
|
||||
```
|
||||
a7ef8d15be539471b4a21095930d39f3af50f676de32a21ee515225692c8d0b4 InterTab-Bold.ttf
|
||||
0e41e795bbb28ee70c6417349e430149c19e98d87485e6b6308e1ab142ee43ca InterTab-Regular.ttf
|
||||
366d6fc641ac090310828b5e9c3c33331bf0699f84cb421b283502e18ae4fcd7 InterTab-SemiBold.ttf
|
||||
15f55cc0c85a2988d2b4b3a8cdb5d77fdfbaf319e1bb5309d725db9818fb7125 Hack-Regular.ttf
|
||||
415dc6290378574135b64c808dc640c1df7531973290c4970c51fdeb849cb0c5 NotoEmoji-Regular.ttf
|
||||
f426bec371f484646d002717e2c555a95cd5145e635d83a48bbef83f3abf18ca emoji-icon-font.ttf
|
||||
```
|
||||
@@ -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.
+192
-41
@@ -2,8 +2,8 @@
|
||||
//! Inter with tabular figures, and the spacing the whole app shares.
|
||||
|
||||
use egui::{
|
||||
Color32, Context, CornerRadius, FontData, FontDefinitions, FontFamily, FontId, Margin, Stroke,
|
||||
TextStyle, Visuals,
|
||||
Color32, Context, CornerRadius, FontData, FontDefinitions, FontFamily, FontId, FontTweak,
|
||||
Margin, Stroke, TextStyle, Visuals,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -104,6 +104,8 @@ pub fn pal(ctx: &Context) -> Palette {
|
||||
|
||||
pub const SEMIBOLD: &str = "semibold";
|
||||
pub const BOLD: &str = "bold";
|
||||
/// The fixed-width face, by the name it is registered under.
|
||||
const MONO: &str = "Hack";
|
||||
|
||||
pub fn regular(size: f32) -> FontId {
|
||||
FontId::new(size, FontFamily::Proportional)
|
||||
@@ -122,63 +124,101 @@ pub fn install_fonts(ctx: &Context) {
|
||||
ctx.set_fonts(font_definitions());
|
||||
}
|
||||
|
||||
/// The viewer's fonts: Inter with tabular figures frozen in, so every
|
||||
/// number in the app lines up digit for digit; egui's own fonts and
|
||||
/// Phosphor's icons as fallbacks in every family; then the PDFs' Noto
|
||||
/// fallbacks (`ledger_import::fonts::FALLBACKS`: Chinese, Japanese,
|
||||
/// Korean, Arabic, Hebrew, Thai, Devanagari), the very bytes the PDFs use,
|
||||
/// so a name in any of those scripts shows as written, never as empty
|
||||
/// boxes, and no font is in the binary twice. (egui shapes each word,
|
||||
/// joining Arabic and setting it right to left, but doesn't reorder the
|
||||
/// words of a right-to-left phrase: they read left to right.)
|
||||
/// The viewer's fonts, every one named here and kept in `assets/fonts/`
|
||||
/// with its licence (`assets/fonts/README.md`); egui's own default set is
|
||||
/// switched off, since it carries Ubuntu Light under a licence Debian and
|
||||
/// Fedora class as non-free:
|
||||
///
|
||||
/// - Inter with tabular figures frozen in, so every number in the app
|
||||
/// lines up digit for digit: the text face, in three weights.
|
||||
/// - Hack for fixed-width text (identifiers, hashes, JSON), with Inter
|
||||
/// behind it for the letters Hack lacks.
|
||||
/// - Phosphor's icons, then Noto Emoji and the emoji icon font, as
|
||||
/// fallbacks: the symbols egui's own widgets and a Markdown document
|
||||
/// draw (a submenu's arrow, the date picker's calendar, an alert's
|
||||
/// mark), and an emoji in a memo.
|
||||
/// - The PDFs' Noto fallbacks (`ledger_import::fonts::FALLBACKS`: Chinese,
|
||||
/// Japanese, Korean, Arabic, Hebrew, Thai, Devanagari), the very bytes
|
||||
/// the PDFs use, so a name in any of those scripts shows as written,
|
||||
/// never as empty boxes, and no font is in the binary twice. (egui
|
||||
/// shapes each word, joining Arabic and setting it right to left, but
|
||||
/// doesn't reorder the words of a right-to-left phrase: they read left
|
||||
/// to right.)
|
||||
pub fn font_definitions() -> FontDefinitions {
|
||||
let mut fonts = FontDefinitions::default();
|
||||
let add = |fonts: &mut FontDefinitions, name: &str, bytes: &'static [u8]| {
|
||||
fonts
|
||||
.font_data
|
||||
.insert(name.to_owned(), Arc::new(FontData::from_static(bytes)));
|
||||
let mut fonts = FontDefinitions::empty();
|
||||
let add = |fonts: &mut FontDefinitions, name: &str, data: FontData| {
|
||||
fonts.font_data.insert(name.to_owned(), Arc::new(data));
|
||||
};
|
||||
// The two symbol fonts are drawn a little smaller, as egui draws them,
|
||||
// so a symbol sits with the text beside it.
|
||||
let smaller = |bytes: &'static [u8], scale: f32| {
|
||||
FontData::from_static(bytes).tweak(FontTweak {
|
||||
scale,
|
||||
..Default::default()
|
||||
})
|
||||
};
|
||||
add(
|
||||
&mut fonts,
|
||||
"InterTab-Regular",
|
||||
include_bytes!("../assets/fonts/InterTab-Regular.ttf"),
|
||||
FontData::from_static(include_bytes!("../assets/fonts/InterTab-Regular.ttf")),
|
||||
);
|
||||
add(
|
||||
&mut fonts,
|
||||
"InterTab-SemiBold",
|
||||
include_bytes!("../assets/fonts/InterTab-SemiBold.ttf"),
|
||||
FontData::from_static(include_bytes!("../assets/fonts/InterTab-SemiBold.ttf")),
|
||||
);
|
||||
add(
|
||||
&mut fonts,
|
||||
"InterTab-Bold",
|
||||
include_bytes!("../assets/fonts/InterTab-Bold.ttf"),
|
||||
FontData::from_static(include_bytes!("../assets/fonts/InterTab-Bold.ttf")),
|
||||
);
|
||||
add(
|
||||
&mut fonts,
|
||||
MONO,
|
||||
FontData::from_static(include_bytes!("../assets/fonts/Hack-Regular.ttf")),
|
||||
);
|
||||
add(
|
||||
&mut fonts,
|
||||
"NotoEmoji-Regular",
|
||||
smaller(
|
||||
include_bytes!("../assets/fonts/NotoEmoji-Regular.ttf"),
|
||||
0.81,
|
||||
),
|
||||
);
|
||||
add(
|
||||
&mut fonts,
|
||||
"emoji-icon-font",
|
||||
smaller(include_bytes!("../assets/fonts/emoji-icon-font.ttf"), 0.90),
|
||||
);
|
||||
egui_phosphor::add_to_fonts(&mut fonts, egui_phosphor::Variant::Regular);
|
||||
let fallbacks: Vec<String> = fonts
|
||||
.families
|
||||
.get(&FontFamily::Proportional)
|
||||
.cloned()
|
||||
.unwrap_or_default();
|
||||
// Text first, icons as a fallback. The bundled Inter copies have their
|
||||
// private-use glyphs removed, so Phosphor's icons (which live there)
|
||||
// are never shadowed.
|
||||
let family = |primary: &str| {
|
||||
let mut v = vec![primary.to_owned()];
|
||||
v.extend(fallbacks.iter().cloned());
|
||||
v
|
||||
// Text first, then icons and symbols. The bundled Inter copies have
|
||||
// their private-use glyphs removed, so Phosphor's icons (which live
|
||||
// there) are never shadowed.
|
||||
let symbols = ["NotoEmoji-Regular", "emoji-icon-font"];
|
||||
let family = |first: &[&str]| -> Vec<String> {
|
||||
first
|
||||
.iter()
|
||||
.chain(&symbols)
|
||||
.map(|name| (*name).to_owned())
|
||||
.collect()
|
||||
};
|
||||
fonts
|
||||
.families
|
||||
.insert(FontFamily::Proportional, family("InterTab-Regular"));
|
||||
fonts.families.insert(
|
||||
FontFamily::Proportional,
|
||||
family(&["InterTab-Regular", "phosphor"]),
|
||||
);
|
||||
fonts.families.insert(
|
||||
FontFamily::Name(SEMIBOLD.into()),
|
||||
family("InterTab-SemiBold"),
|
||||
family(&["InterTab-SemiBold", "phosphor"]),
|
||||
);
|
||||
fonts.families.insert(
|
||||
FontFamily::Name(BOLD.into()),
|
||||
family(&["InterTab-Bold", "phosphor"]),
|
||||
);
|
||||
fonts
|
||||
.families
|
||||
.insert(FontFamily::Name(BOLD.into()), family("InterTab-Bold"));
|
||||
.insert(FontFamily::Monospace, family(&[MONO, "InterTab-Regular"]));
|
||||
for (name, bytes) in &ledger_import::fonts::FALLBACKS {
|
||||
add(&mut fonts, name, bytes);
|
||||
add(&mut fonts, name, FontData::from_static(bytes));
|
||||
for list in fonts.families.values_mut() {
|
||||
list.push((*name).to_owned());
|
||||
}
|
||||
@@ -278,10 +318,10 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
/// font_definitions: every family ends with the PDFs' Noto fallbacks,
|
||||
/// in their order, after Inter, egui's fonts and the icons, each font
|
||||
/// the very bytes ledger-import bundles (the same pointer: one copy in
|
||||
/// the binary); and a name in each script shows with real glyphs in
|
||||
/// every family the viewer uses.
|
||||
/// in their order, after its own face, the icons and the symbol fonts,
|
||||
/// each Noto font the very bytes ledger-import bundles (the same
|
||||
/// pointer: one copy in the binary); and a name in each script shows
|
||||
/// with real glyphs in every family the viewer uses.
|
||||
#[test]
|
||||
fn every_family_falls_back_to_the_noto_fonts() {
|
||||
let defs = font_definitions();
|
||||
@@ -300,6 +340,7 @@ mod tests {
|
||||
assert_eq!(list[list.len() - names.len()..], names[..], "{family:?}");
|
||||
}
|
||||
assert!(defs.families[&FontFamily::Proportional][0] == "InterTab-Regular");
|
||||
assert!(defs.families[&FontFamily::Monospace][0] == MONO);
|
||||
for (name, bytes) in &ledger_import::fonts::FALLBACKS {
|
||||
let data: &[u8] = &defs.font_data[*name].font;
|
||||
assert!(
|
||||
@@ -334,4 +375,114 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// font_definitions: the viewer draws with the fonts it names and no
|
||||
/// others. egui's default set is off (it carries Ubuntu Light, under
|
||||
/// the Ubuntu Font Licence), so a family is exactly what theme.rs
|
||||
/// lists; and without that set nothing the viewer shows turns into an
|
||||
/// empty box: every character egui's widgets, the date picker and a
|
||||
/// Markdown document draw by themselves, and every character in the
|
||||
/// viewer's own source, has a glyph.
|
||||
#[test]
|
||||
fn the_viewer_names_every_font_and_draws_every_symbol() {
|
||||
assert!(
|
||||
FontDefinitions::default().font_data.is_empty(),
|
||||
"egui's default fonts are compiled in: a dependency switched `default_fonts` on"
|
||||
);
|
||||
let defs = font_definitions();
|
||||
let mut bundled: Vec<&str> = defs.font_data.keys().map(String::as_str).collect();
|
||||
bundled.sort_unstable();
|
||||
let mut expected = vec![
|
||||
"Hack",
|
||||
"InterTab-Bold",
|
||||
"InterTab-Regular",
|
||||
"InterTab-SemiBold",
|
||||
"NotoEmoji-Regular",
|
||||
"emoji-icon-font",
|
||||
"phosphor",
|
||||
];
|
||||
expected.extend(ledger_import::fonts::FALLBACKS.iter().map(|(n, _)| *n));
|
||||
expected.sort_unstable();
|
||||
assert_eq!(bundled, expected);
|
||||
for (family, list) in &defs.families {
|
||||
for name in list {
|
||||
assert!(defs.font_data.contains_key(name), "{family:?}: {name}");
|
||||
}
|
||||
}
|
||||
|
||||
let ctx = Context::default();
|
||||
ctx.set_fonts(defs);
|
||||
let mut out = ctx.run_ui(egui::RawInput::default(), |_| {});
|
||||
out.textures_delta.clear();
|
||||
// egui's `has_glyph` says no for every character the replacement
|
||||
// glyph's own font draws (here Noto Emoji), so it cannot be the
|
||||
// whole test. What decides is what is drawn: a character is missing
|
||||
// when its glyph is the one drawn for a code point no font has.
|
||||
let glyph = |c: char, id: &FontId| {
|
||||
let galley =
|
||||
ctx.fonts_mut(|f| f.layout_no_wrap(c.to_string(), id.clone(), Color32::WHITE));
|
||||
galley.rows[0].row.glyphs[0].uv_rect
|
||||
};
|
||||
const NO_FONT_HAS: char = '\u{0378}';
|
||||
let missing = |text: &str, id: &FontId| -> Vec<char> {
|
||||
let blank = glyph(NO_FONT_HAS, id);
|
||||
text.chars()
|
||||
.filter(|c| {
|
||||
!c.is_whitespace()
|
||||
&& !ctx.fonts_mut(|f| f.has_glyph(id, *c))
|
||||
&& glyph(*c, id) == blank
|
||||
})
|
||||
.collect()
|
||||
};
|
||||
// The test can fail: an unassigned code point is missing, and so
|
||||
// is a letter of a script no bundled font covers (Cherokee).
|
||||
const CHEROKEE: char = '\u{13E3}';
|
||||
assert_eq!(
|
||||
missing("a\u{0378}\u{2022}\u{13E3}", ®ular(14.0)),
|
||||
vec![NO_FONT_HAS, CHEROKEE]
|
||||
);
|
||||
// What the libraries draw: a submenu's arrow and the arrow keys
|
||||
// (egui), the date picker's calendar and its arrows (egui_extras),
|
||||
// a code block's copy button and the five alert marks
|
||||
// (egui_commonmark), a check mark, a bullet, an ellipsis.
|
||||
let libraries = "⏵⏴⏶⏷📆🗐✔❕💡💬🔴⚙•…";
|
||||
for id in [regular(14.0), semibold(14.0), bold(14.0)] {
|
||||
assert_eq!(missing(libraries, &id), Vec::<char>::new(), "{id:?}");
|
||||
}
|
||||
// What the viewer itself draws: every character of its source
|
||||
// outside the comments.
|
||||
let src = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("src");
|
||||
let mut files = vec![src];
|
||||
let mut seen = 0;
|
||||
while let Some(path) = files.pop() {
|
||||
if path.is_dir() {
|
||||
files.extend(std::fs::read_dir(&path).unwrap().map(|e| e.unwrap().path()));
|
||||
continue;
|
||||
}
|
||||
if path.extension().is_none_or(|e| e != "rs") {
|
||||
continue;
|
||||
}
|
||||
for (n, line) in std::fs::read_to_string(&path).unwrap().lines().enumerate() {
|
||||
let code = line.trim_start();
|
||||
if code.starts_with("//") {
|
||||
continue;
|
||||
}
|
||||
// A private-use character is a Phosphor icon by its
|
||||
// escape, and a variation selector draws nothing.
|
||||
let drawn: String = code
|
||||
.chars()
|
||||
.filter(|c| !c.is_ascii() && *c != '\u{FE0F}')
|
||||
.collect();
|
||||
seen += drawn.chars().count();
|
||||
assert_eq!(
|
||||
missing(&drawn, ®ular(14.0)),
|
||||
Vec::<char>::new(),
|
||||
"{}:{}",
|
||||
path.display(),
|
||||
n + 1
|
||||
);
|
||||
}
|
||||
}
|
||||
assert!(seen > 50, "the source walk found {seen} characters");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user