使用强制等宽终端字体 Java AWT

发布于 2024-11-30 02:33:51 字数 576 浏览 2 评论 0 原文

我想使用 Terminal 界面来显示程序中读入的字符串(在 Windows 上,平台独立性并不重要)。

如果我使用 Font font = Font.decode("Terminal-10"); 它不是等宽的。

如果我使用 Font font = new Font(Font.MONOSPACED, Font.PLAIN, 11); 一切都很好,但看起来像 Courier。

如果我使用(可能是我误解了 API 文档),

HashMap attr = new HashMap<TextAttribute,TextAttribute>();
attr.put("FAMILY", Font.MONOSPACED);
attr.put("FONT", Font.decode("Terminal-10"));

font = new Font(attr);

它只是使用默认值(一些 12 点普通字体)。如何正确设置终端字体的属性?我正在 Graphics2D 上绘制字符串,并使用 ImageIO 保存它们。

I want to use Terminal face to display read-in strings in my program (on Windows, platform independence not important).

If I use Font font = Font.decode("Terminal-10"); It is not monospaced.

IF I use Font font = new Font(Font.MONOSPACED, Font.PLAIN, 11); All is well but it looks like Courier.

If I use (probably Im misinterpreting the API docs)

HashMap attr = new HashMap<TextAttribute,TextAttribute>();
attr.put("FAMILY", Font.MONOSPACED);
attr.put("FONT", Font.decode("Terminal-10"));

font = new Font(attr);

it's just using default values (some 12 point plain font). How to properly set attributes to a Terminal font? I'm drawing strings on a Graphics2D and saving them with ImageIO.

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

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

发布评论

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

评论(1

千仐 2024-12-07 02:33:52

看起来 Java AWT 根本不支持位图字体 - 从我在 Font 类 - 它仅处理 TRUETYPE_FONTTYPE1_FONT。 Terminal 是一种位图字体,因此没有简单的方法可以使用 AWT 的字体机制来使用它。

我目前正在尝试通过滚动我自己的简单位图字体引擎来解决类似的问题,但在 这个问题

Looks like you Java AWT doesn't support bitmap fonts at all - judging from what I see in Font class - it handles only TRUETYPE_FONT and TYPE1_FONT. Terminal is a bitmap font, so there's no easy way to use it using AWT's Font machinery.

I'm currently trying to solve a similar problem with rolling my own simple bitmap font engine with limited success in this question.

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