Support for new packed fonts. Restructure a bit

This commit is contained in:
Stefan `Sec` Zehl 2011-05-14 22:21:51 +02:00
parent 289881e354
commit 38fb18fdb5
3 changed files with 36 additions and 27 deletions

View File

@ -8,17 +8,8 @@
typedef struct { typedef struct {
const uint8_t widthBits; // width, in bits (or pixels), of the character const uint8_t widthBits; // width, in bits (or pixels), of the character
const uint16_t offset; // offset of the character's bitmap, in bytes,
// into the the struct FONT_DEF's data array
} FONT_CHAR_INFO; } FONT_CHAR_INFO;
typedef struct {
const uint8_t widthBits; // width, in bits (or pixels), of the character
const uint8_t preblank; // How many blanks
const uint8_t blank; // How many blanks
} FONT_CHAR_INFO_v2;
struct FONT_DEF { struct FONT_DEF {
uint8_t u8Width; /* Character width for storage */ uint8_t u8Width; /* Character width for storage */
uint8_t u8Height; /* Character height for storage */ uint8_t u8Height; /* Character height for storage */
@ -30,4 +21,15 @@ struct FONT_DEF {
typedef const struct FONT_DEF * FONT; typedef const struct FONT_DEF * FONT;
/* interesting / exported stuff */
#define FONT_DIR_LTR 0
#define FONT_DIR_RTL 1
// Not implemented
// #define FONT_DIR_UP 2
// #define FONT_DIR_DOWN 3
extern const struct FONT_DEF * font;
extern char font_direction;
#endif #endif

View File

@ -8,6 +8,7 @@ char font_direction = FONT_DIR_LTR;
/* Exported Functions */ /* Exported Functions */
uint8_t * pk_decode(const uint8_t * data,int*len);
int DoChar(int sx, int sy, char c){ int DoChar(int sx, int sy, char c){
int x=0; int x=0;
int y; int y;
@ -15,6 +16,8 @@ int DoChar(int sx, int sy, char c){
/* how many bytes is it high? */ /* how many bytes is it high? */
char height=(font->u8Height-1)/8+1; char height=(font->u8Height-1)/8+1;
const uint8_t * data;
/* "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;
@ -24,13 +27,17 @@ int DoChar(int sx, int sy, char c){
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,preblank,blank; int toff,width,preblank,blank;
if(font->u8Width==0){ if(font->u8Width==0){
off=font->charInfo[c-font->u8FirstChar].offset; toff=0;
width=font->charInfo[c-font->u8FirstChar].widthBits; width=font->charInfo[c-font->u8FirstChar].widthBits;
for(y=0;y<c-font->u8FirstChar;y++)
toff+=font->charInfo[y].widthBits;
toff*=height;
data=&font->au8FontTable[toff];
preblank=0; preblank=0;
blank=1; blank=1;
}else if(font->u8Width==1){ /* }else if(font->u8Width==1){
FONT_CHAR_INFO_v2 * fci=(FONT_CHAR_INFO_v2*)font->charInfo; FONT_CHAR_INFO_v2 * fci=(FONT_CHAR_INFO_v2*)font->charInfo;
off=0; off=0;
width=fci[c-font->u8FirstChar].widthBits; width=fci[c-font->u8FirstChar].widthBits;
@ -38,10 +45,21 @@ int DoChar(int sx, int sy, char c){
off+=fci[y].widthBits; off+=fci[y].widthBits;
off*=height; off*=height;
preblank=fci[y].preblank; preblank=fci[y].preblank;
blank=fci[y].blank; blank=fci[y].blank; */
}else if(font->u8Width==1){ // NEW CODE
// Find offset and length for our character
toff=0;
for(int y=0;y<c-font->u8FirstChar;y++)
toff+=font->charInfo[y].widthBits;
width=font->charInfo[c-font->u8FirstChar].widthBits;
data=pk_decode(&font->au8FontTable[toff],&width);
preblank=0;
blank=0;
}else{ }else{
off=(c-font->u8FirstChar)*font->u8Width*height; toff=(c-font->u8FirstChar)*font->u8Width*height;
width=font->u8Width; width=font->u8Width;
data=&font->au8FontTable[toff];
preblank=0; preblank=0;
blank=0; blank=0;
}; };
@ -98,11 +116,11 @@ int DoChar(int sx, int sy, char c){
if(y==0) if(y==0)
b1=0; b1=0;
else else
b1=font->au8FontTable[off+x*height+y-1]; b1=data[x*height+y-1];
if(y==height) if(y==height)
b2=0; b2=0;
else else
b2=font->au8FontTable[off+x*height+y]; b2=data[x*height+y];
byte= (b1<<(8-yoff)) | (b2>>yoff); byte= (b1<<(8-yoff)) | (b2>>yoff);
if(font_direction==FONT_DIR_LTR) if(font_direction==FONT_DIR_LTR)

View File

@ -12,13 +12,6 @@
#define RESX 96 #define RESX 96
#define RESY 68 #define RESY 68
#define FONT_DIR_LTR 0
#define FONT_DIR_RTL 1
// Not yet implemented
// #define FONT_DIR_UP 2
// #define FONT_DIR_DOWN 3
// ARM supports byte flip natively. Yay! // ARM supports byte flip natively. Yay!
#define flip(byte) \ #define flip(byte) \
__asm("rbit %[value], %[value];" \ __asm("rbit %[value], %[value];" \
@ -33,13 +26,9 @@
}while(0) }while(0)
*/ */
extern const struct FONT_DEF * font;
extern char font_direction;
int DoChar(int sx, int sy, char c); int DoChar(int sx, int sy, char c);
int DoString(int sx, int sy, char *s); int DoString(int sx, int sy, char *s);
int DoInt(int sx, int sy, int num); int DoInt(int sx, int sy, int num);
int DoIntX(int sx, int sy, unsigned int num); int DoIntX(int sx, int sy, unsigned int num);
#endif #endif