Java的旋转的文本已经反转字符序列 [英] Java rotated text has reversed characters sequence

查看:160
本文介绍了Java的旋转的文本已经反转字符序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在的子类的JP​​anel 我这样做:

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D)g;        
    g2d.rotate(Math.toRadians(90.));
    g2d.drawString(aString, 40, -40);
}

字母被正确旋转,但第二个是不低于第一预期位置(其右侧,在旋转空间),但是它上面(其左边),第三个是上述(至的左侧)的第二等改变的旋转角度为45度的结果中的每个字符被旋转45度的CW,如预期的,但字符的行被旋转45度逆时针,这是与两个旋转中途被朝向结果是一致的为90度。

The letters are rotated correctly, but the second one is not in the expected position below the first (to its right, in the rotated space), but is above it (to its left), the third is above (to the left of) the second, etc. Changing the rotation angle to 45 degrees results in each character being rotated 45 degrees cw, as expected, but the row of characters being rotated 45 degrees ccw, which is consistent with both rotations being halfway toward the result for 90 degrees.

在0度的旋转文本显示正确。

At 0 degrees rotation the text appears correctly.

我用在Mac OS X 10.8.2的NetBeans 7.1.2开发。在Win 7 SP1的NetBeans的相同版本没有这个问题。

I'm developing with NetBeans 7.1.2 on Mac OS X 10.8.2. Same version of NetBeans on Win 7 SP1 does not have the problem.

什么引起的?

推荐答案

我已经找到了这一问题的解决方案,奇(即错误的奇怪匹配)

I've found an odd solution for this problem (that matches the oddness of the bug)

FontRenderContext frc = new FontRenderContext(g2.getTransform(), true, true);

g2.drawGlyphVector(currentFont.createGlyphVector(frc, aString), textX, textY);

由于某种原因上的FontRenderContext抗锯齿设置为true,将导致它正确地行事。似乎有人在某个地方缺少一个减号在渲染code或误解他们写!规范

For some reason setting anti-aliasing to true on the FontRenderContext will cause it to act correctly. Seems that someone is missing a minus sign somewhere in the render code, or misunderstood the spec they were writing for!

这篇关于Java的旋转的文本已经反转字符序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