Why does GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts() give different results when ssh'ed in?

≯℡__Kan透↙ 提交于 2021-02-07 14:16:19

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!