swt 中的文本轮廓
我试图找出如何使用 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的轮廓。 有这样的可能吗?
I am trying to find out how to show text outline by using of swt graphics.
More precisely I need to write code which shows text in following way:
http://java.sun.com/developer/onlineTraining/Media/2DText/Art/StarryShape.gif
I found following code and I'd like to translate it from awt to 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);
(code from java.sun.com/developer/onlineTraining/Media/2DText/style.html )
But I can't figure out how to get Outline of the TextLayout in swt.
Is there such possibility?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以使用 SWT 中的 Path 类来完成此操作。例如:
上面的代码不是您发布的 Swing 代码片段的精确翻译,但意图是相同的。
另请检查此链接:http://www.eclipse.org/swt/snippets/
特别路径和模式部分。
希望这会有所帮助。
Well there is a possibility of doing this using
Path
class in SWT. For example:The above code is not an exact translation of the Swing snippet that you have posted but the intent is same.
Also check this link : http://www.eclipse.org/swt/snippets/
Specially the Path and Pattern section.
Hope this will help.