summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/pmpostdir/pmp.ch
blob: 922e98e4be145c31a5ee2335ff6f4a35deb516d3 (plain)
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
% jMetaPost change file for MetaPost
%
% written by Michio Matsuyama <fwhw5892@mb.infoweb.ne.jp>
%            Hideyuki Suzuki <hideyuki@sat.t.u-tokyo.ac.jp>
%
% $Id: jmp.ch,v 1.42 2000/03/20 02:55:50 hideyuki Exp $

%
%
% change file of mp.w for pMetaPost (CWEB version)
% Akira Kakuto (translated the WEB version)
%
%

@x
@d default_banner "This is MetaPost, Version 2.000" /* printed when \MP\ starts */
@y
@z

@x
#define metapost_version "2.00"
@y
#ifdef UPMP
#define P_UP "up"
#define metapost_version "2.00-0.04-u1.21"
#else
#define P_UP "p"
#define metapost_version "2.00-0.04"
#endif
#define default_banner "This is " P_UP "MetaPost, Version " metapost_version /* printed when \MP\ starts */
@z

@x
#  include <unistd.h>           /* for access */
#endif
@y
#  include <unistd.h>           /* for access */
#endif
#include <kpathsea/config.h>
#include <kpathsea/kpathsea.h>
#include <ptexenc/ptexenc.h>
#include <errno.h>
@z

@x
void mp_close_file (MP mp, void *f) {
  (void) mp;
  if (f != NULL)
    fclose ((FILE *) f);
@y
void mp_close_file (MP mp, void *f) {
  (void) mp;
#ifdef WIN32
  if (f != NULL) {
    clear_infile_enc((FILE *)f);
    fclose ((FILE *) f);
  }
#else
  if (f != NULL)
    fclose ((FILE *) f);
#endif
@z

@x
mp->buf_size = 200;
@y
{
  char *kpse_buf = kpse_var_value("buf_size");
  if(kpse_buf) {
    mp->buf_size = atoi(kpse_buf);
    free(kpse_buf);
  } else {
    mp->buf_size = 500000;
  }
}
@z

@x
static boolean mp_input_ln (MP mp, void *f) {
  /* inputs the next line or returns |false| */
  char *s;
  size_t size = 0;
  mp->last = mp->first;         /* cf.\ Matthew 19\thinspace:\thinspace30 */
  s = (mp->read_ascii_file) (mp, f, &size);
  if (s == NULL)
    return false;
  if (size > 0) {
    mp->last = mp->first + size;
    if (mp->last >= mp->max_buf_stack) {
      mp->max_buf_stack = mp->last + 1;
      while (mp->max_buf_stack > mp->buf_size) {
        mp_reallocate_buffer (mp, (mp->buf_size + (mp->buf_size >> 2)));
      }
    }
    (void) memcpy ((mp->buffer + mp->first), s, size);
  }
  free (s);
  return true;
}
@y
static boolean mp_input_ln (MP mp, void *f ) {
  int i = EOF;
  mp->last = input_line2((FILE *)f, mp->buffer, mp->first, mp->buf_size, &i);
  if (i == EOF && errno != EINTR && mp->last == mp->first)
    return false;
  if (i != EOF && i != '\n' && i != '\r') {
    fprintf (stderr, "! Unable to read an entire line---bufsize=%u.\n",
                     (unsigned) mp->buf_size);
    fputs ("Please increase buf_size in texmf.cnf.\n", stderr);
    exit (1);
  }
  if (i == '\r') {
    while ((i = getc ((FILE *)f)) == EOF && errno == EINTR)
      ;
    if (i != '\n')
      ungetc (i, f);
  }
  return true;
}
@z

@x
wterm (mp->banner);
@y
wterm (mp->banner);
wterm(" (");
wterm(getencstring());
wterm(")");
@z

@x
} four_quarters;
typedef union {
  integer sc;
  four_quarters qqqq;
} font_data;
@y
} four_quarters;
typedef struct {
    halfword RH, LH;
} two_halves;
typedef union {
  two_halves hh;
  integer sc;
  four_quarters qqqq;
} font_data;
@z

%
% tategaki support
%
% Suppose h==(0,height), d==(0,-depth) && w==(width,0) in horizontal string,
% && h==(height,0), d==(-depth,0) && w==(0,-width) in vertical string.
% Four vertices of the bounding box is h, d, h+w && d+w && those of the
% transformed boundig box is Th, Td, T(h+w) && T(d+w), so that the values
% of Th, Td && Tw are compared here.

@x
@ The height width and depth information stored in a text node determines a
rectangle that needs to be transformed according to the transformation
parameters stored in the text node.

@y
@ The height width and depth information stored in a text node determines a
rectangle that needs to be transformed according to the transformation
parameters stored in the text node.

Boundig box depends on JFM font ID.

@d yoko_jfm_id   11 /* `yoko-kumi' fonts */
@d tate_jfm_id   9  /* `tate-kumi' fonts */
@d font_jfm_p(A) (mp->font_id[(A)]!=0)

@z

@x
  mp_number x0a, y0a, x1a, y1a, arg1;
  mp_text_node p0 = (mp_text_node)p;
  new_number (x0a);
  new_number (x1a);
  new_number (y0a);
  new_number (y1a);
  new_number (arg1);
  number_clone (arg1, p0->depth);
  number_negate (arg1);
  take_scaled (x1a, p0->txx, p0->width);
  take_scaled (y0a, p0->txy, arg1);
  take_scaled (y1a, p0->txy, p0->height);
