Registration Font Distorts .TTF File

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:

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

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

+6
java true-type-fonts
source share
2 answers

Found! When executing the deployment code, maven distorted .TTF files. To fix this, you need to add extensions that will not be filtered by the 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> 

Thanks! xD ... lucky!

+24
source share
  <resources> <resource> <directory>src/main/resources</directory> <includes> <include>**/*</include> </includes> <excludes> <exclude>**/xyz.properties</exclude> <exclude>**/ehcache-myApp.xml</exclude> <exclude>**/log4j-myApp.xml</exclude> <exclude>**/*.ttf</exclude> </excludes> <filtering>true</filtering> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.ttf</include> </includes> </resource> </resources> 

I broke fonts when copying resources, but font file sizes change and, therefore, get corrupted. This is fixed below for Maven 3.0.4 and maven-resources-plugin 3.0.1.

  <plugins> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>3.0.1</version> <configuration> <encoding>UTF-8</encoding> <nonFilteredFileExtensions> <nonFilteredFileExtension>ttf</nonFilteredFileExtension> </nonFilteredFileExtensions> </configuration> </plugin> 
0
source share

All Articles