在我的系统上,我需要注册两个外部字体.TTF文件:
HamletOrNot.ttf (74 KB)
MorrisRoman-Black.ttf (67 KB)
在创建Font()对象之前,我使用以下命令进行记录:
/* Set full path of font */
String path = filesPath + fileName;
/* Read file */
Resource resource = applicationContext.getResource( path );
File fontFile = resource.getFile();
/* Load font */
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, fontFile ));
然后创建对象(由于格式不同,我创建了多个Font()):
Font font = new Font( "HamletOrNot" , Font.TRUETYPE_FONT , 10 );
Font font = new Font( "HamletOrNot" , Font.TRUETYPE_FONT , 12 );
Font font = new Font( "MorrisRoman-Black" , Font.TRUETYPE_FONT , 20 );
Font font = new Font( "MorrisRoman-Black" , Font.TRUETYPE_FONT , 22 );
好的,系统正常工作。问题在于,运行后,.TTF文件会更改大小(分别为83 KB和80 KB),从而:
HamletOrNot.ttf (83 KB)
MorrisRoman-Black.ttf (80 KB)
然后,当我第二次运行系统时,发生以下错误:
...
Caused by: java.awt.FontFormatException: bad table, tag=1280594760
at sun.font.TrueTypeFont.init(TrueTypeFont.java:513)
at sun.font.TrueTypeFont.<init>(TrueTypeFont.java:162)
at sun.font.FontManager.createFont2D(FontManager.java:2474)
at java.awt.Font.<init>(Font.java:570)
at java.awt.Font.createFont(Font.java:980)
at br.com.linu.vectortown.base.screen.font.GameFontFactory.postConstruct(GameFontFactory.java:43)
at br.com.linu.vectortown.base.screen.font.GameFontContainer.postConstruct(GameFontContainer.java:27)
at br.com.linu.vectortown.client.looping.util.AutomaticInjector.postConstruct(AutomaticInjector.java:47)
... 99 more
如果我将更改后的大小(83 KB和80 KB)的.TTF文件替换为原始文件(74 KB和67 KB),则程序可以正常工作。
我究竟做错了什么?我以为我必须使用applicationContext.getResource()关闭打开的文件,但不知道该怎么做。我不知道该怎么解决。
注意:我得到了Spring的applicationContext。原始的TTF文件(具有正确的大小)位于项目的资源文件夹中,而TTF损坏的文件位于目标资源文件夹中(使用Maven完成构建)。
帮我...
编辑:
我怀疑Maven破坏了文件。为什么?我正在使用带有Maven插件的Eclipse。每当我执行部署或按F5刷新项目时,目标文件夹中的.TTF文件都会损坏。
有人见过Maven损坏的资源文件吗?
谢谢
找到了!专家在执行部署代码时损坏了.TTF文件。要解决此问题,您需要在pom.xml(maven-resources-plugin)中添加不会通过nonFilteredFileExtension命令过滤的扩展名。
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>ttf</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
谢谢!xD,...很幸运!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句