@y
  mp_number x0a, y0a, x1a, y1a, arg1, arg2;
  mp_text_node p0 = (mp_text_node)p;
  new_number (x0a);
  new_number (x1a);
  new_number (y0a);
  new_number (y1a);
  new_number (arg1);
  new_number (arg2);
  number_clone (arg1, p0->depth);
  number_negate (arg1);
  number_clone (arg2, p0->width);
  number_negate (arg2);
  if ( mp->font_id[mp_font_n(p)]!=tate_jfm_id ) {
     take_scaled (x1a, p0->txx, p0->width);
     take_scaled (y0a, p0->txy, arg1);
     take_scaled (y1a, p0->txy, p0->height);
  } else {
     take_scaled (x1a, p0->txy, arg2);
     take_scaled (y0a, p0->txx, arg1);
     take_scaled (y1a, p0->txx, p0->height);
  }
@z

@x
  take_scaled (x1a, p0->tyx, p0->width);
  number_clone (arg1, p0->depth);
  number_negate (arg1);
  take_scaled (y0a, p0->tyy, arg1);
  take_scaled (y1a, p0->tyy, p0->height);
@y
  if ( mp->font_id[mp_font_n(p)]!=tate_jfm_id ) {
     take_scaled (x1a, p0->tyx, p0->width);
     number_clone (arg1, p0->depth);
     number_negate (arg1);
     take_scaled (y0a, p0->tyy, arg1);
     take_scaled (y1a, p0->tyy, p0->height);
  } else {
     number_clone (arg1, p0->depth);
     number_negate (arg1);
     number_clone (arg2, p0->width);
     number_negate (arg2);
     take_scaled (x1a, p0->tyy, arg2);
     take_scaled (y0a, p0->tyx, arg1);
     take_scaled (y1a, p0->tyx, p0->height);
  }
@z

@x
  wlog (mp->banner);
@y
  wlog (mp->banner);
  wlog (" (");
  wlog (getencstring());
  wlog (")");
@z

%
% char type pointers
@x
eight_bits *font_bc;
eight_bits *font_ec;    /* first and last character code */
@y
eight_bits  *font_bc;
eight_bits  *font_ec;  /* first and last character code */
halfword    *font_nt;
halfword    *font_id;
@z

@x
int *char_base; /* base address for |char_info| */
@y
int *char_base;  /* base address for |char_info| */
int *ctype_base;
@z

@x
xfree (mp->char_base);
@y
xfree (mp->font_id);
xfree (mp->font_nt);
xfree (mp->char_base);
xfree (mp->ctype_base);
@z

@x
  XREALLOC (mp->char_base, l, int);
@y
  XREALLOC (mp->font_id, l, halfword);
  XREALLOC (mp->font_nt, l, halfword);
  XREALLOC (mp->char_base, l, int);
  XREALLOC (mp->ctype_base, l, int);
@z


@x
mp->char_base[null_font] = 0;
@y
mp->font_id[null_font] = 0;
mp->font_nt[null_font] = 0;
mp->char_base[null_font] = 0;
mp->ctype_base[null_font] = 0;
@z

@x
@d char_mp_info(A,B) mp->font_info[mp->char_base[(A)]+(B)].qqqq
@y
@d char_mp_info(A,B) mp->font_info[mp->char_base[(A)]+(B)].qqqq
@d ctype_char_end(A) (A)].hh.LH
@d ctype_char(A) mp->font_info[mp->ctype_base[(A)]+ctype_char_end
@d ctype_type_end(A) (A)].hh.RH
@d ctype_type(A) mp->font_info[mp->ctype_base[(A)]+ctype_type_end
@z

%
% lookup character type table
@x
void mp_set_text_box (MP mp, mp_text_node p) {
@y
@<Declare JFM function for text measuring@>;
void mp_set_text_box (MP mp, mp_text_node p) {
@z

@x
  if ((*(mp_text_p (p)->str + k) < bc) || (*(mp_text_p (p)->str + k) > ec)) {
    mp_lost_warning (mp, f, *(mp_text_p (p)->str + k));
  } else {
    cc = char_mp_info (f, *(mp_text_p (p)->str + k));
@y
  if ( ((*(mp_text_p (p)->str + k) < bc) || (*(mp_text_p (p)->str + k) > ec)) && (mp->font_id[f]==0) ) {
    mp_lost_warning (mp, f, *(mp_text_p (p)->str + k));
  } else {
    if (mp->font_id[f]!=0) {
#ifdef UPMP
      integer cx;           /* code for Japanese two byte character */
      if (multistrlen(mp_text_p (p)->str, kk, k)>1) {
        cx=fromBUFF(mp_text_p (p)->str, kk, k);
        k=k+multistrlen(mp_text_p (p)->str, kk, k)-1;
      } else {
        cx=*(mp_text_p (p)->str + k);
      }
      cc=char_mp_info(f,mp_lookup_ctype(mp, f, cx));
#else
      cc=char_mp_info(f,mp_lookup_ctype(mp, f,fromBUFF(mp_text_p(p)->str,limit,k)));
      k++;
#endif
    } else {
      cc = char_mp_info (f, *(mp_text_p (p)->str + k));
    }
@z

@x
@* Debugging.
@y
@ @<Declare JFM function for text measuring@>=
static int mp_lookup_ctype (MP mp,font_number f, integer c)
{
  int l, u, r, ch;
  l=0; u=mp->font_nt[f]-1;
  while ( l<u ) {
    r=(l+u)/2;
    ch=ctype_char(f)(r);
    if ( (ch==c) ) {
      return ctype_type(f)(r);};
    if ( (ch<c) ) l=r+1;
    else u=r-1;
  };
  return 0;
}
@* Debugging.
@z