-
Notifications
You must be signed in to change notification settings - Fork 258
Ligature Support
RSyntaxTextArea supports ligatures via AWT/Swing's built-in support. That means there's no API in the library specific to it; instead you have to define Font
s with certain TextAttributes
defined:
Here's an example of how to enable them:
RSyntaxTextArea textArea = new RSyntaxTextArea(25, 70);
textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT);
// Not all fonts support ligatures. Make sure the font you're using does.
Font font = new Font("JetBrains Mono", Font.PLAIN, 12);
Map<TextAttribute, Object> attrs = new HashMap<>();
attrs.put(TextAttribute.KERNING, TextAttribute.KERNING_ON);
attrs.put(TextAttribute.LIGATURES, TextAttribute.LIGATURES_ON);
textArea.setFont(font.deriveFont(attrs));
The JVM's ligature support has improved greatly over time. If you enable this feature, it's advised that you use the latest JRE version possible, or preferably at least Java 17:
- Java 8 supports ligatures, but some will not render properly, and painting performance will be very, very bad
- Java 11 supports rendering ligatures better, but painting performance is still really bad (noticeable lag when typing fast or moving the caret quickly)
- Java 17 seems to perform better with kerning and/or ligatures enabled, though there is still likely some smaller performance hit
As of 3.5.0, RSTA will try to use the Cascadia Code font as its default font, which does support ligatures. If you don't have that font installed, it will fall back onto Consolas
, which doesn't support ligatures, so you'll need to call setFont()
to use one that does.
On Macs, rendering ligatures seems to work well (all font rendering on Macs is better than on Windows), but there appears to be bugs with calculating font metrics when kerning and/or ligatures are enabled, resulting in caret placement and selection rendering being wrong. I don't advise that you enable ligature support on Macs unless you confirm this doesn't happen in your specific environment.
RSTA's default font on MacOS is Menlo
, which doesn't support ligatures.
I haven't had access to a Linux machine to test ligature performance there.
RSTA's default font on Linux is Ubuntu Mono
, which doesn't support ligatures.