mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-29 01:34:29 +01:00
Fix #8583: document tab titles draw in a condensed face, so more tabs fit
Desktop builds with a craft-fonts checkout that has Noto Sans Condensed SemiBold in its opt-in Latin catalog (fonts/latin-manifest.txt) embed that one face as vectorcraft_text::CONDENSED_UI_FONT. Tab titles draw in a new theme::FONT_TAB family headed by it, scaled to the x-height of the interface's semibold face, with the semibold faces after it on its baseline. In a 1280 pt window, 9 tabs named "Poster draft N" fit whole instead of 8. Without CRAFT_FONTS_DIR, on the web, or with a checkout that lacks the row (a build warning), FONT_TAB is the semibold family and tabs look as before. The tab tests that count tabs measure in the semibold face.
This commit is contained in:
1 parent
88f5ece15b
commit
e67211f070
10 files changed
+171
-27
No files matched your search
+56
-15
@@ -12,6 +12,10 @@
|
||||
//! `fonts/<sha16>/` beside the wasm instead of embedding (`cargo xtask web-fonts` copies them
|
||||
//! there; `apps/vectorcraft-web/src/fonts.rs` fetches them). A list line the manifest lacks is left
|
||||
//! out with a warning, never an error, and never costs the desktop its fonts.
|
||||
//!
|
||||
//! On native targets it writes `CONDENSED_UI_FONT`: the condensed face document tab titles draw in
|
||||
//! (`CONDENSED_UI_FACE`), the one row it reads from the opt-in `fonts/latin-manifest.txt`. A
|
||||
//! checkout without that row leaves it `None` with a warning, never an error.
|
||||
|
||||
use std::fmt::Write as _;
|
||||
use std::path::{Path, PathBuf};
|
||||
@@ -25,7 +29,7 @@ fn main() {
|
||||
println!("cargo::rerun-if-changed=web-fonts.txt");
|
||||
println!("cargo::rerun-if-changed=build/web_fonts.rs");
|
||||
let required = std::env::var_os("CRAFT_FONTS_REQUIRED").is_some();
|
||||
let (mut fonts, mut web) = (String::new(), String::new());
|
||||
let (mut fonts, mut web, mut condensed) = (String::new(), String::new(), String::from("None"));
|
||||
if let Some(dir) = std::env::var_os("CRAFT_FONTS_DIR").filter(|d| !d.is_empty()).map(PathBuf::from) {
|
||||
let dir = from_workspace(dir);
|
||||
match craft_fonts(&dir) {
|
||||
@@ -48,8 +52,16 @@ fn main() {
|
||||
Err(e) if required => println!("cargo::error=web-fonts.txt: {e}"),
|
||||
Err(e) => println!("cargo::warning=web build fetches no craft fonts: web-fonts.txt: {e}"),
|
||||
}
|
||||
if std::env::var("CARGO_CFG_TARGET_ARCH").is_ok_and(|a| a != "wasm32") {
|
||||
match condensed_ui_font(&dir) {
|
||||
Ok(entry) => condensed = format!("Some({entry})"),
|
||||
Err(e) => println!("cargo::warning=document tabs draw in the interface face: CRAFT_FONTS_DIR={}: {e}", dir.display()),
|
||||
}
|
||||
}
|
||||
}
|
||||
let src = format!("pub static CRAFT_FONTS: &[CraftFont] = &[\n{fonts}];\npub static WEB_FONTS: &[WebFont] = &[\n{web}];\n");
|
||||
let src = format!(
|
||||
"pub static CRAFT_FONTS: &[CraftFont] = &[\n{fonts}];\npub static WEB_FONTS: &[WebFont] = &[\n{web}];\npub static CONDENSED_UI_FONT: Option<CraftFont> = {condensed};\n"
|
||||
);
|
||||
let out = PathBuf::from(std::env::var_os("OUT_DIR").unwrap_or_default()).join("craft_fonts.rs");
|
||||
// Unchanged output keeps its mtime. Rewritten just before this crate compiles, it can read as
|
||||
// newer than that compile where cargo's recorded times lose their sub-second part (ecryptfs
|
||||
@@ -91,23 +103,52 @@ fn craft_fonts(dir: &Path) -> Result<String, String> {
|
||||
if wasm && !(*family == WEB_FONT.0 && *style == WEB_FONT.1) {
|
||||
continue;
|
||||
}
|
||||
let path = dir.join(file).canonicalize().map_err(|e| format!("{file}: {e}"))?;
|
||||
// The manifest is supplier data: embed only regular files inside the checkout.
|
||||
if !path.starts_with(&root) || !path.is_file() {
|
||||
return Err(format!("{file}: not a file inside the font checkout"));
|
||||
}
|
||||
println!("cargo::rerun-if-changed={}", path.display());
|
||||
let scripts: Vec<String> = scripts.split(',').map(|s| format!("{:?}", s.trim())).collect();
|
||||
let _ = writeln!(
|
||||
out,
|
||||
" CraftFont {{ family: {family:?}, style: {style:?}, scripts: &[{}], bytes: include_bytes!({:?}) }},",
|
||||
scripts.join(", "),
|
||||
path.display().to_string(),
|
||||
);
|
||||
let _ = writeln!(out, " {},", craft_font(dir, &root, family, style, file, scripts)?);
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// The `CraftFont { .. }` initialiser of one manifest row of the checkout `dir` (canonical `root`).
|
||||
fn craft_font(dir: &Path, root: &Path, family: &str, style: &str, file: &str, scripts: &str) -> Result<String, String> {
|
||||
let path = dir.join(file).canonicalize().map_err(|e| format!("{file}: {e}"))?;
|
||||
// The manifest is supplier data: embed only regular files inside the checkout.
|
||||
if !path.starts_with(root) || !path.is_file() {
|
||||
return Err(format!("{file}: not a file inside the font checkout"));
|
||||
}
|
||||
println!("cargo::rerun-if-changed={}", path.display());
|
||||
let scripts: Vec<String> = scripts.split(',').map(|s| format!("{:?}", s.trim())).collect();
|
||||
Ok(format!(
|
||||
"CraftFont {{ family: {family:?}, style: {style:?}, scripts: &[{}], bytes: include_bytes!({:?}) }}",
|
||||
scripts.join(", "),
|
||||
path.display().to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
/// The condensed craft-fonts face (family, style) document tab titles draw in, from the opt-in
|
||||
/// Latin catalog.
|
||||
const CONDENSED_UI_FACE: (&str, &str) = ("Noto Sans", "Condensed SemiBold");
|
||||
|
||||
/// The `CraftFont { .. }` initialiser of [`CONDENSED_UI_FACE`]'s row in `fonts/latin-manifest.txt`.
|
||||
fn condensed_ui_font(dir: &Path) -> Result<String, String> {
|
||||
let manifest = dir.join("fonts/latin-manifest.txt");
|
||||
// A checkout without the catalog is watched through its folder, so the build runs again once
|
||||
// the catalog appears.
|
||||
let watched = if manifest.is_file() { manifest.clone() } else { dir.join("fonts") };
|
||||
println!("cargo::rerun-if-changed={}", watched.display());
|
||||
let text = std::fs::read_to_string(&manifest).map_err(|e| format!("{}: {e} (an older craft-fonts?)", manifest.display()))?;
|
||||
let root = dir.canonicalize().map_err(|e| format!("{}: {e}", dir.display()))?;
|
||||
let row = text
|
||||
.lines()
|
||||
.map(str::trim)
|
||||
.filter(|l| !l.is_empty() && !l.starts_with('#'))
|
||||
.map(|l| l.split(" | ").map(str::trim).collect::<Vec<_>>())
|
||||
.find(|f| f.first() == Some(&CONDENSED_UI_FACE.0) && f.get(1) == Some(&CONDENSED_UI_FACE.1));
|
||||
let Some([family, style, file, scripts, ..]) = row.as_deref() else {
|
||||
return Err(format!("{} {} not in {} (an older craft-fonts?)", CONDENSED_UI_FACE.0, CONDENSED_UI_FACE.1, manifest.display()));
|
||||
};
|
||||
craft_font(dir, &root, family, style, file, scripts)
|
||||
}
|
||||
|
||||
/// One `WebFont { .. }` initialiser per `web-fonts.txt` line, from its craft-fonts manifest row, and
|
||||
/// the listed faces the manifest lacks (an older craft-fonts checkout), which are left out.
|
||||
fn web_font_entries(dir: &Path) -> Result<(String, Vec<String>), String> {
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
//! Built with `CRAFT_FONTS_DIR=<craft-fonts checkout>`, [`CRAFT_FONTS`] holds every font in its
|
||||
//! manifest (Japanese UI and document fonts, Arabic fonts and Noto Sans Thai); built without it,
|
||||
//! it is empty and that text falls back to the installed system fonts. Release builds always set it. See `build.rs`.
|
||||
//! [`CONDENSED_UI_FONT`] is the condensed face document tab titles draw in, from the checkout's
|
||||
//! opt-in Latin catalog: `None` on wasm32, without `CRAFT_FONTS_DIR`, or with a checkout that
|
||||
//! lacks it.
|
||||
|
||||
/// A font from the optional craft-fonts build input (empty unless built with `CRAFT_FONTS_DIR`).
|
||||
pub struct CraftFont {
|
||||
|
||||
+10
-1
@@ -37,7 +37,7 @@ pub mod thread;
|
||||
|
||||
pub use bitmap::GlyphImage;
|
||||
pub use context_alternates::{ContextAlternate, ContextAlternates, alternate_changes, alternates_in_context, is_alternate_feature};
|
||||
pub use craft_fonts::{CRAFT_FONTS, CraftFont, WEB_FONTS, WebFont};
|
||||
pub use craft_fonts::{CONDENSED_UI_FONT, CRAFT_FONTS, CraftFont, WEB_FONTS, WebFont};
|
||||
pub use features::{
|
||||
EXTRA_FEATURES, LIGATURE_TRACKING_LIMITS, MAX_FEATURE_VALUE, MAX_STYLE_FEATURES, OtFeatures, explicit_ligatures, ligatures_suppressed_by,
|
||||
};
|
||||
@@ -1059,6 +1059,15 @@ pub fn line_metrics(data: &[u8], index: u32) -> Option<(f32, f32, f32, f32)> {
|
||||
Some((f32::from(m.units_per_em.max(1)), m.ascent, m.descent, m.leading))
|
||||
}
|
||||
|
||||
/// The x-height of the font at `index` of `data`, at its default axis settings, in ems. `None` if
|
||||
/// the font can't be read or gives no x-height.
|
||||
pub fn x_height(data: &[u8], index: u32) -> Option<f32> {
|
||||
use skrifa::MetadataProvider;
|
||||
let f = skrifa::FontRef::from_index(data, index).ok()?;
|
||||
let m = f.metrics(skrifa::instance::Size::unscaled(), skrifa::instance::LocationRef::default());
|
||||
m.x_height.filter(|h| *h > 0.0).map(|h| h / f32::from(m.units_per_em.max(1)))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -56,7 +56,7 @@ pub(crate) fn window_tab(app: &VectorcraftApp, ui: &mut Ui, w: crate::doc_window
|
||||
ui.painter().rect_filled(strip, 0.0, t.tab_strip);
|
||||
ui.painter().line_segment([strip.left_bottom(), strip.right_bottom()], Stroke::new(1.0, t.border));
|
||||
let title = document_window_title(app, w).unwrap_or_default();
|
||||
let galley = ui.painter().layout_no_wrap(title, theme::semibold(title_size), t.text_strong);
|
||||
let galley = ui.painter().layout_no_wrap(title, theme::tab_font(title_size), t.text_strong);
|
||||
let r = egui::Rect::from_min_size(strip.min, vec2((galley.size().x + 28.0).min(strip.width()), strip.height() - 1.0));
|
||||
ui.painter().rect_filled(r, 0.0, t.panel);
|
||||
ui.painter().line_segment([r.right_top(), r.right_bottom()], Stroke::new(1.5, t.border));
|
||||
@@ -190,7 +190,8 @@ fn tab_close_box(ui: &Ui, t: &Tokens, xr: egui::Rect, w: f32, id: egui::Id) -> O
|
||||
/// (#746). The first tab that doesn't fit whole fills the room left before the » button with its
|
||||
/// title shortened, when that room holds some of the title (#8584). When the active tab is among
|
||||
/// the last ones and the tabs from it to the end leave room, the tab before them fills that room
|
||||
/// instead. An active tab wider than the whole strip is shortened to it.
|
||||
/// instead. An active tab wider than the whole strip is shortened to it. Titles draw in
|
||||
/// [`theme::FONT_TAB`], a condensed face in builds with craft-fonts (#8583).
|
||||
/// Each view Window › New Window opened has a tab of its own. Windows floating have no tab
|
||||
/// ([`crate::doc_windows`]); while the current window is a floating one, the tab of the window the
|
||||
/// strip shows is the highlighted one. A tab dragged more than [`crate::doc_windows::TEAR_OFF`]
|
||||
@@ -224,7 +225,7 @@ pub fn doc_tabs(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
let title = window_tab_title(app, w, d);
|
||||
let (text, color) =
|
||||
if Some(w) == shown { (title.clone(), t.text_strong) } else { (view_tab_name(d, crate::doc_windows::label(app, w)), t.text_dim) };
|
||||
let galley = ui.painter().layout_no_wrap(text.clone(), theme::semibold(title_size), color);
|
||||
let galley = ui.painter().layout_no_wrap(text.clone(), theme::tab_font(title_size), color);
|
||||
(w, text, title, galley)
|
||||
})
|
||||
.collect();
|
||||
@@ -258,7 +259,7 @@ pub fn doc_tabs(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
break;
|
||||
}
|
||||
let color = if Some(*win) == shown { t.text_strong } else { t.text_dim };
|
||||
let (galley, fits) = shortened_title(ui.ctx(), text, theme::semibold(title_size), color, left - TAB_PADDING);
|
||||
let (galley, fits) = shortened_title(ui.ctx(), text, theme::tab_font(title_size), color, left - TAB_PADDING);
|
||||
(galley, left.max(0.0), true, fits)
|
||||
} else {
|
||||
(galley.clone(), *w, false, true)
|
||||
|
||||
@@ -1498,6 +1498,7 @@ fn bundled_fonts_cover_the_catalogs() {
|
||||
egui::FontFamily::Proportional,
|
||||
egui::FontFamily::Name(crate::theme::FONT_UI.into()),
|
||||
egui::FontFamily::Name(crate::theme::FONT_UI_SEMIBOLD.into()),
|
||||
egui::FontFamily::Name(crate::theme::FONT_TAB.into()),
|
||||
egui::FontFamily::Name(crate::theme::FONT_MONO.into()),
|
||||
];
|
||||
for l in LANGUAGES.iter().filter(|l| !l.source.is_empty()) {
|
||||
|
||||
@@ -44,6 +44,12 @@ fn frame_sized(app: &mut VectorcraftApp, ctx: &egui::Context, size: egui::Vec2,
|
||||
texts
|
||||
}
|
||||
|
||||
/// The interface fonts with tab titles in the semibold face, as in a build without craft-fonts'
|
||||
/// condensed face: the tab counts below are measured in it.
|
||||
fn install_semibold_tab_fonts(ctx: &egui::Context) {
|
||||
ctx.set_fonts(crate::theme::interface_fonts_with(None));
|
||||
}
|
||||
|
||||
fn click(at: Pos2, pressed: bool) -> Event {
|
||||
Event::PointerButton { pos: at, button: PointerButton::Primary, pressed, modifiers: Default::default() }
|
||||
}
|
||||
@@ -61,7 +67,7 @@ fn the_tab_that_does_not_fit_whole_fills_the_rest_of_the_strip() {
|
||||
app.session.set_active(0);
|
||||
app.sync_views();
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
install_semibold_tab_fonts(&ctx);
|
||||
let texts = frame(&mut app, &ctx, 0.0, vec![]);
|
||||
let mut tabs: Vec<(String, egui::Rect)> = texts.into_iter().filter(|(t, _)| t.starts_with("Tab test")).collect();
|
||||
tabs.sort_by(|a, b| a.1.left().total_cmp(&b.1.left()));
|
||||
@@ -100,7 +106,7 @@ fn inactive_tabs_show_the_name_alone_so_more_tabs_fit() {
|
||||
app.session.set_active(0);
|
||||
app.sync_views();
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
install_semibold_tab_fonts(&ctx);
|
||||
let texts = frame(&mut app, &ctx, 0.0, vec![]);
|
||||
let mut tabs: Vec<(String, egui::Rect)> = texts.into_iter().filter(|(t, _)| t.starts_with("Tab test")).collect();
|
||||
tabs.sort_by(|a, b| a.1.left().total_cmp(&b.1.left()));
|
||||
@@ -118,6 +124,35 @@ fn inactive_tabs_show_the_name_alone_so_more_tabs_fit() {
|
||||
assert!(texts.iter().any(|(t, _)| t == "Tab test 2 @ 100 % (RGB/Preview)"), "the tooltip shows the whole title: {texts:?}");
|
||||
}
|
||||
|
||||
/// With craft-fonts' condensed face, tab titles draw in it at the semibold face's x-height, and
|
||||
/// more tabs fit whole in the strip of a 1280 pt window than with the semibold face (#8583).
|
||||
#[test]
|
||||
fn tab_titles_in_the_condensed_face_fit_more_tabs() {
|
||||
let Some(condensed) = vectorcraft_text::CONDENSED_UI_FONT.as_ref() else {
|
||||
eprintln!("skipped: built without craft-fonts' condensed face (set CRAFT_FONTS_DIR to a craft-fonts checkout that has it)");
|
||||
return;
|
||||
};
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
for i in 0..24 {
|
||||
app.run("file.new", json!({"width": 100, "height": 100, "name": format!("Poster draft {i}")})).unwrap();
|
||||
}
|
||||
app.session.set_active(0);
|
||||
app.sync_views();
|
||||
let mut whole_tabs = |face: Option<&vectorcraft_text::CraftFont>| {
|
||||
let ctx = egui::Context::default();
|
||||
ctx.set_fonts(crate::theme::interface_fonts_with(face));
|
||||
let texts = frame_sized(&mut app, &ctx, egui::vec2(1280.0, 700.0), 0.0, vec![]);
|
||||
let whole = texts.iter().filter(|(t, _)| t.starts_with("Poster draft") && !t.ends_with('…')).count();
|
||||
// The height of an x, in the tab font and in semibold text.
|
||||
let x = |font: egui::FontId| ctx.fonts_mut(|f| f.layout_no_wrap("x".into(), font, egui::Color32::WHITE)).rows[0].glyphs[0].uv_rect.size.y;
|
||||
(whole, x(crate::theme::tab_font(40.0)), x(crate::theme::semibold(40.0)))
|
||||
};
|
||||
let (semibold, _, _) = whole_tabs(None);
|
||||
let (narrow, x_tab, x_semibold) = whole_tabs(Some(condensed));
|
||||
assert!(narrow > semibold, "more tabs fit whole in the condensed face: {narrow} against {semibold}");
|
||||
assert!((x_tab - x_semibold).abs() <= 1.0, "an x is {x_tab} pt tall in a tab title and {x_semibold} pt in semibold text");
|
||||
}
|
||||
|
||||
/// With the last document active, the tabs from it to the end leave room before the » button, and
|
||||
/// the tab before them fills that room with its title shortened instead of the strip ending short
|
||||
/// of the » button (#8584).
|
||||
@@ -132,7 +167,7 @@ fn with_the_last_document_active_the_tab_before_the_shown_ones_fills_the_room()
|
||||
app.session.set_active(7);
|
||||
app.sync_views();
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
install_semibold_tab_fonts(&ctx);
|
||||
let texts = frame(&mut app, &ctx, 0.0, vec![]);
|
||||
let mut tabs: Vec<(String, egui::Rect)> = texts.into_iter().filter(|(t, _)| t.starts_with("Tab test")).collect();
|
||||
tabs.sort_by(|a, b| a.1.left().total_cmp(&b.1.left()));
|
||||
|
||||
@@ -494,16 +494,29 @@ pub fn strong_selected_text(ui: &mut egui::Ui) {
|
||||
pub const FONT_UI: &str = "ui";
|
||||
pub const FONT_UI_SEMIBOLD: &str = "ui-semibold";
|
||||
pub const FONT_MONO: &str = "mono";
|
||||
/// The family document tab titles draw in. In a build with craft-fonts' condensed face
|
||||
/// ([`vectorcraft_text::CONDENSED_UI_FONT`]), that face heads it, at the x-height of the
|
||||
/// [`FONT_UI_SEMIBOLD`] face, followed by the faces of [`FONT_UI_SEMIBOLD`] on its baseline, so
|
||||
/// more tabs fit in the strip (#8583). Without it the family is [`FONT_UI_SEMIBOLD`]'s.
|
||||
pub const FONT_TAB: &str = "tab";
|
||||
|
||||
pub fn semibold(size: f32) -> FontId {
|
||||
FontId::new(size, FontFamily::Name(FONT_UI_SEMIBOLD.into()))
|
||||
}
|
||||
/// A document tab's title font ([`FONT_TAB`]).
|
||||
pub fn tab_font(size: f32) -> FontId {
|
||||
FontId::new(size, FontFamily::Name(FONT_TAB.into()))
|
||||
}
|
||||
/// Whether `family` draws semibold text and takes the bold fallback faces.
|
||||
pub(crate) fn is_semibold(family: &FontFamily) -> bool {
|
||||
matches!(family, FontFamily::Name(name) if [FONT_UI_SEMIBOLD, FONT_TAB].contains(&&**name))
|
||||
}
|
||||
pub fn mono(size: f32) -> FontId {
|
||||
FontId::new(size, FontFamily::Name(FONT_MONO.into()))
|
||||
}
|
||||
|
||||
/// Installs the interface's fonts and binds the families the panels and dialogs draw in
|
||||
/// ([`FONT_UI`], [`FONT_UI_SEMIBOLD`], [`FONT_MONO`]). egui 0.37 only bundles its own faces when
|
||||
/// ([`FONT_UI`], [`FONT_UI_SEMIBOLD`], [`FONT_TAB`], [`FONT_MONO`]). egui 0.37 only bundles its own faces when
|
||||
/// its `default_fonts` feature is on (this crate enables it); without any face a family lays out
|
||||
/// tofu, and the `egui_kittest` harness alone panics on a missing glyph. Every context that shows
|
||||
/// these families needs this once: [`crate::VectorcraftApp::ui`] calls it on its first pass, and
|
||||
@@ -520,6 +533,11 @@ pub fn install_fonts(ctx: &egui::Context) {
|
||||
/// whether egui applied them at once or deferred them to the next pass (it must not take input
|
||||
/// or draw with fallback metrics while they are pending).
|
||||
pub fn interface_fonts() -> FontDefinitions {
|
||||
interface_fonts_with(vectorcraft_text::CONDENSED_UI_FONT.as_ref())
|
||||
}
|
||||
|
||||
/// [`interface_fonts`] with `condensed` as the face that heads [`FONT_TAB`].
|
||||
pub(crate) fn interface_fonts_with(condensed: Option<&vectorcraft_text::CraftFont>) -> FontDefinitions {
|
||||
let mut fonts = FontDefinitions::default();
|
||||
let (ui, semi, mono) = interface_faces(&mut fonts);
|
||||
let stack = |fonts: &FontDefinitions, family: FontFamily| fonts.families.get(&family).cloned().unwrap_or_default();
|
||||
@@ -529,13 +547,42 @@ pub fn interface_fonts() -> FontDefinitions {
|
||||
let family =
|
||||
|faces: Vec<&str>, fallback: &[String]| -> Vec<String> { faces.into_iter().map(str::to_owned).chain(fallback.iter().cloned()).collect() };
|
||||
fonts.families.insert(FontFamily::Proportional, family(ui.clone(), &fallback));
|
||||
fonts.families.insert(FontFamily::Name(FONT_UI_SEMIBOLD.into()), family(semi, &fallback));
|
||||
let semi = family(semi, &fallback);
|
||||
let tab = tab_faces(&mut fonts, &semi, condensed);
|
||||
fonts.families.insert(FontFamily::Name(FONT_UI_SEMIBOLD.into()), semi);
|
||||
fonts.families.insert(FontFamily::Name(FONT_TAB.into()), tab);
|
||||
fonts.families.insert(FontFamily::Name(FONT_UI.into()), family(ui, &fallback));
|
||||
fonts.families.insert(FontFamily::Name(FONT_MONO.into()), family(mono, &mono_fallback));
|
||||
add_craft_fonts(&mut fonts);
|
||||
fonts
|
||||
}
|
||||
|
||||
/// The faces of [`FONT_TAB`], added to `fonts`: `condensed`, scaled to the x-height of the first
|
||||
/// face of `semi` (the [`FONT_UI_SEMIBOLD`] stack), then a copy of each face of `semi` on its
|
||||
/// baseline. `semi` itself without `condensed`, or when either face's x-height can't be read.
|
||||
fn tab_faces(fonts: &mut FontDefinitions, semi: &[String], condensed: Option<&vectorcraft_text::CraftFont>) -> Vec<String> {
|
||||
let x_height = |data: &FontData| vectorcraft_text::x_height((*data.font).as_ref(), data.index).map(|h| h * data.tweak.scale);
|
||||
let reference = semi.first().and_then(|head| fonts.font_data.get(head)).and_then(|data| x_height(data));
|
||||
let Some((f, reference)) = condensed.zip(reference) else { return semi.to_vec() };
|
||||
let Some(own) = vectorcraft_text::x_height(f.bytes, 0) else { return semi.to_vec() };
|
||||
let name = craft_font_name(f);
|
||||
let head = FontData::from_static(f.bytes).tweak(egui::epaint::text::FontTweak { scale: reference / own, ..Default::default() });
|
||||
// `baseline_copies` reads the head of each family it is given: here only this one.
|
||||
let mut row = FontDefinitions::empty();
|
||||
row.font_data.insert(name.clone(), Arc::new(head.clone()));
|
||||
row.families.insert(FontFamily::Name(FONT_TAB.into()), vec![name.clone()]);
|
||||
let mut faces = vec![name.clone()];
|
||||
for face in semi {
|
||||
let Some(data) = fonts.font_data.get(face).cloned() else { continue };
|
||||
for (copy, data, _) in crate::ui_fonts::baseline_copies(&row, &format!("{face} / {name}"), &data) {
|
||||
fonts.font_data.insert(copy.clone(), Arc::new(data));
|
||||
faces.push(copy);
|
||||
}
|
||||
}
|
||||
fonts.font_data.insert(name, Arc::new(head));
|
||||
faces
|
||||
}
|
||||
|
||||
/// The interface's own faces, added to `fonts`: the names of the regular, semibold and monospace
|
||||
/// faces that head their families, in order.
|
||||
#[cfg(feature = "interface-fonts")]
|
||||
@@ -587,7 +634,7 @@ fn add_craft_fonts(fonts: &mut FontDefinitions) {
|
||||
}
|
||||
}
|
||||
for (family, stack) in fonts.families.iter_mut() {
|
||||
let bold = *family == FontFamily::Name(FONT_UI_SEMIBOLD.into());
|
||||
let bold = is_semibold(family);
|
||||
let copy = |f: &vectorcraft_text::CraftFont| {
|
||||
let name = craft_font_name(f);
|
||||
copies.get(&(family.clone(), name.clone())).cloned().unwrap_or(name)
|
||||
|
||||
@@ -454,7 +454,7 @@ mod tests {
|
||||
let bottom = |g: &egui::epaint::text::Glyph| g.pos.y + g.uv_rect.offset.y + g.uv_rect.size.y;
|
||||
let glyphs = |text: &str, font: FontId| ctx.fonts_mut(|f| f.layout_no_wrap(text.into(), font, egui::Color32::WHITE)).rows[0].glyphs.clone();
|
||||
for family in families {
|
||||
let semibold = family == FontFamily::Name(crate::theme::FONT_UI_SEMIBOLD.into());
|
||||
let semibold = crate::theme::is_semibold(&family);
|
||||
for &(regular, bold, c) in &probes {
|
||||
let face = if semibold { bold } else { regular };
|
||||
for size in [13.0_f32, 24.0, 40.0] {
|
||||
|
||||
@@ -174,6 +174,12 @@ CRAFT_FONTS_DIR="$PWD/../craft-fonts" cargo xtask ci # also runs the Japanese-
|
||||
Noto Sans Georgian for the Georgian interface), after the UI fonts and before the installed fonts
|
||||
`ui_fonts.rs` discovers for other scripts. On the web, Noto Sans Georgian is fetched at startup
|
||||
and reaches the UI through `ui_fonts.rs`.
|
||||
- Document tab titles: on desktop builds, `crates/text/build.rs` also reads one row of the
|
||||
checkout's opt-in `fonts/latin-manifest.txt`, Noto Sans Condensed SemiBold, as
|
||||
`vectorcraft_text::CONDENSED_UI_FONT`. `theme::FONT_TAB` draws the titles in it at the
|
||||
x-height of the interface's semibold face, so more tabs fit in the strip. Without
|
||||
`CRAFT_FONTS_DIR`, on the web, or with a checkout that lacks the row (a build warning), tab
|
||||
titles draw in the semibold face.
|
||||
- Tests that need Japanese or Georgian glyphs skip with a message when built without craft-fonts. The FreeBSD
|
||||
CI job and every release job (`release.yml`) check craft-fonts out at a pinned commit; release
|
||||
packages carry each embedded font's `OFL-<family>.txt`.
|
||||
|
||||
@@ -443,6 +443,7 @@ next unit in the order a right-click on a ruler lists them, from Feet back to Po
|
||||
| A middle-click on a document tab or its × closes it as the × does; closing a modified document's last view asks to save first (VectorCraft addition, as in PhotoCraft) | done | #6506; `chrome::tests::a_middle_click_on_a_tab_closes_it_as_the_close_box_does`; not scored |
|
||||
| When the document tabs don't all fit, the first tab that doesn't fit whole fills the room before the » button with its title shortened and ending in "…", once that room leaves at least 40 pt for the title; with the active tab among the last ones, the tab before the ones shown fills the room left at the start instead; an active tab wider than the strip is shortened to it, and a tab narrower than 25 pt shows no ×; the tooltip of a shortened tab shows the whole title, wrapped to the window (VectorCraft's own rule) | done | #8584; `tests::tab_overflow`; not scored |
|
||||
| An inactive document tab shows the document's name, the view number and the unsaved-changes mark, without the zoom and the mode in parentheses (the color mode and view, or the opacity mask being edited); the active tab keeps its whole title, and an inactive tab's tooltip shows the whole title (VectorCraft's own rule) | done | #8582; `tests::tab_overflow::inactive_tabs_show_the_name_alone_so_more_tabs_fit`; not scored |
|
||||
| Document tab titles draw in a condensed face (craft-fonts' Noto Sans Condensed SemiBold) at the x-height of the interface's semibold face, so more tabs fit; builds without that face draw them in the semibold face (VectorCraft's own rule) | done | #8583; `tests::tab_overflow::tab_titles_in_the_condensed_face_fit_more_tabs`; not scored |
|
||||
| Panels hidden by Tab or Shift+Tab show for a while when the pointer rests on the left or right edge of the window, over the canvas, and hide again when it moves away; Tab shows them for good | done | Part of #5661; `window.panels.peek` ([Workspace basics](https://web.archive.org/web/2014/https://helpx.adobe.com/illustrator/using/workspace-basics.html), "Hide or show all panels"); VectorCraft's own choices: the 6 pt band and the 0.3 s delays, only the docked panels on that side show (floating panels, Tools and the Control bar stay hidden), and nothing shows in Presentation Mode; `panel_docking::tests::resting_on_the_right_edge_shows_the_hidden_panels_over_the_canvas_until_the_pointer_leaves` and the tests after it |
|
||||
|
||||
| Behaviour | Status | Notes |
|
||||
|
||||
Reference in new issue
Block a user