Debian Codegraph @

texk/web2c/pmpostdir/pmp.ch

raw
1 % jMetaPost change file for MetaPost
2 %
3 % written by Michio Matsuyama <[email protected]>
4 % Hideyuki Suzuki <[email protected]>
5 %
6 % $Id: jmp.ch,v 1.42 2000/03/20 02:55:50 hideyuki Exp $
7
8 %
9 %
10 % change file of mp.w for pMetaPost (CWEB version)
11 % Akira Kakuto (translated the WEB version)
12 %
13 %
14
15 @x
16 @d default_banner "This is MetaPost, Version "metapost_version /* printed when \MP\ starts */
17 @y
18 @d default_banner "This is " P_UP "MetaPost, Version " metapost_version /* printed when \MP\ starts */
19 @z
20
21 @x
22 #define metapost_version "3.00"
23 @y
24 #ifdef UPMP
25 #define P_UP "up"
26 #define metapost_version "3.00-0.04-u2.02"
27 #else
28 #define P_UP "p"
29 #define metapost_version "3.00-0.04"
30 #endif
31 @z
32
33 @x
34 # include <unistd.h> /* for access */
35 #endif
36 @y
37 # include <unistd.h> /* for access */
38 #endif
39 #include <kpathsea/config.h>
40 #include <kpathsea/kpathsea.h>
41 #include <ptexenc/ptexenc.h>
42 #include <errno.h>
43 @z
44
45 @x
46 void mp_close_file (MP mp, void *f) {
47 (void) mp;
48 if (f != NULL)
49 fclose ((FILE *) f);
50 @y
51 void mp_close_file (MP mp, void *f) {
52 (void) mp;
53 #ifdef WIN32
54 if (f != NULL) {
55 clear_infile_enc((FILE *)f);
56 fclose ((FILE *) f);
57 }
58 #else
59 if (f != NULL)
60 fclose ((FILE *) f);
61 #endif
62 @z
63
64 @x
65 mp->buf_size = 200;
66 @y
67 {
68 char *kpse_buf = kpse_var_value("buf_size");
69 if(kpse_buf) {
70 mp->buf_size = atoi(kpse_buf);
71 free(kpse_buf);
72 } else {
73 mp->buf_size = 500000;
74 }
75 }
76 @z
77
78 @x
79 static boolean mp_input_ln (MP mp, void *f) {
80 /* inputs the next line or returns |false| */
81 char *s;
82 size_t size = 0;
83 mp->last = mp->first; /* cf.\ Matthew 19\thinspace:\thinspace30 */
84 s = (mp->read_ascii_file) (mp, f, &size);
85 if (s == NULL)
86 return false;
87 if (size > 0) {
88 mp->last = mp->first + size;
89 if (mp->last >= mp->max_buf_stack) {
90 mp->max_buf_stack = mp->last + 1;
91 while (mp->max_buf_stack > mp->buf_size) {
92 mp_reallocate_buffer (mp, (mp->buf_size + (mp->buf_size >> 2)));
93 }
94 }
95 (void) memcpy ((mp->buffer + mp->first), s, size);
96 }
97 free (s);
98 return true;
99 }
100 @y
101 static boolean mp_input_ln (MP mp, void *f ) {
102 int i = EOF;
103 mp->last = input_line2((FILE *)f, mp->buffer, NULL, mp->first, mp->buf_size, &i);
104 if (i == EOF && errno != EINTR && mp->last == mp->first)
105 return false;
106 if (i != EOF && i != '\n' && i != '\r') {
107 fprintf (stderr, "! Unable to read an entire line---bufsize=%u.\n",
108 (unsigned) mp->buf_size);
109 fputs ("Please increase buf_size in texmf.cnf.\n", stderr);
110 exit (1);
111 }
112 if (i == '\r') {
113 while ((i = getc ((FILE *)f)) == EOF && errno == EINTR)
114 ;
115 if (i != '\n')
116 ungetc (i, f);
117 }
118 return true;
119 }
120 @z
121
122 @x
123 wterm (mp->banner);
124 @y
125 wterm (mp->banner);
126 wterm(" (");
127 wterm(getencstring());
128 wterm(")");
129 @z
130
131 @x
132 } four_quarters;
133 typedef union {
134 integer sc;
135 four_quarters qqqq;
136 } font_data;
137 @y
138 } four_quarters;
139 typedef struct {
140 halfword RH, LH;
141 } two_halves;
142 typedef union {
143 two_halves hh;
144 integer sc;
145 four_quarters qqqq;
146 } font_data;
147 @z
148
149 %
150 % tategaki support
151 %
152 % Suppose h==(0,height), d==(0,-depth) && w==(width,0) in horizontal string,
153 % && h==(height,0), d==(-depth,0) && w==(0,-width) in vertical string.
154 % Four vertices of the bounding box is h, d, h+w && d+w && those of the
155 % transformed boundig box is Th, Td, T(h+w) && T(d+w), so that the values
156 % of Th, Td && Tw are compared here.
157
158 @x
159 @ The height width and depth information stored in a text node determines a
160 rectangle that needs to be transformed according to the transformation
161 parameters stored in the text node.
162
163 @y
164 @ The height width and depth information stored in a text node determines a
165 rectangle that needs to be transformed according to the transformation
166 parameters stored in the text node.
167
168 Boundig box depends on JFM font ID.
169
170 @d yoko_jfm_id 11 /* `yoko-kumi' fonts */
171 @d tate_jfm_id 9 /* `tate-kumi' fonts */
172 @d font_jfm_p(A) (mp->font_id[(A)]!=0)
173
174 @z
175
176 @x
177 mp_number x0a, y0a, x1a, y1a, arg1;
178 mp_text_node p0 = (mp_text_node)p;
179 new_number (x0a);
180 new_number (x1a);
181 new_number (y0a);
182 new_number (y1a);
183 new_number (arg1);
184 number_clone (arg1, p0->depth);
185 number_negate (arg1);
186 take_scaled (x1a, p0->txx, p0->width);
187 take_scaled (y0a, p0->txy, arg1);
188 take_scaled (y1a, p0->txy, p0->height);
189 @y
190 mp_number x0a, y0a, x1a, y1a, arg1, arg2;
191 mp_text_node p0 = (mp_text_node)p;
192 new_number (x0a);
193 new_number (x1a);
194 new_number (y0a);
195 new_number (y1a);
196 new_number (arg1);
197 new_number (arg2);
198 number_clone (arg1, p0->depth);
199 number_negate (arg1);
200 number_clone (arg2, p0->width);
201 number_negate (arg2);
202 if ( mp->font_id[mp_font_n(p)]!=tate_jfm_id ) {
203 take_scaled (x1a, p0->txx, p0->width);
204 take_scaled (y0a, p0->txy, arg1);
205 take_scaled (y1a, p0->txy, p0->height);
206 } else {
207 take_scaled (x1a, p0->txy, arg2);
208 take_scaled (y0a, p0->txx, arg1);
209 take_scaled (y1a, p0->txx, p0->height);
210 }
211 @z
212
213 @x
214 take_scaled (x1a, p0->tyx, p0->width);
215 number_clone (arg1, p0->depth);
216 number_negate (arg1);
217 take_scaled (y0a, p0->tyy, arg1);
218 take_scaled (y1a, p0->tyy, p0->height);
219 @y
220 if ( mp->font_id[mp_font_n(p)]!=tate_jfm_id ) {
221 take_scaled (x1a, p0->tyx, p0->width);
222 number_clone (arg1, p0->depth);
223 number_negate (arg1);
224 take_scaled (y0a, p0->tyy, arg1);
225 take_scaled (y1a, p0->tyy, p0->height);
226 } else {
227 number_clone (arg1, p0->depth);
228 number_negate (arg1);
229 number_clone (arg2, p0->width);
230 number_negate (arg2);
231 take_scaled (x1a, p0->tyy, arg2);
232 take_scaled (y0a, p0->tyx, arg1);
233 take_scaled (y1a, p0->tyx, p0->height);
234 }
235 @z
236
237 @x
238 wlog (mp->banner);
239 @y
240 wlog (mp->banner);
241 wlog (" (");
242 wlog (getencstring());
243 wlog (")");
244 @z
245
246 %
247 % char type pointers
248 @x
249 eight_bits *font_bc;
250 eight_bits *font_ec; /* first and last character code */
251 @y
252 eight_bits *font_bc;
253 eight_bits *font_ec; /* first and last character code */
254 halfword *font_nt;
255 halfword *font_id;
256 @z
257
258 @x
259 int *char_base; /* base address for |char_info| */
260 @y
261 int *char_base; /* base address for |char_info| */
262 int *ctype_base;
263 @z
264
265 @x
266 xfree (mp->char_base);
267 @y
268 xfree (mp->font_id);
269 xfree (mp->font_nt);
270 xfree (mp->char_base);
271 xfree (mp->ctype_base);
272 @z
273
274 @x
275 XREALLOC (mp->char_base, l, int);
276 @y
277 XREALLOC (mp->font_id, l, halfword);
278 XREALLOC (mp->font_nt, l, halfword);
279 XREALLOC (mp->char_base, l, int);
280 XREALLOC (mp->ctype_base, l, int);
281 @z
282
283
284 @x
285 mp->char_base[null_font] = 0;
286 @y
287 mp->font_id[null_font] = 0;
288 mp->font_nt[null_font] = 0;
289 mp->char_base[null_font] = 0;
290 mp->ctype_base[null_font] = 0;
291 @z
292
293 @x
294 @d char_mp_info(A,B) mp->font_info[mp->char_base[(A)]+(B)].qqqq
295 @y
296 @d char_mp_info(A,B) mp->font_info[mp->char_base[(A)]+(B)].qqqq
297 @d ctype_char_end(A) (A)].hh.LH
298 @d ctype_char(A) mp->font_info[mp->ctype_base[(A)]+ctype_char_end
299 @d ctype_type_end(A) (A)].hh.RH
300 @d ctype_type(A) mp->font_info[mp->ctype_base[(A)]+ctype_type_end
301 @z
302
303 %
304 % lookup character type table
305 @x
306 void mp_set_text_box (MP mp, mp_text_node p) {
307 @y
308 @<Declare JFM function for text measuring@>;
309 void mp_set_text_box (MP mp, mp_text_node p) {
310 @z
311
312 @x
313 if ((*(mp_text_p (p)->str + k) < bc) || (*(mp_text_p (p)->str + k) > ec)) {
314 mp_lost_warning (mp, f, *(mp_text_p (p)->str + k));
315 } else {
316 cc = char_mp_info (f, *(mp_text_p (p)->str + k));
317 @y
318 if ( ((*(mp_text_p (p)->str + k) < bc) || (*(mp_text_p (p)->str + k) > ec)) && (mp->font_id[f]==0) ) {
319 mp_lost_warning (mp, f, *(mp_text_p (p)->str + k));
320 } else {
321 if (mp->font_id[f]!=0) {
322 #ifdef UPMP
323 integer cx; /* code for Japanese two byte character */
324 if (multistrlen(mp_text_p (p)->str, kk, k)>1) {
325 cx=fromBUFF(mp_text_p (p)->str, kk, k);
326 k=k+multistrlen(mp_text_p (p)->str, kk, k)-1;
327 } else {
328 cx=*(mp_text_p (p)->str + k);
329 }
330 cc=char_mp_info(f,mp_lookup_ctype(mp, f, cx));
331 #else
332 cc=char_mp_info(f,mp_lookup_ctype(mp, f,fromBUFF(mp_text_p(p)->str,limit,k)));
333 k++;
334 #endif
335 } else {
336 cc = char_mp_info (f, *(mp_text_p (p)->str + k));
337 }
338 @z
339
340 @x
341 @* Debugging.
342 @y
343 @ @<Declare JFM function for text measuring@>=
344 static int mp_lookup_ctype (MP mp,font_number f, integer c)
345 {
346 int l, u, r, ch;
347 l=0; u=mp->font_nt[f]-1;
348 while ( l<u ) {
349 r=(l+u)/2;
350 ch=ctype_char(f)(r);
351 if ( ch==c ) {
352 return ctype_type(f)(r);};
353 if ( ch<c ) l=r+1;
354 else u=r-1;
355 };
356 return 0;
357 }
358 @* Debugging.
359 @z