From 2e1b8e671b1e149a9a4f15f56fe5f2fc6910b41e Mon Sep 17 00:00:00 2001 From: subframe7536 <1667077010@qq.com> Date: Tue, 7 Jan 2025 10:00:47 +0800 Subject: [PATCH] various improves #313: - support full width quote in CN - make CN ligature fine-grain - bring back `locl` in ZHH and ZHT --- build.py | 34 ++++++++++++++++++++-------------- config.json | 2 ++ source/features/README.md | 4 +++- source/features/cn.fea | 38 +++++++++++++++++++++++++++++++++----- source/preset-normal.json | 2 ++ source/schema.json | 10 +++++++++- 6 files changed, 69 insertions(+), 21 deletions(-) diff --git a/build.py b/build.py index 5c78ada..e4852fb 100755 --- a/build.py +++ b/build.py @@ -208,6 +208,8 @@ class FontConfig: "cv34": "ignore", "cv35": "ignore", "cv36": "ignore", + "cv96": "ignore", + "cv97": "ignore", "cv98": "ignore", "cv99": "ignore", "ss01": "ignore", @@ -537,21 +539,23 @@ def parse_style_name(style_name_compact: str, skip_subfamily_list: list[str]): ) -def fix_cv98(font: TTFont): +def fix_cn_cv(font: TTFont): gsub_table = font["GSUB"].table - feature_list = gsub_table.FeatureList + config = { + "cv96": ["quoteleft", "quoteright", "quotedblleft", "quotedblright"], + "cv97": ["ellipsis"], + "cv98": ["emdash"], + } - for feature_record in feature_list.FeatureRecord: - if feature_record.FeatureTag != "cv98": - continue - sub_table = gsub_table.LookupList.Lookup[ - feature_record.Feature.LookupListIndex[0] - ].SubTable[0] - sub_table.mapping = { - "emdash": "emdash.cv98", - "ellipsis": "ellipsis.cv98", - } - break + for feature_record in gsub_table.FeatureList.FeatureRecord: + if feature_record.FeatureTag in config: + sub_table = gsub_table.LookupList.Lookup[ + feature_record.Feature.LookupListIndex[0] + ].SubTable[0] + sub_table.mapping = { + value: f"{value}.full" + for value in config[feature_record.FeatureTag] + } def remove_locl(font: TTFont): @@ -884,7 +888,8 @@ def build_cn(f: str, font_config: FontConfig, build_option: BuildOption): cn_font["OS/2"].xAvgCharWidth = 600 # https://github.com/subframe7536/maple-font/issues/188 - fix_cv98(cn_font) + # https://github.com/subframe7536/maple-font/issues/313 + fix_cn_cv(cn_font) handle_ligatures( font=cn_font, @@ -1075,6 +1080,7 @@ def main(): # ========================================================================================= if not font_config.ttf_only and build_option.should_build_cn(font_config): + def _build_cn(): print( f"\nšŸ”Ž Build CN fonts {'with Nerd-Font' if font_config.should_cn_use_nerd_font() else ''}...\n" diff --git a/config.json b/config.json index d30f956..4aa591a 100644 --- a/config.json +++ b/config.json @@ -15,6 +15,8 @@ "cv34": "ignore", "cv35": "ignore", "cv36": "ignore", + "cv96": "ignore", + "cv97": "ignore", "cv98": "ignore", "cv99": "ignore", "ss01": "ignore", diff --git a/source/features/README.md b/source/features/README.md index 3db2cce..e48b240 100644 --- a/source/features/README.md +++ b/source/features/README.md @@ -165,7 +165,9 @@ fixme)) #### CN Only -- cv98: Full width `…`(ellipsis) and `—`(emdash) +- cv96: Full width `ā€œ`(double quote left), `ā€`(double quote right), `ā€˜`(single quote left), `’`(single quote right) +- cv97: Full width `…`(ellipsis) +- cv98: Full width `—`(emdash) - cv99: Traditional punctuations ### Style Sets (ssXX) diff --git a/source/features/cn.fea b/source/features/cn.fea index 2234aaa..a2500ce 100644 --- a/source/features/cn.fea +++ b/source/features/cn.fea @@ -13,10 +13,20 @@ lookup CN2TW { sub uniFF1F by uniFF1F.tw; } CN2TW; -lookup full_width_e { - sub emdash by emdash.cv98; - sub ellipsis by ellipsis.cv98; -} full_width_e; +lookup full_width_quote { + sub quoteleft by quoteleft.full; + sub quoteright by quoteright.full; + sub quotedblleft by quotedblleft.full; + sub quotedblright by quotedblright.full; +} full_width_quote; + +lookup full_width_ellipsis { + sub ellipsis by ellipsis.full; +} full_width_ellipsis; + +lookup full_width_emdash { + sub emdash by emdash.full; +} full_width_emdash; feature ccmp { # GSUB feature: Glyph Composition / Decomposition @@ -48,8 +58,26 @@ feature ccmp { } ccmp; +feature locl { + language ZHH; # Chinese, Traditional, Hong Kong SAR + lookup CN2TW; + language ZHT; # Chinese, Traditional + lookup CN2TW; +} locl; + +# ā€œā€ ā€˜ā€™ +feature cv96 { + lookup full_width_quote; +} cv96; + +# …… +feature cv97 { + lookup full_width_ellipsis; +} cv97; + +# —— feature cv98 { - lookup full_width_e; + lookup full_width_emdash; } cv98; feature cv99 { diff --git a/source/preset-normal.json b/source/preset-normal.json index 142b1a7..b6c3eec 100644 --- a/source/preset-normal.json +++ b/source/preset-normal.json @@ -15,6 +15,8 @@ "cv34": "enable", "cv35": "enable", "cv36": "enable", + "cv96": "ignore", + "cv97": "ignore", "cv98": "ignore", "cv99": "ignore", "ss01": "ignore", diff --git a/source/schema.json b/source/schema.json index edfa90d..401db7c 100644 --- a/source/schema.json +++ b/source/schema.json @@ -83,8 +83,16 @@ "description": "[Italic Only] Alternative 'x' (without top and bottom tails)", "$ref": "#/definitions/freeze_options" }, + "cv96": { + "description": "[CN Only] Full width 'ā€œ'(double quote left), 'ā€'(double quote right), 'ā€˜'(single quote left), '’'(single quote right)", + "$ref": "#/definitions/freeze_options" + }, + "cv97": { + "description": "[CN Only] Full width '…'(ellipsis)", + "$ref": "#/definitions/freeze_options" + }, "cv98": { - "description": "[CN Only] Full width '…'(ellipsis) and '—'(emdash)", + "description": "[CN Only] Full width '—'(emdash)", "$ref": "#/definitions/freeze_options" }, "cv99": {