Font picker: give the Arabic sample story Noto Sans Arabic from the craft fonts set

The story's catalog had no face that maps Arabic, so no row showed the
Arabic sample. craft-font-manager's build script embeds Noto Sans Arabic
with fonts-build's Embed when the suite feature is on and CRAFT_FONTS_DIR
names a craft-fonts checkout; without it the table is empty and the story
shows the other families only.
This commit is contained in:
aiongg
2026-11-22 15:41:05 +00:00
parent 315a223e69
commit 5c14a9d042
4 changed files with 46 additions and 14 deletions
Generated
+1
View File
@@ -2711,6 +2711,7 @@ dependencies = [
"craft-font-catalog",
"craft-font-manager",
"craft-font-store",
"craft-fonts-build",
"craft-host",
"craft-i18n",
"craft-theme",
+4
View File
@@ -46,6 +46,10 @@ log = { version = "0.4", optional = true }
# Variation axes and named instances of a face (`axes`), on every feature set.
skrifa = { version = "0.44", default-features = false, features = ["std"] }
[build-dependencies]
# The Arabic sample story's face, from the craft fonts set when `CRAFT_FONTS_DIR` names one.
craft-fonts-build = { workspace = true }
[dev-dependencies]
craft-font-manager = { path = ".", features = ["suite"] }
+10
View File
@@ -0,0 +1,10 @@
fn main() {
println!("cargo::rerun-if-changed=build.rs");
// The Arabic sample story's face from the craft fonts set: only for the stories, and never required, so an app
// build with `CRAFT_FONTS_REQUIRED=1` doesn't fail over it.
let stories = std::env::var_os("CARGO_FEATURE_SUITE").is_some();
let written = craft_fonts_build::Embed::documents(&["Noto Sans Arabic"]).filter(move |_| stories).required(false).write("story_fonts.rs");
if let Err(e) = written {
println!("cargo::error={e}");
}
}
+31 -14
View File
@@ -1,10 +1,13 @@
//! Stories of `FontPicker`: the closed field, the list open with recents and a typed query, and the list open with
//! the class column and a filter on. They draw from the two faces egui ships in an in-memory catalog.
//! the class column and a filter on. They draw from the two faces egui ships in an in-memory catalog, with Inter where a
//! story needs a family of two styles and Noto Sans Arabic, from the craft fonts set when the build has
//! `CRAFT_FONTS_DIR`, for the Arabic sample.
use std::sync::{Arc, OnceLock};
use craft_behavior::Mixed;
use craft_ui::contract::{Bind, Show as _, Validity};
use craft_ui::fonts::EmbeddedFace;
use craft_ui::runtime::env::{Label, Message};
use craft_ui::testing::focus::AccessActionKind;
use craft_ui::testing::{Drive, Fixture, StoryData, StoryOutput, story};
@@ -35,19 +38,32 @@ fn demo(family: &str, settings: FontPickerSettings, filters: FontFilters) -> Dem
Demo { family: family.to_owned(), settings, filters }
}
/// The story catalog with Inter Regular and SemiBold, a family of two styles.
/// The craft fonts set's Noto Sans Arabic; empty when the build has no `CRAFT_FONTS_DIR`.
static STORY_FONTS: &[EmbeddedFace] = include!(concat!(env!("OUT_DIR"), "/story_fonts.rs"));
/// A new story catalog with Inter Regular and SemiBold, a family of two styles, and the faces `more`.
fn with_inter(more: &[&'static [u8]]) -> Arc<Catalog> {
let catalog = story_catalog();
let inter = [
include_bytes!("../../../ui-contract/fonts/inter/Inter-Regular.ttf").as_slice(),
include_bytes!("../../../ui-contract/fonts/inter/Inter-SemiBold.ttf").as_slice(),
];
for bytes in inter.iter().chain(more) {
let _ = catalog.add_bytes(bytes.to_vec(), Source::Bundled, &Limits::default());
}
catalog
}
/// The story catalog with Inter Regular and SemiBold.
fn styled_catalog() -> Arc<Catalog> {
static CATALOG: OnceLock<Arc<Catalog>> = OnceLock::new();
Arc::clone(CATALOG.get_or_init(|| {
let catalog = story_catalog();
for bytes in [
include_bytes!("../../../ui-contract/fonts/inter/Inter-Regular.ttf").as_slice(),
include_bytes!("../../../ui-contract/fonts/inter/Inter-SemiBold.ttf").as_slice(),
] {
let _ = catalog.add_bytes(bytes.to_vec(), Source::Bundled, &Limits::default());
}
catalog
}))
Arc::clone(CATALOG.get_or_init(|| with_inter(&[])))
}
/// The styled catalog with Noto Sans Arabic, which draws both samples, when the build has the craft fonts set.
fn arabic_catalog() -> Arc<Catalog> {
static CATALOG: OnceLock<Arc<Catalog>> = OnceLock::new();
Arc::clone(CATALOG.get_or_init(|| with_inter(&STORY_FONTS.iter().map(|face| face.bytes).collect::<Vec<_>>())))
}
/// What a story adds to the picker besides its state.
@@ -166,11 +182,12 @@ fn font_picker_banner_text(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
show_with(ui, data, demo("Ubuntu", FontPickerSettings::default(), FontFilters::default()), &catalog(), &extras)
}
/// Large samples: a face with Arabic letters gets the second sample after the Latin one.
/// Large samples: a face with Arabic letters (Noto Sans Arabic, when the build has the craft fonts set) gets the second
/// sample after the Latin one.
#[story(FontPicker<'static>, covers = [Open], drive = Drive::Custom(open_list))]
fn font_picker_arabic_sample(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let settings = FontPickerSettings { preview: crate::picker::FontPreviewSize::Large, ..FontPickerSettings::default() };
show_with(ui, data, demo("Inter", settings, FontFilters::default()), &styled_catalog(), &Extras::default())
show_with(ui, data, demo("Inter", settings, FontFilters::default()), &arabic_catalog(), &Extras::default())
}
/// Settings whose recents are the families `recent`.