|
|
|
@@ -1,5 +1,8 @@
|
|
|
|
|
use std::path::Path;
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
|
|
use craft::font_manager::Catalog;
|
|
|
|
|
use craft::font_manager::craft_font_catalog::{Limits, Source};
|
|
|
|
|
use craft::font_manager::craft_font_catalog::{FontEnv, Os};
|
|
|
|
|
use craft::ui::buttons::IconButton;
|
|
|
|
|
use craft::ui::contract::{Props as _, Show as _};
|
|
|
|
|
use egui::accesskit::Role;
|
|
|
|
@@ -10,25 +13,14 @@ use wordcraft_engine::Session;
|
|
|
|
|
|
|
|
|
|
use crate::{Services, WordApp};
|
|
|
|
|
|
|
|
|
|
fn ensure_catalog_ready() {
|
|
|
|
|
let catalog = Catalog::global();
|
|
|
|
|
catalog.scan_in_background();
|
|
|
|
|
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(10);
|
|
|
|
|
while !catalog.is_ready() && std::time::Instant::now() < deadline {
|
|
|
|
|
std::thread::sleep(std::time::Duration::from_millis(10));
|
|
|
|
|
}
|
|
|
|
|
assert!(catalog.is_ready(), "font catalog finished scanning");
|
|
|
|
|
|
|
|
|
|
let families = catalog.families();
|
|
|
|
|
for (family, bytes) in [
|
|
|
|
|
("Inter", include_bytes!("../../../../assets/fonts/Inter-Regular.ttf").as_slice()),
|
|
|
|
|
("JetBrains Mono", include_bytes!("../../../../assets/fonts/JetBrainsMono-Regular.ttf").as_slice()),
|
|
|
|
|
("Source Serif 4", include_bytes!("../../../../assets/fonts/SourceSerif4-Regular.ttf").as_slice()),
|
|
|
|
|
] {
|
|
|
|
|
if !families.iter().any(|f| f == family) {
|
|
|
|
|
let _ = catalog.add_bytes(bytes.to_vec(), Source::Bundled, &Limits::default());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fn fixed_catalog() -> Arc<Catalog> {
|
|
|
|
|
let env = FontEnv { os: Os::None, ..Default::default() };
|
|
|
|
|
let catalog = Arc::new(Catalog::new(env).with_font_service(false));
|
|
|
|
|
catalog.set_app_dirs(vec![Path::new(env!("CARGO_MANIFEST_DIR")).join("../../assets/fonts")]);
|
|
|
|
|
catalog.rescan();
|
|
|
|
|
assert!(catalog.is_ready(), "fixed font catalog scanned synchronously");
|
|
|
|
|
assert!(catalog.families().iter().any(|f| f == "Inter"), "fixed catalog loaded assets/fonts");
|
|
|
|
|
catalog
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn open_ribbon_font_box(h: &mut egui_kittest::Harness<'static, WordApp>) {
|
|
|
|
@@ -59,10 +51,11 @@ fn current_font(h: &mut egui_kittest::Harness<'static, WordApp>) -> Option<Strin
|
|
|
|
|
/// when recent fonts exist, and Arrow-Down skips section headings rather than landing on them.
|
|
|
|
|
#[test]
|
|
|
|
|
fn font_list_sections_skip_their_headings() {
|
|
|
|
|
ensure_catalog_ready();
|
|
|
|
|
let catalog = fixed_catalog();
|
|
|
|
|
|
|
|
|
|
let mut app = WordApp::new(Session::new(wordcraft_doc::Document::from_text("Sample")), Services::default());
|
|
|
|
|
app.ui.language = "en".into();
|
|
|
|
|
app.font_catalog = Some(Arc::clone(&catalog));
|
|
|
|
|
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_eframe(|_| app);
|
|
|
|
|
h.run_steps(4);
|
|
|
|
|
|
|
|
|
@@ -89,6 +82,7 @@ fn font_list_sections_skip_their_headings() {
|
|
|
|
|
// heading and land on `first_all`, so Enter switches the document font to `first_all`.
|
|
|
|
|
let mut app = WordApp::new(Session::new(wordcraft_doc::Document::from_text("Sample")), Services::default());
|
|
|
|
|
app.ui.language = "en".into();
|
|
|
|
|
app.font_catalog = Some(catalog);
|
|
|
|
|
app.run("format.font", json!({"name": chosen_recent})).unwrap();
|
|
|
|
|
assert_eq!(app.ui.font_picker.recent, [chosen_recent.as_str()]);
|
|
|
|
|
assert_eq!(app.session.run("format.state", &json!({})).unwrap().get("font").and_then(Value::as_str), Some(chosen_recent.as_str()));
|
|
|
|
@@ -237,10 +231,10 @@ fn drawn_buttons_fade_in_on_hover_and_darken_while_pressed() {
|
|
|
|
|
#[test]
|
|
|
|
|
fn the_typed_list_shows_on_the_frame_of_the_keystroke() {
|
|
|
|
|
const RECENT: &str = "Source Serif 4";
|
|
|
|
|
ensure_catalog_ready();
|
|
|
|
|
|
|
|
|
|
let mut app = WordApp::new(Session::new(wordcraft_doc::Document::from_text("Sample")), Services::default());
|
|
|
|
|
app.ui.language = "en".into();
|
|
|
|
|
app.font_catalog = Some(fixed_catalog());
|
|
|
|
|
app.ui.font_picker.recent = vec![RECENT.to_string()];
|
|
|
|
|
let mut family = String::new();
|
|
|
|
|
|
|
|
|
@@ -268,12 +262,12 @@ fn the_typed_list_shows_on_the_frame_of_the_keystroke() {
|
|
|
|
|
let frames: [(Vec<egui::Event>, &[&str], &[&str], bool); 7] = [
|
|
|
|
|
// Typing an unmatched query clears the list; one Backspace restores recents + all fonts on that frame.
|
|
|
|
|
(vec![egui::Event::Text("!".into())], &[], &[RECENT, "Inter", "JetBrains Mono"], false),
|
|
|
|
|
(erase(), &[RECENT], &[], true),
|
|
|
|
|
(erase(), &[RECENT, "Inter", "JetBrains Mono"], &[], true),
|
|
|
|
|
// Typing narrows immediately on the keystroke frame and excludes non-matching families.
|
|
|
|
|
(vec![egui::Event::Text("jet".into())], &["JetBrains Mono"], &["Inter", RECENT], false),
|
|
|
|
|
(erase(), &["JetBrains Mono"], &["Inter"], false),
|
|
|
|
|
(erase(), &["JetBrains Mono"], &["Inter"], false),
|
|
|
|
|
(erase(), &[RECENT], &[], true),
|
|
|
|
|
(erase(), &[RECENT, "Inter", "JetBrains Mono"], &[], true),
|
|
|
|
|
(vec![egui::Event::Text("int".into())], &["Inter"], &["JetBrains Mono"], false),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
@@ -302,27 +296,15 @@ fn the_typed_list_shows_on_the_frame_of_the_keystroke() {
|
|
|
|
|
assert!(texts.iter().all(|t| t != label), "keystroke {n}: expected {label:?} to be filtered out on the frame, got texts: {texts:?}");
|
|
|
|
|
}
|
|
|
|
|
if restores_recents {
|
|
|
|
|
let jetbrains_y = h.query_all_by_role_and_label(Role::TreeItem, "JetBrains Mono").map(|row| row.rect().min.y).next();
|
|
|
|
|
if let (Some(recent_heading), Some(all_heading)) = (h.query_by_label("Recently Used Fonts"), h.query_by_label("All Fonts")) {
|
|
|
|
|
let recent_y = recent_heading.rect().min.y;
|
|
|
|
|
let all_y = all_heading.rect().min.y;
|
|
|
|
|
assert!(
|
|
|
|
|
h.query_all_by_role_and_label(Role::TreeItem, RECENT).any(|row| {
|
|
|
|
|
let y = row.rect().min.y;
|
|
|
|
|
recent_y < y && y < all_y
|
|
|
|
|
}),
|
|
|
|
|
"keystroke {n}: expected {RECENT:?} between Recently Used Fonts and All Fonts on the clearing frame"
|
|
|
|
|
);
|
|
|
|
|
} else if let Some(jb_y) = jetbrains_y {
|
|
|
|
|
// When system fonts push `JetBrains Mono` down the catalog and `List` keeps that
|
|
|
|
|
// prior lead in view on clear, the restored recent row still sits above `All Fonts`.
|
|
|
|
|
assert!(
|
|
|
|
|
h.query_all_by_role_and_label(Role::TreeItem, RECENT).any(|row| row.rect().min.y < jb_y),
|
|
|
|
|
"keystroke {n}: expected restored recent {RECENT:?} above JetBrains Mono on the clearing frame"
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
panic!("keystroke {n}: expected Recently Used Fonts and All Fonts headings on the clearing frame");
|
|
|
|
|
}
|
|
|
|
|
let recent_y = h.get_by_label("Recently Used Fonts").rect().min.y;
|
|
|
|
|
let all_y = h.get_by_label("All Fonts").rect().min.y;
|
|
|
|
|
assert!(
|
|
|
|
|
h.query_all_by_role_and_label(Role::TreeItem, RECENT).any(|row| {
|
|
|
|
|
let y = row.rect().min.y;
|
|
|
|
|
recent_y < y && y < all_y
|
|
|
|
|
}),
|
|
|
|
|
"keystroke {n}: expected {RECENT:?} between Recently Used Fonts and All Fonts on the clearing frame"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|