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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
| /* new add by Late Lee 2011-05-30*/ //#define HZK24 #ifdef HZK24 /* 24 */ #include "ascii24.h" #define ASCII_CODE ascii24 #define FONT_SIZE 24 /* size: 24 */ #else /* 16 */ #include "ascii16.h" #define ASCII_CODE ascii16 #define FONT_SIZE 16 /* size: 16 */ #endif
#define BYTES (FONT_SIZE/8) /* for HZ: 3 bytes 2 bytes*/ #define BUF_SIZE (BYTES * FONT_SIZE) /* HZ buff 3*24 = 72 bytes 2*16 = 32 bytes */
#define ASCII_BYTES (BYTES-1) /* 2 1*/ #define ASCII_SIZE (FONT_SIZE * ASCII_BYTES) /* ASCII buffer: 24*2 = 48 bytes 16 * 1 = 16 bytes */ #define ASCII_WIDTH (FONT_SIZE/2) /* ASCII: 16*8 24*12 */
/* end here Late Lee*/
/***************************************************************************** * new add by Late Lee 2011-05-30 *****************************************************************************/
/** * __display_ascii - Display an ASCII code on touch screen * @x: Column * @y: Row * @ascii: Which ASCII code to display * @colidx: Color index(?) * This routine display an ASCII code that stored in an array(eg, ASCII_CODE). * 16x8 ASCII code takes 1 byte, 24*12 ASCII code takes 2 bytes, so we need * -ASCII_BYTES-. */ static void __display_ascii(int x, int y, char *ascii, unsigned colidx) { int i, j, k; unsigned char *p_ascii; int offset; offset = (*ascii - 0x20 ) * ASCII_SIZE; /* find the code in the array */ p_ascii = ASCII_CODE + offset;
for(i=0;i<FONT_SIZE;i++) for(j=0;j<ASCII_BYTES;j++) for(k=0;k<8;k++) if( p_ascii[i*ASCII_BYTES+j] & (0x80>>k) ) //if(*( p_ascii + i*ASCII_BYTES+j) & (0x80>>k)) pixel (x + j*8 + k, y + i, colidx); }
/** * put_string_ascii - Display an ASCII string on touch screen * @x: Column * @y: Row * @s: Which string to display * @colidx: Color index */ void put_string_ascii(int x, int y, char *s, unsigned colidx) { while (*s != 0) { __display_ascii(x, y, s, colidx); x += ASCII_WIDTH; s++; } }
/* not test */ void put_string_center_ascii(int x, int y, char *s, unsigned colidx) { size_t sl = strlen (s); put_string_ascii (x - (sl / 2) * ASCII_WIDTH, y - FONT_SIZE / 2, s, colidx); }
/** * __display_font_16 - Display a 16x16 (chinese) character on touch screen * @fp: File pointer points to HZK(ie, HZK16) * @x: Column * @y: Row * @font: Which (chinese) character to display * @colidx: Color index * This routine ONLY display 16*16 character. * Every character takes two bytes, we show the first 8 bits, then the second 8 bits, * then the whole world will be shown before us. */ static void __display_font_16 (FILE *fp, int x, int y, unsigned char *font, unsigned colidx) { int i, j, k; unsigned char mat[BUF_SIZE]={0}; int qh,wh; unsigned long offset; qh = *font - 0xa0; wh = *(font+1) - 0xa0; offset = ( 94*(qh-1) + (wh-1) ) * BUF_SIZE; /* offset of the character in HZK */
/* read it */ fseek(fp,offset,SEEK_SET); fread(mat,BUF_SIZE,1,fp);
/* show it */ for(i=0;i<FONT_SIZE;i++) for(j=0;j<BYTES;j++) for(k=0;k<8;k++) if(mat [i*BYTES+j] & (0x80>>k)) pixel (x + j*8 + k, y + i, colidx); }
/** * __display_font_24 - Display a 24x24 (chinese) character on touch screen * @fp: File pointer points to HZK(ie, HZK24) * @x: Column * @y: Row * @font: Which (chinese) character to display * @colidx: Color index */ static void __display_font_24 (FILE *fp, int x, int y, unsigned char *font, unsigned colidx) { unsigned int i, j; unsigned char mat[FONT_SIZE][BYTES]={{0}}; int qh,wh; unsigned long offset; qh = *font - 0xaf; wh = *(font+1) - 0xa0; offset = ( 94*(qh-1) + (wh-1) ) * BUF_SIZE;
fseek(fp,offset,SEEK_SET); fread(mat,BUF_SIZE,1,fp);
for(i=0;i<FONT_SIZE;i++) for(j=0;j<FONT_SIZE;j++) if( mat[j][i>>3] & (0x80>>(i&7)) ) // if ( mat[j][i/8] & (0x80>>i%8) ) /* org */ pixel (x + j, y + i, colidx); }
/** * put_string_hz - Display a (chinese) character string on touch screen * @fp: File pointer points to HZK(ie, HZK24 or HZK16) * @x: Column * @y: Row * @s: Which string to display(must be 'unsigned char*') * @colidx: Color index */ void put_string_hz (FILE *fp, int x, int y, unsigned char *s, unsigned colidx) { while (*s != 0) { #ifdef HZK24 __display_font_24 (fp, x, y, s, colidx); /* for HZK24 */ #else __display_font_16 (fp, x, y, s, colidx); #endif x += FONT_SIZE; s += 2; /* 2 bytes */ } }
/* not test */ void put_string_center_hz (FILE *fp, int x, int y, unsigned char *s, unsigned colidx) { size_t sl = strlen ((char *)s); put_string_hz (fp, x - (sl/2) * FONT_SIZE, y - FONT_SIZE/2, s, colidx); }
/** * put_font - Display an ASCII or/and (chinese) character string on touch screen * @fp: File pointer points to HZK(ie, HZK24 or HZK16) * @x: Column * @y: Row * @s: Which string to display * @colidx: Color index */ void put_font(FILE *fp, int x, int y, unsigned char *s, unsigned colidx) { while (*s != 0) { if ( (*s>0xa0) && (*(s+1)>0xa0) ) { #ifdef HZK24 __display_font_24 (fp, x, y, s, colidx); /* for HZK24 */ #else __display_font_16 (fp, x, y, s, colidx); /* for HZK16 */ #endif x += FONT_SIZE; s += 2; /* 2 bytes */ } else { __display_ascii (x, y, (char *)s, colidx); x += ASCII_WIDTH; s++; /* 1 byte */ } } } /* not test */ void put_font_center(FILE *fp, int x, int y, unsigned char *s, unsigned colidx) { size_t sl = strlen ((char *)s); put_font (fp, x - (sl/2) * 16, y - 16/2, s, colidx); }
|