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 {
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;
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 {
uint8_t u8Width; /* Character width for storage */
uint8_t u8Height; /* Character height for storage */
@ -30,4 +21,15 @@ struct FONT_DEF {
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

View File

@ -8,6 +8,7 @@ char font_direction = FONT_DIR_LTR;
/* Exported Functions */
uint8_t * pk_decode(const uint8_t * data,int*len);
int DoChar(int sx, int sy, char c){
int x=0;
int y;
@ -15,6 +16,8 @@ int DoChar(int sx, int sy, char c){
/* how many bytes is it high? */
char height=(font->u8Height-1)/8+1;
const uint8_t * data;
/* "real" coordinates. Our physical display is upside down */
int rx=RESX-sx-1;
int ry=RESY-sy-font->u8Height;
@ -24,13 +27,17 @@ int DoChar(int sx, int sy, char c){
c=font->u8FirstChar+1; // error
/* starting offset into character source data */
int off,width,preblank,blank;
int toff,width,preblank,blank;
if(font->u8Width==0){
off=font->charInfo[c-font->u8FirstChar].offset;
toff=0;
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;
blank=1;
}else if(font->u8Width==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;
@ -38,10 +45,21 @@ int DoChar(int sx, int sy, char c){
off+=fci[y].widthBits;
off*=height;
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{
off=(c-font->u8FirstChar)*font->u8Width*height;
toff=(c-font->u8FirstChar)*font->u8Width*height;
width=font->u8Width;
data=&font->au8FontTable[toff];
preblank=0;
blank=0;
};
@ -98,11 +116,11 @@ int DoChar(int sx, int sy, char c){
if(y==0)
b1=0;
else
b1=font->au8FontTable[off+x*height+y-1];
b1=data[x*height+y-1];
if(y==height)
b2=0;
else
b2=font->au8FontTable[off+x*height+y];
b2=data[x*height+y];
byte= (b1<<(8-yoff)) | (b2>>yoff);
if(font_direction==FONT_DIR_LTR)

View File

@ -12,13 +12,6 @@
#define RESX 96
#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!
#define flip(byte) \
__asm("rbit %[value], %[value];" \
@ -33,13 +26,9 @@
}while(0)
*/
extern const struct FONT_DEF * font;
extern char font_direction;
int DoChar(int sx, int sy, char c);
int DoString(int sx, int sy, char *s);
int DoInt(int sx, int sy, int num);
int DoIntX(int sx, int sy, unsigned int num);
#endif