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 / dvi_fbi_hh / DVIDECW / dvidecw.c next >
Text File  |  1993-05-06  |  36KB  |  974 lines

  1. /************************************************************************/
  2. /* Filename: DVIDECW.C                                */
  3. /* Function: Program to view TeX DVI ouput file in a DEC-Windows Envir-    */
  4. /*         onment                            */
  5. /* (c) 1990 by Christian MARKUS, Fachbereich Informatik,        */
  6. /*             Schlueterstr. 70, D 2000 Hamburg 13, Fed.Rep.of Germany    */
  7. /*                                    */
  8. /* EMAIL   : via   friesland@rz.informatik.uni-hamburg.dbp.de        */
  9. /*----------------------------------------------------------------------*/
  10. /* Program History:                            */
  11. /*                                    */
  12. /* Ver#: ! Date:  !Comment:                !Author:        */
  13. /* ------+--------+-------------------------------------+-------------- */
  14. /* 1.0   !04.07.89!First version            !Ch. Markus    */
  15. /* 1.1   !09.03.90!Corrected and updated        !Ch. Markus    */ 
  16. /*          !- get/set bit/byte order correctly    !        */
  17. /*          !- one window/automatically adjusted  !        */
  18. /*          !- window size can be changed        !        */
  19. /*          !- Scrollbars available        !        */
  20. /*          !- Title contains info        !        */
  21. /*           !- Copy to Clipboard            !        */
  22. /* 1.2   !19.06.90!- adaption for ANSI-C/VAX-C 3.1    !Ch. Markus    */
  23. /*----------------------------------------------------------------------*/
  24. /* Program description:                            */
  25. /*                                    */
  26. /* This driver works in a DECWindows environment and is based on TEX    */
  27. /* DVI-driver family developed by N.Beebe, Utah, USA. The include files    */
  28. /* are taken from version 2.10, the driver DVIDECW is based on the    */
  29. /* DVIBIT driver. Instead of using download fonts it creates a bitmap     */
  30. /* (similar to DVIJET) and displays it in the output window upon a    */
  31. /* window exposure event. Upon each interactive command, the bitmap is    */
  32. /* created again.                            */
  33. /*----------------------------------------------------------------------*/
  34. /* Installation guide:                            */
  35. /*                                     */
  36. /* - modify the TEXVIEW.COM file to suit your system's paths        */
  37. /* - in FileView, select the Customize/Verbs and Menus option        */
  38. /* - enter a new verb name 'TeX Preview' below the verb names box and    */
  39. /*   click on enter button upon completition                */
  40. /* - enter the DCL command for the 'Tex Preview' verb, that is entering    */
  41. /*   somewhat like @<path>texview.com and clicking on the 'enter' button*/
  42. /* - select a menu from the 'Menu Names' box and click on the 'Add'    */
  43. /*   button below the 'Verbs in Menu' list box.                */
  44. /* - press 'Apply' and 'Ok' button to install new item in menu bar    */
  45. /* - select the Customize/File Types option and install the .DVI file    */
  46. /*   type.                                */
  47. /*----------------------------------------------------------------------*/
  48. /* Quick guide to operations:                        */
  49. /*                                     */
  50. /* Invoke DVIDecw in four different ways:                */
  51. /* - from a DECTerm terminal window                     */
  52. /*   -> just type the command,options and filename to be processed    */
  53. /* - from the FileView DCL Command window                */
  54. /*   -> just type the command,options and filename to be processed    */
  55. /* - by selecting a FileView menu item (if TEXVIEW.COM is installed)    */
  56. /*   -> a dialog box pops up asking for a filename, a second box will    */
  57. /*      ask for any processing parameters                */
  58. /* - by double-clicking on any .DVI file (if TEXVIEW.COM is installed    */
  59. /*   and the File Types box is set for .DVI files            */
  60. /*   -> a dialog box pops up asking for processing parameters        */
  61. /*                                                                      */
  62. /* All options of DVIBIT are accepted, but the -o option (order pages)    */
  63. /* is ignored, DVIDecw will only pick the first selected page        */
  64. /* The program will create a command and an output window and display    */
  65. /* the first selected page.                                             */
  66. /* All interactive commands can be selected from menus and should be     */
  67. /* easy to understand.                             */
  68. /* If the TeX Preview window has the 'Input focus' key equivalents    */
  69. /* provide a shortcut for some menu commands. To set the input focus,    */
  70. /* just click into the Tex Preview window, the window title will change    */
  71. /* to the highlight color.                        */
  72. /*----------------------------------------------------------------------*/
  73. /* The following files taken from the original BEEBE driver have been    */
  74. /* modified (using #if compiler switches) for DECWINDOWS:        */
  75. /*                                    */
  76. /* DISPCHAR.H -> make up for reversed Y-coordinate origin        */
  77. /* DVIFILE.H  -> change program structure to event-driven calls        */  
  78. /* FATAL.H    -> don't perform resetterm() function in DECW environment    */ 
  79. /* GBLPROCS.H -> modifications to conform with ANSI-C (Vax C 3.1)    */
  80. /* MACHDEFS.H -> changed FONTPATH, FONTLIST and DVIHELP for OS_VMS         */
  81. /* OPENFONT.H -> allow open files according to MAXOPEN,quota and avail.    */
  82. /* PRTPAGE.H  -> changes in EOP case and keyboard status request    */ 
  83. /* SETCHAR.H  -> make up for reversed Y-coordinate origin        */
  84. /* SETRULE.H  -> make up for reversed Y-coordinate origin        */
  85. /*----------------------------------------------------------------------*/
  86. /* The DVIDecw package contains the files listed below:            */
  87. /*                                     */
  88. /* DVIDOC_D.DVI Installation/User's Guide in GERMAN            */
  89. /* DVIDOC_E.DVI Installation/User's Guide in ENGLISH            */
  90. /* DVIDECW.C    Main C source code, all DECWindows specific coding    */
  91. /* DVIDECW.UIL    User Interface description file                */
  92. /* DVIDECW.COM  Compile,UIL and link command procedure            */
  93. /* DVILINK.COM  Link DVIDECW for other VMS versions            */
  94. /* TEXVIEW.COM    Command procedure for FileView invocation of DVIDECW    */
  95. /* xxxxxxx.H    Include files (listed above) modified for DVIDECW    */
  96. /************************************************************************/
  97.  
  98. #include <stdio.h>                      /* Standard definitions        */
  99.  
  100. /************************************************************************/
  101. /* DECWINDOWS definitions                        */
  102. /************************************************************************/
  103.  
  104. #ifdef VMS                              /* Toolkit definitions        */
  105. #include <decw$include/DwtAppl.h>        /* using MIT-Binding        */
  106. #include <decw$include/Xlib.h>
  107. #include <decw$include/Xutil.h>
  108. #else
  109. #include <X11/DwtAppl.h>       
  110. #include <X11/Xlib.h>
  111. #include <X11/Xutil.h>      
  112. #endif
  113.  
  114. #define APP_ID            "TeX Preview"  /* Application name    */
  115. #define    CLPBRD_FORMAT        "XYBitmap" /* Clipboard data format    */
  116.  
  117. /*----------------------------------------------------------------------*/
  118. /* Constants for object identificationv (similar to .UIL file)        */
  119. /*----------------------------------------------------------------------*/
  120.  
  121. #define    k_menu_bar        1
  122.  
  123. #define k_file_pdme             2
  124. #define k_edit_pdme             3    
  125. #define    k_page_pdme        4
  126. #define    k_move_pdme        5
  127. #define k_option_pdme        6
  128.  
  129. #define k_file_menu             7
  130. #define k_edit_menu             8
  131. #define k_page_menu             9
  132. #define    k_move_menu        10
  133. #define k_option_menu           11
  134.  
  135. #define    k_about_me        12
  136. #define    k_quit_me        13
  137.                               
  138. #define    k_undo_me        14   
  139. #define k_cut_me        15
  140. #define k_copy_me        16
  141. #define    k_paste_me         17
  142. #define    k_clear_me        18
  143. #define    k_s_all_me        19
  144.                                  
  145. #define    k_prevpage_me        20
  146. #define    k_nextpage_me        21
  147. #define    k_gotopage_me        22
  148. #define k_zoom_in_me        23
  149. #define k_zoom_out_me        24
  150.  
  151. #define k_curs_up_me        25
  152. #define k_curs_down_me        26
  153. #define k_curs_left_me        27
  154. #define k_curs_right_me        28
  155. #define k_top_page_me            29 
  156. #define k_bot_page_me           30
  157.  
  158. #define k_offset_me        31
  159. #define k_move_speed_me        32
  160. #define k_reset_pos_me        33
  161.  
  162. #define k_clipboard_msg         34
  163. #define k_about_msg        35
  164. #define    k_about_button        36
  165.  
  166. #define k_goto_page_dlg        37
  167. #define k_goto_page_label    38
  168. #define k_pagenumber        39
  169. #define k_ok_button        40
  170. #define k_goto_button        41
  171. #define k_cancel_button        42
  172.                                                       
  173. #define    k_lastpage_msg        43
  174. #define    k_firstpage_msg        44
  175. #define    k_zoomrange_msg        45 
  176.  
  177. #define    k_output        46
  178.  
  179. #define    k_scroll_x        47
  180. #define k_scroll_y        48
  181.  
  182. #define k_max_widget        48
  183.                                
  184. #define MAX_WIDGETS (k_max_widget + 1)
  185.                                         
  186. /*----------------------------------------------------------------------*/
  187. /* Global data declarations                        */
  188. /*----------------------------------------------------------------------*/
  189.  
  190. static Widget     toplevel_widget,        /* Root widget ID of application*/
  191.           main_window_widget,     /* Root widget ID main DRM fetch*/
  192.           widget_array[MAX_WIDGETS]; /* Place for other widget IDs*/
  193. static DRMHierarchy s_DRMHierarchy;     /* DRM database hierarchy ID     */
  194. static DRMType *dummy_class;            /* and class variable.         */
  195. static char *db_filename_vec[] =        /* DRM hierarchy file list.     */
  196.   {"TEX_INPUTS:dvidecw.uid"             /* Fetch resource from path    */
  197.   };                                    /* TEX_INPUTS defined as global    */
  198. static int db_filename_num =
  199.                 (sizeof db_filename_vec / sizeof db_filename_vec [0]);
  200. static Display     *display;                /* Display handle        */        
  201. static Window   top_wi,out_wi;        /* Window handles        */
  202. static GC     gc;             /* Graphic context handle    */
  203. static Screen     *screen;                /* Screen handle        */
  204. static XImage    *out_img;          /* XImage Data block        */
  205. static Arg    arglist[5];        /* Arguments for SetValue    */
  206. static int      x_windsize;        /* Window workarea size in pixel*/
  207. static int      y_windsize;
  208. static int    x_pagesize;        /* Virtual page size in pixel    */
  209. static int    y_pagesize;
  210.  
  211. static    DwtCompString slow_move;
  212. static    DwtCompString fast_move;
  213. static    DwtCompString no_offset;
  214. static  DwtCompString use_offset;
  215. static    DwtCompString discard_dlg;
  216. static  DwtCompString gotopage_dlg;
  217.  
  218. /*----------------------------------------------------------------------*/
  219. /* forward declaration of DECWINDOWS routines                */
  220. /*----------------------------------------------------------------------*/
  221.  
  222. static void s_error(char *problem_string);
  223. static void prtbmap(void);
  224. static void w_print(int line,char *string);
  225. static void clrbmap(void);
  226. static void send_redraw(void);
  227. static void create_proc(Widget w,int *tag,unsigned long *reason);
  228. static void activate_proc(Widget w,int *tag,unsigned long *reason); 
  229. static void output_exp_proc(Widget w,int *tag,
  230.                  DwtAnyCallbackStruct *callback_data);    
  231. static void scroll_bar_proc(Widget w,int *tag,unsigned long *reason); 
  232.  
  233. /*----------------------------------------------------------------------*/
  234. /* Names of callback routines to be registered to DECWINDOWS        */
  235. /*----------------------------------------------------------------------*/
  236.  
  237. static DRMRegisterArg reglist[] = 
  238.  {
  239.     {"create_proc", (caddr_t) create_proc}, 
  240.     {"activate_proc", (caddr_t) activate_proc}, 
  241.     {"scroll_bar_proc", (caddr_t) scroll_bar_proc},     
  242.     {"output_exp_proc", (caddr_t) output_exp_proc} 
  243.  };
  244.  
  245. static int reglist_num = (sizeof reglist / sizeof reglist [0]);
  246.  
  247. /************************************************************************/
  248. /* DVI-BEEBE driver definitions                        */
  249. /************************************************************************/
  250.  
  251. #include <dvihead.h>
  252.  
  253. /*----------------------------------------------------------------------*/
  254. /* Device specific definitions                        */
  255. /*----------------------------------------------------------------------*/  
  256.  
  257. #define DECWINDOWS    1        /* cond. compilations flag    */
  258. #define BBNBITGRAPH    1        /* BITGRAPH driver as base    */
  259.  
  260. #define VERSION_NO    "2.10"        /* DVI driver version number    */
  261. #define DEVICE_ID    "DVI DECWindows 69 dpi"
  262.                     /* String printed at runtime    */ 
  263. #define OUTFILE_EXT    "DEC"        /* Not used here (dummy)    */
  264. #define BYTE_SIZE    8            /* Not used here (dummy)    */
  265.  
  266. /*----------------------------------------------------------------------*/
  267. /* These constants are special to DVIBIT and are not req. by DVIDECW    */
  268. /*----------------------------------------------------------------------*/  
  269.  
  270. #define    FIRSTBGCHAR    32
  271. #define LASTBGCHAR    127
  272. #define NBGFONTS    3
  273.  
  274. /*----------------------------------------------------------------------*/
  275. /* Page dimension definition                        */
  276. /* Bitmap window size: 10" * 8" or 830 * 664 pixel (83 dpi)         */
  277. /* Bitmap window size: 12" * 9" or 828 * 621 pixel (69 dpi)        */
  278. /*----------------------------------------------------------------------*/
  279.  
  280. #define XDPI        69        /* horizontal dots/inch        */
  281. #define XPSIZE        9        /* horizontal screen size in "    */
  282. #define XSIZE        (((XDPI*XPSIZE+2*HOST_WORD_SIZE-1)/\
  283.                  (2*HOST_WORD_SIZE))*(2*HOST_WORD_SIZE))
  284. #define    XWORDS        ((XSIZE + HOST_WORD_SIZE -1)/HOST_WORD_SIZE)
  285.  
  286. #define YDPI        69        /* vertical dots/inch        */
  287. #define YPSIZE        12        /* vertical screen size in inch    */
  288. #define YSIZE        (YDPI*YPSIZE)    /* number vertical pixel     */
  289.  
  290. #define    XBIT        ((1+2*XWORDS)/2) /* Printer bitmap (even col)    */
  291. #define YBIT        YSIZE
  292.  
  293. #define MIN_DPI        69        /* Lowest resolution to display    */
  294. #define MAX_DPI         144        /* Highest res. to display    */
  295.  
  296. /*----------------------------------------------------------------------*/
  297. /* General definitions superseeding previous definitions        */
  298. /*----------------------------------------------------------------------*/
  299.  
  300. #undef  STDRES                   /* 0 for low resolution device    */
  301. #define    STDRES        0
  302.  
  303. /*----------------------------------------------------------------------*/
  304. /* Coding starts here...                        */
  305. /*----------------------------------------------------------------------*/
  306.   
  307. #include <bitmap.h>            /* Bitmap definitions        */
  308. #include <main.h>
  309.  
  310. #if    DECWINDOWS              /* redefine STDMAG previously     */
  311. #undef    STDMAG                       /* define in MAIN.H        */
  312. #if    STDRES
  313. #define    STDMAG        500
  314. #else                                   /* STDMAG = dpi * 5        */
  315. #define    STDMAG        347          /* 83 dpi : STDMAG = 417    */
  316.                     /* 69 dpi : STDMAG = 347    */
  317. #endif    /* STDRES    */
  318. #endif    /* DECWINDOWS    */  
  319.  
  320. #include <abortrun.h>
  321. #include <actfact.h>
  322. #include <alldone.h>
  323.  
  324. /*----------------------------------------------------------------------*/
  325. /* BOPACT begin of page actions                        */
  326. /*----------------------------------------------------------------------*/
  327.  
  328. void bopact()
  329. {
  330.     (void)clrbmap();          /* Clear bitmap memory        */
  331.  
  332.     pbghpos = pbgvpos = -99;      /* set global values        */
  333.     cpagep  = (long)FTELL(dvifp) -1L;
  334.     ppagep  = (long)nosignex(dvifp,(BYTE)4);
  335. }
  336.  
  337. #include <chargf.h>
  338. #include <charpk.h>
  339. #include <charpxl.h>
  340. #include <clrbmap.h>
  341. #include <clrrow.h>
  342. #include <dbgopen.h> 
  343.  
  344. /*----------------------------------------------------------------------*/
  345. /* DEVINIT initialize DEC Windows output                */
  346. /*----------------------------------------------------------------------*/
  347.  
  348. void devinit(argc,argv)
  349. int argc;                           /* Command line argument count. */
  350. char     *argv[];                           /* Pointers to command line args*/
  351. {
  352. int    k;
  353. XSizeHints    xsh;
  354.          
  355.     DwtInitializeDRM();             /* Init DRM first        */
  356.                     /* Init X Toolkit        */
  357.         toplevel_widget = XtInitialize(APP_ID,"DVIDecw",NULL,
  358.                              0,&argc,argv);                          
  359.                                        /* Open the UID file        */
  360.         if(DwtOpenHierarchy(db_filename_num,db_filename_vec,NULL,
  361.        &s_DRMHierarchy) != DRMSuccess)
  362.           s_error("can't open hierarchy");
  363.  
  364.         for (k=0;k<MAX_WIDGETS;k++)      /* Init data structures        */
  365.             widget_array[k] = NULL;
  366.                     /* Register names to DRM    */    
  367.         DwtRegisterDRMNames(reglist, reglist_num);
  368.                         /* Fetch all widgets         */  
  369.     if (DwtFetchWidget(s_DRMHierarchy, "TheMainWindow", toplevel_widget,
  370.             &main_window_widget, &dummy_class) != DRMSuccess)
  371.            s_error("can't fetch main window");
  372.         if (DwtFetchWidget(s_DRMHierarchy, "ClipboardMsg", toplevel_widget,
  373.             &widget_array[k_clipboard_msg], &dummy_class) != DRMSuccess) 
  374.            s_error("can't fetch clipboard msg widget");
  375.         if  (DwtFetchWidget(s_DRMHierarchy, "GotopageDlg", toplevel_widget,
  376.          &widget_array[k_goto_page_dlg], &dummy_class) != DRMSuccess)
  377.            s_error("can't fetch dialog box widget");       
  378.         if  (DwtFetchWidget(s_DRMHierarchy, "AboutMsg", toplevel_widget,
  379.          &widget_array[k_about_msg], &dummy_class) != DRMSuccess)
  380.            s_error("can't fetch info dialog box widget");       
  381.         if  (DwtFetchWidget(s_DRMHierarchy, "LastpageMsg", toplevel_widget,
  382.          &widget_array[k_lastpage_msg], &dummy_class) != DRMSuccess)
  383.            s_error("can't fetch lastpage msg box widget");             
  384.         if  (DwtFetchWidget(s_DRMHierarchy, "FirstpageMsg", toplevel_widget,
  385.          &widget_array[k_firstpage_msg], &dummy_class) != DRMSuccess)
  386.            s_error("can't fetch firstpage msg box widget");   
  387.         if  (DwtFetchWidget(s_DRMHierarchy, "ZoomrangeMsg", toplevel_widget,
  388.          &widget_array[k_zoomrange_msg], &dummy_class) != DRMSuccess)
  389.            s_error("can't fetch zoomrange msg box widget"); 
  390.                           /* Manage all widgets        */
  391.     XtManageChild(main_window_widget);
  392.                     /* Display all widgets        */
  393.     XtRealizeWidget(toplevel_widget);  
  394.                        /* Install accelerators        */
  395.     XtInstallAllAccelerators(main_window_widget,main_window_widget);
  396.                                  /* Query handles        */
  397.     display = XtDisplay(main_window_widget); 
  398.         screen  = XDefaultScreenOfDisplay(display); 
  399.         gc      = XDefaultGCOfScreen(screen);          
  400.     top_wi    = XtWindow(toplevel_widget);
  401.                     /* Define fore/background colors*/
  402.     XSetForeground(display,gc,XBlackPixelOfScreen(screen));
  403.     XSetBackground(display,gc,XWhitePixelOfScreen(screen));   
  404.                                        /* Set Position and Size    */
  405.     xsh.x=1;
  406.     xsh.y=1;                 
  407.                     /* Fit window width in screen    */
  408.     if(XWidthOfScreen(screen) > XSIZE)  
  409.       xsh.width=XSIZE;
  410.     else
  411.       xsh.width=XWidthOfScreen(screen);
  412.                                            /* Fit window height in screen    */
  413.     if(XHeightOfScreen(screen) > YSIZE) 
  414.       xsh.height=YSIZE;
  415.     else
  416.       xsh.height=XHeightOfScreen(screen);
  417.  
  418.     xsh.flags=PPosition|PSize;         /* Set Modification flag    */
  419.     XSetNormalHints(display,top_wi,&xsh);      
  420.  
  421.     (void)getbmap();         /* Allocate bitmap memory    */ 
  422.                                        /* Create X Image structure    */
  423.     out_img = XCreateImage(display,XDefaultVisualOfScreen(screen),
  424.                            1,XYBitmap,0,bitmap,XSIZE,YSIZE,
  425.                    XBitmapPad(display),0);
  426.                     /* Set image byte and bit order    */
  427.                                         /* Comment Values are for VAX WS*/
  428.     out_img->byte_order = XImageByteOrder(display);         /* LSBFirst*/
  429.     out_img->bitmap_bit_order = XBitmapBitOrder(display);/* MSBFirst*/
  430.                     /* Mirror BitmapBitOrder bugfix    */
  431.     if(out_img->bitmap_bit_order == MSBFirst)
  432.       out_img->bitmap_bit_order = LSBFirst;   
  433.         else
  434.       out_img->bitmap_bit_order = MSBFirst; 
  435.                                          /* Fetch text strings for menu    */
  436.     slow_move    = DwtLatin1String("Slow move");
  437.     fast_move    = DwtLatin1String("Fast move");
  438.     no_offset    = DwtLatin1String("No offset");
  439.     use_offset   = DwtLatin1String("Use offset");     
  440.     discard_dlg  = DwtLatin1String("Discard Goto...");
  441.     gotopage_dlg = DwtLatin1String("Goto ...");
  442. }
  443.  
  444. /*----------------------------------------------------------------------*/
  445. /* DEVTERM terminate DEC Windows output                    */
  446. /*----------------------------------------------------------------------*/
  447.  
  448. void devterm()
  449. {
  450.                     /* Terminate output window    */
  451.     XDestroyImage(out_img);
  452.     XUnmapWindow(display,out_wi);
  453.     XDestroyWindow(display,out_wi);
  454. }
  455.  
  456. #include <dispchar.h>
  457. #include <dvifile.h>
  458. #include <dviinit.h>
  459. #include <dviterm.h>
  460. #include <f20open.h>
  461. #include <fatal.h>
  462. #include <fillrect.h>
  463. #include <findpost.h>
  464. #include <fixpos.h>
  465. #include <fontfile.h>
  466. #include <fontsub.h>
  467. #include <getbmap.h>
  468. #include <getbytes.h>
  469. #include <getfntdf.h>
  470. #include <getpgtab.h>
  471. #include <inch.h>
  472. #include <initglob.h>
  473. #include <loadchar.h>
  474. #include <movedown.h>
  475. #include <moveover.h>
  476. #include <moveto.h>
  477.  
  478. /*----------------------------------------------------------------------*/
  479. /* NEWFONT dummy routine called form readxx routines            */
  480. /*----------------------------------------------------------------------*/
  481.  
  482. void newfont()
  483. {
  484. }
  485.  
  486. #include <nosignex.h>
  487. #include <openfont.h>
  488. #include <option.h>
  489.  
  490. /*----------------------------------------------------------------------*/
  491. /* PRTBMAP display created bitmap in output window            */
  492. /*----------------------------------------------------------------------*/
  493.  
  494. void prtbmap()
  495. {                              
  496.                     /*Copy bitmap to window        */
  497.     XPutImage(display,out_wi,gc,out_img,0,0,0,0,
  498.           x_windsize,y_windsize); 
  499. }
  500.  
  501. #include <outrow.h>
  502. #include <prtpage.h>
  503. #include <readfont.h>
  504. #include <readgf.h>
  505. #include <readpk.h>
  506. #include <readpost.h>
  507. #include <readpxl.h>
  508. #include <reldfont.h>
  509. #include <rulepxl.h>
  510. #include <setchar.h>
  511. #include <setfntnm.h>
  512. #include <setrule.h>
  513. #include <signex.h>
  514. #include <skgfspec.h>
  515. #include <skipfont.h>
  516. #include <skpkspec.h>
  517. #include <special.h>
  518. #include <strchr.h>
  519. #include <strcm2.h>
  520. #include <strid2.h>
  521. #include <strrchr.h>
  522. #include <tctos.h>
  523.  
  524. /*----------------------------------------------------------------------*/
  525. /* UNLOADFONTS mark all fonts as unloaded                */
  526. /*----------------------------------------------------------------------*/
  527.  
  528. void unloadfonts()            /* mark all fonts as not loaded */
  529. {                    /* and set no current fonts     */
  530.        INT16 k;                /* loop index             */
  531.  
  532.     for (fontptr = hfontptr; fontptr != (struct font_entry *)NULL;
  533.      fontptr = fontptr->next)
  534.     {
  535.     for (k = 0; k < NPXLCHARS; ++k)
  536.         fontptr->ch[k].isloaded = FALSE;
  537.  
  538.     if (fontptr->font_file_id != (FILE*)NULL)
  539.     {
  540.         (void)fclose(fontptr->font_file_id);
  541.         fontptr->font_file_id = (FILE*)NULL;
  542.     }
  543.     }
  544.  
  545.     fontfp = (FILE*)NULL;        /* no current font file     */
  546.     for ( ; nopen > 0; --nopen)        /* clear font file cache     */
  547.     {
  548.     font_files[nopen].font_id = (FILE*)NULL;
  549.     font_files[nopen].use_count = (INT16)0;
  550.     }
  551.  
  552.     /* NB: It is important here that the loop index be global; the relation
  553.     of fontptr to pfontptr is used by openfont() to decide whether the font
  554.     file is already open. */
  555.     for (fontptr = hfontptr; fontptr != (struct font_entry *)NULL;
  556.      fontptr = fontptr->next)
  557.     {
  558.     pfontptr = (struct font_entry *)(NULL); 
  559.                     /* so reldfont() calls openfont() */
  560.     (void)reldfont(fontptr);    /* get new font metrics     */
  561.     }
  562. }
  563.  
  564. #include <usage.h>
  565. #include <warning.h>
  566.  
  567. /************************************************************************/
  568. /* Service routines for DECWINDOWS environment                */
  569. /************************************************************************/
  570.  
  571. /*----------------------------------------------------------------------*/
  572. /* S_ERROR put up an severe error message                */
  573. /*----------------------------------------------------------------------*/
  574.  
  575. static void s_error(char *problem_string)
  576. {
  577.         printf("%s\n", problem_string);
  578.         exit(0);
  579. }
  580. /*----------------------------------------------------------------------*/
  581. /* SCROLL_BAR callback routine to handle scrollbar event          */
  582. /*----------------------------------------------------------------------*/
  583.  
  584. static void scroll_bar_proc(Widget w,int *tag,unsigned long *reason)
  585. {
  586. int    widget_num = *tag;
  587.  
  588.     switch(widget_num)
  589.     {
  590.      case k_scroll_y:            /* Get vertical slider position    */
  591.             XtSetArg(arglist[0],DwtNvalue,&yscreen);
  592.          XtGetValues(w,arglist,1);
  593.         send_redraw();      
  594.         break;
  595.  
  596.      case k_scroll_x:              /* Get horizontal slider position*/ 
  597.             XtSetArg(arglist[0],DwtNvalue,&xscreen);
  598.         XtGetValues(w,arglist,1);
  599.         send_redraw();          
  600.         break;        
  601.  
  602.      default:             /* Event is unknown        */
  603.         break;
  604.         }                 
  605. }    
  606.  
  607. /*----------------------------------------------------------------------*/
  608. /* CREATE_PROC callback routine to handle an create reason from    UIL    */
  609. /*----------------------------------------------------------------------*/
  610.  
  611. static void create_proc(Widget w,int *tag,unsigned long *reason)
  612. {
  613. int     widget_num = *tag;              /* Convert tag to widget number.*/ 
  614.  
  615.     widget_array[widget_num]= w;       /* register widget handle    */
  616. }
  617.  
  618. /*----------------------------------------------------------------------*/
  619. /* ACTIVATE_PROC callback routine to handle an activate reason from UIL    */
  620. /*----------------------------------------------------------------------*/
  621.  
  622. static void activate_proc(Widget w,int *tag,unsigned long *reason) 
  623. {
  624. int     widget_num = *tag;              /* Convert tag to widget number.*/ 
  625. int     i, value;
  626.  
  627. int    new_page_number;        /* destination page number    */
  628. char    *new_page_string;        /* page number in string form    */
  629.  
  630. int     move_step_x;            /* current step width for moves    */
  631. int     move_step_y;
  632. static  BOOLEAN    move_fast=FALSE;
  633. static  BOOLEAN offset=TRUE;
  634.                                                                            
  635. unsigned long data_id;            /* Item/data identifier for    */
  636. unsigned long item_id;                  /* Clipboard operations        */
  637. unsigned long status;            /* Clipboard operation status    */
  638.  
  639.     
  640.     if(move_fast)              /* Adjust step width for moves    */
  641.     {
  642.      move_step_y = y_windsize;
  643.      move_step_x = x_windsize;
  644.     }
  645.     else
  646.     {
  647.      move_step_y = y_windsize/10;
  648.      move_step_x = x_windsize/10;
  649.     }
  650.  
  651.         switch (widget_num)
  652.     {    
  653.      case k_about_me:        /* show info on DVIDECW        */
  654.         XtManageChild(widget_array[k_about_msg]);
  655.         break;
  656.  
  657.      case k_about_button:        /* close info on DVIDECW    */
  658.         XtUnmanageChild(widget_array[k_about_msg]);
  659.         break;
  660.  
  661.      case k_quit_me:        /* Menu File/Quit        */
  662.         (void)devterm();        /* terminate device output     */  
  663.         (void)dviterm();        /* terminate DVI file processing*/  
  664.         (void)alldone();        /* this will never return     */
  665.         break;                       
  666.  
  667.      case k_copy_me:                   /* perform copy to clibboard    */
  668.         status=DwtBeginCopyToClipboard(display,out_wi,APP_ID,
  669.                        (Widget)0,(VoidProc)0,&item_id);
  670.         if(status != ClipboardSuccess)
  671.         {
  672.              XtManageChild(widget_array[k_clipboard_msg]);  
  673.          break;    
  674.         } 
  675.             status=DwtCopyToClipboard(display,out_wi,item_id,
  676.                       CLPBRD_FORMAT,bitmap,
  677.                       (unsigned long)(XSIZE*YSIZE),
  678.                       0,&data_id);
  679.         if(status != ClipboardSuccess)
  680.         {
  681.              XtManageChild(widget_array[k_clipboard_msg]);  
  682.          break;
  683.         }
  684.         status=DwtEndCopyToClipboard(display,out_wi,item_id);
  685.         if(status != ClipboardSuccess)
  686.         {
  687.              XtManageChild(widget_array[k_clipboard_msg]);  
  688.         }
  689.         break;
  690.  
  691.      case k_prevpage_me:        /* goto previous page (if avail)*/
  692.         if(cur_index > 0)  
  693.         {
  694.          cur_index--;
  695.          cur_page_number--;    
  696.          send_redraw();
  697.         }
  698.         else                           /* first page reached already    */
  699.           XtManageChild(widget_array[k_firstpage_msg]);
  700.         break;
  701.  
  702.      case k_nextpage_me:             /* goto next page (if avail)    */
  703.         if(cur_index < page_count-1)
  704.         {
  705.          cur_index++;
  706.          cur_page_number++;
  707.          send_redraw();
  708.         }
  709.         else                      /* last page reached already    */
  710.               XtManageChild(widget_array[k_lastpage_msg]);
  711.         break;
  712.  
  713.      case k_gotopage_me:           /* open gotopage dialog box    */
  714.         if(XtIsManaged(widget_array[k_goto_page_dlg]))
  715.         {
  716.          XtUnmanageChild(widget_array[k_goto_page_dlg]);                 
  717.              XtSetArg(arglist[0],DwtNlabel,gotopage_dlg);
  718.          XtSetValues(widget_array[k_gotopage_me],arglist,1);              
  719.         }
  720.         else
  721.         {
  722.              XtManageChild(widget_array[k_goto_page_dlg]);
  723.              XtSetArg(arglist[0],DwtNlabel,discard_dlg);
  724.          XtSetValues(widget_array[k_gotopage_me],arglist,1);             
  725.         }
  726.         break;
  727.  
  728.      case k_ok_button:        /* dialog box left by ok button    */
  729.         new_page_string = DwtSTextGetString(widget_array[k_pagenumber]);
  730.         new_page_number = 0;
  731.         sscanf(new_page_string,"%d",&new_page_number);
  732.          if(new_page_number > page_count)
  733.           new_page_number = page_count;    
  734.         if(new_page_number < 1) 
  735.           new_page_number = 1;
  736.             cur_index = new_page_number - 1;
  737.         cur_page_number = new_page_number;
  738.         sprintf(new_page_string,"%d",new_page_number);
  739.         DwtSTextSetString(widget_array[k_pagenumber],new_page_string);  
  740.         XtUnmanageChild(widget_array[k_goto_page_dlg]);               
  741.             XtSetArg(arglist[0],DwtNlabel,gotopage_dlg);
  742.         XtSetValues(widget_array[k_gotopage_me],arglist,1);              
  743.         send_redraw();   
  744.         break;                                  
  745.  
  746.      case k_goto_button:        /* dialog box left by go button    */
  747.         new_page_string = DwtSTextGetString(widget_array[k_pagenumber]);
  748.         new_page_number = 0;
  749.         sscanf(new_page_string,"%d",&new_page_number);
  750.          if(new_page_number > page_count)
  751.           new_page_number = page_count;    
  752.         if(new_page_number < 1) 
  753.           new_page_number = 1;
  754.             cur_index = new_page_number - 1;
  755.         cur_page_number = new_page_number;
  756.         sprintf(new_page_string,"%d",new_page_number);
  757.         DwtSTextSetString(widget_array[k_pagenumber],new_page_string);  
  758.         send_redraw();
  759.         break;                                  
  760.  
  761.      case k_cancel_button:        /* dialog box cancelled        */
  762.         XtUnmanageChild(widget_array[k_goto_page_dlg]);
  763.             XtSetArg(arglist[0],DwtNlabel,gotopage_dlg);
  764.         XtSetValues(widget_array[k_gotopage_me],arglist,1);              
  765.         break;
  766.  
  767.      case k_zoom_out_me:        /* Zoom down one magstep    */    
  768.         runmag=MAGSIZE(actfact((UNSIGN32)((5*runmag)/6)));
  769.         conv = ((float)num/(float)den) *
  770.            ((float)runmag/(float)STDMAG) *
  771. #if    USEGLOBALMAG
  772.                actfact(mag) *
  773. #endif
  774.                ((float)RESOLUTION/254000.0);
  775.                                       /* Constrain resolution range    */  
  776.         if((int)((runmag*10/5+5)/10) < MIN_DPI)        
  777.         XtManageChild(widget_array[k_zoomrange_msg]);
  778.         (void)unloadfonts();
  779.         send_redraw();  
  780.         break;
  781.  
  782.      case k_zoom_in_me:        /* Zoom up one magstep        */
  783.         runmag=MAGSIZE(actfact((UNSIGN32)((6*runmag)/5)));
  784.         conv = ((float)num/(float)den) *
  785.            ((float)runmag/(float)STDMAG) *
  786. #if    USEGLOBALMAG
  787.                actfact(mag) *
  788. #endif
  789.                ((float)RESOLUTION/254000.0);
  790.                                       /* Constrain resolution range    */  
  791.         if((int)((runmag*10/5+5)/10) > MAX_DPI)        
  792.         XtManageChild(widget_array[k_zoomrange_msg]);
  793.         (void)unloadfonts();
  794.         send_redraw();  
  795.         break;
  796.  
  797.      case k_bot_page_me:          /* goto bottom of page        */
  798.         yscreen = y_pagesize - y_windsize;
  799.         send_redraw();
  800.         break;
  801.  
  802.      case k_top_page_me:           /* goto top of page        */
  803.         yscreen = 0;
  804.         send_redraw();
  805.         break;
  806.  
  807.      case k_curs_up_me:            /* move up one step        */
  808.         yscreen -= move_step_y;
  809.         send_redraw();
  810.         break;
  811.  
  812.      case k_curs_down_me:        /* move down one step        */
  813.         yscreen += move_step_y;
  814.         send_redraw();
  815.         break;
  816.  
  817.      case k_curs_left_me:          /* move left one step        */ 
  818.         xscreen -= move_step_x;
  819.         send_redraw();
  820.         break;
  821.  
  822.      case k_curs_right_me:            /* move right one step        */
  823.         xscreen += move_step_x;
  824.         send_redraw();
  825.         break;
  826.                          
  827.      case k_offset_me:               /* toggle use/dont't use offs    */
  828.         if(offset == TRUE)
  829.         {
  830.          lmargin = (COORDINATE)(0.1*((float)XDPI));
  831.          tmargin = (COORDINATE)(0.1*((float)YDPI));
  832.              XtSetArg(arglist[0],DwtNlabel,use_offset);
  833.          XtSetValues(widget_array[k_offset_me],arglist,1);         
  834.          offset=FALSE;
  835.          send_redraw();
  836.             }
  837.         else
  838.         {
  839.          lmargin = (COORDINATE)(leftmargin*((float)XDPI));
  840.          tmargin = (COORDINATE)(topmargin *((float)YDPI));
  841.              XtSetArg(arglist[0],DwtNlabel,no_offset);
  842.          XtSetValues(widget_array[k_offset_me],arglist,1);       
  843.          offset=TRUE;
  844.          send_redraw();    
  845.             }
  846.         break;
  847.  
  848.      case k_move_speed_me:          /* toggle fast/slow cursor moves*/
  849.             if(move_fast == TRUE)
  850.         {
  851.              XtSetArg(arglist[0],DwtNlabel,fast_move);
  852.          XtSetValues(widget_array[k_move_speed_me],arglist,1);       
  853.          move_fast = FALSE;
  854.         }
  855.         else
  856.         {
  857.              XtSetArg(arglist[0],DwtNlabel,slow_move);
  858.          XtSetValues(widget_array[k_move_speed_me],arglist,1);     
  859.          move_fast = TRUE;
  860.         }    
  861.         break;
  862.  
  863.      case k_reset_pos_me:          /* reset position after moves    */
  864.         xscreen = 0;
  865.         yscreen = 0;
  866.         send_redraw();
  867.         break;
  868.                   
  869.          default:               /* event is unknown        */
  870.             break;
  871.         }
  872. }
  873.  
  874. /*----------------------------------------------------------------------*/
  875. /* SEND_REDRAW sends a redraw message to output window            */
  876. /*----------------------------------------------------------------------*/
  877.  
  878. void send_redraw()
  879. {    
  880. XEvent    event;                       /* event record for send event    */   
  881.  
  882.     event.type            = Expose;
  883.     event.xexpose.send_event    = TRUE;
  884.     event.xexpose.display        = display;
  885.     event.xexpose.window        = out_wi;
  886.     event.xexpose.x            = 0;
  887.     event.xexpose.y            = 0;
  888.     event.xexpose.width        = x_windsize;
  889.     event.xexpose.height        = y_windsize;
  890.     event.xexpose.count        = 0;
  891.  
  892.     XSendEvent(display,out_wi,TRUE,ExposureMask,&event);   
  893. }
  894.  
  895. /*----------------------------------------------------------------------*/
  896. /* OUTPUT_EXPOSED_PROC react on Tex Output window exposure event    */
  897. /*----------------------------------------------------------------------*/
  898.  
  899. static void output_exp_proc(Widget w,int *tag,
  900.                 DwtAnyCallbackStruct *callback_data)
  901. {
  902. static     BOOLEAN    first = TRUE;        /* Flag for first time execution*/
  903. char    out_string[128];        /* string for messages        */
  904. XWindowAttributes xwa;                  /* Window attrib. structure    */
  905. XSizeHints    xsh;
  906. int    x_top_windsize;
  907. int    y_top_windsize;
  908.  
  909.     if(first)                     /* Do this only once         */
  910.         { 
  911.      first = FALSE;
  912.      out_wi = XtWindow(w);           /* Inquire window handle    */
  913.      XMapWindow(display,out_wi);       /* Set mapping            */ 
  914.          XClearWindow(display,out_wi);     /* Clear window            */
  915.     }
  916.                     /* Get windowsize in pxl    */
  917.     XGetWindowAttributes(display,out_wi,&xwa);
  918.     x_windsize = xwa.width;
  919.     y_windsize = xwa.height;
  920.                     /* Get topwindow size in pxl    */
  921.     XGetWindowAttributes(display,top_wi,&xwa);
  922.     x_top_windsize = xwa.width;
  923.     y_top_windsize = xwa.height;
  924.                     /* Get pagesize in pxl        */
  925.     x_pagesize = (int)((runmag*10/5+5)/10)*XPSIZE;
  926.     y_pagesize = (int)((runmag*10/5+5)/10)*YPSIZE;
  927.                     /* Resize window if required    */
  928.     if(x_top_windsize > x_pagesize || y_top_windsize > y_pagesize)
  929.     {                            /* Fit window width in screen    */
  930.      if(x_top_windsize > x_pagesize && y_top_windsize <= y_pagesize)
  931.         XResizeWindow(display,out_wi,x_pagesize,y_top_windsize);  
  932.      if(x_top_windsize <= x_pagesize && y_top_windsize > y_pagesize)
  933.         XResizeWindow(display,out_wi,x_top_windsize,y_pagesize);  
  934.      if(x_top_windsize > x_pagesize && y_top_windsize > y_pagesize)
  935.         XResizeWindow(display,out_wi,x_pagesize,y_pagesize);    
  936.     }
  937.                                         /* Constrain view range        */
  938.     if(xscreen < 0)            
  939.        xscreen = 0;
  940.     if(xscreen > (x_pagesize - x_windsize))
  941.        xscreen = x_pagesize - x_windsize;
  942.     if(yscreen < 0)
  943.        yscreen = 0;
  944.     if(yscreen > (y_pagesize-y_windsize))
  945.        yscreen = y_pagesize-y_windsize;
  946.                     /* Set horiz. scrollbar values    */
  947.         XtSetArg(arglist[0],DwtNshown,x_windsize); 
  948.         XtSetArg(arglist[1],DwtNmaxValue,x_pagesize);       
  949.         XtSetArg(arglist[2],DwtNvalue,xscreen);       
  950.     XtSetArg(arglist[3],DwtNinc,x_windsize/10);
  951.     XtSetArg(arglist[4],DwtNpageInc,x_windsize);  
  952.     XtSetValues(widget_array[k_scroll_x],arglist,5);
  953.                                         /* Set vertic. scrollbar values    */
  954.         XtSetArg(arglist[0],DwtNshown,y_windsize); 
  955.         XtSetArg(arglist[1],DwtNmaxValue,y_pagesize);      
  956.         XtSetArg(arglist[2],DwtNvalue,yscreen);       
  957.     XtSetArg(arglist[3],DwtNinc,y_windsize/10);
  958.     XtSetArg(arglist[4],DwtNpageInc,y_windsize);  
  959.     XtSetValues(widget_array[k_scroll_y],arglist,5);  
  960.                                           /* Prepare window title bar    */
  961.                     /* Create page image bitmap    */
  962.     prtpage(page_ptr[cur_index]);     
  963.                     /* Display page image bitmap    */
  964.     sprintf(out_string,"TeX Preview - Page %d/%d  TeX-Page[%s]  %d dpi",
  965.         cur_index+1,page_count,tctos(),(int)((runmag*10/5+5)/10));
  966.     XStoreName(display,top_wi,out_string);                              
  967.  
  968.     prtbmap();
  969. }
  970.  
  971. /************************************************************************/
  972. /* END of source file                            */
  973. /************************************************************************/
  974.