问题
Why does the following program return different results depending on how I'm logged in? I'm compiling and running this program using Java 7 update 60 on a freshly installed Mac OS X Mavericks system. If I compile and run this in a shell when logged into the system normally I get less fonts than when I ssh into the system and run it.
The program is as follows:
import java.awt.Font;
import java.awt.GraphicsEnvironment;
public class FontList
{
public static void main(String[] args)
{
final Font[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
System.out.println("Fonts found: " + fonts.length);
for (Font font : fonts)
{
System.out.println(font.getName());
}
}
}
I get 521 fonts when logged in normally, if I then ssh in and run the program I get 725.
Initially I thought it could be something to do with the graphics environment being headless when I ssh in - so I ran it like this when logged in normally:
java -Djava.awt.headless=true FontList
which made no difference to the output. This difference can also be reproduce when I login using su. Suppose I'm already logged in as stackoverflow:
su -l stackoverflow
and then running the program gives the same results as when I use ssh.
I tried this using Apple Java 6 which gives identical output irrespective of how I'm logged in. I've also tried this on Linux using Java 7 (Oracle and OpenJDK) which again behaved consistently.
Can anyone explain what causes this variation in font availability in Java 7 on MAC OS X?
来源:https://stackoverflow.com/questions/24018848/why-does-graphicsenvironment-getlocalgraphicsenvironment-getallfonts-give-di