Skip to content

Commit

Permalink
support italic feature freeze config and add normal preset
Browse files Browse the repository at this point in the history
  • Loading branch information
subframe7536 committed Aug 10, 2024
1 parent eb4f226 commit db18eb9
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 30 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
.astro
node_modules
dist
/FontPatcher
/fonts
/source/cn/static
33 changes: 15 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,40 +37,37 @@ Base on `Jetbrains Mono` and **much "Opinioned"**
- cv04: Alternative `l` (with bottom left bar) and `1` (without bottom bar)
- cv98: Full width ``(ellipsis) and ``(emdash) support for Maple Mono NF CN
- cv99: Traditional punctuations support for Maple Mono NF CN
- ss01: Non-cursive italic style `f l i j x y`
- ss01: Non-cursive italic style `l i j k x`
- ss02: Disable ligautures on equals like `==` / `!=` / `<=`
- ss03: Ignore cases on all tags
- ss04: Disable ligatures on `__`, `#__`, `***`
- ss04: Disable ligatures on `__`, `#__`, `***`, `\n`

## Build

### Browser

WIP

### Local

clone the repo and run in your local machine.
clone the repo and run in your local machine. Make sure you have `python3` and `pip` installed

```shell
git clone https://github.com/subframe7536/maple-font --depth 1 -b variable
pip install foundrytools-cli
python build.py
```

You can change config in `config.json`
- for `Ubuntu` or `Debian`, maybe `python-is-python3` is needed as well

Make sure you have `python3` and `pip` installed
If you have trouble to install the dependencies, just create a new Github codespace on `variable` branch and run the commands there

- for custom `font-patcher` args, `font-forge` (and maybe `python3-fontforge` as well) is needed
- for `Ubuntu` or `Debian`, maybe `python-is-python3` is needed as well
### Customize

```shell
pip install foundrytools-cli
python build.py
```
You can change build config in `config.json`

If you have trouble to install the dependencies, just create a new Github codespace on `variable` branch and run the commands there
- There is `--normal` option in `build.py` for common config, just like `Jetbrains Mono` (with slashed zero)
- For custom `font-patcher` args, `font-forge` (and maybe `python3-fontforge` as well) is needed

### Chinses version

1. Download CN base font at [Gitee release](https://gitee.com/subframe7536/Maple/releases/tag/v7.0-beta22-cn)
2. put them into `./source/cn`
3. run `build.py` and **BE PATIENT**, instantiation will take about 15 minutes

## credit

Expand Down
43 changes: 34 additions & 9 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
# whether to archieve fonts
release_mode = "--release" in sys.argv

# whether to use normal preset
use_normal = "--normal" in sys.argv

# =========================================================================================

WIN_FONTFORGE_PATH = "C:/Program Files (x86)/FontForgeBuilds/bin/fontforge.exe"
Expand Down Expand Up @@ -68,6 +71,19 @@
"ss04": "ignore",
"zero": "ignore",
},
"feature_freeze_italic": {
"cv01": "ignore",
"cv02": "ignore",
"cv03": "ignore",
"cv04": "ignore",
"cv98": "ignore",
"cv99": "ignore",
"ss01": "ignore",
"ss02": "ignore",
"ss03": "ignore",
"ss04": "ignore",
"zero": "ignore",
},
# nerd font settings
"nerd_font": {
# whether to enable Nerd Font
Expand Down Expand Up @@ -105,7 +121,7 @@
}

try:
with open("config.json", "r") as f:
with open("./source/preset-normal.json" if use_normal else "config.json", "r") as f:
data = json.load(f)
if "$schema" in data:
del data["$schema"]
Expand Down Expand Up @@ -268,12 +284,13 @@ def get_font_name(style_name_compact: str):
_style_name = style_name_compact[:-6] + " Italic"

if style_name_compact in skip_subfamily_list:
return "", _style_name, _style_name
return "", _style_name, _style_name, is_italic
else:
return (
" " + style_name_compact.replace("Italic", ""),
"Italic" if is_italic else "Regular",
_style_name,
is_italic,
)


Expand Down Expand Up @@ -311,7 +328,7 @@ def add_cv98(font):
lang_sys_rec.LangSys.FeatureIndex.append(feature_index)


def freeze_feature(font: TTFont):
def freeze_feature(font: TTFont, is_italic: bool):
# check feature list
feature_record = font["GSUB"].table.FeatureList.FeatureRecord
feature_dict = {
Expand All @@ -325,7 +342,9 @@ def freeze_feature(font: TTFont):
]

# Process features
for tag, status in build_config["feature_freeze"].items():
for tag, status in build_config[
f"feature_freeze{'_italic' if is_italic else ''}"
].items():
target_feature = feature_dict.get(tag)
if not target_feature or status == "ignore":
continue
Expand Down Expand Up @@ -364,7 +383,7 @@ def build_mono(f: str):

style_name_compact = f[10:-4]

style_name1, style_name2, style_name = get_font_name(style_name_compact)
style_name1, style_name2, style_name, is_italic = get_font_name(style_name_compact)

set_font_name(
font,
Expand All @@ -389,7 +408,7 @@ def build_mono(f: str):
elif style_name1 == " ExtraLight":
font["OS/2"].usWeightClass = 275

freeze_feature(font)
freeze_feature(font, is_italic)

font.save(_path)
font.close()
Expand Down Expand Up @@ -434,7 +453,9 @@ def build_using_font_patcher(font_basename: str) -> TTFont:
# format font name
style_name_compact_nf = f[10:-4]

style_name_nf1, style_name_nf2, style_name_nf = get_font_name(style_name_compact_nf)
style_name_nf1, style_name_nf2, style_name_nf, _ = get_font_name(
style_name_compact_nf
)

set_font_name(
nf_font,
Expand Down Expand Up @@ -473,7 +494,9 @@ def build_cn(f: str):
]
)

