On my system, I need to register two external .TTF font files:
HamletOrNot.ttf (74 KB) MorrisRoman-Black.ttf (67 KB)
Before creating Font () objects, I write the following commands:
String path = filesPath + fileName; Resource resource = applicationContext.getResource( path ); File fontFile = resource.getFile(); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, fontFile ));
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 );
Ok, the system is working fine. The problem is that after starting .TTF files change size (up to 83 KB and 80 KB), thus:
HamletOrNot.ttf (83 KB) MorrisRoman-Black.ttf (80 KB)
Then, when I start the system a 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
If I replace the resized .TTF files (83 KB and 80 KB) with the original (with 74 KB and 67 KB), the program works fine.
What am I doing wrong? I thought I would have to close open files with applicationContext.getResource (), but I don't know how to do this. I do not know how to solve it.
Note. I get applicationContext Spring. The source TTF files (with the correct sizes) are in the project resources folder, while the files with the TTF code are in the target resource folder (assembly is done using Maven).
Help me...
EDIT:
I suspect maven is distorting files. What for? I am using Eclipse with the Maven plugin. Whenever I deploy or press F5 to update a project, the .TTF files from the destination folder get corrupted.
Has anyone seen maven's corrupt resource files?
thanks