bobbylight / RSyntaxTextArea

A syntax highlighting, code folding text editor for Java Swing applications.
BSD 3-Clause "New" or "Revised" License
1.1k stars 258 forks source link

How to use fallback font for a token type #526

Open anil-net opened 9 months ago

anil-net commented 9 months ago

Describe the solution you'd like I have a requirement to use RsyntaxTextArea in a desktop based code editor. The requirement is to use JetBrains Mono Regular font for all english/standard characters. But then, we need to have a fallback font (multiple fallback fonts) to print characters like chinese, hebrew, korean if JetBrains Mono Regular font is not able to print.

How to achieve this functionality. Could someone please help?

anil-net commented 9 months ago

Hi @bobbylight,

It would be highly appreciated if you could please help me how to handle the scenario of fallback fonts in RsyntaxTextArea?

I searched a lot but i could not find any solution for this.

Please let me know if any questions.

robert-dbvis commented 3 months ago

We had similar requests. I fixed our problem by adding two methods to RSyntaxTextArea: getFontForToken and getFontMetricsForToken and then our subclass of RSyntaxTextArea overrides these methods to check the characters in the token and change to a fallback font when Font.canDisplay say that the default font does can not. I created a pull request for this, see PR #557. This means that the font for a Token is the same, which may look slightly off if you have tokens that mix character classes, however this is probably good enough for most cases.