我试图找出如何使用 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 的大纲。有这种可能吗?