1 package telnet; 2 3 import java.io.*; 4 import javax.microedition.lcdui.*; 5 6 /* This file is part of "Telnet Floyd". 7 * 8 * (c) Radek Polak 2003-2004. All Rights Reserved. 9 * 10 * Please visit project homepage at http://phoenix.inf.upol.cz/~polakr 11 * 12 * --LICENSE NOTICE-- 13 * This program is free software; you can redistribute it and/or 14 * modify it under the terms of the GNU General Public License 15 * as published by the Free Software Foundation; either version 2 16 * of the License, or (at your option) any later version. 17 * 18 * This program is distributed in the hope that it will be useful, 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 * GNU General Public License for more details. 22 * 23 * You should have received a copy of the GNU General Public License 24 * along with this program; if not, write to the Free Software 25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 26 * --LICENSE NOTICE-- 27 * 28 */ 29 30 31 /** 32 * You can draw characters using this class. 33 * Character size is 3x5 resp. 4x6 when taking into a count spaces between them. 34 */ 35 36 public class DrawFont { 37 38 public final int width =4; 39 public final int height = 6; 40 41 public int[][] data = new int[128][]; 42 43 public DrawFont() { 44 try { 45 InputStream in = getClass().getResourceAsStream("font"); 46 for (int i = 33; i < 128; i++) { 47 int b = in.read(); 48 int l = ( b & 3 ) + 2; // length could be 1,2,3 or 4; this is len+1 49 data[i] = new int[l]; // one more for template 50 data[i][0] = (b >> 2)-32; // draw this template 51 // System.out.println("--- ascii "+i +"---" ); 52 // System.out.println("header "+b ); 53 // System.out.println("len "+(l-1) ); 54 // System.out.println("template "+ data[i][0] ); 55 for( int j=1; j<l; j++ ) 56 { 57 data[i][j] = in.read(); 58 // System.out.println("data["+j+"]" + data[i][j] ); 59 } 60 } 61 in.close(); 62 } 63 catch( Exception e ) 64 { 65 e.printStackTrace(); 66 } 67 } 68 69 public void drawChars( Graphics g, char[] chars, int offset, int length, int x, int y ) 70 { 71 for( int i=offset; i<offset+length; i++ ) 72 { 73 drawChar(g, chars[i], x, y); 74 x += width; 75 } 76 } 77 78 public void drawChar( Graphics g, char c, int x, int y ) 79 { 80 if( data[c] == null ) return; 81 for( int j=1; j<data[c].length; j++ ) 82 { 83 int x1 = data[c][j] & 3; 84 int y1 = ( data[c][j] & 12 ) >> 2; 85 int x2 = ( data[c][j] & 48 ) >> 4; 86 int y2 = ( data[c][j] & 192 ) >> 6; 87 88 if( x1 == 3 ) 89 { 90 x1 = y1; 91 y1 = 4; 92 } 93 94 if( x2 == 3 ) 95 { 96 x2 = y2; 97 y2 = 4; 98 } 99 100 // System.out.println( "char " + c + " x1=" + x1 + " y1="+ (4-y1) +" x2=" + x2 + " y2="+ (4-y2)); 101 102 g.drawLine( x+x1, y+y1, x+x2, y+y2 ); 103 } 104 if( data[c][0] != 0 ) 105 drawChar( g, (char)(c+data[c][0]), x, y ); // draw template 106 } 107 108 } |