I'm implementing a text editor based on JavaFX. Is it possible to display font ligatures in the same way they work for example in Intellij?
I've found a reference to ligature support in the JavaFX API, but I don't know if this "proves" that there's support.
Ligatures are special characters in a font that combine two (or more) troublesome characters into one. For instance, in serifed text faces, the lowercase f often collides with the lowercase i and l. To fix this, the fi and fl are often combined into a single shape (what pros would call a glyph).
You can use Tomas Mikula RichTextFX library.
https://github.com/FXMisc/RichTextFX/
You many options here :
1) InlineCssTextArea
uses the
Node#setStyle(String cssStyle)
method to style Text objects of
InlineCssTextArea
and for each word or line you can set a different style using :
InlineCssTextArea.setStyle(from,to,style);
I have extensively used it before to have different fonts and styles inside the same line or lines.
2) StyleClassedTextArea
uses the Node#setStyleClass(String styleClass)
method to style Text
objects. You can define the style classes in your stylesheet.
So let's say that inside your application.css
you have defined 5 different style classes with different fonts. One of them might be...
.red { -fx-fill: red; }
so you can use :
styleClassedTextArea.setStyleClass(from, to, "red");
This renders the text in the range [from, to) in red.
3) For more please check https://github.com/FXMisc/RichTextFX it has detailed description.
Also you can search for more examples on the web.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With