1

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.

Tengyu Liu
  • 1,223
  • 2
  • 15
  • 36
  • Can you also add you css font loading part? And i think you should have something like this in your code anyway at least once before showing the font. Event if you use it in css... `Font.loadFont(getClass().getResourceAsStream("/tsentsiu-sans-mono-regular.ttc"), 20);` But i can be wrong here, it was just my solution for similar issue. – varren Jun 08 '15 at 02:41
  • @varren I added the part where I loaded the font in css. If I load the font by code, how should I do so? Do I just put the line before I load the css and it will magically work? – Tengyu Liu Jun 08 '15 at 02:47
  • yep, just put load line somewhere in the begining and it should work if it was an issue – varren Jun 08 '15 at 02:51
  • @varren You are right it works like magic! Can you put it in an answer so I can accept it? thx – Tengyu Liu Jun 08 '15 at 03:43

1 Answers1

1

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); 
varren
  • 14,551
  • 2
  • 41
  • 72