static int
PK_packed_num(fp)
register FILE *fp;
{
int i,j;
if ((i = PK_get_nyb(fp)) == 0) {
do {
j = PK_get_nyb(fp);
++i;
}
while (j == 0);
while (i > 0) {
j = (j << 4) | PK_get_nyb(fp);
--i;
}
return (j - 15 + ((13 - PK_dyn_f) << 4) + PK_dyn_f);
}
else {
if (i <= PK_dyn_f) return i;
if (i < 14)
return (((i - PK_dyn_f - 1) << 4) + PK_get_nyb(fp)
+ PK_dyn_f + 1);
if (i == 14) PK_repeat_count = PK_packed_num(fp);
else PK_repeat_count = 1;
return PK_packed_num(fp);
}
}
static void
PK_skip_specials(fontp)
register struct font *fontp;
{
int i,j;
register FILE *fp = fontp->file;
do {
PK_flag_byte = one(fp);
if (PK_flag_byte >= PK_CMD_START) {
switch (PK_flag_byte) {
case PK_X1 :
case PK_X2 :
case PK_X3 :
case PK_X4 :
i = 0;
for (j = PK_CMD_START; j <= PK_flag_byte; ++j)
i = (i << 8) | one(fp);
while (i--) (void) one(fp);
break;
case PK_Y :
(void) four(fp);
case PK_POST :
case PK_NOOP :
break;
default :
oops("Unexpected %d in PK file %s", PK_flag_byte,
fontp->filename);
break;
}
}
}
while (PK_flag_byte != PK_POST && PK_flag_byte >= PK_CMD_START);
}
/*
* Public routines
*/
static void
read_PK_char(fontp, ch)
register struct font *fontp;
ubyte ch;
{
int i, j;
int n;
int row_bit_pos;
Boolean paint_switch;
BMUNIT *cp;
register struct glyph *g;
register FILE *fp = fontp->file;
long fpwidth;
BMUNIT word;
int word_weight, bytes_wide;
int rows_left, h_bit, count;
g = &fontp->glyph[ch];
PK_flag_byte = g->x2;
PK_dyn_f = PK_flag_byte >> 4;
paint_switch = ((PK_flag_byte & 8) != 0);
PK_flag_byte &= 0x7;
if (PK_flag_byte == 7) n = 4;
else if (PK_flag_byte > 3) n = 2;
else n = 1;
if (debug & DBG_PK) Printf("loading pk char %d, char type %d ", ch, n);
/*
* now read rest of character preamble
*/
if (n != 4) fpwidth = num(fp, 3);
else {
fpwidth = sfour(fp);
(void) four(fp); /* horizontal escapement */
}
(void) num(fp, n); /* vertical escapement */
{
unsigned long w, h;
w = num(fp, n);
h = num(fp, n);
if (w > 0x7fff || h > 0x7fff)
oops("Character %d too large in file %s", ch, fontp->fontname);
g->bitmap.w = w;
g->bitmap.h = h;
}
g->x = snum(fp, n);
g->y = snum(fp, n);
g->dvi_adv = fontp->dimconv * fpwidth;
if (debug & DBG_PK) {
if (g->bitmap.w != 0)
Printf(", size=%dx%d, dvi_adv=%ld", g->bitmap.w, g->bitmap.h,
g->dvi_adv);
Putchar('\n');
}