arduino / Arduino

Arduino IDE 1.x
https://www.arduino.cc/en/software
Other
14.07k stars 7.01k forks source link

Enable glyph-ligature for programming fonts like FiraCode #8761

Open sauttefk opened 5 years ago

sauttefk commented 5 years ago

It would be nice if the Arduino-IDE would support fonts with special glyph-ligatures like the font "Fira Code" like most other modern IDEs do.

abritinthebay commented 4 years ago

Apparently this is not hard to do so much as needless complex.

There is an old bug (https://bugs.openjdk.java.net/browse/JDK-8139741) which prevents ligatures from being respected when using the normal pattern (which you can see is used in the preferences file as editor.font=<font name>,<font weight>,<font size>):

// BROKEN PATTERN
Font myFont = new Font(<FONT_CAMILY_NAME>, Font.PLAIN, 72);

Instead, the font ligatures will only be respected if it is loaded from a binary location:

// WORKING PATTERN
File myFontFile = new File(<FILE_LOCATION>);
Font fixed = Font.createFont(Font.TRUETYPE_FONT, myFontFile);

Once the font is loaded from binary, ligatures must be set via TextAttributes like so:

Map attributes = fixed.getAttributes();
attributes.put(TextAttribute.LIGATURES, TextAttribute.LIGATURES_ON);
fixed = fixed.deriveFont(attributes);

So... this is kind of a pain in the ass to implement as you have to resolve the font file from the file name. Possible of course, but a pain in the ass.