How can I use True Type Collection (.ttc) in JavaFX?

810 views Asked by At

I've successfully loaded .ttf fonts in CSS in my application. When I try to load .ttc for international language support, I get this

Jun 08, 2015 10:12:44 AM com.sun.javafx.css.StyleManager loadStylesheetUnPrivileged
INFO: Could not load @font-face font [file:/E:/DanIDE/out/production/DanIDE/font/tsentsiu-sans-mono-regular.ttc]

So my question is how do I use .ttc in my JavaFX project? Thanks a lot!


Edit: In my CSS I loaded the font like this:

@font-face {
    font-family: 'Tsentsiu Sans Mono HC';
    src: url('/font/tsentsiu-sans-mono-regular.ttc');
}

@font-face {
    font-family: 'Tsentsiu Sans Mono HC Bold';
    src: url('/font/tsentsiu-sans-mono-bold.ttc');
}

.code {
    -fx-font-family: "Tsentsiu Sans Mono HC";
    -fx-fill: green;
}

.variable {
    -fx-font-family: 'Tsentsiu Sans Mono HC Bold';
    -fx-fill: red;
}

and the RichTextFX project loaded the CSS for me.

1

There are 1 answers

0
varren On BEST ANSWER

Copy-paste solution from comments:

You have to load font at least once in your code before showing it. Event if you use it in css. Just put load line somewhere in the beginning and it should work.

Font.loadFont(getClass().getResourceAsStream("/tsentsiu-sans-mono-regular.ttc")‌​, 20);