Removal of swing imageio for reading font, also switching to use a PNG file because it is slightly smaller.

This commit is contained in:
Brendan Robert 2015-08-11 21:05:23 -05:00
parent 175484b4b3
commit 4f4febc16b

View File

@ -18,19 +18,22 @@
*/ */
package jace.core; package jace.core;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import javax.imageio.ImageIO; import javafx.scene.image.Image;
import javafx.scene.image.PixelReader;
import javafx.scene.paint.Color;
/** /**
* Represents the Apple ][ character font used in text modes. * Represents the Apple ][ character font used in text modes. Created on January
* Created on January 16, 2007, 8:16 PM * 16, 2007, 8:16 PM
* @author Brendan Robert (BLuRry) brendan.robert@gmail.com *
* @author Brendan Robert (BLuRry) brendan.robert@gmail.com
*/ */
public class Font { public class Font {
static public int[][] font; static public int[][] font;
static public boolean initialized = false; static public boolean initialized = false;
static public int getByte(int c, int yOffset) { static public int getByte(int c, int yOffset) {
if (!initialized) { if (!initialized) {
initalize(); initalize();
@ -39,32 +42,33 @@ public class Font {
} }
private static void initalize() { private static void initalize() {
font = new int[256][8];
initialized = true; initialized = true;
try { font = new int[256][8];
InputStream in = ClassLoader.getSystemResourceAsStream("jace/data/font.gif"); Thread fontLoader = new Thread(() -> {
BufferedImage fontImage = ImageIO.read(in); InputStream in = ClassLoader.getSystemResourceAsStream("jace/data/font.png");
for (int i=0; i < 256; i++) { Image image = new Image(in);
int x = (i >> 4)*13 + 2; PixelReader reader = image.getPixelReader();
int y = (i & 15)*13 + 4; for (int i = 0; i < 256; i++) {
for (int j=0; j < 8; j++) { int x = (i >> 4) * 13 + 2;
int y = (i & 15) * 13 + 4;
for (int j = 0; j < 8; j++) {
int row = 0; int row = 0;
for (int k=0; k < 7; k++) { for (int k = 0; k < 7; k++) {
int color = fontImage.getRGB((7-k)+x, j+y); Color color = reader.getColor((7 - k) + x, j + y);
row = (row<<1) | (1-(color&1)); boolean on = color.getRed() != 0;
// row = (row<<1) | (color&1); row = (row << 1) | (on ? 0 : 1);
} }
font[i][j]=row; font[i][j] = row;
} }
} }
} catch (IOException ex) { });
ex.printStackTrace(); fontLoader.start();
}
} }
/**
/** Creates a new instance of Font */ * Creates a new instance of Font
*/
private Font() { private Font() {
} }
} }