File: jfm.c

package info (click to toggle)
xdvik-ja 22.84.16-j1.40+t1lib-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 16,628 kB
  • ctags: 10,310
  • sloc: ansic: 88,999; sh: 5,309; makefile: 1,031; perl: 245; lisp: 244
file content (94 lines) | stat: -rw-r--r-- 2,430 bytes parent folder | download
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
#include "xdvi-config.h"
#include "xdvi.h"
#ifdef	PTEX

#include "jfm.h"
#include "util.h"

#ifndef	SEEK_SET
#define	SEEK_SET	0
#endif

/**** read_jfm0: borrowed from jxdvi-NEWS ****/
static int read_jfm0(FILE *fp, struct jfm *j)
{
	int i;

	fseek(fp, 0L, SEEK_SET);

	/* read jfm table field. */
	for (i = 0; i <= J_NP; i++)
	    j->table[i] = (short) get_bytes(fp, 2);

	/* read jfm header */
	j->check_sum = get_bytes(fp, 4);
	j->design_size = get_bytes(fp, 4);
	fseek(fp, (long) (4 * (j->table[J_LH] - 2)), 1);

	/* read jfm char_type */
	j->type = xmalloc(sizeof(struct jfm_char_type) * j->table[J_NT]);
	for (i=0; i < j->table[J_NT]; i++) {
	    j->type[i].code = (short) get_bytes(fp, 2);
	    j->type[i].index = (short) get_bytes(fp, 2);
	}

	/* read jfm char_info */
	j->info = xmalloc(sizeof(struct jfm_char_info) * (j->table[J_EC] + 1));
	for (i = 0; i <= j->table[J_EC]; i++) {
	    j->info[i].width_ix = (unsigned char) get_byte(fp);
	    j->info[i].height_depth_ix = (unsigned char) get_byte(fp);
	    j->info[i].italic_ix_tag = (unsigned char) get_byte(fp);
	    j->info[i].remainder_ix = (unsigned char) get_byte(fp);
	}

	/* read jfm width */
	j->width = xmalloc(sizeof(unsigned long) * j->table[J_NW]);
	for (i = 0; i < j->table[J_NW]; i++)
	    j->width[i] = get_bytes(fp, 4);

	/* read jfm height */
	j->height = xmalloc(sizeof(unsigned long) * j->table[J_NH]);
	for (i = 0; i < j->table[J_NH]; i++)
	    j->height[i] = get_bytes(fp, 4);

	/* read jfm depth */
	j->depth = xmalloc(sizeof(unsigned long) * j->table[J_ND]);
	for (i = 0; i < j->table[J_ND]; i++)
	    j->depth[i] = get_bytes(fp, 4);

	/* read jfm italic */
	j->italic = xmalloc(sizeof(unsigned long) * j->table[J_NI]);
	for (i = 0; i < j->table[J_NI]; i++)
	    j->italic[i] = get_bytes(fp, 4);
	return 0;
}

static int jfms_max = 0;
static int jfms_num = 0;
static struct jfm *jfms = NULL;

struct jfm *read_jfm(FILE *fp, char *fontname)
{
	int i;
	struct jfm *j;

	for (i=0; i<jfms_num; i++) {
	    if (strcmp(fontname, jfms[i].fontname) == 0) return &jfms[i];
	}

	if (jfms_num == jfms_max) {
	    if (jfms_max == 0) jfms_max = 8;
	    else               jfms_max *= 2;
	    jfms = xrealloc( jfms, sizeof(jfms[0]) * jfms_max );
	}
	j = &jfms[jfms_num];

	if (read_jfm0(fp, j)) {
	    fprintf(stderr, "Cannot open metric file: %s\n", fontname);
	    return NULL;
	}
	j->fontname = xstrdup(fontname);
	jfms_num++;
	return j;
}
#endif	/* PTEX */