Subversion Repositories wimsdev

Rev

Rev 8103 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 reyssat 1
/*    Copyright (C) 2002-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
2
 *
3
 *  This program is free software; you can redistribute it and/or modify
4
 *  it under the terms of the GNU General Public License as published by
5
 *  the Free Software Foundation; either version 2 of the License, or
6
 *  (at your option) any later version.
7
 *
8
 *  This program is distributed in the hope that it will be useful,
9
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 *  GNU General Public License for more details.
12
 *
13
 *  You should have received a copy of the GNU General Public License
14
 *  along with this program; if not, write to the Free Software
15
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
 */
17
 
18
/* dvi 2 gif driver, gf font loader and processor */
19
 
20
int g;
21
FONTHEADER *fh;
22
int brush, x,y,xmax,ymax,thischar,xsize,charsize,charcnt,charpos;
23
int chswitch;
24
long int datapos;
25
char *onechar;
26
unsigned char *gfbuf;
27
int gfbuflen;
28
FILE *fontf;
29
 
30
void GF_eoc(void)
31
{
32
    if(onechar==NULL) return;
33
    fwrite(onechar,1,charsize,fontf); datapos+=charsize;
34
    free(onechar); onechar=NULL;
35
}
36
 
37
void GF_boc(int p)
38
{
39
    unsigned char cc;
40
    int min_m, min_n, max_m, max_n, del_m, del_n;
41
    if(!chswitch) return;
42
    if(p==0) {
43
        cc=texint(gfbuf+(++g),4); g+=8;
44
        min_m=texint(gfbuf+g,4); g+=4;
45
        max_m=texint(gfbuf+g,4); g+=4;
46
        min_n=texint(gfbuf+g,4); g+=4;
47
        max_n=texint(gfbuf+g,4); g+=4;
48
        del_m=max_m-min_m; del_n=max_n-min_n;
49
        g--;
50
    }
51
    else {
52
        cc=gfbuf[++g];
53
        del_m=gfbuf[++g]; max_m=gfbuf[++g];
54
        del_n=gfbuf[++g]; max_n=gfbuf[++g];
55
        min_m=max_m-del_m; min_n=max_n-del_n;
56
    }
57
    if(cc>tfm.ec || cc<tfm.bc) return;
58
    charpos=cc-tfm.bc;
59
    if(del_m<0) del_m=0; if(del_n<0) del_n=0;
60
    if(del_m>=MAX_FONT_X-1) del_m=MAX_FONT_X-2;
61
    if(del_n>=MAX_FONT_Y-1) del_n=MAX_FONT_Y-2;
62
    x=y=0; xmax=del_m+1; ymax=del_n+1;
63
    fh[charpos].xstart=min_m; fh[charpos].ystart=-max_n;
64
    fh[charpos].xmax=xmax; fh[charpos].ymax=ymax;
65
    brush=0; thischar=cc;
66
    xsize=(xmax+7)/8; charsize=xsize*ymax;
67
    onechar=xmalloc(charsize+1024);
68
    memset(onechar,0,charsize+1024);
69
    fh[charpos].start=datapos;
70
    fh[charpos].w=tfm.f[cc].w;
71
}
72
 
73
void GF_paint(int p)
74
{
75
    int i;
76
    if(onechar==NULL) return;
77
    if(brush) for(i=x;i<p+x && i<xmax;i++) {
78
        onechar[y*xsize+(i>>3)]|=(1<<(i&7));
79
    }
80
    x+=p; if(x>xmax) x=xmax;
81
    brush^=1;
82
}
83
 
84
void GF_new_row(int p)
85
{
86
    y++; if(y>ymax) y=ymax;
87
    x=p; if(x>xmax) x=xmax;
88
    brush=1;
89
}
90
 
91
void GF_skip(int p)
92
{
93
    if(p>0) p=texint(gfbuf+(++g),p);
94
    p++; y+=p; if(y>ymax) y=ymax;
95
    x=0; brush=0;
96
}
97
 
98
void GF_xxx(int p)
99
{
100
    unsigned int t;
101
    t=texint(gfbuf+(++g),p);
102
    g+=p+t-1;
103
}
104
 
105
void GF_yyy(void)
106
{
107
    g+=4;
108
}
109
 
110
void GF_char_loc(int p)
111
{
112
    if(p==0) g+=1+1+4+4;
113
    else g+=1+4+4+4+4;
114
}
115
 
116
void GF_post(void)
117
{
118
    chswitch=0;
119
}
120
 
