mirror of
https://github.com/storytold/designcraft.git
synced 2026-10-28 04:06:54 -06:00
fix(typography): Standard Ligatures switches on over a feature-list -liga
This commit is contained in:
@@ -1501,8 +1501,9 @@ fn open_type_features(s: &mut Session, _p: &Value) -> Result<Value> {
|
||||
let measure = |tag: &str| {
|
||||
let (mut applied, mut available) = (0, 0);
|
||||
for seg in &segments {
|
||||
// Standard ligatures are the `ligatures` attribute, which shaping reads.
|
||||
let on = if tag == "liga" { seg.ligatures } else { designcraft_doc::otf::is_on(&seg.applied, tag) };
|
||||
// Standard ligatures are the `ligatures` attribute, which shaping reads, unless the
|
||||
// feature list turns `liga` off.
|
||||
let on = designcraft_doc::otf::is_on(&seg.applied, tag) && (tag != "liga" || seg.ligatures);
|
||||
if on {
|
||||
applied += seg.len;
|
||||
}
|
||||
@@ -2844,6 +2845,9 @@ mod open_type_features_tests {
|
||||
s.execute("type.char", &json!({"attrs": {"ligatures": true}})).unwrap();
|
||||
let v = s.execute("type.openTypeFeatures", &json!({})).unwrap();
|
||||
assert_eq!(feature(&v, "liga")["applied"], "all", "{v}");
|
||||
s.execute("type.feature", &json!({"features": {"liga": false}})).unwrap();
|
||||
let v = s.execute("type.openTypeFeatures", &json!({})).unwrap();
|
||||
assert_eq!(feature(&v, "liga")["applied"], "none", "-liga in the feature list: {v}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,10 +92,12 @@ struct Changes {
|
||||
|
||||
impl Changes {
|
||||
/// Standard Ligatures is the `ligatures` attribute: shaping turns `liga` off through it, and
|
||||
/// IDML carries it as `Ligatures`, so `liga` stays out of the feature list.
|
||||
/// IDML carries it as `Ligatures`, so `liga` stays out of the feature list. The tag is also
|
||||
/// cleared from the selection's features, since an earlier `-liga` would keep shaping it off.
|
||||
fn set(&mut self, tag: &str, on: bool) {
|
||||
if tag == "liga" {
|
||||
self.ligatures = Some(on);
|
||||
self.features.insert("liga".to_string(), true);
|
||||
} else {
|
||||
self.features.insert(tag.to_string(), on);
|
||||
}
|
||||
@@ -396,4 +398,16 @@ mod tests {
|
||||
click(&mut h, "Standard Ligatures");
|
||||
assert_eq!(chars(&mut h)["ligatures"], true, "the switch turns ligatures back on");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn standard_ligatures_switch_on_clears_a_feature_list_liga_off() {
|
||||
let mut h = harness();
|
||||
h.state_mut().run("type.feature", json!({"features": {"liga": false}})).unwrap();
|
||||
assert_eq!(chars(&mut h)["otfFeatures"], json!(["-liga"]));
|
||||
h.run_steps(2);
|
||||
click(&mut h, "Standard Ligatures");
|
||||
let c = chars(&mut h);
|
||||
assert_eq!(c["ligatures"], true, "{c}");
|
||||
assert!(!c["otfFeatures"].as_array().is_some_and(|l| l.iter().any(|t| t.as_str().is_some_and(|t| t.ends_with("liga")))), "{c}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user