static void ShowGlyph(FILE *ttf,long offset,long len,int imageFormat, struct ttfinfo *info) {
int h,w,sbX,sbY,advance;
int i,j,k,ch;
long here;
if ( imageFormat!=1 && imageFormat!=2 )
return;
here = ftell(ttf);
fseek(ttf,info->bitmapdata_start+offset,SEEK_SET);
h = getc(ttf);
w = getc(ttf);
sbX = (signed char) getc(ttf);
sbY = (signed char) getc(ttf);
advance = getc(ttf);
printf( "\t\theight=%d width=%d sbX=%d sbY=%d advance=%d %s aligned\n",
h,w,sbX,sbY,advance,imageFormat==1?"Byte":"Bit");
len -= 5;
if ( imageFormat==1 ) {
for ( i=0; i<h; ++i ) {
putchar('\t');
for ( j=0; j<(w+7)/8; ++j ) {
ch = getc(ttf); --len;
for ( k=0; k<8 && j*8+k<w; ++k ) {
if ( ch&(0x80>>k))
putchar('*');
else
putchar('.');
}
}
putchar('\n');
}
} else {
k=8;
for ( i=0; i<h; ++i ) {
putchar('\t');
for ( j=0; j<w; ++j ) {
if ( ++k>=8 ) {
ch = getc(ttf); --len;
k=0;
}
if ( ch&(0x80>>k))
putchar('*');
else
putchar('.');
}
putchar('\n');
}
}
if ( len!=0 )
printf("!!!\tLength field wrong. %d left\n", (int) len );
fseek(ttf,here,SEEK_SET);
}
static void readttfIndexSubTab(FILE *ttf,long offset, int first, int last,
struct ttfinfo *info) {
int i, indexFormat, imageFormat, bdatOff;
long curstart, nextstart;
fseek(ttf,offset,SEEK_SET);
printf( "\t index Format=%d ", indexFormat=getushort(ttf));
if ( indexFormat==1 || indexFormat==3 ) printf( "Proportional\n" );
else if ( indexFormat==2 ) printf( "Monospace\n" );
else printf( "Unknown\n" );
printf( "\t image Format=%d\n", imageFormat=getushort(ttf));
printf( "\t Offset in bitmap data table=%d\n", bdatOff=getlong(ttf));
if ( indexFormat==1 || indexFormat==3 ) {
curstart = (indexFormat==1?getlong(ttf):getushort(ttf));
for ( i=first; i<=last; ++i ) {
nextstart = (indexFormat==1?getlong(ttf):getushort(ttf));
if ( info->glyph_names==NULL )
printf( "\t Glyph %d starts at %5d length=%d\n", i, (int) curstart, (int) (nextstart-curstart) );
else if ( i<info->glyph_cnt && info->glyph_names[i]!=NULL )
printf( "\t Glyph %d (%10s) starts at %5d length=%d\n", i,
info->glyph_names[i], (int) curstart, (int) (nextstart-curstart) );
else
printf( "\t Glyph %d ( ) starts at %5d length=%d\n", i,
(int) curstart, (int) (nextstart-curstart) );
ShowGlyph(ttf,bdatOff+curstart,nextstart-curstart,imageFormat,info);
curstart = nextstart;
}
} else if ( indexFormat==2 ) {
printf( "\t Bitmap Image Size=%d\n", (int) getlong(ttf));
printf( "\t big Metrics for any glyph\n" );
readttfBigGlyphMetrics(ttf,"\t ");
}
}
static void readttfIndexSizeSubTab(FILE *ttf,long offset, long size, long num,
struct ttfinfo *info) {
int i, first, last;
long here, moreoff;
fseek(ttf,offset,SEEK_SET);
for ( i=0; i<num; ++i ) {
printf( "\t indexSubTable[%d]\n", i );
printf( "\t first glyph=%d\n", first = getushort(ttf));
printf( "\t last glyph=%d\n", last = getushort(ttf));
printf( "\t additional offset=%d\n", (int) (moreoff = getlong(ttf)));
here = ftell(ttf);
readttfIndexSubTab(ttf,offset+moreoff,first,last,info);
fseek(ttf,here,SEEK_SET);
}
}