注册字体正在破坏.TTF文件 [英] Register font is corrupting .TTF file

查看:609
本文介绍了注册字体正在破坏.TTF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的系统上,我需要注册两个外部字体.TTF文件:

On my system I need to register two external font .TTF files:

HamletOrNot.ttf (74 KB)
MorrisRoman-Black.ttf (67 KB)

在创建Font()对象之前,我记录使用以下命令:

Before creating the Font() objects, I record with the following commands:

/* 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()因为格式不同):

Then I create the objects (I create more than one Font () because the formatting is different):

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),因此:

Ok, system works normally. The problem is that after running, the .TTF files change size (to 83 KB and 80 KB), thus:

HamletOrNot.ttf (83 KB)
MorrisRoman-Black.ttf (80 KB)

然后当我第二次运行系统,发生以下错误:

Then when I go to run the system for the second time, the following error occurs:

...
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

如果我更换.TTF文件由原始文件(74 KB和67 KB)改变大小(83 KB和80 KB),程序正常运行。

If I replace the .TTF files with changed size (83 KB and 80 KB) by the original (with 74 KB and 67 KB), the program works normally.

我做错了什么?我以为我必须用applicationContext.getResource()关闭打开的文件,但不知道怎么做。我不知道如何解决它。

What am I doing wrong? I thought I'd have to close open files with applicationContext.getResource(), but do not know how to do this. I do not know how to solve it.

注意:我得到了Spring的applicationContext。原始TTF文件(具有正确的大小)位于项目的资源文件夹中,而TTF错误文件位于目标资源文件夹中(使用Maven完成构建)。

Note: I get the applicationContext of the Spring. Original TTF files (with correct sizes) are in the resources folder of the project, while TTF bad files are in the target resource folder (the build is done with Maven).

帮助我...

编辑:

我怀疑maven正在破坏文件。为什么?我正在使用Eclipse和Maven插件。每当我进行部署或按F5刷新项目时,目标文件夹中的.TTF文件都会损坏。

I'm suspicious that maven is corrupting the files. Why? I'm using Eclipse with the Maven plugin. Whenever I do a deploy or press F5 to refresh the project, .TTF files from target folder become corrupted.

有没有人看过maven损坏的资源文件?

Has anyone seen the maven corrupt resource files?

谢谢

推荐答案

找到它!在执行部署代码时,maven正在破坏.TTF文件。
要修复,您需要在pom.xml(maven-resources-plugin)中添加不会通过nonFilteredFileExtension命令过滤的扩展名。

Found it! The maven was corrupting .TTF files when doing the deploy code. To fix, you need to add the extensions that will not be filtered through nonFilteredFileExtension command in pom.xml (maven-resources-plugin).

<plugin>
  <artifactId>maven-resources-plugin</artifactId>
  <version>2.5</version>
  <configuration>
    <encoding>UTF-8</encoding>
    <nonFilteredFileExtensions>
      <nonFilteredFileExtension>ttf</nonFilteredFileExtension>
    </nonFilteredFileExtensions>
  </configuration>
</plugin>

谢谢!
xD,......很幸运!

Thank you! xD, ... was lucky!

这篇关于注册字体正在破坏.TTF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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