Merge main into fix/dynamic-text-leading-line-gap

This commit is contained in:
dotCooCoo
2026-11-26 06:37:11 -08:00
3 changed files with 132 additions and 4 deletions
+123 -3
View File
@@ -197,6 +197,8 @@ enum Change {
Position(usize),
/// A checkbox row turned on or off.
Toggle(Flag, bool),
/// A row menu's Reset OpenType Features: the panel menu's default.
Reset,
}
impl Change {
@@ -205,6 +207,7 @@ impl Change {
Change::Figure(i) => set_figure(f, i),
Change::Position(i) => set_position(f, i),
Change::Toggle(flag, on) => flag.put(f, on),
Change::Reset => *f = OtFeatures::default(),
}
}
}
@@ -286,11 +289,18 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
}
Divider::horizontal().show(ui);
// A row whose characters differ shows a dash, and a click turns the feature on for all of them.
// A secondary click keeps the text selection and opens that row's menu.
for (label, flag) in rows() {
let out = Checkbox::new(Bind::given(mixed(shown_flag(app, flag)))).label(label).show(ui);
let shown = shown_flag(app, flag);
let out = Checkbox::new(Bind::given(mixed(shown))).label(label).show(ui);
if let Some(on) = out.events.committed() {
change = Some(Change::Toggle(flag, *on));
}
// The row menu's choice is applied with the rest at the end of the pass, so the rows drawn
// after it still read the state the pass started with.
if let Some(c) = Menu::context(label, &out.response).show(ui, |ui, _| feature_row_menu(app, ui, flag, shown)).inner.flatten() {
change = Some(c);
}
}
let sets = set_entries(app, &st);
let opener = Button::new(tl!("Stylistic Sets")).enabled(!sets.is_empty()).show(ui);
@@ -304,11 +314,30 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
if tracking_drops_ligatures(app) {
Text::new(tl!("Ligatures are off while the text is tracked.")).shade(Shade::Muted).show(ui);
}
if let Some(c) = change {
edit(app, c);
match change {
// Reset writes the default as the whole feature list, as the panel menu's entry does.
Some(Change::Reset) => set(app, OtFeatures::default()),
Some(c) => edit(app, c),
None => {}
}
}
/// The menu a secondary click on one feature row opens. Turn Off when the row is on
/// (`shown` is `Some(true)`); Turn On when it is off or mixed, through the same toggle a click
/// uses, so a mixed row turns the feature on for every character the panel acts on. Reset
/// OpenType Features applies the panel menu's default and is enabled on the same condition.
fn feature_row_menu(app: &VectorcraftApp, ui: &mut Ui, flag: Flag, shown: Option<bool>) -> Option<Change> {
let on = shown == Some(true);
let mut chosen = None;
if MenuItem::new(if on { tl!("Turn Off") } else { tl!("Turn On") }).show(ui).ran {
chosen = Some(Change::Toggle(flag, !on));
}
if MenuItem::new(tl!("Reset OpenType Features")).enabled(text_style(app).is_some()).show(ui).ran {
chosen = Some(Change::Reset);
}
chosen
}
/// Whether tracking turns off the standard ligatures of any character the panel acts on: one with
/// Standard Ligatures on, tracked past [`vectorcraft_text::ligatures_suppressed_by`]'s limit and
/// without an explicit `liga` or `clig` tag ([`vectorcraft_text::explicit_ligatures`]).
@@ -485,6 +514,7 @@ mod tests {
use vectorcraft_doc::NodeId;
use super::*;
use crate::tests::panel_harness::Panel;
fn selected_text() -> VectorcraftApp {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
@@ -1146,4 +1176,94 @@ mod tests {
}
}
}
fn row_flag(label: &str) -> Flag {
rows().into_iter().find(|(l, _)| *l == label).unwrap().1
}
#[test]
fn right_clicking_an_opentype_row_offers_turn_on_or_turn_off() {
let mut panel = Panel::new(selected_text(), show);
let ids = panel.app().session.active().unwrap().selection.objects.clone();
let before = features(&panel.app()).to_tags();
let undo = undo_steps(&panel.app());
panel.secondary_click("Standard Ligatures");
assert!(panel.menu_item_enabled("Turn Off"));
assert!(!panel.shows("Turn On"));
assert!(panel.menu_item_enabled("Reset OpenType Features"));
assert_eq!(panel.app().session.active().unwrap().selection.objects, ids);
assert_eq!(features(&panel.app()).to_tags(), before);
assert_eq!(undo_steps(&panel.app()), undo);
panel.click_menu_item("Turn Off");
panel.secondary_click("Standard Ligatures");
assert!(panel.menu_item_enabled("Turn On"));
assert!(!panel.shows("Turn Off"));
assert_eq!(panel.app().session.active().unwrap().selection.objects, ids);
}
#[test]
fn clicking_turn_on_sets_that_feature_in_one_undo_step() {
let off = OtFeatures { ligatures: false, swash: true, ..OtFeatures::default() };
let mut app = selected_text();
set(&mut app, off);
let mut by_check = Panel::new(app, show);
by_check.click("Standard Ligatures");
let mut app = selected_text();
set(&mut app, off);
let before = features(&app).to_tags();
let undo = undo_steps(&app);
let mut panel = Panel::new(app, show);
panel.secondary_click("Standard Ligatures");
panel.click_menu_item("Turn On");
assert_eq!(undo_steps(&panel.app()), undo + 1);
assert_eq!(features(&panel.app()).to_tags(), features(&by_check.app()).to_tags());
panel.app().run("edit.undo", json!({})).unwrap();
assert_eq!(features(&panel.app()).to_tags(), before);
}
#[test]
fn turn_on_preserves_the_mixed_character_range_and_undo_restores_its_runs() {
let mut app = selected_text();
app.session.select_tool("type", Default::default()).unwrap();
let id = app.run("text.create", json!({"x": 0, "y": 20, "text": "abcd"})).unwrap()["id"].clone();
app.run("text.setRangeStyle", json!({"id": id, "start": 1, "end": 2, "features": ["frac"]})).unwrap();
app.session.apply_actions(vec![vectorcraft_tools::Action::Notify("text.editNew".into())]).unwrap();
app.session.set_tool_option("select", &json!({"start": 1, "end": 3}));
let range = Some((NodeId(id.as_u64().unwrap()), 1, 3));
assert_eq!(text_editing(&app), range);
assert_eq!(shown_flag(&app, row_flag("Fractions")), None);
let before = run_features(&mut app, &id, 4);
let undo = undo_steps(&app);
let mut panel = Panel::new(app, show);
panel.secondary_click("Fractions");
assert_eq!(text_editing(&panel.app()), range);
assert_eq!(run_features(&mut panel.app(), &id, 4), before);
panel.click_menu_item("Turn On");
assert_eq!(run_features(&mut panel.app(), &id, 4), [("a".into(), Value::Null), ("bc".into(), json!(["frac"])), ("d".into(), Value::Null)]);
assert_eq!(undo_steps(&panel.app()), undo + 1);
panel.app().run("edit.undo", json!({})).unwrap();
assert_eq!(run_features(&mut panel.app(), &id, 4), before);
}
#[test]
fn clicking_reset_opentype_features_clears_the_rows() {
let custom = OtFeatures { ligatures: false, fractions: true, swash: true, ..OtFeatures::default() };
let mut by_flyout = selected_text();
set(&mut by_flyout, custom);
run(&mut by_flyout, RESET, &json!({})).unwrap().unwrap();
let mut app = selected_text();
set(&mut app, custom);
let before = features(&app).to_tags();
let undo = undo_steps(&app);
let mut panel = Panel::new(app, show);
panel.secondary_click("Fractions");
panel.click_menu_item("Reset OpenType Features");
assert_eq!(undo_steps(&panel.app()), undo + 1);
assert_eq!(features(&panel.app()).to_tags(), features(&by_flyout).to_tags());
assert_eq!(shown_flag(&panel.app(), row_flag("Standard Ligatures")), Some(true));
assert_eq!(shown_flag(&panel.app(), row_flag("Fractions")), Some(false));
assert_eq!(shown_flag(&panel.app(), row_flag("Swash")), Some(false));
panel.app().run("edit.undo", json!({})).unwrap();
assert_eq!(features(&panel.app()).to_tags(), before);
}
}
+8 -1
View File
File diff suppressed because one or more lines are too long
+1
View File
@@ -1820,6 +1820,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
With a Type tool and exactly one character selected, the canvas shows that character's alternate glyphs in a row beside it, and a click on one replaces the character's glyph, as [Replace characters with alternate glyphs](https://helpx.adobe.com/illustrator/desktop/design-with-text/special-characters-glyphs/replace-characters-with-alternate-glyphs.html) describes ("Replace a character with on-canvas alternate glyphs"). The row shows at most five alternates, and an arrow at its end opens the Glyphs panel on Alternates for Current Selection when the character has more, as the [reference manual](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=479) describes. A click runs the command the panel's double-click runs, as one undo step, so a letter of an Arabic word keeps the word joined. These rules are VectorCraft's own: the row leaves out the glyph the character is drawn with and puts the default glyph first for a character drawn with an alternate; it stands under a character of horizontal type and on the right of a character of vertical type, or on the other side when the canvas ends there or the Contextual Task Bar is there; Preferences › Type › Show Character Alternates (`showCharacterAlternates`, on by default) turns it off. Tests: `canvas::alternates_bar::tests`, `tests::prefs::show_character_alternates_preference_is_on_by_default_and_saved`.
With an OpenType font in the Glyphs panel, the Show menu and the panel menu list the font's glyph categories after Alternates for Current Selection, and choosing one restricts the grid to the glyphs of that kind, as the [Glyphs panel overview](https://helpx.adobe.com/illustrator/desktop/design-with-text/special-characters-glyphs/glyphs-panel-overview.html) describes. The categories are Ligatures, Swash, Stylistic Alternates, each stylistic set by the font's name for it (else Set N), Small Caps, Ornaments, Fractions and Figures, each listed only when the font's `GSUB` features give it glyphs; which features make up each category and their order are VectorCraft's own. A font without the chosen category shows Entire Font. `text.glyphCategories` lists them for agents. Tests: `fontdb::gsub::tests` in the text crate, `panels::glyphs::tests::the_show_menu_lists_the_fonts_opentype_categories`, `tests::fontlist::glyph_categories_list_the_glyphs_of_each_kind_of_feature`.
The OpenType panel's Stylistic Sets menu offers `ss01`–`ss20` sets present in the selected text's font, using the font's custom labels when available and numbered labels otherwise. Sets can be combined and deselected individually. With mixed fonts, the menu shows the first selected character's font's sets and applies the feature tag to all selected text; a font without that set draws unchanged. The mixed-font rule is a VectorCraft design choice. Behavior reference: [Add stylistic sets to selected text](https://helpx.adobe.com/illustrator/desktop/design-with-text/special-characters-glyphs/add-stylistic-sets-to-selected-text.html) and the [OpenType specification](https://learn.microsoft.com/en-us/typography/opentype/spec/features_pt).
Right-clicking an OpenType feature row preserves the text selection. The row offers **Turn Off** when every affected character has the feature on, and **Turn On** when the feature is off or mixed. On a mixed Type-tool selection, **Turn On** enables the feature across the selected range and leaves characters outside it untouched. **Reset OpenType Features** restores the same defaults as the panel menu. Each action takes one undo step. Focused tests in `panels::opentype::tests` include `right_clicking_an_opentype_row_offers_turn_on_or_turn_off`, `clicking_turn_on_sets_that_feature_in_one_undo_step`, `turn_on_preserves_the_mixed_character_range_and_undo_restores_its_runs`, and `clicking_reset_opentype_features_clears_the_rows`.
The OpenType panel menu has a Stylistic Sets submenu after Reset OpenType Features, with the same sets, labels and checks as the panel's Stylistic Sets button; a set chosen there turns on or off for the characters the panel acts on in one undo step, keeping their other features, and the submenu is disabled with no text selected or when the font offers no sets. The 2019 user guide ([the help page](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf)) has stylistic sets chosen from the OpenType panel menu. The submenu's place in the menu is VectorCraft's own. Tests: `panels::opentype::tests::the_panel_menu_stylistic_sets_submenu_turns_sets_on_and_off`.
With Show East Asian Options on, the OpenType panel menu has H or V Style and Roman Italics, as [Format East Asian characters](https://helpx.adobe.com/illustrator/using/formatting-asian-characters.html) describes. H or V Style sets the feature tag `hkna`, which draws kana with the forms the font makes for horizontal type, and with `vkna` for vertical type in vertical type; Roman Italics sets `ital`, the font's italic forms of half-width alphanumerics ([OpenType feature list](https://learn.microsoft.com/en-us/typography/opentype/spec/featurelist)). Each is checked when every selected character has it and turns it on or off for all of them in one undo step; character styles carry both in OpenType Features. Tests: `panels::opentype::tests::kana_style_and_roman_italics_turn_on_and_off`, `features::tests::kana_style_and_roman_italics_are_kept_and_shaped`.
With Show East Asian Options on, the OpenType panel menu also has Proportional Metrics, before H or V Style; [the help page](https://helpx.adobe.com/illustrator/using/formatting-asian-characters.html) lists it among the OpenType panel options that this setting shows. It sets the `proportionalMetrics` character attribute that the Character panel menu's item sets (`palt` in horizontal type, `vpal` in vertical type), through `text.setFormat` for selected type and `text.setRangeStyle` while the Type tool edits text. It is checked when every character it changes has the attribute (at a Type tool caret, every character of the text), and choosing it turns the attribute on for all of them, or off when it is checked, in one undo step, keeping their other attributes; with no type selected it is disabled. Its place in the menu and the check rule are VectorCraft's own. Tests: `panels::opentype::tests::proportional_metrics_turns_on_and_off_for_a_mixed_range`, `panels::opentype::tests::proportional_metrics_reaches_a_selected_object_and_the_text_at_a_caret`.