如何在draw2d中给文本加下划线

发布于 2024-08-07 02:47:08 字数 51 浏览 3 评论 0原文

有没有一种简单的方法可以在draw2d中绘制带下划线的文本,而无需在文本下手动绘制线条?

Is there a simple way to draw underlined text in draw2d without manually drawing a line under the text?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼眸里的那抹悲凉 2024-08-14 02:47:08

经过一番研究后,似乎 Draw2D 本身不支持带下划线的文本,因为 SWT 字体是操作系统级别的对象,并且并非 SWT 支持的每个操作系统都支持带下划线的文本。看起来最好的选择是创建一种手动绘制下划线文本的方法。也许稍后会添加到 SWT 中。

这是我最终使用的(或多或少):

private void drawUnderlinedText(GC gc, String string, int x, int y)
{
    Point extent = gc.textExtent(string);
    gc.drawText(string, x, y);
    gc.drawLine(x - 1, y + extent.y - 1, x + extent.x - 1, y + extent.y - 1);
}

After a bit of research, it looks like underlined text isn't supported natively in Draw2D since SWT fonts are OS level objects and not every OS supported by SWT supports underlined text. Looks like the best bet is to create a method that draws underlined text manually. Maybe it's something that will get added into SWT later.

Here's what I ended up using (more or less):

private void drawUnderlinedText(GC gc, String string, int x, int y)
{
    Point extent = gc.textExtent(string);
    gc.drawText(string, x, y);
    gc.drawLine(x - 1, y + extent.y - 1, x + extent.x - 1, y + extent.y - 1);
}
浅黛梨妆こ 2024-08-14 02:47:08

使用带有下划线属性的字体。 Darryl 的 视觉字体设计器 展示了如何使用以下命令创建字体此属性。

Use a Font with an underline attribute. Darryl's Visual Font Designer shows how to create a font with this property.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文