我正在尝试使用 SWT 图形显示文本轮廓。更准确地说,我需要编写以下方式显示文本的代码:
http://java.sun.com/developer/onlineTraining/Media/2DText/Art/StarryShape.gif
我找到了以下代码,并希望将其从 AWT 翻译为 SWT。
FontRenderContext frc = g2.getFontRenderContext();
Font f = new Font("Times",Font.BOLD,w/10);
String s = new String("The Starry Night");
TextLayout tl = new TextLayout(s, f, frc);
float sw = (float) tl.getBounds().getWidth();
AffineTransform transform = new AffineTransform();
transform.setToTranslation(w/2-sw/2, h/4);
Shape shape = tl.getOutline(transform);
Rectangle r = shape.getBounds();
g2.setColor(Color.blue);
g2.draw(shape);
(来自java.sun.com/developer/onlineTraining/Media/2DText/style.html的代码)
但我不知道如何在swt中获取TextLayout的轮廓。 是否有这样的可能性?