-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileCharset.java
44 lines (40 loc) · 1.08 KB
/
FileCharset.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.io.*;
public class FileCharset extends Charset {
public FileCharset(String name, int size, int width, int height) {
super(size,width,height);
assert(this.getWidth()<=8); // Assume bytes in file.
byte[] cga = new byte[size*this.getHeight()];
FileInputStream in = null;
try {
in = new FileInputStream(name);
for(int i=0; i<size; i++)
in.read(cga,i*this.getHeight(),this.getHeight());
in.close();
}
catch(Exception e) {
System.out.println("[FileCharset] Error loading charset! " + e.getMessage());
e.printStackTrace();
}
for(int id=0;id<size;id++)
{
boolean[] tmpchars = new boolean[this.getCharSize()];
for(int yPos=0; yPos<this.getHeight(); yPos++)
{
int data = 255&(int)cga[id*this.getHeight()+yPos];
for(int pixelPos=this.getWidth();pixelPos>=0;pixelPos--)
{
if((data&1)==1)
tmpchars[yPos*this.getWidth()+pixelPos] = true;
data >>= 1;
}
}
this.setBlockData(id,tmpchars);
}
}
public FileCharset(String name, int size) {
this(name,size,8,8);
}
public FileCharset(String name) {
this(name,256);
}
}