home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / DVI_MGR / dvimgr_s.lzh / dvimgr / dvimgr.c < prev    next >
Text File  |  1993-08-06  |  34KB  |  1,082 lines

  1. /************************************************************************/
  2. /* Filename: DVIMGR.C                                */
  3. /* Function: Program to view TeX DVI ouput file in a MGR-Windows Envir-    */
  4. /*         onment under OS-9/68k.                    */
  5. /*                                    */
  6. /* This version is based on the DEC-Windows version from:        */
  7. /*----------------------------------------------------------------------*/
  8. /* (c) 1990 by Christian MARKUS, Fachbereich Informatik,        */
  9. /*             Schlueterstr. 70, D 2000 Hamburg 13, Fed.Rep.of Germany    */
  10. /*                                    */
  11. /* EMAIL   : via   friesland@rz.informatik.uni-hamburg.dbp.de        */
  12. /*----------------------------------------------------------------------*/
  13. /*                                    */
  14. /* Adapted to OS-9/68k and the MGR window environment:            */
  15. /* (c) 1993 by                                                          */
  16. /*-----------------------------+----------------------------------------*/
  17. /* Lars-Christian Schulze      | Institute for Communications Technology*/
  18. /*                             |               at the             */
  19. /* Internet:  (preferred)      |     Braunschweig Technical University    */
  20. /* schulze@ifn.ing.tu-bs.de    |                     */
  21. /*                             | Schleinitzstr. 23            */
  22. /* I7100401@dbstu1.rz.tu-bs.de | 38092 Braunschweig            */
  23. /* Voice:   +49 531 391 2455   | Germany                */
  24. /*-----------------------------+----------------------------------------*/
  25. /*                                    */
  26. /* Program History:                            */
  27. /*                                    */
  28. /* Ver#: ! Date:  !Comment:                !Author:        */
  29. /* ------+--------+-------------------------------------+-------------- */
  30. /* 1.0   !04.07.89!First version            !Ch. Markus    */
  31. /* 1.1   !09.03.90!Corrected and updated        !Ch. Markus    */ 
  32. /*          !- get/set bit/byte order correctly    !        */
  33. /*          !- one window/automatically adjusted  !        */
  34. /*          !- window size can be changed        !        */
  35. /*          !- Scrollbars available        !        */
  36. /*          !- Title contains info        !        */
  37. /*           !- Copy to Clipboard            !        */
  38. /* 1.2   !19.06.90!- adaption for ANSI-C/VAX-C 3.1    !Ch. Markus    */
  39. /*----------------------------------------------------------------------*/
  40. /* Program description:                            */
  41. /*                                    */
  42. /* This driver works in a DECWindows environment and is based on TEX    */
  43. /* DVI-driver family developed by N.Beebe, Utah, USA. The include files    */
  44. /* are taken from version 2.10, the driver DVIDECW is based on the    */
  45. /* DVIBIT driver. Instead of using download fonts it creates a bitmap     */
  46. /* (similar to DVIJET) and displays it in the output window upon a    */
  47. /* window exposure event. Upon each interactive command, the bitmap is    */
  48. /* created again.                            */
  49. /*----------------------------------------------------------------------*/
  50. /* Installation guide:                            */
  51. /*                                     */
  52. /* - modify the TEXVIEW.COM file to suit your system's paths        */
  53. /* - in FileView, select the Customize/Verbs and Menus option        */
  54. /* - enter a new verb name 'TeX Preview' below the verb names box and    */
  55. /*   click on enter button upon completition                */
  56. /* - enter the DCL command for the 'Tex Preview' verb, that is entering    */
  57. /*   somewhat like @<path>texview.com and clicking on the 'enter' button*/
  58. /* - select a menu from the 'Menu Names' box and click on the 'Add'    */
  59. /*   button below the 'Verbs in Menu' list box.                */
  60. /* - press 'Apply' and 'Ok' button to install new item in menu bar    */
  61. /* - select the Customize/File Types option and install the .DVI file    */
  62. /*   type.                                */
  63. /*----------------------------------------------------------------------*/
  64. /* Quick guide to operations:                        */
  65. /*                                     */
  66. /* Invoke DVIDecw in four different ways:                */
  67. /* - from a DECTerm terminal window                     */
  68. /*   -> just type the command,options and filename to be processed    */
  69. /* - from the FileView DCL Command window                */
  70. /*   -> just type the command,options and filename to be processed    */
  71. /* - by selecting a FileView menu item (if TEXVIEW.COM is installed)    */
  72. /*   -> a dialog box pops up asking for a filename, a second box will    */
  73. /*      ask for any processing parameters                */
  74. /* - by double-clicking on any .DVI file (if TEXVIEW.COM is installed    */
  75. /*   and the File Types box is set for .DVI files            */
  76. /*   -> a dialog box pops up asking for processing parameters        */
  77. /*                                                                      */
  78. /* All options of DVIBIT are accepted, but the -o option (order pages)    */
  79. /* is ignored, DVIDecw will only pick the first selected page        */
  80. /* The program will create a command and an output window and display    */
  81. /* the first selected page.                                             */
  82. /* All interactive commands can be selected from menus and should be     */
  83. /* easy to understand.                             */
  84. /* If the TeX Preview window has the 'Input focus' key equivalents    */
  85. /* provide a shortcut for some menu commands. To set the input focus,    */
  86. /* just click into the Tex Preview window, the window title will change    */
  87. /* to the highlight color.                        */
  88. /*----------------------------------------------------------------------*/
  89. /* The following files taken from the original BEEBE driver have been    */
  90. /* modified (using #if compiler switches) for DECWINDOWS:        */
  91. /*                                    */
  92. /* DISPCHAR.H -> make up for reversed Y-coordinate origin        */
  93. /* DVIFILE.H  -> change program structure to event-driven calls        */  
  94. /* FATAL.H    -> don't perform resetterm() function in DECW environment    */ 
  95. /* GBLPROCS.H -> modifications to conform with ANSI-C (Vax C 3.1)    */
  96. /* MACHDEFS.H -> changed FONTPATH, FONTLIST and DVIHELP for OS_VMS         */
  97. /* OPENFONT.H -> allow open files according to MAXOPEN,quota and avail.    */
  98. /* PRTPAGE.H  -> changes in EOP case and keyboard status request    */ 
  99. /* SETCHAR.H  -> make up for reversed Y-coordinate origin        */
  100. /* SETRULE.H  -> make up for reversed Y-coordinate origin        */
  101. /*----------------------------------------------------------------------*/
  102. /* The DVIDecw package contains the files listed below:            */
  103. /*                                     */
  104. /* DVIDOC_D.DVI Installation/User's Guide in GERMAN            */
  105. /* DVIDOC_E.DVI Installation/User's Guide in ENGLISH            */
  106. /* DVIDECW.C    Main C source code, all DECWindows specific coding    */
  107. /* DVIDECW.UIL    User Interface description file                */
  108. /* DVIDECW.COM  Compile,UIL and link command procedure            */
  109. /* DVILINK.COM  Link DVIDECW for other VMS versions            */
  110. /* TEXVIEW.COM    Command procedure for FileView invocation of DVIDECW    */
  111. /* xxxxxxx.H    Include files (listed above) modified for DVIDECW    */
  112. /************************************************************************/
  113.  
  114. #include <stdio.h>                      /* Standard definitions        */
  115.  
  116. /************************************************************************/
  117. /* MGR definitions                            */
  118. /************************************************************************/
  119.  
  120. #include "/h0/mgr/defs/term.h"
  121. #include "/h0/mgr/defs/window.h"
  122.  
  123. char  *_FGETS(char *, int, FILE *);
  124.  
  125. #undef BLACK
  126. #undef WHITE
  127.  
  128.  
  129. #define APP_ID            "TeX Preview"  /* Application name    */
  130. #define    CLPBRD_FORMAT        "XYBitmap" /* Clipboard data format    */
  131.  
  132. /*----------------------------------------------------------------------*/
  133. /* Constants for different actions.                    */
  134. /*----------------------------------------------------------------------*/
  135.  
  136. #define k_top_margin        'a'
  137. #define    k_backward        'b'
  138. #define k_curs_down_me        'd'
  139. #define k_reload_fonts        'e'
  140. #define    k_forward        'f'
  141. #define    k_gotopage_me        'g'
  142. #define k_auto_reshape          'h'
  143. #define k_curs_left_me        'l'
  144. #define    k_left_margin        'm'
  145. #define    k_nextpage_me        'n'
  146. #define k_bot_page_me           'o'
  147. #define    k_prevpage_me        'p'
  148. #define k_curs_right_me        'r'
  149. #define k_top_page_me            't'
  150. #define k_curs_up_me        'u'
  151. #define k_redraw        'w'
  152. #define    k_quit_me        'x'
  153. #define k_reset_pos_me        'y'
  154. #define k_SHAPEREQ              'H'
  155. #define k_DESTROY        'Y'
  156. #define k_zoom_in_me        '+'
  157. #define k_zoom_out_me        '-'
  158. #define k_move_speed_x        '('
  159. #define k_move_speed_y        ')'
  160. #define k_zoom0                 '0'
  161. #define k_zoom1                 '1'
  162. #define k_zoom2                 '2'
  163. #define k_zoom3                 '3'
  164. #define k_zoom4                 '4'
  165. #define k_zoom5                 '5'
  166.                                         
  167. /*----------------------------------------------------------------------*/
  168. /* Global data declarations                        */
  169. /*----------------------------------------------------------------------*/
  170.  
  171. static int      x_windsize;        /* Window workarea size in pixel*/
  172. static int      y_windsize;
  173.  
  174. static int    xwindow,        /* Top left corner coordinates of */
  175.         ywindow;        /* displayed part of TeX page.      */
  176.                 /* Always equal to xscreen and yscreen.   */
  177.  
  178. static int    x_pagesize;        /* Virtual page size in pixel    */
  179. static int    y_pagesize;
  180.  
  181. static int    x_maxwsize = 850,    /* Max. window size.    */
  182.         y_maxwsize = 650,
  183.         x_mag0wins = -1,    /* Max. window for magstep0. */
  184.         y_mag0wins = -1;
  185.  
  186. static int      auto_reshape = 1;       /* do automatic reshape when 
  187.                                            changing magnification.      */
  188.  
  189. static int     x_step_size =  5;    /* current step width for moves    */
  190. static int     y_step_size = 90;    /* in % of window size.        */
  191.  
  192. static int    TeX_win;        /* Output window alternate ID.  */
  193. static int      base_mag,        /* Base magnification for zooming */
  194.         run_magstep = 0;        /* Runtime magstep.        */
  195.  
  196.  
  197. struct menu_entry zoom_menu[] = {
  198.     "magstep 0",        "\1770\n",
  199.     "magstep 1",        "\1771\n",
  200.     "magstep 2",        "\1772\n",
  201.     "magstep 3",        "\1773\n",
  202.     "magstep 4",        "\1774\n",
  203.     "magstep 5",        "\1775\n"
  204. };
  205.  
  206. struct menu_entry stepsize_menu[] = {
  207.     "  5 % ",        "5\n",
  208.     " 10 % ",        "10\n",
  209.     " 15 % ",        "15\n",
  210.     " 20 % ",        "20\n",
  211.     " 30 % ",        "30\n",
  212.     " 50 % ",        "50\n",
  213.     " 75 % ",        "75\n",
  214.     " 90 % ",        "90\n",
  215.     "100 % ",        "100\n"
  216. };
  217.  
  218. struct menu_entry step_menu[] = {
  219.     "step down",        "\177d\n",
  220.     "step up",        "\177u\n",
  221.     "step right",        "\177r\n",
  222.     "step left",        "\177l\n",
  223.     "x stepsize   >>> ",    "\177(",
  224.     "y stepsize   >>> ",    "\177)"
  225. };
  226.  
  227. struct menu_entry main_menu[] = {
  228.     "forward",        "\177f\n",
  229.     "backward",        "\177b\n",
  230.     "next page",        "\177n\n",
  231.     "prev page",        "\177p\n",
  232.     "go to page   ... ",    "\177g\n",
  233.     "steps        >>> ",    "",
  234.     "-----------------",    "",
  235.     "zoom in",        "\177+\n",
  236.     "zoom out",        "\177-\n",
  237.     "set zoom     >>> ",    "",
  238.     "redraw",        "\177w\n",
  239.     "auto reshape",         "\177h\n",
  240.     "-----------------",    "",
  241.     "top of page",        "\177t\n",
  242.     "bottom of page ",    "\177o\n",
  243.     "top left of page",    "\177y\n",
  244.     "-----------------",    "",
  245.     "tgl. top margin",    "\177a\n",
  246.     "tgl. left margin",    "\177m\n",
  247.     "reload fonts",        "\177e\n",
  248.     "-----------------",    "",
  249.     "exit",            "\177x\n"
  250. };
  251.  
  252.  
  253. /*----------------------------------------------------------------------*/
  254. /* forward declaration of some routines.                */
  255. /*----------------------------------------------------------------------*/
  256.  
  257. static void prtbmap(void);
  258. static void w_print(int line,char *string);
  259. static void clrbmap(void);
  260. static void redraw(void);
  261. static void mgr_main_loop( void);
  262. static void read_dvimgrinit(int *, int *, int *, int*, int*);
  263. void calculate_windsize( void);
  264. void get_windowdata( struct window_data *pwd, int winid);
  265.  
  266.  
  267. /************************************************************************/
  268. /* DVI-BEEBE driver definitions                        */
  269. /************************************************************************/
  270.  
  271. #include <dvihead.h>
  272.  
  273. /*----------------------------------------------------------------------*/
  274. /* Device specific definitions                        */
  275. /*----------------------------------------------------------------------*/  
  276.  
  277. #define DECWINDOWS    1        /* cond. compilations flag    */
  278. #define BBNBITGRAPH    1        /* BITGRAPH driver as base    */
  279. #define OSK_MGR
  280.  
  281. #define VERSION_NO    "2.10, (MGR/OSK Version 1.00)"
  282.                                         /*DVI driver version number*/
  283. #define DEVICE_ID    "DVI MGR 69 dpi"
  284.                     /* String printed at runtime    */ 
  285. #define OUTFILE_EXT    "OSK"        /* Not used here (dummy)    */
  286. #define BYTE_SIZE    8            /* Not used here (dummy)    */
  287.  
  288. /*----------------------------------------------------------------------*/
  289. /* These constants are special to DVIBIT and are not req. by DVIDECW    */
  290. /*----------------------------------------------------------------------*/  
  291.  
  292. #define    FIRSTBGCHAR    32
  293. #define LASTBGCHAR    127
  294. #define NBGFONTS    3
  295.  
  296. /*----------------------------------------------------------------------*/
  297. /* Page dimension definition                        */
  298. /* Bitmap window size: 10" * 8" or 830 * 664 pixel (83 dpi)         */
  299. /* Bitmap window size: 12" * 9" or 828 * 621 pixel (69 dpi)        */
  300. /*----------------------------------------------------------------------*/
  301.  
  302. #define XDPI          69        /* horizontal dots/inch        */
  303. #define XPSIZE      13        /* horizontal screen size in "    */
  304. #define XMAG0PSIZE    9        /* mag0 horizontal page size (lcs) */
  305. #define XSIZE          (((XDPI*XPSIZE+2*HOST_WORD_SIZE-1)/\
  306.                  (2*HOST_WORD_SIZE))*(2*HOST_WORD_SIZE))
  307. #define    XWORDS      ((XSIZE + HOST_WORD_SIZE -1)/HOST_WORD_SIZE)
  308.  
  309. #define YDPI          69        /* vertical dots/inch        */
  310. #define YPSIZE      17        /* vertical screen size in inch    */
  311. #define YMAG0PSIZE    12        /* mag0 vertical page size (lcs) */
  312. #define YSIZE          (YDPI*YPSIZE)     /* number vertical pixel     */
  313.  
  314. #define    XBIT          ((1+2*XWORDS)/2) /* Printer bitmap (even col)    */
  315. #define YBIT          YSIZE  
  316.  
  317.  
  318. #define MIN_DPI        69        /* Lowest resolution to display    */
  319. #define MAX_DPI         144        /* Highest res. to display    */
  320.                     /* not used */
  321. #define MIN_MAGSTEP    0
  322. #define MAX_MAGSTEP    5
  323.  
  324.  
  325. /*----------------------------------------------------------------------*/
  326. /* General definitions superseeding previous definitions        */
  327. /*----------------------------------------------------------------------*/
  328.  
  329. #undef  STDRES                   /* 0 for low resolution device    */
  330. #define    STDRES        0
  331.  
  332. /*----------------------------------------------------------------------*/
  333. /* Coding starts here...                        */
  334. /*----------------------------------------------------------------------*/
  335.   
  336. #include <bitmap.h>            /* Bitmap definitions        */
  337. #include <main.h>
  338.  
  339. #if     DECWINDOWS                /* redefine STDMAG previously     */
  340. #undef    STDMAG                       /* define in MAIN.H        */
  341. #if    STDRES
  342. #define    STDMAG        500
  343. #else                                   /* STDMAG = dpi * 5        */
  344. #define    STDMAG        347          /* 83 dpi : STDMAG = 417    */
  345.                     /* 69 dpi : STDMAG = 347    */
  346. #endif    /* STDRES    */
  347. #endif    /* DECWINDOWS    */  
  348.  
  349. #include <abortrun.h>
  350. #include <actfact.h>
  351. #include <alldone.h>
  352.  
  353. /*----------------------------------------------------------------------*/
  354. /* BOPACT begin of page actions                        */
  355. /*----------------------------------------------------------------------*/
  356.  
  357. void bopact()
  358. {
  359.     (void)clrbmap();          /* Clear bitmap memory        */
  360.  
  361.     pbghpos = pbgvpos = -99;      /* set global values        */
  362.     cpagep  = (long)FTELL(dvifp) -1L;
  363.     ppagep  = (long)nosignex(dvifp,(BYTE)4);
  364. }
  365.  
  366. #include <chargf.h>
  367. #include <charpk.h>
  368. #include <charpxl.h>
  369. #include <clrbmap.h>
  370. #include <clrrow.h>
  371. #include <dbgopen.h> 
  372.  
  373. /*----------------------------------------------------------------------*/
  374. /* DEVINIT initialize MGR evironment.                   */
  375. /*----------------------------------------------------------------------*/
  376.  
  377. void devinit(argc,argv)
  378. int argc;                           /* Command line argument count. */
  379. char     *argv[];                           /* Pointers to command line args*/
  380. {
  381.     int     ft = 1,            /* Foreground text color.    */
  382.         bt = 0,            /* Background text color.    */
  383.         f = 0,            /* Foreground color.        */
  384.         b = 1,            /* Background color.        */
  385.         font = 8;        /* Window font number.        */
  386.         int     x = 0, y = 0;           /* Initial position of TeX window.  */
  387.  
  388.     struct window_data wd;        /* To hold window parameters.    */
  389.  
  390.     ckmgrterm(NULL);        /* Check if we're running in a    */
  391.                     /* MGR environment.        */
  392.                                         /* Setup the MGR library.    */
  393.     m_setup(M_FLUSH);        /* flush() after each outpout.    */
  394.     m_push(P_ALL & ~P_WINDOW);    /* Push old window status.    */
  395.         m_ttyset();
  396.                         /* Read init file.    */
  397.         (void)read_dvimgrinit(&ft, &bt, &font, &f, &b);
  398.  
  399.                             /* Open TeX window centered around main window.*/
  400.         get_windowdata(&wd, 0);
  401.         calculate_windsize();
  402.         x = wd.x + (wd.w - x_windsize) / 2;
  403.         y = wd.y + (wd.h - y_windsize) / 2;
  404.         if (x<0) x=0;
  405.         if (y<0) y=0;
  406.     TeX_win = m_makewindowfcol(x, y, x_windsize, y_windsize, font, f, b);
  407.  
  408.     get_windowdata(&wd, TeX_win);
  409.     x_windsize = wd.w;
  410.     y_windsize = wd.h;
  411.  
  412.     m_selectwin(TeX_win);
  413.     m_setmode(M_ABS);
  414.     m_setmode(M_FIXBDRCOL);
  415.     m_setmode(M_SHAPEREQ);
  416.     m_fcolor(ft);
  417.     m_bcolor(bt);
  418.     m_setcursor(CS_NONE);
  419.  
  420.     m_setevent(CHARACTER, "\177%x\n");
  421.         m_setevent(RESHAPE, "\177H%a\n");
  422.     m_setevent(DESTROY, "\177Y %w\n");
  423.  
  424.     menu_load(1, MENU_SIZE(main_menu), main_menu);
  425.     menu_load(2, MENU_SIZE(step_menu), step_menu);
  426.     menu_load(3, MENU_SIZE(stepsize_menu), stepsize_menu);
  427.     menu_load(4, MENU_SIZE(zoom_menu), zoom_menu);
  428.     m_linkmenu(1,  5, 2, MF_AUTO);
  429.     m_linkmenu(2,  4, 3, MF_AUTO);
  430.     m_linkmenu(2,  5, 3, MF_AUTO);
  431.     m_linkmenu(1,  9, 4, MF_AUTO);
  432.     m_selectmenu(1);
  433.     m_selectwin(0);
  434.     m_setmode(M_ACTIVATE);
  435.  
  436.     base_mag = runmag;
  437.     if (run_magstep != 0) {
  438.         set_magstep(run_magstep);
  439.     }
  440.  
  441.     xscreen = 0;            /* Set initial values. */
  442.     yscreen = 0;
  443.     xwindow = 0;
  444.     ywindow = 0;
  445.  
  446.     (void)getbmap();         /* Allocate bitmap memory    */ 
  447. }
  448.  
  449. void get_windowdata( struct window_data *pwd, int winid)
  450. {
  451.     struct window_data wd2;
  452.     int rval;
  453.  
  454.     do {
  455.         rval = get_eachclientwin(&wd2);
  456.         if (wd2.num == winid) {
  457.             *pwd = wd2;
  458.         }
  459.     } while (rval != 0);
  460.     return;
  461. }
  462.  
  463.  
  464. /*----------------------------------------------------------------------*/
  465. /*  Read configuration file for fonts and colors.            */
  466. /*  First look in the current directory, then in /dd/sys, then in    */
  467. /*  /h0/sys.  If no file could be found we use the default values.    */
  468. /*----------------------------------------------------------------------*/
  469.  
  470. static char *paramnames[] = {
  471.     "font",            /*  0 */
  472.     "fgcolor",        /*  1 */
  473.     "bgcolor",        /*  2 */
  474.     "text-fgcolor",        /*  3 */
  475.     "text-bgcolor",        /*  4 */
  476.     "startmag",        /*  5 */
  477.     "x_maxwsize",        /*  6 */
  478.     "y_maxwsize",        /*  7 */
  479.     "x_mag0wins",        /*  8 */
  480.     "y_mag0wins",        /*  9 */
  481.     "x_step_size",        /* 10 */
  482.     "y_step_size",        /* 11 */
  483.     NULL
  484. };
  485.  
  486. static void read_dvimgrinit(int *pft, int *pbt, int *pfont, int *pf, int *pb)
  487. {
  488.     FILE    *fp;
  489.     char    cline[80],
  490.             cpname[32];
  491.     int    i, value;
  492.  
  493.     fp = FOPEN(".dvimgrinit", "r");
  494.     DEBUG_OPEN(fp, ".dvimgrinit", "r");
  495.  
  496.     if (fp == (FILE*)NULL)
  497.     {
  498.         fp = FOPEN("/dd/sys/.dvimgrinit", "r");
  499.         DEBUG_OPEN(fp, "/dd/sys/.dvimgrinit", "r");
  500.  
  501.         if (fp == (FILE*)NULL)
  502.         {
  503.             fp = FOPEN("/h0/sys/.dvimgrinit", "r");
  504.             DEBUG_OPEN(fp, "/h0/sys/.dvimgrinit", "r");
  505.  
  506.             if (fp == (FILE*)NULL) {
  507.                 return;
  508.             }
  509.         }
  510.     }
  511.  
  512.     while (fgets(cline, 80, fp) != NULL)
  513.     {
  514.         if (cline[0] == ';' || cline[0] == '*' || cline[0] == '\n') {
  515.             continue;
  516.         }
  517.         sscanf(cline, "%s %d", &cpname, &value);
  518.         for (i = 0;  paramnames[i] != NULL;  i++) {
  519.             if (strcmp(paramnames[i], cpname) == 0) {
  520.                 break;
  521.             }
  522.         }
  523.  
  524.         switch(i)
  525.         {
  526.         case 0:  *pfont = value; break;
  527.         case 1:  *pf    = value; break;
  528.         case 2:  *pb    = value; break;
  529.         case 3:  *pft   = value; break;
  530.         case 4:  *pbt   = value; break;
  531.  
  532.         case 5:  run_magstep = value; break;
  533.         case 6:     x_maxwsize  = value; break;
  534.         case 7:  y_maxwsize  = value; break;
  535.         case 8:  x_mag0wins  = value; break;
  536.         case 9:  y_mag0wins  = value; break;
  537.  
  538.         case 10: x_step_size = value; break;
  539.         case 11: y_step_size = value; break;
  540.  
  541.         default:
  542.             fprintf(stderr,
  543.                 "Unknown parameter in config file: %s\n", cpname);
  544.         }
  545.     }
  546.     fclose (fp);
  547.     return;
  548. }
  549.  
  550.  
  551.  
  552. /*----------------------------------------------------------------------*/
  553. /* DEVTERM terminate DEC Windows output                    */
  554. /*----------------------------------------------------------------------*/
  555.  
  556. void devterm()
  557. {                    /* Terminate output window    */
  558.         m_selectwin(TeX_win);
  559.     m_clearevent(CHARACTER);
  560.         m_clearevent(RESHAPE);
  561.     m_clearevent(DESTROY);
  562.         m_clearmode(M_SHAPEREQ);
  563.     m_clearmenu(1);
  564.         m_selectwin(0);
  565.     m_destroywin(TeX_win);
  566.     m_popall();
  567.     m_flush();
  568. }
  569.  
  570. #include <dispchar.h>
  571. #include <dvifile.h>
  572. #include <dviinit.h>
  573. #include <dviterm.h>
  574. #include <f20open.h>
  575. #include <fatal.h>
  576. #include <fillrect.h>
  577. #include <findpost.h>
  578. #include <fixpos.h>
  579. #include <fontfile.h>
  580. #include <fontsub.h>
  581. #include <getbmap.h>
  582. #include <getbytes.h>
  583. #include <getfntdf.h>
  584. #include <getpgtab.h>
  585. #include <inch.h>
  586. #include <initglob.h>
  587. #include <loadchar.h>
  588. #include <movedown.h>
  589. #include <moveover.h>
  590. #include <moveto.h>
  591.  
  592. /*----------------------------------------------------------------------*/
  593. /* NEWFONT dummy routine called from readxx routines            */
  594. /*----------------------------------------------------------------------*/
  595.  
  596. void newfont()
  597. {
  598. }
  599.  
  600. #include <nosignex.h>
  601. #include <openfont.h>
  602. #include <option.h>
  603.  
  604. /*----------------------------------------------------------------------*/
  605. /* PRTBMAP display created bitmap in output window            */
  606. /*----------------------------------------------------------------------*/
  607.  
  608. void prtbmap()                /* 25-Jun-1993  lcs */
  609. {                    /* Copy bitmap to window    */
  610.     int       y;
  611.     UNSIGN32  *p;
  612.  
  613.     m_selectwin(TeX_win);        /* Select output window.    */
  614.     m_setmode(M_ACTIVATE);
  615.  
  616.     p = bitmap;
  617.         for (y = 0;  y < y_windsize  &&  y < y_pagesize;  y++)
  618.         {
  619.             m_bitloadcol(0, y, x_windsize, 1, 1, p);
  620.             p += XWORDS;
  621.         }
  622. /*        m_bitloadcol(0, 0, XSIZE, YSIZE, 1, p); */
  623.  
  624.     m_selectwin(0);            /* Back to main window.        */
  625. }
  626.  
  627. #include <outrow.h>
  628. #include <prtpage.h>
  629. #include <readfont.h>
  630. #include <readgf.h>
  631. #include <readpk.h>
  632. #include <readpost.h>
  633. #include <readpxl.h>
  634. #include <reldfont.h>
  635. #include <rulepxl.h>
  636. #include <setchar.h>
  637. #include <setfntnm.h>
  638. #include <setrule.h>
  639. #include <signex.h>
  640. #include <skgfspec.h>
  641. #include <skipfont.h>
  642. #include <skpkspec.h>
  643. #include <special.h>
  644. #include <strchr.h>
  645. #include <strcm2.h>
  646. #include <strid2.h>
  647. #include <strrchr.h>
  648. #include <tctos.h>
  649.  
  650. /*----------------------------------------------------------------------*/
  651. /* UNLOADFONTS mark all fonts as unloaded                */
  652. /*----------------------------------------------------------------------*/
  653.  
  654. void unloadfonts()            /* mark all fonts as not loaded */
  655. {                    /* and set no current fonts     */
  656.        INT16 k;                /* loop index             */
  657.  
  658.     for (fontptr = hfontptr; fontptr != (struct font_entry *)NULL;
  659.      fontptr = fontptr->next)
  660.     {
  661.     for (k = 0; k < NPXLCHARS; ++k)
  662.         fontptr->ch[k].isloaded = FALSE;
  663.  
  664.     if (fontptr->font_file_id != (FILE*)NULL)
  665.     {
  666.         (void)fclose(fontptr->font_file_id);
  667.         fontptr->font_file_id = (FILE*)NULL;
  668.     }
  669.     }
  670.  
  671.     fontfp = (FILE*)NULL;        /* no current font file     */
  672.     for ( ; nopen > 0; --nopen)        /* clear font file cache     */
  673.     {
  674.     font_files[nopen].font_id = (FILE*)NULL;
  675.     font_files[nopen].use_count = (INT16)0;
  676.     }
  677.  
  678.     /* NB: It is important here that the loop index be global; the relation
  679.     of fontptr to pfontptr is used by openfont() to decide whether the font
  680.     file is already open. */
  681.     for (fontptr = hfontptr; fontptr != (struct font_entry *)NULL;
  682.      fontptr = fontptr->next)
  683.     {
  684.     pfontptr = (struct font_entry *)(NULL); 
  685.                     /* so reldfont() calls openfont() */
  686.     (void)reldfont(fontptr);    /* get new font metrics     */
  687.     }
  688. }
  689.  
  690. #include <usage.h>
  691. #include <warning.h>
  692.  
  693. /************************************************************************/
  694. /* Service routines for MGR environment                    */
  695. /************************************************************************/
  696.  
  697. /*----------------------------------------------------------------------*/
  698. /* Main loop to handle MGR events.                    */
  699. /*----------------------------------------------------------------------*/
  700.  
  701. static void mgr_main_loop( void)
  702. {
  703. int     i, value;
  704. char    cline[256];            /* Array for MGR event string.  */
  705. int    new_page_number;        /* destination page number    */
  706. char    *new_page_string;        /* page number in string form    */
  707.  
  708. int     x, y;                       /* Window coordinates for reshape.  */
  709. struct window_data wd;            /* To hold window parameters.    */
  710.  
  711. static  BOOLEAN btmargin = TRUE;
  712. static  BOOLEAN blmargin = TRUE;
  713.                                                                            
  714.  
  715.     m_sendme("\177t\n");        /* Display first page immediately. */
  716.     m_flush();
  717.  
  718.     while(m_getevent(cline, sizeof(cline)) != NULL)   /* Wait for MGR event. */
  719.     {                        /* We'll never leave this loop. */
  720.         if (cline[0] != '\177') {
  721.             continue;
  722.         }
  723.  
  724.         switch (cline[1])
  725.         {
  726.             case k_SHAPEREQ:
  727.                 sscanf(&cline[2],"%d %d %d %d", &x, &y, &x_windsize, &y_windsize);
  728.                 m_selectwin(TeX_win);
  729.                 m_shapewindow(x, y, x_windsize, y_windsize);
  730.                 m_selectwin(0);
  731.                 auto_reshape = FALSE;
  732.                 redraw();
  733.                 break;
  734.  
  735.             case k_auto_reshape:
  736.                 auto_reshape = TRUE;
  737.         get_windowdata(&wd, 0);
  738.         calculate_windsize();
  739.         x = wd.x + (wd.w - x_windsize) / 2;
  740.         y = wd.y + (wd.h - y_windsize) / 2;
  741.         if (x<0) x=0;
  742.         if (y<0) y=0;
  743.         m_selectwin(TeX_win);
  744.         m_shapewindow(x, y, x_windsize, y_windsize);
  745.         get_windowdata(&wd, TeX_win);
  746.         x_windsize = wd.w;
  747.         y_windsize = wd.h;
  748.                 break;
  749.  
  750.         case k_redraw:
  751.                 redraw();
  752.                 break;
  753.  
  754.             case k_prevpage_me:        /* goto previous page (if avail)*/
  755.             if(cur_index > 0)  
  756.             {
  757.                     cur_index--;
  758.                     cur_page_number--;
  759.                     redraw();
  760.             }
  761.             else            /* first page reached already    */
  762.               ;
  763.             break;
  764.  
  765.         case k_nextpage_me:            /* goto next page (if avail)    */
  766.             if(cur_index < page_count-1)
  767.             {
  768.                 cur_index++;
  769.             cur_page_number++;
  770.                     redraw();
  771.             }
  772.             else                      /* last page reached already    */
  773.                 ;
  774.             break;
  775.  
  776.         case k_backward:
  777.         if (ywindow == 0) {
  778.             if(cur_index > 0) {
  779.                         cur_index--;
  780.                         cur_page_number--;
  781.                     ywindow = y_pagesize - y_windsize;
  782.                 }
  783.             } else {
  784.                 ywindow -= y_windsize * 3/4;
  785.                 if (ywindow < 0) {
  786.                     ywindow = 0;
  787.                 }
  788.             }
  789.                 redraw();
  790.                 break;
  791.  
  792.             case k_forward:
  793.                 if (ywindow == y_pagesize - y_windsize) {
  794.             if(cur_index < page_count-1) {
  795.                     cur_index++;
  796.                 cur_page_number++;
  797.                 ywindow = 0;
  798.             }
  799.         } else {
  800.             ywindow += y_windsize * 3/4;
  801.                     if (ywindow > y_pagesize - y_windsize) {
  802.                     ywindow = y_pagesize - y_windsize;
  803.                     }
  804.                 }
  805.                 redraw();
  806.                 break;
  807.  
  808.             case k_bot_page_me:          /* goto bottom of page        */
  809.             ywindow = y_pagesize - y_windsize;
  810.             redraw();
  811.             break;
  812.  
  813.         case k_top_page_me:           /* goto top of page        */
  814.             ywindow = 0;
  815.             redraw();
  816.             break;
  817.  
  818.         case k_curs_up_me:            /* move up one step        */
  819.             ywindow -= y_windsize * y_step_size / 100;
  820.             redraw();
  821.             break;
  822.  
  823.         case k_curs_down_me:    /* move down one step        */
  824.             ywindow += y_windsize * y_step_size / 100;
  825.             redraw();
  826.             break;
  827.  
  828.         case k_curs_left_me:          /* move left one step        */ 
  829.             xwindow -= x_windsize * x_step_size / 100;
  830.             redraw();
  831.             break;
  832.  
  833.         case k_curs_right_me:    /* move right one step        */
  834.             xwindow += x_windsize * x_step_size / 100;
  835.             redraw();
  836.             break;
  837.  
  838.         case k_gotopage_me:        /* Ask for page number to go to. */
  839.             new_page_number = 0;
  840.             m_selectwin(0);
  841.             m_setmode(M_ACTIVATE);
  842.             m_clearevent(CHARACTER);
  843.             m_ttyreset();
  844.             printf("Goto page number: ");
  845.                 fflush(stdout);
  846.             m_gets(cline);
  847.             m_ttyset();
  848.             m_setevent(CHARACTER, "\177" "C%x\n");
  849.             sscanf(cline, "%d", &new_page_number);
  850.             if(new_page_number > page_count) {
  851.                 new_page_number = page_count;
  852.             }
  853.                 if(new_page_number < 1) {
  854.                 new_page_number = 1;
  855.             }
  856.                 cur_index = new_page_number - 1;
  857.             cur_page_number = new_page_number;
  858.             ywindow = 0;
  859.             redraw();
  860.             break;                                  
  861.  
  862.         case k_top_margin:        /* toggle use/dont't use topmargin */
  863.             if(btmargin == TRUE) {
  864.             tmargin = (COORDINATE)(0.1*((float)YDPI));
  865.             btmargin = FALSE;
  866.             } else {
  867.             tmargin = (COORDINATE)(topmargin *((float)YDPI));
  868.             btmargin = TRUE;
  869.             }
  870.         redraw();
  871.             break;
  872.  
  873.         case k_left_margin:        /* toggle use/dont't use leftmargin */
  874.             if(blmargin == TRUE) {
  875.             lmargin = (COORDINATE)(0.1*((float)XDPI));
  876.             blmargin = FALSE;
  877.             } else {
  878.             lmargin = (COORDINATE)(leftmargin *((float)XDPI));
  879.             blmargin = TRUE;
  880.             }
  881.         redraw();
  882.             break;
  883.  
  884.         case k_move_speed_x:          /* set x cursor speed */
  885.             {
  886.                 int i;
  887.  
  888.             i = atol(&cline[2]);
  889.             if (i < 0)   i = 0;
  890.             if (i > 100) i = 100;
  891.             x_step_size = i;
  892.         }
  893.         break;
  894.  
  895.         case k_move_speed_y:          /* set y cursor speed */
  896.             {
  897.                 int i;
  898.  
  899.             i = atol(&cline[2]);
  900.             if (i < 0)   i = 0;
  901.             if (i > 100) i = 100;
  902.             y_step_size = i;
  903.         }
  904.         break;
  905.  
  906.  
  907.                 break;
  908.  
  909.         case k_zoom0:
  910.         case k_zoom1:
  911.         case k_zoom2:
  912.         case k_zoom3:
  913.         case k_zoom4:
  914.         case k_zoom5:         /* Set zoom to selected magstep    */
  915.                 {
  916.                 int i, j;        /* Loop variables. */
  917.  
  918.             i = cline[1] - '0';
  919.             if (i < MIN_MAGSTEP) i = MIN_MAGSTEP;
  920.             if (i > MAX_MAGSTEP) i = MAX_MAGSTEP;
  921.             run_magstep = i;
  922.             set_magstep( run_magstep);
  923.             conv = ((float)num/(float)den) *
  924.             ((float)runmag/(float)STDMAG) *
  925. #if    USEGLOBALMAG
  926.                 actfact(mag) *
  927. #endif
  928.                 ((float)RESOLUTION/254000.0);
  929.             (void)unloadfonts();
  930.             redraw();
  931.             }
  932.                 break;
  933.  
  934.  
  935.         case k_zoom_out_me:        /* Zoom down one magstep    */
  936.             run_magstep--;
  937.             if (run_magstep < 0) {    /* Constrain resolution range    */  
  938.                 run_magstep = 0;
  939.             }
  940.             set_magstep( run_magstep);
  941.             conv = ((float)num/(float)den) *
  942.                 ((float)runmag/(float)STDMAG) *
  943. #if    USEGLOBALMAG
  944.                 actfact(mag) *
  945. #endif
  946.             ((float)RESOLUTION/254000.0);
  947.             (void)unloadfonts();
  948.             redraw();  
  949.             break;
  950.  
  951.         case k_zoom_in_me:        /* Zoom up one magstep        */
  952.             run_magstep++;
  953.             if (run_magstep > 5) {    /* Constrain resolution range    */  
  954.                 run_magstep = 5;
  955.             }
  956.             set_magstep( run_magstep);
  957.             conv = ((float)num/(float)den) *
  958.             ((float)runmag/(float)STDMAG) *
  959. #if    USEGLOBALMAG
  960.             actfact(mag) *
  961. #endif
  962.             ((float)RESOLUTION/254000.0);
  963.             (void)unloadfonts();
  964.                 redraw();  
  965.             break;
  966.  
  967.         case k_reload_fonts:    /* force reloading fonts    */
  968.             (void)unloadfonts();
  969.             redraw();
  970.             break;
  971.  
  972.         case k_reset_pos_me:          /* reset position after moves    */
  973.             xwindow = 0;
  974.             ywindow = 0;
  975.             redraw();
  976.             break;
  977.  
  978.         case k_DESTROY:
  979.             case k_quit_me:        /* Menu File/Quit        */
  980.             (void)devterm();    /* terminate device output     */  
  981.                 (void)dviterm();    /* terminate DVI file processing*/  
  982.             (void)alldone();    /* this will never return     */
  983.             break;
  984.  
  985.         default:               /* event is unknown        */
  986.             break;
  987.         }
  988.     }        /* while (m_gets()) */
  989. }
  990.  
  991.  
  992. /*----------------------------------------------------------------------*/
  993. /*  Redraw the page.                                                    */
  994. /*----------------------------------------------------------------------*/
  995.  
  996. static void redraw( void)
  997. {
  998. char    out_string[128];        /* string for messages        */
  999.  
  1000. int    x_top_windsize;
  1001. int    y_top_windsize;
  1002.  
  1003.                     /* Constrain view range        */
  1004.     if(xwindow > (x_pagesize - x_windsize))
  1005.        xwindow = x_pagesize - x_windsize;
  1006.     if(xwindow < 0)            
  1007.        xwindow = 0;
  1008.     if(ywindow > (y_pagesize-y_windsize))
  1009.        ywindow = y_pagesize-y_windsize;
  1010.     if(ywindow < 0)
  1011.        ywindow = 0;
  1012.  
  1013.     xscreen = xwindow;
  1014.     yscreen = ywindow;
  1015.  
  1016.     prtpage(page_ptr[cur_index]);
  1017.  
  1018.         m_selectwin(0);
  1019.     printf("TeX Preview - Page %d/%d  TeX-Page[%s]  %d dpi\n",
  1020.         cur_index+1,page_count,tctos(),(int)((runmag*10/5+5)/10));
  1021.  
  1022.         prtbmap();
  1023. }
  1024.  
  1025.  
  1026. int set_magstep(int magstep)
  1027. {
  1028.     int i;
  1029.     int x, y;               /* Initial coordinates of TeX window. */
  1030.     struct window_data wd;
  1031.  
  1032.     runmag = base_mag;
  1033.     for (i = 0;  i < magstep;  i++) {
  1034.     runmag=MAGSIZE(actfact((UNSIGN32)((6*runmag)/5)));
  1035.     }
  1036.  
  1037.     if (auto_reshape) {
  1038.         get_windowdata(&wd, 0);
  1039.         calculate_windsize();
  1040.         x = wd.x + (wd.w - x_windsize) / 2;
  1041.         y = wd.y + (wd.h - y_windsize) / 2;
  1042.         if (x<0) x=0;
  1043.         if (y<0) y=0;
  1044.         m_selectwin(TeX_win);
  1045.         m_shapewindow(x, y, x_windsize, y_windsize);
  1046.         get_windowdata(&wd, TeX_win);
  1047.         x_windsize = wd.w;
  1048.         y_windsize = wd.h;
  1049.     }
  1050.     m_selectwin(0);
  1051.     return(0);
  1052. }
  1053.  
  1054. void calculate_windsize( void)
  1055. {
  1056.     x_pagesize = (int) ((runmag*10/5+5)/10) * XMAG0PSIZE;
  1057.     y_pagesize = (int) ((runmag*10/5+5)/10) * YMAG0PSIZE;
  1058.  
  1059.     if (run_magstep == 0)
  1060.     {
  1061.     if (x_mag0wins == -1) {
  1062.         x_windsize = x_pagesize;
  1063.     } else {
  1064.         x_windsize = (x_pagesize > x_mag0wins) ? x_mag0wins : x_pagesize;
  1065.     }
  1066.     if (y_mag0wins == -1) {
  1067.         y_windsize = y_pagesize;
  1068.     } else {
  1069.         y_windsize = (y_pagesize > y_mag0wins) ? y_mag0wins : y_pagesize;
  1070.     }
  1071.     } else {
  1072.     x_windsize = (x_pagesize > x_maxwsize) ? x_maxwsize : x_pagesize;
  1073.     y_windsize = (y_pagesize > y_maxwsize) ? y_maxwsize : y_pagesize;
  1074.     }
  1075.  
  1076.     return;
  1077. }
  1078.  
  1079. /************************************************************************/
  1080. /* END of source file                            */
  1081. /************************************************************************/
  1082.