File: zeit.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 (105 lines) | stat: -rw-r--r-- 2,869 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
95
96
97
98
99
100
101
102
103
104
105
/*******************************************************
 *  Zeit Shotai Kurabu interface routine for xdvi pl.17
 *  Written by Y. Hayashi   (hayashi@me.aoyama.ac.jp)
 ******************************************************/

#include "xdvi-config.h"
#include "xdvi.h"
#include "dvi-init.h"
#include "util.h"

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

#include "ptexmap.h"
#include "zeit.h"
#include "jfm.h"

#ifdef PTEX
#include "ft2.h"

static void read_ZEIT_char(struct font *fontp, wide_ubyte ch)
{
    struct glyph *g;
    int ascend;

    if (ch > fontp->maxchar) {
	int j;
	int i = KTABLESIZE * ((int)(ch / KTABLESIZE)+1);
	fontp->kglyph = xrealloc(fontp->kglyph, sizeof(struct glyph *) * i);
	for (j=fontp->maxchar+1; j<i; j++) {
	    fontp->kglyph[j] = NULL;
	}
	fontp->maxchar = i-1;
    }
    g = fontp->kglyph[ch];
    if (g == NULL) {
	struct glyph *orig = fontp->kglyph[0];
	ASSERT(orig != NULL, "Unexpected error.");
	g = fontp->kglyph[ch] = xcalloc(1, sizeof(struct glyph));
	g->bitmap.w = orig->bitmap.w;
	g->bitmap.h = orig->bitmap.h;
	g->x        = orig->x;
	g->y        = orig->y;
	g->dvi_adv  = orig->dvi_adv;
    }
    alloc_bitmap(&g->bitmap);
    ascend = ft2_get_bitmap(ch, fontp->ft2_index, &g->bitmap);
#ifndef WORDS_BIGENDIAN
    order_reverse_bitmap(&g->bitmap);
#endif  /* !WORDS_BIGENDIAN */
    g->tdir = fontp->dir;
    if (fontp->dir) {  /* tate */
	int swap = g->x;
	g->x     = g->y;
	g->y     = swap;
    } else {  /* yoko */
	g->y = ascend;
    }
}

int read_ZEIT_index(struct font *fontp)
{
    int n;
    struct glyph *g;
    struct jfm *jfm;
    const double dimconv = fontp->dimconv;

    fontp->read_char = read_ZEIT_char;
    fontp->kglyph = xcalloc(KTABLESIZE, sizeof(struct glyph *));
    fontp->maxchar = KTABLESIZE - 1;

    jfm = read_jfm(fontp->file, fontp->fontname);
    if (jfm == NULL) return -1;
    fontp->ft2_index = ft2_open_font(getkanjifont(fontp->fontname));
    if (fontp->ft2_index < 0) return -1;

    for (n=0; n<jfm->table[J_NT]; n++) {
	int code  =  jfm->type[n].code;
	int index =  jfm->type[n].index;
	int width =  jfm->width[jfm->info[index].width_ix];
	int height= jfm->height[jfm->info[index].height_depth_ix / 0x10];
	int depth =  jfm->depth[jfm->info[index].height_depth_ix % 0x10];

	g = xcalloc(1, sizeof(struct glyph));
	g->bitmap.w = (int)(dimconv * width) >> 16;
	g->bitmap.h = (int)(dimconv * (height + depth)) >> 16;
	if (g->bitmap.w != g->bitmap.h) {
	  if (code<0xFF60)
	    fprintf(stderr, "Warning: '%s' (code=0x%X) is not square.\n",
		    fontp->fontname, code);
	    g->bitmap.w = g->bitmap.h; /* FIX-ME */
	}
	g->bitmap.bits = NULL;
	g->x = 0;
	g->y = (int) (dimconv * height) >> 16;
	g->dvi_adv = dimconv * width;
	fontp->kglyph[code] = g;
    }
    g = fontp->kglyph[0];
    alloc_bitmap(&g->bitmap);
    fill_bitmap(&g->bitmap);
    return 0;
}
#endif  /* PTEX */