Debian Codegraph @

texk/web2c/uptexdir/uptftopl.ch

raw
1 % This is a change file for TFtoPL
2 %
3 % (2024-04-27) TTK Support upTeX new encoding for combining characters
4 % (2023-09-17) HY Support more than 256 different glue/kern
5 % (2022-12-03) TTK Merge pTFtoPL source/binary into upTFtoPL
6 % (2018-01-27) HY pTFtoPL p2.0 - new JFM spec by texjporg
7 % (07/18/2006) ST TFtoPL p1.7 (3.1, Web2c 7.2)
8 % (03/27/1998) KN TFtoPL p1.4 (3.1, Web2c 7.2)
9 %
10 @x [0] l.45 - pTeX:
11 \def\title{TF\lowercase{to}PL changes for C}
12 @y
13 \def\title{TF\lowercase{to}PL changes for C, and for KANJI}
14 @z
15
16 @x [2] l.64 - pTeX:
17 @d my_name=='tftopl'
18 @d banner=='This is TFtoPL, Version 3.3' {printed when the program starts}
19 @y
20 @d my_name=='uptftopl'
21 @d banner=='This is upTFtoPL, Version 3.3-p240427'
22 {printed when the program starts}
23 @z
24
25 @x [2] l.91 - pTeX:
26 procedure initialize; {this procedure gets things started properly}
27 @y
28 procedure initialize; {this procedure gets things started properly}
29 var @!k:integer; {all-purpose initiallization index}
30 @z
31
32 @x [2] l.97 - pTeX:
33 tfm_file_array := xmalloc_array (byte, 1002);
34 @y
35 tfm_file_array := xmalloc_array (byte, 1002 + 4);
36 @z
37
38 @x
39 parse_arguments;
40 @y
41 init_kanji;
42 parse_arguments;
43 @z
44
45 @x [7] l.149 - pTeX:
46 print_ln (version_string);
47 @y
48 print_ln (version_string);
49 print_ln ('process kanji code is ', conststringcast(get_enc_string), '.');
50 @z
51
52 @x [18.20] l.438 - pTeX:
53 @d index == index_type
54 @y
55 @d index == index_type
56 @d yoko_id_byte = 11 {id byte for YOKO-kumi kanji tfm files}
57 @d tate_id_byte = 9 {id byte for TATE-kumi kanji tfm files}
58 @d tfm_format = 1 {normal tfm formated metric files}
59 @d jfm_format = 2 {jfm formated metric files for YOKO-kumi kanji}
60 @d vfm_format = 3 {vfm formated metric files for TATE-kumi kanji}
61 @z
62
63 @x [18.20] l.448 - pTeX:
64 @!tfm_file_array: ^byte; {the input data all goes here}
65 @y
66 @!tfm_file_array: ^byte; {the input data all goes here}
67 @!file_format:tfm_format..vfm_format; {format of tfm file}
68 @!nt:0..@'77777; {number of words in the character type table}
69 @!ng:0..@'77777; {number of words in the glue table}
70 @z
71
72 @x [20] l.434 - pTeX: Read JFM header
73 read(tfm_file,tfm[1]); lf:=tfm[0]*@'400+tfm[1];
74 @y
75 read(tfm_file,tfm[1]); lf:=tfm[0]*@'400+tfm[1];
76 if lf=yoko_id_byte then
77 begin file_format:=jfm_format;
78 print_ln('Input file is in YOKO-kumi kanji tfm format.');
79 write_ln(pl_file,'(COMMENT THIS IS A KANJI FORMAT FILE)');
80 end
81 else if lf=tate_id_byte then
82 begin file_format:=vfm_format;
83 print_ln('Input file is in TATE-kumi kanji tfm format.');
84 write_ln(pl_file,'(COMMENT THIS IS A KANJI FORMAT FILE)');
85 write_ln(pl_file,'(DIRECTION TATE)');
86 end
87 else file_format:=tfm_format;
88 if file_format=tfm_format then
89 begin nt:=0; tmp_ptr:=2;
90 end
91 else
92 begin if eof(tfm_file) then abort('The input file is only two bytes long!');
93 read(tfm_file,tfm[2]);
94 if eof(tfm_file) then abort('The input file is only three bytes long!');
95 read(tfm_file,tfm[3]); nt:=tfm[2]*@'400+tfm[3];
96 if eof(tfm_file) then abort('The input file is only four bytes long!');
97 read(tfm_file,tfm[4]);
98 if eof(tfm_file) then abort('The input file is only five bytes long!');
99 if tfm[4]>127 then abort('The fifth byte of the input file exceeds 127!');
100 read(tfm_file,tfm[5]); lf:=tfm[4]*@'400+tfm[5];
101 tmp_ptr:=6;
102 end;
103 @z
104
105 @x [20] l.445 - pTeX: put the rest of the file into tfm[6] and after
106 for tfm_ptr:=2 to 4*lf-1 do
107 @y
108 for tfm_ptr:=tmp_ptr to 4*lf-1 do
109 @z
110
111 @x [21] l.468 - pTeX: the location of subfile sizes is different
112 begin tfm_ptr:=2;@/
113 @y
114 begin
115 if file_format<>tfm_format then
116 begin tfm_ptr:=6; check_sum_value:=28;
117 end
118 else
119 begin tfm_ptr:=2; check_sum_value:=24;
120 end;
121 @z
122
123 @x [21] l.485 - pTeX: ng has to be treated specially
124 if (bc>ec+1)or(ec>255) then abort('The character code range ',
125 @.The character code range...@>
126 bc:1,'..',ec:1,' is illegal!');
127 if (nw=0)or(nh=0)or(nd=0)or(ni=0) then
128 abort('Incomplete subfiles for character dimensions!');
129 @.Incomplete subfiles...@>
130 if ne>256 then abort('There are ',ne:1,' extensible recipes!');
131 @.There are ... recipes@>
132 if lf<>6+lh+(ec-bc+1)+nw+nh+nd+ni+nl+nk+ne+np then
133 abort('Subfile sizes don''t add up to the stated total!');
134 @.Subfile sizes don't add up...@>
135 @y
136 case file_format of
137 tfm_format: begin
138 if (bc>ec+1)or(ec>255) then abort('The character code range ',
139 @.The character code range...@>
140 bc:1,'..',ec:1,' is illegal!');
141 if (nw=0)or(nh=0)or(nd=0)or(ni=0) then
142 abort('Incomplete subfiles for character dimensions!');
143 @.Incomplete subfiles...@>
144 if ne>256 then abort('There are ',ne:1,' extensible recipes!');
145 @.There are ... recipes@>
146 if lf<>6+lh+(ec-bc+1)+nw+nh+nd+ni+nl+nk+ne+np then
147 abort('Subfile sizes don''t add up to the stated total!');
148 @.Subfile sizes don't add up...@>
149 end;
150 jfm_format,vfm_format: begin ng:=ne;
151 if (bc>ec+1)or(ec>255)or(bc<>0) then abort('The character code range ',
152 @.The character code range...@>
153 bc:1,'..',ec:1,' is illegal!');
154 if (nw=0)or(nh=0)or(nd=0)or(ni=0) then
155 abort('Incomplete subfiles for character dimensions!');
156 @.Incomplete subfiles...@>
157 if lf<>7+nt+lh+(ec-bc+1)+nw+nh+nd+ni+nl+nk+ng+np then
158 abort('Sum of subfile sizes (',
159 7+nt+lh+(ec-bc+1)+nw+nh+nd+ni+nl+nk+ng+np:1,
160 ') is not equal to the stated total ', lf:1);
161 @.Subfile sizes don't add up...@>
162 end;
163 end;
164 @z
165
166 @x [23] l.506 - pTeX: declare type_base.
167 @!char_base,@!width_base,@!height_base,@!depth_base,@!italic_base,
168 @!lig_kern_base,@!kern_base,@!exten_base,@!param_base:integer;
169 {base addresses for the subfiles}
170 @y
171 @!char_base,@!width_base,@!height_base,@!depth_base,@!italic_base,
172 @!lig_kern_base,@!kern_base,@!exten_base,@!param_base:integer;
173 @!type_base,@!glue_base:integer; {base addresses for the subfiles}
174 @!check_sum_value:integer; {either 24 (normal case) or 28 (kanji case)}
175 @z
176
177 @x [24] l.510 - pTeX: define type_base
178 @ @<Compute the base addresses@>=
179 begin char_base:=6+lh-bc;
180 @y
181 @ @<Compute the base addresses@>=
182 begin
183 if file_format<>tfm_format then
184 begin type_base:=7+lh;
185 char_base:=type_base+nt-bc; { bc should be zero ...}
186 end
187 else char_base:=6+lh-bc;
188 @z
189
190 @x [24] l.517 - pTeX: define glue_base
191 kern_base:=lig_kern_base+nl;
192 exten_base:=kern_base+nk;
193 param_base:=exten_base+ne-1;
194 @y
195 kern_base:=lig_kern_base+nl;
196 exten_base:=kern_base+nk;
197 glue_base:=exten_base;
198 param_base:=exten_base+ne-1;
199 @z
200
201 @x [25] l.529 - pTeX: must change check_sum from macro (=24) to variable
202 @d check_sum=24
203 @d design_size=check_sum+4
204 @d scheme=design_size+4
205 @d family=scheme+40
206 @d random_word=family+20
207 @y
208 @d check_sum==check_sum_value
209 @d design_size==check_sum+4
210 @d scheme==design_size+4
211 @d family==scheme+40
212 @d random_word==family+20
213 @z
214
215 @x [25] l.549 - pTeX: add definition of glue macro
216 @d kern(#)==4*(kern_base+#) {here \#\ is an index, not a character}
217 @y
218 @d kern(#)==4*(kern_base+#) {here \#\ is an index, not a character}
219 @d glue(#)==4*(glue_base+#) {likewise}
220 @z
221
222 @x [57] l.982 - pTeX: SEVENBITSAFEFLAG
223 if (lh>17) and (tfm[random_word]>127) then
224 @y
225 if (lh>17) and (tfm[random_word]>127) and (file_format=tfm_format) then
226 @z
227
228 @x [63] l.1003 - pTeX: Name of parameter for kanji-font
229 else if (i<=13)and(font_type=mathex) then
230 if i=8 then out('DEFAULTRULETHICKNESS')
231 else out('BIGOPSPACING',i-8:1)
232 else out('PARAMETER D ',i:1)
233 @y
234 else if (i<=13)and(font_type=mathex) then
235 if i=8 then out('DEFAULTRULETHICKNESS')
236 else out('BIGOPSPACING',i-8:1)
237 else if (i<=9)and(file_format<>tfm_format) then
238 if i=8 then out('EXTRASTRETCH')
239 else out('EXTRASHRINK')
240 else out('PARAMETER D ',i:1)
241 @z
242
243 @x [64] l.1027 - pTeX: Add printing of newline at end of program
244 if nk>0 then for i:=0 to nk-1 do check_fix(kern(i))('Kern');
245 @.Kern n is too big@>
246 @y
247 if nk>0 then for i:=0 to nk-1 do check_fix(kern(i))('Kern');
248 @.Kern n is too big@>
249 if file_format<>tfm_format then
250 begin if ng>0 then for i:=0 to ng-1 do check_fix(glue(i))('Glue');
251 @.Glue n is too big@>
252 end;
253 @z
254
255 @x [68] l.1068 - pTeX: we print GLUEKERN instead of LIGTABLE
256 begin left; out('LIGTABLE'); out_ln;@/
257 @y
258 begin left;
259 if file_format<>tfm_format then out('GLUEKERN') else out('LIGTABLE');
260 out_ln;@/
261 @z
262
263 @x [68] l.1075 - pTeX: no need to check for loop
264 @<Check for ligature cycles@>;
265 @y
266 if file_format=tfm_format then begin @<Check for ligature cycles@>; end;
267 @z
268
269 @x [69] l.1090 - pTeX: we print Glue/kern instead of Ligature/kern
270 print('Ligature/kern starting index for character '); print_octal(c);
271 print_ln(' is too large;'); print_ln('so I removed it.'); reset_tag(c);
272 @.Ligature/kern starting index...@>
273 @y
274 case file_format of
275 tfm_format: print('Ligature/kern ');
276 @.Ligature/kern starting index...@>
277 jfm_format,vfm_format: print('Glue/kern ');
278 @.Glue/kern starting index...@>
279 end;
280 print('starting index for character '); print_octal(c);
281 print_ln(' is too large;'); print_ln('so I removed it.'); reset_tag(c);
282 @z
283
284 @x [76] l.1179 - pTeX: if kanji format, output a glue step not a ligature step
285 else @<Output a ligature step@>;
286 @y
287 else if file_format<>tfm_format then @<Output a glue step@>
288 else @<Output a ligature step@>;
289 @z
290
291 @x [78] l.1238 - pTeX:
292 for c:=bc to ec do if width_index(c)>0 then
293 @y
294 for c:=bc to ec do
295 if width_index(c)=0 then
296 begin if file_format<>tfm_format then
297 bad('width index of type ',c:1,' is zero!!')
298 end
299 else if width_index(c)>0 then
300 @z
301
302 @x [78] l.1246 - pTeX: the 'character' table is really the 'type' table
303 left; out('CHARACTER'); out_char(c); out_ln;
304 @y
305 left;
306 if file_format<>tfm_format then
307 begin out('TYPE'); tfm[0]:=c; out_octal(0,1);
308 end
309 else
310 begin out('CHARACTER'); out_char(c);
311 end;
312 out_ln;
313 @z
314
315 @x [78] l.1251 - pTeX: types can only have tags equal to 0 or 1
316 case tag(c) of
317 no_tag: do_nothing;
318 lig_tag: @<Output the applicable part of the ligature/kern
319 program as a comment@>;
320 list_tag: @<Output the character link unless there is a problem@>;
321 ext_tag: @<Output an extensible character recipe@>;
322 end; {there are no other cases}
323 right;
324 end
325 @y
326 case tag(c) of
327 no_tag: do_nothing;
328 lig_tag: @<Output the applicable part of the ligature/kern
329 program as a comment@>;
330 list_tag: if file_format<>tfm_format then
331 bad('the tag of type ',c:1,' must be 0 or 1')
332 else @<Output the character link unless there is a problem@>;
333 ext_tag: if file_format<>tfm_format then
334 bad('the tag of type ',c:1,' must be 0 or 1')
335 else @<Output an extensible character recipe@>;
336 end; {there are no other cases}
337 right;
338 end
339 @z
340
341 @x [96] l.1539 - pTeX:
342 var tfm_ptr:index; {an index into |tfm|}
343 @y
344 var tfm_ptr,tmp_ptr:index; {an index into |tfm|}
345 @z
346
347 @x [98] l.1566 - pTeX: declare kanji conversion subroutines and externals
348 @p begin initialize;@/
349 @y
350 @p
351 @<declare kanji conversion functions@>;
352 begin initialize;@/
353 @z
354
355 @x [99] l.1570 - pTeX: don't check extensible recipes and list the char_type table
356 @<Check the extensible recipes@>;
357 @y
358 if file_format<>tfm_format then
359 begin @<list |char_type| table@>;
360 end
361 else
362 begin @<Check the extensible recipes@>;
363 end;
364 @z
365
366 @x
367 const n_options = 4; {Pascal won't count array lengths for us.}
368 @y
369 const n_options = 6; {Pascal won't count array lengths for us.}
370 @z
371
372 @x
373 usage_help (TFTOPL_HELP, nil);
374 @y
375 usage_help (UPTFTOPL_HELP, 'issue@@texjp.org');
376 @z
377
378 @x
379 end; {Else it was a flag; |getopt| has already done the assignment.}
380 @y
381 end else if argument_is ('kanji') then begin
382 if (not set_enc_string(optarg,optarg)) then
383 print_ln('Bad kanji encoding "', stringcast(optarg), '".');
384
385 end; {Else it was a flag; |getopt| has already done the assignment.}
386 @z
387
388 @x
389 @ An element with all zeros always ends the list.
390 @y
391 @ Kanji option.
392 @.-kanji@>
393
394 @<Define the option...@> =
395 long_options[current_option].name := 'kanji';
396 long_options[current_option].has_arg := 1;
397 long_options[current_option].flag := 0;
398 long_options[current_option].val := 0;
399 incr(current_option);
400
401 @ An element with all zeros always ends the list.
402 @z
403
404 @x [99] l.1751 - pTeX:
405 @* Index.
406 @y
407 @* For Japanese Font Metric routines. % pTeX:
408 We need to include some routines for handling kanji character.
409
410 @d max_kanji=@"2FFFFF {number of the kanji characters - 1}
411
412 @<Glob...@>=
413 @!this_code:integer; {to hold jis code of the current kanji character}
414 @!this_type:integer; {to hold |char_type| of the current kanji character}
415 @!type_index:integer; {index into |char_type| table}
416 @!type_num:integer; {index into |char_info| table}
417 @!type_count:integer; {number of chars with the same type}
418 @!kanji_index:integer; {index into |kanji_type| array}
419 @!kanji_type:array[0..max_kanji] of -1..255; {kanji type index}
420
421 @ @<Output a glue step@>=
422 begin if nonexistent(tfm[k+1]) then if tfm[k+1]<>boundary_char then
423 correct_bad_char('Glue step for')(k+1);
424 @.Glue step for nonexistent...@>
425 left; out('GLUE'); out_char(tfm[k+1]);
426 r:=3*(256*tfm[k+2]+tfm[k+3]);
427 if r>=ng then
428 begin bad('Glue index too large.');
429 @.Glue index too large@>
430 out(' R 0.0 R 0.0 R 0.0');
431 end
432 else begin out_fix(glue(r));
433 out_fix(glue(r+1));
434 out_fix(glue(r+2));
435 end;
436 right;
437 end
438
439 @ list the |char_type| table in a similar way to the type table.
440 The code is based on the new JFM spec by texjporg.
441
442 @d char_type(#)==4*(type_base+#) {here \#\ is an index, not a character}
443 @d JIS_code(#)==tfm[char_type(#)+0]*@'400+tfm[char_type(#)+1]+tfm[char_type(#)+2]*@'400*@'400 {JIS code from |char_type| table}
444 @d JIS_type(#)==tfm[char_type(#)+3] {JIS type from |char_type| table}
445
446 @<list |char_type| table@>=
447 this_code:=JIS_code(0);
448 this_type:=JIS_type(0);
449 if (this_code<>0)or(this_type<>0) then
450 begin bad('the first entry in char_type is not zero. I''ll zero it.');
451 print_ln('JIS code is ', this_code:1, '. Type is ', this_type:1, '.');
452 end;
453 for kanji_index:=0 to max_kanji do kanji_type[kanji_index]:=-1;
454 for type_index:=1 to nt-1 do
455 begin this_code:=JIS_code(type_index);
456 this_type:=JIS_type(type_index);
457 if not valid_jis_code(this_code) then
458 bad('jis code ', this_code:1,
459 ' in char_type table entry ', type_index:1,
460 ' is not valid. Ignoring it.')
461 else if (this_type <= 0) or (this_type > ec) then
462 bad('type ', this_type:1, ' of jis code ', this_code:1,
463 ' in char_type table is not valid. Ignoring character.')
464 else
465 kanji_type[jis_to_index(this_code)] := this_type;
466 end;
467 @#
468 for type_num:=1 to ec do
469 begin left; out('CHARSINTYPE');
470 tfm[0]:=type_num; out_octal(0,1);
471 type_count:=0;
472 for kanji_index:=0 to max_kanji do
473 if kanji_type[kanji_index]=type_num then
474 begin if (type_count mod 10)=0 then out_ln else out(' ');
475 incr(type_count);
476 out_kanji(index_to_jis(kanji_index));
477 end;
478 if type_count=0 then bad('type ', type_num:1, ' has no characters in it!');
479 out_ln; right;
480 end;
481
482 @ Some subroutines to handle kanji codes and i/o
483
484 @<Globals...@>=
485 @!xchr:array[char] of byte; {specifiles conversion of output charcter}
486
487 @ @<Set init...@>=
488 for k:=@'0 to @'37 do xchr[k]:='?';
489 for k:=@'40 to 255 do xchr[k]:=k;
490
491 @ @<declare kanji conversion functions@>=
492 procedure out_kanji(jis_code:integer); { prints a kanji character }
493 var @!cx,@!v,@!nn,@!jj:integer; {KANJI code}
494 i:0..5; {index of array}
495 begin@/
496 if (charcode_format=charcode_octal)or(jis_code<128) then
497 begin cx:=jis_code;
498 if (isinternalUPTEX) then out('U ')
499 else out('J '); {specify jiscode format}
500 dig[0]:=(cx div 65536) div 16; dig[1]:=(cx div 65536) mod 16;
501 dig[2]:=(cx div 4096) mod 16; dig[3]:=(cx div 256) mod 16;
502 dig[4]:=(cx div 16) mod 16; dig[5]:=cx mod 16;
503 for i:=0 to 1 do
504 if (dig[i]<>0)or(dig[0]<>0) then begin { if dig[0]<>0, dig[1] should be always printed }
505 if dig[i]<10 then out(dig[i]) else
506 case dig[i] of
507 10: out('A'); 11: out('B'); 12: out('C');
508 13: out('D'); 14: out('E'); 15: out('F');
509 end;
510 end;
511 for i:=2 to 5 do
512 if dig[i]<10 then out(dig[i]) else
513 case dig[i] of
514 10: out('A'); 11: out('B'); 12: out('C');
515 13: out('D'); 14: out('E'); 15: out('F');
516 end;
517 end
518 else begin
519 if (isinternalUPTEX) then begin
520 cx:=fromDVI(jis_code);
521 nn:=UVSgetcodepointlength(cx);
522 jj:=1;
523 while jj<=nn do begin
524 v:=UVSgetcodepointinsequence(cx,jj);
525 if (v>0) then begin
526 v:=UCStoUTF8(v);
527 if BYTE1(v)<>0 then out(xchr[BYTE1(v)]);
528 if BYTE2(v)<>0 then out(xchr[BYTE2(v)]);
529 if BYTE3(v)<>0 then out(xchr[BYTE3(v)]);
530 out(xchr[BYTE4(v)]);
531 end;
532 incr(jj);
533 end
534 end
535 else begin
536 cx:=toBUFF(fromDVI(jis_code));
537 if BYTE1(cx)<>0 then out(xchr[BYTE1(cx)]);
538 if BYTE2(cx)<>0 then out(xchr[BYTE2(cx)]);
539 if BYTE3(cx)<>0 then out(xchr[BYTE3(cx)]);
540 out(xchr[BYTE4(cx)]);
541 end;
542 end;
543 end;
544
545 @ @<declare kanji conversion functions@>=
546 function valid_jis_code(cx:integer):boolean;
547 begin valid_jis_code:=true;
548 if (cx>max_kanji)or(not is_char_kanji(fromDVI(cx)))
549 or(toDVI(fromDVI(cx))<>cx) then valid_jis_code:=false;
550 end;
551
552 @ @<declare kanji conversion functions@>=
553 function index_to_jis(ix:integer):integer;
554 begin
555 index_to_jis:=ix;
556 end;
557
558 @ @<declare kanji conversion functions@>=
559 function jis_to_index(cx:integer):integer;
560 begin
561 jis_to_index:=cx;
562 end
563
564 @* Index.
565 @z