在Java中嵌入字体 [英] embedding a font in Java
问题描述
我有一个自定义字体,我想在Java程序中炫耀,用户无需安装就可以查看它。有人知道怎么做吗?
工作解决方案
我已经实现了以下内容:
font = java.awt.Font.createFont(java.awt.Font.TRUETYPE_FONT,new的java.io.File(Clazz.class.getResource( /资源/ segoescb.ttf)toURI()。));
font = font.deriveFont(11.0F);
我从来没有这样做,但似乎您需要的方法是
导入字体
字体createFont(int fontFormat,InputStream fontStream)
或者
字体createFont(int fontFormat,File fontFile)
int
参数是 Font.TRUETYPE_FONT
或 Font.TYPE1_FONT
,w hile InputStream
或 File
参数包含字体的二进制数据。
导入后使用字体:
为了使Font可用于Font构造函数,返回的Font必须通过调用 GraphicsEnviroment 中进行注册#registerFont%28java.awt.Font%29rel =noreferrer>
registerFont(Font)
。
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?
working solution
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
Importing the Font
Font createFont(int fontFormat, InputStream fontStream)
or alternatively
Font createFont(int fontFormat, File fontFile)
The int
parameter is either Font.TRUETYPE_FONT
or Font.TYPE1_FONT
, while the InputStream
or File
parameter contains the font's binary data.
Using the Font after import:
To make the Font available to Font constructors the returned Font must be registered in the
GraphicsEnviroment
by callingregisterFont(Font)
.
这篇关于在Java中嵌入字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!