style_name_cn1, style_name_cn2, style_name_cn = get_font_name(style_name_compact_cn)
style_name_cn1, style_name_cn2, style_name_cn, is_italic = get_font_name(
style_name_compact_cn
)

set_font_name(
font,
Expand All @@ -499,7 +522,7 @@ def build_cn(f: str):
# https://github.com/subframe7536/maple-font/issues/188
add_cv98(font)

freeze_feature(font)
freeze_feature(font, is_italic)

if build_config["cn"]["fix_meta_table"]:
# add code page, Latin / Japanese / Simplify Chinese / Traditional Chinese
Expand Down Expand Up @@ -543,6 +566,8 @@ def main():
font = TTFont(input_file)
font.save(input_file.replace(src_dir, output_variable))

run(f"ftcli fix italic-angle {output_variable}")
run(f"ftcli fix monospace {output_variable}")
run(f"ftcli converter vf2i {output_variable} -out {output_ttf}")
run(f"ftcli fix italic-angle {output_ttf}")
run(f"ftcli fix monospace {output_ttf}")
Expand Down
13 changes: 13 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@
"ss04": "ignore",
"zero": "ignore"
},
"feature_freeze_italic": {
"cv01": "ignore",
"cv02": "ignore",
"cv03": "ignore",
"cv04": "ignore",
"cv98": "ignore",
"cv99": "ignore",
"ss01": "ignore",
"ss02": "ignore",
"ss03": "ignore",
"ss04": "ignore",
"zero": "ignore"
},
"nerd_font": {
"enable": true,
"version": "3.2.1",
Expand Down
48 changes: 48 additions & 0 deletions source/preset-normal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"$schema": "./schema.json",
"family_name": "Maple Mono",
"use_hinted": true,
"pool_size": 4,
"feature_freeze": {
"cv01": "enable",
"cv02": "enable",
"cv03": "ignore",
"cv04": "ignore",
"cv98": "ignore",
"cv99": "ignore",
"ss01": "ignore",
"ss02": "ignore",
"ss03": "ignore",
"ss04": "ignore",
"zero": "ignore"
},
"feature_freeze_italic": {
"cv01": "ignore",
"cv02": "ignore",
"cv03": "ignore",
"cv04": "ignore",
"cv98": "ignore",
"cv99": "ignore",
"ss01": "enable",
"ss02": "ignore",
"ss03": "ignore",
"ss04": "ignore",
"zero": "ignore"
},
"nerd_font": {
"enable": true,
"version": "3.2.1",
"mono": false,
"use_font_patcher": false,
"glyphs": [
"--complete"
],
"extra_args": []
},
"cn": {
"enable": true,
"with_nerd_font": true,
"fix_meta_table": true,
"clean_cache": false
}
}
109 changes: 107 additions & 2 deletions source/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"cv03": {
"type": "string",
"description": "Alternative 'i' (without bottom left bar)",
"description": "Alternative regular 'i' (without bottom left bar)",
"enum": [
"ignore",
"disable",
Expand Down Expand Up @@ -78,7 +78,112 @@
},
"ss01": {
"type": "string",
"description": "Non-cursive italic style",
"description": "Non-cursive italic style of 'l i j k x'",
"enum": [
"ignore",
"disable",
"enable"
]
},
"ss02": {
"type": "string",
"description": "Disable ligautures on equals like '==', '!=', '<='",
"enum": [
"ignore",
"disable",
"enable"
]
},
"ss03": {
"type": "string",
"description": "Ignore cases on all tags",
"enum": [
"ignore",
"disable",
"enable"
]
},
"ss04": {
"type": "string",
"description": "Disable ligatures on '__', '#__', '***' and escape strings",
"enum": [
"ignore",
"disable",
"enable"
]
},
"zero": {
"type": "string",
"description": "Dot style '0'",
"enum": [
"ignore",
"disable",
"enable"
]
}
}
},
"feature_freeze_italic": {
"type": "object",
"description": "Freeze some font features (No effect on Variable font) for italic font \n enable: enable font features by default \n disable: remove some font features \n ignore: skip handle target font features",
"properties": {
"cv01": {
"type": "string",
"description": "Classic '@', '$', '&', 'Q', '=>', '->'",
"enum": [
"ignore",
"disable",
"enable"
]
},
"cv02": {
"type": "string",
"description": "Alternative 'a' (with top alarm)",
"enum": [
"ignore",
"disable",
"enable"
]
},
"cv03": {
"type": "string",
"description": "Alternative regular 'i' (without bottom left bar)",
"enum": [
"ignore",
"disable",
"enable"
]
},
"cv04": {
"type": "string",
"description": "Alternative 'l' (with bottom left bar) and '1' (without bottom bar)",
"enum": [
"ignore",
"disable",
"enable"
]
},
"cv98": {
"type": "string",
"description": "Full width '…'(ellipsis) and '—'(emdash) support for Maple Mono NF CN",
"enum": [
"ignore",
"disable",
"enable"
]
},
"cv99": {
"type": "string",
"description": "Traditional punctuations support for Maple Mono NF CN",
"enum": [
"ignore",
"disable",
"enable"
]
},
"ss01": {
"type": "string",
"description": "Non-cursive italic style of 'l i j k x'",
"enum": [
"ignore",
"disable",
Expand Down

0 comments on commit db18eb9

Please sign in to comment.