📄 bhfont.java
字号:
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.util.*;
public class bhFont extends Object
{
Hashtable HashImgFont = new Hashtable();
protected Image font = null;
protected int width;
protected int height;
protected int kern;
protected byte sizes[];
protected int fore;
bhFont(String name, int w, int h, int k, byte fontSizes[], int _fore)
{
System.out.println("Loading bhfont " + name + " : " + _fore);
fore = _fore;
System.gc();
font =(Image)HashImgFont.get(name);
if(font == null){
try { font = Image.createImage(name); } catch(Exception e){ }
HashImgFont.put(name, font);
}
width = w;
height = h;
kern = k;
sizes = fontSizes;
return;
}
public static void Touch()
{
}
private int getIndex(int c)
{
if(c >= '!' && c <= 'Z')
return(c - '!');
else if(c >= 'a' && c <= 'z')
return(58 + c - 'a');
else
return - 1;
}
public int getHeight()
{
return height;
}
public int getWidth()
{
return width;
}
public int getKern()
{
return kern;
}
public int getCharWidth(int c)
{
if(32 == c)
return(kern +(width >> 1));
int index = getIndex(c);
if(- 1 == index)
return 0;
return kern + sizes[index];
}
public int getStringWidth(String text, int len)
{
int width = 0;
if(- 1 == len)
len = text.length();
for(int i = 0; i < len; i++)
width += getCharWidth(text.charAt(i));
return width;
}
public int getStringWidthNew(String text, int len)
{
return smallFont.stringWidth(text);
}
Font smallFont=Font.getFont(Font.FACE_SYSTEM,Font.STYLE_PLAIN,Font.SIZE_SMALL);
public int stringChar(Graphics g, int x, int y, String text, int len, int flags)
{
if(null == font)
return 0;
int fieldWidth = 0;
int strlength = len;
int txtlength = text.length();
if(- 1 == len || 0 !=(0x01 & flags)|| strlength > txtlength)
strlength = txtlength;
if(0 !=(0x01 & flags))
{
fieldWidth = len;
}
else if(0 !=(flags &(0x02 | 0x04)))
{
fieldWidth = getStringWidthNew(text, strlength);
}
if(0 !=(flags & 0x02))
x -= fieldWidth / 2;
else if(0 !=(flags & 0x04))
x -= fieldWidth;
int fntHgt = height;
if(0 !=(flags & 0x08))
y -= fntHgt / 2;
else if(0 !=(flags & 0x10))
y -= fntHgt;
int xstart = x;
int cx = g.getClipX();
int cy = g.getClipY();
int dx = g.getClipWidth();
int dy = g.getClipHeight();
/* for(int i = 0; i < strlength; i++)
{
int letter = text.charAt(i);
int index = getIndex(letter);
if(- 1 == index)
{
if(32 == letter)
x +=(kern +(width >> 1));
continue;
}
g.setClip(cx, cy, dx, dy);
g.clipRect(x, y, sizes[index], height);
g.drawImage(font, x -(width *(index % 28)), y -(height *(index / 28)), Graphics.LEFT | Graphics.TOP);
x +=(kern + sizes[index]);
}*/
g.setFont(smallFont);
g.setColor(0xFFFFFF);
g.drawString(text, x, y , Graphics.LEFT | Graphics.TOP);
g.setClip(cx, cy, dx, dy);
int lenused =(x - xstart);
return lenused;
}
boolean isColor(int _fore)
{
return(fore == _fore);
}
public int stringCharNew(Graphics g, int x, int y, String text, int len, int flags)
{
if(null == font)
return 0;
int fieldWidth = 0;
int strlength = len;
int txtlength = text.length();
if(- 1 == len || 0 !=(0x01 & flags)|| strlength > txtlength)
strlength = txtlength;
if(0 !=(0x01 & flags))
{
fieldWidth = len;
}
else if(0 !=(flags &(0x02 | 0x04)))
{
fieldWidth = getStringWidth(text, strlength);
}
if(0 !=(flags & 0x02))
x -= fieldWidth / 2;
else if(0 !=(flags & 0x04))
x -= fieldWidth;
int fntHgt = height;
if(0 !=(flags & 0x08))
y -= fntHgt / 2;
else if(0 !=(flags & 0x10))
y -= fntHgt;
int xstart = x;
int cx = g.getClipX();
int cy = g.getClipY();
int dx = g.getClipWidth();
int dy = g.getClipHeight();
for(int i = 0; i < strlength; i++)
{
int letter = text.charAt(i);
int index = getIndex(letter);
if(- 1 == index)
{
if(32 == letter)
x +=(kern +(width >> 1));
continue;
}
g.setClip(cx, cy, dx, dy);
g.clipRect(x, y, sizes[index], height);
g.drawImage(font, x -(width *(index % 28)), y -(height *(index / 28)), Graphics.LEFT | Graphics.TOP);
x +=(kern + sizes[index]);
}
g.setClip(cx, cy, dx, dy);
int lenused =(x - xstart);
return lenused;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -