Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you use font ligatures with JavaFX

Tags:

java

javafx

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.

like image 945
kossmoboleat Avatar asked Dec 10 '17 13:12

kossmoboleat


People also ask

What is font ligature?

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).


1 Answers

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.

like image 169
GOXR3PLUS Avatar answered Oct 22 '22 01:10

GOXR3PLUS