File: jfm.c

package info (click to toggle)
vftool 2.0alpha-4.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 388 kB
  • ctags: 769
  • sloc: ansic: 2,748; makefile: 190; sh: 79
file content (71 lines) | stat: -rw-r--r-- 1,874 bytes parent folder | download | duplicates (5)
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
#include	<stdio.h>
#include	"defs.h"
#include	"bifont.h"
#include	"jsub.h"

char header[4*2];
char width[4*256];
int id, nt, lh, bc, ec, nw, ds;
struct jfmfntinfo *jfmfi;

readjfm(fntfp)
register FILE *fntfp;
{
    register struct jfmtype_entry *te;
    register struct jfmchar_entry *ce;
    register int i;
    char *alloc_check();

    if ((id=getuint(fntfp, 2)) != JFM_ID && id != TJFM_ID)
	return (FALSE);
    nt = getuint(fntfp, 2);
    fseek(fntfp, 2, 1);		/* lf */
    lh = getuint(fntfp, 2);
    bc = getuint(fntfp, 2);	/* bc should be 0 */
    ec = getuint(fntfp, 2);
    nw = getuint(fntfp, 2);
    fseek(fntfp, 7*4, 0);
    getbytes(fntfp, header, 2*4);
    ds = makeuint(header+4, 4);
    fseek(fntfp, (7+lh+nt+(ec-bc)+1)*4, 0);
    getbytes(fntfp, width, 4*nw);
    fseek(fntfp, (7+lh)*4, 0);	/* ready to read char_type and char_info */

    jfmfi = NEW(struct jfmfntinfo, "jfmfont info");
    jfmfi->nctype = nt;
    jfmfi->ctype = NEWTAB(struct jfmtype_entry, nt, "jfmtype table");
    for (i = 0, te = jfmfi->ctype; i < nt; i++, te++) {
	te->jfm_code = getuint(fntfp, 2);
	te->jfm_type = getuint(fntfp, 2);
    }
    jfmfi->lasttypecode = (te-1)->jfm_code;
    jfmfi->ch = NEWTAB(struct jfmchar_entry, ec+1, "jfmchar table");
    for (i = bc, ce = (jfmfi->ch)+bc; i <= ec; i++, ce++) {
	ce->tfmw = makeuint(width+4*getuint(fntfp,1),4);
	fseek(fntfp, 3, 1);
    }
    return (TRUE);
}

getctype(c, jfmfi)
int c;
struct jfmfntinfo *jfmfi;
{
    register int m;
    register int left, right;
    register struct jfmtype_entry *te;
    int code;

    if (c > jfmfi->lasttypecode)
	return (0);
    for (left = 0, right = jfmfi->nctype, te = jfmfi->ctype; left <= right;) {
	m = (left+right)/2;
	if (c < (code = (te+m)->jfm_code))
	    right = m-1;
	else if (c > code)
	    left = m+1;
	else if (c == code)
	    return ((te+m)->jfm_type);
    }
    return (0);
}