This discussion is archived
0 Replies Latest reply: Oct 22, 2012 3:47 PM by Håkan Andersson RSS

Loading font from resource degrades quality?!

Håkan Andersson Newbie
Currently Being Moderated
Hi,

I have some specialized fonts that I want to distribute within my JAR file in order to ensure that my Java FX 2.0 application has the correct visual appearance on the client machine. However, I have noticed that the font anti-aliasing and overall quality gets really bad when I load it via Font.loadFont(InputStream, int); In order to test this I took Arial (arial.ttf) which was already installed in my Windows OS font folder and copied it to my resource/fonts folder within my source folder. When I load Arial from this location using Font.load(InputStream, int) it looks really bad, but if I skip the load command (relying on the OS installed version) it looks excellent. Why is this?

I set my fonts via CSS, e.g:

     -fx-font-family: Arial;
     -fx-font-size: 13px;

And load my fonts using:

     InputStream resource = getClass().getResourceAsStream(aResource);
if (resource == null) {
     throw new ResourceIOException("Failed to load resource stream: \"" + aResource + "\"", aResource);
}
Font font = Font.loadFont(resource, 36);
if (font == null) {
     throw new ResourceException("Invalid font resource: " + aResource, aResource);
}

As you can see the loaded size is set to 36 but I have tried all kinds of values here ranging from 10 to 200 and it doesn't seems to make any difference. Any suggestions?

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points