Enhanced font support: support extended(utf8) characters

This commit is contained in:
Stefan `Sec` Zehl 2011-05-22 21:06:45 +02:00
parent 1bfcc7baf6
commit f3b14ba4de
6 changed files with 1703 additions and 1490 deletions

View File

@ -17,6 +17,7 @@ struct FONT_DEF {
uint8_t u8LastChar; /* The last character available */
const uint8_t *au8FontTable; /* Font table start address in memory */
const FONT_CHAR_INFO *charInfo; /* Pointer to array of char information */
const uint16_t *charExtra; /* Pointer to array of extra char info */
};
typedef const struct FONT_DEF * FONT;

View File

@ -9,7 +9,7 @@ char font_direction = FONT_DIR_LTR;
/* Exported Functions */
int DoChar(int sx, int sy, char c){
int DoChar(int sx, int sy, int c){
int x=0;
/* how many bytes is it high? */
@ -22,8 +22,20 @@ int DoChar(int sx, int sy, char c){
int ry=RESY-sy-font->u8Height;
/* Does this font provide this character? */
if(c<font->u8FirstChar || c>font->u8LastChar)
if(c<font->u8FirstChar)
c=font->u8FirstChar+1; // error
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;
};
/* starting offset into character source data */
int toff=0,width,preblank=0,blank=0;
@ -127,9 +139,26 @@ int DoChar(int sx, int sy, char c){
return sx-dmul*(x+preblank+blank);
};
#define UTF8
// decode 2 and 4-byte utf-8 strings.
#define UT2(a,b) ( ((a&31)<<6) + (b&63) )
#define UT3(a,b,c) ( ((a&15)<<12) + ((b&63)<<6) + (c&63) )
int DoString(int sx, int sy, char *s){
char *c;
int uc;
for(c=s;*c!=0;c++){
#ifdef UTF8
/* will b0rk on non-utf8 */
if((*c&(128+64+32))==(128+64)){
uc=UT2(*c,*(++c));
sx=DoChar(sx,sy,uc);
}else if( (*c&(128+64+32+16))==(128+64+32)){
uc=UT3(*c,*(++c),*(++c));
sx=DoChar(sx,sy,uc);
}else
#endif
sx=DoChar(sx,sy,*c);
};
return sx;

View File

@ -26,7 +26,7 @@
}while(0)
*/
int DoChar(int sx, int sy, char c);
int DoChar(int sx, int sy, int 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);

View File

@ -548,9 +548,9 @@ const uint8_t au8Font8x8Thin[]= {
};
/* Global variables */
const struct FONT_DEF Font_3x6 = {3, 6, 32, 96, au8Font3x6, NULL};
const struct FONT_DEF Font_5x8 = {5, 8, 32, 128, au8Font5x8, NULL};
const struct FONT_DEF Font_7x8 = {7, 8, 32, 128, au8Font7x8, NULL};
const struct FONT_DEF Font_8x8 = {8, 8, 32, 128, au8Font8x8, NULL};
const struct FONT_DEF Font_8x8Thin = {8, 8, 32, 128, au8Font8x8Thin, NULL};
const struct FONT_DEF Font_3x6 = {3, 6, 32, 96, au8Font3x6, NULL,NULL};
const struct FONT_DEF Font_5x8 = {5, 8, 32, 128, au8Font5x8, NULL,NULL};
const struct FONT_DEF Font_7x8 = {7, 8, 32, 128, au8Font7x8, NULL,NULL};
const struct FONT_DEF Font_8x8 = {8, 8, 32, 128, au8Font8x8, NULL,NULL};
const struct FONT_DEF Font_8x8Thin = {8, 8, 32, 128, au8Font8x8Thin,NULL,NULL};

File diff suppressed because it is too large Load Diff

View File

@ -22,10 +22,9 @@ $|=1;
### Configure me
###
my $charlist;
for(32..126){
$charlist.=chr $_;
};
my @charlist=(32..126,0x20ac); #,0x3044 # hiragana I
push @charlist,map {ord $_} qw(ä ö ü Ä Ö Ü ß);
###
### Runtime Options
@ -84,6 +83,9 @@ $file.="-raw" if($raw);
print "Rasterizing $title into ${file}.c\n";
@charlist=sort { $a <=> $b } @charlist;
my $charlist=join("",map {chr $_} @charlist);
### Get & optimize bounding box
my $im = new GD::Image($width,$height);
@ -278,9 +280,22 @@ EOF
print C @offsets;
my($first)=ord substr($charlist,0,1);
my($last)=$first+length($charlist)-1;
printf C "};
my($first)=$charlist[0];
my($last)=$first-1;
for(@charlist){
last unless $_ == $last+1;
$last++;
};
print C <<EOF;
};
const uint16_t ${fonts}Extra[] = {
EOF
print C join(",",@charlist[($last-$first+1)..$#charlist],0xffff);
printf C "
};
/* Font info */
const struct FONT_DEF Font_$fonts = {
@ -288,9 +303,9 @@ const struct FONT_DEF Font_$fonts = {
%3d, /* character height */
%3d, /* first char */
%3d, /* last char */
%s, %s
%s, %s, %s
};
",1,$pxsize,$first,$last,"${fonts}Bitmaps","${fonts}Lengths";
",1,$pxsize,$first,$last,"${fonts}Bitmaps","${fonts}Lengths","${fonts}Extra";
printf C "\n";
printf C "/* Font metadata: \n";