And here is the patch for UnicodeFont:
Code:
Index: src/org/newdawn/slick/UnicodeFont.java
===================================================================
--- src/org/newdawn/slick/UnicodeFont.java (revision 1529)
+++ src/org/newdawn/slick/UnicodeFont.java (working copy)
@@ -1,4 +1,3 @@
-
package org.newdawn.slick;
import java.awt.Font;
@@ -8,6 +7,7 @@
import java.awt.font.GlyphVector;
import java.awt.font.TextAttribute;
import java.io.IOException;
+import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
@@ -51,14 +51,15 @@
/**
* Utility to create a Java font for a TTF file reference
*
+ * @param ttfInputStream The stream with the TrueTypeFont file.
* @param ttfFileRef The file system or classpath location of the TrueTypeFont file.
* @return The font created
* @throws SlickException Indicates a failure to locate or load the font into Java's font
* system.
*/
- private static Font createFont (String ttfFileRef) throws SlickException {
+ private static Font createFont(InputStream ttfInputStream, String ttfFileRef) throws SlickException {
try {
- return Font.createFont(Font.TRUETYPE_FONT, ResourceLoader.getResourceAsStream(ttfFileRef));
+ return Font.createFont(Font.TRUETYPE_FONT, ttfInputStream);
} catch (FontFormatException ex) {
throw new SlickException("Invalid font: " + ttfFileRef, ex);
} catch (IOException ex) {
@@ -144,7 +145,7 @@
public UnicodeFont (String ttfFileRef, String hieroFileRef) throws SlickException {
this(ttfFileRef, new HieroSettings(hieroFileRef));
}
-
+
/**
* Create a new unicode font based on a TTF file and a set of heiro configuration
*
@@ -152,9 +153,20 @@
* @param settings The settings configured via the Hiero tool
* @throws SlickException if the UnicodeFont could not be initialized.
*/
- public UnicodeFont (String ttfFileRef, HieroSettings settings) throws SlickException {
+ public UnicodeFont(String ttfFileRef, HieroSettings settings) throws SlickException {
+ this(ResourceLoader.getResourceAsStream(ttfFileRef), ttfFileRef, settings);
+ }
+
+ /**
+ * Create a new unicode font based on a TTF file and a set of heiro configuration
+ * @param ttfInputStream The stream of the ttf file.
+ * @param ttfFileRef The file system or classpath location of the TrueTypeFont file.
+ * @param settings The settings configured via the Hiero tool
+ * @throws SlickException if the UnicodeFont could not be initialized.
+ */
+ public UnicodeFont(InputStream ttfInputStream, String ttfFileRef, HieroSettings settings) throws SlickException {
this.ttfFileRef = ttfFileRef;
- Font font = createFont(ttfFileRef);
+ Font font = createFont(ttfInputStream, ttfFileRef);
initializeFont(font, settings.getFontSize(), settings.isBold(), settings.isItalic());
loadSettings(settings);
}
@@ -168,9 +180,9 @@
* @param italic True if the font should be rendered in bold typeface
* @throws SlickException if the UnicodeFont could not be initialized.
*/
- public UnicodeFont (String ttfFileRef, int size, boolean bold, boolean italic) throws SlickException {
+ public UnicodeFont(String ttfFileRef, int size, boolean bold, boolean italic) throws SlickException {
this.ttfFileRef = ttfFileRef;
- initializeFont(createFont(ttfFileRef), size, bold, italic);
+ initializeFont(createFont(ResourceLoader.getResourceAsStream(ttfFileRef), ttfFileRef), size, bold, italic);
}
/**
I can see the constructor with hieroFileRef is a bit unnecessary since you have a HieroSettings constructor with a fileRef, so UnicodeFont could be cleaner without having to have HieroSettings constructor knowledge, same thing for java.awt.Font construction, but this is only a suggestion because that would change the API and if someone is using that way now it will break his code.
Well, hope you could take a look at this patch also, however it depends on first patch, and again I kept the string parameter in some cases only because exceptions needed them.
Thanks again.