home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume4 / xdvi / patch4 < prev    next >
Encoding:
Text File  |  1989-07-16  |  57.6 KB  |  2,165 lines

  1. Path: uunet!island!argv
  2. From: argv@island.uu.net (Dan Heller)
  3. Newsgroups: comp.sources.x
  4. Subject: v04i044: xdvi, Patch4
  5. Message-ID: <875@island.uu.net>
  6. Date: 17 Jul 89 06:27:26 GMT
  7. Organization: Island Graphics, Marin County, California
  8. Lines: 2154
  9. Approved: island!argv@sun.com
  10.  
  11. Submitted-by: vojta@bosco.Berkeley.EDU
  12. Posting-number: Volume 4, Issue 44
  13. Archive-name: xdvi/patch4
  14.  
  15. Here's patch 4 to xdvi.  This patch allows the magnifying glass to move.
  16. It's jerky, but better than nothing.  Also, it changes the default shrink
  17. factor to 3.  I find it more useful than 4.
  18.  
  19. --Paul Vojta, vojta@math.berkeley.edu
  20.  
  21. ---- cut here ----
  22. diff -cr old/Makefile new/Makefile
  23. *** old/Makefile    Thu Jul 13 12:52:07 1989
  24. --- new/Makefile    Thu Jul 13 12:58:03 1989
  25. ***************
  26. *** 22,28 ****
  27.   BINDIR=/usr/sipb/$$(MACHTYPE)bin
  28.   INCLUDES=-I$(INCDIR)
  29.   CFLAGS=-O $(INCLUDES) $(DEFINES)
  30. ! LIBS=-L$(LIBDIR) -lXaw -lXt $(XMULIB) -lX11 -lm
  31.   SRCS=xdvi.c dvi_init.c dvi_draw.c $(FONTFORMATS_C) pxl_open.c tpic.c \
  32.     xdvi.h dvi.h xdvi.icon
  33.   OBJS=xdvi.o dvi_init.o dvi_draw.o $(FONTFORMATS_O) pxl_open.o tpic.o
  34. --- 22,28 ----
  35.   BINDIR=/usr/sipb/$$(MACHTYPE)bin
  36.   INCLUDES=-I$(INCDIR)
  37.   CFLAGS=-O $(INCLUDES) $(DEFINES)
  38. ! LIBS=-L$(LIBDIR) -lXaw $(XMULIB) -lXt -lX11 -lm
  39.   SRCS=xdvi.c dvi_init.c dvi_draw.c $(FONTFORMATS_C) pxl_open.c tpic.c \
  40.     xdvi.h dvi.h xdvi.icon
  41.   OBJS=xdvi.o dvi_init.o dvi_draw.o $(FONTFORMATS_O) pxl_open.o tpic.o
  42. diff -cr old/README new/README
  43. *** old/README    Thu Jul 13 12:52:13 1989
  44. --- new/README    Sat Jul  8 15:43:09 1989
  45. ***************
  46. *** 61,68 ****
  47.                   time xdvi -d 8 file.dvi
  48.       BMLONG        (X11 only; xdvi.c dvi_draw.c gf.c pk.c pxl.c)  Store
  49.               bitmaps in long integers instead of bytes.
  50. -     MAXCHARS    (dvi_init.c dvi_draw.c gf.c pk.c pxl.c)  Set to 256 for
  51. -             256-character fonts.  Default is 128.
  52.       ALTFONT        Default font to use if the font named in the dvi file
  53.               cannot be found.  Can be set to NULL.  By default, it
  54.               is "cmr10".
  55. --- 61,66 ----
  56. ***************
  57. *** 125,130 ****
  58. --- 123,131 ----
  59.       generating table.h.
  60.   --  Patchlevel 3:  --
  61.      13.  Added -altfont command line option and SYSV compilation option.
  62. + --  Patchlevel 4:  --
  63. +    14.  Removed MAXCHARS compilation option.  It's automatic now.  Made X10
  64. +     scrolling smoother.  Implemented the moving magnifying glass.
  65.   
  66.   Paul Vojta, vojta@math.berkeley.edu
  67.   ================================================================================
  68. diff -cr old/dvi_draw.c new/dvi_draw.c
  69. *** old/dvi_draw.c    Thu Jul 13 12:52:19 1989
  70. --- new/dvi_draw.c    Sat Jul  8 15:20:40 1989
  71. ***************
  72. *** 19,25 ****
  73.    *    MSBITFIRST    store bitmaps internally in with significant bit first
  74.    *    BMSHORT    store bitmaps in shorts instead of bytes
  75.    *    BMLONG    store bitmaps in longs instead of bytes
  76. -  *    MAXCHARS set to 256 for 256 character fonts (default = 128)
  77.    */
  78.   
  79.   #include <stdio.h>
  80. --- 19,24 ----
  81. ***************
  82. *** 294,302 ****
  83.   {
  84.       register struct glyph *g;
  85.   
  86. !     g = ¤t_font->glyph[ch];
  87. !     if (g->bitmap.bits == NULL) {
  88. !         if (g->addr == NULL)
  89.           oops("Character %d not defined in font %s\n", ch,
  90.               current_font->fontname);
  91.           open_pxl_file(current_font);
  92. --- 293,301 ----
  93.   {
  94.       register struct glyph *g;
  95.   
  96. !     if (ch > maxchar ||
  97. !         (g = ¤t_font->glyph[ch])->bitmap.bits == NULL) {
  98. !         if (ch > maxchar || g->addr == 0)
  99.           oops("Character %d not defined in font %s\n", ch,
  100.               current_font->fontname);
  101.           open_pxl_file(current_font);
  102. ***************
  103. *** 378,383 ****
  104. --- 377,383 ----
  105.       *prev = fontp->next;
  106.       fontp->next = current_font;
  107.       current_font = fontp;
  108. +     maxchar = current_font->maxchar;
  109.   }
  110.   
  111.   static
  112. ***************
  113. *** 426,435 ****
  114.                   case SET1:
  115.                   case PUT1:
  116.                   ch1 = one(dvi_file);
  117. - #if    MAXCHARS < 256
  118. -                 if (ch1 >= MAXCHARS)
  119. -                     oops("Character code too large:  %d", ch1);
  120. - #endif    MAXCHARS
  121.                   set_char(ch1);
  122.                   if (ch == SET1)
  123.                       DVI_H += current_font->glyph[ch1].dvi_adv;
  124. --- 426,431 ----
  125. diff -cr old/dvi_init.c new/dvi_init.c
  126. *** old/dvi_init.c    Thu Jul 13 12:52:22 1989
  127. --- new/dvi_init.c    Mon Jul 10 13:27:43 1989
  128. ***************
  129. *** 19,25 ****
  130.    *    MSBITFIRST    store bitmaps internally in with significant bit first
  131.    *    BMSHORT    store bitmaps in shorts instead of bytes
  132.    *    BMLONG    store bitmaps in longs instead of bytes
  133. -  *    MAXCHARS set to 256 for 256 character fonts (default = 128)
  134.    */
  135.   
  136.   #include <stdio.h>
  137. --- 19,24 ----
  138. ***************
  139. *** 29,34 ****
  140. --- 28,34 ----
  141.   #include <sys/stat.h>
  142.   
  143.   #define    dvi_oops(str)    longjmp(dvi_env, (int) str);
  144. + #define XtOffset(type, field)    ((unsigned int)&(((type)NULL)->field))
  145.   extern char    *alt_font;
  146.   
  147.   static    struct stat fstatbuf;        /* mechanism to see if file was */
  148. ***************
  149. *** 35,40 ****
  150. --- 35,41 ----
  151.   time_t    dvi_time;            /* modified since last usage */
  152.   
  153.   struct font *current_font = NULL;    /* ptr into linked list of fonts */
  154. + ubyte    maxchar;
  155.   
  156.   static    Boolean    font_not_found;
  157.   static    struct font **old_fonts;    /* used by read_postamble */
  158. ***************
  159. *** 41,46 ****
  160. --- 42,49 ----
  161.   
  162.   int    n_fonts_left    = 32767;    /* for LRU management of fonts */
  163.   
  164. + char    *realloc();
  165.   /*
  166.    * DVI preamble and postamble information.
  167.    */
  168. ***************
  169. *** 66,72 ****
  170.   #ifndef SYSV
  171.   char    *sprintf();
  172.   #endif
  173. ! char    *malloc();
  174.   FILE    *pxl_open();
  175.   
  176.   static    Boolean
  177. --- 69,75 ----
  178.   #ifndef SYSV
  179.   char    *sprintf();
  180.   #endif
  181. ! char    *malloc(), *strcpy();
  182.   FILE    *pxl_open();
  183.   
  184.   static    Boolean
  185. ***************
  186. *** 159,164 ****
  187. --- 162,168 ----
  188.       for (;;) {
  189.           fontp1 = *fontpp;
  190.           if (fontp1 == NULL) {
  191. +         maxchar = 255;
  192.           if (!define_new_font(fontp, fontp->fontname)) {
  193.               if (alt_font == NULL || !define_new_font(fontp, alt_font)) {
  194.               font_not_found = True;
  195. ***************
  196. *** 171,176 ****
  197. --- 175,186 ----
  198.               fontp->fontname = malloc((unsigned) strlen(alt_font)+1);
  199.               (void) strcpy(fontp->fontname, alt_font);
  200.           }
  201. +         while (maxchar > 0 && fontp->glyph[maxchar].addr == 0)
  202. +             --maxchar;
  203. +         if (maxchar < 255)
  204. +             fontp = (struct font *) realloc((char *) fontp,
  205. +             XtOffset(struct font *, glyph[(int) maxchar + 1]));
  206. +         fontp->maxchar = maxchar;
  207.           break;
  208.           }
  209.           if (strcmp(fontp->fontname, fontp1->fontname) == 0
  210. ***************
  211. *** 294,300 ****
  212.           }
  213.           free(fontp->fontname);
  214.           free(fontp->filename);
  215. !         for (g = &fontp->glyph[0]; g < &fontp->glyph[MAXCHARS]; ++g) {
  216.               if (g->bitmap.bits) free(g->bitmap.bits);
  217.               if (g->bitmap2.bits) free(g->bitmap2.bits);
  218.           }
  219. --- 304,311 ----
  220.           }
  221.           free(fontp->fontname);
  222.           free(fontp->filename);
  223. !         for (g = fontp->glyph; g <= fontp->glyph + fontp->maxchar; ++g)
  224. !         {
  225.               if (g->bitmap.bits) free(g->bitmap.bits);
  226.               if (g->bitmap2.bits) free(g->bitmap2.bits);
  227.           }
  228. ***************
  229. *** 394,400 ****
  230.       register struct glyph *g;
  231.   
  232.       for (f = current_font; f != NULL; f = f->next)
  233. !         for (g = &f->glyph[0]; g < &f->glyph[MAXCHARS]; ++g)
  234.           if (g->bitmap2.bits) {
  235.               free(g->bitmap2.bits);
  236.               g->bitmap2.bits = NULL;
  237. --- 405,411 ----
  238.       register struct glyph *g;
  239.   
  240.       for (f = current_font; f != NULL; f = f->next)
  241. !         for (g = f->glyph; g <= f->glyph + f->maxchar; ++g)
  242.           if (g->bitmap2.bits) {
  243.               free(g->bitmap2.bits);
  244.               g->bitmap2.bits = NULL;
  245. diff -cr old/gf.c new/gf.c
  246. *** old/gf.c    Thu Jul 13 12:52:25 1989
  247. --- new/gf.c    Sat Jul  8 15:21:34 1989
  248. ***************
  249. *** 76,82 ****
  250.    */
  251.       if (debug & DBG_PK)
  252.           Printf("Reading header for GF pixel file %s\n", fontp->filename);
  253. -     GF_file = fontp->file;
  254.       expect(PRE);
  255.       expect(GF_ID_BYTE);
  256.   /*
  257. --- 76,81 ----
  258. ***************
  259. *** 96,116 ****
  260.    *    Read postamble.
  261.    */
  262.       expect(POST);
  263. !     (void) four(GF_file);    /* pointer to last eoc + 1 */
  264. !     (void) four(fontp->file);        /* skip design size */
  265. !     (void) four(fontp->file);        /* skip checksum */
  266. !     hppp = sfour(fontp->file);
  267. !     vppp = sfour(fontp->file);
  268.       if (debug && hppp != vppp)
  269.           oops("Warning: aspect ratio not 1:1 for font %s", fontp->fontname);
  270. !     (void) four(fontp->file);        /* skip min_m */
  271. !     (void) four(fontp->file);        /* skip max_m */
  272. !     (void) four(fontp->file);        /* skip min_n */
  273. !     (void) four(fontp->file);        /* skip max_n */
  274.   /*
  275.    *    Prepare glyph array.
  276.    */
  277. !     for (g = fontp->glyph; g < &fontp->glyph[MAXCHARS]; ++g) {
  278.           g->addr = 0;
  279.           g->bitmap.bits = NULL;
  280.           g->bitmap2.bits = NULL;
  281. --- 95,115 ----
  282.    *    Read postamble.
  283.    */
  284.       expect(POST);
  285. !     (void) four(GF_file);        /* pointer to last eoc + 1 */
  286. !     (void) four(GF_file);        /* skip design size */
  287. !     (void) four(GF_file);        /* skip checksum */
  288. !     hppp = sfour(GF_file);
  289. !     vppp = sfour(GF_file);
  290.       if (debug && hppp != vppp)
  291.           oops("Warning: aspect ratio not 1:1 for font %s", fontp->fontname);
  292. !     (void) four(GF_file);        /* skip min_m */
  293. !     (void) four(GF_file);        /* skip max_m */
  294. !     (void) four(GF_file);        /* skip min_n */
  295. !     (void) four(GF_file);        /* skip max_n */
  296.   /*
  297.    *    Prepare glyph array.
  298.    */
  299. !     for (g = fontp->glyph; g < fontp->glyph + 256; ++g) {
  300.           g->addr = 0;
  301.           g->bitmap.bits = NULL;
  302.           g->bitmap2.bits = NULL;
  303. ***************
  304. *** 123,133 ****
  305.           int addr;
  306.   
  307.           ch = one(GF_file);            /* character code */
  308. - #if    MAXCHARS < 256
  309. -         if (ch >= MAXCHARS)
  310. -         oops("Character code %d outside range, file %s", ch,
  311. -             fontp->fontname);
  312. - #endif    MAXCHARS
  313.           g = &fontp->glyph[ch];
  314.           switch (cmnd) {
  315.           case CHAR_LOC:
  316. --- 122,127 ----
  317. diff -cr old/patchlevel.h new/patchlevel.h
  318. *** old/patchlevel.h    Thu Jul 13 12:52:26 1989
  319. --- new/patchlevel.h    Sat Jul  8 15:43:22 1989
  320. ***************
  321. *** 1 ****
  322. ! #define PATCHLEVEL 3
  323. --- 1 ----
  324. ! #define PATCHLEVEL 4
  325. diff -cr old/pk.c new/pk.c
  326. *** old/pk.c    Thu Jul 13 12:52:29 1989
  327. --- new/pk.c    Sat Jul  8 15:22:10 1989
  328. ***************
  329. *** 29,40 ****
  330.   
  331.   static    int
  332.   PK_get_nyb( fp )
  333. !      register struct font *fp;
  334.   {
  335.     unsigned temp;
  336.     if( PK_bitpos < 0 )
  337.       {
  338. !       PK_input_byte = one(fp->file);
  339.         PK_bitpos = 4;
  340.       }
  341.     temp = PK_input_byte >> PK_bitpos;
  342. --- 29,40 ----
  343.   
  344.   static    int
  345.   PK_get_nyb( fp )
  346. !      register FILE *fp;
  347.   {
  348.     unsigned temp;
  349.     if( PK_bitpos < 0 )
  350.       {
  351. !       PK_input_byte = one(fp);
  352.         PK_bitpos = 4;
  353.       }
  354.     temp = PK_input_byte >> PK_bitpos;
  355. ***************
  356. *** 45,51 ****
  357.   
  358.   static    int
  359.   PK_packed_num( fp )
  360. !      register struct font *fp;
  361.   {
  362.     int i,j;
  363.     if( ( i = PK_get_nyb( fp ) ) == 0 )
  364. --- 45,51 ----
  365.   
  366.   static    int
  367.   PK_packed_num( fp )
  368. !      register FILE *fp;
  369.   {
  370.     int i,j;
  371.     if( ( i = PK_get_nyb( fp ) ) == 0 )
  372. ***************
  373. *** 76,88 ****
  374.   
  375.   
  376.   static    void
  377. ! PK_skip_specials( fp )
  378. !      register struct font *fp;
  379.   {
  380.     int i,j;
  381.     do
  382.       {
  383. !       PK_flag_byte = one(fp->file);
  384.         if( PK_flag_byte >= PK_CMD_START )
  385.       {
  386.         switch( PK_flag_byte )
  387. --- 76,89 ----
  388.   
  389.   
  390.   static    void
  391. ! PK_skip_specials(fontp)
  392. !     register struct font *fontp;
  393.   {
  394.     int i,j;
  395. +   register FILE *fp = fontp->file;
  396.     do
  397.       {
  398. !       PK_flag_byte = one(fp);
  399.         if( PK_flag_byte >= PK_CMD_START )
  400.       {
  401.         switch( PK_flag_byte )
  402. ***************
  403. *** 94,110 ****
  404.             {
  405.           i = 0;
  406.           for (j = PK_CMD_START; j <= PK_flag_byte; j++)
  407. !           i = (i*256) + one(fp->file);
  408. !         while (i--) (void) one(fp->file);
  409.           break;
  410.             }
  411.           case PK_Y :
  412. !           (void) four(fp->file);
  413.           case PK_POST :
  414.           case PK_NOOP :
  415.             break;
  416.           default :
  417. !           oops("Unexpected %d in PK file %s\n", PK_flag_byte, fp->fontname);
  418.             break;
  419.           }
  420.       }
  421. --- 95,112 ----
  422.             {
  423.           i = 0;
  424.           for (j = PK_CMD_START; j <= PK_flag_byte; j++)
  425. !           i = (i*256) + one(fp);
  426. !         while (i--) (void) one(fp);
  427.           break;
  428.             }
  429.           case PK_Y :
  430. !           (void) four(fp);
  431.           case PK_POST :
  432.           case PK_NOOP :
  433.             break;
  434.           default :
  435. !           oops("Unexpected %d in PK file %s\n", PK_flag_byte,
  436. !         fontp->fontname);
  437.             break;
  438.           }
  439.       }
  440. ***************
  441. *** 147,153 ****
  442.     /*if (fontp->f_scale == 0) fontp->f_scale = 1000;*/
  443.       {
  444.           register struct glyph *g;
  445. !         for (g = fontp->glyph; g < &fontp->glyph[MAXCHARS]; ++g) {
  446.           g->addr = 0;
  447.           g->bitmap.bits = NULL;
  448.           g->bitmap2.bits = NULL;
  449. --- 149,155 ----
  450.     /*if (fontp->f_scale == 0) fontp->f_scale = 1000;*/
  451.       {
  452.           register struct glyph *g;
  453. !         for (g = fontp->glyph; g < fontp->glyph + 256; ++g) {
  454.           g->addr = 0;
  455.           g->bitmap.bits = NULL;
  456.           g->bitmap2.bits = NULL;
  457. ***************
  458. *** 173,183 ****
  459.           bytes_left = (flag_low_bits << 8) + one(fontp->file);
  460.           cc = one(fontp->file);
  461.           }
  462. - #if    MAXCHARS < 256
  463. -         if (cc >= MAXCHARS)
  464. -         oops("Character code %d outside range, file %s\n", cc,
  465. -             fontp->fontname);
  466. - #endif    MAXCHARS
  467.           fontp->glyph[cc].addr = ftell(fontp->file);
  468.           fontp->glyph[cc].x2 = PK_flag_byte;
  469.           Fseek(fontp->file, (long) bytes_left, 1);
  470. --- 175,180 ----
  471. ***************
  472. *** 185,192 ****
  473.   }
  474.   
  475.   static    void
  476. ! read_char(fp, ch)
  477. !     register struct font *fp;
  478.       ubyte ch;
  479.   {
  480.       int    i, j;
  481. --- 182,189 ----
  482.   }
  483.   
  484.   static    void
  485. ! read_char(fontp, ch)
  486. !     register struct font *fontp;
  487.       ubyte ch;
  488.   {
  489.       int    i, j;
  490. ***************
  491. *** 195,206 ****
  492.       Boolean    paint_switch;
  493.       BMUNIT    *cp;
  494.       register struct glyph *g;
  495.       long    fpwidth;
  496.       BMUNIT    word;
  497.       int    word_weight, bytes_wide;
  498.       int    rows_left, h_bit, count;
  499.   
  500. !   g = &fp->glyph[ch];
  501.     PK_flag_byte = g->x2;
  502.     PK_dyn_f = PK_flag_byte >> 4;
  503.     paint_switch = ((PK_flag_byte & 8) != 0);
  504. --- 192,204 ----
  505.       Boolean    paint_switch;
  506.       BMUNIT    *cp;
  507.       register struct glyph *g;
  508. +     register FILE *fp = fontp->file;
  509.       long    fpwidth;
  510.       BMUNIT    word;
  511.       int    word_weight, bytes_wide;
  512.       int    rows_left, h_bit, count;
  513.   
  514. !   g = &fontp->glyph[ch];
  515.     PK_flag_byte = g->x2;
  516.     PK_dyn_f = PK_flag_byte >> 4;
  517.     paint_switch = ((PK_flag_byte & 8) != 0);
  518. ***************
  519. *** 214,238 ****
  520.   
  521.       /* now read rest of character preamble */
  522.   
  523. !     if (n != 4) fpwidth = snum(fp->file, 3);
  524.       else {
  525. !     fpwidth = sfour(fp->file);
  526. !     (void) four(fp->file);    /* horizontal escapement */
  527.       }
  528. !     (void) num(fp->file, n);    /* vertical escapement */
  529.       {
  530.       unsigned long w, h;
  531. !     w = num(fp->file, n);
  532. !     h = num(fp->file, n);
  533.       if (w > 0x7fff || h > 0x7fff)
  534. !         oops("Too large character (%d) in file %s\n", ch, fp->fontname);
  535.       g->bitmap.w = w;
  536.       g->bitmap.h = h;
  537.       }
  538. !     g->x = snum(fp->file, n);
  539. !     g->y = snum(fp->file, n);
  540.   
  541. !     g->dvi_adv = ((double) fp->scale * fpwidth) / (1 << 20);
  542.   
  543.       if (debug & DBG_PK) {
  544.       if (g->bitmap.w != 0)
  545. --- 212,237 ----
  546.   
  547.       /* now read rest of character preamble */
  548.   
  549. !     if (n != 4) fpwidth = snum(fp, 3);
  550.       else {
  551. !     fpwidth = sfour(fp);
  552. !     (void) four(fp);    /* horizontal escapement */
  553.       }
  554. !     (void) num(fp, n);    /* vertical escapement */
  555.       {
  556.       unsigned long w, h;
  557. !     w = num(fp, n);
  558. !     h = num(fp, n);
  559.       if (w > 0x7fff || h > 0x7fff)
  560. !         oops("Too large character (%d) in file %s\n", ch, fontp->fontname);
  561.       g->bitmap.w = w;
  562.       g->bitmap.h = h;
  563.       }
  564. !     g->x = snum(fp, n);
  565. !     g->y = snum(fp, n);
  566.   
  567. !     g->dvi_adv = ((double) fontp->scale * fpwidth) / (1 << 20);
  568.   
  569.       if (debug & DBG_PK) {
  570.       if (g->bitmap.w != 0)
  571. ***************
  572. *** 242,248 ****
  573.       }
  574.   
  575.       if (g->bitmap.w == 0) return;
  576. !     alloc_bitmap(&g->bitmap, fp->fontname, ch);
  577.       cp = (BMUNIT *) g->bitmap.bits;
  578.   /*
  579.    * read character data into *cp
  580. --- 241,247 ----
  581.       }
  582.   
  583.       if (g->bitmap.w == 0) return;
  584. !     alloc_bitmap(&g->bitmap, fontp->fontname, ch);
  585.       cp = (BMUNIT *) g->bitmap.bits;
  586.   /*
  587.    * read character data into *cp
  588. ***************
  589. *** 264,270 ****
  590.           {
  591.                     if (--PK_bitpos < 0)
  592.                       {
  593. !                       word = one(fp->file);
  594.                         PK_bitpos = 7;
  595.                       }
  596.   #ifndef    MSBITFIRST
  597. --- 263,269 ----
  598.           {
  599.                     if (--PK_bitpos < 0)
  600.                       {
  601. !                       word = one(fp);
  602.                         PK_bitpos = 7;
  603.                       }
  604.   #ifndef    MSBITFIRST
  605. ***************
  606. *** 357,364 ****
  607.           }
  608.         if (cp != ((BMUNIT *) (g->bitmap.bits + bytes_wide * g->bitmap.h)))
  609.           oops("Wrong number of bits stored:  char. %d, font %s\n", ch,
  610. !         fp->fontname);
  611.         if (rows_left != 0 || h_bit != g->bitmap.w)
  612. !         oops("Bad pk file (%s), too many bits\n", fp->fontname);
  613.       }
  614.   }
  615. --- 356,363 ----
  616.           }
  617.         if (cp != ((BMUNIT *) (g->bitmap.bits + bytes_wide * g->bitmap.h)))
  618.           oops("Wrong number of bits stored:  char. %d, font %s\n", ch,
  619. !         fontp->fontname);
  620.         if (rows_left != 0 || h_bit != g->bitmap.w)
  621. !         oops("Bad pk file (%s), too many bits\n", fontp->fontname);
  622.       }
  623.   }
  624. diff -cr old/pxl.c new/pxl.c
  625. *** old/pxl.c    Thu Jul 13 12:52:31 1989
  626. --- new/pxl.c    Sat Jul  8 15:23:15 1989
  627. ***************
  628. *** 56,85 ****
  629.           register struct font *fontp;
  630.   {
  631.       register struct glyph *g;
  632.           long font_dir_ptr;
  633.   
  634.       if (debug & DBG_PK)
  635.           Printf("Reading header for PXL file %s\n", fontp->filename);
  636.       fontp->read_char = read_char;
  637. !     if (four(fontp->file) != 1001)
  638.           oops("File %s has wrong PXL magic number.\n", fontp->filename);
  639.       /* seek to trailer info */
  640. !     Fseek(fontp->file, (long) -5 * 4, 2);
  641. !     (void) four(fontp->file);    /* checksum */
  642. !     (void) four(fontp->file);    /* magnify */
  643. !     (void) four(fontp->file);    /* design size */
  644. !         font_dir_ptr = sfour(fontp->file) * 4;
  645. !     (void) four(fontp->file);    /* pxl id word */
  646.       /* seek to font directory */
  647. !     Fseek(fontp->file, font_dir_ptr, 0);
  648. !     for (g = fontp->glyph; g < &fontp->glyph[128]; ++g) {
  649.           g->bitmap.bits = NULL;
  650.           g->bitmap2.bits = NULL;
  651. !         g->bitmap.w = two(fontp->file);
  652. !         g->bitmap.h = two(fontp->file);
  653. !         g->x = stwo(fontp->file);
  654. !         g->y = stwo(fontp->file);
  655. !         g->addr = four(fontp->file) * 4;
  656.           /*
  657.           **  The TFM-width word is kind of funny in the units
  658.           **  it is expressed in.  It works this way:
  659. --- 56,86 ----
  660.           register struct font *fontp;
  661.   {
  662.       register struct glyph *g;
  663. +     register FILE *fp;
  664.           long font_dir_ptr;
  665.   
  666.       if (debug & DBG_PK)
  667.           Printf("Reading header for PXL file %s\n", fontp->filename);
  668.       fontp->read_char = read_char;
  669. !     if (four(fp = fontp->file) != 1001)
  670.           oops("File %s has wrong PXL magic number.\n", fontp->filename);
  671.       /* seek to trailer info */
  672. !     Fseek(fp, (long) -5 * 4, 2);
  673. !     (void) four(fp);    /* checksum */
  674. !     (void) four(fp);    /* magnify */
  675. !     (void) four(fp);    /* design size */
  676. !         font_dir_ptr = sfour(fp) * 4;
  677. !     (void) four(fp);    /* pxl id word */
  678.       /* seek to font directory */
  679. !     Fseek(fp, font_dir_ptr, 0);
  680. !     for (g = fontp->glyph; g < fontp->glyph + 128; ++g) {
  681.           g->bitmap.bits = NULL;
  682.           g->bitmap2.bits = NULL;
  683. !         g->bitmap.w = two(fp);
  684. !         g->bitmap.h = two(fp);
  685. !         g->x = stwo(fp);
  686. !         g->y = stwo(fp);
  687. !         g->addr = four(fp) * 4;
  688.           /*
  689.           **  The TFM-width word is kind of funny in the units
  690.           **  it is expressed in.  It works this way:
  691. ***************
  692. *** 110,127 ****
  693.           */
  694.   
  695.           g->dvi_adv =
  696. !             ((double) fontp->scale * four(fontp->file)) / (1 << 20);
  697.           if (debug & DBG_PK)
  698.               Printf("size=%dx%d, dvi_adv=%d\n", g->bitmap.w, g->bitmap.h,
  699.               g->dvi_adv);
  700.       }
  701. ! #if    MAXCHARS > 128
  702. !     for ( ; g < &fontp->glyph[MAXCHARS]; ++g) {
  703. !         g->bitmap.bits = NULL;
  704. !         g->bitmap2.bits = NULL;
  705. !         g->addr = 0;
  706. !     }
  707. ! #endif    MAXCHARS
  708.   }
  709.   
  710.   static void
  711. --- 111,122 ----
  712.           */
  713.   
  714.           g->dvi_adv =
  715. !             ((double) fontp->scale * four(fp)) / (1 << 20);
  716.           if (debug & DBG_PK)
  717.               Printf("size=%dx%d, dvi_adv=%d\n", g->bitmap.w, g->bitmap.h,
  718.               g->dvi_adv);
  719.       }
  720. !     maxchar = 127;
  721.   }
  722.   
  723.   static void
  724. ***************
  725. *** 131,136 ****
  726. --- 126,132 ----
  727.   {
  728.       register struct bitmap *bitmap;
  729.       register BMUNIT *ptr;
  730. +     register FILE *fp = fontp->file;
  731.       register int i, j;
  732.   #ifndef    BMLONG
  733.       register int padding_length;
  734. ***************
  735. *** 146,174 ****
  736.       for (i = bitmap->h; i > 0; --i) {
  737.           for (j = bitmap->bytes_wide; j > 0; j -= BYTES_PER_BMUNIT) {
  738.   #ifndef    MSBITFIRST
  739. !         *ptr = _reverse_byte[one(fontp->file)];
  740.   #if    BYTES_PER_BMUNIT > 1
  741. !         *ptr |= _reverse_byte[one(fontp->file)] << 8;
  742.   #endif
  743.   #ifdef    BMLONG
  744. !         *ptr |= _reverse_byte[one(fontp->file)] << 16;
  745. !         *ptr |= _reverse_byte[one(fontp->file)] << 24;
  746.   #endif    BMLONG
  747.   #else    MSBITFIRST
  748.           *ptr = 0;
  749.   #ifdef    BMLONG
  750. !         *ptr |= one(fontp->file) << 24;
  751. !         *ptr |= one(fontp->file) << 16;
  752.   #endif    BMLONG
  753.   #if    BYTES_PER_BMUNIT > 1
  754. !         *ptr |= one(fontp->file) << 8;
  755.   #endif
  756. !         *ptr |= one(fontp->file);
  757.   #endif    MSBITFIRST
  758.           ++ptr;
  759.           }
  760.   #ifndef    BMLONG
  761. !         for (j = padding_length; j > 0; --j) (void) one(fontp->file);
  762.   #endif    BMLONG
  763.       }
  764.   }
  765. --- 142,170 ----
  766.       for (i = bitmap->h; i > 0; --i) {
  767.           for (j = bitmap->bytes_wide; j > 0; j -= BYTES_PER_BMUNIT) {
  768.   #ifndef    MSBITFIRST
  769. !         *ptr = _reverse_byte[one(fp)];
  770.   #if    BYTES_PER_BMUNIT > 1
  771. !         *ptr |= _reverse_byte[one(fp)] << 8;
  772.   #endif
  773.   #ifdef    BMLONG
  774. !         *ptr |= _reverse_byte[one(fp)] << 16;
  775. !         *ptr |= _reverse_byte[one(fp)] << 24;
  776.   #endif    BMLONG
  777.   #else    MSBITFIRST
  778.           *ptr = 0;
  779.   #ifdef    BMLONG
  780. !         *ptr |= one(fp) << 24;
  781. !         *ptr |= one(fp) << 16;
  782.   #endif    BMLONG
  783.   #if    BYTES_PER_BMUNIT > 1
  784. !         *ptr |= one(fp) << 8;
  785.   #endif
  786. !         *ptr |= one(fp);
  787.   #endif    MSBITFIRST
  788.           ++ptr;
  789.           }
  790.   #ifndef    BMLONG
  791. !         for (j = padding_length; j > 0; --j) (void) one(fp);
  792.   #endif    BMLONG
  793.       }
  794.   }
  795. diff -cr old/xdvi.c new/xdvi.c
  796. *** old/xdvi.c    Thu Jul 13 12:52:43 1989
  797. --- new/xdvi.c    Thu Jul 13 13:07:32 1989
  798. ***************
  799. *** 19,25 ****
  800.    *    MSBITFIRST    store bitmaps internally in with significant bit first
  801.    *    BMSHORT    store bitmaps in shorts instead of bytes
  802.    *    BMLONG    store bitmaps in longs instead of bytes
  803. -  *    MAXCHARS set to 256 for 256 character fonts (default = 128)
  804.    *    ALTFONT    default for -altfont option.
  805.    */
  806.   #ifndef lint
  807. --- 19,24 ----
  808. ***************
  809. *** 50,56 ****
  810.   #endif not OLD_X11_TOOLKIT
  811.   #include <X11/Shell.h>    /* needed for def. of XtNiconX */
  812.   #include <X11/Viewport.h>
  813. - #include <X11/Simple.h>
  814.   #include <X11/cursorfont.h>
  815.   #include "xdvi.icon"
  816.   
  817. --- 49,54 ----
  818. ***************
  819. *** 72,80 ****
  820.   static    Screen    *SCRN;
  821.   static    Cursor    redraw_cursor, ready_cursor;
  822.   #define    SetCursor(x)    XDefineCursor(DISP, mane.win, x)
  823. ! #define    ClearPage()    XClearWindow(DISP, mane.win);
  824.   #define    Flush()        XFlush(DISP)
  825. ! static    Boolean    unmapped = True;
  826.   #ifndef X11HEIGHT
  827.   #define    X11HEIGHT    8    /* Height of server default font */
  828.   #endif X11HEIGHT
  829. --- 70,82 ----
  830.   static    Screen    *SCRN;
  831.   static    Cursor    redraw_cursor, ready_cursor;
  832.   #define    SetCursor(x)    XDefineCursor(DISP, mane.win, x)
  833. ! #define    ClearPage(wr)    XClearWindow(DISP, (wr).win);
  834. ! #define    ClearArea(win, x, y, w, h)    XClearArea(DISP, win, x, y, w, h, False)
  835. ! #define    CopyArea(win, x, y, w, h, x2, y2) \
  836. !             XCopyArea(DISP, win, win, DefaultGCOfScreen(SCRN), \
  837. !                 x, y, w, h, x2, y2)
  838.   #define    Flush()        XFlush(DISP)
  839. ! static    Boolean    resized    = False;
  840.   #ifndef X11HEIGHT
  841.   #define    X11HEIGHT    8    /* Height of server default font */
  842.   #endif X11HEIGHT
  843. ***************
  844. *** 86,92 ****
  845.   typedef    int        Position;
  846.   typedef    int        Dimension;
  847.   #define    SetCursor(x)
  848. ! #define    ClearPage()    XClear(mane.win);
  849.   #define    XBell(a,b)    XFeep(b/10-1)
  850.   #define    Flush()        XFlush()
  851.   #define    ConnectionNumber(DISP)    (_XlibCurrentDisplay->fd)
  852. --- 88,97 ----
  853.   typedef    int        Position;
  854.   typedef    int        Dimension;
  855.   #define    SetCursor(x)
  856. ! #define    ClearPage(wr)    XClear((wr).win);
  857. ! #define    ClearArea(win, x, y, w, h)    XPixSet(win, x, y, w, h, backpix)
  858. ! #define    CopyArea(win, x, y, w, h, x2, y2) \
  859. !             XCopyArea(win, x, y, x2, y2, w, h, GXcopy);
  860.   #define    XBell(a,b)    XFeep(b/10-1)
  861.   #define    Flush()        XFlush()
  862.   #define    ConnectionNumber(DISP)    (_XlibCurrentDisplay->fd)
  863. ***************
  864. *** 143,156 ****
  865.   
  866.   int    page_w, page_h;
  867.   static    int    screen_w, screen_h;
  868.   static    Dimension    window_w, window_h;
  869.   static    int    home_x, home_y;
  870.   static    int    min_x, max_x, min_y, max_y;
  871.   
  872. ! struct WindowRec mane    = {NULL, 4, 0, 0, MAXINT, 0, MAXINT, 0};
  873. ! struct WindowRec alt    = {NULL, 1, 0, 0, MAXINT, 0, MAXINT, 0};
  874.   /*    curr is temporary storage except for within redraw() */
  875. ! struct WindowRec curr    = {NULL, 4, 0, 0, MAXINT, 0, MAXINT, 0};
  876.   
  877.   /*
  878.    *    Mechanism to keep track of the magnifier window.  The problems are,
  879. --- 148,173 ----
  880.   
  881.   int    page_w, page_h;
  882.   static    int    screen_w, screen_h;
  883. + #define    clip_w    mane.width
  884. + #define    clip_h    mane.height
  885. + #ifndef X10
  886.   static    Dimension    window_w, window_h;
  887. + static    Position    main_x, main_y;
  888. + #else X10
  889. + #define    window_w clip_w
  890. + #define    window_h clip_h
  891. + #define    main_x    0
  892. + #define    main_y    0
  893. + #endif X10
  894. + static    Position mag_x, mag_y, new_mag_x, new_mag_y;
  895. + static    Boolean    mag_moved = False;
  896.   static    int    home_x, home_y;
  897.   static    int    min_x, max_x, min_y, max_y;
  898.   
  899. ! struct WindowRec mane    = {NULL, 3, 0, 0, 0, 0, MAXDIM, 0, MAXDIM, 0};
  900. ! struct WindowRec alt    = {NULL, 1, 0, 0, 0, 0, MAXDIM, 0, MAXDIM, 0};
  901.   /*    curr is temporary storage except for within redraw() */
  902. ! struct WindowRec curr    = {NULL, 3, 0, 0, 0, 0, MAXDIM, 0, MAXDIM, 0};
  903.   
  904.   /*
  905.    *    Mechanism to keep track of the magnifier window.  The problems are,
  906. ***************
  907. *** 259,264 ****
  908. --- 276,282 ----
  909.   
  910.   #ifndef X10
  911.   static    Widget    top_level, vport_widget, draw_widget, clip_widget;
  912. + static    Widget    x_bar, y_bar;    /* horizontal and vertical scroll bars */
  913.   static    XImage    *image;
  914.   
  915.   static    Arg    vport_args[] = {
  916. ***************
  917. *** 289,295 ****
  918.   
  919.   #ifdef lint
  920.   #ifndef X10
  921. ! WidgetClass    viewportWidgetClass, simpleWidgetClass;
  922.   char    xdvi_bits[288];
  923.   #else X10
  924.   short    xdvi_bits[15], xdvi_mask_bits[15];
  925. --- 307,313 ----
  926.   
  927.   #ifdef lint
  928.   #ifndef X10
  929. ! WidgetClass    viewportWidgetClass, widgetClass;
  930.   char    xdvi_bits[288];
  931.   #else X10
  932.   short    xdvi_bits[15], xdvi_mask_bits[15];
  933. ***************
  934. *** 323,329 ****
  935.   {
  936.   
  937.       if (debug & DBG_BITMAP)
  938. !         Printf("X(%d,%d)\n", x-curr.base_x, y-curr.base_y);
  939.       if (x < max_x && x + bitmap->w >= min_x &&
  940.           y < max_y && y + bitmap->h >= min_y) {
  941.           if (--event_counter == 0) read_events(False);
  942. --- 341,347 ----
  943.   {
  944.   
  945.       if (debug & DBG_BITMAP)
  946. !         Printf("X(%d,%d)\n", x - curr.base_x, y - curr.base_y);
  947.       if (x < max_x && x + bitmap->w >= min_x &&
  948.           y < max_y && y + bitmap->h >= min_y) {
  949.           if (--event_counter == 0) read_events(False);
  950. ***************
  951. *** 358,363 ****
  952. --- 376,461 ----
  953.       put_rectangle(x + w - t, y, t, h, True);
  954.   }
  955.   
  956. + /*
  957. +  *    Event-handling routines
  958. +  */
  959. + static    void
  960. + expose(windowrec, x, y, w, h)
  961. +     register struct WindowRec *windowrec;
  962. +     int    x, y, w, h;
  963. + {
  964. +     if (windowrec->min_x > x) windowrec->min_x = x;
  965. +     if (windowrec->max_x < x + w)
  966. +         windowrec->max_x = x + w;
  967. +     if (windowrec->min_y > y) windowrec->min_y = y;
  968. +     if (windowrec->max_y < y + h)
  969. +         windowrec->max_y = y + h;
  970. + }
  971. + static    void
  972. + clearexpose(windowrec, x, y, w, h)
  973. +     struct WindowRec *windowrec;
  974. +     int    x, y, w, h;
  975. + {
  976. +     ClearArea(windowrec->win, x, y, w, h);
  977. +     expose(windowrec, x, y, w, h);
  978. + }
  979. + static    void
  980. + scrollwindow(windowrec, x0, y0)
  981. +     register struct WindowRec *windowrec;
  982. +     int    x0, y0;
  983. + {
  984. +     int    x, y;
  985. +     int    x2 = 0, y2 = 0;
  986. +     int    ww, hh;
  987. +     x = x0 - windowrec->base_x;
  988. +     y = y0 - windowrec->base_y;
  989. +     ww = windowrec->width - x;
  990. +     hh = windowrec->height - y;
  991. +     windowrec->base_x = x0;
  992. +     windowrec->base_y = y0;
  993. +     if (curr.win == windowrec->win) {
  994. +         curr.base_x = x0;
  995. +         curr.base_y = y0;
  996. +     }
  997. +     windowrec->min_x -= x;
  998. +     if (windowrec->min_x < 0) windowrec->min_x = 0;
  999. +     windowrec->max_x -= x;
  1000. +     if (windowrec->max_x > windowrec->width)
  1001. +         windowrec->max_x = windowrec->width;
  1002. +     windowrec->min_y -= y;
  1003. +     if (windowrec->min_y < 0) windowrec->min_y = 0;
  1004. +     windowrec->max_y -= y;
  1005. +     if (windowrec->max_y > windowrec->height)
  1006. +         windowrec->max_y = windowrec->height;
  1007. +     if (x < 0) {
  1008. +         x2 = -x;
  1009. +         x = 0;
  1010. +         ww = windowrec->width - x2;
  1011. +     }
  1012. +     if (y < 0) {
  1013. +         y2 = -y;
  1014. +         y = 0;
  1015. +         hh = windowrec->height - y2;
  1016. +     }
  1017. +     if (ww <= 0 || hh <= 0) {
  1018. +         ClearPage(*windowrec);
  1019. +         windowrec->min_x = windowrec->min_y = 0;
  1020. +         windowrec->max_x = windowrec->width;
  1021. +         windowrec->max_y = windowrec->height;
  1022. +     }
  1023. +     else {
  1024. +         CopyArea(windowrec->win, x, y, ww, hh, x2, y2);
  1025. +         if (x > 0) clearexpose(windowrec, ww, 0, x, windowrec->height);
  1026. +         if (x2 > 0) clearexpose(windowrec, 0, 0, x2, windowrec->height);
  1027. +         if (y > 0) clearexpose(windowrec, 0, hh, windowrec->width, y);
  1028. +         if (y2 > 0) clearexpose(windowrec, 0, 0, windowrec->width, y2);
  1029. +     }
  1030. + }
  1031.   #ifndef X10
  1032.   /*
  1033.    *    routines for X11 toolkit
  1034. ***************
  1035. *** 368,374 ****
  1036.       {XtNheight,    (XtArgVal) &window_h},
  1037.   };
  1038.   
  1039. ! #define    get_wh(widget)    XtGetValues(widget, arg_wh, 2)
  1040.   
  1041.   static    Position    window_x, window_y;
  1042.   static    Arg        arg_xy[] = {
  1043. --- 466,475 ----
  1044.       {XtNheight,    (XtArgVal) &window_h},
  1045.   };
  1046.   
  1047. ! static    Arg    arg_wh_clip[] = {
  1048. !     {XtNwidth,    (XtArgVal) &clip_w},
  1049. !     {XtNheight,    (XtArgVal) &clip_h},
  1050. ! };
  1051.   
  1052.   static    Position    window_x, window_y;
  1053.   static    Arg        arg_xy[] = {
  1054. ***************
  1055. *** 381,461 ****
  1056.   #define    mane_base_x    0
  1057.   #define    mane_base_y    0
  1058.   
  1059. ! static    Boolean
  1060. ! scroll(horizontal, percent)
  1061. !     Boolean    horizontal;
  1062. !     float    percent;
  1063. ! {
  1064. !     register Widget    widget;
  1065. !     widget = XtNameToWidget(vport_widget,
  1066. !         horizontal ? "horizontal" : "vertical");
  1067. !     if (!widget) return False;
  1068. !     XtGetValues(clip_widget, horizontal ? &arg_wh[0] : &arg_wh[1], 1);
  1069. !     XtCallCallbacks(widget, XtNscrollProc,
  1070. !         (int) (percent*(horizontal ? window_w : window_h)));
  1071. !     return True;
  1072. ! }
  1073. ! /*
  1074. !  *    We unmap the window so that it does not generate expose events when
  1075. !  *    moving things around.  I have found that compress_exposure does not do
  1076. !  *    this.
  1077. !  */
  1078.   static
  1079. ! unmap()
  1080.   {
  1081. -     if (unmapped) return;
  1082. -     XUnmapWindow(DISP, mane.win);
  1083. -     unmapped = True;
  1084. - }
  1085. - static
  1086. - home()
  1087. - {
  1088. -     register Widget    widget;
  1089.       register int coord;
  1090.   
  1091. -     unmap();
  1092.       get_xy();
  1093. !     get_wh(clip_widget);
  1094. !     widget = XtNameToWidget(vport_widget, "horizontal");
  1095. !     if (widget) {
  1096.           coord = 0;
  1097. !         if (page_w > window_w) {
  1098. !         coord = (page_w - window_w) / 2;
  1099.           if (coord > home_x / mane.shrinkfactor)
  1100.               coord = home_x / mane.shrinkfactor;
  1101.           }
  1102. !         XtCallCallbacks(widget, XtNscrollProc, window_x + coord);
  1103.       }
  1104. !     widget = XtNameToWidget(vport_widget, "vertical");
  1105. !     if (widget) {
  1106.           coord = 0;
  1107. !         if (page_h > window_h) {
  1108. !         coord = (page_h - window_h) / 2;
  1109.           if (coord > home_y / mane.shrinkfactor)
  1110.               coord = home_y / mane.shrinkfactor;
  1111.           }
  1112. !         XtCallCallbacks(widget, XtNscrollProc, window_y + coord);
  1113.       }
  1114.   }
  1115.   
  1116.   static    void
  1117.   center(x, y)
  1118.       int x, y;
  1119.   {
  1120. -     register Widget widget;
  1121.   /*    We use the clip widget here because it gives a more exact value. */
  1122. !     get_wh(clip_widget);
  1123. !     x -= window_w/2;
  1124. !     y -= window_h/2;
  1125. !     widget = XtNameToWidget(vport_widget, "horizontal");
  1126. !     if (widget) XtCallCallbacks(widget, XtNscrollProc, x);
  1127. !     widget = XtNameToWidget(vport_widget, "vertical");
  1128. !     if (widget) XtCallCallbacks(widget, XtNscrollProc, y);
  1129.       XWarpPointer(DISP, None, None, 0, 0, 0, 0, -x, -y);
  1130.   }
  1131.   
  1132. --- 482,536 ----
  1133.   #define    mane_base_x    0
  1134.   #define    mane_base_y    0
  1135.   
  1136. ! #define    home(x)    Xtk_home()
  1137.   static
  1138. ! Xtk_home()
  1139.   {
  1140.       register int coord;
  1141.   
  1142.       get_xy();
  1143. !     if (x_bar) {
  1144.           coord = 0;
  1145. !         if (page_w > clip_w) {
  1146. !         coord = (page_w - clip_w) / 2;
  1147.           if (coord > home_x / mane.shrinkfactor)
  1148.               coord = home_x / mane.shrinkfactor;
  1149.           }
  1150. !         XtCallCallbacks(x_bar, XtNscrollProc, window_x + coord);
  1151.       }
  1152. !     if (y_bar) {
  1153.           coord = 0;
  1154. !         if (page_h > clip_h) {
  1155. !         coord = (page_h - clip_h) / 2;
  1156.           if (coord > home_y / mane.shrinkfactor)
  1157.               coord = home_y / mane.shrinkfactor;
  1158.           }
  1159. !         XtCallCallbacks(y_bar, XtNscrollProc, window_y + coord);
  1160.       }
  1161.   }
  1162.   
  1163. + static
  1164. + get_geom()
  1165. + {
  1166. +     register Dimension old_clip_w = clip_w;
  1167. +     XtGetValues(vport_widget, arg_wh, 2);
  1168. +     XtGetValues(clip_widget, arg_wh_clip, 2);
  1169. +     x_bar = XtNameToWidget(vport_widget, "horizontal");
  1170. +     y_bar = XtNameToWidget(vport_widget, "vertical");
  1171. +     if (old_clip_w == 0) home(False);
  1172. +     resized = False;
  1173. + }
  1174.   static    void
  1175.   center(x, y)
  1176.       int x, y;
  1177.   {
  1178.   /*    We use the clip widget here because it gives a more exact value. */
  1179. !     x -= clip_w/2;
  1180. !     y -= clip_h/2;
  1181. !     if (x_bar) XtCallCallbacks(x_bar, XtNscrollProc, x);
  1182. !     if (y_bar) XtCallCallbacks(y_bar, XtNscrollProc, y);
  1183.       XWarpPointer(DISP, None, None, 0, 0, 0, 0, -x, -y);
  1184.   }
  1185.   
  1186. ***************
  1187. *** 473,498 ****
  1188.   {
  1189.       XBell(DISP, 20);
  1190.   }
  1191.   #else X10
  1192. ! static
  1193. ! home()
  1194.   {
  1195. !     mane.base_x = 0;
  1196. !     if (page_w > window_w) {
  1197. !         mane.base_x = (page_w - window_w) / 2;
  1198. !         if (mane.base_x > home_x / mane.shrinkfactor)
  1199. !         mane.base_x = home_x / mane.shrinkfactor;
  1200.       }
  1201. !     mane.base_y = 0;
  1202. !     if (page_h > window_h) {
  1203. !         mane.base_y = (page_h - window_h) / 2;
  1204. !         if (mane.base_y > home_y / mane.shrinkfactor)
  1205. !         mane.base_y = home_y / mane.shrinkfactor;
  1206.       }
  1207.   }
  1208.   
  1209. - #define    unmap()
  1210. - #define    get_wh(widget)
  1211.   #define    get_xy()
  1212.   #define    window_x 0
  1213.   #define    window_y 0
  1214. --- 548,593 ----
  1215.   {
  1216.       XBell(DISP, 20);
  1217.   }
  1218. +     /*ARGSUSED*/
  1219. + static    void
  1220. + handle_resize(widget, junk, event)
  1221. +     Widget    widget;
  1222. +     caddr_t    junk;
  1223. +     XEvent    *event;
  1224. + {
  1225. +     resized = True;
  1226. + }
  1227.   #else X10
  1228. ! static    void
  1229. ! home(scrl)
  1230. !     Boolean    scrl;
  1231.   {
  1232. !     int    x = 0, y = 0;
  1233. !     if (page_w > clip_w) {
  1234. !         x = (page_w - clip_w) / 2;
  1235. !         if (x > home_x / mane.shrinkfactor)
  1236. !         x = home_x / mane.shrinkfactor;
  1237.       }
  1238. !     if (page_h > clip_h) {
  1239. !         y = (page_h - clip_h) / 2;
  1240. !         if (y > home_y / mane.shrinkfactor)
  1241. !         y = home_y / mane.shrinkfactor;
  1242.       }
  1243. +     if (scrl)
  1244. +         scrollwindow(&mane, x, y);
  1245. +     else {
  1246. +         mane.base_x = x;
  1247. +         mane.base_y = y;
  1248. +         if (curr.win == mane.win) {
  1249. +         curr.base_x = x;
  1250. +         curr.base_y = y;
  1251. +         }
  1252. +     }
  1253.   }
  1254.   
  1255.   #define    get_xy()
  1256.   #define    window_x 0
  1257.   #define    window_y 0
  1258. ***************
  1259. *** 500,506 ****
  1260. --- 595,629 ----
  1261.   #define    mane_base_y    mane.base_y
  1262.   #endif X10
  1263.   
  1264. + static    void
  1265. + compute_mag_pos(xp, yp)
  1266. +     int    *xp, *yp;
  1267. + {
  1268. +     register int t;
  1269. +     t = mag_x + main_x - alt.width/2;
  1270.   #ifndef X10
  1271. +     if (t > WidthOfScreen(SCRN) - alt.width - 2*MAGBORD)
  1272. +         t = WidthOfScreen(SCRN) - alt.width - 2*MAGBORD;
  1273. + #else X10
  1274. +     if (t > window_w - alt.width - 2*MAGBORD)
  1275. +         t = window_w - alt.width - 2*MAGBORD;
  1276. + #endif X10
  1277. +     if (t < 0) t = 0;
  1278. +     *xp = t;
  1279. +     t = mag_y + main_y - alt.height/2;
  1280. + #ifndef X10
  1281. +     if (t > HeightOfScreen(SCRN) - alt.height - 2*MAGBORD)
  1282. +         t = HeightOfScreen(SCRN) - alt.height - 2*MAGBORD;
  1283. + #else X10
  1284. +     if (t > window_h - alt.height - 2*MAGBORD)
  1285. +         t = window_h - alt.height - 2*MAGBORD;
  1286. + #endif X10
  1287. +     if (t < 0) t = 0;
  1288. +     *yp = t;
  1289. + }
  1290. + #ifndef X10
  1291.       /*ARGSUSED*/
  1292.   static    void
  1293.   handle_button(widget, junk, event)
  1294. ***************
  1295. *** 509,565 ****
  1296.       XButtonEvent *event;
  1297.   #else X10
  1298.   static    void
  1299. ! handle_button(event, mag_size)
  1300.       XButtonPressedEvent *event;
  1301. -     int mag_size;
  1302.   #endif X10
  1303.   {
  1304.       int x, y;
  1305.   #ifndef X10
  1306. -     int mag_size = mg_size[event->button - 1];
  1307.       XSetWindowAttributes attr;
  1308. - #endif X10
  1309.   
  1310. !     if (alt.win != NULL || mane.shrinkfactor == 1 || mag_size <= 0)
  1311.           XBell(DISP, 20);
  1312.       else {
  1313.   #ifndef X10
  1314. !         x = event->x_root - mag_size/2;
  1315. !         if (x > WidthOfScreen(SCRN) - mag_size - 2*MAGBORD)
  1316. !         x = WidthOfScreen(SCRN) - mag_size - 2*MAGBORD;
  1317. !         if (x < 0) x = 0;
  1318. !         y = event->y_root - mag_size/2;
  1319. !         if (y > HeightOfScreen(SCRN) - mag_size - 2*MAGBORD)
  1320. !         y = HeightOfScreen(SCRN) - mag_size - 2*MAGBORD;
  1321. !         if (y < 0) y = 0;
  1322. ! #else X10
  1323. !         x = event->x - mag_size/2;
  1324. !         if (x > window_w - mag_size - 2*MAGBORD)
  1325. !         x = window_w - mag_size - 2*MAGBORD;
  1326. !         if (x < 0) x = 0;
  1327. !         y = event->y - mag_size/2;
  1328. !         if (y > window_h - mag_size - 2*MAGBORD)
  1329. !         y = window_h - mag_size - 2*MAGBORD;
  1330. !         if (y < 0) y = 0;
  1331.   #endif X10
  1332.           alt.base_x = (event->x + mane_base_x) * mane.shrinkfactor -
  1333. !         mag_size/2;
  1334.           alt.base_y = (event->y + mane_base_y) * mane.shrinkfactor -
  1335. !         mag_size/2;
  1336.   #ifndef X10
  1337.           attr.save_under = True;
  1338.           attr.border_pixel = fore_args.value;
  1339.           attr.background_pixel = back_args.value;
  1340.           alt.win = XCreateWindow(DISP, RootWindowOfScreen(SCRN),
  1341. !             x, y, mag_size, mag_size, MAGBORD,
  1342.               0,    /* depth from parent */
  1343.               InputOutput, CopyFromParent,
  1344. !             CWSaveUnder|CWBorderPixel|CWBackPixel, &attr);
  1345. !         XSetTransientForHint(DISP, alt.win, XtWindow(top_level));
  1346.           XSelectInput(DISP, alt.win, ExposureMask);
  1347.   #else X10
  1348.           alt.win = XCreateWindow(mane.win,
  1349. !             x, y, mag_size, mag_size, MAGBORD,
  1350.               bdrmap, backmap);
  1351.           XSelectInput(alt.win, ExposeRegion);
  1352.   #endif X10
  1353. --- 632,676 ----
  1354.       XButtonEvent *event;
  1355.   #else X10
  1356.   static    void
  1357. ! handle_button(event)
  1358.       XButtonPressedEvent *event;
  1359.   #endif X10
  1360.   {
  1361.       int x, y;
  1362.   #ifndef X10
  1363.       XSetWindowAttributes attr;
  1364.   
  1365. !     alt.width = alt.height = mg_size[event->button - 1];
  1366. ! #endif X10
  1367. !     if (alt.win != NULL || mane.shrinkfactor == 1 || alt.width <= 0)
  1368.           XBell(DISP, 20);
  1369.       else {
  1370. +         mag_x = event->x;
  1371. +         mag_y = event->y;
  1372.   #ifndef X10
  1373. !         main_x = event->x_root - mag_x;
  1374. !         main_y = event->y_root - mag_y;
  1375.   #endif X10
  1376. +         compute_mag_pos(&x, &y);
  1377.           alt.base_x = (event->x + mane_base_x) * mane.shrinkfactor -
  1378. !         alt.width/2;
  1379.           alt.base_y = (event->y + mane_base_y) * mane.shrinkfactor -
  1380. !         alt.height/2;
  1381.   #ifndef X10
  1382.           attr.save_under = True;
  1383.           attr.border_pixel = fore_args.value;
  1384.           attr.background_pixel = back_args.value;
  1385. +         attr.override_redirect = True;
  1386.           alt.win = XCreateWindow(DISP, RootWindowOfScreen(SCRN),
  1387. !             x, y, alt.width, alt.height, MAGBORD,
  1388.               0,    /* depth from parent */
  1389.               InputOutput, CopyFromParent,
  1390. !             CWSaveUnder | CWBorderPixel | CWBackPixel |
  1391. !             CWOverrideRedirect, &attr);
  1392.           XSelectInput(DISP, alt.win, ExposureMask);
  1393.   #else X10
  1394.           alt.win = XCreateWindow(mane.win,
  1395. !             x, y, alt.width, alt.height, MAGBORD,
  1396.               bdrmap, backmap);
  1397.           XSelectInput(alt.win, ExposeRegion);
  1398.   #endif X10
  1399. ***************
  1400. *** 571,576 ****
  1401. --- 682,718 ----
  1402.   #ifndef X10
  1403.       /*ARGSUSED*/
  1404.   static    void
  1405. + handle_motion(widget, junk, event)
  1406. +     Widget    widget;
  1407. +     caddr_t    junk;
  1408. +     XMotionEvent *event;
  1409. + {
  1410. +     new_mag_x = event->x;
  1411. +     main_x = event->x_root - new_mag_x;
  1412. +     new_mag_y = event->y;
  1413. +     main_y = event->y_root - new_mag_y;
  1414. +     mag_moved = (new_mag_x != mag_x || new_mag_y != mag_y);
  1415. + }
  1416. + #endif X10
  1417. + static    void
  1418. + movemag(x, y)
  1419. +     int    x, y;
  1420. + {
  1421. +     int    xx, yy;
  1422. +     mag_x = x;
  1423. +     mag_y = y;
  1424. +     if (mag_x == new_mag_x && mag_y == new_mag_y) mag_moved = False;
  1425. +     compute_mag_pos(&xx, &yy);
  1426. +     XMoveWindow(DPY alt.win, xx, yy);
  1427. +     scrollwindow(&alt, (x + mane_base_x) * mane.shrinkfactor - alt.width/2,
  1428. +         (y + mane_base_y) * mane.shrinkfactor - alt.height/2);
  1429. + }
  1430. + #ifndef X10
  1431. +     /*ARGSUSED*/
  1432. + static    void
  1433.   handle_release(widget, junk, event)
  1434.       Widget    widget;
  1435.       caddr_t    junk;
  1436. ***************
  1437. *** 586,591 ****
  1438. --- 728,734 ----
  1439.           XDestroyWindow(DPY alt.win);
  1440.           if (curr.win == alt.win) alt_canit = True;
  1441.           alt.win = NULL;
  1442. +         mag_moved = False;
  1443.           can_exposures(&alt);
  1444.           }
  1445.   }
  1446. ***************
  1447. *** 606,617 ****
  1448.           }
  1449.           else
  1450.           alt_stat = 0;
  1451. !     if (windowrec->min_x > event->x) windowrec->min_x = event->x;
  1452. !     if (windowrec->max_x < event->x + event->width)
  1453. !         windowrec->max_x = event->x + event->width;
  1454. !     if (windowrec->min_y > event->y) windowrec->min_y = event->y;
  1455. !     if (windowrec->max_y < event->y + event->height)
  1456. !         windowrec->max_y = event->y + event->height;
  1457.   }
  1458.   #endif X10
  1459.   
  1460. --- 749,755 ----
  1461.           }
  1462.           else
  1463.           alt_stat = 0;
  1464. !     expose(windowrec, event->x, event->y, event->width, event->height);
  1465.   }
  1466.   #endif X10
  1467.   
  1468. ***************
  1469. *** 643,654 ****
  1470.            * Also, watch out, if we destroy the magnifying glass while
  1471.            * writing it.
  1472.            */
  1473. !         if (!XtPending() && (!wait || canit || mane.min_x < MAXINT ||
  1474. !             alt.min_x < MAXINT))
  1475.           if (alt_canit) longjmp(canit_env, 1);
  1476.           else return;
  1477.   #ifndef X10
  1478.           XtNextEvent(&event);
  1479.           if (event.xany.window == alt.win &&
  1480.               event.type == Expose) {
  1481.           handle_exp((Widget) NULL, &alt, &event.xexpose);
  1482. --- 781,793 ----
  1483.            * Also, watch out, if we destroy the magnifying glass while
  1484.            * writing it.
  1485.            */
  1486. !         if (!XtPending() && (!wait || canit || mane.min_x < MAXDIM ||
  1487. !             alt.min_x < MAXDIM || mag_moved))
  1488.           if (alt_canit) longjmp(canit_env, 1);
  1489.           else return;
  1490.   #ifndef X10
  1491.           XtNextEvent(&event);
  1492. +         if (resized) get_geom();
  1493.           if (event.xany.window == alt.win &&
  1494.               event.type == Expose) {
  1495.           handle_exp((Widget) NULL, &alt, &event.xexpose);
  1496. ***************
  1497. *** 667,685 ****
  1498.           switch (event.type) {
  1499.           case ExposeWindow:
  1500.           if (event.window == mane.win) {
  1501. !             window_h = ((XExposeEvent *)(&event))->height;
  1502. !             window_w = ((XExposeEvent *)(&event))->width;
  1503. !             home();
  1504. !             ch = '\f';
  1505. !             break;
  1506. !         }
  1507. !         /* otherwise control passes through */
  1508.   
  1509.           case ExposeRegion:
  1510.               /* check in case we already destroyed the window */
  1511.           if (event.window == mane.win || alt.win != NULL) {
  1512.               struct WindowRec *wr =
  1513.               (event.window == mane.win ? &mane : &alt);
  1514.               if (wr == &alt)
  1515.               if (alt_stat < 0) { /* destroy upon exposure */
  1516.                   alt_stat = 0;
  1517. --- 806,824 ----
  1518.           switch (event.type) {
  1519.           case ExposeWindow:
  1520.           if (event.window == mane.win) {
  1521. !             register Dimension old_clip_w = clip_w;
  1522.   
  1523. +             window_w = ((XExposeEvent *) &event)->width;
  1524. +             window_h = ((XExposeEvent *) &event)->height;
  1525. +             if (old_clip_w == 0) home(False);
  1526. +         }
  1527. +         /* control falls through */
  1528.           case ExposeRegion:
  1529.               /* check in case we already destroyed the window */
  1530.           if (event.window == mane.win || alt.win != NULL) {
  1531.               struct WindowRec *wr =
  1532.               (event.window == mane.win ? &mane : &alt);
  1533.               if (wr == &alt)
  1534.               if (alt_stat < 0) { /* destroy upon exposure */
  1535.                   alt_stat = 0;
  1536. ***************
  1537. *** 688,713 ****
  1538.               }
  1539.               else
  1540.                   alt_stat = 0;
  1541. ! #define    ev        ((XExposeEvent *)(&event))
  1542. !             if (wr->min_x > ev->x) wr->min_x = ev->x;
  1543. !             if (wr->max_x < ev->x + ev->width)
  1544. !             wr->max_x = ev->x + ev->width;
  1545. !             if (wr->min_y > ev->y) wr->min_y = ev->y;
  1546. !             if (wr->max_y < ev->y + ev->height)
  1547. !             wr->max_y = ev->y + ev->height;
  1548. ! #undef    ev
  1549.           }
  1550.           break;
  1551.   
  1552.           case ButtonPressed: {
  1553. !             int n = 0;
  1554. !             switch (((XButtonPressedEvent *) (&event))->detail &
  1555.                   ValueMask) {
  1556. -             case LeftButton:  n=0; break;
  1557.               case MiddleButton:  n=1; break;
  1558.               case RightButton:  n=2; break;
  1559.               }
  1560. !             handle_button((XButtonPressedEvent *) (&event), mg_size[n]);
  1561.           }
  1562.           break;
  1563.           case ButtonReleased:
  1564. --- 827,864 ----
  1565.               }
  1566.               else
  1567.                   alt_stat = 0;
  1568. !             if (((XExposeEvent *) &event)->detail & ExposeCopy)
  1569. !             ClearArea(event.window,
  1570. !                 ((XExposeEvent *) &event)->x,
  1571. !                 ((XExposeEvent *) &event)->y,
  1572. !                 ((XExposeEvent *) &event)->width,
  1573. !                 ((XExposeEvent *) &event)->height);
  1574. !             expose(wr, ((XExposeEvent *) &event)->x,
  1575. !             ((XExposeEvent *) &event)->y,
  1576. !             ((XExposeEvent *) &event)->width,
  1577. !             ((XExposeEvent *) &event)->height);
  1578.           }
  1579. +         case ExposeCopy:    /* throw away junk event */
  1580.           break;
  1581.   
  1582. +         case MouseMoved:
  1583. +         case LeftDownMotion:
  1584. +         case MiddleDownMotion:
  1585. +         case RightDownMotion:
  1586. +         new_mag_x = ((XMouseMovedEvent *) &event)->x;
  1587. +         new_mag_y = ((XMouseMovedEvent *) &event)->y;
  1588. +         mag_moved = (new_mag_x != mag_x || new_mag_y != mag_y);
  1589. +         break;
  1590.           case ButtonPressed: {
  1591. !             register int n = 0;
  1592. !             switch (((XButtonPressedEvent *) &event)->detail &
  1593.                   ValueMask) {
  1594.               case MiddleButton:  n=1; break;
  1595.               case RightButton:  n=2; break;
  1596.               }
  1597. !             alt.width = alt.height = mg_size[n];
  1598. !             handle_button((XButtonPressedEvent *) &event);
  1599.           }
  1600.           break;
  1601.           case ButtonReleased:
  1602. ***************
  1603. *** 718,723 ****
  1604. --- 869,877 ----
  1605.           if (nbytes > 1) goto bad;
  1606.           if (nbytes != 0) ch = *string;
  1607.           break;
  1608. + /*MouseMoved */
  1609. +         default:
  1610. +         Fprintf(stderr, "???:  %x\n", event.type);
  1611.           }
  1612.   #endif X10
  1613.           if (ch == '\0') continue;
  1614. ***************
  1615. *** 771,791 ****
  1616.               /* redisplay current page */
  1617.               break;
  1618.           case '^':
  1619. !             home();
  1620. !             break;
  1621. ! #ifndef X10
  1622. !         case 'u':
  1623. !             if (!scroll(False, -0.67)) goto bad;
  1624.               continue;
  1625. !         case 'd':
  1626. !             if (!scroll(False, 0.67)) goto bad;
  1627. !             continue;
  1628.           case 'l':
  1629. !             if (!scroll(True, -0.67)) goto bad;
  1630.               continue;
  1631.           case 'r':
  1632. !             if (!scroll(True, 0.67)) goto bad;
  1633.               continue;
  1634.           case 'c':
  1635.               center(event.xkey.x, event.xkey.y);
  1636.               continue;
  1637. --- 925,953 ----
  1638.               /* redisplay current page */
  1639.               break;
  1640.           case '^':
  1641. !             home(True);
  1642.               continue;
  1643. ! #ifndef X10
  1644.           case 'l':
  1645. !             if (!x_bar) goto bad;
  1646. !             XtCallCallbacks(x_bar, XtNscrollProc,
  1647. !             -2 * (int) clip_w / 3);
  1648.               continue;
  1649.           case 'r':
  1650. !             if (!x_bar) goto bad;
  1651. !             XtCallCallbacks(x_bar, XtNscrollProc,
  1652. !             2 * (int) clip_w / 3);
  1653.               continue;
  1654. +         case 'u':
  1655. +             if (!y_bar) goto bad;
  1656. +             XtCallCallbacks(y_bar, XtNscrollProc,
  1657. +             -2 * (int) clip_h / 3);
  1658. +             continue;
  1659. +         case 'd':
  1660. +             if (!y_bar) goto bad;
  1661. +             XtCallCallbacks(y_bar, XtNscrollProc,
  1662. +             2 * (int) clip_h / 3);
  1663. +             continue;
  1664.           case 'c':
  1665.               center(event.xkey.x, event.xkey.y);
  1666.               continue;
  1667. ***************
  1668. *** 802,837 ****
  1669.               ImageByteOrder(DISP));
  1670.               continue;
  1671.   #else X10
  1672. -         case 'u':
  1673. -             if (mane.base_y == 0) goto bad;
  1674. -             mane.base_y -= window_h;
  1675. -             if (mane.base_y < 0)
  1676. -             mane.base_y = 0;
  1677. -             break;
  1678. -         case 'd':
  1679. -             if (mane.base_y >= page_h - window_h) goto bad;
  1680. -             mane.base_y += window_h;
  1681. -             if (mane.base_y > page_h - window_h)
  1682. -             mane.base_y = page_h - window_h;
  1683. -             break;
  1684.           case 'l':
  1685.               if (mane.base_x == 0) goto bad;
  1686. !             mane.base_x -= window_w;
  1687. !             if (mane.base_x < 0)
  1688. !             mane.base_x = 0;
  1689. !             break;
  1690.           case 'r':
  1691. !             if (mane.base_x >= page_w - window_w) goto bad;
  1692. !             mane.base_x += window_w;
  1693. !             if (mane.base_x > page_w - window_w)
  1694. !             mane.base_x = page_w - window_w;
  1695. !             break;
  1696.           case 'c':
  1697. ! #define    ev        ((XKeyPressedEvent *) (&event))
  1698. !             mane.base_x += ev->x - window_w/2;
  1699. !             mane.base_y += ev->y - window_h/2;
  1700.               XWarpMouse(mane.win, window_w/2, window_h/2, 3);
  1701. !             break;
  1702.           case 'M':
  1703.               home_x = (ev->x + mane.base_x) * mane.shrinkfactor;
  1704.               home_y = (ev->y + mane.base_y) * mane.shrinkfactor;
  1705. --- 964,999 ----
  1706.               ImageByteOrder(DISP));
  1707.               continue;
  1708.   #else X10
  1709.           case 'l':
  1710.               if (mane.base_x == 0) goto bad;
  1711. !             number0 = mane.base_x - 2 * clip_w / 3;
  1712. !             if (number0 < 0) number0 = 0;
  1713. !             scrollwindow(&mane, number0, mane.base_y);
  1714. !             continue;
  1715.           case 'r':
  1716. !             number0 = mane.base_x + 2 * clip_w / 3;
  1717. !             if (number0 > page_w - clip_w) number0 = page_w - clip_w;
  1718. !             if (number0 == mane.base_x) goto bad;
  1719. !             scrollwindow(&mane, number0, mane.base_y);
  1720. !             continue;
  1721. !         case 'u':
  1722. !             if (mane.base_y == 0) goto bad;
  1723. !             number0 = mane.base_y - 2 * clip_h / 3;
  1724. !             if (number0 < 0) number0 = 0;
  1725. !             scrollwindow(&mane, mane.base_x, number0);
  1726. !             continue;
  1727. !         case 'd':
  1728. !             number0 = mane.base_y + 2 * clip_h / 3;
  1729. !             if (number0 > page_h - clip_h) number0 = page_h - clip_h;
  1730. !             if (number0 == mane.base_y) goto bad;
  1731. !             scrollwindow(&mane, mane.base_x, number0);
  1732. !             continue;
  1733.           case 'c':
  1734. ! #define    ev        ((XKeyPressedEvent *) &event)
  1735. !             scrollwindow(&mane, mane.base_x + ev->x - window_w/2,
  1736. !             mane.base_y + ev->y - window_h/2);
  1737.               XWarpMouse(mane.win, window_w/2, window_h/2, 3);
  1738. !             continue;
  1739.           case 'M':
  1740.               home_x = (ev->x + mane.base_x) * mane.shrinkfactor;
  1741.               home_y = (ev->y + mane.base_y) * mane.shrinkfactor;
  1742. ***************
  1743. *** 842,848 ****
  1744.               if (!arg0) {
  1745.               long fac1, fac2;
  1746.               shrink_factor = 1;
  1747. -             get_wh(vport_widget);
  1748.               fac1 = ROUNDUP(PAPER_WIDTH, window_w);
  1749.               fac2 = ROUNDUP(PAPER_HEIGHT, window_h);
  1750.               if (fac1 < fac2)
  1751. --- 1004,1009 ----
  1752. ***************
  1753. *** 853,859 ****
  1754.               if (number0 <= 0) goto bad;
  1755.               if (number0 == mane.shrinkfactor) continue;
  1756.               shrink_factor = mane.shrinkfactor = number0;
  1757. -             unmap();
  1758.               init_page();
  1759.               if (number0 != 1 && number0 != bak_shrink) {
  1760.               bak_shrink = number0;
  1761. --- 1014,1019 ----
  1762. ***************
  1763. *** 860,870 ****
  1764.               reset_fonts();
  1765.               }
  1766.   #ifndef X10
  1767.               set_draw_args();
  1768.               XtSetValues(draw_widget, draw_args, 2);
  1769. ! #endif X10
  1770. !             home();
  1771.               break;
  1772.           case 'S':
  1773.               if (!arg0) goto bad;
  1774.               if (number0 < 0) goto bad;
  1775. --- 1020,1036 ----
  1776.               reset_fonts();
  1777.               }
  1778.   #ifndef X10
  1779. +             XUnmapWindow(DISP, mane.win);
  1780.               set_draw_args();
  1781.               XtSetValues(draw_widget, draw_args, 2);
  1782. !             get_geom();
  1783. !             home(False);
  1784. !             XMapWindow(DISP, mane.win);
  1785. !             continue;
  1786. ! #else X10
  1787. !             home(False);
  1788.               break;
  1789. + #endif X10
  1790.           case 'S':
  1791.               if (!arg0) goto bad;
  1792.               if (number0 < 0) goto bad;
  1793. ***************
  1794. *** 872,878 ****
  1795.               density = number0;
  1796.               reset_fonts();
  1797.               if (mane.shrinkfactor == 1) continue;
  1798. -             unmap();
  1799.               break;
  1800.           case 'R':
  1801.               /* reread DVI file */
  1802. --- 1038,1043 ----
  1803. ***************
  1804. *** 885,891 ****
  1805.           if (current_page != next_page) {
  1806.               current_page = next_page;
  1807.               spec_warn = True;
  1808. !             home();
  1809.           }
  1810.           canit = True;
  1811.           Flush();
  1812. --- 1050,1056 ----
  1813.           if (current_page != next_page) {
  1814.               current_page = next_page;
  1815.               spec_warn = True;
  1816. !             home(False);
  1817.           }
  1818.           canit = True;
  1819.           Flush();
  1820. ***************
  1821. *** 916,922 ****
  1822.           max_y - min_y, min_x, min_y, curr.base_x, curr.base_y);
  1823.       SetCursor(redraw_cursor);
  1824.       if (errtext = (char *) setjmp(dvi_env)) {
  1825. !         ClearPage();
  1826.   #ifndef X10
  1827.           get_xy();
  1828.           XDrawString(DISP, mane.win, foreGC,
  1829. --- 1081,1087 ----
  1830.           max_y - min_y, min_x, min_y, curr.base_x, curr.base_y);
  1831.       SetCursor(redraw_cursor);
  1832.       if (errtext = (char *) setjmp(dvi_env)) {
  1833. !         ClearPage(mane);
  1834.   #ifndef X10
  1835.           get_xy();
  1836.           XDrawString(DISP, mane.win, foreGC,
  1837. ***************
  1838. *** 941,953 ****
  1839.   redraw_page()
  1840.   {
  1841.       if (debug & DBG_EVENT) fputs("Redraw page:  ", stdout);
  1842. -     get_wh(clip_widget);
  1843.       get_xy();
  1844. !     ClearPage();
  1845.       mane.min_x = -window_x;
  1846. !     mane.max_x = -window_x + window_w;
  1847.       mane.min_y = -window_y;
  1848. !     mane.max_y = -window_y + window_h;
  1849.       redraw(&mane);
  1850.   }
  1851.   
  1852. --- 1106,1117 ----
  1853.   redraw_page()
  1854.   {
  1855.       if (debug & DBG_EVENT) fputs("Redraw page:  ", stdout);
  1856.       get_xy();
  1857. !     ClearPage(mane);
  1858.       mane.min_x = -window_x;
  1859. !     mane.max_x = -window_x + clip_w;
  1860.       mane.min_y = -window_y;
  1861. !     mane.max_y = -window_y + clip_h;
  1862.       redraw(&mane);
  1863.   }
  1864.   
  1865. ***************
  1866. *** 975,981 ****
  1867.   can_exposures(windowrec)
  1868.       struct WindowRec *windowrec;
  1869.   {
  1870. !     windowrec->min_x = windowrec->min_y = MAXINT;
  1871.       windowrec->max_x = windowrec->max_y = 0;
  1872.   }
  1873.   
  1874. --- 1139,1145 ----
  1875.   can_exposures(windowrec)
  1876.       struct WindowRec *windowrec;
  1877.   {
  1878. !     windowrec->min_x = windowrec->min_y = MAXDIM;
  1879.       windowrec->max_x = windowrec->max_y = 0;
  1880.   }
  1881.   
  1882. ***************
  1883. *** 1005,1013 ****
  1884.   {
  1885.       if (debug & DBG_BATCH) {
  1886.   #ifndef X10
  1887. !         while (mane.min_x == MAXINT) read_events(True);
  1888.   #else X10
  1889. !         while (mane.min_x == MAXINT)
  1890.           if (setjmp(canit_env)) break;
  1891.           else read_events(True);
  1892.   #endif X10
  1893. --- 1169,1177 ----
  1894.   {
  1895.       if (debug & DBG_BATCH) {
  1896.   #ifndef X10
  1897. !         while (mane.min_x == MAXDIM) read_events(True);
  1898.   #else X10
  1899. !         while (mane.min_x == MAXDIM)
  1900.           if (setjmp(canit_env)) break;
  1901.           else read_events(True);
  1902.   #endif X10
  1903. ***************
  1904. *** 1025,1042 ****
  1905.               canit = False;
  1906.               can_exposures(&mane);
  1907.               can_exposures(&alt);
  1908. ! #ifndef X10
  1909. !             if (unmapped) {
  1910. !                 /* this creates a redraw event */
  1911. !             XMapWindow(DISP, mane.win);
  1912. !             unmapped = False;
  1913. !             }
  1914. !             else
  1915. ! #endif
  1916. !             redraw_page();
  1917.           }
  1918. !         else if (alt.min_x < MAXINT) redraw(&alt);
  1919. !         else if (mane.min_x < MAXINT) redraw(&mane);
  1920.           Flush();
  1921.           }
  1922.       }
  1923. --- 1189,1208 ----
  1924.               canit = False;
  1925.               can_exposures(&mane);
  1926.               can_exposures(&alt);
  1927. !             redraw_page();
  1928.           }
  1929. !         else if (mag_moved) {
  1930. !             if (alt.win == NULL) mag_moved = False;
  1931. !             else if (abs(new_mag_x - mag_x) >
  1932. !             2 * abs(new_mag_y - mag_y))
  1933. !                 movemag(new_mag_x, mag_y);
  1934. !             else if (abs(new_mag_y - mag_y) >
  1935. !             2 * abs(new_mag_x - mag_x))
  1936. !                 movemag(mag_x, new_mag_y);
  1937. !             else movemag(new_mag_x, new_mag_y);
  1938. !         }
  1939. !         else if (alt.min_x < MAXDIM) redraw(&alt);
  1940. !         else if (mane.min_x < MAXDIM) redraw(&mane);
  1941.           Flush();
  1942.           }
  1943.       }
  1944. ***************
  1945. *** 1249,1269 ****
  1946.           top_level, vport_args, XtNumber(vport_args));
  1947.       clip_widget = XtNameToWidget(vport_widget, "clip");
  1948.       set_draw_args();
  1949. !     draw_widget = XtCreateManagedWidget("drawing", simpleWidgetClass,
  1950.           vport_widget, draw_args, XtNumber(draw_args));
  1951. !     XtAddEventHandler(vport_widget, KeyPressMask, 0, handle_key,
  1952.           (caddr_t) NULL);
  1953. !     XtAddEventHandler(draw_widget, ExposureMask, GraphicsExpose, handle_exp,
  1954.           (caddr_t) &mane);
  1955. !     XtAddEventHandler(draw_widget, ButtonPressMask, 0, handle_button,
  1956.           (caddr_t) NULL);
  1957. !     XtAddEventHandler(draw_widget, ButtonReleaseMask, 0, handle_release,
  1958.           (caddr_t) NULL);
  1959.       XtRealizeWidget(top_level);
  1960.       curr.win = mane.win = XtWindow(draw_widget);
  1961. -     /* unmapped = True;    (it was initialized this way) */
  1962. -     home();            /* no need to unmap at this stage */
  1963. -     unmapped = False;
  1964.   
  1965.       if (reverse) {
  1966.           if (!fore_color) fore_args.value = WhitePixelOfScreen(SCRN);
  1967. --- 1415,1436 ----
  1968.           top_level, vport_args, XtNumber(vport_args));
  1969.       clip_widget = XtNameToWidget(vport_widget, "clip");
  1970.       set_draw_args();
  1971. !     draw_widget = XtCreateManagedWidget("drawing", widgetClass,
  1972.           vport_widget, draw_args, XtNumber(draw_args));
  1973. !     XtAddEventHandler(vport_widget, KeyPressMask, False, handle_key,
  1974.           (caddr_t) NULL);
  1975. !     XtAddEventHandler(vport_widget, StructureNotifyMask, False,
  1976. !         handle_resize, (caddr_t) NULL);
  1977. !     XtAddEventHandler(draw_widget, ExposureMask, False, handle_exp,
  1978.           (caddr_t) &mane);
  1979. !     XtAddEventHandler(draw_widget, ButtonPressMask, False, handle_button,
  1980.           (caddr_t) NULL);
  1981. !     XtAddEventHandler(draw_widget, ButtonMotionMask, False, handle_motion,
  1982.           (caddr_t) NULL);
  1983. +     XtAddEventHandler(draw_widget, ButtonReleaseMask, False, handle_release,
  1984. +         (caddr_t) NULL);
  1985.       XtRealizeWidget(top_level);
  1986.       curr.win = mane.win = XtWindow(draw_widget);
  1987.   
  1988.       if (reverse) {
  1989.           if (!fore_color) fore_args.value = WhitePixelOfScreen(SCRN);
  1990. ***************
  1991. *** 1311,1317 ****
  1992.           cr_Pixel = high_color ? hl_Pixel : fore_args.value;
  1993.       {
  1994.           XColor bg_Color, cr_Color;
  1995. !         
  1996.           bg_Color.pixel = back_args.value;
  1997.           XQueryColor(DISP, DefaultColormapOfScreen(SCRN), &bg_Color);
  1998.           cr_Color.pixel = cr_Pixel;
  1999. --- 1478,1484 ----
  2000.           cr_Pixel = high_color ? hl_Pixel : fore_args.value;
  2001.       {
  2002.           XColor bg_Color, cr_Color;
  2003.           bg_Color.pixel = back_args.value;
  2004.           XQueryColor(DISP, DefaultColormapOfScreen(SCRN), &bg_Color);
  2005.           cr_Color.pixel = cr_Pixel;
  2006. ***************
  2007. *** 1550,1560 ****
  2008.       Sprintf(def, "=%dx%d+0+0", frame.width, frame.height);
  2009.       mane.win = XCreate("DVI Previewer", prog, geometry, def,
  2010.           &frame, 50, 50);
  2011. -     window_w = frame.width;
  2012. -     window_h = frame.height;
  2013.       XSelectInput(mane.win,
  2014.           KeyPressed|ButtonPressed|ButtonReleased|
  2015. !         ExposeWindow|ExposeRegion);
  2016.       XMapWindow(mane.win);
  2017.       XDefineCursor(mane.win,
  2018.           XCreateCursor(xdvi_width, xdvi_height, xdvi_bits, xdvi_mask_bits,
  2019. --- 1717,1726 ----
  2020.       Sprintf(def, "=%dx%d+0+0", frame.width, frame.height);
  2021.       mane.win = XCreate("DVI Previewer", prog, geometry, def,
  2022.           &frame, 50, 50);
  2023.       XSelectInput(mane.win,
  2024.           KeyPressed|ButtonPressed|ButtonReleased|
  2025. !         ExposeWindow|ExposeRegion|ExposeCopy|
  2026. !         LeftDownMotion|MiddleDownMotion|RightDownMotion);
  2027.       XMapWindow(mane.win);
  2028.       XDefineCursor(mane.win,
  2029.           XCreateCursor(xdvi_width, xdvi_height, xdvi_bits, xdvi_mask_bits,
  2030. diff -cr old/xdvi.h new/xdvi.h
  2031. *** old/xdvi.h    Thu Jul 13 12:52:45 1989
  2032. --- new/xdvi.h    Sat Jul  8 15:05:11 1989
  2033. ***************
  2034. *** 34,40 ****
  2035.   #define    True    1
  2036.   #define    False    0
  2037.   
  2038. ! #define    MAXINT        32767
  2039.   
  2040.   #define    pixel_conv(x)    ((int) (((x) / shrink_factor) >> 16))
  2041.   #define    pixel_round(x)    ((int) (((x) / shrink_factor + (1<<15)) >> 16))
  2042. --- 34,40 ----
  2043.   #define    True    1
  2044.   #define    False    0
  2045.   
  2046. ! #define    MAXDIM        32767
  2047.   
  2048.   #define    pixel_conv(x)    ((int) (((x) / shrink_factor) >> 16))
  2049.   #define    pixel_round(x)    ((int) (((x) / shrink_factor + (1<<15)) >> 16))
  2050. ***************
  2051. *** 123,132 ****
  2052.       char *bits;        /* pointer to the bits */
  2053.   };
  2054.   
  2055. - #ifndef    MAXCHARS
  2056. - #define    MAXCHARS    128    /* make 256 for 8 bit characters */
  2057. - #endif    MAXCHARS
  2058.   /*
  2059.    * Per-character information.
  2060.    * There is one of these for each character in a font.
  2061. --- 123,128 ----
  2062. ***************
  2063. *** 173,183 ****
  2064.       short size;            /* dots per 5 inches */
  2065.       FILE *file;            /* open PXL file or NULL */
  2066.       char *filename;            /* name of PXL file */
  2067.       read_char_proc read_char;    /* function to read bitmap */
  2068. !     struct glyph glyph[MAXCHARS];
  2069.   };
  2070.   
  2071.   extern    struct font    *current_font;
  2072.   
  2073.   /*
  2074.    * Command line flags.
  2075. --- 169,181 ----
  2076.       short size;            /* dots per 5 inches */
  2077.       FILE *file;            /* open PXL file or NULL */
  2078.       char *filename;            /* name of PXL file */
  2079. +     ubyte maxchar;            /* largest character code */
  2080.       read_char_proc read_char;    /* function to read bitmap */
  2081. !     struct glyph glyph[256];
  2082.   };
  2083.   
  2084.   extern    struct font    *current_font;
  2085. + extern    ubyte    maxchar;
  2086.   
  2087.   /*
  2088.    * Command line flags.
  2089. ***************
  2090. *** 205,210 ****
  2091. --- 203,209 ----
  2092.       long    win;        /* type Window is not defined yet */
  2093.       int    shrinkfactor;
  2094.       int    base_x, base_y;
  2095. +     int    width, height;
  2096.       int    min_x, max_x, min_y, max_y;    /* for pending expose events */
  2097.   } mane, alt, curr;
  2098.   
  2099. diff -cr old/xdvi.man.sed new/xdvi.man.sed
  2100. *** old/xdvi.man.sed    Thu Jul 13 12:52:49 1989
  2101. --- new/xdvi.man.sed    Mon Jul 10 13:51:21 1989
  2102. ***************
  2103. *** 44,50 ****
  2104.   .TP
  2105.   .BI \-s " shrink"
  2106.   (.shrinkFactor)
  2107. ! Defines the initial shrink factor.  The default value is 4.
  2108.   .TP
  2109.   .BI \-S " density"
  2110.   (.densityPercent)
  2111. --- 44,50 ----
  2112.   .TP
  2113.   .BI \-s " shrink"
  2114.   (.shrinkFactor)
  2115. ! Defines the initial shrink factor.  The default value is 3.
  2116.   .TP
  2117.   .BI \-S " density"
  2118.   (.densityPercent)
  2119. diff -cr old/xdvi10.man.s new/xdvi10.man.s
  2120. *** old/xdvi10.man.s    Thu Jul 13 12:52:51 1989
  2121. --- new/xdvi10.man.s    Mon Jul 10 13:47:37 1989
  2122. ***************
  2123. *** 44,50 ****
  2124.   .TP
  2125.   .BI \-s " shrink"
  2126.   (shrinkFactor)
  2127. ! Defines the initial shrink factor.  The default value is 4.
  2128.   .TP
  2129.   .BI \-S " density"
  2130.   (densityPercent)
  2131. --- 44,50 ----
  2132.   .TP
  2133.   .BI \-s " shrink"
  2134.   (shrinkFactor)
  2135. ! Defines the initial shrink factor.  The default value is 3.
  2136.   .TP
  2137.   .BI \-S " density"
  2138.   (densityPercent)
  2139.