📄 doscharpainter.java
字号:
package china.DosFonts;
import java.awt.*;
import java.awt.image.*;
import java.io.*;
public class DosCharPainter
{
static boolean fontsLoaded=false;
static byte[] ASCdots=new byte[256*16];
static byte[] GBdots=new byte[94*87*32];
static byte[] GBFdots=new byte[94*87*32];
static final Color defaultForground=Color.black,
defaultBackground=Color.white;
static//preload fonts file into memory
{
try
{
RandomAccessFile tempFile=new
RandomAccessFile("font16","r");
tempFile.readFully(ASCdots,0,256*16);
tempFile.readFully(GBdots,0,8178*32);
tempFile.readFully(GBFdots,0,8178*32);
tempFile.close();
fontsLoaded=true;
}
catch(IOException e){}
}
public static void load(){}//to load the class into memory
private static void drawAscanLine(Graphics g, int x, int y,int dot,
int width,int mask)
{
int startX=0;
boolean start=false;
for(int i=0;i<width;i++)
{
if((dot&mask)!=0)
{
if(!start)
{
startX=i;
start=true;
}
}
else if(start)
{
start=false;
g.fillRect(x+startX,y,i-startX,1);
}
dot=dot<<1;
}
if(start)
{
g.fillRect(x+startX,y,width-startX,1);
}
}
public static void drawASC(Graphics g, int x, int y, char asciiCode,
Color forground, Color background)
{
int dot;
int tempCode;
Color original;
if(fontsLoaded==false)
return;
tempCode=asciiCode&0xff;
original=g.getColor();
g.setColor(background);
g.fillRect(x,y,8,16);
g.setColor(forground);
for(int i=0;i<16;i++)
{
dot=ASCdots[tempCode*16+i];
drawAscanLine(g,x,y+i,dot,8,0x80);
}
g.setColor(original);
}
public static void drawGB(Graphics g, int x, int y, char areaCode,
Color forground, Color background)
{
int gbCode,highByte,lowByte;
int dot;
Color original;
if(fontsLoaded==false)
return;
highByte=(areaCode>>8)&0xff;
lowByte=areaCode&0xff;
if( highByte<161 || lowByte<161 ||
highByte>=161+87 || lowByte>=161+94 )
{
drawASC(g,x,y,(char)highByte,forground,background);
drawASC(g,x+8,y,(char)highByte,forground,background);
return;
}
gbCode=(highByte-161)*94+lowByte-161;
original=g.getColor();
g.setColor(background);
g.fillRect(x,y,16,16);
g.setColor(forground);
for(int i=0;i<16;i++)
{
dot=GBdots[gbCode*32+2*i]*256+
(GBdots[gbCode*32+2*i+1]&0xff);
drawAscanLine(g,x,y+i,dot,16,0x8000);
}
g.setColor(original);
}
public static void drawGBF(Graphics g, int x, int y, char areaCode,
Color forground, Color background)
{
int gbCode,highByte,lowByte;
int dot;
Color original;
if(fontsLoaded==false)
return;
highByte=(areaCode>>8)&0xff;
lowByte=areaCode&0xff;
if( highByte<161 || lowByte<161 ||
highByte>=161+87 || lowByte>=161+94 )
{
drawASC(g,x,y,(char)highByte,forground,background);
drawASC(g,x+8,y,(char)highByte,forground,background);
return;
}
gbCode=(highByte-161)*94+lowByte-161;
original=g.getColor();
g.setColor(background);
g.fillRect(x,y,16,16);
g.setColor(forground);
for(int i=0;i<16;i++)
{
dot=GBFdots[gbCode*32+2*i]*256+
(GBFdots[gbCode*32+2*i+1]&0xff);
drawAscanLine(g,x,y+i,dot,16,0x8000);
}
g.setColor(original);
}
public static void drawASCstring(Graphics g, int x, int y,
String string)
{
drawASCstring(g,x,y,string,
defaultForground,defaultBackground);
}
public static void drawASCstring(
Graphics g, int x, int y, String string,
Color forground, Color background)
{
for(int i=0;i<string.length();i++)
{
drawASC(g,x+i*8,y,string.charAt(i),
forground,background);
}
}
public static void drawGBstring(Graphics g, int x, int y,
String string)
{
drawGBstring(g,x,y,string,defaultForground,
defaultBackground,true);
}
public static void drawGBstring(
Graphics g, int x, int y, String string,
Color forground, Color background)
{
drawGBstring(g,x,y,string,forground,background,true);
}
public static void drawGBstring(Graphics g, int x, int y,
String string,boolean simplify)
{
drawGBstring(g,x,y,string,
defaultForground,defaultBackground,simplify);
}
public static void drawGBstring(
Graphics g, int x, int y, String string,
Color forground, Color background,boolean simplify)
{
char tempChar;
for(int i=0;i<string.length();i++)
{
tempChar=string.charAt(i);
if(tempChar<161 ||
tempChar>=161+87 || i>=string.length()-1)
drawASC(g,x+i*8,y,tempChar,
forground,background);
else
{
tempChar=(char)(
tempChar*256+string.charAt(i+1) );
if(simplify)
drawGB(g,x+i*8,y,
tempChar,forground,background);
else
drawGBF(g,x+i*8,y,
tempChar,forground,background);
i++;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -