mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-30 02:07:10 +01:00
Glyphs panel menu: East Asian form rows read the selection's fonts when the panel is hidden (#9223)
Fixes main's red Linux gate leg 1 (`panels::glyphs::tests::east_asian_glyph_forms_in_the_panel_menu_set_the_selected_characters_form`, `glyphs/tests.rs:243`). It was a real bug on every platform. The test skips without the craft fonts, so only Linux CI ran it. **Cause.** The Glyphs panel menu's East Asian glyph form rows read the selection's faces from a cache that only the shown panel's `show` filled. With the panel hidden, the cache was empty, and the "unknown" arm enabled every form, so JIS 2004 was offered for a font with no `jp04`. Production always read the faces when it built the items (prod `panels/glyphs.rs:1407`, `:1492`). **Fix.** `form_faces` returns the cached faces while their key is current and reads them otherwise, as `symbols::instance_flags` does. The unknown-means-enabled arm is gone. `refresh_form_faces` runs from the menu rebuild next to `symbols::cache_instances`, so the faces are read once per change of document, selection or fonts, whether or not the panel is shown. Checks: `vectorcraft-ui-egui` lib tests 3779 passed, 0 failed, with `CRAFT_FONTS_DIR` set so the glyph tests run in full. Clippy (`-D warnings`, all targets) and `cargo fmt --check` are clean.
This commit is contained in:
1 parent
a245ad2a6e
commit
19ebdcab54
2 files changed
+25
-20
No files matched your search
@@ -225,6 +225,8 @@ fn rebuild(app: &mut VectorcraftApp, target: Target) {
|
|||||||
}
|
}
|
||||||
// The Symbols panel menu's states read the selection's instances from the walk this keeps.
|
// The Symbols panel menu's states read the selection's instances from the walk this keeps.
|
||||||
crate::panels::symbols::cache_instances(app);
|
crate::panels::symbols::cache_instances(app);
|
||||||
|
// The Glyphs panel menu's East Asian glyph forms read the faces that draw the selected text from the layout this keeps.
|
||||||
|
crate::panels::glyphs::refresh_form_faces(app);
|
||||||
let listed = Listed::of(app);
|
let listed = Listed::of(app);
|
||||||
let mut build = Build { app, lang: crate::i18n::current(), states: CommandStates::new(), refs: Vec::new() };
|
let mut build = Build { app, lang: crate::i18n::current(), states: CommandStates::new(), refs: Vec::new() };
|
||||||
let menus: Vec<Menu> = menu_tree_named(app.session.prefs.font_names_in_english, &listed)
|
let menus: Vec<Menu> = menu_tree_named(app.session.prefs.font_names_in_english, &listed)
|
||||||
|
|||||||
@@ -458,9 +458,6 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
|||||||
// scrolls freely meanwhile.
|
// scrolls freely meanwhile.
|
||||||
let reveal = (marked != app.ui.glyphs_marked).then_some(marked).flatten();
|
let reveal = (marked != app.ui.glyphs_marked).then_some(marked).flatten();
|
||||||
app.ui.glyphs_marked = marked;
|
app.ui.glyphs_marked = marked;
|
||||||
if app.session.prefs.show_east_asian_options {
|
|
||||||
refresh_form_faces(app);
|
|
||||||
}
|
|
||||||
let source = VcGlyphs::of(app);
|
let source = VcGlyphs::of(app);
|
||||||
let (mut family, mut style) = {
|
let (mut family, mut style) = {
|
||||||
let (family, style) = source.font();
|
let (family, style) = source.font();
|
||||||
@@ -1297,10 +1294,13 @@ fn form_face_ids(app: &VectorcraftApp) -> Vec<u32> {
|
|||||||
ids
|
ids
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read the faces of the selection again when the document, the selection or the fonts changed:
|
/// Read the faces of the selection again when the document, the selection or the fonts changed,
|
||||||
/// laying the text out is too much to do for each menu state. The shown panel does it, and a panel
|
/// for the readers that only borrow the app ([`form_faces`]): laying the text out is too much to
|
||||||
/// menu opens only from a shown panel.
|
/// do for each menu state. The menu model does it before it reads the panel menus' states.
|
||||||
fn refresh_form_faces(app: &mut VectorcraftApp) {
|
pub(crate) fn refresh_form_faces(app: &mut VectorcraftApp) {
|
||||||
|
if !app.session.prefs.show_east_asian_options {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let Some(key) = faces_key(app) else {
|
let Some(key) = faces_key(app) else {
|
||||||
app.canvas.glyph_form_faces = None;
|
app.canvas.glyph_form_faces = None;
|
||||||
return;
|
return;
|
||||||
@@ -1312,11 +1312,18 @@ fn refresh_form_faces(app: &mut VectorcraftApp) {
|
|||||||
app.canvas.glyph_form_faces = Some((key, ids));
|
app.canvas.glyph_form_faces = Some((key, ids));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The faces [`refresh_form_faces`] read, when they are those of the selection now.
|
/// The faces of the selection: those [`refresh_form_faces`] read when they are still current, else
|
||||||
fn form_faces(app: &VectorcraftApp) -> Option<Vec<Arc<FontFace>>> {
|
/// read now.
|
||||||
let key = faces_key(app)?;
|
fn form_faces(app: &VectorcraftApp) -> Vec<Arc<FontFace>> {
|
||||||
let (cached, ids) = app.canvas.glyph_form_faces.as_ref()?;
|
let read;
|
||||||
(*cached == key).then(|| ids.iter().filter_map(|id| FontDb::global().face_by_id(*id)).collect())
|
let ids = match (&app.canvas.glyph_form_faces, faces_key(app)) {
|
||||||
|
(Some((cached, ids)), Some(key)) if *cached == key => ids,
|
||||||
|
_ => {
|
||||||
|
read = form_face_ids(app);
|
||||||
|
&read
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ids.iter().filter_map(|id| FontDb::global().face_by_id(*id)).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The value `f` gives every character the glyph form rows act on: the Type tool's selected
|
/// The value `f` gives every character the glyph form rows act on: the Type tool's selected
|
||||||
@@ -1386,8 +1393,7 @@ pub(crate) fn menu_rows(app: &VectorcraftApp) -> Vec<PanelRow> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The row titles of a category, which are the panel's words, with the check on the shown one. A
|
/// The row titles of a category, which are the panel's words, with the check on the shown one. A
|
||||||
/// form a face of the selection has no feature for is disabled, once the shown panel has read the
|
/// form no face of the selection has a feature for is disabled ([`form_faces`]).
|
||||||
/// faces ([`refresh_form_faces`]).
|
|
||||||
pub(crate) fn menu_states(app: &VectorcraftApp, states: &mut CommandStates) {
|
pub(crate) fn menu_states(app: &VectorcraftApp, states: &mut CommandStates) {
|
||||||
let (_, _, face) = browsed_face(app);
|
let (_, _, face) = browsed_face(app);
|
||||||
let cats = categories(face.as_deref());
|
let cats = categories(face.as_deref());
|
||||||
@@ -1409,12 +1415,9 @@ pub(crate) fn menu_states(app: &VectorcraftApp, states: &mut CommandStates) {
|
|||||||
for form in GlyphForm::ALL {
|
for form in GlyphForm::ALL {
|
||||||
// A width form may be drawn with other widths for the same glyphs (`GPOS`) instead of
|
// A width form may be drawn with other widths for the same glyphs (`GPOS`) instead of
|
||||||
// other glyphs.
|
// other glyphs.
|
||||||
let enabled = match (form.feature(), &faces) {
|
let enabled = match form.feature() {
|
||||||
(Some(tag), Some(faces)) => {
|
Some(tag) => faces.iter().any(|f| f.has_substitution_feature(*tag) || (form.is_width() && f.has_positioning_feature(*tag))),
|
||||||
faces.iter().any(|f| f.has_substitution_feature(*tag) || (form.is_width() && f.has_positioning_feature(*tag)))
|
None => has,
|
||||||
}
|
|
||||||
(Some(_), None) => true,
|
|
||||||
(None, _) => has,
|
|
||||||
};
|
};
|
||||||
let checked = form != GlyphForm::Default && shared == Some(form);
|
let checked = form != GlyphForm::Default && shared == Some(form);
|
||||||
states.set(form_ref(form), CommandState::new().title(tl!(glyph_form_label(form))).enabled(enabled).checked(checked));
|
states.set(form_ref(form), CommandState::new().title(tl!(glyph_form_label(form))).enabled(enabled).checked(checked));
|
||||||
|
|||||||
Reference in new issue
Block a user