| 1 |
@x |
| 2 |
\def\MP{MetaPost} |
| 3 |
@y |
| 4 |
\def\MP{MetaPost} |
| 5 |
\def\pTeX{p\kern-.15em\TeX} |
| 6 |
@z |
| 7 |
|
| 8 |
@x |
| 9 |
#include "avl.h" |
| 10 |
@y |
| 11 |
#include "avl.h" |
| 12 |
#include <ptexenc/ptexenc.h> |
| 13 |
@z |
| 14 |
|
| 15 |
@x |
| 16 |
@d virtual_space 1000000 /* maximum total bytes of typesetting commands for virtual fonts */ |
| 17 |
@d max_fonts 1000 /* maximum number of distinct fonts per \.{DVI} file */ |
| 18 |
@d max_fnums 3000 /* maximum number of fonts plus fonts local to virtual fonts */ |
| 19 |
@d max_widths (256*max_fonts) /* maximum number of different characters among all fonts */ |
| 20 |
@d line_length 79 /* maximum output line length (must be at least 60) */ |
| 21 |
@d stack_size 100 /* \.{DVI} files shouldn't |push| beyond this depth */ |
| 22 |
@d font_tolerance 0.00001 |
| 23 |
@y |
| 24 |
@ @<Glob...@>= |
| 25 |
#ifdef UPMP |
| 26 |
#define virtual_space 2000000 /* maximum total bytes of typesetting commands for virtual fonts */ |
| 27 |
#else |
| 28 |
#define virtual_space 1000000 /* maximum total bytes of typesetting commands for virtual fonts */ |
| 29 |
#endif |
| 30 |
#define max_fonts 1000 /* maximum number of distinct fonts per \.{DVI} file */ |
| 31 |
#define max_fnums 3000 /* maximum number of fonts plus fonts local to virtual fonts */ |
| 32 |
#ifdef UPMP |
| 33 |
#define max_widths 2000000 /* maximum number of different characters among all fonts */ |
| 34 |
#else |
| 35 |
#define max_widths 512000 /* maximum number of different characters among all fonts */ |
| 36 |
#endif |
| 37 |
#define line_length 79 /* maximum output line length (must be at least 60) */ |
| 38 |
#define stack_size 100 /* \.{DVI} files shouldn't |push| beyond this depth */ |
| 39 |
#define font_tolerance 0.00001 |
| 40 |
@z |
| 41 |
|
| 42 |
@x |
| 43 |
@d undefined_commands 250: case 251: case 252: case 253: case 254: case 255 |
| 44 |
@y |
| 45 |
@d dir 255 /* \pTeX\ direction */ |
| 46 |
@d undefined_commands 250: case 251: case 252: case 253: case 254 |
| 47 |
@z |
| 48 |
|
| 49 |
@x |
| 50 |
mpx_read_tfm_word(mpx); lh=mpx->b2*(int)(256)+mpx->b3; |
| 51 |
@y |
| 52 |
mpx_read_tfm_word(mpx); |
| 53 |
@<Read the pTeX header data@>;@/ |
| 54 |
lh=mpx->b2*(int)(256)+mpx->b3; |
| 55 |
@z |
| 56 |
|
| 57 |
@x |
| 58 |
if ( mpx->b0<128 ) |
| 59 |
mpx->tfm_check_sum=((mpx->b0*(int)(256)+mpx->b1)*256+mpx->b2)*256+mpx->b3; |
| 60 |
else |
| 61 |
mpx->tfm_check_sum=(((mpx->b0-256)*(int)(256)+mpx->b1)*256+mpx->b2)*256+mpx->b3; |
| 62 |
} |
| 63 |
if ( k==5 ) { |
| 64 |
if (mpx->mode == mpx_troff_mode) { |
| 65 |
mpx->font_design_size[f]=(((mpx->b0*(int)(256)+mpx->b1)*256+mpx->b2)*256+mpx->b3)/(65536.0*16); |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
@y |
| 70 |
if ( mpx->b0<128 ) |
| 71 |
mpx->tfm_check_sum=((mpx->b0*(int)(256)+mpx->b1)*256+mpx->b2)*256+mpx->b3; |
| 72 |
else |
| 73 |
mpx->tfm_check_sum=(((mpx->b0-256)*(int)(256)+mpx->b1)*256+mpx->b2)*256+mpx->b3; |
| 74 |
} |
| 75 |
if ( k==5 ) { |
| 76 |
if (mpx->mode == mpx_troff_mode) { |
| 77 |
mpx->font_design_size[f]=(((mpx->b0*(int)(256)+mpx->b1)*256+mpx->b2)*256+mpx->b3)/(65536.0*16); |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
@<Read JFM character type table@>; |
| 82 |
@z |
| 83 |
|
| 84 |
@x |
| 85 |
@<Width of character |c| in font |f|@>= |
| 86 |
floor(mpx->dvi_scale*mpx->font_scaled_size[f]*char_width(f,c)) |
| 87 |
|
| 88 |
@ @<Width of character |p| in font |cur_font|@>= |
| 89 |
floor(mpx->dvi_scale*mpx->font_scaled_size[cur_font]*char_width(cur_font,p)) |
| 90 |
@y |
| 91 |
@ @c @<Declare JFM character type table lookup routine@>@; /* \pTeX */ |
| 92 |
static integer mpx_scaled_char_width (MPX mpx,integer f,integer c) |
| 93 |
{ |
| 94 |
if (mpx->font_id[f]!=0) c=mpx_lookup_ctype(mpx, f,c); |
| 95 |
return floor(mpx->dvi_scale*mpx->font_scaled_size[f]*char_width(f,c)); |
| 96 |
} |
| 97 |
@z |
| 98 |
|
| 99 |
@x |
| 100 |
@ @c @<Declare a procedure called |finish_last_char|@>@; |
| 101 |
static void mpx_do_set_char (MPX mpx,web_integer f, web_integer c) { |
| 102 |
if ( (c<mpx->font_bc[f])||(c>mpx->font_ec[f]) ) |
| 103 |
mpx_abort(mpx,"attempt to typeset invalid character %d",c); |
| 104 |
@.attempt to typeset...@> |
| 105 |
@y |
| 106 |
@ (u)pDVItoMP: |do_set_char| is called with non-virtual font. |
| 107 |
In the case of non-virtual Kanji font, the width is looked up |
| 108 |
with the character type, and the character is printed by the |
| 109 |
function |set_kanji_char|. |
| 110 |
|
| 111 |
When the width written in the virtual font is same as |
| 112 |
the width of the substituted font, the next character can be |
| 113 |
written in the same string in output mpx file. |
| 114 |
In other words, the width of the character is calculated |
| 115 |
in |do_dvi_commands|. So even if the width is wrong here, the output PostScript file is not affected. |
| 116 |
|
| 117 |
@ @c @<Declare a procedure called |finish_last_char|@>@; |
| 118 |
static void mpx_do_set_char (MPX mpx,integer f,integer c) |
| 119 |
{ |
| 120 |
integer kkk; |
| 121 |
|
| 122 |
if (mpx->font_id[f]!=0) { |
| 123 |
kkk=mpx_lookup_ctype(mpx, f,c); |
| 124 |
if ( (kkk<mpx->font_bc[f]) || (kkk>mpx->font_ec[f]) ) |
| 125 |
mpx_abort(mpx,"attempt to typeset invalid character (JFM) %d",c); |
| 126 |
} else if ( (c<mpx->font_bc[f])||(c>mpx->font_ec[f]) ) { |
| 127 |
mpx_abort(mpx,"attempt to typeset invalid character %d",c); |
| 128 |
} |
| 129 |
@.attempt to typeset...@> |
| 130 |
@z |
| 131 |
|
| 132 |
@x |
| 133 |
if ((mpx->h!=mpx->str_h2)||(mpx->v!=mpx->str_v)|| |
| 134 |
(f!=mpx->str_f)||(mpx->dvi_scale!=mpx->str_scale) ) { |
| 135 |
@y |
| 136 |
if ((mpx->h!=mpx->str_h2)||(mpx->v!=mpx->str_v2)|| |
| 137 |
(f!=mpx->str_f)||(mpx->dvi_scale!=mpx->str_scale) ) { |
| 138 |
@z |
| 139 |
|
| 140 |
@x |
| 141 |
fprintf(mpx->mpxfile,"_s("); mpx->print_col=3;@/ |
| 142 |
mpx->str_scale=mpx->dvi_scale; mpx->str_f=f; |
| 143 |
mpx->str_v=mpx->v; mpx->str_h1=mpx->h; |
| 144 |
@y |
| 145 |
if ((mpx->d==0) || (mpx->font_id[f]==9)) { |
| 146 |
fprintf(mpx->mpxfile,"_s("); mpx->print_col=3;}@/ |
| 147 |
else { |
| 148 |
fprintf(mpx->mpxfile,"_sr("); mpx->print_col=4;}@/ |
| 149 |
mpx->str_scale=mpx->dvi_scale; mpx->str_f=f; |
| 150 |
mpx->str_v1=mpx->v; mpx->str_h1=mpx->h; |
| 151 |
@z |
| 152 |
|
| 153 |
@x |
| 154 |
mpx_print_char(mpx, (unsigned char)c); |
| 155 |
mpx->str_h2=(web_integer)(mpx->h+@<Width of character |c| in font |f|@>); |
| 156 |
@y |
| 157 |
if (mpx->font_id[f]!=0) |
| 158 |
mpx_print_kanji_char(mpx, c); |
| 159 |
else |
| 160 |
mpx_print_char(mpx, c); |
| 161 |
if (mpx->d==0) { |
| 162 |
mpx->str_h2=mpx->h+mpx_scaled_char_width(mpx, f, c); |
| 163 |
mpx->str_v2=mpx->v; |
| 164 |
} else { |
| 165 |
mpx->str_h2=mpx->h; |
| 166 |
mpx->str_v2=mpx->v+mpx_scaled_char_width(mpx, f, c); |
| 167 |
} |
| 168 |
@z |
| 169 |
|
| 170 |
@x |
| 171 |
web_integer str_h1; |
| 172 |
web_integer str_v; /* starting position for current output string */ |
| 173 |
web_integer str_h2; /* where the current output string ends */ |
| 174 |
@y |
| 175 |
integer str_h1; |
| 176 |
integer str_v1; /* starting position for current output string */ |
| 177 |
integer str_h2; |
| 178 |
integer str_v2; /* where the current output string ends */ |
| 179 |
@z |
| 180 |
|
| 181 |
@x |
| 182 |
fprintf(mpx->mpxfile,"vardef _s(expr _t,_f,_m,_x,_y)(text _c)=\n"); |
| 183 |
fprintf(mpx->mpxfile, |
| 184 |
" addto _p also _t infont _f scaled _m shifted (_x,_y) _c; enddef;\n"); |
| 185 |
@y |
| 186 |
fprintf(mpx->mpxfile,"vardef _s(expr _t,_f,_m,_x,_y)(text _c)=\n"); |
| 187 |
fprintf(mpx->mpxfile, |
| 188 |
" addto _p also _t infont _f scaled _m shifted (_x,_y) _c; enddef;\n"); |
| 189 |
fprintf(mpx->mpxfile,"vardef _sr(expr _t,_f,_m,_x,_y)=\n"); |
| 190 |
fprintf(mpx->mpxfile," addto _p also _t infont _f rotated -90"); |
| 191 |
fprintf(mpx->mpxfile," scaled _m shifted (_x,_y); enddef;\n"); |
| 192 |
@z |
| 193 |
|
| 194 |
@x |
| 195 |
x=mpx->conv*mpx->str_h1; |
| 196 |
y=mpx->conv*(-mpx->str_v); |
| 197 |
@y |
| 198 |
x=mpx->conv*mpx->str_h1; |
| 199 |
y=mpx->conv*(-mpx->str_v1); |
| 200 |
@z |
| 201 |
|
| 202 |
@x |
| 203 |
@<Handle a special rule that determines the box size@>= |
| 204 |
{ |
| 205 |
mpx->pic_wd=mpx->h; mpx->pic_dp=mpx->v; mpx->pic_ht=ht-mpx->v; |
| 206 |
} |
| 207 |
@y |
| 208 |
@<Handle a special rule that determines the box size@>= |
| 209 |
{ if (mpx->d==0) { |
| 210 |
mpx->pic_wd=mpx->h; mpx->pic_dp=mpx->v; mpx->pic_ht=ht-mpx->v; |
| 211 |
} else { |
| 212 |
mpx->pic_wd=mpx->v; mpx->pic_dp=-mpx->h; mpx->pic_ht=ht+mpx->h; |
| 213 |
} |
| 214 |
} |
| 215 |
@z |
| 216 |
|
| 217 |
@x |
| 218 |
mpx->str_v=0; |
| 219 |
mpx->str_h2=0; |
| 220 |
mpx->str_scale=1.0; /* values don't matter */ |
| 221 |
@y |
| 222 |
mpx->str_h2=0; |
| 223 |
mpx->str_v2=0; |
| 224 |
mpx->str_scale=1.0; /* values don't matter */ |
| 225 |
@z |
| 226 |
|
| 227 |
@x |
| 228 |
dd=-mpx->pic_dp*mpx->conv; |
| 229 |
w=mpx->conv*mpx->pic_wd; |
| 230 |
h=mpx->conv*mpx->pic_ht; |
| 231 |
fprintf(mpx->mpxfile, |
| 232 |
"setbounds _p to (0,%1.4f)--(%1.4f,%1.4f)--\n" |
| 233 |
" (%1.4f,%1.4f)--(0,%1.4f)--cycle;\n",dd,w,dd,w,h,h) |
| 234 |
@y |
| 235 |
if (mpx->d==0) { |
| 236 |
dd=-mpx->pic_dp*mpx->conv; |
| 237 |
w=mpx->conv*mpx->pic_wd; |
| 238 |
h=mpx->conv*mpx->pic_ht; |
| 239 |
fprintf(mpx->mpxfile, |
| 240 |
"setbounds _p to (0,%1.4f)--(%1.4f,%1.4f)--\n",dd,w,dd); |
| 241 |
fprintf(mpx->mpxfile, |
| 242 |
" (%1.4f,%1.4f)--(0,%1.4f)--cycle;\n",w,h,h); |
| 243 |
} else { |
| 244 |
dd=-mpx->pic_dp*mpx->conv; |
| 245 |
w=-mpx->pic_wd*mpx->conv; |
| 246 |
h=mpx->conv*mpx->pic_ht; |
| 247 |
fprintf(mpx->mpxfile, |
| 248 |
"setbounds _p to (%1.4f,0)--(%1.4f,%1.4f)--\n",h,h,w); |
| 249 |
fprintf(mpx->mpxfile, |
| 250 |
" (%1.4f,%1.4f)--(%1.4f,0)--cycle;\n", dd,w,dd); |
| 251 |
} |
| 252 |
@z |
| 253 |
|
| 254 |
@x |
| 255 |
web_integer w;web_integer x;web_integer y;web_integer z; |
| 256 |
/* current state values (|h| and |v| have already been declared) */ |
| 257 |
web_integer hstack[(stack_size+1)]; |
| 258 |
web_integer vstack[(stack_size+1)]; |
| 259 |
web_integer wstack[(stack_size+1)]; |
| 260 |
web_integer xstack[(stack_size+1)]; |
| 261 |
web_integer ystack[(stack_size+1)]; |
| 262 |
web_integer zstack[(stack_size+1)]; /* pushed down values in \.{DVI} units */ |
| 263 |
@y |
| 264 |
integer w;integer x;integer y;integer z;integer d; |
| 265 |
/* current state values (|h| and |v| have already been declared) */ |
| 266 |
integer hstack[(stack_size+1)]; |
| 267 |
integer vstack[(stack_size+1)]; |
| 268 |
integer wstack[(stack_size+1)]; |
| 269 |
integer xstack[(stack_size+1)]; |
| 270 |
integer ystack[(stack_size+1)]; |
| 271 |
integer zstack[(stack_size+1)]; |
| 272 |
integer dstack[(stack_size+1)]; /* pushed down values in \.{DVI} units */ |
| 273 |
@z |
| 274 |
|
| 275 |
@x |
| 276 |
mpx->h=0; mpx->v=0; |
| 277 |
@y |
| 278 |
mpx->h=0; mpx->v=0; mpx->d=0; |
| 279 |
@z |
| 280 |
|
| 281 |
@x |
| 282 |
mpx->hstack[mpx->stk_siz]=mpx->h; |
| 283 |
mpx->vstack[mpx->stk_siz]=mpx->v; mpx->wstack[mpx->stk_siz]=mpx->w; |
| 284 |
mpx->xstack[mpx->stk_siz]=mpx->x; |
| 285 |
mpx->ystack[mpx->stk_siz]=mpx->y; mpx->zstack[mpx->stk_siz]=mpx->z; |
| 286 |
@y |
| 287 |
mpx->hstack[mpx->stk_siz]=mpx->h; |
| 288 |
mpx->vstack[mpx->stk_siz]=mpx->v; mpx->wstack[mpx->stk_siz]=mpx->w; |
| 289 |
mpx->xstack[mpx->stk_siz]=mpx->x; |
| 290 |
mpx->ystack[mpx->stk_siz]=mpx->y; mpx->zstack[mpx->stk_siz]=mpx->z; |
| 291 |
mpx->dstack[mpx->stk_siz]=mpx->d; |
| 292 |
@z |
| 293 |
|
| 294 |
@x |
| 295 |
mpx->h=mpx->hstack[mpx->stk_siz]; |
| 296 |
mpx->v=mpx->vstack[mpx->stk_siz]; mpx->w=mpx->wstack[mpx->stk_siz]; |
| 297 |
mpx->x=mpx->xstack[mpx->stk_siz]; |
| 298 |
mpx->y=mpx->ystack[mpx->stk_siz]; mpx->z=mpx->zstack[mpx->stk_siz]; |
| 299 |
@y |
| 300 |
mpx->h=mpx->hstack[mpx->stk_siz]; |
| 301 |
mpx->v=mpx->vstack[mpx->stk_siz]; mpx->w=mpx->wstack[mpx->stk_siz]; |
| 302 |
mpx->x=mpx->xstack[mpx->stk_siz]; |
| 303 |
mpx->y=mpx->ystack[mpx->stk_siz]; mpx->z=mpx->zstack[mpx->stk_siz]; |
| 304 |
mpx->d=mpx->dstack[mpx->stk_siz]; |
| 305 |
@z |
| 306 |
|
| 307 |
@x |
| 308 |
case z0: return mpx->z; break; |
| 309 |
@y |
| 310 |
case z0: return mpx->z; break; |
| 311 |
case dir: return mpx_get_byte(mpx); break; |
| 312 |
@z |
| 313 |
|
| 314 |
@x |
| 315 |
mpx->h += @<Width of character |p| in font |cur_font|@>; |
| 316 |
@y |
| 317 |
if (mpx->d==0) { |
| 318 |
mpx->h+=mpx_scaled_char_width(mpx, cur_font, p); |
| 319 |
} else { |
| 320 |
mpx->v+=mpx_scaled_char_width(mpx, cur_font, p); |
| 321 |
} |
| 322 |
@z |
| 323 |
|
| 324 |
@x |
| 325 |
mpx->h += q; |
| 326 |
@y |
| 327 |
if (mpx->d==0) { |
| 328 |
mpx->h += q; |
| 329 |
} else { |
| 330 |
mpx->v += q; |
| 331 |
} |
| 332 |
@z |
| 333 |
|
| 334 |
@x |
| 335 |
case pop: |
| 336 |
mpx_do_pop(mpx); |
| 337 |
break; |
| 338 |
@y |
| 339 |
case pop: |
| 340 |
mpx_do_pop(mpx); |
| 341 |
break; |
| 342 |
case dir: |
| 343 |
mpx->d=p; |
| 344 |
break; |
| 345 |
@z |
| 346 |
|
| 347 |
@x |
| 348 |
case four_cases(right1): |
| 349 |
mpx->h += trunc(p*mpx->dvi_scale); |
| 350 |
break; |
| 351 |
case w0: case four_cases(w1): |
| 352 |
mpx->w = (web_integer)trunc(p*mpx->dvi_scale); mpx->h += mpx->w; |
| 353 |
break; |
| 354 |
case x0: case four_cases(x1): |
| 355 |
mpx->x = (web_integer)trunc(p*mpx->dvi_scale); mpx->h += mpx->x; |
| 356 |
break; |
| 357 |
case four_cases(down1): |
| 358 |
mpx->v += trunc(p*mpx->dvi_scale); |
| 359 |
break; |
| 360 |
case y0: case four_cases(y1): |
| 361 |
mpx->y = (web_integer)trunc(p*mpx->dvi_scale); mpx->v += mpx->y; |
| 362 |
break; |
| 363 |
case z0: case four_cases(z1): |
| 364 |
mpx->z = (web_integer)trunc(p*mpx->dvi_scale); mpx->v += mpx->z; |
| 365 |
break; |
| 366 |
@y |
| 367 |
case four_cases(right1): |
| 368 |
if (mpx->d==0) { |
| 369 |
mpx->h+=trunc(p*mpx->dvi_scale); |
| 370 |
} else { |
| 371 |
mpx->v+=trunc(p*mpx->dvi_scale); |
| 372 |
} |
| 373 |
break; |
| 374 |
case w0: case four_cases(w1): |
| 375 |
if (mpx->d==0) { |
| 376 |
mpx->h+=mpx->w; |
| 377 |
} else { |
| 378 |
mpx->v+=mpx->w; |
| 379 |
} |
| 380 |
break; |
| 381 |
case x0: case four_cases(x1): |
| 382 |
if (mpx->d==0) { |
| 383 |
mpx->h+=mpx->x; |
| 384 |
} else { |
| 385 |
mpx->v+=mpx->x; |
| 386 |
} |
| 387 |
break; |
| 388 |
case four_cases(down1): |
| 389 |
if (mpx->d==0) { |
| 390 |
mpx->v+=trunc(p*mpx->dvi_scale); |
| 391 |
} else { |
| 392 |
mpx->h-=trunc(p*mpx->dvi_scale); |
| 393 |
} |
| 394 |
break; |
| 395 |
case y0: case four_cases(y1): |
| 396 |
if (mpx->d==0) { |
| 397 |
mpx->v+=mpx->y; |
| 398 |
} else { |
| 399 |
mpx->h-=mpx->y; |
| 400 |
} |
| 401 |
break; |
| 402 |
case z0: case four_cases(z1): |
| 403 |
if (mpx->d==0) { |
| 404 |
mpx->v+=mpx->z; |
| 405 |
} else { |
| 406 |
mpx->h-=mpx->z; |
| 407 |
} |
| 408 |
break; |
| 409 |
@z |
| 410 |
|
| 411 |
@x |
| 412 |
mpx->progname = "dvitomp"; |
| 413 |
@y |
| 414 |
#ifdef UPMP |
| 415 |
mpx->progname = "updvitomp"; |
| 416 |
#else |
| 417 |
mpx->progname = "pdvitomp"; |
| 418 |
#endif |
| 419 |
@z |
| 420 |
|
| 421 |
@x |
| 422 |
@<Check if mp file is newer than mpxfile, exit if not@>= |
| 423 |
if (mpx_newer(mpxopt->mpname, mpxopt->mpxname)) |
| 424 |
return 0 |
| 425 |
@y |
| 426 |
@<Check if mp file is newer than mpxfile, exit if not@>= |
| 427 |
if (mpx_newer(mpxopt->mpname, mpxopt->mpxname)) |
| 428 |
return 0 |
| 429 |
|
| 430 |
@ ASCII \pTeX\ JFM ID |
| 431 |
@d yoko_jfm_id 11 /* for `yoko-kumi' fonts */ |
| 432 |
@d tate_jfm_id 9 /* for `tate-kumi' fonts */ |
| 433 |
@d font_jfm_p(A) (mpx->font_id[(A)]!=0) |
| 434 |
|
| 435 |
@ @<Global...@>= |
| 436 |
integer font_nt[max_fonts+1]; /* number of words in ctype table */ |
| 437 |
integer font_id[max_fonts+1]; |
| 438 |
integer jfm_char_code[max_widths+1]; |
| 439 |
integer jfm_char_type[max_widths+1]; |
| 440 |
integer jfm_char_index[max_fonts+1]; |
| 441 |
integer next_jfm_char_index; |
| 442 |
|
| 443 |
@ @<Set init...@>= |
| 444 |
mpx->font_nt[0]=0; |
| 445 |
mpx->font_id[0]=0; |
| 446 |
mpx->jfm_char_type[0]=0; |
| 447 |
mpx->next_jfm_char_index=0; |
| 448 |
|
| 449 |
@ JFM character type table is stored in the array |jfm_char_code| and |
| 450 |
|jfm_char_type|. The character code and the character type of $i$-th |
| 451 |
record is stored in |jfm_char_code[i]| and |jfm_char_type[i]|, respectively. |
| 452 |
The table is in the order of character code. |
| 453 |
|
| 454 |
@<Read the pTeX header data@>= |
| 455 |
mpx->font_id[f]=mpx->b0*(int)(256)+mpx->b1; |
| 456 |
if ((mpx->font_id[f]==yoko_jfm_id) || (mpx->font_id[f]==tate_jfm_id)) { |
| 457 |
mpx->font_nt[f]=mpx->b2*(int)(256)+mpx->b3; |
| 458 |
mpx_read_tfm_word(mpx); |
| 459 |
} else { |
| 460 |
mpx->font_id[f]=0; |
| 461 |
mpx->font_nt[f]=0; |
| 462 |
} |
| 463 |
|
| 464 |
@ @<Read JFM character type table@>= |
| 465 |
mpx->jfm_char_index[f]=mpx->next_jfm_char_index; |
| 466 |
k=mpx->jfm_char_index[f]; |
| 467 |
mpx->next_jfm_char_index+=mpx->font_nt[f]; |
| 468 |
while (k<mpx->next_jfm_char_index) { |
| 469 |
mpx_read_tfm_word(mpx); |
| 470 |
mpx->jfm_char_code[k]=mpx->b0*(int)(256)+mpx->b1; |
| 471 |
mpx->jfm_char_type[k]=mpx->b2*(int)(256)+mpx->b3; |
| 472 |
k++; |
| 473 |
} |
| 474 |
|
| 475 |
@ JFM character type table is looked up by binary search. |
| 476 |
|
| 477 |
@<Declare JFM character type table lookup routine@>= |
| 478 |
static integer mpx_lookup_ctype (MPX mpx,integer f, integer c) |
| 479 |
{ |
| 480 |
integer l, u, r, ch; |
| 481 |
l=0; u=mpx->font_nt[f]-1; |
| 482 |
while (l<u) { |
| 483 |
r=(l+u)/2; |
| 484 |
ch=mpx->jfm_char_code[mpx->jfm_char_index[f]+r]; |
| 485 |
if (ch==c) { |
| 486 |
return mpx->jfm_char_type[mpx->jfm_char_index[f]+r]; |
| 487 |
} |
| 488 |
if (ch<c) |
| 489 |
l=r+1; |
| 490 |
else |
| 491 |
u=r-1; |
| 492 |
} |
| 493 |
return 0; |
| 494 |
} |
| 495 |
|
| 496 |
@ All Kanji characters are supposed to be printable here, |
| 497 |
so that the state always results in normal at the end of the procedure. |
| 498 |
Kanji characters need to be converted into output Kanji encoding |
| 499 |
from DVI(JIS). |
| 500 |
|
| 501 |
@<Declare subroutines for printing strings@>= |
| 502 |
static void mpx_print_kanji_char (MPX mpx,integer c) |
| 503 |
{ |
| 504 |
#ifdef UPMP |
| 505 |
#define BYTE1(x) (((x)>>24) & 0xff) |
| 506 |
#define BYTE2(x) (((x)>>16) & 0xff) |
| 507 |
#define BYTE3(x) (((x)>> 8) & 0xff) |
| 508 |
#define BYTE4(x) ( (x) & 0xff) |
| 509 |
int pflag = 0; |
| 510 |
#else |
| 511 |
#define Hi(x) (((x)>> 8) & 0xff) |
| 512 |
#define Lo(x) ( (x) & 0xff) |
| 513 |
#endif |
| 514 |
if (mpx->print_col+2>line_length-2 ) { |
| 515 |
if (mpx->state==normal) { |
| 516 |
fprintf(mpx->mpxfile, "\""); |
| 517 |
mpx->state=special; |
| 518 |
} |
| 519 |
fprintf(mpx->mpxfile, " \n"); |
| 520 |
mpx->print_col=0; |
| 521 |
} |
| 522 |
if (mpx->state==special) { |
| 523 |
fprintf(mpx->mpxfile,"&"); |
| 524 |
mpx->print_col++; |
| 525 |
} |
| 526 |
if (mpx->state!=normal) { |
| 527 |
fprintf(mpx->mpxfile, "\""); |
| 528 |
mpx->print_col++; |
| 529 |
mpx->state=normal; |
| 530 |
} |
| 531 |
c=toBUFF(fromDVI(c)); |
| 532 |
#ifdef UPMP |
| 533 |
if (BYTE1(c)!=0) pflag = 1; |
| 534 |
if (pflag) { |
| 535 |
putc2(BYTE1(c), mpx->mpxfile); |
| 536 |
mpx->print_col++; |
| 537 |
} |
| 538 |
if (BYTE2(c)!=0) pflag = 1; |
| 539 |
if (pflag) { |
| 540 |
putc2(BYTE2(c), mpx->mpxfile); |
| 541 |
mpx->print_col++; |
| 542 |
} |
| 543 |
if (BYTE3(c)!=0) pflag = 1; |
| 544 |
if (pflag) { |
| 545 |
putc2(BYTE3(c), mpx->mpxfile); |
| 546 |
mpx->print_col++; |
| 547 |
} |
| 548 |
putc2(BYTE4(c), mpx->mpxfile); |
| 549 |
#else |
| 550 |
putc2(Hi(c), mpx->mpxfile); |
| 551 |
mpx->print_col++; |
| 552 |
putc2(Lo(c), mpx->mpxfile); |
| 553 |
#endif |
| 554 |
mpx->print_col++; |
| 555 |
} |
| 556 |
@z |