| 1 |
/* |
| 2 |
* dvi2tty |
| 3 |
* Copyright (C) 2003 Marcel J.E. Mol <[email protected]> |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU General Public License |
| 7 |
* as published by the Free Software Foundation; either version 2 |
| 8 |
* of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program; if not, write to the Free Software |
| 17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 |
* |
| 19 |
*/ |
| 20 |
|
| 21 |
/* |
| 22 |
* Include files |
| 23 |
*/ |
| 24 |
|
| 25 |
#include "dvi2tty.h" |
| 26 |
|
| 27 |
#include <sys/types.h> |
| 28 |
#include <sys/stat.h> |
| 29 |
|
| 30 |
#include "commands.h" |
| 31 |
#include "tex2ucs.h" |
| 32 |
|
| 33 |
|
| 34 |
/* |
| 35 |
* Constant definitions |
| 36 |
*/ |
| 37 |
|
| 38 |
#define mseek fseek |
| 39 |
|
| 40 |
#define VERSIONID 2 /* dvi version number that pgm handles */ |
| 41 |
#define VERTICALEPSILON 450000L /* crlf when increasing v more than this */ |
| 42 |
|
| 43 |
#define rightmargin MAXTERMWIDTH+20 |
| 44 |
/* nr of columns allowed to the right of h=0*/ |
| 45 |
#define leftmargin -50 /* give some room for negative h-coordinate */ |
| 46 |
#define LINELEN rightmargin - leftmargin + 1 |
| 47 |
|
| 48 |
#define MOVE TRUE /* if advancing h when outputing a rule */ |
| 49 |
#define STAY FALSE /* if not advancing h when outputing a rule */ |
| 50 |
|
| 51 |
#define absolute 0 /* for seeking in files */ |
| 52 |
#define relative 1 |
| 53 |
|
| 54 |
#define FORM 12 /* formfeed */ |
| 55 |
#define SPACE 32 /* space */ |
| 56 |
#define DEL 127 /* delete */ |
| 57 |
|
| 58 |
#define LASTCHAR 127 /* max dvi character, above are commands */ |
| 59 |
#define LASTCHAR8B 255 |
| 60 |
|
| 61 |
#define IS_UNICODE 0x400000 /* flag for unicode */ |
| 62 |
#define MAX_UNICODE 0x10FFFF /* max unicode */ |
| 63 |
|
| 64 |
#define IMIN(a, b) (a<b ? a : b) |
| 65 |
#define IMAX(a, b) (a>b ? a : b) |
| 66 |
|
| 67 |
#define get1() num(1) |
| 68 |
#define get2() num(2) |
| 69 |
#define get3() num(3) |
| 70 |
#define get4() num(4) |
| 71 |
#define sget1() snum(1) |
| 72 |
#define sget2() snum(2) |
| 73 |
#define sget3() snum(3) |
| 74 |
#define sget4() snum(4) |
| 75 |
|
| 76 |
|
| 77 |
/* |
| 78 |
* Structure and variable definitions |
| 79 |
*/ |
| 80 |
|
| 81 |
/* const char *dvistuff = "@(#) dvistuff.c " VERSION " 20101027 M.J.E. Mol (c) 1989-2010"; */ |
| 82 |
|
| 83 |
typedef struct { |
| 84 |
long hh; |
| 85 |
long vv; |
| 86 |
long ww; |
| 87 |
long xx; |
| 88 |
long yy; |
| 89 |
long zz; |
| 90 |
} stackitem; |
| 91 |
|
| 92 |
typedef struct lineptr { /* the lines of text to be output to outfile */ |
| 93 |
long vv; /* vertical position of the line */ |
| 94 |
int charactercount; /* pos of last char on line */ |
| 95 |
struct lineptr *prev; /* preceding line */ |
| 96 |
struct lineptr *next; /* succeeding line */ |
| 97 |
long text[LINELEN+1]; /* leftmargin...rightmargin */ |
| 98 |
} linetype; |
| 99 |
|
| 100 |
typedef struct _font { |
| 101 |
long num; |
| 102 |
struct _font * next; |
| 103 |
char * name; |
| 104 |
unsigned char flags; /* to store font encoding types */ |
| 105 |
int fontnum; /* helper for japanese fonts */ |
| 106 |
bool is8bit; /* 8bit fonts */ |
| 107 |
} font; |
| 108 |
|
| 109 |
#define TTFONT 0x01 |
| 110 |
#define SYMFONT 0x02 |
| 111 |
#define MIFONT 0x03 |
| 112 |
#define T1FONT 0x04 |
| 113 |
#define TS1FONT 0x05 |
| 114 |
#define OT2FONT 0x10 |
| 115 |
#define T2AFONT 0x11 |
| 116 |
#define T2BFONT 0x12 |
| 117 |
#define T2CFONT 0x13 |
| 118 |
#define X2FONT 0x14 |
| 119 |
#define JPFONT 0x80 |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
bool pageswitchon; /* true if user-set pages to print */ |
| 124 |
bool sequenceon; /* false if pagesw-nrs refers to TeX-nrs */ |
| 125 |
bool scascii; /* if true make Scand. nat. chars right */ |
| 126 |
bool latin1; /* if true make latin1 chars right */ |
| 127 |
bool utf8; /* if true print by utf8 encoding */ |
| 128 |
bool noligaturefi; /* if true do not use ligature for ff,fi,fl,ffi,ffl */ |
| 129 |
bool accent; /* if true output accents etc: \'{e} etc. */ |
| 130 |
bool ttfont = FALSE; /* if true we assumed ttfonts, not cmr */ |
| 131 |
bool symbolfont = FALSE; /* true if font is a symbol font */ |
| 132 |
bool nttj = FALSE; /* switch to NTT japanese fonts ... */ |
| 133 |
bool asciip = FALSE; /* switch to ASCII japanese fonts ... */ |
| 134 |
bool uptex = FALSE; /* switch to upTeX CJK fonts ... */ |
| 135 |
bool japan = FALSE; /* switch to NTT/ASCII/.. japanese fonts ... */ |
| 136 |
bool jautodetect = FALSE; /* switch if do auto detection of Japanese TeX */ |
| 137 |
bool jdetect = FALSE; /* switch if Japanese TeX detection is done */ |
| 138 |
bool mifont = FALSE; /* ASCII japanese font ??? */ |
| 139 |
bool is8bit = FALSE; /* true if 8bit encoding font */ |
| 140 |
bool noffd; /* if true output ^L instead of formfeed */ |
| 141 |
const char *delim; /* -bdelim for font switch printing */ |
| 142 |
bool printfont; /* true if user wants font switches printed */ |
| 143 |
bool compose; /* if true try to compose a combining character sequence */ |
| 144 |
bool allchar; /* true if user sets all characters */ |
| 145 |
/* overrides sscasci, accent */ |
| 146 |
|
| 147 |
int opcode; /* dvi-opcodes */ |
| 148 |
|
| 149 |
long h, v; /* coordinates, horizontal and vertical */ |
| 150 |
long w, x, y, z; /* horizontal and vertical amounts */ |
| 151 |
|
| 152 |
long pagecounter; /* sequence page number counter */ |
| 153 |
long backpointer; /* pointer for offset to previous page */ |
| 154 |
long pagenr; /* TeX page number */ |
| 155 |
int stackmax; /* stacksize required */ |
| 156 |
|
| 157 |
long maxpagewidth; /* width of widest page in file */ |
| 158 |
long charwidth; /* aprox width of character */ |
| 159 |
long lineheight = VERTICALEPSILON; |
| 160 |
/* aprox height of a line */ |
| 161 |
|
| 162 |
linetype * currentline; /* pointer to current line on current page */ |
| 163 |
linetype * firstline; /* pointer to first line on current page */ |
| 164 |
linetype * lastline; /* pointer to last line on current page */ |
| 165 |
int firstcolumn; /* 1st column with something to print */ |
| 166 |
|
| 167 |
stackitem * stack; /* stack for dvi-pushes */ |
| 168 |
int sptr; /* stack pointer */ |
| 169 |
|
| 170 |
font * fonts = NULL; /* List of fontnames defined */ |
| 171 |
font * fnt = NULL; /* Current font */ |
| 172 |
|
| 173 |
int kanji1 = 0; /* number of rest of trailer bytes in kanji character */ |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
/* |
| 178 |
* Function definitions |
| 179 |
*/ |
| 180 |
|
| 181 |
void postamble (void); |
| 182 |
void preamble (void); |
| 183 |
void walkpages (void); |
| 184 |
void initpage (void); |
| 185 |
void dopage (void); |
| 186 |
void skippage (void); |
| 187 |
void printpage (void); |
| 188 |
bool inlist (long pagenr); |
| 189 |
void rule (bool moving, long rulewt, long ruleht); |
| 190 |
void ruleaux (long rulewt, long ruleht, char ch); |
| 191 |
long horizontalmove (long amount); |
| 192 |
int skipnops (void); |
| 193 |
linetype * my_getline (void); |
| 194 |
linetype * findline (void); |
| 195 |
unsigned long num (int size); |
| 196 |
long snum (int size); |
| 197 |
void dochar (unsigned char ch); |
| 198 |
void symchar (unsigned char ch); |
| 199 |
void michar (unsigned char ch); |
| 200 |
void normchar (char flag, unsigned char ch); |
| 201 |
void t1char (unsigned char ch); |
| 202 |
void ts1char (unsigned char ch); |
| 203 |
void ot2char (unsigned char ch); |
| 204 |
void t2char (char flag, unsigned char ch); |
| 205 |
void outchar (long ch); |
| 206 |
void putcharacter (long charnr); |
| 207 |
void setchar (long charnr); |
| 208 |
void fontdef (int x); |
| 209 |
void setfont (long fntnum); |
| 210 |
void jischar (unsigned long ch); |
| 211 |
void compute_jis (int f, unsigned int c, unsigned int * ku, unsigned int * ten); |
| 212 |
void dounichar (long ch); |
| 213 |
void dokanji (long ch); |
| 214 |
int getjsubfont (char * s); |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
/* |
| 219 |
* DVIMAIN -- The main function for processing the dvi file. |
| 220 |
* Here we assume there are to file pointers: DVIfile and output. |
| 221 |
* Also we have a list of pages pointed to by 'currentpage', |
| 222 |
* which is only used (in 'inlist()') when a page list is given. |
| 223 |
*/ |
| 224 |
|
| 225 |
void dvimain(void) |
| 226 |
{ |
| 227 |
|
| 228 |
postamble(); /* seek and process the postamble */ |
| 229 |
preamble(); /* process preamble */ |
| 230 |
/* note that walkpages *must* immediately follow preamble */ |
| 231 |
walkpages(); /* time to do the actual work! */ |
| 232 |
|
| 233 |
return; |
| 234 |
|
| 235 |
} /* dvimain */ |
| 236 |
|
| 237 |
|
| 238 |
/* |
| 239 |
* POSTAMBLE -- Find and process postamble, use random access |
| 240 |
*/ |
| 241 |
|
| 242 |
void postamble(void) |
| 243 |
{ |
| 244 |
register long size; |
| 245 |
register int count; |
| 246 |
|
| 247 |
fseek (DVIfile, 0L, SEEK_END); |
| 248 |
size = ftell (DVIfile); /* get size of file */ |
| 249 |
|
| 250 |
count = -1; |
| 251 |
do { /* back file up past signature bytes (223), to id-byte */ |
| 252 |
if (size-- == 0) |
| 253 |
errorexit(nopst); |
| 254 |
mseek(DVIfile, size, absolute); |
| 255 |
opcode = (int) get1(); |
| 256 |
count++; |
| 257 |
} while (opcode == TRAILER); |
| 258 |
if (count < 4) { /* must have 4 trailer bytes */ |
| 259 |
foo = count; |
| 260 |
errorexit(fwsgn); |
| 261 |
} |
| 262 |
if (opcode != VERSIONID) |
| 263 |
errorexit(badid); |
| 264 |
mseek(DVIfile, size-4, absolute); /* back up to back-pointer */ |
| 265 |
mseek(DVIfile, sget4(), absolute); /* and to start of postamble */ |
| 266 |
if (get1() != POST) |
| 267 |
errorexit(nopst); |
| 268 |
mseek(DVIfile, 20L, relative); /* lastpageoffset, numerator, denominator */ |
| 269 |
/* magnification, maxpageheight */ |
| 270 |
maxpagewidth = sget4(); |
| 271 |
charwidth = maxpagewidth / (ttywidth + espace); |
| 272 |
stackmax = (int) get2(); |
| 273 |
if ((stack = (stackitem *) malloc(stackmax * sizeof(stackitem))) == NULL) |
| 274 |
errorexit(stkrq); |
| 275 |
|
| 276 |
/* get2() -- totalpages */ |
| 277 |
/* fontdefs do fontdefs in flight ... */ |
| 278 |
|
| 279 |
return; |
| 280 |
|
| 281 |
} /* postamble */ |
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
/* |
| 286 |
* PREAMBLE --process preamble, use random access |
| 287 |
*/ |
| 288 |
|
| 289 |
void preamble(void) |
| 290 |
{ |
| 291 |
|
| 292 |
mseek(DVIfile, 0L, absolute); /* read the dvifile from the start */ |
| 293 |
if ((opcode = (int) num(1)) != PRE) |
| 294 |
errorexit(nopre); |
| 295 |
opcode = (int) get1(); /* check id in preamble, ignore rest of it */ |
| 296 |
if (opcode != VERSIONID) |
| 297 |
errorexit(badid); |
| 298 |
mseek(DVIfile, 12L, relative); /* numerator, denominator, magnification */ |
| 299 |
mseek(DVIfile, get1(), relative); /* skip job identification */ |
| 300 |
|
| 301 |
return; |
| 302 |
|
| 303 |
} /* preamble */ |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
/* |
| 308 |
* WALKPAGES -- process the pages in the DVI-file |
| 309 |
*/ |
| 310 |
|
| 311 |
void walkpages(void) |
| 312 |
{ |
| 313 |
register bool wantpage; |
| 314 |
|
| 315 |
pagecounter = 0L; |
| 316 |
while ((opcode = skipnops()) != POST) { |
| 317 |
|
| 318 |
if (opcode != BOP) /* should be at start of page now */ |
| 319 |
errorexit(nobop); |
| 320 |
|
| 321 |
pagecounter++; |
| 322 |
pagenr = sget4(); /* get TeX page number */ |
| 323 |
mseek(DVIfile, 36L, relative); /* skip page header */ |
| 324 |
backpointer = sget4(); /* get previous page offset */ |
| 325 |
if (pageswitchon) |
| 326 |
wantpage = inlist(sequenceon ? pagecounter : pagenr); |
| 327 |
else |
| 328 |
wantpage = TRUE; |
| 329 |
|
| 330 |
if (wantpage) { |
| 331 |
initpage(); |
| 332 |
dopage(); |
| 333 |
printpage(); |
| 334 |
} |
| 335 |
else |
| 336 |
skippage(); |
| 337 |
} |
| 338 |
|
| 339 |
return; |
| 340 |
|
| 341 |
} /* walkpages */ |
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
/* |
| 346 |
* INITPAGE -- Setup a new, empty page. |
| 347 |
*/ |
| 348 |
|
| 349 |
void initpage(void) |
| 350 |
{ |
| 351 |
|
| 352 |
h = 0L; v = 0L; /* initialize coordinates */ |
| 353 |
x = 0L; w = 0L; y = 0L; z = 0L; /* initialize amounts */ |
| 354 |
sptr = 0; /* initialize stack */ |
| 355 |
currentline = my_getline(); /* initialize list of lines */ |
| 356 |
currentline->vv = 0L; |
| 357 |
firstline = currentline; |
| 358 |
lastline = currentline; |
| 359 |
firstcolumn = rightmargin; |
| 360 |
if (pageswitchon) { |
| 361 |
if ((sequenceon ? pagecounter : pagenr) != firstpage->pag) { |
| 362 |
if (noffd) |
| 363 |
fprintf(output, "^L\n"); |
| 364 |
else |
| 365 |
putc(FORM, output); |
| 366 |
} |
| 367 |
} |
| 368 |
else |
| 369 |
if (backpointer != -1) { /* not FORM at first page */ |
| 370 |
if (noffd) |
| 371 |
fprintf(output, "^L\n"); |
| 372 |
else |
| 373 |
putc(FORM, output); |
| 374 |
} |
| 375 |
|
| 376 |
return; |
| 377 |
|
| 378 |
} /* initpage */ |
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
/* |
| 383 |
* DOPAGE -- Process the dvi file until an end-off-page. |
| 384 |
* Build up a page image. |
| 385 |
*/ |
| 386 |
|
| 387 |
void dopage(void) |
| 388 |
{ |
| 389 |
|
| 390 |
while ((opcode = (int) get1()) != EOP) { /* process page until eop */ |
| 391 |
if (opcode <= LASTCHAR) |
| 392 |
dochar((unsigned char) opcode); |
| 393 |
else if ((opcode >= FONT_00) && (opcode <= FONT_63)) |
| 394 |
setfont((long) opcode - FONT_00); |
| 395 |
else if (opcode > POST_POST) |
| 396 |
errorexit(illop); |
| 397 |
else |
| 398 |
switch (opcode) { |
| 399 |
case SET1 : nttj ? jischar(get1()) : setchar(get1());break; |
| 400 |
case SET2 : (asciip || uptex) ? dokanji(get2()) : setchar(get2()); break; |
| 401 |
case SET3 : uptex ? dokanji(get3()) : setchar(get3()); break; |
| 402 |
case SET4 : setchar(get4()); break; |
| 403 |
case SET_RULE : { long height = sget4(); |
| 404 |
rule(MOVE, sget4(), height); break; |
| 405 |
} |
| 406 |
case PUT1 : putcharacter(get1()); break; |
| 407 |
case PUT2 : putcharacter(get2()); break; |
| 408 |
case PUT3 : putcharacter(get3()); break; |
| 409 |
case PUT4 : putcharacter(get4()); break; |
| 410 |
case PUT_RULE : { long height = sget4(); |
| 411 |
rule(STAY, sget4(), height); break; |
| 412 |
} |
| 413 |
case NOP : break; /* no-op */ |
| 414 |
case BOP : errorexit(bdbop); break; |
| 415 |
/* case EOP : break; strange place to have EOP */ |
| 416 |
case PUSH : if (sptr >= stackmax) /* push */ |
| 417 |
errorexit(stkof); |
| 418 |
stack[sptr].hh = h; |
| 419 |
stack[sptr].vv = v; |
| 420 |
stack[sptr].ww = w; |
| 421 |
stack[sptr].xx = x; |
| 422 |
stack[sptr].yy = y; |
| 423 |
stack[sptr].zz = z; |
| 424 |
sptr++; |
| 425 |
break; |
| 426 |
case POP : if (sptr-- == 0) /* pop */ |
| 427 |
errorexit(stkuf); |
| 428 |
h = stack[sptr].hh; |
| 429 |
v = stack[sptr].vv; |
| 430 |
w = stack[sptr].ww; |
| 431 |
x = stack[sptr].xx; |
| 432 |
y = stack[sptr].yy; |
| 433 |
z = stack[sptr].zz; |
| 434 |
break; |
| 435 |
case RIGHT1 : (void) horizontalmove(sget1()); break; |
| 436 |
case RIGHT2 : (void) horizontalmove(sget2()); break; |
| 437 |
case RIGHT3 : (void) horizontalmove(sget3()); break; |
| 438 |
case RIGHT4 : (void) horizontalmove(sget4()); break; |
| 439 |
case W0 : h += w; break; |
| 440 |
case W1 : w = horizontalmove(sget1()); break; |
| 441 |
case W2 : w = horizontalmove(sget2()); break; |
| 442 |
case W3 : w = horizontalmove(sget3()); break; |
| 443 |
case W4 : w = horizontalmove(sget4()); break; |
| 444 |
case X0 : h += x; break; |
| 445 |
case X1 : x = horizontalmove(sget1()); break; |
| 446 |
case X2 : x = horizontalmove(sget2()); break; |
| 447 |
case X3 : x = horizontalmove(sget3()); break; |
| 448 |
case X4 : x = horizontalmove(sget4()); break; |
| 449 |
case DOWN1 : v += sget1(); break; |
| 450 |
case DOWN2 : v += sget2(); break; |
| 451 |
case DOWN3 : v += sget3(); break; |
| 452 |
case DOWN4 : v += sget4(); break; |
| 453 |
case Y0 : v += y; break; |
| 454 |
case Y1 : y = sget1(); v += y; break; |
| 455 |
case Y2 : y = sget2(); v += y; break; |
| 456 |
case Y3 : y = sget3(); v += y; break; |
| 457 |
case Y4 : y = sget4(); v += y; break; |
| 458 |
case Z0 : v += z; break; |
| 459 |
case Z1 : z = sget1(); v += z; break; |
| 460 |
case Z2 : z = sget2(); v += z; break; |
| 461 |
case Z3 : z = sget3(); v += z; break; |
| 462 |
case Z4 : z = sget4(); v += z; break; |
| 463 |
case FNT1 : |
| 464 |
case FNT2 : |
| 465 |
case FNT3 : |
| 466 |
case FNT4 : setfont(num(opcode - FNT1 + 1)); |
| 467 |
break; |
| 468 |
case XXX1 : mseek(DVIfile, get1(), relative); break; |
| 469 |
case XXX2 : mseek(DVIfile, get2(), relative); break; |
| 470 |
case XXX3 : mseek(DVIfile, get3(), relative); break; |
| 471 |
case XXX4 : mseek(DVIfile, get4(), relative); break; |
| 472 |
case FNT_DEF1 : |
| 473 |
case FNT_DEF2 : |
| 474 |
case FNT_DEF3 : |
| 475 |
case FNT_DEF4 : fontdef(opcode - FNT_DEF1 + 1); |
| 476 |
break; |
| 477 |
case PRE : errorexit(bdpre); break; |
| 478 |
case POST : errorexit(bdpst); break; |
| 479 |
case POST_POST: errorexit(bdpp); break; |
| 480 |
} |
| 481 |
} |
| 482 |
|
| 483 |
return; |
| 484 |
|
| 485 |
} /* dopage */ |
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
/* |
| 490 |
* SKIPPAGE -- Scan the dvi file until an end-off-page. |
| 491 |
* Skip this page. |
| 492 |
*/ |
| 493 |
|
| 494 |
void skippage(void) |
| 495 |
{ |
| 496 |
register int opcode; |
| 497 |
|
| 498 |
while ((opcode = (int) get1()) != EOP) { |
| 499 |
if (opcode > POST_POST) |
| 500 |
errorexit(illop); |
| 501 |
else |
| 502 |
switch (opcode) { |
| 503 |
case SET1 : |
| 504 |
case PUT1 : |
| 505 |
case RIGHT1 : |
| 506 |
case W1 : |
| 507 |
case X1 : |
| 508 |
case DOWN1 : |
| 509 |
case Y1 : |
| 510 |
case Z1 : /* assume FNT change can also be skipped */ |
| 511 |
case FNT1 : mseek(DVIfile, 1L, relative); break; |
| 512 |
case SET2 : |
| 513 |
case PUT2 : |
| 514 |
case RIGHT2 : |
| 515 |
case W2 : |
| 516 |
case X2 : |
| 517 |
case DOWN2 : |
| 518 |
case Y2 : |
| 519 |
case Z2 : |
| 520 |
case FNT2 : mseek(DVIfile, 2L, relative); break; |
| 521 |
case SET3 : |
| 522 |
case PUT3 : |
| 523 |
case RIGHT3 : |
| 524 |
case W3 : |
| 525 |
case X3 : |
| 526 |
case DOWN3 : |
| 527 |
case Y3 : |
| 528 |
case Z3 : |
| 529 |
case FNT3 : mseek(DVIfile, 3L, relative); break; |
| 530 |
case SET4 : |
| 531 |
case PUT4 : |
| 532 |
case RIGHT4 : |
| 533 |
case W4 : |
| 534 |
case X4 : |
| 535 |
case DOWN4 : |
| 536 |
case Y4 : |
| 537 |
case Z4 : |
| 538 |
case FNT4 : mseek(DVIfile, 4L, relative); break; |
| 539 |
case SET_RULE : |
| 540 |
case PUT_RULE : mseek(DVIfile, 8L, relative); break; |
| 541 |
case BOP : errorexit(bdbop); break; |
| 542 |
case XXX1 : mseek(DVIfile, get1(), relative); break; |
| 543 |
case XXX2 : mseek(DVIfile, get2(), relative); break; |
| 544 |
case XXX3 : mseek(DVIfile, get3(), relative); break; |
| 545 |
case XXX4 : mseek(DVIfile, get4(), relative); break; |
| 546 |
case FNT_DEF1 : |
| 547 |
case FNT_DEF2 : |
| 548 |
case FNT_DEF3 : |
| 549 |
case FNT_DEF4 : fontdef(opcode - FNT_DEF1 + 1); break; |
| 550 |
case PRE : errorexit(bdpre); break; |
| 551 |
case POST : errorexit(bdpst); break; |
| 552 |
case POST_POST: errorexit(bdpp); break; |
| 553 |
} |
| 554 |
} |
| 555 |
|
| 556 |
return; |
| 557 |
|
| 558 |
} /* skippage */ |
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
/* |
| 563 |
* PRINTPAGE -- 'end of page', writes lines of page to output file |
| 564 |
*/ |
| 565 |
|
| 566 |
void printpage(void) |
| 567 |
{ |
| 568 |
register int i, j, k; |
| 569 |
register long ch, mbch; |
| 570 |
unsigned char buff[4]; |
| 571 |
|
| 572 |
if (sptr != 0) |
| 573 |
fprintf(stderr, "dvi2tty: warning - stack not empty at eop.\n"); |
| 574 |
for (currentline = firstline; currentline != nil; |
| 575 |
currentline = currentline->next) { |
| 576 |
if (currentline != firstline) { |
| 577 |
foo = ((currentline->vv - currentline->prev->vv)/lineheight)-1; |
| 578 |
if (foo > 3) |
| 579 |
foo = 3; /* linespacings not too large */ |
| 580 |
for (i = 1; i <= (int) foo; i++) |
| 581 |
putc('\n', output); |
| 582 |
} |
| 583 |
if (currentline->charactercount >= leftmargin) { |
| 584 |
foo = ttywidth - 2; |
| 585 |
for (i = firstcolumn, j = 1; i <= currentline->charactercount; |
| 586 |
i++, j++) { |
| 587 |
ch = currentline->text[i - leftmargin]; |
| 588 |
|
| 589 |
if (japan && !(ch & IS_UNICODE)) { |
| 590 |
if (ch > 127) { |
| 591 |
for (k = 0; k < 4; k++) { |
| 592 |
if (i - leftmargin + k < LINELEN+1) |
| 593 |
buff[k] = currentline->text[i - leftmargin + k]; |
| 594 |
else buff[k] = '\0'; |
| 595 |
} |
| 596 |
kanji1 = multistrlen(buff, 4, 0) - 1; |
| 597 |
} |
| 598 |
else kanji1 = 0; |
| 599 |
if (kanji1 && (j + kanji1 > (int) foo) && |
| 600 |
(currentline->charactercount > i+1)) { |
| 601 |
putc2('*', output); |
| 602 |
putc2('\n', output); /* if line to large */ |
| 603 |
putc2(' ', output); |
| 604 |
putc2('*', output); /* mark output */ |
| 605 |
j = 2; |
| 606 |
} |
| 607 |
} |
| 608 |
|
| 609 |
if (ch >= SPACE || allchar) { |
| 610 |
if (utf8 && (ch & IS_UNICODE)) { |
| 611 |
#ifdef WIN32 |
| 612 |
wchar_t wch; |
| 613 |
HANDLE hStdout; |
| 614 |
DWORD ret; |
| 615 |
const int fd = fileno(output); |
| 616 |
|
| 617 |
if ((fd == fileno(stdout) || fd == fileno(stderr)) && _isatty(fd)) { |
| 618 |
if (fd == fileno(stdout)) |
| 619 |
hStdout = GetStdHandle(STD_OUTPUT_HANDLE); |
| 620 |
else |
| 621 |
hStdout = GetStdHandle(STD_ERROR_HANDLE); |
| 622 |
|
| 623 |
wch=(wchar_t)(ch & MAX_UNICODE); /* do not expect over BMP */ |
| 624 |
WriteConsoleW(hStdout, &wch, 1, &ret, NULL); |
| 625 |
|
| 626 |
} else { |
| 627 |
#endif |
| 628 |
mbch = UCStoUTF8(ch & MAX_UNICODE); |
| 629 |
if (BYTE1(mbch) != 0) putc((unsigned char)BYTE1(mbch), output); |
| 630 |
if (BYTE2(mbch) != 0) putc((unsigned char)BYTE2(mbch), output); |
| 631 |
if (BYTE3(mbch) != 0) putc((unsigned char)BYTE3(mbch), output); |
| 632 |
/* always */ putc((unsigned char)BYTE4(mbch), output); |
| 633 |
#ifdef WIN32 |
| 634 |
} |
| 635 |
#endif |
| 636 |
} |
| 637 |
else if (japan) { |
| 638 |
for (k = 0; k < kanji1; k++) { |
| 639 |
putc2(ch, output); |
| 640 |
i++; j++; |
| 641 |
ch = currentline->text[i - leftmargin]; |
| 642 |
} |
| 643 |
putc2(ch, output); |
| 644 |
} |
| 645 |
else |
| 646 |
putc(ch, output); |
| 647 |
} |
| 648 |
if ((j > (int) foo) && (currentline->charactercount > i+1)) { |
| 649 |
if (japan) { |
| 650 |
putc2('*', output); |
| 651 |
putc2('\n', output); /* if line to large */ |
| 652 |
putc2(' ', output); |
| 653 |
putc2('*', output); /* mark output */ |
| 654 |
} |
| 655 |
else { |
| 656 |
fprintf(output, "*\n"); /* if line to large */ |
| 657 |
fprintf(output, " *"); /* mark output */ |
| 658 |
} |
| 659 |
j = 2; |
| 660 |
} |
| 661 |
} |
| 662 |
} |
| 663 |
if (japan) |
| 664 |
putc2('\n', output); |
| 665 |
else |
| 666 |
putc('\n', output); |
| 667 |
} |
| 668 |
|
| 669 |
currentline = firstline; |
| 670 |
while (currentline->next != nil) { |
| 671 |
currentline = currentline->next; |
| 672 |
free(currentline->prev); |
| 673 |
} |
| 674 |
free(currentline); /* free last line */ |
| 675 |
currentline = nil; |
| 676 |
|
| 677 |
return; |
| 678 |
|
| 679 |
} /* printpage */ |
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
/* |
| 684 |
* INLIST -- return true if pagenr is in the list of pages to be printed. |
| 685 |
*/ |
| 686 |
|
| 687 |
bool inlist(long pagenr) |
| 688 |
{ |
| 689 |
|
| 690 |
while ((currentpage->pag < 0) && (currentpage->pag != pagenr) && |
| 691 |
!currentpage->all && (currentpage->nxt != nil)) |
| 692 |
currentpage = currentpage->nxt; |
| 693 |
if ((currentpage->all && (pagenr < currentpage->pag)) || |
| 694 |
(currentpage->pag == pagenr)) |
| 695 |
return TRUE; |
| 696 |
else if (pagenr > 0) { |
| 697 |
while ((currentpage->pag < pagenr) && (currentpage->nxt != nil)) |
| 698 |
currentpage = currentpage->nxt; |
| 699 |
if (currentpage->pag == pagenr) |
| 700 |
return TRUE; |
| 701 |
} |
| 702 |
|
| 703 |
return FALSE; |
| 704 |
|
| 705 |
} /* inlist */ |
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
/* |
| 710 |
* RULE -- Output a rule (vertical or horizontal). |
| 711 |
* Increment h if moving is true. |
| 712 |
*/ |
| 713 |
|
| 714 |
void rule(bool moving, long rulewt, long ruleht) |
| 715 |
{ |
| 716 |
|
| 717 |
register char ch; /* character to set rule with */ |
| 718 |
register long saveh = 0, savev; |
| 719 |
/* rule -- starts up the recursive routine */ |
| 720 |
if (!moving) |
| 721 |
saveh = h; |
| 722 |
if ((ruleht <= 0) || (rulewt <= 0)) |
| 723 |
h += rulewt; |
| 724 |
else { |
| 725 |
savev = v; |
| 726 |
if ((ruleht / rulewt) > 0) /* value < 1 truncates to 0 */ |
| 727 |
ch = '|'; |
| 728 |
else if (ruleht > (lineheight / 2)) |
| 729 |
ch = '='; |
| 730 |
else |
| 731 |
ch = '_'; |
| 732 |
ruleaux(rulewt, ruleht, ch); |
| 733 |
v = savev; |
| 734 |
} |
| 735 |
if (!moving) |
| 736 |
h = saveh; |
| 737 |
|
| 738 |
return; |
| 739 |
|
| 740 |
} /* rule */ |
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
/* |
| 745 |
* RULEAUX -- do the actual output for the rule recursively. |
| 746 |
*/ |
| 747 |
|
| 748 |
void ruleaux(long rulewt, long ruleht, char ch) |
| 749 |
{ |
| 750 |
register long wt, lmh, rmh; |
| 751 |
|
| 752 |
wt = rulewt; |
| 753 |
lmh = h; /* save left margin */ |
| 754 |
if (h < 0) { /* let rules that start at negative h */ |
| 755 |
wt -= h; /* start at coordinate 0, but let it */ |
| 756 |
h = 0; /* have the right length */ |
| 757 |
} |
| 758 |
while (wt > 0) { /* output the part of the rule that */ |
| 759 |
rmh = h; /* goes on this line */ |
| 760 |
outchar(ch); |
| 761 |
wt -= (h-rmh); /* decrease the width left on line */ |
| 762 |
} |
| 763 |
ruleht -= lineheight; /* decrease the height */ |
| 764 |
if (ruleht > lineheight) { /* still more vertical? */ |
| 765 |
rmh = h; /* save current h (right margin) */ |
| 766 |
h = lmh; /* restore left margin */ |
| 767 |
v -= (lineheight + lineheight / 10); |
| 768 |
ruleaux(rulewt, ruleht, ch); |
| 769 |
h = rmh; /* restore right margin */ |
| 770 |
} |
| 771 |
|
| 772 |
return; |
| 773 |
|
| 774 |
} /* ruleaux */ |
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
/* |
| 779 |
* HORIZONTALMOVE -- Move the h pointer by amount. |
| 780 |
*/ |
| 781 |
|
| 782 |
long horizontalmove(long amount) |
| 783 |
{ |
| 784 |
|
| 785 |
if (labs(amount) > charwidth / 4L) { |
| 786 |
foo = 3*charwidth / 4; |
| 787 |
if (amount > 0) |
| 788 |
amount = ((amount+foo) / charwidth) * charwidth; |
| 789 |
else |
| 790 |
amount = ((amount-foo) / charwidth) * charwidth; |
| 791 |
h += amount; |
| 792 |
return amount; |
| 793 |
} |
| 794 |
else |
| 795 |
return 0; |
| 796 |
|
| 797 |
} /* horizontalmove */ |
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
/* |
| 802 |
* SKIPNOPS -- Return first non NOP opcode. |
| 803 |
*/ |
| 804 |
|
| 805 |
int skipnops(void) |
| 806 |
{ |
| 807 |
register int opcode; |
| 808 |
|
| 809 |
while (opcode = (int) num(1)) { |
| 810 |
if (opcode >= FNT_DEF1 && opcode <= FNT_DEF4) { |
| 811 |
fontdef(opcode - FNT_DEF1 + 1); |
| 812 |
continue; |
| 813 |
} |
| 814 |
else if (opcode == NOP) |
| 815 |
continue; |
| 816 |
break; |
| 817 |
} |
| 818 |
return opcode; |
| 819 |
|
| 820 |
} /* skipnops */ |
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
/* |
| 825 |
* GETLINE -- Returns an initialized line-object |
| 826 |
*/ |
| 827 |
|
| 828 |
linetype *my_getline(void) |
| 829 |
{ |
| 830 |
register int i; |
| 831 |
register linetype *temp; |
| 832 |
|
| 833 |
if ((temp = (linetype *) malloc(sizeof(linetype))) == NULL) |
| 834 |
errorexit(lnerq); |
| 835 |
temp->charactercount = leftmargin - 1; |
| 836 |
temp->prev = nil; |
| 837 |
temp->next = nil; |
| 838 |
for (i = 0; i < LINELEN; i++) |
| 839 |
temp->text[i] = ' '; |
| 840 |
temp->text[i] = '\0'; |
| 841 |
|
| 842 |
return temp; |
| 843 |
|
| 844 |
} /* my_getline */ |
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
/* |
| 849 |
* FINDLINE -- Find best fit line were text should go |
| 850 |
* and generate new line if needed. |
| 851 |
*/ |
| 852 |
|
| 853 |
linetype *findline(void) |
| 854 |
{ |
| 855 |
register linetype *temp; |
| 856 |
register long topd, botd; |
| 857 |
|
| 858 |
if (v <= firstline->vv) { /* above first line */ |
| 859 |
if (firstline->vv - v > lineheight) { |
| 860 |
temp = my_getline(); |
| 861 |
temp->next = firstline; |
| 862 |
firstline->prev = temp; |
| 863 |
temp->vv = v; |
| 864 |
firstline = temp; |
| 865 |
} |
| 866 |
return firstline; |
| 867 |
} |
| 868 |
|
| 869 |
if (v >= lastline->vv) { /* below last line */ |
| 870 |
if (v - lastline->vv > lineheight) { |
| 871 |
temp = my_getline(); |
| 872 |
temp->prev = lastline; |
| 873 |
lastline->next = temp; |
| 874 |
temp->vv = v; |
| 875 |
lastline = temp; |
| 876 |
} |
| 877 |
return lastline; |
| 878 |
} |
| 879 |
|
| 880 |
temp = lastline; /* in between two lines */ |
| 881 |
while ((temp->vv > v) && (temp != firstline)) |
| 882 |
temp = temp->prev; |
| 883 |
|
| 884 |
/* temp->vv < v < temp->next->vv --- temp is above, temp->next is below */ |
| 885 |
topd = v - temp->vv; |
| 886 |
botd = temp->next->vv - v; |
| 887 |
if ((topd < lineheight) || (botd < lineheight)) { |
| 888 |
if (topd < botd) /* take best fit */ |
| 889 |
return temp; |
| 890 |
else |
| 891 |
return temp->next; |
| 892 |
} |
| 893 |
|
| 894 |
/* no line fits suitable, generate a new one */ |
| 895 |
currentline = my_getline(); |
| 896 |
currentline->next = temp->next; |
| 897 |
currentline->prev = temp; |
| 898 |
temp->next->prev = currentline; |
| 899 |
temp->next = currentline; |
| 900 |
currentline->vv = v; |
| 901 |
|
| 902 |
return currentline; |
| 903 |
|
| 904 |
} /* findline */ |
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
/* |
| 909 |
* NUM -- |
| 910 |
*/ |
| 911 |
|
| 912 |
unsigned long num(int size) |
| 913 |
{ |
| 914 |
register int i; |
| 915 |
register unsigned long x = 0; |
| 916 |
|
| 917 |
for (i = size; i > 0; i--) |
| 918 |
x = (x << 8) + (unsigned) getc(DVIfile); |
| 919 |
|
| 920 |
return x; |
| 921 |
|
| 922 |
} /* num */ |
| 923 |
|
| 924 |
|
| 925 |
/* |
| 926 |
* SNUM -- |
| 927 |
*/ |
| 928 |
|
| 929 |
long snum(int size) |
| 930 |
{ |
| 931 |
register int i; |
| 932 |
register long x; |
| 933 |
|
| 934 |
x = getc(DVIfile); |
| 935 |
if (x & 0x80) |
| 936 |
x -= 0x100; |
| 937 |
for (i = size - 1; i > 0; i--) |
| 938 |
x = (x << 8) + (unsigned) getc(DVIfile); |
| 939 |
|
| 940 |
return x; |
| 941 |
|
| 942 |
} /* snum */ |
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
/* |
| 947 |
* DOUNICHAR -- Process a Unicode character |
| 948 |
*/ |
| 949 |
|
| 950 |
void dounichar(long ch) |
| 951 |
{ |
| 952 |
unsigned char c[4] = {0}, *cc; |
| 953 |
|
| 954 |
if (noligaturefi && 0xFB00<=ch && ch<=0xFB04) { |
| 955 |
switch (ch) { |
| 956 |
case 0xFB00: strcpy((char*)c,"ff"); break; |
| 957 |
case 0xFB01: strcpy((char*)c,"fi"); break; |
| 958 |
case 0xFB02: strcpy((char*)c,"fl"); break; |
| 959 |
case 0xFB03: strcpy((char*)c,"ffi"); break; |
| 960 |
case 0xFB04: strcpy((char*)c,"ffl"); break; |
| 961 |
} |
| 962 |
cc=c; |
| 963 |
while (*cc) { outchar((long)*cc); cc++; } |
| 964 |
return; |
| 965 |
} |
| 966 |
if (ch>0x7F) |
| 967 |
outchar((long)(ch | IS_UNICODE)); |
| 968 |
else { |
| 969 |
outchar((long)ch); |
| 970 |
} |
| 971 |
|
| 972 |
return; |
| 973 |
|
| 974 |
} /* dounichar */ |
| 975 |
|
| 976 |
|
| 977 |
/* |
| 978 |
* DOKANJI -- Process a kanji character opcode. |
| 979 |
*/ |
| 980 |
|
| 981 |
void dokanji(long ch) |
| 982 |
{ |
| 983 |
long i; |
| 984 |
i = toBUFF(fromDVI(ch)); |
| 985 |
|
| 986 |
kanji1 = 3; |
| 987 |
if (BYTE1(i) != 0) outchar((long)BYTE1(i)); |
| 988 |
kanji1 = 2; |
| 989 |
if (BYTE2(i) != 0) outchar((long)BYTE2(i)); |
| 990 |
kanji1 = 1; |
| 991 |
if (BYTE3(i) != 0) outchar((long)BYTE3(i)); |
| 992 |
kanji1 = 0; |
| 993 |
/* always */ outchar((long)BYTE4(i)); |
| 994 |
|
| 995 |
return; |
| 996 |
|
| 997 |
} /* dokanji */ |
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
/* |
| 1002 |
* DOCHAR -- Process a character opcode. |
| 1003 |
*/ |
| 1004 |
|
| 1005 |
void dochar(unsigned char ch) |
| 1006 |
{ |
| 1007 |
char flag; |
| 1008 |
if (!fnt) errorexit(bdfnt); |
| 1009 |
flag = fnt->flags; |
| 1010 |
|
| 1011 |
if (nttj && fnt->fontnum) |
| 1012 |
jischar((long) ch); |
| 1013 |
else if (symbolfont) |
| 1014 |
symchar(ch); |
| 1015 |
else if (mifont) |
| 1016 |
michar(ch); |
| 1017 |
else if (flag == T1FONT) |
| 1018 |
t1char(ch); |
| 1019 |
else if (flag == TS1FONT) |
| 1020 |
ts1char(ch); |
| 1021 |
else if (flag == OT2FONT) |
| 1022 |
ot2char(ch); |
| 1023 |
else if (flag == T2AFONT || flag == T2BFONT || |
| 1024 |
flag == T2CFONT || flag == X2FONT) |
| 1025 |
t2char(flag, ch); |
| 1026 |
else |
| 1027 |
normchar(flag, ch); |
| 1028 |
|
| 1029 |
return; |
| 1030 |
|
| 1031 |
} /* dochar */ |
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
/* |
| 1036 |
* SYMCHAR -- Process a character opcode for a symbol font. |
| 1037 |
*/ |
| 1038 |
|
| 1039 |
void symchar(unsigned char ch) |
| 1040 |
{ |
| 1041 |
unsigned char c[4] = {0}, *cc; |
| 1042 |
long ucs; |
| 1043 |
|
| 1044 |
ucs = oms_to_ucs[ch]; |
| 1045 |
if (utf8) { |
| 1046 |
dounichar(ucs); |
| 1047 |
return; |
| 1048 |
} |
| 1049 |
else if ((latin1 && ucs<0x100) || ucs<0x80) { |
| 1050 |
outchar(ucs); |
| 1051 |
return; |
| 1052 |
} |
| 1053 |
|
| 1054 |
switch (ch) { /* can do a lot more on MSDOS/latin1/unicode machines ... */ |
| 1055 |
case 0: c[0] = '-'; break; |
| 1056 |
case 1: c[0] = '.'; break; |
| 1057 |
case 2: c[0] = 'x'; break; |
| 1058 |
case 3: c[0] = '*'; break; |
| 1059 |
case 4: c[0] = '/'; break; |
| 1060 |
case 6: c[0] = '+'; c[1] = '-'; break; |
| 1061 |
case 7: c[0] = '-'; c[1] = '+'; break; |
| 1062 |
case 13: c[0] = 'O'; break; |
| 1063 |
case 14: c[0] = 'O'; break; |
| 1064 |
case 15: c[0] = 'o'; break; |
| 1065 |
case 24: c[0] = '~'; break; |
| 1066 |
case 28: c[0] = '<'; c[1] = '<'; break; |
| 1067 |
case 29: c[0] = '>'; c[1] = '>'; break; |
| 1068 |
case 32: c[0] = '<'; c[1] = '-'; break; |
| 1069 |
case 33: c[0] = '-'; c[1] = '>'; break; |
| 1070 |
case 34: c[0] = '^'; break; |
| 1071 |
case 35: c[0] = 'v'; break; |
| 1072 |
case 36: c[0] = '<'; c[1] = '-'; c[2] = '>'; break; |
| 1073 |
case 40: c[0] = '<'; c[1] = '='; break; |
| 1074 |
case 41: c[0] = '='; c[1] = '>'; break; |
| 1075 |
case 42: c[0] = '^'; break; |
| 1076 |
case 43: c[0] = 'v'; break; |
| 1077 |
case 44: c[0] = '<'; c[1] = '='; c[2] = '>'; break; |
| 1078 |
case 60: c[0] = 'R'; c[1] = 'e'; break; |
| 1079 |
case 61: c[0] = 'I'; c[1] = 'm'; break; |
| 1080 |
case 102: c[0] = '{'; break; |
| 1081 |
case 103: c[0] = '}'; break; |
| 1082 |
case 104: c[0] = '<'; break; |
| 1083 |
case 105: c[0] = '>'; break; |
| 1084 |
case 106: c[0] = '|'; break; |
| 1085 |
case 107: c[0] = '|'; c[1] = '|'; break; |
| 1086 |
case 110: c[0] = '\\'; break; |
| 1087 |
case 120: c[0] = 'S'; break; |
| 1088 |
case 121: c[0] = '*'; break; |
| 1089 |
case 122: c[0] = '*'; c[1] = '*'; break; |
| 1090 |
case 123: c[0] = 'P'; break; |
| 1091 |
|
| 1092 |
default: c[0] = '#'; |
| 1093 |
} |
| 1094 |
|
| 1095 |
cc=c; |
| 1096 |
while (*cc) { outchar(*cc); cc++; } |
| 1097 |
|
| 1098 |
return; |
| 1099 |
|
| 1100 |
} /* symchar */ |
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
/* |
| 1105 |
* MICHAR -- Process a character opcode for OML font. |
| 1106 |
*/ |
| 1107 |
|
| 1108 |
void michar(unsigned char ch) |
| 1109 |
{ |
| 1110 |
unsigned char c[4] = {0}, *cc; |
| 1111 |
long ucs; |
| 1112 |
|
| 1113 |
if (allchar) { |
| 1114 |
outchar(ch); |
| 1115 |
return; |
| 1116 |
} |
| 1117 |
ucs = oml_to_ucs[ch]; |
| 1118 |
if (utf8) { |
| 1119 |
dounichar(ucs); |
| 1120 |
return; |
| 1121 |
} |
| 1122 |
else if ((latin1 && ucs<0x100) || ucs<0x80) { |
| 1123 |
outchar(ucs); |
| 1124 |
return; |
| 1125 |
} |
| 1126 |
|
| 1127 |
switch (ch) { |
| 1128 |
case 0x3a: c[0] = '.'; break; /* . */ |
| 1129 |
case 0x3b: c[0] = ','; break; /* , */ |
| 1130 |
case 0x3d: c[0] = '/'; break; /* / */ |
| 1131 |
case 0x3e: c[0] = '*'; break; /* \star */ |
| 1132 |
case 0x40: c[0] = 'd'; break; /* \partial */ |
| 1133 |
case 0x60: c[0] = 'l'; break; /* \ell */ |
| 1134 |
case 0x7b: c[0] = 'i'; break; /* dotless i */ |
| 1135 |
case 0x7c: c[0] = 'j'; break; /* dotless j */ |
| 1136 |
case 0x7d: c[0] = 'P'; break; /* \wp */ |
| 1137 |
|
| 1138 |
default : c[0] = '#'; |
| 1139 |
} |
| 1140 |
|
| 1141 |
cc=c; |
| 1142 |
while (*cc) { outchar(*cc); cc++; } |
| 1143 |
|
| 1144 |
return; |
| 1145 |
|
| 1146 |
} /* michar */ |
| 1147 |
|
| 1148 |
|
| 1149 |
/* |
| 1150 |
* NORMCHAR -- Process a character opcode for a normal font. |
| 1151 |
*/ |
| 1152 |
|
| 1153 |
void normchar(char flag, unsigned char ch) |
| 1154 |
{ |
| 1155 |
unsigned char c[4] = {0}, *cc; |
| 1156 |
const unsigned short *tex_to_ucs; |
| 1157 |
long ucs; |
| 1158 |
|
| 1159 |
if (allchar) { |
| 1160 |
outchar(ch); |
| 1161 |
return; |
| 1162 |
} |
| 1163 |
if (!accent) { |
| 1164 |
switch (ch) { |
| 1165 |
case 18 : /* grave from \` */ |
| 1166 |
case 19 : /* acute from \' */ |
| 1167 |
case 20 : /* caron from \v */ |
| 1168 |
case 21 : /* breve from \u */ |
| 1169 |
case 22 : /* macron from \= */ |
| 1170 |
case 23 : /* ring above from \r */ |
| 1171 |
case 24 : /* cedilla from \c */ |
| 1172 |
case 32 : /* stroke i.e. \L,\l */ |
| 1173 |
case 94 : /* circumflex from \^ */ |
| 1174 |
case 126 : /* tilde from \~ */ |
| 1175 |
case 127 : /* diaeresis from \" */ |
| 1176 |
return; |
| 1177 |
case 125 : /* double acute from \H */ |
| 1178 |
case 95 : /* dot from \. */ |
| 1179 |
if (!ttfont) return; |
| 1180 |
} |
| 1181 |
} |
| 1182 |
switch (flag) { |
| 1183 |
case TTFONT : tex_to_ucs=tt_to_ucs; break; |
| 1184 |
default : tex_to_ucs=ot1_to_ucs; |
| 1185 |
} |
| 1186 |
ucs = tex_to_ucs[ch]; |
| 1187 |
if (utf8) { |
| 1188 |
dounichar(ucs); |
| 1189 |
return; |
| 1190 |
} |
| 1191 |
else if ((latin1 && ucs<0x100) || ucs<0x80) { |
| 1192 |
outchar(ucs); |
| 1193 |
return; |
| 1194 |
} |
| 1195 |
|
| 1196 |
switch (ch) { |
| 1197 |
case 11 : if (ttfont) |
| 1198 |
c[0] = '^'; /* up symbol */ |
| 1199 |
else { |
| 1200 |
c[0] = 'f'; c[1] = 'f'; /* ligature */ |
| 1201 |
} |
| 1202 |
break; |
| 1203 |
case 12 : if (ttfont) |
| 1204 |
c[0] = 'v'; /* low symbol */ |
| 1205 |
else { |
| 1206 |
c[0] = 'f'; c[1] = 'i'; /* ligature */ |
| 1207 |
} |
| 1208 |
break; |
| 1209 |
case 13 : if (ttfont) |
| 1210 |
c[0] = '`'; |
| 1211 |
else { |
| 1212 |
c[0] = 'f'; c[1] = 'l'; /* ligature */ |
| 1213 |
} |
| 1214 |
break; |
| 1215 |
case 14 : if (ttfont) |
| 1216 |
c[0] = 'i'; /* spanish ! */ |
| 1217 |
else { |
| 1218 |
c[0] = 'f'; c[1] = 'f'; |
| 1219 |
c[2] = 'i'; /* ligature */ |
| 1220 |
} |
| 1221 |
break; |
| 1222 |
case 15 : if (ttfont) |
| 1223 |
c[0] = '.'; /* spanish ? */ |
| 1224 |
else { |
| 1225 |
c[0] = 'f'; c[1] = 'f'; |
| 1226 |
c[2] = 'l'; /* ligature */ |
| 1227 |
} |
| 1228 |
break; |
| 1229 |
case 16 : c[0] = 'i'; break; |
| 1230 |
case 17 : c[0] = 'j'; break; |
| 1231 |
case 25 : if (latin1) |
| 1232 |
c[0] = 0xdf; |
| 1233 |
else { |
| 1234 |
c[0] = 's'; c[1] = 's'; |
| 1235 |
} |
| 1236 |
break; /* German double s */ |
| 1237 |
case 26 : if (latin1) |
| 1238 |
c[0] = 0xe6; |
| 1239 |
else { |
| 1240 |
c[0] = 'a'; c[1] = 'e'; |
| 1241 |
} |
| 1242 |
break; /* Dane/Norw ae */ |
| 1243 |
case 27 : c[0] = 'o'; c[1] = 'e'; |
| 1244 |
break; /* Dane/Norw oe */ |
| 1245 |
case 28 : if (scascii) |
| 1246 |
c[0] = '|'; |
| 1247 |
else if (latin1) |
| 1248 |
c[0] = 0xf8; |
| 1249 |
else |
| 1250 |
c[0] = 'o'; |
| 1251 |
break; /* Dane/Norw /o */ |
| 1252 |
case 29 : if (latin1) |
| 1253 |
c[0] = 0xc6; |
| 1254 |
else { |
| 1255 |
c[0] = 'A'; c[1] = 'E'; |
| 1256 |
} |
| 1257 |
break; /* Dane/Norw AE */ |
| 1258 |
case 30 : c[0] = 'O'; c[1] = 'E'; |
| 1259 |
break; /* Dane/Norw OE */ |
| 1260 |
case 31 : if (scascii) |
| 1261 |
c[0] = '\\'; |
| 1262 |
else if (latin1) |
| 1263 |
c[0] = 0xd8; |
| 1264 |
else |
| 1265 |
c[0] = 'O'; |
| 1266 |
break; /* Dane/Norw /O */ |
| 1267 |
case 60 : if (ttfont) |
| 1268 |
c[0] = ch; /* '>' */ |
| 1269 |
else if (latin1) |
| 1270 |
c[0] = 0xa1; |
| 1271 |
else |
| 1272 |
c[0] = '!'; |
| 1273 |
break; /* inverted ! */ |
| 1274 |
case 62 : if (ttfont) |
| 1275 |
c[0] = ch; /* '<' */ |
| 1276 |
else if (latin1) |
| 1277 |
c[0] = 0xbf; |
| 1278 |
else |
| 1279 |
c[0] = '?'; |
| 1280 |
break; /* inverted ? */ |
| 1281 |
case 32 : c[0] = ttfont ? ch : '_'; break; /* underlined blank */ |
| 1282 |
case 92 : c[0] = ttfont ? ch : '"'; break; /* \ from `` */ |
| 1283 |
case 123 : if (ttfont) |
| 1284 |
c[0] = ch; /* { */ |
| 1285 |
else { |
| 1286 |
c[0] = '-'; c[1] = '-'; /* -- */ |
| 1287 |
} |
| 1288 |
break; |
| 1289 |
case 124 : if (ttfont) |
| 1290 |
c[0] = ch; /* | */ |
| 1291 |
else { |
| 1292 |
c[0] = '-'; c[1] = '-'; /* --- */ |
| 1293 |
c[2] = '-'; |
| 1294 |
} |
| 1295 |
break; |
| 1296 |
case 125 : if (ttfont) |
| 1297 |
c[0] = ch; /* } */ |
| 1298 |
else |
| 1299 |
c[0] = '"'; /* double acute from \H */ |
| 1300 |
break; |
| 1301 |
case 34 : /* " */ |
| 1302 |
case 39 : /* ' */ |
| 1303 |
case 96 : c[0] = ch; break; /* ` */ |
| 1304 |
|
| 1305 |
/* diacritical marks */ |
| 1306 |
case 18 : c[0] = '`' ; break; /* grave from \` */ |
| 1307 |
case 19 : c[0] = latin1 ? 0xb4 : '\''; break; |
| 1308 |
/* acute from \' */ |
| 1309 |
case 20 : c[0] = '~' ; break; /* caron from \v */ |
| 1310 |
case 21 : c[0] = '~' ; break; /* breve from \u */ |
| 1311 |
case 22 : c[0] = '~' ; break; /* macron from \= */ |
| 1312 |
case 23 : c[0] = latin1 ? 0xb0 : '~'; break; |
| 1313 |
/* ring above from \r */ |
| 1314 |
case 24 : c[0] = latin1 ? 0xb8 : ','; break; |
| 1315 |
/* cedilla from \c */ |
| 1316 |
case 94 : c[0] = '^' ; break; /* circumflex from \^ */ |
| 1317 |
case 95 : c[0] = !ttfont ? '.' : ch; break; |
| 1318 |
/* dot from \. */ |
| 1319 |
case 126 : c[0] = '~' ; break; /* tilde from \~ */ |
| 1320 |
case 127 : c[0] = '"' ; break; /* diaeresis from \" */ |
| 1321 |
|
| 1322 |
default : c[0] = '#'; |
| 1323 |
} |
| 1324 |
|
| 1325 |
cc=c; |
| 1326 |
while (*cc) { outchar(*cc); cc++; } |
| 1327 |
|
| 1328 |
return; |
| 1329 |
|
| 1330 |
} /* normchar */ |
| 1331 |
|
| 1332 |
|
| 1333 |
/* |
| 1334 |
* T1CHAR -- Process a character opcode for a T1 encoding font. |
| 1335 |
*/ |
| 1336 |
|
| 1337 |
void t1char(unsigned char ch) |
| 1338 |
{ |
| 1339 |
unsigned char c[4] = {0}, *cc; |
| 1340 |
long ucs; |
| 1341 |
|
| 1342 |
if (allchar) { |
| 1343 |
outchar(ch); |
| 1344 |
return; |
| 1345 |
} |
| 1346 |
if (!accent) { |
| 1347 |
switch (ch) { |
| 1348 |
case 0x00: /* grave from \` */ |
| 1349 |
case 0x01: /* acute from \' */ |
| 1350 |
case 0x02: /* circumflex from \^ */ |
| 1351 |
case 0x03: /* tilde from \~ */ |
| 1352 |
case 0x04: /* diaeresis from \" */ |
| 1353 |
case 0x05: /* double acute from \H */ |
| 1354 |
case 0x06: /* ring above from \r */ |
| 1355 |
case 0x07: /* caron from \v */ |
| 1356 |
case 0x08: /* breve from \u */ |
| 1357 |
case 0x09: /* macron from \= */ |
| 1358 |
case 0x0a: /* dot from \. */ |
| 1359 |
case 0x0b: /* cedilla from \c */ |
| 1360 |
case 0x0c: /* ogonek from \k */ |
| 1361 |
return; |
| 1362 |
} |
| 1363 |
} |
| 1364 |
if (ch==0xdf) { |
| 1365 |
outchar('S'); outchar('S'); /* SS */ |
| 1366 |
return; |
| 1367 |
} |
| 1368 |
ucs = t1_to_ucs[ch]; |
| 1369 |
if (utf8) { |
| 1370 |
dounichar(ucs); |
| 1371 |
return; |
| 1372 |
} |
| 1373 |
else if ((latin1 && ucs<0x100) || ucs<0x80) { |
| 1374 |
outchar(ucs); |
| 1375 |
return; |
| 1376 |
} |
| 1377 |
|
| 1378 |
switch (ch) { |
| 1379 |
case 0x17: return; /* \textcompwordmark */ |
| 1380 |
case 0x0d: /* \quotesinglbase */ |
| 1381 |
case 0x27: /* \textquoteright */ |
| 1382 |
case 0x60: c[0] = '\''; break; /* \textquoteleft */ |
| 1383 |
case 0x10: /* \textquotedblleft */ |
| 1384 |
case 0x11: /* \textquotedblright */ |
| 1385 |
case 0x12: c[0] = '"'; break; /* \quotedblbase */ |
| 1386 |
case 0x0e: c[0] = '<'; break; /* \guilsinglleft */ |
| 1387 |
case 0x0f: c[0] = '>'; break; /* \guilsinglright */ |
| 1388 |
case 0x13: c[0] = '<'; c[1] = '<'; /* \guillemotleft */ |
| 1389 |
break; |
| 1390 |
case 0x14: c[0] = '>'; c[1] = '>'; /* \guillemotright */ |
| 1391 |
break; |
| 1392 |
case 0x15: c[0] = '-'; c[1] = '-'; /* \textendash */ |
| 1393 |
break; |
| 1394 |
case 0x16: c[0] = '-'; c[1] = '-'; /* \textemdash */ |
| 1395 |
c[2] = '-'; break; |
| 1396 |
case 0x20: c[0] = '_'; break; /* \textvisiblespace */ |
| 1397 |
case 0x7f: c[0] = '-'; break; /* - */ |
| 1398 |
case 0x19: c[0] = 'i'; break; /* dotless i */ |
| 1399 |
case 0x1a: c[0] = 'j'; break; /* dotless j */ |
| 1400 |
case 0x1b: c[0] = 'f'; c[1] = 'f'; /* ligature */ |
| 1401 |
break; |
| 1402 |
case 0x1c: c[0] = 'f'; c[1] = 'i'; /* ligature */ |
| 1403 |
break; |
| 1404 |
case 0x1d: c[0] = 'f'; c[1] = 'l'; /* ligature */ |
| 1405 |
break; |
| 1406 |
case 0x1e: c[0] = 'f'; c[1] = 'f'; |
| 1407 |
c[2] = 'i'; /* ligature */ |
| 1408 |
break; |
| 1409 |
case 0x1f: c[0] = 'f'; c[1] = 'f'; |
| 1410 |
c[2] = 'l'; /* ligature */ |
| 1411 |
break; |
| 1412 |
case 0xff: c[0] = 's'; c[1] = 's'; |
| 1413 |
break; /* German double s */ |
| 1414 |
case 0xe6: c[0] = 'a'; c[1] = 'e'; |
| 1415 |
break; /* Dane/Norw ae */ |
| 1416 |
case 0xf7: c[0] = 'o'; c[1] = 'e'; |
| 1417 |
break; /* Dane/Norw oe */ |
| 1418 |
case 0xf8: c[0] = '/'; c[1] = 'o'; |
| 1419 |
break; /* Dane/Norw /o */ |
| 1420 |
case 0xc6: c[0] = 'A'; c[1] = 'E'; |
| 1421 |
break; /* Dane/Norw AE */ |
| 1422 |
case 0xd7: c[0] = 'O'; c[1] = 'E'; |
| 1423 |
break; /* Dane/Norw OE */ |
| 1424 |
case 0xd8: c[0] = '/'; c[1] = 'O'; |
| 1425 |
break; /* Dane/Norw /O */ |
| 1426 |
case 0x9c: c[0] = 'I'; c[1] = 'J'; |
| 1427 |
break; /* IJ */ |
| 1428 |
case 0xbc: c[0] = 'i'; c[1] = 'j'; |
| 1429 |
break; /* ij */ |
| 1430 |
case 0x8d: c[0] = 'N'; c[1] = 'G'; |
| 1431 |
break; /* ENG */ |
| 1432 |
case 0xad: c[0] = 'n'; c[1] = 'g'; |
| 1433 |
break; /* eng */ |
| 1434 |
case 0xde: c[0] = 'T'; c[1] = 'H'; |
| 1435 |
break; /* THORN */ |
| 1436 |
case 0xfe: c[0] = 't'; c[1] = 'h'; |
| 1437 |
break; /* thorn */ |
| 1438 |
case 0x80: c[0] = '~'; c[1] ='A'; break; /* uA */ |
| 1439 |
case 0x81: c[0] = ','; c[1] ='A'; break; /* ,A */ |
| 1440 |
case 0x82: c[0] = '\''; c[1] ='C'; break; /* 'C */ |
| 1441 |
case 0x83: c[0] = '~'; c[1] ='C'; break; /* vC */ |
| 1442 |
case 0x84: c[0] = '~'; c[1] ='D'; break; /* vD */ |
| 1443 |
case 0x85: c[0] = '~'; c[1] ='E'; break; /* vE */ |
| 1444 |
case 0x86: c[0] = ','; c[1] ='E'; break; /* ,E */ |
| 1445 |
case 0x87: c[0] = '~'; c[1] ='G'; break; /* uG */ |
| 1446 |
case 0x88: c[0] = '\''; c[1] ='L'; break; /* 'L */ |
| 1447 |
case 0x89: c[0] = '\''; c[1] ='L'; break; /* 'L */ |
| 1448 |
case 0x8a: c[0] = '-'; c[1] ='L'; break; /* -L */ |
| 1449 |
case 0x8b: c[0] = '\''; c[1] ='N'; break; /* 'N */ |
| 1450 |
case 0x8c: c[0] = '~'; c[1] ='N'; break; /* vN */ |
| 1451 |
case 0x8e: c[0] = '"'; c[1] ='O'; break; /* "O */ |
| 1452 |
case 0x8f: c[0] = '\''; c[1] ='R'; break; /* 'R */ |
| 1453 |
case 0x90: c[0] = '~'; c[1] ='R'; break; /* vR */ |
| 1454 |
case 0x91: c[0] = '\''; c[1] ='S'; break; /* 'S */ |
| 1455 |
case 0x92: c[0] = '~'; c[1] ='S'; break; /* vS */ |
| 1456 |
case 0x93: c[0] = ','; c[1] ='S'; break; /* ,S */ |
| 1457 |
case 0x94: c[0] = '~'; c[1] ='T'; break; /* vT */ |
| 1458 |
case 0x95: c[0] = ','; c[1] ='T'; break; /* ,T */ |
| 1459 |
case 0x96: c[0] = '"'; c[1] ='U'; break; /* "U */ |
| 1460 |
case 0x97: c[0] = '\''; c[1] ='U'; break; /* oU */ |
| 1461 |
case 0x98: c[0] = '"'; c[1] ='Y'; break; /* "Y */ |
| 1462 |
case 0x99: c[0] = '\''; c[1] ='Z'; break; /* 'Z */ |
| 1463 |
case 0x9a: c[0] = '~'; c[1] ='Z'; break; /* vZ */ |
| 1464 |
case 0x9b: c[0] = '\''; c[1] ='Z'; break; /* .Z */ |
| 1465 |
case 0x9d: c[0] = '\''; c[1] ='I'; break; /* .I */ |
| 1466 |
case 0x9e: c[0] = '-'; c[1] ='d'; break; /* -d */ |
| 1467 |
case 0x9f: c[0] = 'S'; break; /* section sign */ |
| 1468 |
|
| 1469 |
case 0xa0: c[0] = '~'; c[1] ='a'; break; /* ua */ |
| 1470 |
case 0xa1: c[0] = ','; c[1] ='a'; break; /* ,a */ |
| 1471 |
case 0xa2: c[0] = '\''; c[1] ='c'; break; /* 'c */ |
| 1472 |
case 0xa3: c[0] = '~'; c[1] ='c'; break; /* vc */ |
| 1473 |
case 0xa4: c[0] = '\''; c[1] ='d'; break; /* 'd */ |
| 1474 |
case 0xa5: c[0] = '~'; c[1] ='e'; break; /* ve */ |
| 1475 |
case 0xa6: c[0] = ','; c[1] ='e'; break; /* ,e */ |
| 1476 |
case 0xa7: c[0] = '~'; c[1] ='g'; break; /* ug */ |
| 1477 |
case 0xa8: c[0] = '\''; c[1] ='l'; break; /* 'l */ |
| 1478 |
case 0xa9: c[0] = '\''; c[1] ='l'; break; /* 'l */ |
| 1479 |
case 0xaa: c[0] = '-'; c[1] ='l'; break; /* -l */ |
| 1480 |
case 0xab: c[0] = '\''; c[1] ='n'; break; /* 'n */ |
| 1481 |
case 0xac: c[0] = '~'; c[1] ='n'; break; /* vn */ |
| 1482 |
case 0xae: c[0] = '"'; c[1] ='o'; break; /* "o */ |
| 1483 |
case 0xaf: c[0] = '\''; c[1] ='r'; break; /* 'r */ |
| 1484 |
|
| 1485 |
case 0xb0: c[0] = '~'; c[1] ='r'; break; /* vr */ |
| 1486 |
case 0xb1: c[0] = '\''; c[1] ='s'; break; /* 's */ |
| 1487 |
case 0xb2: c[0] = '~'; c[1] ='s'; break; /* vs */ |
| 1488 |
case 0xb3: c[0] = ','; c[1] ='s'; break; /* ,s */ |
| 1489 |
case 0xb4: c[0] = '\''; c[1] ='t'; break; /* 't */ |
| 1490 |
case 0xb5: c[0] = ','; c[1] ='t'; break; /* ,t */ |
| 1491 |
case 0xb6: c[0] = '"'; c[1] ='u'; break; /* "u */ |
| 1492 |
case 0xb7: c[0] = '\''; c[1] ='u'; break; /* ou */ |
| 1493 |
case 0xb8: c[0] = '"'; c[1] ='y'; break; /* "y */ |
| 1494 |
case 0xb9: c[0] = '\''; c[1] ='z'; break; /* 'z */ |
| 1495 |
case 0xba: c[0] = '~'; c[1] ='z'; break; /* vz */ |
| 1496 |
case 0xbb: c[0] = '\''; c[1] ='z'; break; /* .z */ |
| 1497 |
|
| 1498 |
case 0xbd: c[0] = '!'; break; /* inversed ! */ |
| 1499 |
case 0xbe: c[0] = '?'; break; /* inversed ? */ |
| 1500 |
case 0xbf: c[0] = 'L'; break; /* pound sign */ |
| 1501 |
|
| 1502 |
case 0xc0: c[0] = '`'; c[1] ='A'; break; /* `A */ |
| 1503 |
case 0xc1: c[0] = '\''; c[1] ='A'; break; /* 'A */ |
| 1504 |
case 0xc2: c[0] = '^'; c[1] ='A'; break; /* ^A */ |
| 1505 |
case 0xc3: c[0] = '~'; c[1] ='A'; break; /* ~A */ |
| 1506 |
case 0xc4: c[0] = '"'; c[1] ='A'; break; /* "A */ |
| 1507 |
case 0xc5: c[0] = 'A'; c[1] ='A'; break; /* oA */ |
| 1508 |
case 0xc7: c[0] = ','; c[1] ='C'; break; /* ,C */ |
| 1509 |
case 0xc8: c[0] = '`'; c[1] ='E'; break; /* `E */ |
| 1510 |
case 0xc9: c[0] = '\''; c[1] ='E'; break; /* 'E */ |
| 1511 |
case 0xca: c[0] = '^'; c[1] ='E'; break; /* ^E */ |
| 1512 |
case 0xcb: c[0] = '^'; c[1] ='E'; break; /* "E */ |
| 1513 |
case 0xcc: c[0] = '`'; c[1] ='I'; break; /* `I */ |
| 1514 |
case 0xcd: c[0] = '\''; c[1] ='I'; break; /* 'I */ |
| 1515 |
case 0xce: c[0] = '^'; c[1] ='I'; break; /* ^I */ |
| 1516 |
case 0xcf: c[0] = '"'; c[1] ='I'; break; /* "I */ |
| 1517 |
case 0xd0: c[0] = '-'; c[1] ='D'; break; /* -D */ |
| 1518 |
case 0xd1: c[0] = '~'; c[1] ='n'; break; /* ~n */ |
| 1519 |
case 0xd2: c[0] = '`'; c[1] ='O'; break; /* `O */ |
| 1520 |
case 0xd3: c[0] = '\''; c[1] ='O'; break; /* 'O */ |
| 1521 |
case 0xd4: c[0] = '^'; c[1] ='O'; break; /* ^O */ |
| 1522 |
case 0xd5: c[0] = '~'; c[1] ='O'; break; /* ~O */ |
| 1523 |
case 0xd6: c[0] = '"'; c[1] ='O'; break; /* "O */ |
| 1524 |
case 0xd9: c[0] = '`'; c[1] ='U'; break; /* `U */ |
| 1525 |
case 0xda: c[0] = '\''; c[1] ='U'; break; /* 'U */ |
| 1526 |
case 0xdb: c[0] = '^'; c[1] ='U'; break; /* ^U */ |
| 1527 |
case 0xdc: c[0] = '"'; c[1] ='U'; break; /* "U */ |
| 1528 |
case 0xdd: c[0] = '\''; c[1] ='Y'; break; /* 'Y */ |
| 1529 |
case 0xe0: c[0] = '`'; c[1] ='a'; break; /* `a */ |
| 1530 |
case 0xe1: c[0] = '\''; c[1] ='a'; break; /* 'a */ |
| 1531 |
case 0xe2: c[0] = '^'; c[1] ='a'; break; /* ^a */ |
| 1532 |
case 0xe3: c[0] = '~'; c[1] ='a'; break; /* ~a */ |
| 1533 |
case 0xe4: c[0] = '"'; c[1] ='a'; break; /* "a */ |
| 1534 |
case 0xe5: c[0] = 'a'; c[1] ='a'; break; /* oa */ |
| 1535 |
case 0xe7: c[0] = ','; c[1] ='c'; break; /* ,c */ |
| 1536 |
case 0xe8: c[0] = '`'; c[1] ='e'; break; /* `e */ |
| 1537 |
case 0xe9: c[0] = '\''; c[1] ='e'; break; /* 'e */ |
| 1538 |
case 0xea: c[0] = '^'; c[1] ='e'; break; /* ^e */ |
| 1539 |
case 0xeb: c[0] = '^'; c[1] ='e'; break; /* "e */ |
| 1540 |
case 0xec: c[0] = '`'; c[1] ='i'; break; /* `i */ |
| 1541 |
case 0xed: c[0] = '\''; c[1] ='i'; break; /* 'i */ |
| 1542 |
case 0xee: c[0] = '^'; c[1] ='i'; break; /* ^i */ |
| 1543 |
case 0xef: c[0] = '"'; c[1] ='i'; break; /* "i */ |
| 1544 |
case 0xf0: c[0] = '-'; c[1] ='d'; break; /* -d */ |
| 1545 |
case 0xf1: c[0] = '~'; c[1] ='n'; break; /* ~n */ |
| 1546 |
case 0xf2: c[0] = '`'; c[1] ='o'; break; /* `o */ |
| 1547 |
case 0xf3: c[0] = '\''; c[1] ='o'; break; /* 'o */ |
| 1548 |
case 0xf4: c[0] = '^'; c[1] ='o'; break; /* ^o */ |
| 1549 |
case 0xf5: c[0] = '~'; c[1] ='o'; break; /* ~o */ |
| 1550 |
case 0xf6: c[0] = '"'; c[1] ='o'; break; /* "o */ |
| 1551 |
case 0xf9: c[0] = '`'; c[1] ='u'; break; /* `u */ |
| 1552 |
case 0xfa: c[0] = '\''; c[1] ='u'; break; /* 'u */ |
| 1553 |
case 0xfb: c[0] = '^'; c[1] ='u'; break; /* ^u */ |
| 1554 |
case 0xfc: c[0] = '"'; c[1] ='u'; break; /* "u */ |
| 1555 |
case 0xfd: c[0] = '\''; c[1] ='y'; break; /* 'y */ |
| 1556 |
|
| 1557 |
/* diacritical marks */ |
| 1558 |
case 0x00: c[0] = '`' ; break; /* grave from \` */ |
| 1559 |
case 0x01: c[0] = latin1 ? 0xb4 : '\''; break; |
| 1560 |
/* acute from \' */ |
| 1561 |
case 0x02: c[0] = '^' ; break; /* circumflex from \^ */ |
| 1562 |
case 0x03: c[0] = '~' ; break; /* tilde from \~ */ |
| 1563 |
case 0x04: c[0] = '"' ; break; /* diaeresis from \" */ |
| 1564 |
case 0x05: c[0] = '"' ; break; /* double acute from \H */ |
| 1565 |
case 0x06: c[0] = latin1 ? 0xb0 : '~'; break; |
| 1566 |
/* ring above from \r */ |
| 1567 |
case 0x07: c[0] = '~' ; break; /* caron from \v */ |
| 1568 |
case 0x08: c[0] = '~' ; break; /* breve from \u */ |
| 1569 |
case 0x09: c[0] = '~' ; break; /* macron from \= */ |
| 1570 |
case 0x0a: c[0] = '.' ; break; /* dot from \. */ |
| 1571 |
case 0x0b: c[0] = latin1 ? 0xb8 : ','; break; |
| 1572 |
/* cedilla from \c */ |
| 1573 |
case 0x0c: c[0] = ',' ; break; /* ogonek from \k */ |
| 1574 |
|
| 1575 |
default : c[0] = '#'; |
| 1576 |
} |
| 1577 |
|
| 1578 |
cc=c; |
| 1579 |
while (*cc) { outchar(*cc); cc++; } |
| 1580 |
|
| 1581 |
return; |
| 1582 |
|
| 1583 |
} /* t1char */ |
| 1584 |
|
| 1585 |
|
| 1586 |
/* |
| 1587 |
* TS1CHAR -- Process a character opcode for a TS1 encoding font. |
| 1588 |
*/ |
| 1589 |
|
| 1590 |
void ts1char(unsigned char ch) |
| 1591 |
{ |
| 1592 |
unsigned char c[4] = {0}, *cc; |
| 1593 |
long ucs; |
| 1594 |
|
| 1595 |
if (allchar) { |
| 1596 |
outchar(ch); |
| 1597 |
return; |
| 1598 |
} |
| 1599 |
ucs = ts1_to_ucs[ch]; |
| 1600 |
if (utf8) { |
| 1601 |
dounichar(ucs); |
| 1602 |
return; |
| 1603 |
} |
| 1604 |
else if ((latin1 && ucs<0x100) || ucs<0x80) { |
| 1605 |
outchar(ucs); |
| 1606 |
return; |
| 1607 |
} |
| 1608 |
|
| 1609 |
switch (ch) { |
| 1610 |
case 0x17: /* \capitalcompwordmark */ |
| 1611 |
case 0x1F: return; /* \textascendercompwordmark */ |
| 1612 |
case 0x0D: /* \textquotestraightbase */ |
| 1613 |
case 0x27: c[0] = '\''; break; /* \textquotesingle */ |
| 1614 |
case 0x12: c[0] = '"'; break; /* \textquotestraghtdblbase */ |
| 1615 |
case 0x15: c[0] = '-'; break; /* \texttwelveudash */ |
| 1616 |
case 0x16: c[0] = '-'; c[1] = '-'; /* \textthreequartersemdash */ |
| 1617 |
break; |
| 1618 |
case 0x18: c[0] = '<'; c[1] = '-'; /* \textleftarrow */ |
| 1619 |
break; |
| 1620 |
case 0x19: c[0] = '-'; c[1] = '>'; /* \textrightarrow */ |
| 1621 |
break; |
| 1622 |
case 0x2A: c[0] = '*'; break; /* \textasteriskcentered */ |
| 1623 |
case 0x2D: c[0] = '='; break; /* \textdblhyphen */ |
| 1624 |
case 0x2F: c[0] = '/'; break; /* \textfractionsolidus */ |
| 1625 |
case 0x3C: c[0] = '<'; break; /* \textlangle */ |
| 1626 |
case 0x3D: c[0] = '-'; break; /* \textminus */ |
| 1627 |
case 0x3E: c[0] = '>'; break; /* \textrangle */ |
| 1628 |
case 0x5B: c[0] = '['; break; /* \textlbrackdbl */ |
| 1629 |
case 0x5D: c[0] = ']'; break; /* \textrbrackdbl */ |
| 1630 |
case 0x5E: c[0] = '^'; break; /* \textuparrow */ |
| 1631 |
case 0x5F: c[0] = 'v'; break; /* \textdownarrow */ |
| 1632 |
case 0x7E: c[0] = '~'; break; /* \texttildelow */ |
| 1633 |
case 0x7F: c[0] = '='; break; /* \textdblhyphenchar */ |
| 1634 |
case 0x84: c[0] = '*'; break; /* \textdagger */ |
| 1635 |
case 0x85: c[0] = '*'; c[1] = '*'; /* \textdaggerdbl */ |
| 1636 |
break; |
| 1637 |
case 0x86: c[0] = '|'; c[1] = '|'; /* \textbardbl */ |
| 1638 |
break; |
| 1639 |
case 0x89: if (latin1) { |
| 1640 |
c[0] = 0xb0; c[1] = 'C'; |
| 1641 |
} |
| 1642 |
else |
| 1643 |
c[0] = 'C'; |
| 1644 |
break; /* \textcelsius */ |
| 1645 |
case 0x8B: c[0] = 'c'; break; /* \textcent */ |
| 1646 |
case 0x8C: c[0] = 'f'; break; /* \textflorin */ |
| 1647 |
case 0x8D: c[0] = 'C'; break; /* \textcentoldstyle */ |
| 1648 |
case 0x8E: c[0] = 'W'; break; /* \textwon */ |
| 1649 |
case 0x8F: c[0] = 'N'; break; /* \textnaira */ |
| 1650 |
case 0x90: c[0] = 'G'; break; /* \textguarani */ |
| 1651 |
case 0x91: c[0] = 'P'; break; /* \textpeso */ |
| 1652 |
case 0x92: c[0] = 'L'; break; /* \textlira */ |
| 1653 |
case 0x93: c[0] = 'R'; break; /* \textrecipe */ |
| 1654 |
case 0x94: /* \textinterrobang */ |
| 1655 |
case 0x95: c[0] = '!'; c[1] = '?'; /* \textinterrobangdown */ |
| 1656 |
break; |
| 1657 |
case 0x97: c[0] = 'T'; c[1] = 'M'; /* \texttrademark */ |
| 1658 |
break; |
| 1659 |
case 0x99: c[0] = 'P'; break; /* \textpilcrow */ |
| 1660 |
case 0x9B: c[0] = 'N'; c[1] = 'o'; /* \textnumero */ |
| 1661 |
break; |
| 1662 |
case 0x9F: c[0] = 'S'; c[1] = 'M'; /* \textservicemark */ |
| 1663 |
break; |
| 1664 |
case 0xA0: c[0] = '{'; break; /* \textlquill */ |
| 1665 |
case 0xA1: c[0] = '}'; break; /* \textrquill */ |
| 1666 |
case 0xA2: c[0] = 'c'; break; /* \textcent */ |
| 1667 |
case 0xA3: c[0] = 'L'; break; /* \textsterling */ |
| 1668 |
case 0xA5: c[0] = 'Y'; break; /* \textyen */ |
| 1669 |
case 0xA6: c[0] = '|'; break; /* \textbrokenbar */ |
| 1670 |
case 0xA7: c[0] = 'S'; break; /* \textsection */ |
| 1671 |
case 0xA9: c[0] = 'C'; break; /* \textcopyright */ |
| 1672 |
case 0xAD: c[0] = 'P'; break; /* \textcircledP */ |
| 1673 |
case 0xAE: c[0] = 'R'; break; /* \textregistered */ |
| 1674 |
case 0xB6: c[0] = 'P'; break; /* \textparagraph */ |
| 1675 |
case 0xB1: c[0] = '+'; c[1] = '-'; /* \textpm */ |
| 1676 |
break; |
| 1677 |
case 0xBC: c[0] = '1'; c[1] = '/'; /* \textonequarter */ |
| 1678 |
c[2] = '4'; break; |
| 1679 |
case 0xBD: c[0] = '1'; c[1] = '/'; /* \textonehalf */ |
| 1680 |
c[2] = '2'; break; |
| 1681 |
case 0xBE: c[0] = '3'; c[1] = '/'; /* \textthreequarters */ |
| 1682 |
c[2] = '4'; break; |
| 1683 |
case 0xBF: c[0] = 'E'; break; /* \texteuro */ |
| 1684 |
case 0xD6: c[0] = 'x'; break; /* \texttimes */ |
| 1685 |
case 0xF6: c[0] = '/'; break; /* \textdiv */ |
| 1686 |
|
| 1687 |
case 0x30: case 0x31: case 0x32: case 0x33: |
| 1688 |
case 0x34: case 0x35: case 0x36: case 0x37: |
| 1689 |
case 0x38: case 0x39: case 0x3A: case 0x3B: |
| 1690 |
c[0] = ch; break; |
| 1691 |
|
| 1692 |
/* diacritical marks */ |
| 1693 |
case 0x00: c[0] = '`' ; break; /* grave from \` */ |
| 1694 |
case 0x01: c[0] = latin1 ? 0xb4 : '\''; break; |
| 1695 |
/* acute from \' */ |
| 1696 |
case 0x02: c[0] = '^' ; break; /* circumflex from \^ */ |
| 1697 |
case 0x03: c[0] = '~' ; break; /* tilde from \~ */ |
| 1698 |
case 0x04: c[0] = '"' ; break; /* diaeresis from \" */ |
| 1699 |
case 0x05: c[0] = '"' ; break; /* double acute from \H */ |
| 1700 |
case 0x06: c[0] = latin1 ? 0xb0 : '~'; break; |
| 1701 |
/* ring above from \r */ |
| 1702 |
case 0x07: c[0] = '~' ; break; /* caron from \v */ |
| 1703 |
case 0x08: c[0] = '~' ; break; /* breve from \u */ |
| 1704 |
case 0x09: c[0] = '~' ; break; /* macron from \= */ |
| 1705 |
case 0x0a: c[0] = '.' ; break; /* dot from \. */ |
| 1706 |
case 0x0b: c[0] = latin1 ? 0xb8 : ','; break; |
| 1707 |
/* cedilla from \c */ |
| 1708 |
case 0x0c: c[0] = ',' ; break; /* ogonek from \k */ |
| 1709 |
|
| 1710 |
default : c[0] = '#'; |
| 1711 |
} |
| 1712 |
|
| 1713 |
cc=c; |
| 1714 |
while (*cc) { outchar(*cc); cc++; } |
| 1715 |
|
| 1716 |
return; |
| 1717 |
|
| 1718 |
} /* ts1char */ |
| 1719 |
|
| 1720 |
|
| 1721 |
/* |
| 1722 |
* T2CHAR -- Process a character opcode for a T2A/T2B/T2C/X2 encoding font. |
| 1723 |
*/ |
| 1724 |
|
| 1725 |
void t2char(char flag, unsigned char ch) |
| 1726 |
{ |
| 1727 |
unsigned char c[4] = {0}, *cc; |
| 1728 |
const unsigned short *tex_to_ucs; |
| 1729 |
long ucs; |
| 1730 |
|
| 1731 |
if (allchar) { |
| 1732 |
outchar(ch); |
| 1733 |
return; |
| 1734 |
} |
| 1735 |
if (!accent) { |
| 1736 |
switch (ch) { |
| 1737 |
case 0x00: /* grave from \` */ |
| 1738 |
case 0x01: /* acute from \' */ |
| 1739 |
case 0x02: /* circumflex from \^ */ |
| 1740 |
case 0x03: /* tilde from \~ */ |
| 1741 |
case 0x04: /* diaeresis from \" */ |
| 1742 |
case 0x05: /* double acute from \H */ |
| 1743 |
case 0x06: /* ring above from \r */ |
| 1744 |
case 0x07: /* caron from \v */ |
| 1745 |
case 0x08: /* breve from \u */ |
| 1746 |
case 0x09: /* macron from \= */ |
| 1747 |
case 0x0a: /* dot from \. */ |
| 1748 |
case 0x0b: /* cedilla from \c */ |
| 1749 |
case 0x0c: /* ogonek from \k */ |
| 1750 |
case 0x12: /* from \f */ |
| 1751 |
case 0x13: /* from \C */ |
| 1752 |
case 0x14: /* breve from \U */ |
| 1753 |
return; |
| 1754 |
} |
| 1755 |
} |
| 1756 |
switch (flag) { |
| 1757 |
case T2AFONT: tex_to_ucs=t2a_to_ucs; break; |
| 1758 |
case T2BFONT: tex_to_ucs=t2b_to_ucs; break; |
| 1759 |
case T2CFONT: tex_to_ucs=t2c_to_ucs; break; |
| 1760 |
case X2FONT : tex_to_ucs=x2_to_ucs; break; |
| 1761 |
default : exit(41); /* not supported */ |
| 1762 |
} |
| 1763 |
ucs = tex_to_ucs[ch]; |
| 1764 |
if (utf8) { |
| 1765 |
dounichar(ucs); |
| 1766 |
return; |
| 1767 |
} |
| 1768 |
else if ((latin1 && ucs<0x100) || ucs<0x80) { |
| 1769 |
outchar(ucs); |
| 1770 |
return; |
| 1771 |
} |
| 1772 |
|
| 1773 |
switch (ch) { |
| 1774 |
case 0x49: c[0] = 'I'; break; /* \CYRII */ |
| 1775 |
case 0x69: c[0] = 'i'; break; /* \cyrii */ |
| 1776 |
case 0x4A: c[0] = 'J'; break; /* \CYRJE */ |
| 1777 |
case 0x6A: c[0] = 'j'; break; /* \cyrje */ |
| 1778 |
case 0x51: c[0] = 'Q'; break; /* \CYRQ */ |
| 1779 |
case 0x53: c[0] = 'S'; break; /* \CYRDZE */ |
| 1780 |
case 0x57: c[0] = 'W'; break; /* \CYRW */ |
| 1781 |
case 0x71: c[0] = 'q'; break; /* \cyrq */ |
| 1782 |
case 0x73: c[0] = 's'; break; /* \cyrdze */ |
| 1783 |
case 0x77: c[0] = 'w'; break; /* \cyrw */ |
| 1784 |
case 0x0E: c[0] = '<'; break; /* \cyrlangle */ |
| 1785 |
case 0x0F: c[0] = '>'; break; /* \cyrrangle */ |
| 1786 |
case 0x15: c[0] = '-'; c[1] = '-'; /* \textendash */ |
| 1787 |
break; |
| 1788 |
case 0x16: c[0] = '-'; c[1] = '-'; /* \textemdash */ |
| 1789 |
c[2] = '-'; break; |
| 1790 |
case 0x27: /* \textquoteright */ |
| 1791 |
case 0x60: c[0] = '\''; break; /* \textquoteleft */ |
| 1792 |
case 0x10: /* \textquotedblleft */ |
| 1793 |
case 0x11: /* \textquotedblright */ |
| 1794 |
case 0xBD: c[0] = '"'; break; /* \quotedblbase */ |
| 1795 |
case 0x20: c[0] = '_'; break; /* \textvisiblespace */ |
| 1796 |
case 0x17: return; /* \textcompwordmark */ |
| 1797 |
case 0x7E: c[0] = '~'; break; /* \textasciitilde */ |
| 1798 |
case 0x9D: c[0] = 'N'; c[1] = 'o'; /* \textnumero */ |
| 1799 |
break; |
| 1800 |
case 0x9F: c[0] = 'S'; break; /* \textsection */ |
| 1801 |
case 0xBE: c[0] = '<'; c[1] = '<'; /* \guillemotleft */ |
| 1802 |
break; |
| 1803 |
case 0xBF: c[0] = '>'; c[1] = '>'; /* \guillemotright */ |
| 1804 |
break; |
| 1805 |
|
| 1806 |
/* diacritical marks */ |
| 1807 |
case 0x00: c[0] = '`' ; break; /* grave from \` */ |
| 1808 |
case 0x01: c[0] = latin1 ? 0xb4 : '\''; break; |
| 1809 |
/* acute from \' */ |
| 1810 |
case 0x02: c[0] = '^' ; break; /* circumflex from \^ */ |
| 1811 |
case 0x03: c[0] = '~' ; break; /* tilde from \~ */ |
| 1812 |
case 0x04: c[0] = '"' ; break; /* diaeresis from \" */ |
| 1813 |
case 0x05: c[0] = '"' ; break; /* double acute from \H */ |
| 1814 |
case 0x06: c[0] = latin1 ? 0xb0 : '~'; break; |
| 1815 |
/* ring above from \r */ |
| 1816 |
case 0x07: c[0] = '~' ; break; /* caron from \v */ |
| 1817 |
case 0x08: c[0] = '~' ; break; /* breve from \u */ |
| 1818 |
case 0x09: c[0] = '~' ; break; /* macron from \= */ |
| 1819 |
case 0x0a: c[0] = '.' ; break; /* dot from \. */ |
| 1820 |
case 0x0b: c[0] = latin1 ? 0xb8 : ','; break; |
| 1821 |
/* cedilla from \c */ |
| 1822 |
case 0x0c: c[0] = ',' ; break; /* ogonek from \k */ |
| 1823 |
case 0x14: c[0] = '~' ; break; /* breve from \U */ |
| 1824 |
|
| 1825 |
default : c[0] = '#'; |
| 1826 |
} |
| 1827 |
if (flag != X2FONT) { |
| 1828 |
switch (ch) { |
| 1829 |
case 0x19: c[0] = 'i'; break; /* dotless i */ |
| 1830 |
case 0x1A: c[0] = 'j'; break; /* dotless j */ |
| 1831 |
case 0x1B: c[0] = 'f'; c[1] = 'f'; /* ligature */ |
| 1832 |
break; |
| 1833 |
case 0x1C: c[0] = 'f'; c[1] = 'i'; /* ligature */ |
| 1834 |
break; |
| 1835 |
case 0x1D: c[0] = 'f'; c[1] = 'l'; /* ligature */ |
| 1836 |
break; |
| 1837 |
case 0x1E: c[0] = 'f'; c[1] = 'f'; /* ligature */ |
| 1838 |
c[2] = 'i'; break; |
| 1839 |
case 0x1F: c[0] = 'f'; c[1] = 'f'; /* ligature */ |
| 1840 |
c[2] = 'l'; break; |
| 1841 |
} |
| 1842 |
} |
| 1843 |
|
| 1844 |
cc=c; |
| 1845 |
while (*cc) { outchar(*cc); cc++; } |
| 1846 |
|
| 1847 |
return; |
| 1848 |
|
| 1849 |
} /* t2char */ |
| 1850 |
|
| 1851 |
|
| 1852 |
/* |
| 1853 |
* OT2CHAR -- Process a character opcode for a OT2 encoding font. |
| 1854 |
*/ |
| 1855 |
|
| 1856 |
void ot2char(unsigned char ch) |
| 1857 |
{ |
| 1858 |
unsigned char c[4] = {0}, *cc; |
| 1859 |
long ucs; |
| 1860 |
|
| 1861 |
if (allchar) { |
| 1862 |
outchar(ch); |
| 1863 |
return; |
| 1864 |
} |
| 1865 |
if (!accent) { |
| 1866 |
switch (ch) { |
| 1867 |
case 0x20: /* diaeresis from \" */ |
| 1868 |
case 0x24: /* breve from \U */ |
| 1869 |
case 0x26: /* acute from \' */ |
| 1870 |
case 0x40: /* breve from \u */ |
| 1871 |
return; |
| 1872 |
} |
| 1873 |
} |
| 1874 |
ucs = ot2_to_ucs[ch]; |
| 1875 |
if (utf8) { |
| 1876 |
dounichar(ucs); |
| 1877 |
return; |
| 1878 |
} |
| 1879 |
else if ((latin1 && ucs<0x100) || ucs<0x80) { |
| 1880 |
outchar(ucs); |
| 1881 |
return; |
| 1882 |
} |
| 1883 |
|
| 1884 |
switch (ch) { |
| 1885 |
case 0x04: c[0] = 'I'; break; /* \CYRII */ |
| 1886 |
case 0x0C: c[0] = 'i'; break; /* \cyrii */ |
| 1887 |
case 0x4A: c[0] = 'J'; break; /* \CYRJE */ |
| 1888 |
case 0x6A: c[0] = 'j'; break; /* \cyrje */ |
| 1889 |
case 0x16: c[0] = 'S'; break; /* \CYRDZE */ |
| 1890 |
case 0x1E: c[0] = 's'; break; /* \cyrdze */ |
| 1891 |
case 0x7B: c[0] = '-'; c[1] = '-'; /* \textendash */ |
| 1892 |
break; |
| 1893 |
case 0x7C: c[0] = '-'; c[1] = '-'; /* \textemdash */ |
| 1894 |
c[2] = '-'; break; |
| 1895 |
case 0x7D: c[0] = 'N'; c[1] = 'o'; /* \textnumero */ |
| 1896 |
break; |
| 1897 |
case 0x3C: c[0] = '<'; c[1] = '<'; /* \guillemotleft */ |
| 1898 |
break; |
| 1899 |
case 0x3D: c[0] = 'i'; break; /* dotless i */ |
| 1900 |
case 0x3E: c[0] = '>'; c[1] = '>'; /* \guillemotright */ |
| 1901 |
break; |
| 1902 |
case 0x27: /* \textquoteright */ |
| 1903 |
case 0x60: c[0] = '\''; break; /* \textquoteleft */ |
| 1904 |
case 0x22: /* \textquotedblright */ |
| 1905 |
case 0x5C: c[0] = '"'; break; /* \textquotedblleft */ |
| 1906 |
|
| 1907 |
/* diacritical marks */ |
| 1908 |
case 0x20: c[0] = '"' ; break; /* diaeresis from \" */ |
| 1909 |
case 0x24: c[0] = '~' ; break; /* breve from \u */ |
| 1910 |
case 0x26: c[0] = latin1 ? 0xb4 : '\''; break; |
| 1911 |
/* acute from \' */ |
| 1912 |
case 0x40: c[0] = '~' ; break; /* breve from \U */ |
| 1913 |
|
| 1914 |
default : c[0] = '#'; |
| 1915 |
} |
| 1916 |
|
| 1917 |
cc=c; |
| 1918 |
while (*cc) { outchar(*cc); cc++; } |
| 1919 |
|
| 1920 |
return; |
| 1921 |
|
| 1922 |
} /* ot2char */ |
| 1923 |
|
| 1924 |
|
| 1925 |
|
| 1926 |
/* |
| 1927 |
* OUTCHAR -- Here we put the character into the current page. |
| 1928 |
* |
| 1929 |
* This function includes some code to handle Latin1/Scandinavian |
| 1930 |
* characters. I think that code doesn't belong here. IT |
| 1931 |
* SHOULD BE MOVED OUT. |
| 1932 |
*/ |
| 1933 |
|
| 1934 |
void outchar(long ch) |
| 1935 |
{ |
| 1936 |
register int i, j; |
| 1937 |
register long dia; |
| 1938 |
|
| 1939 |
/* fprintf(stderr, "hor: %ld, ver: %ld\n", h, v); */ |
| 1940 |
|
| 1941 |
if (labs(v - currentline->vv) > lineheight / 2L) |
| 1942 |
currentline = findline(); |
| 1943 |
|
| 1944 |
#if 0 |
| 1945 |
j = (int) (((double) h / (double) maxpagewidth) * (ttywidth-1)) + 1; |
| 1946 |
#else |
| 1947 |
j = (int) (h / charwidth); |
| 1948 |
#endif |
| 1949 |
if (j > rightmargin) /* leftmargin <= j <= rightmargin */ |
| 1950 |
j = rightmargin; |
| 1951 |
else if (j < leftmargin) |
| 1952 |
j = leftmargin; |
| 1953 |
foo = leftmargin - 1; |
| 1954 |
|
| 1955 |
/* |
| 1956 |
* This code does not really belong here ... |
| 1957 |
* |
| 1958 |
* The following is very specialized code, it handles national * |
| 1959 |
* Swe/Fin characters. They are respectively: a and o with two * |
| 1960 |
* dots ("a & "o) and a with a circle (Oa). In Swe/Fin "ASCII" * |
| 1961 |
* these characters replace {}|[] and \. TeX outputs these by * |
| 1962 |
* first issuing the dots or circle and then backspace and set * |
| 1963 |
* the a or o. When dvi2tty finds an a or o it searches in the * |
| 1964 |
* near vicinity for the character codes that represent circle * |
| 1965 |
* or dots and if one is found the corresponding national char * |
| 1966 |
* replaces the special character codes. * |
| 1967 |
*/ |
| 1968 |
if (!allchar && compose && scascii) { |
| 1969 |
if (strchr("aAoO", ch) != NULL) { |
| 1970 |
for (i = IMAX(leftmargin, j-2); |
| 1971 |
i <= IMIN(rightmargin, j+2); |
| 1972 |
i++) |
| 1973 |
if ((currentline->text[i - leftmargin] == 127) || /* DEL */ |
| 1974 |
(currentline->text[i - leftmargin] == 34) || /* " */ |
| 1975 |
(currentline->text[i - leftmargin] == 23)) |
| 1976 |
foo = i; |
| 1977 |
if (foo >= leftmargin) { |
| 1978 |
j = (int) foo; |
| 1979 |
switch (currentline->text[j - leftmargin]) { |
| 1980 |
case 127 : |
| 1981 |
case 34 : /* DEL or " */ |
| 1982 |
if (ch == 'a') |
| 1983 |
ch = '{'; /* } vi */ |
| 1984 |
else if (ch == 'A') /* dots ... */ |
| 1985 |
ch = '['; |
| 1986 |
else if (ch == 'o') |
| 1987 |
ch = '|'; |
| 1988 |
else if (ch == 'O') |
| 1989 |
ch = '\\'; |
| 1990 |
break; |
| 1991 |
case 23 : if (ch == 'a') |
| 1992 |
ch = '}'; /* { vi */ |
| 1993 |
else if (ch == 'A') /* circle */ |
| 1994 |
ch = ']'; |
| 1995 |
break; |
| 1996 |
} |
| 1997 |
} |
| 1998 |
} |
| 1999 |
} |
| 2000 |
if (!allchar && compose && (latin1 || utf8)) { |
| 2001 |
if (strchr("aAeEiIoOuUnCcNYy", ch) != NULL || (ch & MAX_UNICODE) == 0x131) { |
| 2002 |
for (i = IMAX(leftmargin, j-2); |
| 2003 |
i <= IMIN(rightmargin, j+2); |
| 2004 |
i++) { |
| 2005 |
dia = currentline->text[i - leftmargin] & MAX_UNICODE; |
| 2006 |
if ((dia == 0x60) || /* grave */ |
| 2007 |
(dia == 0xB0) || /* ring above */ |
| 2008 |
(dia == 0x2DA) || /* ring above */ |
| 2009 |
(dia == 0xB4) || /* acute */ |
| 2010 |
(dia == 0x5E) || /* circumflex */ |
| 2011 |
(dia == 0xA8) || /* diaeresis */ |
| 2012 |
(dia == 0xB8) || /* cedilla */ |
| 2013 |
(dia == 0x7E) || /* tilde */ |
| 2014 |
(dia == 0x2DC)) /* tilde */ |
| 2015 |
foo = i; |
| 2016 |
} |
| 2017 |
if (foo >= leftmargin) { |
| 2018 |
j = (int) foo; |
| 2019 |
dia = currentline->text[j - leftmargin] & MAX_UNICODE; |
| 2020 |
switch (dia) { |
| 2021 |
case 0x60: /* grave */ |
| 2022 |
if (ch == 'a') ch = 0xe0; |
| 2023 |
else if (ch == 'A') ch = 0xc0; |
| 2024 |
else if (ch == 'e') ch = 0xe8; |
| 2025 |
else if (ch == 'E') ch = 0xc8; |
| 2026 |
else if (ch == 'i') ch = 0xec; |
| 2027 |
else if ((ch & MAX_UNICODE) == 0x131) ch = 0xec; |
| 2028 |
else if (ch == 'I') ch = 0xcc; |
| 2029 |
else if (ch == 'o') ch = 0xf2; |
| 2030 |
else if (ch == 'O') ch = 0xd2; |
| 2031 |
else if (ch == 'u') ch = 0xf9; |
| 2032 |
else if (ch == 'U') ch = 0xd9; |
| 2033 |
break; |
| 2034 |
case 0xB0: /* ring above */ |
| 2035 |
case 0x2DA: |
| 2036 |
if (ch == 'a') ch = 0xe5; |
| 2037 |
else if (ch == 'A') ch = 0xc5; |
| 2038 |
break; |
| 2039 |
case 0xB4: /* acute */ |
| 2040 |
if (ch == 'a') ch = 0xe1; |
| 2041 |
else if (ch == 'A') ch = 0xc1; |
| 2042 |
else if (ch == 'e') ch = 0xe9; |
| 2043 |
else if (ch == 'E') ch = 0xc9; |
| 2044 |
else if (ch == 'i') ch = 0xed; |
| 2045 |
else if ((ch & MAX_UNICODE) == 0x131) ch = 0xed; |
| 2046 |
else if (ch == 'I') ch = 0xcd; |
| 2047 |
else if (ch == 'o') ch = 0xf3; |
| 2048 |
else if (ch == 'O') ch = 0xd3; |
| 2049 |
else if (ch == 'u') ch = 0xfa; |
| 2050 |
else if (ch == 'U') ch = 0xda; |
| 2051 |
else if (ch == 'y') ch = 0xfd; |
| 2052 |
else if (ch == 'Y') ch = 0xdd; |
| 2053 |
break; |
| 2054 |
case 0x5E: /* circumflex */ |
| 2055 |
if (ch == 'a') ch = 0xe2; |
| 2056 |
else if (ch == 'A') ch = 0xc2; |
| 2057 |
else if (ch == 'e') ch = 0xea; |
| 2058 |
else if (ch == 'E') ch = 0xca; |
| 2059 |
else if (ch == 'i') ch = 0xee; |
| 2060 |
else if ((ch & MAX_UNICODE) == 0x131) ch = 0xee; |
| 2061 |
else if (ch == 'I') ch = 0xce; |
| 2062 |
else if (ch == 'o') ch = 0xf4; |
| 2063 |
else if (ch == 'O') ch = 0xd4; |
| 2064 |
else if (ch == 'u') ch = 0xfb; |
| 2065 |
else if (ch == 'U') ch = 0xdb; |
| 2066 |
break; |
| 2067 |
case 0xA8: /* diaeresis */ |
| 2068 |
if (ch == 'a') ch = 0xe4; |
| 2069 |
else if (ch == 'A') ch = 0xc4; |
| 2070 |
else if (ch == 'e') ch = 0xeb; |
| 2071 |
else if (ch == 'E') ch = 0xcb; |
| 2072 |
else if (ch == 'i') ch = 0xef; |
| 2073 |
else if ((ch & MAX_UNICODE) == 0x131) ch = 0xef; |
| 2074 |
else if (ch == 'I') ch = 0xcf; |
| 2075 |
else if (ch == 'o') ch = 0xf6; |
| 2076 |
else if (ch == 'O') ch = 0xd6; |
| 2077 |
else if (ch == 'u') ch = 0xfc; |
| 2078 |
else if (ch == 'U') ch = 0xdc; |
| 2079 |
else if (ch == 'y') ch = 0xff; |
| 2080 |
else if (ch == 'Y' && utf8) ch = 0x178; |
| 2081 |
break; |
| 2082 |
case 0xB8: /* cedilla */ |
| 2083 |
if (ch == 'c') ch = 0xe7; |
| 2084 |
else if (ch == 'C') ch = 0xc7; /* It does not seem to work */ |
| 2085 |
break; |
| 2086 |
case 0x7E: /* tilde */ |
| 2087 |
case 0x2DC: |
| 2088 |
if (ch == 'a') ch = 0xe3; |
| 2089 |
else if (ch == 'A') ch = 0xc3; |
| 2090 |
else if (ch == 'o') ch = 0xf5; |
| 2091 |
else if (ch == 'O') ch = 0xd5; |
| 2092 |
else if (ch == 'n') ch = 0xf1; |
| 2093 |
else if (ch == 'N') ch = 0xd1; |
| 2094 |
break; |
| 2095 |
} |
| 2096 |
if (utf8 && ch>0x7f) ch |= IS_UNICODE; |
| 2097 |
} |
| 2098 |
} |
| 2099 |
} |
| 2100 |
/*----------------- end of 'latin1 / Scandinavian code' ----------------*/ |
| 2101 |
|
| 2102 |
if (foo == leftmargin-1) { |
| 2103 |
if (japan) { |
| 2104 |
while (((currentline->text[j - leftmargin] != SPACE) || |
| 2105 |
(kanji1 && (currentline->text[j+kanji1 - leftmargin] != SPACE))) |
| 2106 |
&& (j < rightmargin)) { |
| 2107 |
j++; |
| 2108 |
h += charwidth; |
| 2109 |
} |
| 2110 |
} else { |
| 2111 |
while (j < rightmargin && |
| 2112 |
(currentline->text[j - leftmargin] != SPACE)) { |
| 2113 |
j++; |
| 2114 |
h += charwidth; |
| 2115 |
} |
| 2116 |
} |
| 2117 |
} |
| 2118 |
if ( allchar || ((ch >= SPACE) && (ch != DEL)) || |
| 2119 |
((latin1 || scascii) && (ch == 23)) ) { |
| 2120 |
if (j < rightmargin) |
| 2121 |
currentline->text[j - leftmargin] = ch; |
| 2122 |
else |
| 2123 |
currentline->text[rightmargin - leftmargin] = '@'; |
| 2124 |
if (j > currentline->charactercount) |
| 2125 |
currentline->charactercount = j; |
| 2126 |
if (j < firstcolumn) |
| 2127 |
firstcolumn = j; |
| 2128 |
} |
| 2129 |
h += charwidth; |
| 2130 |
|
| 2131 |
return; |
| 2132 |
|
| 2133 |
} /* outchar */ |
| 2134 |
|
| 2135 |
|
| 2136 |
|
| 2137 |
/* |
| 2138 |
* PUTCHARACTER -- Output character, don't change h |
| 2139 |
*/ |
| 2140 |
|
| 2141 |
void putcharacter(long charnr) |
| 2142 |
{ |
| 2143 |
register long saveh; |
| 2144 |
|
| 2145 |
saveh = h; |
| 2146 |
if (nttj || is8bit) |
| 2147 |
dochar((unsigned char) charnr); |
| 2148 |
else if (allchar || ((charnr >= 0) && (charnr <= LASTCHAR))) |
| 2149 |
outchar((unsigned char) charnr); |
| 2150 |
else |
| 2151 |
setchar(charnr); |
| 2152 |
h = saveh; |
| 2153 |
|
| 2154 |
return; |
| 2155 |
|
| 2156 |
} /* putcharacter */ |
| 2157 |
|
| 2158 |
|
| 2159 |
|
| 2160 |
/* |
| 2161 |
* SETCHAR -- Should print characters with character code>127 from |
| 2162 |
* current font. Note that the parameter is a dummy, since |
| 2163 |
* ascii-chars are<=127. |
| 2164 |
*/ |
| 2165 |
|
| 2166 |
void setchar(long charnr) |
| 2167 |
{ |
| 2168 |
|
| 2169 |
if (is8bit) |
| 2170 |
dochar((unsigned char) charnr); |
| 2171 |
else |
| 2172 |
outchar((unsigned char)(allchar ? charnr : '#')); |
| 2173 |
|
| 2174 |
return; |
| 2175 |
|
| 2176 |
} /* setchar */ |
| 2177 |
|
| 2178 |
|
| 2179 |
static const char *ptex_fontchk[] = { |
| 2180 |
"min", "goth", "jis", |
| 2181 |
"hmin", "hgoth", "hmgoth", /* japanese-otf package */ |
| 2182 |
"nmlmin", "nmlgoth", "nmlmgoth", |
| 2183 |
"hiramin", "hirakaku", "hiramaru", |
| 2184 |
NULL /* end */ |
| 2185 |
}; |
| 2186 |
|
| 2187 |
static const char *uptex_fontchk[] = { |
| 2188 |
"umin", "ugoth", "ujis", |
| 2189 |
"upjis", "upjpn", "upsch", "uptch", "upkor", |
| 2190 |
"uphmin", "uphgoth", "uphmgoth", /* japanese-otf package */ |
| 2191 |
"upnmlmin", "upnmlgoth", "upnmlmgoth", |
| 2192 |
"uphiramin", "uphirakaku", "uphiramaru", |
| 2193 |
NULL /* end */ |
| 2194 |
}; |
| 2195 |
|
| 2196 |
static const char *jtex_fontchk[] = { |
| 2197 |
"dmj", "dgj", |
| 2198 |
NULL /* end */ |
| 2199 |
}; |
| 2200 |
|
| 2201 |
static int checkjfont(const char **jfontlist, const char *name) |
| 2202 |
{ |
| 2203 |
int i, len; |
| 2204 |
const char *tmpfont; |
| 2205 |
|
| 2206 |
i=0; |
| 2207 |
while ( (tmpfont=jfontlist[i]) != NULL ) { |
| 2208 |
len=strlen(tmpfont); |
| 2209 |
if ( !strncmp(tmpfont, name, len) ) return 1; |
| 2210 |
i++; |
| 2211 |
} |
| 2212 |
return 0; |
| 2213 |
} /* checkjfont */ |
| 2214 |
|
| 2215 |
|
| 2216 |
|
| 2217 |
/* |
| 2218 |
* FONTDEF -- Process a font definition. |
| 2219 |
*/ |
| 2220 |
|
| 2221 |
void fontdef(int x) |
| 2222 |
{ |
| 2223 |
register int i; |
| 2224 |
char * name; |
| 2225 |
font * fnt; |
| 2226 |
int namelen; |
| 2227 |
long fntnum; |
| 2228 |
int new = 0; |
| 2229 |
|
| 2230 |
fntnum = num(x); |
| 2231 |
(void) get4(); /* checksum */ |
| 2232 |
(void) get4(); /* scale */ |
| 2233 |
(void) get4(); /* design */ |
| 2234 |
namelen = (int) get1() + (int) get1(); |
| 2235 |
fnt = fonts; |
| 2236 |
while (fnt != NULL && fnt->num != fntnum) /* does fontnum exist */ |
| 2237 |
fnt = fnt->next; |
| 2238 |
if (fnt == NULL) { |
| 2239 |
if ((fnt = (font *) malloc(sizeof(font))) == NULL) { |
| 2240 |
perror("fontdef"); |
| 2241 |
exit(40); |
| 2242 |
} |
| 2243 |
fnt->num = fntnum; |
| 2244 |
new = 1; |
| 2245 |
} |
| 2246 |
else |
| 2247 |
free(fnt->name); /* free old name */ |
| 2248 |
if ((name = (char *) malloc((namelen+1) * sizeof(char))) == NULL) { |
| 2249 |
perror("fontdef"); |
| 2250 |
exit(40); |
| 2251 |
} |
| 2252 |
|
| 2253 |
for (i = 0; i < namelen; i++) |
| 2254 |
name[i] = get1(); |
| 2255 |
name[i] = '\0'; /* properly end string */ |
| 2256 |
fnt->name = name; |
| 2257 |
if (new) { |
| 2258 |
fnt->next = fonts; |
| 2259 |
fonts = fnt; |
| 2260 |
} |
| 2261 |
|
| 2262 |
/* |
| 2263 |
* some magic to learn about font types... |
| 2264 |
*/ |
| 2265 |
fonts->flags = 0; |
| 2266 |
fonts->is8bit = FALSE; |
| 2267 |
|
| 2268 |
if ((asciip == FALSE && nttj == FALSE && uptex == FALSE) |
| 2269 |
&& (!jdetect) && jautodetect) { |
| 2270 |
if ( checkjfont(ptex_fontchk, name) ) { |
| 2271 |
/* Detect as ASCII TeX */ |
| 2272 |
asciip = TRUE; |
| 2273 |
nttj = uptex = FALSE; |
| 2274 |
japan = jdetect = TRUE; |
| 2275 |
fonts->flags |= MIFONT; |
| 2276 |
set_enc_string (NULL, PTEX_INTERNAL_ENC); |
| 2277 |
} else if ( checkjfont(uptex_fontchk, name) ) { |
| 2278 |
/* Detect as upTeX */ |
| 2279 |
uptex = TRUE; |
| 2280 |
nttj = asciip = FALSE; |
| 2281 |
japan = jdetect = TRUE; |
| 2282 |
fonts->flags |= MIFONT; |
| 2283 |
enable_UPTEX(true); |
| 2284 |
set_enc_string (NULL, UPTEX_INTERNAL_ENC); |
| 2285 |
} else if ( checkjfont(jtex_fontchk, name) ) { |
| 2286 |
/* Detect as NTT JTeX */ |
| 2287 |
nttj = TRUE; |
| 2288 |
asciip = uptex = FALSE; |
| 2289 |
japan = jdetect = TRUE; |
| 2290 |
fonts->flags |= JPFONT; |
| 2291 |
set_enc_string (NULL, JTEX_INTERNAL_ENC); |
| 2292 |
} |
| 2293 |
} |
| 2294 |
if (nttj) |
| 2295 |
fonts->fontnum = getjsubfont(name); |
| 2296 |
else |
| 2297 |
fonts->fontnum = 0; |
| 2298 |
|
| 2299 |
if ((strncmp(name, "ec", 2)) == 0) { |
| 2300 |
fonts->flags = T1FONT; |
| 2301 |
fonts->is8bit = TRUE; |
| 2302 |
return; |
| 2303 |
} |
| 2304 |
else if ((strncmp(name, "tc", 2)) == 0 || |
| 2305 |
(strncmp(name, "ts1", 3)) == 0) { |
| 2306 |
fonts->flags = TS1FONT; |
| 2307 |
fonts->is8bit = TRUE; |
| 2308 |
return; |
| 2309 |
} |
| 2310 |
else if ((strncmp(name, "wn", 2)) == 0) { |
| 2311 |
fonts->flags = OT2FONT; |
| 2312 |
return; |
| 2313 |
} |
| 2314 |
else if ((strncmp(name, "la", 2)) == 0) { |
| 2315 |
fonts->flags = T2AFONT; |
| 2316 |
fonts->is8bit = TRUE; |
| 2317 |
return; |
| 2318 |
} |
| 2319 |
else if ((strncmp(name, "lb", 2)) == 0) { |
| 2320 |
fonts->flags = T2BFONT; |
| 2321 |
fonts->is8bit = TRUE; |
| 2322 |
return; |
| 2323 |
} |
| 2324 |
else if ((strncmp(name, "lc", 2)) == 0) { |
| 2325 |
fonts->flags = T2CFONT; |
| 2326 |
fonts->is8bit = TRUE; |
| 2327 |
return; |
| 2328 |
} |
| 2329 |
else if ((strncmp(name, "rx", 2)) == 0) { |
| 2330 |
fonts->flags = X2FONT; |
| 2331 |
fonts->is8bit = TRUE; |
| 2332 |
return; |
| 2333 |
} |
| 2334 |
if ((strstr(name, "sy")) != NULL) |
| 2335 |
fonts->flags = SYMFONT; |
| 2336 |
if ((strstr(name, "tt")) != NULL) |
| 2337 |
fonts->flags = TTFONT; |
| 2338 |
if ((strstr(name, "mi")) != NULL) |
| 2339 |
fonts->flags = MIFONT; |
| 2340 |
|
| 2341 |
return; |
| 2342 |
|
| 2343 |
} /* fontdef */ |
| 2344 |
|
| 2345 |
|
| 2346 |
|
| 2347 |
#define NJSUBS 33 |
| 2348 |
const char *jsf_names[]={ |
| 2349 |
"sy", "roma", "hira", "kata", "greek", "russian", "keisen", |
| 2350 |
"ka", "kb", "kc", "kd", "ke", "kf", "kg", "kh", "ki", "kj", |
| 2351 |
"kk", "kl", "km", "kn", "ko", "kp", "kq", "kr", "ks", "kt", |
| 2352 |
"ku", "kv", "kw", "kx", "ky", "kz" |
| 2353 |
}; |
| 2354 |
|
| 2355 |
|
| 2356 |
int getjsubfont(char *s) |
| 2357 |
{ |
| 2358 |
int jf; |
| 2359 |
|
| 2360 |
if (strlen(s) > 3 && s[0] == 'd' && (s[1] == 'm' || s[1] == 'g') && s[2] == 'j') { |
| 2361 |
for (jf = 0; jf < NJSUBS; jf++) { |
| 2362 |
if (strncmp(&s[3], jsf_names[jf], strlen(jsf_names[jf])) == 0) |
| 2363 |
return jf+1; |
| 2364 |
} |
| 2365 |
} |
| 2366 |
|
| 2367 |
return 0; |
| 2368 |
|
| 2369 |
} /* getjsubfont */ |
| 2370 |
|
| 2371 |
|
| 2372 |
|
| 2373 |
/* |
| 2374 |
* SETFONT -- Switch to specific font. Try to find out if it is a symbol |
| 2375 |
* font. |
| 2376 |
* Option -c allchar does not pertain to this portion, so symbols |
| 2377 |
* are still translated. |
| 2378 |
*/ |
| 2379 |
|
| 2380 |
void setfont(long fntnum) |
| 2381 |
{ |
| 2382 |
char * s; |
| 2383 |
const char * d; |
| 2384 |
|
| 2385 |
symbolfont = FALSE; |
| 2386 |
ttfont = FALSE; |
| 2387 |
mifont = FALSE; |
| 2388 |
fnt = fonts; |
| 2389 |
|
| 2390 |
while (fnt != NULL && fnt->num != fntnum) |
| 2391 |
fnt = fnt->next; |
| 2392 |
|
| 2393 |
if (fnt == NULL) { |
| 2394 |
/* error : font not found */ |
| 2395 |
return; |
| 2396 |
} |
| 2397 |
|
| 2398 |
if (fnt->fontnum == 0) { |
| 2399 |
symbolfont = fnt->flags == SYMFONT; |
| 2400 |
ttfont = fnt->flags == TTFONT; |
| 2401 |
mifont = fnt->flags == MIFONT; |
| 2402 |
is8bit = fnt->is8bit; |
| 2403 |
} |
| 2404 |
|
| 2405 |
s = fnt->name; |
| 2406 |
if (printfont) { |
| 2407 |
d = delim; /* print delim and font name if -b was chosen */ |
| 2408 |
while (*d) {putcharacter(*d); d++;} |
| 2409 |
while (*s) {putcharacter(*s); s++;} |
| 2410 |
while (d-- > delim) {putcharacter(*d);} |
| 2411 |
} |
| 2412 |
|
| 2413 |
return; |
| 2414 |
|
| 2415 |
} /* setfont */ |
| 2416 |
|
| 2417 |
|
| 2418 |
|
| 2419 |
void jischar(unsigned long ch) |
| 2420 |
{ |
| 2421 |
unsigned int Ku, Ten; |
| 2422 |
|
| 2423 |
compute_jis(fnt->fontnum, (unsigned int) ch, &Ku, &Ten); |
| 2424 |
kanji1 = 1; |
| 2425 |
outchar((unsigned char)(Ku+128)); |
| 2426 |
kanji1 = 0; |
| 2427 |
outchar((unsigned char)(Ten+128)); |
| 2428 |
|
| 2429 |
return; |
| 2430 |
|
| 2431 |
} /* jischar */ |
| 2432 |
|
| 2433 |
#define kushift(c) c+0x20 |
| 2434 |
#define tenshift(c) c+0x20 |
| 2435 |
|
| 2436 |
void compute_jis(int f, unsigned int c, unsigned int *ku, unsigned int *ten) |
| 2437 |
{ |
| 2438 |
int n; |
| 2439 |
|
| 2440 |
if (f <= 7) { |
| 2441 |
if (f == 1) { |
| 2442 |
if (c >= 100) { |
| 2443 |
*ku = kushift(2); |
| 2444 |
*ten = tenshift(c-100); |
| 2445 |
} |
| 2446 |
else { |
| 2447 |
*ku = kushift(1); |
| 2448 |
*ten = tenshift(c); |
| 2449 |
} |
| 2450 |
} |
| 2451 |
else if (f == 2) { |
| 2452 |
*ku = kushift(3); |
| 2453 |
*ten = tenshift(c-32); |
| 2454 |
} |
| 2455 |
else { |
| 2456 |
*ku = kushift(f+1); |
| 2457 |
*ten = tenshift(c); |
| 2458 |
} |
| 2459 |
} |
| 2460 |
else if (f <= 19) { /* Daiichi Suijun */ |
| 2461 |
n = (f-8)*256+c; |
| 2462 |
*ku = kushift((n/94)+16); |
| 2463 |
*ten = tenshift((n%94)+1); |
| 2464 |
} |
| 2465 |
else { /* Daini Suijun */ |
| 2466 |
n = (f-20)*256+c; |
| 2467 |
*ku = kushift((n/94)+48); |
| 2468 |
*ten = tenshift((n%94)+1); |
| 2469 |
} |
| 2470 |
|
| 2471 |
return; |
| 2472 |
|
| 2473 |
} /* compute_jis */ |
| 2474 |
|