From 99456e3ce0664c314bcd06c28f59daefe00252ac Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Fri, 13 May 2011 03:19:47 +0200 Subject: [PATCH] Compress fonts a little. Chop of space at beginning and end --- lcd/render.c | 50 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/lcd/render.c b/lcd/render.c index 7299eef..3b4870d 100644 --- a/lcd/render.c +++ b/lcd/render.c @@ -9,7 +9,7 @@ char font_direction = FONT_DIR_LTR; /* Exported Functions */ int DoChar(int sx, int sy, char c){ - int x; + int x=0; int y; /* how many bytes is it high? */ @@ -18,41 +18,60 @@ int DoChar(int sx, int sy, char c){ /* "real" coordinates. Our physical display is upside down */ int rx=RESX-sx-1; int ry=RESY-sy-font->u8Height; -// int ry=RESY-sy-height*8; /* Does this font provide this character? */ if(cu8FirstChar || c>font->u8LastChar) c=font->u8FirstChar+1; // error /* starting offset into character source data */ - int off,width,blank; + int off,width,preblank,blank; if(font->u8Width==0){ off=font->charInfo[c-font->u8FirstChar].offset; width=font->charInfo[c-font->u8FirstChar].widthBits; -// width=(font->charInfo[c-font->u8FirstChar].offset-off)/8; + preblank=0; blank=1; + }else if(font->u8Width==1){ + FONT_CHAR_INFO_v2 * fci=(FONT_CHAR_INFO_v2*)font->charInfo; + off=0; + width=fci[c-font->u8FirstChar].widthBits; + for(y=0;yu8FirstChar;y++) + off+=fci[y].widthBits; + off*=height; + preblank=fci[y].preblank; + blank=fci[y].blank; }else{ off=(c-font->u8FirstChar)*font->u8Width*height; width=font->u8Width; + preblank=0; blank=0; }; + // boundary sanity checks + if(sx<0 || sy<0 || sx >= RESX || (sy+font->u8Height) >= RESY) + return sx; // nothing printed. + /* raw character data */ int byte; unsigned char mask; /* print forward or backward? */ int dmul=0; - if(font_direction==FONT_DIR_RTL) + if(font_direction==FONT_DIR_RTL){ dmul=1; - else if (font_direction==FONT_DIR_LTR) + if(sx-(width+preblank+blank)<=0) // sanity check for left side + return sx; + } else if (font_direction==FONT_DIR_LTR){ dmul=-1; - + if(sx+(width+preblank+blank)>=RESX) // sanity check for right side + return sx; + }; /* break down the position on byte boundaries */ char yidx=ry/8; char yoff=ry%8; + rx+=dmul*preblank; + /* multiple 8-bit-lines */ for(y=0;y<=height;y++){ int m=yoff+font->u8Height-8*y; @@ -61,19 +80,19 @@ int DoChar(int sx, int sy, char c){ mask=255<<(8-m); if(y==0){ - mask=mask>>(yoff); - } else if(y==height){ -// mask=mask<<((8-(font->u8Height%8))%8); -// mask=mask<<(8-yoff); + mask=mask>>yoff; }; - if(mask==0) + if(mask==0) // Optimize :-) break; // buffer[(rx-dmul)+(yidx+y)*RESX]=5; if(font_direction==FONT_DIR_LTR) flip(mask); + for(m=1;m<=preblank;m++){ + buffer[(rx-dmul*(m))+(yidx+y)*RESX]&=~mask; + }; for(x=0;x