summaryrefslogtreecommitdiff
path: root/dviware/beebe/src/readpk.h
blob: 1cf71e5147967bda25f472810bbcb2bc1364d41f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/* -*-C-*- readpk.h */
/*-->readpk*/
/**********************************************************************/
/******************************* readpk *******************************/
/**********************************************************************/

int
readpk()	/* return 0 on success, EOF on failure */
{
    UNSIGN32 checksum;
    long end_of_packet;	/* pointer to byte following character packet */
    register BYTE flag_byte;
    UNSIGN32 packet_length;
    long start_of_packet;	/* pointer to start of character packet */
    register struct char_entry *tcharptr;/* temporary char_entry pointer */
    register UNSIGN32 the_char;

    /* Read a PK file, extracting character metrics and raster
       locations. */

    /******************************************************************/

    /* Process the preamble parameters */

    (void)REWIND(fontfp);	/* start at beginning of file */
    if ((BYTE)nosignex(fontfp,(BYTE)1) != PKPRE)
    {
	(void)warning("readpk():  PK font file does not start with PRE byte");
	return(EOF);
    }
    if ((BYTE)nosignex(fontfp,(BYTE)1) != PKID)
    {
	(void)warning(
	    "readpk():  PK font file PRE byte not followed by ID byte");
	return(EOF);
    }

    if (FSEEK(fontfp,(long)nosignex(fontfp,(BYTE)1),1))
    {
	(void)warning("readpk():  PK font file has garbled comment string");
	return(EOF);		/* skip comment string */
    }

    fontptr->designsize = nosignex(fontfp,(BYTE)4);

    checksum = nosignex(fontfp,(BYTE)4);	/* checksum */
    if ((fontptr->c != 0L) && (checksum != 0L) && (fontptr->c != checksum))
    {
	(void)sprintf(message,
	"readpk():  font [%s] has checksum = 10#%010lu [16#%08lx] [8#%011lo] \
different from DVI checksum = 10#%010lu [16#%08lx] [8#%011lo].  \
TeX preloaded .fmt file is probably out-of-date with respect to new fonts.",
	    fontptr->name, fontptr->c, fontptr->c, fontptr->c,
	    checksum, checksum, checksum);
	(void)warning(message);
    }

    fontptr->hppp = (UNSIGN32)nosignex(fontfp,(BYTE)4);
    fontptr->vppp = (UNSIGN32)nosignex(fontfp,(BYTE)4);

    fontptr->min_m = 0L;	/* these are unused in PK format */
    fontptr->max_m = 0L;
    fontptr->min_n = 0L;
    fontptr->max_n = 0L;

    fontptr->magnification = (UNSIGN32)( 0.5 + 5.0 * 72.27 *
	(float)(fontptr->hppp) / 65536.0 );	/* from GFtoPXL Section 53 */

    /******************************************************************/
    /* Process the characters until the POST byte is reached */

    (void)skpkspec();	/* skip any PK specials */

    start_of_packet = (long)FTELL(fontfp);
    while ((flag_byte = (BYTE)nosignex(fontfp,(BYTE)1)) != PKPOST)
    {
	flag_byte &= 0x07;
	switch(flag_byte)	/* flag_byte is in 0..7 */
	{
	case 0:
	case 1:
	case 2:
	case 3:		/* short character preamble */
	    packet_length = (UNSIGN32)flag_byte;
	    packet_length <<= 8;
	    packet_length += (UNSIGN32)nosignex(fontfp,(BYTE)1);
	    the_char = (UNSIGN32)nosignex(fontfp,(BYTE)1);
	    if (the_char >= NPXLCHARS)
	    {
		(void)warning(
		"readpk():  PK font file character number is too big for me");
	        return(EOF);
	    }
	    tcharptr = &(fontptr->ch[the_char]);
	    end_of_packet = (long)FTELL(fontfp) + (long)packet_length;
	    tcharptr->tfmw = (UNSIGN32)(((float)nosignex(fontfp,(BYTE)3) *
		(float)fontptr->s) / (float)(1L << 20));
	    tcharptr->dx = (INT32)nosignex(fontfp,(BYTE)1) << 16;
	    tcharptr->dy = 0L;
	    tcharptr->pxlw = (UNSIGN16)PIXROUND(tcharptr->dx, 1.0/65536.0);
	    tcharptr->wp = (COORDINATE)nosignex(fontfp,(BYTE)1);
	    tcharptr->hp = (COORDINATE)nosignex(fontfp,(BYTE)1);
	    tcharptr->xoffp = (COORDINATE)signex(fontfp,(BYTE)1);
	    tcharptr->yoffp = (COORDINATE)signex(fontfp,(BYTE)1);
	    break;

	case 4:
	case 5:
	case 6:		/* extended short character preamble */
	    packet_length = (UNSIGN32)(flag_byte & 0x03);
	    packet_length <<= 16;
	    packet_length += (UNSIGN32)nosignex(fontfp,(BYTE)2);
	    the_char = (UNSIGN32)nosignex(fontfp,(BYTE)1);
	    if (the_char >= NPXLCHARS)
	    {
		(void)warning(
		"readpk():  PK font file character number is too big for me");
	        return(EOF);
	    }
	    tcharptr = &(fontptr->ch[the_char]);
	    end_of_packet = (long)FTELL(fontfp) + (long)packet_length;
	    tcharptr->tfmw = (UNSIGN32)(((float)nosignex(fontfp,(BYTE)3) *
		(float)fontptr->s) / (float)(1L << 20));
	    tcharptr->dx = (INT32)nosignex(fontfp,(BYTE)2) << 16;
	    tcharptr->dy = 0L;
	    tcharptr->pxlw = (UNSIGN16)PIXROUND(tcharptr->dx, 1.0/65536.0);
	    tcharptr->wp = (COORDINATE)nosignex(fontfp,(BYTE)2);
	    tcharptr->hp = (COORDINATE)nosignex(fontfp,(BYTE)2);
	    tcharptr->xoffp = (COORDINATE)signex(fontfp,(BYTE)2);
	    tcharptr->yoffp = (COORDINATE)signex(fontfp,(BYTE)2);
	    break;

	case 7:		/* long character preamble */
	    packet_length = (UNSIGN32)nosignex(fontfp,(BYTE)4);
	    the_char = (UNSIGN32)nosignex(fontfp,(BYTE)4);
	    if (the_char >= NPXLCHARS)
	    {
		(void)warning(
		"readpk():  PK font file character number is too big for me");
	        return(EOF);
	    }
	    tcharptr = &(fontptr->ch[the_char]);
	    end_of_packet = (long)FTELL(fontfp) + (long)packet_length;
	    tcharptr->tfmw = (UNSIGN32)(((float)nosignex(fontfp,(BYTE)4) *
		(float)fontptr->s) / (float)(1L << 20));
	    tcharptr->dx = (INT32)signex(fontfp,(BYTE)4);
	    tcharptr->dy = (INT32)signex(fontfp,(BYTE)4);
	    tcharptr->pxlw = (UNSIGN16)PIXROUND(tcharptr->dx, 1.0/65536.0);
	    tcharptr->wp = (COORDINATE)nosignex(fontfp,(BYTE)4);
	    tcharptr->hp = (COORDINATE)nosignex(fontfp,(BYTE)4);
	    tcharptr->xoffp = (COORDINATE)signex(fontfp,(BYTE)4);
	    tcharptr->yoffp = (COORDINATE)signex(fontfp,(BYTE)4);
	    break;
	} /* end switch */
	tcharptr->fontrp = start_of_packet;
	(void)FSEEK(fontfp,end_of_packet,0); /* position to end of packet */
	(void)skpkspec();	/* skip any PK specials */
	start_of_packet = (long)FTELL(fontfp);
    } /* end while */

#if    (BBNBITGRAPH | HPJETPLUS | POSTSCRIPT | IMPRESS | CANON_A2)
    (void)newfont();
#endif

    return(0);
}