在 Java 中嵌入字体 [英] embedding a font in Java

查看:27
本文介绍了在 Java 中嵌入字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义字体,我想在 Java 程序中展示它,用户可以在其中查看它而无需安装它.有人知道怎么做吗?

I have a custom font I want to show off in a Java program where the user can view it without having to install it. Does anyone know how to do that?

我已经实现了以下内容:

I have implemented the following:

font = java.awt.Font.createFont(java.awt.Font.TRUETYPE_FONT, new java.io.File(Clazz.class.getResource("/resources/segoescb.ttf").toURI()));
font = font.deriveFont(11.0F);

推荐答案

我没做过,不过貌似你要的方法是

I have never done it, but it seems like the methods you want are

导入字体

Font createFont(int fontFormat, InputStream fontStream)

或者替代

Font createFont(int fontFormat, File fontFile)

int 参数是 Font.TRUETYPE_FONTFont.TYPE1_FONT,而 InputStreamFile 参数包含字体的二进制数据.

The int parameter is either Font.TRUETYPE_FONT or Font.TYPE1_FONT, while the InputStream or File parameter contains the font's binary data.

导入后使用字体:

要使 Font 可用于 Font 构造函数,必须通过调用 registerFont(Font).

To make the Font available to Font constructors the returned Font must be registered in the GraphicsEnviroment by calling registerFont(Font).

这篇关于在 Java 中嵌入字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