RSyntaxTextArea icon indicating copy to clipboard operation
RSyntaxTextArea copied to clipboard

How to use fallback font for a token type

Open anil-net opened this issue 1 year ago • 2 comments

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 avatar Dec 19 '23 04:12 anil-net

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.

anil-net avatar Dec 29 '23 17:12 anil-net

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.

robert-dbvis avatar Jun 27 '24 12:06 robert-dbvis