Merge main into fix/restore-document-font-hinting

This commit is contained in:
dotCooCoo committed 2026-12-05 14:11:57 -08:00
commit 1088f0894a
9 files changed
+120 -40

No files matched your search

+9 -7
View File
@@ -44,17 +44,19 @@ jobs:
# The workspace crates also build without line tables. A panic still names its file and line.
dev-debug: "0"
# The `build (<os>)` job builds the tests once and writes one nextest archive per shard with
# that shard's test binaries (`cargo xtask ci archive`), then runs the doctests. Five test
# legs download their own archive and run it without building: shards 1 and 2 each run half
# of vectorcraft-ui-egui's tests, and shards 3 to 5 the tests of their own crates
# (xtask/src/shards.rs). The `lint (<os>)` leg runs the other `cargo xtask ci` steps beside
# them, with a dependency cache of its own. `gate (<os>)` passes when the build and every
# test leg that ran passed; `lint (<os>)` is a check of its own.
# that shard's test binaries (`cargo xtask ci archive`), then runs the doctests and the tests
# built without the bundled fonts (`cargo xtask ci after-archive`), whose second build of the
# workspace crates the build job's cache entry keeps. Five test legs download their own archive and
# run it without building: shards 1 and 2 each run half of vectorcraft-ui-egui's tests, and
# shards 3 to 5 the tests of their own crates (xtask/src/shards.rs). The `lint (<os>)` leg
# runs the other `cargo xtask ci` steps beside them, with a dependency cache of its own.
# `gate (<os>)` passes when the build and every test leg that ran passed; `lint (<os>)` is a
# check of its own.
test-shards: 5
shard-command: cargo xtask ci shard
archive-command: cargo xtask ci archive
shard-archives: true
after-archive-command: cargo xtask ci doctests
after-archive-command: cargo xtask ci after-archive
lint-command: cargo xtask ci checks
# A pull request runs only the test shards whose crates its changes reach: the crates that
# own a changed file or declare a read of it (`[package.metadata.craft] reads`), and every
+3 -2
View File
@@ -21,9 +21,10 @@ use objc2_core_text::CTFontManagerCopyAvailableFontURLs;
/// The most fonts read from the list (a system has a few thousand faces).
const MAX_FONTS: usize = 1 << 16;
/// Have the font scans read the font files CoreText lists.
/// Have the font scans read the font files CoreText lists, in place of asking the font service for
/// CoreText's fonts a second time.
pub fn install() {
vectorcraft_text::set_platform_font_files(font_files);
vectorcraft_text::set_platform_font_files_complete(font_files);
}
/// The files of the fonts available to the app as CoreText lists them now (fonts registered since
+3 -2
View File
@@ -40,9 +40,10 @@ const MAX_FACE_FILES: u32 = 8;
/// The longest file path taken, in UTF-16 units (Windows' own limit).
const MAX_PATH: u32 = 32_767;
/// Have the font scans read the font files DirectWrite and GDI list.
/// Have the font scans read the font files DirectWrite and GDI list, in place of asking the font
/// service for DirectWrite's collection a second time.
pub fn install() {
vectorcraft_text::set_platform_font_files(font_files);
vectorcraft_text::set_platform_font_files_complete(font_files);
}
/// The local files of the fonts in DirectWrite's system font collection as it is now (fonts
+4 -4
View File
@@ -46,12 +46,12 @@ use cache::GlyphCache;
use cache::{CanonicalNames, GlyphColours, GlyphImages};
pub use composite::{CompositeCoverage, LentCompositeFonts};
use craft::font_catalog::Catalog;
#[cfg(test)]
pub(crate) use dirs::sfnt_of;
pub use dirs::{
PlatformFontFiles, app_font_dir, set_app_font_dir, set_platform_font_files, set_user_font_dirs, set_user_font_dirs_confined, system_font_dirs,
user_font_dirs,
PlatformFontFiles, app_font_dir, set_app_font_dir, set_platform_font_files, set_platform_font_files_complete, set_user_font_dirs,
set_user_font_dirs_confined, system_font_dirs, user_font_dirs,
};
#[cfg(test)]
pub(crate) use dirs::{sfnt_of, uses_font_service};
use face::Instances;
pub(crate) use face::PathAlignHeights;
pub use face::{FALLBACK_FAMILY, FontFace, IcfMargins, OutlineFormat};
+29 -3
View File
@@ -47,6 +47,22 @@ pub fn set_platform_font_files(list: PlatformFontFiles) {
let _ = list;
}
/// [`set_platform_font_files`] for a lister that lists every font the platform's font service
/// lists. [`FontDb::global`]'s scan then reads the lister's files and does not also ask the font
/// service, which opens every installed face a second time. Only the first lister set counts.
pub fn set_platform_font_files_complete(list: PlatformFontFiles) {
#[cfg(not(target_arch = "wasm32"))]
if PLATFORM_FONT_FILES.set(list).is_ok() {
LISTER_IS_COMPLETE.store(true, std::sync::atomic::Ordering::Relaxed);
}
#[cfg(target_arch = "wasm32")]
let _ = list;
}
/// Whether the lister was set with [`set_platform_font_files_complete`].
#[cfg(not(target_arch = "wasm32"))]
static LISTER_IS_COMPLETE: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
/// The most files [`platform_font_files`] takes from the lister.
#[cfg(not(target_arch = "wasm32"))]
const MAX_PLATFORM_FILES: usize = 1 << 16;
@@ -64,10 +80,20 @@ fn platform_font_files() -> Vec<PathBuf> {
Vec::new()
}
/// The catalog of [`FontDb::global`]: the platform's font folders and font service, the font
/// store, VectorCraft's own folders ([`app_dirs`]) and the files [`set_platform_font_files`] lists.
/// Whether [`system_catalog`] asks the platform's font service: not when the lister was set with
/// [`set_platform_font_files_complete`].
pub(crate) fn uses_font_service() -> bool {
#[cfg(not(target_arch = "wasm32"))]
return !LISTER_IS_COMPLETE.load(std::sync::atomic::Ordering::Relaxed);
#[cfg(target_arch = "wasm32")]
true
}
/// The catalog of [`FontDb::global`]: the platform's font folders, the platform's font service
/// ([`uses_font_service`]), the font store, VectorCraft's own folders ([`app_dirs`]) and the files
/// [`set_platform_font_files`] lists.
pub(super) fn system_catalog() -> Catalog {
let catalog = Catalog::new(FontEnv::from_process()).with_lister(Arc::new(platform_font_files));
let catalog = Catalog::new(FontEnv::from_process()).with_font_service(uses_font_service()).with_lister(Arc::new(platform_font_files));
catalog.set_app_dirs(app_dirs());
catalog
}
+2 -2
View File
@@ -49,8 +49,8 @@ pub use fontdb::{
CompositeCoverage, FALLBACK_FAMILY, FontClass, FontDb, FontFace, FontLikeness, FontMatch, FontTraits, GENERIC_FAMILIES, GlyphAlternate,
GlyphCategory, GlyphCategoryKind, GlyphOrigin, IcfMargins, InstalledFace, JoiningPosition, LentCompositeFonts, MAX_FILE_FACES, OutlineFormat,
PlatformFontFiles, RECENTLY_ADDED_WITHIN, RecentlyAdded, StylisticSet, Substitution, SubstitutionKind, UnloadedFile, WantedFont, WantedFonts,
app_font_dir, is_font_file, is_generic_family, is_suitcase, set_app_font_dir, set_platform_font_files, set_user_font_dirs,
set_user_font_dirs_confined, style_weight, system_font_dirs, user_font_dirs,
app_font_dir, is_font_file, is_generic_family, is_suitcase, set_app_font_dir, set_platform_font_files, set_platform_font_files_complete,
set_user_font_dirs, set_user_font_dirs_confined, style_weight, system_font_dirs, user_font_dirs,
};
pub use hyphen::{hyphenation_exceptions, set_hyphenation_exceptions};
pub use layout::{envelope_ink, layout_inputs, register_envelope_ink};
+3 -1
View File
@@ -760,7 +760,9 @@ fn fonts_the_platform_lists_outside_the_font_folders_are_cataloged() {
use std::sync::Mutex;
static FILES: Mutex<Vec<String>> = Mutex::new(Vec::new());
let list = |files: Vec<String>| *FILES.lock().unwrap_or_else(|e| e.into_inner()) = files;
set_platform_font_files(|| FILES.lock().unwrap_or_else(|e| e.into_inner()).clone());
assert!(crate::fontdb::uses_font_service(), "without a complete lister the scan asks the font service");
set_platform_font_files_complete(|| FILES.lock().unwrap_or_else(|e| e.into_inner()).clone());
assert!(!crate::fontdb::uses_font_service(), "with a complete lister the scan does not also ask the font service");
let file = service_font();
std::fs::create_dir_all(file.parent().unwrap()).unwrap();
let _ = std::fs::remove_file(&file);
+4 -2
View File
@@ -227,8 +227,10 @@ context. It replaces the context's font definitions, so an embedder's own faces
- `cargo test -p vectorcraft-text --no-default-features --test without_bundled_fonts` checks the
configuration without them, and `cargo test -p vectorcraft-ui-egui --no-default-features --test
install_fonts` that the fonts `embed::install` sets up bind the proportional, monospace and
semibold families, so an effect dialog draws; the same step lints `vectorcraft-ui-egui` without
its default features.
semibold families, so an effect dialog draws. `cargo xtask ci` runs these two tests in its
`no-bundled-fonts-tests` step, and its `no-bundled-fonts` step also lints `vectorcraft-ui-egui`
without its default features. In CI the gate's `build` job runs the tests (`cargo xtask ci
after-archive`) and the `lint` leg runs the rest (`cargo xtask ci checks`).
### Arabic fonts and the web build
+63 -17
View File
@@ -49,7 +49,7 @@ commands:
layers enforce the crate dependency layering (plan/architecture.md §3)
wasm cargo check --target wasm32-unknown-unknown for the wasm-safe crates, the web app and its plug-in worker
test the workspace tests (cargo nextest when installed, else cargo test), then the doctests
ci fmt --check, clippy -D warnings, test, doctests, no-bundled-fonts, pdf-deps, assets, brands, grant-sites, cursors (warnings only), test-lint, ui-commands --check, layers, wasm (stops at first failure)
ci fmt --check, clippy -D warnings, test, doctests, no-bundled-fonts, no-bundled-fonts-tests, pdf-deps, assets, brands, grant-sites, cursors (warnings only), test-lint, ui-commands --check, layers, wasm (stops at first failure)
ci shard shard $GATE_SHARD of $GATE_SHARDS of ci's tests (xtask/src/shards.rs): from the
nextest archive in $NEXTEST_ARCHIVE_FILE when set, otherwise it builds them and
also runs the doctests of its crates
@@ -57,7 +57,11 @@ commands:
$NEXTEST_ARCHIVE_DIR/<k>/$NEXTEST_ARCHIVE_NAME for k from 1 to $GATE_SHARDS; with
CRAFT_CACHE_UNITS set, appends Cargo's JSON messages for the build to that file
ci doctests the doctests of each shard's crates, one cargo command per shard
ci checks the ci steps other than the tests, the doctests and the i18n report
ci after-archive
ci doctests, then the tests built without the bundled fonts
(no-bundled-fonts-tests), for the gate's build job
ci checks the ci steps other than the tests, the doctests, the i18n report and
no-bundled-fonts-tests
shards list the crates each shard tests; fails when a member is in no shard or in two,
or builds with other features in its shard than in the whole workspace
corpus [--download | --affinity | --scripts]
@@ -100,6 +104,7 @@ fn main() -> ExitCode {
Some("ci") if rest.first() == Some(&"shard") => cmd_ci_shard(),
Some("ci") if rest.first() == Some(&"archive") => cmd_ci_archive(),
Some("ci") if rest.first() == Some(&"doctests") => cmd_ci_doctests(),
Some("ci") if rest.first() == Some(&"after-archive") => cmd_ci_after_archive(),
Some("ci") if rest.first() == Some(&"checks") => cmd_ci_checks(),
Some("ci") => cmd_ci(),
Some("shards") => shards::run().map(drop),
@@ -541,8 +546,8 @@ fn test_build(r: &shards::Run, units: bool) -> (Command, String) {
}
/// `cargo xtask ci doctests`: the doctests of each shard's crates, one cargo command per shard
/// with the crates `ci shard` runs them for, after `ci archive` (the shared gate's
/// `after-archive-command`). Every command runs before the first error is returned.
/// with the crates `ci shard` runs them for, after `ci archive`. Every command runs before the
/// first error is returned.
fn cmd_ci_doctests() -> Result<(), String> {
let mut result = Ok(());
for s in shards::assigned()?.iter().filter(|s| s.part.is_none_or(|p| p.is_first())) {
@@ -551,10 +556,32 @@ fn cmd_ci_doctests() -> Result<(), String> {
result
}
/// `cargo xtask ci checks`: every `ci` step other than [`TEST_STEPS`], for the shared gate's
/// `lint` leg.
/// The `ci` steps that `ci after-archive` runs in the gate's `build` job, whose cache entry keeps
/// the workspace crates they build without the bundled fonts; `ci checks` leaves them out.
const BUILD_JOB_STEPS: [&str; 1] = ["no-bundled-fonts-tests"];
/// `cargo xtask ci after-archive`: the shared gate's `after-archive-command`. It runs `ci
/// doctests`, then the [`BUILD_JOB_STEPS`].
fn cmd_ci_after_archive() -> Result<(), String> {
run_steps(&after_archive_steps())
}
/// The steps of [`cmd_ci_after_archive`].
fn after_archive_steps() -> Vec<Step> {
let mut steps: Vec<Step> = vec![("doctests", Box::new(cmd_ci_doctests))];
steps.extend(ci_steps().into_iter().filter(|(name, _)| BUILD_JOB_STEPS.contains(name)));
steps
}
/// `cargo xtask ci checks`: every `ci` step other than [`TEST_STEPS`] and [`BUILD_JOB_STEPS`], for
/// the shared gate's `lint` leg.
fn cmd_ci_checks() -> Result<(), String> {
run_steps(&ci_steps().into_iter().filter(|(name, _)| !TEST_STEPS.contains(name)).collect::<Vec<_>>())
run_steps(&checks_steps())
}
/// The steps of [`cmd_ci_checks`].
fn checks_steps() -> Vec<Step> {
ci_steps().into_iter().filter(|(name, _)| !TEST_STEPS.contains(name) && !BUILD_JOB_STEPS.contains(name)).collect()
}
/// Runs `steps` in turn, stopping at the first that fails; the summary names the steps that passed
@@ -604,21 +631,28 @@ fn ci_steps() -> Vec<Step> {
(
"no-bundled-fonts",
Box::new(|| {
// vectorcraft-text as embedders that bring their own fonts build it.
let mut c = cargo();
c.args(["test", "-p", "vectorcraft-text", "--no-default-features", "--test", "without_bundled_fonts"]);
run(c, "cargo test -p vectorcraft-text --no-default-features --test without_bundled_fonts")?;
// The egui panels and the MCP server as such an embedder builds them: nothing turns
// the fonts back on.
// The egui panels and the MCP server as an embedder that brings its own fonts
// builds them: nothing turns the fonts back on.
libraries_without_bundled_fonts()?;
// The panels without their interface faces lint clean and still bind every family
// they draw in.
// The panels without their interface faces lint clean.
let mut c = cargo();
c.args(["clippy", "-p", "vectorcraft-ui-egui", "--no-default-features", "--all-targets", "--", "-D", "warnings"]);
run(c, "cargo clippy -p vectorcraft-ui-egui --no-default-features --all-targets -- -D warnings")?;
run(c, "cargo clippy -p vectorcraft-ui-egui --no-default-features --all-targets -- -D warnings")
}),
),
(
"no-bundled-fonts-tests",
Box::new(|| {
// vectorcraft-text as such an embedder builds it, and the panels without their
// interface faces still bind every family they draw in. In a leg that saves the
// cache the builds record their units (xtask/src/cache_units.rs), so the entry
// keeps the workspace crates built without the fonts.
let mut c = cargo();
c.args(["test", "-p", "vectorcraft-text", "--no-default-features", "--test", "without_bundled_fonts"]);
cache_units::run(c, "cargo test -p vectorcraft-text --no-default-features --test without_bundled_fonts")?;
let mut c = cargo();
c.args(["test", "-p", "vectorcraft-ui-egui", "--no-default-features", "--test", "install_fonts"]);
run(c, "cargo test -p vectorcraft-ui-egui --no-default-features --test install_fonts")
cache_units::run(c, "cargo test -p vectorcraft-ui-egui --no-default-features --test install_fonts")
}),
),
("pdf-deps", Box::new(|| pdf_deps::run(&root()))),
@@ -758,4 +792,16 @@ mod tests {
assert_eq!(archived.len(), shards::GROUPS.len());
assert!(archived.iter().zip(&real).all(|(r, s)| s.runs == [(*r).clone()]));
}
#[test]
fn the_build_job_runs_the_tests_without_bundled_fonts_and_the_lint_leg_the_rest() {
let names = |steps: Vec<Step>| steps.into_iter().map(|(name, _)| name).collect::<Vec<_>>();
assert_eq!(names(after_archive_steps()), ["doctests", "no-bundled-fonts-tests"]);
let checks = names(checks_steps());
assert!(checks.contains(&"no-bundled-fonts"), "{checks:?}");
assert!(!checks.contains(&"no-bundled-fonts-tests"), "{checks:?}");
let workflow = include_str!("../../.github/workflows/ci.yml");
assert!(workflow.contains("after-archive-command: cargo xtask ci after-archive\n"), "ci.yml's after-archive-command");
assert!(workflow.contains("lint-command: cargo xtask ci checks\n"), "ci.yml's lint-command");
}
}