static int _getIndex(int c){ #define ERRCHR (font->u8FirstChar+1) /* Does this font provide this character? */ if(c<font->u8FirstChar) c=ERRCHR; if(c>font->u8LastChar && efont.type!=FONT_EXTERNAL && font->charExtra == NULL) c=ERRCHR; if(c>font->u8LastChar && (efont.type==FONT_EXTERNAL || font->charExtra != NULL)){ if(efont.type==FONT_EXTERNAL){ _getFontData(SEEK_EXTRAS,0); int cc=0; int cache; while( (cache=_getFontData(GET_EXTRAS,0)) < c) cc++; if( cache > c) c=ERRCHR; else c=font->u8LastChar+cc+1; }else{ int cc=0; while( font->charExtra[cc] < c) cc++; if(font->charExtra[cc] > c) c=ERRCHR; else c=font->u8LastChar+cc+1; }; }; c-=font->u8FirstChar; return c; }
static char gnn(){ // Get next nibble static int byte; int val; if(hilo==1) ctr++; hilo=1-hilo; if(hilo==1){ if(efont.type==FONT_EXTERNAL){ byte=_getFontData(GET_DATA,0); }else{ byte=data[ctr]; }; val=byte>>4; }else{
void setExtFont(const char *fname){ if(strlen(fname)>8+4) return; strcpy(efont.name,fname); efont.type=FONT_EXTERNAL; font=NULL; UINT res; res=f_open(&file, efont.name, FA_OPEN_EXISTING|FA_READ); if(res!=FR_OK){ efont.type=0; font=&Font_7x8; }else{ _getFontData(START_FONT,0); font=&efont.def; }; }
int DoChar(int sx, int sy, int c){ if(font==NULL){ font=&Font_7x8; }; /* how many bytes is it high? */ char height=(font->u8Height-1)/8+1; char hoff=(8-(font->u8Height%8))%8; const uint8_t * data; int width,preblank=0,postblank=0; do { /* Get Character data */ /* Get intex into character list */ c=_getIndex(c); /* starting offset into character source data */ int toff=0; if(font->u8Width==0){ if(efont.type == FONT_EXTERNAL){ _getFontData(SEEK_WIDTH,0); for(int y=0;y<c;y++) toff+=_getFontData(GET_WIDTH,0); width=_getFontData(GET_WIDTH,0); _getFontData(SEEK_DATA,toff); UINT res; UINT readbytes; UINT size = width * height; if(size > MAXCHR) size = MAXCHR; res = f_read(&file, charBuf, size, &readbytes); if(res != FR_OK || readbytes<width*height) return sx; data=charBuf; }else{ for(int y=0;y<c;y++) toff+=font->charInfo[y].widthBits; width=font->charInfo[c].widthBits; toff*=height; data=&font->au8FontTable[toff]; }; postblank=1; }else if(font->u8Width==1){ // NEW CODE if(efont.type == FONT_EXTERNAL){ _getFontData(SEEK_WIDTH,0); for(int y=0;y<c;y++) toff+=_getFontData(GET_WIDTH,0); width=_getFontData(GET_WIDTH,0); _getFontData(SEEK_DATA,toff); UINT res; UINT readbytes; uint8_t testbyte; testbyte = read_byte (); if(testbyte>>4 ==15){ preblank = read_byte (); postblank = read_byte (); width-=3; width/=height; UINT size = width * height; if(size > MAXCHR) size = MAXCHR; res = f_read(&file, charBuf, size, &readbytes); if(res != FR_OK || readbytes<width*height) return sx; data=charBuf; }else{ _getFontData(SEEK_DATA,toff); data=pk_decode(NULL,&width); // Hackety-hack }; }else{ // Find offset and length for our character for(int y=0;y<c;y++) toff+=font->charInfo[y].widthBits; width=font->charInfo[c].widthBits; if(font->au8FontTable[toff]>>4 == 15){ // It's a raw character! preblank = font->au8FontTable[toff+1]; postblank= font->au8FontTable[toff+2]; data=&font->au8FontTable[toff+3]; width=(width-3/height); }else{ data=pk_decode(&font->au8FontTable[toff],&width); } };