File: dnpzeit.c

package info (click to toggle)
xdvik-ja 22.15-j1.03-3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 7,556 kB
  • ctags: 9,278
  • sloc: ansic: 79,619; sh: 7,174; makefile: 657; sed: 271; awk: 35
file content (177 lines) | stat: -rw-r--r-- 4,452 bytes parent folder | download | duplicates (2)
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
167
168
169
170
171
172
173
174
175
176
177
/***************************************************
 * NTT JTeX support routine for xdvi-zeit
 * Written by Y. Hayashi (hayashi@me.aoyama.ac.jp)
 **************************************************/

/* Modified by Masahito Yamaga(yamaga@ipc.chiba-u.ac.jp) 1996.9.5 */

/* #include "xdvi.h" */
#include "xdvi-config.h"
#ifdef  NTTZEIT

#ifndef       X_NOT_STDC_ENV
#include <stdlib.h>
#endif

static struct _dnplist {
	char *name;
	int index;
} dnplist[] = {
	{ "sy",      1 },	{ "roma",    2 },
	{ "hira",    3 },	{ "kata",    4 },
	{ "greek",   5 },	{ "russian", 6 },
	{ "keisen",  7 },	{ "ka",      8 },
	{ "kb",      9 },	{ "kc",     10 },
	{ "kd",     11 },	{ "ke",     12 },
	{ "kf",     13 },	{ "kg",     14 },
	{ "kh",     15 },	{ "ki",     16 },
	{ "kj",     17 },	{ "kk",     18 },
	{ "kl",     19 },	{ "km",     20 },
	{ "kn",     21 },	{ "ko",     22 },
	{ "kp",     23 },	{ "kq",     24 },
	{ "kr",     25 },	{ "ks",     26 },
	{ "kt",     27 },	{ "ku",     28 },
	{ "kv",     29 },	{ "kw",     30 },
	{ "kx",     31 },	{ "ky",     32 },
	{ "kz",     33 },	{ NULL,      0 }
};

struct _tfminfo {
	char *point;	/* point number	*/
	double width;
	double height;
double depth;
} tfminfo[] = {
	{  "5", 0.9154200, 0.7708800, 0.1445400 },
	{  "6", 0.9234495, 0.7628500, 0.1606000 },
	{  "7", 0.9291850, 0.7915280, 0.1376560 },
	{  "8", 0.9033750, 0.7226990, 0.1806750 },
	{  "9", 0.9100670, 0.7494660, 0.1606000 },
	{ "10", 0.9154200, 0.7708800, 0.1445400 },
	{ "12", 0.9234495, 0.7628500, 0.1606000 },
	{ "17", 0.9352580, 0.7793820, 0.1558760 },
	{ "20", 0.9154200, 0.7588350, 0.1565850 },
	{ NULL, 0.0,       0.0,       0.0       }
};

static	void
get_NTT_font(fontp, code)
	struct font *fontp;
	int code;
{
	struct bitmap *bm;
	int bwidth, jiscode;

	bm = &fontp->glyph[code].bitmap;
	bwidth = (bm->w + 7) / 8;
	bzero(bm->bits, bwidth * bm->h);
	jiscode = ku_ten_compute(fontp->index, code);
	
 	VF_GetBitmap(jiscode, fontp->vf, bm->w, bm->h,
 		      bwidth, 0, bm->bits);
}

static	void
read_NTT_char(fontp, ch)
	struct font *fontp;
	int ch;
{
	struct glyph *g;

	g = &fontp->glyph[ch];
	g->bitmap.w = fontp->glyph[0].bitmap.w;
	g->bitmap.h = fontp->glyph[0].bitmap.h;
	g->dvi_adv = fontp->glyph[0].dvi_adv;
	g->x = fontp->glyph[0].x;
	g->y = fontp->glyph[0].y;
    
	alloc_bitmap(&g->bitmap);
	get_NTT_font(fontp, ch);
#ifdef	DEBUGZEIT
	dispfont(&g->bitmap);
#endif  /* DEBUGZEIT */
#if	!defined(WORDS_BIGENDIAN) || (BMBYTES == 4) || (BMBYTES == 2)
	adj_ZEIT_bitmap(&g->bitmap);
#endif
}

int
read_NTT_index(fontp)
	register struct font *fontp;
{
	struct _dnplist *dp;
	struct _tfminfo *tp;
	double dimconv, pow();
	char *p;

	fontp->read_char = read_NTT_char;
	fontp->glyph = (struct glyph *)
		xmalloc(256 * sizeof(struct glyph));
	bzero((char *) fontp->glyph, 256 * sizeof(struct glyph));
	dimconv = fontp->dimconv;
	if (-1 == open_ZEIT_font(fontp, isdnpfont(fontp->fontname)))
	    return -1;

/*	p = fontp->fontname + 3; */
	for (dp = dnplist; dp->name; dp++)
/*	    if (0 == strncmp(p, dp->name, strlen(dp->name))) */
	    if (p=strstr(fontp->fontname,dp->name))
		if (*(p+=strlen(dp->name)) >= '0' && *p <= '9')
		break;
	if (NULL == dp->name) {
	    Fprintf(stderr, "Cannot recognize font: %s\n", fontp->fontname);
	    exit(-1);
	}
	fontp->index = dp->index;

/*	p += strlen(dp->name); */
	for (tp = tfminfo; tp->point; tp++)
	    if (0 == strncmp(p, tp->point, strlen(tp->point)))
		break;
	if (NULL == tp->point)
	    tp = &tfminfo[5];	/* default is 10pt. */

	fontp->glyph[0].bitmap.w = (int) (dimconv * tp->width * 16);
	fontp->glyph[0].bitmap.h = (int)
		(dimconv * (tp->height + tp->depth) * 16);
	fontp->glyph[0].dvi_adv = dimconv * tp->width * pow(2.0, 20.0);
	fontp->glyph[0].x = 0;
	fontp->glyph[0].y = (int) (dimconv * tp->height * 16);
}

/**** ku_ten_compute : borrowed from dvi2tty ****/

ku_ten_compute(f, c)
	register unsigned int f, c;
{
	register unsigned int ku, ten;
	int n;

	if (f == 1) {
	    if (c < 100) {
		ku = 1;
		ten = c;
	    } else {
		ku = 2;
		ten = c - 100;
	    }
	} else if (f == 2) {
	    ku = 3;
	    ten = c - 32;
	} else if (f <= 7) {
	    ku = f + 1;
	    ten = c;
	} else if (f <= 19) {	/* Daiichi Suijun */
	    n = (f - 8) * 256 + c;
	    ku = (n / 0x5e) + 0x10;
	    ten = (n % 0x5e) + 1;
	} else {		/* Daini Suijun */
	    n = (f - 20) * 256 + c;
	    ku = (n / 0x5e) + 0x30;
	    ten = (n % 0x5e) + 1;
	}
	ku += 0x20;
	ten += 0x20;
	return(ku * 256 + ten);
}
#endif  /* NTTZEIT */