Support setting font feature values (#11898)

Now (on `macOS` and `Windows`) we can set font feature value:
```rust
  "buffer_font_features": {
    "cv01": true,
    "cv03": 3,
    "cv09": 1,
    "VSAH": 7,
    "VSAJ": 8
  }
```

And one can still use `"cv01": true`.



https://github.com/zed-industries/zed/assets/14981363/3e3fcf4f-abdb-4d9e-a0a6-71dc24a515c2




Release Notes:

- Added font feature values, now you can set font features like `"cv01":
7`.

---------

Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
张小白
2024-05-16 14:27:55 -07:00
committed by GitHub
co-authored by Mikayla
parent b6189b05f9
commit 80caa74866
3 changed files with 153 additions and 265 deletions
@@ -1201,26 +1201,26 @@ fn apply_font_features(
// All of these features are enabled by default by DirectWrite.
// If you want to (and can) peek into the source of DirectWrite
let mut feature_liga = make_direct_write_feature("liga", true);
let mut feature_clig = make_direct_write_feature("clig", true);
let mut feature_calt = make_direct_write_feature("calt", true);
let mut feature_liga = make_direct_write_feature("liga", 1);
let mut feature_clig = make_direct_write_feature("clig", 1);
let mut feature_calt = make_direct_write_feature("calt", 1);
for (tag, enable) in tag_values {
if tag == *"liga" && !enable {
for (tag, value) in tag_values {
if tag.as_str() == "liga" && *value == 0 {
feature_liga.parameter = 0;
continue;
}
if tag == *"clig" && !enable {
if tag.as_str() == "clig" && *value == 0 {
feature_clig.parameter = 0;
continue;
}
if tag == *"calt" && !enable {
if tag.as_str() == "calt" && *value == 0 {
feature_calt.parameter = 0;
continue;
}
unsafe {
direct_write_features.AddFontFeature(make_direct_write_feature(&tag, enable))?;
direct_write_features.AddFontFeature(make_direct_write_feature(&tag, *value))?;
}
}
unsafe {
@@ -1233,18 +1233,11 @@ fn apply_font_features(
}
#[inline]
fn make_direct_write_feature(feature_name: &str, enable: bool) -> DWRITE_FONT_FEATURE {
fn make_direct_write_feature(feature_name: &str, parameter: u32) -> DWRITE_FONT_FEATURE {
let tag = make_direct_write_tag(feature_name);
if enable {
DWRITE_FONT_FEATURE {
nameTag: tag,
parameter: 1,
}
} else {
DWRITE_FONT_FEATURE {
nameTag: tag,
parameter: 0,
}
DWRITE_FONT_FEATURE {
nameTag: tag,
parameter,
}
}