mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 13:15:12 +00:00
Merge pull request #8404 from dotCooCoo/fix/font-menu-document-brush-text
Type: the font menu's Document filter counts type in scatter brushes
This commit is contained in:
@@ -518,10 +518,10 @@ impl Filters {
|
||||
|
||||
/// The families the type in `doc` is set in, lowercase and by the name the menu lists them under
|
||||
/// ([`vectorcraft_text::FontDb::canonical`]): the runs of every text object in the layers, symbols,
|
||||
/// patterns and graph designs, hidden, locked and masked ones included, with a composite font named
|
||||
/// as such. A pattern being edited is read from its editing layer only. Each run's family is looked
|
||||
/// up with its style, so a family and style split from a PostScript name (`Honoka`, `Mincho`) find
|
||||
/// the installed font of that name. Styles no type uses are left out.
|
||||
/// patterns, graph designs and stored scatter brushes, hidden, locked and masked ones included, with
|
||||
/// a composite font named as such. A pattern being edited is read from its editing layer only. Each
|
||||
/// run's family is looked up with its style, so a family and style split from a PostScript name
|
||||
/// (`Honoka`, `Mincho`) find the installed font of that name. Styles no type uses are left out.
|
||||
fn document_families(db: &vectorcraft_text::FontDb, doc: &vectorcraft_doc::Document) -> HashSet<String> {
|
||||
// Each family and style once, so a document with many runs in a few fonts looks each one up
|
||||
// once.
|
||||
@@ -549,6 +549,14 @@ fn document_families(db: &vectorcraft_text::FontDb, doc: &vectorcraft_doc::Docum
|
||||
for n in doc.layers.iter().map(|l| &**l).chain(doc.symbols.iter().map(|s| &*s.art)).chain(patterns).chain(designs) {
|
||||
vectorcraft_doc::swatches::walk_with_masks(n, &mut add);
|
||||
}
|
||||
// A scatter brush draws copies of its art's type along a stroke; art and pattern brushes drop
|
||||
// type when they bend their art. Malformed library entries are skipped.
|
||||
let brushes = doc.unknown.get(vectorcraft_brush::DOC_KEY).map(vectorcraft_brush::parse_library).unwrap_or_default();
|
||||
for b in &brushes {
|
||||
if let vectorcraft_brush::BrushKind::Scatter(s) = &b.kind {
|
||||
vectorcraft_doc::swatches::walk_with_masks(&s.art, &mut add);
|
||||
}
|
||||
}
|
||||
named.iter().flat_map(|(f, styles)| styles.iter().map(move |s| db.canonical(f, s).0.to_lowercase())).collect()
|
||||
}
|
||||
|
||||
|
||||
@@ -1221,6 +1221,58 @@ fn the_document_filter_counts_type_in_graph_designs() {
|
||||
assert_eq!(names, ["inter", "jetbrains mono"]);
|
||||
}
|
||||
|
||||
/// Type in the art of a stored scatter brush counts as the document's type, as a scatter stroke
|
||||
/// draws it, after a malformed library entry too. Type in an art or pattern brush's art does not,
|
||||
/// as those brushes leave type out when they bend their art.
|
||||
#[test]
|
||||
fn the_document_filter_counts_type_in_scatter_brushes() {
|
||||
let mut app = app_with_type(&["Inter"]);
|
||||
let mut art = |font: &str| {
|
||||
let id = app.run("text.create", serde_json::json!({"x": 20, "y": 90, "text": "Dot", "font": font})).unwrap()["id"].as_u64().unwrap();
|
||||
let node = app.session.active().unwrap().doc.node(vectorcraft_doc::NodeId(id)).cloned().expect("the new type");
|
||||
app.run("edit.undo", serde_json::json!({})).unwrap();
|
||||
node
|
||||
};
|
||||
let (scatter, bent, tiled) = (art("JetBrains Mono"), art("Source Serif 4"), art("Source Sans 3"));
|
||||
let brush = |name: &str, kind| serde_json::to_value(vectorcraft_brush::Brush { name: name.into(), kind }).unwrap();
|
||||
let library = serde_json::json!([
|
||||
{"name": "Broken", "type": "scatter", "art": 7},
|
||||
brush("Art", vectorcraft_brush::BrushKind::Art(vectorcraft_brush::ArtBrush { art: bent, ..Default::default() })),
|
||||
brush("Pattern", vectorcraft_brush::BrushKind::Pattern(vectorcraft_brush::PatternBrush { side: tiled, ..Default::default() })),
|
||||
brush("Dots", vectorcraft_brush::BrushKind::Scatter(vectorcraft_brush::Scatter { art: scatter, ..Default::default() })),
|
||||
]);
|
||||
let mut doc = (*app.session.active().unwrap().doc).clone();
|
||||
doc.unknown.insert(vectorcraft_brush::DOC_KEY.into(), library);
|
||||
let db = vectorcraft_text::FontDb::global();
|
||||
let mut names: Vec<_> = super::document_families(db, &doc).into_iter().collect();
|
||||
names.sort();
|
||||
assert_eq!(names, ["inter", "jetbrains mono"]);
|
||||
}
|
||||
|
||||
/// A scatter brush made of type keeps its family in the Document filter after the type is deleted;
|
||||
/// deleting the brush takes the family out, and undoing the deletion brings it back.
|
||||
#[test]
|
||||
fn the_document_filter_follows_a_scatter_brushs_edits_and_undo() {
|
||||
let mut app = app_with_type(&["Inter"]);
|
||||
let id = app.run("text.create", serde_json::json!({"x": 20, "y": 90, "text": "Dot", "font": "JetBrains Mono"})).unwrap()["id"].clone();
|
||||
let name = app.run("brush.new", serde_json::json!({"type": "scatter", "name": "Type Dots"})).unwrap()["name"].clone();
|
||||
app.run("edit.clear", serde_json::json!({"ids": [id]})).unwrap();
|
||||
let db = vectorcraft_text::FontDb::global();
|
||||
// One menu state throughout, so each edit has to get past the families it keeps.
|
||||
let mut st = super::MenuState { document_only: true, ..Default::default() };
|
||||
let mut families = |app: &crate::VectorcraftApp| {
|
||||
let used = super::used_families(db, &mut st, super::MenuLook::of(app)).expect("a document is open");
|
||||
let mut names: Vec<_> = used.iter().cloned().collect();
|
||||
names.sort();
|
||||
names
|
||||
};
|
||||
assert_eq!(families(&app), ["inter", "jetbrains mono"], "the brush's type");
|
||||
app.run("brush.delete", serde_json::json!({"name": name})).unwrap();
|
||||
assert_eq!(families(&app), ["inter"], "the brush deleted");
|
||||
app.run("edit.undo", serde_json::json!({})).unwrap();
|
||||
assert_eq!(families(&app), ["inter", "jetbrains mono"], "the deletion undone");
|
||||
}
|
||||
|
||||
/// A run whose family and style were split from a PostScript name (as an importer without the font
|
||||
/// splits one) counts under the family of the installed font of that name, found with its style.
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user