Compress fonts a little. Chop of space at beginning and end

This commit is contained in:
Stefan `Sec` Zehl 2011-05-13 03:19:47 +02:00
parent 7647b79033
commit 99456e3ce0
1 changed files with 34 additions and 16 deletions

View File

@ -9,7 +9,7 @@ char font_direction = FONT_DIR_LTR;
/* Exported Functions */ /* Exported Functions */
int DoChar(int sx, int sy, char c){ int DoChar(int sx, int sy, char c){
int x; int x=0;
int y; int y;
/* how many bytes is it high? */ /* 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 */ /* "real" coordinates. Our physical display is upside down */
int rx=RESX-sx-1; int rx=RESX-sx-1;
int ry=RESY-sy-font->u8Height; int ry=RESY-sy-font->u8Height;
// int ry=RESY-sy-height*8;
/* Does this font provide this character? */ /* Does this font provide this character? */
if(c<font->u8FirstChar || c>font->u8LastChar) if(c<font->u8FirstChar || c>font->u8LastChar)
c=font->u8FirstChar+1; // error c=font->u8FirstChar+1; // error
/* starting offset into character source data */ /* starting offset into character source data */
int off,width,blank; int off,width,preblank,blank;
if(font->u8Width==0){ if(font->u8Width==0){
off=font->charInfo[c-font->u8FirstChar].offset; off=font->charInfo[c-font->u8FirstChar].offset;
width=font->charInfo[c-font->u8FirstChar].widthBits; width=font->charInfo[c-font->u8FirstChar].widthBits;
// width=(font->charInfo[c-font->u8FirstChar].offset-off)/8; preblank=0;
blank=1; 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;y<c-font->u8FirstChar;y++)
off+=fci[y].widthBits;
off*=height;
preblank=fci[y].preblank;
blank=fci[y].blank;
}else{ }else{
off=(c-font->u8FirstChar)*font->u8Width*height; off=(c-font->u8FirstChar)*font->u8Width*height;
width=font->u8Width; width=font->u8Width;
preblank=0;
blank=0; blank=0;
}; };
// boundary sanity checks
if(sx<0 || sy<0 || sx >= RESX || (sy+font->u8Height) >= RESY)
return sx; // nothing printed.
/* raw character data */ /* raw character data */
int byte; int byte;
unsigned char mask; unsigned char mask;
/* print forward or backward? */ /* print forward or backward? */
int dmul=0; int dmul=0;
if(font_direction==FONT_DIR_RTL) if(font_direction==FONT_DIR_RTL){
dmul=1; 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; dmul=-1;
if(sx+(width+preblank+blank)>=RESX) // sanity check for right side
return sx;
};
/* break down the position on byte boundaries */ /* break down the position on byte boundaries */
char yidx=ry/8; char yidx=ry/8;
char yoff=ry%8; char yoff=ry%8;
rx+=dmul*preblank;
/* multiple 8-bit-lines */ /* multiple 8-bit-lines */
for(y=0;y<=height;y++){ for(y=0;y<=height;y++){
int m=yoff+font->u8Height-8*y; int m=yoff+font->u8Height-8*y;
@ -61,19 +80,19 @@ int DoChar(int sx, int sy, char c){
mask=255<<(8-m); mask=255<<(8-m);
if(y==0){ if(y==0){
mask=mask>>(yoff); mask=mask>>yoff;
} else if(y==height){
// mask=mask<<((8-(font->u8Height%8))%8);
// mask=mask<<(8-yoff);
}; };
if(mask==0) if(mask==0) // Optimize :-)
break; break;
// buffer[(rx-dmul)+(yidx+y)*RESX]=5; // buffer[(rx-dmul)+(yidx+y)*RESX]=5;
if(font_direction==FONT_DIR_LTR) if(font_direction==FONT_DIR_LTR)
flip(mask); flip(mask);
for(m=1;m<=preblank;m++){
buffer[(rx-dmul*(m))+(yidx+y)*RESX]&=~mask;
};
for(x=0;x<width;x++){ for(x=0;x<width;x++){
unsigned char b1,b2; unsigned char b1,b2;
if(y==0) if(y==0)
@ -92,12 +111,11 @@ int DoChar(int sx, int sy, char c){
buffer[(rx+dmul*x)+(yidx+y)*RESX]&=~mask; buffer[(rx+dmul*x)+(yidx+y)*RESX]&=~mask;
buffer[(rx+dmul*x)+(yidx+y)*RESX]|=byte; buffer[(rx+dmul*x)+(yidx+y)*RESX]|=byte;
}; };
if(blank){ for(m=0;m<blank;m++){
buffer[(rx+dmul*x)+(yidx+y)*RESX]&=~mask; buffer[(rx+dmul*(x+m))+(yidx+y)*RESX]&=~mask;
}; };
}; };
return sx-dmul*(x+blank); return sx-dmul*(x+preblank+blank);
}; };
int DoString(int sx, int sy, char *s){ int DoString(int sx, int sy, char *s){