home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume12 / hershtools / part03 < prev    next >
Encoding:
Internet Message Format  |  1987-10-24  |  22.5 KB

  1. Subject:  v12i042:  Hershey font manipulation tools and data, Part03/05
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rs@uunet.UU.NET
  5.  
  6. Submitted-by: lee@uhccux.UUCP (Greg Lee)
  7. Posting-number: Volume 12, Issue 42
  8. Archive-name: hershtools/part03
  9.  
  10. # This is a shell archive.  Remove anything before this line
  11. # then unpack it by saving it in a file and typing "sh file"
  12. # (Files unpacked will be owned by you and have default permissions).
  13. # This archive contains the following files:
  14. #    ./hplot.c
  15. #
  16. if `test ! -s ./hplot.c`
  17. then
  18. echo "writing ./hplot.c"
  19. sed 's/^X//' > ./hplot.c << '\Rogue\Monster\'
  20. X
  21. X
  22. X#include <stdio.h>
  23. X#include <sys/file.h>
  24. X
  25. X#define TRUE 1
  26. X#define FALSE 0
  27. X#define ERROR -1
  28. X
  29. Xint tty_fid;
  30. Xextern char *term_name;
  31. Xchar w300 = FALSE;
  32. X
  33. X#define movmem bcopy
  34. X
  35. X#define STSIZE    32000
  36. X#define KEEPSIZE 20
  37. X#define GRSIZE 160
  38. X#define GROFF 80
  39. X
  40. Xchar debug, ins[90];
  41. XFILE *ibuf;
  42. Xint cnum;
  43. X
  44. Xint itempt, co1, co2, w, x, y;
  45. Xint deltax, deltay, xinc, yinc;
  46. Xint lx,llx,ly,lly, cx,ccx,cy,ccy, x1,x2,y1,y2, a1,a2,d1,d2, i1,i2;
  47. Xint xx1,xx2,yy1,yy2;
  48. Xint minx, miny, maxx, maxy, base, obase, xheight, ytop, ybot, serifs;
  49. Xchar itemtype, linelet, retrace, openflag, lighten, hairflag, cvflag;
  50. Xint lbear, rbear;
  51. Xunsigned char letter;
  52. Xint xheavy, xlight, yheavy, ylight, penwidth, pxdelta, pydelta,
  53. X    squarepen, shading, xshade, yshade;
  54. Xint ppenw, blob, bblob, dblob;
  55. Xint fgrey,fvertical,fhorizontal,fchecked,fhatched,fdiagonal,fwidth;
  56. Xint bwidth,bedge,breverse;
  57. X
  58. X
  59. X#define WYSE    1
  60. X#define ESC    27
  61. X
  62. X#define    FTSIZE     12000
  63. X#define PRPTNL  2
  64. X
  65. X#define BLACK    '1'
  66. X#define BLUE    '2'
  67. X#define GREEN    '3'
  68. X#define CYAN    '4'
  69. X#define RED    '5'
  70. X#define MAGENTA '6'
  71. X#define YELLOW    '7'
  72. X#define WHITE    '8'
  73. X
  74. X#define UPPRDOT    ','
  75. X#define LOWRDOT    '-'
  76. X#define BOTHDOT '7'
  77. X#define NODOT    ' '
  78. X
  79. Xchar upperdot=UPPRDOT, lowerdot=LOWRDOT, bothdot=BOTHDOT;
  80. X
  81. Xchar    cmd, currch, cch, cbyte, cbyteo, mxflag;
  82. Xint    col, row, currlen;
  83. X
  84. Xchar    vkeep[GRSIZE][KEEPSIZE], gxoff, gyoff, ib;
  85. Xchar ckeep[6][GRSIZE];
  86. X
  87. Xint i, fd;
  88. Xchar ftname[30];
  89. X
  90. X
  91. Xchar  duplflag /*, ftlen[128]*/;
  92. Xshort int fix[128];
  93. Xchar  ft[FTSIZE];
  94. X
  95. X
  96. X
  97. X
  98. Xchar gr[GRSIZE][GRSIZE];
  99. X
  100. Xunsigned stsize, cindex[128], storept;
  101. Xchar store[STSIZE];
  102. X
  103. X
  104. X#include "vfont.c"
  105. X
  106. Xmain()
  107. X{    char key();
  108. X
  109. X/* stuff from xum */
  110. X
  111. X    if (term_setup() != 0)
  112. X    {
  113. X        printf("Warning: This program needs to have the\n");
  114. X        printf("TERM environment variable setup before\n");
  115. X        printf("being run. Make sure this is done before\n");
  116. X        printf("executing hplot again (set yourself up like\n");
  117. X        printf("you were going to use vi).\n");
  118. X        exit(1);
  119. X    }
  120. X    printf("Terminal is a %s.\n", term_name);
  121. X    if (!strcmp(term_name, "w300")) w300 = TRUE;
  122. X    if (!w300)
  123. X    {    upperdot='^'; lowerdot='j'; bothdot='g';
  124. X    }
  125. X
  126. X    tty_fid = cbreak_tty("/dev/tty");
  127. X    if (tty_fid == -1)
  128. X    {
  129. X        printf("Error opening terminal for cbreak i/o\n");
  130. X        exit(1);
  131. X    }
  132. X
  133. X    debug = 0;
  134. X
  135. X    stsize = STSIZE;
  136. X
  137. X    printf("\nHplot - (c) Greg Lee, Oct. 1984\n\n");
  138. X
  139. X    base = 9;
  140. X    ytop = 22;
  141. X    ybot = 7;
  142. X    cvflag = FALSE;
  143. X    lbear = rbear = 2;
  144. X    strcpy(ftname,"vwork");
  145. X    letter = currch = duplflag = 0;
  146. X
  147. X    storept = x1 = x2 = y1 = y2 = a2 = d2 = 1;
  148. X    serifs = 2;
  149. X
  150. X    do
  151. X    {    printf("\n");
  152. X        if (currch > ' ') printf("%c",currch);
  153. X            else printf("^%c",currch+64);
  154. X        printf("* ");
  155. X        cmd = key();
  156. X    switch (cmd)
  157. X    {
  158. X    case 'r': rdchr(); break;
  159. X    case 'z': bzero(cindex, 128*sizeof(int));
  160. X          bzero(store, STSIZE);
  161. X          storept = 1;
  162. X          printf("zapped");
  163. X          break;
  164. X    case 'p': plotlet(); break;
  165. X    case 'g': printf("enerating the font\n");
  166. X          /*for (letter=1;letter<127;letter++)
  167. X            lplot(letter);*/
  168. X          vfont();
  169. X          cvflag = FALSE;
  170. X          break;
  171. X#if WYSE
  172. X    case 'v': if (currch) showbits(); break;
  173. X#endif
  174. X    case 'b': gvar("ase",&base); break;
  175. X    case 'h': gvar("eight",&ytop); break;
  176. X    case 'd': gvar("epth",&ybot); break;
  177. X    case 'f': printf("actors:\n");
  178. X          gvar("X1",&x1);
  179. X          gvar("X2",&x2);
  180. X          gvar("Y1",&y1);
  181. X          gvar("Y2",&y2);
  182. X          break;
  183. X    case '2': printf(" FACTORS (plot 2):\n");
  184. X          gvar("XX1",&xx1);
  185. X          gvar("XX2",&xx2);
  186. X          gvar("YY1",&yy1);
  187. X          gvar("YY2",&yy2);
  188. X          break;
  189. X    case 'A': printf("SCENDERS:\n");
  190. X          gvar("A1",&a1);
  191. X          gvar("A2",&a2);
  192. X          break;
  193. X    case 'D': printf("ESCENDERS:\n");
  194. X          gvar("D1",&d1);
  195. X          gvar("D2",&d2);
  196. X          break;
  197. X    case 'I': printf("^ITALIC:\n");
  198. X          gvar("I1",&i1);
  199. X          gvar("I2",&i2);
  200. X          break;
  201. X    case 't': if (duplflag) fix[0] &= ~PRPTNL;
  202. X          else fix[0] |= PRPTNL;
  203. X          chkdupl();
  204. X          if (!duplflag) printf("not "); printf("tall");
  205. X          break;
  206. X    case 'P': printf("EN STYLE:\n");
  207. X          gvar("Width",&penwidth);
  208. X          gvar("Delta X",&pxdelta);
  209. X          gvar("Delta Y",&pydelta);
  210. X          gvar("Square Pen",&squarepen);
  211. X          gvar("Blob",&blob);
  212. X          gvar("Delta Blob",&dblob);
  213. X          break;
  214. X    case 'H': printf(" SHADE:\n");
  215. X          gvar("Shading",&shading);
  216. X          gvar("X Shade",&xshade);
  217. X          gvar("Y Shade",&yshade);
  218. X          break;
  219. X    case 'F': printf("ILL:\n");
  220. X          gvar("Grey",&fgrey);
  221. X          gvar("Vertical",&fvertical);
  222. X          gvar("Horizontal",&fhorizontal);
  223. X          gvar("Checked",&fchecked);
  224. X          gvar("Hatched",&fhatched);
  225. X          gvar("Diagonal",&fdiagonal);
  226. X          gvar("Width",&fwidth);
  227. X          break;
  228. X    case 'w': printf("idth adjust:\n");
  229. X          gvar("Left Bearing",&lbear);
  230. X          gvar("Right Bearing",&rbear);
  231. X          break;
  232. X    case 'B': printf("OX:\n");
  233. X          gvar("Width",&bwidth);
  234. X          gvar("Edge",&bedge);
  235. X          gvar("Reverse",&breverse);
  236. X          break;
  237. X    case 'L': printf("INE STYLE:\n");
  238. X          gvar("X Heavy",&xheavy);
  239. X          gvar("X Light",&xlight);
  240. X          gvar("Y Heavy",&yheavy);
  241. X          gvar("Y Light",&ylight);
  242. X          break;
  243. X    case 'O': if (openflag) printf("not ");
  244. X          openflag = ~openflag;
  245. X          printf("open");
  246. X          break;
  247. X    case 'l': if (lighten) printf("not ");
  248. X          lighten = ~lighten;
  249. X          printf("light");
  250. X          break;
  251. X    case 's': gvar("erifs",&serifs);
  252. X          break;
  253. X    case 'R': if (retrace) printf(" not r");
  254. X          retrace = !retrace;
  255. X          printf("etrace");
  256. X          break;
  257. X    case 'n': printf("ame of font(%s) = ",ftname);
  258. X          scanf("%s",ftname);
  259. X          break;
  260. X    case '?': cmdinfo();
  261. X          printf("\nstore room %d, font room %d",
  262. X            stsize-storept,FTSIZE-fix[127]);
  263. X          break;
  264. X    case '\\': printf("debug");
  265. X          if (debug) printf(" off");
  266. X          debug = !debug;
  267. X    case 'q':
  268. X    case 'x': break;
  269. X    case 'c': loadft();
  270. X          cvflag = TRUE;
  271. X          break;
  272. X    default: conout('?'); break;
  273. X    }
  274. X    }
  275. X    while ((cmd != 'x') && (cmd != 'q'));
  276. X
  277. X    reset_tty(tty_fid);
  278. X
  279. X}
  280. X
  281. Xcmdinfo()
  282. X{
  283. X      printf("\nRead   Plot      Name font  mag.Factors ^Pen style\n");
  284. X    printf("Zap    Generate            ^Ascenders   ^Line style\n");
  285. X    printf("Base   Vdisplay  Serifs    ^Descenders  ^Open face\n");
  286. X    printf("Height eXit/Quit^Italic     s^Hading     Convert\n");
  287. X    printf("Depth ^Fill     ^Box       ^Retrace      Width adjust\n");
  288. X}
  289. X
  290. X
  291. Xgvar(s,v)
  292. Xchar *s; int *v;
  293. X{    char is[80];
  294. X
  295. X    printf(s);
  296. X    printf("(%d) = ", *v);
  297. X    gets(is);
  298. X    if (is[0] < '0' || is[0] > '9') return;
  299. X    sscanf(is, "%d", v);
  300. X}
  301. X
  302. Xplotlet()
  303. X{
  304. X    printf("lot a letter? : ");
  305. X    scanf("%c", &letter);
  306. X    lplot(letter);
  307. X}
  308. X
  309. X
  310. Xrdchr()
  311. X{    char fname[20];
  312. X
  313. X
  314. X    printf("ead what .chr file?  : "); scanf("%s", fname);
  315. X    if (!fname[0]) return;
  316. X    strcat(fname, ".chr");
  317. X    if ((ibuf = fopen(fname, "r")) == NULL) return;
  318. X
  319. X    while (fgets(ins, 90, ibuf))
  320. X    {    itempt = 0;
  321. X        while (itemtype = scnitem())
  322. X        switch(itemtype)
  323. X        {
  324. X        case 1: letter = 0;
  325. X            break;
  326. X        case 2: cindex[letter] = storept;
  327. X            lbear = rbear = 2;
  328. X            break;
  329. X        case 3: sto2(co1 + 64, co2 + 64);
  330. X            break;
  331. X        case 4: sto2(0, 64);
  332. X            break;
  333. X        case 5: sto2(0, 0);
  334. X            break;
  335. X        case 6: sto2(0, 'H');
  336. X            break;
  337. X        }
  338. X    }
  339. X
  340. X
  341. X    fclose(ibuf);
  342. X
  343. X    printf("\nUsed %u of buffer (%d remaining).", storept,stsize-storept);
  344. X}
  345. X
  346. Xsto2(x,y)
  347. Xchar x, y;
  348. X{
  349. X    if (letter < 1 || letter > 127) return;
  350. X    if (storept > stsize - 2) return;
  351. X
  352. X    store[storept++] = x;
  353. X    store[storept++] = y;
  354. X
  355. X}
  356. X
  357. Xscnitem()
  358. X{    char dc;
  359. X
  360. X    while (ins[itempt] == ' ' || ins[itempt] == '\t') itempt++;
  361. X
  362. X    if (!ins[itempt] || ins[itempt] == '\n') return(0);
  363. X
  364. X    if (sscanf(ins + itempt, "%d:", &cnum))
  365. X    {    match(':');    return(1); }
  366. X
  367. X    if (sscanf(ins + itempt, "'%c':", &letter))
  368. X    {    match(':');    return(2); }
  369. X
  370. X    if (sscanf(ins + itempt, "^%c':", &letter))
  371. X    {    match(':');    letter &=  0x1F; return(2); }
  372. X
  373. X    if (sscanf(ins + itempt, "Bounds(%d,%d)", &co1, &co2))
  374. X    {    match(')');    return(66); }
  375. X
  376. X    if (sscanf(ins + itempt, "Bearings(%d,%d)", &lbear, &rbear))
  377. X    {    match(')');    return(66); }
  378. X
  379. X    if (sscanf(ins + itempt, "s(%d,%d)", &co1, &co2))
  380. X    {    match(')');    if (serifs) return(3); return(66); }
  381. X
  382. X    if (sscanf(ins + itempt, "S(%d,%d)", &co1, &co2))
  383. X    {    match(')');    if (serifs>1) return(3); return(66); }
  384. X
  385. X    if (sscanf(ins + itempt, "(%d,%d)", &co1, &co2))
  386. X    {    match(')');    return(3); }
  387. X
  388. X    if (sscanf(ins + itempt, "Pen Up%c", &dc))
  389. X    {    match('p');    return(4); }
  390. X
  391. X    if (sscanf(ins + itempt, "End Char%c", &dc))
  392. X    {    match('r');    return(5); }
  393. X
  394. X    if (sscanf(ins + itempt, "Hair%c", &dc))
  395. X    {    match('r');    return(6); }
  396. X
  397. X    if (sscanf(ins + itempt, "Base(%d)", &base))
  398. X    {    match(')');    obase = base; return(66); }
  399. X
  400. X    if (sscanf(ins + itempt, "x Height(%d)", &xheight))
  401. X    {    match(')');    return(66); }
  402. X
  403. X    if (sscanf(ins + itempt, "Height(%d)", &ytop))
  404. X    {    match(')');    return(66); }
  405. X
  406. X    if (sscanf(ins + itempt, "Depth(%d)", &ybot))
  407. X    {    match(')');    return(66); }
  408. X
  409. X    return(0);
  410. X
  411. X}
  412. X
  413. Xmatch(c)
  414. Xchar c;
  415. X{    while (ins[itempt++] != c);
  416. X}
  417. X
  418. Xlplot(let)
  419. Xchar let;
  420. X{    int ox1,ox2,oy1,oy2;
  421. X    int oopen;
  422. X
  423. X    if (xx1 || xx2 || yy1 || yy2)
  424. X    {    ox1 = x1; oy1 = y1;
  425. X        ox2 = x2; oy2 = y2;
  426. X        oopen = openflag;
  427. X
  428. X        if (xx1 || xx2)
  429. X        {    x1 = xx1 ; x2 = xx2; }
  430. X        if (yy1 || yy2)
  431. X        {    y1 = yy1 ; y2 = yy2; }
  432. X
  433. X        openflag = FALSE;
  434. X        retrace = 2;
  435. X        llplot(let);
  436. X        openflag = oopen;
  437. X
  438. X        x1 = ox1; y1 = oy1;
  439. X        x2 = ox2; y2 = oy2;
  440. X        retrace = TRUE;
  441. X    }
  442. X
  443. X    llplot(let);
  444. X}
  445. X
  446. X
  447. Xllplot(let)
  448. Xchar let;
  449. X{    char c1, c2, penstate;
  450. X    unsigned xpt;
  451. X
  452. X    currch = let;
  453. X    chkdupl();
  454. X
  455. X    if (let < 0 || let > 128) return;
  456. X
  457. X    if (!(xpt = cindex[let])) return;
  458. X    /*if (kbhit()) return;*/
  459. X
  460. X    if (retrace != TRUE) cleargr();
  461. X
  462. X    bblob = blob;
  463. X
  464. X    for (penstate = 0 ; (c1 = store[xpt++])
  465. X              + (c2 = store[xpt++]) ; )
  466. X    if (!c1)
  467. X    {    penstate = 0;
  468. X        if (c2 == 'H') hairflag = TRUE;
  469. X
  470. X        bblob = blob;
  471. X    }
  472. X
  473. X    else
  474. X    {    lx = cx; ly = cy;
  475. X        cx = c1 - 64; cy = c2 - 64;
  476. X
  477. X        if (penstate) drawline();
  478. X
  479. X        penstate = 1;
  480. X
  481. X    }
  482. X
  483. X
  484. X    showgr();
  485. X
  486. X    retrace = 0;
  487. X}
  488. X
  489. X
  490. Xcleargr()
  491. X{
  492. X    bzero(gr, GRSIZE * GRSIZE);
  493. X    linelet = '0';
  494. X/*    penwidth = abs(penwidth);*/
  495. X}
  496. X
  497. X
  498. Xdrawline()
  499. X{
  500. X    if (debug) printf("\nDrawing from (%d,%d) to (%d,%d).", lx,ly,cx,cy);
  501. X
  502. X    linelet++;
  503. X    if (linelet > '9' && linelet < 'A') linelet = 'A';
  504. X    else if (linelet > 'Z' && linelet < 'a') linelet = 'a';
  505. X    else if (linelet > 'z') linelet = '!'+1;
  506. X
  507. X    if (abs(cy) <= abs(ly))
  508. X    {    llx = lx;
  509. X        lly = ly;
  510. X        ccx = cx;
  511. X        ccy = cy;
  512. X    }
  513. X    else
  514. X    {    llx = cx;
  515. X        lly = cy;
  516. X        ccx = lx;
  517. X        ccy = ly;
  518. X    }
  519. X
  520. X
  521. X    if (i1 && i2) llx += fadjust(lly,i1,i2)-GROFF;
  522. X    x = fadjust(llx,x1,x2);
  523. X
  524. X    if (i1 && i2) ccx += fadjust(ccy,i1,i2)-GROFF;
  525. X    ccx = fadjust(ccx,x1,x2);
  526. X
  527. X    deltax = abs(ccx - x);
  528. X    if (ccx >= x) xinc = 1; else xinc = -1;
  529. X
  530. X    if (xheight && letter >= 'a' && letter <= 'z')
  531. X    {    if (lly > obase) lly += ((lly-obase)*d1)/d2;
  532. X        else if (lly + xheight <= obase)
  533. X            lly -= ((obase+1-xheight-lly)*a1)/a2;
  534. X        if (ccy > obase) ccy += ((ccy-obase)*d1)/d2;
  535. X        else if (ccy + xheight <= obase)
  536. X            ccy -= ((obase+1-xheight-ccy)*a1)/a2;
  537. X    }
  538. X
  539. X    y = fadjust(lly,y1,y2);
  540. X    ccy = fadjust(ccy,y1,y2);
  541. X    deltay = abs(ccy - y);
  542. X    if (ccy >= y) yinc = 1; else yinc = -1;
  543. X
  544. X    drawdot();
  545. X
  546. X    if (deltax >= deltay) doforx();
  547. X    else dofory();
  548. X
  549. X    hairflag = FALSE;
  550. X}
  551. X
  552. Xfadjust(u,f1,f2)
  553. Xint u,f1,f2;
  554. X{
  555. X    return( (u * f1 + f2-1)/f2 + GROFF);
  556. X}
  557. X
  558. Xdrawdot()
  559. X{
  560. X    dotset();
  561. X
  562. X    if (bblob > 0) bblob -= dblob;
  563. X    else if (bblob < 0) bblob += dblob;
  564. X
  565. X    ppenw = abs(penwidth + bblob/8);
  566. X    if (ppenw) doforpen();
  567. X}
  568. X
  569. X
  570. X
  571. Xdoforpen()
  572. X{    int sx,sy;
  573. X
  574. X    if (hairflag) return;
  575. X
  576. X    sx = x; sy = y;
  577. X
  578. X    x -= ppenw * pxdelta / 2;
  579. X    y -= ppenw * pydelta / 2;
  580. X
  581. X    w = ppenw;
  582. X    while(w--)
  583. X    {    x += pxdelta;
  584. X        dotset();
  585. X        y += pydelta;
  586. X        dotset();
  587. X    }
  588. X
  589. X
  590. X    w = ppenw;
  591. X    if (squarepen)
  592. X    while(w--)
  593. X    {    x -= pydelta;
  594. X        y -= pxdelta;
  595. X        dotset();
  596. X    }
  597. X
  598. X    w = ppenw;
  599. X    if (squarepen > 1)
  600. X    while(w--)
  601. X    {    x -= pxdelta;
  602. X        y -= pydelta;
  603. X        dotset();
  604. X    }
  605. X
  606. X    w = ppenw;
  607. X    if (squarepen > 2)
  608. X    while(w--)
  609. X    {    x += pydelta;
  610. X        y += pxdelta;
  611. X        dotset();
  612. X    }
  613. X
  614. X    x = sx; y = sy;
  615. X}
  616. X
  617. X
  618. Xdotset()
  619. X{
  620. X
  621. X    if (x<0 || x>=GRSIZE || y<0 || y>=GRSIZE) return;
  622. X    if (gr[x][y]) return;
  623. X    gr[x][y] = linelet;
  624. X
  625. X}
  626. X
  627. X
  628. X
  629. Xdoforx()
  630. X{    int err, i;
  631. X
  632. X    err = deltax / 2;
  633. X    i = deltax;
  634. X
  635. X    while (i--)
  636. X    {    err += deltay;
  637. X        if (err >= deltax)
  638. X        {    err -= deltax;
  639. X            y += yinc;
  640. X            if (xheavy) drawdot();
  641. X            if (xlight) {x += xinc; continue;}
  642. X        }
  643. X        x += xinc;
  644. X        if (hairflag && (i&1)) continue;
  645. X        drawdot();
  646. X        if (debug) printf("\n   @(%d,%d) [%d,%d]",
  647. X            x-GROFF, y-GROFF, x,y);
  648. X    }
  649. X    
  650. X}
  651. X
  652. Xdofory()
  653. X{    int err, i;
  654. X
  655. X    gr[x][y] = linelet;
  656. X
  657. X    err = deltay / 2;
  658. X    i = deltay;
  659. X
  660. X    while (i--)
  661. X    {    err += deltax;
  662. X        if (err >= deltay)
  663. X        {    err -= deltay;
  664. X            x += xinc;
  665. X            if (yheavy) drawdot();
  666. X            if (ylight) { y+= yinc; continue; }
  667. X        }
  668. X        y += yinc;
  669. X        if (hairflag && (i&1)) continue;
  670. X        drawdot();
  671. X        if (debug) printf("\n   @(%d,%d) [%d,%d]",
  672. X            x-GROFF, y-GROFF, x,y);
  673. X    }
  674. X    
  675. X}
  676. X
  677. Xshowgr()
  678. X{    /* int x, y;*/
  679. X
  680. X    minx = miny = GRSIZE-1;
  681. X    maxx = maxy = 0;
  682. X
  683. X    for (y = 0; y < GRSIZE; y++)
  684. X    {    for (x = 0; x < GRSIZE; x++)
  685. X        if (gr[x][y])
  686. X        {    if (x < minx) minx = x;
  687. X            if (y < miny) miny = y;
  688. X            if (x > maxx) maxx = x;
  689. X            if (y > maxy) maxy = y;
  690. X        }
  691. X    }
  692. X
  693. X    if (bwidth)
  694. X    {    i = max(bedge+2, 1 + (bwidth + minx - maxx) / 2);
  695. X        minx = max(0, minx - i);
  696. X        maxx = min(GRSIZE-1, maxx + i);
  697. X        while (maxx - minx > GRSIZE) {minx++; maxx--; }
  698. X        miny = base + GROFF + 1 - ytop;
  699. X        maxy = miny + ybot;
  700. X    }
  701. X
  702. X    printf("\n");
  703. X
  704. X    if (openflag || lighten)
  705. X    { for (y = miny; y <= maxy; y++)
  706. X       for (x = minx; x <= maxx; x++)
  707. X        if (gr[x][y])
  708. X        {
  709. X         if (!gr[x+1][y] && !gr[x+2][y] && !gr[x+3][y]) continue;
  710. X         if (!gr[x][y+1] && !gr[x][y+2] && !gr[x][y+3]) continue;
  711. X         if (!gr[x-1][y] && !gr[x-2][y] && !gr[x-3][y]) continue;
  712. X         if (!gr[x][y-1] && !gr[x][y-2] && !gr[x][y-3]) continue;
  713. X            gr[x][y] = 1;
  714. X        }
  715. X
  716. X    if (breverse)
  717. X      for (y = miny; y <= maxy; y++)
  718. X       for (x = minx; x <= maxx; x++)
  719. X        { if (!gr[x][y]) gr[x][y] = 1;
  720. X          else if (gr[x][y] == 1) gr[x][y] = 0;
  721. X        }
  722. X
  723. X      for (y = miny; y <= maxy; y++)
  724. X       for (x = minx; x <= maxx; x++)
  725. X        if (gr[x][y])
  726. X        {    gr[x][y]--;
  727. X            if (lighten)
  728. X             if (gr[x][y])
  729. X             {    if (gr[x-1][y])
  730. X                {    if (gr[x-1][y-1])
  731. X                      gr[x-1][y] = 0;
  732. X                    else gr[x][y] = 0;
  733. X                }
  734. X             }
  735. X             else if (!gr[x-1][y] && gr[x+1][y] < 2)
  736. X                gr[x][y] = '*';
  737. X
  738. X            if (fgrey<0) gr[x][y] = 0;
  739. X            if (gr[x][y]) continue;
  740. X
  741. X            if (fgrey)
  742. X            {    if (x % fgrey) continue;
  743. X                if (y % fgrey) continue;
  744. X                if (!fwidth) gr[x][y] = '+';
  745. X            }
  746. X
  747. X            if (fwidth)
  748. X            { if (t(x,fvertical))        continue;
  749. X              if (t(y,fhorizontal))    continue;
  750. X              if (fchecked &&
  751. X               (!t(x,fchecked) == !t(y,fchecked))) continue;
  752. X              if (t(x,fhatched) && t(y,fhatched)) continue;
  753. X              if (fdiagonal < 0)
  754. X              {    if (t(abs(x-y),-fdiagonal)) continue;  }
  755. X              else if (t(x+y, fdiagonal))    continue;
  756. X
  757. X                gr[x][y] = '#';
  758. X            }
  759. X        }
  760. X    }
  761. X
  762. X
  763. X    if (shading && retrace != 2)
  764. X    {    shading = abs(shading);
  765. X        xshade = abs(xshade);
  766. X
  767. X        lx = minx + shading + yshade;
  768. X        ly = min(maxy + shading + yshade,GRSIZE-1);
  769. X
  770. X        llx = maxx;
  771. X        
  772. X        while (lx <= llx)
  773. X        {    raybounce();
  774. X            lx += 2 + xshade;
  775. X        }
  776. X
  777. X        while (ly >= miny)
  778. X        {    raybounce();
  779. X            ly -= 2 + xshade;
  780. X        }
  781. X    }
  782. X
  783. X
  784. X    if (bedge && retrace != 2)
  785. X      for (y = miny; y <= maxy; y++)
  786. X       for (x = minx; x <= maxx; x++)
  787. X          if (       y < miny+bedge
  788. X            || y > maxy-bedge
  789. X            || x < minx+bedge
  790. X            || x > maxx-bedge
  791. X             )
  792. X          gr[x][y] = '|';
  793. X
  794. X    if (maxx - minx > GRSIZE-1) maxx = minx + GRSIZE-1;
  795. X
  796. X    for (y = miny; y <= maxy; y++)
  797. X    {    for (x = minx; x <= maxx; x++)
  798. X        {    if (x-minx > 78) break;
  799. X            if (gr[x][y]) printf("%c",gr[x][y]);
  800. X              else if (y == base+GROFF) putchar('-');
  801. X              else putchar(' ');
  802. X        }
  803. X        /*if (y-miny == 23) key();*/
  804. X        printf("\n");
  805. X    }
  806. X
  807. X    printf("\nHeight %d; Depth %d; Width %d\n",
  808. X         base+GROFF+1-miny, maxy-GROFF-base, maxx-minx+1);
  809. X
  810. X    rdedf();
  811. X}
  812. X
  813. X
  814. Xt(a,period)
  815. Xint a, period;
  816. X{    if (!period) return(FALSE);
  817. X    a %= period;
  818. X    if (fwidth == 1) return(a);
  819. X    if (fwidth < 0) a = (a >= abs(period) / -fwidth);
  820. X    else        a = (a <  abs(period) /  fwidth);
  821. X
  822. X    if (period < 0) a = !a;
  823. X
  824. X    return(a);
  825. X}
  826. X
  827. X
  828. X
  829. Xradar()
  830. X{    x = lx; y = ly;
  831. X
  832. X    while (    !gr[x][y]
  833. X       &&    !gr[x-1][y]
  834. X       &&    !gr[x][y-1]
  835. X       &&    !gr[x-1][y-1] )
  836. X    {    x--; y--;
  837. X        if (x < minx || y < miny) return(FALSE);
  838. X    }
  839. X    return(TRUE);
  840. X}
  841. X
  842. Xraybounce()
  843. X{
  844. X    if (!radar()) return;
  845. X
  846. X    i = shading;
  847. X    cx = x + yshade; cy = y + yshade;
  848. X
  849. X    while(i-- && cx<98 && cy<98 )
  850. X    {    cx++;  cy++;
  851. X        if (gr[cx][cy]) i = 0;
  852. X        else gr[cx][cy] = '.';
  853. X    }
  854. X    maxx = max(cx,maxx);
  855. X    maxy = max(cy,maxy);
  856. X}
  857. X
  858. X
  859. Xchar conin()
  860. X{    return (0x7f & getchar());
  861. X}
  862. X
  863. Xconout(c)
  864. Xchar c;
  865. X{    putchar(c);
  866. X}
  867. X
  868. X
  869. Xtokeep()
  870. X{
  871. X    tokepp(0, currch);
  872. X    if (duplflag) tokepp(3, dtrans(currch, FALSE));
  873. X}
  874. X
  875. Xtokepp(ib, currch)
  876. Xunsigned char ib, currch;
  877. X{    int i, j, cbase;
  878. X
  879. X    cbase = fix[currch];
  880. X    currlen = (fix[currch+1] - cbase) / 3;
  881. X
  882. X    if (currlen > GRSIZE) currlen = GRSIZE;
  883. X    for (i = 0; i < 3; i++)
  884. X     for (j = 0; j < GRSIZE; j++)
  885. X      if (j >= currlen) ckeep[ib+i][j] = 0;
  886. X           else  ckeep[ib+i][j] =  ft[cbase + j + i*currlen];
  887. X}
  888. X
  889. X
  890. X#if WYSE
  891. Xfromkeep()
  892. X{
  893. X    frommkeep(0,currch);
  894. X    if (duplflag) frommkeep(3, dtrans(currch, FALSE));
  895. X}
  896. X
  897. Xfrommkeep(ib, currch)
  898. Xchar ib, currch;
  899. X#else
  900. Xfromkeep()
  901. X#endif
  902. X{    int i, j, cend, cbase, cnext, mlen;
  903. X
  904. X    cbase = fix[currch];
  905. X    cnext = fix[currch+1];
  906. X
  907. X    cend = cbase + currlen * 3;
  908. X    mlen = (cend-cnext) ? FTSIZE - 1 - max(cnext,cend)
  909. X                  : 0;
  910. X    if (fix[127] + cend - cnext >= FTSIZE)
  911. X    {    printf("\nfont overflow\n"); return; }
  912. X
  913. X    if (mlen)
  914. X    {    movmem(ft+cnext, ft+cend, mlen); 
  915. X         for (i = currch+1; i < 128; i++)
  916. X            fix[i] = fix[i] + cend - cnext;
  917. X        /*for (i = 0; i < 127; i++)
  918. X            ftlen[i] = (fix[i+1] - fix[i])/3;*/
  919. X        /*if (fix[127] >= FTSIZE) ovlflag = TRUE;*/
  920. X    }
  921. X
  922. X    if (currlen)
  923. X    for (i = 0; i < 3; i++)
  924. X     for (j = 0; j < currlen; j++)
  925. X       ft[cbase + j + i*currlen] = vkeep[ib+i][j];
  926. X}
  927. X
  928. X
  929. Xchar key()
  930. X{    char c;
  931. X
  932. X    c = conin();
  933. X    if (c < ' ') c += '@';
  934. X        else if (c >='A' && c <= 'Z')
  935. X        c += ' ';
  936. X    if (c == 'J') return(key());
  937. X    return(c);
  938. X}
  939. X
  940. X
  941. Xdtrans(c, upper)
  942. Xchar c, upper;
  943. X{    if (c == 0x20 || c == 0x5F) return(c);
  944. X
  945. X    if (c >= 0x60) c -= 0x20;
  946. X    else if (c < 0x20) c += 0x20;
  947. X
  948. X    if (upper) return(c);
  949. X
  950. X    if (c < 0x40) c -= 0x20;
  951. X    else c += 0x20;
  952. X
  953. X    return(c);
  954. X}
  955. X
  956. Xchkdupl()
  957. X{
  958. X    duplflag = fix[0] & PRPTNL;
  959. X#if WYSE
  960. X    if (duplflag) currch = dtrans(currch, TRUE);
  961. X#endif
  962. X}
  963. X
  964. Xrdedf()
  965. X{    char c;
  966. X    int i, y, lasty, dcurrlen;
  967. X
  968. X
  969. X    if  (duplflag)    currch = dtrans(currch, TRUE);
  970. X
  971. X
  972. X    lbear = rbear = 0;
  973. X
  974. X
  975. X    bzero(vkeep, KEEPSIZE*GRSIZE);
  976. X    row = currlen = 0; dcurrlen = 10000;
  977. X
  978. X    y = base + GROFF + 1 - ytop;
  979. X    lasty = y + ytop + ybot;
  980. X    if (lasty >= GRSIZE) lasty = GRSIZE-1;
  981. X
  982. X    for ( ; y <= lasty; row++,y++)
  983. X    {
  984. X        for (i = minx, col = lbear; i <= maxx; col++,i++)
  985. X         if (gr[i][y]) chngbit(TRUE);
  986. X
  987. X        if (currlen < col + rbear)
  988. X            currlen = col + rbear;
  989. X    }
  990. X
  991. X/*    fromkeep();*/
  992. X}
  993. X
  994. X
  995. Xchngbit(biton)
  996. Xchar biton;
  997. X{    unsigned char bit, mask;
  998. X    
  999. X    bit = col % 8;
  1000. X    mask = 128 >> bit; 
  1001. X    cbyte = vkeep[row][col/8];
  1002. X    if (biton) cbyte |= mask;
  1003. X        else cbyte &= ~mask;
  1004. X    vkeep[row][col/8] = cbyte;
  1005. X}
  1006. X
  1007. X
  1008. X
  1009. X
  1010. X
  1011. X
  1012. Xgxy(x,y)
  1013. Xchar x,y;
  1014. X{    if (w300)
  1015. X    {    conout(ESC); conout('=');
  1016. X        conout(y+' '); conout(x+' ');
  1017. X    } else mov_cur(x,y);
  1018. X}
  1019. X
  1020. Xshowbits()
  1021. X{
  1022. X/*    conout(0x1A);
  1023. X    sleep(1);
  1024. X*/    cls();
  1025. X    graph(TRUE);
  1026. X/*    tokeep();*/
  1027. X
  1028. X    gxoff = (78 - currlen)/2;
  1029. X    gyoff = (46 - ytop - ybot)/4;
  1030. X    sshowbits();
  1031. X    graph(FALSE);
  1032. X    gxy(0,22);
  1033. X}
  1034. X
  1035. Xsshowbits()
  1036. X{    unsigned char i, j, bit, mask, r;
  1037. X
  1038. X    r = gyoff + (ytop + ybot + 1)/2;
  1039. X
  1040. X     if (currlen > 0)
  1041. X     {
  1042. X    color(RED,WHITE);
  1043. X    gxy(gxoff-1,gyoff-1);
  1044. X    conout(w300 ? '2':'+');
  1045. X    for (i = 0; i < currlen; i++) conout(w300 ? ':':'-');
  1046. X    conout(w300 ? '3':'+');
  1047. X
  1048. X    for (i = gyoff; i < r; i++)
  1049. X      {
  1050. X        gxy(gxoff-1,i); conout(w300 ? '6':'|');
  1051. X        gxy(currlen+gxoff,i); conout(w300 ? '6':'|');
  1052. X      }
  1053. X    gxy(gxoff-1,r);
  1054. X    conout(w300 ? '1':'+');
  1055. X    for (i = 0; i < currlen; i++) conout(w300 ? ':':'-');
  1056. X    conout(w300 ? '5':'+');
  1057. X
  1058. X    color(BLACK,WHITE);
  1059. X     }
  1060. X
  1061. X    for (i = 0; i < ytop + ybot; i++,i++)
  1062. X     for (j = 0; j < currlen; j += 8)
  1063. X      {    cbyte = vkeep[i][j/8];
  1064. X        cbyteo = vkeep[i+1][j/8];
  1065. X        mask = 128;
  1066. X        for (bit = 0; bit < 8; bit++, mask >>= 1)
  1067. X         if ( /* there is a dot in this row or the next */
  1068. X             (mask & cbyte) | (mask & cbyteo)
  1069. X            )
  1070. X         {    gxy(j+bit+gxoff, i/2+gyoff);
  1071. X             /* both dots? */
  1072. X            if ((mask & cbyte)&& (mask & cbyteo))
  1073. X                conout(bothdot);
  1074. X            /* dot in this row only? */
  1075. X            else if (mask & cbyte)
  1076. X                conout(upperdot);
  1077. X            else conout(lowerdot);    /* must be dot in next row */
  1078. X         }
  1079. X      }
  1080. X}
  1081. X
  1082. X
  1083. Xgraph(yes)
  1084. Xchar yes;
  1085. X{    if (!w300) return;
  1086. X
  1087. X    conout(ESC);    conout('H');
  1088. X    if (yes) conout(2); else conout(3);
  1089. X    conout(ESC);    conout('`');    /* cursor off/on    */
  1090. X    if (yes) conout('0'); else conout('1');
  1091. X    if (!yes) color(BLACK, WHITE);
  1092. X}
  1093. X
  1094. Xcolor(fc, bc)
  1095. Xchar fc, bc;
  1096. X{    if (!w300) return;
  1097. X
  1098. X    conout(ESC);    conout('g');
  1099. X    conout(fc);    conout(bc);
  1100. X}
  1101. X
  1102. X
  1103. Xmax(x,y)
  1104. Xint x,y;
  1105. X{    if (x >= y) return(x);
  1106. X    return(y);
  1107. X}
  1108. X
  1109. Xmin(x,y)
  1110. Xint x,y;
  1111. X{    if (x >= y) return(y);
  1112. X    return(x);
  1113. X}
  1114. X
  1115. Xctovkeep()
  1116. X{    bzero(vkeep,KEEPSIZE*GRSIZE);
  1117. X
  1118. X    for (row = 0; row < 24; row++)
  1119. X    for (col = 0; col < currlen+lbear; col++)
  1120. X        if (chkcbit()) chngbit(TRUE);
  1121. X    currlen += lbear + rbear;
  1122. X}
  1123. X
  1124. Xchkcbit()
  1125. X{    if (duplflag && row > 23)
  1126. X        return( cchkcbit(3, row - 24));
  1127. X    else return( cchkcbit(0, row));
  1128. X}
  1129. X
  1130. Xcchkcbit(ib, row)
  1131. Xchar ib, row;
  1132. X{    unsigned char bit, mask, cbyte;
  1133. X
  1134. X    if (col < lbear) return(0);
  1135. X    bit = row / 3;
  1136. X    mask = 128 >> bit; 
  1137. X    cbyte = ckeep[ib + (row % 3)][col-lbear];
  1138. X    if (cbyte & mask) return(1);
  1139. X    return(0);
  1140. X}
  1141. X
  1142. X
  1143. X
  1144. Xloadft()
  1145. X{    int fdft, i, ftrecs;
  1146. X    char fname[20];
  1147. X
  1148. X    strcpy(fname,ftname); strcat(fname,".fn2");
  1149. X
  1150. X    if ((fdft = open(fname,O_RDONLY,"r")) == ERROR)
  1151. X        {printf("no font"); return;}
  1152. X    if (read(fdft, fix, 2*128) != 2*128)
  1153. X        {printf("bad font"); return;}
  1154. X
  1155. X    /* only read enough of the font to get info for char's
  1156. X        up to ascii nul (which is not used)        */
  1157. X    ftrecs = (fix[127]+127)/128;
  1158. X
  1159. X    if (read(fdft, ft, ftrecs*128) != ftrecs*128)
  1160. X        {printf("bad font"); return;}
  1161. X    close(fdft);
  1162. X/*
  1163. X        if (ftrecs > FTSIZE/128) ovlflag = TRUE;
  1164. X    for (i = 1; i < 127; i++)
  1165. X        ftlen[i] = (fix[i+1] - fix[i])/3;
  1166. X*/
  1167. X    chkdupl();
  1168. X
  1169. X}
  1170. X
  1171. X
  1172. X
  1173. \Rogue\Monster\
  1174. else
  1175.   echo "will not over write ./hplot.c"
  1176. fi
  1177. if [ `wc -c ./hplot.c | awk '{printf $1}'` -ne 20996 ]
  1178. then
  1179. echo `wc -c ./hplot.c | awk '{print "Got " $1 ", Expected " 20996}'`
  1180. fi
  1181. echo "Finished archive 3 of 4"
  1182. # if you want to concatenate archives, remove anything after this line
  1183. exit
  1184.  
  1185.