embedding a font in Java

此生再无相见时 提交于 2019-12-28 13:34:13

问题


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);

回答1:


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 calling registerFont(Font).



来源:https://stackoverflow.com/questions/4487871/embedding-a-font-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!