2011-05-11 21:18:46 +00:00
|
|
|
#include <sysdefs.h>
|
|
|
|
#include <render.h>
|
2011-05-14 22:56:33 +00:00
|
|
|
#include <decoder.h>
|
2011-05-11 21:18:46 +00:00
|
|
|
#include <fonts.h>
|
|
|
|
|
|
|
|
/* Global Variables */
|
|
|
|
const struct FONT_DEF * font = NULL;
|
|
|
|
char font_direction = FONT_DIR_LTR;
|
|
|
|
|
|
|
|
/* Exported Functions */
|
2011-05-11 23:37:26 +00:00
|
|
|
|
2011-05-22 19:06:45 +00:00
|
|
|
int DoChar(int sx, int sy, int c){
|
2011-05-13 01:19:47 +00:00
|
|
|
int x=0;
|
2011-05-11 23:37:26 +00:00
|
|
|
|
2011-05-12 00:23:07 +00:00
|
|
|
/* how many bytes is it high? */
|
|
|
|
char height=(font->u8Height-1)/8+1;
|
|
|
|
|
2011-05-14 20:21:51 +00:00
|
|
|
const uint8_t * data;
|
|
|
|
|
2011-05-11 23:37:26 +00:00
|
|
|
/* "real" coordinates. Our physical display is upside down */
|
2011-05-11 21:18:46 +00:00
|
|
|
int rx=RESX-sx-1;
|
|
|
|
int ry=RESY-sy-font->u8Height;
|
2011-05-11 23:37:26 +00:00
|
|
|
|
|
|
|
/* Does this font provide this character? */
|
2011-05-22 19:06:45 +00:00
|
|
|
if(c<font->u8FirstChar)
|
2011-05-11 21:18:46 +00:00
|
|
|
c=font->u8FirstChar+1; // error
|
2011-05-22 19:06:45 +00:00
|
|
|
if(c>font->u8LastChar && font->charExtra == NULL)
|
|
|
|
c=font->u8FirstChar+1; // error
|
|
|
|
|
|
|
|
if(c>font->u8LastChar && font->charExtra != NULL){
|
|
|
|
int cc=0;
|
|
|
|
while( font->charExtra[cc] < c)
|
|
|
|
cc++;
|
|
|
|
if(font->charExtra[cc] > c)
|
|
|
|
c=font->u8FirstChar+1; // error
|
|
|
|
else
|
|
|
|
c=font->u8LastChar+cc+1;
|
|
|
|
};
|
2011-05-11 21:18:46 +00:00
|
|
|
|
2011-05-11 23:37:26 +00:00
|
|
|
/* starting offset into character source data */
|
2011-05-14 22:56:33 +00:00
|
|
|
int toff=0,width,preblank=0,blank=0;
|
|
|
|
|
2011-05-11 23:37:26 +00:00
|
|
|
if(font->u8Width==0){
|
2011-05-14 22:56:33 +00:00
|
|
|
for(int y=0;y<c-font->u8FirstChar;y++)
|
2011-05-14 20:21:51 +00:00
|
|
|
toff+=font->charInfo[y].widthBits;
|
2011-05-14 22:56:33 +00:00
|
|
|
width=font->charInfo[c-font->u8FirstChar].widthBits;
|
|
|
|
|
2011-05-14 20:21:51 +00:00
|
|
|
toff*=height;
|
|
|
|
data=&font->au8FontTable[toff];
|
2011-05-12 00:23:07 +00:00
|
|
|
blank=1;
|
2011-05-14 20:21:51 +00:00
|
|
|
}else if(font->u8Width==1){ // NEW CODE
|
|
|
|
// Find offset and length for our character
|
|
|
|
for(int y=0;y<c-font->u8FirstChar;y++)
|
|
|
|
toff+=font->charInfo[y].widthBits;
|
|
|
|
width=font->charInfo[c-font->u8FirstChar].widthBits;
|
|
|
|
|
2011-05-14 20:44:18 +00:00
|
|
|
if(font->au8FontTable[toff]>>4 == 15){ // It's a raw character!
|
|
|
|
preblank = font->au8FontTable[toff+1];
|
|
|
|
blank= font->au8FontTable[toff+2];
|
|
|
|
data=&font->au8FontTable[toff+3];
|
2011-07-05 13:49:44 +00:00
|
|
|
width=(width-3/height);
|
2011-05-14 20:44:18 +00:00
|
|
|
}else{
|
|
|
|
data=pk_decode(&font->au8FontTable[toff],&width);
|
|
|
|
}
|
2011-05-11 23:37:26 +00:00
|
|
|
}else{
|
2011-05-14 20:21:51 +00:00
|
|
|
toff=(c-font->u8FirstChar)*font->u8Width*height;
|
2011-05-11 23:37:26 +00:00
|
|
|
width=font->u8Width;
|
2011-05-14 20:21:51 +00:00
|
|
|
data=&font->au8FontTable[toff];
|
2011-05-11 23:37:26 +00:00
|
|
|
};
|
|
|
|
|
2011-05-13 01:19:47 +00:00
|
|
|
// boundary sanity checks
|
|
|
|
if(sx<0 || sy<0 || sx >= RESX || (sy+font->u8Height) >= RESY)
|
|
|
|
return sx; // nothing printed.
|
|
|
|
|
2011-05-11 23:37:26 +00:00
|
|
|
/* raw character data */
|
2011-05-11 21:18:46 +00:00
|
|
|
int byte;
|
2011-05-11 23:37:26 +00:00
|
|
|
unsigned char mask;
|
|
|
|
|
|
|
|
/* print forward or backward? */
|
2011-05-11 21:18:46 +00:00
|
|
|
int dmul=0;
|
2011-05-13 01:19:47 +00:00
|
|
|
if(font_direction==FONT_DIR_RTL){
|
2011-05-11 21:18:46 +00:00
|
|
|
dmul=1;
|
2011-05-13 01:19:47 +00:00
|
|
|
if(sx-(width+preblank+blank)<=0) // sanity check for left side
|
|
|
|
return sx;
|
|
|
|
} else if (font_direction==FONT_DIR_LTR){
|
2011-05-11 21:18:46 +00:00
|
|
|
dmul=-1;
|
2011-05-13 01:19:47 +00:00
|
|
|
if(sx+(width+preblank+blank)>=RESX) // sanity check for right side
|
|
|
|
return sx;
|
|
|
|
};
|
2011-05-11 23:37:26 +00:00
|
|
|
|
|
|
|
/* break down the position on byte boundaries */
|
2011-05-11 21:18:46 +00:00
|
|
|
char yidx=ry/8;
|
2011-05-11 23:37:26 +00:00
|
|
|
char yoff=ry%8;
|
|
|
|
|
2011-05-13 01:19:47 +00:00
|
|
|
rx+=dmul*preblank;
|
|
|
|
|
2011-05-11 23:37:26 +00:00
|
|
|
/* multiple 8-bit-lines */
|
2011-05-14 22:56:33 +00:00
|
|
|
for(int y=0;y<=height;y++){
|
2011-05-12 12:07:54 +00:00
|
|
|
int m=yoff+font->u8Height-8*y;
|
|
|
|
if(m>8)m=8;
|
|
|
|
if(m<0)m=0;
|
|
|
|
mask=255<<(8-m);
|
|
|
|
|
2011-05-11 23:37:26 +00:00
|
|
|
if(y==0){
|
2011-05-13 01:19:47 +00:00
|
|
|
mask=mask>>yoff;
|
2011-05-11 21:18:46 +00:00
|
|
|
};
|
|
|
|
|
2011-05-13 01:19:47 +00:00
|
|
|
if(mask==0) // Optimize :-)
|
2011-05-12 12:07:54 +00:00
|
|
|
break;
|
|
|
|
|
2011-05-11 21:18:46 +00:00
|
|
|
if(font_direction==FONT_DIR_LTR)
|
|
|
|
flip(mask);
|
|
|
|
|
2011-05-14 22:56:33 +00:00
|
|
|
for(int m=1;m<=preblank;m++){
|
2011-05-20 23:12:09 +00:00
|
|
|
lcdBuffer[(rx-dmul*(m))+(yidx+y)*RESX]&=~mask;
|
2011-05-13 01:19:47 +00:00
|
|
|
};
|
2011-05-12 00:23:07 +00:00
|
|
|
for(x=0;x<width;x++){
|
2011-05-11 23:37:26 +00:00
|
|
|
unsigned char b1,b2;
|
|
|
|
if(y==0)
|
|
|
|
b1=0;
|
|
|
|
else
|
2011-05-14 20:21:51 +00:00
|
|
|
b1=data[x*height+y-1];
|
2011-05-11 23:37:26 +00:00
|
|
|
if(y==height)
|
|
|
|
b2=0;
|
|
|
|
else
|
2011-05-14 20:21:51 +00:00
|
|
|
b2=data[x*height+y];
|
2011-05-11 23:37:26 +00:00
|
|
|
|
|
|
|
byte= (b1<<(8-yoff)) | (b2>>yoff);
|
2011-05-11 21:18:46 +00:00
|
|
|
if(font_direction==FONT_DIR_LTR)
|
|
|
|
flip(byte);
|
2011-05-11 23:37:26 +00:00
|
|
|
|
2011-05-20 23:12:09 +00:00
|
|
|
lcdBuffer[(rx+dmul*x)+(yidx+y)*RESX]&=~mask;
|
|
|
|
lcdBuffer[(rx+dmul*x)+(yidx+y)*RESX]|=byte;
|
2011-05-11 21:18:46 +00:00
|
|
|
};
|
2011-05-14 22:56:33 +00:00
|
|
|
for(int m=0;m<blank;m++){
|
2011-05-20 23:12:09 +00:00
|
|
|
lcdBuffer[(rx+dmul*(x+m))+(yidx+y)*RESX]&=~mask;
|
2011-05-12 00:23:07 +00:00
|
|
|
};
|
2011-05-11 21:18:46 +00:00
|
|
|
};
|
2011-05-13 01:19:47 +00:00
|
|
|
return sx-dmul*(x+preblank+blank);
|
2011-05-11 21:18:46 +00:00
|
|
|
};
|
|
|
|
|
2011-05-22 19:06:45 +00:00
|
|
|
#define UTF8
|
|
|
|
// decode 2 and 4-byte utf-8 strings.
|
2011-07-12 22:05:03 +00:00
|
|
|
#define UT2(a) ( ((a[0]&31)<<6) + (a[1]&63) )
|
|
|
|
#define UT3(a) ( ((a[0]&15)<<12) + ((a[1]&63)<<6) + (a[2]&63) )
|
2011-05-22 19:06:45 +00:00
|
|
|
|
2011-07-12 22:05:03 +00:00
|
|
|
int DoString(int sx, int sy, const char *s){
|
|
|
|
const char *c;
|
2011-05-22 19:06:45 +00:00
|
|
|
int uc;
|
2011-05-11 21:18:46 +00:00
|
|
|
for(c=s;*c!=0;c++){
|
2011-05-22 19:06:45 +00:00
|
|
|
#ifdef UTF8
|
|
|
|
/* will b0rk on non-utf8 */
|
2011-07-12 22:05:03 +00:00
|
|
|
if((*c&(128+64+32))==(128+64) && c[1]!=0){
|
|
|
|
uc=UT2(c); c+=1;
|
2011-05-22 19:06:45 +00:00
|
|
|
sx=DoChar(sx,sy,uc);
|
2011-07-12 22:05:03 +00:00
|
|
|
}else if( (*c&(128+64+32+16))==(128+64+32) && c[1]!=0 && c[2] !=0){
|
|
|
|
uc=UT3(c); c+=2;
|
2011-05-22 19:06:45 +00:00
|
|
|
sx=DoChar(sx,sy,uc);
|
|
|
|
}else
|
|
|
|
#endif
|
2011-05-11 21:18:46 +00:00
|
|
|
sx=DoChar(sx,sy,*c);
|
|
|
|
};
|
|
|
|
return sx;
|
|
|
|
};
|
|
|
|
|
|
|
|
int DoInt(int sx, int sy, int num){
|
|
|
|
#define mxlen 5
|
|
|
|
char s[(mxlen+1)];
|
|
|
|
char * o=s;
|
|
|
|
int len;
|
|
|
|
s[mxlen]=0;
|
|
|
|
char neg=0;
|
|
|
|
|
|
|
|
if(num<0){
|
|
|
|
num=-num;
|
|
|
|
neg=1;
|
|
|
|
};
|
2011-07-09 12:53:01 +00:00
|
|
|
if(num==0){
|
|
|
|
neg=2;
|
|
|
|
};
|
2011-05-11 21:18:46 +00:00
|
|
|
|
|
|
|
for (len=(mxlen-1);len>=0;len--){
|
|
|
|
s[len]=(num%10)+'0';
|
|
|
|
if(num==0){
|
|
|
|
s[len]=' '; // configurable?
|
|
|
|
o=s+len;
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
num/=10;
|
|
|
|
};
|
2011-07-09 12:53:01 +00:00
|
|
|
if(neg==1)
|
2011-05-11 21:18:46 +00:00
|
|
|
*o='-';
|
2011-07-09 12:53:01 +00:00
|
|
|
if(neg==2)
|
|
|
|
*o='0';
|
2011-05-11 21:18:46 +00:00
|
|
|
return DoString(sx,sy,o);
|
|
|
|
#undef mxlen
|
|
|
|
};
|
|
|
|
|
2011-07-14 00:01:41 +00:00
|
|
|
int DoIntXn(int sx, int sy, unsigned int num, unsigned int mxlen){
|
2011-05-11 21:18:46 +00:00
|
|
|
char s[(mxlen+1)];
|
|
|
|
char * o=s;
|
|
|
|
int len;
|
|
|
|
s[mxlen]=0;
|
|
|
|
for (len=(mxlen-1);len>=0;len--){
|
|
|
|
s[len]=(num%16)+'0';
|
|
|
|
if(s[len]>'9')
|
|
|
|
s[len]+='A'-'9'-1;
|
|
|
|
num/=16;
|
|
|
|
};
|
|
|
|
return DoString(sx,sy,o);
|
|
|
|
};
|
|
|
|
|
2011-07-14 00:01:41 +00:00
|
|
|
int DoIntX(int sx, int sy, unsigned int num){
|
|
|
|
return DoIntXn(sx, sy, num, 8);
|
|
|
|
};
|
|
|
|
|
|
|
|
int DoCharX(int sx, int sy, unsigned char num){
|
|
|
|
return DoIntXn(sx, sy, num, 2);
|
|
|
|
};
|
2011-07-16 18:09:08 +00:00
|
|
|
|
|
|
|
int DoShortX(int sx, int sy, uint16_t num){
|
|
|
|
return DoIntXn(sx, sy, num, 4);
|
|
|
|
};
|