121
void GF_post_post(void)
122
{
123
    g=gfbuflen; chswitch=0;
124
}
125
 
126
#include "gfcmd.c"
127
 
128
void loadgf(char *fname, int density)
129
{
130
    int len;
131
    char namebuf[128];
132
 
133
    snprintf(namebuf,sizeof(namebuf),"%s/texgf.%dgf",tmpdir,density);
134
    len=getfile(namebuf,&gfbuf);
135
    if(len<=0) {
136
        error("Metafont failed.");
137
    }
138
    gfbuflen=len;
139
}
140
 
141
void makegf(char *fontname, int density)
142
{
143
    call_sh("mkdir -p %s\n\
144
cd %s\n\
145
rm -f texgf.* 2>/dev/null\n\
146
cat >texgf.mf <<@\n\
147
batchmode;\n\
148
mode_def texgf =\n\
149
        mode_param (pixels_per_inch, %d);\n\
150
        mode_param (blacker, %f);\n\
151
        mode_param (fillin, 0);\n\
152
        mode_param (o_correction, 0);\n\
153
        mode_common_setup_;\n\
154
enddef;\n\
155
mode = texgf;\n\
156
input %s;\n\
157
@\n\
158
mf texgf </dev/null || mf-nowin texgf </dev/null\n\
159
", fontdir, tmpdir, density, pow((double)density/100,0.75)*blacker, fontname);
160
}
161
 
162
void gf2font(char *fontname,int density)
163
{
164
    unsigned char cc;
165
    char namebuf[1024];
166
    char tmpname[1024];
167
 
168
    if((gfbuf[0]&255)!=gf_pre || (gfbuf[1]&255)!=131) return;
169
    g=3+(gfbuf[2]&255);
170
    if(gfbuflen<=g) return;
171
    if(tfm.ec==0 && tfm.bc==0) return;
172
    charcnt=tfm.ec-tfm.bc+1;
173
    fh=xmalloc(charcnt*sizeof(FONTHEADER)+256);
174
    memset(fh,0,charcnt*sizeof(FONTHEADER));
175
    snprintf(tmpname,sizeof(tmpname),"%s/wims.fonttmp",tmpdir);
176
    fontf=fopen(tmpname,"w"); if(fontf==NULL) return;
177
    brush=0; x=y=xmax=ymax=datapos=0; onechar=NULL; chswitch=1;
178
    for(;g<gfbuflen;g++) {
179
        cc=gfbuf[g];
180
        if(cc<=63) {GF_paint(cc); continue;}
181
        if(cc>=74 && cc<=238) {GF_new_row(cc-74); continue;}
182
        switch(cc) {
183
            case gf_boc:        GF_boc(0); break;
184
            case gf_boc1:       GF_boc(1); break;
185
            case gf_eoc:        GF_eoc(); break;
186
            case gf_skip0:      GF_skip(0); break;
187
            case gf_skip1:      GF_skip(1); break;
188
            case gf_skip2:      GF_skip(2); break;
189
            case gf_skip3:      GF_skip(3); break;
190
            case gf_char_loc:   GF_char_loc(1); break;
191
            case gf_char_loc0:  GF_char_loc(0); break;
192
            case gf_xxx1:       GF_xxx(1); break;
193
            case gf_xxx2:       GF_xxx(2); break;
194
            case gf_xxx3:       GF_xxx(3); break;
195
            case gf_xxx4:       GF_xxx(4); break;
196
            case gf_yyy:        GF_yyy(); break;
197
 
198
            default: break;
199
        }
200
    }
201
    fclose(fontf);
202
    snprintf(namebuf,sizeof(namebuf),"%s/%s.font",
203
             tmpdir,fontname);
204
    fontf=fopen(namebuf,"w"); if(fontf!=NULL) {
205
        fwrite(&(tfm.checksum),sizeof(int),1,fontf);
206
        fwrite(&(tfm.designsize),sizeof(int),1,fontf);
207
        fwrite(&(tfm.bc),sizeof(int),1,fontf);
208
        fwrite(&(tfm.ec),sizeof(int),1,fontf);
209
        fwrite(fh,sizeof(FONTHEADER),charcnt,fontf);
210
        fclose(fontf);
211
        call_sh("cat %s >>%s; mkdir -p %s/%d; mv -f %s %s/%d",
212
                tmpname,namebuf,fontdir,density,namebuf,fontdir,density);
213
        unlink(tmpname);
214
    }
215
    free(fh);
216
}
217