How to enable fake slant feature in kitty? #9700
-
|
I'm trying to configure Chinese fonts in kitty. I prefer to use JetBrains Mono in English and Noto Sans CJK SC in Chinese. To solve the font fallback, I use <?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd">
<fontconfig>
<match target="pattern">
<test name="prgname" compare="eq">
<string>kitty</string>
</test>
<edit mode="prepend" name="family">
<string>Noto Sans CJK SC</string>
</edit>
</match>
</fontconfig>It works well in regular and bold fonts. But for CJK fonts, the font files rarely provide italic glyphs directly. Instead, they use <?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<!-- bold -->
<match target="pattern">
<test name="family"><string>Noto Sans CJK SC</string></test>
<test name="weight" compare="more_eq"><const>bold</const></test>
<edit name="family" mode="assign"><string>Noto Sans CJK SC</string></edit>
<edit name="style" mode="assign"><string>Bold</string></edit>
</match>
<!-- italic (fake slant) -->
<match target="font">
<test name="family"><string>Noto Sans CJK SC</string></test>
<test name="slant" compare="more_eq"><const>italic</const></test>
<edit name="matrix" mode="assign">
<matrix>
<double>1</double><double>0.2</double>
<double>0</double><double>1</double>
</matrix>
</edit>
<edit name="slant" mode="assign"><const>italic</const></edit>
<edit name="embeddedbitmap" mode="assign"><bool>false</bool></edit>
</match>
</fontconfig>$ fc-match "Noto Sans CJK SC:slant=italic" matrix
:matrix=1 0.2 0 1I am sure that the configuration take effects, but it seems that kitty does not support this feature. $ echo -e "\033[3m斜体中文测试 Italic\033[0m"
斜体中文测试 ItalicIt fallbacks to Noto Sans CJK SC directly. I wonder if there is an approach to achieve my expected effects. (Well, I know that fake slant is not a good feature in font designing, but it is special and important in CJK fonts.) |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
|
I recall kitty supports "font_features" to enable OpenType features, but fake slant is not an OpenType feature; it's a fontconfig transformation. Kitty uses harfbuzz and fontconfig directly? I think kitty respects fontconfig's matrix for slant if you set "italic_font" to the same family and enable "allow_bold"? Actually there is a known issue: kitty does not apply fontconfig's slant transform; you need to use the "italic_font" setting pointing to a font file that has italic glyphs, or use the "allow_bold" for bold. For fake slant, you can use the "italic_font" with same file and set "font_features" maybe? I think you need to set "italic_font" to the same font and then set "allow_bold"? Not sure. |
Beta Was this translation helpful? Give feedback.
-
|
Your transform is silently dropped because kitty doesn't read Kitty also has no italic synthesis path of its own. There is no The good news: fontconfig-based fallback does honour italic state. When your primary font lacks a CJK glyph, kitty queries fontconfig with Two options that work without any kitty changes:
Note that There's also feature request #9857 asking for |
Beta Was this translation helpful? Give feedback.
-
|
I opened #9990 which makes kitty honour FC_MATRIX. Two corrections to my answer above:
|
Beta Was this translation helpful? Give feedback.
-
|
Even after the 0.47.0 update I can't seem to get FiraCode rendering with fake slant. What could I be missing? |
Beta Was this translation helpful? Give feedback.
I opened #9990 which makes kitty honour FC_MATRIX. Two corrections to my answer above:
Your original setup was correct. fontconfig's stock
90-synthetic.conf(default-enabled in every distro) already produces the matrix(1, 0.2, 0, 1)for italic-context CJK queries on roman-only fonts. Your custom<edit name="matrix">rule was redundant but harmless. The reason nothing rendered as italic was kitty silently dropping the matrix inpattern_as_dict(), not anything wrong on your side.If #9990 lands you won't need to switch fonts. Stock Noto Sans CJK SC + stock fontconfig + your existing kitty.conf will fake-italic Chinese automatically. The Sarasa Mono SC and cjk-fonts-ttf options remain u…