a jak z wydajnością?
cos w stylu tego? :
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class customfont extends MIDlet {
customfontCanvas m_canvas;
Display disp;
public void startApp() {
disp = Display.getDisplay(this);
m_canvas = new customfontCanvas(this);
disp.setCurrent(m_canvas);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
import javax.microedition.lcdui.*;
import java.util.*;
import java.io.*;
import java.io.InputStreamReader;
public class customfontCanvas extends Canvas implements Runnable {
customfont midlet;
Thread gameThread;
Image font = null;
byte[] charWidth = {
2, 6, 2, 5, 2, 2, 2, 2, 4, 4, 5, 4, 6, 3, 5, 4, 2, 4, 5, 3, 5, 5, 6, 5, 5, 5, 5, 5, 8, 9, 5, 3, 3,
4, 4, 7, 6, 7, 7, 8, 5, 6, 6, 6, 5, 6, 6, 2, 5, 6, 5, 8, 6, 6, 5, 6, 6, 5, 6, 6, 8, 10, 6, 6,
7, 6, 5, 5, 5, 5, 5, 4, 5, 5, 2, 3, 5, 2, 8, 5, 5, 5, 5, 4, 5, 4, 5, 6, 6, 5, 6, 4, 8, 8, 8, 8, 8, 6,
6, 6, 6, 3, 3, 5, 4, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 3, 5, 4, 5, 5, 5,
5, 5, 5, 5, 6, 5, 5, 5, 2, 4, 4, 9, 9,
};
byte[] charHeight = {9, 9, 11, 11, 10, 9, 10, 4, 8, 8, 9, 5, 9, 7, 7, 9, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 11, 9,
11, 11, 11, 11, 9, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
9, 9, 11, 9, 9, 9, 9, 9, 9, 11, 9, 9, 11, 9, 9, 9, 9, 9, 11, 11, 9, 9, 9, 9, 9, 9, 9, 11, 9, 9, 9, 9, 9,
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 12, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
9, 9, 9, 9, 9, 12, 9, 9, 8, 8, 9, 9,
};
short[] fontX = {0, 2, 8, 10, 15, 17, 19, 21, 23, 27, 31, 36, 40, 46, 49, 54, 58, 60, 64, 69, 72, 77, 82, 88, 93, 98, 103, 108, 113, 121, 130, 135, 138, 141, 145, 149,
156, 162, 169, 176, 184, 189, 195, 201, 207, 212, 218, 224, 226, 231, 237, 242, 250, 0, 6, 11, 17, 23, 28, 34, 40, 48, 58, 64, 70, 77, 83, 88, 93, 98,
103, 108, 112, 117, 122, 124, 127, 132, 134, 142, 147, 152, 157, 162, 166, 171, 175, 180, 186, 192, 197, 203, 207, 215, 223, 231, 239, 247, 253,
0, 6, 12, 15, 18, 23, 27, 33, 39, 45, 51, 57, 63, 69, 75, 81, 87, 93, 98, 103, 108, 113, 118, 123, 128, 133, 138, 141, 144, 149, 153, 158, 163, 168,
173, 178, 183, 188, 194, 199, 204, 209, 211, 215, 219, 228
};
short[] fontY = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24
};
String[] hex_value = {"21", "3f", "a1", "bf", "2c", "2e", "3b", "27", "3c", "3e", "23", "2a", "2b", "2d", "3d", "2f", "7c", "5c", "30", "31",
"32", "33", "34", "35", "36", "37", "38", "39", "a9", "40", "df", "5b", "5d", "28", "29", "ac", "24", "26", "25", "41", "42", "43",
"44", "45", "46", "47", "48", "49", "4a", "4b", "4c", "4d", "4e", "4f", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59",
"5a", "5f", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6a", "6b", "6c", "6d", "6e", "6f", "70", "71", "72", "73",
"74", "75", "76", "77", "78", "79", "7a", "c1", "c0", "c2", "c3", "c4", "c9", "c8", "ca", "cb", "cd", "cc", "ce", "cf", "d3", "d2", "d4",
"d5", "d6", "da", "d9", "db", "dc", "c7", "d1", "e1", "e0", "e2", "e3", "e4", "e9", "e8", "ea", "eb", "ed", "ec", "ee", "ef", "f3", "f2", "f4",
"f5", "f6", "fa", "f9", "fb", "fc", "e7", "f1", "3a", "20", "a0", "8c", "9c", "00"
};
int j = 0;
String[] MAIN_MENU = {"kkkkkkkk", "Infotech", "@#$%^&*"};
/**
* constructor
*/
public customfontCanvas(customfont m_Midlet) {
midlet = m_Midlet;
try {
font = Image.createImage("/new_font.png");
gameThread = new Thread(this);
gameThread.start();
} catch (Exception e) {
e.printStackTrace();
}
}
public void run(String s) {
repaint();
// readfile(String s);
}
/**
* paint
*/
public void paint(Graphics g) {
drawMenu(g);
}
public void drawMenu(Graphics g) {
g.setColor(0xffffff);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0);
try {
int y = 50;
for (int i = 0; i <= MAIN_MENU.length; i++) {
drawString1(g, MAIN_MENU[i], getWidth() / 3 - MAIN_MENU[i].length(), y, 0);
y += 20;
}
} catch (Exception e) {
System.out.println("error ");
}
}
void drawString1(Graphics g, String s, int xPos, int yPos, int anc) {
String s1 = new String(s);
System.out.println(s1);
// short word;
try {
for (int i = 0; i < s1.length(); i++) {
// get current character
char c = s1.charAt(i);
System.out.println("c -" + c); // kris
// get ordinal value or ASCII equivalent
int cIndex = (int) c;
System.out.println("cIndex -" + cIndex);
String hex = Integer.toHexString(cIndex);
System.out.println("hex- " + hex);
for (j = hex_value.length - 1; j >= 0; j--) {
if (hex_value[j].equals(hex)) {
System.out.println("j-" + j);
if (cIndex >= 33 && cIndex <= 255) {
int w1 = charWidth[cIndex - 33];
System.out.println("charwidth-" + w1);
int w2 = charHeight[(cIndex - 33)];
System.out.println("charheight-" + w2);
setImage(g, xPos, yPos, font, fontX[(j)], fontY[(j)], charWidth[(j)], charHeight[(j)], 0);
System.out.println("fontX[j+1]= " + fontX[j + 1]);
xPos += charWidth[(j)];
System.out.println("xpos-" + xPos);
//}//for loop krishnan
}
}
}
}
} catch (Exception e) {
System.out.println("error in draw");
}
}
static void setImage(Graphics g, int xPos, int yPos, Image img, int cutX, int cutY, int width, int height, int anc) {
g.setClip(xPos, yPos, width, height);
g.drawImage(img, xPos - cutX, yPos - cutY, 0);
}
public void run() {
}
}