17

I've been building a development environment in Java (as a small research project). As part of that, I built a custom text component that draws the text itself using Graphics2d like so:

g2.drawString("some text", 100, 100);

Everything worked fine developing things in Eclipse using 1.6 (I assume this is provided by Apple), until I packaged everything up and ran in java 1.7 (provided by Oracle). Obviously in development environments fonts are pretty important, so I was displeased to see the results in 1.7.

enter image description here

I have tried packaging custom fonts, but they all appear grainy and eroded. The comparison above isn't too bad, but some fonts (like Monaco) look terrible.

I'm guessing this is to do with how Apple hooks things into Quartz. But is there any way to improve things so it doesn't look terrible on other systems? Does anyone have a strategy for this?

Update: This is the comparison in Monaco: enter image description here

and a zoomed comparison of the C (in paintComponent) in Monaco (1.7 on left, 1.6 on right). Note that I am loading the font from a local ttf file using:

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("monaco.ttf");
Font customFont = null;
try
{
customFont = Font.createFont(Font.TRUETYPE_FONT, is);
customFont = customFont.deriveFont(16.0f).deriveFont(Font.BOLD);
                    is.close();
                    ge.registerFont(customFont);
                } catch (FontFormatException e1)
                {
                    e1.printStackTrace();
                } catch (IOException e1)
                {
                    e1.printStackTrace();
                }
this.setFont(customFont);

enter image description here

Note also that anti aliasing is turned on using:

 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
                    RenderingHints.VALUE_ANTIALIAS_ON);
4

1 回答 1

14

Java 6 是由 Apple 开发的。Apple 在图形层上做了很多工作,以使其与 Quartz/Cocoa 一起工作,尤其是让它看起来不错。

对于 Java 7,开发由 Oracle 接管。这并不意味着甲骨文从苹果那里获得了消息来源。相反,他们重新开始(可能将一些 Unix 代码移植到 OS X)。这意味着 Apple 为使 Java 在 OS X 上看起来更好而付出的所有工作基本上都付诸东流了。

苹果非常重视设计。甲骨文...嗯...没那么多(展览A展览B

你能做什么?

  • 编写并向 OpenJDK 提交补丁。
  • 让足够多的人愿意要求 Apple 提交补丁(钱可能会有所帮助)。
  • 回到 Java 6
  • 使用 JNI 直接访问 Cocoa/Quartz,从而获得 OS X 字体渲染引擎。

相关文章:

于 2013-09-16T14:31:43.440 回答