Files
craft-libs/vendor/linesweeper/tests/fonts.rs
dotCooCoo f14cc7f21e linesweeper: keep a copy of the crates.io 0.5.0 package in vendor/
Add the linesweeper 0.5.0 package to vendor/ with no file changed, so
that a fix to it can reach the Craft apps through this repository
without waiting for a linesweeper release. The GitHub repository its
manifest names is archived, and its README says development moved off
GitHub.

Leave out the test font (fonts live in craft-fonts), the logo artwork,
the snapshot images and the package's repository tooling. SOURCE.json
lists each with its hash.

Add a workspace exclude, a [patch.crates-io] entry, SOURCE.json with
the archive hash and per-file hashes, NOTICE and ATTRIBUTION.md rows,
and the package's tests in the backend test script. craft-prepress's
flatten feature now builds against the copy, so Cargo.lock drops the
package's registry source and checksum.
2026-11-06 19:05:18 -08:00

57 lines
1.7 KiB
Rust

use std::path::PathBuf;
use kurbo::BezPath;
use libtest_mimic::{Arguments, Failed, Trial};
use linesweeper::topology::Topology;
use linesweeper_util::outline_to_bezpath;
use skrifa::{FontRef, MetadataProvider};
fn main() {
let args = Arguments::from_args();
let tests = glyph_tests();
libtest_mimic::run(&args, tests).exit();
}
fn glyph_tests() -> Vec<Trial> {
let ws = std::env::var("CARGO_MANIFEST_DIR").unwrap();
let paths = glob::glob(&format!("{ws}/tests/fonts/**/*.ttf")).unwrap();
paths
.into_iter()
.flat_map(|p| {
let p = p.unwrap();
let name = p.strip_prefix(&ws).unwrap().display().to_string();
font_glyph_tests(name, p)
})
.collect()
}
fn font_glyph_tests(name: String, path: PathBuf) -> Vec<Trial> {
let data = std::fs::read(&path).unwrap();
let font_ref = FontRef::new(&data).unwrap();
let names = font_ref.glyph_names();
font_ref
.outline_glyphs()
.iter()
.zip(font_ref.outline_glyphs().iter().skip(1))
.map(|((id1, outline1), (_id2, outline2))| {
let glyph_name = names.get(id1).unwrap();
let path1 = outline_to_bezpath(outline1);
let path2 = outline_to_bezpath(outline2);
Trial::test(format!("{name}-{glyph_name}"), || {
test_outline(path1, path2)
})
})
.collect()
}
fn test_outline(path1: BezPath, path2: BezPath) -> Result<(), Failed> {
if path1.is_empty() || path2.is_empty() {
return Ok(());
}
let top = Topology::from_paths_binary(&path1, &path2, 1e-3).unwrap();
let _out_paths = top.compute_positions();
Ok(())
}