Add OpenType font feature support via 'guifont' ":f" modifiers#1689
Add OpenType font feature support via 'guifont' ":f" modifiers#1689humblehacker wants to merge 5 commits into
Conversation
Add a SetFontFeaturesMsgID message that carries a comma-separated list
of OpenType feature settings ("tag" or "tag=N" entries). The Core
Text renderer parses the list into a kCTFontFeatureSettingsAttribute
array and applies it when deriving the fonts used for drawing, so the
base, wide, bold and italic fonts all pick up the features. Requires
macOS 10.13 for the OpenType feature tag API; older systems ignore the
setting. The legacy renderer does not support font features.
Signed-off-by: David Whetstone <david@humblehacker.com>
The macfontfeatures option is a comma-separated list of OpenType font
features to enable, e.g.:
:set macfontfeatures=cv01,cv09,ss03=2
Each entry is a four-character feature tag optionally followed by "="
and a number; a bare tag is equivalent to "tag=1". This allows
selecting character variants and stylistic sets in fonts that provide
them, similar to font feature settings in other editors. Setting the
option to an empty string restores the font's default features.
Invalid values are rejected with E474. Includes tests for option
existence, validation and round-tripping.
Signed-off-by: David Whetstone <david@humblehacker.com>
Signed-off-by: David Whetstone <david@humblehacker.com>
|
The test failure doesn't look like it's related to my changes. Can we retry the build? |
|
Looks good for me in the first glance.
|
The kCTFontOpenTypeFeatureTag and kCTFontOpenTypeFeatureValue keys are available since macOS 10.10 per the CoreText SDK headers, which also document that OpenType setting dictionaries are accepted by kCTFontFeatureSettingsAttribute starting with OS X 10.10. The 10.13 guard was stricter than necessary. Signed-off-by: David Whetstone <david@humblehacker.com>
Adopt the OpenType font feature syntax that patch 9.2.0321 introduced for
the Win32 DirectWrite backend, e.g.:
:set guifont=Maple\ Mono:h14:fss19=1:fcalt=0
The ":f" entries in 'guifont' are validated during font parsing (an
invalid entry rejects the font with E596) and routed through the same
SetFontFeaturesMsgID mechanism to the Core Text renderer. A bare tag is
equivalent to "tag=1"; "tag=0" disables a default-on feature.
This removes the MacVim-specific 'macfontfeatures' option in favor of the
cross-platform 'guifont' syntax.
Signed-off-by: David Whetstone <david@humblehacker.com>
|
Thanks for you review!
I believe it is, but it was overly strict. I've dropped it to macOS 10.10, since that's the minimum supported by
Good call. I completely missed that
Yes — |
|
Thank you for your responses and additional work. I've added information about minimal supported version in the changelog somewhere. This will be useful for MacPorts port for old macOS versions, not for a general public version. One more seemingly unrelated question: how could I list all features for a given font and read more information about them? |
|
There are a few third-party command-line tools that could give you that info, but they're not available by default and I don't know them off the top of my head. FontBook unfortunately doesn't show this detail, and the built-in typography settings in macOS's font selection panel show some, but not a complete set. We could add a really simple CoreText function that could dump this info, but I'm not sure if that kind of thing belongs in MacVim. Generally, I find this info where I find the specific font. For example, Maple Mono has a really helpful "Playground" for experimenting with the various features. |
This adds OpenType font feature support — character variants, stylistic sets, etc. — to MacVim's Core Text renderer, using the same
:f'guifont' modifier syntax that patch 9.2.0321 introduced for the Win32 DirectWrite backend:tag=0disables a feature the font enables by default (e.g.fcalt=0); default features are otherwise preserved, matching the Win32 behavior.Implementation
gui_macvim_font_with_name) acceptsh<size>andf<feature>modifiers. Each feature is validated during font parsing (four-character printable-ASCII tag, optional=<number>); an invalid entry rejects the font withE596, like other malformed guifont values.getfontname()round-trips them) and sent to the GUI via a newSetFontFeaturesMsgID(appended beforeLoopBackMsgIDso existing message IDs keep their values across version skew).MMCoreTextViewparses the list into akCTFontFeatureSettingsAttributearray and applies it infontVariantForTextFlags:after bold/italic trait conversion, so the base, wide, bold, and italic fonts all pick up the features and they surviveNSFontManagertrait conversion. Font caches are invalidated on change.@availableguard. The legacy (non-Core Text) renderer ignores the option, matching'macligatures'.'macligatures', which takes precedence over aligaentry (documented).Note on history: the first revision of this PR implemented this as a new
'macfontfeatures'option; per review feedback it now uses the cross-platform 'guifont' syntax instead, and the option has been removed. The renderer-side machinery is unchanged.Testing
test_macvim.vim: guifont:fround-trip andE596validation tests (GUI-only, skipped in terminal runs);test_codestyle.vimpasses.fcv01=1changes the rendered character variants, features apply to bold/italic/wide variants,fcalt=0:fliga=0decomposes the font's default ligatures, an unsupported tag renders unchanged, and removing the:fentries restores defaults.gui.txt, mirroring the Win32fXXflag documentation.AI disclosure
This contribution was developed with AI assistance (Claude Code); the design, implementation, and documentation were AI-generated under my direction, and I reviewed and tested the result.
🤖 Generated with Claude Code